| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
#pragma once |
| 3 |
|
| 4 |
/* Use the coverage-related tweaks below only for C stuff as they're not really |
| 5 |
* C++ compatible, and the only thing that is built with a C++ compiler is |
| 6 |
* the lone test-bus-vtable-cc unit test. |
| 7 |
*/ |
| 8 |
#ifndef __cplusplus |
| 9 |
|
| 10 |
void __gcov_dump(void); |
| 11 |
void __gcov_reset(void); |
| 12 |
|
| 13 |
/* When built with --coverage (gcov) we need to explicitly call __gcov_dump() |
| 14 |
* in places where we use _exit(), since _exit() skips at-exit hooks resulting |
| 15 |
* in lost coverage. |
| 16 |
* |
| 17 |
* To make sure we don't miss any _exit() calls, this header file is included |
| 18 |
* explicitly on the compiler command line via the -include directive (only |
| 19 |
* when built with -Db_coverage=true) |
| 20 |
*/ |
| 21 |
void _exit(int); |
| 22 |
|
| 23 |
static inline _Noreturn void _coverage__exit(int status) { |
| 24 |
__gcov_dump(); |
| 25 |
_exit(status); |
| 26 |
} |
| 27 |
#define _exit(x) _coverage__exit(x) |
| 28 |
|
| 29 |
/* gcov provides wrappers for the exec*() calls but there's none for execveat() |
| 30 |
* and execvpe() which means we lose all coverage prior to such call. To mitigate |
| 31 |
* this, let's add simple wrappers in gcov's style[0] for these exec*() calls, |
| 32 |
* which dump and reset the coverage data as needed. |
| 33 |
* |
| 34 |
* [0] https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=libgcc/libgcov-interface.c;h=b2ee930864183b78c8826255183ca86e15e21ded;hb=HEAD |
| 35 |
*/ |
| 36 |
|
| 37 |
int execveat(int, const char *, char * const [], char * const [], int); |
| 38 |
int execvpe(const char *, char * const [], char * const []); |
| 39 |
|
| 40 |
static inline int _coverage_execveat( |
| 41 |
int dirfd, |
| 42 |
const char *pathname, |
| 43 |
char * const argv[], |
| 44 |
char * const envp[], |
| 45 |
int flags) { |
| 46 |
__gcov_dump(); |
| 47 |
int r = execveat(dirfd, pathname, argv, envp, flags); |
| 48 |
__gcov_reset(); |
| 49 |
|
| 50 |
return r; |
| 51 |
} |
| 52 |
#define execveat(d,p,a,e,f) _coverage_execveat(d, p, a, e, f) |
| 53 |
|
| 54 |
static inline int _coverage_execvpe( |
| 55 |
const char *file, |
| 56 |
char * const argv[], |
| 57 |
char * const envp[]) { |
| 58 |
__gcov_dump(); |
| 59 |
int r = execvpe(file, argv, envp); |
| 60 |
__gcov_reset(); |
| 61 |
|
| 62 |
return r; |
| 63 |
} |
| 64 |
#define execvpe(f,a,e) _coverage_execvpe(f, a, e) |
| 65 |
|
| 66 |
#endif |