2 sys
.path
.append("../src")
3 sys
.path
.append("../../TestUtil")
5 from nmigen
.compat
.sim
import run_simulation
9 from test_helper
import assert_eq
, assert_ne
11 def set_cam(dut
, e
, we
, a
, d
):
12 yield dut
.enable
.eq(e
)
13 yield dut
.write_enable
.eq(we
)
14 yield dut
.address_in
.eq(a
)
15 yield dut
.data_in
.eq(d
)
18 def check_multiple_match(dut
, mm
, op
):
19 out_mm
= yield dut
.multiple_match
21 assert_eq("Multiple Match", out_mm
, mm
)
23 assert_ne("Multiple Match", out_mm
, mm
)
25 def check_single_match(dut
, sm
, op
):
26 out_sm
= yield dut
.single_match
28 assert_eq("Single Match", out_sm
, sm
)
30 assert_ne("Single Match", out_sm
, sm
)
32 def check_match_address(dut
, ma
, op
):
33 out_ma
= yield dut
.match_address
35 assert_eq("Match Address", out_ma
, ma
)
37 assert_ne("Match Address", out_ma
, ma
)
39 def check_all(dut
, multiple_match
, single_match
, match_address
, mm_op
, sm_op
, ma_op
):
40 yield from check_multiple_match(dut
, multiple_match
, mm_op
)
41 yield from check_single_match(dut
, single_match
, sm_op
)
42 yield from check_match_address(dut
, match_address
, ma_op
)
53 yield from set_cam(dut
, enable
, write_enable
, address
, data
)
55 yield from check_single_match(dut
, single_match
, 0)
58 # Note that the default starting entry data bits are all 0
65 yield from set_cam(dut
, enable
, write_enable
, address
, data
)
67 yield from check_multiple_match(dut
, multiple_match
, 0)
70 # Note that the default starting entry data bits are all 0
77 yield from set_cam(dut
, enable
, write_enable
, address
, data
)
79 yield from check_single_match(dut
, single_match
, 0)
88 yield from set_cam(dut
, enable
, write_enable
, address
, data
)
90 yield from check_single_match(dut
, single_match
, 0)
99 yield from set_cam(dut
, enable
, write_enable
, address
, data
)
101 yield from check_all(dut
, multiple_match
, single_match
, address
, 0, 0, 0)
110 yield from set_cam(dut
, enable
, write_enable
, address
, data
)
112 yield from check_all(dut
, multiple_match
, single_match
, address
, 0, 0, 0)
120 yield from set_cam(dut
, enable
, write_enable
, address
, data
)
122 yield from check_single_match(dut
, single_match
, 0)
127 if __name__
== "__main__":
129 run_simulation(dut
, testbench(dut
), vcd_name
="Waveforms/cam_test.vcd")
130 print("Cam Unit Test Success")