test-runner: add iwmon options

This extends test-runner to also use iwmon if --log is enabled.
For this case the iwmon log will be found inside each test
log directory.

A new option, --monitor <file> was added in case full logging isn't
desired (potentially for timing issues) but a iwmon log is needed.
Be aware that when --monitor is used test-runner will mount the
entire parent directory. test-runner itself will only write to the
file specified, but just know that the parent directory is available
as read-write inside the VM.

--log takes precedence over --monitor, meaning the iwmon log will
be written to <logdir>/<test>/iwmon instead of the file specified
with --monitor if both options are provided.
This commit is contained in:
James Prestwood 2020-09-25 13:52:33 -07:00 committed by Denis Kenzior
parent c51e187462
commit 1a02fdcefd
1 changed files with 30 additions and 1 deletions

View File

@ -163,7 +163,8 @@ class Process:
run over the entire test run and will not be killed after each run over the entire test run and will not be killed after each
test exits. test exits.
''' '''
def __init__(self, args, wait=False, multi_test=False, env=None, ctx=None, check=False): def __init__(self, args, wait=False, multi_test=False, env=None, ctx=None, check=False,
outfile=None):
self.args = args self.args = args
self.wait = wait self.wait = wait
self.name = args[0] self.name = args[0]
@ -185,6 +186,9 @@ class Process:
self.args.extend(args) self.args.extend(args)
set_stdout = True set_stdout = True
if outfile:
set_stdout = True
# Anything labeled as multi_test isn't important to # Anything labeled as multi_test isn't important to
# log. These are processes such as dbus-daemon and # log. These are processes such as dbus-daemon and
# haveged. # haveged.
@ -200,6 +204,9 @@ class Process:
self.stdout = open('%s/%s' % (test_dir, args[0]), 'w') self.stdout = open('%s/%s' % (test_dir, args[0]), 'w')
self.stderr = open('%s/%s' % (test_dir, args[0]), 'w') self.stderr = open('%s/%s' % (test_dir, args[0]), 'w')
elif outfile:
self.stdout = open(outfile, 'w')
self.stderr = open(outfile, 'w')
else: else:
self.stdout = sys.__stdout__ self.stdout = sys.__stdout__
self.stderr = sys.__stderr__ self.stderr = sys.__stderr__
@ -872,6 +879,11 @@ def pre_test(ctx, test):
ctx.start_hostapd() ctx.start_hostapd()
ctx.start_ofono() ctx.start_ofono()
if ctx.args.log:
ctx.start_process(['iwmon'])
elif ctx.args.monitor:
ctx.start_process(['iwmon'], outfile=ctx.args.monitor)
if ctx.hw_config.has_option('SETUP', 'start_iwd'): if ctx.hw_config.has_option('SETUP', 'start_iwd'):
start = ctx.hw_config.getboolean('SETUP', 'start_iwd') start = ctx.hw_config.getboolean('SETUP', 'start_iwd')
else: else:
@ -1028,6 +1040,7 @@ def run_tests():
parser.add_argument('--log-gid') parser.add_argument('--log-gid')
parser.add_argument('--log-uid') parser.add_argument('--log-uid')
parser.add_argument('--hw') parser.add_argument('--hw')
parser.add_argument('--monitor')
args = parser.parse_args(options) args = parser.parse_args(options)
@ -1057,6 +1070,9 @@ def run_tests():
if args.log: if args.log:
mount('logdir', args.log, '9p', 0, 'trans=virtio,version=9p2000.L') mount('logdir', args.log, '9p', 0, 'trans=virtio,version=9p2000.L')
elif args.monitor:
parent = os.path.abspath(os.path.join(args.monitor, os.pardir))
mount('mondir', parent, '9p', 0, 'trans=virtio,version=9p2000.L')
if config.ctx.args.unit_tests is None: if config.ctx.args.unit_tests is None:
run_auto_tests(config.ctx, args) run_auto_tests(config.ctx, args)
@ -1091,6 +1107,8 @@ class Main:
help='Directory for log files') help='Directory for log files')
self.parser.add_argument('--hw', '-w', type=str, nargs=1, self.parser.add_argument('--hw', '-w', type=str, nargs=1,
help='Use physical adapters for tests (passthrough)') help='Use physical adapters for tests (passthrough)')
self.parser.add_argument('--monitor', '-m', type=str,
help='Enables iwmon output to file')
# Prevent --autotest/--unittest from being used together # Prevent --autotest/--unittest from being used together
auto_unit_group = self.parser.add_mutually_exclusive_group() auto_unit_group = self.parser.add_mutually_exclusive_group()
@ -1199,6 +1217,10 @@ class Main:
options += ' --log-gid %u' % gid options += ' --log-gid %u' % gid
options += ' --log-uid %u' % uid options += ' --log-uid %u' % uid
if self.args.monitor:
self.args.monitor = os.path.abspath(self.args.monitor)
mon_parent_dir = os.path.abspath(os.path.join(self.args.monitor, os.pardir))
denylist = [ denylist = [
'auto_tests', 'auto_tests',
'qemu', 'qemu',
@ -1271,6 +1293,13 @@ class Main:
% self.args.log % self.args.log
]) ])
if self.args.monitor:
qemu_cmdline.extend([
'-virtfs',
'local,path=%s,mount_tag=mondir,security_model=passthrough,id=mondir' \
% mon_parent_dir
])
os.execlp(qemu_cmdline[0], *qemu_cmdline) os.execlp(qemu_cmdline[0], *qemu_cmdline)
if __name__ == '__main__': if __name__ == '__main__':