Skip to content

Commit 183ef65

Browse files
committed
WIP: Add support for repeating tests with different seeds.
1 parent ce51561 commit 183ef65

File tree

2 files changed

+36
-18
lines changed

2 files changed

+36
-18
lines changed

vunit/ui/__init__.py

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,8 @@ def _main(self, post_run):
749749
if self._args.compile:
750750
return self._main_compile_only()
751751

752-
all_ok = self._main_run(post_run)
752+
all_ok = self._main_run(post_run, n_iterations=self._args.repeat + 1)
753+
753754
return all_ok
754755

755756
def _create_simulator_if(self):
@@ -770,7 +771,7 @@ def _create_simulator_if(self):
770771

771772
return self._simulator_class.from_args(args=self._args, output_path=self._simulator_output_path)
772773

773-
def _main_run(self, post_run):
774+
def _main_run(self, post_run, n_iterations):
774775
"""
775776
Main with running tests
776777
"""
@@ -779,30 +780,35 @@ def _main_run(self, post_run):
779780
self._compile(simulator_if)
780781
print()
781782

782-
start_time = ostools.get_time()
783-
report = TestReport(printer=self._printer)
783+
all_ok = True
784+
for iteration in range(1, n_iterations + 1):
785+
start_time = ostools.get_time()
786+
report = TestReport(printer=self._printer)
784787

785-
try:
786-
self._run_test(test_list, report)
787-
except KeyboardInterrupt:
788-
print()
789-
LOGGER.debug("_main: Caught Ctrl-C shutting down")
790-
finally:
791-
del test_list
788+
try:
789+
self._run_test(test_list, report, iteration)
790+
except KeyboardInterrupt:
791+
print()
792+
LOGGER.debug("_main: Caught Ctrl-C shutting down")
793+
finally:
794+
if (sys.exc_info()[0] is not None) or (iteration == n_iterations):
795+
del test_list
792796

793-
report.set_real_total_time(ostools.get_time() - start_time)
794-
report.print_str()
797+
report.set_real_total_time(ostools.get_time() - start_time)
798+
report.print_str()
795799

796-
if post_run is not None:
797-
post_run(results=Results(self._output_path, simulator_if, report))
800+
if post_run is not None:
801+
post_run(results=Results(self._output_path, simulator_if, report))
802+
803+
all_ok &= report.all_ok()
798804

799805
del simulator_if
800806

801807
if self._args.xunit_xml is not None:
802808
xml = report.to_junit_xml_str(self._args.xunit_xml_format)
803809
ostools.write_file(self._args.xunit_xml, xml)
804810

805-
return report.all_ok()
811+
return all_ok
806812

807813
def _main_list_only(self):
808814
"""
@@ -938,7 +944,7 @@ def _get_testbench_files(self, simulator_if: Union[None, SimulatorInterface]):
938944
for file_name in tb_file_names
939945
]
940946

941-
def _run_test(self, test_cases, report):
947+
def _run_test(self, test_cases, report, iteration):
942948
"""
943949
Run the test suites and return the report
944950
"""
@@ -950,9 +956,14 @@ def _run_test(self, test_cases, report):
950956
else:
951957
verbosity = TestRunner.VERBOSITY_NORMAL
952958

959+
full_test_output_path = Path(self._output_path) / TEST_OUTPUT_PATH
960+
if iteration > 1:
961+
full_test_output_path /= f"rep_{iteration - 1}"
962+
full_test_output_path = str(full_test_output_path)
963+
953964
runner = TestRunner(
954965
report,
955-
str(Path(self._output_path) / TEST_OUTPUT_PATH),
966+
full_test_output_path,
956967
verbosity=verbosity,
957968
num_threads=self._args.num_threads,
958969
fail_fast=self._args.fail_fast,

vunit/vunit_cli.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,13 @@ def _create_argument_parser(description=None, for_documentation=False):
252252
help="Base seed provided to the simulation. Must be 16 hex digits. Default seed is generated from system time.",
253253
)
254254

255+
parser.add_argument(
256+
"-r",
257+
"--repeat",
258+
type=nonnegative_int,
259+
default=0,
260+
help="Number of times the tests are repeated with new seed values (unless --seed is set). Default: 0. ",
261+
)
255262
SIMULATOR_FACTORY.add_arguments(parser)
256263

257264
return parser

0 commit comments

Comments
 (0)