def set_encoder(dut, i):
yield dut.i.eq(i)
yield
-
+
# Checks the single match of the AddressEncoder
# Arguments:
# dut: The AddressEncoder being tested
def check_single_match(dut, sm, op):
out_sm = yield dut.single_match
assert_op("Single Match", out_sm, sm, op)
-
+
# Checks the multiple match of the AddressEncoder
# Arguments:
# dut: The AddressEncoder being tested
# mm (Multiple Match): The expected match result
-# op (Operation): (0 => ==), (1 => !=)
+# op (Operation): (0 => ==), (1 => !=)
def check_multiple_match(dut, mm, op):
out_mm = yield dut.multiple_match
assert_op("Multiple Match", out_mm, mm, op)
-
+
# Checks the output of the AddressEncoder
# Arguments:
# dut: The AddressEncoder being tested
output = 0
yield from set_encoder(dut, input)
yield from check_all(dut, single_match, multiple_match, output, 0, 0, 0)
-
+
# Check single bit
input = 1
single_match = 1
multiple_match = 0
output = 0
yield from set_encoder(dut, input)
- yield from check_all(dut, single_match, multiple_match, output, 0, 0, 0)
-
+ yield from check_all(dut, single_match, multiple_match, output, 0, 0, 0)
+
# Check another single bit
input = 4
single_match = 1
multiple_match = 0
output = 2
yield from set_encoder(dut, input)
- yield from check_all(dut, single_match, multiple_match, output, 0, 0, 0)
-
+ yield from check_all(dut, single_match, multiple_match, output, 0, 0, 0)
+
# Check multiple match
# We expected the lowest bit to be returned which is address 0
input = 5
multiple_match = 1
output = 0
yield from set_encoder(dut, input)
- yield from check_all(dut, single_match, multiple_match, output, 0, 0, 0)
-
+ yield from check_all(dut, single_match, multiple_match, output, 0, 0, 0)
+
# Check another multiple match
# We expected the lowest bit to be returned which is address 1
input = 6
multiple_match = 1
output = 1
yield from set_encoder(dut, input)
- yield from check_all(dut, single_match, multiple_match, output, 0, 0, 0)
-
-
+ yield from check_all(dut, single_match, multiple_match, output, 0, 0, 0)
if __name__ == "__main__":
dut = AddressEncoder(4)
run_simulation(dut, testbench(dut), vcd_name="Waveforms/test_address_encoder.vcd")
- print("AddressEncoder Unit Test Success")
\ No newline at end of file
+ print("AddressEncoder Unit Test Success")