Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code Coverage using gcov #2629

Closed
wants to merge 11 commits into from
Closed

Code Coverage using gcov #2629

wants to merge 11 commits into from

Conversation

mazimkhan
Copy link

Code Coverage (GCOV)

GCOV based code coverage can be enabled by compiling and linking code with flags -fprofile-arcs -ftest-coverage. Optimisation should be disabled with flag -O0 and debug symbols added with -g flags. An additional coverage macro -DMBED_CFG_DEBUG_OPTIONS_COVERAGE is added to code the instrumentation required for moving coverage data from embedded platform to the host machine under it.

GCOV Impact on application

Enabling gcov profiling has an impact on binary size and stack requirement. Stack size has been increased in rtos/rtx/TARGET_CORTEX_M/cmsis_os.h under coverage macro.

It has not been possible to compile whole of mbed-os with coverage flags as it increases static data part of the binary making heap and stack overlap. Typically giving following error:

[DEBUG] Errors: c:/program files (x86)/gnu tools arm embedded/4.9 2015q3/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/bin/ld.exe: region m_data_2 overflowed with stack and
 heap

or

[DEBUG] Errors: c:/program files (x86)/gnu tools arm embedded/4.9 2015q3/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/bin/ld.exe: C:/Users/azikha01/Documents/GitHub/mazimkhan/mbed
-os/.build/tests/K64F/GCC_ARM/./TESTS/integration/basic/basic.elf section `.bss' will not fit in region `m_data_2'

Heap and stack size are reduced a little in below file to fit individual modules: hal/targets/cmsis/TARGET_Freescale/TARGET_MCU_K64F/TOOLCHAIN_GCC_ARM/MK64FN1M0xxx12.ld.

Still whole mbed-os does not fit the memory. For this reason below build tool changes are made to selectively turn On coverage on parts mbed-os source.

Build tools changes

A new option is passed down test.py to class GCC that adds coverage flags to gcc compiler:
Option synopsis:
--coverage-filter <regex to match source path> [--coverage-filter <regex to match source path>]
This new option collects all supplied filters (regex) into a list. Coverage is turned on if list is not empty.

test.py also enables coverage on test case sources when coverage filter is supplied. This is because for gcov to initialise it should also be enabled on the file containing main().

Code changes

gcov flags make the application write profiling data on disk per source file profiled. Embedded applications that do not have file-system require instrumentation to print coverage report on serial console that can be read and consolidated by a host application (greentea).
Mainly open, write and close wrappers in retartget.cpp are modified to channel gcov file data to serial console.

@mazimkhan
Copy link
Author

@c1728p9 @0xc0170 @bridadan @adbridge Please review

@@ -82,7 +82,12 @@

#endif

#if defined (MBED_CFG_DEBUG_OPTIONS_COVERAGE)
/* GCOV works with stack size approx. 32K. */
#define DEFAULT_STACK_SIZE (WORDS_STACK_SIZE*4*8)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be worth checking stack usage with a debugger to see how big this stack needs to be.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have two problems with this:

  • if "gcov works with stack size approx. 32k", that should be stated explicitly in the definition of DEFAULT_STACK_SIZE, rather than depending on the definition of another macro (WORDS_STACK_SIZE) that can change unexpectedly. In other words: #define DEFAULT_STACK_SIZE 32768.
  • that said, that's a pretty huge stack. Where is the "gcov works with stack size approx. 32k" coming from? I was not able to find this information with google.

@mazimkhan
Copy link
Author

@bogdanm please review.

/* Coverage sync flag used between greentea_client\source\test_env.cpp:greentea_notify_completion()
* and _open() to indicate that file is being open by gcov.
*/
bool coverage_report = false;
Copy link
Contributor

@bogdanm bogdanm Sep 8, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't greentea also need a change to work with this flag? Or is this covered in a separate PR (or maybe it already works with this flag)?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since greentea-client was taken from the yotta module used with mbed-os 3.0 this flag is already implemented in mbed-os/features/frameworks/greentea-client/source/test_env.cpp

@bogdanm
Copy link
Contributor

bogdanm commented Sep 8, 2016

Not yet ready to merge I think:

  • address @c1728p9's comments about the changed in the .ld file (since they don't seem to do what you expected them to do, is that affecting this PR in any way?)
  • figure out if the 32k stack size requirement for coverage is indeed a requirement
  • how does this work in combination with greentea? Does greentea use the same macro to figure out if coverage is enabled, or something else?

@mazimkhan
Copy link
Author

@bogdanm Yes not until all the comment here are satisfied.

@mazimkhan
Copy link
Author

retest uvisor

@bogdanm
Copy link
Contributor

bogdanm commented Nov 1, 2016

@mazimkhan, are you still looking at this? We need a way to enable code coverage.

@mazimkhan
Copy link
Author

mazimkhan commented Nov 1, 2016

Yes. This PR enables it. However you can't enable coverage on whole code. Hence looking into fast models.

@bogdanm
Copy link
Contributor

bogdanm commented Nov 1, 2016

Sorry, what do you mean by "you can't enable coverage on whole code"? Why?

@mazimkhan
Copy link
Author

Ok so we only compile a part of the source files with coverage flags to include coverage code introduced by gcov. This code inserted by gcov is extra to mbed-os code. When enabled on whole source the image size exceeds to fit K64F target.

@bogdanm
Copy link
Contributor

bogdanm commented Nov 1, 2016

Ah OK, I see now. Using --coverage-filter you can enable code coverage only on some parts of the code. That's perfect, thank you.

@bogdanm
Copy link
Contributor

bogdanm commented Nov 1, 2016

I can see some errors related to the "coverage filter" argument, for example https://travis-ci.org/ARMmbed/mbed-os/builds/169266037#L469. Does this need a retest?

@mazimkhan
Copy link
Author

Some of the failing jobs are not run any more. Those checks will stay. But two checks towards the bottom are passing.
Please try locally. It should build fine.

@sg-
Copy link
Contributor

sg- commented Nov 1, 2016

@mazimkhan Can we close this and re-open so current CI is only viewable and tested?

@mazimkhan
Copy link
Author

Sure. I will recreate it.

@mazimkhan mazimkhan closed this Nov 1, 2016
artokin pushed a commit to artokin/mbed-os that referenced this pull request Jun 22, 2021
…..4a3c5c5

4a3c5c5 Merge remote-tracking branch 'origin/release_internal' into release_external
2b8d2e1 Do not reset radio when MAC data request timeouts (ARMmbed#2647)
95c506a Frame counters for nw keys are now stored to NVM only after send key is set (ARMmbed#2641)
3b3010a Adjusted stagger random to [min,min+max] and for small nw set the stagger value to 10 seconds
02bc33a Adjusted security protocol (EAP-TLS,4WH,2WH) retry timers
eb26726 High Priority timestamp compare overflow support fix.
928723a FHSS WS: Initialize broadcast channel count when enabling FHSS (ARMmbed#2642)
6040d70 Updated change log
667b191 Changed initial EAPOL-key retries from trickle to exponential backup
d925145 Add RTT calculation for DHCP Time calculation
0b82953 Traceroute bug fix.
04de6e2 Merge pull request ARMmbed#2638 from PelionIoT/mbed_os_fix_ufsi_calculation
2012347 Fixed FHSS UFSI calculation unit tests
436f16e Handle timer rollover in calculate_ufsi
411cf5c coding style
d6f4421 Correct ufsi timing calculation
560619d Add network time vendor data element to DHCPv6 reply message
6d290dc System time read/write callbacks (ARMmbed#2637)
7905df6 Restart or remove transmission when MAC data request timeouts (ARMmbed#2636)
c97695c Bug fix: EAPOL parent compare fix
e283e62 Fixed channel mask usage with OFDM configurations (ARMmbed#2633)
24168f8 Do not send too old packets (ARMmbed#2632)
dbd83be Fix copyrights (ARMmbed#2631)
7f0cffd Merge pull request ARMmbed#2630 from PelionIoT/use_pelion_copyright
511bd5a Corrected coding style
57ec028 Corrected comparison
7d853de When EAPOL waiting queue is full oldest entry is removed
acf580f Update copyright in changed MDNS files
933c0bb Update copyright
3aeb2af Statistics for data request latencies (ARMmbed#2629)
3f7eae6 EAPOL FHSS temp entry discover
5200b66 DHCP time elapsed time write fix.
0536874 Removed empty EAPOL-key message send after 4WH completion to nodes on relay
8a2a683 Fixed DHCP wrong time elapsed value write.
283f2ee DHCPv6 update:
99be778 EAPOL temp neighbour update
4f9e3d1 Adaptation layer to remove oldest packet first
20f1f64 Added ignoring of retry messages from RADIUS server when waiting EAP-TLS
8a8b407 Add RSL check for ETX Calculation for RPL parent selection
c05e1da Fix DHCP server Uninitialized memory read
77229ee Fix CPP error from domain prefix check
7e47889 support filtering of EAPOL parents based device-min-sens configuration
618a191 Wi-SUN Expedite forward state update
4371462 Fix NULL read from RPL header addition
7802c7e Update CHANGELOG.md
b2c8104 CHANGELOG for Nanostack v13.0.0 (ARMmbed#2615)

git-subtree-dir: features/nanostack/sal-stack-nanostack
git-subtree-split: 4a3c5c5
artokin pushed a commit to artokin/mbed-os that referenced this pull request Jun 23, 2021
…903b81..4a3c5c5

4a3c5c5 Merge remote-tracking branch 'origin/release_internal' into release_external
2b8d2e1 Do not reset radio when MAC data request timeouts (ARMmbed#2647)
95c506a Frame counters for nw keys are now stored to NVM only after send key is set (ARMmbed#2641)
3b3010a Adjusted stagger random to [min,min+max] and for small nw set the stagger value to 10 seconds
02bc33a Adjusted security protocol (EAP-TLS,4WH,2WH) retry timers
eb26726 High Priority timestamp compare overflow support fix.
928723a FHSS WS: Initialize broadcast channel count when enabling FHSS (ARMmbed#2642)
6040d70 Updated change log
667b191 Changed initial EAPOL-key retries from trickle to exponential backup
d925145 Add RTT calculation for DHCP Time calculation
0b82953 Traceroute bug fix.
04de6e2 Merge pull request ARMmbed#2638 from PelionIoT/mbed_os_fix_ufsi_calculation
2012347 Fixed FHSS UFSI calculation unit tests
436f16e Handle timer rollover in calculate_ufsi
411cf5c coding style
d6f4421 Correct ufsi timing calculation
560619d Add network time vendor data element to DHCPv6 reply message
6d290dc System time read/write callbacks (ARMmbed#2637)
7905df6 Restart or remove transmission when MAC data request timeouts (ARMmbed#2636)
c97695c Bug fix: EAPOL parent compare fix
e283e62 Fixed channel mask usage with OFDM configurations (ARMmbed#2633)
24168f8 Do not send too old packets (ARMmbed#2632)
dbd83be Fix copyrights (ARMmbed#2631)
7f0cffd Merge pull request ARMmbed#2630 from PelionIoT/use_pelion_copyright
511bd5a Corrected coding style
57ec028 Corrected comparison
7d853de When EAPOL waiting queue is full oldest entry is removed
acf580f Update copyright in changed MDNS files
933c0bb Update copyright
3aeb2af Statistics for data request latencies (ARMmbed#2629)
3f7eae6 EAPOL FHSS temp entry discover
5200b66 DHCP time elapsed time write fix.
0536874 Removed empty EAPOL-key message send after 4WH completion to nodes on relay
8a2a683 Fixed DHCP wrong time elapsed value write.
283f2ee DHCPv6 update:
99be778 EAPOL temp neighbour update
4f9e3d1 Adaptation layer to remove oldest packet first
20f1f64 Added ignoring of retry messages from RADIUS server when waiting EAP-TLS
8a8b407 Add RSL check for ETX Calculation for RPL parent selection
c05e1da Fix DHCP server Uninitialized memory read
77229ee Fix CPP error from domain prefix check
7e47889 support filtering of EAPOL parents based device-min-sens configuration
618a191 Wi-SUN Expedite forward state update
4371462 Fix NULL read from RPL header addition
7802c7e Update CHANGELOG.md
b2c8104 CHANGELOG for Nanostack v13.0.0 (ARMmbed#2615)

git-subtree-dir: connectivity/nanostack/sal-stack-nanostack
git-subtree-split: 4a3c5c5
artokin pushed a commit to artokin/mbed-os that referenced this pull request Jun 28, 2021
…903b81..4a3c5c5

4a3c5c5 Merge remote-tracking branch 'origin/release_internal' into release_external
2b8d2e1 Do not reset radio when MAC data request timeouts (ARMmbed#2647)
95c506a Frame counters for nw keys are now stored to NVM only after send key is set (ARMmbed#2641)
3b3010a Adjusted stagger random to [min,min+max] and for small nw set the stagger value to 10 seconds
02bc33a Adjusted security protocol (EAP-TLS,4WH,2WH) retry timers
eb26726 High Priority timestamp compare overflow support fix.
928723a FHSS WS: Initialize broadcast channel count when enabling FHSS (ARMmbed#2642)
6040d70 Updated change log
667b191 Changed initial EAPOL-key retries from trickle to exponential backup
d925145 Add RTT calculation for DHCP Time calculation
0b82953 Traceroute bug fix.
04de6e2 Merge pull request ARMmbed#2638 from PelionIoT/mbed_os_fix_ufsi_calculation
2012347 Fixed FHSS UFSI calculation unit tests
436f16e Handle timer rollover in calculate_ufsi
411cf5c coding style
d6f4421 Correct ufsi timing calculation
560619d Add network time vendor data element to DHCPv6 reply message
6d290dc System time read/write callbacks (ARMmbed#2637)
7905df6 Restart or remove transmission when MAC data request timeouts (ARMmbed#2636)
c97695c Bug fix: EAPOL parent compare fix
e283e62 Fixed channel mask usage with OFDM configurations (ARMmbed#2633)
24168f8 Do not send too old packets (ARMmbed#2632)
dbd83be Fix copyrights (ARMmbed#2631)
7f0cffd Merge pull request ARMmbed#2630 from PelionIoT/use_pelion_copyright
511bd5a Corrected coding style
57ec028 Corrected comparison
7d853de When EAPOL waiting queue is full oldest entry is removed
acf580f Update copyright in changed MDNS files
933c0bb Update copyright
3aeb2af Statistics for data request latencies (ARMmbed#2629)
3f7eae6 EAPOL FHSS temp entry discover
5200b66 DHCP time elapsed time write fix.
0536874 Removed empty EAPOL-key message send after 4WH completion to nodes on relay
8a2a683 Fixed DHCP wrong time elapsed value write.
283f2ee DHCPv6 update:
99be778 EAPOL temp neighbour update
4f9e3d1 Adaptation layer to remove oldest packet first
20f1f64 Added ignoring of retry messages from RADIUS server when waiting EAP-TLS
8a8b407 Add RSL check for ETX Calculation for RPL parent selection
c05e1da Fix DHCP server Uninitialized memory read
77229ee Fix CPP error from domain prefix check
7e47889 support filtering of EAPOL parents based device-min-sens configuration
618a191 Wi-SUN Expedite forward state update
4371462 Fix NULL read from RPL header addition
7802c7e Update CHANGELOG.md
b2c8104 CHANGELOG for Nanostack v13.0.0 (ARMmbed#2615)

git-subtree-dir: connectivity/nanostack/sal-stack-nanostack
git-subtree-split: 4a3c5c5
artokin pushed a commit to artokin/mbed-os that referenced this pull request Jun 28, 2021
…..4a3c5c5

4a3c5c5 Merge remote-tracking branch 'origin/release_internal' into release_external
2b8d2e1 Do not reset radio when MAC data request timeouts (ARMmbed#2647)
95c506a Frame counters for nw keys are now stored to NVM only after send key is set (ARMmbed#2641)
3b3010a Adjusted stagger random to [min,min+max] and for small nw set the stagger value to 10 seconds
02bc33a Adjusted security protocol (EAP-TLS,4WH,2WH) retry timers
eb26726 High Priority timestamp compare overflow support fix.
928723a FHSS WS: Initialize broadcast channel count when enabling FHSS (ARMmbed#2642)
6040d70 Updated change log
667b191 Changed initial EAPOL-key retries from trickle to exponential backup
d925145 Add RTT calculation for DHCP Time calculation
0b82953 Traceroute bug fix.
04de6e2 Merge pull request ARMmbed#2638 from PelionIoT/mbed_os_fix_ufsi_calculation
2012347 Fixed FHSS UFSI calculation unit tests
436f16e Handle timer rollover in calculate_ufsi
411cf5c coding style
d6f4421 Correct ufsi timing calculation
560619d Add network time vendor data element to DHCPv6 reply message
6d290dc System time read/write callbacks (ARMmbed#2637)
7905df6 Restart or remove transmission when MAC data request timeouts (ARMmbed#2636)
c97695c Bug fix: EAPOL parent compare fix
e283e62 Fixed channel mask usage with OFDM configurations (ARMmbed#2633)
24168f8 Do not send too old packets (ARMmbed#2632)
dbd83be Fix copyrights (ARMmbed#2631)
7f0cffd Merge pull request ARMmbed#2630 from PelionIoT/use_pelion_copyright
511bd5a Corrected coding style
57ec028 Corrected comparison
7d853de When EAPOL waiting queue is full oldest entry is removed
acf580f Update copyright in changed MDNS files
933c0bb Update copyright
3aeb2af Statistics for data request latencies (ARMmbed#2629)
3f7eae6 EAPOL FHSS temp entry discover
5200b66 DHCP time elapsed time write fix.
0536874 Removed empty EAPOL-key message send after 4WH completion to nodes on relay
8a2a683 Fixed DHCP wrong time elapsed value write.
283f2ee DHCPv6 update:
99be778 EAPOL temp neighbour update
4f9e3d1 Adaptation layer to remove oldest packet first
20f1f64 Added ignoring of retry messages from RADIUS server when waiting EAP-TLS
8a8b407 Add RSL check for ETX Calculation for RPL parent selection
c05e1da Fix DHCP server Uninitialized memory read
77229ee Fix CPP error from domain prefix check
7e47889 support filtering of EAPOL parents based device-min-sens configuration
618a191 Wi-SUN Expedite forward state update
4371462 Fix NULL read from RPL header addition
7802c7e Update CHANGELOG.md
b2c8104 CHANGELOG for Nanostack v13.0.0 (ARMmbed#2615)

git-subtree-dir: features/nanostack/sal-stack-nanostack
git-subtree-split: 4a3c5c5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants