From 16fc6b87bb5aaeb65e5b6d263e600185b4d425a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michel=20D=C3=A4nzer?= Date: Thu, 4 Mar 2021 12:58:56 +0100 Subject: [PATCH] ci: Run meson tests in strace if it's available and can be used Keep the strace logs in job artifacts for tests which timed out. This can be useful for figuring out why a timeout occurred. strace cannot be used in jobs where ASAN is enabled, because ASAN's leak checker also uses ptrace(), which isn't possible within strace. Suggested-by: Daniel Stone Reviewed-by: Adam Jackson Part-of: --- .gitlab-ci.yml | 2 ++ .gitlab-ci/meson/build.sh | 16 ++++++++--- .gitlab-ci/meson/time-strace.sh | 27 +++++++++++++++++++ .gitlab-ci/meson/{test-wrapper.sh => time.sh} | 0 4 files changed, 42 insertions(+), 3 deletions(-) create mode 100755 .gitlab-ci/meson/time-strace.sh rename .gitlab-ci/meson/{test-wrapper.sh => time.sh} (100%) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 45f91b3d601..ad72c6c7fb7 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -197,6 +197,7 @@ success: # https://gitlab.com/gitlab-org/gitlab-ce/commit/8788fb925706cad594adf6917a6c5f6587dd1521 - artifacts - _build/meson-logs/*.txt + - _build/meson-logs/strace # Docker image tag helper templates @@ -586,6 +587,7 @@ sanity: when: always paths: - _build/meson-logs/*.txt + - _build/meson-logs/strace # scons: - build/*/config.log - shader-db diff --git a/.gitlab-ci/meson/build.sh b/.gitlab-ci/meson/build.sh index bca9e4fea4c..e47dc48be49 100755 --- a/.gitlab-ci/meson/build.sh +++ b/.gitlab-ci/meson/build.sh @@ -41,9 +41,19 @@ if [ -n "$CROSS" ]; then fi # Only use GNU time if available, not any shell built-in command -if test -f /usr/bin/time; then - MESON_TEST_ARGS+=--wrapper=$PWD/.gitlab-ci/meson/test-wrapper.sh -fi +case $CI_JOB_NAME in + # ASAN leak detection is incompatible with strace + *-asan*) + if test -f /usr/bin/time; then + MESON_TEST_ARGS+=--wrapper=$PWD/.gitlab-ci/meson/time.sh + fi + ;; + *) + if test -f /usr/bin/time -a -f /usr/bin/strace; then + MESON_TEST_ARGS+=--wrapper=$PWD/.gitlab-ci/meson/time-strace.sh + fi + ;; +esac rm -rf _build meson _build --native-file=native.file \ diff --git a/.gitlab-ci/meson/time-strace.sh b/.gitlab-ci/meson/time-strace.sh new file mode 100755 index 00000000000..d579529f2a6 --- /dev/null +++ b/.gitlab-ci/meson/time-strace.sh @@ -0,0 +1,27 @@ +#!/bin/sh + +STRACEDIR=meson-logs/strace/$(for i in $@; do basename -z -- $i; echo -n _; done) + +mkdir -p $STRACEDIR + +# If the test times out, meson sends SIGTERM 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 strace -ff -tt -T -o $STRACEDIR/log "$@" & +TIMEPID=$! +STRACEPID=$(ps --ppid $TIMEPID -o pid=) +TESTPID=$(ps --ppid $STRACEPID -o pid=) + +if test "x$TESTPID" != x; then + trap 'kill -TERM $TESTPID; wait $TIMEPID; exit $?' TERM +fi + +wait $TIMEPID +EXITCODE=$? + +# Only keep strace logs if the test timed out +rm -rf $STRACEDIR & + +exit $EXITCODE diff --git a/.gitlab-ci/meson/test-wrapper.sh b/.gitlab-ci/meson/time.sh similarity index 100% rename from .gitlab-ci/meson/test-wrapper.sh rename to .gitlab-ci/meson/time.sh