gcov: add reboot gcov storage coverage info

Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
This commit is contained in:
wangmingrong1 2025-01-02 21:52:43 +08:00 committed by Xiang Xiao
parent 781c27a98e
commit 66e074ed97
3 changed files with 65 additions and 6 deletions

View file

@ -26,11 +26,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>

View file

@ -66,6 +66,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

View file

@ -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
@ -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;
@ -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;
}