X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=tests%2Futils%2Ftap-driver.sh;h=56d4d3e45487d8eb2c15800f92a355b43b332340;hb=HEAD;hp=65037ab65f5dfb03d729704d0132217b66091053;hpb=202486fa276e34e4c81d560bfd8897824c51af8c;p=lttng-tools.git diff --git a/tests/utils/tap-driver.sh b/tests/utils/tap-driver.sh index 65037ab65..e2d9ad9c6 100755 --- a/tests/utils/tap-driver.sh +++ b/tests/utils/tap-driver.sh @@ -49,6 +49,7 @@ print_usage () cat <&3 fi - "$@" - echo $? + # Since stderr and stdout may go to the same file and the script + # may run in situations with different types of buffering, enforce + # line buffering for both FDs. This helps to prevent interleave between + # 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 + 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" \ @@ -154,6 +183,7 @@ fi -v ignore_exit="$ignore_exit" \ -v comments="$comments" \ -v diag_string="$diag_string" \ + -v time_script="${TIME_SCRIPT}" \ ' # TODO: the usages of "cat >&3" below could be optimized when using # GNU awk, and/on on systems that supports /dev/fd/. @@ -211,6 +241,16 @@ function copy_in_global_log() return 0 } +function gettime_ns( r) +{ + r = "" + if (time_script | getline r) { + r = r + } + close(time_script) + return sprintf("%f", r) +} + function get_global_test_result() { if ("ERROR" in test_results_seen) @@ -482,6 +522,7 @@ function write_test_results() print ":global-test-result: " get_global_test_result() > trs_file print ":recheck: " yn(must_recheck()) > trs_file print ":copy-in-global-log: " yn(copy_in_global_log()) > trs_file + print ":time-taken: " sprintf("%f", gettime_ns() - TIME_START) > trs_file for (i = 0; i < test_results_index; i += 1) print ":test-result: " test_results_list[i] > trs_file close(trs_file); @@ -515,6 +556,7 @@ bailed_out = 0 # Whether a "Bail out!" directive has been seen. # it is ("early" is seen before any test result, "late" otherwise). plan_seen = NO_PLAN +TIME_START = gettime_ns(); ## --------- ## ## PARSING ## ## --------- ##