-
Notifications
You must be signed in to change notification settings - Fork 5
/
test_interpolate.py
57 lines (47 loc) · 1.31 KB
/
test_interpolate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import numpy as np
import unittest
from migen import *
import interpolate
def feed(endpoint, x, rate):
n, d = rate
t = 0
for i, xi in enumerate(x):
while t * n < i * d:
yield
t += 1
yield endpoint.data.eq(int(xi))
yield endpoint.stb.eq(1)
yield
t += 1
while not (yield endpoint.ack):
yield
yield endpoint.stb.eq(0)
@passive
def retrieve(endpoint, o):
yield
while True:
yield endpoint.ack.eq(1)
yield
while not (yield endpoint.stb):
yield
o.append(((yield endpoint.data0), (yield endpoint.data1)))
yield endpoint.ack.eq(0)
class TestInter(unittest.TestCase):
def setUp(self):
self.dut = interpolate.InterpolateChannel()
def test_init(self):
self.assertEqual(len(self.dut.input.data), 14)
self.assertEqual(len(self.dut.output.data0), 16)
def test_seq(self):
# impulse response plus latency
x = [(1 << 13) - 1] + [0] * (30 + 10)
y = []
run_simulation(
self.dut,
[feed(self.dut.input, x, rate=(1, 10)), retrieve(self.dut.output, y)],
vcd_name="int.vcd",
)
y = np.ravel(y)
print(repr(y))
# y0 =
# np.testing.assert_equal(y, y0)