Skip to content

Commit

Permalink
Gcov: Enable Code coverage reporting over UART.
Browse files Browse the repository at this point in the history
This patch provides support for generating Code coverage reports.
The prj.conf needs to enable CONFIG_COVERAGE. Once enabled, the
code coverage data dump now comes via UART.
This data dump on the UART is triggered once the main
thread exits.

Next step is to save this data dump on file. Then run
scripts/gen_gcov_files.py with the serial console log as argument.

The last step would be be to run the gcovr. Use the following cmd
 gcovr -r . --html -o gcov_report/coverage.html --html-details

Currently supported architectures are ARM and x86.

Signed-off-by: Adithya Baglody <[email protected]>
  • Loading branch information
AdithyaBaglody authored and nashif committed Jan 16, 2019
1 parent e223cfa commit 71e90f9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions arch/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ config PRIVILEGED_STACK_TEXT_AREA

config KOBJECT_TEXT_AREA
int "Size if kobject text area"
default 512 if COVERAGE_GCOV
default 256 if (!SIZE_OPTIMIZATIONS || STACK_CANARIES || ARC)
default 256 if CODE_DATA_RELOCATION
default 128
Expand Down
12 changes: 12 additions & 0 deletions include/linker/common-rom.ld
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@
__object_access_end = .;
}
#endif

#ifdef CONFIG_COVERAGE_GCOV
/* Section needed by gcov when coverage is turned on.*/
SECTION_PROLOGUE (gcov, (OPTIONAL),)
{
PROVIDE_HIDDEN (__init_array_start = .);
KEEP (*(SORT(.init_array.*)))
KEEP (*(.init_array*))
PROVIDE_HIDDEN (__init_array_end = .);
} GROUP_LINK_IN(ROMABLE_REGION)
#endif /* CONFIG_COVERAGE_GCOV */

SECTION_PROLOGUE (devconfig, (OPTIONAL),)
{
__devconfig_start = .;
Expand Down
11 changes: 11 additions & 0 deletions kernel/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <logging/log_ctrl.h>
#include <tracing.h>
#include <stdbool.h>
#include <misc/gcov.h>

#define IDLE_THREAD_NAME "idle"
#define LOG_LEVEL CONFIG_KERNEL_LOG_LEVEL
Expand Down Expand Up @@ -156,6 +157,10 @@ void _bss_zero(void)
(void)memset(&__app_bss_start, 0,
((u32_t) &__app_bss_end - (u32_t) &__app_bss_start));
#endif
#ifdef CONFIG_COVERAGE_GCOV
(void)memset(&__gcov_bss_start, 0,
((u32_t) &__gcov_bss_end - (u32_t) &__gcov_bss_start));
#endif
}


Expand Down Expand Up @@ -252,6 +257,9 @@ static void bg_thread_main(void *unused1, void *unused2, void *unused3)

main();

/* Dump coverage data once the main() has exited. */
gcov_coverage_dump();

/* Terminate thread normally since it has no more work to do */
_main_thread->base.user_options &= ~K_ESSENTIAL;
}
Expand Down Expand Up @@ -453,6 +461,9 @@ extern uintptr_t __stack_chk_guard;
*/
FUNC_NORETURN void _Cstart(void)
{
/* gcov hook needed to get the coverage report.*/
gcov_static_init();

#ifdef CONFIG_MULTITHREADING
#ifdef CONFIG_ARCH_HAS_CUSTOM_SWAP_TO_MAIN
struct k_thread *dummy_thread = NULL;
Expand Down

0 comments on commit 71e90f9

Please sign in to comment.