From 87eff7c1ae8302f11bb4c0d9d4248e7f3c41e512 Mon Sep 17 00:00:00 2001 From: Daniel Benusovich Date: Wed, 13 Mar 2019 22:18:03 -0700 Subject: [PATCH] Add permission validator unit test. Still needs more but basics are here! --- TLB/test/test_permission_validator.py | 145 ++++++++++++++++++++++++++ 1 file changed, 145 insertions(+) create mode 100644 TLB/test/test_permission_validator.py diff --git a/TLB/test/test_permission_validator.py b/TLB/test/test_permission_validator.py new file mode 100644 index 00000000..6b4d7573 --- /dev/null +++ b/TLB/test/test_permission_validator.py @@ -0,0 +1,145 @@ +import sys +sys.path.append("../src") +sys.path.append("../../TestUtil") + +from nmigen.compat.sim import run_simulation + +from PermissionValidator import PermissionValidator + +from test_helper import assert_op + +def set_validator(dut, d, xwr, sm, sa, asid): + yield dut.data.eq(d) + yield dut.xwr.eq(xwr) + yield dut.super_mode.eq(sm) + yield dut.super_access.eq(sa) + yield dut.asid.eq(asid) + yield + +def check_valid(dut, v, op): + out_v = yield dut.valid + assert_op("Valid", out_v, v, op) + +def testbench(dut): + # 80 bits represented. Ignore the MSB as it will be truncated + # ASID is bits first 4 hex values (bits 64 - 78) + + # Test user mode entry valid + # Global Bit matching ASID + # Ensure that user mode and valid is enabled! + data = 0x7FFF0000000000000031 + # Ignore MSB it will be truncated + asid = 0x7FFF + super_mode = 0 + super_access = 0 + xwr = 0 + valid = 1 + yield from set_validator(dut, data, xwr, super_mode, super_access, asid) + yield from check_valid(dut, valid, 0) + + # Test user mode entry valid + # Global Bit nonmatching ASID + # Ensure that user mode and valid is enabled! + data = 0x7FFF0000000000000031 + # Ignore MSB it will be truncated + asid = 0x7FF6 + super_mode = 0 + super_access = 0 + xwr = 0 + valid = 1 + yield from set_validator(dut, data, xwr, super_mode, super_access, asid) + yield from check_valid(dut, valid, 0) + + # Test user mode entry invalid + # Global Bit nonmatching ASID + # Ensure that user mode and valid is enabled! + data = 0x7FFF0000000000000021 + # Ignore MSB it will be truncated + asid = 0x7FF6 + super_mode = 0 + super_access = 0 + xwr = 0 + valid = 0 + yield from set_validator(dut, data, xwr, super_mode, super_access, asid) + yield from check_valid(dut, valid, 0) + + # Test user mode entry valid + # Ensure that user mode and valid is enabled! + data = 0x7FFF0000000000000011 + # Ignore MSB it will be truncated + asid = 0x7FFF + super_mode = 0 + super_access = 0 + xwr = 0 + valid = 1 + yield from set_validator(dut, data, xwr, super_mode, super_access, asid) + yield from check_valid(dut, valid, 0) + + # Test user mode entry invalid + # Ensure that user mode and valid is enabled! + data = 0x7FFF0000000000000011 + # Ignore MSB it will be truncated + asid = 0x7FF6 + super_mode = 0 + super_access = 0 + xwr = 0 + valid = 0 + yield from set_validator(dut, data, xwr, super_mode, super_access, asid) + yield from check_valid(dut, valid, 0) + + # Test supervisor mode entry valid + # The entry is NOT in user mode + # Ensure that user mode and valid is enabled! + data = 0x7FFF0000000000000001 + # Ignore MSB it will be truncated + asid = 0x7FFF + super_mode = 1 + super_access = 0 + xwr = 0 + valid = 1 + yield from set_validator(dut, data, xwr, super_mode, super_access, asid) + yield from check_valid(dut, valid, 0) + + # Test supervisor mode entry invalid + # The entry is in user mode + # Ensure that user mode and valid is enabled! + data = 0x7FFF0000000000000011 + # Ignore MSB it will be truncated + asid = 0x7FFF + super_mode = 1 + super_access = 0 + xwr = 0 + valid = 0 + yield from set_validator(dut, data, xwr, super_mode, super_access, asid) + yield from check_valid(dut, valid, 0) + + # Test supervisor mode entry valid + # The entry is NOT in user mode with access + # Ensure that user mode and valid is enabled! + data = 0x7FFF0000000000000001 + # Ignore MSB it will be truncated + asid = 0x7FFF + super_mode = 1 + super_access = 1 + xwr = 0 + valid = 1 + yield from set_validator(dut, data, xwr, super_mode, super_access, asid) + yield from check_valid(dut, valid, 0) + + # Test supervisor mode entry valid + # The entry is in user mode with access + # Ensure that user mode and valid is enabled! + data = 0x7FFF0000000000000011 + # Ignore MSB it will be truncated + asid = 0x7FFF + super_mode = 1 + super_access = 1 + xwr = 0 + valid = 1 + yield from set_validator(dut, data, xwr, super_mode, super_access, asid) + yield from check_valid(dut, valid, 0) + +if __name__ == "__main__": + dut = PermissionValidator(64 + 15); + run_simulation(dut, testbench(dut), vcd_name="Waveforms/test_permission_validator.vcd") + print("PermissionValidator Unit Test Success") -- 2.30.2