Example #1
0
    with open(DRIVER_PATH, 'w') as output_file:
        output_file.write(DRIVER_SRC.replace('$MODULE$', modulename))

    make_args = [
        'make', 'CXXFLAGS=-Wno-parentheses-equality', '-C',
        test_harness.WORK_DIR, '-f', 'V' + modulename + '.mk', 'V' + modulename
    ]

    try:
        subprocess.check_output(make_args, stderr=subprocess.STDOUT)
    except subprocess.CalledProcessError as exc:
        raise test_harness.TestException('Build failed:\n' +
                                         exc.output.decode())

    model_args = [os.path.join(test_harness.WORK_DIR, 'V' + modulename)]

    try:
        result = test_harness.run_test_with_timeout(model_args, 60)
    except subprocess.CalledProcessError as exc:
        raise test_harness.TestException('Build failed:\n' +
                                         exc.output.decode())

    if 'PASS' not in result:
        raise test_harness.TestException('test failed:\n' + result)


test_harness.register_tests(run_unit_test,
                            test_harness.find_files(('.sv', '.v')),
                            ['verilator'])
test_harness.execute_tests()
Example #2
0
#

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')

test_harness.register_tests(test_emulator, ['sdmmc_emulator'])
test_harness.register_tests(test_verilator, ['sdmmc_verilator'])
test_harness.execute_tests()

Example #3
0
    make_args = [
        'make',
        'CXXFLAGS=-Wno-parentheses-equality',
        '-C', 'obj/',
        '-f', 'V' + modulename + '.mk',
        'V' + modulename
    ]

    try:
        subprocess.check_output(make_args, stderr=subprocess.STDOUT)
    except subprocess.CalledProcessError as exc:
        raise test_harness.TestException(
            'Build failed:\n' + exc.output.decode())

    model_args = [
        'obj/V' + modulename
    ]

    try:
        result = test_harness.run_test_with_timeout(model_args, 60)
    except subprocess.CalledProcessError as exc:
        raise test_harness.TestException(
            'Build failed:\n' + exc.output.decode())

    if 'PASS' not in result:
        raise test_harness.TestException('test failed:\n' + result)

test_harness.register_tests(run_unit_test,
                            test_harness.find_files(('.sv', '.v')), ['verilator'])
test_harness.execute_tests()
Example #4
0
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')

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')

test_harness.register_tests(test_emulator, ['sdmmc (emulator)'])
test_harness.register_tests(test_verilator, ['sdmmc (verilator)'])
test_harness.execute_tests()

Example #5
0
# 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

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')
	
test_harness.register_tests(dinvalidate_test, ['dinvalidate'])
test_harness.execute_tests()


Example #6
0
    will print 'PASS' if it is successful.
    """

    test_harness.build_program(['fs.c'])
    subprocess.check_output([
        os.path.join(test_harness.BIN_DIR, 'mkfs'), FS_IMAGE_PATH, 'fstest.txt'
    ],
                            stderr=subprocess.STDOUT)
    result = test_harness.run_program(target=target,
                                      block_device=FS_IMAGE_PATH)
    if 'PASS' not in result or 'FAIL' in result:
        raise test_harness.TestException(
            'test program did not indicate pass\n' + result)


def run_test(source_file, target):
    test_harness.build_program([source_file])
    result = test_harness.run_program(target)
    test_harness.check_result(source_file, result)


# hack: register all source files in this directory except for fs test,
# which has special handling.
test_list = [
    fname for fname in test_harness.find_files(('.c', '.cpp'))
    if not fname.startswith('_')
]
test_list.remove('fs.c')
test_harness.register_tests(run_test, test_list, ['emulator', 'fpga'])
test_harness.execute_tests()
Example #7
0
import test_harness

BASE_ADDRESS = 0x400000


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


test_harness.register_tests(dflush_test, ['dflush'])
test_harness.execute_tests()
Example #8
0
#
# 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


def run_emulator_test(source_file):
    test_harness.build_program([source_file])
    result = test_harness.run_program(environment='emulator')
    test_harness.check_result(source_file, result)


test_harness.register_tests(run_emulator_test, ['compiler-rt.c'])
test_harness.execute_tests()
Example #9
0
# See the License for the specific language governing permissions and
# limitations under the License.
#

import sys
import struct

# Test load_sync/store_sync instructions by having four threads update
# variables round-robin.

sys.path.insert(0, '../..')
import test_harness

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))

test_harness.register_tests(atomic_test, ['atomic'])
test_harness.execute_tests()
Example #10
0
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')

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')

test_harness.register_tests(test_emulator, ['ps2 (emulator)'])
test_harness.register_tests(test_verilator, ['ps2 (verilator)'])
test_harness.execute_tests()

Example #11
0
import sys
import struct

sys.path.insert(0, '../..')
import test_harness


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')


test_harness.register_tests(dinvalidate_test, ['dinvalidate'])
test_harness.execute_tests()
Example #12
0
import subprocess

sys.path.insert(0, '../..')
import test_harness


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)


tests = ['creg_non_supervisor', 'eret_non_supervisor', 'syscall']

for name in tests:
    test_harness.register_tests(run_test, [name + '_verilator'])
    test_harness.register_tests(run_test, [name + '_emulator'])

test_harness.execute_tests()
Example #13
0
sys.path.insert(0, '../..')
import test_harness


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 verilator_crash(name):
    test_harness.compile_test('crash.c')
    try:
        result = test_harness.run_verilator()
        raise TestException('Did not catch crash')
    except:
        pass


test_harness.register_tests(emulator_crash, ['crash (emulator)'])
test_harness.register_tests(verilator_crash, ['crash (verilator)'])
test_harness.execute_tests()
Example #14
0
    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 register_generic_test(name):
    test_harness.register_tests(run_generic_test, [name + '_verilator'])
    test_harness.register_tests(run_generic_test, [name + '_emulator'])


test_harness.register_tests(test_alias_verilator, ['alias_verilator'])
test_harness.register_tests(test_alias_emulator, ['alias_emulator'])
test_harness.register_tests(test_fill_verilator, ['fill_verilator'])
test_harness.register_tests(test_fill_emulator, ['fill_emulator'])
test_harness.register_tests(test_io_map_verilator, ['io_map_verilator'])
test_harness.register_tests(test_io_map_emulator, ['io_map_emulator'])
register_generic_test('dflush_tlb_miss')
register_generic_test('dinvalidate_tlb_miss')
register_generic_test('duplicate_tlb_insert')
register_generic_test('write_fault')
register_generic_test('data_supervisor_fault_read')
register_generic_test('data_supervisor_fault_write')
register_generic_test('instruction_supervisor_fault')
register_generic_test('tlb_invalidate')
register_generic_test('tlb_invalidate_all')
register_generic_test('asid')
Example #15
0
sys.path.insert(0, '..')
import test_harness


def run_compiler_test(source_file, target):
    if target == 'host':
        subprocess.check_call(['cc', source_file, '-o', 'obj/a.out'],
                              stderr=subprocess.STDOUT)
        result = subprocess.check_output('obj/a.out')
        test_harness.check_result(source_file, result.decode())
    else:
        test_harness.build_program([source_file])
        result = test_harness.run_program(target)
        test_harness.check_result(source_file, result)


test_list = [
    fname for fname in test_harness.find_files(('.c', '.cpp'))
    if not fname.startswith('_')
]

all_targets = [fname for fname in test_list if 'noverilator' not in fname]
test_harness.register_tests(run_compiler_test, all_targets,
                            ['emulator', 'verilator', 'host', 'fpga'])

noverilator_targets = [fname for fname in test_list if 'noverilator' in fname]
test_harness.register_tests(run_compiler_test, noverilator_targets,
                            ['emulator', 'host', 'fpga'])

test_harness.execute_tests()
Example #16
0
sys.path.insert(0, '../..')
import test_harness

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)

tests = [
	'creg_non_supervisor',
	'eret_non_supervisor',
	'syscall'
]

for name in tests:
	test_harness.register_tests(run_test, [name + '_verilator'])
	test_harness.register_tests(run_test, [name + '_emulator'])

test_harness.execute_tests()
Example #17
0
# 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

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

test_harness.register_tests(dflush_test, ['dflush'])
test_harness.execute_tests()
Example #18
0
# 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


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')


test_harness.register_tests(fs_test, ['fs'])
test_harness.execute_tests()
Example #19
0
# 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

# Test PS/2 keyboard peripheral

sys.path.insert(0, '../..')
import test_harness

def ps2_test(name):
	test_harness.compile_test('ps2.c')
	result = test_harness.run_verilator()
	if result.find('PASS') == -1:
		raise test_harness.TestException('program did not indicate pass\n' + result)

test_harness.register_tests(ps2_test, ['ps2'])
test_harness.execute_tests()
Example #20
0
# Copyright 2016 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


def run_kernel_test(source_file, target):
    test_harness.build_program([source_file], image_type='user')
    result = test_harness.run_kernel(target=target, timeout=240)
    test_harness.check_result(source_file, result)

test_list = test_harness.find_files(('.c', '.cpp'))
test_harness.register_tests(run_kernel_test, test_list, [
    'emulator', 'verilator', 'fpga'])
test_harness.execute_tests()
Example #21
0
# 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


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')


test_harness.register_tests(test_uart, ['uart'])
test_harness.execute_tests()
Example #22
0
# 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

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')

test_harness.register_tests(fs_test, ['fs'])
test_harness.execute_tests()
Example #23
0
#
# 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

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)

test_harness.register_tests(perf_counters_test, ['perf_counters'])
test_harness.execute_tests()
Example #24
0
	return True
	
use_verilator = 'USE_VERILATOR' in os.environ

def run_verilator_test(source_file):
	test_harness.compile_test(source_file, optlevel='3')
	result = test_harness.run_verilator()
	check_result(source_file, result)
	
def run_host_test(source_file):
	subprocess.check_call(['c++', '-w', source_file, '-o', 'obj/a.out'])
	result = subprocess.check_output('obj/a.out')
	check_result(source_file, result)

def run_emulator_test(source_file):
	test_harness.compile_test(source_file, optlevel='3')
	result = test_harness.run_emulator()
	check_result(source_file, result)

test_list = [fname for fname in test_harness.find_files(('.c', '.cpp')) if not fname.startswith('_')]

if 'USE_VERILATOR' in os.environ:
	test_list = [fname for fname in test_list if fname.find('noverilator') == -1]
	test_harness.register_tests(run_verilator_test, test_list)
elif 'USE_HOSTCC' in os.environ:
	test_harness.register_tests(run_host_test, test_list)
else:
	test_harness.register_tests(run_emulator_test, test_list)

test_harness.execute_tests()
Example #25
0
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')


test_harness.register_tests(test_emulator, ['sdmmc (emulator)'])
test_harness.register_tests(test_verilator, ['sdmmc (verilator)'])
test_harness.execute_tests()
Example #26
0
    result = test_harness.run_program(environment='verilator')
    test_harness.check_result(source_file, result)


def run_host_test(source_file):
    subprocess.check_call(['c++', '-w', source_file, '-o', 'obj/a.out'])
    result = subprocess.check_output('obj/a.out')
    test_harness.check_result(source_file, result)


def run_emulator_test(source_file):
    test_harness.build_program([source_file])
    result = test_harness.run_program(environment='emulator')
    test_harness.check_result(source_file, result)


test_list = [
    fname for fname in test_harness.find_files(('.c', '.cpp'))
    if not fname.startswith('_')
]

if 'USE_VERILATOR' in os.environ:
    test_list = [fname for fname in test_list if 'noverilator' not in fname]
    test_harness.register_tests(run_verilator_test, test_list)
elif 'USE_HOSTCC' in os.environ:
    test_harness.register_tests(run_host_test, test_list)
else:
    test_harness.register_tests(run_emulator_test, test_list)

test_harness.execute_tests()
Example #27
0
import subprocess
import sys

sys.path.insert(0, '..')
import test_harness


def run_compiler_test(source_file, target):
    if target == 'host':
        subprocess.check_call(['cc', source_file, '-o', 'obj/a.out'],
                              stderr=subprocess.STDOUT)
        result = subprocess.check_output('obj/a.out')
        test_harness.check_result(source_file, result.decode())
    else:
        test_harness.build_program([source_file])
        result = test_harness.run_program(target)
        test_harness.check_result(source_file, result)

test_list = [fname for fname in test_harness.find_files(
    ('.c', '.cpp')) if not fname.startswith('_')]

all_targets = [fname for fname in test_list if 'noverilator' not in fname]
test_harness.register_tests(run_compiler_test, all_targets, [
                            'emulator', 'verilator', 'host', 'fpga'])

noverilator_targets = [fname for fname in test_list if 'noverilator' in fname]
test_harness.register_tests(
    run_compiler_test, noverilator_targets, ['emulator', 'host', 'fpga'])

test_harness.execute_tests()
Example #28
0
#!/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

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')

test_harness.register_tests(test_uart, ['uart'])
test_harness.execute_tests()
Example #29
0
		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 register_generic_test(name):
	test_harness.register_tests(run_generic_test, [name + '_verilator'])
	test_harness.register_tests(run_generic_test, [name + '_emulator'])

test_harness.register_tests(test_alias_verilator, ['alias_verilator'])
test_harness.register_tests(test_alias_emulator, ['alias_emulator'])
test_harness.register_tests(test_fill_verilator, ['fill_verilator'])
test_harness.register_tests(test_fill_emulator, ['fill_emulator'])
test_harness.register_tests(test_io_map_verilator, ['io_map_verilator'])
test_harness.register_tests(test_io_map_emulator, ['io_map_emulator'])
register_generic_test('dflush_tlb_miss')
register_generic_test('dinvalidate_tlb_miss')
register_generic_test('duplicate_tlb_insert')
register_generic_test('write_fault')
register_generic_test('data_supervisor_fault_read')
register_generic_test('data_supervisor_fault_write')
register_generic_test('instruction_supervisor_fault')
register_generic_test('tlb_invalidate')
register_generic_test('tlb_invalidate_all')
register_generic_test('asid')
Example #30
0
    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')


test_harness.register_tests(run_cosimulation_test,
                            test_harness.find_files(('.s', '.S')),
                            ['verilator'])

test_harness.execute_tests()
Example #31
0
def register_generic_test(name):
	test_harness.register_tests(run_generic_test, [name + '_verilator'])
	test_harness.register_tests(run_generic_test, [name + '_emulator'])
Example #32
0
def register_generic_test(name):
    test_harness.register_tests(run_generic_test, [name + '_verilator'])
    test_harness.register_tests(run_generic_test, [name + '_emulator'])
Example #33
0
import sys
import os

sys.path.insert(0, '../..')
import test_harness

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 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

test_harness.register_tests(emulator_crash, ['crash_emulator'])
test_harness.register_tests(verilator_crash, ['crash_verilator'])
test_harness.execute_tests()

Example #34
0
#!/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


def run_emulator_test(source_file):
    test_harness.build_program([source_file])
    result = test_harness.run_program(environment='emulator')
    test_harness.check_result(source_file, result)

test_harness.register_tests(run_emulator_test, ['compiler-rt.c'])
test_harness.execute_tests()
Example #35
0
    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')

test_harness.register_tests(run_cosimulation_test,
                            test_harness.find_files(('.s', '.S')), ['verilator'])

test_harness.execute_tests()
Example #36
0
# limitations under the License.
#

import sys
import struct

sys.path.insert(0, '../..')
import test_harness


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))


test_harness.register_tests(atomic_test, ['atomic'])
test_harness.execute_tests()
Example #37
0
#!/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

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')

test_harness.register_tests(ps2_test, ['ps2'])
test_harness.execute_tests()