2 sys
.path
.append("../src")
3 sys
.path
.append("../../TestUtil")
5 from nmigen
.compat
.sim
import run_simulation
7 from AddressEncoder
import AddressEncoder
9 from test_helper
import assert_eq
, assert_ne
, assert_op
11 # This function allows for the easy setting of values to the AddressEncoder
13 # dut: The AddressEncoder being tested
14 # i (Input): The array of single bits to be written
15 def set_encoder(dut
, i
):
19 # Checks the single match of the AddressEncoder
21 # dut: The AddressEncoder being tested
22 # sm (Single Match): The expected match result
23 # op (Operation): (0 => ==), (1 => !=)
24 def check_single_match(dut
, sm
, op
):
25 out_sm
= yield dut
.single_match
26 assert_op("Single Match", out_sm
, sm
, op
)
28 # Checks the multiple match of the AddressEncoder
30 # dut: The AddressEncoder being tested
31 # mm (Multiple Match): The expected match result
32 # op (Operation): (0 => ==), (1 => !=)
33 def check_multiple_match(dut
, mm
, op
):
34 out_mm
= yield dut
.multiple_match
35 assert_op("Multiple Match", out_mm
, mm
, op
)
37 # Checks the output of the AddressEncoder
39 # dut: The AddressEncoder being tested
40 # o (Output): The expected output
41 # op (Operation): (0 => ==), (1 => !=)
42 def check_output(dut
, o
, op
):
44 assert_op("Output", out_o
, o
, op
)
46 # Checks the state of the AddressEncoder
48 # dut: The AddressEncoder being tested
49 # sm (Single Match): The expected match result
50 # mm (Multiple Match): The expected match result
51 # o (Output): The expected output
52 # ss_op (Operation): Operation for the match assertion (0 => ==), (1 => !=)
53 # mm_op (Operation): Operation for the match assertion (0 => ==), (1 => !=)
54 # o_op (Operation): Operation for the match assertion (0 => ==), (1 => !=)
55 def check_all(dut
, sm
, mm
, o
, sm_op
, mm_op
, o_op
):
56 yield from check_single_match(dut
, sm
, sm_op
)
57 yield from check_multiple_match(dut
, mm
, mm_op
)
58 yield from check_output(dut
, o
, o_op
)
66 yield from set_encoder(dut
, input)
67 yield from check_all(dut
, single_match
, multiple_match
, output
, 0, 0, 0)
74 yield from set_encoder(dut
, input)
75 yield from check_all(dut
, single_match
, multiple_match
, output
, 0, 0, 0)
77 # Check another single bit
82 yield from set_encoder(dut
, input)
83 yield from check_all(dut
, single_match
, multiple_match
, output
, 0, 0, 0)
85 # Check multiple match
86 # We expected the lowest bit to be returned which is address 0
91 yield from set_encoder(dut
, input)
92 yield from check_all(dut
, single_match
, multiple_match
, output
, 0, 0, 0)
94 # Check another multiple match
95 # We expected the lowest bit to be returned which is address 1
100 yield from set_encoder(dut
, input)
101 yield from check_all(dut
, single_match
, multiple_match
, output
, 0, 0, 0)
105 if __name__
== "__main__":
106 dut
= AddressEncoder(4)
107 run_simulation(dut
, testbench(dut
), vcd_name
="Waveforms/test_address_encoder.vcd")
108 print("AddressEncoder Unit Test Success")