From 02e084e2b5bb159fe1c9f0c5939de016b7d10038 Mon Sep 17 00:00:00 2001 From: Alexey Gerenkov Date: Tue, 1 Oct 2019 13:16:43 +0300 Subject: [PATCH 1/2] examples: Collects coverage info in component --- examples/system/gcov/README.md | 65 ++++++++++++------- .../gcov/components/sample/CMakeLists.txt | 6 ++ .../gcov/components/sample/component.mk | 6 ++ .../gcov/components/sample/some_funcs.c | 10 +++ examples/system/gcov/main/gcov_example_func.c | 2 +- examples/system/gcov/main/gcov_example_main.c | 2 + 6 files changed, 65 insertions(+), 26 deletions(-) create mode 100644 examples/system/gcov/components/sample/CMakeLists.txt create mode 100644 examples/system/gcov/components/sample/component.mk create mode 100644 examples/system/gcov/components/sample/some_funcs.c diff --git a/examples/system/gcov/README.md b/examples/system/gcov/README.md index c753d4f22c..3bd93810af 100644 --- a/examples/system/gcov/README.md +++ b/examples/system/gcov/README.md @@ -63,10 +63,12 @@ See the Getting Started Guide for full steps to configure and use ESP-IDF to bui The example will initially execute two hard-coded dumps. Therefore, when the application outputs `Ready to dump GCOV data...`, users should execute the `esp32 gcov dump` OpenOCD command. The example should output the following: ``` -Counter = 0 +blink_dummy_func: Counter = 0 +some_dummy_func: Counter = 0 Ready to dump GCOV data... GCOV data have been dumped. -Counter = 1 +blink_dummy_func: Counter = 1 +some_dummy_func: Counter = 2 Ready to dump GCOV data... GCOV data have been dumped. ``` @@ -76,15 +78,24 @@ GCOV data have been dumped. After the two hard-coded dumps, the example will continue looping through it's main blink function. Users can call `esp32 gcov` OpenOCD command to trigger an instant run-time dump. The output should resemble the following: ``` -Counter = 2 -Counter = 3 -Counter = 4 -Counter = 5 -Counter = 6 -Counter = 7 -Counter = 8 -Counter = 9 -Counter = 10 +blink_dummy_func: Counter = 2 +some_dummy_func: Counter = 4 +blink_dummy_func: Counter = 3 +some_dummy_func: Counter = 6 +blink_dummy_func: Counter = 4 +some_dummy_func: Counter = 8 +blink_dummy_func: Counter = 5 +some_dummy_func: Counter = 10 +blink_dummy_func: Counter = 6 +some_dummy_func: Counter = 12 +blink_dummy_func: Counter = 7 +some_dummy_func: Counter = 14 +blink_dummy_func: Counter = 8 +some_dummy_func: Counter = 16 +blink_dummy_func: Counter = 9 +some_dummy_func: Counter = 18 +blink_dummy_func: Counter = 10 +some_dummy_func: Counter = 20 ... ``` @@ -99,26 +110,30 @@ To clean Gcov and report related data from the build directory, call `cmake --bu The following log should be output when generating the coverage report: ``` -Generating coverage report in: /home/alexey/projects/esp/esp-idf/examples/system/gcov/build/coverage_report -Using gcov: ~/projects/esp/crosstool-NG/builds/xtensa-esp32-elf/bin/xtensa-esp32-elf-gcov -Capturing coverage data from /home/alexey/projects/esp/esp-idf/examples/system/gcov/build -Found gcov version: 5.2.0 -Scanning /home/alexey/projects/esp/esp-idf/examples/system/gcov/build for .gcda files ... -Found 2 data files in /home/alexey/projects/esp/esp-idf/examples/system/gcov/build -Processing main/gcov_example_func.gcda -Processing main/gcov_example.gcda +[1/1] Generating coverage report in: /home/user/projects/esp/tmp_idf/esp-idf/examples/system/gcov/build/coverage_report +Using gcov: xtensa-esp32-elf-gcov +Capturing coverage data from /home/user/projects/esp/tmp_idf/esp-idf/examples/system/gcov/build +Found gcov version: 8.2.0 +Using intermediate gcov format +Scanning /home/user/projects/esp/tmp_idf/esp-idf/examples/system/gcov/build for .gcda files ... +Found 3 data files in /home/user/projects/esp/tmp_idf/esp-idf/examples/system/gcov/build +Processing sample/CMakeFiles/__idf_sample.dir/some_funcs.c.gcda +Processing main/CMakeFiles/__idf_main.dir/gcov_example_func.c.gcda +Processing main/CMakeFiles/__idf_main.dir/gcov_example_main.c.gcda Finished .info-file creation -Reading data file /home/alexey/projects/esp/esp-idf/examples/system/gcov/build/coverage_report/gcov_example.info -Found 2 entries. -Found common filename prefix "/home/alexey/projects/esp/esp-idf/examples/system/gcov" +Reading data file /home/user/projects/esp/tmp_idf/esp-idf/examples/system/gcov/build/coverage_report/gcov_example.info +Found 4 entries. +Found common filename prefix "/home/user/projects/esp/tmp_idf/esp-idf/examples/system/gcov" Writing .css and .png files. Generating output. -Processing file main/gcov_example.c +Processing file /home/user/projects/esp/tmp_idf/esp-idf/components/freertos/include/freertos/task.h +Processing file components/sample/some_funcs.c +Processing file main/gcov_example_main.c Processing file main/gcov_example_func.c Writing directory view page. Overall coverage rate: - lines......: 90.0% (18 of 20 lines) - functions..: 100.0% (3 of 3 functions) + lines......: 100.0% (28 of 28 lines) + functions..: 100.0% (4 of 4 functions) ``` ## Troubleshooting diff --git a/examples/system/gcov/components/sample/CMakeLists.txt b/examples/system/gcov/components/sample/CMakeLists.txt new file mode 100644 index 0000000000..e83fb0e784 --- /dev/null +++ b/examples/system/gcov/components/sample/CMakeLists.txt @@ -0,0 +1,6 @@ +idf_component_register(SRCS "some_funcs.c" + INCLUDE_DIRS ".") + +set_source_files_properties(some_funcs.c + PROPERTIES COMPILE_FLAGS + --coverage) diff --git a/examples/system/gcov/components/sample/component.mk b/examples/system/gcov/components/sample/component.mk new file mode 100644 index 0000000000..ed258eda5a --- /dev/null +++ b/examples/system/gcov/components/sample/component.mk @@ -0,0 +1,6 @@ +# +# "main" pseudo-component makefile. +# +# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.) + +CFLAGS += --coverage diff --git a/examples/system/gcov/components/sample/some_funcs.c b/examples/system/gcov/components/sample/some_funcs.c new file mode 100644 index 0000000000..00084dfc2c --- /dev/null +++ b/examples/system/gcov/components/sample/some_funcs.c @@ -0,0 +1,10 @@ +#include + + +void some_dummy_func(void) +{ + static int i; + printf("some_dummy_func: Counter = %d\n", i++); + i++; +} + diff --git a/examples/system/gcov/main/gcov_example_func.c b/examples/system/gcov/main/gcov_example_func.c index b65b242dc1..7118f76d30 100644 --- a/examples/system/gcov/main/gcov_example_func.c +++ b/examples/system/gcov/main/gcov_example_func.c @@ -4,6 +4,6 @@ void blink_dummy_func(void) { static int i; - printf("Counter = %d\n", i++); + printf("blink_dummy_func: Counter = %d\n", i++); } diff --git a/examples/system/gcov/main/gcov_example_main.c b/examples/system/gcov/main/gcov_example_main.c index 5ded23b0d1..444361b1a8 100644 --- a/examples/system/gcov/main/gcov_example_main.c +++ b/examples/system/gcov/main/gcov_example_main.c @@ -19,6 +19,7 @@ #define BLINK_GPIO CONFIG_BLINK_GPIO void blink_dummy_func(void); +void some_dummy_func(void); static void blink_task(void *pvParameter) { @@ -43,6 +44,7 @@ static void blink_task(void *pvParameter) gpio_set_level(BLINK_GPIO, 1); vTaskDelay(500 / portTICK_PERIOD_MS); blink_dummy_func(); + some_dummy_func(); if (dump_gcov_after++ < 0) { // Dump gcov data printf("Ready to dump GCOV data...\n"); From 5b83b198c60394a9e544aaf239d2432c81c54a20 Mon Sep 17 00:00:00 2001 From: Alexey Gerenkov Date: Tue, 1 Oct 2019 20:42:32 +0300 Subject: [PATCH 2/2] gcov: Fixes libgcov and libapp_trace cross dependency linking issue Closes IDF-834 --- components/app_trace/CMakeLists.txt | 7 ++++++- examples/system/gcov/README.md | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/components/app_trace/CMakeLists.txt b/components/app_trace/CMakeLists.txt index b9bcdddccc..609c50cfff 100644 --- a/components/app_trace/CMakeLists.txt +++ b/components/app_trace/CMakeLists.txt @@ -33,4 +33,9 @@ idf_component_register(SRCS "${srcs}" # disable --coverage for this component, as it is used as transport # for gcov target_compile_options(${COMPONENT_LIB} PRIVATE "-fno-profile-arcs" "-fno-test-coverage") -target_link_libraries(${COMPONENT_LIB} PUBLIC gcov ${LIBC} ${LIBM} gcc) + +# Force app_trace to also appear later than gcov in link line +add_library(gcov_apptrace INTERFACE) +idf_component_get_property(app_trace app_trace COMPONENT_LIB) +target_link_libraries(gcov_apptrace INTERFACE $ gcov $) +target_link_libraries(${COMPONENT_LIB} PUBLIC gcov_apptrace ${LIBC}) diff --git a/examples/system/gcov/README.md b/examples/system/gcov/README.md index 3bd93810af..5404cb96de 100644 --- a/examples/system/gcov/README.md +++ b/examples/system/gcov/README.md @@ -5,7 +5,7 @@ The following example demonstrates how to compile an ESP-IDF project to generate code coverage data, and how generate a code coverage report using Gcov or Lcov. Refer to the [Gcov Guide](https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/app_trace.html#gcov-source-code-coverage) for more details on the code coverage features supported in ESP-IDF. This example implements a simple blink application but with code coverage enabled. The example will demonstrate the following features: -* How to compile a project with the `--coverage` flag +* How to compile a project with coverage info enabled. * Various methods of dumping code coverage data (e.g. Instant Run-Time Dump and Hard-coded Dump). * How to generate a code coverage report.