Skip to content

Commit

Permalink
ZTS: Log test name to /dev/kmsg on Linux
Browse files Browse the repository at this point in the history
Add a -K option to the test suite to log each test name to /dev/kmsg
(on Linux), so if there's a kernel warning we'll be able to match
it up to a particular test.

Reviewed-by: John Kennedy <john.kennedy@delphix.com>
Signed-off-by: Tony Hutter <hutter2@llnl.gov>
Closes  openzfs#13227
  • Loading branch information
tonyhutter authored and andrewc12 committed Sep 23, 2022
1 parent 7c4473b commit aa5dc63
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
9 changes: 8 additions & 1 deletion scripts/zfs-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ VERBOSE="no"
QUIET=""
CLEANUP="yes"
CLEANUPALL="no"
KMSG=""
LOOPBACK="yes"
STACK_TRACER="no"
FILESIZE="4G"
Expand Down Expand Up @@ -326,6 +327,7 @@ OPTIONS:
-q Quiet test-runner output
-x Remove all testpools, dm, lo, and files (unsafe)
-k Disable cleanup after test failure
-K Log test names to /dev/kmsg
-f Use files only, disables block device tests
-S Enable stack tracer (negative performance impact)
-c Only create and populate constrained path
Expand Down Expand Up @@ -357,7 +359,7 @@ $0 -x
EOF
}

while getopts 'hvqxkfScRmn:d:s:r:?t:T:u:I:' OPTION; do
while getopts 'hvqxkKfScRmn:d:s:r:?t:T:u:I:' OPTION; do
case $OPTION in
h)
usage
Expand All @@ -375,6 +377,9 @@ while getopts 'hvqxkfScRmn:d:s:r:?t:T:u:I:' OPTION; do
k)
CLEANUP="no"
;;
K)
KMSG="yes"
;;
f)
LOOPBACK="no"
;;
Expand Down Expand Up @@ -705,13 +710,15 @@ REPORT_FILE=$(mktemp_file zts-report)
msg "${TEST_RUNNER}" \
"${QUIET:+-q}" \
"${KMEMLEAK:+-m}" \
"${KMSG:+-K}" \
"-c \"${RUNFILES}\"" \
"-T \"${TAGS}\"" \
"-i \"${STF_SUITE}\"" \
"-I \"${ITERATIONS}\""
{ ${TEST_RUNNER} \
${QUIET:+-q} \
${KMEMLEAK:+-m} \
${KMSG:+-K} \
-c "${RUNFILES}" \
-T "${TAGS}" \
-i "${STF_SUITE}" \
Expand Down
33 changes: 24 additions & 9 deletions tests/test-runner/bin/test-runner.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ from subprocess import Popen
from subprocess import check_output
from threading import Timer
from time import time, CLOCK_MONOTONIC
from os.path import exists

BASEDIR = '/var/tmp/test_results'
TESTDIR = '/usr/share/zfs/'
Expand Down Expand Up @@ -256,7 +257,7 @@ User: %s

return out.lines, err.lines

def run(self, dryrun, kmemleak):
def run(self, dryrun, kmemleak, kmsg):
"""
This is the main function that runs each individual test.
Determine whether or not the command requires sudo, and modify it
Expand All @@ -275,6 +276,18 @@ User: %s
except OSError as e:
fail('%s' % e)

"""
Log each test we run to /dev/kmsg (on Linux), so if there's a kernel
warning we'll be able to match it up to a particular test.
"""
if kmsg is True and exists("/dev/kmsg"):
try:
kp = Popen([SUDO, "sh", "-c",
f"echo ZTS run {self.pathname} > /dev/kmsg"])
kp.wait()
except Exception:
pass

self.result.starttime = monotonic_time()

if kmemleak:
Expand Down Expand Up @@ -459,22 +472,22 @@ Tags: %s

cont = True
if len(pretest.pathname):
pretest.run(options.dryrun, False)
pretest.run(options.dryrun, False, options.kmsg)
cont = pretest.result.result == 'PASS'
pretest.log(options)

if cont:
test.run(options.dryrun, options.kmemleak)
test.run(options.dryrun, options.kmemleak, options.kmsg)
if test.result.result == 'KILLED' and len(failsafe.pathname):
failsafe.run(options.dryrun, False)
failsafe.run(options.dryrun, False, options.kmsg)
failsafe.log(options, suppress_console=True)
else:
test.skip()

test.log(options)

if len(posttest.pathname):
posttest.run(options.dryrun, False)
posttest.run(options.dryrun, False, options.kmsg)
posttest.log(options)


Expand Down Expand Up @@ -577,7 +590,7 @@ Tags: %s

cont = True
if len(pretest.pathname):
pretest.run(options.dryrun, False)
pretest.run(options.dryrun, False, options.kmsg)
cont = pretest.result.result == 'PASS'
pretest.log(options)

Expand All @@ -590,17 +603,17 @@ Tags: %s
failsafe = Cmd(self.failsafe, outputdir=odir, timeout=self.timeout,
user=self.failsafe_user, identifier=self.identifier)
if cont:
test.run(options.dryrun, options.kmemleak)
test.run(options.dryrun, options.kmemleak, options.kmsg)
if test.result.result == 'KILLED' and len(failsafe.pathname):
failsafe.run(options.dryrun, False)
failsafe.run(options.dryrun, False, options.kmsg)
failsafe.log(options, suppress_console=True)
else:
test.skip()

test.log(options)

if len(posttest.pathname):
posttest.run(options.dryrun, False)
posttest.run(options.dryrun, False, options.kmsg)
posttest.log(options)


Expand Down Expand Up @@ -1060,6 +1073,8 @@ def parse_args():
parser.add_option('-i', action='callback', callback=options_cb,
default=TESTDIR, dest='testdir', type='string',
metavar='testdir', help='Specify a test directory.')
parser.add_option('-K', action='store_true', default=False, dest='kmsg',
help='Log tests names to /dev/kmsg')
parser.add_option('-m', action='callback', callback=kmemleak_cb,
default=False, dest='kmemleak',
help='Enable kmemleak reporting (Linux only)')
Expand Down

0 comments on commit aa5dc63

Please sign in to comment.