Tests: Add and set new log-file-d for the tap driver
authorKienan Stewart <kstewart@efficios.com>
Mon, 12 Aug 2024 19:59:15 +0000 (15:59 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 6 Sep 2024 15:31:39 +0000 (15:31 +0000)
This adds a new option `--log-file-d` to the tap-driver, which will
create a `*.log.d` folder for each test when running `make check` and
the `LTTNG_TEST_LOG_DIR` accordingly.

Doing so allows the tests to be run in verbose and create logs in a
predictable location. These log folders are removed when running `make
clean`.

Change-Id: Ibcf7e2cb54098a3e9ccd828ca76df6efcf33431d
Signed-off-by: Kienan Stewart <kstewart@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
tests/regression/Makefile.am
tests/utils/tap-driver.sh

index 5a8eebd9b8434953ceac5ddb2c680e0dcc74e061..6537a33dd7b0651a420ece7a548d5463189ab85c 100644 (file)
@@ -148,3 +148,8 @@ endif
 if PRECIOUS_TESTS
 .PRECIOUS: $(TEST_LOGS)
 endif
+
+mostlyclean-local:
+       @for f in $(TESTS); do \
+               rm -rf "$$f.log.d/"; \
+       done
index 56d4d3e45487d8eb2c15800f92a355b43b332340..e2d9ad9c64893aec3a075a74f2562dde1fb1f1f7 100755 (executable)
@@ -49,6 +49,7 @@ print_usage ()
   cat <<END
 Usage:
   tap-driver.sh --test-name=NAME --log-file=PATH --trs-file=PATH
+                [--log-file-d={yes|no}]
                 [--expect-failure={yes|no}] [--color-tests={yes|no}]
                 [--enable-hard-errors={yes|no}] [--ignore-exit]
                 [--diagnostic-string=STRING] [--merge|--no-merge]
@@ -61,6 +62,7 @@ END
 # TODO: $log_file, $trs_file and $test_name are defined).
 test_name= # Used for reporting.
 log_file=  # Where to save the result and output of the test script.
+log_file_d=yes  # If a directory "${log_file}.d" should be created and used for LTTng logs
 trs_file=  # Where to save the metadata of the test run.
 post_script= # Script to be run after the test.
 expect_failure=0
@@ -75,6 +77,7 @@ while test $# -gt 0; do
   --version) echo "$me $scriptversion"; exit $?;;
   --test-name) test_name=$2; shift;;
   --log-file) log_file=$2; shift;;
+  --log-file-d) log_file_d=$2; shift;;
   --trs-file) trs_file=$2; shift;;
   --color-tests) color_tests=$2; shift;;
   --expect-failure) expect_failure=$2; shift;;
@@ -150,12 +153,26 @@ TIME_SCRIPT="$(realpath -e -- "$(dirname "$0")")/tap/clock"
     # the outputs in the resulting file for half written lines, eg.
     #   ok 93 - Tes# PERROR - xxxx
     #   t some function
+    ORIG_LTTNG_TEST_LOG_DIR="${LTTNG_TEST_LOG_DIR:-}"
+    LTTNG_TEST_LOG_DIR=""
+    if test "${log_file_d}" = yes && [ ! -e "${log_file}.d" ]; then
+      mkdir -p "${log_file}.d"
+      LTTNG_TEST_LOG_DIR="$(realpath "${log_file}.d")"
+      export LTTNG_TEST_LOG_DIR
+    fi
     if [ "${LTTNG_TESTS_TAP_AUTOTIME:-}" != 0 ]; then
       stdbuf -eL -oL -- "$@"
     else
       "$@"
     fi
-    echo $?
+    ret=$?
+    if [ "${ret}" = "0" ] && test "${log_file_d}" = yes && [ -d "${LTTNG_TEST_LOG_DIR}" ]; then
+      rm -rf "${LTTNG_TEST_LOG_DIR:?}/"
+    fi
+    if [ -n "${ORIG_LTTNG_TEST_LOG_DIR}" ]; then
+      LTTNG_TEST_LOG_DIR="${ORIG_LTTNG_TEST_LOG_DIR}"
+    fi
+    echo $ret
   ) | LC_ALL=C ${AM_TAP_AWK-awk} \
         -v me="$me" \
         -v test_script_name="$test_name" \
This page took 0.02699 seconds and 4 git commands to generate.