CMake: add coverage-clean target and fix coverage dependency issue.

* improve/fix README

Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
This commit is contained in:
Toni Uhlig
2024-08-20 11:49:38 +02:00
parent 4efe7e43a2
commit adb8fe96f5
2 changed files with 43 additions and 21 deletions

View File

@@ -239,6 +239,11 @@ if(ENABLE_COVERAGE)
COMMAND genhtml -o "${CMAKE_BINARY_DIR}/coverage_report" "${CMAKE_BINARY_DIR}/lcov.info" COMMAND genhtml -o "${CMAKE_BINARY_DIR}/coverage_report" "${CMAKE_BINARY_DIR}/lcov.info"
DEPENDS nDPId nDPId-test nDPIsrvd DEPENDS nDPId nDPId-test nDPIsrvd
) )
add_custom_target(coverage-clean)
add_custom_command(
TARGET coverage-clean
COMMAND find "${CMAKE_BINARY_DIR}" "${CMAKE_SOURCE_DIR}/libnDPI" -name "*.gcda" -delete
)
add_custom_target(coverage-view) add_custom_target(coverage-view)
add_custom_command( add_custom_command(
TARGET coverage-view TARGET coverage-view
@@ -460,6 +465,9 @@ if(BUILD_EXAMPLES)
"${GCRYPT_LIBRARY}" "${GCRYPT_ERROR_LIBRARY}" "${PCAP_LIBRARY}") "${GCRYPT_LIBRARY}" "${GCRYPT_ERROR_LIBRARY}" "${PCAP_LIBRARY}")
add_executable(nDPIsrvd-analysed examples/c-analysed/c-analysed.c utils.c) add_executable(nDPIsrvd-analysed examples/c-analysed/c-analysed.c utils.c)
if(BUILD_NDPI)
add_dependencies(nDPIsrvd-analysed libnDPI)
endif()
target_compile_definitions(nDPIsrvd-analysed PRIVATE ${NDPID_DEFS}) target_compile_definitions(nDPIsrvd-analysed PRIVATE ${NDPID_DEFS})
target_include_directories(nDPIsrvd-analysed PRIVATE target_include_directories(nDPIsrvd-analysed PRIVATE
"${STATIC_LIBNDPI_INC}" "${DEFAULT_NDPI_INCLUDE}" "${CMAKE_SOURCE_DIR}" ${NDPID_DEPS_INC}) "${STATIC_LIBNDPI_INC}" "${DEFAULT_NDPI_INCLUDE}" "${CMAKE_SOURCE_DIR}" ${NDPID_DEPS_INC})
@@ -469,7 +477,7 @@ if(BUILD_EXAMPLES)
target_include_directories(nDPIsrvd-simple PRIVATE ${NDPID_DEPS_INC}) target_include_directories(nDPIsrvd-simple PRIVATE ${NDPID_DEPS_INC})
if(ENABLE_COVERAGE) if(ENABLE_COVERAGE)
add_dependencies(coverage nDPIsrvd-analysed nDPIsrvd-collectd nDPIsrvd-captured nDPIsrvd-simple) add_dependencies(coverage libnDPI nDPIsrvd-analysed nDPIsrvd-collectd nDPIsrvd-captured nDPIsrvd-simple)
endif() endif()
if(ENABLE_DBUS) if(ENABLE_DBUS)

View File

@@ -193,9 +193,10 @@ ccmake ..
or to build with a staticially linked libnDPI: or to build with a staticially linked libnDPI:
```shell ```shell
mkdir build cmake -S . -B ./build \
cd build -DSTATIC_LIBNDPI_INSTALLDIR=[path/to/your/libnDPI/installdir] \
cmake .. -DSTATIC_LIBNDPI_INSTALLDIR=[path/to/your/libnDPI/installdir] -DNDPI_NO_PKGCONFIG=ON -DNDPI_NO_PKGCONFIG=ON
cmake --build ./build
``` ```
If you use the latter, make sure that you've configured libnDPI with `./configure --prefix=[path/to/your/libnDPI/installdir]` If you use the latter, make sure that you've configured libnDPI with `./configure --prefix=[path/to/your/libnDPI/installdir]`
@@ -205,17 +206,19 @@ You'll also need to use `-DNDPI_NO_PKGCONFIG=ON` if `STATIC_LIBNDPI_INSTALLDIR`
e.g.: e.g.:
```shell ```shell
mkdir build cmake -S . -B ./build \
cd build -DSTATIC_LIBNDPI_INSTALLDIR=[path/to/your/libnDPI/installdir] \
cmake .. -DSTATIC_LIBNDPI_INSTALLDIR=[path/to/your/libnDPI/installdir] -DNDPI_WITH_GCRYPT=ON -DNDPI_WITH_PCRE=OFF -DNDPI_WITH_MAXMINDDB=OFF -DNDPI_NO_PKGCONFIG=ON \
-DNDPI_WITH_GCRYPT=ON -DNDPI_WITH_PCRE=OFF -DNDPI_WITH_MAXMINDDB=OFF
cmake --build ./build
``` ```
Or let a shell script do the work for you: Or let a shell script do the work for you:
```shell ```shell
mkdir build cmake -S . -B ./build \
cd build -DBUILD_NDPI=ON
cmake .. -DBUILD_NDPI=ON cmake --build ./build
``` ```
The CMake cache variable `-DBUILD_NDPI=ON` builds a version of `libnDPI` residing as a git submodule in this repository. The CMake cache variable `-DBUILD_NDPI=ON` builds a version of `libnDPI` residing as a git submodule in this repository.
@@ -312,24 +315,35 @@ Format: `subopt` (unit, comment): description
The recommended way to run regression / diff tests: The recommended way to run regression / diff tests:
```shell ```shell
mkdir build cmake -S . -B ./build-like-ci \
cd build -DBUILD_NDPI=ON -DENABLE_ZLIB=ON -DBUILD_EXAMPLES=ON
cmake .. -DBUILD_NDPI=ON # optional: -DENABLE_CURL=ON -DENABLE_SANITIZER=ON
make nDPId-test test ./test/run_tests.sh ./libnDPI ./build-like-ci/nDPId-test
# or: make -C ./build-like-ci test
``` ```
Alternatively you can run some integration tests manually: Run `./test/run_tests.sh` to see some usage information.
`./test/run_tests.sh [/path/to/libnDPI/root/directory] [/path/to/nDPId-test]`
e.g.:
`./test/run_tests.sh "${HOME}/git/nDPI "${HOME}/git/nDPId/build/nDPId-test"`
Remember that all test results are tied to a specific libnDPI commit hash Remember that all test results are tied to a specific libnDPI commit hash
as part of the `git submodule`. Using `test/run_tests.sh` for other commit hashes as part of the `git submodule`. Using `test/run_tests.sh` for other commit hashes
will most likely result in PCAP diffs. will most likely result in PCAP diffs.
# Code Coverage
You may generate code coverage by using:
```shell
cmake -S . -B ./build-coverage \
-DENABLE_COVERAGE=ON -DENABLE_ZLIB=ON
# optional: -DBUILD_NDPI=ON
make -C ./build-coverage coverage-clean
make -C ./build-coverage clean
make -C ./build-coverage all
./test/run_tests.sh ./libnDPI ./build-coverage/nDPId-test
make -C ./build-coverage coverage
make -C ./build-coverage coverage-view
```
# Contributors # Contributors
Special thanks to Damiano Verzulli ([@verzulli](https://github.com/verzulli)) from [GARRLab](https://www.garrlab.it) for providing server and test infrastructure. Special thanks to Damiano Verzulli ([@verzulli](https://github.com/verzulli)) from [GARRLab](https://www.garrlab.it) for providing server and test infrastructure.