Skip to content

Commit 4e56be3

Browse files
committed
Add flatten option tests
This commit adds a basic test for the flatten option in the verilog-diagram directive. Signed-off-by: Robert Winkler <rwinkler@antmicro.com>
1 parent ac79fa4 commit 4e56be3

File tree

5 files changed

+185
-0
lines changed

5 files changed

+185
-0
lines changed

.travis.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ jobs:
2222
- source env/conda/bin/activate sphinxcontrib-verilog-diagrams
2323
- cd tests && python3 -m unittest test.TestYosysScript
2424

25+
name: "Test :flatten: option"
26+
script:
27+
- source env/conda/bin/activate sphinxcontrib-verilog-diagrams
28+
- cd tests && python3 -m unittest test.TestFlatten
29+
2530
- stage: Tests
2631
name: "Test verilog_diagram_yosys config variable"
2732
script:

tests/test.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,5 +190,43 @@ def test_yosys_path(self):
190190
app = Sphinx(buildername="html", warningiserror=True, **sphinx_dirs)
191191
app.build(force_all=True)
192192

193+
class TestFlatten(unittest.TestCase):
194+
195+
TEST_CASE_NAME = "TestFlatten"
196+
TEST_CASE_BUILD_DIR = os.path.join("build", TEST_CASE_NAME)
197+
198+
def test_yosys_script(self):
199+
TEST_NAME = "test_flatten"
200+
TEST_BUILD_DIR = os.path.join("build", self.TEST_CASE_NAME, TEST_NAME)
201+
TEST_FILES = [
202+
"test_flatten/test_flatten.rst",
203+
"verilog/fullAdder.v",
204+
"verilog/halfAdder.v"
205+
]
206+
TEST_JINJA_DICT = {
207+
"verilog_diagrams_path": "'{}'".format(VERILOG_DIAGRAMS_PATH),
208+
"master_doc": "'test_flatten'",
209+
"custom_variables": ""
210+
}
211+
212+
# Create the TestCase build directory
213+
os.makedirs(TEST_BUILD_DIR, exist_ok=True)
214+
215+
# Generate a Sphinx config
216+
generate_sphinx_config(TEST_BUILD_DIR, **TEST_JINJA_DICT)
217+
218+
# Copy the test files
219+
for src in TEST_FILES:
220+
src_basename = os.path.basename(src)
221+
dst = os.path.join(TEST_BUILD_DIR, src_basename)
222+
shutil.copyfile(src, dst)
223+
224+
# Run the Sphinx
225+
sphinx_dirs = get_sphinx_dirs(TEST_BUILD_DIR)
226+
with docutils_namespace():
227+
app = Sphinx(buildername="html", warningiserror=True, **sphinx_dirs)
228+
app.build(force_all=True)
229+
230+
193231
if __name__ == '__main__':
194232
unittest.main()
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
Test Flatten Option
2+
===================
3+
4+
This test checks whether the ``:flatten:`` option in the ``verilog-diagram``
5+
directive works as intended. The ``:flatten:`` option is used to resolve
6+
the black boxes created by Yosys in place of instantiated modules.
7+
With this option enabled Yosys will convert everything into low-level logic
8+
where only basic logic cells and basic FPGA primitives will be used.
9+
10+
Netlistsvg Diagram
11+
------------------
12+
13+
Here is the diagram of a half-adder with its RST code::
14+
15+
.. verilog-diagram:: halfAdder.v
16+
:type: netlistsvg
17+
:module: halfAdder
18+
19+
.. verilog-diagram:: halfAdder.v
20+
:type: netlistsvg
21+
:module: halfAdder
22+
23+
The diagram below has been created without the ``:flatten:`` option::
24+
25+
.. verilog-diagram:: fullAdder.v
26+
:type: netlistsvg
27+
:module: fullAdder
28+
29+
.. verilog-diagram:: fullAdder.v
30+
:type: netlistsvg
31+
:module: fullAdder
32+
33+
The diagram below has been created using the ``:flatten:`` option.
34+
You can see that the ``halfAdder`` black box is substituted by the appropriate
35+
logic elements::
36+
37+
.. verilog-diagram:: fullAdder.v
38+
:type: netlistsvg
39+
:module: fullAdder
40+
:flatten:
41+
42+
.. verilog-diagram:: fullAdder.v
43+
:type: netlistsvg
44+
:module: fullAdder
45+
:flatten:
46+
47+
Yosys BlackBox Diagram
48+
----------------------
49+
50+
Here is the diagram of a half-adder with its RST code::
51+
52+
.. verilog-diagram:: halfAdder.v
53+
:type: yosys-blackbox
54+
:module: halfAdder
55+
56+
.. verilog-diagram:: halfAdder.v
57+
:type: yosys-blackbox
58+
:module: halfAdder
59+
60+
The diagram below has been created without the ``:flatten:`` option::
61+
62+
.. verilog-diagram:: fullAdder.v
63+
:type: yosys-blackbox
64+
:module: fullAdder
65+
66+
.. verilog-diagram:: fullAdder.v
67+
:type: yosys-blackbox
68+
:module: fullAdder
69+
70+
The diagram below has been created using the ``:flatten:`` option.
71+
You can see that the ``halfAdder`` black box is substituted by the appropriate
72+
logic elements::
73+
74+
.. verilog-diagram:: fullAdder.v
75+
:type: yosys-blackbox
76+
:module: fullAdder
77+
:flatten:
78+
79+
.. verilog-diagram:: fullAdder.v
80+
:type: yosys-blackbox
81+
:module: fullAdder
82+
:flatten:
83+
84+
Yosys AIG Diagram
85+
-----------------
86+
87+
Here is the diagram of a half-adder with its RST code::
88+
89+
.. verilog-diagram:: halfAdder.v
90+
:type: yosys-aig
91+
:module: halfAdder
92+
93+
.. verilog-diagram:: halfAdder.v
94+
:type: yosys-aig
95+
:module: halfAdder
96+
97+
The diagram below has been created without the ``:flatten:`` option::
98+
99+
.. verilog-diagram:: fullAdder.v
100+
:type: yosys-aig
101+
:module: fullAdder
102+
103+
.. verilog-diagram:: fullAdder.v
104+
:type: yosys-aig
105+
:module: fullAdder
106+
107+
The diagram below has been created using the ``:flatten:`` option.
108+
You can see that the ``halfAdder`` black box is substituted by the appropriate
109+
logic elements::
110+
111+
.. verilog-diagram:: fullAdder.v
112+
:type: yosys-aig
113+
:module: fullAdder
114+
:flatten:
115+
116+
.. verilog-diagram:: fullAdder.v
117+
:type: yosys-aig
118+
:module: fullAdder
119+
:flatten:

tests/verilog/fullAdder.v

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
`include "halfAdder.v"
2+
3+
module fullAdder (
4+
output wire cout, s,
5+
input wire cin, x, y
6+
);
7+
wire c1, c2, s1;
8+
9+
halfAdder h1(c1, s1, x, y);
10+
halfAdder h2(c2, s, cin, s1);
11+
12+
assign cout = c1 | c2;
13+
14+
endmodule

tests/verilog/halfAdder.v

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module halfAdder (
2+
output wire c, s,
3+
input wire x, y
4+
);
5+
6+
assign s = x ^ y;
7+
assign c = x & y;
8+
9+
endmodule

0 commit comments

Comments
 (0)