|
1 | 1 | # SPDX-License-Identifier: Apache-2.0
|
2 |
| - |
3 | 2 | import os
|
4 | 3 | import random
|
5 | 4 | import time
|
| 5 | +import shutil |
6 | 6 |
|
7 | 7 | import nox
|
8 | 8 | from nox_utils import VerificationTest, isCocotbSimFailure, nox_config
|
|
23 | 23 | else:
|
24 | 24 | coverage_types = None
|
25 | 25 |
|
| 26 | + |
26 | 27 | def _verify(session, test_group, test_type, test_name, coverage=None, simulator=None):
|
27 | 28 | # session.install("-r", pip_requirements_path)
|
28 |
| - test = VerificationTest(test_group, test_type, test_name, coverage) |
29 |
| - |
30 |
| - # Translate session options to plusargs |
31 |
| - plusargs = list(session.posargs) |
32 |
| - |
33 |
| - # Randomize seed for initialization of undefined signals in the simulation |
34 |
| - random.seed(time.time_ns()) |
35 |
| - seed = random.randint(1, 10000) |
36 |
| - |
37 |
| - with open(test.paths["log_default"], "w") as test_log: |
38 |
| - |
39 |
| - args = [ |
40 |
| - "make", |
41 |
| - "-C", |
42 |
| - test.testPath, |
43 |
| - "all", |
44 |
| - "MODULE=" + test_name, |
45 |
| - "COCOTB_RESULTS_FILE=" + test.filenames["xml"], |
46 |
| - ] |
47 |
| - if simulator == "verilator": |
48 |
| - plusargs.extend( |
49 |
| - [ |
50 |
| - "+verilator+rand+reset+2", |
51 |
| - f"+verilator+seed+{seed}", |
52 |
| - ] |
| 29 | + |
| 30 | + test_iterations = int(os.getenv("TEST_ITERATIONS", 1)) |
| 31 | + for i in range(test_iterations): |
| 32 | + pfx = "" if test_iterations == 1 else f"_{i}" |
| 33 | + test = VerificationTest(test_group, test_type, test_name, coverage, pfx) |
| 34 | + # Translate session options to plusargs |
| 35 | + plusargs = list(session.posargs) |
| 36 | + |
| 37 | + # Randomize seed for initialization of undefined signals in the simulation |
| 38 | + random.seed(time.time_ns()) |
| 39 | + seed = random.randint(1, 10000) |
| 40 | + |
| 41 | + with open(test.paths["log_default"], "w") as test_log: |
| 42 | + # Remove simulation build artifacts |
| 43 | + # When collecting coverage and renaming `vdb` database |
| 44 | + # the following simulations will fail due to non-existent database |
| 45 | + if simulator == "vcs" and i > 0: |
| 46 | + shutil.rmtree(os.path.join(test.testPath, test.sim_build)) |
| 47 | + |
| 48 | + args = [ |
| 49 | + "make", |
| 50 | + "-C", |
| 51 | + test.testPath, |
| 52 | + "all", |
| 53 | + "MODULE=" + test_name, |
| 54 | + "COCOTB_RESULTS_FILE=" + test.filenames["xml"], |
| 55 | + ] |
| 56 | + if simulator == "verilator": |
| 57 | + plusargs.extend( |
| 58 | + [ |
| 59 | + "+verilator+rand+reset+2", |
| 60 | + f"+verilator+seed+{seed}", |
| 61 | + ] |
| 62 | + ) |
| 63 | + if coverage: |
| 64 | + args.append("COVERAGE_TYPE=" + coverage) |
| 65 | + |
| 66 | + if simulator: |
| 67 | + args.append("SIM=" + simulator) |
| 68 | + |
| 69 | + args.append("PLUSARGS=" + " ".join(plusargs)) |
| 70 | + |
| 71 | + session.run( |
| 72 | + *args, |
| 73 | + external=True, |
| 74 | + stdout=test_log, |
| 75 | + stderr=test_log, |
53 | 76 | )
|
54 |
| - if coverage: |
55 |
| - args.append("COVERAGE_TYPE=" + coverage) |
56 |
| - |
57 |
| - if simulator: |
58 |
| - args.append("SIM=" + simulator) |
59 |
| - |
60 |
| - args.append("PLUSARGS=" + " ".join(plusargs)) |
61 |
| - |
62 |
| - session.run( |
63 |
| - *args, |
64 |
| - external=True, |
65 |
| - stdout=test_log, |
66 |
| - stderr=test_log, |
67 |
| - ) |
68 |
| - # Prevent coverage.dat and test log from being overwritten |
69 |
| - test.rename_defaults(coverage, simulator) |
70 |
| - |
71 |
| - # Add check from results.xml to notify nox that test failed |
72 |
| - isTBFailure = isCocotbSimFailure(resultsFile=test.paths["xml"]) |
73 |
| - if isTBFailure: |
74 |
| - raise Exception("SimFailure: cocotb failed. See test logs for more information.") |
| 77 | + # Prevent coverage.dat and test log from being overwritten |
| 78 | + test.rename_defaults(coverage, simulator) |
| 79 | + |
| 80 | + # Add check from results.xml to notify nox that test failed |
| 81 | + if isCocotbSimFailure(resultsFile=test.paths["xml"]): |
| 82 | + raise Exception("SimFailure: cocotb failed. See test logs for more information.") |
75 | 83 |
|
76 | 84 |
|
77 | 85 | def verify_block(session, test_group, test_name, coverage=None, simulator=None):
|
|
0 commit comments