forked from ms3273/ece4750-S01-pymtl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRegIncrFL_test.py
96 lines (71 loc) · 2.38 KB
/
RegIncrFL_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
#=======================================================================
# RegIncrFL_test.py
#=======================================================================
import random
import pytest
from pymtl import *
from RegIncrFL import RegIncrFL as RegIncr
#-----------------------------------------------------------------------
# simple_test_vectors
#-----------------------------------------------------------------------
simple_test_vectors = [
( 4, 5),
( 6, 7),
( 2, 3),
(15, 16),
( 8, 9),
( 0, 1),
(10, 11),
]
#-----------------------------------------------------------------------
# test_simple
#-----------------------------------------------------------------------
@pytest.mark.parametrize( 'dtype', [8] )
def test_simple( dtype ):
# instantiate the model and elaborate it
model = RegIncr( dtype )
model.elaborate()
# create the simulator
sim = SimulationTool( model )
# verify the model
print
for input_vector, expected_out in simple_test_vectors:
model.in_.value = input_vector
sim.print_line_trace()
sim.cycle()
assert model.out == expected_out
sim.print_line_trace()
#-----------------------------------------------------------------------
# test_random
#-----------------------------------------------------------------------
@pytest.mark.parametrize( 'dtype', [8] )
def test_random( dtype ):
do_random_test( RegIncr, dtype )
#-----------------------------------------------------------------------
# do_random_test
#-----------------------------------------------------------------------
def do_random_test( ModelType, dtype ):
# elaborate model
model = ModelType( dtype )
model.elaborate()
# create the simulator
sim = SimulationTool( model )
# verify the model
print
for input_vector, expected_out in gen_test_vectors( dtype ):
#print input_vector, expected_out
model.in_.value = input_vector
sim.print_line_trace()
sim.cycle()
assert model.out == expected_out
sim.print_line_trace()
#-----------------------------------------------------------------------
# gen_test_vectors
#-----------------------------------------------------------------------
def gen_test_vectors( nbits, size=10 ):
# random.seed( 0x5750 ) # debug!
vectors = []
for i in range( size ):
input_value = Bits( nbits, random.randrange( 2**nbits ) )
vectors.append( (input_value, input_value + 1) )
return vectors