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 def set_encoder(dut
, i
):
15 # Checks the single match of the AddressEncoder
17 # dut: The AddressEncoder being tested
18 # sm (Single Match): The expected match result
19 # op (Operation): (0 => ==), (1 => !=)
20 def check_single_match(dut
, sm
, op
):
21 out_sm
= yield dut
.single_match
22 assert_op("Single Match", out_sm
, sm
, op
)
24 # Checks the multiple match of the AddressEncoder
26 # dut: The AddressEncoder being tested
27 # mm (Multiple Match): The expected match result
28 # op (Operation): (0 => ==), (1 => !=)
29 def check_multiple_match(dut
, mm
, op
):
30 out_mm
= yield dut
.multiple_match
31 assert_op("Multiple Match", out_mm
, mm
, op
)
33 # Checks the output of the AddressEncoder
35 # dut: The AddressEncoder being tested
36 # o (Output): The expected output
37 # op (Operation): (0 => ==), (1 => !=)
38 def check_output(dut
, o
, op
):
40 assert_op("Output", out_o
, o
, op
)
42 # Checks the state of the AddressEncoder
44 # dut: The AddressEncoder being tested
45 # sm (Single Match): The expected match result
46 # mm (Multiple Match): The expected match result
47 # o (Output): The expected output
48 # ss_op (Operation): Operation for the match assertion (0 => ==), (1 => !=)
49 # mm_op (Operation): Operation for the match assertion (0 => ==), (1 => !=)
50 # o_op (Operation): Operation for the match assertion (0 => ==), (1 => !=)
51 def check_all(dut
, sm
, mm
, o
, sm_op
, mm_op
, o_op
):
52 yield from check_single_match(dut
, sm
, sm_op
)
53 yield from check_multiple_match(dut
, mm
, mm_op
)
54 yield from check_output(dut
, o
, o_op
)
62 yield from set_encoder(dut
, input)
63 yield from check_all(dut
, single_match
, multiple_match
, output
, 0, 0, 0)
70 yield from set_encoder(dut
, input)
71 yield from check_all(dut
, single_match
, multiple_match
, output
, 0, 0, 0)
73 # Check another single bit
78 yield from set_encoder(dut
, input)
79 yield from check_all(dut
, single_match
, multiple_match
, output
, 0, 0, 0)
81 # Check multiple match
82 # We expected the lowest bit to be returned which is address 0
87 yield from set_encoder(dut
, input)
88 yield from check_all(dut
, single_match
, multiple_match
, output
, 0, 0, 0)
90 # Check another multiple match
91 # We expected the lowest bit to be returned which is address 1
96 yield from set_encoder(dut
, input)
97 yield from check_all(dut
, single_match
, multiple_match
, output
, 0, 0, 0)
101 if __name__
== "__main__":
102 dut
= AddressEncoder(4)
103 run_simulation(dut
, testbench(dut
), vcd_name
="Waveforms/test_address_encoder.vcd")
104 print("AddressEncoder Unit Test Success")