Skip to content

Commit 8199bc9

Browse files
committed
attempt to fix gl_test
1 parent 06a6fcb commit 8199bc9

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

test/test.py

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,17 @@
55
from cocotb.clock import Clock
66
from cocotb.triggers import RisingEdge, ClockCycles, ReadOnly
77

8+
# to help in gd_test build
9+
from cocotb.handle import SimHandleBase
10+
11+
def safe_get(dut: SimHandleBase, *paths: str) -> SimHandleBase:
12+
# Return the first handle that exists. Works with or without Yosys flattening.
13+
for p in paths:
14+
try:
15+
return dut._id(p, extended=True)
16+
except (AttributeError, KeyError):
17+
continue
18+
raise AttributeError(f"None of {paths} found in DUT hierarchy")
819

920
async def clock_init(dut, useconds):
1021
clock = Clock(dut.clk, useconds, units="us")
@@ -36,14 +47,24 @@ async def load_instruction(dut, byte):
3647
await pb0_press(dut)
3748

3849
async def get_acc(dut):
39-
val = dut.user_project.u_cpu_core.acc.acc_bits.value
40-
return val
50+
# val = dut.user_project.u_cpu_core.acc.acc_bits.value
51+
# return val
52+
h = safe_get(dut,
53+
"user_project.u_cpu_core.acc.acc_bits", # un‑flattened
54+
"user_project.acc_reg") # flattened (Yosys default)
55+
await ReadOnly()
56+
return h.value.integer & 0xFF
4157

4258
async def get_reg(dut, reg):
43-
dut.user_project.u_cpu_core.regfile.rs1_addr.value = reg
59+
rs1 = safe_get(dut,
60+
"user_project.u_cpu_core.regfile.rs1_addr",
61+
"user_project.rs1_addr")
62+
data = safe_get(dut,
63+
"user_project.u_cpu_core.regfile.regfile_bits",
64+
"user_project.regfile_bits")
65+
rs1.value = reg
4466
await ReadOnly()
45-
val = dut.user_project.u_cpu_core.regfile.regfile_bits.value
46-
return val
67+
return data.value.integer & 0xFF
4768

4869
async def assert_acc(dut, value):
4970
await ClockCycles(dut.clk, 3)

0 commit comments

Comments
 (0)