]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
cmake: Make intrusive (formerly embedded) tests into a separate option
authorSimon McVittie <smcv@collabora.com>
Mon, 9 Dec 2024 18:16:46 +0000 (18:16 +0000)
committerSimon McVittie <smcv@collabora.com>
Tue, 10 Dec 2024 15:43:34 +0000 (15:43 +0000)
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)

.gitlab-ci.yml
CMakeLists.txt
README.cmake
cmake/modules/Macros.cmake
tools/ci-build.sh

index a9928968ef5bbf166ebc215c34dac0ac1186b3a1..45b8407b34e4c11c1fd88937d06bfe23ac451eb5 100644 (file)
@@ -167,13 +167,14 @@ debian image:
     - .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:
@@ -287,12 +288,13 @@ opensuse image:
     - .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:
@@ -360,14 +362,14 @@ windows msys64 ucrt64 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
@@ -469,6 +471,7 @@ freebsd cmake debug:
     - .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"
index 3f9f37f1c9ab0f973f3a981ce546cfea2c4281ff..c2f2880010c6306dcaca47ab7b9851bd7872eede 100644 (file)
@@ -25,6 +25,7 @@ project(dbus
 )
 
 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)
@@ -443,7 +444,6 @@ enable_testing()
 
 ########### command line options ###############
 if(DBUS_BUILD_TESTS)
-    set(DBUS_ENABLE_INTRUSIVE_TESTS ON)
     set(DBUS_ENABLE_MODULAR_TESTS ON)
 endif()
 
@@ -639,7 +639,7 @@ add_definitions(-DHAVE_CONFIG_H)
 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
@@ -700,7 +700,7 @@ endif()
 
 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-.*
@@ -752,6 +752,7 @@ if(MSVC)
 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}              ")
@@ -786,11 +787,11 @@ message("        build timestamp:          ${DBUS_BUILD_TIMESTAMP}             "
 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()
 
index 03e5f27b3821cd5f9b591f0d7a0adf042526b9c2..81cac84b37353b4b892ed21440dad05dc39a49a4 100644 (file)
@@ -124,6 +124,9 @@ CMAKE_INSTALL_PREFIX:PATH=C:/Program Files/dbus
 // 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
 
index 044e2a70dd3e8e8707e7e1a38283ed4dad9ccb78..d952b5f3c0ba1aa2de5af732759e348e41511793 100644 (file)
@@ -1,6 +1,6 @@
 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
index 55a3c1a42aa18211c14dcb11a20088c1f0abc37c..8752904d6a865b58e5b11dbb649f1caddb755437 100755 (executable)
@@ -269,6 +269,14 @@ case "$ci_buildsys" in
                 ;;
         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}