From: Simon McVittie Date: Thu, 16 Apr 2020 13:15:18 +0000 (+0100) Subject: test: Move TAP helpers into dbus-testutils if embedded tests are disabled X-Git-Tag: dbus-1.13.14~2^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fcbb5e658604a9501fe408aa8d2a7a753032f992;p=thirdparty%2Fdbus.git test: Move TAP helpers into dbus-testutils if embedded tests are disabled 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 --- diff --git a/dbus/CMakeLists.txt b/dbus/CMakeLists.txt index 51b2aec68..2fedcba4f 100644 --- a/dbus/CMakeLists.txt +++ b/dbus/CMakeLists.txt @@ -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 diff --git a/dbus/Makefile.am b/dbus/Makefile.am index ceed5ddf3..7a71f4686 100644 --- a/dbus/Makefile.am +++ b/dbus/Makefile.am @@ -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 diff --git a/dbus/dbus-test-tap.c b/dbus/dbus-test-tap.c index b728fa116..46738de72 100644 --- a/dbus/dbus-test-tap.c +++ b/dbus/dbus-test-tap.c @@ -35,8 +35,6 @@ * will not be explained here. */ -#ifdef DBUS_ENABLE_EMBEDDED_TESTS - #include #include @@ -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 diff --git a/dbus/dbus-test-tap.h b/dbus/dbus-test-tap.h index 19f041b6c..fd4c7af74 100644 --- a/dbus/dbus-test-tap.h +++ b/dbus/dbus-test-tap.h @@ -29,34 +29,32 @@ #include -#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 diff --git a/test/test-utils.c b/test/test-utils.c index 28c9bc048..c8884da49 100644 --- a/test/test-utils.c +++ b/test/test-utils.c @@ -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 diff --git a/test/test-utils.h b/test/test-utils.h index eb0d9e24c..b6a150f31 100644 --- a/test/test-utils.h +++ b/test/test-utils.h @@ -38,6 +38,8 @@ #include #include +#include "dbus/dbus-test-tap.h" + typedef DBusLoop TestMainContext; _DBUS_WARN_UNUSED_RESULT