Skip to content

Commit a005ba3

Browse files
committed
testing things
1 parent b9dbeca commit a005ba3

File tree

5 files changed

+45
-20
lines changed

5 files changed

+45
-20
lines changed

apps/frisc/harness/expected.py

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
import argparse
12
from harness import parse_instrs, init, reg_to_binary, generate_json
2-
from tests import tests
3+
import tests
4+
from tests import *
35
import json
46
import subprocess
7+
import os
58

69
def run_instr_seq(instrs, mem, rf):
710
for instr in instrs:
@@ -104,7 +107,7 @@ def run_instr(instr, mem, rf):
104107

105108
# Formats mem as an array
106109
def mem_to_array(mem):
107-
mem_arr = [99999] * 2
110+
mem_arr = [99999] * 64
108111
for k in sorted(mem.keys()):
109112
mem_arr[k] = mem[k]
110113
return mem_arr
@@ -118,13 +121,13 @@ def mem_to_json(instrs, mem):
118121
output_json = json.dumps(output_dict)
119122
return output_json
120123

121-
def run_fud():
124+
def run_fud(insn_size, data_size, dump_vcd):
122125
subprocess.run([
123126
"fud",
124127
"e",
125-
"top.futil",
128+
f"top_{insn_size}_{data_size}.futil",
126129
"--to",
127-
"dat",
130+
"vcd" if dump_vcd else "dat",
128131
"--through",
129132
"icarus-verilog",
130133
"-s",
@@ -133,7 +136,7 @@ def run_fud():
133136
], stdout=open("top.out",'w'), stderr=open("top.err", 'w')
134137
)
135138

136-
def generate_input_json(instrs):
139+
def generate_input_json(instrs, data_size):
137140
int_lst = parse_instrs(instrs)
138141
output_dict= {}
139142
output_dict["iram"] = {}
@@ -146,7 +149,7 @@ def generate_input_json(instrs):
146149
output_dict["iram"]["format"]["width"] = 32
147150

148151
output_dict["res"] = {}
149-
output_dict["res"]["data"] = 2 * [99999]
152+
output_dict["res"]["data"] = data_size * [99999]
150153
output_dict["res"]["format"] = {}
151154
output_dict["res"]["format"]["numeric_type"] = "bitnum"
152155
output_dict["res"]["format"]["is_signed"] = False
@@ -157,9 +160,21 @@ def generate_input_json(instrs):
157160
with open("top.json", 'w') as f:
158161
f.write(output_json)
159162

163+
def generate_top(insn_size, data_size):
164+
subprocess.run([
165+
"cp",
166+
"top.futil",
167+
f"top_{insn_size}_{data_size}.futil"
168+
])
169+
os.system(f"sed -i '' 's/INSN_SIZE/{insn_size}/g;s/DATA_SIZE/{data_size}/g' top_{insn_size}_{data_size}.futil")
170+
160171
def main():
172+
parser = argparse.ArgumentParser(description="Parse arguments for generating tests")
173+
parser.add_argument("--vcd", action="store_true")
174+
args = parser.parse_args()
175+
161176
# test is a string
162-
for test in tests:
177+
for test in tests.tests1:
163178
mem = {}
164179
rf = {}
165180
for i in range(0, 32):
@@ -168,25 +183,31 @@ def main():
168183

169184
# instrs is a list of strings
170185
instrs = init(test)
186+
insn_size = len(instrs)
187+
data_size = 64
171188
exp_mem = run_instr_seq(instrs, mem, rf)
189+
print(f"exp_mem: {exp_mem}")
172190

173191
# the expected memory output
174192
exp_mem_json = mem_to_json(instrs, exp_mem)
175193

176-
generate_input_json(instrs)
194+
generate_input_json(instrs, data_size)
195+
196+
generate_top(insn_size, data_size)
177197

178198
# run fud
179-
run_fud()
199+
run_fud(insn_size, data_size, args.vcd)
180200

181201
processed_fud_out = {}
182202
with open("top.out") as f:
183203
fud_out = json.load(f)
184204
processed_fud_out = fud_out["memories"]
185205
processed_fud_out = str(processed_fud_out).replace("\'", "\"")
186206

187-
if exp_mem_json != processed_fud_out:
207+
if exp_mem_json != processed_fud_out and not args.vcd:
188208
print(f"expected {exp_mem_json} but got {processed_fud_out}\n")
189-
209+
elif exp_mem_json == processed_fud_out:
210+
print(f"got {exp_mem_json}")
190211

191212
if __name__ == "__main__":
192213
main()

apps/frisc/harness/run.sh

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,4 @@ cargo run --bin filament ../src/cpu.fil --library ../../.. --backend calyx --dis
77

88
python expected.py
99

10-
rm top.err
11-
rm top.out
12-
rm top.json
13-
rm frisc.futil
10+
# rm top.err top.out top.json frisc.futil

apps/frisc/harness/tests.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,10 @@
33
sw x1 0(x0)
44
"""
55

6-
tests = [test0]
6+
test1 = """
7+
addi x1 x0 2
8+
sw x1 0(x1)
9+
"""
10+
11+
tests0 = [test0]
12+
tests1 = [test1]

apps/frisc/harness/top.futil

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import "primitives/memories/comb.futil";
33

44
component main (@clk clk: 1, @reset reset: 1, @go go: 1) -> () {
55
cells {
6-
@external iram = comb_mem_d1(32,2,32);
7-
@external res = comb_mem_d1(32,2,32);
6+
@external iram = comb_mem_d1(32,INSN_SIZE,32);
7+
@external res = comb_mem_d1(32,DATA_SIZE,32);
88
cpu = CPU();
99

1010
pc_reg = std_reg(32);

apps/frisc/src/cpu.fil

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,8 @@ comp CPU<'G:1> (
200200
nextpc = nextPC.out;
201201
pc = pc.pc;
202202
memAddr = loadStoreAddr.out;
203-
memData = memData_31_0.out;
203+
// memData = memData_31_0.out;
204+
memData = rf.rs2;
204205
memWriteMask = writeMask.out;
205206
rfDataOut = rfData.out;
206207
isStore = decoder.isStore;

0 commit comments

Comments
 (0)