1
by Bryce Harrington
Initial import |
1 |
DELAY=3 # Time to wait for X to start up (in sec) |
2 |
DEFAULT_XORG_CONF="/etc/X11/xorg.conf" |
|
3 |
DISPLAY=:0 |
|
4 |
||
5 |
# Internal variables |
|
6 |
test_count=0 |
|
7 |
pass_count=0 |
|
8 |
fail_count=0 |
|
9 |
||
3
by Bryce Harrington
* Check running as non-root |
10 |
is_superuser() { |
11 |
test $(id -u) = 0 |
|
12 |
}
|
|
13 |
||
5
by Bryce Harrington
Add a "prerequisite" call in all tests to check that required files or |
14 |
warn() { |
15 |
echo "Warning: $1" 1>&2 |
|
16 |
}
|
|
17 |
||
1
by Bryce Harrington
Initial import |
18 |
die() { |
19 |
msg=$1 |
|
20 |
||
21 |
echo "Error: $msg" |
|
22 |
print_test_summary |
|
23 |
exit 1 |
|
24 |
}
|
|
25 |
||
26 |
pass() { |
|
27 |
msg=$1 |
|
28 |
echo "[PASS] $msg" |
|
29 |
pass_count=$(( $pass_count + 1 )) |
|
30 |
return 0 |
|
31 |
}
|
|
32 |
||
33 |
fail() { |
|
34 |
msg=$1 |
|
35 |
echo "[FAIL] $msg" |
|
36 |
fail_count=$(( $fail_count + 1 )) |
|
37 |
return 1 |
|
38 |
}
|
|
39 |
||
6
by Bryce Harrington
Adding support for printing out summary info as json files |
40 |
print_test_summary() { |
41 |
echo "Tests: $test_count; Passed: $pass_count; Failed: $fail_count" |
|
42 |
}
|
|
43 |
||
44 |
json_test_summary() { |
|
45 |
[ ! -z "$1" ] || return 1 |
|
46 |
echo > $1 <<EOF |
|
47 |
{
|
|
48 |
"tests": "$test_count", |
|
49 |
"passed": "$pass_count", |
|
50 |
"failed": "$fail_count" |
|
51 |
}
|
|
52 |
EOF
|
|
53 |
return 0 |
|
54 |
}
|
|
55 |
||
1
by Bryce Harrington
Initial import |
56 |
is_running() { |
57 |
proc=$1 |
|
58 |
$(pidof $proc > /dev/null) |
|
59 |
}
|
|
60 |
||
5
by Bryce Harrington
Add a "prerequisite" call in all tests to check that required files or |
61 |
is_installed() { |
62 |
prog=$1 |
|
63 |
need=$2 |
|
64 |
/usr/bin/which $prog > /dev/null 2>&1 |
|
65 |
err=$? |
|
66 |
if [ ! $err = 0 ]; then |
|
67 |
warn "Could not $need because $prog is not installed ($err)" |
|
68 |
return $err |
|
69 |
fi |
|
70 |
return 0 |
|
71 |
}
|
|
72 |
||
1
by Bryce Harrington
Initial import |
73 |
stop_service() { |
74 |
svc=$1 |
|
75 |
pidof $svc > /dev/null && /etc/init.d/$svc stop |
|
76 |
pidof $svc > /dev/null && die "Could not stop service $svc" |
|
77 |
echo "Service $svc stopped" |
|
78 |
}
|
|
79 |
||
80 |
stop_command() { |
|
81 |
cmd=$1 |
|
82 |
pidof $cmd > /dev/null && pkill -9 $cmd |
|
83 |
pidof $cmd > /dev/null && die "Could not stop command $cmd" |
|
84 |
echo "Command $cmd stopped" |
|
85 |
}
|
|
86 |
||
5
by Bryce Harrington
Add a "prerequisite" call in all tests to check that required files or |
87 |
# pid_is_valid(PID) |
88 |
#
|
|
89 |
# Checks if the given $PID is still running. Returns a true value if |
|
90 |
# it is, false otherwise. |
|
91 |
#
|
|
92 |
pid_is_valid() |
|
93 |
{
|
|
94 |
PID=$1 |
|
95 |
ps --pid ${PID} --no-header | grep ${PID} |
|
96 |
return $? |
|
97 |
}
|
|
98 |
||
99 |
# kill_pid(PID) |
|
100 |
#
|
|
101 |
# Forcibly kills the process ID and prevents it from |
|
102 |
# displaying any messages (to stdout, stderr, or otherwise) |
|
103 |
#
|
|
104 |
kill_pid() |
|
105 |
{
|
|
106 |
PID=$1 |
|
107 |
disown $PID |
|
108 |
kill -9 $PID > /dev/null 2>&1 |
|
109 |
}
|
|
110 |
||
1
by Bryce Harrington
Initial import |
111 |
get_xorg_drivers() { |
112 |
pid=`pidof X` |
|
113 |
if [ -z "$pid" ]; then |
|
114 |
echo "Error: X is not running" |
|
115 |
return 1 |
|
116 |
fi |
|
117 |
cat /proc/$pid/smaps | \ |
|
118 |
egrep '_drv.so|_dri.so' | \ |
|
119 |
cut -d '/' -f 7 | \ |
|
120 |
cut -d "_" -f 1 | \ |
|
121 |
uniq |
|
122 |
}
|
|
123 |
||
124 |
get_xorg_driver_version_loaded() { |
|
125 |
driver=$1 |
|
126 |
xlogparse /var/log/Xorg.0.log --modules | egrep "^$driver " | sed -e 's/ \+/ /g' | cut -d ' ' -f2 |
|
127 |
}
|
|
128 |
||
129 |
get_debian_version() { |
|
130 |
pkg=$1 |
|
131 |
dpkg -l $pkg | cat \ |
|
132 |
| egrep '^ii' \ |
|
133 |
| sed -e "s/ \+/ /g" \ |
|
134 |
| cut -d' ' -f 3 |
|
135 |
}
|
|
136 |
||
137 |
get_installed_version() { |
|
138 |
get_debian_version $1 \ |
|
139 |
| sed -e "s/^.*+//" \ |
|
140 |
| cut -d- -f1 \ |
|
141 |
| sed -e "s/^[0-9]://" \ |
|
142 |
| sed -e "s/ubuntu.*$//" |
|
143 |
}
|
|
144 |
||
145 |
test_syntax_bash() { |
|
146 |
file=$1 |
|
147 |
test_count=$(( $test_count + 1)) |
|
148 |
||
149 |
errors=`bash -n $file 2>&1` |
|
150 |
if [ $? = 0 ]; then |
|
151 |
pass "$file is a valid bash program" |
|
152 |
else |
|
153 |
fail "$file has invalid bash syntax: $errors" |
|
154 |
fi |
|
155 |
}
|
|
156 |
||
157 |
test_syntax_perl() { |
|
158 |
file=$1 |
|
159 |
test_count=$(( $test_count + 1)) |
|
160 |
||
161 |
errors=`perl -c $file 2>&1` |
|
162 |
if [ $? = 0 ]; then |
|
163 |
pass "$file is a valid perl program" |
|
164 |
else |
|
165 |
fail "$file has invalid perl syntax: $errors" |
|
166 |
fi |
|
167 |
}
|
|
168 |
||
169 |
test_process_running() { |
|
170 |
proc=$1 |
|
171 |
test_count=$(( $test_count + 1 )) |
|
172 |
||
173 |
pid=`pidof $proc` |
|
174 |
if [ ! -z $pid ]; then |
|
175 |
pass "$proc is running as process $pid" |
|
176 |
else |
|
177 |
fail "$proc is not running" |
|
178 |
fi |
|
179 |
}
|
|
180 |
||
181 |
test_driver_loaded() { |
|
182 |
test_count=$(( $test_count + 1 )) |
|
183 |
||
184 |
driver=`get_xorg_drivers | grep $1` |
|
185 |
||
186 |
if [ ! -z $driver ]; then |
|
187 |
pass "driver $driver is loaded" |
|
188 |
else |
|
189 |
fail "driver $driver is not loaded" |
|
190 |
fi |
|
191 |
}
|
|
192 |
||
193 |
test_driver_version() { |
|
194 |
driver=$1 |
|
195 |
expected=$2 |
|
196 |
||
197 |
test_count=$(( $test_count + 1 )) |
|
198 |
||
199 |
version=`get_xorg_driver_version_loaded $driver` |
|
200 |
if [ $version = $expected ]; then |
|
201 |
pass "$driver driver version $expected is loaded" |
|
202 |
else |
|
203 |
fail "$driver driver version is $version, not $expected as expected" |
|
204 |
fi |
|
205 |
}
|
|
206 |
||
207 |
test_xorg_restart() { |
|
208 |
# Shut down X, gdm, etc |
|
209 |
echo "Stopping X" |
|
210 |
stop_command gdm |
|
211 |
stop_command startx |
|
212 |
stop_command X |
|
213 |
||
3
by Bryce Harrington
* Check running as non-root |
214 |
# Remove any stray X lock files |
215 |
rm -f /tmp/.X*-lock |
|
216 |
||
1
by Bryce Harrington
Initial import |
217 |
echo "Starting X" |
218 |
startx & |
|
219 |
||
220 |
sleep $DELAY |
|
221 |
||
222 |
# Verify X is running |
|
223 |
test_process_running X |
|
224 |
}
|
|
225 |
||
226 |
test_xorg_conf_creation() { |
|
227 |
xorg_conf_file=$1 |
|
228 |
||
229 |
test_count=$(( $test_count + 1 )) |
|
230 |
||
231 |
if [ -e $DEFAULT_XORG_CONF ]; then |
|
3
by Bryce Harrington
* Check running as non-root |
232 |
mv -f $DEFAULT_XORG_CONF $DEFAULT_XORG_CONF.backup |
1
by Bryce Harrington
Initial import |
233 |
fi |
234 |
||
235 |
output=`dexconf 2>&1` |
|
236 |
if [ $? = 0 ]; then |
|
237 |
pass "dexconf ran without error" |
|
238 |
else |
|
239 |
fail "dexconf returned error code. $output" |
|
240 |
fi |
|
241 |
}
|