.gitignore: ignore local vscode workspace settings file
[lttng-tools.git] / tests / utils / tap / tap.sh
index 24ac1aa250d6a092ef9cd8a2c4bb21e9ea75d331..eae7c3a2c2610784d2f45f479883c35329c68223 100755 (executable)
@@ -2,19 +2,8 @@
 #
 # Copyright 2010 Patrick LeBoutillier <patrick.leboutillier@gmail.com>
 #
-#    This program is free software: you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation, either version 3 of the License, or
-#    (at your option) any later version.
+# SPDX-License-Identifier: GPL-3.0-or-later
 #
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License
-#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
-
 
 _version='1.01'
 
@@ -25,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'
@@ -63,6 +54,7 @@ TODO:
 
 OTHER:
   diag MSG
+  autotime 0|1
 
 EXAMPLE:
   #!/bin/bash
@@ -116,6 +108,7 @@ plan_no_plan(){
 
     _plan_set=1
     _no_plan=1
+    _last_time=$("${TIME_SCRIPT}")
 
     return 0
 }
@@ -130,6 +123,7 @@ plan_skip_all(){
 
     _skip_all=1
     _plan_set=1
+    _last_time=$("${TIME_SCRIPT}")
     _exit 0
 
     return 0
@@ -144,6 +138,7 @@ plan_tests(){
     _print_plan $tests
     _expected_tests=$tests
     _plan_set=1
+    _last_time=$("${TIME_SCRIPT}")
 
     return $tests
 }
@@ -206,6 +201,7 @@ ok(){
     fi
 
     echo
+    _autotime
     if (( result != 0 )) ; then
         local file='tap-functions'
         local func=
@@ -244,6 +240,7 @@ okx(){
         diag "$line"
     done
     ok ${PIPESTATUS[0]} "$command"
+    _autotime
 }
 
 
@@ -353,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
@@ -360,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:?}
This page took 0.025587 seconds and 4 git commands to generate.