diff --git a/umi/sumi/tests/conftest.py b/umi/sumi/tests/conftest.py index bc56321..4591f1c 100644 --- a/umi/sumi/tests/conftest.py +++ b/umi/sumi/tests/conftest.py @@ -68,3 +68,19 @@ def sumi_dut(build_dir, request): yield dut dut.terminate() + + +def pytest_addoption(parser): + parser.addoption("--seed", type=int, action="store", help="Provide a fixed seed") + + +@pytest.fixture +def random_seed(request): + fixed_seed = request.config.getoption("--seed") + if fixed_seed is not None: + test_seed = fixed_seed + else: + test_seed = os.getpid() + print(f'Random seed used: {test_seed}') + yield test_seed + print(f'Random seed used: {test_seed}') diff --git a/umi/sumi/tests/test_crossbar.py b/umi/sumi/tests/test_crossbar.py index 4d74cd6..d8b5a1b 100755 --- a/umi/sumi/tests/test_crossbar.py +++ b/umi/sumi/tests/test_crossbar.py @@ -6,15 +6,12 @@ import pytest import multiprocessing import random -import numpy as np from switchboard import UmiTxRx, random_umi_packet, delete_queue -def umi_send(x, n, ports): - import os +def umi_send(x, n, ports, seed): - random.seed(os.getpid()) - np.random.seed(os.getpid()) + random.seed(seed) umi = UmiTxRx(f'client2rtl_{x}.q', '') tee = UmiTxRx(f'tee_{x}.q', '') @@ -32,7 +29,7 @@ def umi_send(x, n, ports): @pytest.mark.skip(reason="Crossbar asserts output valid even when in reset") -def test_crossbar(sumi_dut, sb_umi_valid_mode, sb_umi_ready_mode): +def test_crossbar(sumi_dut, random_seed, sb_umi_valid_mode, sb_umi_ready_mode): n = 100 ports = 4 for x in range(ports): @@ -59,7 +56,7 @@ def test_crossbar(sumi_dut, sb_umi_valid_mode, sb_umi_ready_mode): procs = [] for x in range(ports): - procs.append(multiprocessing.Process(target=umi_send, args=(x, n, ports,))) + procs.append(multiprocessing.Process(target=umi_send, args=(x, n, ports, (random_seed+x),))) for proc in procs: proc.start() diff --git a/umi/sumi/tests/test_fifo.py b/umi/sumi/tests/test_fifo.py index e86e74b..29d8cb9 100755 --- a/umi/sumi/tests/test_fifo.py +++ b/umi/sumi/tests/test_fifo.py @@ -9,7 +9,10 @@ from switchboard import UmiTxRx -def test_fifo(sumi_dut, sb_umi_valid_mode, sb_umi_ready_mode): +def test_fifo(sumi_dut, random_seed, sb_umi_valid_mode, sb_umi_ready_mode): + + random.seed(random_seed) + np.random.seed(random_seed) # launch the simulation sumi_dut.simulate(plusargs=[('valid_mode', sb_umi_valid_mode), ('ready_mode', sb_umi_ready_mode)]) diff --git a/umi/sumi/tests/test_fifo_flex.py b/umi/sumi/tests/test_fifo_flex.py index 53714ca..7415cb1 100755 --- a/umi/sumi/tests/test_fifo_flex.py +++ b/umi/sumi/tests/test_fifo_flex.py @@ -9,7 +9,10 @@ from switchboard import UmiTxRx -def test_fifo_flex(sumi_dut, sb_umi_valid_mode, sb_umi_ready_mode): +def test_fifo_flex(sumi_dut, random_seed, sb_umi_valid_mode, sb_umi_ready_mode): + + random.seed(random_seed) + np.random.seed(random_seed) # launch the simulation sumi_dut.simulate(plusargs=[('valid_mode', sb_umi_valid_mode), ('ready_mode', sb_umi_ready_mode)]) diff --git a/umi/sumi/tests/test_mem_agent.py b/umi/sumi/tests/test_mem_agent.py index f418c3e..69f1430 100755 --- a/umi/sumi/tests/test_mem_agent.py +++ b/umi/sumi/tests/test_mem_agent.py @@ -52,7 +52,9 @@ def apply_atomic(origdata, atomicdata, operation, maxrange): return tempval -def test_mem_agent(sumi_dut, sb_umi_valid_mode, sb_umi_ready_mode): +def test_mem_agent(sumi_dut, random_seed, sb_umi_valid_mode, sb_umi_ready_mode): + + np.random.seed(random_seed) # launch the simulation sumi_dut.simulate(plusargs=[('valid_mode', sb_umi_valid_mode), ('ready_mode', sb_umi_ready_mode)])