|
1 | | -ESP-IDF Coverage |
2 | | -=============================== |
| 1 | +Code Coverage |
| 2 | +============= |
3 | 3 |
|
4 | | -Source code coverage is data indicating the count and frequency of every program execution path that has been taken within a program runtime. `GCOV <https://en.wikipedia.org/wiki/Gcov>`_ is a GCC tool that, when used in concert with the compiler, can generate log files indicating the execution count of each line of a source code. |
| 4 | +:link_to_translation:`zh_CN:[中文]` |
| 5 | + |
| 6 | +Source code coverage provides data indicating the count and frequency of every program execution path taken during runtime. `GCOV <https://en.wikipedia.org/wiki/Gcov>`_ is a GCC tool that, when used with the compiler, generates log files showing the execution count of each line of source code. |
5 | 7 |
|
6 | 8 | Your ESP-IDF project should be configured to generate ``gcda/gcno`` coverage files using ``gcov``. Please read `GCOV Code Coverage <https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/app_trace.html#gcov-source-code-coverage>`_ to learn more about code coverage with GCOV in ESP-IDF projects. |
7 | 9 |
|
8 | | -You can use the **ESP-IDF: Configure Project SDKConfig for Coverage** to set required configuration in the SDK Configuration Editor. |
| 10 | +You can use the ``ESP-IDF: Configure Project SDKConfig for Coverage`` to set the required configuration in the SDK Configuration Editor. |
| 11 | + |
9 | 12 |
|
10 | | -Code coverage example |
11 | | -------------------------------- |
| 13 | +Code Coverage Example |
| 14 | +--------------------- |
12 | 15 |
|
13 | 16 | Let's use the ESP-IDF `GCOV Example <https://github.com/espressif/esp-idf/tree/master/examples/system/gcov>`_ for this tutorial. |
14 | 17 |
|
15 | | -- Navigate to **View** > **Command Palette**. |
| 18 | +1. Navigate to ``View`` > ``Command Palette``. |
16 | 19 |
|
17 | | -- Type **ESP-IDF: New Project** and choose ESP-IDF version to use. |
| 20 | +2. Type ``ESP-IDF: New Project`` and choose ESP-IDF version to use. |
18 | 21 |
|
19 | | -If you don't see the option, please review the current ESP-IDF setup in :ref:`Installation <installation>`. |
| 22 | + .. note:: |
20 | 23 |
|
21 | | -- A window will be open with settings to configure the project. Later you can choose from a list a ESP-IDF examples, go the **system** section and choose the ``gcov``. You will see a **Create Project Using Example gcov** button in the top and a description of the project below. Click **Create Project Using Example GCOV** button. |
| 24 | + If you don't see the option, please review the current ESP-IDF setup in :ref:`Installation <installation>`. |
22 | 25 |
|
23 | | -.. image:: ../../../media/tutorials/coverage/gcov_example.png |
| 26 | +3. A window will open with settings to configure the project. Choose from a list of ESP-IDF examples, go to the ``system`` section, and select ``gcov``. You will see a ``Create Project Using Example GCOV`` button at the top and a project description below. Click ``Create Project Using Example GCOV``. |
24 | 27 |
|
25 | | -- Now select a container directory where to copy the example project. For example, if you choose ``/Users/myUser/someFolder`` the resulting folder will be ``/Users/myUser/someFolder/gcov``. This new project directory will be created and opened in Visual Studio Code. |
| 28 | + .. image:: ../../../media/tutorials/coverage/gcov_example.png |
26 | 29 |
|
27 | | -- First you should select an Espressif target (esp32, esp32s2, etc.) with: |
| 30 | +4. Select a container directory where to copy the example project. For example, if you choose ``/Users/myUser/someFolder``, the resulting folder will be ``/Users/myUser/someFolder/gcov``. This new project directory will be created and opened in Visual Studio Code. |
28 | 31 |
|
29 | | - - Navigate to **View** > **Command Palette**. |
30 | | - - Type **ESP-IDF: Set Espressif Device Target** command. Default is ``esp32`` and the one used in this tutorial. |
| 32 | +5. Select an Espressif target (esp32, esp32s2, etc.): |
31 | 33 |
|
32 | | -- Next configure your sdkconfig project with the **ESP-IDF: Configure Project SDKConfig for Coverage** command or by yourself using the **ESP-IDF: SDK Configuration Editor** command where you can modify the ESP-IDF project settings. After all changes are made, click save and close this window. |
| 34 | + - Navigate to ``View`` > ``Command Palette``. |
| 35 | + - Type ``ESP-IDF: Set Espressif Device Target`` command. The default target is ``esp32``, which is used in this tutorial. |
33 | 36 |
|
34 | | -.. image:: ../../../media/tutorials/basic_use/gui_menuconfig.png |
| 37 | +6. Configure your sdkconfig project with the ``ESP-IDF: Configure Project SDKConfig for Coverage`` command or manually using the ``ESP-IDF: SDK Configuration Editor`` command. After all changes are made, click ``Save`` and close the window. |
35 | 38 |
|
36 | | -- The example will enable the following options by default: |
| 39 | + .. image:: ../../../media/tutorials/basic_use/gui_menuconfig.png |
37 | 40 |
|
38 | | - - Enable the Application Tracing Module under ``Component Config`` > ``Application Level Tracing`` > ``Data Destination`` by choosing ``Trace Memory``. |
39 | | - - Enable GCOV to host interface under ``Component Config`` > ``Application Level Tracing`` > ``GCOV to Host Enable``. |
40 | | - - Enable OpenOCD Debug Stubs under ``Component Config`` > ``ESP32-specific`` > ``OpenOCD Debug Stubs``. |
| 41 | +7. The example will enable the following options by default: |
41 | 42 |
|
42 | | -- Now build the project, flash your device and start the ESP-IDF Monitor you can use the **ESP-IDF: Build your Project**, **ESP-IDF: Flash your Project** and **ESP-IDF: Monitor Device** commands. |
| 43 | + - Enable the Application Tracing Module under ``Component Config`` > ``Application Level Tracing`` > ``Data Destination`` by choosing ``Trace Memory``. |
| 44 | + - Enable GCOV to host interface under ``Component Config`` > ``Application Level Tracing`` > ``GCOV to Host Enable``. |
| 45 | + - Enable OpenOCD Debug Stubs under ``Component Config`` > ``ESP32-specific`` > ``OpenOCD Debug Stubs``. |
43 | 46 |
|
44 | | -.. note:: |
45 | | - There is also a **ESP-IDF: Build, Flash and Start a Monitor on your Device** command which does all three former commands in one. |
| 47 | +8. Build the project, flash your device, and start the ESP-IDF Monitor using the ``ESP-IDF: Build your Project``, ``ESP-IDF: Flash your Project``, and ``ESP-IDF: Monitor Device`` commands. |
46 | 48 |
|
47 | | -- Next step is to launch OpenOCD and send some commands. To start openOCD from the extension, execute the **ESP-IDF: OpenOCD Manager** command or from the ``OpenOCD Server (Running | Stopped)`` button in the Visual Studio Code status bar. OpenOCD server output is shown in menu **View** > **Output** > **ESP-IDF**. |
| 49 | + .. note:: |
| 50 | + |
| 51 | + There is also an ``ESP-IDF: Build, Flash and Start a Monitor on your Device`` command that combines all three commands. |
48 | 52 |
|
49 | | -- Launch a new terminal with menu **Terminal** > New Terminal and execute ``telnet <oocd_host> <oocd_port>`` which by default is ``telnet localhost 4444``. Latest MacOS users can use ``nc <oocd_host> <oocd_port>`` if ``telnet`` is not in the system. |
| 53 | +9. Launch OpenOCD and send some commands. To start OpenOCD from the extension, execute the ``ESP-IDF: OpenOCD Manager`` command or use the ``OpenOCD Server (Running | Stopped)`` button in the Visual Studio Code status bar. OpenOCD server output is shown in ``View`` > ``Output`` > ``ESP-IDF``. |
50 | 54 |
|
51 | | -.. note:: |
52 | | - you can modify **openocd.tcl.host** and **openocd.tcl.port** configuration settings to modify these values. |
| 55 | +10. Launch a new terminal with menu ``Terminal`` > ``New Terminal`` and execute ``telnet <oocd_host> <oocd_port>``, which defaults to ``telnet localhost 4444``. Latest macOS users can use ``nc <oocd_host> <oocd_port>`` if ``telnet`` is not available. |
53 | 56 |
|
54 | | -- Send the OpenOCD command ``esp gcov dump`` for hard-coded dump which will dump two hard-coded dumps based on this example. After that send the ``esp gcov`` command for instant run-time dump. |
| 57 | + .. note:: |
| 58 | + |
| 59 | + You can modify ``openocd.tcl.host`` and ``openocd.tcl.port`` configuration settings to change these values. |
55 | 60 |
|
56 | | -.. image:: ../../../media/tutorials/coverage/oocd_cmds.png |
| 61 | +11. Send the OpenOCD command ``esp gcov dump`` for a hard-coded dump, which will perform two hard-coded dumps based on this example. Then send the ``esp gcov`` command for an instant run-time dump. |
57 | 62 |
|
58 | | -- After dumping data one or more times, open the desired file in your editor and execute the **ESP-IDF: Add Editor Coverage** command to highlight the editor with code coverage. |
| 63 | + .. image:: ../../../media/tutorials/coverage/oocd_cmds.png |
59 | 64 |
|
60 | | -- You can customize highlight color using these extension settings.json configuration settings: |
| 65 | +12. After dumping data, open the desired file in your editor and execute the ``ESP-IDF: Add Editor Coverage`` command to highlight the editor with code coverage. |
61 | 66 |
|
62 | | - - Covered lines use **idf.coveredLightTheme** for light themes and **idf.coveredDarkTheme** for dark themes. |
63 | | - - Partially covered lines use **idf.partialLightTheme** for light themes and **idf.partialDarkTheme** for dark themes. |
64 | | - - Non-covered lines use **idf.uncoveredLightTheme** for light themes and **idf.uncoveredDarkTheme** for dark themes. |
| 67 | +13. You can customize the highlight color through the following configuration settings in the extension’s ``settings.json`` file: |
65 | 68 |
|
66 | | -Visual Studio code support ``"red"``, ``rgb(255,0,120)`` or ``rgba(120,0,0,0.1)``. |
| 69 | + - Covered lines use ``idf.coveredLightTheme`` for light themes and ``idf.coveredDarkTheme`` for dark themes. |
| 70 | + - Partially covered lines use ``idf.partialLightTheme`` for light themes and ``idf.partialDarkTheme`` for dark themes. |
| 71 | + - Non-covered lines use ``idf.uncoveredLightTheme`` for light themes and ``idf.uncoveredDarkTheme`` for dark themes. |
67 | 72 |
|
68 | | -.. image:: ../../../media/tutorials/coverage/editor_coverage.png |
| 73 | + Visual Studio Code supports ``red``, ``rgb(255,0,120)`` or ``rgba(120,0,0,0.1)``. |
69 | 74 |
|
70 | | -- When finished, use the **ESP-IDF: Remove Editor Coverage** command to remove the code coverage. |
| 75 | + .. image:: ../../../media/tutorials/coverage/editor_coverage.png |
71 | 76 |
|
72 | | -- Navigate to **View** > **Command Palette**. |
| 77 | +14. When finished, use the ``ESP-IDF: Remove Editor Coverage`` command to remove the code coverage. |
73 | 78 |
|
74 | | -- Type **ESP-IDF: Get HTML Coverage Report for Project** select the command to generate a HTML report for code coverage. |
| 79 | + - Navigate to ``View`` > ``Command Palette``. |
| 80 | + - Type ``ESP-IDF: Get HTML Coverage Report for Project`` and select the command to generate an HTML report for code coverage. |
75 | 81 |
|
76 | | -.. image:: ../../../media/tutorials/coverage/html_report.png |
| 82 | + .. image:: ../../../media/tutorials/coverage/html_report.png |
77 | 83 |
|
78 | 84 | .. note:: |
79 | | - * Check the :ref:`Troubleshooting <troubleshooting-section>` section if you have any issues. |
| 85 | + |
| 86 | + Check the :ref:`Troubleshooting <troubleshooting-section>` section if you encounter any issues. |
0 commit comments