Skip to content

Commit 3d5f9d8

Browse files
authored
Added the ability to specify a regex filter for the part-name on the synthesis tests. Implemented as --synth-part. Closes #179 (#180)
1 parent 543bf2b commit 3d5f9d8

File tree

5 files changed

+36
-7
lines changed

5 files changed

+36
-7
lines changed

tests/conftest.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,17 @@ def pytest_addoption(parser):
4646
auto: choose the best tool based on what is installed
4747
"""
4848
)
49+
50+
parser.addoption(
51+
"--synth-part",
52+
type=str,
53+
default=".*",
54+
help="""
55+
A REGEX expression used to filter the part used for the synthesis test.
56+
57+
Useful when the default method for finding a part finds a part which you don't have a
58+
license for.
59+
60+
Defaults to '.*'.
61+
"""
62+
)

tests/lib/synth_testcase.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
from typing import List
21
import os
2+
from typing import List
33

44
import pytest
55

66
from .base_testcase import BaseTestCase
77
from .synthesizers import get_synthesizer_cls
88

9+
910
class SynthTestCase(BaseTestCase):
1011

1112
def _get_synth_files(self) -> List[str]:
@@ -26,7 +27,7 @@ def setUp(self) -> None:
2627
def run_synth(self) -> None:
2728
name = self.request.config.getoption("--synth-tool")
2829
synth_cls = get_synthesizer_cls(name)
29-
synth = synth_cls(self)
30+
synth = synth_cls(self, request=self.request)
3031

3132
# cd into the build directory
3233
cwd = os.getcwd()

tests/lib/synthesizers/base.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,28 @@
11
from typing import TYPE_CHECKING, List
22

3+
import pytest
4+
35
if TYPE_CHECKING:
46
from ..synth_testcase import SynthTestCase
57

68
class Synthesizer:
79
name = ""
810

11+
#: this gets auto-loaded via the _load_request autouse fixture
12+
request = None # type: pytest.FixtureRequest
13+
14+
@pytest.fixture(autouse=True)
15+
def _load_request(self, request):
16+
self.request = request
17+
918
@classmethod
1019
def is_installed(cls) -> bool:
1120
raise NotImplementedError
1221

13-
def __init__(self, testcase: 'SynthTestCase' = None) -> None:
22+
def __init__(self, testcase: 'SynthTestCase' = None,
23+
request: 'pytest.FixtureRequest' = None) -> None:
1424
self.testcase = testcase
25+
self.request = request
1526

1627
def run(self) -> None:
1728
raise NotImplementedError

tests/lib/synthesizers/vivado.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import os
2-
import subprocess
32
import shutil
3+
import subprocess
44

55
from .base import Synthesizer
66

7+
78
class Vivado(Synthesizer):
89
name = "vivado"
910

@@ -22,7 +23,7 @@ def run(self) -> None:
2223
"-mode", "batch",
2324
"-log", "out.log",
2425
"-source", script,
25-
"-tclargs"
26+
"-tclargs", self.request.config.getoption("--synth-part")
2627
]
2728
cmd.extend(self.testcase._get_synth_files())
2829

tests/lib/synthesizers/vivado_scripts/run.tcl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
set this_dir [file dirname [file normalize [info script]]]
2-
set files $argv
2+
set files [lrange $argv 1 end]
3+
4+
set part_regex [lindex $argv 0]
35

46

57
# Multi-driven
@@ -22,7 +24,7 @@ set_msg_config -id {[Synth 8-295]} -new_severity "ERROR"
2224
set_msg_config -severity {CRITICAL WARNING} -new_severity "ERROR"
2325

2426

25-
set_part [lindex [get_parts] 0]
27+
set_part [lindex [get_parts -regex $part_regex] 0]
2628
read_verilog -sv $files
2729
read_xdc $this_dir/constr.xdc
2830
synth_design -top regblock -mode out_of_context

0 commit comments

Comments
 (0)