1 from nmigen
.compat
.sim
import run_simulation
2 from soc
.TLB
.AddressEncoder
import AddressEncoder
3 from soc
.TestUtil
.test_helper
import assert_eq
, assert_ne
, assert_op
6 # This function allows for the easy setting of values to the AddressEncoder
8 # dut: The AddressEncoder being tested
9 # i (Input): The array of single bits to be written
10 def set_encoder(dut
, i
):
14 # Checks the single match of the AddressEncoder
16 # dut: The AddressEncoder being tested
17 # sm (Single Match): The expected match result
18 # op (Operation): (0 => ==), (1 => !=)
21 def check_single_match(dut
, sm
, op
):
22 out_sm
= yield dut
.single_match
23 assert_op("Single Match", out_sm
, sm
, op
)
25 # Checks the multiple match of the AddressEncoder
27 # dut: The AddressEncoder being tested
28 # mm (Multiple Match): The expected match result
29 # op (Operation): (0 => ==), (1 => !=)
32 def check_multiple_match(dut
, mm
, op
):
33 out_mm
= yield dut
.multiple_match
34 assert_op("Multiple Match", out_mm
, mm
, op
)
36 # Checks the output of the AddressEncoder
38 # dut: The AddressEncoder being tested
39 # o (Output): The expected output
40 # op (Operation): (0 => ==), (1 => !=)
43 def check_output(dut
, o
, op
):
45 assert_op("Output", out_o
, o
, op
)
47 # Checks the state of the AddressEncoder
49 # dut: The AddressEncoder being tested
50 # sm (Single Match): The expected match result
51 # mm (Multiple Match): The expected match result
52 # o (Output): The expected output
53 # ss_op (Operation): Operation for the match assertion (0 => ==), (1 => !=)
54 # mm_op (Operation): Operation for the match assertion (0 => ==), (1 => !=)
55 # o_op (Operation): Operation for the match assertion (0 => ==), (1 => !=)
58 def check_all(dut
, sm
, mm
, o
, sm_op
, mm_op
, o_op
):
59 yield from check_single_match(dut
, sm
, sm_op
)
60 yield from check_multiple_match(dut
, mm
, mm_op
)
61 yield from check_output(dut
, o
, o_op
)
70 yield from set_encoder(dut
, in_val
)
71 yield from check_all(dut
, single_match
, multiple_match
, output
, 0, 0, 0)
78 yield from set_encoder(dut
, in_val
)
79 yield from check_all(dut
, single_match
, multiple_match
, output
, 0, 0, 0)
81 # Check another single bit
86 yield from set_encoder(dut
, in_val
)
87 yield from check_all(dut
, single_match
, multiple_match
, output
, 0, 0, 0)
89 # Check multiple match
90 # We expected the lowest bit to be returned which is address 0
95 yield from set_encoder(dut
, in_val
)
96 yield from check_all(dut
, single_match
, multiple_match
, output
, 0, 0, 0)
98 # Check another multiple match
99 # We expected the lowest bit to be returned which is address 1
104 yield from set_encoder(dut
, in_val
)
105 yield from check_all(dut
, single_match
, multiple_match
, output
, 0, 0, 0)
109 dut
= AddressEncoder(4)
110 run_simulation(dut
, tbench(dut
),
111 vcd_name
="Waveforms/test_address_encoder.vcd")
112 print("AddressEncoder Unit Test Success")
115 if __name__
== "__main__":