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 verilator_crash(name): test_harness.compile_test('crash.c') try: result = test_harness.run_verilator() raise TestException('Did not catch crash') except: pass
def fs_test(name): test_harness.compile_test('fs.c') subprocess.check_output( ['../../../bin/mkfs', 'obj/fsimage.bin', 'test.txt'], stderr=subprocess.STDOUT) result = test_harness.run_emulator(block_device='obj/fsimage.bin') if result.find('PASS') == -1: raise TestException('test program did not indicate pass')
def test_alias_emulator(name): test_harness.compile_test(['alias.c', 'identity_tlb_miss_handler.s']) result = test_harness.run_emulator(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 emulator_crash(name): test_harness.compile_test('crash.c') try: result = test_harness.run_emulator() # The test program deliberately crashes. If the harness doesn't throw # an exception, that is a failure. raise test_harness.TestException('Did not catch crash') except: # ...and vice versa pass
def emulator_crash(name): test_harness.compile_test('crash.c') try: result = test_harness.run_emulator() # The test program deliberately crashes. If the harness doesn't throw # an exception, that is a failure. raise TestException('Did not catch crash') except: # ...and vice versa pass
def test_io_map_emulator(name): test_harness.compile_test(['io_map.c']) result = test_harness.run_emulator(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 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 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 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 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 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 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
# # 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'
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')
import sys import os # # Test reading blocks from SDMMC device # sys.path.insert(0, '../..') import test_harness 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)) 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 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 run_emulator_test(source_file): test_harness.compile_test(source_file, optlevel='3') result = test_harness.run_emulator() check_result(source_file, result)
# See the License for the specific language governing permissions and # limitations under the License. # import sys import os sys.path.insert(0, "../..") import test_harness 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(
# # 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 import subprocess sys.path.insert(0, '../..') import test_harness test_harness.compile_test('fs.c') subprocess.check_call(['../../../bin/mkfs', 'obj/fsimage.bin', 'test.txt']) result = test_harness.run_emulator(block_device='obj/fsimage.bin') if result.find('PASS') == -1: print 'FAIL' sys.exit(1) else: print 'PASS'
# See the License for the specific language governing permissions and # limitations under the License. # import sys import os sys.path.insert(0, '../..') import test_harness 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)) 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')
# limitations under the License. # # # 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
#!/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'
def test_fill_emulator(name): test_harness.compile_test(['fill_test.c', 'wrap_tlb_miss_handler.s']) result = test_harness.run_emulator() 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 test_fill_emulator(name): test_harness.compile_test(['fill_test.c', 'wrap_tlb_miss_handler.s']) result = test_harness.run_emulator() if result.find('FAIL') != -1 or result.find('PASS') == -1: raise test_harness.TestException(result + '\ntest did not signal pass')
def fs_test(name): test_harness.compile_test('fs.c') subprocess.check_output(['../../../bin/mkfs', 'obj/fsimage.bin', 'test.txt'], stderr=subprocess.STDOUT) result = test_harness.run_emulator(block_device='obj/fsimage.bin') if result.find('PASS') == -1: raise TestException('test program did not indicate pass')
def run_emulator_test(source_file): test_harness.compile_test(source_file, optlevel='3') result = test_harness.run_emulator() test_harness.check_result(source_file, result)
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)
print 'FAIL' else: print 'PASS' except KeyboardInterrupt: sys.exit(1) except: print 'FAIL' failing_tests += 1 elif 'USE_VERILATOR' in os.environ: for source_file in files: if source_file.find('noverilator') != -1: continue print 'Testing ' + source_file + ' (verilator)', try: test_harness.compile_test(source_file) result = test_harness.run_verilator() if not check_result(source_file, result): failing_tests += 1 print 'FAIL' else: print 'PASS' except KeyboardInterrupt: sys.exit(1) except: print 'FAIL' failing_tests += 1 else: # Emulator for source_file in files: for optlevel in ['s', '0', '3']:
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)