6b4d7573fbce9bb5361997fe8b0046b870910dad
[soc.git] / TLB / test / test_permission_validator.py
1 import sys
2 sys.path.append("../src")
3 sys.path.append("../../TestUtil")
4
5 from nmigen.compat.sim import run_simulation
6
7 from PermissionValidator import PermissionValidator
8
9 from test_helper import assert_op
10
11 def set_validator(dut, d, xwr, sm, sa, asid):
12 yield dut.data.eq(d)
13 yield dut.xwr.eq(xwr)
14 yield dut.super_mode.eq(sm)
15 yield dut.super_access.eq(sa)
16 yield dut.asid.eq(asid)
17 yield
18
19 def check_valid(dut, v, op):
20 out_v = yield dut.valid
21 assert_op("Valid", out_v, v, op)
22
23 def testbench(dut):
24 # 80 bits represented. Ignore the MSB as it will be truncated
25 # ASID is bits first 4 hex values (bits 64 - 78)
26
27 # Test user mode entry valid
28 # Global Bit matching ASID
29 # Ensure that user mode and valid is enabled!
30 data = 0x7FFF0000000000000031
31 # Ignore MSB it will be truncated
32 asid = 0x7FFF
33 super_mode = 0
34 super_access = 0
35 xwr = 0
36 valid = 1
37 yield from set_validator(dut, data, xwr, super_mode, super_access, asid)
38 yield from check_valid(dut, valid, 0)
39
40 # Test user mode entry valid
41 # Global Bit nonmatching ASID
42 # Ensure that user mode and valid is enabled!
43 data = 0x7FFF0000000000000031
44 # Ignore MSB it will be truncated
45 asid = 0x7FF6
46 super_mode = 0
47 super_access = 0
48 xwr = 0
49 valid = 1
50 yield from set_validator(dut, data, xwr, super_mode, super_access, asid)
51 yield from check_valid(dut, valid, 0)
52
53 # Test user mode entry invalid
54 # Global Bit nonmatching ASID
55 # Ensure that user mode and valid is enabled!
56 data = 0x7FFF0000000000000021
57 # Ignore MSB it will be truncated
58 asid = 0x7FF6
59 super_mode = 0
60 super_access = 0
61 xwr = 0
62 valid = 0
63 yield from set_validator(dut, data, xwr, super_mode, super_access, asid)
64 yield from check_valid(dut, valid, 0)
65
66 # Test user mode entry valid
67 # Ensure that user mode and valid is enabled!
68 data = 0x7FFF0000000000000011
69 # Ignore MSB it will be truncated
70 asid = 0x7FFF
71 super_mode = 0
72 super_access = 0
73 xwr = 0
74 valid = 1
75 yield from set_validator(dut, data, xwr, super_mode, super_access, asid)
76 yield from check_valid(dut, valid, 0)
77
78 # Test user mode entry invalid
79 # Ensure that user mode and valid is enabled!
80 data = 0x7FFF0000000000000011
81 # Ignore MSB it will be truncated
82 asid = 0x7FF6
83 super_mode = 0
84 super_access = 0
85 xwr = 0
86 valid = 0
87 yield from set_validator(dut, data, xwr, super_mode, super_access, asid)
88 yield from check_valid(dut, valid, 0)
89
90 # Test supervisor mode entry valid
91 # The entry is NOT in user mode
92 # Ensure that user mode and valid is enabled!
93 data = 0x7FFF0000000000000001
94 # Ignore MSB it will be truncated
95 asid = 0x7FFF
96 super_mode = 1
97 super_access = 0
98 xwr = 0
99 valid = 1
100 yield from set_validator(dut, data, xwr, super_mode, super_access, asid)
101 yield from check_valid(dut, valid, 0)
102
103 # Test supervisor mode entry invalid
104 # The entry is in user mode
105 # Ensure that user mode and valid is enabled!
106 data = 0x7FFF0000000000000011
107 # Ignore MSB it will be truncated
108 asid = 0x7FFF
109 super_mode = 1
110 super_access = 0
111 xwr = 0
112 valid = 0
113 yield from set_validator(dut, data, xwr, super_mode, super_access, asid)
114 yield from check_valid(dut, valid, 0)
115
116 # Test supervisor mode entry valid
117 # The entry is NOT in user mode with access
118 # Ensure that user mode and valid is enabled!
119 data = 0x7FFF0000000000000001
120 # Ignore MSB it will be truncated
121 asid = 0x7FFF
122 super_mode = 1
123 super_access = 1
124 xwr = 0
125 valid = 1
126 yield from set_validator(dut, data, xwr, super_mode, super_access, asid)
127 yield from check_valid(dut, valid, 0)
128
129 # Test supervisor mode entry valid
130 # The entry is in user mode with access
131 # Ensure that user mode and valid is enabled!
132 data = 0x7FFF0000000000000011
133 # Ignore MSB it will be truncated
134 asid = 0x7FFF
135 super_mode = 1
136 super_access = 1
137 xwr = 0
138 valid = 1
139 yield from set_validator(dut, data, xwr, super_mode, super_access, asid)
140 yield from check_valid(dut, valid, 0)
141
142 if __name__ == "__main__":
143 dut = PermissionValidator(64 + 15);
144 run_simulation(dut, testbench(dut), vcd_name="Waveforms/test_permission_validator.vcd")
145 print("PermissionValidator Unit Test Success")