mirror of
https://gitlab.freedesktop.org/dbus/dbus.git
synced 2025-12-26 01:40:11 +01:00
_dbus_test_main: Move to test-utils
Now that there is no code outside test/ that calls into this, we can move it into test/, reducing the size of libdbus. dbus-test-tap.[ch] still need to stay in dbus/ as long as there is code in dbus/ or bus/ relying on them, and also need to be linked into libdbus as long as there is other code in libdbus relying on them, so they stay where they are for now. Similarly, dbus-tests.h lists the tests that are still embedded in libdbus, and must stay where it is for the moment. With this move, various tests now need to be linked to the dbus-testutils convenience library. Signed-off-by: Simon McVittie <smcv@collabora.com>
This commit is contained in:
parent
e23bba929a
commit
b7f11c17d1
15 changed files with 217 additions and 274 deletions
|
|
@ -168,13 +168,6 @@ set (DBUS_UTIL_SOURCES
|
|||
${DBUS_DIR}/dbus-sysdeps-util.c
|
||||
)
|
||||
|
||||
if (DBUS_ENABLE_EMBEDDED_TESTS)
|
||||
set (DBUS_UTIL_SOURCES
|
||||
${DBUS_UTIL_SOURCES}
|
||||
${DBUS_DIR}/dbus-test-wrappers.c
|
||||
)
|
||||
endif (DBUS_ENABLE_EMBEDDED_TESTS)
|
||||
|
||||
set (DBUS_UTIL_HEADERS
|
||||
${DBUS_DIR}/dbus-asv-util.h
|
||||
${DBUS_DIR}/dbus-auth-script.h
|
||||
|
|
@ -184,7 +177,6 @@ set (DBUS_UTIL_HEADERS
|
|||
${DBUS_DIR}/dbus-pollable-set.h
|
||||
${DBUS_DIR}/dbus-spawn.h
|
||||
${DBUS_DIR}/dbus-test.h
|
||||
${DBUS_DIR}/dbus-test-wrappers.h
|
||||
)
|
||||
|
||||
### platform specific settings
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ add_helper_executable(test-privserver ${TEST_DIR}/test-privserver.c dbus-testuti
|
|||
add_helper_executable(test-shell-service ${test-shell-service_SOURCES} dbus-testutils)
|
||||
add_helper_executable(test-spawn ${test-spawn_SOURCES} ${DBUS_INTERNAL_LIBRARIES})
|
||||
if(NOT WINCE)
|
||||
add_test_executable(test-spawn-oom ${TEST_DIR}/internals/spawn-oom.c ${DBUS_INTERNAL_LIBRARIES})
|
||||
add_test_executable(test-spawn-oom ${TEST_DIR}/internals/spawn-oom.c dbus-testutils)
|
||||
endif()
|
||||
add_helper_executable(test-exit ${test-exit_SOURCES} ${DBUS_INTERNAL_LIBRARIES})
|
||||
# the second argument of add_helper_executable() is a whitespace-separated
|
||||
|
|
@ -93,24 +93,24 @@ if(WIN32)
|
|||
endif()
|
||||
|
||||
if(DBUS_ENABLE_EMBEDDED_TESTS)
|
||||
add_test_executable(test-misc-internals ${TEST_DIR}/internals/misc-internals.c ${DBUS_INTERNAL_LIBRARIES})
|
||||
add_test_executable(test-misc-internals ${TEST_DIR}/internals/misc-internals.c dbus-testutils)
|
||||
set_target_properties(test-misc-internals PROPERTIES COMPILE_FLAGS ${DBUS_INTERNAL_CLIENT_DEFINITIONS})
|
||||
|
||||
set(SOURCES ${TEST_DIR}/bus/main.c)
|
||||
add_test_executable(test-bus "${SOURCES}" dbus-daemon-internal ${DBUS_INTERNAL_LIBRARIES} ${EXPAT_LIBRARIES})
|
||||
add_test_executable(test-bus "${SOURCES}" dbus-daemon-internal dbus-testutils ${EXPAT_LIBRARIES})
|
||||
set_target_properties(test-bus PROPERTIES COMPILE_FLAGS ${DBUS_INTERNAL_CLIENT_DEFINITIONS})
|
||||
|
||||
set(SOURCES ${TEST_DIR}/bus/dispatch.c)
|
||||
add_test_executable(test-bus-dispatch "${SOURCES}" dbus-daemon-internal ${DBUS_INTERNAL_LIBRARIES} ${EXPAT_LIBRARIES})
|
||||
add_test_executable(test-bus-dispatch "${SOURCES}" dbus-daemon-internal dbus-testutils ${EXPAT_LIBRARIES})
|
||||
set_target_properties(test-bus-dispatch PROPERTIES COMPILE_FLAGS ${DBUS_INTERNAL_CLIENT_DEFINITIONS})
|
||||
|
||||
set(SOURCES ${TEST_DIR}/bus/dispatch-sha1.c)
|
||||
add_test_executable(test-bus-dispatch-sha1 "${SOURCES}" dbus-daemon-internal ${DBUS_INTERNAL_LIBRARIES} ${EXPAT_LIBRARIES})
|
||||
add_test_executable(test-bus-dispatch-sha1 "${SOURCES}" dbus-daemon-internal dbus-testutils ${EXPAT_LIBRARIES})
|
||||
set_target_properties(test-bus-dispatch-sha1 PROPERTIES COMPILE_FLAGS ${DBUS_INTERNAL_CLIENT_DEFINITIONS})
|
||||
|
||||
if(NOT WIN32)
|
||||
add_test_executable(test-bus-system ${TEST_DIR}/bus/system.c launch-helper-internal)
|
||||
add_test_executable(test-bus-launch-helper-oom ${TEST_DIR}/bus/launch-helper-oom.c launch-helper-internal)
|
||||
add_test_executable(test-bus-system ${TEST_DIR}/bus/system.c launch-helper-internal dbus-testutils)
|
||||
add_test_executable(test-bus-launch-helper-oom ${TEST_DIR}/bus/launch-helper-oom.c launch-helper-internal dbus-testutils)
|
||||
add_helper_executable(dbus-daemon-launch-helper-for-tests ${TEST_DIR}/bus/launch-helper-for-tests.c launch-helper-internal)
|
||||
endif()
|
||||
endif()
|
||||
|
|
|
|||
|
|
@ -268,13 +268,6 @@ DBUS_UTIL_SOURCES= \
|
|||
dbus-sysdeps-util.c \
|
||||
dbus-test.h
|
||||
|
||||
if DBUS_ENABLE_EMBEDDED_TESTS
|
||||
DBUS_UTIL_SOURCES += \
|
||||
dbus-test-wrappers.c \
|
||||
dbus-test-wrappers.h \
|
||||
$(NULL)
|
||||
endif
|
||||
|
||||
libdbus_1_la_SOURCES= \
|
||||
$(DBUS_LIB_SOURCES) \
|
||||
$(DBUS_SHARED_SOURCES)
|
||||
|
|
|
|||
|
|
@ -1,183 +0,0 @@
|
|||
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
||||
/*
|
||||
* Copyright 2002-2009 Red Hat Inc.
|
||||
* Copyright 2011-2018 Collabora Ltd.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person
|
||||
* obtaining a copy of this software and associated documentation files
|
||||
* (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
* and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
||||
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include "dbus/dbus-test-wrappers.h"
|
||||
|
||||
#ifndef DBUS_ENABLE_EMBEDDED_TESTS
|
||||
#error This file is only relevant for the embedded tests
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "dbus/dbus-message-internal.h"
|
||||
#include "dbus/dbus-test-tap.h"
|
||||
|
||||
#if HAVE_LOCALE_H
|
||||
#include <locale.h>
|
||||
#endif
|
||||
|
||||
#ifdef DBUS_UNIX
|
||||
# include <dbus/dbus-sysdeps-unix.h>
|
||||
#endif
|
||||
|
||||
/*
|
||||
* 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,
|
||||
* similar to g_strcmp0()).
|
||||
*/
|
||||
static char *
|
||||
strdup0_or_die (const char *str)
|
||||
{
|
||||
char *ret;
|
||||
|
||||
if (str == NULL)
|
||||
return NULL; /* not an error */
|
||||
|
||||
ret = strdup (str);
|
||||
|
||||
if (ret == NULL)
|
||||
_dbus_test_fatal ("Out of memory");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* _dbus_test_main:
|
||||
* @argc: number of command-line arguments
|
||||
* @argv: array of @argc arguments
|
||||
* @n_tests: length of @tests
|
||||
* @tests: array of @n_tests tests
|
||||
* @flags: flags affecting all tests
|
||||
* @test_pre_hook: if not %NULL, called before each test
|
||||
* @test_post_hook: if not %NULL, called after each test
|
||||
*
|
||||
* Wrapper for dbus tests that do not use GLib. Processing of @tests
|
||||
* can be terminated early by an entry with @name = NULL, which is a
|
||||
* convenient way to put a trailing comma on every "real" test entry
|
||||
* without breaking compilation on pedantic C compilers.
|
||||
*/
|
||||
int
|
||||
_dbus_test_main (int argc,
|
||||
char **argv,
|
||||
size_t n_tests,
|
||||
const DBusTestCase *tests,
|
||||
DBusTestFlags flags,
|
||||
void (*test_pre_hook) (void),
|
||||
void (*test_post_hook) (void))
|
||||
{
|
||||
char *test_data_dir;
|
||||
char *specific_test;
|
||||
size_t i;
|
||||
|
||||
#ifdef DBUS_UNIX
|
||||
/* close any inherited fds so dbus-spawn's check for close-on-exec works */
|
||||
_dbus_close_all ();
|
||||
#endif
|
||||
|
||||
#if HAVE_SETLOCALE
|
||||
setlocale(LC_ALL, "");
|
||||
#endif
|
||||
|
||||
/* We can't assume that strings from _dbus_getenv() will remain valid
|
||||
* forever, because some tests call setenv(), which is allowed to
|
||||
* reallocate the entire environment block, and in Wine it seems that it
|
||||
* genuinely does; so we copy them.
|
||||
*
|
||||
* We can't use _dbus_strdup() here because the test might be checking
|
||||
* for memory leaks, so we don't want any libdbus allocations still
|
||||
* alive at the end; so we use strdup(), which is not in Standard C but
|
||||
* is available in both POSIX and Windows. */
|
||||
if (argc > 1 && strcmp (argv[1], "--tap") != 0)
|
||||
test_data_dir = strdup0_or_die (argv[1]);
|
||||
else
|
||||
test_data_dir = strdup0_or_die (_dbus_getenv ("DBUS_TEST_DATA"));
|
||||
|
||||
if (test_data_dir != NULL)
|
||||
_dbus_test_diag ("Test data in %s", test_data_dir);
|
||||
else if (flags & DBUS_TEST_FLAGS_REQUIRE_DATA)
|
||||
_dbus_test_fatal ("Must specify test data directory as argv[1] or "
|
||||
"in DBUS_TEST_DATA environment variable");
|
||||
else
|
||||
_dbus_test_diag ("No test data!");
|
||||
|
||||
if (argc > 2)
|
||||
specific_test = strdup0_or_die (argv[2]);
|
||||
else
|
||||
specific_test = strdup0_or_die (_dbus_getenv ("DBUS_TEST_ONLY"));
|
||||
|
||||
for (i = 0; i < n_tests; i++)
|
||||
{
|
||||
long before, after;
|
||||
DBusInitialFDs *initial_fds = NULL;
|
||||
|
||||
if (tests[i].name == NULL)
|
||||
break;
|
||||
|
||||
if (n_tests > 1 &&
|
||||
specific_test != NULL &&
|
||||
strcmp (specific_test, tests[i].name) != 0)
|
||||
{
|
||||
_dbus_test_skip ("%s - Only intending to run %s",
|
||||
tests[i].name, specific_test);
|
||||
continue;
|
||||
}
|
||||
|
||||
_dbus_test_diag ("Running test: %s", tests[i].name);
|
||||
_dbus_get_monotonic_time (&before, NULL);
|
||||
|
||||
if (test_pre_hook)
|
||||
test_pre_hook ();
|
||||
|
||||
if (flags & DBUS_TEST_FLAGS_CHECK_FD_LEAKS)
|
||||
initial_fds = _dbus_check_fdleaks_enter ();
|
||||
|
||||
if (tests[i].func (test_data_dir))
|
||||
_dbus_test_ok ("%s", tests[i].name);
|
||||
else
|
||||
_dbus_test_not_ok ("%s", tests[i].name);
|
||||
|
||||
_dbus_get_monotonic_time (&after, NULL);
|
||||
|
||||
_dbus_test_diag ("%s test took %ld seconds",
|
||||
tests[i].name, after - before);
|
||||
|
||||
if (test_post_hook)
|
||||
test_post_hook ();
|
||||
|
||||
if (flags & DBUS_TEST_FLAGS_CHECK_MEMORY_LEAKS)
|
||||
_dbus_test_check_memleaks (tests[i].name);
|
||||
|
||||
if (flags & DBUS_TEST_FLAGS_CHECK_FD_LEAKS)
|
||||
_dbus_check_fdleaks_leave (initial_fds);
|
||||
}
|
||||
|
||||
free (test_data_dir);
|
||||
free (specific_test);
|
||||
|
||||
return _dbus_test_done_testing ();
|
||||
}
|
||||
|
|
@ -1,55 +0,0 @@
|
|||
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
||||
/*
|
||||
* Copyright © 2017 Collabora Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person
|
||||
* obtaining a copy of this software and associated documentation files
|
||||
* (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
* and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
||||
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef DBUS_TEST_WRAPPERS_H
|
||||
#define DBUS_TEST_WRAPPERS_H
|
||||
|
||||
#include <dbus/dbus-types.h>
|
||||
|
||||
typedef struct
|
||||
{
|
||||
const char *name;
|
||||
dbus_bool_t (*func) (const char *test_data_dir);
|
||||
} DBusTestCase;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
DBUS_TEST_FLAGS_REQUIRE_DATA = (1 << 0),
|
||||
DBUS_TEST_FLAGS_CHECK_MEMORY_LEAKS = (1 << 1),
|
||||
DBUS_TEST_FLAGS_CHECK_FD_LEAKS = (1 << 2),
|
||||
DBUS_TEST_FLAGS_NONE = 0
|
||||
} DBusTestFlags;
|
||||
|
||||
int _dbus_test_main (int argc,
|
||||
char **argv,
|
||||
size_t n_tests,
|
||||
const DBusTestCase *tests,
|
||||
DBusTestFlags flags,
|
||||
void (*test_pre_hook) (void),
|
||||
void (*test_post_hook) (void));
|
||||
|
||||
#endif
|
||||
|
|
@ -120,7 +120,7 @@ test_shell_LDADD = libdbus-testutils.la
|
|||
test_spawn_SOURCES = spawn-test.c
|
||||
test_spawn_LDADD = $(top_builddir)/dbus/libdbus-internal.la
|
||||
test_spawn_oom_SOURCES = internals/spawn-oom.c
|
||||
test_spawn_oom_LDADD = $(top_builddir)/dbus/libdbus-internal.la
|
||||
test_spawn_oom_LDADD = libdbus-testutils.la
|
||||
|
||||
test_assertions_SOURCES = internals/assertions.c
|
||||
test_assertions_LDADD = libdbus-testutils.la $(GLIB_LIBS)
|
||||
|
|
@ -165,25 +165,40 @@ manual_tcp_SOURCES = manual-tcp.c
|
|||
manual_tcp_LDADD = $(top_builddir)/dbus/libdbus-internal.la
|
||||
|
||||
test_bus_launch_helper_oom_SOURCES = bus/launch-helper-oom.c
|
||||
test_bus_launch_helper_oom_LDADD = $(top_builddir)/bus/liblaunch-helper-internal.la
|
||||
test_bus_launch_helper_oom_LDADD = \
|
||||
$(top_builddir)/bus/liblaunch-helper-internal.la \
|
||||
libdbus-testutils.la \
|
||||
$(NULL)
|
||||
|
||||
dbus_daemon_launch_helper_for_tests_SOURCES = bus/launch-helper-for-tests.c
|
||||
dbus_daemon_launch_helper_for_tests_LDADD = $(top_builddir)/bus/liblaunch-helper-internal.la
|
||||
|
||||
test_bus_system_SOURCES = bus/system.c
|
||||
test_bus_system_LDADD = $(top_builddir)/bus/liblaunch-helper-internal.la
|
||||
test_bus_system_LDADD = \
|
||||
$(top_builddir)/bus/liblaunch-helper-internal.la \
|
||||
libdbus-testutils.la \
|
||||
$(NULL)
|
||||
|
||||
test_bus_SOURCES = bus/main.c
|
||||
test_bus_LDADD = $(top_builddir)/bus/libdbus-daemon-internal.la
|
||||
test_bus_LDADD = \
|
||||
$(top_builddir)/bus/libdbus-daemon-internal.la \
|
||||
libdbus-testutils.la \
|
||||
$(NULL)
|
||||
|
||||
test_bus_dispatch_SOURCES = bus/dispatch.c
|
||||
test_bus_dispatch_LDADD = $(top_builddir)/bus/libdbus-daemon-internal.la
|
||||
test_bus_dispatch_LDADD = \
|
||||
$(top_builddir)/bus/libdbus-daemon-internal.la \
|
||||
libdbus-testutils.la \
|
||||
$(NULL)
|
||||
|
||||
test_bus_dispatch_sha1_SOURCES = bus/dispatch-sha1.c
|
||||
test_bus_dispatch_sha1_LDADD = $(top_builddir)/bus/libdbus-daemon-internal.la
|
||||
test_bus_dispatch_sha1_LDADD = \
|
||||
$(top_builddir)/bus/libdbus-daemon-internal.la \
|
||||
libdbus-testutils.la \
|
||||
$(NULL)
|
||||
|
||||
test_misc_internals_SOURCES = internals/misc-internals.c
|
||||
test_misc_internals_LDADD = $(top_builddir)/dbus/libdbus-internal.la
|
||||
test_misc_internals_LDADD = libdbus-testutils.la
|
||||
|
||||
EXTRA_DIST += dbus-test-runner
|
||||
|
||||
|
|
|
|||
|
|
@ -26,9 +26,9 @@
|
|||
#include "bus/test.h"
|
||||
|
||||
#include <dbus/dbus-test-tap.h>
|
||||
#include <dbus/dbus-test-wrappers.h>
|
||||
|
||||
#include "bus/selinux.h"
|
||||
#include "test/test-utils.h"
|
||||
|
||||
#ifndef DBUS_ENABLE_EMBEDDED_TESTS
|
||||
#error This file is only relevant for the embedded tests
|
||||
|
|
|
|||
|
|
@ -26,9 +26,9 @@
|
|||
#include "bus/test.h"
|
||||
|
||||
#include <dbus/dbus-test-tap.h>
|
||||
#include <dbus/dbus-test-wrappers.h>
|
||||
|
||||
#include "bus/selinux.h"
|
||||
#include "test/test-utils.h"
|
||||
|
||||
#ifndef DBUS_ENABLE_EMBEDDED_TESTS
|
||||
#error This file is only relevant for the embedded tests
|
||||
|
|
|
|||
|
|
@ -28,9 +28,9 @@
|
|||
|
||||
#include <dbus/dbus-internals.h>
|
||||
#include <dbus/dbus-test-tap.h>
|
||||
#include <dbus/dbus-test-wrappers.h>
|
||||
|
||||
#include "bus/activation-helper.h"
|
||||
#include "test/test-utils.h"
|
||||
|
||||
#if !defined(DBUS_ENABLE_EMBEDDED_TESTS) || !defined(DBUS_UNIX)
|
||||
#error This file is only relevant for the embedded tests on Unix
|
||||
|
|
|
|||
|
|
@ -27,9 +27,9 @@
|
|||
#include "bus/test.h"
|
||||
|
||||
#include <dbus/dbus-test-tap.h>
|
||||
#include <dbus/dbus-test-wrappers.h>
|
||||
|
||||
#include "bus/selinux.h"
|
||||
#include "test/test-utils.h"
|
||||
|
||||
#ifndef DBUS_ENABLE_EMBEDDED_TESTS
|
||||
#error This file is only relevant for the embedded tests
|
||||
|
|
|
|||
|
|
@ -27,7 +27,8 @@
|
|||
#include "bus/test.h"
|
||||
|
||||
#include <dbus/dbus-test-tap.h>
|
||||
#include <dbus/dbus-test-wrappers.h>
|
||||
|
||||
#include "test/test-utils.h"
|
||||
|
||||
#if !defined(DBUS_ENABLE_EMBEDDED_TESTS) || !defined(DBUS_UNIX)
|
||||
#error This file is only relevant for the embedded tests on Unix
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@
|
|||
|
||||
#include "dbus/dbus-internals.h"
|
||||
#include "dbus/dbus-test.h"
|
||||
#include "dbus/dbus-test-wrappers.h"
|
||||
#include "test/test-utils.h"
|
||||
|
||||
static DBusTestCase tests[] =
|
||||
{
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@
|
|||
#include "dbus/dbus-spawn.h"
|
||||
#include "dbus/dbus-sysdeps.h"
|
||||
#include "dbus/dbus-test.h"
|
||||
#include "dbus/dbus-test-wrappers.h"
|
||||
#include "test/test-utils.h"
|
||||
|
||||
static char *
|
||||
get_test_exec (const char *exe,
|
||||
|
|
|
|||
|
|
@ -28,6 +28,43 @@
|
|||
#include <config.h>
|
||||
#include "test-utils.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#if HAVE_LOCALE_H
|
||||
#include <locale.h>
|
||||
#endif
|
||||
|
||||
#ifdef DBUS_UNIX
|
||||
# include <dbus/dbus-sysdeps-unix.h>
|
||||
#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,
|
||||
* similar to g_strcmp0()).
|
||||
*/
|
||||
static char *
|
||||
strdup0_or_die (const char *str)
|
||||
{
|
||||
char *ret;
|
||||
|
||||
if (str == NULL)
|
||||
return NULL; /* not an error */
|
||||
|
||||
ret = strdup (str);
|
||||
|
||||
if (ret == NULL)
|
||||
_dbus_test_fatal ("Out of memory");
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
typedef struct
|
||||
{
|
||||
DBusLoop *loop;
|
||||
|
|
@ -416,3 +453,122 @@ test_pending_call_store_reply (DBusPendingCall *pc,
|
|||
*message_p = dbus_pending_call_steal_reply (pc);
|
||||
_dbus_assert (*message_p != NULL);
|
||||
}
|
||||
|
||||
#ifdef DBUS_ENABLE_EMBEDDED_TESTS
|
||||
/*
|
||||
* _dbus_test_main:
|
||||
* @argc: number of command-line arguments
|
||||
* @argv: array of @argc arguments
|
||||
* @n_tests: length of @tests
|
||||
* @tests: array of @n_tests tests
|
||||
* @flags: flags affecting all tests
|
||||
* @test_pre_hook: if not %NULL, called before each test
|
||||
* @test_post_hook: if not %NULL, called after each test
|
||||
*
|
||||
* Wrapper for dbus tests that do not use GLib. Processing of @tests
|
||||
* can be terminated early by an entry with @name = NULL, which is a
|
||||
* convenient way to put a trailing comma on every "real" test entry
|
||||
* without breaking compilation on pedantic C compilers.
|
||||
*/
|
||||
int
|
||||
_dbus_test_main (int argc,
|
||||
char **argv,
|
||||
size_t n_tests,
|
||||
const DBusTestCase *tests,
|
||||
DBusTestFlags flags,
|
||||
void (*test_pre_hook) (void),
|
||||
void (*test_post_hook) (void))
|
||||
{
|
||||
char *test_data_dir;
|
||||
char *specific_test;
|
||||
size_t i;
|
||||
|
||||
#ifdef DBUS_UNIX
|
||||
/* close any inherited fds so dbus-spawn's check for close-on-exec works */
|
||||
_dbus_close_all ();
|
||||
#endif
|
||||
|
||||
#if HAVE_SETLOCALE
|
||||
setlocale(LC_ALL, "");
|
||||
#endif
|
||||
|
||||
/* We can't assume that strings from _dbus_getenv() will remain valid
|
||||
* forever, because some tests call setenv(), which is allowed to
|
||||
* reallocate the entire environment block, and in Wine it seems that it
|
||||
* genuinely does; so we copy them.
|
||||
*
|
||||
* We can't use _dbus_strdup() here because the test might be checking
|
||||
* for memory leaks, so we don't want any libdbus allocations still
|
||||
* alive at the end; so we use strdup(), which is not in Standard C but
|
||||
* is available in both POSIX and Windows. */
|
||||
if (argc > 1 && strcmp (argv[1], "--tap") != 0)
|
||||
test_data_dir = strdup0_or_die (argv[1]);
|
||||
else
|
||||
test_data_dir = strdup0_or_die (_dbus_getenv ("DBUS_TEST_DATA"));
|
||||
|
||||
if (test_data_dir != NULL)
|
||||
_dbus_test_diag ("Test data in %s", test_data_dir);
|
||||
else if (flags & DBUS_TEST_FLAGS_REQUIRE_DATA)
|
||||
_dbus_test_fatal ("Must specify test data directory as argv[1] or "
|
||||
"in DBUS_TEST_DATA environment variable");
|
||||
else
|
||||
_dbus_test_diag ("No test data!");
|
||||
|
||||
if (argc > 2)
|
||||
specific_test = strdup0_or_die (argv[2]);
|
||||
else
|
||||
specific_test = strdup0_or_die (_dbus_getenv ("DBUS_TEST_ONLY"));
|
||||
|
||||
for (i = 0; i < n_tests; i++)
|
||||
{
|
||||
long before, after;
|
||||
DBusInitialFDs *initial_fds = NULL;
|
||||
|
||||
if (tests[i].name == NULL)
|
||||
break;
|
||||
|
||||
if (n_tests > 1 &&
|
||||
specific_test != NULL &&
|
||||
strcmp (specific_test, tests[i].name) != 0)
|
||||
{
|
||||
_dbus_test_skip ("%s - Only intending to run %s",
|
||||
tests[i].name, specific_test);
|
||||
continue;
|
||||
}
|
||||
|
||||
_dbus_test_diag ("Running test: %s", tests[i].name);
|
||||
_dbus_get_monotonic_time (&before, NULL);
|
||||
|
||||
if (test_pre_hook)
|
||||
test_pre_hook ();
|
||||
|
||||
if (flags & DBUS_TEST_FLAGS_CHECK_FD_LEAKS)
|
||||
initial_fds = _dbus_check_fdleaks_enter ();
|
||||
|
||||
if (tests[i].func (test_data_dir))
|
||||
_dbus_test_ok ("%s", tests[i].name);
|
||||
else
|
||||
_dbus_test_not_ok ("%s", tests[i].name);
|
||||
|
||||
_dbus_get_monotonic_time (&after, NULL);
|
||||
|
||||
_dbus_test_diag ("%s test took %ld seconds",
|
||||
tests[i].name, after - before);
|
||||
|
||||
if (test_post_hook)
|
||||
test_post_hook ();
|
||||
|
||||
if (flags & DBUS_TEST_FLAGS_CHECK_MEMORY_LEAKS)
|
||||
_dbus_test_check_memleaks (tests[i].name);
|
||||
|
||||
if (flags & DBUS_TEST_FLAGS_CHECK_FD_LEAKS)
|
||||
_dbus_check_fdleaks_leave (initial_fds);
|
||||
}
|
||||
|
||||
free (test_data_dir);
|
||||
free (specific_test);
|
||||
|
||||
return _dbus_test_done_testing ();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -35,6 +35,8 @@
|
|||
|
||||
#include <dbus/dbus-mainloop.h>
|
||||
#include <dbus/dbus-internals.h>
|
||||
#include <dbus/dbus-types.h>
|
||||
|
||||
typedef DBusLoop TestMainContext;
|
||||
|
||||
_DBUS_WARN_UNUSED_RESULT
|
||||
|
|
@ -64,4 +66,26 @@ void test_server_shutdown (TestMainContext *ctx,
|
|||
void test_pending_call_store_reply (DBusPendingCall *pc,
|
||||
void *data);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
const char *name;
|
||||
dbus_bool_t (*func) (const char *test_data_dir);
|
||||
} DBusTestCase;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
DBUS_TEST_FLAGS_REQUIRE_DATA = (1 << 0),
|
||||
DBUS_TEST_FLAGS_CHECK_MEMORY_LEAKS = (1 << 1),
|
||||
DBUS_TEST_FLAGS_CHECK_FD_LEAKS = (1 << 2),
|
||||
DBUS_TEST_FLAGS_NONE = 0
|
||||
} DBusTestFlags;
|
||||
|
||||
int _dbus_test_main (int argc,
|
||||
char **argv,
|
||||
size_t n_tests,
|
||||
const DBusTestCase *tests,
|
||||
DBusTestFlags flags,
|
||||
void (*test_pre_hook) (void),
|
||||
void (*test_post_hook) (void));
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue