author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 11 Jun 2010 15:26:22 +0300 | |
changeset 34 | 5fae379060a7 |
parent 31 | ce057bb09d0b |
child 45 | 4b03adbd26ca |
permissions | -rw-r--r-- |
34
5fae379060a7
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
1 |
/* Portion Copyright © 2008 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.*/ |
31 | 2 |
/** |
3 |
* Test to make sure late thread initialization works |
|
4 |
*/ |
|
5 |
||
6 |
#include <dbus/dbus.h> |
|
7 |
#ifndef __SYMBIAN32__ |
|
8 |
#include <dbus/dbus-sysdeps.h> |
|
9 |
#else |
|
10 |
#include "dbus-sysdeps.h" |
|
11 |
#endif //__SYMBIAN32__ |
|
12 |
#include <stdio.h> |
|
13 |
#include <stdlib.h> |
|
14 |
||
15 |
#ifndef __SYMBIAN32__ |
|
16 |
#include <dbus/dbus-internals.h> |
|
17 |
#include <dbus/dbus-connection-internal.h> |
|
18 |
#else |
|
19 |
#include "dbus-internals.h" |
|
20 |
#include "dbus-connection-internal.h" |
|
21 |
#endif //__SYMBIAN32__ |
|
22 |
||
23 |
#define LOG_FILE "c:\\logs\\test-threads-init_log1.txt" |
|
24 |
#include "std_log_result.h" |
|
25 |
#define LOG_FILENAME_LINE __FILE__, __LINE__ |
|
26 |
||
27 |
void create_xml(int result) |
|
28 |
{ |
|
29 |
if(result) |
|
30 |
assert_failed = 1; |
|
31 |
||
32 |
testResultXml("test-threads-init"); |
|
33 |
close_log_file(); |
|
34 |
} |
|
35 |
||
36 |
static void |
|
37 |
_run_iteration (DBusConnection *conn) |
|
38 |
{ |
|
39 |
DBusPendingCall *echo_pending; |
|
40 |
DBusPendingCall *dbus_pending; |
|
41 |
DBusMessage *method; |
|
42 |
DBusMessage *reply; |
|
43 |
char *echo = "echo"; |
|
44 |
||
45 |
/* send the first message */ |
|
46 |
method = dbus_message_new_method_call ("org.freedesktop.DBus.TestSuiteEchoService", |
|
47 |
"/org/freedesktop/TestSuite", |
|
48 |
"org.freedesktop.TestSuite", |
|
49 |
"Echo"); |
|
50 |
||
51 |
dbus_message_append_args (method, DBUS_TYPE_STRING, &echo, NULL); |
|
52 |
dbus_connection_send_with_reply (conn, method, &echo_pending, -1); |
|
53 |
dbus_message_unref (method); |
|
54 |
||
55 |
/* send the second message */ |
|
56 |
method = dbus_message_new_method_call (DBUS_SERVICE_DBUS, |
|
57 |
DBUS_PATH_DBUS, |
|
58 |
"org.freedesktop.Introspectable", |
|
59 |
"Introspect"); |
|
60 |
||
61 |
dbus_connection_send_with_reply (conn, method, &dbus_pending, -1); |
|
62 |
dbus_message_unref (method); |
|
63 |
||
64 |
/* block on the second message (should return immediately) */ |
|
65 |
dbus_pending_call_block (dbus_pending); |
|
66 |
||
67 |
/* block on the first message */ |
|
68 |
/* if it does not return immediately chances |
|
69 |
are we hit the block in poll bug */ |
|
70 |
dbus_pending_call_block (echo_pending); |
|
71 |
||
72 |
/* check the reply only to make sure we |
|
73 |
are not getting errors unrelated |
|
74 |
to the block in poll bug */ |
|
75 |
reply = dbus_pending_call_steal_reply (echo_pending); |
|
76 |
||
77 |
if (reply == NULL) |
|
78 |
{ |
|
79 |
printf ("Failed: Reply is NULL ***\n"); |
|
80 |
std_log(LOG_FILENAME_LINE, "Failed: Reply is NULL ***\n"); |
|
81 |
create_xml(1); |
|
82 |
exit (1); |
|
83 |
} |
|
84 |
||
85 |
if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) |
|
86 |
{ |
|
87 |
printf ("Failed: Reply is error: %s ***\n", dbus_message_get_error_name (reply)); |
|
88 |
std_log(LOG_FILENAME_LINE, "Failed: Reply is error: %s ***\n", dbus_message_get_error_name (reply)); |
|
89 |
create_xml(1); |
|
90 |
exit (1); |
|
91 |
} |
|
92 |
||
93 |
dbus_message_unref (reply); |
|
94 |
dbus_pending_call_unref (dbus_pending); |
|
95 |
dbus_pending_call_unref (echo_pending); |
|
96 |
||
97 |
} |
|
98 |
static void |
|
99 |
check_mutex_lock (DBusMutex *mutex1, |
|
100 |
DBusMutex *mutex2, |
|
101 |
dbus_bool_t is_same) |
|
102 |
{ |
|
103 |
_dbus_assert (mutex1 != NULL); |
|
104 |
_dbus_assert (mutex2 != NULL); |
|
105 |
||
106 |
if (is_same) |
|
107 |
{ |
|
108 |
_dbus_assert (mutex1 == mutex2); |
|
109 |
} |
|
110 |
else |
|
111 |
{ |
|
112 |
_dbus_assert (mutex1 != mutex2); |
|
113 |
} |
|
114 |
} |
|
115 |
||
116 |
static void |
|
117 |
check_condvar_lock (DBusCondVar *condvar1, |
|
118 |
DBusCondVar *condvar2, |
|
119 |
dbus_bool_t is_same) |
|
120 |
{ |
|
121 |
_dbus_assert (condvar1 != NULL); |
|
122 |
_dbus_assert (condvar2 != NULL); |
|
123 |
||
124 |
if (is_same) |
|
125 |
{ |
|
126 |
_dbus_assert (condvar1 == condvar2); |
|
127 |
} |
|
128 |
else |
|
129 |
{ |
|
130 |
_dbus_assert (condvar1 != condvar2); |
|
131 |
} |
|
132 |
} |
|
133 |
||
134 |
||
135 |
int |
|
136 |
main () |
|
137 |
{ |
|
138 |
DBusMessage *method; |
|
139 |
DBusConnection *conn; |
|
140 |
DBusError error; |
|
141 |
DBusMutex *mutex1, *dispatch_mutex1, *io_path_mutex1; |
|
142 |
DBusCondVar *dispatch_cond1, *io_path_cond1; |
|
143 |
DBusMutex *mutex2, *dispatch_mutex2, *io_path_mutex2; |
|
144 |
DBusCondVar *dispatch_cond2, *io_path_cond2; |
|
145 |
||
146 |
printf ("*** Testing late thread init\n"); |
|
147 |
std_log(LOG_FILENAME_LINE, "*** Testing late thread init\n"); |
|
148 |
||
149 |
dbus_error_init (&error); |
|
150 |
||
151 |
conn = dbus_bus_get (DBUS_BUS_SESSION, &error); |
|
152 |
||
153 |
_dbus_connection_test_get_locks (conn, &mutex1, |
|
154 |
&dispatch_mutex1, |
|
155 |
&io_path_mutex1, |
|
156 |
&dispatch_cond1, |
|
157 |
&io_path_cond1); |
|
158 |
_run_iteration (conn); |
|
159 |
_dbus_connection_test_get_locks (conn, &mutex2, |
|
160 |
&dispatch_mutex2, |
|
161 |
&io_path_mutex2, |
|
162 |
&dispatch_cond2, |
|
163 |
&io_path_cond2); |
|
164 |
||
165 |
check_mutex_lock (mutex1, mutex2, TRUE); |
|
166 |
check_mutex_lock (dispatch_mutex1, dispatch_mutex2, TRUE); |
|
167 |
check_mutex_lock (io_path_mutex1, io_path_mutex2, TRUE); |
|
168 |
check_condvar_lock (dispatch_cond1, dispatch_cond2, TRUE); |
|
169 |
check_condvar_lock (io_path_cond1, io_path_cond2, TRUE); |
|
170 |
||
171 |
dbus_threads_init_default (); |
|
172 |
||
173 |
_dbus_connection_test_get_locks (conn, &mutex1, |
|
174 |
&dispatch_mutex1, |
|
175 |
&io_path_mutex1, |
|
176 |
&dispatch_cond1, |
|
177 |
&io_path_cond1); |
|
178 |
||
179 |
check_mutex_lock (mutex1, mutex2, FALSE); |
|
180 |
check_mutex_lock (dispatch_mutex1, dispatch_mutex2, FALSE); |
|
181 |
check_mutex_lock (io_path_mutex1, io_path_mutex2, FALSE); |
|
182 |
check_condvar_lock (dispatch_cond1, dispatch_cond2, FALSE); |
|
183 |
check_condvar_lock (io_path_cond1, io_path_cond2, FALSE); |
|
184 |
||
185 |
_run_iteration (conn); |
|
186 |
_dbus_connection_test_get_locks (conn, &mutex2, |
|
187 |
&dispatch_mutex2, |
|
188 |
&io_path_mutex2, |
|
189 |
&dispatch_cond2, |
|
190 |
&io_path_cond2); |
|
191 |
||
192 |
check_mutex_lock (mutex1, mutex2, TRUE); |
|
193 |
check_mutex_lock (dispatch_mutex1, dispatch_mutex2, TRUE); |
|
194 |
check_mutex_lock (io_path_mutex1, io_path_mutex2, TRUE); |
|
195 |
check_condvar_lock (dispatch_cond1, dispatch_cond2, TRUE); |
|
196 |
check_condvar_lock (io_path_cond1, io_path_cond2, TRUE); |
|
197 |
||
198 |
method = dbus_message_new_method_call ("org.freedesktop.TestSuiteEchoService", |
|
199 |
"/org/freedesktop/TestSuite", |
|
200 |
"org.freedesktop.TestSuite", |
|
201 |
"Exit"); |
|
202 |
dbus_connection_send (conn, method, NULL); |
|
203 |
dbus_message_unref (method); |
|
204 |
||
205 |
printf ("Success ***\n"); |
|
206 |
std_log(LOG_FILENAME_LINE, "Success ***\n"); |
|
207 |
// ch=getchar(); |
|
208 |
create_xml(0); |
|
209 |
exit (0); |
|
210 |
} |