diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2021-07-15 07:35:55 +0200 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2022-04-12 08:37:54 +0200 |
commit | 59d3b483c1c0f6039aa2a364cae6a75219372ece (patch) | |
tree | 13447b284a8e469b4e97dad3060b30a9002edc32 | |
parent | 3cdc953f44c6eba49ba29093f78c629495dfaab8 (diff) |
build: Add RTEMS_COVERAGE support
-rw-r--r-- | bsps/shared/start/bspreset-empty.c | 5 | ||||
-rw-r--r-- | cpukit/include/rtems/score/io.h | 10 | ||||
-rw-r--r-- | cpukit/libtest/testextension.c | 1 | ||||
-rw-r--r-- | cpukit/libtest/wrapcpufatalhalt.c | 54 | ||||
-rw-r--r-- | cpukit/posix/src/_execve.c | 43 | ||||
-rw-r--r-- | cpukit/posix/src/fork.c | 10 | ||||
-rw-r--r-- | cpukit/score/src/iodumpgcovinfo.c | 100 | ||||
-rw-r--r-- | spec/build/cpukit/cpuopts.yml | 2 | ||||
-rw-r--r-- | spec/build/cpukit/grp.yml | 6 | ||||
-rw-r--r-- | spec/build/cpukit/librtemscpu.yml | 5 | ||||
-rw-r--r-- | spec/build/cpukit/librtemstest.yml | 1 | ||||
-rw-r--r-- | spec/build/cpukit/optcflagscoverage.yml | 22 | ||||
-rw-r--r-- | spec/build/cpukit/optcflagscoverageopt.yml | 19 | ||||
-rw-r--r-- | spec/build/cpukit/optcoverage.yml | 16 | ||||
-rw-r--r-- | spec/build/cpukit/optldflagscoverage.yml | 20 |
15 files changed, 312 insertions, 2 deletions
diff --git a/bsps/shared/start/bspreset-empty.c b/bsps/shared/start/bspreset-empty.c index 6d7d1667a4..bdddb031b6 100644 --- a/bsps/shared/start/bspreset-empty.c +++ b/bsps/shared/start/bspreset-empty.c @@ -10,8 +10,13 @@ */ #include <rtems.h> +#include <rtems/bspIo.h> +#include <rtems/score/io.h> #include <bsp/bootcard.h> void bsp_reset( void ) { +#if defined(RTEMS_COVERAGE) + _IO_Dump_gcov_info( rtems_put_char, NULL ); +#endif } diff --git a/cpukit/include/rtems/score/io.h b/cpukit/include/rtems/score/io.h index 106418f185..3595c8431e 100644 --- a/cpukit/include/rtems/score/io.h +++ b/cpukit/include/rtems/score/io.h @@ -133,6 +133,16 @@ int _IO_Base64url( int wordlen ); +/* + * @brief Dumps the gcov info sections using _IO_Printf(). + * + * @param put_char is the put character handler used to dump the gcov info + * sections. + * + * @param arg is the argument passed to the put character handler. + */ +void _IO_Dump_gcov_info( IO_Put_char put_char, void *arg ); + /** * @brief Issues a couple of no-operation instructions. * diff --git a/cpukit/libtest/testextension.c b/cpukit/libtest/testextension.c index 6bfe61eb0c..5e496feeb9 100644 --- a/cpukit/libtest/testextension.c +++ b/cpukit/libtest/testextension.c @@ -32,6 +32,7 @@ #include <rtems/test-info.h> #include <rtems/profiling.h> #include <rtems/bspIo.h> +#include <rtems/score/io.h> #if defined(RTEMS_PROFILING) static bool report_done; diff --git a/cpukit/libtest/wrapcpufatalhalt.c b/cpukit/libtest/wrapcpufatalhalt.c new file mode 100644 index 0000000000..0b41dc0480 --- /dev/null +++ b/cpukit/libtest/wrapcpufatalhalt.c @@ -0,0 +1,54 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + +/** + * @file + * + * @ingroup RTEMSTest + * + * @brief This source file contains the implementation of a wrapper for + * _CPU_Fatal_halt() which dumps the gcov information using + * _IO_Dump_gcov_info() before the real _CPU_Fatal_halt() is called. + */ + +/* + * Copyright (C) 2021 embedded brains GmbH (http://www.embedded-brains.de) + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <rtems/score/cpu.h> +#include <rtems/score/io.h> +#include <rtems/bspIo.h> + +void __real__CPU_Fatal_halt( uint32_t source, CPU_Uint32ptr error ); + +void __wrap__CPU_Fatal_halt( uint32_t source, CPU_Uint32ptr error ); + +void __wrap__CPU_Fatal_halt( uint32_t source, CPU_Uint32ptr error ) +{ + _IO_Dump_gcov_info( rtems_put_char, NULL ); + __real__CPU_Fatal_halt( source, error ); +} diff --git a/cpukit/posix/src/_execve.c b/cpukit/posix/src/_execve.c index 2858d13082..6c48e817eb 100644 --- a/cpukit/posix/src/_execve.c +++ b/cpukit/posix/src/_execve.c @@ -47,9 +47,11 @@ */ #define _COMPILING_NEWLIB +#include <sys/unistd.h> #include <errno.h> + +#include <rtems/score/cpuopts.h> #include <rtems/seterr.h> -#include <sys/unistd.h> int _execve( const char *path, @@ -62,3 +64,42 @@ int _execve( (void) envp; rtems_set_errno_and_return_minus_one( ENOSYS ); } + +#if defined(RTEMS_COVERAGE) +int __gcov_execl( const char *path, char *arg, ... ); +int __gcov_execlp( const char *path, char *arg, ... ); +int __gcov_execle( const char *path, char *arg, ... ); +int __gcov_execv( const char *path, char *const argv[] ); +int __gcov_execvp( const char *path, char *const argv[] ); +int __gcov_execve( const char *path, char *const argv[], char *const envp[] ); + +int __gcov_execl( const char *path, char *arg, ... ) +{ + rtems_set_errno_and_return_minus_one( ENOSYS ); +} + +int __gcov_execlp( const char *path, char *arg, ... ) +{ + rtems_set_errno_and_return_minus_one( ENOSYS ); +} + +int __gcov_execle( const char *path, char *arg, ... ) +{ + rtems_set_errno_and_return_minus_one( ENOSYS ); +} + +int __gcov_execv( const char *path, char *const argv[] ) +{ + rtems_set_errno_and_return_minus_one( ENOSYS ); +} + +int __gcov_execvp( const char *path, char *const argv[] ) +{ + rtems_set_errno_and_return_minus_one( ENOSYS ); +} + +int __gcov_execve( const char *path, char *const argv[], char *const envp[] ) +{ + rtems_set_errno_and_return_minus_one( ENOSYS ); +} +#endif diff --git a/cpukit/posix/src/fork.c b/cpukit/posix/src/fork.c index 6ddff99746..2de352ca33 100644 --- a/cpukit/posix/src/fork.c +++ b/cpukit/posix/src/fork.c @@ -43,9 +43,19 @@ #include <unistd.h> #include <errno.h> +#include <rtems/score/cpuopts.h> #include <rtems/seterr.h> int fork( void ) { rtems_set_errno_and_return_minus_one( ENOSYS ); } + +#if defined(RTEMS_COVERAGE) +pid_t __gcov_fork( void ); + +pid_t __gcov_fork( void ) +{ + rtems_set_errno_and_return_minus_one( ENOSYS ); +} +#endif diff --git a/cpukit/score/src/iodumpgcovinfo.c b/cpukit/score/src/iodumpgcovinfo.c new file mode 100644 index 0000000000..ecf780f9d7 --- /dev/null +++ b/cpukit/score/src/iodumpgcovinfo.c @@ -0,0 +1,100 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + +/** + * @file + * + * @ingroup RTEMSScoreIO + * + * @brief This source file contains the implementation of _IO_Dump_gcov_info(). + */ + +/* + * Copyright (C) 2021 embedded brains GmbH (http://www.embedded-brains.de) + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <rtems/score/io.h> +#include <rtems/score/interr.h> +#include <rtems/linkersets.h> + +#include <gcov.h> + +RTEMS_LINKER_ROSET( gcov_info, const struct gcov_info * ); + +typedef struct { + IO_Put_char put_char; + void *arg; +} IO_Dump_gcov_context; + +static void _IO_Gcov_filename( const char *f, void *arg ) +{ + const IO_Dump_gcov_context *ctx; + + ctx = arg; + _IO_Printf( ctx->put_char, ctx->arg, "Emitting gcda bytes for %s\n", f ); +} + +static void _IO_Gcov_dump( const void *d, unsigned n, void *arg ) +{ + const IO_Dump_gcov_context *ctx; + const unsigned char *c; + unsigned i; + + ctx = arg; + c = d; + + for (i = 0; i < n; ++i) { + _IO_Printf( ctx->put_char, ctx->arg, "%02x", c[ i ] ); + } +} + +static void *_IO_Gcov_allocate( unsigned length, void *arg ) +{ + (void) length; + (void) arg; + return NULL; +} + +void _IO_Dump_gcov_info( IO_Put_char put_char, void *arg ) +{ + IO_Dump_gcov_context ctx; + const struct gcov_info * const *item; + + ctx.put_char = put_char; + ctx.arg = arg; + + RTEMS_LINKER_SET_FOREACH( gcov_info, item ) { + __gcov_info_to_gcda( + *item, + _IO_Gcov_filename, + _IO_Gcov_dump, + _IO_Gcov_allocate, + &ctx + ); + ( *put_char )( '\n', arg ); + } +} diff --git a/spec/build/cpukit/cpuopts.yml b/spec/build/cpukit/cpuopts.yml index 301d49ccea..7cd59d2b63 100644 --- a/spec/build/cpukit/cpuopts.yml +++ b/spec/build/cpukit/cpuopts.yml @@ -36,6 +36,8 @@ links: - role: build-dependency uid: optbuildlabel - role: build-dependency + uid: optcoverage +- role: build-dependency uid: optdebug - role: build-dependency uid: optdrvmgr diff --git a/spec/build/cpukit/grp.yml b/spec/build/cpukit/grp.yml index f84419b675..d87d08ad56 100644 --- a/spec/build/cpukit/grp.yml +++ b/spec/build/cpukit/grp.yml @@ -12,6 +12,12 @@ links: - role: build-dependency uid: cfghdr - role: build-dependency + uid: optcflagscoverage +- role: build-dependency + uid: optcflagscoverageopt +- role: build-dependency + uid: optldflagscoverage +- role: build-dependency uid: libdebugger - role: build-dependency uid: libftpd diff --git a/spec/build/cpukit/librtemscpu.yml b/spec/build/cpukit/librtemscpu.yml index 965419c389..2cd453d42b 100644 --- a/spec/build/cpukit/librtemscpu.yml +++ b/spec/build/cpukit/librtemscpu.yml @@ -1,6 +1,8 @@ SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause build-type: library -cflags: [] +cflags: +- ${CFLAGS_COVERAGE} +- ${CFLAGS_COVERAGE_OPTIMIZATION} copyrights: - Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de) cppflags: [] @@ -1417,6 +1419,7 @@ source: - cpukit/score/src/heapwalk.c - cpukit/score/src/interr.c - cpukit/score/src/iobase64.c +- cpukit/score/src/iodumpgcovinfo.c - cpukit/score/src/ioprintf.c - cpukit/score/src/iorelax.c - cpukit/score/src/iovprintf.c diff --git a/spec/build/cpukit/librtemstest.yml b/spec/build/cpukit/librtemstest.yml index cba3dfcc02..87dfadd0d9 100644 --- a/spec/build/cpukit/librtemstest.yml +++ b/spec/build/cpukit/librtemstest.yml @@ -41,5 +41,6 @@ source: - cpukit/libtest/testparallel.c - cpukit/libtest/testrun.c - cpukit/libtest/testwrappers.c +- cpukit/libtest/wrapcpufatalhalt.c target: rtemstest type: build diff --git a/spec/build/cpukit/optcflagscoverage.yml b/spec/build/cpukit/optcflagscoverage.yml new file mode 100644 index 0000000000..f4fe6b5fcb --- /dev/null +++ b/spec/build/cpukit/optcflagscoverage.yml @@ -0,0 +1,22 @@ +SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause +actions: +- get-string: null +- split: null +- env-assign: null +- env-append: BSP_CFLAGS +build-type: option +copyrights: +- Copyright (C) 2021 embedded brains GmbH (http://www.embedded-brains.de) +default: +- -fprofile-arcs +- -fprofile-info-section=.rtemsroset.gcov_info.content +- -fprofile-update=atomic +- -ftest-coverage +default-by-variant: [] +description: | + C compiler flags recommended for components which should generate coverage + information if RTEMS_COVERAGE is enabled. +enabled-by: RTEMS_COVERAGE +links: [] +name: CFLAGS_COVERAGE +type: build diff --git a/spec/build/cpukit/optcflagscoverageopt.yml b/spec/build/cpukit/optcflagscoverageopt.yml new file mode 100644 index 0000000000..a8c08ba413 --- /dev/null +++ b/spec/build/cpukit/optcflagscoverageopt.yml @@ -0,0 +1,19 @@ +SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause +actions: +- get-string: null +- split: null +- env-assign: null +- env-append: BSP_CFLAGS +build-type: option +copyrights: +- Copyright (C) 2021 embedded brains GmbH (http://www.embedded-brains.de) +default: +- -O0 +default-by-variant: [] +description: | + C compiler optimization flags recommended for components which should + generate coverage information if RTEMS_COVERAGE is enabled. +enabled-by: RTEMS_COVERAGE +links: [] +name: CFLAGS_COVERAGE_OPTIMIZATION +type: build diff --git a/spec/build/cpukit/optcoverage.yml b/spec/build/cpukit/optcoverage.yml new file mode 100644 index 0000000000..3dcd6a5061 --- /dev/null +++ b/spec/build/cpukit/optcoverage.yml @@ -0,0 +1,16 @@ +SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause +actions: +- get-boolean: null +- env-enable: null +- define-condition: null +build-type: option +copyrights: +- Copyright (C) 2021 embedded brains GmbH (http://www.embedded-brains.de) +default: false +default-by-variant: [] +description: | + Enable the code coverage support. +enabled-by: true +links: [] +name: RTEMS_COVERAGE +type: build diff --git a/spec/build/cpukit/optldflagscoverage.yml b/spec/build/cpukit/optldflagscoverage.yml new file mode 100644 index 0000000000..5bdb0f6674 --- /dev/null +++ b/spec/build/cpukit/optldflagscoverage.yml @@ -0,0 +1,20 @@ +SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause +actions: +- get-string: null +- split: null +- env-append: LDFLAGS +build-type: option +copyrights: +- Copyright (C) 2021 embedded brains GmbH (http://www.embedded-brains.de) +default: +- -lrtemscpu +- -lgcov +- -Wl,--wrap=_CPU_Fatal_halt +default-by-variant: [] +description: | + Flags passed to the linker at the end of the link command if RTEMS_COVERAGE + is enabled. +enabled-by: RTEMS_COVERAGE +links: [] +name: LDFLAGS_COVERAGE +type: build |