Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

system/gcov: enhance gcov #2650

Merged
merged 3 commits into from
Oct 9, 2024
Merged
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
2 changes: 1 addition & 1 deletion system/gcov/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

config SYSTEM_GCOV
tristate "gcov tool"
depends on ARCH_COVERAGE
depends on SCHED_GCOV
---help---
Enable support for the 'gcov' command.

Expand Down
36 changes: 32 additions & 4 deletions system/gcov/gcov.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
****************************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

/****************************************************************************
Expand All @@ -35,11 +36,13 @@

static void show_usage(FAR const char *progname)
{
printf("\nUsage: %s [-d] [-r] [-h]\n", progname);
printf("\nUsage: %s [-d path] [-t strip] [-r] [-h]\n", progname);
printf("\nWhere:\n");
printf(" -d dump the coverage.\n");
printf(" -d dump the coverage, path is the path to the coverage file\n");
printf(" -t strip the path prefix number\n");
printf(" -r reset the coverage\n");
printf(" -h show this text and exits.\n");
exit(EXIT_FAILURE);
}

/****************************************************************************
Expand All @@ -49,25 +52,49 @@ static void show_usage(FAR const char *progname)
void __gcov_dump(void);
void __gcov_reset(void);

/****************************************************************************
* Private Functions
****************************************************************************/

static void gcov_dump(FAR const char * path, FAR const char *strip)
{
if (path == NULL || access(path, F_OK) != 0 || atoi(strip) <= 0)
{
fprintf(stderr, "ERROR: Invalid parameter\n");
return;
}

setenv("GCOV_PREFIX_STRIP", strip, 1);
setenv("GCOV_PREFIX", path, 1);
__gcov_dump();
}

/****************************************************************************
* Public Functions
****************************************************************************/

int main(int argc, FAR char *argv[])
{
FAR const char *strip = "99";
FAR const char *path = NULL;
int option;

if (argc < 2)
{
show_usage(argv[0]);
}

while ((option = getopt(argc, argv, "drh")) != ERROR)
while ((option = getopt(argc, argv, "d:t:rh")) != ERROR)
{
switch (option)
{
case 'd':
__gcov_dump();
path = optarg;
break;

case 't':
strip = optarg;

break;

case 'r':
Expand All @@ -83,5 +110,6 @@ int main(int argc, FAR char *argv[])
}
}

gcov_dump(path, strip);
return 0;
}
Loading