Skip to content

Commit e9d7fb0

Browse files
committed
integration of llvm-cov + force-cover + lcov style reports
Fix typo in forceCover build step name
1 parent f6aae96 commit e9d7fb0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+4708
-74
lines changed

.github/workflows/Coverage.yml

Lines changed: 53 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,42 +15,76 @@ on:
1515
- '.gitignore'
1616
- 'README.md'
1717
- 'LICENSE'
18-
18+
1919
permissions:
2020
contents: read
2121

2222
jobs:
2323
Coverage_Testing:
2424
runs-on: ubuntu-latest
2525
steps:
26-
- uses: actions/checkout@v3
26+
- uses: actions/checkout@v4
2727
with:
2828
ref: master
29-
- name: Install Dependencies
30-
run : sudo apt-get update && sudo apt-get install libgl1-mesa-dev libx11-dev libxi-dev libxrandr-dev libxinerama-dev libxcursor-dev lcov
31-
- name: configure
32-
run: mkdir build && cd build && cmake .. -DCMAKE_BUILD_TYPE=Debug -DUSE_EZ_LIBS_TESTING=ON -DUSE_CODE_COVERAGE=ON -DUSE_EZ_EXPR_PERFOS_GENERATION=ON
33-
- name: build
34-
run: cmake --build build --config Debug
35-
- name: ctest
36-
run: ctest --test-dir build --output-on-failure
37-
- name: Install gcovr
38-
run: pip install gcovr==8.2
39-
- name: generate coverage
40-
run: cmake --build build --config Debug --target cov && mkdir -p ./build/coverage_web && mv ./build/Tests/coverage.html ./build/coverage_web/index.html
29+
fetch-depth: 0 # recommended for Codecov
30+
31+
- name: Install Clang/LLVM + deps
32+
run: |
33+
sudo apt-get update
34+
sudo apt-get install -y clang llvm llvm-dev libclang-dev lcov python3-pip git \
35+
libgl1-mesa-dev libx11-dev libxi-dev libxrandr-dev libxinerama-dev libxcursor-dev
36+
CLANG_MAJOR=$(clang -dumpversion | cut -d. -f1 || true)
37+
if [ -n "$CLANG_MAJOR" ]; then
38+
sudo apt-get install -y "libclang-rt-${CLANG_MAJOR}-dev" || true
39+
fi
40+
41+
- name: Configure (Clang + LLVM source-based coverage)
42+
env:
43+
CC: clang
44+
CXX: clang++
45+
run: |
46+
cmake -S . -B build \
47+
-DCMAKE_BUILD_TYPE=Debug \
48+
-DUSE_EZ_LIBS_TESTING=ON \
49+
-DUSE_CODE_COVERAGE=ON \
50+
-DCOVERAGE_VERBOSE=ON \
51+
-DUSE_EZ_EXPR_PERFOS_GENERATION=ON
52+
53+
- name: Builf forceCover
54+
run: cmake --build build --target forceCover -j 12
55+
56+
- name: Run forceCover
57+
run: cmake --build build --target forcecover_prep -j 12
58+
59+
- name: Build tests
60+
run: cmake --build build -j 12
61+
62+
- name: Generate coverage
63+
run: |
64+
cmake --build build --target cov -j 12
65+
mkdir -p build/coverage_web
66+
cp -r build/Tests/coverage_lcov/* build/coverage_web/
67+
68+
- name: upload artifact
69+
uses: actions/upload-artifact@v4
70+
with:
71+
name: coverage_bundle.tar.gz
72+
path: build/Tests/coverage_bundle.tar.gz
73+
4174
- name: Setup web pages
4275
uses: actions/configure-pages@v5
76+
4377
- name: Upload coverage web pages
44-
uses: actions/upload-pages-artifact@v3
78+
uses: actions/upload-pages-artifact@v3
4579
with:
4680
path: ./build/coverage_web
47-
- name: Upload coverage xml to Codecov
81+
82+
- name: Upload coverage to Codecov (LCOV)
4883
uses: codecov/codecov-action@v5
4984
with:
50-
fail_ci_if_error: true
51-
disable_search: true
52-
files: ./build/Tests/coverage.xml
85+
files: ./build/Tests/lcov.info
5386
token: ${{ secrets.CODECOV_TOKEN }}
87+
fail_ci_if_error: true
5488
verbose: true
5589

5690
deploy-coverage:

CMakeLists.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,25 @@
11
cmake_minimum_required(VERSION 3.20)
2+
3+
# --- Force Clang on Linux ---
4+
if(UNIX AND NOT APPLE)
5+
if(NOT DEFINED CMAKE_C_COMPILER AND NOT DEFINED CMAKE_CXX_COMPILER)
6+
find_program(_CLANG NAMES clang)
7+
find_program(_CLANGXX NAMES clang++)
8+
if(_CLANG AND _CLANGXX)
9+
set(CMAKE_C_COMPILER "${_CLANG}" CACHE FILEPATH "" FORCE)
10+
set(CMAKE_CXX_COMPILER "${_CLANGXX}" CACHE FILEPATH "" FORCE)
11+
message(STATUS "Using Clang: C=${_CLANG} CXX=${_CLANGXX}")
12+
else()
13+
message(FATAL_ERROR "Clang not found on Linux. Please install clang/clang++.")
14+
endif()
15+
endif()
16+
endif()
17+
218
project(ezLibs)
19+
320
set(CMAKE_CXX_STANDARD 11)
21+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
22+
set(CMAKE_CXX_EXTENSIONS OFF)
423

524
option(USE_EZ_LIBS_TESTING "Enable ezLibs testing" OFF)
625

Makefile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
all:
2+
make clean
3+
make configure
4+
make preBuildCoverage
5+
make buildTests
6+
make coverage
7+
8+
clean:
9+
rm -rf build
10+
rm -rf TestResults
11+
12+
configure:
13+
cmake -B build -DUSE_CODE_COVERAGE=ON -DCOVERAGE_VERBOSE=ON
14+
15+
preBuildCoverage:
16+
cmake --build build --target forceCover -j 12
17+
cmake --build build --target forcecover_prep -j 12
18+
19+
buildTests:
20+
cmake --build build -j 12
21+
22+
test:
23+
ctest --test-dir build --output-on-failure -j 12
24+
25+
coverage:
26+
cmake --build build --target cov -j 12

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
[![Win](https://github.com/aiekick/EzLibs/actions/workflows/Win.yml/badge.svg)](https://github.com/aiekick/EzLibs/actions/workflows/Win.yml)
22
[![Linux](https://github.com/aiekick/EzLibs/actions/workflows/Linux.yml/badge.svg)](https://github.com/aiekick/EzLibs/actions/workflows/Linux.yml)
3-
[![Osx](https://github.com/aiekick/EzLibs/actions/workflows/Osx.yml/badge.svg)](https://github.com/aiekick/EzLibs/actions/workflows/Osx.yml)
43
[![Code Coverage](https://github.com/aiekick/ezLibs/actions/workflows/Coverage.yml/badge.svg)](https://aiekick.github.io/ezLibs)
54
[![codecov](https://codecov.io/github/aiekick/EzLibs/graph/badge.svg?token=JSOD4SG2OU)](https://codecov.io/github/aiekick/EzLibs)
65
[![CodeFactor](https://www.codefactor.io/repository/github/aiekick/ezlibs/badge/master)](https://www.codefactor.io/repository/github/aiekick/ezlibs/overview/master)

Tests/CMakeLists.txt

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,45 @@ option(TESTING_OPENGL "Enable testing of Opengl related libs" ON)
1717
option(TESTING_TIME "Enable testing of Time related libs" ON)
1818
option(TESTING_GEO "Enable testing of Geo related libs" ON)
1919

20+
set(CMAKE_CXX_STANDARD 11)
21+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
22+
set(CMAKE_CXX_EXTENSIONS OFF)
23+
2024
if (USE_LEAK_SANITIZER)
2125
add_compile_options(-fexceptions -pthread -ldl -lGL -Wall -g -fsanitize=undefined -fno-sanitize-recover -fsanitize=float-cast-overflow -fsanitize=leak -fsanitize=address -fsanitize-address-use-after-scope -fstack-protector -fstack-protector-all)
2226
add_link_options(-fexceptions -pthread -ldl -lGL -Wall -g -fsanitize=undefined -fno-sanitize-recover -fsanitize=float-cast-overflow -fsanitize=leak -fsanitize=address -fsanitize-address-use-after-scope -fstack-protector -fstack-protector-all)
2327
endif()
2428

2529
if (USE_CODE_COVERAGE)
26-
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
27-
add_compile_options(-fprofile-instr-generate -fcoverage-mapping -fprofile-arcs -ftest-coverage --coverage -fno-inline -O0)
28-
add_link_options(-fprofile-instr-generate -fcoverage-mapping -fprofile-arcs -ftest-coverage --coverage -fno-inline -O0)
29-
else()
30-
add_compile_options(-fprofile-arcs -ftest-coverage --coverage -fno-inline -O0)
31-
add_link_options(-fprofile-arcs -ftest-coverage --coverage -fno-inline -O0)
32-
endif()
30+
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
31+
# LLVM source-based coverage (no gcov flags here)
32+
add_compile_options(-fprofile-instr-generate -fcoverage-mapping -O0 -fno-inline -fno-elide-constructors)
33+
add_link_options(-fprofile-instr-generate -fcoverage-mapping)
34+
else()
35+
# GCC / others: gcov-style coverage
36+
add_compile_options(-fprofile-arcs -ftest-coverage --coverage -fno-inline -O0)
37+
add_link_options(-fprofile-arcs -ftest-coverage --coverage -fno-inline -O0)
38+
endif()
3339
endif()
3440

3541
function(AddTest arg)
3642
add_test("${arg}" "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT}" "${arg}")
3743
endfunction(AddTest)
3844

45+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/ezBuildInc)
46+
set_target_properties(ezBuildInc PROPERTIES FOLDER 3rdparty/tools)
47+
48+
function(StageBuildInc)
49+
add_custom_command(
50+
TARGET ${PROJECT}
51+
COMMAND ezBuildInc ezLibs $<$<CONFIG:Debug>:${CMAKE_SOURCE_DIR}/include/ezlibs.hpp> -ff ${CMAKE_SOURCE_DIR}/Tests/res/big.flf
52+
)
53+
endfunction(StageBuildInc)
54+
55+
if (USE_CODE_COVERAGE)
56+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/coverage)
57+
endif()
58+
3959
if (TESTING_WIP)
4060
add_definitions(-DTESTING_WIP)
4161
endif()
@@ -77,19 +97,5 @@ if (TESTING_GEO)
7797
endif()
7898

7999
if (USE_CODE_COVERAGE)
80-
set(COVERAGE_WEB_PAGE "coverage.html")
81-
set(COVERAGE_XML "coverage.xml") # for codecov
82-
add_custom_target(cov DEPENDS ${COVERAGE_WEB_PAGE} ${COVERAGE_XML})
83-
add_custom_command(
84-
OUTPUT ${COVERAGE_WEB_PAGE}
85-
COMMAND gcovr -r ../.. . -f "${EZ_LIBS_INCLUDE_DIR}" --decisions --calls --exclude-unreachable-branches --exclude-throw-branches --exclude-noncode-lines --html-single-page --html-details ${COVERAGE_WEB_PAGE}
86-
)
87-
add_custom_command(
88-
OUTPUT ${COVERAGE_XML}
89-
COMMAND gcovr -r ../.. . -f "${EZ_LIBS_INCLUDE_DIR}" --decisions --calls --exclude-unreachable-branches --exclude-throw-branches --exclude-noncode-lines --cobertura > ${COVERAGE_XML}
90-
)
91-
set_directory_properties(PROPERTIES
92-
ADDITIONAL_CLEAN_FILES ${COVERAGE_WEB_PAGE}
93-
ADDITIONAL_CLEAN_FILES ${COVERAGE_XML}
94-
)
100+
include(${CMAKE_CURRENT_SOURCE_DIR}/coverage/coverage.cmake)
95101
endif()

Tests/TestApp/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ set(PROJECT EzLibs_TestApp)
44
enable_language(C CXX)
55
project(${PROJECT} CXX)
66

7+
set(CMAKE_CXX_STANDARD 11)
8+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
9+
set(CMAKE_CXX_EXTENSIONS OFF)
10+
711
file(GLOB_RECURSE PROJECT_TEST_SRC_RECURSE
812
${CMAKE_CURRENT_SOURCE_DIR}/*.cpp
913
${CMAKE_CURRENT_SOURCE_DIR}/*.h)
@@ -25,6 +29,8 @@ target_include_directories(${PROJECT} PRIVATE
2529
${CMAKE_CURRENT_SOURCE_DIR}
2630
)
2731

32+
StageBuildInc()
33+
2834
##########################################################
2935
##### TESTS ##############################################
3036
##########################################################

Tests/TestApp/TestEzBuildInc.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ bool TestEzBuildInc_base() {
3535
#define Project_MinorNumber 3
3636
#define Project_MajorNumber 0
3737
#define Project_BuildId "0.3.3629"
38+
#define Project_BuildIdNum 00033629
3839
)";
3940
if (!ez::file::saveStringToFile(baseContent, file)) {
4041
return false;
@@ -55,6 +56,7 @@ bool TestEzBuildInc_base() {
5556
#define Project_MinorNumber 3
5657
#define Project_MajorNumber 0
5758
#define Project_BuildId "0.3.3630"
59+
#define Project_BuildIdNum 00033630
5860
#define Project_FigFontLabel u8R"( _ _ ___ ____
5961
(_) | | / _ \ |___ \
6062
_ __ _ __ ___ _ ___ ___ | |_ __ __| | | | __) |
@@ -78,6 +80,7 @@ bool TestEzBuildInc_base() {
7880
#define Project_MinorNumber 3
7981
#define Project_MajorNumber 0
8082
#define Project_BuildId "0.3.3630"
83+
#define Project_BuildIdNum 00033630
8184
#define Project_FigFontLabel u8R"( ___ ____
8285
/ _ \ |___ \
8386
__ __| | | | __) |
@@ -98,6 +101,7 @@ __ __| | | | __) |
98101
#define Project_MinorNumber 3
99102
#define Project_MajorNumber 0
100103
#define Project_BuildId "0.3.3630"
104+
#define Project_BuildIdNum 00033630
101105
#define Project_FigFontLabel u8R"( ___ ____ ____ __ ____ ___
102106
/ _ \ |___ \ |___ \ / / |___ \ / _ \
103107
__ __| | | | __) | __) | / /_ __) || | | |
@@ -118,6 +122,7 @@ __ __| | | | __) | __) | / /_ __) || | | |
118122
#define Project_MinorNumber 3
119123
#define Project_MajorNumber 0
120124
#define Project_BuildId "0.3.3630"
125+
#define Project_BuildIdNum 00033630
121126
#define Project_FigFontLabel u8R"( _ _ ___ ____ ____ __ ____ ___
122127
(_) | | / _ \ |___ \ |___ \ / / |___ \ / _ \
123128
_ __ _ __ ___ _ ___ ___ | |_ __ __| | | | __) | __) | / /_ __) || | | |

Tests/TestApp/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ int main(int argc, char** argv) {
2727
return TestApp(argv[1]) ? 0 : 1;
2828
}
2929
// User testing
30-
return TestApp("TestEzArgs_optional_required") ? 0 : 1;
30+
return TestApp("TestEzBuildInc_base") ? 0 : 1;
3131
}

Tests/TestCom/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ set(PROJECT EzLibs_TestCom)
44
enable_language(C CXX)
55
project(${PROJECT} CXX)
66

7+
set(CMAKE_CXX_STANDARD 11)
8+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
9+
set(CMAKE_CXX_EXTENSIONS OFF)
710

811
option(USE_EZ_EXPR_PERFOS_GENERATION "Enable the perfos file generation of EzExpr" OFF)
912

@@ -27,6 +30,8 @@ target_include_directories(${PROJECT} PRIVATE
2730
${CMAKE_CURRENT_SOURCE_DIR}
2831
)
2932

33+
StageBuildInc()
34+
3035
##########################################################
3136
## TESTS NAMED PIPE ######################################
3237
##########################################################

Tests/TestComp/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ set(PROJECT EzLibs_TestComp)
44
enable_language(C CXX)
55
project(${PROJECT} CXX)
66

7+
set(CMAKE_CXX_STANDARD 11)
8+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
9+
set(CMAKE_CXX_EXTENSIONS OFF)
10+
711
file(GLOB_RECURSE PROJECT_TEST_SRC_RECURSE
812
${CMAKE_CURRENT_SOURCE_DIR}/*.cpp
913
${CMAKE_CURRENT_SOURCE_DIR}/*.h)
@@ -24,6 +28,8 @@ target_include_directories(${PROJECT} PRIVATE
2428
${CMAKE_CURRENT_SOURCE_DIR}
2529
)
2630

31+
StageBuildInc()
32+
2733
##########################################################
2834
##### TESTS ##############################################
2935
##########################################################

0 commit comments

Comments
 (0)