Skip to content

Commit d185f8e

Browse files
JordanYatesnashif
authored andcommitted
testsuite: optional limiting of coverage dumps
Add an option that excludes generation of a given path of `.gcda` files when running coverage testing. This can be useful when running testing coverage on downstream repos, which would otherwise result in large `.gcda` files for paths we don't care about filling up the disk. One example of using this is to exclude coverage outputs from mbedtls files with the following: `CONFIG_COVERAGE_DUMP_PATH_EXCLUDE="*modules/crypto/mbedtls*"` Signed-off-by: Jordan Yates <[email protected]>
1 parent 1beee4f commit d185f8e

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

subsys/testsuite/Kconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,15 @@ config COVERAGE_DUMP
9595

9696
endchoice
9797

98+
config COVERAGE_DUMP_PATH_EXCLUDE
99+
string "Exclude files matching this pattern from the coverage data"
100+
default ""
101+
help
102+
Filenames are matched against the pattern using the POSIX fnmatch
103+
function. Filenames are based on their path in the build folder, not the
104+
original source tree. The empty string "" disables the pattern
105+
matching.
106+
98107
endif # COVERAGE_GCOV
99108

100109
config FORCE_COVERAGE

subsys/testsuite/coverage/coverage.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <stdint.h>
1010
#include <errno.h>
1111
#include <string.h>
12+
#include <fnmatch.h>
1213
#include "coverage.h"
1314

1415
K_HEAP_DEFINE(gcov_heap, CONFIG_COVERAGE_GCOV_HEAP_SIZE);
@@ -315,6 +316,11 @@ void gcov_coverage_dump(void)
315316
}
316317
printk("\nGCOV_COVERAGE_DUMP_START");
317318
while (gcov_list) {
319+
if ((strlen(CONFIG_COVERAGE_DUMP_PATH_EXCLUDE) > 0) &&
320+
(fnmatch(CONFIG_COVERAGE_DUMP_PATH_EXCLUDE, gcov_list->filename, 0) == 0)) {
321+
/* Don't print a note here, it would be interpreted as dump data */
322+
goto file_dump_end;
323+
}
318324

319325
dump_on_console_start(gcov_list->filename);
320326
size = gcov_calculate_buff_size(gcov_list);
@@ -334,6 +340,7 @@ void gcov_coverage_dump(void)
334340
dump_on_console_data(buffer, size);
335341

336342
k_heap_free(&gcov_heap, buffer);
343+
file_dump_end:
337344
gcov_list = gcov_list->next;
338345
if (gcov_list_first == gcov_list) {
339346
goto coverage_dump_end;

0 commit comments

Comments
 (0)