07c09c48dcaf673a38815cd03647bfe391fa1250
2 sys
.path
.append("../src")
3 sys
.path
.append("../../TestUtil")
5 from nmigen
.compat
.sim
import run_simulation
7 from test_helper
import check
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 # k (key): The key to be set
16 # d (data): The data to be set
17 def set_cam_entry(dut
, c
, k
, d
):
18 # Write desired values
19 yield dut
.command
.eq(c
)
20 yield dut
.key_in
.eq(k
)
21 yield dut
.data_in
.eq(d
)
24 yield dut
.command
.eq(0)
25 yield dut
.key_in
.eq(0)
26 yield dut
.data_in
.eq(0)
29 # Checks the key state of the CAM entry
31 # dut: The CamEntry being tested
32 # k (Key): The expected key
33 # op (Operation): (0 => ==), (1 => !=)
34 def check_key(dut
, k
, op
):
36 check("Key", out_k
, k
, op
)
38 # Checks the data state of the CAM entry
40 # dut: The CamEntry being tested
41 # d (Data): The expected data
42 # op (Operation): (0 => ==), (1 => !=)
43 def check_data(dut
, d
, op
):
44 out_d
= yield dut
.data
45 check("Data", out_d
, d
, op
)
47 # Checks the match state of the CAM entry
49 # dut: The CamEntry being tested
50 # m (Match): The expected match
51 # op (Operation): (0 => ==), (1 => !=)
52 def check_match(dut
, m
, op
):
53 out_m
= yield dut
.match
54 check("Match", out_m
, m
, op
)
56 # Checks the state of the CAM entry
58 # dut: The CamEntry being tested
59 # k (key): The expected key
60 # d (data): The expected data
61 # m (match): The expected match
62 # k_op (Operation): The operation for the key assertion (0 => ==), (1 => !=)
63 # d_op (Operation): The operation for the data assertion (0 => ==), (1 => !=)
64 # m_op (Operation): The operation for the match assertion (0 => ==), (1 => !=)
65 def check_all(dut
, k
, d
, m
, k_op
, d_op
, m_op
):
66 yield from check_key(dut
, k
, k_op
)
67 yield from check_data(dut
, d
, d_op
)
68 yield from check_match(dut
, m
, m_op
)
70 # This testbench goes through the paces of testing the CamEntry module
71 # It is done by writing and then reading various combinations of key/data pairs
72 # and reading the results with varying keys to verify the resulting stored
80 yield from set_cam_entry(dut
, command
, key
, data
)
81 yield from check_all(dut
, key
, data
, match
, 0, 0, 0)
88 yield from set_cam_entry(dut
, command
, key
, data
)
89 yield from check_all(dut
, key
, data
, match
, 1, 0, 0)
96 yield from set_cam_entry(dut
, command
, key
, data
)
97 yield from check_all(dut
, key
, data
, match
, 0, 0, 0)
104 yield from set_cam_entry(dut
, command
, key
, data
)
106 yield from check_all(dut
, key
, data
, match
, 0, 0, 0)
113 yield from set_cam_entry(dut
, command
, key
, data
)
114 yield from check_all(dut
, key
, data
, match
, 0, 0, 0)
116 # Extra clock cycle for waveform
119 if __name__
== "__main__":
121 run_simulation(dut
, testbench(dut
), vcd_name
="Waveforms/cam_entry_test.vcd")
122 print("CamEntry Unit Test Success")