2015-07-10 13:17:50 +02:00
|
|
|
#!/bin/sh
|
2015-10-03 14:54:17 +02:00
|
|
|
#
|
|
|
|
# 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.
|
2015-07-10 13:17:50 +02:00
|
|
|
|
|
|
|
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
|
2015-10-03 14:54:17 +02:00
|
|
|
TEST_PAUSE_ON_ERRORS=${TEST_PAUSE_ON_ERRORS-0}
|
2015-07-10 13:17:50 +02:00
|
|
|
TEST_QUIT_ON_TIMEOUT=1
|
|
|
|
fi
|
2015-10-03 14:54:17 +02:00
|
|
|
export TEST_PAUSE_ON_ERRORS # Used in tests/_runner.lua.
|
2015-07-10 13:17:50 +02:00
|
|
|
|
|
|
|
XEPHYR=Xephyr
|
|
|
|
XVFB=Xvfb
|
|
|
|
AWESOME=$root_dir/build/awesome
|
|
|
|
RC_FILE=$root_dir/build/awesomerc.lua
|
2015-08-05 17:36:21 +02:00
|
|
|
AWESOME_CLIENT="$root_dir/utils/awesome-client"
|
2015-07-10 13:17:50 +02:00
|
|
|
D=:5
|
|
|
|
SIZE=1024x768
|
|
|
|
|
|
|
|
if [ $HEADLESS = 1 ]; then
|
2015-08-13 12:59:57 +02:00
|
|
|
"$XVFB" $D -noreset -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
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2015-07-14 12:49:35 +02:00
|
|
|
cd - >/dev/null
|
2015-07-10 13:17:50 +02:00
|
|
|
|
2015-08-05 17:41:26 +02:00
|
|
|
# Cleanup on errors / aborting.
|
|
|
|
cleanup() {
|
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
|
2015-08-05 17:41:26 +02:00
|
|
|
rm -rf $tmp_files || true
|
2015-07-10 13:17:50 +02:00
|
|
|
}
|
2015-08-05 17:41:26 +02:00
|
|
|
trap "cleanup" 0 2 3 15
|
|
|
|
|
|
|
|
tmp_files=$(mktemp -d)
|
|
|
|
awesome_log=$tmp_files/_awesome_test.log
|
|
|
|
echo "awesome_log: $awesome_log"
|
2015-07-10 13:17:50 +02:00
|
|
|
|
2015-08-05 17:48:09 +02:00
|
|
|
wait_until_success() {
|
2015-08-05 17:57:50 +02:00
|
|
|
if [ "$CI" = true ]; then
|
|
|
|
set +x
|
|
|
|
fi
|
2015-08-05 17:48:09 +02:00
|
|
|
max_wait=60
|
|
|
|
while true; do
|
|
|
|
set +e
|
|
|
|
eval reply="\$($2)"
|
|
|
|
ret=$?
|
|
|
|
set -e
|
|
|
|
if [ $ret = 0 ]; then
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
max_wait=$(expr $max_wait - 1 || true)
|
|
|
|
if [ "$max_wait" -lt 0 ]; then
|
|
|
|
echo "Error: failed to $1!"
|
|
|
|
echo "Last reply: $reply."
|
|
|
|
if [ -f "$awesome_log" ]; then
|
|
|
|
echo "Log:"
|
|
|
|
cat "$awesome_log"
|
|
|
|
fi
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
sleep 0.05
|
|
|
|
done
|
2015-08-05 17:57:50 +02:00
|
|
|
if [ "$CI" = true ]; then
|
|
|
|
set -x
|
|
|
|
fi
|
2015-08-05 17:48:09 +02:00
|
|
|
}
|
|
|
|
|
2015-07-21 13:09:07 +02:00
|
|
|
# Wait for DISPLAY to be available, and setup xrdb,
|
|
|
|
# for awesome's xresources backend / queries.
|
2015-08-05 17:48:09 +02:00
|
|
|
wait_until_success "setup xrdb" "echo 'Xft.dpi: 96' | DISPLAY='$D' xrdb 2>&1"
|
2015-07-21 13:09:07 +02:00
|
|
|
|
2015-08-05 17:10:56 +02:00
|
|
|
# Use a separate D-Bus session; sets $DBUS_SESSION_BUS_PID.
|
|
|
|
eval $(DISPLAY="$D" dbus-launch --sh-syntax --exit-with-session)
|
|
|
|
|
2015-08-05 17:44:00 +02:00
|
|
|
# Not in Travis?
|
|
|
|
if [ "$CI" != true ]; then
|
|
|
|
# Prepare a config file pointing to a working theme
|
2015-10-03 14:54:17 +02:00
|
|
|
# Handle old filename of config files (useful for git-bisect).
|
|
|
|
if [ -f $root_dir/awesomerc.lua.in ]; then
|
|
|
|
SED_IN=.in
|
|
|
|
fi
|
2015-08-05 17:44:00 +02:00
|
|
|
RC_FILE=$tmp_files/awesomerc.lua
|
|
|
|
THEME_FILE=$tmp_files/theme.lua
|
2015-10-03 14:54:17 +02:00
|
|
|
sed -e "s:beautiful.init(\"@AWESOME_THEMES_PATH@/default/theme.lua\"):beautiful.init('$THEME_FILE'):" $root_dir/awesomerc.lua$SED_IN > $RC_FILE
|
2015-08-05 17:44:00 +02:00
|
|
|
sed -e "s:@AWESOME_THEMES_PATH@/default/titlebar:$root_dir/build/themes/default/titlebar:" \
|
|
|
|
-e "s:@AWESOME_THEMES_PATH@:$root_dir/themes/:" \
|
2015-10-03 14:54:17 +02:00
|
|
|
-e "s:@AWESOME_ICON_PATH@:$root_dir/icons:" $root_dir/themes/default/theme.lua$SED_IN > $THEME_FILE
|
2015-08-05 17:44:00 +02:00
|
|
|
fi
|
|
|
|
|
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
|
|
|
|
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).
|
2015-08-05 17:48:09 +02:00
|
|
|
wait_until_success "wait for awesome startup via awesome-client" "echo 'return 1' | DISPLAY=$D '$AWESOME_CLIENT' 2>&1"
|
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
|
|
|
|
2015-10-03 14:54:17 +02:00
|
|
|
start_awesome
|
|
|
|
|
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
|
|
|
# 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.
|
2015-08-05 17:58:10 +02:00
|
|
|
tail -n 100000 -f --pid $awesome_pid $awesome_log
|
2015-07-10 13:17:50 +02:00
|
|
|
|
|
|
|
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)
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2015-10-03 14:54:17 +02:00
|
|
|
if ! [ $errors = 0 ]; then
|
|
|
|
if [ "$TEST_PAUSE_ON_ERRORS" = 1 ]; then
|
|
|
|
echo "Pausing... press Enter to continue."
|
|
|
|
read enter
|
|
|
|
fi
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
exit 0
|