]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
test: Move TAP helpers into dbus-testutils if embedded tests are disabled
authorSimon McVittie <smcv@collabora.com>
Thu, 16 Apr 2020 13:15:18 +0000 (14:15 +0100)
committerSimon McVittie <smcv@collabora.com>
Mon, 20 Apr 2020 09:13:04 +0000 (10:13 +0100)
This lets us run a subset of the tests that previously relied on extra
test-only code being compiled into libdbus.

Signed-off-by: Simon McVittie <smcv@collabora.com>
dbus/CMakeLists.txt
dbus/Makefile.am
dbus/dbus-test-tap.c
dbus/dbus-test-tap.h
test/test-utils.c
test/test-utils.h

index 51b2aec68cb9b19d71a8cf5bde64993187ecc1fc..2fedcba4f55d3a1eeb657215529a7c0e2a41314b 100644 (file)
@@ -125,7 +125,6 @@ set(DBUS_SHARED_SOURCES
     dbus-string.c
     dbus-sysdeps.c
     dbus-pipe.c
-    dbus-test-tap.c
 )
 
 set(DBUS_SHARED_HEADERS
@@ -140,9 +139,14 @@ set(DBUS_SHARED_HEADERS
     dbus-string-private.h
     dbus-pipe.h
     dbus-sysdeps.h
-    dbus-test-tap.h
 )
 
+if(DBUS_ENABLE_EMBEDDED_TESTS)
+    set(DBUS_SHARED_SOURCES ${DBUS_SHARED_SOURCES} dbus-test-tap.c)
+    set(DBUS_SHARED_HEADERS ${DBUS_SHARED_HEADERS} dbus-test-tap.h)
+    # ... else they are in the test library instead
+endif()
+
 ### source code that is generic utility functionality used
 ### by the bus daemon or test apps, but is NOT included
 ### in the D-BUS client library (all symbols in here 
index ceed5ddf338ca16e549862f7265850fd3fd3dff1..7a71f4686ca3b173a57c900f29e3fd28c7559e51 100644 (file)
@@ -240,10 +240,16 @@ DBUS_SHARED_SOURCES=                              \
        $(DBUS_SHARED_arch_sources)             \
        dbus-sysdeps.c                          \
        dbus-sysdeps.h                          \
-       dbus-test-tap.c                         \
-       dbus-test-tap.h                         \
        dbus-valgrind-internal.h
 
+if DBUS_ENABLE_EMBEDDED_TESTS
+DBUS_SHARED_SOURCES += \
+       dbus-test-tap.c \
+       dbus-test-tap.h \
+       $(NULL)
+# else they are included in the test library instead
+endif
+
 ### source code that is generic utility functionality used
 ### by the bus daemon or test apps, but is NOT included
 ### in the D-Bus client library (all symbols in here
index b728fa11605c876bffc5631649cc271a84dacc2c..46738de72c489b1d19e5abc92c08ff03f0073ee7 100644 (file)
@@ -35,8 +35,6 @@
  * will not be explained here.
  */
 
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
-
 #include <stdio.h>
 #include <stdlib.h>
 
@@ -166,6 +164,7 @@ _dbus_test_skip (const char *format,
 void
 _dbus_test_check_memleaks (const char *test_name)
 {
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
   dbus_shutdown ();
 
   if (_dbus_get_malloc_blocks_outstanding () == 0)
@@ -180,6 +179,12 @@ _dbus_test_check_memleaks (const char *test_name)
           _dbus_get_malloc_blocks_outstanding ());
       failures++;
     }
+#else
+  _dbus_test_skip (
+      "unable to determine whether %s leaked memory (not compiled "
+      "with memory instrumentation)",
+      test_name);
+#endif
 }
 
 /*
@@ -202,5 +207,3 @@ _dbus_test_done_testing (void)
 
   return 1;
 }
-
-#endif
index 19f041b6c969dadd5303576b1d660dd01f67421f..fd4c7af74f024fdb6c169307d62717dc24ed5dc7 100644 (file)
 
 #include <dbus/dbus-internals.h>
 
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
-
-DBUS_PRIVATE_EXPORT
+DBUS_EMBEDDED_TESTS_EXPORT
 void _dbus_test_fatal (const char *format,
     ...) _DBUS_GNUC_NORETURN _DBUS_GNUC_PRINTF (1, 2);
 
-DBUS_PRIVATE_EXPORT
+DBUS_EMBEDDED_TESTS_EXPORT
 void _dbus_test_diag (const char *format,
     ...) _DBUS_GNUC_PRINTF (1, 2);
 
-DBUS_PRIVATE_EXPORT
+DBUS_EMBEDDED_TESTS_EXPORT
 void _dbus_test_skip_all (const char *format,
     ...) _DBUS_GNUC_NORETURN _DBUS_GNUC_PRINTF (1, 2);
 
-DBUS_PRIVATE_EXPORT
+DBUS_EMBEDDED_TESTS_EXPORT
 void _dbus_test_ok (const char *format,
     ...) _DBUS_GNUC_PRINTF (1, 2);
-DBUS_PRIVATE_EXPORT
+DBUS_EMBEDDED_TESTS_EXPORT
 void _dbus_test_not_ok (const char *format,
     ...) _DBUS_GNUC_PRINTF (1, 2);
-DBUS_PRIVATE_EXPORT
+DBUS_EMBEDDED_TESTS_EXPORT
 void _dbus_test_skip (const char *format,
     ...) _DBUS_GNUC_PRINTF (1, 2);
 
-DBUS_PRIVATE_EXPORT
+DBUS_EMBEDDED_TESTS_EXPORT
 void _dbus_test_check_memleaks (const char *test_name);
 
-DBUS_PRIVATE_EXPORT
+DBUS_EMBEDDED_TESTS_EXPORT
 int _dbus_test_done_testing (void);
 
 #define _dbus_test_check(a) do { \
@@ -65,5 +63,3 @@ int _dbus_test_done_testing (void);
   } while (0)
 
 #endif
-
-#endif
index 28c9bc048a09a662c61dfe7ffed59f1b7cfc95e7..c8884da49d74aabd5b3a1da4d1425a428f6dba30 100644 (file)
@@ -54,9 +54,7 @@
 #endif
 
 #include "dbus/dbus-message-internal.h"
-#include "dbus/dbus-test-tap.h"
 
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
 /*
  * Like strdup(), but crash on out-of-memory, and pass through NULL
  * unchanged (the "0" in the name is meant to be a mnemonic for this,
@@ -77,7 +75,6 @@ strdup0_or_die (const char *str)
 
   return ret;
 }
-#endif
 
 typedef struct
 {
@@ -468,8 +465,6 @@ test_pending_call_store_reply (DBusPendingCall *pc,
   _dbus_assert (*message_p != NULL);
 }
 
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
-
 #ifdef DBUS_UNIX
 
 /*
@@ -785,4 +780,11 @@ _dbus_test_main (int                  argc,
   return _dbus_test_done_testing ();
 }
 
+/* If embedded tests are enabled, the TAP helpers have to be in the
+ * shared library because some of the embedded tests call them. If not,
+ * implement them here. We #include the file here instead of adding it
+ * to SOURCES because Automake versions older than 1.16 can't cope with
+ * expanding directory variables in SOURCES when using subdir-objects. */
+#ifndef DBUS_ENABLE_EMBEDDED_TESTS
+#include "dbus/dbus-test-tap.c"
 #endif
index eb0d9e24c92fc38d690984372afad1c1c5e6374e..b6a150f311b5b5db0408c6626f57dab74922a1ef 100644 (file)
@@ -38,6 +38,8 @@
 #include <dbus/dbus-internals.h>
 #include <dbus/dbus-types.h>
 
+#include "dbus/dbus-test-tap.h"
+
 typedef DBusLoop TestMainContext;
 
 _DBUS_WARN_UNUSED_RESULT