build-gem5: build individual unit tests

This commit is contained in:
Ciro Santilli 六四事件 法轮功
2019-01-25 00:00:02 +00:00
parent 82f04daef1
commit 7b99c45ac2
3 changed files with 36 additions and 9 deletions

View File

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

View File

@@ -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'],

View File

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