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]
# 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
--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;;
init_colors=''
fi
+TIME_SCRIPT="$(realpath -e -- "$(dirname "$0")")/tap/clock"
+
# :; is there to work around a bug in bash 3.2 (and earlier) which
# does not always set '$?' properly on redirection failure.
# See the Autoconf manual for more details.
else
exec 2>&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" \
-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/.
return 0
}
-function gettime_ns( r, cmd)
+function gettime_ns( r)
{
- cmd = "date +%s.%N"
r = ""
- if (cmd | getline r) {
+ if (time_script | getline r) {
r = r
}
- close(cmd)
+ close(time_script)
return sprintf("%f", r)
}