From 7b99c45ac222ed5d0b32163f1ca1c42116c2ea65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ciro=20Santilli=20=E5=85=AD=E5=9B=9B=E4=BA=8B=E4=BB=B6=20?= =?UTF-8?q?=E6=B3=95=E8=BD=AE=E5=8A=9F?= Date: Fri, 25 Jan 2019 00:00:02 +0000 Subject: [PATCH] build-gem5: build individual unit tests --- README.adoc | 10 +++++++++- build-gem5 | 24 ++++++++++++++++++------ common.py | 11 +++++++++-- 3 files changed, 36 insertions(+), 9 deletions(-) diff --git a/README.adoc b/README.adoc index d73336e..812e248 100644 --- a/README.adoc +++ b/README.adoc @@ -10148,7 +10148,7 @@ Build the unit tests and run them: ./build-gem5 --unit-tests .... -Building individual unit tests is not exposed, but it is easy to do: while running the full tests, GTest prints each test command being run, e.g.: +Running individual unit tests is not yet exposed, but it is easy to do: while running the full tests, GTest prints each test command being run, e.g.: .... /path/to/build/ARM/base/circlebuf.test.opt --gtest_output=xml:/path/to/build/ARM/unittests.opt/base/circlebuf.test.xml @@ -10172,6 +10172,14 @@ Building individual unit tests is not exposed, but it is easy to do: while runni so you can just copy paste the command. +Building individual tests is possible with: + +.... +./build-gem5 --unit-test base/circlebuf.test +.... + +This does not run the test however. + Note that the command and it's corresponding results don't need to show consecutively on stdout because tests are run in parallel. You just have to match them based on the class name `CircleBufTest` to the file `circlebuf.test.cpp`. == Buildroot diff --git a/build-gem5 b/build-gem5 index 763af16..442edc6 100755 --- a/build-gem5 +++ b/build-gem5 @@ -13,13 +13,23 @@ class Main(common.BuildCliFunction): description='''\ Build gem5. https://github.com/cirosantilli/linux-kernel-module-cheat-regression#gem5-buildroot-setup +''' + ) + self.add_argument( + '--unit-test', + action='append', + default=[], + help='''\ +Build and run the given unit test. Paths are relative to src/ without the .opt suffix. +If given multiple times, runs multiple unit tests. Ignore --unit-tests. +https://github.com/cirosantilli/linux-kernel-module-cheat-regression#gem5-unit-tests ''' ) self.add_argument( '--unit-tests', default=False, help='''\ -Build and run the gem5 unit tests instead of the gem5 executable. +Build and run all the gem5 unit tests instead of the gem5 executable. https://github.com/cirosantilli/linux-kernel-module-cheat-regression#gem5-unit-tests ''' ) @@ -99,20 +109,22 @@ https://github.com/cirosantilli/linux-kernel-module-cheat-regression#gem5-unit-t # https://stackoverflow.com/questions/16764946/what-generates-the-text-file-busy-message-in-unix/52427512#52427512 self.sh.rmrf(self.env['gem5_m5term']) self.sh.cp(m5term_build, self.env['gem5_m5term']) - if self.env['unit_tests']: - target = self.env['gem5_unit_test_target'] + if self.env['unit_test']: + targets = [self.get_gem5_target_path(self.env, test) for test in self.env['unit_test']] + elif self.env['unit_tests']: + targets = [self.env['gem5_unit_test_target']] else: - target = self.env['gem5_executable'] + targets = [self.env['gem5_executable']] exit_status = self.sh.run_cmd( ( [ 'scons', LF, '-j', str(self.env['nproc']), LF, - '--gold-linker', LF, + # '--gold-linker', LF, '--ignore-style', LF, ] + verbose + - [target, LF] + + self.sh.add_newlines(targets) + self.sh.add_newlines(self.env['extra_scons_args']) ), cwd=self.env['gem5_source_dir'], diff --git a/common.py b/common.py index d5a24a7..0a68f7b 100644 --- a/common.py +++ b/common.py @@ -530,8 +530,8 @@ Valid emulators: {} env['gem5_build_build_dir'] = join(env['gem5_build_dir'], 'build') env['gem5_executable_dir'] = join(env['gem5_build_build_dir'], env['gem5_arch']) env['gem5_executable_suffix'] = '.{}'.format(env['gem5_build_type']) - env['gem5_executable'] = join(env['gem5_executable_dir'], 'gem5' + env['gem5_executable_suffix']) - env['gem5_unit_test_target'] = join(env['gem5_executable_dir'], 'unittests' + env['gem5_executable_suffix']) + env['gem5_executable'] = self.get_gem5_target_path(env, 'gem5') + env['gem5_unit_test_target'] = self.get_gem5_target_path(env, 'unittests') env['gem5_system_dir'] = join(env['gem5_build_dir'], 'system') # gem5 source @@ -738,6 +738,13 @@ Valid emulators: {} break return int(addr, 0) + @staticmethod + def get_gem5_target_path(env, name): + ''' + Get the magic gem5 target path form the meaningful component name. + ''' + return os.path.join(env['gem5_executable_dir'], name + env['gem5_executable_suffix']) + def gem5_list_checkpoint_dirs(self): ''' List checkpoint directory, oldest first.