2 * Test to make sure late thread initialization works
6 #include <dbus/dbus-sysdeps.h>
10 #include <dbus/dbus-internals.h>
11 #include <dbus/dbus-connection-internal.h>
14 _run_iteration (DBusConnection *conn)
16 DBusPendingCall *echo_pending;
17 DBusPendingCall *dbus_pending;
22 /* send the first message */
23 method = dbus_message_new_method_call ("org.freedesktop.DBus.TestSuiteEchoService",
24 "/org/freedesktop/TestSuite",
25 "org.freedesktop.TestSuite",
28 dbus_message_append_args (method, DBUS_TYPE_STRING, &echo, NULL);
29 dbus_connection_send_with_reply (conn, method, &echo_pending, -1);
30 dbus_message_unref (method);
32 /* send the second message */
33 method = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
35 "org.freedesktop.Introspectable",
38 dbus_connection_send_with_reply (conn, method, &dbus_pending, -1);
39 dbus_message_unref (method);
41 /* block on the second message (should return immediately) */
42 dbus_pending_call_block (dbus_pending);
44 /* block on the first message */
45 /* if it does not return immediately chances
46 are we hit the block in poll bug */
47 dbus_pending_call_block (echo_pending);
49 /* check the reply only to make sure we
50 are not getting errors unrelated
51 to the block in poll bug */
52 reply = dbus_pending_call_steal_reply (echo_pending);
56 printf ("Failed: Reply is NULL ***\n");
60 if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR)
62 printf ("Failed: Reply is error: %s ***\n", dbus_message_get_error_name (reply));
66 dbus_message_unref (reply);
67 dbus_pending_call_unref (dbus_pending);
68 dbus_pending_call_unref (echo_pending);
72 check_mutex_lock (DBusMutex *mutex1,
76 _dbus_assert (mutex1 != NULL);
77 _dbus_assert (mutex2 != NULL);
81 _dbus_assert (mutex1 == mutex2);
85 _dbus_assert (mutex1 != mutex2);
90 check_condvar_lock (DBusCondVar *condvar1,
91 DBusCondVar *condvar2,
94 _dbus_assert (condvar1 != NULL);
95 _dbus_assert (condvar2 != NULL);
99 _dbus_assert (condvar1 == condvar2);
103 _dbus_assert (condvar1 != condvar2);
109 main (int argc, char *argv[])
112 DBusConnection *conn;
114 DBusMutex *mutex1, *dispatch_mutex1, *io_path_mutex1;
115 DBusCondVar *dispatch_cond1, *io_path_cond1;
116 DBusMutex *mutex2, *dispatch_mutex2, *io_path_mutex2;
117 DBusCondVar *dispatch_cond2, *io_path_cond2;
119 printf ("*** Testing late thread init\n");
121 dbus_error_init (&error);
123 conn = dbus_bus_get (DBUS_BUS_SESSION, &error);
125 _dbus_connection_test_get_locks (conn, &mutex1,
130 _run_iteration (conn);
131 _dbus_connection_test_get_locks (conn, &mutex2,
137 check_mutex_lock (mutex1, mutex2, TRUE);
138 check_mutex_lock (dispatch_mutex1, dispatch_mutex2, TRUE);
139 check_mutex_lock (io_path_mutex1, io_path_mutex2, TRUE);
140 check_condvar_lock (dispatch_cond1, dispatch_cond2, TRUE);
141 check_condvar_lock (io_path_cond1, io_path_cond2, TRUE);
143 dbus_threads_init_default ();
145 _dbus_connection_test_get_locks (conn, &mutex1,
151 check_mutex_lock (mutex1, mutex2, FALSE);
152 check_mutex_lock (dispatch_mutex1, dispatch_mutex2, FALSE);
153 check_mutex_lock (io_path_mutex1, io_path_mutex2, FALSE);
154 check_condvar_lock (dispatch_cond1, dispatch_cond2, FALSE);
155 check_condvar_lock (io_path_cond1, io_path_cond2, FALSE);
157 _run_iteration (conn);
158 _dbus_connection_test_get_locks (conn, &mutex2,
164 check_mutex_lock (mutex1, mutex2, TRUE);
165 check_mutex_lock (dispatch_mutex1, dispatch_mutex2, TRUE);
166 check_mutex_lock (io_path_mutex1, io_path_mutex2, TRUE);
167 check_condvar_lock (dispatch_cond1, dispatch_cond2, TRUE);
168 check_condvar_lock (io_path_cond1, io_path_cond2, TRUE);
170 method = dbus_message_new_method_call ("org.freedesktop.TestSuiteEchoService",
171 "/org/freedesktop/TestSuite",
172 "org.freedesktop.TestSuite",
174 dbus_connection_send (conn, method, NULL);
175 dbus_message_unref (method);
177 printf ("Success ***\n");