Skip to content

Commit 245adb6

Browse files
robnbehlendorf
authored andcommitted
ZTS: include microsecond timestamps on all output
When reviewing test output after a failure, it's often quite difficult to work out the order and timing of events, and to correlate test suite output with kernel logs. This adds timestamps to ZTS output to help with this, in three places: - all of the standard log_XXX functions ultimately end up in _printline, which now prefixes output with a timestamp. An escape hatch environment variable is provided for user_cmd, which often calls the logging functions while also depending on the captured output. - the test runner logging function log() also now prefixes its output with a timestamp. - on failure, when capturing the kernel log in zfs_dmesg.ksh, the "iso" time format is requested. Sponsored-by: Klara, Inc. Sponsored-by: Wasabi Technology, Inc. Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: Tino Reichardt <[email protected]> Signed-off-by: Rob Norris <[email protected]> Closes #17045
1 parent 82a0868 commit 245adb6

File tree

5 files changed

+22
-5
lines changed

5 files changed

+22
-5
lines changed

tests/test-runner/bin/test-runner.py.in

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#
1616
# Copyright (c) 2012, 2018 by Delphix. All rights reserved.
1717
# Copyright (c) 2019 Datto Inc.
18+
# Copyright (c) 2025, Klara, Inc.
1819
#
1920
# This script must remain compatible with Python 3.6+.
2021
#
@@ -372,6 +373,8 @@ User: %s
372373
stdout/stderr/merged in its own file.
373374
"""
374375

376+
timeprefix = datetime.now().strftime('[%FT%T.%f] ')
377+
375378
logname = getpwuid(os.getuid()).pw_name
376379
rer = ''
377380
if self.reran is True:
@@ -383,7 +386,7 @@ User: %s
383386
msga = 'Test: %s%s ' % (self.pathname, user)
384387
msgb = '[%s] [%s]%s\n' % (self.result.runtime, self.result.result, rer)
385388
pad = ' ' * (80 - (len(msga) + len(msgb)))
386-
result_line = msga + pad + msgb
389+
result_line = timeprefix + msga + pad + msgb
387390

388391
# The result line is always written to the log file. If -q was
389392
# specified only failures are written to the console, otherwise

tests/test-runner/bin/zts-report.py.in

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#
1616
# Copyright (c) 2017 by Delphix. All rights reserved.
1717
# Copyright (c) 2018 by Lawrence Livermore National Security, LLC.
18+
# Copyright (c) 2025, Klara, Inc.
1819
#
1920
# This script must remain compatible with Python 3.6+.
2021
#
@@ -381,7 +382,8 @@ def process_results(pathname):
381382

382383
prefix = '/zfs-tests/tests/(?:functional|perf/regression)/'
383384
pattern = \
384-
r'^Test(?:\s+\(\S+\))?:' + \
385+
r'^(?:\[[0-9\-T:\.]+\]\s+)?' + \
386+
r'Test(?:\s+\(\S+\))?:' + \
385387
rf'\s*\S*{prefix}(\S+)' + \
386388
r'\s*\(run as (\S+)\)\s*\[(\S+)\]\s*\[(\S+)\]'
387389
pattern_log = r'^\s*Log directory:\s*(\S*)'

tests/test-runner/include/logapi.shlib

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
# Use is subject to license terms.
2626
#
2727
# Copyright (c) 2012, 2020 by Delphix. All rights reserved.
28+
# Copyright (c) 2025, Klara, Inc.
2829
#
2930

3031
STF_PASS=0
@@ -465,7 +466,11 @@ function _endlog
465466

466467
function _printline
467468
{
468-
echo "$@"
469+
if [[ -n "$ZTS_LOG_SUPPRESS_TIMESTAMP" ]] ; then
470+
printf '[%(%FT%T.%6N)T] %s\n' now "$*"
471+
else
472+
echo "$@"
473+
fi
469474
}
470475

471476
# Output an error message

tests/zfs-tests/callbacks/zfs_dmesg.ksh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#
1616
# Copyright (c) 2016 by Delphix. All rights reserved.
1717
# Copyright (c) 2017 Lawrence Livermore National Security, LLC.
18+
# Copyright (c) 2025, Klara, Inc.
1819
#
1920

2021
# $1: number of lines to output (default: 200)
@@ -25,7 +26,11 @@ echo " Tailing last $lines lines of dmesg log"
2526
echo "================================================================="
2627

2728
# report and reset afterwards
28-
sudo dmesg -c | tail -n $lines
29+
dmesg_args="-c"
30+
if [[ $(uname) = "Linux" ]] ; then
31+
dmesg_args="$dmesg_args --time-format=iso"
32+
fi
33+
sudo dmesg $dmesg_args | tail -n $lines
2934

3035
echo "================================================================="
3136
echo " End of dmesg log"

tests/zfs-tests/include/libtest.shlib

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2884,7 +2884,9 @@ function user_run
28842884
typeset out=$TEST_BASE_DIR/out
28852885
typeset err=$TEST_BASE_DIR/err
28862886

2887-
sudo -Eu $user env PATH="$PATH" ksh <<<"$*" >$out 2>$err
2887+
sudo -Eu $user \
2888+
env PATH="$PATH" ZTS_LOG_SUPPRESS_TIMESTAMP=1 \
2889+
ksh <<<"$*" >$out 2>$err
28882890
typeset res=$?
28892891
log_note "out: $(<$out)"
28902892
log_note "err: $(<$err)"

0 commit comments

Comments
 (0)