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 atomic_test(name): test_harness.compile_test('atomic.c') test_harness.run_verilator(dump_file='obj/vmem.bin', dump_base=0x100000, dump_length=0x800, extra_args=['+autoflushl2=1']) with open('obj/vmem.bin', 'rb') as f: while True: val = f.read(4) if len(val) == 0: break numVal = struct.unpack('<L', val)[0] if numVal != 10: raise test_harness.TestException('FAIL: mismatch: ' + str(numVal))
def atomic_test(name): test_harness.compile_test('atomic.c') test_harness.run_verilator(dump_file='obj/vmem.bin', dump_base=0x100000, dump_length=0x800, extra_args=['+autoflushl2=1']) with open('obj/vmem.bin', 'rb') as f: while True: val = f.read(4) if val == '': break numVal = ord(val[0]) | (ord(val[1]) << 8) | (ord(val[2]) << 16) | (ord(val[3]) << 24) if numVal != 10: raise TestException('FAIL: mismatch: ' + str(numVal))
def verilator_crash(name): test_harness.compile_test('crash.c') try: result = test_harness.run_verilator() raise TestException('Did not catch crash') except: pass
def atomic_test(name): test_harness.compile_test('atomic.c') test_harness.run_verilator(dump_file='obj/vmem.bin', dump_base=0x100000, dump_length=0x800, extra_args=['+autoflushl2=1']) with open('obj/vmem.bin', 'rb') as f: while True: val = f.read(4) if len(val) == 0: break numVal = struct.unpack('<L', val)[0] if numVal != 10: raise TestException('FAIL: mismatch: ' + str(numVal))
def verilator_crash(name): test_harness.compile_test('crash.c') try: result = test_harness.run_verilator() raise test_harness.TestException('Did not catch crash') except: pass
def dflush_test(name): test_harness.compile_test('dflush.c') test_harness.run_verilator(dump_file='obj/vmem.bin', dump_base=BASE_ADDRESS, dump_length=0x40000) with open('obj/vmem.bin', 'rb') as f: index = 0 while True: val = f.read(4) if val == '': break numVal = ord(val[0]) | (ord(val[1]) << 8) | (ord(val[2]) << 16) | (ord(val[3]) << 24) expected = 0x1f0e6231 + (index / 16) if numVal != expected: raise TestException('FAIL: mismatch at' + hex(BASE_ADDRESS + (index * 4)) + 'want' + str(expected) + 'got' + str(numVal)) index += 1
def test_alias_verilator(name): test_harness.compile_test(['alias.c', 'identity_tlb_miss_handler.s']) result = test_harness.run_verilator(dump_file=DUMP_FILE, dump_base=0x100000, dump_length=32) if result.find('read 00900000 "Test String"') == -1: raise test_harness.TestException('did not get correct read string:\n' + result) with open(DUMP_FILE, 'rb') as f: if f.read(len(EXPECT_STRING)) != EXPECT_STRING: raise test_harness.TestException('memory contents did not match')
def dflush_test(name): test_harness.compile_test('dflush.c') test_harness.run_verilator(dump_file='obj/vmem.bin', dump_base=BASE_ADDRESS, dump_length=0x40000) with open('obj/vmem.bin', 'rb') as f: index = 0 while True: val = f.read(4) if len(val): break numVal = ord(val[0]) | (ord(val[1]) << 8) | (ord(val[2]) << 16) | ( ord(val[3]) << 24) expected = 0x1f0e6231 + (index // 16) if numVal != expected: raise TestException('FAIL: mismatch at' + hex(BASE_ADDRESS + (index * 4)) + 'want' + str(expected) + 'got' + str(numVal)) index += 1
def test_io_map_verilator(name): test_harness.compile_test(['io_map.c']) result = test_harness.run_verilator(dump_file=DUMP_FILE, dump_base=0x100000, dump_length=32) # Check value printed via virtual serial port if result.find('jabberwocky') == -1: raise test_harness.TestException('did not get correct read string:\n' + result) # Check value written to memory with open(DUMP_FILE, 'rb') as f: if f.read(len('galumphing')) != bytearray('galumphing', 'ascii'): raise test_harness.TestException('memory contents did not match')
def dinvalidate_test(name): test_harness.assemble_test('dinvalidate.s') result = test_harness.run_verilator(dump_file='obj/vmem.bin', dump_base=0x100, dump_length=4, extra_args=['+trace=1', '+autoflushl2=1']) # 1. Check that the proper value was read into s2 if result.find('02 deadbeef') == -1: raise TestException('incorrect value was written back ' + result) # 2. Read the memory dump to ensure the proper value is flushed from the L2 cache with open('obj/vmem.bin', 'rb') as f: val = f.read(4) if ord(val[0]) != 0xef or ord(val[1]) != 0xbe or ord(val[2]) != 0xad or ord(val[3]) != 0xde: raise TestException('memory contents were incorrect')
def run_test(name): if name.endswith('_emulator'): basename = name[0:-len('_emulator')] isverilator = False elif name.endswith('_verilator'): basename = name[0:-len('_verilator')] isverilator = True test_harness.compile_test([basename + '.c']) if isverilator: result = test_harness.run_verilator() else: result = test_harness.run_emulator() test_harness.check_result(basename + '.c', result)
def run_generic_test(name): if name.endswith('_emulator'): basename = name[0:-len('_emulator')] isverilator = False elif name.endswith('_verilator'): basename = name[0:-len('_verilator')] isverilator = True test_harness.compile_test([basename + '.c']) if isverilator: result = test_harness.run_verilator() else: result = test_harness.run_emulator() test_harness.check_result(basename + '.c', result)
def dinvalidate_test(name): test_harness.assemble_test('dinvalidate.s') result = test_harness.run_verilator(dump_file='obj/vmem.bin', dump_base=0x100, dump_length=4, extra_args=['+trace=1', '+autoflushl2=1']) # 1. Check that the proper value was read into s2 if result.find('02 deadbeef') == -1: raise TestException('incorrect value was written back ' + result) # 2. Read the memory dump to ensure the proper value is flushed from the L2 cache with open('obj/vmem.bin', 'rb') as f: numVal = struct.unpack('<L', f.read(4))[0] if numVal != 0xdeadbeef: print(hex(numVal)) raise test_harness.TestException('memory contents were incorrect')
def dinvalidate_test(name): test_harness.assemble_test('dinvalidate.s') result = test_harness.run_verilator( dump_file='obj/vmem.bin', dump_base=0x100, dump_length=4, extra_args=['+trace=1', '+autoflushl2=1']) # 1. Check that the proper value was read into s2 if result.find('02 deadbeef') == -1: raise TestException('incorrect value was written back ' + result) # 2. Read the memory dump to ensure the proper value is flushed from the L2 cache with open('obj/vmem.bin', 'rb') as f: numVal = struct.unpack('<L', f.read(4))[0] if numVal != 0xdeadbeef: print(hex(numVal)) raise test_harness.TestException('memory contents were incorrect')
def test_uart(name): test_harness.compile_test('uart.c') result = test_harness.run_verilator() if result.find('PASS') == -1: raise TestException('test did not indicate pass')
def test_fill_verilator(name): test_harness.compile_test(['fill_test.c', 'wrap_tlb_miss_handler.s']) result = test_harness.run_verilator() if result.find('FAIL') != -1 or result.find('PASS') == -1: raise test_harness.TestException(result + '\ntest did not signal pass')
# http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # import sys sys.path.insert(0, '../..') import test_harness test_harness.compile_test('atomic.c') test_harness.run_verilator(dump_file='obj/vmem.bin', dump_base=0x100000, dump_length=0x800, extra_args=['+autoflushl2=1']) with open('obj/vmem.bin', 'rb') as f: while True: val = f.read(4) if val == '': break numVal = ord(val[0]) | (ord(val[1]) << 8) | (ord(val[2]) << 16) | (ord(val[3]) << 24) if numVal != 10: print 'FAIL: mismatch: ', numVal sys.exit(1) print 'PASS'
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) print "PASS"
def run_verilator_test(source_file): test_harness.compile_test(source_file, optlevel='3') result = test_harness.run_verilator() check_result(source_file, result)
# # # This test writes a pattern to memory and manually flushes it from code. It then # checks the contents of system memory to ensure the data was flushed correctly. # import sys sys.path.insert(0, '../..') import test_harness BASE_ADDRESS=0x400000 test_harness.compile_test('dflush.c') test_harness.run_verilator(dump_file='obj/vmem.bin', dump_base=BASE_ADDRESS, dump_length=0x40000) with open('obj/vmem.bin', 'rb') as f: index = 0 while True: val = f.read(4) if val == '': break numVal = ord(val[0]) | (ord(val[1]) << 8) | (ord(val[2]) << 16) | (ord(val[3]) << 24) expected = 0x1f0e6231 + (index / 16) if numVal != expected: print 'FAIL: mismatch at', hex(BASE_ADDRESS + (index * 4)), 'want', expected, 'got', numVal sys.exit(1) index += 1
# http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # import sys sys.path.insert(0, '../..') import test_harness test_harness.assemble_test('dinvalidate.s') result = test_harness.run_verilator(dump_file='obj/vmem.bin', dump_base=0x100, dump_length=4, extra_args=['+regtrace=1', '+autoflushl2=1']) # 1. Check that the proper value was read into s2 if result.find('02 deadbeef') == -1: print 'incorrect value was written back' sys.exit(1) # 2. Read the memory dump to ensure the proper value is flushed from the L2 cache with open('obj/vmem.bin', 'rb') as f: val = f.read(4) if ord(val[0]) != 0xef or ord(val[1]) != 0xbe or ord(val[2]) != 0xad or ord(val[3]) != 0xde: print 'FAIL: memory contents were incorrect' sys.exit(1) print 'PASS'
def test_fill_verilator(name): test_harness.compile_test(['fill_test.c', 'wrap_tlb_miss_handler.s']) result = test_harness.run_verilator() if result.find('FAIL') != -1 or result.find('PASS') == -1: raise test_harness.TestException(result + '\ntest did not signal pass\n' + result)
def ps2_test(name): test_harness.compile_test('ps2.c') result = test_harness.run_verilator() if result.find('PASS') == -1: raise Exception('program did not indicate pass')
def perf_counters_test(name): test_harness.compile_test('perf_counters.c') result = test_harness.run_verilator() if result.find('PASS') == -1: raise test_harness.TestException('test program did not indicate pass\n' + result)
def run_verilator_test(source_file): test_harness.compile_test(source_file, optlevel='3') result = test_harness.run_verilator() test_harness.check_result(source_file, result)
#!/usr/bin/env python # # Copyright 2011-2015 Jeff Bush # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # import sys sys.path.insert(0, '../..') import test_harness test_harness.compile_test('ps2.c') result = test_harness.run_verilator() if result.find('PASS') == -1: print 'FAIL' sys.exit(1) else: print 'PASS'