Skip to content

Commit 598533d

Browse files
committed
Add tests for verilog_domain_yosys global setting
Signed-off-by: Robert Winkler <rwinkler@antmicro.com>
1 parent 027f374 commit 598533d

File tree

6 files changed

+280
-22
lines changed

6 files changed

+280
-22
lines changed

.travis.yml

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

25+
- stage: Tests
26+
name: "Test verilog_diagram_yosys config variable"
27+
script:
28+
- source env/conda/bin/activate sphinxcontrib-verilog-diagrams
29+
- cd tests && python3 -m unittest test.TestYosysType
30+
2531
- stage: Build
2632
name: "Build"
2733
script:

environment.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ dependencies:
1111
- pip
1212
- python=3.7
1313
- sphinx
14+
- yosys
1415
- pip: # Packages installed from PyPI
1516
- -r file:requirements.txt
1617
- -r file:docs/requirements.txt

tests/test.py

Lines changed: 104 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
VERILOG_DIAGRAMS_PATH = os.path.abspath("..")
1212

13+
## Helpers
1314

1415
def get_sphinx_dirs(test_build_dir):
1516
sphinx_dirs = {
@@ -29,8 +30,37 @@ def generate_sphinx_config(test_build_dir, **jinja_dict):
2930
template = env.get_template("conf.py.template")
3031
template.stream(**jinja_dict).dump(fd)
3132

33+
## Base class for tests
3234

33-
class TestSkins(unittest.TestCase):
35+
class TestBase(unittest.TestCase):
36+
37+
def print_test_header(self, case_name, test_name):
38+
print("")
39+
print("# ---------------------------------------------------------- #")
40+
print("# TEST CASE: {}".format(case_name))
41+
print("# TEST NAME: {}".format(test_name))
42+
print("# ---------------------------------------------------------- #")
43+
print("")
44+
45+
def prepare_test(self, test_name, test_build_dir, test_files, **test_jinja_dict):
46+
self.print_test_header(self.TEST_CASE_NAME, test_name)
47+
48+
# Create the TestCase build directory
49+
os.makedirs(test_build_dir, exist_ok=True)
50+
51+
# Generate a Sphinx config
52+
generate_sphinx_config(test_build_dir, **test_jinja_dict)
53+
54+
# Copy the test files
55+
for src in test_files:
56+
src_basename = os.path.basename(src)
57+
dst = os.path.join(test_build_dir, src_basename)
58+
shutil.copyfile(src, dst)
59+
60+
61+
## Test cases
62+
63+
class TestSkins(TestBase):
3464

3565
TEST_CASE_NAME = "TestSkins"
3666
TEST_CASE_BUILD_DIR = os.path.join("build", TEST_CASE_NAME)
@@ -50,17 +80,7 @@ def test_netlistsvg_diagram(self):
5080
"custom_variables": "verilog_diagram_skin = os.path.realpath('skin-purple.svg')"
5181
}
5282

53-
# Create the TestCase build directory
54-
os.makedirs(TEST_BUILD_DIR, exist_ok=True)
55-
56-
# Generate a Sphinx config
57-
generate_sphinx_config(TEST_BUILD_DIR, **TEST_JINJA_DICT)
58-
59-
# Copy the test files
60-
for src in TEST_FILES:
61-
src_basename = os.path.basename(src)
62-
dst = os.path.join(TEST_BUILD_DIR, src_basename)
63-
shutil.copyfile(src, dst)
83+
self.prepare_test(TEST_NAME, TEST_BUILD_DIR, TEST_FILES, **TEST_JINJA_DICT)
6484

6585
# Run the Sphinx
6686
sphinx_dirs = get_sphinx_dirs(TEST_BUILD_DIR)
@@ -69,7 +89,7 @@ def test_netlistsvg_diagram(self):
6989
app.build(force_all=True)
7090

7191

72-
class TestYosysScript(unittest.TestCase):
92+
class TestYosysScript(TestBase):
7393

7494
TEST_CASE_NAME = "TestYosysScript"
7595
TEST_CASE_BUILD_DIR = os.path.join("build", TEST_CASE_NAME)
@@ -89,24 +109,86 @@ def test_yosys_script(self):
89109
"custom_variables": "verilog_diagram_yosys_script = os.path.realpath('yosys_script.ys')"
90110
}
91111

92-
# Create the TestCase build directory
93-
os.makedirs(TEST_BUILD_DIR, exist_ok=True)
112+
self.prepare_test(TEST_NAME, TEST_BUILD_DIR, TEST_FILES, **TEST_JINJA_DICT)
94113

95-
# Generate a Sphinx config
96-
generate_sphinx_config(TEST_BUILD_DIR, **TEST_JINJA_DICT)
114+
# Run the Sphinx
115+
sphinx_dirs = get_sphinx_dirs(TEST_BUILD_DIR)
116+
with docutils_namespace():
117+
app = Sphinx(buildername="html", warningiserror=True, **sphinx_dirs)
118+
app.build(force_all=True)
97119

98-
# Copy the test files
99-
for src in TEST_FILES:
100-
src_basename = os.path.basename(src)
101-
dst = os.path.join(TEST_BUILD_DIR, src_basename)
102-
shutil.copyfile(src, dst)
120+
class TestYosysType(TestBase):
121+
122+
TEST_CASE_NAME = "TestYowasp"
123+
TEST_CASE_BUILD_DIR = os.path.join("build", TEST_CASE_NAME)
124+
125+
def test_yosys_yowasp(self):
126+
TEST_NAME = "test_yosys_yowasp"
127+
TEST_BUILD_DIR = os.path.join("build", self.TEST_CASE_NAME, TEST_NAME)
128+
TEST_FILES = [
129+
"test_yosys_type/test_yosys_yowasp.rst",
130+
"verilog/adder.v"
131+
]
132+
TEST_JINJA_DICT = {
133+
"verilog_diagrams_path": "'{}'".format(VERILOG_DIAGRAMS_PATH),
134+
"master_doc": "'test_yosys_yowasp'",
135+
"custom_variables": ""
136+
}
137+
138+
self.prepare_test(TEST_NAME, TEST_BUILD_DIR, TEST_FILES, **TEST_JINJA_DICT)
139+
140+
# Run the Sphinx
141+
sphinx_dirs = get_sphinx_dirs(TEST_BUILD_DIR)
142+
with docutils_namespace():
143+
app = Sphinx(buildername="html", warningiserror=True, **sphinx_dirs)
144+
app.build(force_all=True)
145+
146+
@unittest.skipIf(shutil.which('yosys') is None, 'Skipping test_yosys_system. Yosys is not installed!')
147+
def test_yosys_system(self):
148+
TEST_NAME = "test_yosys_system"
149+
TEST_BUILD_DIR = os.path.join("build", self.TEST_CASE_NAME, TEST_NAME)
150+
TEST_FILES = [
151+
"test_yosys_type/test_yosys_system.rst",
152+
"verilog/adder.v"
153+
]
154+
TEST_JINJA_DICT = {
155+
"verilog_diagrams_path": "'{}'".format(VERILOG_DIAGRAMS_PATH),
156+
"master_doc": "'test_yosys_system'",
157+
"custom_variables": "verilog_diagram_yosys = 'system'"
158+
}
159+
160+
self.prepare_test(TEST_NAME, TEST_BUILD_DIR, TEST_FILES, **TEST_JINJA_DICT)
103161

104162
# Run the Sphinx
105163
sphinx_dirs = get_sphinx_dirs(TEST_BUILD_DIR)
106164
with docutils_namespace():
107165
app = Sphinx(buildername="html", warningiserror=True, **sphinx_dirs)
108166
app.build(force_all=True)
109167

168+
@unittest.skipIf(shutil.which('yosys') is None, 'Skipping test_yosys_path. Yosys is not installed!')
169+
def test_yosys_path(self):
170+
TEST_NAME = "test_yosys_path"
171+
TEST_BUILD_DIR = os.path.join("build", self.TEST_CASE_NAME, TEST_NAME)
172+
TEST_FILES = [
173+
"test_yosys_type/test_yosys_path.rst",
174+
"verilog/adder.v"
175+
]
176+
177+
yosys_path = shutil.which("yosys")
178+
179+
TEST_JINJA_DICT = {
180+
"verilog_diagrams_path": "'{}'".format(VERILOG_DIAGRAMS_PATH),
181+
"master_doc": "'test_yosys_path'",
182+
"custom_variables": "verilog_diagram_yosys = '{}'".format(yosys_path)
183+
}
184+
185+
self.prepare_test(TEST_NAME, TEST_BUILD_DIR, TEST_FILES, **TEST_JINJA_DICT)
186+
187+
# Run the Sphinx
188+
sphinx_dirs = get_sphinx_dirs(TEST_BUILD_DIR)
189+
with docutils_namespace():
190+
app = Sphinx(buildername="html", warningiserror=True, **sphinx_dirs)
191+
app.build(force_all=True)
110192

111193
if __name__ == '__main__':
112194
unittest.main()
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
Test Yowasp - path
2+
==================
3+
4+
This test checks whether the ability to switch between different Yosys types
5+
works as intended. This functionality is enabled by ``verilog_domain_yosys``
6+
variable, which can take the following values:
7+
8+
- ``yowasp`` (default)
9+
- ``system``
10+
- ``<path-to-yosys>``
11+
12+
The diagrams presented below have been generated using the ``<path-to-yosys>`` option.
13+
14+
Here is the fragment of the ``conf.py`` script, used to configure the extension:
15+
16+
.. literalinclude:: conf.py
17+
:lines: 58
18+
19+
Yosys BlackBox Diagram
20+
----------------------
21+
22+
.. code-block:: rst
23+
24+
.. verilog-diagram:: adder.v
25+
:type: yosys-blackbox
26+
:module: ADDER
27+
28+
.. verilog-diagram:: adder.v
29+
:type: yosys-blackbox
30+
:module: ADDER
31+
32+
Yosys AIG Diagram
33+
-----------------
34+
35+
.. code-block:: rst
36+
37+
.. verilog-diagram:: adder.v
38+
:type: yosys-aig
39+
:module: ADDER
40+
41+
.. verilog-diagram:: adder.v
42+
:type: yosys-aig
43+
:module: ADDER
44+
45+
Netlistsvg Diagram
46+
------------------
47+
48+
.. code-block:: rst
49+
50+
.. verilog-diagram:: adder.v
51+
:type: netlistsvg
52+
:module: ADDER
53+
54+
.. verilog-diagram:: adder.v
55+
:type: netlistsvg
56+
:module: ADDER
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
Test Yowasp - system
2+
====================
3+
4+
This test checks whether the ability to switch between different Yosys types
5+
works as intended. This functionality is enabled by ``verilog_domain_yosys``
6+
variable, which can take the following values:
7+
8+
- ``yowasp`` (default)
9+
- ``system``
10+
- ``<path-to-yosys>``
11+
12+
The diagrams presented below have been generated using the ``system`` option.
13+
14+
Here is the fragment of the ``conf.py`` script, used to configure the extension::
15+
16+
verilog_diagram_yosys = 'system'
17+
18+
Yosys BlackBox Diagram
19+
----------------------
20+
21+
.. code-block:: rst
22+
23+
.. verilog-diagram:: adder.v
24+
:type: yosys-blackbox
25+
:module: ADDER
26+
27+
.. verilog-diagram:: adder.v
28+
:type: yosys-blackbox
29+
:module: ADDER
30+
31+
Yosys AIG Diagram
32+
-----------------
33+
34+
.. code-block:: rst
35+
36+
.. verilog-diagram:: adder.v
37+
:type: yosys-aig
38+
:module: ADDER
39+
40+
.. verilog-diagram:: adder.v
41+
:type: yosys-aig
42+
:module: ADDER
43+
44+
Netlistsvg Diagram
45+
------------------
46+
47+
.. code-block:: rst
48+
49+
.. verilog-diagram:: adder.v
50+
:type: netlistsvg
51+
:module: ADDER
52+
53+
.. verilog-diagram:: adder.v
54+
:type: netlistsvg
55+
:module: ADDER
56+
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
Test Yowasp - yowasp
2+
====================
3+
4+
This test checks whether the ability to switch between different Yosys types
5+
works as intended. This functionality is enabled by ``verilog_domain_yosys``
6+
variable, which can take the following values:
7+
8+
- ``yowasp`` (default)
9+
- ``system``
10+
- ``<path-to-yosys>``
11+
12+
The diagrams presented below have been generated using the ``<yowasp>`` option.
13+
14+
Here is the fragment of the ``conf.py`` script, used to configure the extension::
15+
16+
verilog_diagram_yosys = 'yowasp'
17+
18+
.. note:: ``yowasp`` is the default setting. The configuration presented above can be omitted.
19+
20+
Yosys BlackBox Diagram
21+
----------------------
22+
23+
.. code-block:: rst
24+
25+
.. verilog-diagram:: adder.v
26+
:type: yosys-blackbox
27+
:module: ADDER
28+
29+
.. verilog-diagram:: adder.v
30+
:type: yosys-blackbox
31+
:module: ADDER
32+
33+
Yosys AIG Diagram
34+
-----------------
35+
36+
.. code-block:: rst
37+
38+
.. verilog-diagram:: adder.v
39+
:type: yosys-aig
40+
:module: ADDER
41+
42+
.. verilog-diagram:: adder.v
43+
:type: yosys-aig
44+
:module: ADDER
45+
46+
Netlistsvg Diagram
47+
------------------
48+
49+
.. code-block:: rst
50+
51+
.. verilog-diagram:: adder.v
52+
:type: netlistsvg
53+
:module: ADDER
54+
55+
.. verilog-diagram:: adder.v
56+
:type: netlistsvg
57+
:module: ADDER

0 commit comments

Comments
 (0)