From: Gabe Black Date: Fri, 23 Oct 2020 03:00:45 +0000 (-0700) Subject: util: Teach the m5 utility's scons how to run unit tests. X-Git-Tag: develop-gem5-snapshot~398 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=77869b05b8c03a05b4bc3539daaa32d754ffa8a3;p=gem5.git 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 Tested-by: kokoro Reviewed-by: Bobby R. Bruce --- diff --git a/util/m5/SConstruct b/util/m5/SConstruct index bbae8d9bb..e1d7e1dfd 100644 --- a/util/m5/SConstruct +++ b/util/m5/SConstruct @@ -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}')) diff --git a/util/m5/src/abi/aarch64/SConsopts b/util/m5/src/abi/aarch64/SConsopts index 010b22ec7..f55b1a147 100644 --- a/util/m5/src/abi/aarch64/SConsopts +++ b/util/m5/src/abi/aarch64/SConsopts @@ -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') diff --git a/util/m5/src/abi/arm/SConsopts b/util/m5/src/abi/arm/SConsopts index 4988b7164..49762ad49 100644 --- a/util/m5/src/abi/arm/SConsopts +++ b/util/m5/src/abi/arm/SConsopts @@ -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) diff --git a/util/m5/src/abi/sparc/SConsopts b/util/m5/src/abi/sparc/SConsopts index 5f35848ad..ccadbe60b 100644 --- a/util/m5/src/abi/sparc/SConsopts +++ b/util/m5/src/abi/sparc/SConsopts @@ -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) diff --git a/util/m5/src/abi/thumb/SConsopts b/util/m5/src/abi/thumb/SConsopts index f8956e3be..b4226347a 100644 --- a/util/m5/src/abi/thumb/SConsopts +++ b/util/m5/src/abi/thumb/SConsopts @@ -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) diff --git a/util/m5/src/abi/x86/SConsopts b/util/m5/src/abi/x86/SConsopts index 5c41ea7d2..1be526b81 100644 --- a/util/m5/src/abi/x86/SConsopts +++ b/util/m5/src/abi/x86/SConsopts @@ -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')