aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2012-03-29 07:44:31 -0700
committerCharles Kerr <charles.kerr@canonical.com>2012-03-29 07:44:31 -0700
commit921aacaeec41ef3b62d2c1650f9f872eea921013 (patch)
treed12db36a7cedb1d3ce93da2fab0a227d46507a74 /tests
parent4c0ab8af125ecdac6690bc56ab60f0059bafad9f (diff)
parent11ee75120bad73033ccd1ec1ceb919395023084e (diff)
downloadlibdbusmenu-921aacaeec41ef3b62d2c1650f9f872eea921013.tar.gz
libdbusmenu-921aacaeec41ef3b62d2c1650f9f872eea921013.tar.bz2
libdbusmenu-921aacaeec41ef3b62d2c1650f9f872eea921013.zip
merge lp:~ted/dbusmenu/instruction-count-testing to support benchmarking based on callgrind measurements h/t Chase
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am19
-rw-r--r--tests/test-json-client.c4
-rwxr-xr-xtests/test-json-instruction-count6
-rw-r--r--tests/test-json-server.c18
4 files changed, 40 insertions, 7 deletions
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;
}