Skip to content

Commit e3005c5

Browse files
committed
Changes from Peter's feedback
1 parent e34339f commit e3005c5

File tree

7 files changed

+74
-69
lines changed

7 files changed

+74
-69
lines changed

lambdalib/ramlib/make.py

Lines changed: 0 additions & 30 deletions
This file was deleted.

lambdalib/ramlib/rtl/la_asyncfifo.v

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@
2121
****************************************************************************/
2222

2323
module la_asyncfifo #(
24-
parameter DW = 32, // Memory width
25-
parameter DEPTH = 4, // FIFO depth
26-
parameter ALMOST_FULL_LEVEL = DEPTH-1, // FIFO depth
27-
parameter NS = 1, // Number of power supplies
28-
parameter CTRLW = 1, // width of asic ctrl interface
29-
parameter TESTW = 1, // width of asic teset interface
30-
parameter CHAOS = 0, // generates random full logic when set
31-
parameter PROP = "DEFAULT" // Pass through variable for hard macro
24+
parameter DW = 32, // Memory width
25+
parameter DEPTH = 4, // FIFO depth
26+
parameter ALMOST_FULL_LEVEL = DEPTH-1, // FIFO depth
27+
parameter NS = 1, // Number of power supplies
28+
parameter CTRLW = 1, // width of asic ctrl interface
29+
parameter TESTW = 1, // width of asic teset interface
30+
parameter CHAOS = 0, // generates random full logic when set
31+
parameter PROP = "DEFAULT" // Pass through variable for hard macro
3232
) ( // write port
3333
input wr_clk,
3434
input wr_nreset,

lambdalib/ramlib/tests/la_asyncfifo.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import logging
2-
31
import cocotb
42
from cocotb.triggers import RisingEdge
53
from cocotb_bus.bus import Bus
@@ -8,6 +6,7 @@
86

97

108
class LaAsyncFifoWrBus(Bus):
9+
"""Cocotb bus for lambdalib async FIFO WR interface"""
1110

1211
_signals = ["wr_din", "wr_en", "wr_full"]
1312
_optional_signals = ["wr_almost_full", "wr_chaosmode"]
@@ -31,6 +30,7 @@ def from_prefix(cls, entity, prefix, **kwargs):
3130

3231

3332
class LaAsyncFifoRdBus(Bus):
33+
"""Cocotb bus for lambdalib async FIFO RD interface"""
3434

3535
_signals = ["rd_dout", "rd_en", "rd_empty"]
3636
_optional_signals = []
@@ -60,7 +60,6 @@ def __init__(self, bus: LaAsyncFifoWrBus, clock, reset=None):
6060
self.bus = bus
6161
self.clock = clock
6262
self.reset = reset
63-
self.log = logging.getLogger(f"cocotb.{bus._entity._name}.{bus._name}")
6463

6564
self.queue = Queue()
6665
self.width = len(self.bus.wr_din)
@@ -113,7 +112,6 @@ def __init__(self, bus: LaAsyncFifoRdBus, clock, reset=None):
113112
self.bus = bus
114113
self.clock = clock
115114
self.reset = reset
116-
self.log = logging.getLogger(f"cocotb.{bus._entity._name}.{bus._name}")
117115

118116
self.queue = Queue()
119117
self.width = len(self.bus.rd_dout)
@@ -145,12 +143,13 @@ async def _run(self):
145143
await clock_edge_event
146144

147145
fifo_empty = self.bus.rd_empty.value
148-
if self.rd_en_generator:
146+
147+
if self._pause:
148+
self.bus.rd_en.value = 0
149+
elif self.rd_en_generator:
149150
self.bus.rd_en.value = next(self.rd_en_generator)
150-
elif not self._pause:
151-
self.bus.rd_en.value = 1
152151
else:
153-
self.bus.rd_en.value = 0
152+
self.bus.rd_en.value = 1
154153

155154
if self.bus.rd_en.value and not fifo_empty:
156155
self.queue.put_nowait(self.bus.rd_dout.value)

lambdalib/ramlib/tests/tb_la_asyncfifo.py

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
import random
2+
from decimal import Decimal
3+
4+
import siliconcompiler
25

36
import cocotb
47
from cocotb.clock import Clock
58
from cocotb.triggers import ClockCycles, Timer, Combine
69
from cocotb.regression import TestFactory
710
from cocotb import utils
811

9-
from lambdalib.ramlib.tests.common import (
12+
from lambdalib import ramlib
13+
from lambdalib.utils._tb_common import (
14+
run_cocotb,
1015
drive_reset,
1116
random_bool_generator
1217
)
13-
1418
from lambdalib.ramlib.tests.la_asyncfifo import (
1519
LaAsyncFifoWrBus,
1620
LaAsyncFifoRdBus,
@@ -136,16 +140,51 @@ async def fifo_rd_wr_test(
136140
RAND_WR_CLK_PERIOD_NS, RAND_RD_CLK_PERIOD_NS = [utils.get_time_from_sim_steps(
137141
# Time step must be even for cocotb clock driver
138142
steps=utils.get_sim_steps(
139-
time=MIN_PERIOD_NS + ((MAX_PERIOD_NS - MIN_PERIOD_NS) * random.random()),
143+
time=Decimal(MIN_PERIOD_NS) + (
144+
Decimal(MAX_PERIOD_NS - MIN_PERIOD_NS)
145+
* Decimal(random.random()).quantize(Decimal("0.00"))
146+
),
140147
units="ns",
141148
round_mode="round"
142149
) & ~1,
143150
units="ns"
144151
) for _ in range(0, 2)]
145152

153+
utils.get_sim_steps(Decimal("8.104"), "ns")
154+
155+
# Factory to automatically generate a set of tests based on the different permutations
156+
# of the provided test arguments
146157
tf = TestFactory(fifo_rd_wr_test)
147158
tf.add_option('wr_clk_period_ns', [MIN_PERIOD_NS, RAND_WR_CLK_PERIOD_NS, MAX_PERIOD_NS])
148159
tf.add_option('rd_clk_period_ns', [MIN_PERIOD_NS, RAND_RD_CLK_PERIOD_NS, MAX_PERIOD_NS])
149160
tf.add_option('wr_en_generator', [None, random_bool_generator, bursty_en_gen])
150161
tf.add_option('rd_en_generator', [None, random_bool_generator, bursty_en_gen])
151162
tf.generate_tests()
163+
164+
165+
def test_la_asyncfifo():
166+
chip = siliconcompiler.Chip("la_asyncfifo")
167+
168+
# TODO: Ask Peter how to set la_asyncfifo path
169+
# such that it can be found by pytest and when run locally
170+
chip.input("../rtl/la_asyncfifo.v")
171+
chip.use(ramlib)
172+
173+
for depth in [2, 4, 8]:
174+
test_module_name = "lambdalib.ramlib.tests.tb_la_asyncfifo"
175+
test_name = f"{test_module_name}_depth_{depth}"
176+
tests_failed = run_cocotb(
177+
chip=chip,
178+
test_module_name=test_module_name,
179+
timescale=("1ns", "1ps"),
180+
parameters={
181+
"DW": 32,
182+
"DEPTH": depth
183+
},
184+
output_dir_name=test_name
185+
)
186+
assert (tests_failed == 0), f"Error test {test_name} failed!"
187+
188+
189+
if __name__ == "__main__":
190+
test_la_asyncfifo()

lambdalib/ramlib/tests/test_pytest_runners.py

Lines changed: 0 additions & 8 deletions
This file was deleted.

lambdalib/ramlib/tests/common.py renamed to lambdalib/utils/_tb_common.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from cocotb.runner import get_runner, get_results
88

99
import siliconcompiler
10-
from siliconcompiler.tools.surelog import parse
10+
from siliconcompiler.tools.slang import elaborate
1111

1212

1313
def run_cocotb(
@@ -18,29 +18,26 @@ def run_cocotb(
1818
timescale=None,
1919
parameters=None):
2020

21-
print(f"test module name = {test_module_name}")
22-
2321
# Use surelog to pickle Verilog sources
2422
flow = "cocotb_flow"
25-
chip.node(flow, "import", parse)
23+
chip.node(flow, "import", elaborate)
2624
chip.set("option", "flow", flow)
27-
chip.run()
25+
assert chip.run()
2826

2927
pickled_verilog = chip.find_result("v", "import")
30-
if not pickled_verilog:
31-
assert False, "Could not locate pickled verilog"
28+
assert pickled_verilog, "Could not locate pickled verilog"
3229

3330
if output_dir_name is None:
3431
output_dir_name = test_module_name
3532

36-
pytest_current_test = os.getenv("PYTEST_CURRENT_TEST", None)
37-
38-
top_level_dir = Path(chip.getbuilddir()).parent.parent
33+
top_level_dir = os.getcwd()
3934
build_dir = Path(chip.getbuilddir()) / output_dir_name
4035
test_dir = None
4136

4237
results_xml = None
43-
if not pytest_current_test:
38+
# Need to check if we are running inside of pytest. See link below.
39+
# https://github.com/cocotb/cocotb/blob/d883ce914063c3601455d10a40f459fffa22d8f2/cocotb/runner.py#L313
40+
if not os.getenv("PYTEST_CURRENT_TEST", None):
4441
results_xml = build_dir / "results.xml"
4542
test_dir = top_level_dir
4643

@@ -56,7 +53,7 @@ def run_cocotb(
5653
)
5754
# Run test
5855
_, tests_failed = get_results(runner.test(
59-
hdl_toplevel=chip.design,
56+
hdl_toplevel=chip.top(),
6057
test_module=test_module_name,
6158
test_dir=test_dir,
6259
results_xml=results_xml,

tests/test_rtl.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import pytest
2+
3+
import lambdalib.ramlib.tests.tb_la_asyncfifo as ramlib_tests
4+
5+
6+
@pytest.mark.eda
7+
def test_la_asyncfifo():
8+
ramlib_tests.test_la_asyncfifo()

0 commit comments

Comments
 (0)