util: Teach the m5 utility's scons how to run unit tests.
This may be directly in the case of native tests, or through a user level QEMU binary for non-native tests. scons is smart enough to expect to be able to run native tests always, and non-native tests only if a qemu binary has been found. To tell scons to run tests in a particular category, you can use a command of this form: scons build/[category]/test/ where category is either an "abi" like sparc or x86, or "native" for tests which don't do anything target specific and so can be run on the host. There will be two directories under .../tests, "bin" and "result". "bin" is where the test binaries themselves will be built, and "result" is for the results of running those binaries. Change-Id: I6450ab4a97169f8a01292d946bfac18008b0430c Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/27752 Maintainer: Jason Lowe-Power <power.jg@gmail.com> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Bobby R. Bruce <bbruce@ucdavis.edu>
This commit is contained in:
@@ -70,7 +70,21 @@ def GTest(env, name, *srcs, **kwargs):
|
||||
|
||||
if not srcs:
|
||||
srcs = [ name + '.cc', name + '.test.cc' ]
|
||||
env['GTEST_ENV'].Program('test/%s' % name, srcs, **kwargs)
|
||||
test_bin = env['GTEST_ENV'].Program('test/bin/%s' % name, srcs, **kwargs)
|
||||
|
||||
# The native environment doesn't need QEMU, and doesn't define HAVE_QEMU.
|
||||
need_qemu_to_run = 'HAVE_QEMU' in env;
|
||||
|
||||
# If we can run this test...
|
||||
if not need_qemu_to_run or env['HAVE_QEMU']:
|
||||
# An XML file which holds the results of the test.
|
||||
xml = Dir('test').Dir('result').File('%s.xml' % name)
|
||||
# The basic command line for the test.
|
||||
cmd = '${SOURCES[0]} --gtest_output=xml:${TARGETS[0]}'
|
||||
if need_qemu_to_run:
|
||||
# A prefix that runs it in QEMU if necessary.
|
||||
cmd = '${QEMU} -L ${QEMU_SYSROOT} -- ' + cmd
|
||||
AlwaysBuild(env.Command(xml, test_bin, cmd))
|
||||
|
||||
main.AddMethod(GTest)
|
||||
|
||||
@@ -89,6 +103,7 @@ main['CXX'] = '${CROSS_COMPILE}g++'
|
||||
main['AS'] = '${CROSS_COMPILE}as'
|
||||
main['LD'] = '${CROSS_COMPILE}ld'
|
||||
main['AR'] = '${CROSS_COMPILE}ar'
|
||||
main['QEMU'] = 'qemu-${QEMU_ARCH}'
|
||||
|
||||
class CallType(object):
|
||||
def __init__(self, name):
|
||||
@@ -146,6 +161,13 @@ for root, dirs, files in os.walk(abspath(src_dir)):
|
||||
env.SConscript(Dir(root).File('SConsopts'),
|
||||
exports=[ 'env', 'get_abi_opt' ])
|
||||
|
||||
# Check if this version of QEMU is available for running unit tests.
|
||||
env['HAVE_QEMU'] = env.Detect('${QEMU}') is not None
|
||||
if env['HAVE_QEMU'] and env.Detect('${CC}'):
|
||||
sysroot_cmd = env.subst('${CC} -print-sysroot')
|
||||
sysroot = os.popen(sysroot_cmd).read().strip()
|
||||
env['QEMU_SYSROOT'] = sysroot
|
||||
|
||||
# Once all the options have been configured, set up build targets for
|
||||
# this abi.
|
||||
abi_dir = build_dir.Dir(env.subst('${ABI}'))
|
||||
|
||||
@@ -27,6 +27,7 @@ Import('*')
|
||||
|
||||
env['ABI'] = 'aarch64'
|
||||
get_abi_opt('CROSS_COMPILE', 'aarch64-linux-gnu-')
|
||||
get_abi_opt('QEMU_ARCH', 'aarch64')
|
||||
|
||||
env['CALL_TYPE']['inst'].impl('m5op.S', 'verify_inst.cc', default=True)
|
||||
env['CALL_TYPE']['addr'].impl('m5op_addr.S')
|
||||
|
||||
@@ -27,6 +27,7 @@ Import('*')
|
||||
|
||||
env['ABI'] = 'arm'
|
||||
get_abi_opt('CROSS_COMPILE', 'arm-linux-gnueabihf-')
|
||||
get_abi_opt('QEMU_ARCH', 'arm')
|
||||
env.Append(CXXFLAGS=[ '-march=armv7-a', '-mfpu=neon' ])
|
||||
|
||||
env['CALL_TYPE']['inst'].impl('m5op.S', 'verify_inst.cc', default=True)
|
||||
|
||||
@@ -27,6 +27,7 @@ Import('*')
|
||||
|
||||
env['ABI'] = 'sparc'
|
||||
get_abi_opt('CROSS_COMPILE', 'sparc64-linux-gnu-')
|
||||
get_abi_opt('QEMU_ARCH', 'sparc64')
|
||||
env.Append(CXXFLAGS='-m64')
|
||||
|
||||
env['CALL_TYPE']['inst'].impl('m5op.S', 'verify_inst.cc', default=True)
|
||||
|
||||
@@ -27,6 +27,7 @@ Import('*')
|
||||
|
||||
env['ABI'] = 'thumb'
|
||||
get_abi_opt('CROSS_COMPILE', 'arm-linux-gnueabihf-')
|
||||
get_abi_opt('QEMU_ARCH', 'arm')
|
||||
env.Append(CXXFLAGS=[ '-mthumb', '-march=armv7', '-mfpu=neon' ])
|
||||
|
||||
env['CALL_TYPE']['inst'].impl('m5op.S', 'verify_inst.cc', default=True)
|
||||
|
||||
@@ -27,6 +27,7 @@ Import('*')
|
||||
|
||||
env['ABI'] = 'x86'
|
||||
get_abi_opt('CROSS_COMPILE', '')
|
||||
get_abi_opt('QEMU_ARCH', 'x86_64')
|
||||
env.Append(CXXFLAGS='-DM5OP_ADDR=0xFFFF0000')
|
||||
env.Append(CCFLAGS='-DM5OP_ADDR=0xFFFF0000')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user