forked from way-cooler/way-cooler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_wayland.sh
executable file
·308 lines (273 loc) · 8.85 KB
/
test_wayland.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
#!/usr/bin/env bash
#
# Test runner.
#
# This can also be used to start awesome from the build directory, e.g. for
# git-bisect:
# 1. Put the file into a subdirectory, which is ignored by git, e.g.
# `tmp/run.sh`.
# 2. Run it from the source root (after `make`):
# env TEST_PAUSE_ON_ERRORS=1 sh tmp/run.sh
# It should start Xephyr and launch awesome in it, using the default config.
# TODO FIXME
# This needs to upstreamed in some way eventually.
# The tests/ directory should become a separate repo used by both Awesome
# and Way Cooler.
#
# NOTE That a lot of the code relies on the tests/ residing in AwesomeWM's root dir.
# So look for the this_dir/.. to fix those
set -e
export SHELL=/bin/sh
export HOME=/dev/null
# Parse options.
usage() {
cat >&2 <<EOF
Usage: $0 [OPTION]... [FILE]...
Options:
-v: verbose mode
-W: warnings become errors
-h: show this help
EOF
exit "$1"
}
fail_on_warning=
verbose=${VERBOSE:-0}
while getopts vWh opt; do
case $opt in
v) verbose=1 ;;
W) fail_on_warning=1 ;;
h) usage 0 ;;
*) usage 64 ;;
esac
done
shift $((OPTIND-1))
if (( verbose )); then
set -x
fi
# Change to file's dir (POSIXly).
cd -P -- "$(dirname -- "$0")"
this_dir="$PWD/tests/awesome/tests/"
source_dir="${PWD}"
# Either the build dir is passed in from Cargo or we guess based on $PWD
build_dir="$CARGO_TARGET_DIR"
if [ -z "$build_dir" ]; then
if [ -d "$source_dir/target/debug" ]; then
build_dir="$source_dir/target/debug"
else
echo "Need debug build of Way Cooler" >&2
exit 1
fi
fi
export build_dir
# Get test files: test*, or the ones provided as args (relative to tests/).
if [ $# != 0 ]; then
tests="$*"
else
tests="$this_dir/test*.lua"
fi
# Travis.
if [ "$CI" = true ]; then
echo "Not yet support for CI / headless" >&2
exit 1
#HEADLESS=1
#TEST_PAUSE_ON_ERRORS=0
else
HEADLESS=${HEADLESS-0}
TEST_PAUSE_ON_ERRORS=${TEST_PAUSE_ON_ERRORS-0}
fi
export TEST_PAUSE_ON_ERRORS # Used in tests/_runner.lua.
COMPOSITOR=$build_dir/way-cooler
AWESOME=$build_dir/awesome
if ! [ -x "$COMPOSITOR" ]; then
echo "$COMPOSITOR is not executable." >&2
exit 1
fi
if ! [ -x "$AWESOME" ]; then
echo "$AWESOME is not executable." >&2
exit 1
fi
AWESOME_CLIENT="$this_dir/../utils/awesome-client"
# TODO make it 5 or something
D=:1
WD=wayland-1
SIZE="${TESTS_SCREEN_SIZE:-1024x768}"
tmp_files=$(mktemp -d)
compositor_log=$tmp_files/_compositor_test.log
touch $compositor_log
echo "compositor_log: $compositor_log"
if [ $HEADLESS = 1 ]; then
echo "Way Cooler doesn't yet support headless mode" >&2
exit 1
else
$COMPOSITOR > $compositor_log 2>&1 &
compositor_pid=$!
fi
# Add test dir (for _runner.lua).
# shellcheck disable=SC2206
awesome_options=($AWESOME_OPTIONS --search lib --search "$this_dir")
export XDG_CONFIG_HOME="$build_dir"
# Cleanup on errors / aborting.
cleanup() {
for p in $awesome_pid $compositor_pid; do
kill -TERM "$p" 2>/dev/null || true
# TODO This should not be || true
# We need to fix the return code for Awesome and Way Cooler
wait "$p" || true
done
rm -rf "$tmp_files" || true
}
trap "cleanup" 0 2 3 15
awesome_log=$tmp_files/_awesome_test.log
touch $awesome_log
echo "awesome_log: $awesome_log"
wait_until_success() {
if (( verbose )); then set +x; fi
wait_count=60 # 60*0.05s => 3s.
while true; do
set +e
eval reply="\$($2)"
ret=$?
set -e
if [ $ret = 0 ]; then
break
fi
wait_count=$((wait_count - 1))
if [ "$wait_count" -lt 0 ]; then
echo "Error: failed to $1!" >&2
# shellcheck disable=SC2154
echo "Last reply: $reply" >&2
echo >&2
if [ -f "$awesome_log" ]; then
echo "Awesome Log:" >&2
cat "$awesome_log" >&2
echo >&2
fi
if [ -f "$compositor_log" ]; then
echo "Compositor Log:" >&2
# TODO renable
#cat "$compositor_log" >&2
echo >&2
fi
exit 1
fi
sleep 0.05
done
if (( verbose )); then set -x; fi
}
# Wait for DISPLAY to be available, i.e. the X server is running.
wait_until_success "talk to X server for DISPLAY \"$D\"" "DISPLAY='$D' xrdb -q >/dev/null 2>&1"
# Use a separate D-Bus session; sets $DBUS_SESSION_BUS_PID.
eval "$(DISPLAY="$D" dbus-launch --sh-syntax --exit-with-session)"
RC_FILE=${AWESOME_RC_FILE:-${source_dir}/config/rc.lua}
AWESOME_THEMES_PATH="${AWESOME_THEMES_PATH:-${this_dir}/../themes}"
AWESOME_ICON_PATH="${AWESOME_ICON_PATH:-${this_dir}/../icons}"
# TODO Make this work, currently untouched/untested
# Inject coverage runner via temporary RC file.
if [ -n "$DO_COVERAGE" ] && [ "$DO_COVERAGE" != 0 ]; then
# Handle old filename of config files (useful for git-bisect).
if [ -f "${RC_FILE}.in" ]; then
RC_FILE="${RC_FILE}.in"
fi
sed "1 s~^~require('luacov.runner')('$source_dir/.luacov'); \0~" \
"$RC_FILE" > "$tmp_files/awesomerc.lua"
RC_FILE=$tmp_files/awesomerc.lua
fi
# Start awesome.
start_awesome() {
cd "$build_dir"
# Kill awesome after $TEST_TIMEOUT seconds (e.g. for errors during test setup).
# SOURCE_DIRECTORY is used by .luacov.
WAYLAND_DISPLAY="$WD" DISPLAY="$D" SOURCE_DIRECTORY="$source_dir" \
AWESOME_THEMES_PATH="$AWESOME_THEMES_PATH" \
AWESOME_ICON_PATH="$AWESOME_ICON_PATH" \
timeout "$TEST_TIMEOUT" "$AWESOME" -c "$RC_FILE" "${awesome_options[@]}" > "$awesome_log" 2>&1 &
awesome_pid=$!
cd - >/dev/null
# Wait until the interface for awesome-client is ready (D-Bus interface).
# Do this with dbus-send so that we can specify a low --reply-timeout
wait_until_success "wait for awesome startup via awesome-client" "dbus-send --reply-timeout=100 --dest=org.awesomewm.awful --print-reply / org.awesomewm.awful.Remote.Eval 'string:return 1' 2>&1"
}
if command -v tput >/dev/null; then
color_red() { tput setaf 1; }
color_reset() { tput sgr0; }
else
color_red() { :; }
color_reset() { :; }
fi
count_tests=0
errors=()
# Seconds after when awesome gets killed.
TEST_TIMEOUT=${TEST_TIMEOUT:-30}
for f in $tests; do
echo "== Running $f =="
(( ++count_tests ))
start_awesome
if [ ! -r "$f" ]; then
if [ -r "${f#tests/}" ]; then
f=${f#tests/}
else
echo "===> ERROR $f is not readable! <==="
errors+=("$f is not readable.")
continue
fi
fi
# Make the filename absolute if it is not.
if [ "$f#/" = "$f" ]; then
f="$source_dir/$f"
fi
# Execute the test file in awesome.
DISPLAY=$D "$AWESOME_CLIENT" 2>&1 "dofile('$f')" || echo "Error: awesome-client failed" >> "$awesome_log"
# Tail the log and quit, when awesome quits.
# Use a single `grep`, otherwise `--line-buffered` would be required.
tail -n 100000 -s 0.1 -f --pid "$awesome_pid" "$awesome_log" \
| grep -vE '^(.{19} W: awesome: a_dbus_connect:[0-9]+: Could not connect to D-Bus system bus:|Test finished successfully\.$)' || true
set +e
wait $awesome_pid
code=$?
set -e
case $code in
0) ;;
124) echo "Awesome was killed due to timeout after $TEST_TIMEOUT seconds" ;;
*) echo "Awesome exited with status code $code" ;;
esac
# Parse any error from the log.
pattern='.*[Ee]rror.*|.*assertion failed.*|^Step .* failed:|^.{19} E: awesome: .*|.*luaA_panic.*'
if [[ $fail_on_warning ]]; then
pattern+='|^.{19} W: awesome:.*'
fi
error="$(grep --color -o --binary-files=text -E "$pattern" "$awesome_log" || true)"
# Filter out false positive errors:
error="$(echo "$error" | grep -vE ".{19} W: awesome: (Can't read color .* from GTK)" || true)"
if [[ $fail_on_warning ]]; then
# Filter out ignored warnings.
error="$(echo "$error" | grep -vE ".{19} W: awesome: (a_glib_poll|Cannot reliably detect EOF|beautiful: can't get colorscheme from xrdb|Can't read color .* from GTK+3 theme)" || true)"
fi
if [[ -n "$error" ]]; then
color_red
echo "===> ERROR running $f <==="
echo "$error"
color_reset
errors+=("$f: $error")
elif ! grep -q -E '^Test finished successfully\.$' "$awesome_log"; then
color_red
echo "===> ERROR running $f <==="
color_reset
errors+=("$f: test did not indicate success. See the output above.")
fi
done
echo "$count_tests tests finished."
if (( "${#errors[@]}" )); then
if [ "$TEST_PAUSE_ON_ERRORS" = 1 ]; then
echo "Pausing... press Enter to continue."
read -r
fi
color_red
echo "There were ${#errors[@]} errors:"
for error in "${errors[@]}"; do
echo " - $error"
done
color_reset
exit 1
fi
exit 0
# vim: filetype=sh:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80