|
22 | 22 | * Included Files
|
23 | 23 | ****************************************************************************/
|
24 | 24 |
|
25 |
| -#include <errno.h> |
26 | 25 | #include <gcov.h>
|
| 26 | +#include <fcntl.h> |
| 27 | +#include <errno.h> |
27 | 28 | #include <string.h>
|
28 | 29 | #include <syslog.h>
|
29 |
| -#include <fcntl.h> |
30 |
| -#include <sys/stat.h> |
31 | 30 | #include <unistd.h>
|
| 31 | +#include <sys/stat.h> |
32 | 32 |
|
33 | 33 | #include <nuttx/lib/lib.h>
|
| 34 | +#include <nuttx/reboot_notifier.h> |
34 | 35 |
|
35 | 36 | /****************************************************************************
|
36 | 37 | * Pre-processor Definitions
|
@@ -246,7 +247,7 @@ static int gcov_process_path(FAR char *prefix, int strip,
|
246 | 247 | strcat(new_path, tokens[i]);
|
247 | 248 | if (access(new_path, F_OK) != 0)
|
248 | 249 | {
|
249 |
| - ret = mkdir(new_path, 0644); |
| 250 | + ret = mkdir(new_path, 0777); |
250 | 251 | if (ret != 0)
|
251 | 252 | {
|
252 | 253 | return -errno;
|
@@ -297,12 +298,50 @@ static int gcov_write_file(FAR const char *filename,
|
297 | 298 | return ret;
|
298 | 299 | }
|
299 | 300 |
|
| 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 | + |
300 | 310 | /****************************************************************************
|
301 | 311 | * Public Functions
|
302 | 312 | ****************************************************************************/
|
303 | 313 |
|
304 | 314 | void __gcov_init(FAR struct gcov_info *info)
|
305 | 315 | {
|
| 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 | + |
306 | 345 | info->next = __gcov_info_start;
|
307 | 346 | __gcov_info_start = info;
|
308 | 347 | }
|
|
0 commit comments