Skip to content

Commit

Permalink
gcov: add reboot gcov storage coverage info
Browse files Browse the repository at this point in the history
Signed-off-by: wangmingrong1 <[email protected]>
  • Loading branch information
W-M-R authored and xiaoxiang781216 committed Jan 13, 2025
1 parent 3a328ac commit c4a6f39
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 6 deletions.
5 changes: 3 additions & 2 deletions boards/boardctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@

#include <nuttx/config.h>

#include <sys/types.h>
#include <sys/boardctl.h>
#include <sys/types.h>
#include <assert.h>
#include <stdint.h>
#include <errno.h>
#include <assert.h>
#include <gcov.h>

#include <nuttx/arch.h>
#include <nuttx/board.h>
Expand Down
19 changes: 19 additions & 0 deletions libs/libbuiltin/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,25 @@ config COVERAGE_NONE

endchoice

config COVERAGE_GCOV_DUMP_REBOOT
bool "Dump gcov data on reboot"
default n
---help---
Dump gcov data on reboot, this will cause the gcov data to be
dumped to the default path when the system is rebooted.

config COVERAGE_DEFAULT_PREFIX_STRIP
string "Default gcov dump path prefix strip"
default "99"
---help---
The default prefix strip of the gcov data

config COVERAGE_DEFAULT_PREFIX
string "Default gcov dump path prefix"
default "/data"
---help---
The default prefix to store the gcov data

choice
prompt "Builtin profile support"
default PROFILE_NONE
Expand Down
47 changes: 43 additions & 4 deletions libs/libbuiltin/libgcc/gcov.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,16 @@
* Included Files
****************************************************************************/

#include <errno.h>
#include <gcov.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <syslog.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <unistd.h>
#include <sys/stat.h>

#include <nuttx/lib/lib.h>
#include <nuttx/reboot_notifier.h>

/****************************************************************************
* Pre-processor Definitions
Expand Down Expand Up @@ -246,7 +247,7 @@ static int gcov_process_path(FAR char *prefix, int strip,
strcat(new_path, tokens[i]);
if (access(new_path, F_OK) != 0)
{
ret = mkdir(new_path, 0644);
ret = mkdir(new_path, 0777);
if (ret != 0)
{
return -errno;
Expand Down Expand Up @@ -297,12 +298,50 @@ static int gcov_write_file(FAR const char *filename,
return ret;
}

#ifdef CONFIG_COVERAGE_GCOV_DUMP_REBOOT
static int gcov_reboot_notify(FAR struct notifier_block *nb,
unsigned long action, FAR void *data)
{
__gcov_dump();
return 0;
}
#endif

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

void __gcov_init(FAR struct gcov_info *info)
{
#ifdef CONFIG_COVERAGE_GCOV_DUMP_REBOOT
static struct notifier_block nb;
#endif
char path[PATH_MAX] = CONFIG_COVERAGE_DEFAULT_PREFIX;
static int inited = 0;
struct tm *tm_info;
time_t cur;

if (!inited)
{
cur = time(NULL);
tm_info = localtime(&cur);

strftime(path + strlen(path),
PATH_MAX,
"/gcov_%Y%m%d_%H%M%S",
tm_info);

setenv("GCOV_PREFIX_STRIP", CONFIG_COVERAGE_DEFAULT_PREFIX_STRIP, 1);
setenv("GCOV_PREFIX", path, 1);

#ifdef CONFIG_COVERAGE_GCOV_DUMP_REBOOT
nb.notifier_call = gcov_reboot_notify;
register_reboot_notifier(&nb);
#endif

inited++;
}

info->next = __gcov_info_start;
__gcov_info_start = info;
}
Expand Down

0 comments on commit c4a6f39

Please sign in to comment.