Skip to content

Commit 835918b

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 408c327 commit 835918b

File tree

5 files changed

+186
-0
lines changed

5 files changed

+186
-0
lines changed

.travis.yml

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

24+
- stage: Tests
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+
2430
- stage: Build
2531
name: "Build"
2632
script:

tests/test.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,5 +108,43 @@ def test_yosys_script(self):
108108
app.build(force_all=True)
109109

110110

111+
class TestFlatten(unittest.TestCase):
112+
113+
TEST_CASE_NAME = "TestFlatten"
114+
TEST_CASE_BUILD_DIR = os.path.join("build", TEST_CASE_NAME)
115+
116+
def test_yosys_script(self):
117+
TEST_NAME = "test_flatten"
118+
TEST_BUILD_DIR = os.path.join("build", self.TEST_CASE_NAME, TEST_NAME)
119+
TEST_FILES = [
120+
"test_flatten/test_flatten.rst",
121+
"verilog/fullAdder.v",
122+
"verilog/halfAdder.v"
123+
]
124+
TEST_JINJA_DICT = {
125+
"verilog_diagrams_path": "'{}'".format(VERILOG_DIAGRAMS_PATH),
126+
"master_doc": "'test_flatten'",
127+
"custom_variables": ""
128+
}
129+
130+
# Create the TestCase build directory
131+
os.makedirs(TEST_BUILD_DIR, exist_ok=True)
132+
133+
# Generate a Sphinx config
134+
generate_sphinx_config(TEST_BUILD_DIR, **TEST_JINJA_DICT)
135+
136+
# Copy the test files
137+
for src in TEST_FILES:
138+
src_basename = os.path.basename(src)
139+
dst = os.path.join(TEST_BUILD_DIR, src_basename)
140+
shutil.copyfile(src, dst)
141+
142+
# Run the Sphinx
143+
sphinx_dirs = get_sphinx_dirs(TEST_BUILD_DIR)
144+
with docutils_namespace():
145+
app = Sphinx(buildername="html", warningiserror=True, **sphinx_dirs)
146+
app.build(force_all=True)
147+
148+
111149
if __name__ == '__main__':
112150
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)