Skip to content

Commit

Permalink
template: clean up template project.
Browse files Browse the repository at this point in the history
  • Loading branch information
kivikakk committed Jul 2, 2024
1 parent db7ca3b commit 4db4fc2
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 21 deletions.
2 changes: 1 addition & 1 deletion template/.github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ jobs:
- uses: kivikakk/niar/setup-action@main

- name: Run tests
run: pytest -n auto tests
run: pytest
2 changes: 1 addition & 1 deletion template/cxxrtl/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
6 changes: 5 additions & 1 deletion template/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@ 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"}

[build-system]
requires = ["pdm-backend"]
build-backend = "pdm.backend"

[tool.pytest.ini_options]
addopts = ["-n", "auto"]
testpaths = ["tests"]
30 changes: 12 additions & 18 deletions template/tests/test_top.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import unittest

from amaranth.hdl import Fragment
from amaranth.sim import Simulator

from newproject.rtl import Blinker


Expand All @@ -11,20 +8,17 @@ class test:
default_clk_frequency = 8.0


class TestBlinker(unittest.TestCase):
platform = test()

def test_blinks(self):
dut = Blinker()
def test_blinks():
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()

0 comments on commit 4db4fc2

Please sign in to comment.