9fcc6609ab4f29b6270a9d2bac43d7196b8fd362
2 sys
.path
.append("../src")
3 sys
.path
.append("../../TestUtil")
5 from nmigen
.compat
.sim
import run_simulation
7 from test_helper
import assert_eq
, assert_ne
8 from CamEntry
import CamEntry
10 # This function allows for the easy setting of values to the Cam Entry
11 # unless the key is incorrect
13 # dut: The CamEntry being tested
14 # c (command): NA (0), Read (1), Write (2), Reserve (3)
15 # d (data): The data to be set
16 def set_cam_entry(dut
, c
, d
):
17 # Write desired values
18 yield dut
.command
.eq(c
)
19 yield dut
.data_in
.eq(d
)
22 yield dut
.command
.eq(0)
23 yield dut
.data_in
.eq(0)
26 # Checks the data state of the CAM entry
28 # dut: The CamEntry being tested
29 # d (Data): The expected data
30 # op (Operation): (0 => ==), (1 => !=)
31 def check_data(dut
, d
, op
):
32 out_d
= yield dut
.data
34 assert_eq("Data", out_d
, d
)
36 assert_ne("Data", out_d
, d
)
38 # Checks the match state of the CAM entry
40 # dut: The CamEntry being tested
41 # m (Match): The expected match
42 # op (Operation): (0 => ==), (1 => !=)
43 def check_match(dut
, m
, op
):
44 out_m
= yield dut
.match
46 assert_eq("Match", out_m
, m
)
48 assert_ne("Match", out_m
, m
)
50 # Checks the state of the CAM entry
52 # dut: The CamEntry being tested
53 # d (data): The expected data
54 # m (match): The expected match
55 # d_op (Operation): The operation for the data assertion (0 => ==), (1 => !=)
56 # m_op (Operation): The operation for the match assertion (0 => ==), (1 => !=)
57 def check_all(dut
, d
, m
, d_op
, m_op
):
58 yield from check_data(dut
, d
, d_op
)
59 yield from check_match(dut
, m
, m_op
)
61 # This testbench goes through the paces of testing the CamEntry module
62 # It is done by writing and then reading various combinations of key/data pairs
63 # and reading the results with varying keys to verify the resulting stored
70 yield from set_cam_entry(dut
, command
, data
)
71 yield from check_all(dut
, data
, match
, 0, 0)
77 yield from set_cam_entry(dut
, command
, data
)
78 yield from check_all(dut
, data
, match
, 1, 0)
84 yield from set_cam_entry(dut
, command
, data
)
85 yield from check_all(dut
, data
, match
, 0, 0)
91 yield from set_cam_entry(dut
, command
, data
)
93 yield from check_all(dut
, data
, match
, 0, 0)
99 yield from set_cam_entry(dut
, command
, data
)
100 yield from check_all(dut
, data
, match
, 0, 0)
106 yield from set_cam_entry(dut
, command
, data
)
107 yield from check_all(dut
, data
, match
, 0, 0)
109 # Extra clock cycle for waveform
112 if __name__
== "__main__":
114 run_simulation(dut
, testbench(dut
), vcd_name
="Waveforms/cam_entry_test.vcd")
115 print("CamEntry Unit Test Success")