Previously, the CMake build enabled tests by default, and enabled both
modular and intrusive (embedded) tests with a single option. This is
a really bad idea if anyone is using CMake-built binaries in production.
DBUS_BUILD_TESTS now enables only the modular tests, which are safe to
enable in production builds.
A new DBUS_ENABLE_INTRUSIVE_TESTS option enables the intrusive test
instrumentation.
To preserve existing test coverage, explicitly enable the intrusive
tests in most CMake-based Gitlab-CI jobs (Debian native, openSUSE native,
Windows).
In jobs that have a mirrored pair of production/debug builds (openSUSE
and Debian mingw32/mingw64 cmake), instead we leave the production
build as-is and only build full test coverage in the debug build.
Co-authored-by: Philip Withnall <philip@tecnocode.co.uk>
Signed-off-by: Simon McVittie <smcv@collabora.com>
(cherry picked from commit
41c7570e1ea803e9635d9bcabba5fc221c94e7e6)
- .unix-host-build
stage: build
-debian cmake:
+debian cmake debug:
extends:
- .cmake-common
- .debian-build
when: manual
variables:
ci_buildsys: "cmake"
+ ci_variant: "debug"
debian meson:
extends:
- .unix-host-build
stage: build
-opensuse cmake:
+opensuse cmake debug:
extends:
- .cmake-common
- .suse-build
variables:
ci_local_packages: "no"
+ ci_variant: "debug"
# TODO: https://gitlab.freedesktop.org/dbus/dbus/-/issues/520
opensuse mingw32 cmake:
- $env:MSYS2_PATH_TYPE = "inherit"
- $env:PATH += ";C:\msys64\usr\bin"
# FIXME: glib from msys2 has issues, disable it for now
- - C:\msys64\usr\bin\bash -lc 'cmake -G \"MinGW Makefiles\" -S . -B build -DDBUS_WITH_GLIB=OFF && cmake --build build --config Release'
+ - C:\msys64\usr\bin\bash -lc 'cmake -G \"MinGW Makefiles\" -S . -B build -DDBUS_WITH_GLIB=OFF -DDBUS_ENABLE_INTRUSIVE_TESTS=ON && cmake --build build --config Release'
windows vs15-64 cmake:
extends:
- .cmake-common
- .win-build
script:
- - cmake -DCMAKE_PREFIX_PATH=C:/ -G "Visual Studio 15 2017 Win64" -DCMAKE_BUILD_TYPE=Debug -DDBUS_ENABLE_VERBOSE_MODE=OFF -S . -B build
+ - cmake -DCMAKE_PREFIX_PATH=C:/ -G "Visual Studio 15 2017 Win64" -DCMAKE_BUILD_TYPE=Debug -DDBUS_ENABLE_VERBOSE_MODE=OFF -DDBUS_ENABLE_INTRUSIVE_TESTS=ON -S . -B build
- cmake --build build --config Debug
- cmake --install build --config Debug
# FIXME: a few tests timeout on gitlab runner for unknown reason
- .cmake-common
- .build-env-freebsd
variables:
+ ci_variant: "debug"
# Don't build doxygen documentation since installing the required tools
# massively increases the VM image (and therefore container) size.
CI_BUILD_ARGS: "-DDBUS_ENABLE_DOXYGEN_DOCS=OFF -DDBUS_ENABLE_XML_DOCS=ON -DCMAKE_BUILD_TYPE=Debug"
)
option(DBUS_BUILD_TESTS "enable unit test code" ON)
+option(DBUS_ENABLE_INTRUSIVE_TESTS "enable tests that require insecure extra code in the library and binaries" OFF)
# replacement for AC_C_BIGENDIAN
include (TestBigEndian)
########### command line options ###############
if(DBUS_BUILD_TESTS)
- set(DBUS_ENABLE_INTRUSIVE_TESTS ON)
set(DBUS_ENABLE_MODULAR_TESTS ON)
endif()
add_definitions(${DBUS_BUS_CFLAGS})
-if(DBUS_BUILD_TESTS)
+if(DBUS_ENABLE_MODULAR_TESTS OR DBUS_ENABLE_INTRUSIVE_TESTS)
# set variables used for the .in files (substituted by configure_file) in test/data:
set(DBUS_TEST_EXEC ${Z_DRIVE_IF_WINE}${CMAKE_RUNTIME_OUTPUT_DIRECTORY}${IDE_BIN})
# Working directory for build-time tests, so that they'll pick up
add_subdirectory( dbus )
add_subdirectory( bus )
-if(DBUS_BUILD_TESTS)
+if(DBUS_ENABLE_MODULAR_TESTS OR DBUS_ENABLE_INTRUSIVE_TESTS)
add_subdirectory( test )
add_custom_target(check
COMMAND ctest -R ^test-.*
message(" MSVC code analyze mode: ${DBUS_MSVC_ANALYZE} ")
endif()
message(" Building unit tests: ${DBUS_BUILD_TESTS} ")
+message(" Building intrusive tests: ${DBUS_ENABLE_INTRUSIVE_TESTS} ")
message(" Building with GLib: ${DBUS_WITH_GLIB} ")
message(" Building verbose mode: ${DBUS_ENABLE_VERBOSE_MODE} ")
message(" Building w/o assertions: ${DBUS_DISABLE_ASSERT} ")
endif()
message(" ")
-if(DBUS_BUILD_TESTS)
- message("NOTE: building with unit tests increases the size of the installed library and renders it insecure.")
+if(DBUS_ENABLE_INTRUSIVE_TESTS)
+ message("NOTE: building with intrusive test code increases the size of the installed library and renders it insecure.")
endif()
-if(DBUS_BUILD_TESTS AND DBUS_DISABLE_ASSERT)
+if(DBUS_ENABLE_INTRUSIVE_TESTS AND DBUS_DISABLE_ASSERT)
message("NOTE: building with unit tests but without assertions means tests may not properly report failures (this configuration is only useful when doing something like profiling the tests)")
endif()
// enable unit test code
DBUS_BUILD_TESTS:BOOL=ON
+// embed intrusive test code in the library and binaries
+DBUS_ENABLE_INTRUSIVE_TESTS:BOOL=ON
+
// The name of the dbus daemon executable
DBUS_DAEMON_NAME:STRING=dbus-daemon
option(DBUS_USE_WINE "set to 1 or ON to support running test cases with Wine" OFF)
-if(DBUS_BUILD_TESTS AND CMAKE_CROSSCOMPILING AND CMAKE_SYSTEM_NAME STREQUAL "Windows")
+if((DBUS_ENABLE_MODULAR_TESTS OR DBUS_ENABLE_INTRUSIVE_TESTS) AND CMAKE_CROSSCOMPILING AND CMAKE_SYSTEM_NAME STREQUAL "Windows")
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux")
find_file(WINE_EXECUTABLE
NAMES wine
;;
esac
+ set -- "$@" -D DBUS_BUILD_TESTS=ON
+
+ case "$ci_variant" in
+ (debug)
+ set -- "$@" -D DBUS_ENABLE_INTRUSIVE_TESTS=ON
+ ;;
+ esac
+
$cmake -DCMAKE_VERBOSE_MAKEFILE=ON -DENABLE_WERROR=ON -S "$srcdir" -B "$ci_builddir" "$@"
${make}