Daniel Bretón Suárez
10/06/2022, 7:14 AMgcovr
tool (on which I have very little knowledge). .gcno
and .gcda
files are generated but test coverage is always 0% in all the sources. At the moment I'm blocked, all the guides I've read say it should work. Maybe someone can point me in the right direction?
I think it is related to the way extensions are built because sources are in a different folder than binaries. However, gcovr
has a --root
option on which source files can be specified so it might not be the problem.
This are the steps I'm performing on Ubuntu
cd osquery
ln -s /home/danielbreton/workspace/osquery-extension-hello/ external/extension_hello
cd build
cmake -DOSQUERY_TOOLCHAIN_SYSROOT=/usr/local/osquery-toolchain -DOSQUERY_BUILD_TESTS=ON -DENABLE_COVERAGE=true ..
cmake --build . -j$(nproc) --target hello_my_friend_extension_test
./external/extension_hello/hello_my_friend_extension_test
gcovr --xml-pretty --exclude-unreachable-branches --print-summary -o coverage.xml --root /home/danielbreton/workspace/osquery-extension-hello/
And this is the complete CMakeLists.txt
for the extension
project("hello_my_friend_extension")
addOsqueryExtension(
"${PROJECT_NAME}"
hello.cpp
main.cpp
)
set(common_test_files
hello.cpp
)
add_executable(
"${PROJECT_NAME}_test"
EXCLUDE_FROM_ALL
${common_test_files}
test.cpp
)
if(ENABLE_COVERAGE)
message("Enabling coverage")
# set compiler flags
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -fprofile-arcs -ftest-coverage")
set(CMAKE_CXX_FLAGS " ${CMAKE_CXX_FLAGS} -O0 -fprofile-arcs -ftest-coverage")
# find required tools
find_program(GCOVR gcovr REQUIRED)
endif()
target_link_libraries("${PROJECT_NAME}_test" PRIVATE
thirdparty_googletest
osquery_sdk_pluginsdk
osquery_extensions_implthrift
)
if(ENABLE_COVERAGE)
add_link_options("--coverage")
endif()
Project tree
danielbreton@2022-EMEA-0022 ~/workspace/osquery-extension-hello (feature/UA-1101)$ tree
.
├── CMakeLists.txt
├── hello.cpp
├── hello.h
├── main.cpp
├── README.md
└── test.cpp
alessandrogario
10/06/2022, 7:31 PMDaniel Bretón Suárez
10/07/2022, 1:01 PMgcno
files under `osquery/build/external/extension_hello/CMakeFiles/hello_my_friend_extension_test.dir`so the util is not able to "link" the filesalessandrogario
10/07/2022, 1:04 PMDaniel Bretón Suárez
10/07/2022, 2:39 PMalessandrogario
10/07/2022, 2:41 PMDaniel Bretón Suárez
10/07/2022, 2:48 PMalessandrogario
10/07/2022, 3:00 PM