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

Test coverage #1073

Merged
merged 5 commits into from
Dec 11, 2019
Merged

Test coverage #1073

merged 5 commits into from
Dec 11, 2019

Conversation

emye
Copy link

@emye emye commented Dec 10, 2019

Implements creation of local coverage reports using gcovr as stated in #1068

Example usage:

cmake -DBUILD_WITH_COVERAGE=yes ../
make all
make tests
make coverage

It will create a directory called coverage_output inside the CMAKE_BINARY_DIR directory, storing the html output from gcovr.

@codecov
Copy link

codecov bot commented Dec 10, 2019

Codecov Report

Merging #1073 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@          Coverage Diff           @@
##           master   #1073   +/-   ##
======================================
  Coverage    71.4%   71.4%           
======================================
  Files         148     148           
  Lines       17439   17439           
======================================
  Hits        12453   12453           
  Misses       4986    4986

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a55451b...969e6db. Read the comment docs.

Copy link
Collaborator

@piponazo piponazo left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution!

After some trial and error I could finally obtain the desired coverage reports 🎊 . It is important to note that the gcov and gcc versions must match. I had some issues because of that, since I have many gcc versions installed in my system and I the gcov version was not matching with the gcc one.

I left some suggestions to improve a little bit the code. Once these comments are addressed I will be happy to merge the changes.

CMakeLists.txt Outdated
@@ -8,6 +8,9 @@ project(exiv2
include(cmake/mainSetup.cmake REQUIRED)
include(CTest)

list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
include (gcovr)
Copy link
Collaborator

Choose a reason for hiding this comment

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

[minor] Although this is correct, we are trying in this project to not modify the CMAKE_MODULE_PATH internally so that we can clearly differentiate between the CMake provided modules and the ones provided by us.

Please remove line 11 and change line 12 to:

include(cmake/gcovr.cmake REQUIRED)

@@ -0,0 +1,16 @@
if(USE_GCOV)
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should create a option in the main CMakeLists.txt for this variable. Ideally we should reuse the existing one for remote coverage BUILD_WITH_COVERAGE.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Note that the line include(cmake/gcovr.cmake REQUIRED) should appear after that option.

Copy link
Author

Choose a reason for hiding this comment

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

@piponazo, should we continue using the new gcovr.cmake file, or should we append the code to BUILD_WITH_COVERAGE within the compilerFlags.cmake file?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I do not have a strong opinion about that. Either you add it in compilerFlags.cmake well separated from the "generic" compiler flags or you keep it in that new file. Up to you 😉

@@ -0,0 +1,16 @@
if(USE_GCOV)

SET(GCOVR gcovr)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Here we are assuming the existence of gcovr. Please, use find_program to check whether it exists:

https://cmake.org/cmake/help/v3.5/command/find_program.html


SET(GCC_COVERAGE_COMPILE_FLAGS "-fprofile-arcs -ftest-coverage")
SET(GCC_COVERAGE_LINK_FLAGS "-lgcov")
SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS}" )
Copy link
Collaborator

Choose a reason for hiding this comment

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

We are moving away from using CMAKE_CXX_FLAGS variables which is considered a bad practice in CMake. Instead of that, we should be using add_compile_options and add_link_options. However, the second one is only available from CMake 3.13 and therefore we keep using CMAKE_EXE_LINKER_FLAGS and CMAKE_SHARED_LINKER_FLAGS instead. You can take a look to the file cmake/compilerFlags.cmake to see some examples.

piponazo
piponazo previously approved these changes Dec 10, 2019
Copy link
Collaborator

@piponazo piponazo left a comment

Choose a reason for hiding this comment

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

There is only a missing piece (see the previous comment). I would appreciate if you add the additional changes, but I would not block the PR just because of that.

SET( CMAKE_EXE_LINKER_FLAGS "${CMAKE_LINKER_FLAGS} ${GCC_COVERAGE_LINK_FLAGS}" )
if(BUILD_WITH_COVERAGE)

find_program (GCOVR gcovr)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks for the changes.

The only missing piece would be to add a check after this line, something like:

if(NOT GCOVR)
  message(FATAL_ERROR "gcovr not found")
endif()

Copy link
Author

Choose a reason for hiding this comment

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

Just added the change. Thank you very much for the help!

Copy link
Author

Choose a reason for hiding this comment

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

@piponazo , there are some failures in the CI tests due to the lack of gcovr. If a user doesn't have it, should we just not apply the target?

Copy link
Member

Choose a reason for hiding this comment

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

@piponazo , there are some failures in the CI tests due to the lack of gcovr. If a user doesn't have it, should we just not apply the target?

I agree with that suggestion: gcovr is not essential for obtaining the test coverage data on the CI.

Copy link
Author

@emye emye Dec 11, 2019

Choose a reason for hiding this comment

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

@piponazo @D4N We've changed the if statement to if(GCOVR), and put the flags inside the if statement. That should solve the CI problem.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Fine for me as it is! Thank you a lot for the contribution 😄

Copy link
Author

Choose a reason for hiding this comment

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

Thank you! We greatly enjoyed this experience!

@mergify mergify bot dismissed piponazo’s stale review December 10, 2019 19:06

Pull request has been modified.

@D4N
Copy link
Member

D4N commented Dec 10, 2019

This looks very nice, thanks @emye and @piponazo!

@D4N
Copy link
Member

D4N commented Dec 11, 2019

Lgtm to me now! @piponazo what do you think?

@piponazo piponazo merged commit 24d6feb into Exiv2:master Dec 11, 2019
1div0 pushed a commit to 1div0/exiv2 that referenced this pull request Jun 7, 2020
* Compiles and runs

* Created gcovr reports in separate directory

* Improved style and degree of coverage

* Added error check for existence of gcovr

* CI test fixes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants