diff options
-rw-r--r-- | configure.ac | 3 | ||||
-rw-r--r-- | tests/Makefile.am | 19 | ||||
-rw-r--r-- | tests/test-json-client.c | 4 | ||||
-rwxr-xr-x | tests/test-json-instruction-count | 6 | ||||
-rw-r--r-- | tests/test-json-server.c | 18 |
5 files changed, 42 insertions, 8 deletions
diff --git a/configure.ac b/configure.ac index 42c5b3d..04c93e5 100644 --- a/configure.ac +++ b/configure.ac @@ -118,7 +118,8 @@ AM_CONDITIONAL([WANT_TESTS], [test "x$enable_tests" != "xno"]) AS_IF([test "x$enable_tests" != "xno"],[ PKG_CHECK_MODULES(DBUSMENUTESTS, json-glib-1.0 >= $JSON_GLIB_REQUIRED_VERSION - gio-unix-2.0 >= $GIO_UNIX_REQUIRED_VERSION, + gio-unix-2.0 >= $GIO_UNIX_REQUIRED_VERSION + valgrind, [have_tests=yes] ) ]) diff --git a/tests/Makefile.am b/tests/Makefile.am index 16f00c5..82f6a9d 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -16,7 +16,8 @@ TESTS = \ if WANT_DBUSMENUDUMPER TESTS += \ - test-json + test-json \ + test-json-instruction endif if WANT_LIBDBUSMENUGTK @@ -242,6 +243,22 @@ test_json_client_LDADD = \ $(DBUSMENUTESTS_LIBS) \ $(DBUSMENUGLIB_LIBS) +######################### +# Test JSON Instructions +######################### + +test-json-instruction: test-json-client test-json-server test-json-instruction-count Makefile.am + @echo "#!/bin/bash" > $@ + @echo export UBUNTU_MENUPROXY="" >> $@ + @echo export G_DEBUG=fatal_criticals >> $@ + @echo $(XVFB_RUN) >> $@ + @echo $(DBUS_RUNNER) --task $(builddir)/test-json-client --wait-for org.dbusmenu.test --task-name Client --parameter $(top_builddir)/tools/dbusmenu-dumper --parameter /dev/null --ignore-return --task libtool --parameter --mode=execute --parameter $(srcdir)/test-json-instruction-count --parameter $(builddir)/test-json-server --task-name Server --parameter $(srcdir)/test-json-01.json --ignore-return >> $@ + @chmod +x $@ + +EXTRA_DIST += \ + test-json-instruction-count + + ###################### # Test Glib Submenu ###################### diff --git a/tests/test-json-client.c b/tests/test-json-client.c index 55d2ede..8900902 100644 --- a/tests/test-json-client.c +++ b/tests/test-json-client.c @@ -44,6 +44,8 @@ timeout_func (gpointer user_data) g_file_replace_contents(ofile, output, g_utf8_strlen(output, -1), NULL, FALSE, 0, NULL, NULL, NULL); } + g_spawn_command_line_sync("gdbus call --session --dest org.dbusmenu.test --object-path /org/test --method com.canonical.dbusmenu.Event 0 clicked \"<0>\" 0", NULL, NULL, NULL, NULL); + g_main_loop_quit(mainloop); return TRUE; } @@ -53,7 +55,7 @@ main (int argc, char ** argv) { g_type_init(); - g_timeout_add_seconds(2, timeout_func, argv); + g_timeout_add_seconds(1, timeout_func, argv); mainloop = g_main_loop_new(NULL, FALSE); g_main_loop_run(mainloop); diff --git a/tests/test-json-instruction-count b/tests/test-json-instruction-count new file mode 100755 index 0000000..3a4db97 --- /dev/null +++ b/tests/test-json-instruction-count @@ -0,0 +1,6 @@ +#!/bin/sh + +COMMAND=$@ +INSTRUCTIONS=`valgrind --tool=callgrind --callgrind-out-file=/dev/null --instr-atstart=no --collect-atstart=no --combine-dumps=yes $COMMAND 2>&1 > /dev/null | grep refs | grep I | tail --lines=1 | cut -d ":" -f 2 | sed -e 's/^[ \t]*//'` + +echo "Instructions needed to execute '$COMMAND': $INSTRUCTIONS" diff --git a/tests/test-json-server.c b/tests/test-json-server.c index 083de60..7165838 100644 --- a/tests/test-json-server.c +++ b/tests/test-json-server.c @@ -22,6 +22,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>. #include <glib.h> #include <gio/gio.h> +#include "callgrind.h" #include <libdbusmenu-glib/server.h> #include <libdbusmenu-glib/menuitem.h> @@ -29,11 +30,14 @@ with this program. If not, see <http://www.gnu.org/licenses/>. static GMainLoop * mainloop = NULL; -static gboolean -timer_func (gpointer data) +static void +root_activate (void) { + g_debug("Dumping callgrind data"); + CALLGRIND_DUMP_STATS_AT("exported"); + CALLGRIND_STOP_INSTRUMENTATION; g_main_loop_quit(mainloop); - return FALSE; + return; } static void @@ -50,9 +54,13 @@ on_bus (GDBusConnection * connection, const gchar * name, gpointer user_data) return; } - dbusmenu_server_set_root(server, root); + g_signal_connect(G_OBJECT(root), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(root_activate), NULL); - g_timeout_add(10000, timer_func, NULL); + g_debug("Starting Callgrind"); + CALLGRIND_START_INSTRUMENTATION; + CALLGRIND_ZERO_STATS; + CALLGRIND_TOGGLE_COLLECT; + dbusmenu_server_set_root(server, root); return; } |