class LayoutTestCase(FHDLTestCase):
+ def assertFieldEqual(self, field, expected):
+ (shape, dir) = field
+ shape = Shape.cast(shape)
+ self.assertEqual((shape, dir), expected)
+
def test_fields(self):
layout = Layout.cast([
("cyc", 1),
])
])
- self.assertEqual(layout["cyc"], ((1, False), DIR_NONE))
- self.assertEqual(layout["data"], ((32, True), DIR_NONE))
- self.assertEqual(layout["stb"], ((1, False), DIR_FANOUT))
- self.assertEqual(layout["ack"], ((1, False), DIR_FANIN))
+ self.assertFieldEqual(layout["cyc"], ((1, False), DIR_NONE))
+ self.assertFieldEqual(layout["data"], ((32, True), DIR_NONE))
+ self.assertFieldEqual(layout["stb"], ((1, False), DIR_FANOUT))
+ self.assertFieldEqual(layout["ack"], ((1, False), DIR_FANIN))
sublayout = layout["info"][0]
self.assertEqual(layout["info"][1], DIR_NONE)
- self.assertEqual(sublayout["a"], ((1, False), DIR_NONE))
- self.assertEqual(sublayout["b"], ((1, False), DIR_NONE))
+ self.assertFieldEqual(sublayout["a"], ((1, False), DIR_NONE))
+ self.assertFieldEqual(sublayout["b"], ((1, False), DIR_NONE))
def test_enum_field(self):
layout = Layout.cast([
("enum", UnsignedEnum),
("enum_dir", UnsignedEnum, DIR_FANOUT),
])
- self.assertEqual(layout["enum"], ((2, False), DIR_NONE))
- self.assertEqual(layout["enum_dir"], ((2, False), DIR_FANOUT))
+ self.assertFieldEqual(layout["enum"], ((2, False), DIR_NONE))
+ self.assertFieldEqual(layout["enum_dir"], ((2, False), DIR_FANOUT))
def test_range_field(self):
layout = Layout.cast([
("range", range(0, 7)),
])
- self.assertEqual(layout["range"], ((3, False), DIR_NONE))
+ self.assertFieldEqual(layout["range"], ((3, False), DIR_NONE))
def test_slice_tuple(self):
layout = Layout.cast([
self.assertEqual(layout["a", "c"], expect)
def test_repr(self):
- self.assertEqual(repr(Layout([("a", 1), ("b", signed(2))])),
+ self.assertEqual(repr(Layout([("a", unsigned(1)), ("b", signed(2))])),
"Layout([('a', unsigned(1)), ('b', signed(2))])")
- self.assertEqual(repr(Layout([("a", 1), ("b", [("c", signed(3))])])),
+ self.assertEqual(repr(Layout([("a", unsigned(1)), ("b", [("c", signed(3))])])),
"Layout([('a', unsigned(1)), "
"('b', Layout([('c', signed(3))]))])")
self.assertIs(r2.a, r1.a)
self.assertIs(r2.c, r1.c)
+ def test_enum_decoder(self):
+ r1 = Record([("a", UnsignedEnum)])
+ self.assertEqual(r1.a.decoder(UnsignedEnum.FOO), "FOO/1")
+
class ConnectTestCase(FHDLTestCase):
def setUp_flat(self):
from ..lib.io import *
-class PinLayoutCombTestCase(FHDLTestCase):
+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):
def test_pin_layout_i(self):
layout_1 = pin_layout(1, dir="i")
- self.assertEqual(layout_1.fields, {
+ self.assertLayoutEqual(layout_1.fields, {
"i": ((1, False), DIR_NONE),
})
layout_2 = pin_layout(2, dir="i")
- self.assertEqual(layout_2.fields, {
+ self.assertLayoutEqual(layout_2.fields, {
"i": ((2, False), DIR_NONE),
})
def test_pin_layout_o(self):
layout_1 = pin_layout(1, dir="o")
- self.assertEqual(layout_1.fields, {
+ self.assertLayoutEqual(layout_1.fields, {
"o": ((1, False), DIR_NONE),
})
layout_2 = pin_layout(2, dir="o")
- self.assertEqual(layout_2.fields, {
+ self.assertLayoutEqual(layout_2.fields, {
"o": ((2, False), DIR_NONE),
})
def test_pin_layout_oe(self):
layout_1 = pin_layout(1, dir="oe")
- self.assertEqual(layout_1.fields, {
+ self.assertLayoutEqual(layout_1.fields, {
"o": ((1, False), DIR_NONE),
"oe": ((1, False), DIR_NONE),
})
layout_2 = pin_layout(2, dir="oe")
- self.assertEqual(layout_2.fields, {
+ self.assertLayoutEqual(layout_2.fields, {
"o": ((2, False), DIR_NONE),
"oe": ((1, False), DIR_NONE),
})
def test_pin_layout_io(self):
layout_1 = pin_layout(1, dir="io")
- self.assertEqual(layout_1.fields, {
+ self.assertLayoutEqual(layout_1.fields, {
"i": ((1, False), DIR_NONE),
"o": ((1, False), DIR_NONE),
"oe": ((1, False), DIR_NONE),
})
layout_2 = pin_layout(2, dir="io")
- self.assertEqual(layout_2.fields, {
+ self.assertLayoutEqual(layout_2.fields, {
"i": ((2, False), DIR_NONE),
"o": ((2, False), DIR_NONE),
"oe": ((1, False), DIR_NONE),
})
-class PinLayoutSDRTestCase(FHDLTestCase):
+class PinLayoutSDRTestCase(PinLayoutTestCase):
def test_pin_layout_i(self):
layout_1 = pin_layout(1, dir="i", xdr=1)
- self.assertEqual(layout_1.fields, {
+ self.assertLayoutEqual(layout_1.fields, {
"i_clk": ((1, False), DIR_NONE),
"i": ((1, False), DIR_NONE),
})
layout_2 = pin_layout(2, dir="i", xdr=1)
- self.assertEqual(layout_2.fields, {
+ self.assertLayoutEqual(layout_2.fields, {
"i_clk": ((1, False), DIR_NONE),
"i": ((2, False), DIR_NONE),
})
def test_pin_layout_o(self):
layout_1 = pin_layout(1, dir="o", xdr=1)
- self.assertEqual(layout_1.fields, {
+ self.assertLayoutEqual(layout_1.fields, {
"o_clk": ((1, False), DIR_NONE),
"o": ((1, False), DIR_NONE),
})
layout_2 = pin_layout(2, dir="o", xdr=1)
- self.assertEqual(layout_2.fields, {
+ self.assertLayoutEqual(layout_2.fields, {
"o_clk": ((1, False), DIR_NONE),
"o": ((2, False), DIR_NONE),
})
def test_pin_layout_oe(self):
layout_1 = pin_layout(1, dir="oe", xdr=1)
- self.assertEqual(layout_1.fields, {
+ self.assertLayoutEqual(layout_1.fields, {
"o_clk": ((1, False), DIR_NONE),
"o": ((1, False), DIR_NONE),
"oe": ((1, False), DIR_NONE),
})
layout_2 = pin_layout(2, dir="oe", xdr=1)
- self.assertEqual(layout_2.fields, {
+ self.assertLayoutEqual(layout_2.fields, {
"o_clk": ((1, False), DIR_NONE),
"o": ((2, False), DIR_NONE),
"oe": ((1, False), DIR_NONE),
def test_pin_layout_io(self):
layout_1 = pin_layout(1, dir="io", xdr=1)
- self.assertEqual(layout_1.fields, {
+ self.assertLayoutEqual(layout_1.fields, {
"i_clk": ((1, False), DIR_NONE),
"i": ((1, False), DIR_NONE),
"o_clk": ((1, False), DIR_NONE),
})
layout_2 = pin_layout(2, dir="io", xdr=1)
- self.assertEqual(layout_2.fields, {
+ self.assertLayoutEqual(layout_2.fields, {
"i_clk": ((1, False), DIR_NONE),
"i": ((2, False), DIR_NONE),
"o_clk": ((1, False), DIR_NONE),
})
-class PinLayoutDDRTestCase(FHDLTestCase):
+class PinLayoutDDRTestCase(PinLayoutTestCase):
def test_pin_layout_i(self):
layout_1 = pin_layout(1, dir="i", xdr=2)
- self.assertEqual(layout_1.fields, {
+ self.assertLayoutEqual(layout_1.fields, {
"i_clk": ((1, False), DIR_NONE),
"i0": ((1, False), DIR_NONE),
"i1": ((1, False), DIR_NONE),
})
layout_2 = pin_layout(2, dir="i", xdr=2)
- self.assertEqual(layout_2.fields, {
+ self.assertLayoutEqual(layout_2.fields, {
"i_clk": ((1, False), DIR_NONE),
"i0": ((2, False), DIR_NONE),
"i1": ((2, False), DIR_NONE),
def test_pin_layout_o(self):
layout_1 = pin_layout(1, dir="o", xdr=2)
- self.assertEqual(layout_1.fields, {
+ self.assertLayoutEqual(layout_1.fields, {
"o_clk": ((1, False), DIR_NONE),
"o0": ((1, False), DIR_NONE),
"o1": ((1, False), DIR_NONE),
})
layout_2 = pin_layout(2, dir="o", xdr=2)
- self.assertEqual(layout_2.fields, {
+ self.assertLayoutEqual(layout_2.fields, {
"o_clk": ((1, False), DIR_NONE),
"o0": ((2, False), DIR_NONE),
"o1": ((2, False), DIR_NONE),
def test_pin_layout_oe(self):
layout_1 = pin_layout(1, dir="oe", xdr=2)
- self.assertEqual(layout_1.fields, {
+ self.assertLayoutEqual(layout_1.fields, {
"o_clk": ((1, False), DIR_NONE),
"o0": ((1, False), DIR_NONE),
"o1": ((1, False), DIR_NONE),
})
layout_2 = pin_layout(2, dir="oe", xdr=2)
- self.assertEqual(layout_2.fields, {
+ self.assertLayoutEqual(layout_2.fields, {
"o_clk": ((1, False), DIR_NONE),
"o0": ((2, False), DIR_NONE),
"o1": ((2, False), DIR_NONE),
def test_pin_layout_io(self):
layout_1 = pin_layout(1, dir="io", xdr=2)
- self.assertEqual(layout_1.fields, {
+ self.assertLayoutEqual(layout_1.fields, {
"i_clk": ((1, False), DIR_NONE),
"i0": ((1, False), DIR_NONE),
"i1": ((1, False), DIR_NONE),
})
layout_2 = pin_layout(2, dir="io", xdr=2)
- self.assertEqual(layout_2.fields, {
+ self.assertLayoutEqual(layout_2.fields, {
"i_clk": ((1, False), DIR_NONE),
"i0": ((2, False), DIR_NONE),
"i1": ((2, False), DIR_NONE),