ayatana-commits team mailing list archive
-
ayatana-commits team
-
Mailing list archive
-
Message #00661
[Branch ~indicator-applet-developers/dbus-test-runner/trunk] Rev 23: Adding the ability to record the messages on the buss using bustle-dbus-monitor.
Merge authors:
Ted Gould (ted)
Related merge proposals:
https://code.launchpad.net/~ted/dbus-test-runner/bustle-data/+merge/15801
proposed by: Ted Gould (ted)
review: Approve - Cody Russell (bratsche)
------------------------------------------------------------
revno: 23 [merge]
committer: Ted Gould <ted@xxxxxxxx>
branch nick: trunk
timestamp: Tue 2009-12-08 14:25:05 -0600
message:
Adding the ability to record the messages on the buss using bustle-dbus-monitor.
added:
tests/test-bustle.reference
modified:
.bzrignore
src/Makefile.am
src/dbus-test-runner.c
tests/Makefile.am
--
lp:dbus-test-runner
https://code.launchpad.net/~indicator-applet-developers/dbus-test-runner/trunk
Your team ayatana-commits is subscribed to branch lp:dbus-test-runner.
To unsubscribe from this branch go to https://code.launchpad.net/~indicator-applet-developers/dbus-test-runner/trunk/+edit-subscription.
=== modified file '.bzrignore'
--- .bzrignore 2009-12-03 17:39:04 +0000
+++ .bzrignore 2009-12-08 05:25:49 +0000
@@ -15,3 +15,6 @@
tests/testcat.output.cat2.filtered.txt
tests/testcat.output.cat2.txt
tests/testcat.output.txt
+tests/test-bustle
+tests/test-bustle.bustle
+tests/test-bustle.filtered
=== modified file 'src/Makefile.am'
--- src/Makefile.am 2009-04-27 19:26:24 +0000
+++ src/Makefile.am 2009-12-07 21:00:43 +0000
@@ -2,5 +2,7 @@
bin_PROGRAMS = dbus-test-runner
dbus_test_runner_SOURCES = dbus-test-runner.c
-dbus_test_runner_CFLAGS = $(DBUS_TEST_RUNNER_CFLAGS) -DDEFAULT_SESSION_CONF="\"$(datadir)/dbus-test-runner/session.conf\""
+dbus_test_runner_CFLAGS = $(DBUS_TEST_RUNNER_CFLAGS) \
+ -DDEFAULT_SESSION_CONF="\"$(datadir)/dbus-test-runner/session.conf\"" \
+ -Wall -Werror
dbus_test_runner_LDADD = $(DBUS_TEST_RUNNER_LIBS)
=== modified file 'src/dbus-test-runner.c'
--- src/dbus-test-runner.c 2009-12-03 19:00:06 +0000
+++ src/dbus-test-runner.c 2009-12-08 05:26:05 +0000
@@ -27,6 +27,196 @@
static void check_task_cleanup (task_t * task, gboolean force);
+static gchar * bustle_datafile = NULL;
+static GIOChannel * bustle_stdout = NULL;
+static GIOChannel * bustle_stderr = NULL;
+static GIOChannel * bustle_file = NULL;
+static GPid bustle_pid = 0;
+static GList * bustle_watches = NULL;
+
+#define BUSTLE_ERROR_DEFAULT "Bustle"
+static gchar * bustle_error = BUSTLE_ERROR_DEFAULT;
+
+static gboolean
+bustle_write_error (GIOChannel * channel, GIOCondition condition, gpointer data)
+{
+ gchar * line;
+ gsize termloc;
+
+ do {
+ GIOStatus status = g_io_channel_read_line (channel, &line, NULL, &termloc, NULL);
+
+ if (status == G_IO_STATUS_EOF) {
+ return FALSE;
+ }
+
+ if (status != G_IO_STATUS_NORMAL) {
+ continue;
+ }
+
+ line[termloc] = '\0';
+
+ g_print("%s: %s\n", bustle_error, line);
+ g_free(line);
+ } while (G_IO_IN & g_io_channel_get_buffer_condition(channel));
+
+ return TRUE;
+}
+
+static gboolean
+bustle_writes (GIOChannel * channel, GIOCondition condition, gpointer data)
+{
+ g_debug("Bustle write");
+ gchar * line;
+ gsize termloc;
+
+ do {
+ GIOStatus status = g_io_channel_read_line (channel, &line, NULL, &termloc, NULL);
+
+ if (status == G_IO_STATUS_EOF) {
+ continue;
+ }
+
+ if (status != G_IO_STATUS_NORMAL) {
+ continue;
+ }
+
+ g_io_channel_write_chars((GIOChannel *)data,
+ line,
+ termloc,
+ NULL,
+ NULL);
+ g_io_channel_write_chars((GIOChannel *)data,
+ "\n",
+ 1,
+ NULL,
+ NULL);
+
+ g_free(line);
+ } while ((G_IO_IN | G_IO_PRI) & g_io_channel_get_buffer_condition(channel));
+
+ return TRUE;
+}
+
+static void
+start_bustling (void)
+{
+ if (bustle_datafile == NULL) {
+ return;
+ }
+
+ GError * error = NULL;
+
+ bustle_file = g_io_channel_new_file(bustle_datafile, "w", &error);
+
+ if (error != NULL) {
+ g_warning("Unable to open bustle file '%s': %s", bustle_datafile, error->message);
+ g_error_free(error);
+ g_free(bustle_datafile);
+ bustle_datafile = NULL;
+ return;
+ }
+
+ gint bustle_stdout_num;
+ gint bustle_stderr_num;
+
+ gchar ** bustle_monitor = g_new0(gchar *, g_list_length(bustle_watches) + 3);
+ bustle_monitor[0] = "bustle-dbus-monitor";
+ bustle_monitor[1] = "--session";
+ int i;
+ for (i = 0; i < g_list_length(bustle_watches); i++) {
+ bustle_monitor[i + 2] = (gchar *)g_list_nth(bustle_watches, i)->data;
+ }
+
+ g_spawn_async_with_pipes(g_get_current_dir(),
+ bustle_monitor, /* argv */
+ NULL, /* envp */
+ /* G_SPAWN_SEARCH_PATH | G_SPAWN_STDERR_TO_DEV_NULL, */ /* flags */
+ G_SPAWN_SEARCH_PATH, /* flags */
+ NULL, /* child setup func */
+ NULL, /* child setup data */
+ &bustle_pid, /* PID */
+ NULL, /* stdin */
+ &bustle_stdout_num, /* stdout */
+ &bustle_stderr_num, /* stderr */
+ &error); /* error */
+
+ if (error != NULL) {
+ g_warning("Unable to start bustling data: %s", error->message);
+ return;
+ }
+
+ bustle_stdout = g_io_channel_unix_new(bustle_stdout_num);
+ g_io_add_watch(bustle_stdout,
+ G_IO_IN | G_IO_PRI, /* conditions */
+ bustle_writes, /* func */
+ bustle_file); /* func data */
+
+ bustle_stderr = g_io_channel_unix_new(bustle_stderr_num);
+ g_io_add_watch(bustle_stderr,
+ G_IO_IN, /* conditions */
+ bustle_write_error, /* func */
+ NULL); /* func data */
+
+ return;
+}
+
+static void
+stop_bustling (void)
+{
+ if (bustle_datafile == NULL) {
+ return;
+ }
+
+ gchar * killline = g_strdup_printf("kill -INT %d", bustle_pid);
+ g_spawn_command_line_sync(killline, NULL, NULL, NULL, NULL);
+ g_free(killline);
+
+ gchar * send_stdout = NULL;
+ gchar * send_stderr = NULL;
+ g_spawn_command_line_sync("dbus-send --session --print-reply --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.ListNames", &send_stdout, &send_stderr, NULL, NULL);
+ if (send_stdout != NULL) {
+ g_free(send_stdout);
+ }
+ if (send_stderr != NULL) {
+ g_free(send_stderr);
+ }
+
+ gchar * line;
+ gsize termloc;
+
+ while (!((G_IO_ERR | G_IO_HUP | G_IO_NVAL) & g_io_channel_get_buffer_condition(bustle_stdout))) {
+ GIOStatus status = g_io_channel_read_line (bustle_stdout, &line, NULL, &termloc, NULL);
+
+ if (status == G_IO_STATUS_EOF) {
+ break;
+ }
+
+ if (status != G_IO_STATUS_NORMAL) {
+ continue;
+ }
+
+ g_io_channel_write_chars((GIOChannel *)bustle_file,
+ line,
+ termloc,
+ NULL,
+ NULL);
+ g_io_channel_write_chars((GIOChannel *)bustle_file,
+ "\n",
+ 1,
+ NULL,
+ NULL);
+
+ g_free(line);
+ }
+
+ g_io_channel_shutdown(bustle_stdout, TRUE, NULL);
+ g_io_channel_shutdown(bustle_stderr, TRUE, NULL);
+ g_io_channel_shutdown(bustle_file, TRUE, NULL);
+
+ return;
+}
+
static gboolean
force_kill_in_a_bit (gpointer data)
{
@@ -185,7 +375,14 @@
g_setenv("DBUS_STARTER_ADDRESS", line, TRUE);
g_setenv("DBUS_STARTER_BUS_TYPE", "session", TRUE);
- g_list_foreach(tasks, start_task, NULL);
+ if (tasks != NULL) {
+ start_bustling();
+
+ g_list_foreach(tasks, start_task, NULL);
+ } else {
+ g_print("No tasks!\n");
+ g_main_loop_quit(global_mainloop);
+ }
}
g_free(line);
@@ -274,14 +471,20 @@
return TRUE;
}
+static gboolean
+bustle_watch (const gchar * arg, const gchar * value, gpointer data, GError ** error)
+{
+ bustle_watches = g_list_append(bustle_watches, g_strdup(value));
+ return TRUE;
+}
+
static void
length_finder (gpointer data, gpointer udata)
{
task_t * task = (task_t *)data;
guint * longest = (guint *)udata;
- /* 640 should be enough characters for anyone */
- guint length = g_utf8_strlen(task->name, 640);
+ guint length = g_utf8_strlen(task->name, -1);
if (length > *longest) {
*longest = length;
}
@@ -307,8 +510,7 @@
task_t * task = (task_t *)data;
guint * target = (guint *)udata;
- /* 640 should be enough characters for anyone */
- guint length = g_utf8_strlen(task->name, 640);
+ guint length = g_utf8_strlen(task->name, -1);
if (length != *target) {
gchar * fillstr = g_strnfill(*target - length, ' ');
gchar * newname = g_strconcat(task->name, fillstr, NULL);
@@ -321,14 +523,37 @@
}
static void
+normalize_bustle (guint target)
+{
+ if (bustle_datafile == NULL) {
+ return;
+ }
+
+ guint length = g_utf8_strlen(BUSTLE_ERROR_DEFAULT, -1);
+ if (length != target) {
+ gchar * fillstr = g_strnfill(target - length, ' ');
+ bustle_error = g_strconcat(BUSTLE_ERROR_DEFAULT, fillstr, NULL);
+ g_free(fillstr);
+ }
+
+ return;
+}
+
+static void
normalize_name_length (void)
{
guint maxlen = 0;
+
+ if (bustle_datafile != NULL) {
+ maxlen = g_utf8_strlen(BUSTLE_ERROR_DEFAULT, -1);
+ }
g_list_foreach(tasks, set_name, NULL);
g_list_foreach(tasks, length_finder, &maxlen);
g_list_foreach(tasks, normalize_name, &maxlen);
+ normalize_bustle(maxlen);
+
return;
}
@@ -336,6 +561,8 @@
static GOptionEntry general_options[] = {
{"dbus-config", 'd', G_OPTION_FLAG_FILENAME, G_OPTION_ARG_FILENAME, &dbus_configfile, "Configuration file for newly created DBus server. Defaults to '" DEFAULT_SESSION_CONF "'.", "config_file"},
+ {"bustle-data", 'b', G_OPTION_FLAG_FILENAME, G_OPTION_ARG_FILENAME, &bustle_datafile, "A file to write out data from the bustle logger to.", "data_file"},
+ {"bustle-watch", 'w', 0, G_OPTION_ARG_CALLBACK, bustle_watch, "Defines a watch string for the bustle watcher task. (broken)", "filter"},
{NULL}
};
@@ -399,6 +626,8 @@
global_mainloop = g_main_loop_new(NULL, FALSE);
g_main_loop_run(global_mainloop);
+ stop_bustling();
+
gchar * killline = g_strdup_printf("kill -9 %d", dbus);
g_spawn_command_line_sync(killline, NULL, NULL, NULL, NULL);
g_free(killline);
=== modified file 'tests/Makefile.am'
--- tests/Makefile.am 2009-12-03 17:39:04 +0000
+++ tests/Makefile.am 2009-12-08 05:22:06 +0000
@@ -64,5 +64,16 @@
@chmod +x $@
DISTCLEANFILES += testcat.output.txt testcat.output.cat1.txt testcat.output.cat2.txt testcat.output.cat1.filtered.txt testcat.output.cat2.filtered.txt
+TESTS += test-bustle
+test-bustle: Makefile.am test-bustle.reference
+ @echo "#!/bin/sh -e" > $@
+ @echo $(DBUS_RUNNER) --bustle-data \"$(builddir)/test-bustle.bustle\" --task dbus-send -p "--session" -p "--print-reply" -p "--dest=org.freedesktop.DBus" -p "/org/freedesktop/DBus" -p "org.freedesktop.DBus.ListNames" --ignore-return >> $@
+ @echo "grep ^mc \"$(builddir)/test-bustle.bustle\" | grep ":1.1" | grep "ListNames" | cut -f 5-9 > test-bustle.filtered" >> $@
+ @echo "diff \"$(srcdir)/test-bustle.reference\" \"$(builddir)/test-bustle.filtered\"" >> $@
+ @chmod +x $@
+DISTCLEANFILES += test-bustle.bustle test-bustle.filtered
+
+
EXTRA_DIST = \
- delayrm.sh
+ delayrm.sh \
+ test-bustle.reference
=== added file 'tests/test-bustle.reference'
--- tests/test-bustle.reference 1970-01-01 00:00:00 +0000
+++ tests/test-bustle.reference 2009-12-08 05:22:06 +0000
@@ -0,0 +1,1 @@
+:1.1 org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus ListNames