Skip to content

Commit 66e074e

Browse files
W-M-Rxiaoxiang781216
authored andcommitted
gcov: add reboot gcov storage coverage info
Signed-off-by: wangmingrong1 <[email protected]>
1 parent 781c27a commit 66e074e

File tree

3 files changed

+65
-6
lines changed

3 files changed

+65
-6
lines changed

boards/boardctl.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,12 @@
2626

2727
#include <nuttx/config.h>
2828

29-
#include <sys/types.h>
3029
#include <sys/boardctl.h>
30+
#include <sys/types.h>
31+
#include <assert.h>
3132
#include <stdint.h>
3233
#include <errno.h>
33-
#include <assert.h>
34+
#include <gcov.h>
3435

3536
#include <nuttx/arch.h>
3637
#include <nuttx/board.h>

libs/libbuiltin/Kconfig

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,25 @@ config COVERAGE_NONE
6666

6767
endchoice
6868

69+
config COVERAGE_GCOV_DUMP_REBOOT
70+
bool "Dump gcov data on reboot"
71+
default n
72+
---help---
73+
Dump gcov data on reboot, this will cause the gcov data to be
74+
dumped to the default path when the system is rebooted.
75+
76+
config COVERAGE_DEFAULT_PREFIX_STRIP
77+
string "Default gcov dump path prefix strip"
78+
default "99"
79+
---help---
80+
The default prefix strip of the gcov data
81+
82+
config COVERAGE_DEFAULT_PREFIX
83+
string "Default gcov dump path prefix"
84+
default "/data"
85+
---help---
86+
The default prefix to store the gcov data
87+
6988
choice
7089
prompt "Builtin profile support"
7190
default PROFILE_NONE

libs/libbuiltin/libgcc/gcov.c

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,16 @@
2222
* Included Files
2323
****************************************************************************/
2424

25-
#include <errno.h>
2625
#include <gcov.h>
26+
#include <fcntl.h>
27+
#include <errno.h>
2728
#include <string.h>
2829
#include <syslog.h>
29-
#include <fcntl.h>
30-
#include <sys/stat.h>
3130
#include <unistd.h>
31+
#include <sys/stat.h>
3232

3333
#include <nuttx/lib/lib.h>
34+
#include <nuttx/reboot_notifier.h>
3435

3536
/****************************************************************************
3637
* Pre-processor Definitions
@@ -246,7 +247,7 @@ static int gcov_process_path(FAR char *prefix, int strip,
246247
strcat(new_path, tokens[i]);
247248
if (access(new_path, F_OK) != 0)
248249
{
249-
ret = mkdir(new_path, 0644);
250+
ret = mkdir(new_path, 0777);
250251
if (ret != 0)
251252
{
252253
return -errno;
@@ -297,12 +298,50 @@ static int gcov_write_file(FAR const char *filename,
297298
return ret;
298299
}
299300

301+
#ifdef CONFIG_COVERAGE_GCOV_DUMP_REBOOT
302+
static int gcov_reboot_notify(FAR struct notifier_block *nb,
303+
unsigned long action, FAR void *data)
304+
{
305+
__gcov_dump();
306+
return 0;
307+
}
308+
#endif
309+
300310
/****************************************************************************
301311
* Public Functions
302312
****************************************************************************/
303313

304314
void __gcov_init(FAR struct gcov_info *info)
305315
{
316+
#ifdef CONFIG_COVERAGE_GCOV_DUMP_REBOOT
317+
static struct notifier_block nb;
318+
#endif
319+
char path[PATH_MAX] = CONFIG_COVERAGE_DEFAULT_PREFIX;
320+
static int inited = 0;
321+
struct tm *tm_info;
322+
time_t cur;
323+
324+
if (!inited)
325+
{
326+
cur = time(NULL);
327+
tm_info = localtime(&cur);
328+
329+
strftime(path + strlen(path),
330+
PATH_MAX,
331+
"/gcov_%Y%m%d_%H%M%S",
332+
tm_info);
333+
334+
setenv("GCOV_PREFIX_STRIP", CONFIG_COVERAGE_DEFAULT_PREFIX_STRIP, 1);
335+
setenv("GCOV_PREFIX", path, 1);
336+
337+
#ifdef CONFIG_COVERAGE_GCOV_DUMP_REBOOT
338+
nb.notifier_call = gcov_reboot_notify;
339+
register_reboot_notifier(&nb);
340+
#endif
341+
342+
inited++;
343+
}
344+
306345
info->next = __gcov_info_start;
307346
__gcov_info_start = info;
308347
}

0 commit comments

Comments
 (0)