31
|
1 |
/*
|
|
2 |
* Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
/**
|
|
19 |
* Test to make sure we don't get stuck polling a dbus connection
|
|
20 |
* which has no data on the socket. This was an issue where
|
|
21 |
* one pending call would read all the data off the bus
|
|
22 |
* and the second pending call would not check to see
|
|
23 |
* if its data had already been read before polling the connection
|
|
24 |
* and blocking.
|
|
25 |
**/
|
|
26 |
|
|
27 |
#include <dbus/dbus.h>
|
|
28 |
#ifndef __SYMBIAN32__
|
|
29 |
#include <dbus/dbus-sysdeps.h>
|
|
30 |
#else
|
|
31 |
#include "dbus-sysdeps.h"
|
|
32 |
#endif //__SYMBIAN32__
|
|
33 |
#include <stdio.h>
|
|
34 |
#include <stdlib.h>
|
|
35 |
|
|
36 |
#define LOG_FILE "c:\\logs\\test_pending_call_dispatch_log1.txt"
|
|
37 |
#include "std_log_result.h"
|
|
38 |
#define LOG_FILENAME_LINE __FILE__, __LINE__
|
|
39 |
|
|
40 |
void create_xml(int result)
|
|
41 |
{
|
|
42 |
if(result)
|
|
43 |
assert_failed = 1;
|
|
44 |
|
|
45 |
testResultXml("test_pending_call_dispatch");
|
|
46 |
close_log_file();
|
|
47 |
}
|
|
48 |
|
|
49 |
|
|
50 |
static void
|
|
51 |
_run_iteration (DBusConnection *conn)
|
|
52 |
{
|
|
53 |
DBusPendingCall *echo_pending;
|
|
54 |
DBusPendingCall *dbus_pending;
|
|
55 |
DBusMessage *method;
|
|
56 |
DBusMessage *reply;
|
|
57 |
char *echo = "echo";
|
|
58 |
|
|
59 |
/* send the first message */
|
|
60 |
method = dbus_message_new_method_call ("org.freedesktop.DBus.TestSuiteEchoService",
|
|
61 |
"/org/freedesktop/TestSuite",
|
|
62 |
"org.freedesktop.TestSuite",
|
|
63 |
"Echo");
|
|
64 |
|
|
65 |
dbus_message_append_args (method, DBUS_TYPE_STRING, &echo, NULL);
|
|
66 |
dbus_connection_send_with_reply (conn, method, &echo_pending, -1);
|
|
67 |
dbus_message_unref (method);
|
|
68 |
|
|
69 |
/* send the second message */
|
|
70 |
method = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
|
|
71 |
DBUS_PATH_DBUS,
|
|
72 |
"org.freedesktop.Introspectable",
|
|
73 |
"Introspect");
|
|
74 |
|
|
75 |
dbus_connection_send_with_reply (conn, method, &dbus_pending, -1);
|
|
76 |
dbus_message_unref (method);
|
|
77 |
|
|
78 |
/* block on the second message (should return immediately) */
|
|
79 |
dbus_pending_call_block (dbus_pending);
|
|
80 |
|
|
81 |
/* block on the first message */
|
|
82 |
/* if it does not return immediately chances
|
|
83 |
are we hit the block in poll bug */
|
|
84 |
dbus_pending_call_block (echo_pending);
|
|
85 |
|
|
86 |
/* check the reply only to make sure we
|
|
87 |
are not getting errors unrelated
|
|
88 |
to the block in poll bug */
|
|
89 |
reply = dbus_pending_call_steal_reply (echo_pending);
|
|
90 |
|
|
91 |
if (reply == NULL)
|
|
92 |
{
|
|
93 |
printf ("Failed: Reply is NULL ***\n");
|
|
94 |
std_log(LOG_FILENAME_LINE, "Failed: Reply is NULL ***\n");
|
|
95 |
create_xml(1);
|
|
96 |
exit (1);
|
|
97 |
}
|
|
98 |
|
|
99 |
if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR)
|
|
100 |
{
|
|
101 |
printf ("Failed: Reply is error: %s ***\n", dbus_message_get_error_name (reply));
|
|
102 |
std_log(LOG_FILENAME_LINE, "Failed: Reply is error: %s ***\n", dbus_message_get_error_name (reply));
|
|
103 |
create_xml(1);
|
|
104 |
exit (1);
|
|
105 |
}
|
|
106 |
|
|
107 |
dbus_message_unref (reply);
|
|
108 |
dbus_pending_call_unref (dbus_pending);
|
|
109 |
dbus_pending_call_unref (echo_pending);
|
|
110 |
|
|
111 |
}
|
|
112 |
|
|
113 |
int
|
|
114 |
main ()
|
|
115 |
{
|
|
116 |
long start_tv_sec, start_tv_usec;
|
|
117 |
long end_tv_sec, end_tv_usec;
|
|
118 |
int i;
|
|
119 |
DBusMessage *method;
|
|
120 |
DBusConnection *conn;
|
|
121 |
DBusError error;
|
|
122 |
|
|
123 |
/* Time each iteration and make sure it doesn't take more than 5 seconds
|
|
124 |
to complete. Outside influences may cause connections to take longer
|
|
125 |
but if it does and we are stuck in a poll call then we know the
|
|
126 |
stuck in poll bug has come back to haunt us */
|
|
127 |
|
|
128 |
printf ("*** Testing stuck in poll\n");
|
|
129 |
std_log(LOG_FILENAME_LINE, "*** Testing stuck in poll\n");
|
|
130 |
|
|
131 |
dbus_error_init (&error);
|
|
132 |
|
|
133 |
conn = dbus_bus_get (DBUS_BUS_SESSION, &error);
|
|
134 |
|
|
135 |
/* run 100 times to make sure */
|
|
136 |
for (i = 0; i < 100; i++)
|
|
137 |
{
|
|
138 |
long delta;
|
|
139 |
|
|
140 |
_dbus_get_current_time (&start_tv_sec, &start_tv_usec);
|
|
141 |
_run_iteration (conn);
|
|
142 |
_dbus_get_current_time (&end_tv_sec, &end_tv_usec);
|
|
143 |
|
|
144 |
/* we just care about seconds */
|
|
145 |
delta = end_tv_sec - start_tv_sec;
|
|
146 |
printf ("Iter %i: %lis\n", i, delta);
|
|
147 |
std_log(LOG_FILENAME_LINE, "Iter %i: %lis\n", i, delta);
|
|
148 |
if (delta >= 5)
|
|
149 |
{
|
|
150 |
printf ("Failed: looks like we might have been be stuck in poll ***\n");
|
|
151 |
std_log(LOG_FILENAME_LINE, "Failed: looks like we might have been be stuck in poll ***\n");
|
|
152 |
create_xml(1);
|
|
153 |
exit (1);
|
|
154 |
}
|
|
155 |
}
|
|
156 |
|
|
157 |
method = dbus_message_new_method_call ("org.freedesktop.TestSuiteEchoService",
|
|
158 |
"/org/freedesktop/TestSuite",
|
|
159 |
"org.freedesktop.TestSuite",
|
|
160 |
"Exit");
|
|
161 |
dbus_connection_send (conn, method, NULL);
|
|
162 |
dbus_message_unref (method);
|
|
163 |
|
|
164 |
printf ("Success ***\n");
|
|
165 |
std_log(LOG_FILENAME_LINE, "Test Successful.");
|
|
166 |
// ch=getchar();
|
|
167 |
create_xml(0);
|
|
168 |
exit (0);
|
|
169 |
}
|