2015-07-10 13:17:50 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
set -e
|
2015-07-14 12:49:35 +02:00
|
|
|
|
|
|
|
# Be verbose on Travis.
|
|
|
|
if [ "$CI" = true ]; then
|
|
|
|
set -x
|
|
|
|
fi
|
2015-07-10 13:17:50 +02:00
|
|
|
|
|
|
|
# Change to file's dir (POSIXly).
|
|
|
|
cd -P -- "$(dirname -- "$0")"
|
|
|
|
this_dir=$PWD
|
|
|
|
|
|
|
|
# Get test files: test*, or the ones provided as args (relative to tests/).
|
|
|
|
if [ $# != 0 ]; then
|
|
|
|
tests="$@"
|
|
|
|
else
|
|
|
|
tests=$this_dir/test*.lua
|
|
|
|
fi
|
|
|
|
|
|
|
|
root_dir=$PWD/..
|
|
|
|
|
|
|
|
# Travis.
|
|
|
|
if [ "$CI" = true ]; then
|
|
|
|
HEADLESS=1
|
|
|
|
TEST_PAUSE_ON_ERRORS=0
|
|
|
|
TEST_QUIT_ON_TIMEOUT=1
|
|
|
|
else
|
|
|
|
HEADLESS=0
|
|
|
|
TEST_PAUSE_ON_ERRORS=0
|
|
|
|
TEST_QUIT_ON_TIMEOUT=1
|
|
|
|
fi
|
|
|
|
export TEST_PAUSE_ON_ERRORS
|
|
|
|
|
|
|
|
XEPHYR=Xephyr
|
|
|
|
XVFB=Xvfb
|
|
|
|
AWESOME=$root_dir/build/awesome
|
|
|
|
RC_FILE=$root_dir/build/awesomerc.lua
|
|
|
|
D=:5
|
|
|
|
SIZE=1024x768
|
|
|
|
|
|
|
|
if [ $HEADLESS = 1 ]; then
|
|
|
|
"$XVFB" $D -screen 0 ${SIZE}x24 &
|
2015-07-18 10:44:16 +02:00
|
|
|
xserver_pid=$!
|
2015-07-10 13:17:50 +02:00
|
|
|
else
|
|
|
|
# export XEPHYR_PAUSE=1000
|
|
|
|
"$XEPHYR" $D -ac -name xephyr_$D -noreset -screen "$SIZE" $XEPHYR_OPTIONS &
|
2015-07-18 10:44:16 +02:00
|
|
|
xserver_pid=$!
|
2015-07-18 15:03:43 +02:00
|
|
|
# Toggles debugging mode, using XEPHYR_PAUSE.
|
|
|
|
# ( sleep 1; kill -USR1 $xserver_pid ) &
|
2015-07-10 13:17:50 +02:00
|
|
|
fi
|
|
|
|
|
2015-07-18 10:45:03 +02:00
|
|
|
# Use a separate D-Bus session; sets $DBUS_SESSION_BUS_PID.
|
|
|
|
eval $(DISPLAY="$D" dbus-launch --sh-syntax --exit-with-session)
|
2015-07-10 13:17:50 +02:00
|
|
|
|
|
|
|
cd $root_dir/build
|
|
|
|
|
|
|
|
LUA_PATH="$(lua -e 'print(package.path)');lib/?.lua;lib/?/init.lua"
|
|
|
|
# Add test dir (for _runner.lua).
|
|
|
|
LUA_PATH="$LUA_PATH;$this_dir/?.lua"
|
|
|
|
XDG_CONFIG_HOME="./"
|
|
|
|
export LUA_PATH
|
|
|
|
export XDG_CONFIG_HOME
|
|
|
|
|
|
|
|
awesome_log=/tmp/_awesome_test.log
|
|
|
|
echo "awesome_log: $awesome_log"
|
|
|
|
|
2015-07-14 12:49:35 +02:00
|
|
|
cd - >/dev/null
|
2015-07-10 13:17:50 +02:00
|
|
|
|
|
|
|
|
|
|
|
kill_childs() {
|
2015-07-18 10:45:03 +02:00
|
|
|
for p in $awesome_pid $xserver_pid; do
|
2015-07-10 13:17:50 +02:00
|
|
|
kill -TERM $p 2>/dev/null || true
|
|
|
|
done
|
|
|
|
}
|
|
|
|
# Cleanup on errors / aborting.
|
|
|
|
set_trap() {
|
2015-07-14 12:49:35 +02:00
|
|
|
trap "kill_childs" 0 2 3 15
|
2015-07-10 13:17:50 +02:00
|
|
|
}
|
|
|
|
set_trap
|
|
|
|
|
2015-07-14 12:49:35 +02:00
|
|
|
AWESOME_CLIENT="$root_dir/utils/awesome-client"
|
|
|
|
|
2015-07-10 13:17:50 +02:00
|
|
|
# Start awesome.
|
|
|
|
start_awesome() {
|
2015-07-18 10:44:16 +02:00
|
|
|
export DISPLAY="$D"
|
|
|
|
cd $root_dir/build
|
|
|
|
# Setup xrdb, for awesome's xresources backend / queries.
|
|
|
|
echo "Xft.dpi: 96" | DISPLAY="$D" xrdb
|
|
|
|
DISPLAY="$D" "$AWESOME" -c "$RC_FILE" $AWESOME_OPTIONS > $awesome_log 2>&1 &
|
|
|
|
awesome_pid=$!
|
|
|
|
cd - >/dev/null
|
2015-07-14 12:49:35 +02:00
|
|
|
|
|
|
|
# Wait until the interface for awesome-client is ready (D-Bus interface).
|
|
|
|
client_reply=
|
|
|
|
max_wait=50
|
|
|
|
while true; do
|
|
|
|
set +e
|
|
|
|
client_reply=$(echo 'return 1' | DISPLAY=$D "$AWESOME_CLIENT" 2>&1)
|
|
|
|
ret=$?
|
|
|
|
set -e
|
|
|
|
if [ $ret = 0 ]; then
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
max_wait=$(expr $max_wait - 1)
|
|
|
|
if [ "$max_wait" -lt 0 ]; then
|
|
|
|
echo "Error: did not receive a successful reply via awesome-client!"
|
|
|
|
echo "Last reply: $client_reply."
|
|
|
|
echo "Log:"
|
|
|
|
cat "$awesome_log"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
sleep 0.1
|
|
|
|
done
|
2015-07-10 13:17:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Count errors.
|
|
|
|
errors=0
|
|
|
|
|
|
|
|
for f in $tests; do
|
|
|
|
echo "== Running $f =="
|
2015-07-18 12:33:24 +02:00
|
|
|
|
|
|
|
if [ ! -r $f ]; then
|
|
|
|
echo "===> ERROR $f is not readable! <==="
|
|
|
|
errors=$(expr $errors + 1)
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
2015-07-10 13:17:50 +02:00
|
|
|
start_awesome
|
|
|
|
|
|
|
|
# Send the test file to awesome.
|
2015-07-14 12:49:35 +02:00
|
|
|
cat $f | DISPLAY=$D "$AWESOME_CLIENT" 2>&1
|
2015-07-10 13:17:50 +02:00
|
|
|
|
|
|
|
# Tail the log and quit, when awesome quits.
|
|
|
|
tail -f --pid $awesome_pid $awesome_log
|
|
|
|
|
|
|
|
if grep -q -E '^Error|assertion failed' $awesome_log; then
|
|
|
|
echo "===> ERROR running $f! <==="
|
|
|
|
grep --color -o --binary-files=text -E '^Error.*|.*assertion failed.*' $awesome_log
|
|
|
|
errors=$(expr $errors + 1)
|
|
|
|
|
|
|
|
if [ "$TEST_PAUSE_ON_ERRORS" = 1 ]; then
|
|
|
|
echo "Pausing... press Enter to continue."
|
|
|
|
read enter
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
[ $errors = 0 ] && exit 0 || exit 1
|