Skip to content

Commit 300860c

Browse files
committed
Clean up test suite and get it running
1 parent 691a504 commit 300860c

File tree

12 files changed

+272
-470
lines changed

12 files changed

+272
-470
lines changed

chipflow_lib/platforms/utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ def invert(self) -> Iterable[bool]:
198198
assert type(self._model['invert']) is tuple
199199
return self._model['invert']
200200

201+
@property
201202
def options(self) -> _IOModelOptions:
202203
"""
203204
Options set on the io port at construction

chipflow_lib/steps/silicon.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def elaborate(self, platform: SiliconPlatform):
3737

3838
# heartbeat led (to confirm clock/reset alive)
3939
if (self._config.chipflow.silicon.debug and
40-
self._config.chipflow.silicon.debug.heartbeat):
40+
self._config.chipflow.silicon.debug.get('heartbeat', False)):
4141
heartbeat_ctr = Signal(23)
4242
m.d.sync += heartbeat_ctr.eq(heartbeat_ctr + 1)
4343
m.d.comb += platform.request("heartbeat").o.eq(heartbeat_ctr[-1])

docs/example-chipflow.toml

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,6 @@ project_name = "test-chip"
44
[chipflow.top]
55
soc = "my_design.design:MySoC"
66

7-
[chipflow.steps]
8-
silicon = "chipflow_lib.steps.silicon:SiliconStep"
9-
10-
[chipflow.clocks]
11-
default = 'sys_clk'
12-
13-
[chipflow.resets]
14-
default = 'sys_rst_n'
15-
167
[chipflow.silicon]
178
process = "gf130bcd"
189
package = "pga144"
19-
20-
[chipflow.silicon.pads]
21-
# System
22-
sys_clk = { type = "clock", loc = "114" }
23-
sys_rst_n = { type = "reset", loc = "115" }
24-
25-
[chipflow.silicon.power]
26-
dvss0 = { type = "power", loc = "1" }
27-
dvdd0 = { type = "ground", loc = "9" }
28-
vss0 = { type = "power", loc = "17" }
29-
vdd0 = { type = "ground", loc = "25" }
30-
dvss1 = { type = "power", loc = "33" }
31-
dvdd1 = { type = "ground", loc = "41" }
32-
vss1 = { type = "power", loc = "49" }
33-
vdd1 = { type = "ground", loc = "57" }
34-
dvss2 = { type = "power", loc = "65" }
35-
dvdd2 = { type = "ground", loc = "73" }
36-
vss2 = { type = "power", loc = "81" }
37-
vdd2 = { type = "ground", loc = "89" }
38-
dvss3 = { type = "power", loc = "97" }
39-
dvdd3 = { type = "ground", loc = "105" }
40-
vss3 = { type = "power", loc = "113" }
41-
vdd3 = { type = "ground", loc = "121" }
42-
dvss4 = { type = "power", loc = "129" }
43-
dvdd4 = { type = "ground", loc = "137" }

pdm.lock

Lines changed: 23 additions & 122 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ dependencies = [
2626
"doit>=0.36.0",
2727
"requests>=2.20",
2828
"python-dotenv>=1.0.1",
29-
"pydantic>=2.8",
29+
"pydantic>=2.11",
3030
"halo>=0.0.31",
3131
"pyrefly>=0.21.0",
3232
"amaranth-stubs>=0.1.1",

tests/test_cli.py

Lines changed: 10 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from chipflow_lib import ChipFlowError
88
from chipflow_lib.cli import run
9-
9+
from chipflow_lib.config_models import Config, ChipFlowConfig
1010

1111
class MockCommand:
1212
"""Mock command for testing CLI"""
@@ -22,6 +22,9 @@ def run_cli(self, args):
2222
raise ValueError("Unexpected error")
2323
# Valid action does nothing
2424

25+
MOCK_CONFIG = Config(chipflow=ChipFlowConfig(project_name="test",
26+
steps={"test": "test:MockStep"}
27+
))
2528

2629
class TestCLI(unittest.TestCase):
2730
@mock.patch("chipflow_lib.cli._parse_config")
@@ -30,14 +33,7 @@ class TestCLI(unittest.TestCase):
3033
def test_run_success(self, mock_get_cls, mock_pin_command, mock_parse_config):
3134
"""Test CLI run with successful command execution"""
3235
# Setup mocks
33-
mock_config = {
34-
"chipflow": {
35-
"steps": {
36-
"test": "test:MockStep"
37-
}
38-
}
39-
}
40-
mock_parse_config.return_value = mock_config
36+
mock_parse_config.return_value = MOCK_CONFIG
4137

4238
mock_pin_cmd = MockCommand()
4339
mock_pin_command.return_value = mock_pin_cmd
@@ -59,14 +55,7 @@ def test_run_success(self, mock_get_cls, mock_pin_command, mock_parse_config):
5955
def test_run_command_error(self, mock_get_cls, mock_pin_command, mock_parse_config):
6056
"""Test CLI run with command raising ChipFlowError"""
6157
# Setup mocks
62-
mock_config = {
63-
"chipflow": {
64-
"steps": {
65-
"test": "test:MockStep"
66-
}
67-
}
68-
}
69-
mock_parse_config.return_value = mock_config
58+
mock_parse_config.return_value = MOCK_CONFIG
7059

7160
mock_pin_cmd = MockCommand()
7261
mock_pin_command.return_value = mock_pin_cmd
@@ -93,14 +82,7 @@ def test_run_command_error(self, mock_get_cls, mock_pin_command, mock_parse_conf
9382
def test_run_unexpected_error(self, mock_get_cls, mock_pin_command, mock_parse_config):
9483
"""Test CLI run with command raising unexpected exception"""
9584
# Setup mocks
96-
mock_config = {
97-
"chipflow": {
98-
"steps": {
99-
"test": "test:MockStep"
100-
}
101-
}
102-
}
103-
mock_parse_config.return_value = mock_config
85+
mock_parse_config.return_value = MOCK_CONFIG
10486

10587
mock_pin_cmd = MockCommand()
10688
mock_pin_command.return_value = mock_pin_cmd
@@ -127,14 +109,7 @@ def test_run_unexpected_error(self, mock_get_cls, mock_pin_command, mock_parse_c
127109
def test_step_init_error(self, mock_pin_command, mock_parse_config):
128110
"""Test CLI run with error initializing step"""
129111
# Setup mocks
130-
mock_config = {
131-
"chipflow": {
132-
"steps": {
133-
"test": "test:MockStep"
134-
}
135-
}
136-
}
137-
mock_parse_config.return_value = mock_config
112+
mock_parse_config.return_value = MOCK_CONFIG
138113

139114
mock_pin_cmd = MockCommand()
140115
mock_pin_command.return_value = mock_pin_cmd
@@ -154,14 +129,7 @@ def test_step_init_error(self, mock_pin_command, mock_parse_config):
154129
def test_build_parser_error(self, mock_get_cls, mock_pin_command, mock_parse_config):
155130
"""Test CLI run with error building CLI parser"""
156131
# Setup mocks
157-
mock_config = {
158-
"chipflow": {
159-
"steps": {
160-
"test": "test:MockStep"
161-
}
162-
}
163-
}
164-
mock_parse_config.return_value = mock_config
132+
mock_parse_config.return_value = MOCK_CONFIG
165133

166134
# Make pin command raise an error during build_cli_parser
167135
mock_pin_cmd = mock.Mock()
@@ -183,14 +151,7 @@ def test_build_parser_error(self, mock_get_cls, mock_pin_command, mock_parse_con
183151
# def test_verbosity_flags(self, mock_get_cls, mock_pin_command, mock_parse_config):
184152
# """Test CLI verbosity flags"""
185153
# # Setup mocks
186-
# mock_config = {
187-
# "chipflow": {
188-
# "steps": {
189-
# "test": "test:MockStep"
190-
# }
191-
# }
192-
# }
193-
# mock_parse_config.return_value = mock_config
154+
# mock_parse_config.return_value = MOCK_CONFIG
194155
#
195156
# mock_pin_cmd = MockCommand()
196157
# mock_pin_command.return_value = mock_pin_cmd

tests/test_init.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@
1111
ChipFlowError,
1212
_get_cls_by_reference,
1313
_ensure_chipflow_root,
14-
_parse_config_file,
1514
_parse_config
1615
)
17-
from chipflow_lib.config_model import Config, ChipFlowConfig
16+
from chipflow_lib.config import _parse_config_file
17+
from chipflow_lib.config_models import Config, ChipFlowConfig
18+
from chipflow_lib.platforms import Process
1819

1920

2021
class TestCoreUtilities(unittest.TestCase):
@@ -67,7 +68,7 @@ def test_ensure_chipflow_root_already_set(self):
6768
os.environ["CHIPFLOW_ROOT"] = "/test/path"
6869
sys.path = ["/some/other/path"]
6970

70-
_ensure_chipflow_root.root = None
71+
_ensure_chipflow_root.root = None #type: ignore
7172
result = _ensure_chipflow_root()
7273

7374
self.assertEqual(result, Path("/test/path"))
@@ -77,7 +78,7 @@ def test_ensure_chipflow_root_not_set(self):
7778
"""Test _ensure_chipflow_root when CHIPFLOW_ROOT is not set"""
7879
if "CHIPFLOW_ROOT" in os.environ:
7980
del os.environ["CHIPFLOW_ROOT"]
80-
_ensure_chipflow_root.root = None
81+
_ensure_chipflow_root.root = None #type: ignore
8182

8283
with mock.patch("os.getcwd", return_value="/mock/cwd"):
8384
result = _ensure_chipflow_root()
@@ -107,15 +108,16 @@ def test_parse_config_file_valid(self):
107108
config = _parse_config_file(config_path)
108109

109110
assert config.chipflow
111+
assert config.chipflow.silicon
110112
self.assertEqual(config.chipflow.project_name, "test_project")
111-
self.assertEqual(config.chipflow.silicon.process, "sky130")
113+
self.assertEqual(config.chipflow.silicon.process, Process.SKY130)
112114

113115
@mock.patch("chipflow_lib._ensure_chipflow_root")
114-
@mock.patch("chipflow_lib._parse_config_file")
116+
@mock.patch("chipflow_lib.config._parse_config_file")
115117
def test_parse_config(self, mock_parse_config_file, mock_ensure_chipflow_root):
116118
"""Test _parse_config which uses _ensure_chipflow_root and _parse_config_file"""
117119
mock_ensure_chipflow_root.return_value = "/mock/chipflow/root"
118-
mock_parse_config_file.return_value = Config(chipflow=ChipFlowConfig(project_name='test', top={'test','test'}))
120+
mock_parse_config_file.return_value = Config(chipflow=ChipFlowConfig(project_name='test', top={'test': 'test'}))
119121

120122
config = _parse_config()
121123

@@ -126,4 +128,4 @@ def test_parse_config(self, mock_parse_config_file, mock_ensure_chipflow_root):
126128
else mock_parse_config_file.call_args[0][0],
127129
"/mock/chipflow/root/chipflow.toml")
128130
self.assertEqual(config.chipflow.project_name, "test")
129-
self.assertEqual(config.chipflow.project_name.top, {'test': 'test'})
131+
self.assertEqual(config.chipflow.top, {'test': 'test'})

0 commit comments

Comments
 (0)