2 * Test to make sure late thread initialization works
6 #include <dbus/dbus-sysdeps.h>
10 #include <dbus/dbus-internals.h>
13 _run_iteration (DBusConnection *conn)
15 DBusPendingCall *echo_pending;
16 DBusPendingCall *dbus_pending;
21 /* send the first message */
22 method = dbus_message_new_method_call ("org.freedesktop.DBus.TestSuiteEchoService",
23 "/org/freedesktop/TestSuite",
24 "org.freedesktop.TestSuite",
27 dbus_message_append_args (method, DBUS_TYPE_STRING, &echo, NULL);
28 dbus_connection_send_with_reply (conn, method, &echo_pending, -1);
29 dbus_message_unref (method);
31 /* send the second message */
32 method = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
34 "org.freedesktop.Introspectable",
37 dbus_connection_send_with_reply (conn, method, &dbus_pending, -1);
38 dbus_message_unref (method);
40 /* block on the second message (should return immediately) */
41 dbus_pending_call_block (dbus_pending);
43 /* block on the first message */
44 /* if it does not return immediately chances
45 are we hit the block in poll bug */
46 dbus_pending_call_block (echo_pending);
48 /* check the reply only to make sure we
49 are not getting errors unrelated
50 to the block in poll bug */
51 reply = dbus_pending_call_steal_reply (echo_pending);
55 printf ("Failed: Reply is NULL ***\n");
59 if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR)
61 printf ("Failed: Reply is error: %s ***\n", dbus_message_get_error_name (reply));
65 dbus_message_unref (reply);
66 dbus_pending_call_unref (dbus_pending);
67 dbus_pending_call_unref (echo_pending);
71 check_mutex_lock (DBusMutex *mutex1,
75 _dbus_assert (mutex1 != NULL);
76 _dbus_assert (mutex2 != NULL);
80 _dbus_assert (mutex1 == mutex2);
84 _dbus_assert (mutex1 != mutex2);
89 check_condvar_lock (DBusCondVar *condvar1,
90 DBusCondVar *condvar2,
93 _dbus_assert (condvar1 != NULL);
94 _dbus_assert (condvar2 != NULL);
98 _dbus_assert (condvar1 == condvar2);
102 _dbus_assert (condvar1 != condvar2);
108 main (int argc, char *argv[])
110 long start_tv_sec, start_tv_usec;
111 long end_tv_sec, end_tv_usec;
114 DBusConnection *conn;
116 DBusMutex *mutex1, *dispatch_mutex1, *io_path_mutex1;
117 DBusCondVar *dispatch_cond1, *io_path_cond1;
118 DBusMutex *mutex2, *dispatch_mutex2, *io_path_mutex2;
119 DBusCondVar *dispatch_cond2, *io_path_cond2;
121 printf ("*** Testing late thread init\n");
123 dbus_error_init (&error);
125 conn = dbus_bus_get (DBUS_BUS_SESSION, &error);
127 _dbus_connection_test_get_locks (conn, &mutex1,
132 _run_iteration (conn);
133 _dbus_connection_test_get_locks (conn, &mutex2,
139 check_mutex_lock (mutex1, mutex2, TRUE);
140 check_mutex_lock (dispatch_mutex1, dispatch_mutex2, TRUE);
141 check_mutex_lock (io_path_mutex1, io_path_mutex2, TRUE);
142 check_condvar_lock (dispatch_cond1, dispatch_cond2, TRUE);
143 check_condvar_lock (io_path_cond1, io_path_cond2, TRUE);
145 _dbus_threads_init_debug ();
147 _dbus_connection_test_get_locks (conn, &mutex1,
153 check_mutex_lock (mutex1, mutex2, FALSE);
154 check_mutex_lock (dispatch_mutex1, dispatch_mutex2, FALSE);
155 check_mutex_lock (io_path_mutex1, io_path_mutex2, FALSE);
156 check_condvar_lock (dispatch_cond1, dispatch_cond2, FALSE);
157 check_condvar_lock (io_path_cond1, io_path_cond2, FALSE);
159 _run_iteration (conn);
160 _dbus_connection_test_get_locks (conn, &mutex2,
166 check_mutex_lock (mutex1, mutex2, TRUE);
167 check_mutex_lock (dispatch_mutex1, dispatch_mutex2, TRUE);
168 check_mutex_lock (io_path_mutex1, io_path_mutex2, TRUE);
169 check_condvar_lock (dispatch_cond1, dispatch_cond2, TRUE);
170 check_condvar_lock (io_path_cond1, io_path_cond2, TRUE);
172 method = dbus_message_new_method_call ("org.freedesktop.TestSuiteEchoService",
173 "/org/freedesktop/TestSuite",
174 "org.freedesktop.TestSuite",
176 dbus_connection_send (conn, method, NULL);
177 dbus_message_unref (method);
179 printf ("Success ***\n");