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

Enhancements to Unit Testing, Code Coverage Reporting, and CI Build Process #45

Open
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

plops
Copy link

@plops plops commented Feb 4, 2024

This pull request introduces several improvements to the project's testing and continuous integration (CI) workflow. Below is a summary of the changes:

  1. Unit Tests:

    • A set of new unit tests has been added to the tests/ directory. I kept it very simple and only implemented three tests.
    • Modifications to CMakeLists.txt now allow these tests to be included in the build when the -DDENABLE_GEOM2D_UNIT_TESTS=ON option is provided. I only tested this on Linux, though.
  2. GitHub Actions for CI:

    • A GitHub Action workflow has been set up to automate the build and test process. This is configured in the .github/workflows/code_coverage.yml file.
    • With this workflow in place, every commit pushed to the repository will trigger a virtual machine with Ubuntu 22 to spin up, execute the build, run the unit tests, and generate a code coverage report.
  3. Code Coverage Report:

    • The code coverage report is archived as a ZIP file after the GitHub Action completes. This file can be retrieved from the "Actions" tab on the GitHub repository page.
    • Although not yet implemented, there is potential to publish the coverage report to codecov.io. Guidance on integrating with codecov.io can be found here: CMake Coverage Example with GitHub Actions and codecov.io.
  4. Current Limitation:

    • There is an issue with the gcovr tool, which is preventing the generation of the code coverage report.

This pull request aims to bolster the robustness of our codebase and improve the visibility of our testing efforts. Your review and feedback are welcome.

Example output of the unit test:

[==========] Running 3 tests from 1 test suite.
[----------] Global test environment set-up.
[----------] 3 tests from CircleTest
[ RUN      ] CircleTest.circle_contains_PointOnCircleBoundary_True
[       OK ] CircleTest.circle_contains_PointOnCircleBoundary_True (0 ms)
[ RUN      ] CircleTest.circleContains_PointIsInside_True
[       OK ] CircleTest.circleContains_PointIsInside_True (0 ms)
[ RUN      ] CircleTest.circleContains_PointIsOutside_False
[       OK ] CircleTest.circleContains_PointIsOutside_False (0 ms)
[----------] 3 tests from CircleTest (0 ms total)

[----------] Global test environment tear-down
[==========] 3 tests from 1 test suite ran. (0 ms total)
[  PASSED  ] 3 tests.

Screenshots of the code coverage report:

As it the code is in only one header file this listing is not very useful:
2024-02-04-193155_1091x255_scrot

When you click on the file, you can see the lines highlighted, that were executed during the unit tests:
2024-02-04-193237_889x201_scrot

-- Detecting CXX compile features - done
24
CMake Error at /usr/local/share/cmake-3.28/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
25
  Could NOT find OpenGL (missing: OPENGL_opengl_LIBRARY OPENGL_glx_LIBRARY
26
  OPENGL_INCLUDE_DIR)
27
Call Stack (most recent call first):
28
  /usr/local/share/cmake-3.28/Modules/FindPackageHandleStandardArgs.cmake:600 (_FPHSA_FAILURE_MESSAGE)
29
  /usr/local/share/cmake-3.28/Modules/FindOpenGL.cmake:545 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
30
  CMakeLists.txt:45 (find_package)
31
-- Configuring incomplete, errors occurred!
32
Error: Process completed with exit code 1.
Build with Ninja
0s
1
Run ninja -C build test
2
  ninja -C build test
3
  shell: /usr/bin/bash -e {0}
4
ninja: Entering directory `build'
5
ninja: error: unknown target 'test', did you mean 'help'?
6
Error: Process completed with exit code 1.
Collect coverage
Run ninja -C build cov
2
  ninja -C build cov
3
  lcov --list build/coverage.info
4
  shell: /usr/bin/bash -e {0}
5
ninja: Entering directory `build'
6
[1/1] Generating cov.info
7
FAILED: cov.info /home/runner/work/olcUTIL_Geometry2D/olcUTIL_Geometry2D/build/cov.info
8
cd /home/runner/work/olcUTIL_Geometry2D/olcUTIL_Geometry2D/build && /usr/bin/lcov -c -o cov.info -d . -b . --gcov-tool /usr/bin/gcov --ignore-errors mismatch && /usr/bin/lcov -r cov.info -o cov.info */tests/* */googletest/* */g++*/bits/* '*/g++-v13/*' && /usr/bin/lcov -l cov.info && /usr/bin/genhtml cov.info -output coverage && /usr/bin/lcov -l cov.info 2>/dev/null | grep Total | sed 's/|//g' | sed 's/Total://g' | awk '{print }' | sed s/%//g > coverage/total
9
Capturing coverage data from .
10
Subroutine read_intermediate_text redefined at /usr/bin/geninfo line 2623.
11
Subroutine read_intermediate_json redefined at /usr/bin/geninfo line 2655.
12
Subroutine intermediate_text_to_info redefined at /usr/bin/geninfo line 2703.
13
Subroutine intermediate_json_to_info redefined at /usr/bin/geninfo line 2792.
14
Subroutine get_output_fd redefined at /usr/bin/geninfo line 2872.
15
Subroutine print_gcov_warnings redefined at /usr/bin/geninfo line 2900.
16
Subroutine process_intermediate redefined at /usr/bin/geninfo line 2930.
17
Found gcov version: 11.4.0
18
geninfo: ERROR: unknown argument for --ignore-errors: mismatch
19
Using intermediate gcov format
20
ninja: build stopped: subcommand failed.
21
Error: Process completed with exit code 1.
Generate JSON coverage report
lcov: ERROR: cannot read file build/coverage.info!
85
Reading tracefile build/coverage.info
86
Error: Process completed with exit code 9.
Generate JSON coverage report
@OneLoneCoder
Copy link
Owner

Firstly thanks for doing this!

Secondly, I'm utterly out of my depth with this sort of thing, so I've given this PR some visibility on the discord server. It'll take me a little while to understand what all this is for (by that i mean, of course i get whats happening, but ive not used git and github in this way before).

So please bear with me while I learn about it 😄

@plops
Copy link
Author

plops commented Feb 5, 2024

The coverage report consistently shows 100% due to the project being header-only. This does not reflect actual coverage. I found a Stack Overflow thread discussing better coverage for such libraries, which I'm still reviewing: https://stackoverflow.com/questions/9666800/getting-useful-gcov-results-for-header-only-libraries

Meanwhile, the colored lines in the HTML report help visually indicate tested lines.

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.

2 participants