2020-07-12 02:35:58 +03:00
|
|
|
#!/usr/bin/env @PYTHON_SHEBANG@
|
2015-07-02 01:23:09 +03:00
|
|
|
|
|
|
|
#
|
|
|
|
# This file and its contents are supplied under the terms of the
|
|
|
|
# Common Development and Distribution License ("CDDL"), version 1.0.
|
|
|
|
# You may only use this file in accordance with the terms of version
|
|
|
|
# 1.0 of the CDDL.
|
|
|
|
#
|
|
|
|
# A full copy of the text of the CDDL should have accompanied this
|
|
|
|
# source. A copy of the CDDL is also available via the Internet at
|
|
|
|
# http://www.illumos.org/license/CDDL.
|
|
|
|
#
|
|
|
|
|
|
|
|
#
|
2018-12-03 21:38:06 +03:00
|
|
|
# Copyright (c) 2012, 2018 by Delphix. All rights reserved.
|
2019-04-11 20:20:37 +03:00
|
|
|
# Copyright (c) 2019 Datto Inc.
|
2015-07-02 01:23:09 +03:00
|
|
|
#
|
2022-01-13 19:51:12 +03:00
|
|
|
# This script must remain compatible with Python 3.6+.
|
pyzfs: python3 support (build system)
Almost all of the Python code in the respository has been updated
to be compatibile with Python 2.6, Python 3.4, or newer. The only
exceptions are arc_summery3.py which requires Python 3, and pyzfs
which requires at least Python 2.7. This allows us to maintain a
single version of the code and support most default versions of
python. This change does the following:
* Sets the default shebang for all Python scripts to python3. If
only Python 2 is available, then at install time scripts which
are compatible with Python 2 will have their shebangs replaced
with /usr/bin/python. This is done for compatibility until
Python 2 goes end of life. Since only the installed versions
are changed this means Python 3 must be installed on the system
for test-runner when testing in-tree.
* Added --with-python=<2|3|3.4,etc> configure option which sets
the PYTHON environment variable to target a specific python
version. By default the newest installed version of Python
will be used or the preferred distribution version when
creating pacakges.
* Fixed --enable-pyzfs configure checks so they are run when
--enable-pyzfs=check and --enable-pyzfs=yes.
* Enabled pyzfs for Python 3.4 and newer, which is now supported.
* Renamed pyzfs package to python<VERSION>-pyzfs and updated to
install in the appropriate site location. For example, when
building with --with-python=3.4 a python34-pyzfs will be
created which installs in /usr/lib/python3.4/site-packages/.
* Renamed the following python scripts according to the Fedora
guidance for packaging utilities in /bin
- dbufstat.py -> dbufstat
- arcstat.py -> arcstat
- arc_summary.py -> arc_summary
- arc_summary3.py -> arc_summary3
* Updated python-cffi package name. On CentOS 6, CentOS 7, and
Amazon Linux it's called python-cffi, not python2-cffi. For
Python3 it's called python3-cffi or python3x-cffi.
* Install one version of arc_summary. Depending on the version
of Python available install either arc_summary2 or arc_summary3
as arc_summary. The user output is only slightly different.
Reviewed-by: John Ramsden <johnramsden@riseup.net>
Reviewed-by: Neal Gompa <ngompa@datto.com>
Reviewed-by: loli10K <ezomori.nozomu@gmail.com>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #8096
2018-10-31 19:22:59 +03:00
|
|
|
#
|
2015-07-02 01:23:09 +03:00
|
|
|
|
|
|
|
import os
|
2018-12-03 21:38:06 +03:00
|
|
|
import sys
|
2019-04-11 20:20:37 +03:00
|
|
|
import ctypes
|
2021-12-01 20:38:53 +03:00
|
|
|
import re
|
2022-01-13 19:51:12 +03:00
|
|
|
import configparser
|
2018-12-03 21:38:06 +03:00
|
|
|
|
2015-07-02 01:23:09 +03:00
|
|
|
from datetime import datetime
|
|
|
|
from optparse import OptionParser
|
|
|
|
from pwd import getpwnam
|
|
|
|
from pwd import getpwuid
|
|
|
|
from select import select
|
|
|
|
from subprocess import PIPE
|
|
|
|
from subprocess import Popen
|
2022-02-24 21:21:13 +03:00
|
|
|
from subprocess import check_output
|
2015-07-02 01:23:09 +03:00
|
|
|
from threading import Timer
|
2022-01-22 02:37:46 +03:00
|
|
|
from time import time, CLOCK_MONOTONIC
|
2022-03-23 18:15:02 +03:00
|
|
|
from os.path import exists
|
2015-07-02 01:23:09 +03:00
|
|
|
|
|
|
|
BASEDIR = '/var/tmp/test_results'
|
|
|
|
TESTDIR = '/usr/share/zfs/'
|
2022-02-24 21:21:13 +03:00
|
|
|
KMEMLEAK_FILE = '/sys/kernel/debug/kmemleak'
|
2015-07-02 01:23:09 +03:00
|
|
|
KILL = 'kill'
|
|
|
|
TRUE = 'true'
|
|
|
|
SUDO = 'sudo'
|
2018-12-03 21:38:06 +03:00
|
|
|
LOG_FILE = 'LOG_FILE'
|
|
|
|
LOG_OUT = 'LOG_OUT'
|
|
|
|
LOG_ERR = 'LOG_ERR'
|
|
|
|
LOG_FILE_OBJ = None
|
2015-07-02 01:23:09 +03:00
|
|
|
|
2023-04-06 20:40:23 +03:00
|
|
|
try:
|
|
|
|
from time import monotonic as monotonic_time
|
|
|
|
except ImportError:
|
|
|
|
class timespec(ctypes.Structure):
|
|
|
|
_fields_ = [
|
|
|
|
('tv_sec', ctypes.c_long),
|
|
|
|
('tv_nsec', ctypes.c_long)
|
|
|
|
]
|
2019-04-11 20:20:37 +03:00
|
|
|
|
2023-04-06 20:40:23 +03:00
|
|
|
librt = ctypes.CDLL('librt.so.1', use_errno=True)
|
|
|
|
clock_gettime = librt.clock_gettime
|
|
|
|
clock_gettime.argtypes = [ctypes.c_int, ctypes.POINTER(timespec)]
|
2019-04-11 20:20:37 +03:00
|
|
|
|
2023-04-06 20:40:23 +03:00
|
|
|
def monotonic_time():
|
|
|
|
t = timespec()
|
|
|
|
if clock_gettime(CLOCK_MONOTONIC, ctypes.pointer(t)) != 0:
|
|
|
|
errno_ = ctypes.get_errno()
|
|
|
|
raise OSError(errno_, os.strerror(errno_))
|
|
|
|
return t.tv_sec + t.tv_nsec * 1e-9
|
2019-04-11 20:20:37 +03:00
|
|
|
|
2015-07-02 01:23:09 +03:00
|
|
|
|
|
|
|
class Result(object):
|
|
|
|
total = 0
|
2019-04-11 20:20:37 +03:00
|
|
|
runresults = {'PASS': 0, 'FAIL': 0, 'SKIP': 0, 'KILLED': 0, 'RERAN': 0}
|
2015-07-02 01:23:09 +03:00
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
self.starttime = None
|
|
|
|
self.returncode = None
|
|
|
|
self.runtime = ''
|
|
|
|
self.stdout = []
|
|
|
|
self.stderr = []
|
2022-02-24 21:21:13 +03:00
|
|
|
self.kmemleak = ''
|
2015-07-02 01:23:09 +03:00
|
|
|
self.result = ''
|
|
|
|
|
2019-04-11 20:20:37 +03:00
|
|
|
def done(self, proc, killed, reran):
|
2015-07-02 01:23:09 +03:00
|
|
|
"""
|
|
|
|
Finalize the results of this Cmd.
|
|
|
|
"""
|
|
|
|
Result.total += 1
|
2019-04-11 20:20:37 +03:00
|
|
|
m, s = divmod(monotonic_time() - self.starttime, 60)
|
2015-07-02 01:23:09 +03:00
|
|
|
self.runtime = '%02d:%02d' % (m, s)
|
|
|
|
self.returncode = proc.returncode
|
2019-04-11 20:20:37 +03:00
|
|
|
if reran is True:
|
|
|
|
Result.runresults['RERAN'] += 1
|
2015-07-02 01:23:09 +03:00
|
|
|
if killed:
|
|
|
|
self.result = 'KILLED'
|
|
|
|
Result.runresults['KILLED'] += 1
|
2022-02-24 21:21:13 +03:00
|
|
|
elif len(self.kmemleak) > 0:
|
|
|
|
self.result = 'FAIL'
|
|
|
|
Result.runresults['FAIL'] += 1
|
2019-02-04 20:02:46 +03:00
|
|
|
elif self.returncode == 0:
|
2015-07-02 01:23:09 +03:00
|
|
|
self.result = 'PASS'
|
|
|
|
Result.runresults['PASS'] += 1
|
2019-02-04 20:02:46 +03:00
|
|
|
elif self.returncode == 4:
|
2015-07-02 01:23:09 +03:00
|
|
|
self.result = 'SKIP'
|
|
|
|
Result.runresults['SKIP'] += 1
|
2019-02-04 20:02:46 +03:00
|
|
|
elif self.returncode != 0:
|
2015-07-02 01:23:09 +03:00
|
|
|
self.result = 'FAIL'
|
|
|
|
Result.runresults['FAIL'] += 1
|
|
|
|
|
|
|
|
|
|
|
|
class Output(object):
|
|
|
|
"""
|
|
|
|
This class is a slightly modified version of the 'Stream' class found
|
2024-07-25 21:00:32 +03:00
|
|
|
here: https://stackoverflow.com/q/4984549/
|
2015-07-02 01:23:09 +03:00
|
|
|
"""
|
2024-04-16 19:13:01 +03:00
|
|
|
def __init__(self, stream, debug=False):
|
2015-07-02 01:23:09 +03:00
|
|
|
self.stream = stream
|
2024-04-16 19:13:01 +03:00
|
|
|
self.debug = debug
|
2018-12-03 21:38:06 +03:00
|
|
|
self._buf = b''
|
2015-07-02 01:23:09 +03:00
|
|
|
self.lines = []
|
|
|
|
|
|
|
|
def fileno(self):
|
|
|
|
return self.stream.fileno()
|
|
|
|
|
|
|
|
def read(self, drain=0):
|
|
|
|
"""
|
|
|
|
Read from the file descriptor. If 'drain' set, read until EOF.
|
|
|
|
"""
|
|
|
|
while self._read() is not None:
|
|
|
|
if not drain:
|
|
|
|
break
|
|
|
|
|
|
|
|
def _read(self):
|
|
|
|
"""
|
|
|
|
Read up to 4k of data from this output stream. Collect the output
|
|
|
|
up to the last newline, and append it to any leftover data from a
|
|
|
|
previous call. The lines are stored as a (timestamp, data) tuple
|
|
|
|
for easy sorting/merging later.
|
|
|
|
"""
|
|
|
|
fd = self.fileno()
|
|
|
|
buf = os.read(fd, 4096)
|
|
|
|
if not buf:
|
|
|
|
return None
|
2024-04-16 19:13:01 +03:00
|
|
|
if self.debug:
|
|
|
|
os.write(sys.stderr.fileno(), buf)
|
2018-12-03 21:38:06 +03:00
|
|
|
if b'\n' not in buf:
|
2015-07-02 01:23:09 +03:00
|
|
|
self._buf += buf
|
|
|
|
return []
|
|
|
|
|
|
|
|
buf = self._buf + buf
|
2018-12-03 21:38:06 +03:00
|
|
|
tmp, rest = buf.rsplit(b'\n', 1)
|
2015-07-02 01:23:09 +03:00
|
|
|
self._buf = rest
|
|
|
|
now = datetime.now()
|
2018-12-03 21:38:06 +03:00
|
|
|
rows = tmp.split(b'\n')
|
2015-07-02 01:23:09 +03:00
|
|
|
self.lines += [(now, r) for r in rows]
|
|
|
|
|
|
|
|
|
|
|
|
class Cmd(object):
|
|
|
|
verified_users = []
|
|
|
|
|
2019-10-09 20:39:26 +03:00
|
|
|
def __init__(self, pathname, identifier=None, outputdir=None,
|
|
|
|
timeout=None, user=None, tags=None):
|
2015-07-02 01:23:09 +03:00
|
|
|
self.pathname = pathname
|
2019-10-09 20:39:26 +03:00
|
|
|
self.identifier = identifier
|
2015-07-02 01:23:09 +03:00
|
|
|
self.outputdir = outputdir or 'BASEDIR'
|
2019-04-11 20:20:37 +03:00
|
|
|
"""
|
|
|
|
The timeout for tests is measured in wall-clock time
|
|
|
|
"""
|
2016-08-04 00:26:15 +03:00
|
|
|
self.timeout = timeout
|
2015-07-02 01:23:09 +03:00
|
|
|
self.user = user or ''
|
|
|
|
self.killed = False
|
2019-04-11 20:20:37 +03:00
|
|
|
self.reran = None
|
2015-07-02 01:23:09 +03:00
|
|
|
self.result = Result()
|
|
|
|
|
2016-10-06 20:11:06 +03:00
|
|
|
if self.timeout is None:
|
|
|
|
self.timeout = 60
|
2016-08-04 00:26:15 +03:00
|
|
|
|
2015-07-02 01:23:09 +03:00
|
|
|
def __str__(self):
|
2020-03-10 21:00:56 +03:00
|
|
|
return '''\
|
|
|
|
Pathname: %s
|
|
|
|
Identifier: %s
|
|
|
|
Outputdir: %s
|
|
|
|
Timeout: %d
|
|
|
|
User: %s
|
|
|
|
''' % (self.pathname, self.identifier, self.outputdir, self.timeout, self.user)
|
2015-07-02 01:23:09 +03:00
|
|
|
|
test-runner: pass kmemleak and kmsg to Cmd.run
test-runner.py orchestrates all of the ZTS executions. The `Cmd` object
manages these process, and its `run` method specifically invokes these
possibly long-running processes, possibly retrying in the event of a
timeout. Since its inception, memory leak detection using the kmemleak
infrastructure [1], and kernel logging [2] have been added to this run
mechanism.
However, the callback to cull a process beyond its timeout threshold,
`kill_cmd`, has evaded modernization by both of these changes. As a
result, this function fails to properly invoke `run`, leading to an
untrapped exception and unreported test failure.
This patch extends `kill_cmd` to receive these kernel devices through
the `options` parameter, and regularizes all the `.run` calls from
`Cmd`, and its subclasses, to accept that parameter.
[1] Commit a69765ea5b563e0cd4d15fac4b1ac08c6ccf12d1
[2] Commit fc2c0256c55a2859d1988671b0896d22b75c8aba
Reviewed-by: John Wren Kennedy <john.kennedy@delphix.com>
Signed-off-by: Antonio Russo <aerusso@aerusso.net>
Closes #14849
2023-05-16 02:11:33 +03:00
|
|
|
def kill_cmd(self, proc, options, kmemleak, keyboard_interrupt=False):
|
2015-07-02 01:23:09 +03:00
|
|
|
"""
|
|
|
|
Kill a running command due to timeout, or ^C from the keyboard. If
|
|
|
|
sudo is required, this user was verified previously.
|
|
|
|
"""
|
|
|
|
self.killed = True
|
|
|
|
do_sudo = len(self.user) != 0
|
|
|
|
signal = '-TERM'
|
|
|
|
|
|
|
|
cmd = [SUDO, KILL, signal, str(proc.pid)]
|
|
|
|
if not do_sudo:
|
|
|
|
del cmd[0]
|
|
|
|
|
|
|
|
try:
|
|
|
|
kp = Popen(cmd)
|
|
|
|
kp.wait()
|
2017-10-24 00:01:43 +03:00
|
|
|
except Exception:
|
2015-07-02 01:23:09 +03:00
|
|
|
pass
|
|
|
|
|
2019-04-11 20:20:37 +03:00
|
|
|
"""
|
|
|
|
If this is not a user-initiated kill and the test has not been
|
|
|
|
reran before we consider if the test needs to be reran:
|
|
|
|
If the test has spent some time hibernating and didn't run the whole
|
|
|
|
length of time before being timed out we will rerun the test.
|
|
|
|
"""
|
|
|
|
if keyboard_interrupt is False and self.reran is None:
|
|
|
|
runtime = monotonic_time() - self.result.starttime
|
|
|
|
if int(self.timeout) > runtime:
|
|
|
|
self.killed = False
|
|
|
|
self.reran = False
|
test-runner: pass kmemleak and kmsg to Cmd.run
test-runner.py orchestrates all of the ZTS executions. The `Cmd` object
manages these process, and its `run` method specifically invokes these
possibly long-running processes, possibly retrying in the event of a
timeout. Since its inception, memory leak detection using the kmemleak
infrastructure [1], and kernel logging [2] have been added to this run
mechanism.
However, the callback to cull a process beyond its timeout threshold,
`kill_cmd`, has evaded modernization by both of these changes. As a
result, this function fails to properly invoke `run`, leading to an
untrapped exception and unreported test failure.
This patch extends `kill_cmd` to receive these kernel devices through
the `options` parameter, and regularizes all the `.run` calls from
`Cmd`, and its subclasses, to accept that parameter.
[1] Commit a69765ea5b563e0cd4d15fac4b1ac08c6ccf12d1
[2] Commit fc2c0256c55a2859d1988671b0896d22b75c8aba
Reviewed-by: John Wren Kennedy <john.kennedy@delphix.com>
Signed-off-by: Antonio Russo <aerusso@aerusso.net>
Closes #14849
2023-05-16 02:11:33 +03:00
|
|
|
self.run(options, dryrun=False, kmemleak=kmemleak)
|
2019-04-11 20:20:37 +03:00
|
|
|
self.reran = True
|
|
|
|
|
2015-07-02 01:23:09 +03:00
|
|
|
def update_cmd_privs(self, cmd, user):
|
|
|
|
"""
|
|
|
|
If a user has been specified to run this Cmd and we're not already
|
|
|
|
running as that user, prepend the appropriate sudo command to run
|
|
|
|
as that user.
|
|
|
|
"""
|
|
|
|
me = getpwuid(os.getuid())
|
|
|
|
|
|
|
|
if not user or user is me:
|
2016-06-07 19:16:52 +03:00
|
|
|
if os.path.isfile(cmd+'.ksh') and os.access(cmd+'.ksh', os.X_OK):
|
|
|
|
cmd += '.ksh'
|
|
|
|
if os.path.isfile(cmd+'.sh') and os.access(cmd+'.sh', os.X_OK):
|
|
|
|
cmd += '.sh'
|
2015-07-02 01:23:09 +03:00
|
|
|
return cmd
|
|
|
|
|
|
|
|
if not os.path.isfile(cmd):
|
|
|
|
if os.path.isfile(cmd+'.ksh') and os.access(cmd+'.ksh', os.X_OK):
|
|
|
|
cmd += '.ksh'
|
|
|
|
if os.path.isfile(cmd+'.sh') and os.access(cmd+'.sh', os.X_OK):
|
|
|
|
cmd += '.sh'
|
|
|
|
|
|
|
|
ret = '%s -E -u %s %s' % (SUDO, user, cmd)
|
|
|
|
return ret.split(' ')
|
|
|
|
|
2024-04-16 19:13:01 +03:00
|
|
|
def collect_output(self, proc, debug=False):
|
2015-07-02 01:23:09 +03:00
|
|
|
"""
|
|
|
|
Read from stdout/stderr as data becomes available, until the
|
|
|
|
process is no longer running. Return the lines from the stdout and
|
|
|
|
stderr Output objects.
|
|
|
|
"""
|
2024-04-16 19:13:01 +03:00
|
|
|
out = Output(proc.stdout, debug)
|
|
|
|
err = Output(proc.stderr, debug)
|
2015-07-02 01:23:09 +03:00
|
|
|
res = []
|
|
|
|
while proc.returncode is None:
|
|
|
|
proc.poll()
|
|
|
|
res = select([out, err], [], [], .1)
|
|
|
|
for fd in res[0]:
|
|
|
|
fd.read()
|
|
|
|
for fd in res[0]:
|
|
|
|
fd.read(drain=1)
|
|
|
|
|
|
|
|
return out.lines, err.lines
|
|
|
|
|
test-runner: pass kmemleak and kmsg to Cmd.run
test-runner.py orchestrates all of the ZTS executions. The `Cmd` object
manages these process, and its `run` method specifically invokes these
possibly long-running processes, possibly retrying in the event of a
timeout. Since its inception, memory leak detection using the kmemleak
infrastructure [1], and kernel logging [2] have been added to this run
mechanism.
However, the callback to cull a process beyond its timeout threshold,
`kill_cmd`, has evaded modernization by both of these changes. As a
result, this function fails to properly invoke `run`, leading to an
untrapped exception and unreported test failure.
This patch extends `kill_cmd` to receive these kernel devices through
the `options` parameter, and regularizes all the `.run` calls from
`Cmd`, and its subclasses, to accept that parameter.
[1] Commit a69765ea5b563e0cd4d15fac4b1ac08c6ccf12d1
[2] Commit fc2c0256c55a2859d1988671b0896d22b75c8aba
Reviewed-by: John Wren Kennedy <john.kennedy@delphix.com>
Signed-off-by: Antonio Russo <aerusso@aerusso.net>
Closes #14849
2023-05-16 02:11:33 +03:00
|
|
|
def run(self, options, dryrun=None, kmemleak=None):
|
2015-07-02 01:23:09 +03:00
|
|
|
"""
|
|
|
|
This is the main function that runs each individual test.
|
|
|
|
Determine whether or not the command requires sudo, and modify it
|
|
|
|
if needed. Run the command, and update the result object.
|
|
|
|
"""
|
test-runner: pass kmemleak and kmsg to Cmd.run
test-runner.py orchestrates all of the ZTS executions. The `Cmd` object
manages these process, and its `run` method specifically invokes these
possibly long-running processes, possibly retrying in the event of a
timeout. Since its inception, memory leak detection using the kmemleak
infrastructure [1], and kernel logging [2] have been added to this run
mechanism.
However, the callback to cull a process beyond its timeout threshold,
`kill_cmd`, has evaded modernization by both of these changes. As a
result, this function fails to properly invoke `run`, leading to an
untrapped exception and unreported test failure.
This patch extends `kill_cmd` to receive these kernel devices through
the `options` parameter, and regularizes all the `.run` calls from
`Cmd`, and its subclasses, to accept that parameter.
[1] Commit a69765ea5b563e0cd4d15fac4b1ac08c6ccf12d1
[2] Commit fc2c0256c55a2859d1988671b0896d22b75c8aba
Reviewed-by: John Wren Kennedy <john.kennedy@delphix.com>
Signed-off-by: Antonio Russo <aerusso@aerusso.net>
Closes #14849
2023-05-16 02:11:33 +03:00
|
|
|
if dryrun is None:
|
|
|
|
dryrun = options.dryrun
|
2019-04-11 20:20:37 +03:00
|
|
|
if dryrun is True:
|
2018-09-26 21:02:26 +03:00
|
|
|
print(self)
|
2015-07-02 01:23:09 +03:00
|
|
|
return
|
test-runner: pass kmemleak and kmsg to Cmd.run
test-runner.py orchestrates all of the ZTS executions. The `Cmd` object
manages these process, and its `run` method specifically invokes these
possibly long-running processes, possibly retrying in the event of a
timeout. Since its inception, memory leak detection using the kmemleak
infrastructure [1], and kernel logging [2] have been added to this run
mechanism.
However, the callback to cull a process beyond its timeout threshold,
`kill_cmd`, has evaded modernization by both of these changes. As a
result, this function fails to properly invoke `run`, leading to an
untrapped exception and unreported test failure.
This patch extends `kill_cmd` to receive these kernel devices through
the `options` parameter, and regularizes all the `.run` calls from
`Cmd`, and its subclasses, to accept that parameter.
[1] Commit a69765ea5b563e0cd4d15fac4b1ac08c6ccf12d1
[2] Commit fc2c0256c55a2859d1988671b0896d22b75c8aba
Reviewed-by: John Wren Kennedy <john.kennedy@delphix.com>
Signed-off-by: Antonio Russo <aerusso@aerusso.net>
Closes #14849
2023-05-16 02:11:33 +03:00
|
|
|
if kmemleak is None:
|
|
|
|
kmemleak = options.kmemleak
|
2015-07-02 01:23:09 +03:00
|
|
|
|
|
|
|
privcmd = self.update_cmd_privs(self.pathname, self.user)
|
|
|
|
try:
|
|
|
|
old = os.umask(0)
|
|
|
|
if not os.path.isdir(self.outputdir):
|
2018-09-26 21:02:26 +03:00
|
|
|
os.makedirs(self.outputdir, mode=0o777)
|
2015-07-02 01:23:09 +03:00
|
|
|
os.umask(old)
|
2018-09-26 21:02:26 +03:00
|
|
|
except OSError as e:
|
2015-07-02 01:23:09 +03:00
|
|
|
fail('%s' % e)
|
|
|
|
|
2022-03-23 18:15:02 +03:00
|
|
|
"""
|
|
|
|
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.
|
|
|
|
"""
|
test-runner: pass kmemleak and kmsg to Cmd.run
test-runner.py orchestrates all of the ZTS executions. The `Cmd` object
manages these process, and its `run` method specifically invokes these
possibly long-running processes, possibly retrying in the event of a
timeout. Since its inception, memory leak detection using the kmemleak
infrastructure [1], and kernel logging [2] have been added to this run
mechanism.
However, the callback to cull a process beyond its timeout threshold,
`kill_cmd`, has evaded modernization by both of these changes. As a
result, this function fails to properly invoke `run`, leading to an
untrapped exception and unreported test failure.
This patch extends `kill_cmd` to receive these kernel devices through
the `options` parameter, and regularizes all the `.run` calls from
`Cmd`, and its subclasses, to accept that parameter.
[1] Commit a69765ea5b563e0cd4d15fac4b1ac08c6ccf12d1
[2] Commit fc2c0256c55a2859d1988671b0896d22b75c8aba
Reviewed-by: John Wren Kennedy <john.kennedy@delphix.com>
Signed-off-by: Antonio Russo <aerusso@aerusso.net>
Closes #14849
2023-05-16 02:11:33 +03:00
|
|
|
if options.kmsg is True and exists("/dev/kmsg"):
|
2022-03-23 18:15:02 +03:00
|
|
|
try:
|
|
|
|
kp = Popen([SUDO, "sh", "-c",
|
|
|
|
f"echo ZTS run {self.pathname} > /dev/kmsg"])
|
|
|
|
kp.wait()
|
|
|
|
except Exception:
|
|
|
|
pass
|
|
|
|
|
ZTS: Use QEMU for tests on Linux and FreeBSD
This commit adds functional tests for these systems:
- AlmaLinux 8, AlmaLinux 9, ArchLinux
- CentOS Stream 9, Fedora 39, Fedora 40
- Debian 11, Debian 12
- FreeBSD 13, FreeBSD 14, FreeBSD 15
- Ubuntu 20.04, Ubuntu 22.04, Ubuntu 24.04
- enabled by default:
- AlmaLinux 8, AlmaLinux 9
- Debian 11, Debian 12
- Fedora 39, Fedora 40
- FreeBSD 13, FreeBSD 14
Workflow for each operating system:
- install qemu on the github runner
- download current cloud image of operating system
- start and init that image via cloud-init
- install dependencies and poweroff system
- start system and build openzfs and then poweroff again
- clone build system and start 2 instances of it
- run functional testings and complete in around 3h
- when tests are done, do some logfile preparing
- show detailed results for each system
- in the end, generate the job summary
Real-world benefits from this PR:
1. The github runner scripts are in the zfs repo itself. That means
you can just open a PR against zfs, like "Add Fedora 41 tester", and
see the results directly in the PR. ZFS admins no longer need
manually to login to the buildbot server to update the buildbot config
with new version of Fedora/Almalinux.
2. Github runners allow you to run the entire test suite against your
private branch before submitting a formal PR to openzfs. Just open a
PR against your private zfs repo, and the exact same
Fedora/Alma/FreeBSD runners will fire up and run ZTS. This can be
useful if you want to iterate on a ZTS change before submitting a
formal PR.
3. buildbot is incredibly cumbersome. Our buildbot config files alone
are ~1500 lines (not including any build/setup scripts)!
It's a huge pain to setup.
4. We're running the super ancient buildbot 0.8.12. It's so ancient
it requires python2. We actually have to build python2 from source
for almalinux9 just to get it to run. Ugrading to a more modern
buildbot is a huge undertaking, and the UI on the newer versions is
worse.
5. Buildbot uses EC2 instances. EC2 is a pain because:
* It costs money
* They throttle IOPS and CPU usage, leading to mysterious,
* hard-to-diagnose, failures and timeouts in ZTS.
* EC2 is high maintenance. We have to setup security groups, SSH
* keys, networking, users, etc, in AWS and it's a pain. We also
* have to periodically go in an kill zombie EC2 instances that
* buildbot is unable to kill off.
6. Buildbot doesn't always handle failures well. One of the things we
saw in the past was the FreeBSD builders would often die, and each
builder death would take up a "slot" in buildbot. So we would
periodically have to restart buildbot via a cron job to get the slots
back.
7. This PR divides up the ZTS test list into two parts, launches two
VMs, and on each VM runs half the test suite. The test results are
then merged and shown in the sumary page. So we're basically
parallelizing ZTS on the same github runner. This leads to lower
overall ZTS runtimes (2.5-3 hours vs 4+ hours on buildbot), and one
unified set of results per runner, which is nice.
8. Since the tests are running on a VM, we have much more control over
what happens. We can capture the serial console output even if the
test completely brings down the VM. In the future, we could also
restart the test on the VM where it left off, so that if a single test
panics the VM, we can just restart it and run the remaining ZTS tests
(this functionaly is not yet implemented though, just an idea).
9. Using the runners, users can manually kill or restart a test run
via the github IU. That really isn't possible with buildbot unless
you're an admin.
10. Anecdotally, the tests seem to be more stable and constant under
the QEMU runners.
Reviewed by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Tino Reichardt <milky-zfs@mcmilk.de>
Signed-off-by: Tony Hutter <hutter2@llnl.gov>
Closes #16537
2024-06-17 17:52:58 +03:00
|
|
|
"""
|
|
|
|
Log each test we run to /dev/ttyu0 (on FreeBSD), so if there's a kernel
|
|
|
|
warning we'll be able to match it up to a particular test.
|
|
|
|
"""
|
|
|
|
if options.kmsg is True and exists("/dev/ttyu0"):
|
|
|
|
try:
|
|
|
|
kp = Popen([SUDO, "sh", "-c",
|
|
|
|
f"echo ZTS run {self.pathname} > /dev/ttyu0"])
|
|
|
|
kp.wait()
|
|
|
|
except Exception:
|
|
|
|
pass
|
|
|
|
|
2019-04-11 20:20:37 +03:00
|
|
|
self.result.starttime = monotonic_time()
|
2022-02-24 21:21:13 +03:00
|
|
|
|
|
|
|
if kmemleak:
|
2022-03-14 03:41:03 +03:00
|
|
|
cmd = f'{SUDO} sh -c "echo clear > {KMEMLEAK_FILE}"'
|
2022-02-24 21:21:13 +03:00
|
|
|
check_output(cmd, shell=True)
|
|
|
|
|
2016-06-07 19:16:52 +03:00
|
|
|
proc = Popen(privcmd, stdout=PIPE, stderr=PIPE)
|
2016-08-04 00:26:15 +03:00
|
|
|
# Allow a special timeout value of 0 to mean infinity
|
|
|
|
if int(self.timeout) == 0:
|
2023-02-03 02:19:26 +03:00
|
|
|
self.timeout = sys.maxsize / (10 ** 9)
|
test-runner: pass kmemleak and kmsg to Cmd.run
test-runner.py orchestrates all of the ZTS executions. The `Cmd` object
manages these process, and its `run` method specifically invokes these
possibly long-running processes, possibly retrying in the event of a
timeout. Since its inception, memory leak detection using the kmemleak
infrastructure [1], and kernel logging [2] have been added to this run
mechanism.
However, the callback to cull a process beyond its timeout threshold,
`kill_cmd`, has evaded modernization by both of these changes. As a
result, this function fails to properly invoke `run`, leading to an
untrapped exception and unreported test failure.
This patch extends `kill_cmd` to receive these kernel devices through
the `options` parameter, and regularizes all the `.run` calls from
`Cmd`, and its subclasses, to accept that parameter.
[1] Commit a69765ea5b563e0cd4d15fac4b1ac08c6ccf12d1
[2] Commit fc2c0256c55a2859d1988671b0896d22b75c8aba
Reviewed-by: John Wren Kennedy <john.kennedy@delphix.com>
Signed-off-by: Antonio Russo <aerusso@aerusso.net>
Closes #14849
2023-05-16 02:11:33 +03:00
|
|
|
t = Timer(
|
|
|
|
int(self.timeout), self.kill_cmd, [proc, options, kmemleak]
|
|
|
|
)
|
2016-06-07 19:16:52 +03:00
|
|
|
|
2015-07-02 01:23:09 +03:00
|
|
|
try:
|
|
|
|
t.start()
|
2024-04-16 19:13:01 +03:00
|
|
|
|
|
|
|
out, err = self.collect_output(proc, options.debug)
|
|
|
|
self.result.stdout = out
|
|
|
|
self.result.stderr = err
|
2022-02-24 21:21:13 +03:00
|
|
|
|
|
|
|
if kmemleak:
|
2022-03-14 03:41:03 +03:00
|
|
|
cmd = f'{SUDO} sh -c "echo scan > {KMEMLEAK_FILE}"'
|
2022-02-24 21:21:13 +03:00
|
|
|
check_output(cmd, shell=True)
|
|
|
|
cmd = f'{SUDO} cat {KMEMLEAK_FILE}'
|
|
|
|
self.result.kmemleak = check_output(cmd, shell=True)
|
2015-07-02 01:23:09 +03:00
|
|
|
except KeyboardInterrupt:
|
test-runner: pass kmemleak and kmsg to Cmd.run
test-runner.py orchestrates all of the ZTS executions. The `Cmd` object
manages these process, and its `run` method specifically invokes these
possibly long-running processes, possibly retrying in the event of a
timeout. Since its inception, memory leak detection using the kmemleak
infrastructure [1], and kernel logging [2] have been added to this run
mechanism.
However, the callback to cull a process beyond its timeout threshold,
`kill_cmd`, has evaded modernization by both of these changes. As a
result, this function fails to properly invoke `run`, leading to an
untrapped exception and unreported test failure.
This patch extends `kill_cmd` to receive these kernel devices through
the `options` parameter, and regularizes all the `.run` calls from
`Cmd`, and its subclasses, to accept that parameter.
[1] Commit a69765ea5b563e0cd4d15fac4b1ac08c6ccf12d1
[2] Commit fc2c0256c55a2859d1988671b0896d22b75c8aba
Reviewed-by: John Wren Kennedy <john.kennedy@delphix.com>
Signed-off-by: Antonio Russo <aerusso@aerusso.net>
Closes #14849
2023-05-16 02:11:33 +03:00
|
|
|
self.kill_cmd(proc, options, kmemleak, True)
|
2015-07-02 01:23:09 +03:00
|
|
|
fail('\nRun terminated at user request.')
|
|
|
|
finally:
|
|
|
|
t.cancel()
|
|
|
|
|
2019-04-11 20:20:37 +03:00
|
|
|
if self.reran is not False:
|
|
|
|
self.result.done(proc, self.killed, self.reran)
|
2015-07-02 01:23:09 +03:00
|
|
|
|
|
|
|
def skip(self):
|
|
|
|
"""
|
|
|
|
Initialize enough of the test result that we can log a skipped
|
|
|
|
command.
|
|
|
|
"""
|
|
|
|
Result.total += 1
|
|
|
|
Result.runresults['SKIP'] += 1
|
|
|
|
self.result.stdout = self.result.stderr = []
|
2019-04-11 20:20:37 +03:00
|
|
|
self.result.starttime = monotonic_time()
|
|
|
|
m, s = divmod(monotonic_time() - self.result.starttime, 60)
|
2015-07-02 01:23:09 +03:00
|
|
|
self.result.runtime = '%02d:%02d' % (m, s)
|
|
|
|
self.result.result = 'SKIP'
|
|
|
|
|
2020-03-10 21:00:56 +03:00
|
|
|
def log(self, options, suppress_console=False):
|
2015-07-02 01:23:09 +03:00
|
|
|
"""
|
|
|
|
This function is responsible for writing all output. This includes
|
|
|
|
the console output, the logfile of all results (with timestamped
|
|
|
|
merged stdout and stderr), and for each test, the unmodified
|
2019-09-03 04:17:39 +03:00
|
|
|
stdout/stderr/merged in its own file.
|
2015-07-02 01:23:09 +03:00
|
|
|
"""
|
|
|
|
|
|
|
|
logname = getpwuid(os.getuid()).pw_name
|
2019-04-11 20:20:37 +03:00
|
|
|
rer = ''
|
|
|
|
if self.reran is True:
|
|
|
|
rer = ' (RERAN)'
|
2015-07-02 01:23:09 +03:00
|
|
|
user = ' (run as %s)' % (self.user if len(self.user) else logname)
|
2019-10-09 20:39:26 +03:00
|
|
|
if self.identifier:
|
|
|
|
msga = 'Test (%s): %s%s ' % (self.identifier, self.pathname, user)
|
|
|
|
else:
|
|
|
|
msga = 'Test: %s%s ' % (self.pathname, user)
|
2019-04-11 20:20:37 +03:00
|
|
|
msgb = '[%s] [%s]%s\n' % (self.result.runtime, self.result.result, rer)
|
2015-07-02 01:23:09 +03:00
|
|
|
pad = ' ' * (80 - (len(msga) + len(msgb)))
|
2018-12-03 21:38:06 +03:00
|
|
|
result_line = msga + pad + msgb
|
2015-07-02 01:23:09 +03:00
|
|
|
|
2018-12-03 21:38:06 +03:00
|
|
|
# The result line is always written to the log file. If -q was
|
|
|
|
# specified only failures are written to the console, otherwise
|
2020-03-10 21:00:56 +03:00
|
|
|
# the result line is written to the console. The console output
|
|
|
|
# may be suppressed by calling log() with suppress_console=True.
|
2018-12-03 21:38:06 +03:00
|
|
|
write_log(bytearray(result_line, encoding='utf-8'), LOG_FILE)
|
2020-03-10 21:00:56 +03:00
|
|
|
if not suppress_console:
|
|
|
|
if not options.quiet:
|
|
|
|
write_log(result_line, LOG_OUT)
|
|
|
|
elif options.quiet and self.result.result != 'PASS':
|
|
|
|
write_log(result_line, LOG_OUT)
|
2015-07-02 01:23:09 +03:00
|
|
|
|
2016-02-25 08:13:41 +03:00
|
|
|
lines = sorted(self.result.stdout + self.result.stderr,
|
2018-09-26 21:02:26 +03:00
|
|
|
key=lambda x: x[0])
|
2016-02-25 08:13:41 +03:00
|
|
|
|
2018-12-03 21:38:06 +03:00
|
|
|
# Write timestamped output (stdout and stderr) to the logfile
|
2016-02-25 08:13:41 +03:00
|
|
|
for dt, line in lines:
|
2018-12-03 21:38:06 +03:00
|
|
|
timestamp = bytearray(dt.strftime("%H:%M:%S.%f ")[:11],
|
|
|
|
encoding='utf-8')
|
|
|
|
write_log(b'%s %s\n' % (timestamp, line), LOG_FILE)
|
2015-07-02 01:23:09 +03:00
|
|
|
|
2018-12-03 21:38:06 +03:00
|
|
|
# Write the separate stdout/stderr/merged files, if the data exists
|
2015-07-02 01:23:09 +03:00
|
|
|
if len(self.result.stdout):
|
2018-12-03 21:38:06 +03:00
|
|
|
with open(os.path.join(self.outputdir, 'stdout'), 'wb') as out:
|
2015-07-02 01:23:09 +03:00
|
|
|
for _, line in self.result.stdout:
|
2018-12-03 21:38:06 +03:00
|
|
|
os.write(out.fileno(), b'%s\n' % line)
|
2015-07-02 01:23:09 +03:00
|
|
|
if len(self.result.stderr):
|
2018-12-03 21:38:06 +03:00
|
|
|
with open(os.path.join(self.outputdir, 'stderr'), 'wb') as err:
|
2015-07-02 01:23:09 +03:00
|
|
|
for _, line in self.result.stderr:
|
2018-12-03 21:38:06 +03:00
|
|
|
os.write(err.fileno(), b'%s\n' % line)
|
2015-07-02 01:23:09 +03:00
|
|
|
if len(self.result.stdout) and len(self.result.stderr):
|
2018-12-03 21:38:06 +03:00
|
|
|
with open(os.path.join(self.outputdir, 'merged'), 'wb') as merged:
|
2016-02-25 08:13:41 +03:00
|
|
|
for _, line in lines:
|
2018-12-03 21:38:06 +03:00
|
|
|
os.write(merged.fileno(), b'%s\n' % line)
|
2022-02-24 21:21:13 +03:00
|
|
|
if len(self.result.kmemleak):
|
|
|
|
with open(os.path.join(self.outputdir, 'kmemleak'), 'wb') as kmem:
|
|
|
|
kmem.write(self.result.kmemleak)
|
2015-07-02 01:23:09 +03:00
|
|
|
|
|
|
|
|
|
|
|
class Test(Cmd):
|
|
|
|
props = ['outputdir', 'timeout', 'user', 'pre', 'pre_user', 'post',
|
2020-03-10 21:00:56 +03:00
|
|
|
'post_user', 'failsafe', 'failsafe_user', 'tags']
|
2015-07-02 01:23:09 +03:00
|
|
|
|
2019-10-09 20:39:26 +03:00
|
|
|
def __init__(self, pathname,
|
2020-03-10 21:00:56 +03:00
|
|
|
pre=None, pre_user=None, post=None, post_user=None,
|
|
|
|
failsafe=None, failsafe_user=None, tags=None, **kwargs):
|
2019-10-09 20:39:26 +03:00
|
|
|
super(Test, self).__init__(pathname, **kwargs)
|
2015-07-02 01:23:09 +03:00
|
|
|
self.pre = pre or ''
|
|
|
|
self.pre_user = pre_user or ''
|
|
|
|
self.post = post or ''
|
|
|
|
self.post_user = post_user or ''
|
2020-03-10 21:00:56 +03:00
|
|
|
self.failsafe = failsafe or ''
|
|
|
|
self.failsafe_user = failsafe_user or ''
|
2017-11-03 19:53:32 +03:00
|
|
|
self.tags = tags or []
|
2015-07-02 01:23:09 +03:00
|
|
|
|
|
|
|
def __str__(self):
|
2020-03-10 21:00:56 +03:00
|
|
|
post_user = pre_user = failsafe_user = ''
|
2015-07-02 01:23:09 +03:00
|
|
|
if len(self.pre_user):
|
|
|
|
pre_user = ' (as %s)' % (self.pre_user)
|
|
|
|
if len(self.post_user):
|
|
|
|
post_user = ' (as %s)' % (self.post_user)
|
2020-03-10 21:00:56 +03:00
|
|
|
if len(self.failsafe_user):
|
|
|
|
failsafe_user = ' (as %s)' % (self.failsafe_user)
|
|
|
|
return '''\
|
|
|
|
Pathname: %s
|
|
|
|
Identifier: %s
|
|
|
|
Outputdir: %s
|
|
|
|
Timeout: %d
|
|
|
|
User: %s
|
|
|
|
Pre: %s%s
|
|
|
|
Post: %s%s
|
|
|
|
Failsafe: %s%s
|
|
|
|
Tags: %s
|
|
|
|
''' % (self.pathname, self.identifier, self.outputdir, self.timeout, self.user,
|
|
|
|
self.pre, pre_user, self.post, post_user, self.failsafe,
|
|
|
|
failsafe_user, self.tags)
|
2015-07-02 01:23:09 +03:00
|
|
|
|
2018-12-03 21:38:06 +03:00
|
|
|
def verify(self):
|
2015-07-02 01:23:09 +03:00
|
|
|
"""
|
2020-03-10 21:00:56 +03:00
|
|
|
Check the pre/post/failsafe scripts, user and Test. Omit the Test from
|
|
|
|
this run if there are any problems.
|
2015-07-02 01:23:09 +03:00
|
|
|
"""
|
2020-03-10 21:00:56 +03:00
|
|
|
files = [self.pre, self.pathname, self.post, self.failsafe]
|
|
|
|
users = [self.pre_user, self.user, self.post_user, self.failsafe_user]
|
2015-07-02 01:23:09 +03:00
|
|
|
|
|
|
|
for f in [f for f in files if len(f)]:
|
|
|
|
if not verify_file(f):
|
2018-12-03 21:38:06 +03:00
|
|
|
write_log("Warning: Test '%s' not added to this run because"
|
|
|
|
" it failed verification.\n" % f, LOG_ERR)
|
2015-07-02 01:23:09 +03:00
|
|
|
return False
|
|
|
|
|
|
|
|
for user in [user for user in users if len(user)]:
|
2018-12-03 21:38:06 +03:00
|
|
|
if not verify_user(user):
|
|
|
|
write_log("Not adding Test '%s' to this run.\n" %
|
|
|
|
self.pathname, LOG_ERR)
|
2015-07-02 01:23:09 +03:00
|
|
|
return False
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
test-runner: pass kmemleak and kmsg to Cmd.run
test-runner.py orchestrates all of the ZTS executions. The `Cmd` object
manages these process, and its `run` method specifically invokes these
possibly long-running processes, possibly retrying in the event of a
timeout. Since its inception, memory leak detection using the kmemleak
infrastructure [1], and kernel logging [2] have been added to this run
mechanism.
However, the callback to cull a process beyond its timeout threshold,
`kill_cmd`, has evaded modernization by both of these changes. As a
result, this function fails to properly invoke `run`, leading to an
untrapped exception and unreported test failure.
This patch extends `kill_cmd` to receive these kernel devices through
the `options` parameter, and regularizes all the `.run` calls from
`Cmd`, and its subclasses, to accept that parameter.
[1] Commit a69765ea5b563e0cd4d15fac4b1ac08c6ccf12d1
[2] Commit fc2c0256c55a2859d1988671b0896d22b75c8aba
Reviewed-by: John Wren Kennedy <john.kennedy@delphix.com>
Signed-off-by: Antonio Russo <aerusso@aerusso.net>
Closes #14849
2023-05-16 02:11:33 +03:00
|
|
|
def run(self, options, dryrun=None, kmemleak=None):
|
2015-07-02 01:23:09 +03:00
|
|
|
"""
|
2020-03-10 21:00:56 +03:00
|
|
|
Create Cmd instances for the pre/post/failsafe scripts. If the pre
|
|
|
|
script doesn't pass, skip this Test. Run the post script regardless.
|
|
|
|
If the Test is killed, also run the failsafe script.
|
2015-07-02 01:23:09 +03:00
|
|
|
"""
|
2016-08-30 22:01:41 +03:00
|
|
|
odir = os.path.join(self.outputdir, os.path.basename(self.pre))
|
2019-10-09 20:39:26 +03:00
|
|
|
pretest = Cmd(self.pre, identifier=self.identifier, outputdir=odir,
|
|
|
|
timeout=self.timeout, user=self.pre_user)
|
|
|
|
test = Cmd(self.pathname, identifier=self.identifier,
|
|
|
|
outputdir=self.outputdir, timeout=self.timeout,
|
|
|
|
user=self.user)
|
2020-03-10 21:00:56 +03:00
|
|
|
odir = os.path.join(self.outputdir, os.path.basename(self.failsafe))
|
|
|
|
failsafe = Cmd(self.failsafe, identifier=self.identifier,
|
|
|
|
outputdir=odir, timeout=self.timeout,
|
|
|
|
user=self.failsafe_user)
|
2016-08-30 22:01:41 +03:00
|
|
|
odir = os.path.join(self.outputdir, os.path.basename(self.post))
|
2019-10-09 20:39:26 +03:00
|
|
|
posttest = Cmd(self.post, identifier=self.identifier, outputdir=odir,
|
|
|
|
timeout=self.timeout, user=self.post_user)
|
2015-07-02 01:23:09 +03:00
|
|
|
|
|
|
|
cont = True
|
|
|
|
if len(pretest.pathname):
|
test-runner: pass kmemleak and kmsg to Cmd.run
test-runner.py orchestrates all of the ZTS executions. The `Cmd` object
manages these process, and its `run` method specifically invokes these
possibly long-running processes, possibly retrying in the event of a
timeout. Since its inception, memory leak detection using the kmemleak
infrastructure [1], and kernel logging [2] have been added to this run
mechanism.
However, the callback to cull a process beyond its timeout threshold,
`kill_cmd`, has evaded modernization by both of these changes. As a
result, this function fails to properly invoke `run`, leading to an
untrapped exception and unreported test failure.
This patch extends `kill_cmd` to receive these kernel devices through
the `options` parameter, and regularizes all the `.run` calls from
`Cmd`, and its subclasses, to accept that parameter.
[1] Commit a69765ea5b563e0cd4d15fac4b1ac08c6ccf12d1
[2] Commit fc2c0256c55a2859d1988671b0896d22b75c8aba
Reviewed-by: John Wren Kennedy <john.kennedy@delphix.com>
Signed-off-by: Antonio Russo <aerusso@aerusso.net>
Closes #14849
2023-05-16 02:11:33 +03:00
|
|
|
pretest.run(options, kmemleak=False)
|
2019-02-04 20:02:46 +03:00
|
|
|
cont = pretest.result.result == 'PASS'
|
2018-12-03 21:38:06 +03:00
|
|
|
pretest.log(options)
|
2015-07-02 01:23:09 +03:00
|
|
|
|
|
|
|
if cont:
|
test-runner: pass kmemleak and kmsg to Cmd.run
test-runner.py orchestrates all of the ZTS executions. The `Cmd` object
manages these process, and its `run` method specifically invokes these
possibly long-running processes, possibly retrying in the event of a
timeout. Since its inception, memory leak detection using the kmemleak
infrastructure [1], and kernel logging [2] have been added to this run
mechanism.
However, the callback to cull a process beyond its timeout threshold,
`kill_cmd`, has evaded modernization by both of these changes. As a
result, this function fails to properly invoke `run`, leading to an
untrapped exception and unreported test failure.
This patch extends `kill_cmd` to receive these kernel devices through
the `options` parameter, and regularizes all the `.run` calls from
`Cmd`, and its subclasses, to accept that parameter.
[1] Commit a69765ea5b563e0cd4d15fac4b1ac08c6ccf12d1
[2] Commit fc2c0256c55a2859d1988671b0896d22b75c8aba
Reviewed-by: John Wren Kennedy <john.kennedy@delphix.com>
Signed-off-by: Antonio Russo <aerusso@aerusso.net>
Closes #14849
2023-05-16 02:11:33 +03:00
|
|
|
test.run(options, kmemleak=kmemleak)
|
2020-03-10 21:00:56 +03:00
|
|
|
if test.result.result == 'KILLED' and len(failsafe.pathname):
|
test-runner: pass kmemleak and kmsg to Cmd.run
test-runner.py orchestrates all of the ZTS executions. The `Cmd` object
manages these process, and its `run` method specifically invokes these
possibly long-running processes, possibly retrying in the event of a
timeout. Since its inception, memory leak detection using the kmemleak
infrastructure [1], and kernel logging [2] have been added to this run
mechanism.
However, the callback to cull a process beyond its timeout threshold,
`kill_cmd`, has evaded modernization by both of these changes. As a
result, this function fails to properly invoke `run`, leading to an
untrapped exception and unreported test failure.
This patch extends `kill_cmd` to receive these kernel devices through
the `options` parameter, and regularizes all the `.run` calls from
`Cmd`, and its subclasses, to accept that parameter.
[1] Commit a69765ea5b563e0cd4d15fac4b1ac08c6ccf12d1
[2] Commit fc2c0256c55a2859d1988671b0896d22b75c8aba
Reviewed-by: John Wren Kennedy <john.kennedy@delphix.com>
Signed-off-by: Antonio Russo <aerusso@aerusso.net>
Closes #14849
2023-05-16 02:11:33 +03:00
|
|
|
failsafe.run(options, kmemleak=False)
|
2020-03-10 21:00:56 +03:00
|
|
|
failsafe.log(options, suppress_console=True)
|
2015-07-02 01:23:09 +03:00
|
|
|
else:
|
|
|
|
test.skip()
|
|
|
|
|
2018-12-03 21:38:06 +03:00
|
|
|
test.log(options)
|
2015-07-02 01:23:09 +03:00
|
|
|
|
|
|
|
if len(posttest.pathname):
|
test-runner: pass kmemleak and kmsg to Cmd.run
test-runner.py orchestrates all of the ZTS executions. The `Cmd` object
manages these process, and its `run` method specifically invokes these
possibly long-running processes, possibly retrying in the event of a
timeout. Since its inception, memory leak detection using the kmemleak
infrastructure [1], and kernel logging [2] have been added to this run
mechanism.
However, the callback to cull a process beyond its timeout threshold,
`kill_cmd`, has evaded modernization by both of these changes. As a
result, this function fails to properly invoke `run`, leading to an
untrapped exception and unreported test failure.
This patch extends `kill_cmd` to receive these kernel devices through
the `options` parameter, and regularizes all the `.run` calls from
`Cmd`, and its subclasses, to accept that parameter.
[1] Commit a69765ea5b563e0cd4d15fac4b1ac08c6ccf12d1
[2] Commit fc2c0256c55a2859d1988671b0896d22b75c8aba
Reviewed-by: John Wren Kennedy <john.kennedy@delphix.com>
Signed-off-by: Antonio Russo <aerusso@aerusso.net>
Closes #14849
2023-05-16 02:11:33 +03:00
|
|
|
posttest.run(options, kmemleak=False)
|
2018-12-03 21:38:06 +03:00
|
|
|
posttest.log(options)
|
2015-07-02 01:23:09 +03:00
|
|
|
|
|
|
|
|
|
|
|
class TestGroup(Test):
|
|
|
|
props = Test.props + ['tests']
|
|
|
|
|
2019-10-09 20:39:26 +03:00
|
|
|
def __init__(self, pathname, tests=None, **kwargs):
|
|
|
|
super(TestGroup, self).__init__(pathname, **kwargs)
|
2015-07-02 01:23:09 +03:00
|
|
|
self.tests = tests or []
|
|
|
|
|
|
|
|
def __str__(self):
|
2020-03-10 21:00:56 +03:00
|
|
|
post_user = pre_user = failsafe_user = ''
|
2015-07-02 01:23:09 +03:00
|
|
|
if len(self.pre_user):
|
|
|
|
pre_user = ' (as %s)' % (self.pre_user)
|
|
|
|
if len(self.post_user):
|
|
|
|
post_user = ' (as %s)' % (self.post_user)
|
2020-03-10 21:00:56 +03:00
|
|
|
if len(self.failsafe_user):
|
|
|
|
failsafe_user = ' (as %s)' % (self.failsafe_user)
|
|
|
|
return '''\
|
|
|
|
Pathname: %s
|
|
|
|
Identifier: %s
|
|
|
|
Outputdir: %s
|
|
|
|
Tests: %s
|
|
|
|
Timeout: %s
|
|
|
|
User: %s
|
|
|
|
Pre: %s%s
|
|
|
|
Post: %s%s
|
|
|
|
Failsafe: %s%s
|
|
|
|
Tags: %s
|
|
|
|
''' % (self.pathname, self.identifier, self.outputdir, self.tests,
|
|
|
|
self.timeout, self.user, self.pre, pre_user, self.post, post_user,
|
|
|
|
self.failsafe, failsafe_user, self.tags)
|
2015-07-02 01:23:09 +03:00
|
|
|
|
2021-12-01 20:38:53 +03:00
|
|
|
def filter(self, keeplist):
|
|
|
|
self.tests = [x for x in self.tests if x in keeplist]
|
|
|
|
|
2018-12-03 21:38:06 +03:00
|
|
|
def verify(self):
|
2015-07-02 01:23:09 +03:00
|
|
|
"""
|
2020-03-10 21:00:56 +03:00
|
|
|
Check the pre/post/failsafe scripts, user and tests in this TestGroup.
|
|
|
|
Omit the TestGroup entirely, or simply delete the relevant tests in the
|
2015-07-02 01:23:09 +03:00
|
|
|
group, if that's all that's required.
|
|
|
|
"""
|
2020-03-10 21:00:56 +03:00
|
|
|
# If the pre/post/failsafe scripts are relative pathnames, convert to
|
2015-07-02 01:23:09 +03:00
|
|
|
# absolute, so they stand a chance of passing verification.
|
|
|
|
if len(self.pre) and not os.path.isabs(self.pre):
|
|
|
|
self.pre = os.path.join(self.pathname, self.pre)
|
|
|
|
if len(self.post) and not os.path.isabs(self.post):
|
|
|
|
self.post = os.path.join(self.pathname, self.post)
|
2020-03-10 21:00:56 +03:00
|
|
|
if len(self.failsafe) and not os.path.isabs(self.failsafe):
|
|
|
|
self.post = os.path.join(self.pathname, self.post)
|
2015-07-02 01:23:09 +03:00
|
|
|
|
2020-03-10 21:00:56 +03:00
|
|
|
auxfiles = [self.pre, self.post, self.failsafe]
|
|
|
|
users = [self.pre_user, self.user, self.post_user, self.failsafe_user]
|
2015-07-02 01:23:09 +03:00
|
|
|
|
|
|
|
for f in [f for f in auxfiles if len(f)]:
|
2020-03-10 21:00:56 +03:00
|
|
|
if f != self.failsafe and self.pathname != os.path.dirname(f):
|
2018-12-03 21:38:06 +03:00
|
|
|
write_log("Warning: TestGroup '%s' not added to this run. "
|
|
|
|
"Auxiliary script '%s' exists in a different "
|
|
|
|
"directory.\n" % (self.pathname, f), LOG_ERR)
|
2015-07-02 01:23:09 +03:00
|
|
|
return False
|
|
|
|
|
|
|
|
if not verify_file(f):
|
2018-12-03 21:38:06 +03:00
|
|
|
write_log("Warning: TestGroup '%s' not added to this run. "
|
|
|
|
"Auxiliary script '%s' failed verification.\n" %
|
|
|
|
(self.pathname, f), LOG_ERR)
|
2015-07-02 01:23:09 +03:00
|
|
|
return False
|
|
|
|
|
|
|
|
for user in [user for user in users if len(user)]:
|
2018-12-03 21:38:06 +03:00
|
|
|
if not verify_user(user):
|
|
|
|
write_log("Not adding TestGroup '%s' to this run.\n" %
|
|
|
|
self.pathname, LOG_ERR)
|
2015-07-02 01:23:09 +03:00
|
|
|
return False
|
|
|
|
|
|
|
|
# If one of the tests is invalid, delete it, log it, and drive on.
|
|
|
|
for test in self.tests:
|
|
|
|
if not verify_file(os.path.join(self.pathname, test)):
|
|
|
|
del self.tests[self.tests.index(test)]
|
2018-12-03 21:38:06 +03:00
|
|
|
write_log("Warning: Test '%s' removed from TestGroup '%s' "
|
|
|
|
"because it failed verification.\n" %
|
|
|
|
(test, self.pathname), LOG_ERR)
|
2015-07-02 01:23:09 +03:00
|
|
|
|
2019-02-04 20:02:46 +03:00
|
|
|
return len(self.tests) != 0
|
2015-07-02 01:23:09 +03:00
|
|
|
|
test-runner: pass kmemleak and kmsg to Cmd.run
test-runner.py orchestrates all of the ZTS executions. The `Cmd` object
manages these process, and its `run` method specifically invokes these
possibly long-running processes, possibly retrying in the event of a
timeout. Since its inception, memory leak detection using the kmemleak
infrastructure [1], and kernel logging [2] have been added to this run
mechanism.
However, the callback to cull a process beyond its timeout threshold,
`kill_cmd`, has evaded modernization by both of these changes. As a
result, this function fails to properly invoke `run`, leading to an
untrapped exception and unreported test failure.
This patch extends `kill_cmd` to receive these kernel devices through
the `options` parameter, and regularizes all the `.run` calls from
`Cmd`, and its subclasses, to accept that parameter.
[1] Commit a69765ea5b563e0cd4d15fac4b1ac08c6ccf12d1
[2] Commit fc2c0256c55a2859d1988671b0896d22b75c8aba
Reviewed-by: John Wren Kennedy <john.kennedy@delphix.com>
Signed-off-by: Antonio Russo <aerusso@aerusso.net>
Closes #14849
2023-05-16 02:11:33 +03:00
|
|
|
def run(self, options, dryrun=None, kmemleak=None):
|
2015-07-02 01:23:09 +03:00
|
|
|
"""
|
2020-03-10 21:00:56 +03:00
|
|
|
Create Cmd instances for the pre/post/failsafe scripts. If the pre
|
|
|
|
script doesn't pass, skip all the tests in this TestGroup. Run the
|
|
|
|
post script regardless. Run the failsafe script when a test is killed.
|
2015-07-02 01:23:09 +03:00
|
|
|
"""
|
2017-11-03 19:53:32 +03:00
|
|
|
# tags assigned to this test group also include the test names
|
|
|
|
if options.tags and not set(self.tags).intersection(set(options.tags)):
|
|
|
|
return
|
|
|
|
|
2016-08-30 22:01:41 +03:00
|
|
|
odir = os.path.join(self.outputdir, os.path.basename(self.pre))
|
|
|
|
pretest = Cmd(self.pre, outputdir=odir, timeout=self.timeout,
|
2019-10-09 20:39:26 +03:00
|
|
|
user=self.pre_user, identifier=self.identifier)
|
2016-08-30 22:01:41 +03:00
|
|
|
odir = os.path.join(self.outputdir, os.path.basename(self.post))
|
|
|
|
posttest = Cmd(self.post, outputdir=odir, timeout=self.timeout,
|
2019-10-09 20:39:26 +03:00
|
|
|
user=self.post_user, identifier=self.identifier)
|
2015-07-02 01:23:09 +03:00
|
|
|
|
|
|
|
cont = True
|
|
|
|
if len(pretest.pathname):
|
test-runner: pass kmemleak and kmsg to Cmd.run
test-runner.py orchestrates all of the ZTS executions. The `Cmd` object
manages these process, and its `run` method specifically invokes these
possibly long-running processes, possibly retrying in the event of a
timeout. Since its inception, memory leak detection using the kmemleak
infrastructure [1], and kernel logging [2] have been added to this run
mechanism.
However, the callback to cull a process beyond its timeout threshold,
`kill_cmd`, has evaded modernization by both of these changes. As a
result, this function fails to properly invoke `run`, leading to an
untrapped exception and unreported test failure.
This patch extends `kill_cmd` to receive these kernel devices through
the `options` parameter, and regularizes all the `.run` calls from
`Cmd`, and its subclasses, to accept that parameter.
[1] Commit a69765ea5b563e0cd4d15fac4b1ac08c6ccf12d1
[2] Commit fc2c0256c55a2859d1988671b0896d22b75c8aba
Reviewed-by: John Wren Kennedy <john.kennedy@delphix.com>
Signed-off-by: Antonio Russo <aerusso@aerusso.net>
Closes #14849
2023-05-16 02:11:33 +03:00
|
|
|
pretest.run(options, dryrun=dryrun, kmemleak=False)
|
2019-02-04 20:02:46 +03:00
|
|
|
cont = pretest.result.result == 'PASS'
|
2018-12-03 21:38:06 +03:00
|
|
|
pretest.log(options)
|
2015-07-02 01:23:09 +03:00
|
|
|
|
|
|
|
for fname in self.tests:
|
2020-03-10 21:00:56 +03:00
|
|
|
odir = os.path.join(self.outputdir, fname)
|
|
|
|
test = Cmd(os.path.join(self.pathname, fname), outputdir=odir,
|
2019-10-09 20:39:26 +03:00
|
|
|
timeout=self.timeout, user=self.user,
|
|
|
|
identifier=self.identifier)
|
2020-03-10 21:00:56 +03:00
|
|
|
odir = os.path.join(odir, os.path.basename(self.failsafe))
|
|
|
|
failsafe = Cmd(self.failsafe, outputdir=odir, timeout=self.timeout,
|
|
|
|
user=self.failsafe_user, identifier=self.identifier)
|
2015-07-02 01:23:09 +03:00
|
|
|
if cont:
|
test-runner: pass kmemleak and kmsg to Cmd.run
test-runner.py orchestrates all of the ZTS executions. The `Cmd` object
manages these process, and its `run` method specifically invokes these
possibly long-running processes, possibly retrying in the event of a
timeout. Since its inception, memory leak detection using the kmemleak
infrastructure [1], and kernel logging [2] have been added to this run
mechanism.
However, the callback to cull a process beyond its timeout threshold,
`kill_cmd`, has evaded modernization by both of these changes. As a
result, this function fails to properly invoke `run`, leading to an
untrapped exception and unreported test failure.
This patch extends `kill_cmd` to receive these kernel devices through
the `options` parameter, and regularizes all the `.run` calls from
`Cmd`, and its subclasses, to accept that parameter.
[1] Commit a69765ea5b563e0cd4d15fac4b1ac08c6ccf12d1
[2] Commit fc2c0256c55a2859d1988671b0896d22b75c8aba
Reviewed-by: John Wren Kennedy <john.kennedy@delphix.com>
Signed-off-by: Antonio Russo <aerusso@aerusso.net>
Closes #14849
2023-05-16 02:11:33 +03:00
|
|
|
test.run(options, dryrun=dryrun, kmemleak=kmemleak)
|
2020-03-10 21:00:56 +03:00
|
|
|
if test.result.result == 'KILLED' and len(failsafe.pathname):
|
test-runner: pass kmemleak and kmsg to Cmd.run
test-runner.py orchestrates all of the ZTS executions. The `Cmd` object
manages these process, and its `run` method specifically invokes these
possibly long-running processes, possibly retrying in the event of a
timeout. Since its inception, memory leak detection using the kmemleak
infrastructure [1], and kernel logging [2] have been added to this run
mechanism.
However, the callback to cull a process beyond its timeout threshold,
`kill_cmd`, has evaded modernization by both of these changes. As a
result, this function fails to properly invoke `run`, leading to an
untrapped exception and unreported test failure.
This patch extends `kill_cmd` to receive these kernel devices through
the `options` parameter, and regularizes all the `.run` calls from
`Cmd`, and its subclasses, to accept that parameter.
[1] Commit a69765ea5b563e0cd4d15fac4b1ac08c6ccf12d1
[2] Commit fc2c0256c55a2859d1988671b0896d22b75c8aba
Reviewed-by: John Wren Kennedy <john.kennedy@delphix.com>
Signed-off-by: Antonio Russo <aerusso@aerusso.net>
Closes #14849
2023-05-16 02:11:33 +03:00
|
|
|
failsafe.run(options, dryrun=dryrun, kmemleak=False)
|
2020-03-10 21:00:56 +03:00
|
|
|
failsafe.log(options, suppress_console=True)
|
2015-07-02 01:23:09 +03:00
|
|
|
else:
|
|
|
|
test.skip()
|
|
|
|
|
2018-12-03 21:38:06 +03:00
|
|
|
test.log(options)
|
2015-07-02 01:23:09 +03:00
|
|
|
|
|
|
|
if len(posttest.pathname):
|
test-runner: pass kmemleak and kmsg to Cmd.run
test-runner.py orchestrates all of the ZTS executions. The `Cmd` object
manages these process, and its `run` method specifically invokes these
possibly long-running processes, possibly retrying in the event of a
timeout. Since its inception, memory leak detection using the kmemleak
infrastructure [1], and kernel logging [2] have been added to this run
mechanism.
However, the callback to cull a process beyond its timeout threshold,
`kill_cmd`, has evaded modernization by both of these changes. As a
result, this function fails to properly invoke `run`, leading to an
untrapped exception and unreported test failure.
This patch extends `kill_cmd` to receive these kernel devices through
the `options` parameter, and regularizes all the `.run` calls from
`Cmd`, and its subclasses, to accept that parameter.
[1] Commit a69765ea5b563e0cd4d15fac4b1ac08c6ccf12d1
[2] Commit fc2c0256c55a2859d1988671b0896d22b75c8aba
Reviewed-by: John Wren Kennedy <john.kennedy@delphix.com>
Signed-off-by: Antonio Russo <aerusso@aerusso.net>
Closes #14849
2023-05-16 02:11:33 +03:00
|
|
|
posttest.run(options, dryrun=dryrun, kmemleak=False)
|
2018-12-03 21:38:06 +03:00
|
|
|
posttest.log(options)
|
2015-07-02 01:23:09 +03:00
|
|
|
|
|
|
|
|
|
|
|
class TestRun(object):
|
2024-04-16 19:13:01 +03:00
|
|
|
props = ['quiet', 'outputdir', 'debug']
|
2015-07-02 01:23:09 +03:00
|
|
|
|
|
|
|
def __init__(self, options):
|
|
|
|
self.tests = {}
|
|
|
|
self.testgroups = {}
|
|
|
|
self.starttime = time()
|
|
|
|
self.timestamp = datetime.now().strftime('%Y%m%dT%H%M%S')
|
|
|
|
self.outputdir = os.path.join(options.outputdir, self.timestamp)
|
2018-12-03 21:38:06 +03:00
|
|
|
self.setup_logging(options)
|
2015-07-02 01:23:09 +03:00
|
|
|
self.defaults = [
|
|
|
|
('outputdir', BASEDIR),
|
|
|
|
('quiet', False),
|
|
|
|
('timeout', 60),
|
|
|
|
('user', ''),
|
|
|
|
('pre', ''),
|
|
|
|
('pre_user', ''),
|
|
|
|
('post', ''),
|
2017-11-03 19:53:32 +03:00
|
|
|
('post_user', ''),
|
2020-03-10 21:00:56 +03:00
|
|
|
('failsafe', ''),
|
|
|
|
('failsafe_user', ''),
|
2024-04-16 19:13:01 +03:00
|
|
|
('tags', []),
|
|
|
|
('debug', False)
|
2015-07-02 01:23:09 +03:00
|
|
|
]
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
s = 'TestRun:\n outputdir: %s\n' % self.outputdir
|
|
|
|
s += 'TESTS:\n'
|
|
|
|
for key in sorted(self.tests.keys()):
|
|
|
|
s += '%s%s' % (self.tests[key].__str__(), '\n')
|
|
|
|
s += 'TESTGROUPS:\n'
|
|
|
|
for key in sorted(self.testgroups.keys()):
|
|
|
|
s += '%s%s' % (self.testgroups[key].__str__(), '\n')
|
|
|
|
return s
|
|
|
|
|
|
|
|
def addtest(self, pathname, options):
|
|
|
|
"""
|
|
|
|
Create a new Test, and apply any properties that were passed in
|
|
|
|
from the command line. If it passes verification, add it to the
|
|
|
|
TestRun.
|
|
|
|
"""
|
|
|
|
test = Test(pathname)
|
|
|
|
for prop in Test.props:
|
|
|
|
setattr(test, prop, getattr(options, prop))
|
|
|
|
|
2018-12-03 21:38:06 +03:00
|
|
|
if test.verify():
|
2015-07-02 01:23:09 +03:00
|
|
|
self.tests[pathname] = test
|
|
|
|
|
|
|
|
def addtestgroup(self, dirname, filenames, options):
|
|
|
|
"""
|
|
|
|
Create a new TestGroup, and apply any properties that were passed
|
|
|
|
in from the command line. If it passes verification, add it to the
|
|
|
|
TestRun.
|
|
|
|
"""
|
|
|
|
if dirname not in self.testgroups:
|
|
|
|
testgroup = TestGroup(dirname)
|
|
|
|
for prop in Test.props:
|
|
|
|
setattr(testgroup, prop, getattr(options, prop))
|
|
|
|
|
2020-03-10 21:00:56 +03:00
|
|
|
# Prevent pre/post/failsafe scripts from running as regular tests
|
|
|
|
for f in [testgroup.pre, testgroup.post, testgroup.failsafe]:
|
2015-07-02 01:23:09 +03:00
|
|
|
if f in filenames:
|
|
|
|
del filenames[filenames.index(f)]
|
|
|
|
|
|
|
|
self.testgroups[dirname] = testgroup
|
|
|
|
self.testgroups[dirname].tests = sorted(filenames)
|
|
|
|
|
2018-12-03 21:38:06 +03:00
|
|
|
testgroup.verify()
|
2015-07-02 01:23:09 +03:00
|
|
|
|
2021-12-01 20:38:53 +03:00
|
|
|
def filter(self, keeplist):
|
|
|
|
for group in list(self.testgroups.keys()):
|
|
|
|
if group not in keeplist:
|
|
|
|
del self.testgroups[group]
|
|
|
|
continue
|
|
|
|
|
|
|
|
g = self.testgroups[group]
|
|
|
|
|
|
|
|
if g.pre and os.path.basename(g.pre) in keeplist[group]:
|
|
|
|
continue
|
|
|
|
|
|
|
|
g.filter(keeplist[group])
|
|
|
|
|
|
|
|
for test in list(self.tests.keys()):
|
|
|
|
directory, base = os.path.split(test)
|
|
|
|
if directory not in keeplist or base not in keeplist[directory]:
|
|
|
|
del self.tests[test]
|
|
|
|
|
2018-12-03 21:38:06 +03:00
|
|
|
def read(self, options):
|
2015-07-02 01:23:09 +03:00
|
|
|
"""
|
2019-10-09 20:39:26 +03:00
|
|
|
Read in the specified runfiles, and apply the TestRun properties
|
2015-07-02 01:23:09 +03:00
|
|
|
listed in the 'DEFAULT' section to our TestRun. Then read each
|
|
|
|
section, and apply the appropriate properties to the Test or
|
|
|
|
TestGroup. Properties from individual sections override those set
|
|
|
|
in the 'DEFAULT' section. If the Test or TestGroup passes
|
|
|
|
verification, add it to the TestRun.
|
|
|
|
"""
|
2018-09-26 21:02:26 +03:00
|
|
|
config = configparser.RawConfigParser()
|
2019-10-09 20:39:26 +03:00
|
|
|
parsed = config.read(options.runfiles)
|
|
|
|
failed = options.runfiles - set(parsed)
|
|
|
|
if len(failed):
|
|
|
|
files = ' '.join(sorted(failed))
|
|
|
|
fail("Couldn't read config files: %s" % files)
|
2015-07-02 01:23:09 +03:00
|
|
|
|
|
|
|
for opt in TestRun.props:
|
|
|
|
if config.has_option('DEFAULT', opt):
|
|
|
|
setattr(self, opt, config.get('DEFAULT', opt))
|
|
|
|
self.outputdir = os.path.join(self.outputdir, self.timestamp)
|
|
|
|
|
2020-03-10 21:00:56 +03:00
|
|
|
testdir = options.testdir
|
|
|
|
|
2015-07-02 01:23:09 +03:00
|
|
|
for section in config.sections():
|
|
|
|
if 'tests' in config.options(section):
|
2019-10-09 20:39:26 +03:00
|
|
|
parts = section.split(':', 1)
|
|
|
|
sectiondir = parts[0]
|
|
|
|
identifier = parts[1] if len(parts) == 2 else None
|
|
|
|
if os.path.isdir(sectiondir):
|
|
|
|
pathname = sectiondir
|
2020-03-10 21:00:56 +03:00
|
|
|
elif os.path.isdir(os.path.join(testdir, sectiondir)):
|
|
|
|
pathname = os.path.join(testdir, sectiondir)
|
2015-07-02 01:23:09 +03:00
|
|
|
else:
|
2019-10-09 20:39:26 +03:00
|
|
|
pathname = sectiondir
|
2015-07-02 01:23:09 +03:00
|
|
|
|
2019-10-09 20:39:26 +03:00
|
|
|
testgroup = TestGroup(os.path.abspath(pathname),
|
|
|
|
identifier=identifier)
|
2015-07-02 01:23:09 +03:00
|
|
|
for prop in TestGroup.props:
|
2016-08-30 22:01:41 +03:00
|
|
|
for sect in ['DEFAULT', section]:
|
|
|
|
if config.has_option(sect, prop):
|
2020-03-10 21:00:56 +03:00
|
|
|
if prop == 'tags':
|
2017-11-03 19:53:32 +03:00
|
|
|
setattr(testgroup, prop,
|
|
|
|
eval(config.get(sect, prop)))
|
2020-03-10 21:00:56 +03:00
|
|
|
elif prop == 'failsafe':
|
|
|
|
failsafe = config.get(sect, prop)
|
|
|
|
setattr(testgroup, prop,
|
|
|
|
os.path.join(testdir, failsafe))
|
2017-11-03 19:53:32 +03:00
|
|
|
else:
|
|
|
|
setattr(testgroup, prop,
|
|
|
|
config.get(sect, prop))
|
2015-07-02 01:23:09 +03:00
|
|
|
|
|
|
|
# Repopulate tests using eval to convert the string to a list
|
|
|
|
testgroup.tests = eval(config.get(section, 'tests'))
|
|
|
|
|
2018-12-03 21:38:06 +03:00
|
|
|
if testgroup.verify():
|
2015-07-02 01:23:09 +03:00
|
|
|
self.testgroups[section] = testgroup
|
|
|
|
else:
|
|
|
|
test = Test(section)
|
|
|
|
for prop in Test.props:
|
2016-08-30 22:01:41 +03:00
|
|
|
for sect in ['DEFAULT', section]:
|
|
|
|
if config.has_option(sect, prop):
|
2020-03-10 21:00:56 +03:00
|
|
|
if prop == 'failsafe':
|
|
|
|
failsafe = config.get(sect, prop)
|
|
|
|
setattr(test, prop,
|
|
|
|
os.path.join(testdir, failsafe))
|
|
|
|
else:
|
|
|
|
setattr(test, prop, config.get(sect, prop))
|
2016-08-30 22:01:41 +03:00
|
|
|
|
2018-12-03 21:38:06 +03:00
|
|
|
if test.verify():
|
2015-07-02 01:23:09 +03:00
|
|
|
self.tests[section] = test
|
|
|
|
|
|
|
|
def write(self, options):
|
|
|
|
"""
|
|
|
|
Create a configuration file for editing and later use. The
|
|
|
|
'DEFAULT' section of the config file is created from the
|
|
|
|
properties that were specified on the command line. Tests are
|
|
|
|
simply added as sections that inherit everything from the
|
|
|
|
'DEFAULT' section. TestGroups are the same, except they get an
|
|
|
|
option including all the tests to run in that directory.
|
|
|
|
"""
|
|
|
|
|
|
|
|
defaults = dict([(prop, getattr(options, prop)) for prop, _ in
|
2016-08-30 22:01:41 +03:00
|
|
|
self.defaults])
|
2018-09-26 21:02:26 +03:00
|
|
|
config = configparser.RawConfigParser(defaults)
|
2015-07-02 01:23:09 +03:00
|
|
|
|
|
|
|
for test in sorted(self.tests.keys()):
|
|
|
|
config.add_section(test)
|
2021-12-01 20:38:53 +03:00
|
|
|
for prop in Test.props:
|
|
|
|
if prop not in self.props:
|
|
|
|
config.set(test, prop,
|
|
|
|
getattr(self.tests[test], prop))
|
2015-07-02 01:23:09 +03:00
|
|
|
|
|
|
|
for testgroup in sorted(self.testgroups.keys()):
|
|
|
|
config.add_section(testgroup)
|
|
|
|
config.set(testgroup, 'tests', self.testgroups[testgroup].tests)
|
2021-12-01 20:38:53 +03:00
|
|
|
for prop in TestGroup.props:
|
|
|
|
if prop not in self.props:
|
|
|
|
config.set(testgroup, prop,
|
|
|
|
getattr(self.testgroups[testgroup], prop))
|
2015-07-02 01:23:09 +03:00
|
|
|
|
|
|
|
try:
|
|
|
|
with open(options.template, 'w') as f:
|
|
|
|
return config.write(f)
|
|
|
|
except IOError:
|
|
|
|
fail('Could not open \'%s\' for writing.' % options.template)
|
|
|
|
|
2016-08-30 22:01:41 +03:00
|
|
|
def complete_outputdirs(self):
|
2015-07-02 01:23:09 +03:00
|
|
|
"""
|
|
|
|
Collect all the pathnames for Tests, and TestGroups. Work
|
|
|
|
backwards one pathname component at a time, to create a unique
|
|
|
|
directory name in which to deposit test output. Tests will be able
|
|
|
|
to write output files directly in the newly modified outputdir.
|
|
|
|
TestGroups will be able to create one subdirectory per test in the
|
|
|
|
outputdir, and are guaranteed uniqueness because a group can only
|
|
|
|
contain files in one directory. Pre and post tests will create a
|
|
|
|
directory rooted at the outputdir of the Test or TestGroup in
|
2020-03-10 21:00:56 +03:00
|
|
|
question for their output. Failsafe scripts will create a directory
|
|
|
|
rooted at the outputdir of each Test for their output.
|
2015-07-02 01:23:09 +03:00
|
|
|
"""
|
|
|
|
done = False
|
|
|
|
components = 0
|
2018-09-26 21:02:26 +03:00
|
|
|
tmp_dict = dict(list(self.tests.items()) +
|
|
|
|
list(self.testgroups.items()))
|
2015-07-02 01:23:09 +03:00
|
|
|
total = len(tmp_dict)
|
|
|
|
base = self.outputdir
|
|
|
|
|
|
|
|
while not done:
|
2017-10-24 00:01:43 +03:00
|
|
|
paths = []
|
2015-07-02 01:23:09 +03:00
|
|
|
components -= 1
|
2018-09-26 21:02:26 +03:00
|
|
|
for testfile in list(tmp_dict.keys()):
|
2015-07-02 01:23:09 +03:00
|
|
|
uniq = '/'.join(testfile.split('/')[components:]).lstrip('/')
|
2017-10-24 00:01:43 +03:00
|
|
|
if uniq not in paths:
|
|
|
|
paths.append(uniq)
|
2015-07-02 01:23:09 +03:00
|
|
|
tmp_dict[testfile].outputdir = os.path.join(base, uniq)
|
|
|
|
else:
|
|
|
|
break
|
2017-10-24 00:01:43 +03:00
|
|
|
done = total == len(paths)
|
2015-07-02 01:23:09 +03:00
|
|
|
|
|
|
|
def setup_logging(self, options):
|
|
|
|
"""
|
2019-09-03 04:17:39 +03:00
|
|
|
This function creates the output directory and gets a file object
|
2018-12-03 21:38:06 +03:00
|
|
|
for the logfile. This function must be called before write_log()
|
|
|
|
can be used.
|
2015-07-02 01:23:09 +03:00
|
|
|
"""
|
|
|
|
if options.dryrun is True:
|
|
|
|
return
|
|
|
|
|
2018-12-03 21:38:06 +03:00
|
|
|
global LOG_FILE_OBJ
|
2021-12-01 20:38:53 +03:00
|
|
|
if not options.template:
|
2015-07-02 01:23:09 +03:00
|
|
|
try:
|
|
|
|
old = os.umask(0)
|
2018-09-26 21:02:26 +03:00
|
|
|
os.makedirs(self.outputdir, mode=0o777)
|
2015-07-02 01:23:09 +03:00
|
|
|
os.umask(old)
|
2018-12-03 21:38:06 +03:00
|
|
|
filename = os.path.join(self.outputdir, 'log')
|
|
|
|
LOG_FILE_OBJ = open(filename, buffering=0, mode='wb')
|
2018-09-26 21:02:26 +03:00
|
|
|
except OSError as e:
|
2015-07-02 01:23:09 +03:00
|
|
|
fail('%s' % e)
|
|
|
|
|
|
|
|
def run(self, options):
|
|
|
|
"""
|
|
|
|
Walk through all the Tests and TestGroups, calling run().
|
|
|
|
"""
|
|
|
|
try:
|
|
|
|
os.chdir(self.outputdir)
|
|
|
|
except OSError:
|
|
|
|
fail('Could not change to directory %s' % self.outputdir)
|
2016-10-24 20:24:10 +03:00
|
|
|
# make a symlink to the output for the currently running test
|
|
|
|
logsymlink = os.path.join(self.outputdir, '../current')
|
2016-10-18 20:19:28 +03:00
|
|
|
if os.path.islink(logsymlink):
|
|
|
|
os.unlink(logsymlink)
|
|
|
|
if not os.path.exists(logsymlink):
|
|
|
|
os.symlink(self.outputdir, logsymlink)
|
|
|
|
else:
|
2018-12-03 21:38:06 +03:00
|
|
|
write_log('Could not make a symlink to directory %s\n' %
|
|
|
|
self.outputdir, LOG_ERR)
|
2022-02-24 21:21:13 +03:00
|
|
|
|
|
|
|
if options.kmemleak:
|
2022-03-14 03:41:03 +03:00
|
|
|
cmd = f'{SUDO} -c "echo scan=0 > {KMEMLEAK_FILE}"'
|
2022-02-24 21:21:13 +03:00
|
|
|
check_output(cmd, shell=True)
|
|
|
|
|
2017-11-03 19:53:32 +03:00
|
|
|
iteration = 0
|
|
|
|
while iteration < options.iterations:
|
|
|
|
for test in sorted(self.tests.keys()):
|
2018-12-03 21:38:06 +03:00
|
|
|
self.tests[test].run(options)
|
2017-11-03 19:53:32 +03:00
|
|
|
for testgroup in sorted(self.testgroups.keys()):
|
2018-12-03 21:38:06 +03:00
|
|
|
self.testgroups[testgroup].run(options)
|
2017-11-03 19:53:32 +03:00
|
|
|
iteration += 1
|
2015-07-02 01:23:09 +03:00
|
|
|
|
|
|
|
def summary(self):
|
2019-02-04 20:02:46 +03:00
|
|
|
if Result.total == 0:
|
2017-06-30 21:14:26 +03:00
|
|
|
return 2
|
2015-07-02 01:23:09 +03:00
|
|
|
|
2018-09-26 21:02:26 +03:00
|
|
|
print('\nResults Summary')
|
|
|
|
for key in list(Result.runresults.keys()):
|
2019-02-04 20:02:46 +03:00
|
|
|
if Result.runresults[key] != 0:
|
2018-09-26 21:02:26 +03:00
|
|
|
print('%s\t% 4d' % (key, Result.runresults[key]))
|
2015-07-02 01:23:09 +03:00
|
|
|
|
|
|
|
m, s = divmod(time() - self.starttime, 60)
|
|
|
|
h, m = divmod(m, 60)
|
2018-09-26 21:02:26 +03:00
|
|
|
print('\nRunning Time:\t%02d:%02d:%02d' % (h, m, s))
|
|
|
|
print('Percent passed:\t%.1f%%' % ((float(Result.runresults['PASS']) /
|
|
|
|
float(Result.total)) * 100))
|
|
|
|
print('Log directory:\t%s' % self.outputdir)
|
2015-07-02 01:23:09 +03:00
|
|
|
|
2017-06-30 21:14:26 +03:00
|
|
|
if Result.runresults['FAIL'] > 0:
|
|
|
|
return 1
|
2017-07-08 03:07:40 +03:00
|
|
|
|
|
|
|
if Result.runresults['KILLED'] > 0:
|
|
|
|
return 1
|
|
|
|
|
2019-04-11 20:20:37 +03:00
|
|
|
if Result.runresults['RERAN'] > 0:
|
|
|
|
return 3
|
|
|
|
|
2017-06-30 21:14:26 +03:00
|
|
|
return 0
|
|
|
|
|
2015-07-02 01:23:09 +03:00
|
|
|
|
2018-12-03 21:38:06 +03:00
|
|
|
def write_log(msg, target):
|
|
|
|
"""
|
|
|
|
Write the provided message to standard out, standard error or
|
|
|
|
the logfile. If specifying LOG_FILE, then `msg` must be a bytes
|
|
|
|
like object. This way we can still handle output from tests that
|
|
|
|
may be in unexpected encodings.
|
|
|
|
"""
|
|
|
|
if target == LOG_OUT:
|
|
|
|
os.write(sys.stdout.fileno(), bytearray(msg, encoding='utf-8'))
|
|
|
|
elif target == LOG_ERR:
|
|
|
|
os.write(sys.stderr.fileno(), bytearray(msg, encoding='utf-8'))
|
|
|
|
elif target == LOG_FILE:
|
|
|
|
os.write(LOG_FILE_OBJ.fileno(), msg)
|
|
|
|
else:
|
|
|
|
fail('log_msg called with unknown target "%s"' % target)
|
|
|
|
|
|
|
|
|
2015-07-02 01:23:09 +03:00
|
|
|
def verify_file(pathname):
|
|
|
|
"""
|
|
|
|
Verify that the supplied pathname is an executable regular file.
|
|
|
|
"""
|
|
|
|
if os.path.isdir(pathname) or os.path.islink(pathname):
|
|
|
|
return False
|
|
|
|
|
2016-10-06 20:11:06 +03:00
|
|
|
for ext in '', '.ksh', '.sh':
|
|
|
|
script_path = pathname + ext
|
|
|
|
if os.path.isfile(script_path) and os.access(script_path, os.X_OK):
|
|
|
|
return True
|
2015-07-02 01:23:09 +03:00
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
2018-12-03 21:38:06 +03:00
|
|
|
def verify_user(user):
|
2015-07-02 01:23:09 +03:00
|
|
|
"""
|
|
|
|
Verify that the specified user exists on this system, and can execute
|
|
|
|
sudo without being prompted for a password.
|
|
|
|
"""
|
|
|
|
testcmd = [SUDO, '-n', '-u', user, TRUE]
|
|
|
|
|
|
|
|
if user in Cmd.verified_users:
|
|
|
|
return True
|
|
|
|
|
|
|
|
try:
|
2016-10-06 20:11:06 +03:00
|
|
|
getpwnam(user)
|
2015-07-02 01:23:09 +03:00
|
|
|
except KeyError:
|
2018-12-03 21:38:06 +03:00
|
|
|
write_log("Warning: user '%s' does not exist.\n" % user,
|
|
|
|
LOG_ERR)
|
2015-07-02 01:23:09 +03:00
|
|
|
return False
|
|
|
|
|
|
|
|
p = Popen(testcmd)
|
|
|
|
p.wait()
|
2019-02-04 20:02:46 +03:00
|
|
|
if p.returncode != 0:
|
2018-12-03 21:38:06 +03:00
|
|
|
write_log("Warning: user '%s' cannot use passwordless sudo.\n" % user,
|
|
|
|
LOG_ERR)
|
2015-07-02 01:23:09 +03:00
|
|
|
return False
|
|
|
|
else:
|
|
|
|
Cmd.verified_users.append(user)
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
def find_tests(testrun, options):
|
|
|
|
"""
|
|
|
|
For the given list of pathnames, add files as Tests. For directories,
|
|
|
|
if do_groups is True, add the directory as a TestGroup. If False,
|
|
|
|
recursively search for executable files.
|
|
|
|
"""
|
|
|
|
|
|
|
|
for p in sorted(options.pathnames):
|
|
|
|
if os.path.isdir(p):
|
|
|
|
for dirname, _, filenames in os.walk(p):
|
|
|
|
if options.do_groups:
|
|
|
|
testrun.addtestgroup(dirname, filenames, options)
|
|
|
|
else:
|
|
|
|
for f in sorted(filenames):
|
|
|
|
testrun.addtest(os.path.join(dirname, f), options)
|
|
|
|
else:
|
|
|
|
testrun.addtest(p, options)
|
|
|
|
|
|
|
|
|
2021-12-01 20:38:53 +03:00
|
|
|
def filter_tests(testrun, options):
|
|
|
|
try:
|
|
|
|
fh = open(options.logfile, "r")
|
|
|
|
except Exception as e:
|
|
|
|
fail('%s' % e)
|
|
|
|
|
|
|
|
failed = {}
|
|
|
|
while True:
|
|
|
|
line = fh.readline()
|
|
|
|
if not line:
|
|
|
|
break
|
|
|
|
m = re.match(r'Test: .*(tests/.*)/(\S+).*\[FAIL\]', line)
|
|
|
|
if not m:
|
|
|
|
continue
|
|
|
|
group, test = m.group(1, 2)
|
|
|
|
try:
|
|
|
|
failed[group].append(test)
|
|
|
|
except KeyError:
|
|
|
|
failed[group] = [test]
|
|
|
|
fh.close()
|
|
|
|
|
|
|
|
testrun.filter(failed)
|
|
|
|
|
|
|
|
|
2015-07-02 01:23:09 +03:00
|
|
|
def fail(retstr, ret=1):
|
2018-12-03 21:38:06 +03:00
|
|
|
print('%s: %s' % (sys.argv[0], retstr))
|
2015-07-02 01:23:09 +03:00
|
|
|
exit(ret)
|
|
|
|
|
|
|
|
|
2022-02-24 21:21:13 +03:00
|
|
|
def kmemleak_cb(option, opt_str, value, parser):
|
|
|
|
if not os.path.exists(KMEMLEAK_FILE):
|
|
|
|
fail(f"File '{KMEMLEAK_FILE}' doesn't exist. " +
|
|
|
|
"Enable CONFIG_DEBUG_KMEMLEAK in kernel configuration.")
|
|
|
|
|
|
|
|
setattr(parser.values, option.dest, True)
|
|
|
|
|
|
|
|
|
2015-07-02 01:23:09 +03:00
|
|
|
def options_cb(option, opt_str, value, parser):
|
2021-12-01 20:38:53 +03:00
|
|
|
path_options = ['outputdir', 'template', 'testdir', 'logfile']
|
2015-07-02 01:23:09 +03:00
|
|
|
|
|
|
|
if opt_str in parser.rargs:
|
|
|
|
fail('%s may only be specified once.' % opt_str)
|
|
|
|
|
2019-10-09 20:39:26 +03:00
|
|
|
if option.dest == 'runfiles':
|
2015-07-02 01:23:09 +03:00
|
|
|
parser.values.cmd = 'rdconfig'
|
2019-10-09 20:39:26 +03:00
|
|
|
value = set(os.path.abspath(p) for p in value.split(','))
|
2019-02-04 20:02:46 +03:00
|
|
|
if option.dest == 'tags':
|
2017-11-03 19:53:32 +03:00
|
|
|
value = [x.strip() for x in value.split(',')]
|
2015-07-02 01:23:09 +03:00
|
|
|
|
|
|
|
if option.dest in path_options:
|
|
|
|
setattr(parser.values, option.dest, os.path.abspath(value))
|
2019-10-09 20:39:26 +03:00
|
|
|
else:
|
|
|
|
setattr(parser.values, option.dest, value)
|
2015-07-02 01:23:09 +03:00
|
|
|
|
|
|
|
|
|
|
|
def parse_args():
|
|
|
|
parser = OptionParser()
|
|
|
|
parser.add_option('-c', action='callback', callback=options_cb,
|
2019-10-09 20:39:26 +03:00
|
|
|
type='string', dest='runfiles', metavar='runfiles',
|
|
|
|
help='Specify tests to run via config files.')
|
2015-07-02 01:23:09 +03:00
|
|
|
parser.add_option('-d', action='store_true', default=False, dest='dryrun',
|
|
|
|
help='Dry run. Print tests, but take no other action.')
|
2024-04-16 19:13:01 +03:00
|
|
|
parser.add_option('-D', action='store_true', default=False, dest='debug',
|
|
|
|
help='Write all test output to stdout as it arrives.')
|
2021-12-01 20:38:53 +03:00
|
|
|
parser.add_option('-l', action='callback', callback=options_cb,
|
|
|
|
default=None, dest='logfile', metavar='logfile',
|
|
|
|
type='string',
|
|
|
|
help='Read logfile and re-run tests which failed.')
|
2015-07-02 01:23:09 +03:00
|
|
|
parser.add_option('-g', action='store_true', default=False,
|
|
|
|
dest='do_groups', help='Make directories TestGroups.')
|
|
|
|
parser.add_option('-o', action='callback', callback=options_cb,
|
|
|
|
default=BASEDIR, dest='outputdir', type='string',
|
|
|
|
metavar='outputdir', help='Specify an output directory.')
|
|
|
|
parser.add_option('-i', action='callback', callback=options_cb,
|
|
|
|
default=TESTDIR, dest='testdir', type='string',
|
|
|
|
metavar='testdir', help='Specify a test directory.')
|
2022-03-23 18:15:02 +03:00
|
|
|
parser.add_option('-K', action='store_true', default=False, dest='kmsg',
|
|
|
|
help='Log tests names to /dev/kmsg')
|
2022-02-24 21:21:13 +03:00
|
|
|
parser.add_option('-m', action='callback', callback=kmemleak_cb,
|
|
|
|
default=False, dest='kmemleak',
|
|
|
|
help='Enable kmemleak reporting (Linux only)')
|
2015-07-02 01:23:09 +03:00
|
|
|
parser.add_option('-p', action='callback', callback=options_cb,
|
|
|
|
default='', dest='pre', metavar='script',
|
|
|
|
type='string', help='Specify a pre script.')
|
|
|
|
parser.add_option('-P', action='callback', callback=options_cb,
|
|
|
|
default='', dest='post', metavar='script',
|
|
|
|
type='string', help='Specify a post script.')
|
|
|
|
parser.add_option('-q', action='store_true', default=False, dest='quiet',
|
|
|
|
help='Silence on the console during a test run.')
|
2020-03-10 21:00:56 +03:00
|
|
|
parser.add_option('-s', action='callback', callback=options_cb,
|
|
|
|
default='', dest='failsafe', metavar='script',
|
|
|
|
type='string', help='Specify a failsafe script.')
|
|
|
|
parser.add_option('-S', action='callback', callback=options_cb,
|
|
|
|
default='', dest='failsafe_user',
|
|
|
|
metavar='failsafe_user', type='string',
|
|
|
|
help='Specify a user to execute the failsafe script.')
|
2015-07-02 01:23:09 +03:00
|
|
|
parser.add_option('-t', action='callback', callback=options_cb, default=60,
|
|
|
|
dest='timeout', metavar='seconds', type='int',
|
|
|
|
help='Timeout (in seconds) for an individual test.')
|
|
|
|
parser.add_option('-u', action='callback', callback=options_cb,
|
|
|
|
default='', dest='user', metavar='user', type='string',
|
|
|
|
help='Specify a different user name to run as.')
|
|
|
|
parser.add_option('-w', action='callback', callback=options_cb,
|
|
|
|
default=None, dest='template', metavar='template',
|
|
|
|
type='string', help='Create a new config file.')
|
|
|
|
parser.add_option('-x', action='callback', callback=options_cb, default='',
|
|
|
|
dest='pre_user', metavar='pre_user', type='string',
|
|
|
|
help='Specify a user to execute the pre script.')
|
|
|
|
parser.add_option('-X', action='callback', callback=options_cb, default='',
|
|
|
|
dest='post_user', metavar='post_user', type='string',
|
|
|
|
help='Specify a user to execute the post script.')
|
2017-11-03 19:53:32 +03:00
|
|
|
parser.add_option('-T', action='callback', callback=options_cb, default='',
|
|
|
|
dest='tags', metavar='tags', type='string',
|
|
|
|
help='Specify tags to execute specific test groups.')
|
|
|
|
parser.add_option('-I', action='callback', callback=options_cb, default=1,
|
|
|
|
dest='iterations', metavar='iterations', type='int',
|
|
|
|
help='Number of times to run the test run.')
|
2015-07-02 01:23:09 +03:00
|
|
|
(options, pathnames) = parser.parse_args()
|
|
|
|
|
2019-10-09 20:39:26 +03:00
|
|
|
if options.runfiles and len(pathnames):
|
2015-07-02 01:23:09 +03:00
|
|
|
fail('Extraneous arguments.')
|
|
|
|
|
|
|
|
options.pathnames = [os.path.abspath(path) for path in pathnames]
|
|
|
|
|
|
|
|
return options
|
|
|
|
|
|
|
|
|
2016-08-30 22:01:41 +03:00
|
|
|
def main():
|
2015-07-02 01:23:09 +03:00
|
|
|
options = parse_args()
|
2021-12-01 20:38:53 +03:00
|
|
|
|
2015-07-02 01:23:09 +03:00
|
|
|
testrun = TestRun(options)
|
|
|
|
|
2021-12-01 20:38:53 +03:00
|
|
|
if options.runfiles:
|
2018-12-03 21:38:06 +03:00
|
|
|
testrun.read(options)
|
2021-12-01 20:38:53 +03:00
|
|
|
else:
|
2015-07-02 01:23:09 +03:00
|
|
|
find_tests(testrun, options)
|
2021-12-01 20:38:53 +03:00
|
|
|
|
|
|
|
if options.logfile:
|
|
|
|
filter_tests(testrun, options)
|
|
|
|
|
|
|
|
if options.template:
|
2015-07-02 01:23:09 +03:00
|
|
|
testrun.write(options)
|
|
|
|
exit(0)
|
|
|
|
|
2016-08-30 22:01:41 +03:00
|
|
|
testrun.complete_outputdirs()
|
2015-07-02 01:23:09 +03:00
|
|
|
testrun.run(options)
|
2017-06-30 21:14:26 +03:00
|
|
|
exit(testrun.summary())
|
2015-07-02 01:23:09 +03:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2016-08-30 22:01:41 +03:00
|
|
|
main()
|