Merge lp:~mrazik/unity/coverage-support into lp:unity

Proposed by Martin Mrazik
Status: Merged
Approved by: Jussi Pakkanen
Approved revision: no longer in the source branch.
Merged at revision: 2941
Proposed branch: lp:~mrazik/unity/coverage-support
Merge into: lp:unity
Diff against target: 29 lines (+19/-0)
1 file modified
CMakeLists.txt (+19/-0)
To merge this branch: bzr merge lp:~mrazik/unity/coverage-support
Reviewer Review Type Date Requested Status
Jussi Pakkanen (community) Approve
PS Jenkins bot continuous-integration Pending
Thomas Voß Pending
Review via email: mp+136345@code.launchpad.net

Commit message

Adding -DCMAKE_BUILD_TYPE=coverage support as well as a custom coverage-xml target which is generated if gcovr is found on the system.

Description of the change

= Problem description =

This adds code coverage support to the build system by adding -DCMAKE_BUILD_TYPE=coverage and a custom coverage-xml target in case gcovr is installed.

= The fix =

CMakeLists.txt only change.

= Test coverage =

Build with -DCMAKE_BUILD_TYPE=coverage
https://jenkins.qa.ubuntu.com/job/unity-coverage-test/1/cobertura/?

Build log without -DCMAKE_BUILD_TYPE=coverage
https://jenkins.qa.ubuntu.com/job/unity-coverage-test/2/console

To post a comment you must log in.
Revision history for this message
Jussi Pakkanen (jpakkane) wrote :

The if clause on line 18 is incorrect and always evaluates to true. It should be written like this:

if (NOT GCOVR_EXECUTABLE)

Also, trying to run coverity tests without gcovr is an error. It does not provide any useful data, and only wastes time. The build system should stop with an error. This is simple, just change line 19 to this:

message(FATAL_ERROR "Cannot enable coverage targets because gcovr was not found.")

review: Needs Fixing
Revision history for this message
Jussi Pakkanen (jpakkane) wrote :

Also, the comment says "gcovr cannot write directly to a file", but 'gcovr -h' prints the following:

-o OUTPUT, --output=OUTPUT Print output to this filename

Does this not work? Does it not do the correct thing? Or is there something else afoot?

Revision history for this message
Martin Mrazik (mrazik) wrote :

> Also, the comment says "gcovr cannot write directly to a file", but 'gcovr -h'
> prints the following:
>
> -o OUTPUT, --output=OUTPUT Print output to this filename
>
> Does this not work? Does it not do the correct thing? Or is there something
> else afoot?

Thomas, can you answer this? I've copy&pasted this part from your project.

Revision history for this message
Martin Mrazik (mrazik) wrote :

> The if clause on line 18 is incorrect and always evaluates to true. It should
> be written like this:
>
> if (NOT GCOVR_EXECUTABLE)
>
> Also, trying to run coverity tests without gcovr is an error. It does not
> provide any useful data, and only wastes time. The build system should stop
> with an error. This is simple, just change line 19 to this:
>
> message(FATAL_ERROR "Cannot enable coverage targets because gcovr was not
> found.")

Thanks. These are fixed.

Revision history for this message
Jussi Pakkanen (jpakkane) wrote :

I can't run make check because it errors out with "No rule to make target `../tests/test-gtest', needed by `tests/CMakeFiles/check'. Stop." However if I just run "make coverage-xml", I get an XML file with no real content in it.

It would be nice if this was done automatically (by e.g. having a dependency between coverity-xml and tests) but I assume that Jenkins will automatically run these in the correct order so adding the dependency would run the tests twice.

This is not a blocker in any case, just would-be-nice-to-have speculation.

Revision history for this message
Martin Mrazik (mrazik) wrote :

Setting to WIP as I forgot about the MP and I'm using this branch in the jenkins job for a test. I'll switch back to Needs Review once I'm finished with the testing.

Revision history for this message
Martin Mrazik (mrazik) wrote :

> Also, the comment says "gcovr cannot write directly to a file", but 'gcovr -h'
> prints the following:
>
> -o OUTPUT, --output=OUTPUT Print output to this filename
>
> Does this not work? Does it not do the correct thing? Or is there something
> else afoot?

Fixed and here is a sample run with it:
https://jenkins.qa.ubuntu.com/job/unity-coverage-test/4/cobertura/?

Revision history for this message
Martin Mrazik (mrazik) wrote :

> I can't run make check because it errors out with "No rule to make target
> `../tests/test-gtest', needed by `tests/CMakeFiles/check'. Stop." However if
> I just run "make coverage-xml", I get an XML file with no real content in it.
>
> It would be nice if this was done automatically (by e.g. having a dependency
> between coverity-xml and tests) but I assume that Jenkins will automatically
> run these in the correct order so adding the dependency would run the tests
> twice.
>
> This is not a blocker in any case, just would-be-nice-to-have speculation.

I would prefer to leave this is up to you guys. TBH a coverage-html target should be also created (which would be using lcov) so you can check the coverage locally as well. This is a minimal support for coverage for jenkins. Not much more than that.

Revision history for this message
Jussi Pakkanen (jpakkane) wrote :

You really should not do 'cd "${CMAKE_BINARY_DIR}"', because that should already be the working directory and cd'ing around is strongly discouraged. Remove that (works fine without on my machine with a quick test). If you must set the working directory, use the WORKING_DIRECTORY option of add_custom_command.

Once this is fixed, this is ready to merge.

review: Needs Fixing
Revision history for this message
Martin Mrazik (mrazik) wrote :

Done.

Revision history for this message
Jussi Pakkanen (jpakkane) wrote :

Nice.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'CMakeLists.txt'
2--- CMakeLists.txt 2012-11-22 11:22:38 +0000
3+++ CMakeLists.txt 2012-11-29 12:56:21 +0000
4@@ -46,6 +46,25 @@
5 set (UNITY_STANDALONE_LADD "-lunity-core-${UNITY_API_VERSION} -lm -lpthread -ldl -lGL -lGLU")
6 endif ()
7
8+if (CMAKE_BUILD_TYPE MATCHES coverage)
9+ set (COVERAGE_XML_FILE "${CMAKE_BINARY_DIR}/coverage.xml")
10+
11+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage" )
12+ set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage" )
13+ set (CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} --coverage" )
14+ set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --coverage" )
15+
16+ find_program(GCOVR_EXECUTABLE gcovr HINTS ${GCOVR_ROOT} "${GCOVR_ROOT}/bin")
17+ if (NOT GCOVR_EXECUTABLE)
18+ message(FATAL_ERROR "Cannot enable coverage targets because gcovr was not found.")
19+ else ()
20+ message (STATUS "Enabling XML coverage report")
21+ add_custom_target (coverage-xml
22+ COMMAND "${GCOVR_EXECUTABLE}" --exclude="tests.*" --exclude="obj-.*" -x -r "${CMAKE_SOURCE_DIR}" -o "${COVERAGE_XML_FILE}")
23+ endif()
24+endif (CMAKE_BUILD_TYPE MATCHES coverage)
25+
26+
27 #
28 # Niceties
29 #