From 776fe3f999e637f6ae00a52aba88d4c2df0f25dc Mon Sep 17 00:00:00 2001 From: Paul Fagerburg Date: Thu, 11 Jun 2020 10:51:19 -0600 Subject: makefile: use separate directory for code coverage When building host-based unit tests for code coverage, put the build outputs in a different directory. Because the code coverage build has calls into gcov library functions, a partial rebuild without code coverage will result in undefined linker errors. The previous solution was an inefficient cycle of `make clobber` and full rebuild when switching between building with and without code coverage. BUG=b:157091606 BRANCH=None TEST=`make buildall -j ; make coverage -j` Verify that build/host and build/coverage both exist, and that code coverage data (*.gcno, *.gcda, *.info) is only in build/coverage. Signed-off-by: Paul Fagerburg Change-Id: Iac0b18068082d34546aa15b174f86efb6a7f41a7 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2242351 Tested-by: Paul Fagerburg Reviewed-by: Jett Rink Reviewed-by: Jack Rosenthal Commit-Queue: Paul Fagerburg --- util/run_host_test | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'util') diff --git a/util/run_host_test b/util/run_host_test index 57b197b6e7..ce33722c3a 100755 --- a/util/run_host_test +++ b/util/run_host_test @@ -91,26 +91,30 @@ def run_test(path, timeout=10): proc.kill() -def host_test(test_name): - exec_path = pathlib.Path('build', 'host', test_name, f'{test_name}.exe') - if not exec_path.is_file(): - raise argparse.ArgumentTypeError(f'No test named {test_name} exists!') - return exec_path - - def parse_options(argv): parser = argparse.ArgumentParser() parser.add_argument('-t', '--timeout', type=float, default=60, help='Timeout to kill test after.') - parser.add_argument('test_name', type=host_test) + parser.add_argument('--coverage', action='store_const', const='coverage', + default='host', dest='test_target', + help='Flag if this is a code coverage test.') + parser.add_argument('test_name', type=str) return parser.parse_args(argv) def main(argv): opts = parse_options(argv) + # Tests will be located in build/host, unless the --coverage flag was + # provided, in which case they will be in build/coverage. + exec_path = pathlib.Path('build', opts.test_target, opts.test_name, + f'{opts.test_name}.exe') + if not exec_path.is_file(): + print(f'No test named {opts.test_name} exists!') + return 1 + start_time = time.monotonic() - result, output = run_test(opts.test_name, timeout=opts.timeout) + result, output = run_test(exec_path, timeout=opts.timeout) elapsed_time = time.monotonic() - start_time print('{} {}! ({:.3f} seconds)'.format( -- cgit v1.2.1