Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions subsys/testsuite/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,18 @@ config COVERAGE_DUMP

endchoice

config HAVE_COVERAGE_DUMP_PATH_EXCLUDE
bool
default y
depends on COVERAGE_DUMP_PATH_EXCLUDE != ""
help
Helper symbol that is true when COVERAGE_DUMP_PATH_EXCLUDE is a
non-empty string

config COVERAGE_DUMP_PATH_EXCLUDE
string "Exclude files matching this pattern from the coverage data"
default ""
depends on !MINIMAL_LIBC
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could use some assistance with finding the correct condition(s) to put here. MINIMAL_LIBC does not support it. I don't think newlib does either, but not certain. For an external libc, I don't know if there is any way to tell...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, we could not bother with checking which libc and leave it up to the developer to ensure fnmatch is provided if they require this new feature. The helper symbol HAVE_COVERAGE_DUMP_PATH_EXCLUDE causes the references to be guarded when the feature is not used (i.e. the path is an empty string), which limits the build error to just cases where a developer tries using COVERAGE_DUMP_PATH_EXCLUDE and does not have fnmatch().

help
Filenames are matched against the pattern using the POSIX fnmatch
function. Filenames are based on their path in the build folder, not the
Expand Down
8 changes: 7 additions & 1 deletion subsys/testsuite/coverage/coverage.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
#include <stdint.h>
#include <errno.h>
#include <string.h>

#ifdef CONFIG_HAVE_COVERAGE_DUMP_PATH_EXCLUDE
#include <fnmatch.h>
#endif /* CONFIG_HAVE_COVERAGE_DUMP_PATH_EXCLUDE */

#include "coverage.h"

K_HEAP_DEFINE(gcov_heap, CONFIG_COVERAGE_GCOV_HEAP_SIZE);
Expand Down Expand Up @@ -316,11 +320,13 @@ void gcov_coverage_dump(void)
}
printk("\nGCOV_COVERAGE_DUMP_START");
while (gcov_list) {
#ifdef CONFIG_HAVE_COVERAGE_DUMP_PATH_EXCLUDE
if ((strlen(CONFIG_COVERAGE_DUMP_PATH_EXCLUDE) > 0) &&
(fnmatch(CONFIG_COVERAGE_DUMP_PATH_EXCLUDE, gcov_list->filename, 0) == 0)) {
/* Don't print a note here, it would be interpreted as dump data */
goto file_dump_end;
}
#endif /* CONFIG_HAVE_COVERAGE_DUMP_PATH_EXCLUDE */

dump_on_console_start(gcov_list->filename);
size = gcov_calculate_buff_size(gcov_list);
Expand All @@ -340,7 +346,7 @@ void gcov_coverage_dump(void)
dump_on_console_data(buffer, size);

k_heap_free(&gcov_heap, buffer);
file_dump_end:
goto file_dump_end; file_dump_end:
gcov_list = gcov_list->next;
if (gcov_list_first == gcov_list) {
goto coverage_dump_end;
Expand Down