mirror of
https://github.com/apache/nuttx.git
synced 2025-12-11 12:57:57 +08:00
gcov: add reboot gcov storage coverage info
Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
This commit is contained in:
committed by
Xiang Xiao
parent
781c27a98e
commit
66e074ed97
@@ -26,11 +26,12 @@
|
|||||||
|
|
||||||
#include <nuttx/config.h>
|
#include <nuttx/config.h>
|
||||||
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/boardctl.h>
|
#include <sys/boardctl.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <assert.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <assert.h>
|
#include <gcov.h>
|
||||||
|
|
||||||
#include <nuttx/arch.h>
|
#include <nuttx/arch.h>
|
||||||
#include <nuttx/board.h>
|
#include <nuttx/board.h>
|
||||||
|
|||||||
@@ -66,6 +66,25 @@ config COVERAGE_NONE
|
|||||||
|
|
||||||
endchoice
|
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
|
choice
|
||||||
prompt "Builtin profile support"
|
prompt "Builtin profile support"
|
||||||
default PROFILE_NONE
|
default PROFILE_NONE
|
||||||
|
|||||||
@@ -22,15 +22,16 @@
|
|||||||
* Included Files
|
* Included Files
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include <errno.h>
|
|
||||||
#include <gcov.h>
|
#include <gcov.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <errno.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
#include <fcntl.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#include <nuttx/lib/lib.h>
|
#include <nuttx/lib/lib.h>
|
||||||
|
#include <nuttx/reboot_notifier.h>
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Pre-processor Definitions
|
* Pre-processor Definitions
|
||||||
@@ -246,7 +247,7 @@ static int gcov_process_path(FAR char *prefix, int strip,
|
|||||||
strcat(new_path, tokens[i]);
|
strcat(new_path, tokens[i]);
|
||||||
if (access(new_path, F_OK) != 0)
|
if (access(new_path, F_OK) != 0)
|
||||||
{
|
{
|
||||||
ret = mkdir(new_path, 0644);
|
ret = mkdir(new_path, 0777);
|
||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
{
|
{
|
||||||
return -errno;
|
return -errno;
|
||||||
@@ -297,12 +298,50 @@ static int gcov_write_file(FAR const char *filename,
|
|||||||
return ret;
|
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
|
* Public Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
void __gcov_init(FAR struct gcov_info *info)
|
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;
|
info->next = __gcov_info_start;
|
||||||
__gcov_info_start = info;
|
__gcov_info_start = info;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user