Skip to content

Commit 016885f

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 dd4de9b commit 016885f

File tree

5 files changed

+213
-0
lines changed

5 files changed

+213
-0
lines changed

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ jobs:
2121
script:
2222
- cd tests && python3 -m unittest test.TestYosysScript
2323

24+
name: "Test :flatten: option"
25+
script:
26+
- cd tests && python3 -m unittest test.TestFlatten
27+
2428
- stage: Tests
2529
name: "Test verilog_diagram_yosys config variable"
2630
script:

tests/code/verilog/fullAdder.v

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright (C) 2020 The SymbiFlow Authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* SPDX-License-Identifier: Apache-2.0
17+
*/
18+
19+
`include "halfAdder.v"
20+
21+
module fullAdder (
22+
output wire cout, s,
23+
input wire cin, x, y
24+
);
25+
wire c1, c2, s1;
26+
27+
halfAdder h1(c1, s1, x, y);
28+
halfAdder h2(c2, s, cin, s1);
29+
30+
assign cout = c1 | c2;
31+
32+
endmodule

tests/code/verilog/halfAdder.v

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright (C) 2020 The SymbiFlow Authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* SPDX-License-Identifier: Apache-2.0
17+
*/
18+
19+
module halfAdder (
20+
output wire c, s,
21+
input wire x, y
22+
);
23+
24+
assign s = x ^ y;
25+
assign c = x & y;
26+
27+
endmodule

tests/test.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ def test_yosys_script(self):
117117
app = Sphinx(buildername="html", warningiserror=True, **sphinx_dirs)
118118
app.build(force_all=True)
119119

120+
120121
class TestYosysType(TestBase):
121122

122123
TEST_CASE_NAME = "TestYowasp"
@@ -190,6 +191,7 @@ def test_yosys_path(self):
190191
app = Sphinx(buildername="html", warningiserror=True, **sphinx_dirs)
191192
app.build(force_all=True)
192193

194+
193195
class TestNMigen(TestBase):
194196

195197
TEST_CASE_NAME = "TestNMigen"
@@ -216,6 +218,7 @@ def test_yosys_script(self):
216218
app = Sphinx(buildername="html", warningiserror=True, **sphinx_dirs)
217219
app.build(force_all=True)
218220

221+
219222
class TestRTLIL(TestBase):
220223

221224
TEST_CASE_NAME = "TestRTLIL"
@@ -273,5 +276,33 @@ def test_yosys_script(self):
273276
app.build(force_all=True)
274277

275278

279+
class TestFlatten(TestBase):
280+
281+
TEST_CASE_NAME = "TestFlatten"
282+
TEST_CASE_BUILD_DIR = os.path.join("build", TEST_CASE_NAME)
283+
284+
def test_yosys_script(self):
285+
TEST_NAME = "test_flatten"
286+
TEST_BUILD_DIR = os.path.join("build", self.TEST_CASE_NAME, TEST_NAME)
287+
TEST_FILES = [
288+
"test_flatten/test_flatten.rst",
289+
"code/verilog/fullAdder.v",
290+
"code/verilog/halfAdder.v"
291+
]
292+
TEST_JINJA_DICT = {
293+
"hdl_diagrams_path": "'{}'".format(HDL_DIAGRAMS_PATH),
294+
"master_doc": "'test_flatten'",
295+
"custom_variables": ""
296+
}
297+
298+
self.prepare_test(TEST_NAME, TEST_BUILD_DIR, TEST_FILES, **TEST_JINJA_DICT)
299+
300+
# Run the Sphinx
301+
sphinx_dirs = get_sphinx_dirs(TEST_BUILD_DIR)
302+
with docutils_namespace():
303+
app = Sphinx(buildername="html", warningiserror=True, **sphinx_dirs)
304+
app.build(force_all=True)
305+
306+
276307
if __name__ == '__main__':
277308
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:

0 commit comments

Comments
 (0)