Skip to content

Commit 24a18dd

Browse files
committed
wip coverage changes
1 parent fc74cda commit 24a18dd

18 files changed

Lines changed: 537 additions & 143 deletions

CMakeLists.txt

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,14 @@ set(CMAKE_CXX_STANDARD 26)
77
project(rsltest CXX)
88
add_library(rsltest SHARED)
99
add_library(rsltest_main SHARED)
10-
add_library(rsltest_cov)
10+
1111

1212
set_target_properties(rsltest PROPERTIES OUTPUT_NAME rsltest)
1313
target_compile_options(rsltest PUBLIC
1414
"-freflection-latest"
1515
# "-ftime-trace"
1616
# "-fconstexpr-steps=10000000" # required to scan the global namespace
17-
)
18-
19-
target_compile_options(rsltest_cov PUBLIC
20-
"-freflection-latest"
17+
"-ftemplate-backtrace-limit=0"
2118
)
2219

2320
target_include_directories(rsltest PUBLIC
@@ -55,15 +52,14 @@ if (BUILD_TESTING)
5552
# add_test(NAME rsltest_test COMMAND rsltest_example)
5653
endif()
5754

55+
add_subdirectory(ext)
56+
57+
install(TARGETS rsltest_main)
58+
install(TARGETS rsltest)
59+
install(DIRECTORY include/ DESTINATION include)
5860
if (BUILD_EXAMPLES)
5961
add_executable(example_test)
6062
add_subdirectory(example)
6163
target_link_libraries(example_test PRIVATE rsltest)
6264
target_link_libraries(example_test PRIVATE rsltest_main)
63-
target_link_libraries(example_test PRIVATE rsltest_cov)
64-
endif()
65-
66-
install(TARGETS rsltest_cov)
67-
install(TARGETS rsltest_main)
68-
install(TARGETS rsltest)
69-
install(DIRECTORY include/ DESTINATION include)
65+
endif()

conanfile.py

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class rsltestRecipe(ConanFile):
2323
"editable": [True, False]
2424
}
2525

26-
default_options = {"shared": False, "fPIC": True, "coverage": False, "examples": False, "editable": False}
26+
default_options = {"shared": True, "fPIC": True, "coverage": False, "examples": False, "editable": False}
2727

2828
# Sources are located in the same place as this recipe, copy them to the recipe
2929
exports_sources = "CMakeLists.txt", "src/*", "include/*", "example/*", "test/*"
@@ -37,7 +37,7 @@ def configure(self):
3737
self.options.rm_safe("fPIC")
3838

3939
def requirements(self):
40-
self.requires("libassert/dev", transitive_headers=True, transitive_libs=True)
40+
self.requires("libassert/dev", transitive_headers=True, transitive_libs=True, options={"shared": True})
4141
self.requires("rsl-util/0.1", transitive_headers=True, transitive_libs=True)
4242
self.requires("rsl-config/0.1", transitive_headers=False, transitive_libs=True)
4343
self.requires("rsl-xml/0.1", transitive_headers=False, transitive_libs=True)
@@ -69,16 +69,47 @@ def package(self):
6969

7070
def package_info(self):
7171
self.cpp_info.set_property("cmake_file_name", "rsl-test")
72-
self.cpp_info.components["test"].set_property("cmake_target_name", "rsl::test")
73-
self.cpp_info.components["test"].includedirs = ["include"]
74-
self.cpp_info.components["test"].libdirs = ["lib"]
75-
self.cpp_info.components["test"].requires = ["libassert::assert", "rsl-util::util"]
76-
self.cpp_info.components["test"].libs = ["rsltest"]
77-
78-
self.cpp_info.components["test_main"].set_property("cmake_target_name", "rsl::test_main")
79-
self.cpp_info.components["test_main"].includedirs = ["include"]
80-
self.cpp_info.components["test_main"].libdirs = ["lib"]
81-
self.cpp_info.components["test_main"].requires = ["test", "rsl-config::config", "rsl-xml::xml"]
82-
self.cpp_info.components["test_main"].libs = ["rsltest_main"]
72+
73+
test = self.cpp_info.components["test"]
74+
test.set_property("cmake_target_name", "rsl::test")
75+
test.includedirs = ["include"]
76+
test.libdirs = ["lib"]
77+
test.requires = ["libassert::assert", "rsl-util::util"]
78+
test.libs = ["rsltest"]
79+
80+
test_main = self.cpp_info.components["test_main"]
81+
test_main.set_property("cmake_target_name", "rsl::test_main")
82+
test_main.includedirs = ["include"]
83+
test_main.libdirs = ["lib"]
84+
test_main.requires = ["test", "rsl-config::config", "rsl-xml::xml"]
85+
test_main.libs = ["rsltest_main"]
86+
87+
if str(self.settings.compiler) == "clang":
88+
test_cov = self.cpp_info.components["test_cov"]
89+
test_cov.set_property("cmake_target_name", "rsl::test_cov")
90+
test_cov.libs = []
91+
test_cov.sources = ["ext/coverage_hooks.cpp"]
92+
test_cov.cxxflags = ["-fsanitize-coverage=pc-table,trace-pc-guard"]
93+
test_cov.sharedlinkflags = ["-fsanitize-coverage=pc-table,trace-pc-guard"]
94+
test_cov.exelinkflags = ["-fsanitize-coverage=pc-table,trace-pc-guard"]
95+
test_cov.requires = []
96+
97+
98+
test_cov_flags = self.cpp_info.components["test_cov_flags"]
99+
test_cov_flags.set_property("cmake_target_name", "rsl::test_cov_flags")
100+
test_cov_flags.cxxflags = ["-fsanitize-coverage=pc-table,trace-pc-guard"]
101+
test_cov_flags.sharedlinkflags = ["-fsanitize-coverage=pc-table,trace-pc-guard"]
102+
test_cov_flags.exelinkflags = ["-fsanitize-coverage=pc-table,trace-pc-guard"]
103+
104+
test_cov_hooks = self.cpp_info.components["test_cov_hooks"]
105+
test_cov_hooks.set_property("cmake_target_name", "rsl::test_cov_hooks")
106+
test_cov_hooks.sources = ["ext/coverage_hooks.cpp"]
107+
108+
# test_cov = self.cpp_info.components["test_cov"]
109+
# test_cov.set_property("cmake_target_name", "rsl::test_cov")
110+
# test_cov.requires = ["test_cov_flags", "test_cov_hooks"]
111+
112+
113+
83114

84115

ext/CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
2+
add_library(rsltest_cov INTERFACE)
3+
target_sources(rsltest_cov INTERFACE "${CMAKE_CURRENT_LIST_DIR}/coverage_hooks.cpp")
4+
add_library(rsl::test_cov ALIAS rsltest_cov)
5+
6+
# set(COVERAGE_FLAGS
7+
# -fsanitize-coverage=pc-table,trace-pc-guard
8+
# )
9+
10+
# target_compile_options(rsltest_cov INTERFACE ${COVERAGE_FLAGS} "-O0" "-g")
11+
# target_link_options(rsltest_cov INTERFACE ${COVERAGE_FLAGS})
12+
install(TARGETS rsltest_cov)
13+
endif()

ext/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Building with coverage
2+
3+
To enable coverage you need to link to the optional target `rsl::test_cov` for whichever component you want to enable coverage for. Note that if you are testing a library, you will likely want to instrument the library rather than the tests.
4+
5+
This feature is currently only supported with the new `CMakeConfigDeps` Conan generator. To enable it, pass `-c tools.cmake.cmakedeps:new=will_break_next` when pulling in rsl-test.
6+
7+
8+
Alternatively you can copy `coverage_hooks.cpp` into your project's source tree and build it alongside your project. Remember to adjust your compiler and linker options by appending `-fsanitize-coverage=pc-table,trace-pc-guard`.

0 commit comments

Comments
 (0)