Skip to content

Commit 79255d5

Browse files
committed
Fix up gpio tests
1 parent 1a0a147 commit 79255d5

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

chipflow_digital_ip/io/_gpio.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,13 @@ class GPIOPeripheral(wiring.Component):
4444
"""
4545

4646
def __init__(self, *, pin_count, addr_width=4, data_width=8, input_stages=2):
47-
if pin_count > 32:
47+
if type(pin_count) is not int:
48+
raise TypeError(f"Pin count must be a positive integer, not {pin_count}")
49+
50+
if pin_count > 32 or pin_count <= 0:
4851
# TODO: why?
49-
raise ValueError(f"Pin pin_count must be lesser than or equal to 32, not {pin_count}")
52+
raise ValueError(f"Pin pin_count must be a postive integrer less than 32, not {pin_count}")
53+
5054
self._gpio = gpio.Peripheral(pin_count=pin_count,
5155
addr_width=addr_width,
5256
data_width=data_width,

tests/test_gpio.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
# SPDX-License-Identifier: BSD-2-Clause
44

55
import unittest
6+
import warnings
7+
68
from amaranth import *
79
from amaranth.sim import *
10+
from amaranth.hdl import UnusedElaboratable
811

912
from chipflow_digital_ip.io import GPIOPeripheral
1013

@@ -24,11 +27,18 @@ def test_init(self):
2427

2528
def test_init_wrong_pin_count(self):
2629
with self.assertRaisesRegex(TypeError,
27-
r"Pin count must be a positive integer, not 'foo'"):
30+
r"Pin count must be a positive integer, not foo"):
2831
GPIOPeripheral(pin_count="foo", addr_width=2, data_width=8)
29-
with self.assertRaisesRegex(TypeError,
30-
r"Pin count must be a positive integer, not 0"):
32+
with self.assertRaisesRegex(ValueError,
33+
r"Pin pin_count must be a postive integrer less than 32, not -1"):
34+
GPIOPeripheral(pin_count=-1, addr_width=2, data_width=8)
35+
with self.assertRaisesRegex(ValueError,
36+
r"Pin pin_count must be a postive integrer less than 32, not 0"):
3137
GPIOPeripheral(pin_count=0, addr_width=2, data_width=8)
38+
with self.assertRaisesRegex(ValueError,
39+
r"Pin pin_count must be a postive integrer less than 32, not 33"):
40+
GPIOPeripheral(pin_count=33, addr_width=2, data_width=8)
41+
3242

3343
def test_init_wrong_input_stages(self):
3444
with self.assertRaisesRegex(TypeError,
@@ -53,6 +63,9 @@ def test_smoke_test(self):
5363
"""
5464
Smoke test GPIO. We assume that amaranth-soc GPIO tests are fully testing functionality.
5565
"""
66+
67+
warnings.simplefilter(action="ignore", category=UnusedElaboratable)
68+
5669
dut = GPIOPeripheral(pin_count=4, addr_width=2, data_width=8)
5770

5871
mode_addr = 0x0

0 commit comments

Comments
 (0)