2024-07-12 05:07:33 -05:00
|
|
|
import pytest
|
|
|
|
from rtlil_cells import generate_test_cases
|
2024-07-16 11:55:26 -05:00
|
|
|
import random
|
|
|
|
|
|
|
|
random_seed = random.getrandbits(32)
|
2024-07-12 05:07:33 -05:00
|
|
|
|
2024-09-04 04:30:08 -05:00
|
|
|
def pytest_configure(config):
|
|
|
|
config.addinivalue_line("markers", "smt: test uses smtlib/z3")
|
|
|
|
config.addinivalue_line("markers", "rkt: test uses racket/rosette")
|
|
|
|
|
2024-07-12 05:07:33 -05:00
|
|
|
def pytest_addoption(parser):
|
2024-07-16 11:55:26 -05:00
|
|
|
parser.addoption("--per-cell", type=int, default=None, help="run only N tests per cell")
|
|
|
|
parser.addoption("--steps", type=int, default=1000, help="run each test for N steps")
|
|
|
|
parser.addoption("--seed", type=int, default=random_seed, help="seed for random number generation, use random seed if unspecified")
|
|
|
|
|
|
|
|
def pytest_collection_finish(session):
|
|
|
|
print('random seed: {}'.format(session.config.getoption("seed")))
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def num_steps(request):
|
|
|
|
return request.config.getoption("steps")
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def rnd(request):
|
|
|
|
seed1 = request.config.getoption("seed")
|
|
|
|
return lambda seed2: random.Random('{}-{}'.format(seed1, seed2))
|
2024-07-12 05:07:33 -05:00
|
|
|
|
|
|
|
def pytest_generate_tests(metafunc):
|
|
|
|
if "cell" in metafunc.fixturenames:
|
|
|
|
per_cell = metafunc.config.getoption("per_cell", default=None)
|
2024-07-16 11:55:26 -05:00
|
|
|
seed1 = metafunc.config.getoption("seed")
|
|
|
|
rnd = lambda seed2: random.Random('{}-{}'.format(seed1, seed2))
|
|
|
|
names, cases = generate_test_cases(per_cell, rnd)
|
2024-09-04 04:30:08 -05:00
|
|
|
metafunc.parametrize("cell,parameters", cases, ids=names)
|