2021-12-09 22:39:50 -07:00
|
|
|
from amaranth.hdl import *
|
|
|
|
from amaranth.hdl.rec import *
|
|
|
|
from amaranth.sim import *
|
|
|
|
from amaranth.lib.io import *
|
tests: move out of the main package.
Compared to tests in the repository root, tests in the package have
many downsides:
* Unless explicitly excluded in find_packages(), tests and their
support code effectively become a part of public API.
This, unfortunately, happened with FHDLTestCase, which was never
intended for downstream use.
* Even if explicitly excluded from the setuptools package, using
an editable install, or setting PYTHONPATH still allows accessing
the tests.
* Having a sub-package that is present in the source tree but not
exported (or, worse, exported only sometimes) is confusing.
* The name `nmigen.test` cannot be used for anything else, such as
testing utilities that *are* intended for downstream use.
2020-08-26 18:33:31 -06:00
|
|
|
|
2019-10-13 12:53:38 -06:00
|
|
|
from .utils import *
|
2019-04-15 10:27:23 -06:00
|
|
|
|
|
|
|
|
2020-06-04 21:19:46 -06:00
|
|
|
class PinLayoutTestCase(FHDLTestCase):
|
|
|
|
def assertLayoutEqual(self, layout, expected):
|
|
|
|
casted_layout = {}
|
|
|
|
for name, (shape, dir) in layout.items():
|
|
|
|
casted_layout[name] = (Shape.cast(shape), dir)
|
|
|
|
|
|
|
|
self.assertEqual(casted_layout, expected)
|
|
|
|
|
|
|
|
|
|
|
|
class PinLayoutCombTestCase(PinLayoutTestCase):
|
2019-04-15 10:27:23 -06:00
|
|
|
def test_pin_layout_i(self):
|
|
|
|
layout_1 = pin_layout(1, dir="i")
|
2020-06-04 21:19:46 -06:00
|
|
|
self.assertLayoutEqual(layout_1.fields, {
|
2019-05-25 15:57:07 -06:00
|
|
|
"i": ((1, False), DIR_NONE),
|
2019-04-15 10:27:23 -06:00
|
|
|
})
|
|
|
|
|
|
|
|
layout_2 = pin_layout(2, dir="i")
|
2020-06-04 21:19:46 -06:00
|
|
|
self.assertLayoutEqual(layout_2.fields, {
|
2019-05-25 15:57:07 -06:00
|
|
|
"i": ((2, False), DIR_NONE),
|
2019-04-15 10:27:23 -06:00
|
|
|
})
|
|
|
|
|
|
|
|
def test_pin_layout_o(self):
|
|
|
|
layout_1 = pin_layout(1, dir="o")
|
2020-06-04 21:19:46 -06:00
|
|
|
self.assertLayoutEqual(layout_1.fields, {
|
2019-05-25 15:57:07 -06:00
|
|
|
"o": ((1, False), DIR_NONE),
|
2019-04-15 10:27:23 -06:00
|
|
|
})
|
|
|
|
|
|
|
|
layout_2 = pin_layout(2, dir="o")
|
2020-06-04 21:19:46 -06:00
|
|
|
self.assertLayoutEqual(layout_2.fields, {
|
2019-05-25 15:57:07 -06:00
|
|
|
"o": ((2, False), DIR_NONE),
|
2019-04-15 10:27:23 -06:00
|
|
|
})
|
|
|
|
|
2019-06-02 22:28:53 -06:00
|
|
|
def test_pin_layout_oe(self):
|
|
|
|
layout_1 = pin_layout(1, dir="oe")
|
2020-06-04 21:19:46 -06:00
|
|
|
self.assertLayoutEqual(layout_1.fields, {
|
2019-06-02 22:28:53 -06:00
|
|
|
"o": ((1, False), DIR_NONE),
|
|
|
|
"oe": ((1, False), DIR_NONE),
|
|
|
|
})
|
|
|
|
|
|
|
|
layout_2 = pin_layout(2, dir="oe")
|
2020-06-04 21:19:46 -06:00
|
|
|
self.assertLayoutEqual(layout_2.fields, {
|
2019-06-02 22:28:53 -06:00
|
|
|
"o": ((2, False), DIR_NONE),
|
|
|
|
"oe": ((1, False), DIR_NONE),
|
|
|
|
})
|
|
|
|
|
2019-04-15 10:27:23 -06:00
|
|
|
def test_pin_layout_io(self):
|
|
|
|
layout_1 = pin_layout(1, dir="io")
|
2020-06-04 21:19:46 -06:00
|
|
|
self.assertLayoutEqual(layout_1.fields, {
|
2019-05-25 15:57:07 -06:00
|
|
|
"i": ((1, False), DIR_NONE),
|
|
|
|
"o": ((1, False), DIR_NONE),
|
|
|
|
"oe": ((1, False), DIR_NONE),
|
2019-04-15 10:27:23 -06:00
|
|
|
})
|
|
|
|
|
|
|
|
layout_2 = pin_layout(2, dir="io")
|
2020-06-04 21:19:46 -06:00
|
|
|
self.assertLayoutEqual(layout_2.fields, {
|
2019-05-25 15:57:07 -06:00
|
|
|
"i": ((2, False), DIR_NONE),
|
|
|
|
"o": ((2, False), DIR_NONE),
|
|
|
|
"oe": ((1, False), DIR_NONE),
|
2019-04-15 10:27:23 -06:00
|
|
|
})
|
|
|
|
|
|
|
|
|
2020-06-04 21:19:46 -06:00
|
|
|
class PinLayoutSDRTestCase(PinLayoutTestCase):
|
2019-06-02 21:29:27 -06:00
|
|
|
def test_pin_layout_i(self):
|
|
|
|
layout_1 = pin_layout(1, dir="i", xdr=1)
|
2020-06-04 21:19:46 -06:00
|
|
|
self.assertLayoutEqual(layout_1.fields, {
|
2019-06-02 23:56:18 -06:00
|
|
|
"i_clk": ((1, False), DIR_NONE),
|
2019-06-02 21:29:27 -06:00
|
|
|
"i": ((1, False), DIR_NONE),
|
|
|
|
})
|
|
|
|
|
|
|
|
layout_2 = pin_layout(2, dir="i", xdr=1)
|
2020-06-04 21:19:46 -06:00
|
|
|
self.assertLayoutEqual(layout_2.fields, {
|
2019-06-02 23:56:18 -06:00
|
|
|
"i_clk": ((1, False), DIR_NONE),
|
2019-06-02 21:29:27 -06:00
|
|
|
"i": ((2, False), DIR_NONE),
|
|
|
|
})
|
|
|
|
|
|
|
|
def test_pin_layout_o(self):
|
|
|
|
layout_1 = pin_layout(1, dir="o", xdr=1)
|
2020-06-04 21:19:46 -06:00
|
|
|
self.assertLayoutEqual(layout_1.fields, {
|
2019-06-02 23:56:18 -06:00
|
|
|
"o_clk": ((1, False), DIR_NONE),
|
2019-06-02 21:29:27 -06:00
|
|
|
"o": ((1, False), DIR_NONE),
|
|
|
|
})
|
|
|
|
|
|
|
|
layout_2 = pin_layout(2, dir="o", xdr=1)
|
2020-06-04 21:19:46 -06:00
|
|
|
self.assertLayoutEqual(layout_2.fields, {
|
2019-06-02 23:56:18 -06:00
|
|
|
"o_clk": ((1, False), DIR_NONE),
|
2019-06-02 21:29:27 -06:00
|
|
|
"o": ((2, False), DIR_NONE),
|
|
|
|
})
|
|
|
|
|
2019-06-02 22:28:53 -06:00
|
|
|
def test_pin_layout_oe(self):
|
|
|
|
layout_1 = pin_layout(1, dir="oe", xdr=1)
|
2020-06-04 21:19:46 -06:00
|
|
|
self.assertLayoutEqual(layout_1.fields, {
|
2019-06-02 23:56:18 -06:00
|
|
|
"o_clk": ((1, False), DIR_NONE),
|
2019-06-02 22:28:53 -06:00
|
|
|
"o": ((1, False), DIR_NONE),
|
|
|
|
"oe": ((1, False), DIR_NONE),
|
|
|
|
})
|
|
|
|
|
|
|
|
layout_2 = pin_layout(2, dir="oe", xdr=1)
|
2020-06-04 21:19:46 -06:00
|
|
|
self.assertLayoutEqual(layout_2.fields, {
|
2019-06-02 23:56:18 -06:00
|
|
|
"o_clk": ((1, False), DIR_NONE),
|
2019-06-02 22:28:53 -06:00
|
|
|
"o": ((2, False), DIR_NONE),
|
|
|
|
"oe": ((1, False), DIR_NONE),
|
|
|
|
})
|
|
|
|
|
2019-06-02 21:29:27 -06:00
|
|
|
def test_pin_layout_io(self):
|
|
|
|
layout_1 = pin_layout(1, dir="io", xdr=1)
|
2020-06-04 21:19:46 -06:00
|
|
|
self.assertLayoutEqual(layout_1.fields, {
|
2019-06-02 23:56:18 -06:00
|
|
|
"i_clk": ((1, False), DIR_NONE),
|
2019-06-02 21:29:27 -06:00
|
|
|
"i": ((1, False), DIR_NONE),
|
2019-06-02 23:56:18 -06:00
|
|
|
"o_clk": ((1, False), DIR_NONE),
|
2019-06-02 21:29:27 -06:00
|
|
|
"o": ((1, False), DIR_NONE),
|
|
|
|
"oe": ((1, False), DIR_NONE),
|
|
|
|
})
|
|
|
|
|
|
|
|
layout_2 = pin_layout(2, dir="io", xdr=1)
|
2020-06-04 21:19:46 -06:00
|
|
|
self.assertLayoutEqual(layout_2.fields, {
|
2019-06-02 23:56:18 -06:00
|
|
|
"i_clk": ((1, False), DIR_NONE),
|
2019-06-02 21:29:27 -06:00
|
|
|
"i": ((2, False), DIR_NONE),
|
2019-06-02 23:56:18 -06:00
|
|
|
"o_clk": ((1, False), DIR_NONE),
|
2019-06-02 21:29:27 -06:00
|
|
|
"o": ((2, False), DIR_NONE),
|
|
|
|
"oe": ((1, False), DIR_NONE),
|
|
|
|
})
|
|
|
|
|
|
|
|
|
2020-06-04 21:19:46 -06:00
|
|
|
class PinLayoutDDRTestCase(PinLayoutTestCase):
|
2019-04-15 10:27:23 -06:00
|
|
|
def test_pin_layout_i(self):
|
|
|
|
layout_1 = pin_layout(1, dir="i", xdr=2)
|
2020-06-04 21:19:46 -06:00
|
|
|
self.assertLayoutEqual(layout_1.fields, {
|
2019-06-02 23:56:18 -06:00
|
|
|
"i_clk": ((1, False), DIR_NONE),
|
2019-05-25 15:57:07 -06:00
|
|
|
"i0": ((1, False), DIR_NONE),
|
|
|
|
"i1": ((1, False), DIR_NONE),
|
2019-04-15 10:27:23 -06:00
|
|
|
})
|
|
|
|
|
|
|
|
layout_2 = pin_layout(2, dir="i", xdr=2)
|
2020-06-04 21:19:46 -06:00
|
|
|
self.assertLayoutEqual(layout_2.fields, {
|
2019-06-02 23:56:18 -06:00
|
|
|
"i_clk": ((1, False), DIR_NONE),
|
2019-05-25 15:57:07 -06:00
|
|
|
"i0": ((2, False), DIR_NONE),
|
|
|
|
"i1": ((2, False), DIR_NONE),
|
2019-04-15 10:27:23 -06:00
|
|
|
})
|
|
|
|
|
|
|
|
def test_pin_layout_o(self):
|
|
|
|
layout_1 = pin_layout(1, dir="o", xdr=2)
|
2020-06-04 21:19:46 -06:00
|
|
|
self.assertLayoutEqual(layout_1.fields, {
|
2019-06-02 23:56:18 -06:00
|
|
|
"o_clk": ((1, False), DIR_NONE),
|
2019-05-25 15:57:07 -06:00
|
|
|
"o0": ((1, False), DIR_NONE),
|
|
|
|
"o1": ((1, False), DIR_NONE),
|
2019-04-15 10:27:23 -06:00
|
|
|
})
|
|
|
|
|
|
|
|
layout_2 = pin_layout(2, dir="o", xdr=2)
|
2020-06-04 21:19:46 -06:00
|
|
|
self.assertLayoutEqual(layout_2.fields, {
|
2019-06-02 23:56:18 -06:00
|
|
|
"o_clk": ((1, False), DIR_NONE),
|
2019-05-25 15:57:07 -06:00
|
|
|
"o0": ((2, False), DIR_NONE),
|
|
|
|
"o1": ((2, False), DIR_NONE),
|
2019-04-15 10:27:23 -06:00
|
|
|
})
|
|
|
|
|
2019-06-02 22:28:53 -06:00
|
|
|
def test_pin_layout_oe(self):
|
|
|
|
layout_1 = pin_layout(1, dir="oe", xdr=2)
|
2020-06-04 21:19:46 -06:00
|
|
|
self.assertLayoutEqual(layout_1.fields, {
|
2019-06-02 23:56:18 -06:00
|
|
|
"o_clk": ((1, False), DIR_NONE),
|
2019-06-02 22:28:53 -06:00
|
|
|
"o0": ((1, False), DIR_NONE),
|
|
|
|
"o1": ((1, False), DIR_NONE),
|
|
|
|
"oe": ((1, False), DIR_NONE),
|
|
|
|
})
|
|
|
|
|
|
|
|
layout_2 = pin_layout(2, dir="oe", xdr=2)
|
2020-06-04 21:19:46 -06:00
|
|
|
self.assertLayoutEqual(layout_2.fields, {
|
2019-06-02 23:56:18 -06:00
|
|
|
"o_clk": ((1, False), DIR_NONE),
|
2019-06-02 22:28:53 -06:00
|
|
|
"o0": ((2, False), DIR_NONE),
|
|
|
|
"o1": ((2, False), DIR_NONE),
|
|
|
|
"oe": ((1, False), DIR_NONE),
|
|
|
|
})
|
|
|
|
|
2019-04-15 10:27:23 -06:00
|
|
|
def test_pin_layout_io(self):
|
|
|
|
layout_1 = pin_layout(1, dir="io", xdr=2)
|
2020-06-04 21:19:46 -06:00
|
|
|
self.assertLayoutEqual(layout_1.fields, {
|
2019-06-02 23:56:18 -06:00
|
|
|
"i_clk": ((1, False), DIR_NONE),
|
2019-05-25 15:57:07 -06:00
|
|
|
"i0": ((1, False), DIR_NONE),
|
|
|
|
"i1": ((1, False), DIR_NONE),
|
2019-06-02 23:56:18 -06:00
|
|
|
"o_clk": ((1, False), DIR_NONE),
|
2019-05-25 15:57:07 -06:00
|
|
|
"o0": ((1, False), DIR_NONE),
|
|
|
|
"o1": ((1, False), DIR_NONE),
|
|
|
|
"oe": ((1, False), DIR_NONE),
|
2019-04-15 10:27:23 -06:00
|
|
|
})
|
|
|
|
|
|
|
|
layout_2 = pin_layout(2, dir="io", xdr=2)
|
2020-06-04 21:19:46 -06:00
|
|
|
self.assertLayoutEqual(layout_2.fields, {
|
2019-06-02 23:56:18 -06:00
|
|
|
"i_clk": ((1, False), DIR_NONE),
|
2019-05-25 15:57:07 -06:00
|
|
|
"i0": ((2, False), DIR_NONE),
|
|
|
|
"i1": ((2, False), DIR_NONE),
|
2019-06-02 23:56:18 -06:00
|
|
|
"o_clk": ((1, False), DIR_NONE),
|
2019-05-25 15:57:07 -06:00
|
|
|
"o0": ((2, False), DIR_NONE),
|
|
|
|
"o1": ((2, False), DIR_NONE),
|
|
|
|
"oe": ((1, False), DIR_NONE),
|
2019-04-15 10:27:23 -06:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
class PinTestCase(FHDLTestCase):
|
|
|
|
def test_attributes(self):
|
|
|
|
pin = Pin(2, dir="io", xdr=2)
|
|
|
|
self.assertEqual(pin.width, 2)
|
|
|
|
self.assertEqual(pin.dir, "io")
|
|
|
|
self.assertEqual(pin.xdr, 2)
|