Skip to content

Commit 58039aa

Browse files
committed
Expanded tests to better catch regression issues
Mostly by adding GCC/lcov code coverage tests and adding both static and shared variants.
1 parent df8459b commit 58039aa

File tree

13 files changed

+214
-30
lines changed

13 files changed

+214
-30
lines changed

.gitlab-ci.yml

Lines changed: 115 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,133 @@
1+
stages:
2+
- Targeted Code Coverage
3+
- All Code Coverage
4+
- Fedora
5+
- openSUSE
6+
17
variables:
2-
GIT_SUBMODULE_STRATEGY: recursive
38
CTEST_OUTPUT_ON_FAILURE: '1'
49

5-
Code Coverage:
6-
image: stabletec/build-foe:fedora-clang
10+
# Targeted Code Coverage
11+
12+
Targeted CC GCC Static:
13+
image: stabletec/build-core:fedora-gcc
14+
stage: Targeted Code Coverage
15+
tags:
16+
- docker-linux
17+
script:
18+
- mkdir build && cd build
19+
- cmake ../example/code-coverage-target/ -GNinja -DCMAKE_BUILD_TYPE=Release -DCODE_COVERAGE=ON ${CMAKE_OPTIONS}
20+
- ninja
21+
- ninja ccov
22+
23+
Targeted CC GCC Shared:
24+
image: stabletec/build-core:fedora-gcc
25+
variables:
26+
CMAKE_OPTIONS: -DBUILD_SHARED_LIBS=ON
27+
stage: Targeted Code Coverage
28+
tags:
29+
- docker-linux
30+
script:
31+
- mkdir build && cd build
32+
- cmake ../example/code-coverage-target/ -GNinja -DCMAKE_BUILD_TYPE=Release -DCODE_COVERAGE=ON ${CMAKE_OPTIONS}
33+
- ninja
34+
- ninja ccov
35+
36+
Targeted CC Clang Static:
37+
image: stabletec/build-core:fedora-clang
38+
stage: Targeted Code Coverage
39+
tags:
40+
- docker-linux
41+
script:
42+
- mkdir build && cd build
43+
- cmake ../example/code-coverage-target/ -GNinja -DCMAKE_BUILD_TYPE=Release -DCODE_COVERAGE=ON ${CMAKE_OPTIONS}
44+
- ninja
45+
- ninja ccov
46+
- ninja ccov-report
47+
48+
Targeted CC Clang Shared:
49+
image: stabletec/build-core:fedora-clang
50+
variables:
51+
CMAKE_OPTIONS: -DBUILD_SHARED_LIBS=ON
52+
stage: Targeted Code Coverage
53+
tags:
54+
- docker-linux
55+
script:
56+
- mkdir build && cd build
57+
- cmake ../example/code-coverage-target/ -GNinja -DCMAKE_BUILD_TYPE=Release -DCODE_COVERAGE=ON ${CMAKE_OPTIONS}
58+
- ninja
59+
- ninja ccov
60+
- ninja ccov-report
61+
62+
# All Code Coverage
63+
64+
All CC GCC Static:
65+
image: stabletec/build-core:fedora-gcc
66+
stage: All Code Coverage
67+
tags:
68+
- docker-linux
69+
script:
70+
- mkdir build && cd build
71+
- cmake ../example/code-coverage-all/ -GNinja -DCMAKE_BUILD_TYPE=Release -DCODE_COVERAGE=ON ${CMAKE_OPTIONS}
72+
- ninja
73+
- ninja ccov
74+
- ninja ccov-all
75+
76+
All CC GCC Shared:
77+
image: stabletec/build-core:fedora-gcc
78+
variables:
79+
CMAKE_OPTIONS: -DBUILD_SHARED_LIBS=ON
80+
stage: All Code Coverage
81+
tags:
82+
- docker-linux
83+
script:
84+
- mkdir build && cd build
85+
- cmake ../example/code-coverage-all/ -GNinja -DCMAKE_BUILD_TYPE=Release -DCODE_COVERAGE=ON ${CMAKE_OPTIONS}
86+
- ninja
87+
- ninja ccov
88+
- ninja ccov-all
89+
90+
All CC Clang Static:
91+
image: stabletec/build-core:fedora-clang
92+
stage: All Code Coverage
93+
tags:
94+
- docker-linux
95+
script:
96+
- mkdir build && cd build
97+
- cmake ../example/code-coverage-all/ -GNinja -DCMAKE_BUILD_TYPE=Release -DCODE_COVERAGE=ON ${CMAKE_OPTIONS}
98+
- ninja
99+
- ninja
100+
- ninja ccov-all
101+
- ninja ccov-report
102+
- ninja ccov-all-report
103+
104+
All CC Clang Shared:
105+
image: stabletec/build-core:fedora-clang
106+
variables:
107+
CMAKE_OPTIONS: -DBUILD_SHARED_LIBS=ON
108+
stage: All Code Coverage
7109
tags:
8110
- docker-linux
9111
script:
10-
- mkdir example/build && cd example/build
11-
- cmake .. -GNinja -DCMAKE_BUILD_TYPE=Release -DCODE_COVERAGE=ON
112+
- mkdir build && cd build
113+
- cmake ../example/code-coverage-all/ -GNinja -DCMAKE_BUILD_TYPE=Release -DCODE_COVERAGE=ON ${CMAKE_OPTIONS}
12114
- ninja
13115
- ninja ccov
14116
- ninja ccov-all
15117
- ninja ccov-report
16118
- ninja ccov-all-report
17-
artifacts:
18-
name: CodeCoverage
19-
paths:
20-
- example/build/ccov
21-
expire_in: 1 day
22119

23120
# Fedora
24121

25122
.fedora_template: &fedora_template
26-
image: stabletec/build-foe:fedora-clang
123+
stage: Fedora
124+
image: stabletec/build-core:fedora-clang
27125
allow_failure: true
28126
tags:
29127
- docker-linux
30128
script:
31-
- mkdir example/build && cd example/build
32-
- cmake .. -GNinja -DCMAKE_BUILD_TYPE=Release ${CMAKE_OPTIONS}
129+
- mkdir build && cd build
130+
- cmake ../example/all -GNinja -DCMAKE_BUILD_TYPE=Release ${CMAKE_OPTIONS}
33131
- ninja
34132
- ninja test
35133

@@ -61,13 +159,14 @@ Fedora UndefinedSanitizer:
61159
# openSUSE
62160

63161
.opensuse_template: &opensuse_template
64-
image: stabletec/build-foe:opensuse-clang
162+
stage: openSUSE
163+
image: stabletec/build-core:opensuse-clang
65164
allow_failure: true
66165
tags:
67166
- docker-linux
68167
script:
69-
- mkdir example/build && cd example/build
70-
- cmake .. -GNinja -DCMAKE_BUILD_TYPE=Release ${CMAKE_OPTIONS}
168+
- mkdir build && cd build
169+
- cmake ../example/all -GNinja -DCMAKE_BUILD_TYPE=Release ${CMAKE_OPTIONS}
71170
- ninja
72171
- ninja test
73172

code-coverage.cmake

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,12 +196,13 @@ endif()
196196
# Optional:
197197
# AUTO - Adds the target to the 'ccov' target so that it can be run in a batch with others easily. Effective on executable targets.
198198
# ALL - Adds the target to the 'ccov-all' and 'ccov-all-report' targets, which merge several executable targets coverage data to a single report. Effective on executable targets.
199+
# EXTERNAL - For GCC's lcov, allows the profiling of 'external' files from the processing directory
199200
# EXCLUDE <REGEX_PATTERNS> - Excludes files of the patterns provided from coverage. **These do not copy to the 'all' targets.**
200201
# OBJECTS <TARGETS> - For executables ONLY, if the provided targets are shared libraries, adds coverage information to the output
201202
# ~~~
202203
function(target_code_coverage TARGET_NAME)
203204
# Argument parsing
204-
set(options AUTO ALL)
205+
set(options AUTO ALL EXTERNAL)
205206
set(multi_value_keywords EXCLUDE OBJECTS)
206207
cmake_parse_arguments(target_code_coverage
207208
"${options}"
@@ -367,6 +368,10 @@ function(target_code_coverage TARGET_NAME)
367368
set(EXCLUDE_COMMAND ;)
368369
endif()
369370

371+
if(NOT ${target_code_coverage_EXTERNAL})
372+
set(EXTERNAL_OPTION --no-external)
373+
endif()
374+
370375
# Generates HTML output of the coverage information for perusal
371376
add_custom_target(
372377
ccov-${TARGET_NAME}
@@ -385,7 +390,7 @@ function(target_code_coverage TARGET_NAME)
385390
--base-directory
386391
${CMAKE_SOURCE_DIR}
387392
--capture
388-
--no-external
393+
${EXTERNAL_OPTION}
389394
--output-file
390395
${COVERAGE_INFO}
391396
COMMAND ${EXCLUDE_COMMAND}
Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
cmake_minimum_required(VERSION 3.10)
22
project(sanitizer-tests C CXX)
33

4-
include(../c++-standards.cmake)
5-
include(../code-coverage.cmake)
6-
include(../formatting.cmake)
7-
include(../sanitizers.cmake)
8-
include(../tools.cmake)
9-
include(../dependency-graph.cmake)
4+
# Set the searching location for cmake 'include' locations
5+
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/../..;")
6+
7+
include(c++-standards)
8+
include(code-coverage)
9+
include(formatting)
10+
include(sanitizers)
11+
include(tools)
12+
include(dependency-graph)
1013

1114
# Require C++11
1215
cxx_11()
@@ -32,34 +35,33 @@ cppcheck(
3235
--force)
3336

3437
enable_testing()
35-
add_code_coverage_all_targets()
3638

3739
# Fails with ThreadSanitizer
38-
add_executable(tsanFail tsan_fail.cpp)
40+
add_executable(tsanFail ../src/tsan_fail.cpp)
3941
target_code_coverage(tsanFail AUTO ALL)
4042
if(UNIX)
4143
target_link_libraries(tsanFail PUBLIC pthread)
4244
endif()
4345
add_test(tsan tsanFail)
4446

4547
# Fails with LeakSanitizer
46-
add_executable(lsanFail lsan_fail.c)
48+
add_executable(lsanFail ../src/lsan_fail.c)
4749
target_code_coverage(lsanFail AUTO ALL)
4850
add_test(lsan lsanFail)
4951

5052
# Fails with AddressSanitizer
5153
if(USE_SANITIZER MATCHES "[Aa]ddress")
52-
add_executable(asanFail asan_fail.cpp)
54+
add_executable(asanFail ../src/asan_fail.cpp)
5355
target_code_coverage(asanFail AUTO ALL)
5456
add_test(asan asanFail)
5557
endif()
5658

5759
# Fails with MemorySanitizer
58-
add_executable(msanFail msan_fail.cpp)
60+
add_executable(msanFail ../src/msan_fail.cpp)
5961
target_code_coverage(msanFail AUTO ALL)
6062
add_test(msan msanFail)
6163

6264
# Fails with UndefinedBehaviourSanitizer
63-
add_executable(ubsanFail ubsan_fail.cpp)
65+
add_executable(ubsanFail ../src/ubsan_fail.cpp)
6466
target_code_coverage(ubsanFail AUTO ALL)
6567
add_test(ubsan ubsanFail)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
cmake_minimum_required(VERSION 3.10)
2+
project(code-covare-all C CXX)
3+
4+
# Set the searching location for cmake 'include' locations
5+
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/../..;")
6+
# Include the sanitizer module
7+
include(code-coverage)
8+
9+
# Require C++11
10+
include(c++-standards)
11+
cxx_11()
12+
13+
# This introduces the 'ccov-all' targets
14+
# Also excludes the main file via a regex
15+
add_code_coverage_all_targets(EXCLUDE coverage.main.cpp)
16+
17+
# The library
18+
add_library(lib ../src/coverage.cpp)
19+
20+
# Instruments the library
21+
target_code_coverage(lib AUTO ALL)
22+
23+
# The executable
24+
add_executable(main ../src/coverage.main.cpp)
25+
target_link_libraries(main PUBLIC lib)
26+
27+
# Adds the executable to the 'ccov' and 'ccov-all' targets
28+
# and excludes the file itself via regex
29+
target_code_coverage(main AUTO ALL EXTERNAL)
30+
31+
# The second executable
32+
add_executable(main2 ../src/coverage.main.cpp)
33+
target_link_libraries(main2 PUBLIC lib)
34+
35+
# Adds the executable to the 'ccov' and 'ccov-all' targets
36+
# and excludes the file itself via regex
37+
target_code_coverage(main2 AUTO ALL EXTERNAL)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
cmake_minimum_required(VERSION 3.10)
2+
project(code-covare-all C CXX)
3+
4+
# Set the searching location for cmake 'include' locations
5+
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/../..;")
6+
# Include the sanitizer module
7+
include(code-coverage)
8+
9+
# Require C++11
10+
include(c++-standards)
11+
cxx_11()
12+
13+
# The library
14+
add_library(lib ../src/coverage.cpp)
15+
16+
# Instruments the library
17+
target_code_coverage(lib AUTO)
18+
19+
# The executable
20+
add_executable(main ../src/coverage.main.cpp)
21+
target_link_libraries(main PUBLIC lib)
22+
23+
# Adds the executable to the 'ccov' target
24+
target_code_coverage(main AUTO EXTERNAL)

example/src/coverage.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include "coverage.hpp"
2+
3+
#include <cmath>
4+
5+
int tested_func(double param1) { return std::sqrt(param1); }
6+
7+
int untested_func(double param1) { return std::sqrt(param1); }

example/src/coverage.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
int tested_func(double param1);
2+
3+
int untested_func(double param1);

example/src/coverage.main.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include "coverage.hpp"
2+
3+
int main() {
4+
tested_func(1.0);
5+
6+
return 0;
7+
}

0 commit comments

Comments
 (0)