Skip to content

Commit

Permalink
ZTS: include microsecond timestamps on all output
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
robn committed Feb 12, 2025
1 parent b901d4a commit c73849f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
5 changes: 4 additions & 1 deletion tests/test-runner/bin/test-runner.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#
# Copyright (c) 2012, 2018 by Delphix. All rights reserved.
# Copyright (c) 2019 Datto Inc.
# Copyright (c) 2025, Klara, Inc.
#
# This script must remain compatible with Python 3.6+.
#
Expand Down Expand Up @@ -363,6 +364,8 @@ User: %s
stdout/stderr/merged in its own file.
"""

timeprefix = datetime.now().strftime('[%FT%T.%f] ')

logname = getpwuid(os.getuid()).pw_name
rer = ''
if self.reran is True:
Expand All @@ -374,7 +377,7 @@ User: %s
msga = 'Test: %s%s ' % (self.pathname, user)
msgb = '[%s] [%s]%s\n' % (self.result.runtime, self.result.result, rer)
pad = ' ' * (80 - (len(msga) + len(msgb)))
result_line = msga + pad + msgb
result_line = timeprefix + msga + pad + msgb

# The result line is always written to the log file. If -q was
# specified only failures are written to the console, otherwise
Expand Down
3 changes: 2 additions & 1 deletion tests/test-runner/include/logapi.shlib
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
# Use is subject to license terms.
#
# Copyright (c) 2012, 2020 by Delphix. All rights reserved.
# Copyright (c) 2025, Klara, Inc.
#

STF_PASS=0
Expand Down Expand Up @@ -464,7 +465,7 @@ function _endlog

function _printline
{
echo "$@"
printf '[%(%FT%T.%6N)T] %s\n' now "$*"
}

# Output an error message
Expand Down
7 changes: 6 additions & 1 deletion tests/zfs-tests/callbacks/zfs_dmesg.ksh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#
# Copyright (c) 2016 by Delphix. All rights reserved.
# Copyright (c) 2017 Lawrence Livermore National Security, LLC.
# Copyright (c) 2025, Klara, Inc.
#

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

# report and reset afterwards
sudo dmesg -c | tail -n $lines
dmesg_args="-c"
if [[ $(uname) = "Linux" ]] ; then
dmesg_args="$dmesg_args --time-format=iso"
fi
sudo dmesg $dmesg_args | tail -n $lines

echo "================================================================="
echo " End of dmesg log"
Expand Down

0 comments on commit c73849f

Please sign in to comment.