1 from nmigen
.compat
.sim
import run_simulation
2 from TLB
.AddressEncoder
import AddressEncoder
3 from 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 => !=)
19 def check_single_match(dut
, sm
, op
):
20 out_sm
= yield dut
.single_match
21 assert_op("Single Match", out_sm
, sm
, op
)
23 # Checks the multiple match of the AddressEncoder
25 # dut: The AddressEncoder being tested
26 # mm (Multiple Match): The expected match result
27 # op (Operation): (0 => ==), (1 => !=)
28 def check_multiple_match(dut
, mm
, op
):
29 out_mm
= yield dut
.multiple_match
30 assert_op("Multiple Match", out_mm
, mm
, op
)
32 # Checks the output of the AddressEncoder
34 # dut: The AddressEncoder being tested
35 # o (Output): The expected output
36 # op (Operation): (0 => ==), (1 => !=)
37 def check_output(dut
, o
, op
):
39 assert_op("Output", out_o
, o
, op
)
41 # Checks the state of the AddressEncoder
43 # dut: The AddressEncoder being tested
44 # sm (Single Match): The expected match result
45 # mm (Multiple Match): The expected match result
46 # o (Output): The expected output
47 # ss_op (Operation): Operation for the match assertion (0 => ==), (1 => !=)
48 # mm_op (Operation): Operation for the match assertion (0 => ==), (1 => !=)
49 # o_op (Operation): Operation for the match assertion (0 => ==), (1 => !=)
50 def check_all(dut
, sm
, mm
, o
, sm_op
, mm_op
, o_op
):
51 yield from check_single_match(dut
, sm
, sm_op
)
52 yield from check_multiple_match(dut
, mm
, mm_op
)
53 yield from check_output(dut
, o
, o_op
)
61 yield from set_encoder(dut
, in_val
)
62 yield from check_all(dut
, single_match
, multiple_match
, output
, 0, 0, 0)
69 yield from set_encoder(dut
, in_val
)
70 yield from check_all(dut
, single_match
, multiple_match
, output
, 0, 0, 0)
72 # Check another single bit
77 yield from set_encoder(dut
, in_val
)
78 yield from check_all(dut
, single_match
, multiple_match
, output
, 0, 0, 0)
80 # Check multiple match
81 # We expected the lowest bit to be returned which is address 0
86 yield from set_encoder(dut
, in_val
)
87 yield from check_all(dut
, single_match
, multiple_match
, output
, 0, 0, 0)
89 # Check another multiple match
90 # We expected the lowest bit to be returned which is address 1
95 yield from set_encoder(dut
, in_val
)
96 yield from check_all(dut
, single_match
, multiple_match
, output
, 0, 0, 0)
99 dut
= AddressEncoder(4)
100 run_simulation(dut
, tbench(dut
),
101 vcd_name
="Waveforms/test_address_encoder.vcd")
102 print("AddressEncoder Unit Test Success")
104 if __name__
== "__main__":