X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=tests%2Futils%2Ftap%2Ftap.sh;h=eae7c3a2c2610784d2f45f479883c35329c68223;hb=HEAD;hp=109cc8e4ce5bc4ebba3af6f8f9c669b2c26f8365;hpb=9d16b343fb9e781fc8d8fa3c448a3f382306dd33;p=lttng-tools.git diff --git a/tests/utils/tap/tap.sh b/tests/utils/tap/tap.sh index 109cc8e4c..eae7c3a2c 100755 --- a/tests/utils/tap/tap.sh +++ b/tests/utils/tap/tap.sh @@ -14,8 +14,10 @@ _test_died=0 _expected_tests=0 _executed_tests=0 _failed_tests=0 +_auto_timing="${LTTNG_TESTS_TAP_AUTOTIME:-1}" +_last_time='' TODO= - +TIME_SCRIPT="$(realpath -e -- "$(dirname "${BASH_SOURCE[0]}")")/clock" usage(){ cat <<'USAGE' @@ -52,6 +54,7 @@ TODO: OTHER: diag MSG + autotime 0|1 EXAMPLE: #!/bin/bash @@ -105,6 +108,7 @@ plan_no_plan(){ _plan_set=1 _no_plan=1 + _last_time=$("${TIME_SCRIPT}") return 0 } @@ -119,6 +123,7 @@ plan_skip_all(){ _skip_all=1 _plan_set=1 + _last_time=$("${TIME_SCRIPT}") _exit 0 return 0 @@ -133,6 +138,7 @@ plan_tests(){ _print_plan $tests _expected_tests=$tests _plan_set=1 + _last_time=$("${TIME_SCRIPT}") return $tests } @@ -195,6 +201,7 @@ ok(){ fi echo + _autotime if (( result != 0 )) ; then local file='tap-functions' local func= @@ -233,6 +240,7 @@ okx(){ diag "$line" done ok ${PIPESTATUS[0]} "$command" + _autotime } @@ -342,6 +350,7 @@ skip(){ for (( i=0 ; i<$n ; i++ )) ; do _executed_tests=$(( _executed_tests + 1 )) echo "ok $_executed_tests # skip: $reason" + _autotime done return 0 else @@ -349,6 +358,32 @@ skip(){ fi } +_autotime(){ + local new_time + local duration + + if [ "${_auto_timing}" -eq "1" ] ; then + new_time=$("${TIME_SCRIPT}") + duration=$(awk "BEGIN { printf(\"%f\n\", ($new_time - $_last_time)*1000) }") + echo " ---" + echo " duration_ms: ${duration}" + echo " ..." + fi + _last_time=$("${TIME_SCRIPT}") + return 0 +} + + +autotime(){ + local val=${1:?} + + if [[ "${val}" != "0" ]] ; then + _auto_timing=1 + else + _auto_timing=0; + fi + return 0 +} diag(){ local msg=${1:?} @@ -381,6 +416,11 @@ BAIL_OUT(){ _cleanup(){ local rc=0 + if (( _plan_set == 0 )) ; then + diag "Looks like your test died before it could output anything." + return $rc + fi + if (( _test_died != 0 )) ; then diag "Looks like your test died just after $_executed_tests." return $rc