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 <smcv@collabora.com>
This commit is contained in:
Simon McVittie 2020-04-16 14:15:18 +01:00
parent c46e002fe6
commit fcbb5e6586
6 changed files with 38 additions and 25 deletions

View 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

View file

@ -240,9 +240,15 @@ DBUS_SHARED_SOURCES= \
$(DBUS_SHARED_arch_sources) \
dbus-sysdeps.c \
dbus-sysdeps.h \
dbus-valgrind-internal.h
if DBUS_ENABLE_EMBEDDED_TESTS
DBUS_SHARED_SOURCES += \
dbus-test-tap.c \
dbus-test-tap.h \
dbus-valgrind-internal.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

View 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

View file

@ -29,34 +29,32 @@
#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

View 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

View 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