def run_cosimulation_test(source_file, *unused): random_seed = random.randint(0, 0xffffffff) if test_harness.DEBUG: print('random seed is {}'.format(random_seed)) verilator_args = [ test_harness.VSIM_PATH, '+trace', '+memdumpfile=' + VERILATOR_MEM_DUMP, '+memdumpbase=800000', '+memdumplen=400000', '+autoflushl2', '+verilator+rand+reset+2', '+verilator+seed+{}'.format(random_seed) ] # XXX this should probably be a command line option in test_harness.py if 'RANDSEED' in os.environ: verilator_args += ['+randseed=' + os.environ['RANDSEED']] emulator_args = [ test_harness.EMULATOR_PATH, '-m', 'cosim', '-d', EMULATOR_MEM_DUMP + ',0x800000,0x400000' ] if test_harness.DEBUG: emulator_args += ['-v'] hexfile = test_harness.build_program([source_file]) try: p1 = subprocess.Popen( verilator_args + ['+bin=' + hexfile], stdout=subprocess.PIPE) p2 = subprocess.Popen( emulator_args + [hexfile], stdin=p1.stdout, stdout=subprocess.PIPE) output = '' while True: got = p2.stdout.read(0x1000) if not got: break if test_harness.DEBUG: print(got.decode()) else: output += got.decode() p2.wait() time.sleep(1) # Give verilator a chance to clean up finally: p1.kill() p2.kill() if p2.returncode: raise test_harness.TestException( 'FAIL: cosimulation mismatch\n' + output) test_harness.assert_files_equal(VERILATOR_MEM_DUMP, EMULATOR_MEM_DUMP, 'final memory contents to not match')
def run_cosimulation_test(source_file): global emulator_args global verilator_args hexfile = test_harness.assemble_test(source_file) p1 = subprocess.Popen(verilator_args + [ '+bin=' + hexfile ], stdout=subprocess.PIPE) p2 = subprocess.Popen(emulator_args + [ hexfile ], stdin=p1.stdout, stdout=subprocess.PIPE) output = '' while True: got = p2.stdout.read(0x1000) if not got: break if verbose: print(str(got)) else: output += str(got) p2.wait() time.sleep(1) # Give verilator a chance to clean up p1.kill() # Make sure verilator has exited if p2.returncode != 0: raise test_harness.TestException('FAIL: cosimulation mismatch\n' + output) test_harness.assert_files_equal(VERILATOR_MEM_DUMP, EMULATOR_MEM_DUMP, 'final memory contents to not match')
def run_cosimulation_test(source_file, target): verilator_args = [ '../../bin/verilator_model', '+trace', '+simcycles=2000000', '+memdumpfile=' + VERILATOR_MEM_DUMP, '+memdumpbase=800000', '+memdumplen=400000', '+autoflushl2' ] # XXX this should probably be a command line option in test_harness.py if 'RANDSEED' in os.environ: verilator_args += ['+randseed=' + os.environ['RANDSEED']] emulator_args = [ '../../bin/emulator', '-m', 'cosim', '-d', 'obj/mmem.bin,0x800000,0x400000' ] if test_harness.DEBUG: emulator_args += ['-v'] hexfile = test_harness.build_program([source_file]) p1 = subprocess.Popen( verilator_args + ['+bin=' + hexfile], stdout=subprocess.PIPE) p2 = subprocess.Popen( emulator_args + [hexfile], stdin=p1.stdout, stdout=subprocess.PIPE) output = '' while True: got = p2.stdout.read(0x1000) if not got: break if test_harness.DEBUG: print(got.decode()) else: output += got.decode() p2.wait() time.sleep(1) # Give verilator a chance to clean up p1.kill() # Make sure verilator has exited if p2.returncode: raise test_harness.TestException( 'FAIL: cosimulation mismatch\n' + output) test_harness.assert_files_equal(VERILATOR_MEM_DUMP, EMULATOR_MEM_DUMP, 'final memory contents to not match')
def sdmmc_read(name, target): # Create random file with open(SOURCE_BLOCK_DEV, 'wb') as randfile: randfile.write(os.urandom(FILE_SIZE)) test_harness.build_program(['sdmmc_read.c']) test_harness.run_program(target=target, block_device=SOURCE_BLOCK_DEV, dump_file=MEMDUMP, dump_base=0x200000, dump_length=FILE_SIZE, flush_l2=True) test_harness.assert_files_equal(SOURCE_BLOCK_DEV, MEMDUMP, 'file mismatch')
def run_cosimulation_test(source_file, *unused): verilator_args = [ test_harness.VSIM_PATH, '+trace', '+memdumpfile=' + VERILATOR_MEM_DUMP, '+memdumpbase=800000', '+memdumplen=400000', '+autoflushl2' ] # XXX this should probably be a command line option in test_harness.py if 'RANDSEED' in os.environ: verilator_args += ['+randseed=' + os.environ['RANDSEED']] emulator_args = [ test_harness.EMULATOR_PATH, '-m', 'cosim', '-d', EMULATOR_MEM_DUMP + ',0x800000,0x400000' ] if test_harness.DEBUG: emulator_args += ['-v'] hexfile = test_harness.build_program([source_file]) p1 = subprocess.Popen( verilator_args + ['+bin=' + hexfile], stdout=subprocess.PIPE) p2 = subprocess.Popen( emulator_args + [hexfile], stdin=p1.stdout, stdout=subprocess.PIPE) output = '' while True: got = p2.stdout.read(0x1000) if not got: break if test_harness.DEBUG: print(got.decode()) else: output += got.decode() p2.wait() time.sleep(1) # Give verilator a chance to clean up test_harness.kill_gently(p2) # Make sure verilator has exited if p2.returncode: raise test_harness.TestException( 'FAIL: cosimulation mismatch\n' + output) test_harness.assert_files_equal(VERILATOR_MEM_DUMP, EMULATOR_MEM_DUMP, 'final memory contents to not match')
def sdmmc_read(name): # Create random file with open(SOURCE_BLOCK_DEV, 'wb') as randfile: randfile.write(os.urandom(FILE_SIZE)) test_harness.build_program(['sdmmc_read.c']) test_harness.run_program( environment='emulator' if name.endswith('_emulator') else 'verilator', block_device=SOURCE_BLOCK_DEV, dump_file=MEMDUMP, dump_base=0x200000, dump_length=FILE_SIZE, flush_l2=True) test_harness.assert_files_equal(SOURCE_BLOCK_DEV, MEMDUMP, 'file mismatch')
def sdmmc_read(name, target): # Create random file with open(SOURCE_BLOCK_DEV, 'wb') as randfile: randfile.write(os.urandom(FILE_SIZE)) test_harness.build_program(['sdmmc_read.c']) test_harness.run_program( target=target, block_device=SOURCE_BLOCK_DEV, dump_file=MEMDUMP, dump_base=0x200000, dump_length=FILE_SIZE, flush_l2=True) test_harness.assert_files_equal(SOURCE_BLOCK_DEV, MEMDUMP, 'file mismatch')
def test_verilator(name): test_harness.run_verilator(block_device=SOURCE_BLOCK_DEV, dump_file=VERILATOR_OUTPUT, dump_base=0x200000, dump_length=FILE_SIZE, extra_args=['+autoflushl2=1']) test_harness.assert_files_equal(SOURCE_BLOCK_DEV, VERILATOR_OUTPUT, 'file mismatch')
def test_emulator(name): test_harness.run_emulator(block_device=SOURCE_BLOCK_DEV, dump_file=EMULATOR_OUTPUT, dump_base=0x200000, dump_length=FILE_SIZE) test_harness.assert_files_equal(SOURCE_BLOCK_DEV, EMULATOR_OUTPUT, 'file mismatch')
def files_not_equal(_, target): test_harness.assert_files_equal('compare_file1', 'compare_file2')
FILE_SIZE = 8192 SOURCE_BLOCK_DEV = "obj/bdevimage.bin" EMULATOR_OUTPUT = "obj/emumem.bin" VERILATOR_OUTPUT = "obj/verimem.bin" test_harness.compile_test("sdmmc.c") # Create random file with open(SOURCE_BLOCK_DEV, "wb") as f: f.write(os.urandom(FILE_SIZE)) print "testing in emulator" test_harness.run_emulator( block_device=SOURCE_BLOCK_DEV, dump_file=EMULATOR_OUTPUT, dump_base=0x200000, dump_length=FILE_SIZE ) if not test_harness.assert_files_equal(SOURCE_BLOCK_DEV, EMULATOR_OUTPUT): print "FAIL: simulator final memory contents do not match" sys.exit(1) print "testing in verilator" test_harness.run_verilator( block_device=SOURCE_BLOCK_DEV, dump_file=VERILATOR_OUTPUT, dump_base=0x200000, dump_length=FILE_SIZE, extra_args=["+autoflushl2=1"], ) if not test_harness.assert_files_equal(SOURCE_BLOCK_DEV, VERILATOR_OUTPUT): print "FAIL: verilator final memory contents do not match" sys.exit(1)
def files_not_equal(*unused): test_harness.assert_files_equal('compare_file1', 'compare_file2')
emulator_args = [ '../../bin/emulator', '-m', 'cosim', '-d', 'obj/mmem.bin,0x800000,0x400000' ] if 'EMULATOR_DEBUG_ARGS' in os.environ: emulator_args += [ os.environ['EMULATOR_DEBUG_ARGS'] ] for source_file in files: print 'testing ' + source_file, hexfile = test_harness.assemble_test(source_file) p1 = subprocess.Popen(verilator_args + [ '+bin=' + hexfile ], stdout=subprocess.PIPE) p2 = subprocess.Popen(emulator_args + [ hexfile ], stdin=p1.stdout, stdout=subprocess.PIPE) p1.stdout.close() # Allow P1 to receive SIGPIPE if p2 exits while True: got = p2.stdout.read(0x1000) if not got: break print got if not test_harness.assert_files_equal(VERILATOR_MEM_DUMP, EMULATOR_MEM_DUMP): print "FAIL: simulator final memory contents do not match" sys.exit(1) else: print 'PASS'