diff --git a/README.adoc b/README.adoc index 7306d44..d73336e 100644 --- a/README.adoc +++ b/README.adoc @@ -10140,7 +10140,39 @@ Tested on: link:http://github.com/cirosantilli/linux-kernel-module-cheat/commit/ https://stackoverflow.com/questions/52279971/how-to-run-the-gem5-unit-tests -Not currently exposed here. +These are just very small GTest tests that test a single class in isolation, they don't run any executables. + +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.: + +.... +/path/to/build/ARM/base/circlebuf.test.opt --gtest_output=xml:/path/to/build/ARM/unittests.opt/base/circlebuf.test.xml +[==========] Running 4 tests from 1 test case. +[----------] Global test environment set-up. +[----------] 4 tests from CircleBufTest +[ RUN ] CircleBufTest.BasicReadWriteNoOverflow +[ OK ] CircleBufTest.BasicReadWriteNoOverflow (0 ms) +[ RUN ] CircleBufTest.SingleWriteOverflow +[ OK ] CircleBufTest.SingleWriteOverflow (0 ms) +[ RUN ] CircleBufTest.MultiWriteOverflow +[ OK ] CircleBufTest.MultiWriteOverflow (0 ms) +[ RUN ] CircleBufTest.PointerWrapAround +[ OK ] CircleBufTest.PointerWrapAround (0 ms) +[----------] 4 tests from CircleBufTest (0 ms total) + +[----------] Global test environment tear-down +[==========] 4 tests from 1 test case ran. (0 ms total) +[ PASSED ] 4 tests. +.... + +so you can just copy paste the command. + +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 @@ -12080,6 +12112,7 @@ The link:test[] script runs several different types of tests, which can also be * <> * <> * <> +* <> link:test[] does not all possible tests, because there are too many possible variations and that would take forever. The rationale is the same as for `./build all` and is explained in `./build --help`. diff --git a/build-gem5 b/build-gem5 index ad2ea55..763af16 100755 --- a/build-gem5 +++ b/build-gem5 @@ -9,7 +9,20 @@ from shell_helpers import LF class Main(common.BuildCliFunction): def __init__(self): - super().__init__() + super().__init__( + description='''\ +Build gem5. +https://github.com/cirosantilli/linux-kernel-module-cheat-regression#gem5-buildroot-setup +''' + ) + self.add_argument( + '--unit-tests', + default=False, + help='''\ +Build and run the gem5 unit tests instead of the gem5 executable. +https://github.com/cirosantilli/linux-kernel-module-cheat-regression#gem5-unit-tests +''' + ) self.add_argument( 'extra_scons_args', metavar='extra-scons-args', @@ -77,21 +90,6 @@ class Main(common.BuildCliFunction): # TODO cross_compile is ignored because the make does not use CC... self.sh.run_cmd(['make', '-C', bootloader64_dir, LF]) self.sh.cp(os.path.join(bootloader64_dir, 'boot_emm.arm64'), binaries_dir) - self.sh.run_cmd( - ( - [ - 'scons', LF, - '-j', str(self.env['nproc']), LF, - '--gold-linker', LF, - '--ignore-style', LF, - self.env['gem5_executable'], LF, - ] + - verbose + - self.sh.add_newlines(self.env['extra_scons_args']) - ), - cwd=self.env['gem5_source_dir'], - extra_paths=[self.env['ccache_dir']], - ) term_source_dir = os.path.join(self.env['gem5_source_dir'], 'util/term') m5term_build = os.path.join(term_source_dir, 'm5term') self.sh.run_cmd(['make', '-C', term_source_dir, LF]) @@ -101,6 +99,27 @@ class Main(common.BuildCliFunction): # 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'] + else: + target = self.env['gem5_executable'] + exit_status = self.sh.run_cmd( + ( + [ + 'scons', LF, + '-j', str(self.env['nproc']), LF, + '--gold-linker', LF, + '--ignore-style', LF, + ] + + verbose + + [target, LF] + + self.sh.add_newlines(self.env['extra_scons_args']) + ), + cwd=self.env['gem5_source_dir'], + extra_paths=[self.env['ccache_dir']], + raise_on_failure = False, + ) + return exit_status def get_build_dir(self): return self.env['gem5_build_dir'] diff --git a/common.py b/common.py index 332986e..d5a24a7 100644 --- a/common.py +++ b/common.py @@ -528,7 +528,10 @@ Valid emulators: {} env['gem5_fake_iso'] = join(env['gem5_out_dir'], 'fake.iso') env['gem5_m5term'] = join(env['gem5_build_dir'], 'm5term') env['gem5_build_build_dir'] = join(env['gem5_build_dir'], 'build') - env['gem5_executable'] = join(env['gem5_build_build_dir'], env['gem5_arch'], 'gem5.{}'.format(env['gem5_build_type'])) + 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_system_dir'] = join(env['gem5_build_dir'], 'system') # gem5 source diff --git a/test b/test index 67b3b2f..3389277 100755 --- a/test +++ b/test @@ -33,6 +33,10 @@ Size of the tests to run. Scale: self.run_test(self.import_path_main('test-baremetal'), run_args, 'test-baremetal') self.run_test(self.import_path_main('test-user-mode'), run_args, 'test-user-mode') self.run_test(self.import_path_main('test-gdb'), run_args, 'test-gdb') + if self.env['emulator'] == 'gem5': + gem5_unit_test_args = run_args.copy() + gem5_unit_test_args['unit_tests'] = True + self.run_test(self.import_path_main('build-gem5'), gem5_unit_test_args, 'gem5-unit-tests') if __name__ == '__main__': Main().cli()