diff --git a/template/.github/workflows/unit-tests.yml b/template/.github/workflows/unit-tests.yml index 8d1b75e..3b02703 100644 --- a/template/.github/workflows/unit-tests.yml +++ b/template/.github/workflows/unit-tests.yml @@ -19,4 +19,4 @@ jobs: - uses: kivikakk/niar/setup-action@main - name: Run tests - run: pytest -n auto tests + run: pytest diff --git a/template/cxxrtl/main.cc b/template/cxxrtl/main.cc index 43b8d07..0b68a95 100644 --- a/template/cxxrtl/main.cc +++ b/template/cxxrtl/main.cc @@ -45,7 +45,7 @@ int main(int argc, char **argv) { // ledr should be low or high according to 'expected', where each element // represents 1/4th of a second. ledg should always be high. // - // This mirrors TestTop in Python. + // This mirrors test_blinks in Python. int rc = 0; bool done = false; diff --git a/template/pyproject.toml b/template/pyproject.toml index 2abd799..4626fc7 100644 --- a/template/pyproject.toml +++ b/template/pyproject.toml @@ -8,7 +8,7 @@ authors = [ dependencies = [ "amaranth >= 0.5, < 0.7", "amaranth-boards", - "niar >= 0.1", + "niar >= 0.1.1", ] requires-python = ">=3.8" license = {text = "BSD-2-Clause"} @@ -16,3 +16,7 @@ license = {text = "BSD-2-Clause"} [build-system] requires = ["pdm-backend"] build-backend = "pdm.backend" + +[tool.pytest.ini_options] +addopts = ["-n", "auto"] +testpaths = ["tests"] diff --git a/template/tests/test_top.py b/template/tests/test_top.py index d1b1e4e..8523f88 100644 --- a/template/tests/test_top.py +++ b/template/tests/test_top.py @@ -1,8 +1,5 @@ -import unittest - from amaranth.hdl import Fragment from amaranth.sim import Simulator - from newproject.rtl import Blinker @@ -11,20 +8,17 @@ class test: default_clk_frequency = 8.0 -class TestBlinker(unittest.TestCase): - platform = test() +def test_blinks(): + dut = Blinker() - def test_blinks(self): - dut = Blinker() + async def testbench(ctx): + for ledr in [0, 1, 1, 0, 0, 1, 1, 0]: + for _ in range(2): + assert ctx.get(dut.ledr) == ledr + assert ctx.get(dut.ledg) + await ctx.tick() - async def testbench(ctx): - for ledr in [0, 1, 1, 0, 0, 1, 1, 0]: - for _ in range(2): - assert ctx.get(dut.ledr) == ledr - assert ctx.get(dut.ledg) - await ctx.tick() - - sim = Simulator(Fragment.get(dut, self.platform)) - sim.add_clock(1 / 8) - sim.add_testbench(testbench) - sim.run() + sim = Simulator(Fragment.get(dut, test())) + sim.add_clock(1 / 8) + sim.add_testbench(testbench) + sim.run()