Skip to content

Commit d0562f8

Browse files
committed
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. - 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. Signed-off-by: Rob Norris <[email protected]>
1 parent b901d4a commit d0562f8

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-4
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#
1515
# Copyright (c) 2012, 2018 by Delphix. All rights reserved.
1616
# Copyright (c) 2019 Datto Inc.
17+
# Copyright (c) 2025, Klara, Inc.
1718
#
1819
# This script must remain compatible with Python 3.6+.
1920
#
@@ -363,6 +364,8 @@ User: %s
363364
stdout/stderr/merged in its own file.
364365
"""
365366

367+
timeprefix = datetime.now().strftime('[%FT%T.%f] ')
368+
366369
logname = getpwuid(os.getuid()).pw_name
367370
rer = ''
368371
if self.reran is True:
@@ -374,7 +377,7 @@ User: %s
374377
msga = 'Test: %s%s ' % (self.pathname, user)
375378
msgb = '[%s] [%s]%s\n' % (self.result.runtime, self.result.result, rer)
376379
pad = ' ' * (80 - (len(msga) + len(msgb)))
377-
result_line = msga + pad + msgb
380+
result_line = timeprefix + msga + pad + msgb
378381

379382
# The result line is always written to the log file. If -q was
380383
# 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
@@ -14,6 +14,7 @@
1414
#
1515
# Copyright (c) 2017 by Delphix. All rights reserved.
1616
# Copyright (c) 2018 by Lawrence Livermore National Security, LLC.
17+
# Copyright (c) 2025, Klara, Inc.
1718
#
1819
# This script must remain compatible with Python 3.6+.
1920
#
@@ -373,7 +374,8 @@ def process_results(pathname):
373374

374375
prefix = '/zfs-tests/tests/(?:functional|perf/regression)/'
375376
pattern = \
376-
r'^Test(?:\s+\(\S+\))?:' + \
377+
r'^(?:\[[0-9\-T:\.]+\]\s+)?' + \
378+
r'Test(?:\s+\(\S+\))?:' + \
377379
rf'\s*\S*{prefix}(\S+)' + \
378380
r'\s*\(run as (\S+)\)\s*\[(\S+)\]\s*\[(\S+)\]'
379381
pattern_log = r'^\s*Log directory:\s*(\S*)'

tests/test-runner/include/logapi.shlib

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

2930
STF_PASS=0
@@ -464,7 +465,7 @@ function _endlog
464465

465466
function _printline
466467
{
467-
echo "$@"
468+
printf '[%(%FT%T.%6N)T] %s\n' now "$*"
468469
}
469470

470471
# 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
@@ -14,6 +14,7 @@
1414
#
1515
# Copyright (c) 2016 by Delphix. All rights reserved.
1616
# Copyright (c) 2017 Lawrence Livermore National Security, LLC.
17+
# Copyright (c) 2025, Klara, Inc.
1718
#
1819

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

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

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

0 commit comments

Comments
 (0)