Skip to content

Commit 9546b1c

Browse files
committed
WIP: Added support for repeating seeds from previous test run.
1 parent 6d416fb commit 9546b1c

File tree

14 files changed

+253
-35
lines changed

14 files changed

+253
-35
lines changed

tests/acceptance/artificial/verilog/run.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ def post_check(output_path):
6565
module.add_config("cfg", post_check=post_check)
6666
module = ui.library("lib").module("tb_same_sim_from_python_all_pass")
6767
module.add_config("cfg", post_check=post_check, attributes=dict(run_all_in_same_sim=True))
68-
68+
69+
6970
configure_tb_with_parameter_config()
7071
configure_tb_same_sim_all_pass(vu)
7172
lib.module("tb_same_sim_from_python_some_fail").set_attribute("run_all_in_same_sim", True)
0 Bytes
Binary file not shown.
110 Bytes
Binary file not shown.

tests/unit/test_test_bench.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
FileLocation,
2828
Attribute,
2929
LegacyAttribute,
30+
_get_historic_seed,
3031
)
3132
from vunit.configuration import AttributeException
3233
from vunit.ostools import write_file
@@ -483,7 +484,7 @@ def test_error_on_global_attributes_from_python_on_tests(self, tempdir):
483484

484485
test_bench = TestBench(design_unit)
485486
test = test_bench.get_test_case("Test 1")
486-
self.assertRaises(AttributeException, test.set_attribute, "run_all_in_same_sim", True)
487+
self.assertRaises(AttributeException, test.set_attribute, "run_all_in_same_sim", True)
487488

488489
@with_tempdir
489490
def test_test_information(self, tempdir):
@@ -904,6 +905,19 @@ def assert_has_tests(self, test_list, tests):
904905
self.assertEqual(test1.name, test2)
905906
self.assertEqual(test1.test_names, [test2])
906907

908+
def test_seed_from_test_history(self):
909+
test_history = dict(test_suite1=dict(test1=dict(seed="11"), test2=dict(seed="12")), test_suite2=dict())
910+
911+
self.assertEqual(_get_historic_seed(test_history, test_suite_name="test_suite1"), "11")
912+
self.assertEqual(_get_historic_seed(test_history, test_suite_name="test_suite1", test_name="test2"), "12")
913+
914+
def test_no_seed_from_test_history(self):
915+
test_history = dict(test_suite1=dict(test1=dict(seed="11"), test2=dict(seed="12")), test_suite2=dict())
916+
917+
self.assertIsNone(_get_historic_seed(test_history, test_suite_name="foo"))
918+
self.assertIsNone(_get_historic_seed(test_history, test_suite_name="test_suite1", test_name="test3"))
919+
self.assertIsNone(_get_historic_seed(test_history, test_suite_name="test_suite2"))
920+
907921
@staticmethod
908922
def create_tests(test_bench):
909923
"""

tests/unit/test_test_report.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,13 @@ def test_junit_report_with_some_skipped_tests(self):
289289
def test_junit_report_with_testcase_classname(self):
290290
report = self._new_report()
291291
report.add_result(
292-
"test", PASSED, time=1.0, output_file_name=self.output_file_name, test_suite_name="test", start_time=0
292+
"test",
293+
PASSED,
294+
time=1.0,
295+
output_file_name=self.output_file_name,
296+
test_suite_name="test",
297+
start_time=0,
298+
seed="0123456789abcdef",
293299
)
294300
report.add_result(
295301
"lib.entity",
@@ -298,6 +304,7 @@ def test_junit_report_with_testcase_classname(self):
298304
output_file_name=self.output_file_name,
299305
test_suite_name="lib.entity",
300306
start_time=0,
307+
seed="0123456789abcdef",
301308
)
302309
report.add_result(
303310
"lib.entity.test",
@@ -306,6 +313,7 @@ def test_junit_report_with_testcase_classname(self):
306313
output_file_name=self.output_file_name,
307314
test_suite_name="lib.entity.test",
308315
start_time=0,
316+
seed="0123456789abcdef",
309317
)
310318
report.add_result(
311319
"lib.entity.config.test",
@@ -314,6 +322,7 @@ def test_junit_report_with_testcase_classname(self):
314322
output_file_name=self.output_file_name,
315323
test_suite_name="lib.entity.config.test",
316324
start_time=0,
325+
seed="0123456789abcdef",
317326
)
318327
root = ElementTree.fromstring(report.to_junit_xml_str())
319328
names = set(
@@ -372,6 +381,7 @@ def _report_with_all_passed_tests(self, output_file_name=None):
372381
output_file_name=output_file_name,
373382
test_suite_name="passed_test0",
374383
start_time=0,
384+
seed="0123456789abcdef",
375385
)
376386
report.add_result(
377387
"passed_test1",
@@ -380,6 +390,7 @@ def _report_with_all_passed_tests(self, output_file_name=None):
380390
output_file_name=output_file_name,
381391
test_suite_name="passed_test0",
382392
start_time=0,
393+
seed="0123456789abcdef",
383394
)
384395
report.set_expected_num_tests(2)
385396
return report
@@ -394,6 +405,7 @@ def _report_with_missing_tests(self):
394405
output_file_name=self.output_file_name,
395406
test_suite_name="passed_test0",
396407
start_time=0,
408+
seed="0123456789abcdef",
397409
)
398410
report.add_result(
399411
"passed_test1",
@@ -402,6 +414,7 @@ def _report_with_missing_tests(self):
402414
output_file_name=self.output_file_name,
403415
test_suite_name="passed_test0",
404416
start_time=0,
417+
seed="0123456789abcdef",
405418
)
406419
report.set_expected_num_tests(3)
407420
return report
@@ -416,6 +429,7 @@ def _report_with_some_failed_tests(self):
416429
output_file_name=self.output_file_name,
417430
test_suite_name="failed_test0",
418431
start_time=0,
432+
seed="0123456789abcdef",
419433
)
420434
report.add_result(
421435
"passed_test",
@@ -424,6 +438,7 @@ def _report_with_some_failed_tests(self):
424438
output_file_name=self.output_file_name,
425439
test_suite_name="passed_test",
426440
start_time=0,
441+
seed="0123456789abcdef",
427442
)
428443
report.add_result(
429444
"failed_test1",
@@ -432,6 +447,7 @@ def _report_with_some_failed_tests(self):
432447
output_file_name=self.output_file_name,
433448
test_suite_name="failed_test1",
434449
start_time=0,
450+
seed="0123456789abcdef",
435451
)
436452
report.set_expected_num_tests(3)
437453
return report
@@ -446,6 +462,7 @@ def _report_with_some_skipped_tests(self):
446462
output_file_name=self.output_file_name,
447463
test_suite_name="passed_test",
448464
start_time=0,
465+
seed="0123456789abcdef",
449466
)
450467
report.add_result(
451468
"skipped_test",
@@ -454,6 +471,7 @@ def _report_with_some_skipped_tests(self):
454471
output_file_name=self.output_file_name,
455472
test_suite_name="skipped_test",
456473
start_time=0,
474+
seed="0123456789abcdef",
457475
)
458476
report.add_result(
459477
"failed_test",
@@ -462,6 +480,7 @@ def _report_with_some_skipped_tests(self):
462480
output_file_name=self.output_file_name,
463481
test_suite_name="failed_test",
464482
start_time=0,
483+
seed="0123456789abcdef",
465484
)
466485
report.set_expected_num_tests(3)
467486
return report
@@ -476,6 +495,7 @@ def _report_with_mixed_length_tests(self):
476495
output_file_name=self.output_file_name,
477496
test_suite_name="passed_test0",
478497
start_time=0,
498+
seed="0123456789abcdef",
479499
)
480500
report.add_result(
481501
"passed_test1",
@@ -484,6 +504,7 @@ def _report_with_mixed_length_tests(self):
484504
output_file_name=self.output_file_name,
485505
test_suite_name="passed_test1",
486506
start_time=0,
507+
seed="0123456789abcdef",
487508
)
488509
report.add_result(
489510
"passed_test2",
@@ -492,6 +513,7 @@ def _report_with_mixed_length_tests(self):
492513
output_file_name=self.output_file_name,
493514
test_suite_name="passed_test2",
494515
start_time=0,
516+
seed="0123456789abcdef",
495517
)
496518
report.add_result(
497519
"passed_test3",
@@ -500,6 +522,7 @@ def _report_with_mixed_length_tests(self):
500522
output_file_name=self.output_file_name,
501523
test_suite_name="passed_test3",
502524
start_time=0,
525+
seed="0123456789abcdef",
503526
)
504527
report.set_expected_num_tests(4)
505528
return report
@@ -514,6 +537,7 @@ def _report_with_long_tests(self):
514537
output_file_name=self.output_file_name,
515538
test_suite_name="passed_test0",
516539
start_time=0,
540+
seed="0123456789abcdef",
517541
)
518542
report.add_result(
519543
"passed_test1",
@@ -522,6 +546,7 @@ def _report_with_long_tests(self):
522546
output_file_name=self.output_file_name,
523547
test_suite_name="passed_test1",
524548
start_time=0,
549+
seed="0123456789abcdef",
525550
)
526551
report.add_result(
527552
"passed_test2",
@@ -530,6 +555,7 @@ def _report_with_long_tests(self):
530555
output_file_name=self.output_file_name,
531556
test_suite_name="passed_test2",
532557
start_time=0,
558+
seed="0123456789abcdef",
533559
)
534560
report.add_result(
535561
"passed_test3",
@@ -538,6 +564,7 @@ def _report_with_long_tests(self):
538564
output_file_name=self.output_file_name,
539565
test_suite_name="passed_test3",
540566
start_time=0,
567+
seed="0123456789abcdef",
541568
)
542569
report.add_result(
543570
"passed_test4",
@@ -546,6 +573,7 @@ def _report_with_long_tests(self):
546573
output_file_name=self.output_file_name,
547574
test_suite_name="passed_test4",
548575
start_time=0,
576+
seed="0123456789abcdef",
549577
)
550578
report.add_result(
551579
"passed_test5",
@@ -554,6 +582,7 @@ def _report_with_long_tests(self):
554582
output_file_name=self.output_file_name,
555583
test_suite_name="passed_test5",
556584
start_time=0,
585+
seed="0123456789abcdef",
557586
)
558587
report.set_expected_num_tests(6)
559588
return report

tests/unit/test_test_runner.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,3 +256,6 @@ def run(self, output_path, read_output):
256256
self.output_path = output_path
257257
self.read_output = read_output
258258
return self.run_side_effect(output_path=output_path, read_output=read_output)
259+
260+
def get_seed(self):
261+
return "0123456789abcdef"

tests/unit/test_test_suites.py

Lines changed: 74 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@
1010

1111
from pathlib import Path
1212
from unittest import TestCase
13-
from tests.common import create_tempdir
13+
from time import sleep
14+
from tests.common import with_tempdir, create_tempdir
1415
from vunit.test.suites import TestRun
1516
from vunit.test.report import PASSED, SKIPPED, FAILED
1617
from vunit.sim_if import SimulatorInterface
18+
from vunit.configuration import Configuration
1719

1820

1921
class TestTestSuites(TestCase):
@@ -105,7 +107,7 @@ def _read_test_results(self, expected, contents):
105107
elaborate_only=False,
106108
test_suite_name=None,
107109
test_cases=expected,
108-
seed="seed"
110+
seed="seed",
109111
)
110112
results = run._read_test_results(file_name=file_name) # pylint: disable=protected-access
111113
self.assertEqual(results, expected)
@@ -180,11 +182,80 @@ def func():
180182
elaborate_only=False,
181183
test_suite_name=None,
182184
test_cases=expected,
183-
seed="seed"
185+
seed="seed",
184186
)
185187

186188
results = run._read_test_results(file_name=file_name) # pylint: disable=protected-access
187189
self.assertEqual(
188190
run._check_results(results, sim_ok), # pylint: disable=protected-access
189191
(waschecked, expected),
190192
)
193+
194+
@with_tempdir
195+
def test_get_external_seed(self, tempdir):
196+
design_unit = Entity(file_name=str(Path(tempdir) / "file.vhd"))
197+
config = Configuration(name="config", design_unit=design_unit, sim_options=dict(seed="config_seed"))
198+
run = TestRun(
199+
simulator_if=None,
200+
config=config,
201+
elaborate_only=False,
202+
test_suite_name=None,
203+
test_cases=None,
204+
seed="external_seed",
205+
)
206+
207+
self.assertEqual(run.get_seed(), "external_seed")
208+
209+
@with_tempdir
210+
def test_get_seed_from_config(self, tempdir):
211+
design_unit = Entity(file_name=str(Path(tempdir) / "file.vhd"))
212+
config = Configuration(name="config", design_unit=design_unit, sim_options=dict(seed="config_seed"))
213+
run = TestRun(
214+
simulator_if=None,
215+
config=config,
216+
elaborate_only=False,
217+
test_suite_name=None,
218+
test_cases=None,
219+
seed=None,
220+
)
221+
222+
self.assertEqual(run.get_seed(), "config_seed")
223+
224+
@with_tempdir
225+
def test_get_generated_seed(self, tempdir):
226+
design_unit = Entity(file_name=str(Path(tempdir) / "file.vhd"))
227+
config = Configuration(name="config", design_unit=design_unit)
228+
run = TestRun(
229+
simulator_if=None,
230+
config=config,
231+
elaborate_only=False,
232+
test_suite_name=None,
233+
test_cases=None,
234+
seed=None,
235+
)
236+
237+
# Seed is "random" but do not change for an instance
238+
seed = run.get_seed()
239+
self.assertEqual(run.get_seed(), seed)
240+
241+
run = TestRun(
242+
simulator_if=None,
243+
config=config,
244+
elaborate_only=False,
245+
test_suite_name=None,
246+
test_cases=None,
247+
seed=None,
248+
)
249+
250+
# New random value for a new instance if we let system time ellapse
251+
sleep(0.1)
252+
self.assertNotEqual(run.get_seed(), seed)
253+
254+
class Entity(object): # pylint: disable=too-many-instance-attributes
255+
"""
256+
Mock Entity
257+
"""
258+
259+
def __init__(self, file_name):
260+
self.generic_names = []
261+
self.original_file_name = file_name

0 commit comments

Comments
 (0)