forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_env.sh
executable file
·77 lines (61 loc) · 1.65 KB
/
check_env.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/zsh
# Copyright (c) 2021 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
set -eu
function SystemProfilerProperty()
{
local result=$2
local local_result=$(system_profiler $3| grep -i $1 |\
cut -d ":" -f 2 | awk '{$1=$1};1')
eval $result="'$local_result'"
}
function GetPowerProperty()
{
SystemProfilerProperty $1 $2 "SPPowerDataType"
}
function GetDisplayProperty()
{
SystemProfilerProperty $1 $2 "SPDisplaysDataType"
}
function CompareValue()
{
if [ "$1" != "$2" ]; then
echo $3
exit 127
fi
}
CheckPowerValue()
{
# Query value, remove newlines.
GetPowerProperty $1 VALUE
VALUE=$(echo $VALUE|tr -d '\n')
CompareValue $VALUE $2 $3
}
CheckDisplayValue()
{
# Query value, remove newlines.
GetDisplayProperty $1 VALUE
VALUE=$(echo $VALUE|tr -d '\n')
CompareValue $VALUE $2 $3
}
function CheckProgramNotRunning(){
if pgrep -x "$1" > /dev/null; then
echo "$2"
exit 127
fi
}
function CheckEnv()
{
# Validate power setup.
CheckPowerValue "charging" "NoNo" "Laptop cannot be charging during test."
CheckPowerValue "connected" "No" "Charger cannot be connected during test."
# Validate display setup.
CheckDisplayValue "Automatically adjust brightness" "No"\
"Disable automatic brightness adjustments and unplug external monitors"
# Verify that no terminals are running.
# They introduce too much overhead. (As measured with powermetrics)
CheckProgramNotRunning "Terminal" "Do not have a terminal opened. Use SSH.";
CheckProgramNotRunning "iTerm2" "Do not have a terminal opened. Use SSH.";
}
CheckEnv