build.run: implement SSH remote builds using Paramiko.
[nmigen.git] / nmigen / test / test_lib_io.py
1 from .utils import *
2 from ..hdl import *
3 from ..hdl.rec import *
4 from ..back.pysim import *
5 from ..lib.io import *
6
7
8 class PinLayoutTestCase(FHDLTestCase):
9 def assertLayoutEqual(self, layout, expected):
10 casted_layout = {}
11 for name, (shape, dir) in layout.items():
12 casted_layout[name] = (Shape.cast(shape), dir)
13
14 self.assertEqual(casted_layout, expected)
15
16
17 class PinLayoutCombTestCase(PinLayoutTestCase):
18 def test_pin_layout_i(self):
19 layout_1 = pin_layout(1, dir="i")
20 self.assertLayoutEqual(layout_1.fields, {
21 "i": ((1, False), DIR_NONE),
22 })
23
24 layout_2 = pin_layout(2, dir="i")
25 self.assertLayoutEqual(layout_2.fields, {
26 "i": ((2, False), DIR_NONE),
27 })
28
29 def test_pin_layout_o(self):
30 layout_1 = pin_layout(1, dir="o")
31 self.assertLayoutEqual(layout_1.fields, {
32 "o": ((1, False), DIR_NONE),
33 })
34
35 layout_2 = pin_layout(2, dir="o")
36 self.assertLayoutEqual(layout_2.fields, {
37 "o": ((2, False), DIR_NONE),
38 })
39
40 def test_pin_layout_oe(self):
41 layout_1 = pin_layout(1, dir="oe")
42 self.assertLayoutEqual(layout_1.fields, {
43 "o": ((1, False), DIR_NONE),
44 "oe": ((1, False), DIR_NONE),
45 })
46
47 layout_2 = pin_layout(2, dir="oe")
48 self.assertLayoutEqual(layout_2.fields, {
49 "o": ((2, False), DIR_NONE),
50 "oe": ((1, False), DIR_NONE),
51 })
52
53 def test_pin_layout_io(self):
54 layout_1 = pin_layout(1, dir="io")
55 self.assertLayoutEqual(layout_1.fields, {
56 "i": ((1, False), DIR_NONE),
57 "o": ((1, False), DIR_NONE),
58 "oe": ((1, False), DIR_NONE),
59 })
60
61 layout_2 = pin_layout(2, dir="io")
62 self.assertLayoutEqual(layout_2.fields, {
63 "i": ((2, False), DIR_NONE),
64 "o": ((2, False), DIR_NONE),
65 "oe": ((1, False), DIR_NONE),
66 })
67
68
69 class PinLayoutSDRTestCase(PinLayoutTestCase):
70 def test_pin_layout_i(self):
71 layout_1 = pin_layout(1, dir="i", xdr=1)
72 self.assertLayoutEqual(layout_1.fields, {
73 "i_clk": ((1, False), DIR_NONE),
74 "i": ((1, False), DIR_NONE),
75 })
76
77 layout_2 = pin_layout(2, dir="i", xdr=1)
78 self.assertLayoutEqual(layout_2.fields, {
79 "i_clk": ((1, False), DIR_NONE),
80 "i": ((2, False), DIR_NONE),
81 })
82
83 def test_pin_layout_o(self):
84 layout_1 = pin_layout(1, dir="o", xdr=1)
85 self.assertLayoutEqual(layout_1.fields, {
86 "o_clk": ((1, False), DIR_NONE),
87 "o": ((1, False), DIR_NONE),
88 })
89
90 layout_2 = pin_layout(2, dir="o", xdr=1)
91 self.assertLayoutEqual(layout_2.fields, {
92 "o_clk": ((1, False), DIR_NONE),
93 "o": ((2, False), DIR_NONE),
94 })
95
96 def test_pin_layout_oe(self):
97 layout_1 = pin_layout(1, dir="oe", xdr=1)
98 self.assertLayoutEqual(layout_1.fields, {
99 "o_clk": ((1, False), DIR_NONE),
100 "o": ((1, False), DIR_NONE),
101 "oe": ((1, False), DIR_NONE),
102 })
103
104 layout_2 = pin_layout(2, dir="oe", xdr=1)
105 self.assertLayoutEqual(layout_2.fields, {
106 "o_clk": ((1, False), DIR_NONE),
107 "o": ((2, False), DIR_NONE),
108 "oe": ((1, False), DIR_NONE),
109 })
110
111 def test_pin_layout_io(self):
112 layout_1 = pin_layout(1, dir="io", xdr=1)
113 self.assertLayoutEqual(layout_1.fields, {
114 "i_clk": ((1, False), DIR_NONE),
115 "i": ((1, False), DIR_NONE),
116 "o_clk": ((1, False), DIR_NONE),
117 "o": ((1, False), DIR_NONE),
118 "oe": ((1, False), DIR_NONE),
119 })
120
121 layout_2 = pin_layout(2, dir="io", xdr=1)
122 self.assertLayoutEqual(layout_2.fields, {
123 "i_clk": ((1, False), DIR_NONE),
124 "i": ((2, False), DIR_NONE),
125 "o_clk": ((1, False), DIR_NONE),
126 "o": ((2, False), DIR_NONE),
127 "oe": ((1, False), DIR_NONE),
128 })
129
130
131 class PinLayoutDDRTestCase(PinLayoutTestCase):
132 def test_pin_layout_i(self):
133 layout_1 = pin_layout(1, dir="i", xdr=2)
134 self.assertLayoutEqual(layout_1.fields, {
135 "i_clk": ((1, False), DIR_NONE),
136 "i0": ((1, False), DIR_NONE),
137 "i1": ((1, False), DIR_NONE),
138 })
139
140 layout_2 = pin_layout(2, dir="i", xdr=2)
141 self.assertLayoutEqual(layout_2.fields, {
142 "i_clk": ((1, False), DIR_NONE),
143 "i0": ((2, False), DIR_NONE),
144 "i1": ((2, False), DIR_NONE),
145 })
146
147 def test_pin_layout_o(self):
148 layout_1 = pin_layout(1, dir="o", xdr=2)
149 self.assertLayoutEqual(layout_1.fields, {
150 "o_clk": ((1, False), DIR_NONE),
151 "o0": ((1, False), DIR_NONE),
152 "o1": ((1, False), DIR_NONE),
153 })
154
155 layout_2 = pin_layout(2, dir="o", xdr=2)
156 self.assertLayoutEqual(layout_2.fields, {
157 "o_clk": ((1, False), DIR_NONE),
158 "o0": ((2, False), DIR_NONE),
159 "o1": ((2, False), DIR_NONE),
160 })
161
162 def test_pin_layout_oe(self):
163 layout_1 = pin_layout(1, dir="oe", xdr=2)
164 self.assertLayoutEqual(layout_1.fields, {
165 "o_clk": ((1, False), DIR_NONE),
166 "o0": ((1, False), DIR_NONE),
167 "o1": ((1, False), DIR_NONE),
168 "oe": ((1, False), DIR_NONE),
169 })
170
171 layout_2 = pin_layout(2, dir="oe", xdr=2)
172 self.assertLayoutEqual(layout_2.fields, {
173 "o_clk": ((1, False), DIR_NONE),
174 "o0": ((2, False), DIR_NONE),
175 "o1": ((2, False), DIR_NONE),
176 "oe": ((1, False), DIR_NONE),
177 })
178
179 def test_pin_layout_io(self):
180 layout_1 = pin_layout(1, dir="io", xdr=2)
181 self.assertLayoutEqual(layout_1.fields, {
182 "i_clk": ((1, False), DIR_NONE),
183 "i0": ((1, False), DIR_NONE),
184 "i1": ((1, False), DIR_NONE),
185 "o_clk": ((1, False), DIR_NONE),
186 "o0": ((1, False), DIR_NONE),
187 "o1": ((1, False), DIR_NONE),
188 "oe": ((1, False), DIR_NONE),
189 })
190
191 layout_2 = pin_layout(2, dir="io", xdr=2)
192 self.assertLayoutEqual(layout_2.fields, {
193 "i_clk": ((1, False), DIR_NONE),
194 "i0": ((2, False), DIR_NONE),
195 "i1": ((2, False), DIR_NONE),
196 "o_clk": ((1, False), DIR_NONE),
197 "o0": ((2, False), DIR_NONE),
198 "o1": ((2, False), DIR_NONE),
199 "oe": ((1, False), DIR_NONE),
200 })
201
202
203 class PinTestCase(FHDLTestCase):
204 def test_attributes(self):
205 pin = Pin(2, dir="io", xdr=2)
206 self.assertEqual(pin.width, 2)
207 self.assertEqual(pin.dir, "io")
208 self.assertEqual(pin.xdr, 2)