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

Add coverage to CMake unit-tests #1860

Merged
merged 4 commits into from Jul 25, 2019

Conversation

@zfields
Copy link
Contributor

commented Jul 18, 2019

ch35880


  • [internal] Add coverage to CMake unit-tests #1860
@zfields

This comment has been minimized.

Copy link
Contributor Author

commented Jul 18, 2019

We need to eliminate non-production code from coverage statistics (i.e. mock_types.h shown below).

Scanning dependencies of target coverage
------------------------------------------------------------------------------
                           GCC Code Coverage Report
Directory: /home/zak/dev/GitHub/particle-iot/device-os/test/unit_tests
------------------------------------------------------------------------------
File                                       Lines    Exec  Cover   Missing
------------------------------------------------------------------------------
cloud/publish_vitals.cpp                     142     142   100%   
mock_types.h                                  13       6    46%   25,27,32,34,36,39,42
services/str_util.cpp                         30      30   100%   
------------------------------------------------------------------------------
TOTAL                                        185     178    96%
------------------------------------------------------------------------------
lines: 96.2% (178 out of 185)
branches: 48.9% (830 out of 1696)
@zfields

This comment has been minimized.

Copy link
Contributor Author

commented Jul 19, 2019

I corrected the coverage logic, and uncovered a mistake I make in my unit-testing... Ughhh!

Scanning dependencies of target coverage
------------------------------------------------------------------------------
                           GCC Code Coverage Report
Directory: /home/zak/dev/GitHub/particle-iot/device-os/test/unit_tests/../..
------------------------------------------------------------------------------
File                                       Lines    Exec  Cover   Missing
------------------------------------------------------------------------------
hal/src/stm32/bits/gthr-default.h              2       0     0%   38,40
services/src/str_util.cpp                     18      18   100%   
system/inc/active_object.h                     3       3   100%   
system/src/system_publish_vitals.cpp          47      37    78%   82,84-85,87,89-91,93-94,120
wiring/inc/spark_wiring_timer.h                9       0     0%   150,154,156,158,161,163,165,168,171
------------------------------------------------------------------------------
TOTAL                                         79      58    73%
------------------------------------------------------------------------------
lines: 73.4% (58 out of 79)
branches: 60.5% (23 out of 38)
Built target coverage

This PR is good to go!

@m-mcgowan

This comment has been minimized.

Copy link
Contributor

commented Jul 22, 2019

Zak and I tried this on OSX and hit some problems, mostly due to changes in gcovr since 3.4 thru 4.1.

We needed to use relative paths for the exclude directories and allow the gcov executable to be substituted when using gcc on OSX.

add_custom_target( coverage
  gcovr --gcov-executable ${GCOV} --root ${DEVICE_OS_DIR}   --gcov-exclude ../../test/unit_tests/.* --exclude ../../third_party --print-summary
  WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
)

A PoC to substitute the gcov executable,

set(GCOV gcov CACHE STRING "the gcov executable to use")

Ideally this would work by environment variables just like CXX and CC can be used to override the compiler used.

Update README.md to include required dependencies and how to generate coverage.

@zfields

This comment has been minimized.

Copy link
Contributor Author

commented Jul 24, 2019

A PoC to substitute the gcov executable,

set(GCOV gcov CACHE STRING "the gcov executable to use")
Ideally this would work by environment variables just like CXX and CC can be used to override the compiler used.

gcovr natively consumes the GCOV environment variable. I believe we were experiencing difficulties, because our --exclude syntax was incorrect during our testing.

zfields added 2 commits Jul 24, 2019
Updated to work with gcovr 4+
Updated helper paths to be REAL paths, as opposed to be indirect absolute paths.
Updated README.txt to provide coverage statistics

@zfields zfields force-pushed the gcov branch from 78f701f to ecb8a57 Jul 25, 2019

@m-mcgowan
Copy link
Contributor

left a comment

We worked through the problems and now it works on both OSX and Linux!

@zfields zfields merged commit 912b2d9 into develop Jul 25, 2019

3 checks passed

Codacy/PR Quality Review Up to standards. A positive pull request.
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details

@zfields zfields deleted the gcov branch Jul 25, 2019

@technobly technobly added this to the 1.3.1-rc.1 milestone Aug 20, 2019

@technobly technobly added the internal label Aug 20, 2019

@technobly technobly removed request for avtolstoy, sergeuz and technobly Aug 20, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.