{"action":"created","issue":{"url":"https://api.github.com/repos/ARMmbed/mbed-os/issues/2629","repository_url":"https://api.github.com/repos/ARMmbed/mbed-os","labels_url":"https://api.github.com/repos/ARMmbed/mbed-os/issues/2629/labels{/name}","comments_url":"https://api.github.com/repos/ARMmbed/mbed-os/issues/2629/comments","events_url":"https://api.github.com/repos/ARMmbed/mbed-os/issues/2629/events","html_url":"https://github.com/ARMmbed/mbed-os/pull/2629","id":175264249,"number":2629,"title":"Code Coverage using gcov","user":{"login":"mazimkhan","id":13520658,"avatar_url":"https://avatars.githubusercontent.com/u/13520658?v=3","gravatar_id":"","url":"https://api.github.com/users/mazimkhan","html_url":"https://github.com/mazimkhan","followers_url":"https://api.github.com/users/mazimkhan/followers","following_url":"https://api.github.com/users/mazimkhan/following{/other_user}","gists_url":"https://api.github.com/users/mazimkhan/gists{/gist_id}","starred_url":"https://api.github.com/users/mazimkhan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mazimkhan/subscriptions","organizations_url":"https://api.github.com/users/mazimkhan/orgs","repos_url":"https://api.github.com/users/mazimkhan/repos","events_url":"https://api.github.com/users/mazimkhan/events{/privacy}","received_events_url":"https://api.github.com/users/mazimkhan/received_events","type":"User","site_admin":false},"labels":[{"id":144902129,"url":"https://api.github.com/repos/ARMmbed/mbed-os/labels/needs:%20work","name":"needs: work","color":"fbca04","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":7,"created_at":"2016-09-06T14:37:52Z","updated_at":"2016-11-01T13:15:05Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/ARMmbed/mbed-os/pulls/2629","html_url":"https://github.com/ARMmbed/mbed-os/pull/2629","diff_url":"https://github.com/ARMmbed/mbed-os/pull/2629.diff","patch_url":"https://github.com/ARMmbed/mbed-os/pull/2629.patch"},"body":"# Code Coverage (GCOV)\n\nGCOV 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.\n## GCOV Impact on application\n\nEnabling 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. \n\nIt 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:\n\n```\n[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\n heap\n```\n\nor\n\n```\n[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\n-os/.build/tests/K64F/GCC_ARM/./TESTS/integration/basic/basic.elf section `.bss' will not fit in region `m_data_2'\n```\n\nHeap 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`.\n\nStill 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.\n## Build tools changes\n\nA new option is passed down `test.py` to `class GCC` that adds coverage flags to `gcc` compiler:\nOption synopsis:\n`--coverage-filter <regex to match source path> [--coverage-filter <regex to match source path>]` \nThis new option collects all supplied filters (regex) into a list. Coverage is turned on if list is not empty.\n\n`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()`.\n## Code changes\n\ngcov 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). \nMainly `open`, `write` and `close` wrappers in `retartget.cpp` are modified to channel gcov file data to serial console.\n"},"comment":{"url":"https://api.github.com/repos/ARMmbed/mbed-os/issues/comments/257563356","html_url":"https://github.com/ARMmbed/mbed-os/pull/2629#issuecomment-257563356","issue_url":"https://api.github.com/repos/ARMmbed/mbed-os/issues/2629","id":257563356,"user":{"login":"bogdanm","id":211717,"avatar_url":"https://avatars.githubusercontent.com/u/211717?v=3","gravatar_id":"","url":"https://api.github.com/users/bogdanm","html_url":"https://github.com/bogdanm","followers_url":"https://api.github.com/users/bogdanm/followers","following_url":"https://api.github.com/users/bogdanm/following{/other_user}","gists_url":"https://api.github.com/users/bogdanm/gists{/gist_id}","starred_url":"https://api.github.com/users/bogdanm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bogdanm/subscriptions","organizations_url":"https://api.github.com/users/bogdanm/orgs","repos_url":"https://api.github.com/users/bogdanm/repos","events_url":"https://api.github.com/users/bogdanm/events{/privacy}","received_events_url":"https://api.github.com/users/bogdanm/received_events","type":"User","site_admin":false},"created_at":"2016-11-01T13:15:05Z","updated_at":"2016-11-01T13:15:05Z","body":"Sorry, what do you mean by \"you can't enable coverage on whole code\"? Why?"}}
{"actor":{"display_login":"bogdanm"}}