Skip to content

Commit bb1b246

Browse files
committed
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 6614a3a commit bb1b246

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

subsys/testsuite/Kconfig

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,10 @@ config COVERAGE_GCOV
7272

7373
endchoice
7474

75+
if COVERAGE_GCOV
76+
7577
config COVERAGE_GCOV_HEAP_SIZE
7678
int "Size of heap allocated for gcov coverage data dump"
77-
depends on COVERAGE_GCOV
7879
default 32768 if X86 || SOC_SERIES_MPS2
7980
default 16384
8081
help
@@ -84,10 +85,20 @@ config COVERAGE_GCOV_HEAP_SIZE
8485

8586
config COVERAGE_DUMP
8687
bool "Dump coverage data on exit"
87-
depends on COVERAGE_GCOV
8888
help
8989
Dump collected coverage information to console on exit.
9090

91+
config COVERAGE_DUMP_PATH_EXCLUDE
92+
string "Exclude files matching this pattern from the coverage data"
93+
default ""
94+
help
95+
Filenames are matched against the pattern using the posix fnmatch
96+
function. Filenames are based on their path in the build folder, not the
97+
original source tree. The empty string "" disables the pattern
98+
matching.
99+
100+
endif # COVERAGE_GCOV
101+
91102
config FORCE_COVERAGE
92103
bool "Force coverage"
93104
select HAS_COVERAGE_SUPPORT

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)