Skip to content

Commit c4a6f39

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

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
@@ -24,11 +24,12 @@
2424

2525
#include <nuttx/config.h>
2626

27-
#include <sys/types.h>
2827
#include <sys/boardctl.h>
28+
#include <sys/types.h>
29+
#include <assert.h>
2930
#include <stdint.h>
3031
#include <errno.h>
31-
#include <assert.h>
32+
#include <gcov.h>
3233

3334
#include <nuttx/arch.h>
3435
#include <nuttx/board.h>

libs/libbuiltin/Kconfig

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

6666
endchoice
6767

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