Пример #1
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()
Пример #2
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()
Пример #3
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()
Пример #4
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()
Пример #5
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()
Пример #6
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()
Пример #7
0
#!/usr/bin/env python3
#
# 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.register_generic_test(
    test_harness.find_files(('.c')), ['emulator'])
test_harness.execute_tests()
Пример #8
0
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')

test_harness.register_tests(run_cosimulation_test, test_harness.find_files(('.s', '.S')))

test_harness.execute_tests()
Пример #9
0
    """Test the filesystem implementation in libos.

    This creates a filesystem image with the test file fstest.txt
    in it, the compiles the program fs.c to perform operations on it. The program
    will print 'PASS' if it is successful.
    """

    test_harness.build_program(['fs.c'])
    subprocess.check_output(
        [test_harness.BIN_DIR + 'mkfs', test_harness.WORK_DIR + '/fsimage.bin',
         'fstest.txt'], stderr=subprocess.STDOUT)
    result = test_harness.run_program(target=target,
                                      block_device=test_harness.WORK_DIR + '/fsimage.bin')
    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()
Пример #10
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.
#

"""Tests for the compiler-rt (compiler runtime) library.

This library is built as part of the LLVM toolchain and contains compiler
specific built-in functions.
"""

import sys

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

test_harness.register_generic_test(
    test_harness.find_files(('.c')), ['emulator'])
test_harness.execute_tests()
Пример #11
0
#!/usr/bin/env python3
#
# 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.register_generic_test(test_harness.find_files(('.c')),
                                   ['emulator'])
test_harness.execute_tests()
Пример #12
0
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)


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.compile_test(source_file, optlevel="3")
    result = test_harness.run_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 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()
Пример #13
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 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:
        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')))

test_harness.execute_tests()
Пример #14
0
#!/usr/bin/env python3
#
# 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

# XXX need test to dump memory contents and ensure they are written out
# properly

test_harness.register_generic_assembly_tests(
    test_harness.find_files(('.s', '.S')), ['emulator', 'verilator', 'fpga'])
test_harness.execute_tests()