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

Proposed by Ted Gould
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
src/dbus-test-runner.c (+82/-23)
tests/Makefile.am (+140/-1)
To merge this branch: bzr merge lp:~ted/dbus-test-runner/fix-coverage
Reviewer Review Type Date Requested Status
Neil J. Patel (community) Approve
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.
Revision history for this message
Neil J. Patel (njpatel) wrote :

Looks good, approved.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/dbus-test-runner.c'
--- src/dbus-test-runner.c 2011-11-28 22:21:06 +0000
+++ src/dbus-test-runner.c 2011-12-10 03:58:25 +0000
@@ -49,13 +49,15 @@
4949
50static void check_task_cleanup (task_t * task, gboolean force);50static void check_task_cleanup (task_t * task, gboolean force);
51static void start_task (gpointer data, gpointer userdata);51static void start_task (gpointer data, gpointer userdata);
52static void bustle_watcher (GPid pid, gint status, gpointer data);
5253
54static gchar * bustle_cmd = NULL;
53static gchar * bustle_datafile = NULL;55static gchar * bustle_datafile = NULL;
56static guint bustle_watch = 0;
54static GIOChannel * bustle_stdout = NULL;57static GIOChannel * bustle_stdout = NULL;
55static GIOChannel * bustle_stderr = NULL;58static GIOChannel * bustle_stderr = NULL;
56static GIOChannel * bustle_file = NULL;59static GIOChannel * bustle_file = NULL;
57static GPid bustle_pid = 0;60static GPid bustle_pid = 0;
58static GList * bustle_watches = NULL;
59static gboolean any_waitfors = FALSE;61static gboolean any_waitfors = FALSE;
6062
61#define BUSTLE_ERROR_DEFAULT "Bustle"63#define BUSTLE_ERROR_DEFAULT "Bustle"
@@ -127,29 +129,27 @@
127 bustle_file = g_io_channel_new_file(bustle_datafile, "w", &error);129 bustle_file = g_io_channel_new_file(bustle_datafile, "w", &error);
128130
129 if (error != NULL) {131 if (error != NULL) {
130 g_warning("Unable to open bustle file '%s': %s", bustle_datafile, error->message);132 g_critical("Unable to open bustle file '%s': %s", bustle_datafile, error->message);
131 g_error_free(error);133 g_error_free(error);
132 g_free(bustle_datafile);134 g_free(bustle_datafile);
133 bustle_datafile = NULL;135 bustle_datafile = NULL;
136 global_success = FALSE;
137 g_main_loop_quit(global_mainloop);
134 return;138 return;
135 }139 }
136140
137 gint bustle_stdout_num;141 gint bustle_stdout_num;
138 gint bustle_stderr_num;142 gint bustle_stderr_num;
139 143
140 gchar ** bustle_monitor = g_new0(gchar *, g_list_length(bustle_watches) + 3);144 gchar ** bustle_monitor = g_new0(gchar *, 3);
141 bustle_monitor[0] = "bustle-dbus-monitor";145 bustle_monitor[0] = (gchar *)bustle_cmd;
142 bustle_monitor[1] = "--session";146 bustle_monitor[1] = "--session";
143 int i;
144 for (i = 0; i < g_list_length(bustle_watches); i++) {
145 bustle_monitor[i + 2] = (gchar *)g_list_nth(bustle_watches, i)->data;
146 }
147147
148 g_spawn_async_with_pipes(g_get_current_dir(),148 g_spawn_async_with_pipes(g_get_current_dir(),
149 bustle_monitor, /* argv */149 bustle_monitor, /* argv */
150 NULL, /* envp */150 NULL, /* envp */
151 /* G_SPAWN_SEARCH_PATH | G_SPAWN_STDERR_TO_DEV_NULL, */ /* flags */151 /* G_SPAWN_SEARCH_PATH | G_SPAWN_STDERR_TO_DEV_NULL, */ /* flags */
152 G_SPAWN_SEARCH_PATH, /* flags */152 G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD, /* flags */
153 NULL, /* child setup func */153 NULL, /* child setup func */
154 NULL, /* child setup data */154 NULL, /* child setup data */
155 &bustle_pid, /* PID */155 &bustle_pid, /* PID */
@@ -159,11 +159,16 @@
159 &error); /* error */159 &error); /* error */
160160
161 if (error != NULL) {161 if (error != NULL) {
162 g_warning("Unable to start bustling data: %s", error->message);162 g_critical("Unable to start bustling data: %s", error->message);
163 g_error_free(error);
164 bustle_pid = 0;
165 global_success = FALSE;
166 g_main_loop_quit(global_mainloop);
163 return;167 return;
164 }168 }
165169
166 g_debug("Starting bustle monitor. PID: %d", bustle_pid);170 g_debug("Starting bustle monitor. PID: %d", bustle_pid);
171 bustle_watch = g_child_watch_add(bustle_pid, bustle_watcher, NULL);
167172
168 bustle_stdout = g_io_channel_unix_new(bustle_stdout_num);173 bustle_stdout = g_io_channel_unix_new(bustle_stdout_num);
169 g_io_add_watch(bustle_stdout,174 g_io_add_watch(bustle_stdout,
@@ -187,6 +192,14 @@
187 return;192 return;
188 }193 }
189194
195 if (bustle_watch != 0) {
196 g_source_remove(bustle_watch);
197 }
198
199 if (bustle_pid == 0) {
200 return;
201 }
202
190 gchar * killline = g_strdup_printf("kill -INT %d", bustle_pid);203 gchar * killline = g_strdup_printf("kill -INT %d", bustle_pid);
191 g_spawn_command_line_sync(killline, NULL, NULL, NULL, NULL);204 g_spawn_command_line_sync(killline, NULL, NULL, NULL, NULL);
192 g_free(killline);205 g_free(killline);
@@ -281,6 +294,36 @@
281}294}
282295
283static void296static void
297dbus_watcher (GPid pid, gint status, gpointer data)
298{
299 g_critical("DBus Daemon exited abruptly!");
300
301 global_success = FALSE;
302 g_main_loop_quit(global_mainloop);
303
304 if (pid != 0) {
305 g_spawn_close_pid(pid);
306 }
307
308 return;
309}
310
311static void
312bustle_watcher (GPid pid, gint status, gpointer data)
313{
314 g_critical("Bustle Monitor exited abruptly!");
315
316 global_success = FALSE;
317 g_main_loop_quit(global_mainloop);
318
319 if (pid != 0) {
320 g_spawn_close_pid(pid);
321 }
322
323 return;
324}
325
326static void
284proc_watcher (GPid pid, gint status, gpointer data)327proc_watcher (GPid pid, gint status, gpointer data)
285{328{
286 task_t * task = (task_t *)data;329 task_t * task = (task_t *)data;
@@ -404,7 +447,7 @@
404dbus_writes (GIOChannel * channel, GIOCondition condition, gpointer data)447dbus_writes (GIOChannel * channel, GIOCondition condition, gpointer data)
405{448{
406 if (condition & G_IO_ERR) {449 if (condition & G_IO_ERR) {
407 g_error("DBus writing failure!");450 g_critical("DBus writing failure!");
408 return FALSE;451 return FALSE;
409 }452 }
410453
@@ -427,9 +470,14 @@
427 if (tasks != NULL) {470 if (tasks != NULL) {
428 start_bustling();471 start_bustling();
429472
430 g_list_foreach(tasks, start_task, GINT_TO_POINTER(FALSE));473 /* If we're still in a place where we can succeed, then
474 we should continue. Otherwise fail. */
475 if (global_success) {
476 g_list_foreach(tasks, start_task, GINT_TO_POINTER(FALSE));
477 }
431 } else {478 } else {
432 g_print("No tasks!\n");479 g_print("No tasks!\n");
480 global_success = FALSE;
433 g_main_loop_quit(global_mainloop);481 g_main_loop_quit(global_mainloop);
434 }482 }
435 }483 }
@@ -540,13 +588,6 @@
540 return TRUE;588 return TRUE;
541}589}
542590
543static gboolean
544bustle_watch (const gchar * arg, const gchar * value, gpointer data, GError ** error)
545{
546 bustle_watches = g_list_append(bustle_watches, g_strdup(value));
547 return TRUE;
548}
549
550static void591static void
551length_finder (gpointer data, gpointer udata)592length_finder (gpointer data, gpointer udata)
552{593{
@@ -636,11 +677,13 @@
636}677}
637678
638static gchar * dbus_configfile = NULL;679static gchar * dbus_configfile = NULL;
680static gchar * dbus_daemon = NULL;
639681
640static GOptionEntry general_options[] = {682static GOptionEntry general_options[] = {
683 {"dbus-daemon", 0, 0, G_OPTION_ARG_FILENAME, &dbus_daemon, "Path to the DBus deamon to use. Defaults to 'dbus-daemon'.", "executable"},
641 {"dbus-config", 'd', 0, G_OPTION_ARG_FILENAME, &dbus_configfile, "Configuration file for newly created DBus server. Defaults to '" DEFAULT_SESSION_CONF "'.", "config_file"},684 {"dbus-config", 'd', 0, G_OPTION_ARG_FILENAME, &dbus_configfile, "Configuration file for newly created DBus server. Defaults to '" DEFAULT_SESSION_CONF "'.", "config_file"},
685 {"bustle-monitor", 0, 0, G_OPTION_ARG_FILENAME, &bustle_cmd, "Path to the Bustle DBus Monitor to use. Defaults to 'bustle-dbus-monitor'.", "executable"},
642 {"bustle-data", 'b', 0, G_OPTION_ARG_FILENAME, &bustle_datafile, "A file to write out data from the bustle logger to.", "data_file"},686 {"bustle-data", 'b', 0, G_OPTION_ARG_FILENAME, &bustle_datafile, "A file to write out data from the bustle logger to.", "data_file"},
643 {"bustle-watch", 'w', 0, G_OPTION_ARG_CALLBACK, bustle_watch, "Defines a watch string for the bustle watcher task. (broken)", "filter"},
644 {"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"},687 {"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"},
645 {NULL}688 {NULL}
646};689};
@@ -683,21 +726,36 @@
683 dbus_configfile = DEFAULT_SESSION_CONF;726 dbus_configfile = DEFAULT_SESSION_CONF;
684 }727 }
685728
729 if (dbus_daemon == NULL) {
730 dbus_daemon = "dbus-daemon";
731 }
732
733 if (bustle_cmd == NULL) {
734 bustle_cmd = "bustle-dbus-monitor";
735 }
736
686 gint dbus_stdout;737 gint dbus_stdout;
687 GPid dbus;738 GPid dbus;
688 gchar * blank[1] = {NULL};739 gchar * blank[1] = {NULL};
689 gchar * dbus_startup[] = {"dbus-daemon", "--config-file", dbus_configfile, "--print-address", NULL};740 gchar * dbus_startup[] = {dbus_daemon, "--config-file", dbus_configfile, "--print-address", NULL};
690 g_spawn_async_with_pipes(g_get_current_dir(),741 g_spawn_async_with_pipes(g_get_current_dir(),
691 dbus_startup, /* argv */742 dbus_startup, /* argv */
692 blank, /* envp */743 blank, /* envp */
693 G_SPAWN_SEARCH_PATH, /* flags */744 G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD, /* flags */
694 NULL, /* child setup func */745 NULL, /* child setup func */
695 NULL, /* child setup data */746 NULL, /* child setup data */
696 &dbus, /* PID */747 &dbus, /* PID */
697 NULL, /* stdin */748 NULL, /* stdin */
698 &dbus_stdout, /* stdout */749 &dbus_stdout, /* stdout */
699 NULL, /* stderr */750 NULL, /* stderr */
700 NULL); /* error */751 &error); /* error */
752
753 if (error != NULL) {
754 g_critical("Unable to start dbus daemon: %s", error->message);
755 return 1;
756 }
757
758 guint dbus_watch = g_child_watch_add(dbus, dbus_watcher, NULL);
701759
702 GIOChannel * dbus_io = g_io_channel_unix_new(dbus_stdout);760 GIOChannel * dbus_io = g_io_channel_unix_new(dbus_stdout);
703 g_io_add_watch(dbus_io,761 g_io_add_watch(dbus_io,
@@ -714,6 +772,7 @@
714772
715 stop_bustling();773 stop_bustling();
716774
775 g_source_remove(dbus_watch); /* Let's not error when we want to kill it */
717 gchar * killline = g_strdup_printf("kill -9 %d", dbus);776 gchar * killline = g_strdup_printf("kill -9 %d", dbus);
718 g_spawn_command_line_sync(killline, NULL, NULL, NULL, NULL);777 g_spawn_command_line_sync(killline, NULL, NULL, NULL, NULL);
719 g_free(killline);778 g_free(killline);
720779
=== modified file 'tests/Makefile.am'
--- tests/Makefile.am 2011-11-28 22:21:06 +0000
+++ tests/Makefile.am 2011-12-10 03:58:25 +0000
@@ -1,5 +1,5 @@
11
2DBUS_RUNNER=../src/dbus-test-runner --dbus-config $(srcdir)/../data/session.conf2DBUS_RUNNER=$(top_builddir)/src/dbus-test-runner --dbus-config $(srcdir)/../data/session.conf
3TESTS = 3TESTS =
4DISTCLEANFILES = $(TESTS)4DISTCLEANFILES = $(TESTS)
5XFAIL_TESTS =5XFAIL_TESTS =
@@ -57,6 +57,96 @@
57 @chmod +x $@57 @chmod +x $@
58XFAIL_TESTS += test-timeout58XFAIL_TESTS += test-timeout
5959
60TESTS += test-timeout-disable
61test-timeout-disable: Makefile.am
62 @echo "#!/bin/sh" > $@
63 @echo $(DBUS_RUNNER) --max-wait 0 --task true >> $@
64 @chmod +x $@
65
66TESTS += test-param-only-name
67test-param-only-name: Makefile.am
68 @echo "#!/bin/sh" > $@
69 @echo $(DBUS_RUNNER) --task-name Name >> $@
70 @chmod +x $@
71XFAIL_TESTS += test-param-only-name
72
73TESTS += test-param-dup-name
74test-param-dup-name: Makefile.am
75 @echo "#!/bin/sh" > $@
76 @echo $(DBUS_RUNNER) --task true --task-name Name --task-name Name2 >> $@
77 @chmod +x $@
78XFAIL_TESTS += test-param-dup-name
79
80TESTS += test-param-only-ignore
81test-param-only-ignore: Makefile.am
82 @echo "#!/bin/sh" > $@
83 @echo $(DBUS_RUNNER) --ignore-return >> $@
84 @chmod +x $@
85XFAIL_TESTS += test-param-only-ignore
86
87TESTS += test-param-only-invert
88test-param-only-invert: Makefile.am
89 @echo "#!/bin/sh" > $@
90 @echo $(DBUS_RUNNER) --invert-return >> $@
91 @chmod +x $@
92XFAIL_TESTS += test-param-only-invert
93
94TESTS += test-param-multi-return-invert
95test-param-multi-return-invert: Makefile.am
96 @echo "#!/bin/sh" > $@
97 @echo $(DBUS_RUNNER) --task true --ignore-return --invert-return >> $@
98 @chmod +x $@
99XFAIL_TESTS += test-param-multi-return-invert
100
101TESTS += test-param-multi-return-ignore
102test-param-multi-return-ignore: Makefile.am
103 @echo "#!/bin/sh" > $@
104 @echo $(DBUS_RUNNER) --task true --invert-return --ignore-return >> $@
105 @chmod +x $@
106XFAIL_TESTS += test-param-multi-return-ignore
107
108TESTS += test-param-only-param
109test-param-only-param: Makefile.am
110 @echo "#!/bin/sh" > $@
111 @echo $(DBUS_RUNNER) --parameter bob >> $@
112 @chmod +x $@
113XFAIL_TESTS += test-param-only-param
114
115TESTS += test-param-only-wait
116test-param-only-wait: Makefile.am
117 @echo "#!/bin/sh" > $@
118 @echo $(DBUS_RUNNER) --wait-for org.test.test >> $@
119 @chmod +x $@
120XFAIL_TESTS += test-param-only-wait
121
122TESTS += test-param-multi-wait
123test-param-multi-wait: Makefile.am
124 @echo "#!/bin/sh" > $@
125 @echo $(DBUS_RUNNER) --task true --wait-for org.test.test --wait-for org.test.test2 >> $@
126 @chmod +x $@
127XFAIL_TESTS += test-param-multi-wait
128
129TESTS += test-param-bad
130test-param-bad: Makefile.am
131 @echo "#!/bin/sh" > $@
132 @echo $(DBUS_RUNNER) --this-is-most-surly-not-a-real-parameter >> $@
133 @chmod +x $@
134XFAIL_TESTS += test-param-bad
135
136TESTS += test-param-bad-task
137test-param-bad-task: Makefile.am
138 @echo "#!/bin/sh" > $@
139 @echo $(DBUS_RUNNER) --task this-is-most-surly-not-a-real-program >> $@
140 @chmod +x $@
141XFAIL_TESTS += test-param-bad-task
142
143TESTS += test-no-tasks
144test-no-tasks: Makefile.am
145 @echo "#!/bin/sh" > $@
146 @echo $(DBUS_RUNNER) >> $@
147 @chmod +x $@
148XFAIL_TESTS += test-no-tasks
149
60TESTS += test-output150TESTS += test-output
61test-output: Makefile.am151test-output: Makefile.am
62 @echo "#!/bin/sh -e" > $@152 @echo "#!/bin/sh -e" > $@
@@ -85,6 +175,29 @@
85 @chmod +x $@175 @chmod +x $@
86DISTCLEANFILES += test-bustle.bustle test-bustle.filtered176DISTCLEANFILES += test-bustle.bustle test-bustle.filtered
87177
178TESTS += test-bustle-bad-file
179test-bustle-bad-file: Makefile.am
180 @echo "#!/bin/sh -e" > $@
181 @echo $(DBUS_RUNNER) --bustle-data \"$(builddir)\" --task true >> $@
182 @chmod +x $@
183XFAIL_TESTS += test-bustle-bad-file
184
185TESTS += test-bustle-bad-monitor
186test-bustle-bad-monitor: Makefile.am
187 @echo "#!/bin/sh -e" > $@
188 @echo $(DBUS_RUNNER) --bustle-monitor probably-doesnt-exist --bustle-data \"$(builddir)/test-bustle-bad-monitor.bustle\" --task true >> $@
189 @chmod +x $@
190XFAIL_TESTS += test-bustle-bad-monitor
191DISTCLEANFILES += test-bustle-bad-monitor.bustle
192
193TESTS += test-bustle-bad-monitor-error
194test-bustle-bad-monitor-error: Makefile.am
195 @echo "#!/bin/sh -e" > $@
196 @echo $(DBUS_RUNNER) --bustle-monitor sleep --bustle-data \"$(builddir)/test-bustle-bad-monitor-error.bustle\" --task true >> $@
197 @chmod +x $@
198XFAIL_TESTS += test-bustle-bad-monitor-error
199DISTCLEANFILES += test-bustle-bad-monitor-error.bustle
200
88TESTS += test-bustle-data201TESTS += test-bustle-data
89test-bustle-data: Makefile.am202test-bustle-data: Makefile.am
90 @echo "#!/bin/sh -e" > $@203 @echo "#!/bin/sh -e" > $@
@@ -126,6 +239,32 @@
126 @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 >> $@239 @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 >> $@
127 @chmod +x $@240 @chmod +x $@
128241
242TESTS += test-daemon-bad
243test-daemon-bad: Makefile.am
244 @echo "#!/bin/sh" > $@
245 @echo $(DBUS_RUNNER) --dbus-daemon false --task true >> $@
246 @chmod +x $@
247XFAIL_TESTS += test-daemon-bad
248
249TESTS += test-daemon-missing
250test-daemon-missing: Makefile.am
251 @echo "#!/bin/sh" > $@
252 @echo $(DBUS_RUNNER) --dbus-daemon probably-doesnt-exist --task true >> $@
253 @chmod +x $@
254XFAIL_TESTS += test-daemon-missing
255
256TESTS += test-daemon-junk
257test-daemon-junk: Makefile.am test-daemon-junk-spitter
258 @echo "#!/bin/sh" > $@
259 @echo $(DBUS_RUNNER) --dbus-daemon $(builddir)/test-daemon-junk-spitter --task true >> $@
260 @chmod +x $@
261test-daemon-junk-spitter: Makefile.am
262 @echo "#!/bin/sh" > $@
263 @echo cat $(top_builddir)/src/dbus-test-runner >> $@
264 @chmod +x $@
265XFAIL_TESTS += test-daemon-junk
266DISTCLEANFILES += test-daemon-junk-spitter
267
129EXTRA_DIST = \268EXTRA_DIST = \
130 delayrm.sh \269 delayrm.sh \
131 test-bustle.reference \270 test-bustle.reference \

Subscribers

People subscribed via source and target branches