Merge lp:~ted/dbus-test-runner/dbusmock-system-bus into lp:dbus-test-runner/15.04

Proposed by Ted Gould
Status: Merged
Approved by: Ted Gould
Approved revision: 95
Merged at revision: 90
Proposed branch: lp:~ted/dbus-test-runner/dbusmock-system-bus
Merge into: lp:dbus-test-runner/15.04
Diff against target: 339 lines (+143/-33)
6 files modified
debian/libdbustest1.symbols (+1/-0)
libdbustest/dbus-mock.c (+40/-25)
libdbustest/task.c (+17/-2)
libdbustest/task.h (+1/-0)
tests/Makefile.am (+6/-0)
tests/test-libdbustest-mock.c (+78/-6)
To merge this branch: bzr merge lp:~ted/dbus-test-runner/dbusmock-system-bus
Reviewer Review Type Date Requested Status
Charles Kerr (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+248072@code.launchpad.net

Commit message

Make watching the task use the same bus the task is on

Description of the change

While we added the ability for tasks to show up on other busses, we didn't update the watchers of those tasks to be aware of them being on other busses and so therefore the watchers were left behind and lonely. Nobody wants lonely watchers. Participate! Set down that video camera!

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
94. By Ted Gould

Add a test that tests waiting on system services

95. By Ted Gould

Check running the mock on the system bus

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Charles Kerr (charlesk) wrote :

LGTM

review: Approve
96. By Ted Gould

This seems to fail on PPC occationally, curious if it's the fact that we're using the parameter which could be optimized oddly on different platforms. Going for a global.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/libdbustest1.symbols'
2--- debian/libdbustest1.symbols 2014-12-09 22:32:29 +0000
3+++ debian/libdbustest1.symbols 2015-02-02 15:53:09 +0000
4@@ -44,6 +44,7 @@
5 dbus_test_task_set_return@Base 15.04.0+15.04.20141209
6 dbus_test_task_set_wait_finished@Base 15.04.0+15.04.20141209
7 dbus_test_task_set_wait_for@Base 15.04.0+15.04.20141209
8+ dbus_test_task_set_wait_for_bus@Base 0replaceme
9 dbus_test_watchdog_add_pid@Base 15.04.0+15.04.20141209
10 dbus_test_watchdog_get_type@Base 15.04.0+15.04.20141209
11 dbus_test_watchdog_ping@Base 15.04.0+15.04.20141209
12
13=== modified file 'libdbustest/dbus-mock.c'
14--- libdbustest/dbus-mock.c 2014-11-06 17:33:48 +0000
15+++ libdbustest/dbus-mock.c 2015-02-02 15:53:09 +0000
16@@ -145,9 +145,6 @@
17 static void
18 constructed (GObject * object)
19 {
20- DbusTestDbusMock * self = DBUS_TEST_DBUS_MOCK(object);
21- const gchar * paramval = NULL;
22-
23 if (mock_cnt == 0) {
24 dbus_test_task_set_name(DBUS_TEST_TASK(object), "DBusMock");
25 } else {
26@@ -157,27 +154,6 @@
27 }
28 mock_cnt++;
29
30- /* Execute: python3 -m dbusmock $name / com.canonical.DbusTest.DbusMock */
31- g_object_set(object, "executable", "python3", NULL);
32-
33- GArray * params = g_array_new(TRUE, TRUE, sizeof(gchar *));
34- /* NOTE: No free func, none of the memory is managed by the array */
35-
36- paramval = "-m"; g_array_append_val(params, paramval);
37- paramval = "dbusmock"; g_array_append_val(params, paramval);
38-
39- /* If we're set for system, go there, otherwise default to session */
40- if (dbus_test_task_get_bus(DBUS_TEST_TASK(self)) == DBUS_TEST_SERVICE_BUS_SYSTEM) {
41- paramval = "-s"; g_array_append_val(params, paramval);
42- }
43-
44- g_array_append_val(params, self->priv->name);
45- paramval = "/"; g_array_append_val(params, paramval);
46- paramval = "com.canonical.DbusTest.DbusMock"; g_array_append_val(params, paramval);
47-
48- g_object_set(object, "parameters", params, NULL);
49- g_array_unref(params);
50-
51 return;
52 }
53
54@@ -446,6 +422,34 @@
55 return;
56 }
57
58+/* Configure the executable and parameters for the mock */
59+static void
60+configure_process (DbusTestDbusMock * self)
61+{
62+ const gchar * paramval = NULL;
63+
64+ /* Execute: python3 -m dbusmock $name / com.canonical.DbusTest.DbusMock */
65+ g_object_set(G_OBJECT(self), "executable", "python3", NULL);
66+
67+ GArray * params = g_array_new(TRUE, TRUE, sizeof(gchar *));
68+ /* NOTE: No free func, none of the memory is managed by the array */
69+
70+ paramval = "-m"; g_array_append_val(params, paramval);
71+ paramval = "dbusmock"; g_array_append_val(params, paramval);
72+
73+ /* If we're set for system, go there, otherwise default to session */
74+ if (dbus_test_task_get_bus(DBUS_TEST_TASK(self)) == DBUS_TEST_SERVICE_BUS_SYSTEM) {
75+ paramval = "--system"; g_array_append_val(params, paramval);
76+ }
77+
78+ g_array_append_val(params, self->priv->name);
79+ paramval = "/"; g_array_append_val(params, paramval);
80+ paramval = "com.canonical.DbusTest.DbusMock"; g_array_append_val(params, paramval);
81+
82+ g_object_set(G_OBJECT(self), "parameters", params, NULL);
83+ g_array_unref(params);
84+}
85+
86 /* Run the mock */
87 static void
88 run (DbusTestTask * task)
89@@ -454,9 +458,20 @@
90 DbusTestDbusMock * self = DBUS_TEST_DBUS_MOCK(task);
91
92 /* Grab the new bus */
93- self->priv->bus = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL);
94+ if (dbus_test_task_get_bus(DBUS_TEST_TASK(self)) == DBUS_TEST_SERVICE_BUS_SYSTEM) {
95+ self->priv->bus = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
96+ } else {
97+ self->priv->bus = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
98+ }
99+
100+ if (error != NULL) {
101+ g_warning("Unable to get bus to start DBus Mock: %s", error->message);
102+ g_error_free(error);
103+ return;
104+ }
105
106 /* Use the process code to get the process running */
107+ configure_process(self);
108 DBUS_TEST_TASK_CLASS (dbus_test_dbus_mock_parent_class)->run (task);
109
110 /**** Initialize the DBus Mock instance ****/
111
112=== modified file 'libdbustest/task.c'
113--- libdbustest/task.c 2014-11-17 18:24:33 +0000
114+++ libdbustest/task.c 2015-02-02 15:53:09 +0000
115@@ -28,6 +28,7 @@
116 DbusTestTaskReturn return_type;
117
118 gchar * wait_for;
119+ DbusTestServiceBus wait_for_bus;
120 guint wait_task;
121
122 gchar * name;
123@@ -93,6 +94,7 @@
124 self->priv->return_type = DBUS_TEST_TASK_RETURN_NORMAL;
125
126 self->priv->wait_for = NULL;
127+ self->priv->wait_for_bus = DBUS_TEST_SERVICE_BUS_BOTH;
128 self->priv->wait_task = 0;
129
130 self->priv->name = g_strdup_printf("task-%d", task_count++);
131@@ -187,15 +189,21 @@
132
133 return;
134 }
135-
136 void
137 dbus_test_task_set_wait_for (DbusTestTask * task, const gchar * dbus_name)
138 {
139+ return dbus_test_task_set_wait_for_bus(task, dbus_name, DBUS_TEST_SERVICE_BUS_BOTH);
140+}
141+
142+void
143+dbus_test_task_set_wait_for_bus (DbusTestTask * task, const gchar * dbus_name, DbusTestServiceBus bus)
144+{
145 g_return_if_fail(DBUS_TEST_IS_TASK(task));
146
147 if (task->priv->wait_for != NULL) {
148 g_free(task->priv->wait_for);
149 task->priv->wait_for = NULL;
150+ task->priv->wait_for_bus = DBUS_TEST_SERVICE_BUS_BOTH;
151 }
152
153 if (dbus_name == NULL) {
154@@ -203,6 +211,7 @@
155 }
156
157 task->priv->wait_for = g_strdup(dbus_name);
158+ task->priv->wait_for_bus = bus;
159
160 return;
161 }
162@@ -293,7 +302,13 @@
163 /* We're going to process the waiting at this level if we've been
164 asked to do so */
165 if (task->priv->wait_for != NULL) {
166- task->priv->wait_task = g_bus_watch_name(G_BUS_TYPE_SESSION,
167+ GBusType bustype = G_BUS_TYPE_SESSION;
168+ if (task->priv->wait_for_bus == DBUS_TEST_SERVICE_BUS_BOTH &&
169+ task->priv->preferred_bus == DBUS_TEST_SERVICE_BUS_SYSTEM) {
170+ bustype = G_BUS_TYPE_SYSTEM;
171+ }
172+
173+ task->priv->wait_task = g_bus_watch_name(bustype,
174 task->priv->wait_for,
175 G_BUS_NAME_WATCHER_FLAGS_NONE,
176 wait_for_found,
177
178=== modified file 'libdbustest/task.h'
179--- libdbustest/task.h 2014-11-06 17:28:07 +0000
180+++ libdbustest/task.h 2015-02-02 15:53:09 +0000
181@@ -82,6 +82,7 @@
182 void dbus_test_task_set_name (DbusTestTask * task, const gchar * name);
183 void dbus_test_task_set_name_spacing (DbusTestTask * task, glong chars);
184 void dbus_test_task_set_wait_for (DbusTestTask * task, const gchar * dbus_name);
185+void dbus_test_task_set_wait_for_bus (DbusTestTask * task, const gchar * dbus_name, DbusTestServiceBus bus);
186 void dbus_test_task_set_return (DbusTestTask * task, DbusTestTaskReturn ret);
187 void dbus_test_task_set_wait_finished (DbusTestTask * task, gboolean wait_till_complete);
188 void dbus_test_task_set_bus (DbusTestTask * task, DbusTestServiceBus bus);
189
190=== modified file 'tests/Makefile.am'
191--- tests/Makefile.am 2014-11-17 20:55:44 +0000
192+++ tests/Makefile.am 2015-02-02 15:53:09 +0000
193@@ -120,6 +120,12 @@
194 @chmod +x $@
195 XFAIL_TESTS += test-param-only-wait
196
197+TESTS += test-param-wait-system
198+test-param-wait-system: Makefile.am
199+ @echo "#!/bin/sh" > $@
200+ @echo $(DBUS_RUNNER) --bus-type=system --task ls --task-bus=system --wait-for org.test.test --task gdbus --parameter call --parameter --system --parameter --dest --parameter org.freedesktop.DBus --parameter --object-path --parameter / --parameter --method --parameter org.freedesktop.DBus.RequestName --parameter org.test.test --parameter 0 --task-bus=system >> $@
201+ @chmod +x $@
202+
203 TESTS += test-param-multi-wait
204 test-param-multi-wait: Makefile.am
205 @echo "#!/bin/sh" > $@
206
207=== modified file 'tests/test-libdbustest-mock.c'
208--- tests/test-libdbustest-mock.c 2014-02-26 17:25:21 +0000
209+++ tests/test-libdbustest-mock.c 2015-02-02 15:53:09 +0000
210@@ -22,20 +22,22 @@
211 g_main_loop_unref (temploop);
212 }
213
214-#define SESSION_MAX_WAIT 10
215+#define SESSION_MAX_WAIT 100
216
217 /*
218 * Waiting until the session bus shuts down
219 */
220+GDBusConnection * wait_for_close_ptr = NULL;
221 static void
222 wait_for_connection_close (GDBusConnection *connection)
223 {
224- g_object_add_weak_pointer(G_OBJECT(connection), (gpointer) &connection);
225+ wait_for_close_ptr = connection;
226+ g_object_add_weak_pointer(G_OBJECT(connection), (gpointer) &wait_for_close_ptr);
227
228 g_object_unref (connection);
229
230 int wait_count;
231- for (wait_count = 0; connection != NULL && wait_count < SESSION_MAX_WAIT; wait_count++)
232+ for (wait_count = 0; wait_for_close_ptr != NULL && wait_count < SESSION_MAX_WAIT; wait_count++)
233 {
234 process_mainloop(200);
235 }
236@@ -61,6 +63,9 @@
237 DbusTestDbusMock * mock = dbus_test_dbus_mock_new("foo.test");
238 g_assert(mock != NULL);
239
240+ dbus_test_service_add_task(service, DBUS_TEST_TASK(mock));
241+ dbus_test_service_start_tasks(service);
242+
243 gchar * dbusname = NULL;
244 g_object_get(mock, "dbus-name", &dbusname, NULL);
245 g_assert(g_strcmp0(dbusname, "foo.test") == 0);
246@@ -71,9 +76,6 @@
247 g_assert(g_strcmp0(exec, "python3") == 0);
248 g_free(exec);
249
250- dbus_test_service_add_task(service, DBUS_TEST_TASK(mock));
251- dbus_test_service_start_tasks(service);
252-
253 g_assert(dbus_test_task_get_state(DBUS_TEST_TASK(mock)) == DBUS_TEST_TASK_STATE_RUNNING);
254
255 /* check setup */
256@@ -522,6 +524,75 @@
257 }
258
259 void
260+test_running_system (void)
261+{
262+ DbusTestService * service = dbus_test_service_new(NULL);
263+ g_assert(service != NULL);
264+ dbus_test_service_set_bus(service, DBUS_TEST_SERVICE_BUS_SYSTEM);
265+
266+ dbus_test_service_set_conf_file(service, SESSION_CONF);
267+
268+ DbusTestDbusMock * mock = dbus_test_dbus_mock_new("foo.test");
269+ g_assert(mock != NULL);
270+ dbus_test_task_set_bus(DBUS_TEST_TASK(mock), DBUS_TEST_SERVICE_BUS_SYSTEM);
271+
272+ /* Startup the mock */
273+ dbus_test_service_add_task(service, DBUS_TEST_TASK(mock));
274+ dbus_test_service_start_tasks(service);
275+
276+ GDBusConnection * bus = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, NULL);
277+ g_dbus_connection_set_exit_on_close(bus, FALSE);
278+
279+ /* Add the object */
280+ DbusTestDbusMockObject * obj = dbus_test_dbus_mock_get_object(mock, "/test", "foo.test.interface", NULL);
281+ g_assert(obj != NULL);
282+
283+ g_assert(dbus_test_dbus_mock_object_add_method(mock, obj,
284+ "method1",
285+ G_VARIANT_TYPE("s"),
286+ G_VARIANT_TYPE("s"),
287+ "ret = 'test'",
288+ NULL));
289+
290+ GVariant * propret = NULL;
291+ GVariant * testvar = NULL;
292+ GError * error = NULL;
293+
294+ /* Check method */
295+ propret = g_dbus_connection_call_sync(bus,
296+ "foo.test",
297+ "/test",
298+ "foo.test.interface",
299+ "method1",
300+ g_variant_new("(s)", "testin"),
301+ G_VARIANT_TYPE("(s)"),
302+ G_DBUS_CALL_FLAGS_NONE,
303+ -1,
304+ NULL,
305+ &error);
306+
307+ if (error != NULL) {
308+ g_error("Unable to call method1: %s", error->message);
309+ g_error_free(error);
310+ }
311+
312+ g_assert(propret != NULL);
313+ testvar = g_variant_new_string("test");
314+ testvar = g_variant_new_tuple(&testvar, 1);
315+ g_variant_ref_sink(testvar);
316+ g_assert(g_variant_equal(propret, testvar));
317+ g_variant_unref(testvar);
318+
319+ g_variant_unref(propret);
320+
321+ /* Clean up */
322+ g_object_unref(mock);
323+ g_object_unref(service);
324+
325+ wait_for_connection_close(bus);
326+}
327+
328+void
329 test_interfaces (void)
330 {
331 DbusTestService * service = dbus_test_service_new(NULL);
332@@ -637,6 +708,7 @@
333 g_test_add_func ("/libdbustest/mock/methods", test_methods);
334 g_test_add_func ("/libdbustest/mock/signals", test_signals);
335 g_test_add_func ("/libdbustest/mock/running", test_running);
336+ g_test_add_func ("/libdbustest/mock/running-system", test_running_system);
337 g_test_add_func ("/libdbustest/mock/interfaces", test_interfaces);
338
339 return;

Subscribers

People subscribed via source and target branches