forked from m-labs/drtio_transceiver_test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_prbs.py
52 lines (41 loc) · 1.25 KB
/
test_prbs.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
import unittest
from migen import *
from prbs import PRBSGenerator, PRBSChecker
def prbs_genenerate(dw, length):
dut = PRBSGenerator(dw)
output = []
def pump():
yield
for _ in range(length):
yield
output.append((yield dut.o))
run_simulation(dut, pump())
return output
def prbs_check(dw, seq):
error_count = 0
dut = PRBSChecker(dw)
def pump():
nonlocal error_count
for w in seq:
yield dut.i.eq(w)
yield
errors = yield dut.errors
for i in range(len(dut.errors)):
if errors & (1 << i):
error_count += 1
run_simulation(dut, pump())
return error_count
class TestPRBS(unittest.TestCase):
dw = 16
@classmethod
def setUpClass(cls):
cls.sequence = prbs_genenerate(cls.dw, 500)
def test_no_error(self):
self.assertEqual(prbs_check(self.dw, self.sequence), 0)
def test_one_error(self):
err_sequence = list(self.sequence)
err_sequence[42] ^= 0x0100
detected_error_count = prbs_check(self.dw, err_sequence)
print(detected_error_count)
self.assertGreater(detected_error_count, 0)
self.assertLess(detected_error_count, 23)