Evan Benn has uploaded this change for review. ( https://review.coreboot.org/c/flashrom/+/69268 )
Change subject: tests: Add llvm-cov optio and run target for code coverage ......................................................................
tests: Add llvm-cov optio and run target for code coverage
Code coverage can be requested with -Dllvm_cov and run with ninja llvm-cov.
BUG=b:187647884 BRANCH=None TEST=meson test; ninja llvm-cov
Change-Id: Id6c73bff46e7b88d425956a80def97082b201f56 Signed-off-by: Evan Benn evanbenn@chromium.org --- M Documentation/building.md M meson.build M meson_options.txt A scripts/llvm-cov 4 files changed, 40 insertions(+), 8 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/68/69268/1
diff --git a/Documentation/building.md b/Documentation/building.md index 445fd65..9893512 100644 --- a/Documentation/building.md +++ b/Documentation/building.md @@ -60,12 +60,9 @@ #### llvm https://clang.llvm.org/docs/SourceBasedCodeCoverage.html ``` -env CFLAGS="-fprofile-instr-generate -fcoverage-mapping" CC=clang meson setup buildclangcov -env LLVM_PROFILE_FILE=default.profraw ninja -C buildclangcov test -cd buildclangcov -llvm-profdata merge -sparse default.profraw -o default.profdata -llvm-cov show ./flashrom_unit_tests -instr-profile=default.profdata --format=html --output-dir=. -open index.html +env CC=clang meson setup buildclangcov -Dllvm_cov=true +ninja -C buildclangcov test +ninja -C buildclangcov llvm-cov ```
## System specific information diff --git a/meson.build b/meson.build index 81c7190..3fa8ab8 100644 --- a/meson.build +++ b/meson.build @@ -47,6 +47,7 @@ config_default_programmer_args = get_option('default_programmer_args')
cargs = [] +link_args = [] deps = [] srcs = files( '82802ab.c', @@ -530,6 +531,11 @@
cargs += '-DCONFIG_DEFAULT_PROGRAMMER_ARGS="' + config_default_programmer_args + '"'
+if get_option('llvm_cov') + cargs += ['-fprofile-instr-generate', '-fcoverage-mapping'] + link_args += ['-fprofile-instr-generate', '-fcoverage-mapping'] +endif + install_headers([ 'include/libflashrom.h', ], @@ -558,7 +564,7 @@ cargs, ], install : true, - link_args : vflag, + link_args : link_args + [vflag], link_depends : mapfile, )
@@ -602,6 +608,7 @@ include_directories : include_dir, install : true, install_dir : get_option('sbindir'), + link_args : link_args, link_with : libflashrom.get_static_lib(), # flashrom needs internal symbols of libflashrom ) endif @@ -745,10 +752,14 @@ '-fdata-sections', ], export_dynamic : true, - link_args : mocks, + link_args : mocks + link_args, dependencies : [cmocka_dep, flashrom_test_dep], ) test('cmocka test flashrom', flashrom_tests, timeout: 60) + + if get_option('llvm_cov') + run_target('llvm-cov', command : ['scripts/llvm-cov', flashrom_tests]) + endif endif
programmer_names_active = [] diff --git a/meson_options.txt b/meson_options.txt index 8c04029..fcab26a 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -16,3 +16,4 @@ 'pickit2_spi', 'pony_spi', 'raiden_debug_spi', 'rayer_spi', 'realtek_mst_i2c_spi', 'satamv', 'satasii', 'serprog', 'stlinkv3_spi', 'usbblaster_spi', ], description: 'Active programmers') +option('llvm_cov', type : 'boolean', value : 'false', description : 'build for llvm code coverage') diff --git a/scripts/llvm-cov b/scripts/llvm-cov new file mode 100755 index 0000000..b512b3d --- /dev/null +++ b/scripts/llvm-cov @@ -0,0 +1,6 @@ +#!/bin/sh + +cd "${MESON_BUILD_ROOT}" +llvm-profdata merge -sparse default.profraw -o default.profdata +llvm-cov show -instr-profile=default.profdata -format=html -output-dir=. "$@" +echo "file://${MESON_BUILD_ROOT}/index.html"