From 870351439769a35344ead435f2490ed933dd8ff4 Mon Sep 17 00:00:00 2001 From: David Zeuthen Date: Thu, 12 Apr 2012 11:16:48 -0400 Subject: Avoid using monotonic time in the DBUS_COOKIE_SHA1 authentication method When libdbus-1 moved to using monotonic time support for the DBUS_COOKIE_SHA1 authentication was broken, in particular interoperability with non-libdbus-1 implementations such as GDBus. The problem is that if monotonic clocks are available in the OS, _dbus_get_current_time() will not return the number of seconds since the Epoch so using it for DBUS_COOKIE_SHA1 will violate the D-Bus specification. If both peers are using libdbus-1 it's not a problem since both ends will use the wrong time and thus agree. However, if the other end is another implementation and following the spec it will not work. First, we change _dbus_get_current_time() back so it always returns time since the Epoch and we then rename it _dbus_get_real_time() to make this clear. We then introduce _dbus_get_monotonic_time() and carefully make all current users of _dbus_get_current_time() use it, if applicable. During this audit, one of the callers, _dbus_generate_uuid(), was currently using monotonic time but it was decided to make it use real time instead. Signed-off-by: David Zeuthen Reviewed-by: Simon McVittie Bug: https://bugs.freedesktop.org/show_bug.cgi?id=48580 --- test/break-loader.c | 2 +- test/name-test/test-pending-call-dispatch.c | 4 ++-- test/name-test/test-pending-call-timeout.c | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'test') diff --git a/test/break-loader.c b/test/break-loader.c index 7bfa7227..1e222569 100644 --- a/test/break-loader.c +++ b/test/break-loader.c @@ -667,7 +667,7 @@ get_random_seed (void) fprintf (stderr, "could not open/read /dev/urandom, using current time for seed\n"); - _dbus_get_current_time (NULL, &tv_usec); + _dbus_get_monotonic_time (NULL, &tv_usec); seed = tv_usec; } diff --git a/test/name-test/test-pending-call-dispatch.c b/test/name-test/test-pending-call-dispatch.c index 57582d49..c8b5a467 100644 --- a/test/name-test/test-pending-call-dispatch.c +++ b/test/name-test/test-pending-call-dispatch.c @@ -98,9 +98,9 @@ main (int argc, char *argv[]) { long delta; - _dbus_get_current_time (&start_tv_sec, &start_tv_usec); + _dbus_get_monotonic_time (&start_tv_sec, &start_tv_usec); _run_iteration (conn); - _dbus_get_current_time (&end_tv_sec, &end_tv_usec); + _dbus_get_monotonic_time (&end_tv_sec, &end_tv_usec); /* we just care about seconds */ delta = end_tv_sec - start_tv_sec; diff --git a/test/name-test/test-pending-call-timeout.c b/test/name-test/test-pending-call-timeout.c index 381113bd..d051faba 100644 --- a/test/name-test/test-pending-call-timeout.c +++ b/test/name-test/test-pending-call-timeout.c @@ -82,9 +82,9 @@ main (int argc, char *argv[]) { long delta; - _dbus_get_current_time (&start_tv_sec, &start_tv_usec); + _dbus_get_monotonic_time (&start_tv_sec, &start_tv_usec); _run_iteration (conn); - _dbus_get_current_time (&end_tv_sec, &end_tv_usec); + _dbus_get_monotonic_time (&end_tv_sec, &end_tv_usec); /* we just care about seconds */ delta = end_tv_sec - start_tv_sec; -- cgit v1.2.1 From 069c96ccde7d480f0d7d74bfc19163938ef4a3d5 Mon Sep 17 00:00:00 2001 From: Antoine Jacoutot Date: Wed, 25 Apr 2012 19:04:07 +0100 Subject: use cp and mkdir -p instead of install within source tree $(INSTALL) and $(INSTALL_DATA) try to change ownerships to root:bin when copying tests to builddir. Presumably this is a difference in behaviour between GNU and BSD install(1): the one in GNU coreutils doesn't try-and-fail to change ownership if you're not root. [Commit message added by smcv] Bug: https://bugs.freedesktop.org/show_bug.cgi?id=48127 Reviewed-by: Simon McVittie --- test/Makefile.am | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'test') diff --git a/test/Makefile.am b/test/Makefile.am index 55610c18..207a5252 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -296,14 +296,14 @@ EXTRA_DIST += $(static_data) ## copy tests to builddir so that generated tests and static tests ## are all in one place. all-local: - $(AM_V_at)$(INSTALL) -d data/valid-config-files/session.d + $(AM_V_at)$(MKDIR_P) data/valid-config-files/session.d $(AM_V_at)set -e && \ if test $(srcdir) = . || test $(srcdir) -ef .; then \ echo '-- No need to copy test data as srcdir = builddir'; \ else \ for F in $(static_data); do \ - $(INSTALL) -d $${F%/*}; \ - $(INSTALL_DATA) $(srcdir)/$$F $$F; \ + $(MKDIR_P) $${F%/*}; \ + cp $(srcdir)/$$F $$F; \ done; \ fi @@ -324,9 +324,9 @@ noinst_DATA = $(imported_data) CLEANFILES = $(noinst_DATA) data/valid-config-files/session.conf: $(top_builddir)/bus/session.conf - $(AM_V_at)$(INSTALL) -d data/valid-config-files - $(AM_V_GEN)$(INSTALL_DATA) $< $@ + $(AM_V_at)$(MKDIR_P) data/valid-config-files + $(AM_V_GEN)cp $< $@ data/valid-config-files/system.conf: $(top_builddir)/bus/system.conf - $(AM_V_at)$(INSTALL) -d data/valid-config-files - $(AM_V_GEN)$(INSTALL_DATA) $< $@ + $(AM_V_at)$(MKDIR_P) data/valid-config-files + $(AM_V_GEN)cp $< $@ -- cgit v1.2.1 From 7db205d25d93f801b5f22dfb8afd059c3961ff4f Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Tue, 5 Jun 2012 13:27:23 +0100 Subject: Fix distcheck: remove potentially-read-only files from builddir During distcheck, the srcdir is read-only. During "make all", cp may preserve the read-only status of the file copied from the srcdir, resulting in failure to overwrite it with an identical file during "make check" (which depends on all-local). Signed-off-by: Simon McVittie --- test/Makefile.am | 1 + 1 file changed, 1 insertion(+) (limited to 'test') diff --git a/test/Makefile.am b/test/Makefile.am index 0418e595..aa04792b 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -294,6 +294,7 @@ all-local: else \ for F in $(static_data); do \ $(MKDIR_P) $${F%/*}; \ + rm -f $$F; \ cp $(srcdir)/$$F $$F; \ done; \ fi -- cgit v1.2.1 From efddba53da6b76478064f43d8235de12151f33ad Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Mon, 12 Mar 2012 14:15:48 +0000 Subject: When not producing a dynamic library, define DBUS_STATIC_BUILD MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When targeting Windows, linking against the static library requires special effort to turn off DLL import/export processing. We normally link some things against the dynamic library, but if we're not building that, we'll have to link everything statically. Based on patches from 'william' on fd.o #46367. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=33973 Tested-by: René Berber --- test/Makefile.am | 3 +++ 1 file changed, 3 insertions(+) (limited to 'test') diff --git a/test/Makefile.am b/test/Makefile.am index aa04792b..e9448998 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -4,8 +4,10 @@ SUBDIRS= . name-test DIST_SUBDIRS=name-test +# CPPFLAGS for binaries that are normally dynamic AM_CPPFLAGS = \ -I$(top_srcdir) \ + $(DBUS_STATIC_BUILD_CPPFLAGS) \ $(GLIB_CFLAGS) \ $(DBUS_GLIB_CFLAGS) \ $(NULL) @@ -13,6 +15,7 @@ AM_CPPFLAGS = \ # improve backtraces from test stuff AM_LDFLAGS = @R_DYNAMIC_LDFLAG@ +# CPPFLAGS for binaries that are always static static_cppflags = \ $(AM_CPPFLAGS) \ -DDBUS_STATIC_BUILD \ -- cgit v1.2.1 From 4a0b41ee31bdc67c56f672f6e0a64c42bf34c1ae Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Mon, 18 Feb 2013 14:30:22 +0000 Subject: Include config.h as the first thing in every .c file ...except for CheckForAbstractSockets.c, which runs before config.h is generated, and sd-daemon.c, which is externally-maintained. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=59971 Signed-off-by: Simon McVittie Reviewed-by: Colin Walters --- test/name-test/test-autolaunch.c | 2 ++ test/test-exit.c | 2 ++ 2 files changed, 4 insertions(+) (limited to 'test') diff --git a/test/name-test/test-autolaunch.c b/test/name-test/test-autolaunch.c index 5e519895..adbeb185 100644 --- a/test/name-test/test-autolaunch.c +++ b/test/name-test/test-autolaunch.c @@ -1,3 +1,5 @@ +#include "config.h" + #include #include #include diff --git a/test/test-exit.c b/test/test-exit.c index f3358185..b4f967ae 100644 --- a/test/test-exit.c +++ b/test/test-exit.c @@ -1,3 +1,5 @@ +#include "config.h" + /* This is a process that just exits with a failure code */ int main (int argc, char **argv) -- cgit v1.2.1 From 2ab900b678abb6df62790549b55230215f20a8a4 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Fri, 5 Apr 2013 13:28:54 +0100 Subject: Do not suppress syslog test's stderr just because init is systemd This causes the test to fail. The assumption implicitly being made was "if pid 1 is systemd, then every caller of _dbus_init_system_log() is a systemd service" which is not valid for the regression test. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=63163 Signed-off-by: Simon McVittie Reviewed-by: Colin Walters --- test/internals/syslog.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/internals/syslog.c b/test/internals/syslog.c index 4f6b7c22..658281cb 100644 --- a/test/internals/syslog.c +++ b/test/internals/syslog.c @@ -54,7 +54,7 @@ test_syslog (Fixture *f, { if (g_test_trap_fork (0, 0)) { - _dbus_init_system_log (); + _dbus_init_system_log (FALSE); _dbus_system_log (DBUS_SYSTEM_LOG_FATAL, MESSAGE "%d", 23); /* should not be reached: exit 0 so the assertion in the main process * will fail */ @@ -66,7 +66,7 @@ test_syslog (Fixture *f, if (g_test_trap_fork (0, 0)) { - _dbus_init_system_log (); + _dbus_init_system_log (FALSE); _dbus_system_log (DBUS_SYSTEM_LOG_INFO, MESSAGE "%d", 42); _dbus_system_log (DBUS_SYSTEM_LOG_SECURITY, MESSAGE "%d", 666); exit (0); @@ -76,7 +76,7 @@ test_syslog (Fixture *f, g_test_trap_assert_stderr ("*" MESSAGE "42\n*" MESSAGE "666\n*"); /* manual test (this is the best we can do on Windows) */ - _dbus_init_system_log (); + _dbus_init_system_log (FALSE); _dbus_system_log (DBUS_SYSTEM_LOG_INFO, MESSAGE "%d", 42); _dbus_system_log (DBUS_SYSTEM_LOG_SECURITY, MESSAGE "%d", 666); } -- cgit v1.2.1 From 6b2add5e70252c513f506f84cc386f47953df48d Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Mon, 22 Apr 2013 15:36:32 +0100 Subject: Accept non-characters when validating Unicode Unicode Corrigendum #9 clarifies that the non-characters U+nFFFE (for n in the range 0 to 0x10), U+nFFFF (for n in the same range), and U+FDD0..U+FDEF are valid for interchange, and their presence does not make a string ill-formed. GLib 2.36 made the corresponding change in its definition of UTF-8 as used by g_utf8_validate() and similar functions. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=63072 Signed-off-by: Simon McVittie --- test/syntax.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/syntax.c b/test/syntax.c index 88db9638..e26b3643 100644 --- a/test/syntax.c +++ b/test/syntax.c @@ -178,12 +178,14 @@ const char * const invalid_single_signatures[] = { const char * const valid_strings[] = { "", - "\xc2\xa9", + "\xc2\xa9", /* UTF-8 (c) symbol */ + "\xef\xbf\xbe", /* U+FFFE is reserved but Corrigendum 9 says it's OK */ NULL }; const char * const invalid_strings[] = { - "\xa9", + "\xa9", /* Latin-1 (c) symbol */ + "\xed\xa0\x80", /* UTF-16 surrogates are not valid in UTF-8 */ NULL }; -- cgit v1.2.1 From 2420f7ae8b72405de1a41760b213e2e0849b2b8d Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Wed, 12 Jun 2013 13:56:39 +0100 Subject: Add a test-case for CVE-2013-2168 Reviewed-by: Thiago Macieira [build system adjusted to compile it even if we don't have GLib -smcv] --- test/Makefile.am | 5 +++ test/internals/printf.c | 89 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 test/internals/printf.c (limited to 'test') diff --git a/test/Makefile.am b/test/Makefile.am index e9448998..6f0e6e10 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -81,6 +81,10 @@ shell_test_LDADD = libdbus-testutils.la spawn_test_CPPFLAGS = $(static_cppflags) spawn_test_LDADD = $(top_builddir)/dbus/libdbus-internal.la +test_printf_SOURCES = internals/printf.c +test_printf_CPPFLAGS = $(static_cppflags) +test_printf_LDADD = $(top_builddir)/dbus/libdbus-internal.la + test_refs_SOURCES = internals/refs.c test_refs_CPPFLAGS = $(static_cppflags) test_refs_LDADD = libdbus-testutils.la $(GLIB_LIBS) @@ -97,6 +101,7 @@ testexec_PROGRAMS = installable_tests = \ shell-test \ + test-printf \ $(NULL) if DBUS_WITH_GLIB diff --git a/test/internals/printf.c b/test/internals/printf.c new file mode 100644 index 00000000..2d2fff8d --- /dev/null +++ b/test/internals/printf.c @@ -0,0 +1,89 @@ +/* Regression test for _dbus_printf_string_upper_bound + * + * Author: Simon McVittie + * Copyright © 2013 Intel Corporation + * + * 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 + +#define DBUS_COMPILATION /* this test uses libdbus-internal */ +#include +#include +#include +#include "test-utils.h" + +#include +#include + +static void +do_test (int minimum, + const char *format, + ...) +{ + va_list ap; + int result; + + va_start (ap, format); + result = _dbus_printf_string_upper_bound (format, ap); + va_end (ap); + + if (result < minimum) + { + fprintf (stderr, "expected at least %d, got %d\n", minimum, result); + abort (); + } +} + +#define X_TIMES_8 "XXXXXXXX" +#define X_TIMES_16 X_TIMES_8 X_TIMES_8 +#define X_TIMES_32 X_TIMES_16 X_TIMES_16 +#define X_TIMES_64 X_TIMES_32 X_TIMES_32 +#define X_TIMES_128 X_TIMES_64 X_TIMES_64 +#define X_TIMES_256 X_TIMES_128 X_TIMES_128 +#define X_TIMES_512 X_TIMES_256 X_TIMES_256 +#define X_TIMES_1024 X_TIMES_512 X_TIMES_512 + +int +main (int argc, + char **argv) +{ + char buf[] = X_TIMES_1024 X_TIMES_1024 X_TIMES_1024 X_TIMES_1024; + int i; + + do_test (1, "%d", 0); + do_test (7, "%d", 1234567); + do_test (3, "%f", 3.5); + + do_test (0, "%s", ""); + do_test (1024, "%s", X_TIMES_1024); + do_test (1025, "%s", X_TIMES_1024 "Y"); + + for (i = 4096; i > 0; i--) + { + buf[i] = '\0'; + do_test (i, "%s", buf); + do_test (i + 3, "%s:%d", buf, 42); + } + + return 0; +} -- cgit v1.2.1 From 2b3272c75ae48c93911bd6f656965cf77d6de3e8 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Tue, 16 Apr 2013 16:28:44 +0100 Subject: Make taking a global lock automatically initialize locking if needed This lets them be thread-safe by default, at the cost that they can now fail. init_uninitialized_locks() and init_global_locks() must now both reimplement the equivalent of _dbus_register_shutdown_func(), by using _dbus_platform_rmutex_lock() on the same underlying mutex around a call to _dbus_register_shutdown_func_unlocked(). This is because if they used the usual _DBUS_LOCK() API (as _dbus_register_shutdown_func() does), it would automatically try to initialize global locking, leading to infinite recursion. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=54972 Signed-off-by: Simon McVittie Reviewed-by: Alban Crequy Reviewed-by: Anas Nashif --- test/name-test/test-threads-init.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'test') diff --git a/test/name-test/test-threads-init.c b/test/name-test/test-threads-init.c index 5e22852a..580ffe14 100644 --- a/test/name-test/test-threads-init.c +++ b/test/name-test/test-threads-init.c @@ -149,11 +149,15 @@ main (int argc, char *argv[]) &dispatch_cond1, &io_path_cond1); - check_mutex_lock (mutex1, mutex2, FALSE); - check_mutex_lock (dispatch_mutex1, dispatch_mutex2, FALSE); - check_mutex_lock (io_path_mutex1, io_path_mutex2, FALSE); - check_condvar_lock (dispatch_cond1, dispatch_cond2, FALSE); - check_condvar_lock (io_path_cond1, io_path_cond2, FALSE); + /* Since 1.7 it is no longer the case that mutex1 != mutex2, because + * initializing global locks automatically initializes locks + * in general. However, it is true that the mutex is not the dummy + * implementation, which is what we really wanted to check here. */ + _dbus_assert (mutex1 != (DBusMutex *) 0xABCDEF); + _dbus_assert (dispatch_mutex1 != (DBusMutex *) 0xABCDEF); + _dbus_assert (dispatch_cond1 != (DBusCondVar *) 0xABCDEF2); + _dbus_assert (io_path_mutex1 != (DBusMutex *) 0xABCDEF); + _dbus_assert (io_path_cond1 != (DBusCondVar *) 0xABCDEF2); _run_iteration (conn); _dbus_connection_test_get_locks (conn, &mutex2, -- cgit v1.2.1 From 134701b758d834eda139843fcb90c144b57a08b0 Mon Sep 17 00:00:00 2001 From: Chengwei Yang Date: Fri, 28 Jun 2013 16:06:41 +0800 Subject: tests to embedded tests: replaced in automake files Signed-off-by: Chengwei Yang Reviewed-by: Simon McVittie Bug: https://bugs.freedesktop.org/show_bug.cgi?id=66291 --- test/Makefile.am | 6 +++--- test/name-test/Makefile.am | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'test') diff --git a/test/Makefile.am b/test/Makefile.am index 6f0e6e10..074017a5 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -33,7 +33,7 @@ libdbus_testutils_la_LIBADD = \ noinst_LTLIBRARIES = libdbus-testutils.la -if DBUS_BUILD_TESTS +if DBUS_ENABLE_EMBEDDED_TESTS ## break-loader removed for now ## these binaries are used in tests but are not themselves tests TEST_BINARIES = \ @@ -59,12 +59,12 @@ if DBUS_UNIX TESTS += ../bus/bus-test-launch-helper$(EXEEXT) endif -else !DBUS_BUILD_TESTS +else !DBUS_ENABLE_EMBEDDED_TESTS TEST_BINARIES= TESTS= -endif !DBUS_BUILD_TESTS +endif !DBUS_ENABLE_EMBEDDED_TESTS noinst_PROGRAMS= $(TEST_BINARIES) diff --git a/test/name-test/Makefile.am b/test/name-test/Makefile.am index 6aaf1783..424dad3a 100644 --- a/test/name-test/Makefile.am +++ b/test/name-test/Makefile.am @@ -11,7 +11,7 @@ AM_LDFLAGS = @R_DYNAMIC_LDFLAG@ ## note that TESTS has special meaning (stuff to use in make check) ## so if adding tests not to be run in make check, don't add them to ## TESTS -if DBUS_BUILD_TESTS +if DBUS_ENABLE_EMBEDDED_TESTS TESTS_ENVIRONMENT=DBUS_TOP_BUILDDIR=@abs_top_builddir@ DBUS_TOP_SRCDIR=@abs_top_srcdir@ PYTHON=@PYTHON@ TESTS=run-test.sh run-test-systemserver.sh else @@ -20,7 +20,7 @@ endif EXTRA_DIST=run-test.sh run-test-systemserver.sh test-wait-for-echo.py test-activation-forking.py -if DBUS_BUILD_TESTS +if DBUS_ENABLE_EMBEDDED_TESTS ## we use noinst_PROGRAMS not check_PROGRAMS for TESTS so that we ## build even when not doing "make check" -- cgit v1.2.1 From 2de11abd56a7ee350e98b8a957c7c7a4902945ce Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Wed, 24 Jul 2013 21:48:58 +0100 Subject: test/marshal: Ensure we use suitably aligned buffers This test was failing on s390; though it could fail on other platforms too. Basically we need to be sure we're passing at least word-aligned buffers to the demarshalling code. malloc() will do that for us. https://bugs.freedesktop.org/show_bug.cgi?id=67279 --- test/marshal.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) (limited to 'test') diff --git a/test/marshal.c b/test/marshal.c index e9ac7e30..e65ee7c1 100644 --- a/test/marshal.c +++ b/test/marshal.c @@ -27,6 +27,7 @@ #include #include +#include #include #include @@ -244,14 +245,30 @@ int main (int argc, char **argv) { + int ret; + char *aligned_le_blob; + char *aligned_be_blob; + g_test_init (&argc, &argv, NULL); - g_test_add ("/demarshal/le", Fixture, le_blob, setup, test_endian, teardown); - g_test_add ("/demarshal/be", Fixture, be_blob, setup, test_endian, teardown); - g_test_add ("/demarshal/needed/le", Fixture, le_blob, setup, test_needed, + /* We have to pass in a buffer that's at least "default aligned", + * i.e. on GNU systems to 8 or 16. The linker may have only given + * us byte-alignment for the char[] static variables. + */ + aligned_le_blob = g_malloc (sizeof (le_blob)); + memcpy (aligned_le_blob, le_blob, sizeof (le_blob)); + aligned_be_blob = g_malloc (sizeof (be_blob)); + memcpy (aligned_be_blob, be_blob, sizeof (be_blob)); + + g_test_add ("/demarshal/le", Fixture, aligned_le_blob, setup, test_endian, teardown); + g_test_add ("/demarshal/be", Fixture, aligned_be_blob, setup, test_endian, teardown); + g_test_add ("/demarshal/needed/le", Fixture, aligned_le_blob, setup, test_needed, teardown); - g_test_add ("/demarshal/needed/be", Fixture, be_blob, setup, test_needed, + g_test_add ("/demarshal/needed/be", Fixture, aligned_be_blob, setup, test_needed, teardown); - return g_test_run (); + ret = g_test_run (); + g_free (aligned_le_blob); + g_free (aligned_be_blob); + return ret; } -- cgit v1.2.1 From 4b63567c02022cc3a5dc2f4ef03c7bd344766b43 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Thu, 22 Aug 2013 18:21:58 +0100 Subject: GetConnectionCredentials: add The initial set of credentials is just UnixUserID and ProcessID. The rest can follow when someone is sufficiently interested to actually test them. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=54445 Reviewed-by: Ralf Habacker [rename a function that Ralf found unclear -smcv] Signed-off-by: Simon McVittie --- test/dbus-daemon.c | 127 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) (limited to 'test') diff --git a/test/dbus-daemon.c b/test/dbus-daemon.c index cc871530..69b6791e 100644 --- a/test/dbus-daemon.c +++ b/test/dbus-daemon.c @@ -39,6 +39,7 @@ #else # include # include +# include #endif typedef struct { @@ -309,6 +310,131 @@ test_echo (Fixture *f, count, elapsed); } +static void +pending_call_store_reply (DBusPendingCall *pc, + void *data) +{ + DBusMessage **message_p = data; + + *message_p = dbus_pending_call_steal_reply (pc); + g_assert (*message_p != NULL); +} + +static void +test_creds (Fixture *f, + gconstpointer context) +{ + const char *unique = dbus_bus_get_unique_name (f->left_conn); + DBusMessage *m = dbus_message_new_method_call (DBUS_SERVICE_DBUS, + DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS, "GetConnectionCredentials"); + DBusPendingCall *pc; + DBusMessageIter args_iter; + DBusMessageIter arr_iter; + DBusMessageIter pair_iter; + DBusMessageIter var_iter; + enum { + SEEN_UNIX_USER = 1, + SEEN_PID = 2, + SEEN_WINDOWS_SID = 4 + } seen = 0; + + if (m == NULL) + g_error ("OOM"); + + if (!dbus_message_append_args (m, + DBUS_TYPE_STRING, &unique, + DBUS_TYPE_INVALID)) + g_error ("OOM"); + + if (!dbus_connection_send_with_reply (f->left_conn, m, &pc, + DBUS_TIMEOUT_USE_DEFAULT) || + pc == NULL) + g_error ("OOM"); + + dbus_message_unref (m); + m = NULL; + + if (dbus_pending_call_get_completed (pc)) + pending_call_store_reply (pc, &m); + else if (!dbus_pending_call_set_notify (pc, pending_call_store_reply, + &m, NULL)) + g_error ("OOM"); + + while (m == NULL) + g_main_context_iteration (NULL, TRUE); + + g_assert_cmpstr (dbus_message_get_signature (m), ==, "a{sv}"); + + dbus_message_iter_init (m, &args_iter); + g_assert_cmpuint (dbus_message_iter_get_arg_type (&args_iter), ==, + DBUS_TYPE_ARRAY); + g_assert_cmpuint (dbus_message_iter_get_element_type (&args_iter), ==, + DBUS_TYPE_DICT_ENTRY); + dbus_message_iter_recurse (&args_iter, &arr_iter); + + while (dbus_message_iter_get_arg_type (&arr_iter) != DBUS_TYPE_INVALID) + { + const char *name; + + dbus_message_iter_recurse (&arr_iter, &pair_iter); + g_assert_cmpuint (dbus_message_iter_get_arg_type (&pair_iter), ==, + DBUS_TYPE_STRING); + dbus_message_iter_get_basic (&pair_iter, &name); + dbus_message_iter_next (&pair_iter); + g_assert_cmpuint (dbus_message_iter_get_arg_type (&pair_iter), ==, + DBUS_TYPE_VARIANT); + dbus_message_iter_recurse (&pair_iter, &var_iter); + + if (g_strcmp0 (name, "UnixUserID") == 0) + { +#ifdef G_OS_UNIX + guint32 u32; + + g_assert (!(seen & SEEN_UNIX_USER)); + g_assert_cmpuint (dbus_message_iter_get_arg_type (&var_iter), ==, + DBUS_TYPE_UINT32); + dbus_message_iter_get_basic (&var_iter, &u32); + g_message ("%s of this process is %u", name, u32); + g_assert_cmpuint (u32, ==, geteuid ()); + seen |= SEEN_UNIX_USER; +#else + g_assert_not_reached (); +#endif + } + else if (g_strcmp0 (name, "ProcessID") == 0) + { + guint32 u32; + + g_assert (!(seen & SEEN_PID)); + g_assert_cmpuint (dbus_message_iter_get_arg_type (&var_iter), ==, + DBUS_TYPE_UINT32); + dbus_message_iter_get_basic (&var_iter, &u32); + g_message ("%s of this process is %u", name, u32); +#ifdef G_OS_UNIX + g_assert_cmpuint (u32, ==, getpid ()); +#elif defined(G_OS_WIN32) + g_assert_cmpuint (u32, ==, GetCurrentProcessId ()); +#else + g_assert_not_reached (); +#endif + seen |= SEEN_PID; + } + + dbus_message_iter_next (&arr_iter); + } + +#ifdef G_OS_UNIX + g_assert (seen & SEEN_UNIX_USER); + g_assert (seen & SEEN_PID); +#endif + +#ifdef G_OS_WIN32 + /* FIXME: when implemented: + g_assert (seen & SEEN_WINDOWS_SID); + */ +#endif +} + static void teardown (Fixture *f, gconstpointer context G_GNUC_UNUSED) @@ -363,6 +489,7 @@ main (int argc, g_test_add ("/echo/session", Fixture, NULL, setup, test_echo, teardown); g_test_add ("/echo/limited", Fixture, &limited_config, setup, test_echo, teardown); + g_test_add ("/creds", Fixture, NULL, setup, test_creds, teardown); return g_test_run (); } -- cgit v1.2.1 From 22fc03d274f186a788efbdbe6b6dfcff1ad474df Mon Sep 17 00:00:00 2001 From: Cosimo Alfarano Date: Fri, 7 Oct 2011 11:25:00 +0100 Subject: Enable anonymous authorization for tests Now that authorization is in SASL mechs, enable anonymous authorizations when we are testing anonymous mechs functionality Bug: http://bugs.freedesktop.org/show_bug.cgi?id=39720 Reviewed-by: Simon McVittie --- test/data/auth/anonymous-server-successful.auth-script | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/data/auth/anonymous-server-successful.auth-script b/test/data/auth/anonymous-server-successful.auth-script index 172ae9de..c53b30f9 100644 --- a/test/data/auth/anonymous-server-successful.auth-script +++ b/test/data/auth/anonymous-server-successful.auth-script @@ -1,6 +1,7 @@ ## this tests the server side in a successful auth of type ANONYMOUS -SERVER +## Act as a server that accepts anonymous authorization +SERVER_ANONYMOUS ## verify that prior to doing anything, we haven't authed as anyone EXPECT_HAVE_NO_CREDENTIALS SEND 'AUTH ANONYMOUS 442d42757320312e312e31' -- cgit v1.2.1 From 9c0a70f5a3faa6a76e9a06e4e192ce551d7b880c Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Fri, 23 Aug 2013 02:57:27 +0200 Subject: Add a simple manual test for authentication/authorization. Bug: http://bugs.freedesktop.org/show_bug.cgi?id=39720 Reviewed-by: Ralf Habacker --- test/Makefile.am | 14 +- test/manual-authz.c | 405 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 417 insertions(+), 2 deletions(-) create mode 100644 test/manual-authz.c (limited to 'test') diff --git a/test/Makefile.am b/test/Makefile.am index 074017a5..4866b328 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -103,6 +103,8 @@ installable_tests = \ shell-test \ test-printf \ $(NULL) +installable_manual_tests += \ + $(NULL) if DBUS_WITH_GLIB installable_tests += \ @@ -116,6 +118,9 @@ installable_tests += \ test-syntax \ test-syslog \ $(NULL) +installable_manual_tests += \ + manual-authz \ + $(NULL) endif DBUS_WITH_GLIB installcheck_tests = @@ -132,6 +137,11 @@ TESTS_ENVIRONMENT = \ DBUS_TEST_HOMEDIR=@abs_top_builddir@/dbus \ $(NULL) +manual_authz_SOURCES = manual-authz.c +manual_authz_LDADD = $(top_builddir)/dbus/libdbus-1.la \ + $(GLIB_LIBS) \ + $(DBUS_GLIB_LIBS) + test_corrupt_SOURCES = corrupt.c test_corrupt_LDADD = $(top_builddir)/dbus/libdbus-1.la \ $(GLIB_LIBS) \ @@ -173,9 +183,9 @@ TESTS += $(installable_tests) installcheck_tests += $(installable_tests) if DBUS_ENABLE_INSTALLED_TESTS - testexec_PROGRAMS += $(installable_tests) + testexec_PROGRAMS += $(installable_tests) $(installable_manual_tests) else !DBUS_ENABLE_INSTALLED_TESTS - noinst_PROGRAMS += $(installable_tests) + noinst_PROGRAMS += $(installable_tests) $(installable_manual_tests) endif !DBUS_ENABLE_INSTALLED_TESTS endif DBUS_ENABLE_MODULAR_TESTS diff --git a/test/manual-authz.c b/test/manual-authz.c new file mode 100644 index 00000000..d228829b --- /dev/null +++ b/test/manual-authz.c @@ -0,0 +1,405 @@ +/* Simple sanity-check for authentication and authorization. + * + * Copyright © 2010-2011 Nokia Corporation + * Copyright © 2012 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 + +#include + +#include +#include + +#ifdef G_OS_UNIX +#include +#include +#endif + +typedef struct { + DBusError e; + + DBusServer *normal_server; + DBusServer *anon_allowed_server; + DBusServer *anon_only_server; + DBusServer *anon_mech_only_server; + DBusServer *anon_disallowed_server; + DBusServer *permissive_server; + DBusServer *unhappy_server; + DBusServer *same_uid_server; + DBusServer *same_uid_or_anon_server; +} Fixture; + +static void oom (void) G_GNUC_NORETURN; +static void +oom (void) +{ + g_error ("out of memory"); +} + +static void +assert_no_error (const DBusError *e) +{ + if (G_UNLIKELY (dbus_error_is_set (e))) + g_error ("expected success but got error: %s: %s", e->name, e->message); +} + +static DBusHandlerResult +server_message_cb (DBusConnection *conn, + DBusMessage *message, + void *data) +{ + if (dbus_message_is_signal (message, DBUS_INTERFACE_LOCAL, "Disconnected")) + { + dbus_connection_unref (conn); + + return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + } + + if (dbus_message_get_type (message) == DBUS_MESSAGE_TYPE_METHOD_CALL) + { + DBusMessage *reply = dbus_message_new_method_return (message); + const char *hello = "Hello, world!"; + unsigned long uid; + char *sid; + + if (dbus_connection_get_unix_user (conn, &uid)) + { + g_message ("message from uid %lu", uid); + } + else if (dbus_connection_get_windows_user (conn, &sid)) + { + if (sid == NULL) + oom (); + + g_message ("message from sid \"%s\"", sid); + dbus_free (sid); + } + else if (dbus_connection_get_is_anonymous (conn)) + { + g_message ("message from Anonymous"); + } + else + { + g_message ("message from ... someone?"); + } + + if (reply == NULL) + oom (); + + if (!dbus_message_append_args (reply, + DBUS_TYPE_STRING, &hello, + DBUS_TYPE_INVALID)) + oom (); + + if (!dbus_connection_send (conn, reply, NULL)) + oom (); + + dbus_message_unref (reply); + + return DBUS_HANDLER_RESULT_HANDLED; + } + + return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; +} + +static dbus_bool_t +permissive_unix_func (DBusConnection *conn, + unsigned long uid, + void *data) +{ + g_message ("accepting Unix user %lu", uid); + return TRUE; +} + +static dbus_bool_t +permissive_win_func (DBusConnection *conn, + const char *sid, + void *data) +{ + g_message ("accepting Windows user \"%s\"", sid); + return TRUE; +} + +static dbus_bool_t +broken_unix_func (DBusConnection *conn, + unsigned long uid, + void *data) +{ + g_error ("libdbus called the Unix user function for an ANONYMOUS-only " + "connection"); + return FALSE; +} + +static dbus_bool_t +broken_win_func (DBusConnection *conn, + const char *sid, + void *data) +{ + g_error ("libdbus called the Windows user function for an ANONYMOUS-only " + "connection"); + return FALSE; +} + +static dbus_bool_t +unhappy_unix_func (DBusConnection *conn, + unsigned long uid, + void *data) +{ + g_message ("rejecting Unix user %lu", uid); + return FALSE; +} + +static dbus_bool_t +unhappy_win_func (DBusConnection *conn, + const char *sid, + void *data) +{ + g_message ("rejecting Windows user \"%s\"", sid); + return FALSE; +} + +static dbus_bool_t +same_uid_unix_func (DBusConnection *conn, + unsigned long uid, + void *data) +{ + g_message ("checking whether Unix user %lu owns this process", uid); + /* I'd use _dbus_unix_user_is_process_owner(), but it's private... */ +#ifdef G_OS_UNIX + return (geteuid () == uid); +#else + return FALSE; +#endif +} + +static dbus_bool_t +same_uid_win_func (DBusConnection *conn, + const char *sid, + void *data) +{ + g_message ("checking whether Windows user \"%s\" owns this process", sid); + g_message ("Stub implementation consistent with dbus-sysdeps-util-win: " + "assume they do"); + return TRUE; +} + +static void +new_conn_cb (DBusServer *server, + DBusConnection *conn, + void *data) +{ + Fixture *f = data; + + dbus_connection_ref (conn); + dbus_connection_setup_with_g_main (conn, NULL); + + if (!dbus_connection_add_filter (conn, server_message_cb, f, NULL)) + oom (); + + if (server == f->normal_server) + { + } + else if (server == f->anon_allowed_server) + { + dbus_connection_set_allow_anonymous (conn, TRUE); + } + else if (server == f->anon_only_server) + { + dbus_connection_set_allow_anonymous (conn, TRUE); + + dbus_connection_set_unix_user_function (conn, unhappy_unix_func, + f, NULL); + dbus_connection_set_windows_user_function (conn, unhappy_win_func, + f, NULL); + } + else if (server == f->anon_mech_only_server) + { + dbus_connection_set_allow_anonymous (conn, TRUE); + + /* should never get called */ + dbus_connection_set_unix_user_function (conn, broken_unix_func, + f, NULL); + dbus_connection_set_windows_user_function (conn, broken_win_func, + f, NULL); + } + else if (server == f->anon_disallowed_server) + { + dbus_connection_set_allow_anonymous (conn, FALSE); + + /* should never get called */ + dbus_connection_set_unix_user_function (conn, broken_unix_func, + f, NULL); + dbus_connection_set_windows_user_function (conn, broken_win_func, + f, NULL); + } + else if (server == f->permissive_server) + { + dbus_connection_set_unix_user_function (conn, permissive_unix_func, + f, NULL); + dbus_connection_set_windows_user_function (conn, permissive_win_func, + f, NULL); + } + else if (server == f->unhappy_server) + { + dbus_connection_set_unix_user_function (conn, unhappy_unix_func, + f, NULL); + dbus_connection_set_windows_user_function (conn, unhappy_win_func, + f, NULL); + } + else if (server == f->same_uid_server) + { + dbus_connection_set_unix_user_function (conn, same_uid_unix_func, + f, NULL); + dbus_connection_set_windows_user_function (conn, same_uid_win_func, + f, NULL); + } + else if (server == f->same_uid_or_anon_server) + { + dbus_connection_set_allow_anonymous (conn, TRUE); + + dbus_connection_set_unix_user_function (conn, same_uid_unix_func, + f, NULL); + dbus_connection_set_windows_user_function (conn, same_uid_win_func, + f, NULL); + } + else + { + g_assert_not_reached (); + } +} + +static void +setup (Fixture *f, + const gchar *listen_addr) +{ + const char *only_anon[] = { "ANONYMOUS", NULL }; + char *connect_addr; + + f->normal_server = dbus_server_listen (listen_addr, &f->e); + assert_no_error (&f->e); + g_assert (f->normal_server != NULL); + dbus_server_set_new_connection_function (f->normal_server, + new_conn_cb, f, NULL); + dbus_server_setup_with_g_main (f->normal_server, NULL); + connect_addr = dbus_server_get_address (f->normal_server); + g_message ("Normal server:\n%s", connect_addr); + dbus_free (connect_addr); + + f->anon_allowed_server = dbus_server_listen (listen_addr, &f->e); + assert_no_error (&f->e); + g_assert (f->anon_allowed_server != NULL); + dbus_server_set_new_connection_function (f->anon_allowed_server, + new_conn_cb, f, NULL); + dbus_server_setup_with_g_main (f->anon_allowed_server, NULL); + connect_addr = dbus_server_get_address (f->anon_allowed_server); + g_message ("Anonymous-allowed server:\n%s", connect_addr); + dbus_free (connect_addr); + + f->anon_only_server = dbus_server_listen (listen_addr, &f->e); + assert_no_error (&f->e); + g_assert (f->anon_only_server != NULL); + dbus_server_set_new_connection_function (f->anon_only_server, + new_conn_cb, f, NULL); + dbus_server_setup_with_g_main (f->anon_only_server, NULL); + connect_addr = dbus_server_get_address (f->anon_only_server); + g_message ("Anonymous-only server:\n%s", connect_addr); + dbus_free (connect_addr); + + f->anon_mech_only_server = dbus_server_listen (listen_addr, &f->e); + assert_no_error (&f->e); + g_assert (f->anon_mech_only_server != NULL); + dbus_server_set_auth_mechanisms (f->anon_mech_only_server, only_anon); + dbus_server_set_new_connection_function (f->anon_mech_only_server, + new_conn_cb, f, NULL); + dbus_server_setup_with_g_main (f->anon_mech_only_server, NULL); + connect_addr = dbus_server_get_address (f->anon_mech_only_server); + g_message ("Anon mech only server:\n%s", connect_addr); + dbus_free (connect_addr); + + f->anon_disallowed_server = dbus_server_listen (listen_addr, &f->e); + assert_no_error (&f->e); + g_assert (f->anon_disallowed_server != NULL); + dbus_server_set_auth_mechanisms (f->anon_disallowed_server, only_anon); + dbus_server_set_new_connection_function (f->anon_disallowed_server, + new_conn_cb, f, NULL); + dbus_server_setup_with_g_main (f->anon_disallowed_server, NULL); + connect_addr = dbus_server_get_address (f->anon_disallowed_server); + g_message ("Anonymous-disallowed server:\n%s", connect_addr); + dbus_free (connect_addr); + + f->permissive_server = dbus_server_listen (listen_addr, &f->e); + assert_no_error (&f->e); + g_assert (f->permissive_server != NULL); + dbus_server_set_new_connection_function (f->permissive_server, + new_conn_cb, f, NULL); + dbus_server_setup_with_g_main (f->permissive_server, NULL); + connect_addr = dbus_server_get_address (f->permissive_server); + g_message ("Permissive server:\n%s", connect_addr); + dbus_free (connect_addr); + + f->unhappy_server = dbus_server_listen (listen_addr, &f->e); + assert_no_error (&f->e); + g_assert (f->unhappy_server != NULL); + dbus_server_set_new_connection_function (f->unhappy_server, + new_conn_cb, f, NULL); + dbus_server_setup_with_g_main (f->unhappy_server, NULL); + connect_addr = dbus_server_get_address (f->unhappy_server); + g_message ("Unhappy server:\n%s", connect_addr); + dbus_free (connect_addr); + + f->same_uid_server = dbus_server_listen (listen_addr, &f->e); + assert_no_error (&f->e); + g_assert (f->same_uid_server != NULL); + dbus_server_set_new_connection_function (f->same_uid_server, + new_conn_cb, f, NULL); + dbus_server_setup_with_g_main (f->same_uid_server, NULL); + connect_addr = dbus_server_get_address (f->same_uid_server); + g_message ("Same-UID server:\n%s", connect_addr); + dbus_free (connect_addr); + + f->same_uid_or_anon_server = dbus_server_listen (listen_addr, &f->e); + assert_no_error (&f->e); + g_assert (f->same_uid_or_anon_server != NULL); + dbus_server_set_new_connection_function (f->same_uid_or_anon_server, + new_conn_cb, f, NULL); + dbus_server_setup_with_g_main (f->same_uid_or_anon_server, NULL); + connect_addr = dbus_server_get_address (f->same_uid_or_anon_server); + g_message ("Same-UID-or-anon server:\n%s", connect_addr); + dbus_free (connect_addr); +} + +int +main (int argc, + char **argv) +{ + Fixture f = { DBUS_ERROR_INIT }; + + if (argc >= 2) + setup (&f, argv[1]); + else + setup (&f, "tcp:host=127.0.0.1"); + + for (;;) + g_main_context_iteration (NULL, TRUE); +} -- cgit v1.2.1 From 71cfa9cdd0d73c650f79b49c21b42ccd36ad71cf Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Mon, 12 Mar 2012 13:13:55 +0000 Subject: Add a test-case for trying to connect with the wrong GUID Bug: https://bugs.freedesktop.org/show_bug.cgi?id=39720 Signed-off-by: Simon McVittie --- test/loopback.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/loopback.c b/test/loopback.c index d0d69c82..39cf03ab 100644 --- a/test/loopback.c +++ b/test/loopback.c @@ -1,7 +1,7 @@ /* Simple sanity-check for loopback through TCP and Unix sockets. * * Author: Simon McVittie - * Copyright © 2010-2011 Nokia Corporation + * Copyright © 2010-2012 Nokia Corporation * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation files @@ -31,6 +31,8 @@ #include #include +#include + typedef struct { DBusError e; @@ -114,6 +116,66 @@ test_connect (Fixture *f, } } +static void +test_bad_guid (Fixture *f, + gconstpointer addr G_GNUC_UNUSED) +{ + DBusMessage *incoming; + gchar *address = g_strdup (dbus_server_get_address (f->server)); + gchar *guid; + + g_test_bug ("39720"); + + g_assert (f->server_conn == NULL); + + g_assert (strstr (address, "guid=") != NULL); + guid = strstr (address, "guid="); + g_assert_cmpuint (strlen (guid), >=, 5 + 32); + + /* Change the first char of the guid to something different */ + if (guid[5] == '0') + guid[5] = 'f'; + else + guid[5] = '0'; + + f->client_conn = dbus_connection_open_private (address, &f->e); + assert_no_error (&f->e); + g_assert (f->client_conn != NULL); + dbus_connection_setup_with_g_main (f->client_conn, NULL); + + while (f->server_conn == NULL) + { + g_print ("."); + g_main_context_iteration (NULL, TRUE); + } + + /* We get disconnected */ + + while (g_queue_is_empty (&f->server_messages)) + { + g_print ("."); + g_main_context_iteration (NULL, TRUE); + } + + g_assert_cmpuint (g_queue_get_length (&f->server_messages), ==, 1); + + incoming = g_queue_pop_head (&f->server_messages); + + g_assert (!dbus_message_contains_unix_fds (incoming)); + g_assert_cmpstr (dbus_message_get_destination (incoming), ==, NULL); + g_assert_cmpstr (dbus_message_get_error_name (incoming), ==, NULL); + g_assert_cmpstr (dbus_message_get_interface (incoming), ==, + DBUS_INTERFACE_LOCAL); + g_assert_cmpstr (dbus_message_get_member (incoming), ==, "Disconnected"); + g_assert_cmpstr (dbus_message_get_sender (incoming), ==, NULL); + g_assert_cmpstr (dbus_message_get_signature (incoming), ==, ""); + g_assert_cmpstr (dbus_message_get_path (incoming), ==, DBUS_PATH_LOCAL); + + dbus_message_unref (incoming); + + g_free (address); +} + static void test_message (Fixture *f, gconstpointer addr) @@ -189,6 +251,7 @@ main (int argc, char **argv) { g_test_init (&argc, &argv, NULL); + g_test_bug_base ("https://bugs.freedesktop.org/show_bug.cgi?id="); g_test_add ("/connect/tcp", Fixture, "tcp:host=127.0.0.1", setup, test_connect, teardown); @@ -207,5 +270,8 @@ main (int argc, test_message, teardown); #endif + g_test_add ("/message/bad-guid", Fixture, "tcp:host=127.0.0.1", setup, + test_bad_guid, teardown); + return g_test_run (); } -- cgit v1.2.1 From 5fcba306d9e4a9caf137e1550eacd566a7428944 Mon Sep 17 00:00:00 2001 From: Ralf Habacker Date: Fri, 23 Aug 2013 03:10:15 +0200 Subject: Manual rebase fix. --- test/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/Makefile.am b/test/Makefile.am index 4866b328..8b2a5255 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -103,7 +103,7 @@ installable_tests = \ shell-test \ test-printf \ $(NULL) -installable_manual_tests += \ +installable_manual_tests = \ $(NULL) if DBUS_WITH_GLIB -- cgit v1.2.1 From e5f16e571667908ca9eb149bc52c1a0ea980a3c1 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Fri, 23 Aug 2013 11:09:31 +0100 Subject: Revert "Enable anonymous authorization for tests" This reverts commit 22fc03d274f186a788efbdbe6b6dfcff1ad474df. --- test/data/auth/anonymous-server-successful.auth-script | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'test') diff --git a/test/data/auth/anonymous-server-successful.auth-script b/test/data/auth/anonymous-server-successful.auth-script index c53b30f9..172ae9de 100644 --- a/test/data/auth/anonymous-server-successful.auth-script +++ b/test/data/auth/anonymous-server-successful.auth-script @@ -1,7 +1,6 @@ ## this tests the server side in a successful auth of type ANONYMOUS -## Act as a server that accepts anonymous authorization -SERVER_ANONYMOUS +SERVER ## verify that prior to doing anything, we haven't authed as anyone EXPECT_HAVE_NO_CREDENTIALS SEND 'AUTH ANONYMOUS 442d42757320312e312e31' -- cgit v1.2.1 From 412538b3b9fb424c3af313815c3928a9ec221ad7 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Wed, 5 Jun 2013 19:58:22 +0100 Subject: Export dbus_setenv() as a utility function It's sufficiently portable that GLib has an equivalent, and I really don't want to have to either open-code it in dbus-run-session or link dbus-run-session statically. We have enough statically-linked rubbish already. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=39196 Reviewed-by: Colin Walters --- test/name-test/test-autolaunch.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'test') diff --git a/test/name-test/test-autolaunch.c b/test/name-test/test-autolaunch.c index adbeb185..732e6dc7 100644 --- a/test/name-test/test-autolaunch.c +++ b/test/name-test/test-autolaunch.c @@ -8,7 +8,6 @@ #endif #include -#include "dbus/dbus-sysdeps.h" int main (int argc, char *argv[]) @@ -16,7 +15,7 @@ main (int argc, char *argv[]) DBusConnection *conn = NULL; DBusError error; - _dbus_setenv ("DBUS_SESSION_BUS_ADDRESS", NULL); + dbus_setenv ("DBUS_SESSION_BUS_ADDRESS", NULL); dbus_error_init (&error); -- cgit v1.2.1 From ce334cb0d6e141bc480f9d52741766018c2d16f7 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Mon, 2 Sep 2013 17:14:38 +0100 Subject: corrupt test: close connection before releasing GSocket GSocket takes responsibility for closing the fd, and there doesn't seem to be any way to tell it not to. When this test is adapted to run under DBusLoop as an alternative to dbus-glib, that becomes a problem, because DBusLoop/DBusSocketSetEpoll do not tolerate that. Work around it. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=68852 Reviewed-by: Ralf Habacker --- test/corrupt.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'test') diff --git a/test/corrupt.c b/test/corrupt.c index 02495901..be0e0222 100644 --- a/test/corrupt.c +++ b/test/corrupt.c @@ -246,6 +246,16 @@ test_corrupt (Fixture *f, "/org/freedesktop/DBus/Local"); dbus_message_unref (incoming); + + /* Free the DBusConnection before the GSocket, because GSocket is + * going to close our fd. GSocket tolerates closing an already-closed + * fd, whereas DBusLoop + DBusSocketSetEpoll doesn't. On Unix + * we could use dup() but that isn't portable to Windows :-( + */ + dbus_connection_close (f->server_conn); + dbus_connection_unref (f->server_conn); + f->server_conn = NULL; + g_object_unref (socket); } @@ -325,6 +335,12 @@ test_byte_order (Fixture *f, "/org/freedesktop/DBus/Local"); dbus_message_unref (message); + + /* Free the DBusConnection before the GSocket, as above. */ + dbus_connection_close (f->server_conn); + dbus_connection_unref (f->server_conn); + f->server_conn = NULL; + g_object_unref (socket); } -- cgit v1.2.1 From f17fd1cc4e8d69f92986b6f452618c6c1b9819dc Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Fri, 30 Aug 2013 17:45:52 +0100 Subject: Define DBUS_COMPILATION externally for all tests that use internal stuff It might as well go in the AM_CPPFLAGS rather than in the source code. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=68852 Reviewed-by: Ralf Habacker --- test/Makefile.am | 1 + test/internals/printf.c | 1 - test/internals/refs.c | 1 - test/internals/syslog.c | 1 - test/shell-test.c | 2 +- test/spawn-test.c | 2 -- test/test-utils.h | 4 ---- 7 files changed, 2 insertions(+), 10 deletions(-) (limited to 'test') diff --git a/test/Makefile.am b/test/Makefile.am index 8b2a5255..fe163c64 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -19,6 +19,7 @@ AM_LDFLAGS = @R_DYNAMIC_LDFLAG@ static_cppflags = \ $(AM_CPPFLAGS) \ -DDBUS_STATIC_BUILD \ + -DDBUS_COMPILATION \ $(NULL) libdbus_testutils_la_CPPFLAGS = \ diff --git a/test/internals/printf.c b/test/internals/printf.c index 2d2fff8d..db151518 100644 --- a/test/internals/printf.c +++ b/test/internals/printf.c @@ -26,7 +26,6 @@ #include -#define DBUS_COMPILATION /* this test uses libdbus-internal */ #include #include #include diff --git a/test/internals/refs.c b/test/internals/refs.c index db43a4da..202dc043 100644 --- a/test/internals/refs.c +++ b/test/internals/refs.c @@ -29,7 +29,6 @@ #include #include -#define DBUS_COMPILATION /* this test uses libdbus-internal */ #include #include #include diff --git a/test/internals/syslog.c b/test/internals/syslog.c index 658281cb..2811b757 100644 --- a/test/internals/syslog.c +++ b/test/internals/syslog.c @@ -30,7 +30,6 @@ #include -#define DBUS_COMPILATION /* this test uses libdbus-internal */ #include #include diff --git a/test/shell-test.c b/test/shell-test.c index b479a9c6..d1dc5b5b 100644 --- a/test/shell-test.c +++ b/test/shell-test.c @@ -1,7 +1,7 @@ #include #include #include -#define DBUS_COMPILATION + #include #include #include diff --git a/test/spawn-test.c b/test/spawn-test.c index f1a55051..e6513fa6 100644 --- a/test/spawn-test.c +++ b/test/spawn-test.c @@ -1,10 +1,8 @@ #include #include -#define DBUS_COMPILATION /* cheat and use dbus-sysdeps */ #include #include -#undef DBUS_COMPILATION #include static void diff --git a/test/test-utils.h b/test/test-utils.h index 3e1e55e6..8d5357e1 100644 --- a/test/test-utils.h +++ b/test/test-utils.h @@ -1,14 +1,10 @@ #ifndef TEST_UTILS_H #define TEST_UTILS_H -#ifndef DBUS_COMPILATION -#define DBUS_COMPILATION /* Cheat and use private stuff */ -#endif #include #include #include #include #include -#undef DBUS_COMPILATION dbus_bool_t test_connection_setup (DBusLoop *loop, DBusConnection *connection); -- cgit v1.2.1 From 30e7a81302a60adc4ec497deee3c0dfe8ec1123e Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Mon, 2 Sep 2013 16:32:31 +0100 Subject: Tests: allow dbus-glib to be replaced with use of libdbus-internal We only use dbus-glib for its main loop; within dbus, DBusLoop is available as an alternative, although it isn't thread-safe and isn't public API. For tests that otherwise only use libdbus public API, it's desirable to be able to avoid DBusLoop, so we can run them against an installed libdbus as an integration test. However, if we don't have dbus-glib, we're going to have to use an in-tree main loop, which might as well be DBusLoop. The major disadvantage of using dbus-glib is that it isn't safe to link both dbus-1 and dbus-internal at the same time. This is awkward for a future test case that wants to use _dbus_getsid() in dbus-daemon.c, but only on Windows (fd.o #54445). If we use the same API wrapper around both dbus-glib and DBusLoop, we can compile that test against dbus-glib or against DBusLoop, depending on the platform. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=68852 Reviewed-by: Ralf Habacker --- test/Makefile.am | 84 ++++++++++++++++++++++++++------------- test/corrupt.c | 21 ++++++---- test/dbus-daemon-eavesdrop.c | 27 ++++++++----- test/dbus-daemon.c | 21 ++++++---- test/loopback.c | 23 ++++++----- test/manual-authz.c | 30 +++++++------- test/marshal.c | 1 - test/name-test/Makefile.am | 9 +++-- test/relay.c | 25 +++++++----- test/test-utils.c | 93 ++++++++++++++++++++++++++++++++++++++++---- test/test-utils.h | 35 ++++++++++++----- 11 files changed, 262 insertions(+), 107 deletions(-) (limited to 'test') diff --git a/test/Makefile.am b/test/Makefile.am index fe163c64..281b3e2e 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -20,19 +20,40 @@ static_cppflags = \ $(AM_CPPFLAGS) \ -DDBUS_STATIC_BUILD \ -DDBUS_COMPILATION \ + -DDBUS_TEST_USE_INTERNAL \ $(NULL) -libdbus_testutils_la_CPPFLAGS = \ - $(static_cppflags) +noinst_LTLIBRARIES = libdbus-testutils-internal.la + +# You can link either libdbus-testutils, dbus-glib and libdbus-1, +# or libdbus-testutils-internal and libdbus-internal - never both in the +# same binary. +if DBUS_WITH_DBUS_GLIB +noinst_LTLIBRARIES += libdbus-testutils.la libdbus_testutils_la_SOURCES = \ test-utils.c \ test-utils.h \ $(NULL) libdbus_testutils_la_LIBADD = \ - $(top_builddir)/dbus/libdbus-internal.la \ + $(top_builddir)/dbus/libdbus-1.la \ + $(GLIB_LIBS) \ + $(DBUS_GLIB_LIBS) \ $(NULL) +testutils_shared_if_possible = libdbus-testutils.la +else +testutils_shared_if_possible = libdbus-testutils-internal.la +endif -noinst_LTLIBRARIES = libdbus-testutils.la +libdbus_testutils_internal_la_CPPFLAGS = \ + $(static_cppflags) \ + $(NULL) +libdbus_testutils_internal_la_SOURCES = \ + test-utils.c \ + test-utils.h \ + $(NULL) +libdbus_testutils_internal_la_LIBADD = \ + $(top_builddir)/dbus/libdbus-internal.la \ + $(NULL) if DBUS_ENABLE_EMBEDDED_TESTS ## break-loader removed for now @@ -70,15 +91,15 @@ endif !DBUS_ENABLE_EMBEDDED_TESTS noinst_PROGRAMS= $(TEST_BINARIES) test_service_CPPFLAGS = $(static_cppflags) -test_service_LDADD = libdbus-testutils.la +test_service_LDADD = libdbus-testutils-internal.la test_names_CPPFLAGS = $(static_cppflags) -test_names_LDADD = libdbus-testutils.la +test_names_LDADD = libdbus-testutils-internal.la ## break_loader_CPPFLAGS = $(static_cppflags) ## break_loader_LDADD = $(top_builddir)/dbus/libdbus-internal.la test_shell_service_CPPFLAGS = $(static_cppflags) -test_shell_service_LDADD = libdbus-testutils.la +test_shell_service_LDADD = libdbus-testutils-internal.la shell_test_CPPFLAGS = $(static_cppflags) -shell_test_LDADD = libdbus-testutils.la +shell_test_LDADD = libdbus-testutils-internal.la spawn_test_CPPFLAGS = $(static_cppflags) spawn_test_LDADD = $(top_builddir)/dbus/libdbus-internal.la @@ -88,11 +109,11 @@ test_printf_LDADD = $(top_builddir)/dbus/libdbus-internal.la test_refs_SOURCES = internals/refs.c test_refs_CPPFLAGS = $(static_cppflags) -test_refs_LDADD = libdbus-testutils.la $(GLIB_LIBS) +test_refs_LDADD = libdbus-testutils-internal.la $(GLIB_LIBS) test_syslog_SOURCES = internals/syslog.c test_syslog_CPPFLAGS = $(static_cppflags) -test_syslog_LDADD = libdbus-testutils.la $(GLIB_LIBS) +test_syslog_LDADD = libdbus-testutils-internal.la $(GLIB_LIBS) EXTRA_DIST = dbus-test-runner @@ -139,45 +160,52 @@ TESTS_ENVIRONMENT = \ $(NULL) manual_authz_SOURCES = manual-authz.c -manual_authz_LDADD = $(top_builddir)/dbus/libdbus-1.la \ +manual_authz_LDADD = \ + $(testutils_shared_if_possible) \ $(GLIB_LIBS) \ - $(DBUS_GLIB_LIBS) + $(NULL) test_corrupt_SOURCES = corrupt.c -test_corrupt_LDADD = $(top_builddir)/dbus/libdbus-1.la \ +test_corrupt_LDADD = \ + $(testutils_shared_if_possible) \ $(GLIB_LIBS) \ - $(DBUS_GLIB_LIBS) + $(NULL) test_loopback_SOURCES = loopback.c -test_loopback_LDADD = $(top_builddir)/dbus/libdbus-1.la \ +test_loopback_LDADD = \ + $(testutils_shared_if_possible) \ $(GLIB_LIBS) \ - $(DBUS_GLIB_LIBS) + $(NULL) test_relay_SOURCES = relay.c -test_relay_LDADD = $(top_builddir)/dbus/libdbus-1.la \ +test_relay_LDADD = \ + $(testutils_shared_if_possible) \ $(GLIB_LIBS) \ - $(DBUS_GLIB_LIBS) + $(NULL) test_dbus_daemon_SOURCES = dbus-daemon.c -test_dbus_daemon_LDADD = $(top_builddir)/dbus/libdbus-1.la \ +test_dbus_daemon_LDADD = \ + $(testutils_shared_if_possible) \ $(GLIB_LIBS) \ - $(DBUS_GLIB_LIBS) + $(NULL) test_dbus_daemon_eavesdrop_SOURCES = dbus-daemon-eavesdrop.c -test_dbus_daemon_eavesdrop_CPPFLAGS = $(GLIB_CFLAGS) $(DBUS_GLIB_CFLAGS) -test_dbus_daemon_eavesdrop_LDFLAGS = @R_DYNAMIC_LDFLAG@ -test_dbus_daemon_eavesdrop_LDADD = $(top_builddir)/dbus/libdbus-1.la \ +test_dbus_daemon_eavesdrop_LDADD = \ + $(testutils_shared_if_possible) \ $(GLIB_LIBS) \ - $(DBUS_GLIB_LIBS) + $(NULL) test_marshal_SOURCES = marshal.c -test_marshal_LDADD = $(top_builddir)/dbus/libdbus-1.la \ +test_marshal_LDADD = \ + $(top_builddir)/dbus/libdbus-1.la \ $(GLIB_LIBS) \ - $(DBUS_GLIB_LIBS) + $(NULL) test_syntax_SOURCES = syntax.c -test_syntax_LDADD = $(top_builddir)/dbus/libdbus-1.la \ - $(GLIB_LIBS) +test_syntax_LDADD = \ + $(top_builddir)/dbus/libdbus-1.la \ + $(GLIB_LIBS) \ + $(NULL) if DBUS_ENABLE_MODULAR_TESTS TESTS += $(installable_tests) diff --git a/test/corrupt.c b/test/corrupt.c index be0e0222..1a7d4460 100644 --- a/test/corrupt.c +++ b/test/corrupt.c @@ -30,10 +30,12 @@ #include #include -#include + +#include "test-utils.h" typedef struct { DBusError e; + TestMainContext *ctx; DBusServer *server; DBusConnection *server_conn; @@ -72,13 +74,14 @@ new_conn_cb (DBusServer *server, g_assert (f->server_conn == NULL); f->server_conn = dbus_connection_ref (server_conn); - dbus_connection_setup_with_g_main (server_conn, NULL); + test_connection_setup (f->ctx, server_conn); } static void setup (Fixture *f, gconstpointer addr) { + f->ctx = test_main_context_get (); dbus_error_init (&f->e); g_queue_init (&f->client_messages); @@ -88,7 +91,7 @@ setup (Fixture *f, dbus_server_set_new_connection_function (f->server, new_conn_cb, f, NULL); - dbus_server_setup_with_g_main (f->server, NULL); + test_server_setup (f->ctx, f->server); } static void @@ -103,12 +106,12 @@ test_connect (Fixture *f, dbus_server_get_address (f->server), &f->e); assert_no_error (&f->e); g_assert (f->client_conn != NULL); - dbus_connection_setup_with_g_main (f->client_conn, NULL); + test_connection_setup (f->ctx, f->client_conn); while (f->server_conn == NULL) { g_print ("."); - g_main_context_iteration (NULL, TRUE); + test_main_context_iterate (f->ctx, TRUE); } have_mem = dbus_connection_add_filter (f->client_conn, @@ -137,7 +140,7 @@ test_message (Fixture *f, while (g_queue_is_empty (&f->client_messages)) { g_print ("."); - g_main_context_iteration (NULL, TRUE); + test_main_context_iterate (f->ctx, TRUE); } g_assert_cmpuint (g_queue_get_length (&f->client_messages), ==, 1); @@ -229,7 +232,7 @@ test_corrupt (Fixture *f, while (g_queue_is_empty (&f->client_messages)) { g_print ("."); - g_main_context_iteration (NULL, TRUE); + test_main_context_iterate (f->ctx, TRUE); } incoming = g_queue_pop_head (&f->client_messages); @@ -318,7 +321,7 @@ test_byte_order (Fixture *f, while (g_queue_is_empty (&f->client_messages)) { g_print ("."); - g_main_context_iteration (NULL, TRUE); + test_main_context_iterate (f->ctx, TRUE); } message = g_queue_pop_head (&f->client_messages); @@ -368,6 +371,8 @@ teardown (Fixture *f, dbus_server_unref (f->server); f->server = NULL; } + + test_main_context_unref (f->ctx); } int diff --git a/test/dbus-daemon-eavesdrop.c b/test/dbus-daemon-eavesdrop.c index 0bd923d2..2c45f54e 100644 --- a/test/dbus-daemon-eavesdrop.c +++ b/test/dbus-daemon-eavesdrop.c @@ -30,7 +30,6 @@ #include #include -#include #include @@ -42,6 +41,8 @@ # include #endif +#include "test-utils.h" + #define SENDER_NAME "test.eavesdrop.sender" #define SENDER_PATH "/test/eavesdrop/sender" #define SENDER_IFACE SENDER_NAME @@ -71,6 +72,7 @@ typedef enum { } SignalDst; typedef struct { + TestMainContext *ctx; DBusError e; GError *ge; @@ -160,7 +162,8 @@ spawn_dbus_daemon (gchar *binary, } static DBusConnection * -connect_to_bus (const gchar *address) +connect_to_bus (Fixture *f, + const gchar *address) { DBusConnection *conn; DBusError error = DBUS_ERROR_INIT; @@ -175,7 +178,7 @@ connect_to_bus (const gchar *address) g_assert (ok); g_assert (dbus_bus_get_unique_name (conn) != NULL); - dbus_connection_setup_with_g_main (conn, NULL); + test_connection_setup (f->ctx, conn); return conn; } @@ -380,6 +383,8 @@ setup (Fixture *f, gchar *config; gchar *address; + f->ctx = test_main_context_get (); + f->ge = NULL; dbus_error_init (&f->e); @@ -409,12 +414,12 @@ setup (Fixture *f, g_free (dbus_daemon); g_free (config); - f->sender = connect_to_bus (address); + f->sender = connect_to_bus (f, address); dbus_bus_request_name (f->sender, SENDER_NAME, DBUS_NAME_FLAG_DO_NOT_QUEUE, &(f->e)); - f->receiver = connect_to_bus (address); - f->eavesdropper = connect_to_bus (address); - f->politelistener = connect_to_bus (address); + f->receiver = connect_to_bus (f, address); + f->eavesdropper = connect_to_bus (f, address); + f->politelistener = connect_to_bus (f, address); add_receiver_filter (f); add_politelistener_filter (f); add_eavesdropper_filter (f); @@ -432,7 +437,7 @@ test_eavesdrop_broadcast (Fixture *f, while (!f->receiver_got_stopper || !f->politelistener_got_stopper || !f->eavesdropper_got_stopper) - g_main_context_iteration (NULL, TRUE); + test_main_context_iterate (f->ctx, TRUE); /* all the three connection can receive a broadcast */ g_assert_cmpint (f->receiver_dst, ==, BROADCAST); @@ -452,7 +457,7 @@ test_eavesdrop_unicast_to_sender (Fixture *f, while (!f->receiver_got_stopper || !f->politelistener_got_stopper || !f->eavesdropper_got_stopper) - g_main_context_iteration (NULL, TRUE); + test_main_context_iterate (f->ctx, TRUE); /* not directed to it and not broadcasted, they cannot receive it */ g_assert_cmpint (f->receiver_dst, ==, NONE_YET); @@ -472,7 +477,7 @@ test_eavesdrop_unicast_to_receiver (Fixture *f, while (!f->receiver_got_stopper || !f->politelistener_got_stopper || !f->eavesdropper_got_stopper) - g_main_context_iteration (NULL, TRUE); + test_main_context_iterate (f->ctx, TRUE); /* direct to him */ g_assert_cmpint (f->receiver_dst, ==, TO_ME); @@ -534,6 +539,8 @@ teardown (Fixture *f, #endif g_spawn_close_pid (f->daemon_pid); + + test_main_context_unref (f->ctx); } int diff --git a/test/dbus-daemon.c b/test/dbus-daemon.c index 69b6791e..22ea23e3 100644 --- a/test/dbus-daemon.c +++ b/test/dbus-daemon.c @@ -29,7 +29,6 @@ #include #include -#include #include @@ -42,9 +41,13 @@ # include #endif +#include "test-utils.h" + typedef struct { gboolean skip; + TestMainContext *ctx; + DBusError e; GError *ge; @@ -127,7 +130,8 @@ spawn_dbus_daemon (gchar *binary, } static DBusConnection * -connect_to_bus (const gchar *address) +connect_to_bus (Fixture *f, + const gchar *address) { DBusConnection *conn; DBusError error = DBUS_ERROR_INIT; @@ -142,7 +146,7 @@ connect_to_bus (const gchar *address) g_assert (ok); g_assert (dbus_bus_get_unique_name (conn) != NULL); - dbus_connection_setup_with_g_main (conn, NULL); + test_connection_setup (f->ctx, conn); return conn; } @@ -184,6 +188,7 @@ setup (Fixture *f, gchar *arg; gchar *address; + f->ctx = test_main_context_get (); f->ge = NULL; dbus_error_init (&f->e); @@ -227,8 +232,8 @@ setup (Fixture *f, g_free (dbus_daemon); g_free (arg); - f->left_conn = connect_to_bus (address); - f->right_conn = connect_to_bus (address); + f->left_conn = connect_to_bus (f, address); + f->right_conn = connect_to_bus (f, address); g_free (address); } @@ -302,7 +307,7 @@ test_echo (Fixture *f, } while (received < count) - g_main_context_iteration (NULL, TRUE); + test_main_context_iterate (f->ctx, TRUE); elapsed = g_test_timer_elapsed (); @@ -361,7 +366,7 @@ test_creds (Fixture *f, g_error ("OOM"); while (m == NULL) - g_main_context_iteration (NULL, TRUE); + test_main_context_iterate (f->ctx, TRUE); g_assert_cmpstr (dbus_message_get_signature (m), ==, "a{sv}"); @@ -473,6 +478,8 @@ teardown (Fixture *f, g_spawn_close_pid (f->daemon_pid); f->daemon_pid = 0; } + + test_main_context_unref (f->ctx); } static Config limited_config = { diff --git a/test/loopback.c b/test/loopback.c index 39cf03ab..7526d8d2 100644 --- a/test/loopback.c +++ b/test/loopback.c @@ -29,11 +29,13 @@ #include #include -#include #include +#include "test-utils.h" + typedef struct { + TestMainContext *ctx; DBusError e; DBusServer *server; @@ -74,7 +76,7 @@ new_conn_cb (DBusServer *server, g_assert (f->server_conn == NULL); f->server_conn = dbus_connection_ref (server_conn); - dbus_connection_setup_with_g_main (server_conn, NULL); + test_connection_setup (f->ctx, server_conn); have_mem = dbus_connection_add_filter (server_conn, server_message_cb, f, NULL); @@ -85,6 +87,7 @@ static void setup (Fixture *f, gconstpointer addr) { + f->ctx = test_main_context_get (); dbus_error_init (&f->e); g_queue_init (&f->server_messages); @@ -94,7 +97,7 @@ setup (Fixture *f, dbus_server_set_new_connection_function (f->server, new_conn_cb, f, NULL); - dbus_server_setup_with_g_main (f->server, NULL); + test_server_setup (f->ctx, f->server); } static void @@ -107,12 +110,12 @@ test_connect (Fixture *f, dbus_server_get_address (f->server), &f->e); assert_no_error (&f->e); g_assert (f->client_conn != NULL); - dbus_connection_setup_with_g_main (f->client_conn, NULL); + test_connection_setup (f->ctx, f->client_conn); while (f->server_conn == NULL) { g_print ("."); - g_main_context_iteration (NULL, TRUE); + test_main_context_iterate (f->ctx, TRUE); } } @@ -141,12 +144,12 @@ test_bad_guid (Fixture *f, f->client_conn = dbus_connection_open_private (address, &f->e); assert_no_error (&f->e); g_assert (f->client_conn != NULL); - dbus_connection_setup_with_g_main (f->client_conn, NULL); + test_connection_setup (f->ctx, f->client_conn); while (f->server_conn == NULL) { g_print ("."); - g_main_context_iteration (NULL, TRUE); + test_main_context_iterate (f->ctx, TRUE); } /* We get disconnected */ @@ -154,7 +157,7 @@ test_bad_guid (Fixture *f, while (g_queue_is_empty (&f->server_messages)) { g_print ("."); - g_main_context_iteration (NULL, TRUE); + test_main_context_iterate (f->ctx, TRUE); } g_assert_cmpuint (g_queue_get_length (&f->server_messages), ==, 1); @@ -197,7 +200,7 @@ test_message (Fixture *f, while (g_queue_is_empty (&f->server_messages)) { g_print ("."); - g_main_context_iteration (NULL, TRUE); + test_main_context_iterate (f->ctx, TRUE); } g_assert_cmpuint (g_queue_get_length (&f->server_messages), ==, 1); @@ -244,6 +247,8 @@ teardown (Fixture *f, dbus_server_unref (f->server); f->server = NULL; } + + test_main_context_unref (f->ctx); } int diff --git a/test/manual-authz.c b/test/manual-authz.c index d228829b..f9e3688e 100644 --- a/test/manual-authz.c +++ b/test/manual-authz.c @@ -29,15 +29,17 @@ #include #include -#include #ifdef G_OS_UNIX #include #include #endif +#include "test-utils.h" + typedef struct { DBusError e; + TestMainContext *ctx; DBusServer *normal_server; DBusServer *anon_allowed_server; @@ -212,7 +214,7 @@ new_conn_cb (DBusServer *server, Fixture *f = data; dbus_connection_ref (conn); - dbus_connection_setup_with_g_main (conn, NULL); + test_connection_setup (f->ctx, conn); if (!dbus_connection_add_filter (conn, server_message_cb, f, NULL)) oom (); @@ -301,7 +303,7 @@ setup (Fixture *f, g_assert (f->normal_server != NULL); dbus_server_set_new_connection_function (f->normal_server, new_conn_cb, f, NULL); - dbus_server_setup_with_g_main (f->normal_server, NULL); + test_server_setup (f->ctx, f->normal_server); connect_addr = dbus_server_get_address (f->normal_server); g_message ("Normal server:\n%s", connect_addr); dbus_free (connect_addr); @@ -311,7 +313,7 @@ setup (Fixture *f, g_assert (f->anon_allowed_server != NULL); dbus_server_set_new_connection_function (f->anon_allowed_server, new_conn_cb, f, NULL); - dbus_server_setup_with_g_main (f->anon_allowed_server, NULL); + test_server_setup (f->ctx, f->anon_allowed_server); connect_addr = dbus_server_get_address (f->anon_allowed_server); g_message ("Anonymous-allowed server:\n%s", connect_addr); dbus_free (connect_addr); @@ -321,7 +323,7 @@ setup (Fixture *f, g_assert (f->anon_only_server != NULL); dbus_server_set_new_connection_function (f->anon_only_server, new_conn_cb, f, NULL); - dbus_server_setup_with_g_main (f->anon_only_server, NULL); + test_server_setup (f->ctx, f->anon_only_server); connect_addr = dbus_server_get_address (f->anon_only_server); g_message ("Anonymous-only server:\n%s", connect_addr); dbus_free (connect_addr); @@ -332,7 +334,7 @@ setup (Fixture *f, dbus_server_set_auth_mechanisms (f->anon_mech_only_server, only_anon); dbus_server_set_new_connection_function (f->anon_mech_only_server, new_conn_cb, f, NULL); - dbus_server_setup_with_g_main (f->anon_mech_only_server, NULL); + test_server_setup (f->ctx, f->anon_mech_only_server); connect_addr = dbus_server_get_address (f->anon_mech_only_server); g_message ("Anon mech only server:\n%s", connect_addr); dbus_free (connect_addr); @@ -343,7 +345,7 @@ setup (Fixture *f, dbus_server_set_auth_mechanisms (f->anon_disallowed_server, only_anon); dbus_server_set_new_connection_function (f->anon_disallowed_server, new_conn_cb, f, NULL); - dbus_server_setup_with_g_main (f->anon_disallowed_server, NULL); + test_server_setup (f->ctx, f->anon_disallowed_server); connect_addr = dbus_server_get_address (f->anon_disallowed_server); g_message ("Anonymous-disallowed server:\n%s", connect_addr); dbus_free (connect_addr); @@ -353,7 +355,7 @@ setup (Fixture *f, g_assert (f->permissive_server != NULL); dbus_server_set_new_connection_function (f->permissive_server, new_conn_cb, f, NULL); - dbus_server_setup_with_g_main (f->permissive_server, NULL); + test_server_setup (f->ctx, f->permissive_server); connect_addr = dbus_server_get_address (f->permissive_server); g_message ("Permissive server:\n%s", connect_addr); dbus_free (connect_addr); @@ -363,7 +365,7 @@ setup (Fixture *f, g_assert (f->unhappy_server != NULL); dbus_server_set_new_connection_function (f->unhappy_server, new_conn_cb, f, NULL); - dbus_server_setup_with_g_main (f->unhappy_server, NULL); + test_server_setup (f->ctx, f->unhappy_server); connect_addr = dbus_server_get_address (f->unhappy_server); g_message ("Unhappy server:\n%s", connect_addr); dbus_free (connect_addr); @@ -373,7 +375,7 @@ setup (Fixture *f, g_assert (f->same_uid_server != NULL); dbus_server_set_new_connection_function (f->same_uid_server, new_conn_cb, f, NULL); - dbus_server_setup_with_g_main (f->same_uid_server, NULL); + test_server_setup (f->ctx, f->same_uid_server); connect_addr = dbus_server_get_address (f->same_uid_server); g_message ("Same-UID server:\n%s", connect_addr); dbus_free (connect_addr); @@ -383,7 +385,7 @@ setup (Fixture *f, g_assert (f->same_uid_or_anon_server != NULL); dbus_server_set_new_connection_function (f->same_uid_or_anon_server, new_conn_cb, f, NULL); - dbus_server_setup_with_g_main (f->same_uid_or_anon_server, NULL); + test_server_setup (f->ctx, f->same_uid_or_anon_server); connect_addr = dbus_server_get_address (f->same_uid_or_anon_server); g_message ("Same-UID-or-anon server:\n%s", connect_addr); dbus_free (connect_addr); @@ -393,7 +395,7 @@ int main (int argc, char **argv) { - Fixture f = { DBUS_ERROR_INIT }; + Fixture f = { DBUS_ERROR_INIT, test_main_context_get () }; if (argc >= 2) setup (&f, argv[1]); @@ -401,5 +403,7 @@ main (int argc, setup (&f, "tcp:host=127.0.0.1"); for (;;) - g_main_context_iteration (NULL, TRUE); + test_main_context_iterate (f.ctx, TRUE); + + /* never returns */ } diff --git a/test/marshal.c b/test/marshal.c index e65ee7c1..d74e7671 100644 --- a/test/marshal.c +++ b/test/marshal.c @@ -30,7 +30,6 @@ #include #include -#include typedef struct { DBusError e; diff --git a/test/name-test/Makefile.am b/test/name-test/Makefile.am index 424dad3a..54b02af0 100644 --- a/test/name-test/Makefile.am +++ b/test/name-test/Makefile.am @@ -3,6 +3,7 @@ AM_CPPFLAGS = \ -I$(top_srcdir) \ -DDBUS_COMPILATION \ -DDBUS_STATIC_BUILD \ + -DDBUS_TEST_USE_INTERNAL \ $(NULL) # if assertions are enabled, improve backtraces @@ -31,9 +32,9 @@ test_pending_call_timeout_LDADD=$(top_builddir)/dbus/libdbus-internal.la test_threads_init_LDADD=$(top_builddir)/dbus/libdbus-internal.la test_ids_LDADD=$(top_builddir)/dbus/libdbus-internal.la -test_shutdown_LDADD=../libdbus-testutils.la -test_privserver_LDADD=../libdbus-testutils.la -test_privserver_client_LDADD=../libdbus-testutils.la -test_autolaunch_LDADD=../libdbus-testutils.la +test_shutdown_LDADD=../libdbus-testutils-internal.la +test_privserver_LDADD=../libdbus-testutils-internal.la +test_privserver_client_LDADD=../libdbus-testutils-internal.la +test_autolaunch_LDADD=../libdbus-testutils-internal.la endif diff --git a/test/relay.c b/test/relay.c index f4129d0a..ecfe4c82 100644 --- a/test/relay.c +++ b/test/relay.c @@ -29,7 +29,8 @@ #include #include -#include + +#include "test-utils.h" /* This is basically a miniature dbus-daemon. We relay messages from the client * on the left to the client on the right. @@ -43,6 +44,7 @@ */ typedef struct { + TestMainContext *ctx; DBusError e; DBusServer *server; @@ -113,13 +115,14 @@ new_conn_cb (DBusServer *server, f->right_server_conn = dbus_connection_ref (server_conn); } - dbus_connection_setup_with_g_main (server_conn, NULL); + test_connection_setup (f->ctx, server_conn); } static void setup (Fixture *f, gconstpointer data G_GNUC_UNUSED) { + f->ctx = test_main_context_get (); dbus_error_init (&f->e); g_queue_init (&f->messages); @@ -129,7 +132,7 @@ setup (Fixture *f, dbus_server_set_new_connection_function (f->server, new_conn_cb, f, NULL); - dbus_server_setup_with_g_main (f->server, NULL); + test_server_setup (f->ctx, f->server); } static void @@ -148,25 +151,25 @@ test_connect (Fixture *f, f->left_client_conn = dbus_connection_open_private (address, &f->e); assert_no_error (&f->e); g_assert (f->left_client_conn != NULL); - dbus_connection_setup_with_g_main (f->left_client_conn, NULL); + test_connection_setup (f->ctx, f->left_client_conn); while (f->left_server_conn == NULL) { g_print ("."); - g_main_context_iteration (NULL, TRUE); + test_main_context_iterate (f->ctx, TRUE); } f->right_client_conn = dbus_connection_open_private (address, &f->e); assert_no_error (&f->e); g_assert (f->right_client_conn != NULL); - dbus_connection_setup_with_g_main (f->right_client_conn, NULL); + test_connection_setup (f->ctx, f->right_client_conn); dbus_free (address); while (f->right_server_conn == NULL) { g_print ("."); - g_main_context_iteration (NULL, TRUE); + test_main_context_iterate (f->ctx, TRUE); } have_mem = dbus_connection_add_filter (f->right_client_conn, @@ -208,7 +211,7 @@ test_relay (Fixture *f, while (g_queue_get_length (&f->messages) < 2) { g_print ("."); - g_main_context_iteration (NULL, TRUE); + test_main_context_iterate (f->ctx, TRUE); } g_assert_cmpuint (g_queue_get_length (&f->messages), ==, 2); @@ -237,7 +240,7 @@ test_limit (Fixture *f, /* This was an attempt to reproduce fd.o #34393. It didn't work. */ g_test_bug ("34393"); dbus_connection_set_max_received_size (f->left_server_conn, 1); - g_main_context_iteration (NULL, TRUE); + test_main_context_iterate (f->ctx, TRUE); for (i = 0; i < MANY; i++) { @@ -253,7 +256,7 @@ test_limit (Fixture *f, { while (g_queue_is_empty (&f->messages)) { - g_main_context_iteration (NULL, TRUE); + test_main_context_iterate (f->ctx, TRUE); } while ((incoming = g_queue_pop_head (&f->messages)) != NULL) @@ -302,6 +305,8 @@ teardown (Fixture *f, dbus_server_unref (f->server); f->server = NULL; } + + test_main_context_unref (f->ctx); } int diff --git a/test/test-utils.c b/test/test-utils.c index c3c3ed34..9a4f3584 100644 --- a/test/test-utils.c +++ b/test/test-utils.c @@ -1,6 +1,13 @@ #include #include "test-utils.h" +#ifndef DBUS_TEST_USE_INTERNAL +# include +# include +#endif + +#ifdef DBUS_TEST_USE_INTERNAL + typedef struct { DBusLoop *loop; @@ -97,10 +104,14 @@ cdata_new (DBusLoop *loop, return cd; } +#endif /* DBUS_TEST_USE_INTERNAL */ + dbus_bool_t -test_connection_setup (DBusLoop *loop, +test_connection_setup (TestMainContext *ctx, DBusConnection *connection) { +#ifdef DBUS_TEST_USE_INTERNAL + DBusLoop *loop = ctx; CData *cd; cd = NULL; @@ -148,10 +159,23 @@ test_connection_setup (DBusLoop *loop, dbus_connection_set_timeout_functions (connection, NULL, NULL, NULL, NULL, NULL); return FALSE; +#else /* !DBUS_TEST_USE_INTERNAL */ + + dbus_connection_setup_with_g_main (connection, ctx); + return TRUE; + +#endif /* !DBUS_TEST_USE_INTERNAL */ +} + +static void +die (const char *message) +{ + fprintf (stderr, "*** %s", message); + exit (1); } void -test_connection_shutdown (DBusLoop *loop, +test_connection_shutdown (TestMainContext *ctx, DBusConnection *connection) { if (!dbus_connection_set_watch_functions (connection, @@ -159,18 +183,20 @@ test_connection_shutdown (DBusLoop *loop, NULL, NULL, NULL, NULL)) - _dbus_assert_not_reached ("setting watch functions to NULL failed"); + die ("setting watch functions to NULL failed"); if (!dbus_connection_set_timeout_functions (connection, NULL, NULL, NULL, NULL, NULL)) - _dbus_assert_not_reached ("setting timeout functions to NULL failed"); + die ("setting timeout functions to NULL failed"); dbus_connection_set_dispatch_status_function (connection, NULL, NULL, NULL); } +#ifdef DBUS_TEST_USE_INTERNAL + typedef struct { DBusLoop *loop; @@ -252,10 +278,14 @@ remove_server_timeout (DBusTimeout *timeout, _dbus_loop_remove_timeout (context->loop, timeout); } +#endif /* DBUS_TEST_USE_INTERNAL */ + dbus_bool_t -test_server_setup (DBusLoop *loop, +test_server_setup (TestMainContext *ctx, DBusServer *server) { +#ifdef DBUS_TEST_USE_INTERNAL + DBusLoop *loop = ctx; ServerData *sd; sd = serverdata_new (loop, server); @@ -293,10 +323,17 @@ test_server_setup (DBusLoop *loop, test_server_shutdown (loop, server); return FALSE; + +#else /* !DBUS_TEST_USE_INTERNAL */ + + dbus_server_setup_with_g_main (server, ctx); + return TRUE; + +#endif /* !DBUS_TEST_USE_INTERNAL */ } void -test_server_shutdown (DBusLoop *loop, +test_server_shutdown (TestMainContext *ctx, DBusServer *server) { dbus_server_disconnect (server); @@ -305,11 +342,51 @@ test_server_shutdown (DBusLoop *loop, NULL, NULL, NULL, NULL, NULL)) - _dbus_assert_not_reached ("setting watch functions to NULL failed"); + die ("setting watch functions to NULL failed"); if (!dbus_server_set_timeout_functions (server, NULL, NULL, NULL, NULL, NULL)) - _dbus_assert_not_reached ("setting timeout functions to NULL failed"); + die ("setting timeout functions to NULL failed"); +} + +TestMainContext * +test_main_context_get (void) +{ +#ifdef DBUS_TEST_USE_INTERNAL + return _dbus_loop_new (); +#else + /* I suspect dbus-glib relies the default main context in some places */ + return g_main_context_ref (g_main_context_default ()); +#endif +} + +TestMainContext * +test_main_context_ref (TestMainContext *ctx) +{ +#ifdef DBUS_TEST_USE_INTERNAL + return _dbus_loop_ref (ctx); +#else + return g_main_context_ref (ctx); +#endif +} + +void test_main_context_unref (TestMainContext *ctx) +{ +#ifdef DBUS_TEST_USE_INTERNAL + _dbus_loop_unref (ctx); +#else + g_main_context_unref (ctx); +#endif +} + +void test_main_context_iterate (TestMainContext *ctx, + dbus_bool_t may_block) +{ +#ifdef DBUS_TEST_USE_INTERNAL + _dbus_loop_iterate (ctx, may_block); +#else + g_main_context_iteration (ctx, may_block); +#endif } diff --git a/test/test-utils.h b/test/test-utils.h index 8d5357e1..0d3f3690 100644 --- a/test/test-utils.h +++ b/test/test-utils.h @@ -1,21 +1,38 @@ #ifndef TEST_UTILS_H #define TEST_UTILS_H -#include + #include #include -#include -#include -dbus_bool_t test_connection_setup (DBusLoop *loop, +#include + +#ifdef DBUS_TEST_USE_INTERNAL + +# include +# include + typedef DBusLoop TestMainContext; + +#else /* !DBUS_TEST_USE_INTERNAL */ + +# include + typedef GMainContext TestMainContext; + +#endif /* !DBUS_TEST_USE_INTERNAL */ + +TestMainContext *test_main_context_get (void); +TestMainContext *test_main_context_ref (TestMainContext *ctx); +void test_main_context_unref (TestMainContext *ctx); +void test_main_context_iterate (TestMainContext *ctx, + dbus_bool_t may_block); + +dbus_bool_t test_connection_setup (TestMainContext *ctx, DBusConnection *connection); -void test_connection_shutdown (DBusLoop *loop, +void test_connection_shutdown (TestMainContext *ctx, DBusConnection *connection); -void test_connection_dispatch_all_messages (DBusConnection *connection); -dbus_bool_t test_connection_dispatch_one_message (DBusConnection *connection); -dbus_bool_t test_server_setup (DBusLoop *loop, +dbus_bool_t test_server_setup (TestMainContext *ctx, DBusServer *server); -void test_server_shutdown (DBusLoop *loop, +void test_server_shutdown (TestMainContext *ctx, DBusServer *server); #endif -- cgit v1.2.1 From 9d80d46a794e0770494aa517d1b94e7e6ea9e21d Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Tue, 3 Sep 2013 12:25:31 +0100 Subject: run-with-tmp-session-bus.sh: create a unique temporary file per process This makes the regression tests OK to run in parallel. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=68852 Reviewed-by: Ralf Habacker --- test/name-test/.gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/name-test/.gitignore b/test/name-test/.gitignore index 09f7ad36..2bf313a5 100644 --- a/test/name-test/.gitignore +++ b/test/name-test/.gitignore @@ -3,7 +3,7 @@ Makefile Makefile.in echo-error-output.tmp -run-with-tmp-session-bus.conf +tmp-session-bus.*.conf test-ids test-names test-pending-call-dispatch -- cgit v1.2.1 From 87df259d8c4aae3d188a15d7976c0f63141119e8 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Tue, 3 Sep 2013 12:16:32 +0100 Subject: Add CPPFLAGS to "shared if possible" test binaries In principle we ought to define DBUS_STATIC_BUILD in anything that's using libdbus-internal.la (to avoid linking failures on statically-linked mingw builds), and DBUS_TEST_USE_INTERNAL in any test that's using the non-dbus-glib code paths of test-utils.[ch] (to avoid the GLib requirement, although in practice, everything "shared if possible" requires GLib at the moment anyway). Bug: https://bugs.freedesktop.org/show_bug.cgi?id=68852 Reviewed-by: Ralf Habacker --- test/Makefile.am | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'test') diff --git a/test/Makefile.am b/test/Makefile.am index 281b3e2e..405aa1c2 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -39,9 +39,11 @@ libdbus_testutils_la_LIBADD = \ $(GLIB_LIBS) \ $(DBUS_GLIB_LIBS) \ $(NULL) -testutils_shared_if_possible = libdbus-testutils.la +testutils_shared_if_possible_cppflags = $(AM_CPPFLAGS) +testutils_shared_if_possible_libs = libdbus-testutils.la else -testutils_shared_if_possible = libdbus-testutils-internal.la +testutils_shared_if_possible_cppflags = $(static_cppflags) +testutils_shared_if_possible_libs = libdbus-testutils-internal.la endif libdbus_testutils_internal_la_CPPFLAGS = \ @@ -160,38 +162,44 @@ TESTS_ENVIRONMENT = \ $(NULL) manual_authz_SOURCES = manual-authz.c +manual_authz_CPPFLAGS = $(testutils_shared_if_possible_cppflags) manual_authz_LDADD = \ - $(testutils_shared_if_possible) \ + $(testutils_shared_if_possible_libs) \ $(GLIB_LIBS) \ $(NULL) test_corrupt_SOURCES = corrupt.c +test_corrupt_CPPFLAGS = $(testutils_shared_if_possible_cppflags) test_corrupt_LDADD = \ - $(testutils_shared_if_possible) \ + $(testutils_shared_if_possible_libs) \ $(GLIB_LIBS) \ $(NULL) test_loopback_SOURCES = loopback.c +test_loopback_CPPFLAGS = $(testutils_shared_if_possible_cppflags) test_loopback_LDADD = \ - $(testutils_shared_if_possible) \ + $(testutils_shared_if_possible_libs) \ $(GLIB_LIBS) \ $(NULL) test_relay_SOURCES = relay.c +test_relay_CPPFLAGS = $(testutils_shared_if_possible_cppflags) test_relay_LDADD = \ - $(testutils_shared_if_possible) \ + $(testutils_shared_if_possible_libs) \ $(GLIB_LIBS) \ $(NULL) test_dbus_daemon_SOURCES = dbus-daemon.c +test_dbus_daemon_CPPFLAGS = $(testutils_shared_if_possible_cppflags) test_dbus_daemon_LDADD = \ - $(testutils_shared_if_possible) \ + $(testutils_shared_if_possible_libs) \ $(GLIB_LIBS) \ $(NULL) test_dbus_daemon_eavesdrop_SOURCES = dbus-daemon-eavesdrop.c +test_dbus_daemon_eavesdrop_CPPFLAGS = $(testutils_shared_if_possible_cppflags) test_dbus_daemon_eavesdrop_LDADD = \ - $(testutils_shared_if_possible) \ + $(testutils_shared_if_possible_libs) \ $(GLIB_LIBS) \ $(NULL) -- cgit v1.2.1 From 50674ed689a280d3100c843dfebf5b1f3e9928a4 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Wed, 26 Jun 2013 12:33:29 +0100 Subject: Use GNU make features to reduce repetition Bug: https://bugs.freedesktop.org/show_bug.cgi?id=48277 Signed-off-by: Simon McVittie Reviewed-by: Chengwei Yang --- test/Makefile.am | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'test') diff --git a/test/Makefile.am b/test/Makefile.am index 405aa1c2..eddcd644 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -370,10 +370,6 @@ imported_data = \ noinst_DATA = $(imported_data) CLEANFILES = $(noinst_DATA) -data/valid-config-files/session.conf: $(top_builddir)/bus/session.conf - $(AM_V_at)$(MKDIR_P) data/valid-config-files - $(AM_V_GEN)cp $< $@ - -data/valid-config-files/system.conf: $(top_builddir)/bus/system.conf +$(imported_data): data/valid-config-files/%.conf: $(top_builddir)/bus/%.conf $(AM_V_at)$(MKDIR_P) data/valid-config-files $(AM_V_GEN)cp $< $@ -- cgit v1.2.1 From 0cea59aad50c75ee6125e6fc627c4f083489d40d Mon Sep 17 00:00:00 2001 From: Chengwei Yang Date: Wed, 11 Sep 2013 15:27:38 +0800 Subject: Remove DBUS_COMPILATION from test source code DBUS_COMPILATION definition was moved to test/Makefile.am static_cppflags, so remove it from test source code. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=68852 Reviewed-by: Simon McVittie --- test/break-loader.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'test') diff --git a/test/break-loader.c b/test/break-loader.c index e62b8c20..1e406fc3 100644 --- a/test/break-loader.c +++ b/test/break-loader.c @@ -33,12 +33,10 @@ #include #include -#define DBUS_COMPILATION #include #include #include #include -#undef DBUS_COMPILATION static DBusString failure_dir; static int total_attempts; -- cgit v1.2.1 From ee0f28f6a575337fe6d0571f5935f82a601c37c9 Mon Sep 17 00:00:00 2001 From: Chengwei Yang Date: Fri, 13 Sep 2013 16:56:26 +0800 Subject: Use test binaries in build dir to do test When do autolaunch testing, libdbus will try to start dbus-launch in installed direcotry, if fail then fall back to dbus-launch in $PATH. dbus-launch does a relative better thing to start dbus-daemon in build directory, however, in most of case, the build $prefix is different from the real prefix where dbus-daemon installed. So dbus-daemon will fail to start due to can't find its config file. And then dbus-launch will fall back to finally the installed dbus-daemon. This patch fix this behavior and will start dbus-launch and dbus-daemon in build directory in test environment. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=37849 --- test/name-test/Makefile.am | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/name-test/Makefile.am b/test/name-test/Makefile.am index 54b02af0..931cb2c9 100644 --- a/test/name-test/Makefile.am +++ b/test/name-test/Makefile.am @@ -13,7 +13,12 @@ AM_LDFLAGS = @R_DYNAMIC_LDFLAG@ ## so if adding tests not to be run in make check, don't add them to ## TESTS if DBUS_ENABLE_EMBEDDED_TESTS -TESTS_ENVIRONMENT=DBUS_TOP_BUILDDIR=@abs_top_builddir@ DBUS_TOP_SRCDIR=@abs_top_srcdir@ PYTHON=@PYTHON@ +TESTS_ENVIRONMENT = \ + DBUS_TOP_BUILDDIR=@abs_top_builddir@ \ + DBUS_TOP_SRCDIR=@abs_top_srcdir@ \ + PYTHON=@PYTHON@ \ + DBUS_TEST_DATA=@abs_top_builddir@/test/data \ + $(NULL) TESTS=run-test.sh run-test-systemserver.sh else TESTS= -- cgit v1.2.1 From 86c6dbd20b578e28f383ade7c9af1572e4169347 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Fri, 13 Sep 2013 14:59:17 +0100 Subject: Don't assume that X11 autolaunch will work if DISPLAY is unset In practice, it won't; other forms of autolaunch (like Mac OS launchd) might, but we can't really assert either way. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=40352 Reviewed-by: Chengwei Yang [amended to reinstate use of dbus/dbus-sysdeps.h which was removed by 412538b3b9 -smcv] Signed-off-by: Simon McVittie --- test/name-test/test-autolaunch.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/name-test/test-autolaunch.c b/test/name-test/test-autolaunch.c index 732e6dc7..8b5206a6 100644 --- a/test/name-test/test-autolaunch.c +++ b/test/name-test/test-autolaunch.c @@ -8,6 +8,7 @@ #endif #include +#include "dbus/dbus-sysdeps.h" int main (int argc, char *argv[]) @@ -22,14 +23,16 @@ main (int argc, char *argv[]) conn = dbus_bus_get (DBUS_BUS_SESSION, &error); #ifdef DBUS_ENABLE_X11_AUTOLAUNCH - if (dbus_error_is_set (&error)) + /* If X11 autolaunch was enabled, we expect dbus-launch to have worked. */ + if (_dbus_getenv ("DISPLAY") != NULL && dbus_error_is_set (&error)) { fprintf (stderr, "*** Failed to autolaunch session bus: %s\n", error.message); dbus_error_free (&error); return 1; } -#else +#endif + /* We don't necessarily expect it to *work* without X (although it might - * for instance on Mac OS it might have used launchd). Just check that the * results are consistent. */ @@ -39,7 +42,6 @@ main (int argc, char *argv[]) fprintf (stderr, "*** Autolaunched session bus, but an error was set!\n"); return 1; } -#endif if (!dbus_error_is_set (&error) && conn == NULL) { -- cgit v1.2.1 From 47df159cc5b82d29588749b4dafedde33a8a3470 Mon Sep 17 00:00:00 2001 From: Chengwei Yang Date: Tue, 8 Oct 2013 21:59:37 +0800 Subject: Unify the way to find dbus-daemon test binary There are two ways to find the dbus-daemon for testing. The first one is defined as string at compile stage and the second one is export it from test environment. The first way has limitation that after defined, it's static string, so it's impossible to run installable check. So let's unify to the second way. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=37849 [added missing "}" -smcv] Reviewed-by: Simon McVittie --- test/name-test/Makefile.am | 1 + 1 file changed, 1 insertion(+) (limited to 'test') diff --git a/test/name-test/Makefile.am b/test/name-test/Makefile.am index 931cb2c9..da41e58b 100644 --- a/test/name-test/Makefile.am +++ b/test/name-test/Makefile.am @@ -18,6 +18,7 @@ TESTS_ENVIRONMENT = \ DBUS_TOP_SRCDIR=@abs_top_srcdir@ \ PYTHON=@PYTHON@ \ DBUS_TEST_DATA=@abs_top_builddir@/test/data \ + DBUS_TEST_DAEMON=@abs_top_builddir@/bus/dbus-daemon$(EXEEXT) \ $(NULL) TESTS=run-test.sh run-test-systemserver.sh else -- cgit v1.2.1 From 9f0366019d6f344c64b23a0cac29c175fed1673e Mon Sep 17 00:00:00 2001 From: Ralf Habacker Date: Thu, 10 Oct 2013 00:45:15 +0200 Subject: Use TEST_LISTEN in incoming-listen.conf.in instead of unix only hardcoded address Bug: https://bugs.freedesktop.org/show_bug.cgi?id=68506 Reviewed-by: Simon McVittie --- test/data/valid-config-files/incoming-limit.conf | 18 ------------------ test/data/valid-config-files/incoming-limit.conf.in | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+), 18 deletions(-) delete mode 100644 test/data/valid-config-files/incoming-limit.conf create mode 100644 test/data/valid-config-files/incoming-limit.conf.in (limited to 'test') diff --git a/test/data/valid-config-files/incoming-limit.conf b/test/data/valid-config-files/incoming-limit.conf deleted file mode 100644 index abfab3f7..00000000 --- a/test/data/valid-config-files/incoming-limit.conf +++ /dev/null @@ -1,18 +0,0 @@ - - - - session - unix:tmpdir=/tmp - - - - - - - - - - - 1 - diff --git a/test/data/valid-config-files/incoming-limit.conf.in b/test/data/valid-config-files/incoming-limit.conf.in new file mode 100644 index 00000000..40ff2244 --- /dev/null +++ b/test/data/valid-config-files/incoming-limit.conf.in @@ -0,0 +1,18 @@ + + + + session + @TEST_LISTEN@ + + + + + + + + + + + 1 + -- cgit v1.2.1 From 5618696768805abfbc3741f60817584451648795 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Thu, 10 Oct 2013 11:55:36 -0400 Subject: test: Update build for previous commit It should now be in in_data so we find it in $(srcdir). --- test/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/Makefile.am b/test/Makefile.am index eddcd644..12d9ab49 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -246,6 +246,7 @@ in_data = \ data/valid-config-files-system/debug-allow-all-pass.conf.in \ data/valid-config-files/debug-allow-all-sha1.conf.in \ data/valid-config-files/debug-allow-all.conf.in \ + data/valid-config-files/incoming-limit.conf \ data/invalid-service-files-system/org.freedesktop.DBus.TestSuiteNoExec.service.in \ data/invalid-service-files-system/org.freedesktop.DBus.TestSuiteNoService.service.in \ data/invalid-service-files-system/org.freedesktop.DBus.TestSuiteNoUser.service.in \ @@ -317,7 +318,6 @@ static_data = \ data/valid-config-files/basic.conf \ data/valid-config-files/basic.d/basic.conf \ data/valid-config-files/entities.conf \ - data/valid-config-files/incoming-limit.conf \ data/valid-config-files/many-rules.conf \ data/valid-config-files/system.d/test.conf \ data/valid-messages/array-of-array-of-uint32.message \ -- cgit v1.2.1 From 880209788c2d1a09e8dc10e2bb5b8f5fa6f80a5e Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Thu, 10 Oct 2013 16:59:11 +0100 Subject: $(in_data) is meant to contain the .in files Reviewed-by: Colin Walters --- test/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/Makefile.am b/test/Makefile.am index 12d9ab49..870ce321 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -246,7 +246,7 @@ in_data = \ data/valid-config-files-system/debug-allow-all-pass.conf.in \ data/valid-config-files/debug-allow-all-sha1.conf.in \ data/valid-config-files/debug-allow-all.conf.in \ - data/valid-config-files/incoming-limit.conf \ + data/valid-config-files/incoming-limit.conf.in \ data/invalid-service-files-system/org.freedesktop.DBus.TestSuiteNoExec.service.in \ data/invalid-service-files-system/org.freedesktop.DBus.TestSuiteNoService.service.in \ data/invalid-service-files-system/org.freedesktop.DBus.TestSuiteNoUser.service.in \ -- cgit v1.2.1 From ec6ea1a6a8ad1d5e3c1280a55207e9b4f5742814 Mon Sep 17 00:00:00 2001 From: Chengwei Yang Date: Tue, 15 Oct 2013 13:04:53 +0800 Subject: DBusBabysitter: change executable to log_name DBusBabysitter->executable is defined as executable name to use in error messages. However, if servicehelper used, then the executable name is servicehelper. It's not much help because we couldn't figure out which service we're trying to activated if error happens. In the following patch, we'll use service name to be activated as the child log identifier and add a parameter to _dbus_spawn_async_with_babysitter() to pass the log identifier. Since this is not the case in test, so executable changed to log_name. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=68559 Reviewed-by: Simon McVittie --- test/spawn-test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/spawn-test.c b/test/spawn-test.c index e6513fa6..723a4889 100644 --- a/test/spawn-test.c +++ b/test/spawn-test.c @@ -30,7 +30,7 @@ main (int argc, char **argv) argv_copy [i] = argv[i + 1]; argv_copy[argc - 1] = NULL; - if (!_dbus_spawn_async_with_babysitter (NULL, argv_copy, NULL, setup_func, NULL, &error)) + if (!_dbus_spawn_async_with_babysitter (NULL, argv_copy[0], argv_copy, NULL, setup_func, NULL, &error)) { fprintf (stderr, "Could not launch application: \"%s\"\n", error.message); -- cgit v1.2.1 From 2d950f6e9a412da70e9f8bc956980abc949a5fe8 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Tue, 19 Feb 2013 16:39:38 +0000 Subject: Make sure tests run with a temporary XDG_RUNTIME_DIR We don't want the regression tests' "session" getting mixed up in system-wide "sessions". This doesn't actually matter yet, but it is likely to matter in future. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=61301 Reviewed-by: Chengwei Yang [merged with earlier line-wrapping of TESTS_ENVIRONMENT -smcv] Signed-off-by: Simon McVittie --- test/Makefile.am | 4 +++- test/name-test/Makefile.am | 2 ++ test/name-test/run-test-systemserver.sh | 5 +++++ test/name-test/run-test.sh | 5 +++++ 4 files changed, 15 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/Makefile.am b/test/Makefile.am index 870ce321..426a72e0 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -149,11 +149,13 @@ endif DBUS_WITH_GLIB installcheck_tests = installcheck_environment = \ + XDG_RUNTIME_DIR=@abs_top_builddir@/test/XDG_RUNTIME_DIR \ DBUS_TEST_DAEMON=$(DESTDIR)$(DBUS_DAEMONDIR)/dbus-daemon$(EXEEXT) \ DBUS_TEST_HOMEDIR=@abs_top_builddir@/dbus \ DBUS_TEST_SYSCONFDIR=$(DESTDIR)$(sysconfdir) TESTS_ENVIRONMENT = \ + XDG_RUNTIME_DIR=@abs_top_builddir@/test/XDG_RUNTIME_DIR \ DBUS_BLOCK_ON_ABORT=1 \ DBUS_FATAL_WARNINGS=1 \ DBUS_TEST_DAEMON=@abs_top_builddir@/bus/dbus-daemon$(EXEEXT) \ @@ -368,7 +370,7 @@ imported_data = \ $(NULL) noinst_DATA = $(imported_data) -CLEANFILES = $(noinst_DATA) +CLEANFILES = $(noinst_DATA) XDG_RUNTIME_DIR $(imported_data): data/valid-config-files/%.conf: $(top_builddir)/bus/%.conf $(AM_V_at)$(MKDIR_P) data/valid-config-files diff --git a/test/name-test/Makefile.am b/test/name-test/Makefile.am index da41e58b..8ed1e160 100644 --- a/test/name-test/Makefile.am +++ b/test/name-test/Makefile.am @@ -19,7 +19,9 @@ TESTS_ENVIRONMENT = \ PYTHON=@PYTHON@ \ DBUS_TEST_DATA=@abs_top_builddir@/test/data \ DBUS_TEST_DAEMON=@abs_top_builddir@/bus/dbus-daemon$(EXEEXT) \ + XDG_RUNTIME_DIR=@abs_top_builddir@/test/XDG_RUNTIME_DIR \ $(NULL) + TESTS=run-test.sh run-test-systemserver.sh else TESTS= diff --git a/test/name-test/run-test-systemserver.sh b/test/name-test/run-test-systemserver.sh index afd1f045..90c03723 100755 --- a/test/name-test/run-test-systemserver.sh +++ b/test/name-test/run-test-systemserver.sh @@ -30,6 +30,11 @@ if test -n "$DBUS_TEST_MONITOR"; then dbus-monitor --session & fi +XDG_RUNTIME_DIR="$DBUS_TOP_BUILDDIR"/test/XDG_RUNTIME_DIR +test -d "$XDG_RUNTIME_DIR" || mkdir "$XDG_RUNTIME_DIR" +chmod 0700 "$XDG_RUNTIME_DIR" +export XDG_RUNTIME_DIR + echo "running test-expected-echo-fail" ${DBUS_TOP_BUILDDIR}/libtool --mode=execute $DEBUG $DBUS_TOP_BUILDDIR/tools/dbus-send --print-reply --dest=org.freedesktop.DBus.TestSuiteEchoService /org/freedesktop/TestSuite org.freedesktop.TestSuite.Echo string:hi >echo-error-output.tmp 2>&1 if ! grep -q 'DBus.Error' echo-error-output.tmp; then diff --git a/test/name-test/run-test.sh b/test/name-test/run-test.sh index cad5937e..84379c4a 100755 --- a/test/name-test/run-test.sh +++ b/test/name-test/run-test.sh @@ -30,6 +30,11 @@ if test -n "$DBUS_TEST_MONITOR"; then dbus-monitor --session & fi +XDG_RUNTIME_DIR="$DBUS_TOP_BUILDDIR"/test/XDG_RUNTIME_DIR +test -d "$XDG_RUNTIME_DIR" || mkdir "$XDG_RUNTIME_DIR" +chmod 0700 "$XDG_RUNTIME_DIR" +export XDG_RUNTIME_DIR + echo "running test-ids" ${DBUS_TOP_BUILDDIR}/libtool --mode=execute $DEBUG $DBUS_TOP_BUILDDIR/test/name-test/test-ids || die "test-ids failed" -- cgit v1.2.1 From 710bd4a94488585300458733748a0f2462abdf57 Mon Sep 17 00:00:00 2001 From: Ralf Habacker Date: Sat, 12 Oct 2013 00:59:22 +0200 Subject: Skip unix only syslog test. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=41252 Reviewed-by: Simon McVittie --- test/internals/syslog.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/internals/syslog.c b/test/internals/syslog.c index 2811b757..7e0eae79 100644 --- a/test/internals/syslog.c +++ b/test/internals/syslog.c @@ -51,6 +51,7 @@ static void test_syslog (Fixture *f, gconstpointer data) { +#ifndef G_OS_WIN32 if (g_test_trap_fork (0, 0)) { _dbus_init_system_log (FALSE); @@ -73,7 +74,7 @@ test_syslog (Fixture *f, g_test_trap_assert_passed (); g_test_trap_assert_stderr ("*" MESSAGE "42\n*" MESSAGE "666\n*"); - +#endif /* manual test (this is the best we can do on Windows) */ _dbus_init_system_log (FALSE); _dbus_system_log (DBUS_SYSTEM_LOG_INFO, MESSAGE "%d", 42); -- cgit v1.2.1 From e74f0b1efa3f541faabb89c1bd97543d36696d16 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Mon, 2 Sep 2013 16:36:46 +0100 Subject: test/dbus-daemon, test/dbus-daemon-eavesdrop: allow external dbus-daemon It's easier to automate these tests if they launch their own dbus-daemon, but easier to debug them if they don't: you can launch a dbus-daemon separately, under gdb. However, tests that need a specially-configured dbus-daemon will have to be skipped. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=68852 Reviewed-by: Ralf Habacker --- test/dbus-daemon-eavesdrop.c | 9 ++++++++- test/dbus-daemon.c | 17 ++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/dbus-daemon-eavesdrop.c b/test/dbus-daemon-eavesdrop.c index 2c45f54e..bc5ba121 100644 --- a/test/dbus-daemon-eavesdrop.c +++ b/test/dbus-daemon-eavesdrop.c @@ -409,7 +409,14 @@ setup (Fixture *f, config = g_strdup ("--session"); } - address = spawn_dbus_daemon (dbus_daemon, config, &f->daemon_pid); + if (g_getenv ("DBUS_TEST_DAEMON_ADDRESS") != NULL) + { + address = g_strdup (g_getenv ("DBUS_TEST_DAEMON_ADDRESS")); + } + else + { + address = spawn_dbus_daemon (dbus_daemon, config, &f->daemon_pid); + } g_free (dbus_daemon); g_free (config); diff --git a/test/dbus-daemon.c b/test/dbus-daemon.c index 22ea23e3..c883425e 100644 --- a/test/dbus-daemon.c +++ b/test/dbus-daemon.c @@ -194,6 +194,14 @@ setup (Fixture *f, if (config != NULL && config->config_file != NULL) { + if (g_getenv ("DBUS_TEST_DAEMON_ADDRESS") != NULL) + { + g_message ("SKIP: cannot use DBUS_TEST_DAEMON_ADDRESS for " + "unusally-configured dbus-daemon"); + f->skip = TRUE; + return; + } + if (g_getenv ("DBUS_TEST_DATA") == NULL) { g_message ("SKIP: set DBUS_TEST_DATA to a directory containing %s", @@ -227,7 +235,14 @@ setup (Fixture *f, if (dbus_daemon == NULL) dbus_daemon = g_strdup ("dbus-daemon"); - address = spawn_dbus_daemon (dbus_daemon, arg, &f->daemon_pid); + if (g_getenv ("DBUS_TEST_DAEMON_ADDRESS") != NULL) + { + address = g_strdup (g_getenv ("DBUS_TEST_DAEMON_ADDRESS")); + } + else + { + address = spawn_dbus_daemon (dbus_daemon, arg, &f->daemon_pid); + } g_free (dbus_daemon); g_free (arg); -- cgit v1.2.1 From 7457a4401188b50e30dccd2f99db9c6289d080a1 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Tue, 7 Jan 2014 12:23:10 +0000 Subject: tests: don't block and wait for a debugger on abort In general, I think developers running the tests would expect them to terminate rather than hanging. Developers who want to debug such an abort by attaching a debugger to a live process can still set DBUS_BLOCK_ON_ABORT in the environment. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=41252 Reviewed-by: Ralf Habacker --- test/Makefile.am | 1 - 1 file changed, 1 deletion(-) (limited to 'test') diff --git a/test/Makefile.am b/test/Makefile.am index 426a72e0..09b94561 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -156,7 +156,6 @@ installcheck_environment = \ TESTS_ENVIRONMENT = \ XDG_RUNTIME_DIR=@abs_top_builddir@/test/XDG_RUNTIME_DIR \ - DBUS_BLOCK_ON_ABORT=1 \ DBUS_FATAL_WARNINGS=1 \ DBUS_TEST_DAEMON=@abs_top_builddir@/bus/dbus-daemon$(EXEEXT) \ DBUS_TEST_DATA=@abs_top_builddir@/test/data \ -- cgit v1.2.1 From 0cd0714994a94a433745ed9bb2150cddbda5b313 Mon Sep 17 00:00:00 2001 From: Ralf Habacker Date: Sat, 11 Jan 2014 20:51:27 +0100 Subject: Rename dbus-test to test-dbus to match common test application naming scheme. [reverted the dbus-specification part -smcv] Bug: https://bugs.freedesktop.org/show_bug.cgi?id=73495 Reviewed-by: Simon McVittie --- test/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/Makefile.am b/test/Makefile.am index 09b94561..b23eb99f 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -76,7 +76,7 @@ TEST_BINARIES = \ TESTS = \ ../bus/bus-test$(EXEEXT) \ ../bus/bus-test-system$(EXEEXT) \ - ../dbus/dbus-test$(EXEEXT) \ + ../dbus/test-dbus$(EXEEXT) \ $(NULL) if DBUS_UNIX -- cgit v1.2.1 From e782b0806eed9f46164b8aa5da7c1b12109175bf Mon Sep 17 00:00:00 2001 From: Ralf Habacker Date: Fri, 10 Jan 2014 02:17:22 +0100 Subject: Rename shell-test to test-shell to match common test application naming scheme. [Add its source file to SOURCES: this test was previously relying on the Automake feature that the default value of foo_bar_SOURCES is foo-bar.c. -smcv] Bug: https://bugs.freedesktop.org/show_bug.cgi?id=73495 Reviewed-by: Simon McVittie --- test/.gitignore | 2 +- test/Makefile.am | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/test/.gitignore b/test/.gitignore index 1337de64..814a35cc 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -21,7 +21,7 @@ test-segfault test-service test-sleep-forever decode-gcov -shell-test +test-shell test-shell-service test-names test-loopback diff --git a/test/Makefile.am b/test/Makefile.am index b23eb99f..ddb69b4f 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -100,8 +100,9 @@ test_names_LDADD = libdbus-testutils-internal.la ## break_loader_LDADD = $(top_builddir)/dbus/libdbus-internal.la test_shell_service_CPPFLAGS = $(static_cppflags) test_shell_service_LDADD = libdbus-testutils-internal.la -shell_test_CPPFLAGS = $(static_cppflags) -shell_test_LDADD = libdbus-testutils-internal.la +test_shell_SOURCES = shell-test.c +test_shell_CPPFLAGS = $(static_cppflags) +test_shell_LDADD = libdbus-testutils-internal.la spawn_test_CPPFLAGS = $(static_cppflags) spawn_test_LDADD = $(top_builddir)/dbus/libdbus-internal.la @@ -124,7 +125,7 @@ testexecdir = $(libdir)/dbus-1.0/test testexec_PROGRAMS = installable_tests = \ - shell-test \ + test-shell \ test-printf \ $(NULL) installable_manual_tests = \ -- cgit v1.2.1 From 54440baa2192abe889957a23e4448c599ce32260 Mon Sep 17 00:00:00 2001 From: Ralf Habacker Date: Sat, 11 Jan 2014 10:07:21 +0100 Subject: Rename spawn-test to test-spawn to match common test application naming scheme. [Same change as for shell-test in the previous commit. -smcv] Bug: https://bugs.freedesktop.org/show_bug.cgi?id=73495 Reviewed-by: Simon McVittie --- test/.gitignore | 2 +- test/Makefile.am | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/test/.gitignore b/test/.gitignore index 814a35cc..71b3cec9 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -14,7 +14,7 @@ unbase64 *.da *.gcov break-loader -spawn-test +test-spawn test-corrupt test-exit test-segfault diff --git a/test/Makefile.am b/test/Makefile.am index ddb69b4f..af2a0a23 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -61,7 +61,7 @@ if DBUS_ENABLE_EMBEDDED_TESTS ## break-loader removed for now ## these binaries are used in tests but are not themselves tests TEST_BINARIES = \ - spawn-test \ + test-spawn \ test-exit \ test-names \ test-segfault \ @@ -103,8 +103,9 @@ test_shell_service_LDADD = libdbus-testutils-internal.la test_shell_SOURCES = shell-test.c test_shell_CPPFLAGS = $(static_cppflags) test_shell_LDADD = libdbus-testutils-internal.la -spawn_test_CPPFLAGS = $(static_cppflags) -spawn_test_LDADD = $(top_builddir)/dbus/libdbus-internal.la +test_spawn_SOURCES = spawn-test.c +test_spawn_CPPFLAGS = $(static_cppflags) +test_spawn_LDADD = $(top_builddir)/dbus/libdbus-internal.la test_printf_SOURCES = internals/printf.c test_printf_CPPFLAGS = $(static_cppflags) -- cgit v1.2.1 From 3ce5d21edfe5ca4a97892e3144fcbb5979a54cf6 Mon Sep 17 00:00:00 2001 From: Ralf Habacker Date: Mon, 13 Jan 2014 20:45:37 +0100 Subject: Rename bus-test to test-bus to match common test application naming scheme. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=73495 Reviewed-by: Simon McVittie --- test/.gitignore | 2 +- test/Makefile.am | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/.gitignore b/test/.gitignore index 71b3cec9..de1dfe14 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -7,7 +7,7 @@ Makefile.in *.o echo-server echo-client -bus-test +test-bus unbase64 *.bb *.bbg diff --git a/test/Makefile.am b/test/Makefile.am index af2a0a23..3155e87f 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -74,7 +74,7 @@ TEST_BINARIES = \ ## order, but we don't want to run them til we arrive in this directory, ## since they depend on stuff from this directory TESTS = \ - ../bus/bus-test$(EXEEXT) \ + ../bus/test-bus$(EXEEXT) \ ../bus/bus-test-system$(EXEEXT) \ ../dbus/test-dbus$(EXEEXT) \ $(NULL) -- cgit v1.2.1 From cf41239d6684efa3f5d648b1fa84c4fe07148691 Mon Sep 17 00:00:00 2001 From: Ralf Habacker Date: Tue, 14 Jan 2014 18:45:39 +0100 Subject: Rename bus-test-system to test-bus-system to match common test application naming scheme. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=73495 Reviewed-by: Simon McVittie --- test/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/Makefile.am b/test/Makefile.am index 3155e87f..e3e1fa47 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -75,7 +75,7 @@ TEST_BINARIES = \ ## since they depend on stuff from this directory TESTS = \ ../bus/test-bus$(EXEEXT) \ - ../bus/bus-test-system$(EXEEXT) \ + ../bus/test-bus-system$(EXEEXT) \ ../dbus/test-dbus$(EXEEXT) \ $(NULL) -- cgit v1.2.1 From 7e373d4527286ae0ecdc4ccd2064293c61f3b907 Mon Sep 17 00:00:00 2001 From: Ralf Habacker Date: Tue, 14 Jan 2014 18:52:22 +0100 Subject: Rename bus-test-launch-helper to test-bus-launch_helper to match common test application naming scheme. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=73495 Reviewed-by: Simon McVittie --- test/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/Makefile.am b/test/Makefile.am index e3e1fa47..cec5cdab 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -80,7 +80,7 @@ TESTS = \ $(NULL) if DBUS_UNIX -TESTS += ../bus/bus-test-launch-helper$(EXEEXT) +TESTS += ../bus/test-bus-launch-helper$(EXEEXT) endif else !DBUS_ENABLE_EMBEDDED_TESTS -- cgit v1.2.1