Improve tests/run.sh
- `set -x` only for Travis/CI=true. - improve waiting for PID and awesome-client success. - kill childs via trap always. Closes https://github.com/awesomeWM/awesome/pull/316.
This commit is contained in:
parent
d5cf6e0272
commit
1e9da0947e
62
tests/run.sh
62
tests/run.sh
|
@ -1,7 +1,11 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
|
# Be verbose on Travis.
|
||||||
|
if [ "$CI" = true ]; then
|
||||||
set -x
|
set -x
|
||||||
|
fi
|
||||||
|
|
||||||
# Change to file's dir (POSIXly).
|
# Change to file's dir (POSIXly).
|
||||||
cd -P -- "$(dirname -- "$0")"
|
cd -P -- "$(dirname -- "$0")"
|
||||||
|
@ -69,7 +73,7 @@ export XDG_CONFIG_HOME
|
||||||
awesome_log=/tmp/_awesome_test.log
|
awesome_log=/tmp/_awesome_test.log
|
||||||
echo "awesome_log: $awesome_log"
|
echo "awesome_log: $awesome_log"
|
||||||
|
|
||||||
cd -
|
cd - >/dev/null
|
||||||
|
|
||||||
|
|
||||||
kill_childs() {
|
kill_childs() {
|
||||||
|
@ -79,25 +83,61 @@ kill_childs() {
|
||||||
}
|
}
|
||||||
# Cleanup on errors / aborting.
|
# Cleanup on errors / aborting.
|
||||||
set_trap() {
|
set_trap() {
|
||||||
trap "kill_childs" 2 3 15
|
trap "kill_childs" 0 2 3 15
|
||||||
}
|
}
|
||||||
set_trap
|
set_trap
|
||||||
|
|
||||||
|
AWESOME_CLIENT="$root_dir/utils/awesome-client"
|
||||||
|
|
||||||
# Start awesome.
|
# Start awesome.
|
||||||
start_awesome() {
|
start_awesome() {
|
||||||
(cd $root_dir/build; \
|
(
|
||||||
DISPLAY=$D "$AWESOME" -c "$RC_FILE" $AWESOME_OPTIONS > $awesome_log 2>&1 || true &)
|
export DISPLAY="$D"
|
||||||
sleep 1
|
cd $root_dir/build
|
||||||
awesome_pid=$(pgrep -nf "awesome -c $RC_FILE" || true)
|
# Setup xrdb, for awesome's xresources backend / queries.
|
||||||
|
echo "Xft.dpi: 96" | xrdb
|
||||||
|
"$AWESOME" -c "$RC_FILE" $AWESOME_OPTIONS > $awesome_log 2>&1 &
|
||||||
|
)
|
||||||
|
|
||||||
if [ -z $awesome_pid ]; then
|
# Get PID of awesome.
|
||||||
|
awesome_pid=
|
||||||
|
max_wait=30
|
||||||
|
while true; do
|
||||||
|
awesome_pid="$(pgrep -nf "awesome -c $RC_FILE")"
|
||||||
|
if [ -n "$awesome_pid" ]; then
|
||||||
|
break;
|
||||||
|
fi
|
||||||
|
max_wait=$(expr $max_wait - 1)
|
||||||
|
if [ "$max_wait" -lt 0 ]; then
|
||||||
echo "Error: Failed to start awesome (-c $RC_FILE)!"
|
echo "Error: Failed to start awesome (-c $RC_FILE)!"
|
||||||
echo "Log:"
|
echo "Log:"
|
||||||
cat "$awesome_log"
|
cat "$awesome_log"
|
||||||
kill_childs
|
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
set_trap
|
sleep 0.1
|
||||||
|
done
|
||||||
|
|
||||||
|
# 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
|
||||||
}
|
}
|
||||||
|
|
||||||
# Count errors.
|
# Count errors.
|
||||||
|
@ -108,7 +148,7 @@ for f in $tests; do
|
||||||
start_awesome
|
start_awesome
|
||||||
|
|
||||||
# Send the test file to awesome.
|
# Send the test file to awesome.
|
||||||
cat $f | DISPLAY=$D $root_dir/utils/awesome-client 2>&1
|
cat $f | DISPLAY=$D "$AWESOME_CLIENT" 2>&1
|
||||||
|
|
||||||
# Tail the log and quit, when awesome quits.
|
# Tail the log and quit, when awesome quits.
|
||||||
tail -f --pid $awesome_pid $awesome_log
|
tail -f --pid $awesome_pid $awesome_log
|
||||||
|
@ -125,6 +165,4 @@ for f in $tests; do
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
kill_childs
|
|
||||||
|
|
||||||
[ $errors = 0 ] && exit 0 || exit 1
|
[ $errors = 0 ] && exit 0 || exit 1
|
||||||
|
|
Loading…
Reference in New Issue