ci: Run 'time' in the background and propagate signals to test process

Simply exec'ing time didn't produce any output from it when a test
timed out.

Fixes: 35f59e14f8 "ci: Use GNU time as meson test wrapper"
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8830>
This commit is contained in:
Michel Dänzer 2021-02-02 11:38:19 +01:00 committed by Marge Bot
parent 09e421846d
commit 14bafbba9b
3 changed files with 21 additions and 4 deletions

View File

@ -277,7 +277,7 @@ x86_build:
extends:
- .use-x86_build-base
variables:
MESA_IMAGE_TAG: &x86_build "2021-01-29-time"
MESA_IMAGE_TAG: &x86_build "2021-02-02-procps"
.use-x86_build:
variables:

View File

@ -32,6 +32,7 @@ apt-get install -y --no-remove \
liblua5.3-dev \
libxml2-dev \
ocl-icd-opencl-dev \
procps \
time \
wine-development \
wine32-development

View File

@ -1,8 +1,24 @@
#!/bin/sh
# Only use GNU time if available, not any shell built-in command
if test -f /usr/bin/time; then
exec /usr/bin/time -v "$@"
if ! test -f /usr/bin/time; then
exec "$@"
fi
exec "$@"
# If the test times out, meson sends SIGINT & SIGTERM signals to this process.
# Simply exec'ing "time" would result in no output from that in this case.
# Instead, we need to run "time" in the background, catch the signals and
# propagate them to the actual test process.
/usr/bin/time -v "$@" &
TIMEPID=$!
TESTPID=$(ps --ppid $TIMEPID -o pid=)
if test "x$TESTPID" != x; then
trap 'kill -INT $TESTPID; wait $TIMEPID; exit $?' INT
trap 'kill -TERM $TESTPID; wait $TIMEPID; exit $?' TERM
fi
wait $TIMEPID
exit $?