Skip to content

Commit 33acd3a

Browse files
committed
Add tests for RTLIL and nMigen input formats
Signed-off-by: Robert Winkler <rwinkler@antmicro.com>
1 parent 79defb4 commit 33acd3a

File tree

7 files changed

+208
-5
lines changed

7 files changed

+208
-5
lines changed

.travis.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ jobs:
2626
script:
2727
- cd tests && python3 -m unittest test.TestYosysType
2828

29+
- stage: Tests
30+
name: "Test nMigen input format"
31+
script:
32+
- cd tests && python3 -m unittest test.TestNMigen
33+
34+
- stage: Tests
35+
name: "Test RTLIL input format"
36+
script:
37+
- cd tests && python3 -m unittest test.TestRTLIL
38+
2939
- stage: Build
3040
name: "Build"
3141
script:

tests/code/nmigen/counter.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from nmigen import *
2+
from nmigen.back import rtlil
3+
4+
5+
class Counter(Elaboratable):
6+
def __init__(self, width):
7+
self.v = Signal(width, reset=2**width-1)
8+
self.o = Signal()
9+
10+
def elaborate(self, platform):
11+
m = Module()
12+
m.d.sync += self.v.eq(self.v + 1)
13+
m.d.comb += self.o.eq(self.v[-1])
14+
return m
15+
16+
17+
ctr = Counter(width=16)
18+
print(rtlil.convert(ctr, ports=[ctr.o]))

tests/code/rtlil/counter.il

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
attribute \generator "nMigen"
2+
attribute \top 1
3+
attribute \nmigen.hierarchy "top"
4+
module \top
5+
attribute \src "counter.py:9"
6+
wire width 1 output 0 \o
7+
attribute \src "/usr/local/lib/python3.7/site-packages/nmigen/hdl/ir.py:526"
8+
wire width 1 input 1 \clk
9+
attribute \src "/usr/local/lib/python3.7/site-packages/nmigen/hdl/ir.py:526"
10+
wire width 1 input 2 \rst
11+
attribute \src "counter.py:8"
12+
wire width 16 \v
13+
attribute \src "counter.py:8"
14+
wire width 16 \v$next
15+
attribute \src "counter.py:13"
16+
wire width 17 $1
17+
attribute \src "counter.py:13"
18+
wire width 17 $2
19+
attribute \src "counter.py:13"
20+
cell $add $3
21+
parameter \A_SIGNED 1'0
22+
parameter \A_WIDTH 5'10000
23+
parameter \B_SIGNED 1'0
24+
parameter \B_WIDTH 1'1
25+
parameter \Y_WIDTH 5'10001
26+
connect \A \v
27+
connect \B 1'1
28+
connect \Y $2
29+
end
30+
connect $1 $2
31+
process $group_0
32+
assign \v$next \v
33+
assign \v$next $1 [15:0]
34+
attribute \src "/usr/local/lib/python3.7/site-packages/nmigen/hdl/xfrm.py:530"
35+
switch \rst
36+
case 1'1
37+
assign \v$next 16'1111111111111111
38+
end
39+
sync init
40+
update \v 16'1111111111111111
41+
sync posedge \clk
42+
update \v \v$next
43+
end
44+
process $group_1
45+
assign \o 1'0
46+
assign \o \v [15]
47+
sync init
48+
end
49+
end

tests/test.py

Lines changed: 57 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def test_netlistsvg_diagram(self):
7272
"test_skins/test_skins.rst",
7373
"test_skins/skin-purple.svg",
7474
"test_skins/skin-yellow.svg",
75-
"verilog/adder.v"
75+
"code/verilog/adder.v"
7676
]
7777
TEST_JINJA_DICT = {
7878
"hdl_diagrams_path": "'{}'".format(HDL_DIAGRAMS_PATH),
@@ -101,7 +101,7 @@ def test_yosys_script(self):
101101
"test_yosys_script/test_yosys_script.rst",
102102
"test_yosys_script/yosys_script.ys",
103103
"test_yosys_script/yosys_script2.ys",
104-
"verilog/adder.v"
104+
"code/verilog/adder.v"
105105
]
106106
TEST_JINJA_DICT = {
107107
"hdl_diagrams_path": "'{}'".format(HDL_DIAGRAMS_PATH),
@@ -127,7 +127,7 @@ def test_yosys_yowasp(self):
127127
TEST_BUILD_DIR = os.path.join("build", self.TEST_CASE_NAME, TEST_NAME)
128128
TEST_FILES = [
129129
"test_yosys_type/test_yosys_yowasp.rst",
130-
"verilog/adder.v"
130+
"code/verilog/adder.v"
131131
]
132132
TEST_JINJA_DICT = {
133133
"hdl_diagrams_path": "'{}'".format(HDL_DIAGRAMS_PATH),
@@ -149,7 +149,7 @@ def test_yosys_system(self):
149149
TEST_BUILD_DIR = os.path.join("build", self.TEST_CASE_NAME, TEST_NAME)
150150
TEST_FILES = [
151151
"test_yosys_type/test_yosys_system.rst",
152-
"verilog/adder.v"
152+
"code/verilog/adder.v"
153153
]
154154
TEST_JINJA_DICT = {
155155
"hdl_diagrams_path": "'{}'".format(HDL_DIAGRAMS_PATH),
@@ -171,7 +171,7 @@ def test_yosys_path(self):
171171
TEST_BUILD_DIR = os.path.join("build", self.TEST_CASE_NAME, TEST_NAME)
172172
TEST_FILES = [
173173
"test_yosys_type/test_yosys_path.rst",
174-
"verilog/adder.v"
174+
"code/verilog/adder.v"
175175
]
176176

177177
yosys_path = shutil.which("yosys")
@@ -190,5 +190,57 @@ def test_yosys_path(self):
190190
app = Sphinx(buildername="html", warningiserror=True, **sphinx_dirs)
191191
app.build(force_all=True)
192192

193+
class TestNMigen(TestBase):
194+
195+
TEST_CASE_NAME = "TestNMigen"
196+
TEST_CASE_BUILD_DIR = os.path.join("build", TEST_CASE_NAME)
197+
198+
def test_yosys_script(self):
199+
TEST_NAME = "test_nmigen"
200+
TEST_BUILD_DIR = os.path.join("build", self.TEST_CASE_NAME, TEST_NAME)
201+
TEST_FILES = [
202+
"test_nmigen/test_nmigen.rst",
203+
"code/nmigen/counter.py"
204+
]
205+
TEST_JINJA_DICT = {
206+
"hdl_diagrams_path": "'{}'".format(HDL_DIAGRAMS_PATH),
207+
"master_doc": "'test_nmigen'",
208+
"custom_variables": "''"
209+
}
210+
211+
self.prepare_test(TEST_NAME, TEST_BUILD_DIR, TEST_FILES, **TEST_JINJA_DICT)
212+
213+
# Run the Sphinx
214+
sphinx_dirs = get_sphinx_dirs(TEST_BUILD_DIR)
215+
with docutils_namespace():
216+
app = Sphinx(buildername="html", warningiserror=True, **sphinx_dirs)
217+
app.build(force_all=True)
218+
219+
class TestRTLIL(TestBase):
220+
221+
TEST_CASE_NAME = "TestRTLIL"
222+
TEST_CASE_BUILD_DIR = os.path.join("build", TEST_CASE_NAME)
223+
224+
def test_yosys_script(self):
225+
TEST_NAME = "test_rtlil"
226+
TEST_BUILD_DIR = os.path.join("build", self.TEST_CASE_NAME, TEST_NAME)
227+
TEST_FILES = [
228+
"test_rtlil/test_rtlil.rst",
229+
"code/rtlil/counter.il"
230+
]
231+
TEST_JINJA_DICT = {
232+
"hdl_diagrams_path": "'{}'".format(HDL_DIAGRAMS_PATH),
233+
"master_doc": "'test_rtlil'",
234+
"custom_variables": "''"
235+
}
236+
237+
self.prepare_test(TEST_NAME, TEST_BUILD_DIR, TEST_FILES, **TEST_JINJA_DICT)
238+
239+
# Run the Sphinx
240+
sphinx_dirs = get_sphinx_dirs(TEST_BUILD_DIR)
241+
with docutils_namespace():
242+
app = Sphinx(buildername="html", warningiserror=True, **sphinx_dirs)
243+
app.build(force_all=True)
244+
193245
if __name__ == '__main__':
194246
unittest.main()

tests/test_nmigen/test_nmigen.rst

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
Test nMigen
2+
===========
3+
4+
This test checks diagram generation from nMigen sources.
5+
6+
Yosys BlackBox Diagram
7+
----------------------
8+
9+
.. code-block:: rst
10+
11+
.. hdl-diagram:: counter.py
12+
:type: yosys-blackbox
13+
14+
.. hdl-diagram:: counter.py
15+
:type: yosys-blackbox
16+
17+
Yosys AIG Diagram
18+
-----------------
19+
20+
.. code-block:: rst
21+
22+
.. hdl-diagram:: counter.py
23+
:type: yosys-aig
24+
25+
.. hdl-diagram:: counter.py
26+
:type: yosys-aig
27+
28+
Netlistsvg Diagram
29+
------------------
30+
31+
.. code-block:: rst
32+
33+
.. hdl-diagram:: counter.py
34+
:type: netlistsvg
35+
36+
.. hdl-diagram:: counter.py
37+
:type: netlistsvg

tests/test_rtlil/test_rtlil.rst

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
Test RTLIL
2+
===========
3+
4+
This test checks diagram generation from RTLIL sources.
5+
6+
Yosys BlackBox Diagram
7+
----------------------
8+
9+
.. code-block:: rst
10+
11+
.. hdl-diagram:: counter.il
12+
:type: yosys-blackbox
13+
14+
.. hdl-diagram:: counter.il
15+
:type: yosys-blackbox
16+
17+
Yosys AIG Diagram
18+
-----------------
19+
20+
.. code-block:: rst
21+
22+
.. hdl-diagram:: counter.il
23+
:type: yosys-aig
24+
25+
.. hdl-diagram:: counter.il
26+
:type: yosys-aig
27+
28+
Netlistsvg Diagram
29+
------------------
30+
31+
.. code-block:: rst
32+
33+
.. hdl-diagram:: counter.il
34+
:type: netlistsvg
35+
36+
.. hdl-diagram:: counter.il
37+
:type: netlistsvg

0 commit comments

Comments
 (0)