From 8fd2be6013e3d0ff6a6ff63ea022f9606d9a87c6 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Mon, 8 Feb 2016 20:09:58 +0000 Subject: [PATCH 01/10] Replace $DBUS_USE_TEST_BINARY with $DBUS_TEST_DBUS_LAUNCH Instead of using $DBUS_USE_TEST_BINARY to control whether to use the hard-coded test binary TEST_BUS_LAUNCH_BINARY, we can just use $DBUS_TEST_DBUS_LAUNCH to control what we launch directly, as we were already doing for $DBUS_TEST_DAEMON. Signed-off-by: Simon McVittie Bug: https://bugs.freedesktop.org/show_bug.cgi?id=92899 Reviewed-by: Ralf Habacker --- cmake/CMakeLists.txt | 1 - cmake/config.h.cmake | 1 - cmake/modules/Macros.cmake | 1 + configure.ac | 3 --- dbus/dbus-sysdeps-unix.c | 8 ++++---- test/Makefile.am | 2 ++ test/name-test/Makefile.am | 1 + tools/dbus-launch.c | 6 +++--- tools/run-with-tmp-session-bus.sh | 5 ----- 9 files changed, 11 insertions(+), 17 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 4db9c67a..13332503 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -506,7 +506,6 @@ if (DBUS_BUILD_TESTS) set(DBUS_TEST_DATA ${CMAKE_BINARY_DIR}/test/data) set(TEST_SOCKET_DIR ${DBUS_SESSION_SOCKET_DIR} ) set(TEST_LAUNCH_HELPER_BINARY ${EXECUTABLE_OUTPUT_PATH}/dbus-daemon-launch-helper-test) - set(TEST_BUS_LAUNCH_BINARY ${EXECUTABLE_OUTPUT_PATH}/dbus-launch${EXEEXT}) if (UNIX) set (TEST_LISTEN "unix:tmpdir=${TEST_SOCKET_DIR}") endif (UNIX) diff --git a/cmake/config.h.cmake b/cmake/config.h.cmake index d2af3c96..c4983623 100644 --- a/cmake/config.h.cmake +++ b/cmake/config.h.cmake @@ -33,7 +33,6 @@ // test binaries #define DBUS_TEST_EXEC "@DBUS_TEST_EXEC@" #define DBUS_EXEEXT "@EXEEXT@" -#cmakedefine TEST_BUS_LAUNCH_BINARY "@TEST_BUS_LAUNCH_BINARY@" /* Some dbus features */ #cmakedefine DBUS_ENABLE_ANSI 1 diff --git a/cmake/modules/Macros.cmake b/cmake/modules/Macros.cmake index fd3f62c4..8e0278a4 100644 --- a/cmake/modules/Macros.cmake +++ b/cmake/modules/Macros.cmake @@ -52,6 +52,7 @@ macro(add_test_executable _target _source) list(APPEND _env "DBUS_SESSION_BUS_ADDRESS=") list(APPEND _env "DBUS_FATAL_WARNINGS=1") list(APPEND _env "DBUS_TEST_DATA=${PREFIX}${CMAKE_BINARY_DIR}/test/data") + list(APPEND _env "DBUS_TEST_DBUS_LAUNCH=${PREFIX}${CMAKE_BINARY_DIR}/bin/dbus-launch${EXEEXT}") list(APPEND _env "DBUS_TEST_HOMEDIR=${PREFIX}${CMAKE_BINARY_DIR}/dbus") set_tests_properties(${_target} PROPERTIES ENVIRONMENT "${_env}") endmacro(add_test_executable) diff --git a/configure.ac b/configure.ac index 5e883435..a734a3b6 100644 --- a/configure.ac +++ b/configure.ac @@ -1731,9 +1731,6 @@ AC_DEFINE_UNQUOTED([DBUS_TEST_EXEC], ["$DBUS_TEST_EXEC"], AC_DEFINE_UNQUOTED([DBUS_EXEEXT], ["$EXEEXT"], [Extension for executables, typically empty or .exe]) -AC_DEFINE_UNQUOTED(TEST_BUS_LAUNCH_BINARY, ["$DBUS_PWD/tools/dbus-launch$EXEEXT"], - [Full path to the dbus-launch in the builddir]) - ## Export the non-setuid external helper TEST_LAUNCH_HELPER_BINARY="$DBUS_PWD/bus/dbus-daemon-launch-helper-test$EXEEXT" AC_SUBST(TEST_LAUNCH_HELPER_BINARY) diff --git a/dbus/dbus-sysdeps-unix.c b/dbus/dbus-sysdeps-unix.c index 50ca60a2..f0fca85e 100644 --- a/dbus/dbus-sysdeps-unix.c +++ b/dbus/dbus-sysdeps-unix.c @@ -3671,7 +3671,7 @@ _dbus_get_autolaunch_address (const char *scope, * but that's done elsewhere, and if it worked, this function wouldn't * be called.) */ const char *display; - char *progpath; + const char *progpath; char *argv[6]; int i; DBusString uuid; @@ -3716,9 +3716,9 @@ _dbus_get_autolaunch_address (const char *scope, } #ifdef DBUS_ENABLE_EMBEDDED_TESTS - if (_dbus_getenv ("DBUS_USE_TEST_BINARY") != NULL) - progpath = TEST_BUS_LAUNCH_BINARY; - else + progpath = _dbus_getenv ("DBUS_TEST_DBUS_LAUNCH"); + + if (progpath == NULL) #endif progpath = DBUS_BINDIR "/dbus-launch"; /* diff --git a/test/Makefile.am b/test/Makefile.am index b7f40bb0..1438995c 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -174,6 +174,7 @@ installcheck_tests = installcheck_environment = \ export XDG_RUNTIME_DIR=@abs_top_builddir@/test/XDG_RUNTIME_DIR; \ export DBUS_TEST_DAEMON=$(DESTDIR)$(DBUS_DAEMONDIR)/dbus-daemon$(EXEEXT); \ + export DBUS_TEST_DBUS_LAUNCH=$(DESTDIR)$(bindir)/dbus-launch$(EXEEXT); \ export DBUS_TEST_HOMEDIR=@abs_top_builddir@/dbus; \ export DBUS_TEST_DATADIR=$(DESTDIR)$(datadir); \ ${NULL} @@ -182,6 +183,7 @@ AM_TESTS_ENVIRONMENT = \ export XDG_RUNTIME_DIR=@abs_top_builddir@/test/XDG_RUNTIME_DIR; \ export DBUS_FATAL_WARNINGS=1; \ export DBUS_TEST_DAEMON=@abs_top_builddir@/bus/dbus-daemon$(EXEEXT); \ + export DBUS_TEST_DBUS_LAUNCH=@abs_top_builddir@/tools/dbus-launch$(EXEEXT); \ export DBUS_TEST_DATA=@abs_top_builddir@/test/data; \ export DBUS_TEST_HOMEDIR=@abs_top_builddir@/dbus; \ $(NULL) diff --git a/test/name-test/Makefile.am b/test/name-test/Makefile.am index 3b7fcc62..fae28920 100644 --- a/test/name-test/Makefile.am +++ b/test/name-test/Makefile.am @@ -25,6 +25,7 @@ AM_TESTS_ENVIRONMENT = \ export PYTHON=@PYTHON@; \ export DBUS_TEST_DATA=@abs_top_builddir@/test/data; \ export DBUS_TEST_DAEMON=@abs_top_builddir@/bus/dbus-daemon$(EXEEXT); \ + export DBUS_TEST_DBUS_LAUNCH=@abs_top_builddir@/tools/dbus-launch$(EXEEXT); \ export XDG_RUNTIME_DIR=@abs_top_builddir@/test/XDG_RUNTIME_DIR; \ $(NULL) diff --git a/tools/dbus-launch.c b/tools/dbus-launch.c index 0f1e6ede..1b655027 100644 --- a/tools/dbus-launch.c +++ b/tools/dbus-launch.c @@ -1169,10 +1169,10 @@ main (int argc, char **argv) #ifdef DBUS_ENABLE_EMBEDDED_TESTS { - const char *test_daemon; /* exec from testdir */ - if (getenv ("DBUS_USE_TEST_BINARY") != NULL && - (test_daemon = getenv ("DBUS_TEST_DAEMON")) != NULL) + const char *test_daemon = getenv ("DBUS_TEST_DAEMON"); + + if (test_daemon != NULL) { if (config_file == NULL && getenv ("DBUS_TEST_DATA") != NULL) { diff --git a/tools/run-with-tmp-session-bus.sh b/tools/run-with-tmp-session-bus.sh index 94ae8fc8..688f9e48 100755 --- a/tools/run-with-tmp-session-bus.sh +++ b/tools/run-with-tmp-session-bus.sh @@ -45,11 +45,6 @@ export LD_LIBRARY_PATH unset DBUS_SESSION_BUS_ADDRESS unset DBUS_SESSION_BUS_PID -# this does not actually affect dbus-run-session any more, but could be -# significant for dbus-launch as used by the autolaunch test -DBUS_USE_TEST_BINARY=1 -export DBUS_USE_TEST_BINARY - $DBUS_TOP_BUILDDIR/tools/dbus-run-session \ --config-file="$CONFIG_FILE" \ --dbus-daemon="$DBUS_TOP_BUILDDIR/bus/dbus-daemon" \ From fec99c9b3d8318e3abae432f2aca50802a87f90e Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Mon, 8 Feb 2016 20:28:21 +0000 Subject: [PATCH 02/10] name-test C tests: produce structured (TAP) output Similar to commit 58eefa1031e14cb402ed0aae85e6bce1ba030a28. test-privserver is a helper executable, not a test. I moved its output from stdout to stderr so it can't be misinterpreted as the test's stdout. Signed-off-by: Simon McVittie Bug: https://bugs.freedesktop.org/show_bug.cgi?id=92899 Reviewed-by: Ralf Habacker --- test/name-test/test-ids.c | 28 +++++++++++++++------ test/name-test/test-pending-call-dispatch.c | 13 +++++----- test/name-test/test-pending-call-timeout.c | 11 ++++---- test/name-test/test-privserver-client.c | 16 +++++++++--- test/name-test/test-privserver.c | 2 +- test/name-test/test-shutdown.c | 17 ++++++++----- test/name-test/test-threads-init.c | 7 ++++-- 7 files changed, 63 insertions(+), 31 deletions(-) diff --git a/test/name-test/test-ids.c b/test/name-test/test-ids.c index 8f63d044..f73a505f 100644 --- a/test/name-test/test-ids.c +++ b/test/name-test/test-ids.c @@ -11,10 +11,13 @@ static void die (const char *message) { - fprintf (stderr, "*** test-ids: %s", message); + printf ("Bail out! test-ids: %s\n", message); exit (1); } +static int test_num = 0; + +/* This test outputs TAP syntax: http://testanything.org/ */ int main (int argc, char **argv) @@ -23,7 +26,7 @@ main (int argc, DBusConnection *connection; char *id; char *server_id; - + dbus_error_init (&error); connection = dbus_bus_get (DBUS_BUS_SESSION, &error); if (connection == NULL) @@ -33,24 +36,35 @@ main (int argc, dbus_error_free (&error); return 1; } + printf ("ok %d - connected to session bus\n", ++test_num); server_id = dbus_connection_get_server_id (connection); + if (server_id == NULL) die ("No bus server ID retrieved\n"); - /* printf("'%s'\n", server_id); */ + + printf ("ok %d - session bus server ID is %s\n", ++test_num, server_id); + if (strlen (server_id) != 32) die ("Bus server id should have length 32\n"); + + printf ("ok %d - session bus server ID length is 32\n", ++test_num); + dbus_free (server_id); id = dbus_bus_get_id (connection, NULL); if (id == NULL) die ("No bus ID retrieved\n"); - /* printf("'%s'\n", id); */ + + printf ("ok %d - session bus ID is %s\n", ++test_num, id); + if (strlen (id) != 32) die ("Bus ID should have length 32\n"); + + printf ("ok %d - session bus ID length is 32\n", ++test_num); + dbus_free (id); - - _dbus_verbose ("*** Test IDs exiting\n"); - + + printf ("1..%d\n", test_num); return 0; } diff --git a/test/name-test/test-pending-call-dispatch.c b/test/name-test/test-pending-call-dispatch.c index c8b5a467..7785564d 100644 --- a/test/name-test/test-pending-call-dispatch.c +++ b/test/name-test/test-pending-call-dispatch.c @@ -56,13 +56,13 @@ _run_iteration (DBusConnection *conn) if (reply == NULL) { - printf ("Failed: Reply is NULL ***\n"); + printf ("Bail out! Reply is NULL ***\n"); exit (1); } if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) { - printf ("Failed: Reply is error: %s ***\n", dbus_message_get_error_name (reply)); + printf ("Bail out! Reply is error: %s ***\n", dbus_message_get_error_name (reply)); exit (1); } @@ -72,6 +72,7 @@ _run_iteration (DBusConnection *conn) } +/* This test outputs TAP syntax: http://testanything.org/ */ int main (int argc, char *argv[]) { @@ -87,7 +88,7 @@ main (int argc, char *argv[]) but if it does and we are stuck in a poll call then we know the stuck in poll bug has come back to haunt us */ - printf ("*** Testing stuck in poll\n"); + printf ("# Testing stuck in poll\n"); dbus_error_init (&error); @@ -104,10 +105,10 @@ main (int argc, char *argv[]) /* we just care about seconds */ delta = end_tv_sec - start_tv_sec; - printf ("Iter %i: %lis\n", i, delta); + printf ("ok %d - %lis\n", i + 1, delta); if (delta >= 5) { - printf ("Failed: looks like we might have been be stuck in poll ***\n"); + printf ("Bail out! Looks like we might have been be stuck in poll ***\n"); exit (1); } } @@ -119,6 +120,6 @@ main (int argc, char *argv[]) dbus_connection_send (conn, method, NULL); dbus_message_unref (method); - printf ("Success ***\n"); + printf ("# Testing completed\n1..%d\n", i); exit (0); } diff --git a/test/name-test/test-pending-call-timeout.c b/test/name-test/test-pending-call-timeout.c index d051faba..be6b849c 100644 --- a/test/name-test/test-pending-call-timeout.c +++ b/test/name-test/test-pending-call-timeout.c @@ -39,13 +39,13 @@ _method_call (DBusConnection *conn, if (reply == NULL) { - printf ("Failed: Reply is NULL ***\n"); + printf ("Bail out! Reply is NULL ***\n"); exit (1); } if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) { - printf ("Failed: Reply is error: %s ***\n", dbus_message_get_error_name (reply)); + printf ("Bail out! Reply is error: %s ***\n", dbus_message_get_error_name (reply)); exit (1); } @@ -61,6 +61,7 @@ _run_iteration (DBusConnection *conn) _method_call (conn, INT_MAX); } +/* This test outputs TAP syntax: http://testanything.org/ */ int main (int argc, char *argv[]) { @@ -71,7 +72,7 @@ main (int argc, char *argv[]) DBusConnection *conn; DBusError error; - printf ("*** Testing pending call timeouts\n"); + printf ("# Testing pending call timeouts\n"); dbus_error_init (&error); @@ -88,7 +89,7 @@ main (int argc, char *argv[]) /* we just care about seconds */ delta = end_tv_sec - start_tv_sec; - printf ("Iter %i: %lis\n", i, delta); + printf ("ok %d - %lis\n", i + 1, delta); } method = dbus_message_new_method_call ("org.freedesktop.TestSuiteEchoService", @@ -98,6 +99,6 @@ main (int argc, char *argv[]) dbus_connection_send (conn, method, NULL); dbus_message_unref (method); - printf ("Success ***\n"); + printf ("# Testing completed\n1..%d\n", i); exit (0); } diff --git a/test/name-test/test-privserver-client.c b/test/name-test/test-privserver-client.c index e7f48960..56b553c0 100644 --- a/test/name-test/test-privserver-client.c +++ b/test/name-test/test-privserver-client.c @@ -102,7 +102,7 @@ open_shutdown_private_connection (dbus_bool_t use_guid) dbus_message_unref (msg); if (!dbus_message_get_args (reply, &error, DBUS_TYPE_STRING, &addr, DBUS_TYPE_INVALID)) die ("couldn't parse message replym\n"); - printf ("got private temp address %s\n", addr); + printf ("# got private temp address %s\n", addr); addr = strdup (addr); if (!use_guid) { @@ -145,24 +145,32 @@ open_shutdown_private_connection (dbus_bool_t use_guid) _dbus_loop_unref (loop); } +/* This test outputs TAP syntax: http://testanything.org/ */ int main (int argc, char *argv[]) { - open_shutdown_private_connection (TRUE); - - dbus_shutdown (); + int test_num = 0; open_shutdown_private_connection (TRUE); dbus_shutdown (); + printf ("ok %d\n", ++test_num); + + open_shutdown_private_connection (TRUE); + + dbus_shutdown (); + printf ("ok %d\n", ++test_num); open_shutdown_private_connection (FALSE); dbus_shutdown (); + printf ("ok %d\n", ++test_num); open_shutdown_private_connection (FALSE); dbus_shutdown (); + printf ("ok %d\n", ++test_num); + printf ("1..%d\n", test_num); return 0; } diff --git a/test/name-test/test-privserver.c b/test/name-test/test-privserver.c index 39a98b7f..367c8090 100644 --- a/test/name-test/test-privserver.c +++ b/test/name-test/test-privserver.c @@ -97,7 +97,7 @@ main (int argc, char *argv[]) if (!server) die (error.message); testdata->private_addr = dbus_server_get_address (server); - printf ("test server listening on %s\n", testdata->private_addr); + fprintf (stderr, "test server listening on %s\n", testdata->private_addr); dbus_server_set_new_connection_function (server, new_connection_callback, testdata, NULL); diff --git a/test/name-test/test-shutdown.c b/test/name-test/test-shutdown.c index 526c1cbc..39612f18 100644 --- a/test/name-test/test-shutdown.c +++ b/test/name-test/test-shutdown.c @@ -7,7 +7,7 @@ static DBusLoop *loop; static void die (const char *message) { - fprintf (stderr, "*** test-shutdown: %s", message); + printf ("Bail out! test-shutdown: %s", message); exit (1); } @@ -46,23 +46,28 @@ open_destroy_shared_session_bus_connection (void) dbus_connection_unref (connection); } +/* This test outputs TAP syntax: http://testanything.org/ */ int main (int argc, char **argv) { - open_destroy_shared_session_bus_connection (); - - dbus_shutdown (); + int test_num = 0; open_destroy_shared_session_bus_connection (); dbus_shutdown (); + printf ("ok %d\n", ++test_num); open_destroy_shared_session_bus_connection (); dbus_shutdown (); + printf ("ok %d\n", ++test_num); - _dbus_verbose ("*** Test shutdown exiting\n"); - + open_destroy_shared_session_bus_connection (); + + dbus_shutdown (); + printf ("ok %d\n", ++test_num); + + printf ("1..%d\n", test_num); return 0; } diff --git a/test/name-test/test-threads-init.c b/test/name-test/test-threads-init.c index a517e2a2..62857158 100644 --- a/test/name-test/test-threads-init.c +++ b/test/name-test/test-threads-init.c @@ -105,7 +105,7 @@ check_condvar_lock (DBusCondVar *condvar1, } } - +/* This test outputs TAP syntax: http://testanything.org/ */ int main (int argc, char *argv[]) { @@ -116,6 +116,7 @@ main (int argc, char *argv[]) DBusCondVar *dispatch_cond1, *io_path_cond1; DBusMutex *mutex2, *dispatch_mutex2, *io_path_mutex2; DBusCondVar *dispatch_cond2, *io_path_cond2; + int test_num = 0; printf ("*** Testing late thread init\n"); @@ -140,6 +141,7 @@ main (int argc, char *argv[]) check_mutex_lock (io_path_mutex1, io_path_mutex2, TRUE); check_condvar_lock (dispatch_cond1, dispatch_cond2, TRUE); check_condvar_lock (io_path_cond1, io_path_cond2, TRUE); + printf ("ok %d\n", ++test_num); dbus_threads_init_default (); @@ -161,6 +163,7 @@ main (int argc, char *argv[]) check_mutex_lock (io_path_mutex1, io_path_mutex2, TRUE); check_condvar_lock (dispatch_cond1, dispatch_cond2, TRUE); check_condvar_lock (io_path_cond1, io_path_cond2, TRUE); + printf ("ok %d\n", ++test_num); method = dbus_message_new_method_call ("org.freedesktop.TestSuiteEchoService", "/org/freedesktop/TestSuite", @@ -169,6 +172,6 @@ main (int argc, char *argv[]) dbus_connection_send (conn, method, NULL); dbus_message_unref (method); - printf ("Success ***\n"); + printf ("Testing completed\n1..%d\n", test_num); exit (0); } From d893121efdea39d2b32037b32e336ea483829b2e Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Mon, 8 Feb 2016 20:32:34 +0000 Subject: [PATCH 03/10] name-test: run most C tests directly, not via run-test.sh The exception is test-autolaunch, which is really not particularly useful as a build-time test. The only way we can really test autolaunch is as a whole-system integration test, and "make check" is not that. The two tests written in Python and one test based on dbus-send are also not run directly yet; in particular, that includes both the tests in run-test-systemserver.sh. Signed-off-by: Simon McVittie Bug: https://bugs.freedesktop.org/show_bug.cgi?id=92899 Reviewed-by: Ralf Habacker --- test/name-test/Makefile.am | 28 +++++++++++++++++++++++++++- test/name-test/run-test.sh | 10 ++-------- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/test/name-test/Makefile.am b/test/name-test/Makefile.am index fae28920..877d4234 100644 --- a/test/name-test/Makefile.am +++ b/test/name-test/Makefile.am @@ -9,7 +9,15 @@ AM_LDFLAGS = @R_DYNAMIC_LDFLAG@ TEST_EXTENSIONS = .sh -SH_LOG_DRIVER = env AM_TAP_AWK='$(AWK)' $(SHELL) $(top_srcdir)/build-aux/tap-driver.sh +LOG_DRIVER = env AM_TAP_AWK='$(AWK)' $(SHELL) $(top_srcdir)/build-aux/tap-driver.sh +SH_LOG_DRIVER = $(LOG_DRIVER) + +LOG_COMPILER = \ + @abs_top_builddir@/tools/dbus-run-session$(EXEEXT) \ + --config-file=@abs_builddir@/uninstalled-session.conf \ + --dbus-daemon=@abs_top_builddir@/bus/dbus-daemon$(EXEEXT) \ + -- \ + $(NULL) SH_LOG_COMPILER = $(SHELL) ## note that TESTS has special meaning (stuff to use in make check) @@ -22,16 +30,34 @@ if DBUS_UNIX AM_TESTS_ENVIRONMENT = \ export DBUS_TOP_BUILDDIR=@abs_top_builddir@; \ export DBUS_TOP_SRCDIR=@abs_top_srcdir@; \ + export PATH="@abs_top_builddir@/bus:$$PATH"; \ export PYTHON=@PYTHON@; \ export DBUS_TEST_DATA=@abs_top_builddir@/test/data; \ export DBUS_TEST_DAEMON=@abs_top_builddir@/bus/dbus-daemon$(EXEEXT); \ export DBUS_TEST_DBUS_LAUNCH=@abs_top_builddir@/tools/dbus-launch$(EXEEXT); \ export XDG_RUNTIME_DIR=@abs_top_builddir@/test/XDG_RUNTIME_DIR; \ + unset DBUS_SESSION_BUS_ADDRESS; \ + unset DBUS_SESSION_BUS_PID; \ $(NULL) +uninstalled-session.conf: $(top_builddir)/bus/session.conf Makefile + $(SED) -e 's|@abs_top_builddir@/test/data/valid-service-files|g' \ + -e 's| $@ + +check_DATA = \ + uninstalled-session.conf \ + $(NULL) + TESTS += \ run-test.sh \ run-test-systemserver.sh \ + test-ids \ + test-pending-call-dispatch \ + test-pending-call-timeout \ + test-privserver-client \ + test-shutdown \ + test-threads-init \ $(NULL) endif endif diff --git a/test/name-test/run-test.sh b/test/name-test/run-test.sh index 8b9e7ad1..092ec69f 100755 --- a/test/name-test/run-test.sh +++ b/test/name-test/run-test.sh @@ -67,14 +67,8 @@ py_test () { } test_num=1 -# TAP test plan: we will run 8 tests -echo "1..8" +# TAP test plan: we will run 2 tests +echo "1..2" -c_test test-ids -c_test test-pending-call-dispatch -c_test test-pending-call-timeout -c_test test-threads-init -c_test test-privserver-client -c_test test-shutdown py_test test-activation-forking.py c_test test-autolaunch From 1370b44035da90a7fbcebea17074c66c832de0b1 Mon Sep 17 00:00:00 2001 From: Ralf Habacker Date: Fri, 27 Nov 2015 12:10:54 +0100 Subject: [PATCH 04/10] Rename function string_array_length() to _dbus_string_array_length() and move it to dbus-internals.c. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=92899 Reviewed-by: Simon McVittie --- dbus/dbus-internals.c | 15 +++++++++++++++ dbus/dbus-internals.h | 2 ++ dbus/dbus-object-tree.c | 22 +++++++--------------- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/dbus/dbus-internals.c b/dbus/dbus-internals.c index 30a5fa73..d4f0433d 100644 --- a/dbus/dbus-internals.c +++ b/dbus/dbus-internals.c @@ -641,6 +641,21 @@ _dbus_string_array_contains (const char **array, return FALSE; } +/** + * Returns the size of a string array + * + * @param array array to search. + * @returns size of array + */ +size_t +_dbus_string_array_length (const char **array) +{ + size_t i; + for (i = 0; array[i]; i++) {} + return i; +} + + /** * Generates a new UUID. If you change how this is done, * there's some text about it in the spec that should also change. diff --git a/dbus/dbus-internals.h b/dbus/dbus-internals.h index 3eb8749f..6f92fa4c 100644 --- a/dbus/dbus-internals.h +++ b/dbus/dbus-internals.h @@ -246,6 +246,8 @@ void* _dbus_memdup (const void *mem, DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_string_array_contains (const char **array, const char *str); +DBUS_PRIVATE_EXPORT +size_t _dbus_string_array_length (const char **array); char** _dbus_dup_string_array (const char **array); #define _DBUS_INT16_MIN ((dbus_int16_t) 0x8000) diff --git a/dbus/dbus-object-tree.c b/dbus/dbus-object-tree.c index e2a3b737..27481a81 100644 --- a/dbus/dbus-object-tree.c +++ b/dbus/dbus-object-tree.c @@ -1592,14 +1592,6 @@ do_test_dispatch (DBusObjectTree *tree, return FALSE; } -static size_t -string_array_length (const char **array) -{ - size_t i; - for (i = 0; array[i]; i++) ; - return i; -} - typedef struct { const char *path; @@ -1634,14 +1626,14 @@ run_decompose_tests (void) &result, &result_len)) return FALSE; - expected_len = string_array_length (decompose_tests[i].result); + expected_len = _dbus_string_array_length (decompose_tests[i].result); - if (result_len != (int) string_array_length ((const char**)result) || + if (result_len != (int) _dbus_string_array_length ((const char**)result) || expected_len != result_len || path_contains (decompose_tests[i].result, (const char**) result) != STR_EQUAL) { - int real_len = string_array_length ((const char**)result); + int real_len = _dbus_string_array_length ((const char**)result); _dbus_warn ("Expected decompose of %s to have len %d, returned %d, appears to have %d\n", decompose_tests[i].path, expected_len, result_len, real_len); @@ -1875,7 +1867,7 @@ object_tree_test_iteration (void *data) _dbus_object_tree_list_registered_unlocked (tree, path1, &child_entries); if (child_entries != NULL) { - nb = string_array_length ((const char**)child_entries); + nb = _dbus_string_array_length ((const char**)child_entries); _dbus_assert (nb == 1); dbus_free_string_array (child_entries); } @@ -1883,7 +1875,7 @@ object_tree_test_iteration (void *data) _dbus_object_tree_list_registered_unlocked (tree, path2, &child_entries); if (child_entries != NULL) { - nb = string_array_length ((const char**)child_entries); + nb = _dbus_string_array_length ((const char**)child_entries); _dbus_assert (nb == 2); dbus_free_string_array (child_entries); } @@ -1891,7 +1883,7 @@ object_tree_test_iteration (void *data) _dbus_object_tree_list_registered_unlocked (tree, path8, &child_entries); if (child_entries != NULL) { - nb = string_array_length ((const char**)child_entries); + nb = _dbus_string_array_length ((const char**)child_entries); _dbus_assert (nb == 0); dbus_free_string_array (child_entries); } @@ -1899,7 +1891,7 @@ object_tree_test_iteration (void *data) _dbus_object_tree_list_registered_unlocked (tree, root, &child_entries); if (child_entries != NULL) { - nb = string_array_length ((const char**)child_entries); + nb = _dbus_string_array_length ((const char**)child_entries); _dbus_assert (nb == 3); dbus_free_string_array (child_entries); } From 610ff8d9646c1bb944bc5e56f22750f1754b308e Mon Sep 17 00:00:00 2001 From: Ralf Habacker Date: Tue, 9 Feb 2016 15:23:39 +0100 Subject: [PATCH 05/10] Add new functions _dbus_hash_table_to_array() and _dbus_hash_table_from_array() from related activation code. These functions are required for dbus-run-session. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=92899 Reviewed-by: Simon McVittie --- bus/activation.c | 94 +--------------------------------- dbus/dbus-hash.c | 129 +++++++++++++++++++++++++++++++++++++++++++++++ dbus/dbus-hash.h | 8 +++ 3 files changed, 139 insertions(+), 92 deletions(-) diff --git a/bus/activation.c b/bus/activation.c index 7b1ab063..8ca3292d 100644 --- a/bus/activation.c +++ b/bus/activation.c @@ -729,9 +729,6 @@ update_directory (BusActivation *activation, static dbus_bool_t populate_environment (BusActivation *activation) { - DBusString key; - DBusString value; - int i; char **environment; dbus_bool_t retval = FALSE; @@ -740,50 +737,7 @@ populate_environment (BusActivation *activation) if (environment == NULL) return FALSE; - if (!_dbus_string_init (&key)) - { - dbus_free_string_array (environment); - return FALSE; - } - - if (!_dbus_string_init (&value)) - { - _dbus_string_free (&key); - dbus_free_string_array (environment); - return FALSE; - } - - for (i = 0; environment[i] != NULL; i++) - { - if (!_dbus_string_append (&key, environment[i])) - break; - - if (_dbus_string_split_on_byte (&key, '=', &value)) - { - char *hash_key, *hash_value; - - if (!_dbus_string_steal_data (&key, &hash_key)) - break; - - if (!_dbus_string_steal_data (&value, &hash_value)) - break; - - if (!_dbus_hash_table_insert_string (activation->environment, - hash_key, hash_value)) - break; - } - _dbus_string_set_length (&key, 0); - _dbus_string_set_length (&value, 0); - } - - if (environment[i] != NULL) - goto out; - - retval = TRUE; -out: - - _dbus_string_free (&key); - _dbus_string_free (&value); + retval = _dbus_hash_table_from_array (activation->environment, environment, '='); dbus_free_string_array (environment); return retval; @@ -1599,51 +1553,7 @@ activation_find_entry (BusActivation *activation, static char ** bus_activation_get_environment (BusActivation *activation) { - char **environment; - int i, length; - DBusString entry; - DBusHashIter iter; - - length = _dbus_hash_table_get_n_entries (activation->environment); - - environment = dbus_new0 (char *, length + 1); - - if (environment == NULL) - return NULL; - - i = 0; - _dbus_hash_iter_init (activation->environment, &iter); - - if (!_dbus_string_init (&entry)) - { - dbus_free_string_array (environment); - return NULL; - } - - while (_dbus_hash_iter_next (&iter)) - { - const char *key, *value; - - key = (const char *) _dbus_hash_iter_get_string_key (&iter); - value = (const char *) _dbus_hash_iter_get_value (&iter); - - if (!_dbus_string_append_printf (&entry, "%s=%s", key, value)) - break; - - if (!_dbus_string_steal_data (&entry, environment + i)) - break; - i++; - } - - _dbus_string_free (&entry); - - if (i != length) - { - dbus_free_string_array (environment); - environment = NULL; - } - - return environment; + return _dbus_hash_table_to_array (activation->environment, '='); } dbus_bool_t diff --git a/dbus/dbus-hash.c b/dbus/dbus-hash.c index 8f7d04bb..8858bafd 100644 --- a/dbus/dbus-hash.c +++ b/dbus/dbus-hash.c @@ -1828,4 +1828,133 @@ _dbus_hash_test (void) return ret; } +/** + * Imports a string array into a hash table + * The hash table needs to be initialized with string keys, + * and dbus_free() as both key and value free-function. + * + * @param table the hash table + * @param array the string array to import + * @param delimiter the delimiter to separate key and value + * @return #TRUE on success. + * @return #FALSE if not enough memory. + */ + +dbus_bool_t +_dbus_hash_table_from_array (DBusHashTable *table, char **array, char delimiter) +{ + DBusString key; + DBusString value; + int i; + dbus_bool_t retval = FALSE; + + _dbus_assert (table != NULL); + _dbus_assert (array != NULL); + + if (!_dbus_string_init (&key)) + { + return FALSE; + } + + if (!_dbus_string_init (&value)) + { + _dbus_string_free (&key); + return FALSE; + } + + for (i = 0; array[i] != NULL; i++) + { + if (!_dbus_string_append (&key, array[i])) + break; + + if (_dbus_string_split_on_byte (&key, delimiter, &value)) + { + char *hash_key, *hash_value; + + if (!_dbus_string_steal_data (&key, &hash_key)) + break; + + if (!_dbus_string_steal_data (&value, &hash_value)) + break; + + if (!_dbus_hash_table_insert_string (table, + hash_key, hash_value)) + break; + } + _dbus_string_set_length (&key, 0); + _dbus_string_set_length (&value, 0); + } + + if (array[i] != NULL) + goto out; + + retval = TRUE; +out: + + _dbus_string_free (&key); + _dbus_string_free (&value); + + return retval; +} + +/** + * Creates a string array from a hash table + * + * @param table the hash table + * @param delimiter the delimiter to join key and value + * @return pointer to created string array (free with dbus_free_string_array) + * @return #FALSE if not enough memory. + */ +char ** +_dbus_hash_table_to_array (DBusHashTable *table, char delimiter) +{ + int i, length; + DBusString entry; + DBusHashIter iter; + char **array; + + _dbus_assert (table != NULL); + + length = _dbus_hash_table_get_n_entries (table); + + array = dbus_new0 (char *, length + 1); + + if (array == NULL) + return NULL; + + i = 0; + _dbus_hash_iter_init (table, &iter); + + if (!_dbus_string_init (&entry)) + { + dbus_free_string_array (array); + return NULL; + } + + while (_dbus_hash_iter_next (&iter)) + { + const char *key, *value; + + key = (const char *) _dbus_hash_iter_get_string_key (&iter); + value = (const char *) _dbus_hash_iter_get_value (&iter); + + if (!_dbus_string_append_printf (&entry, "%s%c%s", key, delimiter, value)) + break; + + if (!_dbus_string_steal_data (&entry, array + i)) + break; + i++; + } + + _dbus_string_free (&entry); + + if (i != length) + { + dbus_free_string_array (array); + array = NULL; + } + + return array; +} + #endif /* DBUS_ENABLE_EMBEDDED_TESTS */ diff --git a/dbus/dbus-hash.h b/dbus/dbus-hash.h index 2898f51c..93f717a9 100644 --- a/dbus/dbus-hash.h +++ b/dbus/dbus-hash.h @@ -133,6 +133,14 @@ dbus_bool_t _dbus_hash_table_insert_uintptr (DBusHashTable *table, DBUS_PRIVATE_EXPORT int _dbus_hash_table_get_n_entries (DBusHashTable *table); +DBUS_PRIVATE_EXPORT +char ** _dbus_hash_table_to_array (DBusHashTable *table, + char delimiter); +DBUS_PRIVATE_EXPORT +dbus_bool_t _dbus_hash_table_from_array (DBusHashTable *table, + char **array, + char delimiter); + /* Preallocation */ /** A preallocated hash entry */ From 554dba974cf161ac4df8d520a3024f1ba8e21c30 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Fri, 12 Feb 2016 15:24:55 +0000 Subject: [PATCH 06/10] Revert "Add new functions _dbus_hash_table_to_array() and _dbus_hash_table_from_array() from related activation code." This reverts commit 610ff8d9646c1bb944bc5e56f22750f1754b308e. This change was intended for 1.11. --- bus/activation.c | 94 +++++++++++++++++++++++++++++++++- dbus/dbus-hash.c | 129 ----------------------------------------------- dbus/dbus-hash.h | 8 --- 3 files changed, 92 insertions(+), 139 deletions(-) diff --git a/bus/activation.c b/bus/activation.c index 8ca3292d..7b1ab063 100644 --- a/bus/activation.c +++ b/bus/activation.c @@ -729,6 +729,9 @@ update_directory (BusActivation *activation, static dbus_bool_t populate_environment (BusActivation *activation) { + DBusString key; + DBusString value; + int i; char **environment; dbus_bool_t retval = FALSE; @@ -737,7 +740,50 @@ populate_environment (BusActivation *activation) if (environment == NULL) return FALSE; - retval = _dbus_hash_table_from_array (activation->environment, environment, '='); + if (!_dbus_string_init (&key)) + { + dbus_free_string_array (environment); + return FALSE; + } + + if (!_dbus_string_init (&value)) + { + _dbus_string_free (&key); + dbus_free_string_array (environment); + return FALSE; + } + + for (i = 0; environment[i] != NULL; i++) + { + if (!_dbus_string_append (&key, environment[i])) + break; + + if (_dbus_string_split_on_byte (&key, '=', &value)) + { + char *hash_key, *hash_value; + + if (!_dbus_string_steal_data (&key, &hash_key)) + break; + + if (!_dbus_string_steal_data (&value, &hash_value)) + break; + + if (!_dbus_hash_table_insert_string (activation->environment, + hash_key, hash_value)) + break; + } + _dbus_string_set_length (&key, 0); + _dbus_string_set_length (&value, 0); + } + + if (environment[i] != NULL) + goto out; + + retval = TRUE; +out: + + _dbus_string_free (&key); + _dbus_string_free (&value); dbus_free_string_array (environment); return retval; @@ -1553,7 +1599,51 @@ activation_find_entry (BusActivation *activation, static char ** bus_activation_get_environment (BusActivation *activation) { - return _dbus_hash_table_to_array (activation->environment, '='); + char **environment; + int i, length; + DBusString entry; + DBusHashIter iter; + + length = _dbus_hash_table_get_n_entries (activation->environment); + + environment = dbus_new0 (char *, length + 1); + + if (environment == NULL) + return NULL; + + i = 0; + _dbus_hash_iter_init (activation->environment, &iter); + + if (!_dbus_string_init (&entry)) + { + dbus_free_string_array (environment); + return NULL; + } + + while (_dbus_hash_iter_next (&iter)) + { + const char *key, *value; + + key = (const char *) _dbus_hash_iter_get_string_key (&iter); + value = (const char *) _dbus_hash_iter_get_value (&iter); + + if (!_dbus_string_append_printf (&entry, "%s=%s", key, value)) + break; + + if (!_dbus_string_steal_data (&entry, environment + i)) + break; + i++; + } + + _dbus_string_free (&entry); + + if (i != length) + { + dbus_free_string_array (environment); + environment = NULL; + } + + return environment; } dbus_bool_t diff --git a/dbus/dbus-hash.c b/dbus/dbus-hash.c index 8858bafd..8f7d04bb 100644 --- a/dbus/dbus-hash.c +++ b/dbus/dbus-hash.c @@ -1828,133 +1828,4 @@ _dbus_hash_test (void) return ret; } -/** - * Imports a string array into a hash table - * The hash table needs to be initialized with string keys, - * and dbus_free() as both key and value free-function. - * - * @param table the hash table - * @param array the string array to import - * @param delimiter the delimiter to separate key and value - * @return #TRUE on success. - * @return #FALSE if not enough memory. - */ - -dbus_bool_t -_dbus_hash_table_from_array (DBusHashTable *table, char **array, char delimiter) -{ - DBusString key; - DBusString value; - int i; - dbus_bool_t retval = FALSE; - - _dbus_assert (table != NULL); - _dbus_assert (array != NULL); - - if (!_dbus_string_init (&key)) - { - return FALSE; - } - - if (!_dbus_string_init (&value)) - { - _dbus_string_free (&key); - return FALSE; - } - - for (i = 0; array[i] != NULL; i++) - { - if (!_dbus_string_append (&key, array[i])) - break; - - if (_dbus_string_split_on_byte (&key, delimiter, &value)) - { - char *hash_key, *hash_value; - - if (!_dbus_string_steal_data (&key, &hash_key)) - break; - - if (!_dbus_string_steal_data (&value, &hash_value)) - break; - - if (!_dbus_hash_table_insert_string (table, - hash_key, hash_value)) - break; - } - _dbus_string_set_length (&key, 0); - _dbus_string_set_length (&value, 0); - } - - if (array[i] != NULL) - goto out; - - retval = TRUE; -out: - - _dbus_string_free (&key); - _dbus_string_free (&value); - - return retval; -} - -/** - * Creates a string array from a hash table - * - * @param table the hash table - * @param delimiter the delimiter to join key and value - * @return pointer to created string array (free with dbus_free_string_array) - * @return #FALSE if not enough memory. - */ -char ** -_dbus_hash_table_to_array (DBusHashTable *table, char delimiter) -{ - int i, length; - DBusString entry; - DBusHashIter iter; - char **array; - - _dbus_assert (table != NULL); - - length = _dbus_hash_table_get_n_entries (table); - - array = dbus_new0 (char *, length + 1); - - if (array == NULL) - return NULL; - - i = 0; - _dbus_hash_iter_init (table, &iter); - - if (!_dbus_string_init (&entry)) - { - dbus_free_string_array (array); - return NULL; - } - - while (_dbus_hash_iter_next (&iter)) - { - const char *key, *value; - - key = (const char *) _dbus_hash_iter_get_string_key (&iter); - value = (const char *) _dbus_hash_iter_get_value (&iter); - - if (!_dbus_string_append_printf (&entry, "%s%c%s", key, delimiter, value)) - break; - - if (!_dbus_string_steal_data (&entry, array + i)) - break; - i++; - } - - _dbus_string_free (&entry); - - if (i != length) - { - dbus_free_string_array (array); - array = NULL; - } - - return array; -} - #endif /* DBUS_ENABLE_EMBEDDED_TESTS */ diff --git a/dbus/dbus-hash.h b/dbus/dbus-hash.h index 93f717a9..2898f51c 100644 --- a/dbus/dbus-hash.h +++ b/dbus/dbus-hash.h @@ -133,14 +133,6 @@ dbus_bool_t _dbus_hash_table_insert_uintptr (DBusHashTable *table, DBUS_PRIVATE_EXPORT int _dbus_hash_table_get_n_entries (DBusHashTable *table); -DBUS_PRIVATE_EXPORT -char ** _dbus_hash_table_to_array (DBusHashTable *table, - char delimiter); -DBUS_PRIVATE_EXPORT -dbus_bool_t _dbus_hash_table_from_array (DBusHashTable *table, - char **array, - char delimiter); - /* Preallocation */ /** A preallocated hash entry */ From 1aa36b48cc112b2005db62607bb0845c7e444647 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Fri, 12 Feb 2016 15:25:09 +0000 Subject: [PATCH 07/10] Revert "Rename function string_array_length() to _dbus_string_array_length() and move it to dbus-internals.c." This reverts commit 1370b44035da90a7fbcebea17074c66c832de0b1. This change was intended for 1.11. --- dbus/dbus-internals.c | 15 --------------- dbus/dbus-internals.h | 2 -- dbus/dbus-object-tree.c | 22 +++++++++++++++------- 3 files changed, 15 insertions(+), 24 deletions(-) diff --git a/dbus/dbus-internals.c b/dbus/dbus-internals.c index d4f0433d..30a5fa73 100644 --- a/dbus/dbus-internals.c +++ b/dbus/dbus-internals.c @@ -641,21 +641,6 @@ _dbus_string_array_contains (const char **array, return FALSE; } -/** - * Returns the size of a string array - * - * @param array array to search. - * @returns size of array - */ -size_t -_dbus_string_array_length (const char **array) -{ - size_t i; - for (i = 0; array[i]; i++) {} - return i; -} - - /** * Generates a new UUID. If you change how this is done, * there's some text about it in the spec that should also change. diff --git a/dbus/dbus-internals.h b/dbus/dbus-internals.h index 6f92fa4c..3eb8749f 100644 --- a/dbus/dbus-internals.h +++ b/dbus/dbus-internals.h @@ -246,8 +246,6 @@ void* _dbus_memdup (const void *mem, DBUS_PRIVATE_EXPORT dbus_bool_t _dbus_string_array_contains (const char **array, const char *str); -DBUS_PRIVATE_EXPORT -size_t _dbus_string_array_length (const char **array); char** _dbus_dup_string_array (const char **array); #define _DBUS_INT16_MIN ((dbus_int16_t) 0x8000) diff --git a/dbus/dbus-object-tree.c b/dbus/dbus-object-tree.c index 27481a81..e2a3b737 100644 --- a/dbus/dbus-object-tree.c +++ b/dbus/dbus-object-tree.c @@ -1592,6 +1592,14 @@ do_test_dispatch (DBusObjectTree *tree, return FALSE; } +static size_t +string_array_length (const char **array) +{ + size_t i; + for (i = 0; array[i]; i++) ; + return i; +} + typedef struct { const char *path; @@ -1626,14 +1634,14 @@ run_decompose_tests (void) &result, &result_len)) return FALSE; - expected_len = _dbus_string_array_length (decompose_tests[i].result); + expected_len = string_array_length (decompose_tests[i].result); - if (result_len != (int) _dbus_string_array_length ((const char**)result) || + if (result_len != (int) string_array_length ((const char**)result) || expected_len != result_len || path_contains (decompose_tests[i].result, (const char**) result) != STR_EQUAL) { - int real_len = _dbus_string_array_length ((const char**)result); + int real_len = string_array_length ((const char**)result); _dbus_warn ("Expected decompose of %s to have len %d, returned %d, appears to have %d\n", decompose_tests[i].path, expected_len, result_len, real_len); @@ -1867,7 +1875,7 @@ object_tree_test_iteration (void *data) _dbus_object_tree_list_registered_unlocked (tree, path1, &child_entries); if (child_entries != NULL) { - nb = _dbus_string_array_length ((const char**)child_entries); + nb = string_array_length ((const char**)child_entries); _dbus_assert (nb == 1); dbus_free_string_array (child_entries); } @@ -1875,7 +1883,7 @@ object_tree_test_iteration (void *data) _dbus_object_tree_list_registered_unlocked (tree, path2, &child_entries); if (child_entries != NULL) { - nb = _dbus_string_array_length ((const char**)child_entries); + nb = string_array_length ((const char**)child_entries); _dbus_assert (nb == 2); dbus_free_string_array (child_entries); } @@ -1883,7 +1891,7 @@ object_tree_test_iteration (void *data) _dbus_object_tree_list_registered_unlocked (tree, path8, &child_entries); if (child_entries != NULL) { - nb = _dbus_string_array_length ((const char**)child_entries); + nb = string_array_length ((const char**)child_entries); _dbus_assert (nb == 0); dbus_free_string_array (child_entries); } @@ -1891,7 +1899,7 @@ object_tree_test_iteration (void *data) _dbus_object_tree_list_registered_unlocked (tree, root, &child_entries); if (child_entries != NULL) { - nb = _dbus_string_array_length ((const char**)child_entries); + nb = string_array_length ((const char**)child_entries); _dbus_assert (nb == 3); dbus_free_string_array (child_entries); } From c285a053d6ab72b0eb61fbb432511c544ca15c65 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Fri, 12 Feb 2016 15:25:12 +0000 Subject: [PATCH 08/10] Revert "name-test: run most C tests directly, not via run-test.sh" This reverts commit d893121efdea39d2b32037b32e336ea483829b2e. This change was intended for 1.11. --- test/name-test/Makefile.am | 28 +--------------------------- test/name-test/run-test.sh | 10 ++++++++-- 2 files changed, 9 insertions(+), 29 deletions(-) diff --git a/test/name-test/Makefile.am b/test/name-test/Makefile.am index 877d4234..fae28920 100644 --- a/test/name-test/Makefile.am +++ b/test/name-test/Makefile.am @@ -9,15 +9,7 @@ AM_LDFLAGS = @R_DYNAMIC_LDFLAG@ TEST_EXTENSIONS = .sh -LOG_DRIVER = env AM_TAP_AWK='$(AWK)' $(SHELL) $(top_srcdir)/build-aux/tap-driver.sh -SH_LOG_DRIVER = $(LOG_DRIVER) - -LOG_COMPILER = \ - @abs_top_builddir@/tools/dbus-run-session$(EXEEXT) \ - --config-file=@abs_builddir@/uninstalled-session.conf \ - --dbus-daemon=@abs_top_builddir@/bus/dbus-daemon$(EXEEXT) \ - -- \ - $(NULL) +SH_LOG_DRIVER = env AM_TAP_AWK='$(AWK)' $(SHELL) $(top_srcdir)/build-aux/tap-driver.sh SH_LOG_COMPILER = $(SHELL) ## note that TESTS has special meaning (stuff to use in make check) @@ -30,34 +22,16 @@ if DBUS_UNIX AM_TESTS_ENVIRONMENT = \ export DBUS_TOP_BUILDDIR=@abs_top_builddir@; \ export DBUS_TOP_SRCDIR=@abs_top_srcdir@; \ - export PATH="@abs_top_builddir@/bus:$$PATH"; \ export PYTHON=@PYTHON@; \ export DBUS_TEST_DATA=@abs_top_builddir@/test/data; \ export DBUS_TEST_DAEMON=@abs_top_builddir@/bus/dbus-daemon$(EXEEXT); \ export DBUS_TEST_DBUS_LAUNCH=@abs_top_builddir@/tools/dbus-launch$(EXEEXT); \ export XDG_RUNTIME_DIR=@abs_top_builddir@/test/XDG_RUNTIME_DIR; \ - unset DBUS_SESSION_BUS_ADDRESS; \ - unset DBUS_SESSION_BUS_PID; \ $(NULL) -uninstalled-session.conf: $(top_builddir)/bus/session.conf Makefile - $(SED) -e 's|@abs_top_builddir@/test/data/valid-service-files|g' \ - -e 's| $@ - -check_DATA = \ - uninstalled-session.conf \ - $(NULL) - TESTS += \ run-test.sh \ run-test-systemserver.sh \ - test-ids \ - test-pending-call-dispatch \ - test-pending-call-timeout \ - test-privserver-client \ - test-shutdown \ - test-threads-init \ $(NULL) endif endif diff --git a/test/name-test/run-test.sh b/test/name-test/run-test.sh index 092ec69f..8b9e7ad1 100755 --- a/test/name-test/run-test.sh +++ b/test/name-test/run-test.sh @@ -67,8 +67,14 @@ py_test () { } test_num=1 -# TAP test plan: we will run 2 tests -echo "1..2" +# TAP test plan: we will run 8 tests +echo "1..8" +c_test test-ids +c_test test-pending-call-dispatch +c_test test-pending-call-timeout +c_test test-threads-init +c_test test-privserver-client +c_test test-shutdown py_test test-activation-forking.py c_test test-autolaunch From 9843c724c6df98d353e6d627e88bdeac2d0f0d87 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Fri, 12 Feb 2016 15:25:13 +0000 Subject: [PATCH 09/10] Revert "name-test C tests: produce structured (TAP) output" This reverts commit fec99c9b3d8318e3abae432f2aca50802a87f90e. This change was intended for 1.11. --- test/name-test/test-ids.c | 28 ++++++--------------- test/name-test/test-pending-call-dispatch.c | 13 +++++----- test/name-test/test-pending-call-timeout.c | 11 ++++---- test/name-test/test-privserver-client.c | 16 +++--------- test/name-test/test-privserver.c | 2 +- test/name-test/test-shutdown.c | 17 +++++-------- test/name-test/test-threads-init.c | 7 ++---- 7 files changed, 31 insertions(+), 63 deletions(-) diff --git a/test/name-test/test-ids.c b/test/name-test/test-ids.c index f73a505f..8f63d044 100644 --- a/test/name-test/test-ids.c +++ b/test/name-test/test-ids.c @@ -11,13 +11,10 @@ static void die (const char *message) { - printf ("Bail out! test-ids: %s\n", message); + fprintf (stderr, "*** test-ids: %s", message); exit (1); } -static int test_num = 0; - -/* This test outputs TAP syntax: http://testanything.org/ */ int main (int argc, char **argv) @@ -26,7 +23,7 @@ main (int argc, DBusConnection *connection; char *id; char *server_id; - + dbus_error_init (&error); connection = dbus_bus_get (DBUS_BUS_SESSION, &error); if (connection == NULL) @@ -36,35 +33,24 @@ main (int argc, dbus_error_free (&error); return 1; } - printf ("ok %d - connected to session bus\n", ++test_num); server_id = dbus_connection_get_server_id (connection); - if (server_id == NULL) die ("No bus server ID retrieved\n"); - - printf ("ok %d - session bus server ID is %s\n", ++test_num, server_id); - + /* printf("'%s'\n", server_id); */ if (strlen (server_id) != 32) die ("Bus server id should have length 32\n"); - - printf ("ok %d - session bus server ID length is 32\n", ++test_num); - dbus_free (server_id); id = dbus_bus_get_id (connection, NULL); if (id == NULL) die ("No bus ID retrieved\n"); - - printf ("ok %d - session bus ID is %s\n", ++test_num, id); - + /* printf("'%s'\n", id); */ if (strlen (id) != 32) die ("Bus ID should have length 32\n"); - - printf ("ok %d - session bus ID length is 32\n", ++test_num); - dbus_free (id); - - printf ("1..%d\n", test_num); + + _dbus_verbose ("*** Test IDs exiting\n"); + return 0; } diff --git a/test/name-test/test-pending-call-dispatch.c b/test/name-test/test-pending-call-dispatch.c index 7785564d..c8b5a467 100644 --- a/test/name-test/test-pending-call-dispatch.c +++ b/test/name-test/test-pending-call-dispatch.c @@ -56,13 +56,13 @@ _run_iteration (DBusConnection *conn) if (reply == NULL) { - printf ("Bail out! Reply is NULL ***\n"); + printf ("Failed: Reply is NULL ***\n"); exit (1); } if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) { - printf ("Bail out! Reply is error: %s ***\n", dbus_message_get_error_name (reply)); + printf ("Failed: Reply is error: %s ***\n", dbus_message_get_error_name (reply)); exit (1); } @@ -72,7 +72,6 @@ _run_iteration (DBusConnection *conn) } -/* This test outputs TAP syntax: http://testanything.org/ */ int main (int argc, char *argv[]) { @@ -88,7 +87,7 @@ main (int argc, char *argv[]) but if it does and we are stuck in a poll call then we know the stuck in poll bug has come back to haunt us */ - printf ("# Testing stuck in poll\n"); + printf ("*** Testing stuck in poll\n"); dbus_error_init (&error); @@ -105,10 +104,10 @@ main (int argc, char *argv[]) /* we just care about seconds */ delta = end_tv_sec - start_tv_sec; - printf ("ok %d - %lis\n", i + 1, delta); + printf ("Iter %i: %lis\n", i, delta); if (delta >= 5) { - printf ("Bail out! Looks like we might have been be stuck in poll ***\n"); + printf ("Failed: looks like we might have been be stuck in poll ***\n"); exit (1); } } @@ -120,6 +119,6 @@ main (int argc, char *argv[]) dbus_connection_send (conn, method, NULL); dbus_message_unref (method); - printf ("# Testing completed\n1..%d\n", i); + printf ("Success ***\n"); exit (0); } diff --git a/test/name-test/test-pending-call-timeout.c b/test/name-test/test-pending-call-timeout.c index be6b849c..d051faba 100644 --- a/test/name-test/test-pending-call-timeout.c +++ b/test/name-test/test-pending-call-timeout.c @@ -39,13 +39,13 @@ _method_call (DBusConnection *conn, if (reply == NULL) { - printf ("Bail out! Reply is NULL ***\n"); + printf ("Failed: Reply is NULL ***\n"); exit (1); } if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) { - printf ("Bail out! Reply is error: %s ***\n", dbus_message_get_error_name (reply)); + printf ("Failed: Reply is error: %s ***\n", dbus_message_get_error_name (reply)); exit (1); } @@ -61,7 +61,6 @@ _run_iteration (DBusConnection *conn) _method_call (conn, INT_MAX); } -/* This test outputs TAP syntax: http://testanything.org/ */ int main (int argc, char *argv[]) { @@ -72,7 +71,7 @@ main (int argc, char *argv[]) DBusConnection *conn; DBusError error; - printf ("# Testing pending call timeouts\n"); + printf ("*** Testing pending call timeouts\n"); dbus_error_init (&error); @@ -89,7 +88,7 @@ main (int argc, char *argv[]) /* we just care about seconds */ delta = end_tv_sec - start_tv_sec; - printf ("ok %d - %lis\n", i + 1, delta); + printf ("Iter %i: %lis\n", i, delta); } method = dbus_message_new_method_call ("org.freedesktop.TestSuiteEchoService", @@ -99,6 +98,6 @@ main (int argc, char *argv[]) dbus_connection_send (conn, method, NULL); dbus_message_unref (method); - printf ("# Testing completed\n1..%d\n", i); + printf ("Success ***\n"); exit (0); } diff --git a/test/name-test/test-privserver-client.c b/test/name-test/test-privserver-client.c index 56b553c0..e7f48960 100644 --- a/test/name-test/test-privserver-client.c +++ b/test/name-test/test-privserver-client.c @@ -102,7 +102,7 @@ open_shutdown_private_connection (dbus_bool_t use_guid) dbus_message_unref (msg); if (!dbus_message_get_args (reply, &error, DBUS_TYPE_STRING, &addr, DBUS_TYPE_INVALID)) die ("couldn't parse message replym\n"); - printf ("# got private temp address %s\n", addr); + printf ("got private temp address %s\n", addr); addr = strdup (addr); if (!use_guid) { @@ -145,32 +145,24 @@ open_shutdown_private_connection (dbus_bool_t use_guid) _dbus_loop_unref (loop); } -/* This test outputs TAP syntax: http://testanything.org/ */ int main (int argc, char *argv[]) { - int test_num = 0; + open_shutdown_private_connection (TRUE); + + dbus_shutdown (); open_shutdown_private_connection (TRUE); dbus_shutdown (); - printf ("ok %d\n", ++test_num); - - open_shutdown_private_connection (TRUE); - - dbus_shutdown (); - printf ("ok %d\n", ++test_num); open_shutdown_private_connection (FALSE); dbus_shutdown (); - printf ("ok %d\n", ++test_num); open_shutdown_private_connection (FALSE); dbus_shutdown (); - printf ("ok %d\n", ++test_num); - printf ("1..%d\n", test_num); return 0; } diff --git a/test/name-test/test-privserver.c b/test/name-test/test-privserver.c index 367c8090..39a98b7f 100644 --- a/test/name-test/test-privserver.c +++ b/test/name-test/test-privserver.c @@ -97,7 +97,7 @@ main (int argc, char *argv[]) if (!server) die (error.message); testdata->private_addr = dbus_server_get_address (server); - fprintf (stderr, "test server listening on %s\n", testdata->private_addr); + printf ("test server listening on %s\n", testdata->private_addr); dbus_server_set_new_connection_function (server, new_connection_callback, testdata, NULL); diff --git a/test/name-test/test-shutdown.c b/test/name-test/test-shutdown.c index 39612f18..526c1cbc 100644 --- a/test/name-test/test-shutdown.c +++ b/test/name-test/test-shutdown.c @@ -7,7 +7,7 @@ static DBusLoop *loop; static void die (const char *message) { - printf ("Bail out! test-shutdown: %s", message); + fprintf (stderr, "*** test-shutdown: %s", message); exit (1); } @@ -46,28 +46,23 @@ open_destroy_shared_session_bus_connection (void) dbus_connection_unref (connection); } -/* This test outputs TAP syntax: http://testanything.org/ */ int main (int argc, char **argv) { - int test_num = 0; + open_destroy_shared_session_bus_connection (); + + dbus_shutdown (); open_destroy_shared_session_bus_connection (); dbus_shutdown (); - printf ("ok %d\n", ++test_num); open_destroy_shared_session_bus_connection (); dbus_shutdown (); - printf ("ok %d\n", ++test_num); - open_destroy_shared_session_bus_connection (); - - dbus_shutdown (); - printf ("ok %d\n", ++test_num); - - printf ("1..%d\n", test_num); + _dbus_verbose ("*** Test shutdown exiting\n"); + return 0; } diff --git a/test/name-test/test-threads-init.c b/test/name-test/test-threads-init.c index 62857158..a517e2a2 100644 --- a/test/name-test/test-threads-init.c +++ b/test/name-test/test-threads-init.c @@ -105,7 +105,7 @@ check_condvar_lock (DBusCondVar *condvar1, } } -/* This test outputs TAP syntax: http://testanything.org/ */ + int main (int argc, char *argv[]) { @@ -116,7 +116,6 @@ main (int argc, char *argv[]) DBusCondVar *dispatch_cond1, *io_path_cond1; DBusMutex *mutex2, *dispatch_mutex2, *io_path_mutex2; DBusCondVar *dispatch_cond2, *io_path_cond2; - int test_num = 0; printf ("*** Testing late thread init\n"); @@ -141,7 +140,6 @@ main (int argc, char *argv[]) check_mutex_lock (io_path_mutex1, io_path_mutex2, TRUE); check_condvar_lock (dispatch_cond1, dispatch_cond2, TRUE); check_condvar_lock (io_path_cond1, io_path_cond2, TRUE); - printf ("ok %d\n", ++test_num); dbus_threads_init_default (); @@ -163,7 +161,6 @@ main (int argc, char *argv[]) check_mutex_lock (io_path_mutex1, io_path_mutex2, TRUE); check_condvar_lock (dispatch_cond1, dispatch_cond2, TRUE); check_condvar_lock (io_path_cond1, io_path_cond2, TRUE); - printf ("ok %d\n", ++test_num); method = dbus_message_new_method_call ("org.freedesktop.TestSuiteEchoService", "/org/freedesktop/TestSuite", @@ -172,6 +169,6 @@ main (int argc, char *argv[]) dbus_connection_send (conn, method, NULL); dbus_message_unref (method); - printf ("Testing completed\n1..%d\n", test_num); + printf ("Success ***\n"); exit (0); } From 384c924c77ecb32e5b91d737b8b51cb0e883fd7c Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Fri, 12 Feb 2016 15:25:15 +0000 Subject: [PATCH 10/10] Revert "Replace $DBUS_USE_TEST_BINARY with $DBUS_TEST_DBUS_LAUNCH" This reverts commit 8fd2be6013e3d0ff6a6ff63ea022f9606d9a87c6. This change was intended for 1.11. --- cmake/CMakeLists.txt | 1 + cmake/config.h.cmake | 1 + cmake/modules/Macros.cmake | 1 - configure.ac | 3 +++ dbus/dbus-sysdeps-unix.c | 8 ++++---- test/Makefile.am | 2 -- test/name-test/Makefile.am | 1 - tools/dbus-launch.c | 6 +++--- tools/run-with-tmp-session-bus.sh | 5 +++++ 9 files changed, 17 insertions(+), 11 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 13332503..4db9c67a 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -506,6 +506,7 @@ if (DBUS_BUILD_TESTS) set(DBUS_TEST_DATA ${CMAKE_BINARY_DIR}/test/data) set(TEST_SOCKET_DIR ${DBUS_SESSION_SOCKET_DIR} ) set(TEST_LAUNCH_HELPER_BINARY ${EXECUTABLE_OUTPUT_PATH}/dbus-daemon-launch-helper-test) + set(TEST_BUS_LAUNCH_BINARY ${EXECUTABLE_OUTPUT_PATH}/dbus-launch${EXEEXT}) if (UNIX) set (TEST_LISTEN "unix:tmpdir=${TEST_SOCKET_DIR}") endif (UNIX) diff --git a/cmake/config.h.cmake b/cmake/config.h.cmake index c4983623..d2af3c96 100644 --- a/cmake/config.h.cmake +++ b/cmake/config.h.cmake @@ -33,6 +33,7 @@ // test binaries #define DBUS_TEST_EXEC "@DBUS_TEST_EXEC@" #define DBUS_EXEEXT "@EXEEXT@" +#cmakedefine TEST_BUS_LAUNCH_BINARY "@TEST_BUS_LAUNCH_BINARY@" /* Some dbus features */ #cmakedefine DBUS_ENABLE_ANSI 1 diff --git a/cmake/modules/Macros.cmake b/cmake/modules/Macros.cmake index 8e0278a4..fd3f62c4 100644 --- a/cmake/modules/Macros.cmake +++ b/cmake/modules/Macros.cmake @@ -52,7 +52,6 @@ macro(add_test_executable _target _source) list(APPEND _env "DBUS_SESSION_BUS_ADDRESS=") list(APPEND _env "DBUS_FATAL_WARNINGS=1") list(APPEND _env "DBUS_TEST_DATA=${PREFIX}${CMAKE_BINARY_DIR}/test/data") - list(APPEND _env "DBUS_TEST_DBUS_LAUNCH=${PREFIX}${CMAKE_BINARY_DIR}/bin/dbus-launch${EXEEXT}") list(APPEND _env "DBUS_TEST_HOMEDIR=${PREFIX}${CMAKE_BINARY_DIR}/dbus") set_tests_properties(${_target} PROPERTIES ENVIRONMENT "${_env}") endmacro(add_test_executable) diff --git a/configure.ac b/configure.ac index a734a3b6..5e883435 100644 --- a/configure.ac +++ b/configure.ac @@ -1731,6 +1731,9 @@ AC_DEFINE_UNQUOTED([DBUS_TEST_EXEC], ["$DBUS_TEST_EXEC"], AC_DEFINE_UNQUOTED([DBUS_EXEEXT], ["$EXEEXT"], [Extension for executables, typically empty or .exe]) +AC_DEFINE_UNQUOTED(TEST_BUS_LAUNCH_BINARY, ["$DBUS_PWD/tools/dbus-launch$EXEEXT"], + [Full path to the dbus-launch in the builddir]) + ## Export the non-setuid external helper TEST_LAUNCH_HELPER_BINARY="$DBUS_PWD/bus/dbus-daemon-launch-helper-test$EXEEXT" AC_SUBST(TEST_LAUNCH_HELPER_BINARY) diff --git a/dbus/dbus-sysdeps-unix.c b/dbus/dbus-sysdeps-unix.c index f0fca85e..50ca60a2 100644 --- a/dbus/dbus-sysdeps-unix.c +++ b/dbus/dbus-sysdeps-unix.c @@ -3671,7 +3671,7 @@ _dbus_get_autolaunch_address (const char *scope, * but that's done elsewhere, and if it worked, this function wouldn't * be called.) */ const char *display; - const char *progpath; + char *progpath; char *argv[6]; int i; DBusString uuid; @@ -3716,9 +3716,9 @@ _dbus_get_autolaunch_address (const char *scope, } #ifdef DBUS_ENABLE_EMBEDDED_TESTS - progpath = _dbus_getenv ("DBUS_TEST_DBUS_LAUNCH"); - - if (progpath == NULL) + if (_dbus_getenv ("DBUS_USE_TEST_BINARY") != NULL) + progpath = TEST_BUS_LAUNCH_BINARY; + else #endif progpath = DBUS_BINDIR "/dbus-launch"; /* diff --git a/test/Makefile.am b/test/Makefile.am index 1438995c..b7f40bb0 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -174,7 +174,6 @@ installcheck_tests = installcheck_environment = \ export XDG_RUNTIME_DIR=@abs_top_builddir@/test/XDG_RUNTIME_DIR; \ export DBUS_TEST_DAEMON=$(DESTDIR)$(DBUS_DAEMONDIR)/dbus-daemon$(EXEEXT); \ - export DBUS_TEST_DBUS_LAUNCH=$(DESTDIR)$(bindir)/dbus-launch$(EXEEXT); \ export DBUS_TEST_HOMEDIR=@abs_top_builddir@/dbus; \ export DBUS_TEST_DATADIR=$(DESTDIR)$(datadir); \ ${NULL} @@ -183,7 +182,6 @@ AM_TESTS_ENVIRONMENT = \ export XDG_RUNTIME_DIR=@abs_top_builddir@/test/XDG_RUNTIME_DIR; \ export DBUS_FATAL_WARNINGS=1; \ export DBUS_TEST_DAEMON=@abs_top_builddir@/bus/dbus-daemon$(EXEEXT); \ - export DBUS_TEST_DBUS_LAUNCH=@abs_top_builddir@/tools/dbus-launch$(EXEEXT); \ export DBUS_TEST_DATA=@abs_top_builddir@/test/data; \ export DBUS_TEST_HOMEDIR=@abs_top_builddir@/dbus; \ $(NULL) diff --git a/test/name-test/Makefile.am b/test/name-test/Makefile.am index fae28920..3b7fcc62 100644 --- a/test/name-test/Makefile.am +++ b/test/name-test/Makefile.am @@ -25,7 +25,6 @@ AM_TESTS_ENVIRONMENT = \ export PYTHON=@PYTHON@; \ export DBUS_TEST_DATA=@abs_top_builddir@/test/data; \ export DBUS_TEST_DAEMON=@abs_top_builddir@/bus/dbus-daemon$(EXEEXT); \ - export DBUS_TEST_DBUS_LAUNCH=@abs_top_builddir@/tools/dbus-launch$(EXEEXT); \ export XDG_RUNTIME_DIR=@abs_top_builddir@/test/XDG_RUNTIME_DIR; \ $(NULL) diff --git a/tools/dbus-launch.c b/tools/dbus-launch.c index 1b655027..0f1e6ede 100644 --- a/tools/dbus-launch.c +++ b/tools/dbus-launch.c @@ -1169,10 +1169,10 @@ main (int argc, char **argv) #ifdef DBUS_ENABLE_EMBEDDED_TESTS { + const char *test_daemon; /* exec from testdir */ - const char *test_daemon = getenv ("DBUS_TEST_DAEMON"); - - if (test_daemon != NULL) + if (getenv ("DBUS_USE_TEST_BINARY") != NULL && + (test_daemon = getenv ("DBUS_TEST_DAEMON")) != NULL) { if (config_file == NULL && getenv ("DBUS_TEST_DATA") != NULL) { diff --git a/tools/run-with-tmp-session-bus.sh b/tools/run-with-tmp-session-bus.sh index 688f9e48..94ae8fc8 100755 --- a/tools/run-with-tmp-session-bus.sh +++ b/tools/run-with-tmp-session-bus.sh @@ -45,6 +45,11 @@ export LD_LIBRARY_PATH unset DBUS_SESSION_BUS_ADDRESS unset DBUS_SESSION_BUS_PID +# this does not actually affect dbus-run-session any more, but could be +# significant for dbus-launch as used by the autolaunch test +DBUS_USE_TEST_BINARY=1 +export DBUS_USE_TEST_BINARY + $DBUS_TOP_BUILDDIR/tools/dbus-run-session \ --config-file="$CONFIG_FILE" \ --dbus-daemon="$DBUS_TOP_BUILDDIR/bus/dbus-daemon" \