Skip to content

Commit d307c5e

Browse files
committed
9pm.py: add new repeat option (-r)
Repeats all test and suites passed on command line N times. Signed-off-by: Richard Alpe <[email protected]>
1 parent 6648c5b commit d307c5e

File tree

2 files changed

+49
-12
lines changed

2 files changed

+49
-12
lines changed

9pm.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,8 @@ def parse_cmdline():
654654
help='(TEST) Enable test case debug')
655655
parser.add_argument('-o', '--option', action='append', default=[],
656656
help='(TEST) Option(s) passed to all test cases (can be repeated)')
657+
parser.add_argument('-r', '--repeat', type=int, default=1,
658+
help='(TEST) Number of times to repeat the test (default: 1)')
657659
parser.add_argument('suites', nargs='+', metavar='TEST|SUITE',
658660
help='Test or suite to run')
659661
if len(sys.argv) == 1:
@@ -728,20 +730,21 @@ def pr_proj_info(proj):
728730

729731
def create_base_suite(args):
730732
suite = {'name': 'command-line', 'suite': []}
731-
for filename in args.suites:
732-
fpath = os.path.join(os.getcwd(), filename)
733-
if filename.endswith('.yaml'):
734-
suite['suite'].append(parse_suite(fpath, "command-line", args.option, {}))
735-
else:
736-
test = {}
737-
test['case'] = fpath
738-
test['name'] = gen_name(filename)
739-
test['outfile'] = gen_outfile(test['name'])
733+
for _ in range(args.repeat):
734+
for filename in args.suites:
735+
fpath = os.path.join(os.getcwd(), filename)
736+
if filename.endswith('.yaml'):
737+
suite['suite'].append(parse_suite(fpath, "command-line", args.option, {}))
738+
else:
739+
test = {}
740+
test['case'] = fpath
741+
test['name'] = gen_name(filename)
742+
test['outfile'] = gen_outfile(test['name'])
740743

741-
if args.option:
742-
test["options"] = args.option
744+
if args.option:
745+
test["options"] = args.option
743746

744-
suite['suite'].append(test)
747+
suite['suite'].append(test)
745748
return suite
746749

747750
def main():

self_test/run.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,39 @@ def test_abort_flag(self):
278278

279279
self.run(["cases/fail.sh", "cases/pass.sh"], ["--abort"], 1, "Aborting execution")
280280

281+
def test_repeat_flag(self):
282+
"""Verify that -r (--repeat) works"""
283+
284+
self.test(
285+
{
286+
"desc": "Repeate two tests two times",
287+
"args": ["-r", "2"],
288+
"tests": ["cases/worker.py", "cases/worker1.py"],
289+
"expected": [
290+
{"name": "0001-worker", "args": []},
291+
{"name": "0002-worker1", "args": []},
292+
{"name": "0003-worker", "args": []},
293+
{"name": "0004-worker1", "args": []}
294+
],
295+
}
296+
)
297+
self.test(
298+
{
299+
"desc": "Repeate suite and test two times",
300+
"args": ["-r", "2"],
301+
"tests": ["suites/suite.yaml", "cases/worker1.py"],
302+
"expected": [
303+
{"name": "0002-worker", "args": []},
304+
{"name": "0003-worker", "args": []},
305+
{"name": "0004-worker1", "args": []},
306+
{"name": "0007-worker", "args": []},
307+
{"name": "0008-worker", "args": []},
308+
{"name": "0009-worker1", "args": []},
309+
{"name": "0010-worker1", "args": []}
310+
],
311+
}
312+
)
313+
281314
def cleanup(self):
282315
"""Cleanup temp directory after tests"""
283316
self.temp_dir_base.cleanup()
@@ -305,6 +338,7 @@ def cleanup(self):
305338
tester.test_config_file()
306339
tester.test_verbose_flag()
307340
tester.test_abort_flag()
341+
tester.test_repeat_flag()
308342
print_green("All tests passed.")
309343
finally:
310344
tester.cleanup()

0 commit comments

Comments
 (0)