Merge lp:~ted/dbus-test-runner/fix-coverage into lp:dbus-test-runner/0.1

Proposed by Ted Gould on 2011-12-10
Status: Merged
Merged at revision: 37
Proposed branch: lp:~ted/dbus-test-runner/fix-coverage
Merge into: lp:dbus-test-runner/0.1
Diff against target: 399 lines (+222/-24) 2 files modified
To merge this branch: bzr merge lp:~ted/dbus-test-runner/fix-coverage
Reviewer Review Type Date Requested Status
Neil J. Patel (community) 2011-12-10 Approve on 2011-12-13
Review via email: mp+85211@code.launchpad.net

Description of the Change

Provides more tests and some testability to dbus-test-runner. All motivated to increase the code coverage of the test suite.

To post a comment you must log in.
Neil J. Patel (njpatel) wrote :

Looks good, approved.

review: Approve

Preview Diff

1=== modified file 'src/dbus-test-runner.c'
2--- src/dbus-test-runner.c 2011-11-28 22:21:06 +0000
3+++ src/dbus-test-runner.c 2011-12-10 03:58:25 +0000
4@@ -49,13 +49,15 @@
5
6 static void check_task_cleanup (task_t * task, gboolean force);
7 static void start_task (gpointer data, gpointer userdata);
8+static void bustle_watcher (GPid pid, gint status, gpointer data);
9
10+static gchar * bustle_cmd = NULL;
11 static gchar * bustle_datafile = NULL;
12+static guint bustle_watch = 0;
13 static GIOChannel * bustle_stdout = NULL;
14 static GIOChannel * bustle_stderr = NULL;
15 static GIOChannel * bustle_file = NULL;
16 static GPid bustle_pid = 0;
17-static GList * bustle_watches = NULL;
18 static gboolean any_waitfors = FALSE;
19
20 #define BUSTLE_ERROR_DEFAULT "Bustle"
21@@ -127,29 +129,27 @@
22 bustle_file = g_io_channel_new_file(bustle_datafile, "w", &error);
23
24 if (error != NULL) {
25- g_warning("Unable to open bustle file '%s': %s", bustle_datafile, error->message);
26+ g_critical("Unable to open bustle file '%s': %s", bustle_datafile, error->message);
27 g_error_free(error);
28 g_free(bustle_datafile);
29 bustle_datafile = NULL;
30+ global_success = FALSE;
31+ g_main_loop_quit(global_mainloop);
32 return;
33 }
34
35 gint bustle_stdout_num;
36 gint bustle_stderr_num;
37
38- gchar ** bustle_monitor = g_new0(gchar *, g_list_length(bustle_watches) + 3);
39- bustle_monitor[0] = "bustle-dbus-monitor";
40+ gchar ** bustle_monitor = g_new0(gchar *, 3);
41+ bustle_monitor[0] = (gchar *)bustle_cmd;
42 bustle_monitor[1] = "--session";
43- int i;
44- for (i = 0; i < g_list_length(bustle_watches); i++) {
45- bustle_monitor[i + 2] = (gchar *)g_list_nth(bustle_watches, i)->data;
46- }
47
48 g_spawn_async_with_pipes(g_get_current_dir(),
49 bustle_monitor, /* argv */
50 NULL, /* envp */
51 /* G_SPAWN_SEARCH_PATH | G_SPAWN_STDERR_TO_DEV_NULL, */ /* flags */
52- G_SPAWN_SEARCH_PATH, /* flags */
53+ G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD, /* flags */
54 NULL, /* child setup func */
55 NULL, /* child setup data */
56 &bustle_pid, /* PID */
57@@ -159,11 +159,16 @@
58 &error); /* error */
59
60 if (error != NULL) {
61- g_warning("Unable to start bustling data: %s", error->message);
62+ g_critical("Unable to start bustling data: %s", error->message);
63+ g_error_free(error);
64+ bustle_pid = 0;
65+ global_success = FALSE;
66+ g_main_loop_quit(global_mainloop);
67 return;
68 }
69
70 g_debug("Starting bustle monitor. PID: %d", bustle_pid);
71+ bustle_watch = g_child_watch_add(bustle_pid, bustle_watcher, NULL);
72
73 bustle_stdout = g_io_channel_unix_new(bustle_stdout_num);
74 g_io_add_watch(bustle_stdout,
75@@ -187,6 +192,14 @@
76 return;
77 }
78
79+ if (bustle_watch != 0) {
80+ g_source_remove(bustle_watch);
81+ }
82+
83+ if (bustle_pid == 0) {
84+ return;
85+ }
86+
87 gchar * killline = g_strdup_printf("kill -INT %d", bustle_pid);
88 g_spawn_command_line_sync(killline, NULL, NULL, NULL, NULL);
89 g_free(killline);
90@@ -281,6 +294,36 @@
91 }
92
93 static void
94+dbus_watcher (GPid pid, gint status, gpointer data)
95+{
96+ g_critical("DBus Daemon exited abruptly!");
97+
98+ global_success = FALSE;
99+ g_main_loop_quit(global_mainloop);
100+
101+ if (pid != 0) {
102+ g_spawn_close_pid(pid);
103+ }
104+
105+ return;
106+}
107+
108+static void
109+bustle_watcher (GPid pid, gint status, gpointer data)
110+{
111+ g_critical("Bustle Monitor exited abruptly!");
112+
113+ global_success = FALSE;
114+ g_main_loop_quit(global_mainloop);
115+
116+ if (pid != 0) {
117+ g_spawn_close_pid(pid);
118+ }
119+
120+ return;
121+}
122+
123+static void
124 proc_watcher (GPid pid, gint status, gpointer data)
125 {
126 task_t * task = (task_t *)data;
127@@ -404,7 +447,7 @@
128 dbus_writes (GIOChannel * channel, GIOCondition condition, gpointer data)
129 {
130 if (condition & G_IO_ERR) {
131- g_error("DBus writing failure!");
132+ g_critical("DBus writing failure!");
133 return FALSE;
134 }
135
136@@ -427,9 +470,14 @@
137 if (tasks != NULL) {
138 start_bustling();
139
140- g_list_foreach(tasks, start_task, GINT_TO_POINTER(FALSE));
141+ /* If we're still in a place where we can succeed, then
142+ we should continue. Otherwise fail. */
143+ if (global_success) {
144+ g_list_foreach(tasks, start_task, GINT_TO_POINTER(FALSE));
145+ }
146 } else {
147 g_print("No tasks!\n");
148+ global_success = FALSE;
149 g_main_loop_quit(global_mainloop);
150 }
151 }
152@@ -540,13 +588,6 @@
153 return TRUE;
154 }
155
156-static gboolean
157-bustle_watch (const gchar * arg, const gchar * value, gpointer data, GError ** error)
158-{
159- bustle_watches = g_list_append(bustle_watches, g_strdup(value));
160- return TRUE;
161-}
162-
163 static void
164 length_finder (gpointer data, gpointer udata)
165 {
166@@ -636,11 +677,13 @@
167 }
168
169 static gchar * dbus_configfile = NULL;
170+static gchar * dbus_daemon = NULL;
171
172 static GOptionEntry general_options[] = {
173+ {"dbus-daemon", 0, 0, G_OPTION_ARG_FILENAME, &dbus_daemon, "Path to the DBus deamon to use. Defaults to 'dbus-daemon'.", "executable"},
174 {"dbus-config", 'd', 0, G_OPTION_ARG_FILENAME, &dbus_configfile, "Configuration file for newly created DBus server. Defaults to '" DEFAULT_SESSION_CONF "'.", "config_file"},
175+ {"bustle-monitor", 0, 0, G_OPTION_ARG_FILENAME, &bustle_cmd, "Path to the Bustle DBus Monitor to use. Defaults to 'bustle-dbus-monitor'.", "executable"},
176 {"bustle-data", 'b', 0, G_OPTION_ARG_FILENAME, &bustle_datafile, "A file to write out data from the bustle logger to.", "data_file"},
177- {"bustle-watch", 'w', 0, G_OPTION_ARG_CALLBACK, bustle_watch, "Defines a watch string for the bustle watcher task. (broken)", "filter"},
178 {"max-wait", 'm', 0, G_OPTION_ARG_INT, &max_wait, "The maximum amount of time the test runner will wait for the test to complete. Default is 30 seconds.", "seconds"},
179 {NULL}
180 };
181@@ -683,21 +726,36 @@
182 dbus_configfile = DEFAULT_SESSION_CONF;
183 }
184
185+ if (dbus_daemon == NULL) {
186+ dbus_daemon = "dbus-daemon";
187+ }
188+
189+ if (bustle_cmd == NULL) {
190+ bustle_cmd = "bustle-dbus-monitor";
191+ }
192+
193 gint dbus_stdout;
194 GPid dbus;
195 gchar * blank[1] = {NULL};
196- gchar * dbus_startup[] = {"dbus-daemon", "--config-file", dbus_configfile, "--print-address", NULL};
197+ gchar * dbus_startup[] = {dbus_daemon, "--config-file", dbus_configfile, "--print-address", NULL};
198 g_spawn_async_with_pipes(g_get_current_dir(),
199 dbus_startup, /* argv */
200 blank, /* envp */
201- G_SPAWN_SEARCH_PATH, /* flags */
202+ G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD, /* flags */
203 NULL, /* child setup func */
204 NULL, /* child setup data */
205 &dbus, /* PID */
206 NULL, /* stdin */
207 &dbus_stdout, /* stdout */
208 NULL, /* stderr */
209- NULL); /* error */
210+ &error); /* error */
211+
212+ if (error != NULL) {
213+ g_critical("Unable to start dbus daemon: %s", error->message);
214+ return 1;
215+ }
216+
217+ guint dbus_watch = g_child_watch_add(dbus, dbus_watcher, NULL);
218
219 GIOChannel * dbus_io = g_io_channel_unix_new(dbus_stdout);
220 g_io_add_watch(dbus_io,
221@@ -714,6 +772,7 @@
222
223 stop_bustling();
224
225+ g_source_remove(dbus_watch); /* Let's not error when we want to kill it */
226 gchar * killline = g_strdup_printf("kill -9 %d", dbus);
227 g_spawn_command_line_sync(killline, NULL, NULL, NULL, NULL);
228 g_free(killline);
229
230=== modified file 'tests/Makefile.am'
231--- tests/Makefile.am 2011-11-28 22:21:06 +0000
232+++ tests/Makefile.am 2011-12-10 03:58:25 +0000
233@@ -1,5 +1,5 @@
234
235-DBUS_RUNNER=../src/dbus-test-runner --dbus-config $(srcdir)/../data/session.conf
236+DBUS_RUNNER=$(top_builddir)/src/dbus-test-runner --dbus-config $(srcdir)/../data/session.conf
237 TESTS =
238 DISTCLEANFILES = $(TESTS)
239 XFAIL_TESTS =
240@@ -57,6 +57,96 @@
241 @chmod +x $@
242 XFAIL_TESTS += test-timeout
243
244+TESTS += test-timeout-disable
245+test-timeout-disable: Makefile.am
246+ @echo "#!/bin/sh" > $@
247+ @echo $(DBUS_RUNNER) --max-wait 0 --task true >> $@
248+ @chmod +x $@
249+
250+TESTS += test-param-only-name
251+test-param-only-name: Makefile.am
252+ @echo "#!/bin/sh" > $@
253+ @echo $(DBUS_RUNNER) --task-name Name >> $@
254+ @chmod +x $@
255+XFAIL_TESTS += test-param-only-name
256+
257+TESTS += test-param-dup-name
258+test-param-dup-name: Makefile.am
259+ @echo "#!/bin/sh" > $@
260+ @echo $(DBUS_RUNNER) --task true --task-name Name --task-name Name2 >> $@
261+ @chmod +x $@
262+XFAIL_TESTS += test-param-dup-name
263+
264+TESTS += test-param-only-ignore
265+test-param-only-ignore: Makefile.am
266+ @echo "#!/bin/sh" > $@
267+ @echo $(DBUS_RUNNER) --ignore-return >> $@
268+ @chmod +x $@
269+XFAIL_TESTS += test-param-only-ignore
270+
271+TESTS += test-param-only-invert
272+test-param-only-invert: Makefile.am
273+ @echo "#!/bin/sh" > $@
274+ @echo $(DBUS_RUNNER) --invert-return >> $@
275+ @chmod +x $@
276+XFAIL_TESTS += test-param-only-invert
277+
278+TESTS += test-param-multi-return-invert
279+test-param-multi-return-invert: Makefile.am
280+ @echo "#!/bin/sh" > $@
281+ @echo $(DBUS_RUNNER) --task true --ignore-return --invert-return >> $@
282+ @chmod +x $@
283+XFAIL_TESTS += test-param-multi-return-invert
284+
285+TESTS += test-param-multi-return-ignore
286+test-param-multi-return-ignore: Makefile.am
287+ @echo "#!/bin/sh" > $@
288+ @echo $(DBUS_RUNNER) --task true --invert-return --ignore-return >> $@
289+ @chmod +x $@
290+XFAIL_TESTS += test-param-multi-return-ignore
291+
292+TESTS += test-param-only-param
293+test-param-only-param: Makefile.am
294+ @echo "#!/bin/sh" > $@
295+ @echo $(DBUS_RUNNER) --parameter bob >> $@
296+ @chmod +x $@
297+XFAIL_TESTS += test-param-only-param
298+
299+TESTS += test-param-only-wait
300+test-param-only-wait: Makefile.am
301+ @echo "#!/bin/sh" > $@
302+ @echo $(DBUS_RUNNER) --wait-for org.test.test >> $@
303+ @chmod +x $@
304+XFAIL_TESTS += test-param-only-wait
305+
306+TESTS += test-param-multi-wait
307+test-param-multi-wait: Makefile.am
308+ @echo "#!/bin/sh" > $@
309+ @echo $(DBUS_RUNNER) --task true --wait-for org.test.test --wait-for org.test.test2 >> $@
310+ @chmod +x $@
311+XFAIL_TESTS += test-param-multi-wait
312+
313+TESTS += test-param-bad
314+test-param-bad: Makefile.am
315+ @echo "#!/bin/sh" > $@
316+ @echo $(DBUS_RUNNER) --this-is-most-surly-not-a-real-parameter >> $@
317+ @chmod +x $@
318+XFAIL_TESTS += test-param-bad
319+
320+TESTS += test-param-bad-task
321+test-param-bad-task: Makefile.am
322+ @echo "#!/bin/sh" > $@
323+ @echo $(DBUS_RUNNER) --task this-is-most-surly-not-a-real-program >> $@
324+ @chmod +x $@
325+XFAIL_TESTS += test-param-bad-task
326+
327+TESTS += test-no-tasks
328+test-no-tasks: Makefile.am
329+ @echo "#!/bin/sh" > $@
330+ @echo $(DBUS_RUNNER) >> $@
331+ @chmod +x $@
332+XFAIL_TESTS += test-no-tasks
333+
334 TESTS += test-output
335 test-output: Makefile.am
336 @echo "#!/bin/sh -e" > $@
337@@ -85,6 +175,29 @@
338 @chmod +x $@
339 DISTCLEANFILES += test-bustle.bustle test-bustle.filtered
340
341+TESTS += test-bustle-bad-file
342+test-bustle-bad-file: Makefile.am
343+ @echo "#!/bin/sh -e" > $@
344+ @echo $(DBUS_RUNNER) --bustle-data \"$(builddir)\" --task true >> $@
345+ @chmod +x $@
346+XFAIL_TESTS += test-bustle-bad-file
347+
348+TESTS += test-bustle-bad-monitor
349+test-bustle-bad-monitor: Makefile.am
350+ @echo "#!/bin/sh -e" > $@
351+ @echo $(DBUS_RUNNER) --bustle-monitor probably-doesnt-exist --bustle-data \"$(builddir)/test-bustle-bad-monitor.bustle\" --task true >> $@
352+ @chmod +x $@
353+XFAIL_TESTS += test-bustle-bad-monitor
354+DISTCLEANFILES += test-bustle-bad-monitor.bustle
355+
356+TESTS += test-bustle-bad-monitor-error
357+test-bustle-bad-monitor-error: Makefile.am
358+ @echo "#!/bin/sh -e" > $@
359+ @echo $(DBUS_RUNNER) --bustle-monitor sleep --bustle-data \"$(builddir)/test-bustle-bad-monitor-error.bustle\" --task true >> $@
360+ @chmod +x $@
361+XFAIL_TESTS += test-bustle-bad-monitor-error
362+DISTCLEANFILES += test-bustle-bad-monitor-error.bustle
363+
364 TESTS += test-bustle-data
365 test-bustle-data: Makefile.am
366 @echo "#!/bin/sh -e" > $@
367@@ -126,6 +239,32 @@
368 @echo $(DBUS_RUNNER) --task $(builddir)/test-check-name --parameter org.test.name --wait-for org.test.name --task $(builddir)/test-own-name --parameter org.test.name --ignore-return >> $@
369 @chmod +x $@
370
371+TESTS += test-daemon-bad
372+test-daemon-bad: Makefile.am
373+ @echo "#!/bin/sh" > $@
374+ @echo $(DBUS_RUNNER) --dbus-daemon false --task true >> $@
375+ @chmod +x $@
376+XFAIL_TESTS += test-daemon-bad
377+
378+TESTS += test-daemon-missing
379+test-daemon-missing: Makefile.am
380+ @echo "#!/bin/sh" > $@
381+ @echo $(DBUS_RUNNER) --dbus-daemon probably-doesnt-exist --task true >> $@
382+ @chmod +x $@
383+XFAIL_TESTS += test-daemon-missing
384+
385+TESTS += test-daemon-junk
386+test-daemon-junk: Makefile.am test-daemon-junk-spitter
387+ @echo "#!/bin/sh" > $@
388+ @echo $(DBUS_RUNNER) --dbus-daemon $(builddir)/test-daemon-junk-spitter --task true >> $@
389+ @chmod +x $@
390+test-daemon-junk-spitter: Makefile.am
391+ @echo "#!/bin/sh" > $@
392+ @echo cat $(top_builddir)/src/dbus-test-runner >> $@
393+ @chmod +x $@
394+XFAIL_TESTS += test-daemon-junk
395+DISTCLEANFILES += test-daemon-junk-spitter
396+
397 EXTRA_DIST = \
398 delayrm.sh \
399 test-bustle.reference \

Subscribers

People subscribed via source and target branches