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
|
|
|
|
2016-07-17 22:08:01 +02:00
|
|
|
# Change to file's dir (POSIXly).
|
|
|
|
cd -P -- "$(dirname -- "$0")"
|
|
|
|
this_dir=$PWD
|
|
|
|
source_dir="$PWD/.."
|
|
|
|
|
2016-06-12 23:28:32 +02:00
|
|
|
# Either the build dir is passed in $CMAKE_BINARY_DIR or we guess based on $PWD
|
2016-05-08 18:34:39 +02:00
|
|
|
build_dir="$CMAKE_BINARY_DIR"
|
|
|
|
if [ -z "$build_dir" ]; then
|
2016-07-17 22:08:01 +02:00
|
|
|
if [ -d "$source_dir/build" ]; then
|
|
|
|
build_dir="$source_dir/build"
|
2016-06-12 23:28:32 +02:00
|
|
|
else
|
2016-07-17 22:08:01 +02:00
|
|
|
build_dir="$source_dir"
|
2016-06-12 23:28:32 +02:00
|
|
|
fi
|
2016-05-08 18:34:39 +02:00
|
|
|
fi
|
|
|
|
|
2015-07-10 13:17:50 +02:00
|
|
|
# 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
|
|
|
|
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
|
2016-05-08 18:34:39 +02:00
|
|
|
AWESOME=$build_dir/awesome
|
2016-05-03 12:08:00 +02:00
|
|
|
if ! [ -x "$AWESOME" ]; then
|
|
|
|
echo "$AWESOME is not executable." >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
2016-05-08 18:34:39 +02:00
|
|
|
RC_FILE=$build_dir/awesomerc.lua
|
|
|
|
AWESOME_CLIENT="$source_dir/utils/awesome-client"
|
2015-07-10 13:17:50 +02:00
|
|
|
D=:5
|
2016-05-08 20:58:19 +02:00
|
|
|
SIZE="${TESTS_SCREEN_SIZE:-1024x768}"
|
2015-07-10 13:17:50 +02:00
|
|
|
|
2016-05-08 16:46:57 +02:00
|
|
|
# Set up some env vars
|
|
|
|
# Disable GDK's screen scaling support
|
|
|
|
export GDK_SCALE=1
|
|
|
|
# No idea what this does, but it silences a warning that GTK init might print
|
|
|
|
export NO_AT_BRIDGE=1
|
|
|
|
|
2015-07-10 13:17:50 +02:00
|
|
|
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
|
|
|
|
|
2016-05-08 18:34:39 +02:00
|
|
|
cd $build_dir
|
2015-07-10 13:17:50 +02:00
|
|
|
|
2016-09-20 19:53:10 +02:00
|
|
|
AWESOME_OPTIONS="$AWESOME_OPTIONS --search lib"
|
2015-07-10 13:17:50 +02:00
|
|
|
# Add test dir (for _runner.lua).
|
2016-07-24 15:03:05 +02:00
|
|
|
AWESOME_OPTIONS="$AWESOME_OPTIONS --search $this_dir"
|
2016-09-20 19:53:10 +02:00
|
|
|
export XDG_CONFIG_HOME="./"
|
2015-07-10 13:17:50 +02:00
|
|
|
|
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
|
2016-05-31 23:48:50 +02:00
|
|
|
wait_count=60 # 60*0.05s => 3s.
|
2015-08-05 17:48:09 +02:00
|
|
|
while true; do
|
|
|
|
set +e
|
|
|
|
eval reply="\$($2)"
|
|
|
|
ret=$?
|
|
|
|
set -e
|
|
|
|
if [ $ret = 0 ]; then
|
|
|
|
break
|
|
|
|
fi
|
2016-05-31 23:48:50 +02:00
|
|
|
wait_count=$(expr $wait_count - 1 || true)
|
|
|
|
if [ "$wait_count" -lt 0 ]; then
|
2015-08-05 17:48:09 +02:00
|
|
|
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.
|
2016-03-04 01:41:43 +01:00
|
|
|
wait_until_success "setup xrdb" "printf 'Xft.dpi: 96
|
|
|
|
*.background: #002b36
|
|
|
|
*.foreground: #93a1a1
|
|
|
|
*.color0: #002b36
|
|
|
|
*.color1: #dc322f
|
|
|
|
*.color10: #859900
|
|
|
|
*.color11: #b58900
|
|
|
|
*.color12: #268bd2
|
|
|
|
*.color13: #6c71c4
|
|
|
|
*.color14: #2aa198
|
|
|
|
*.color15: #fdf6e3
|
|
|
|
*.color16: #cb4b16
|
|
|
|
*.color17: #d33682
|
|
|
|
*.color18: #073642
|
|
|
|
*.color19: #586e75
|
|
|
|
*.color2: #859900
|
|
|
|
*.color20: #839496
|
|
|
|
*.color21: #eee8d5
|
|
|
|
*.color3: #b58900
|
|
|
|
*.color4: #268bd2
|
|
|
|
*.color5: #6c71c4
|
|
|
|
*.color6: #2aa198
|
|
|
|
*.color7: #93a1a1
|
|
|
|
*.color8: #657b83
|
|
|
|
*.color9: #dc322f' | 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).
|
2016-05-08 18:34:39 +02:00
|
|
|
if [ -f $source_dir/awesomerc.lua.in ]; then
|
2015-10-03 14:54:17 +02:00
|
|
|
SED_IN=.in
|
|
|
|
fi
|
2015-08-05 17:44:00 +02:00
|
|
|
RC_FILE=$tmp_files/awesomerc.lua
|
|
|
|
THEME_FILE=$tmp_files/theme.lua
|
2016-05-08 18:34:39 +02:00
|
|
|
sed -e "s:.*beautiful.init(.*default/theme.lua.*:beautiful.init('$THEME_FILE'):" $source_dir/awesomerc.lua$SED_IN > $RC_FILE
|
|
|
|
sed -e "s:@AWESOME_THEMES_PATH@/default/titlebar:$build_dir/themes/default/titlebar:" \
|
|
|
|
-e "s:@AWESOME_THEMES_PATH@:$source_dir/themes/:" \
|
|
|
|
-e "s:@AWESOME_ICON_PATH@:$source_dir/icons:" $source_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"
|
2016-05-08 18:34:39 +02:00
|
|
|
cd $build_dir
|
2015-07-18 10:44:16 +02:00
|
|
|
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).
|
2016-08-30 18:00:35 +02:00
|
|
|
wait_until_success "wait for awesome startup via awesome-client" "DISPLAY=$D '$AWESOME_CLIENT' 'return 1' 2>&1"
|
2015-07-10 13:17:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Count errors.
|
|
|
|
errors=0
|
2016-05-31 23:46:23 +02:00
|
|
|
# Seconds after when awesome gets killed.
|
2016-09-07 06:40:30 +02:00
|
|
|
timeout_stale=120 # FIXME This should be no more than 60s
|
2015-07-10 13:17:50 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
2016-05-31 23:46:23 +02:00
|
|
|
# Kill awesome after 1 minute (e.g. with errors during test setup).
|
|
|
|
(sleep $timeout_stale
|
|
|
|
if [ "$(ps -o comm= $awesome_pid)" = "${AWESOME##*/}" ]; then
|
|
|
|
echo "Killing (stale?!) awesome (PID $awesome_pid) after $timeout_stale seconds."
|
|
|
|
kill $awesome_pid
|
|
|
|
fi) &
|
|
|
|
|
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
|
|
|
|
2016-02-12 18:12:21 +01:00
|
|
|
if ! grep -q -E '^Test finished successfully$' $awesome_log ||
|
|
|
|
grep -q -E '[Ee]rror|assertion failed' $awesome_log; then
|
2015-07-10 13:17:50 +02:00
|
|
|
echo "===> ERROR running $f! <==="
|
2016-02-12 18:12:21 +01:00
|
|
|
grep --color -o --binary-files=text -E '.*[Ee]rror.*|.*assertion failed.*' $awesome_log
|
2015-07-10 13:17:50 +02:00
|
|
|
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
|
2016-04-06 01:54:18 +02:00
|
|
|
echo "There were $errors errors!"
|
2015-10-03 14:54:17 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
exit 0
|
2015-12-12 17:34:16 +01:00
|
|
|
|
|
|
|
# vim: filetype=sh:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|