1+ import argparse
12from harness import parse_instrs , init , reg_to_binary , generate_json
2- from tests import tests
3+ import tests
4+ from tests import *
35import json
46import subprocess
7+ import os
58
69def 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
106109def 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+
160171def 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
191212if __name__ == "__main__" :
192213 main ()
0 commit comments