Skip to content

Commit a6d6ffa

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 6e89095 commit a6d6ffa

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
@@ -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: 2 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,7 @@ function _endlog
465466

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

471472
# 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"

0 commit comments

Comments
 (0)