• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env bash
2# shellcheck disable=SC2086 # we want word splitting
3
4if [[ -z "$STRACEDIR" ]]; then
5    STRACEDIR=meson-logs/strace/$(for i in "$@"; do basename -z -- $i; echo -n _; done).$$
6fi
7
8mkdir -p $STRACEDIR
9
10# If the test times out, meson sends SIGTERM to this process.
11# Simply exec'ing "time" would result in no output from that in this case.
12# Instead, we need to run "time" in the background, catch the signals and
13# propagate them to the actual test process.
14
15/usr/bin/time -v strace -ff -tt -T -o $STRACEDIR/log "$@" &
16TIMEPID=$!
17STRACEPID=$(ps --ppid $TIMEPID -o pid=)
18TESTPID=$(ps --ppid $STRACEPID -o pid=)
19
20if test "x$TESTPID" != x; then
21    trap 'kill -TERM $TESTPID; wait $TIMEPID; exit $?' TERM
22fi
23
24wait $TIMEPID
25EXITCODE=$?
26
27# Only keep strace logs if the test timed out
28rm -rf $STRACEDIR &
29
30exit $EXITCODE
31