#include "utils.h"
#include "bus.h"
#include "test.h"
-#include "loop.h"
#include <dbus/dbus-internals.h>
#include <string.h>
BUS_SET_OOM (error);
return FALSE;
}
-
+
+ if (!dbus_message_set_sender (error_reply, DBUS_SERVICE_DBUS))
+ {
+ dbus_message_unref (error_reply);
+ BUS_SET_OOM (error);
+ return FALSE;
+ }
+
if (!bus_transaction_send_message (transaction, connection, error_reply))
{
dbus_message_unref (error_reply);
* until we can.
*/
while (!bus_connection_preallocate_oom_error (connection))
- bus_wait_for_memory ();
+ _dbus_wait_for_memory ();
/* Ref connection in case we disconnect it at some point in here */
dbus_connection_ref (connection);
static dbus_bool_t check_no_leftovers (BusContext *context);
+static void
+block_connection_until_message_from_bus (BusContext *context,
+ DBusConnection *connection)
+{
+ while (dbus_connection_get_dispatch_status (connection) ==
+ DBUS_DISPATCH_COMPLETE &&
+ dbus_connection_get_is_connected (connection))
+ {
+ bus_test_run_bus_loop (context, TRUE);
+ bus_test_run_clients_loop (FALSE);
+ }
+}
+
+/* compensate for fact that pop_message() can return #NULL due to OOM */
+static DBusMessage*
+pop_message_waiting_for_memory (DBusConnection *connection)
+{
+ while (dbus_connection_get_dispatch_status (connection) ==
+ DBUS_DISPATCH_NEED_MEMORY)
+ _dbus_wait_for_memory ();
+
+ return dbus_connection_pop_message (connection);
+}
+
typedef struct
{
const char *expected_service_name;
d->failed = TRUE;
service_name = NULL;
- message = dbus_connection_pop_message (connection);
+ message = pop_message_waiting_for_memory (connection);
if (message == NULL)
{
_dbus_warn ("Did not receive a message on %p, expecting %s\n",
_dbus_assert (s != NULL);
while ((base_service = _dbus_strdup (s)) == NULL)
- bus_wait_for_memory ();
+ _dbus_wait_for_memory ();
dbus_connection_ref (connection);
/* kick in the disconnect handler that unrefs the connection */
dbus_connection_disconnect (connection);
- bus_test_flush_bus (context);
-
+ bus_test_run_everything (context);
+
_dbus_assert (bus_test_client_listed (connection));
/* Run disconnect handler in test.c */
CheckNoMessagesData *d = data;
DBusMessage *message;
- message = dbus_connection_pop_message (connection);
+ message = pop_message_waiting_for_memory (connection);
if (message != NULL)
{
_dbus_warn ("Received message %s on %p, expecting no messages\n",
d->failed = TRUE;
service_name = NULL;
- message = dbus_connection_pop_message (connection);
+ message = pop_message_waiting_for_memory (connection);
if (message == NULL)
{
_dbus_warn ("Did not receive a message on %p, expecting %s\n",
dbus_message_unref (message);
message = NULL;
-
- bus_test_flush_bus (context);
+
+ bus_test_run_everything (context);
if (!dbus_connection_get_is_connected (connection))
{
retval = FALSE;
- message = dbus_connection_pop_message (connection);
+ message = pop_message_waiting_for_memory (connection);
if (message == NULL)
{
_dbus_warn ("Did not receive a reply to %s %d on %p\n",
{
_dbus_verbose ("no memory to get service name arg from hello\n");
dbus_error_free (&error);
- bus_wait_for_memory ();
+ _dbus_wait_for_memory ();
goto retry_get_hello_name;
}
else
_dbus_verbose ("Got hello name: %s\n", name);
while (!dbus_bus_set_base_service (connection, name))
- bus_wait_for_memory ();
+ _dbus_wait_for_memory ();
scd.skip_connection = NULL;
scd.failed = FALSE;
/* Client should also have gotten ServiceAcquired */
dbus_message_unref (message);
- message = dbus_connection_pop_message (connection);
+ message = pop_message_waiting_for_memory (connection);
if (message == NULL)
{
_dbus_warn ("Expecting %s, got nothing\n",
{
_dbus_verbose ("no memory to get service name arg from acquired\n");
dbus_error_free (&error);
- bus_wait_for_memory ();
+ _dbus_wait_for_memory ();
goto retry_get_acquired_name;
}
else
dbus_message_unref (message);
message = NULL;
-
- bus_test_flush_bus (context);
+
+ bus_test_run_everything (context);
+ block_connection_until_message_from_bus (context, connection);
+ bus_test_run_everything (context);
if (!dbus_connection_get_is_connected (connection))
{
retval = FALSE;
- message = dbus_connection_pop_message (connection);
+ message = pop_message_waiting_for_memory (connection);
if (message == NULL)
{
_dbus_warn ("Did not receive a reply to %s %d on %p\n",
return retval;
}
-typedef struct
-{
- Check1Func func;
- BusContext *context;
-} Check1Data;
-
static dbus_bool_t
-check_oom_check1_func (void *data)
+check_base_service_activated (BusContext *context,
+ DBusConnection *connection,
+ DBusMessage *initial_message,
+ char **base_service_p)
{
- Check1Data *d = data;
-
- if (! (* d->func) (d->context))
- return FALSE;
+ DBusMessage *message;
+ dbus_bool_t retval;
+ DBusError error;
+ char *base_service;
- if (!check_no_leftovers (d->context))
+ base_service = NULL;
+ retval = FALSE;
+
+ dbus_error_init (&error);
+
+ message = initial_message;
+ dbus_message_ref (message);
+
+ if (dbus_message_name_is (message, DBUS_MESSAGE_SERVICE_CREATED))
{
- _dbus_warn ("Messages were left over, should be covered by test suite");
- return FALSE;
+ char *service_name;
+ CheckServiceCreatedData scd;
+
+ reget_service_name_arg:
+ if (!dbus_message_get_args (message, &error,
+ DBUS_TYPE_STRING, &service_name,
+ DBUS_TYPE_INVALID))
+ {
+ if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY))
+ {
+ dbus_error_free (&error);
+ _dbus_wait_for_memory ();
+ goto reget_service_name_arg;
+ }
+ else
+ {
+ _dbus_warn ("Message %s doesn't have a service name: %s\n",
+ dbus_message_get_name (message),
+ error.message);
+ dbus_error_free (&error);
+ goto out;
+ }
+ }
+
+ if (*service_name != ':')
+ {
+ _dbus_warn ("Expected base service activation, got \"%s\" instead\n",
+ service_name);
+ goto out;
+ }
+
+ base_service = service_name;
+ service_name = NULL;
+
+ scd.skip_connection = connection;
+ scd.failed = FALSE;
+ scd.expected_service_name = base_service;
+ bus_test_clients_foreach (check_service_created_foreach,
+ &scd);
+
+ if (scd.failed)
+ goto out;
+ }
+ else
+ {
+ _dbus_warn ("Expected to get base service ServiceCreated, instead got %s\n",
+ dbus_message_get_name (message));
+ goto out;
}
- return TRUE;
+ retval = TRUE;
+
+ if (base_service_p)
+ {
+ *base_service_p = base_service;
+ base_service = NULL;
+ }
+
+ out:
+ if (message)
+ dbus_message_unref (message);
+
+ if (base_service)
+ dbus_free (base_service);
+
+ return retval;
}
-static void
-check1_try_iterations (BusContext *context,
- const char *description,
- Check1Func func)
+static dbus_bool_t
+check_service_activated (BusContext *context,
+ DBusConnection *connection,
+ const char *activated_name,
+ const char *base_service_name,
+ DBusMessage *initial_message)
{
- Check1Data d;
+ DBusMessage *message;
+ dbus_bool_t retval;
+ DBusError error;
+ dbus_uint32_t activation_result;
+
+ retval = FALSE;
+
+ dbus_error_init (&error);
- d.func = func;
- d.context = context;
+ message = initial_message;
+ dbus_message_ref (message);
- if (!_dbus_test_oom_handling (description, check_oom_check1_func,
- &d))
- _dbus_assert_not_reached ("test failed");
-}
+ if (dbus_message_name_is (message, DBUS_MESSAGE_SERVICE_CREATED))
+ {
+ char *service_name;
+ CheckServiceCreatedData scd;
-typedef struct
-{
- Check2Func func;
- BusContext *context;
- DBusConnection *connection;
-} Check2Data;
+ reget_service_name_arg:
+ if (!dbus_message_get_args (message, &error,
+ DBUS_TYPE_STRING, &service_name,
+ DBUS_TYPE_INVALID))
+ {
+ if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY))
+ {
+ dbus_error_free (&error);
+ _dbus_wait_for_memory ();
+ goto reget_service_name_arg;
+ }
+ else
+ {
+ _dbus_warn ("Message %s doesn't have a service name: %s\n",
+ dbus_message_get_name (message),
+ error.message);
+ dbus_error_free (&error);
+ goto out;
+ }
+ }
-static dbus_bool_t
-check_oom_check2_func (void *data)
-{
- Check2Data *d = data;
+ if (strcmp (service_name, activated_name) != 0)
+ {
+ _dbus_warn ("Expected to see service %s created, saw %s instead\n",
+ activated_name, service_name);
+ dbus_free (service_name);
+ goto out;
+ }
+
+ scd.skip_connection = connection;
+ scd.failed = FALSE;
+ scd.expected_service_name = service_name;
+ bus_test_clients_foreach (check_service_created_foreach,
+ &scd);
+
+ dbus_free (service_name);
- if (! (* d->func) (d->context, d->connection))
- return FALSE;
+ if (scd.failed)
+ goto out;
+
+ dbus_message_unref (message);
+ message = pop_message_waiting_for_memory (connection);
+ if (message == NULL)
+ {
+ _dbus_warn ("Expected a reply to %s, got nothing\n",
+ DBUS_MESSAGE_ACTIVATE_SERVICE);
+ goto out;
+ }
+ }
+ else
+ {
+ _dbus_warn ("Expected to get service %s ServiceCreated, instead got %s\n",
+ activated_name, dbus_message_get_name (message));
+ goto out;
+ }
- if (!check_no_leftovers (d->context))
+ if (!dbus_message_name_is (message, DBUS_MESSAGE_ACTIVATE_SERVICE))
{
- _dbus_warn ("Messages were left over, should be covered by test suite");
- return FALSE;
+ _dbus_warn ("Expected reply to %s, got message %s instead\n",
+ DBUS_MESSAGE_ACTIVATE_SERVICE,
+ dbus_message_get_name (message));
+ goto out;
}
- return TRUE;
-}
+ activation_result = 0;
+ if (!dbus_message_get_args (message, &error,
+ DBUS_TYPE_UINT32, &activation_result,
+ DBUS_TYPE_INVALID))
+ {
+ if (!dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY))
+ {
+ _dbus_warn ("Did not have activation result first argument to %s: %s\n",
+ DBUS_MESSAGE_ACTIVATE_SERVICE, error.message);
+ dbus_error_free (&error);
+ goto out;
+ }
-static void
-check2_try_iterations (BusContext *context,
- DBusConnection *connection,
- const char *description,
- Check2Func func)
-{
- Check2Data d;
+ dbus_error_free (&error);
+ }
+ else
+ {
+ if (activation_result == DBUS_ACTIVATION_REPLY_ACTIVATED)
+ ; /* Good */
+ else if (activation_result == DBUS_ACTIVATION_REPLY_ALREADY_ACTIVE)
+ ; /* Good also */
+ else
+ {
+ _dbus_warn ("Activation result was 0x%x, no good.\n",
+ activation_result);
+ goto out;
+ }
+ }
- d.func = func;
- d.context = context;
- d.connection = connection;
+ dbus_message_unref (message);
+ message = NULL;
+
+ if (!check_no_leftovers (context))
+ {
+ _dbus_warn ("Messages were left over after verifying existent activation results\n");
+ goto out;
+ }
+
+ retval = TRUE;
- if (!_dbus_test_oom_handling (description, check_oom_check2_func,
- &d))
- _dbus_assert_not_reached ("test failed");
+ out:
+ if (message)
+ dbus_message_unref (message);
+
+ return retval;
}
-dbus_bool_t
-bus_dispatch_test (const DBusString *test_data_dir)
+static dbus_bool_t
+check_service_deactivated (BusContext *context,
+ DBusConnection *connection,
+ const char *activated_name,
+ const char *base_service)
{
- BusContext *context;
- DBusConnection *foo;
- DBusConnection *bar;
- DBusConnection *baz;
+ DBusMessage *message;
+ dbus_bool_t retval;
DBusError error;
-
- context = bus_context_new_test (test_data_dir,
- "valid-config-files/debug-allow-all.conf");
- if (context == NULL)
- return FALSE;
+ CheckServiceDeletedData csdd;
- dbus_error_init (&error);
+ message = NULL;
+ retval = FALSE;
- foo = dbus_connection_open ("debug-pipe:name=test-server", &error);
- if (foo == NULL)
- _dbus_assert_not_reached ("could not alloc connection");
+ dbus_error_init (&error);
- if (!bus_setup_debug_client (foo))
- _dbus_assert_not_reached ("could not set up connection");
+ /* Now we are expecting ServiceDeleted messages for the base
+ * service and the activated_name. The base service
+ * notification is required to come last.
+ */
+ csdd.expected_service_name = activated_name;
+ csdd.failed = FALSE;
+ bus_test_clients_foreach (check_service_deleted_foreach,
+ &csdd);
- if (!check_hello_message (context, foo))
- _dbus_assert_not_reached ("hello message failed");
-
- bar = dbus_connection_open ("debug-pipe:name=test-server", &error);
- if (bar == NULL)
- _dbus_assert_not_reached ("could not alloc connection");
+ if (csdd.failed)
+ goto out;
+
+ csdd.expected_service_name = base_service;
+ csdd.failed = FALSE;
+ bus_test_clients_foreach (check_service_deleted_foreach,
+ &csdd);
- if (!bus_setup_debug_client (bar))
- _dbus_assert_not_reached ("could not set up connection");
+ if (csdd.failed)
+ goto out;
+
+ if (!check_no_leftovers (context))
+ {
+ _dbus_warn ("Messages were left over after verifying results of service exiting\n");
+ goto out;
+ }
- if (!check_hello_message (context, bar))
- _dbus_assert_not_reached ("hello message failed");
+ retval = TRUE;
+
+ out:
+ if (message)
+ dbus_message_unref (message);
+
+ return retval;
+}
+
+static dbus_bool_t
+check_send_exit_to_service (BusContext *context,
+ DBusConnection *connection,
+ const char *service_name,
+ const char *base_service)
+{
+ dbus_bool_t got_error;
+ DBusMessage *message;
+ dbus_int32_t serial;
+ dbus_bool_t retval;
+
+ _dbus_verbose ("Sending exit message to the test service\n");
+
+ retval = FALSE;
+
+ /* Kill off the test service by sending it a quit message */
+ message = dbus_message_new (service_name,
+ "org.freedesktop.DBus.TestSuiteExit");
+
+ if (message == NULL)
+ {
+ /* Do this again; we still need the service to exit... */
+ if (!check_send_exit_to_service (context, connection,
+ service_name, base_service))
+ goto out;
+
+ return TRUE;
+ }
+
+ if (!dbus_connection_send (connection, message, &serial))
+ {
+ dbus_message_unref (message);
+
+ /* Do this again; we still need the service to exit... */
+ if (!check_send_exit_to_service (context, connection,
+ service_name, base_service))
+ goto out;
+
+ return TRUE;
+ }
+
+ dbus_message_unref (message);
+ message = NULL;
+
+ /* send message */
+ bus_test_run_clients_loop (TRUE);
+
+ /* read it in and write it out to test service */
+ bus_test_run_bus_loop (context, FALSE);
+
+ /* see if we got an error during message bus dispatching */
+ bus_test_run_clients_loop (FALSE);
+ message = dbus_connection_borrow_message (connection);
+ got_error = message != NULL && dbus_message_get_is_error (message);
+ if (message)
+ dbus_connection_return_message (connection, message);
+
+ if (!got_error)
+ {
+ /* If no error, wait for the test service to exit */
+ block_connection_until_message_from_bus (context, connection);
+
+ bus_test_run_everything (context);
+ }
+
+ if (got_error)
+ {
+ message = pop_message_waiting_for_memory (connection);
+ _dbus_assert (message != NULL);
+
+ if (!dbus_message_get_is_error (message))
+ {
+ _dbus_warn ("expecting an error reply to asking test service to exit, got %s\n",
+ dbus_message_get_name (message));
+ goto out;
+ }
+ else if (!dbus_message_name_is (message, DBUS_ERROR_NO_MEMORY))
+ {
+ _dbus_warn ("not expecting error %s when asking test service to exit\n",
+ dbus_message_get_name (message));
+ goto out;
+ }
+
+ _dbus_verbose ("Got error %s when asking test service to exit\n",
+ dbus_message_get_name (message));
+
+ /* Do this again; we still need the service to exit... */
+ if (!check_send_exit_to_service (context, connection,
+ service_name, base_service))
+ goto out;
+ }
+ else
+ {
+ if (!check_service_deactivated (context, connection,
+ service_name, base_service))
+ goto out;
+ }
+
+ retval = TRUE;
+
+ out:
+ if (message)
+ dbus_message_unref (message);
+
+ return retval;
+}
+
+static dbus_bool_t
+check_got_error (BusContext *context,
+ DBusConnection *connection,
+ const char *error_name)
+{
+ DBusMessage *message;
+ dbus_bool_t retval;
+
+ retval = FALSE;
+
+ message = pop_message_waiting_for_memory (connection);
+ if (message == NULL)
+ {
+ _dbus_warn ("Did not get an expected error\n");
+ goto out;
+ }
+
+ if (!dbus_message_get_is_error (message))
+ {
+ _dbus_warn ("Expected an error, got %s\n",
+ dbus_message_get_name (message));
+ goto out;
+ }
+
+ if (!dbus_message_name_is (message, error_name))
+ {
+ _dbus_warn ("Expected error %s, got %s instead\n",
+ error_name,
+ dbus_message_get_name (message));
+ goto out;
+ }
+
+ retval = TRUE;
+
+ out:
+ if (message)
+ dbus_message_unref (message);
+
+ return retval;
+}
+
+#define EXISTENT_SERVICE_NAME "org.freedesktop.DBus.TestSuiteEchoService"
+
+/* returns TRUE if the correct thing happens,
+ * but the correct thing may include OOM errors.
+ */
+static dbus_bool_t
+check_existent_service_activation (BusContext *context,
+ DBusConnection *connection)
+{
+ DBusMessage *message;
+ dbus_int32_t serial;
+ dbus_bool_t retval;
+ DBusError error;
+ char *base_service;
+
+ base_service = NULL;
+
+ dbus_error_init (&error);
+
+ message = dbus_message_new (DBUS_SERVICE_DBUS,
+ DBUS_MESSAGE_ACTIVATE_SERVICE);
+
+ if (message == NULL)
+ return TRUE;
+
+ if (!dbus_message_append_args (message,
+ DBUS_TYPE_STRING, EXISTENT_SERVICE_NAME,
+ DBUS_TYPE_UINT32, 0,
+ DBUS_TYPE_INVALID))
+ {
+ dbus_message_unref (message);
+ return TRUE;
+ }
+
+ if (!dbus_connection_send (connection, message, &serial))
+ {
+ dbus_message_unref (message);
+ return TRUE;
+ }
+
+ dbus_message_unref (message);
+ message = NULL;
+
+ bus_test_run_everything (context);
+
+ /* now wait for the message bus to hear back from the activated
+ * service.
+ */
+ block_connection_until_message_from_bus (context, connection);
+
+ bus_test_run_everything (context);
+
+ if (!dbus_connection_get_is_connected (connection))
+ {
+ _dbus_verbose ("connection was disconnected\n");
+ return TRUE;
+ }
+
+ retval = FALSE;
+
+ message = pop_message_waiting_for_memory (connection);
+ if (message == NULL)
+ {
+ _dbus_warn ("Did not receive any messages after %s %d on %p\n",
+ DBUS_MESSAGE_ACTIVATE_SERVICE, serial, connection);
+ goto out;
+ }
+
+ _dbus_verbose ("Received %s on %p after sending %s\n",
+ dbus_message_get_name (message), connection,
+ DBUS_MESSAGE_ACTIVATE_SERVICE);
+
+ if (dbus_message_get_is_error (message))
+ {
+ if (!dbus_message_sender_is (message, DBUS_SERVICE_DBUS))
+ {
+ _dbus_warn ("Message has wrong sender %s\n",
+ dbus_message_get_sender (message) ?
+ dbus_message_get_sender (message) : "(none)");
+ goto out;
+ }
+
+ if (dbus_message_name_is (message,
+ DBUS_ERROR_NO_MEMORY))
+ {
+ ; /* good, this is a valid response */
+ }
+ else if (dbus_message_name_is (message,
+ DBUS_ERROR_SPAWN_CHILD_EXITED))
+ {
+ ; /* good, this is expected also */
+ }
+ else
+ {
+ _dbus_warn ("Did not expect error %s\n",
+ dbus_message_get_name (message));
+ goto out;
+ }
+ }
+ else
+ {
+ dbus_bool_t got_service_deleted;
+ dbus_bool_t got_error;
+
+ if (!check_base_service_activated (context, connection,
+ message, &base_service))
+ goto out;
+
+ dbus_message_unref (message);
+ message = NULL;
+
+ /* We may need to block here for the test service to exit or finish up */
+ block_connection_until_message_from_bus (context, connection);
+
+ message = dbus_connection_borrow_message (connection);
+ if (message == NULL)
+ {
+ _dbus_warn ("Did not receive any messages after base service creation notification\n");
+ goto out;
+ }
+
+ got_service_deleted = dbus_message_name_is (message, DBUS_MESSAGE_SERVICE_DELETED);
+ got_error = dbus_message_get_is_error (message);
+
+ dbus_connection_return_message (connection, message);
+ message = NULL;
+
+ if (got_error)
+ {
+ if (!check_got_error (context, connection,
+ DBUS_ERROR_SPAWN_CHILD_EXITED))
+ goto out;
+
+ /* A service deleted should be coming along now after this error.
+ * We can also get the error *after* the service deleted.
+ */
+ got_service_deleted = TRUE;
+ }
+
+ if (got_service_deleted)
+ {
+ /* The service started up and got a base address, but then
+ * failed to register under EXISTENT_SERVICE_NAME
+ */
+ CheckServiceDeletedData csdd;
+
+ csdd.expected_service_name = base_service;
+ csdd.failed = FALSE;
+ bus_test_clients_foreach (check_service_deleted_foreach,
+ &csdd);
+
+ if (csdd.failed)
+ goto out;
+
+ /* Now we should get an error about the service exiting
+ * if we didn't get it before.
+ */
+ if (!got_error)
+ {
+ block_connection_until_message_from_bus (context, connection);
+
+ /* and process everything again */
+ bus_test_run_everything (context);
+
+ if (!check_got_error (context, connection,
+ DBUS_ERROR_SPAWN_CHILD_EXITED))
+ goto out;
+ }
+ }
+ else
+ {
+ message = pop_message_waiting_for_memory (connection);
+ if (message == NULL)
+ {
+ _dbus_warn ("Failed to pop message we just put back! should have been a ServiceCreated\n");
+ goto out;
+ }
+
+ if (!check_service_activated (context, connection, EXISTENT_SERVICE_NAME,
+ base_service, message))
+ goto out;
+
+ dbus_message_unref (message);
+ message = NULL;
+
+
+ if (!check_no_leftovers (context))
+ {
+ _dbus_warn ("Messages were left over after successful activation\n");
+ goto out;
+ }
+
+ if (!check_send_exit_to_service (context, connection,
+ EXISTENT_SERVICE_NAME, base_service))
+ goto out;
+ }
+ }
+
+ retval = TRUE;
+
+ out:
+ if (message)
+ dbus_message_unref (message);
+
+ if (base_service)
+ dbus_free (base_service);
+
+ return retval;
+}
+
+/* returns TRUE if the correct thing happens,
+ * but the correct thing may include OOM errors.
+ */
+static dbus_bool_t
+check_segfault_service_activation (BusContext *context,
+ DBusConnection *connection)
+{
+ DBusMessage *message;
+ dbus_int32_t serial;
+ dbus_bool_t retval;
+ DBusError error;
+
+ dbus_error_init (&error);
+
+ message = dbus_message_new (DBUS_SERVICE_DBUS,
+ DBUS_MESSAGE_ACTIVATE_SERVICE);
+
+ if (message == NULL)
+ return TRUE;
+
+ if (!dbus_message_append_args (message,
+ DBUS_TYPE_STRING,
+ "org.freedesktop.DBus.TestSuiteSegfaultService",
+ DBUS_TYPE_UINT32, 0,
+ DBUS_TYPE_INVALID))
+ {
+ dbus_message_unref (message);
+ return TRUE;
+ }
+
+ if (!dbus_connection_send (connection, message, &serial))
+ {
+ dbus_message_unref (message);
+ return TRUE;
+ }
+
+ dbus_message_unref (message);
+ message = NULL;
+
+ bus_test_run_everything (context);
+ block_connection_until_message_from_bus (context, connection);
+ bus_test_run_everything (context);
+
+ if (!dbus_connection_get_is_connected (connection))
+ {
+ _dbus_verbose ("connection was disconnected\n");
+ return TRUE;
+ }
+
+ retval = FALSE;
+
+ message = pop_message_waiting_for_memory (connection);
+ if (message == NULL)
+ {
+ _dbus_warn ("Did not receive a reply to %s %d on %p\n",
+ DBUS_MESSAGE_ACTIVATE_SERVICE, serial, connection);
+ goto out;
+ }
+
+ _dbus_verbose ("Received %s on %p\n",
+ dbus_message_get_name (message), connection);
+
+ if (dbus_message_get_is_error (message))
+ {
+ if (!dbus_message_sender_is (message, DBUS_SERVICE_DBUS))
+ {
+ _dbus_warn ("Message has wrong sender %s\n",
+ dbus_message_get_sender (message) ?
+ dbus_message_get_sender (message) : "(none)");
+ goto out;
+ }
+
+ if (dbus_message_name_is (message,
+ DBUS_ERROR_NO_MEMORY))
+ {
+ ; /* good, this is a valid response */
+ }
+ else if (dbus_message_name_is (message,
+ DBUS_ERROR_SPAWN_CHILD_SIGNALED))
+ {
+ ; /* good, this is expected also */
+ }
+ else
+ {
+ _dbus_warn ("Did not expect error %s\n",
+ dbus_message_get_name (message));
+ goto out;
+ }
+ }
+ else
+ {
+ _dbus_warn ("Did not expect to successfully activate segfault service\n");
+ goto out;
+ }
+
+ retval = TRUE;
+
+ out:
+ if (message)
+ dbus_message_unref (message);
+
+ return retval;
+}
+
+typedef struct
+{
+ Check1Func func;
+ BusContext *context;
+} Check1Data;
+
+static dbus_bool_t
+check_oom_check1_func (void *data)
+{
+ Check1Data *d = data;
+
+ if (! (* d->func) (d->context))
+ return FALSE;
+
+ if (!check_no_leftovers (d->context))
+ {
+ _dbus_warn ("Messages were left over, should be covered by test suite\n");
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+static void
+check1_try_iterations (BusContext *context,
+ const char *description,
+ Check1Func func)
+{
+ Check1Data d;
+
+ d.func = func;
+ d.context = context;
+
+ if (!_dbus_test_oom_handling (description, check_oom_check1_func,
+ &d))
+ _dbus_assert_not_reached ("test failed");
+}
+
+typedef struct
+{
+ Check2Func func;
+ BusContext *context;
+ DBusConnection *connection;
+} Check2Data;
+
+static dbus_bool_t
+check_oom_check2_func (void *data)
+{
+ Check2Data *d = data;
+
+ if (! (* d->func) (d->context, d->connection))
+ return FALSE;
+
+ if (!check_no_leftovers (d->context))
+ {
+ _dbus_warn ("Messages were left over, should be covered by test suite");
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+static void
+check2_try_iterations (BusContext *context,
+ DBusConnection *connection,
+ const char *description,
+ Check2Func func)
+{
+ Check2Data d;
+
+ d.func = func;
+ d.context = context;
+ d.connection = connection;
+
+ if (!_dbus_test_oom_handling (description, check_oom_check2_func,
+ &d))
+ _dbus_assert_not_reached ("test failed");
+}
+
+dbus_bool_t
+bus_dispatch_test (const DBusString *test_data_dir)
+{
+ BusContext *context;
+ DBusConnection *foo;
+ DBusConnection *bar;
+ DBusConnection *baz;
+ DBusError error;
+
+ context = bus_context_new_test (test_data_dir,
+ "valid-config-files/debug-allow-all.conf");
+ if (context == NULL)
+ return FALSE;
+
+ dbus_error_init (&error);
+
+ foo = dbus_connection_open ("debug-pipe:name=test-server", &error);
+ if (foo == NULL)
+ _dbus_assert_not_reached ("could not alloc connection");
+
+ if (!bus_setup_debug_client (foo))
+ _dbus_assert_not_reached ("could not set up connection");
+
+ if (!check_hello_message (context, foo))
+ _dbus_assert_not_reached ("hello message failed");
+
+ bar = dbus_connection_open ("debug-pipe:name=test-server", &error);
+ if (bar == NULL)
+ _dbus_assert_not_reached ("could not alloc connection");
+
+ if (!bus_setup_debug_client (bar))
+ _dbus_assert_not_reached ("could not set up connection");
+
+ if (!check_hello_message (context, bar))
+ _dbus_assert_not_reached ("hello message failed");
baz = dbus_connection_open ("debug-pipe:name=test-server", &error);
if (baz == NULL)
if (!check_hello_message (context, baz))
_dbus_assert_not_reached ("hello message failed");
+ check1_try_iterations (context, "create_and_hello",
+ check_hello_connection);
+
check2_try_iterations (context, foo, "nonexistent_service_activation",
check_nonexistent_service_activation);
- check1_try_iterations (context, "create_and_hello",
- check_hello_connection);
+ check2_try_iterations (context, foo, "segfault_service_activation",
+ check_segfault_service_activation);
+
+ check2_try_iterations (context, foo, "existent_service_activation",
+ check_existent_service_activation);
_dbus_verbose ("Disconnecting foo, bar, and baz\n");