145ded7d32797e4a4feec808384e9adb8509962f
[soc.git] / src / soc / TLB / ariane / test / test_tlb_content.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 TLB.ariane.tlb_content import TLBContent
8 from TestUtil.test_helper import assert_op, assert_eq
9
10 def update(dut,a,t,g,m):
11 yield dut.replace_en_i.eq(1)
12 yield dut.update_i.valid.eq(1)
13 yield dut.update_i.is_512G.eq(t)
14 yield dut.update_i.is_1G.eq(g)
15 yield dut.update_i.is_2M.eq(m)
16 yield dut.update_i.vpn.eq(a)
17 yield
18 yield
19
20 def check_hit(dut,hit,pagesize):
21 hit_d = yield dut.lu_hit_o
22 assert_eq("hit", hit_d, hit)
23
24 if(hit):
25 if(pagesize=="t"):
26 hitp = yield dut.lu_is_512G_o
27 assert_eq("lu_is_512G_o", hitp, 1)
28 elif(pagesize=="g"):
29 hitp = yield dut.lu_is_1G_o
30 assert_eq("lu_is_1G_o", hitp, 1)
31 elif(pagesize=="m"):
32 hitp = yield dut.lu_is_2M_o
33 assert_eq("lu_is_2M_o", hitp, 1)
34
35 def addr(a,b,c,d):
36 return a | b << 9 | c << 18 | d << 27
37
38 def tbench(dut):
39 yield dut.vpn0.eq(0x0A)
40 yield dut.vpn1.eq(0x0B)
41 yield dut.vpn2.eq(0x0C)
42 yield dut.vpn3.eq(0x0D)
43 yield from update(dut,addr(0xFF,0xFF,0xFF,0x0D),1,0,0)
44 yield from check_hit(dut,1,"t")
45
46 yield from update(dut,addr(0xFF,0xFF,0x0C,0x0D),0,1,0)
47 yield from check_hit(dut,1,"g")
48
49 yield from update(dut,addr(0xFF,0x0B,0x0C,0x0D),0,0,1)
50 yield from check_hit(dut,1,"m")
51
52 yield from update(dut,addr(0x0A,0x0B,0x0C,0x0D),0,0,0)
53 yield from check_hit(dut,1,"")
54
55 yield from update(dut,addr(0xAA,0xBB,0xCC,0xDD),0,0,0)
56 yield from check_hit(dut,0,"miss")
57
58
59 if __name__ == "__main__":
60 dut = TLBContent(4,4)
61 #
62 run_simulation(dut, tbench(dut), vcd_name="test_tlb_content.vcd")
63 print("TLBContent Unit Test Success")