mirror of
https://git.kernel.org/pub/scm/network/wireless/iwd.git
synced 2024-11-22 06:29:23 +01:00
test-runner: add option to write final status to file
Running the tests inside a VM makes it difficult for the host to figure out if the test actually failed or succeeded. For a human its easy to read the results table, but for an automated system parsing this would be fragile. This adds a new option --result <file> which writes PASS/FAIL to the provided file once all tests are completed. Any failures results in 'FAIL' being written to the file.
This commit is contained in:
parent
0e23eafdfc
commit
064b98e27f
@ -62,7 +62,14 @@ def exit_vm():
|
||||
p.kill()
|
||||
|
||||
if config.ctx and config.ctx.results:
|
||||
print_results(config.ctx.results)
|
||||
success = print_results(config.ctx.results)
|
||||
else:
|
||||
success = False
|
||||
|
||||
if config.ctx.args.result:
|
||||
result = 'PASS' if success else 'FAIL'
|
||||
with open(config.ctx.args.result, 'w') as f:
|
||||
f.write(result)
|
||||
|
||||
os.sync()
|
||||
|
||||
@ -1434,6 +1441,8 @@ def print_results(results):
|
||||
|
||||
dbg(table)
|
||||
|
||||
return total_fail == 0
|
||||
|
||||
def run_auto_tests(ctx, args):
|
||||
tests = build_test_list(args)
|
||||
|
||||
@ -1528,6 +1537,7 @@ def run_tests():
|
||||
parser.add_argument('--hw')
|
||||
parser.add_argument('--monitor')
|
||||
parser.add_argument('--sub_tests')
|
||||
parser.add_argument('--result')
|
||||
|
||||
args = parser.parse_args(options)
|
||||
|
||||
@ -1580,6 +1590,10 @@ def run_tests():
|
||||
parent = os.path.abspath(os.path.join(args.monitor, os.pardir))
|
||||
mount('mondir', parent, '9p', 0, 'trans=virtio,version=9p2000.L,msize=10240')
|
||||
|
||||
if args.result:
|
||||
parent = os.path.abspath(os.path.join(args.result, os.pardir))
|
||||
mount('resultdir', parent, '9p', 0, 'trans=virtio,version=9p2000.L,msize=10240')
|
||||
|
||||
if config.ctx.args.unit_tests is None:
|
||||
run_auto_tests(config.ctx, args)
|
||||
else:
|
||||
@ -1620,6 +1634,8 @@ class Main:
|
||||
self.parser.add_argument('--sub-tests', '-S', metavar='<subtests>',
|
||||
type=str, nargs=1, help='List of subtests to run',
|
||||
default=None, dest='sub_tests')
|
||||
self.parser.add_argument('--result', '-r', type=str,
|
||||
help='Writes PASS/FAIL to results file')
|
||||
|
||||
# Prevent --autotest/--unittest from being used together
|
||||
auto_unit_group = self.parser.add_mutually_exclusive_group()
|
||||
@ -1767,6 +1783,20 @@ class Main:
|
||||
options += ' --log-gid %u' % int(os.environ['SUDO_GID'])
|
||||
options += ' --log-uid %u' % int(os.environ['SUDO_UID'])
|
||||
|
||||
if self.args.result:
|
||||
if os.environ.get('SUDO_GID', None) is None:
|
||||
print("--result can only be used as root user")
|
||||
quit()
|
||||
|
||||
self.args.result = os.path.abspath(self.args.result)
|
||||
result_parent_dir = os.path.abspath(os.path.join(self.args.result, os.pardir))
|
||||
|
||||
if '--log-gid' not in options:
|
||||
options += ' --log-gid %u' % int(os.environ['SUDO_GID'])
|
||||
|
||||
if '--log-uid' not in options:
|
||||
options += ' --log-uid %u' % int(os.environ['SUDO_UID'])
|
||||
|
||||
denylist = [
|
||||
'auto_tests',
|
||||
'sub_tests',
|
||||
@ -1873,6 +1903,13 @@ class Main:
|
||||
% mon_parent_dir
|
||||
])
|
||||
|
||||
if self.args.result:
|
||||
qemu_cmdline.extend([
|
||||
'-virtfs',
|
||||
'local,path=%s,mount_tag=resultdir,security_model=passthrough,id=resultdir' \
|
||||
% result_parent_dir
|
||||
])
|
||||
|
||||
os.execlp(qemu_cmdline[0], *qemu_cmdline)
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
Loading…
Reference in New Issue
Block a user