-
Notifications
You must be signed in to change notification settings - Fork 21
/
test.py
executable file
·70 lines (49 loc) · 1.57 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python3
# Simple example illustrating the Switchboard Python binding
# Copyright (c) 2024 Zero ASIC Corporation
# This code is licensed under Apache License 2.0 (see LICENSE for details)
import sys
import numpy as np
from switchboard import PySbPacket, PySbTx, PySbRx, SbDut
def main():
# build the simulator
dut = SbDut(cmdline=True)
dut.input('testbench.sv')
dut.build()
# create queues
tx = PySbTx('to_rtl.q', fresh=True)
rx = PySbRx('from_rtl.q', fresh=True)
# start chip simulation
chip = dut.simulate()
# form packet to be sent into the simulation. note that the arguments
# to the constructor are all optional, and can all be specified later
txp = PySbPacket(
destination=123456789,
flags=1,
data=np.arange(32, dtype=np.uint8)
)
# send the packet
tx.send(txp) # note: blocking by default, can disable with blocking=False
print("*** TX packet ***")
print(txp)
print()
# receive packet
rxp = rx.recv() # note: blocking by default, can disable with blocking=False
rxp.data = rxp.data[:32]
print("*** RX packet ***")
print(rxp)
print()
# check that the received data
success = np.array_equal(rxp.data, txp.data + 1)
# stop simulation
tx.send(PySbPacket(data=np.array([0xff] * 32, dtype=np.uint8)))
chip.wait()
# declare test as having passed for regression testing purposes
if success:
print("PASS!")
sys.exit(0)
else:
print("FAIL")
sys.exit(1)
if __name__ == '__main__':
main()