forked from cirosantilli/vcdvcd
-
Notifications
You must be signed in to change notification settings - Fork 4
/
test.py
executable file
·144 lines (122 loc) · 4.85 KB
/
test.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/usr/bin/env python3
import unittest
import re
from vcdvcd import VCDVCD
import vcdvcd
class Test(unittest.TestCase):
SMALL_CLOCK_VCD = '''
$var reg 1 " clock $end
$enddefinitions $end
#0
$dumpvars
0"
$end
#1
1"
#2
0"
'''
def test_data(self):
vcd = VCDVCD('counter_tb.vcd')
signal = vcd['counter_tb.out[1:0]']
self.assertEqual(
signal.tv[:6],
[
( 0, 'x'),
( 2, '0'),
( 6, '1'),
( 8, '10'),
(10, '11'),
(12, '0'),
]
)
self.assertEqual(signal[0], 'x')
self.assertEqual(signal[1], 'x')
self.assertEqual(signal[2], '0')
self.assertEqual(signal[3], '0')
self.assertEqual(signal[6], '1')
self.assertEqual(signal[7], '1')
self.assertEqual(signal[24], '10')
self.assertEqual(signal[25], '10')
def test_slice(self):
vcd = VCDVCD('counter_tb.vcd')
signal = vcd['counter_tb.out[1:0]']
for t, signal_d in enumerate(signal[0:30]):
if t < 2:
self.assertEqual(signal_d, 'x')
elif t < 6:
self.assertEqual(signal_d, '0')
else:
self.assertEqual(int(signal_d,2), ((t - 4)//2)%4)
def test_REs(self):
vcd = VCDVCD('counter_tb.vcd')
signal = vcd[re.compile('counter_tb\.out.*')]
for t, signal_d in enumerate(signal[0:30]):
if t < 2:
self.assertEqual(signal_d, 'x')
elif t < 6:
self.assertEqual(signal_d, '0')
else:
self.assertEqual(int(signal_d,2), ((t - 4)//2)%4)
signals = vcd[re.compile('out.*')]
self.assertEqual(len(signals),2)
def testContains(self):
vcd = VCDVCD('counter_tb.vcd', store_scopes=True)
scope_counter_tb = vcd[re.compile('counter_tb$')]
for element in ['clock','enable','reset','out[1:0]','top']:
self.assertTrue( element in scope_counter_tb)
def test_scopes(self):
vcd = VCDVCD('counter_tb.vcd', store_scopes=True)
scope_counter_tb = vcd[re.compile('counter_tb$')]
self.assertTrue(isinstance(scope_counter_tb, vcdvcd.Scope))
self.assertIsNotNone(scope_counter_tb['clock'])
self.assertIsNotNone(scope_counter_tb['enable'])
self.assertIsNotNone(scope_counter_tb['reset'])
self.assertIsNotNone(scope_counter_tb['out[1:0]'])
self.assertIsNotNone(scope_counter_tb['top'])
self.assertTrue(isinstance(scope_counter_tb['clock'], vcdvcd.Signal))
self.assertTrue(isinstance(scope_counter_tb['enable'], vcdvcd.Signal))
self.assertTrue(isinstance(scope_counter_tb['reset'], vcdvcd.Signal))
self.assertTrue(isinstance(scope_counter_tb['out[1:0]'], vcdvcd.Signal))
self.assertTrue(isinstance(scope_counter_tb['top'], vcdvcd.Scope ))
signal = scope_counter_tb[re.compile('out.*')]
self.assertTrue(scope_counter_tb['out[1:0]'] is signal)
for t, signal_d in enumerate(signal[0:30]):
if t < 2:
self.assertEqual(signal_d, 'x')
elif t < 6:
self.assertEqual(signal_d, '0')
else:
self.assertEqual(int(signal_d,2), ((t - 4)//2)%4)
scope_top_module = scope_counter_tb[re.compile('top$')]
self.assertTrue(isinstance(scope_top_module, vcdvcd.Scope))
signal = scope_counter_tb[re.compile('top$')][re.compile('out.*')]
self.assertTrue(signal is scope_top_module['out[1:0]'])
self.assertIsNotNone(scope_top_module['clock'])
self.assertIsNotNone(scope_top_module['enable'])
self.assertIsNotNone(scope_top_module['reset'])
self.assertIsNotNone(scope_top_module['out[1:0]'])
self.assertTrue(isinstance(scope_top_module['clock'], vcdvcd.Signal))
self.assertTrue(isinstance(scope_top_module['enable'], vcdvcd.Signal))
self.assertTrue(isinstance(scope_top_module['reset'], vcdvcd.Signal))
self.assertTrue(isinstance(scope_top_module['out[1:0]'], vcdvcd.Signal))
for t, signal_d in enumerate(signal[0:30]):
if t < 2:
self.assertEqual(signal_d, 'x')
elif t < 6:
self.assertEqual(signal_d, '0')
else:
self.assertEqual(int(signal_d,2), ((t - 4)//2)%4)
def test_toplevel_signal(self):
vcd = VCDVCD(vcd_string=self.SMALL_CLOCK_VCD)
signal = vcd['clock']
self.assertEqual(signal[0], '0')
self.assertEqual(signal[1], '1')
self.assertEqual(signal[2], '0')
self.assertEqual(signal[3], '0')
def test_nonexistent_signal(self):
vcd = VCDVCD(vcd_string=self.SMALL_CLOCK_VCD)
with self.assertRaises(KeyError):
vcd['non_existent_signal']
if __name__ == '__main__':
unittest.main()