[systemd-devel] [PATCH 4/4] gdbus: Add basic kdbus tests

Karol Lewandowski k.lewandowsk at samsung.com
Thu Nov 21 03:33:52 PST 2013


---
 configure.ac                                      |   1 +
 gio/tests/Makefile.am                             |  13 +++
 gio/tests/kdbus-test/README                       | 108 ++++++++++++++++++++
 gio/tests/kdbus-test/gdbus-example-kdbus-client.c |  51 ++++++++++
 gio/tests/kdbus-test/gdbus-example-kdbus-server.c | 117 ++++++++++++++++++++++
 5 files changed, 290 insertions(+)
 create mode 100644 gio/tests/kdbus-test/README
 create mode 100644 gio/tests/kdbus-test/gdbus-example-kdbus-client.c
 create mode 100644 gio/tests/kdbus-test/gdbus-example-kdbus-server.c

diff --git a/configure.ac b/configure.ac
index 413c9f2..c3349c4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -264,6 +264,7 @@ AS_IF([test "x$enable_gc_friendly" = "xyes"], [
 ], [ AC_MSG_RESULT([no]) ])
 
 AC_MSG_CHECKING([kdbus transport])
+AM_CONDITIONAL(KDBUS_TRANSPORT, [test "x$enable_kdbus_transport" = "xyes"])
 AS_IF([test "x$enable_kdbus_transport" = "xyes"], [
   AC_DEFINE(KDBUS_TRANSPORT, 1, [Define if kdbus transport is enabled])
   AC_MSG_RESULT([yes])
diff --git a/gio/tests/Makefile.am b/gio/tests/Makefile.am
index bec70d7..8d692bb 100644
--- a/gio/tests/Makefile.am
+++ b/gio/tests/Makefile.am
@@ -470,6 +470,19 @@ gdbus_serialization_SOURCES = \
 	gdbus-tests.c
 endif
 
+if KDBUS_TRANSPORT
+test_programs += gdbus-example-kdbus-server
+test_programs += gdbus-example-kdbus-client
+
+gdbus_example_kdbus_server_CFLAGS = $(AM_CFLAGS) $(DBUS1_CFLAGS)
+gdbus_example_kdbus_server_LDADD = $(LDADD) $(DBUS1_LIBS)
+gdbus_example_kdbus_server_SOURCES = kdbus-test/gdbus-example-kdbus-server.c
+
+gdbus_example_kdbus_client_CFLAGS = $(AM_CFLAGS) $(DBUS1_CFLAGS)
+gdbus_example_kdbus_client_LDADD = $(LDADD) $(DBUS1_LIBS)
+gdbus_example_kdbus_client_SOURCES = kdbus-test/gdbus-example-kdbus-client.c
+endif
+
 # -----------------------------------------------------------------------------
 #  The resources test is a bit more complicated...
 
diff --git a/gio/tests/kdbus-test/README b/gio/tests/kdbus-test/README
new file mode 100644
index 0000000..6f44f0b
--- /dev/null
+++ b/gio/tests/kdbus-test/README
@@ -0,0 +1,108 @@
+Description
+===========
+
+In order to perform tests of modified libgio library (with kdbus
+transport) we have created two programs: gdbus-example-kdbus-server
+and gdbus-example-kdbus-client.  The first of them acts as a server,
+registers itself on the bus under well-known name and waits for calls
+to its objects and methods. The second one (client) makes calls and
+records periods of time between moment of preparing of a call to the
+moment of receiving and parsing an answer. The measurement is made by
+performing one thousand of calls and computing a sum of duration of
+every call (for different sizes of message payload: 4B, 8B, 4kB, 8kB,
+16kB, 64kB and 512kB).  The client program returns total time of
+performed calls after successful execution.
+
+
+Requirements
+============
+
+* kdbus kernel module,
+* modified version of glib (with kdbus transport),
+* modified version of dbus-daemon (with kdbus transport),
+
+
+KDBUS
+=====
+
+Simple install procedure:
+
+  % git clone https://github.com/gregkh/kdbus.git    # download kdbus source
+  % cd kdbus                                         # change to kdbus directory
+  % make                                             # build kdbus module
+  % insmod kdbus.ko                                  # load kdbus kernel module
+
+
+GLIB (modified version)
+=======================
+
+Simple install procedure:
+
+
+  % cd glib                                         # change to glib directory
+  % ./configure --enable-kdbus-transport            # run the `configure' script with kdbus support
+  % make                                            # build GLIB
+
+
+DBUS-DAEMON (modified version)
+==============================
+
+Modified version of dbus-daemon (from tizen.org) is required to run
+kdbus transport in libgio.
+
+Solution, which we propose, includes modifications both in client
+libraries (libgio, libdbus) and dbus daemon. Daemon is registered on
+kdbus bus as a client under "org.freedesktop.DBus" name.  Only
+messages addressed to this interface are handled by daemon. Messages
+such as RequestName or AddMatch are translated by daemon to respective
+ioctl() calls, which send them through kdbus on behalf of original
+client process. The rest of messages would are going straight from
+origin to destination through kdbus.
+
+Simple install procedure:
+
+* download modified version of dbus from tizen.org repository
+  (kdbus-dev branch):
+
+  git clone git://review.tizen.org/platform/upstream/dbus.git -b kdbus-dev
+
+* change to dbus directory and build dbus-daemon with kdbus support:
+
+  ./configure --enable-kdbus-transport
+  make && make install
+
+* start of custom dbus-daemon supporting kdbus transport:
+
+  ./dbus-daemon --nofork --address=kdbus: --config-file=/etc/dbus-1/session.conf
+
+
+TESTS
+=====
+
+* Build test binaries:
+
+  cd gio/tests
+  make
+
+* Set variable to use custom library and to use kdbus as session bus:
+
+  export LD_LIBRARY_PATH=absolute_path_to_glib_libs_with_kdbus_patch
+  export DBUS_SESSION_BUS_ADDRESS=kdbus:path=/dev/kdbus/0-kdbus/bus
+
+* Run test binary server in terminal 1:
+
+  ./gdbus-example-kdbus-server
+
+* Run test binary client in terminal 2:
+
+  ./gdbus-example-kdbus-client
+
+* Sample client app output:
+
+  elapsed time : 0.265072 s
+  elapsed time : 0.264353 s
+  elapsed time : 0.305062 s
+  elapsed time : 0.343710 s
+  elapsed time : 0.451501 s
+  elapsed time : 1.109851 s
+  elapsed time : 8.278217 s
diff --git a/gio/tests/kdbus-test/gdbus-example-kdbus-client.c b/gio/tests/kdbus-test/gdbus-example-kdbus-client.c
new file mode 100644
index 0000000..63f5a88
--- /dev/null
+++ b/gio/tests/kdbus-test/gdbus-example-kdbus-client.c
@@ -0,0 +1,51 @@
+/*
+ * gcc -o gdbus-example-kdbus-client gdbus-example-kdbus-client.c `pkg-config --cflags --libs glib-2.0 gio-2.0`
+ */
+
+#include <stdlib.h>
+#include <gio/gio.h>
+#include <time.h>
+
+#define DBUS_NAME "com.kdbus.test"
+#define DBUS_PATH "/com/kdbus/test"
+#define DBUS_IFACE "com.kdbus.test"
+
+/*
+ * Main function
+ */
+int main (int argc, char ** argv)
+{
+  GDBusConnection *connection;
+  GDBusProxy *proxy;
+  int k,i,l;
+  char *buf = NULL;
+  int msg_size[7] = {4,8,4096,8192,16384,65536,524288};
+  char *bus_name = "HelloKdbus";
+
+  struct timespec start, end;
+  double elapsed;
+
+  connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
+  proxy = g_dbus_proxy_new_sync (connection, G_DBUS_PROXY_FLAGS_NONE, NULL, DBUS_NAME,DBUS_PATH,DBUS_IFACE, NULL, NULL);
+
+  for (i=0; i<7; ++i)
+    {
+      buf = malloc(sizeof(char) * (msg_size[i] + 1));
+      for(k=0; k<msg_size[i]; ++k)
+        buf[k] = 'a';
+      buf[k] = '\0';
+
+      clock_gettime(CLOCK_REALTIME, &start);
+
+      for(l=0; l<1000; l++)
+        g_dbus_proxy_call_sync (proxy, bus_name, g_variant_new("(s)", buf), G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL);
+
+      clock_gettime(CLOCK_REALTIME, &end);
+      elapsed = (end.tv_sec - start.tv_sec) + (end.tv_nsec - start.tv_nsec) / 1E9;
+      g_print("elapsed time : %lf s\n", elapsed);
+      free (buf);
+    }
+
+  return 0;
+}
+
diff --git a/gio/tests/kdbus-test/gdbus-example-kdbus-server.c b/gio/tests/kdbus-test/gdbus-example-kdbus-server.c
new file mode 100644
index 0000000..fe80165
--- /dev/null
+++ b/gio/tests/kdbus-test/gdbus-example-kdbus-server.c
@@ -0,0 +1,117 @@
+/*
+ * gcc -o gdbus-example-kdbus-server gdbus-example-kdbus-server.c `pkg-config --cflags --libs glib-2.0 gio-2.0`
+ */
+
+#include <stdlib.h>
+#include <gio/gio.h>
+
+#define DBUS_NAME "com.kdbus.test"
+#define DBUS_PATH "/com/kdbus/test"
+#define DBUS_IFACE "com.kdbus.test"
+
+/*
+ * Handlers
+ */
+static void bus_acquired_handler (GDBusConnection *connection, const gchar *name, gpointer user_data);
+static void name_acquired_handler (GDBusConnection *connection, const gchar *name, gpointer user_data);
+static void name_lost_handler (GDBusConnection *connection, const gchar *name, gpointer user_data);
+
+/*
+ * Globals
+ */
+static GDBusNodeInfo *introspection_data = NULL;
+
+
+/*
+ * method_call_handler
+ */
+static void method_call_handler (GDBusConnection *connection,
+				 const gchar *sender,
+				 const gchar *object_path,
+				 const gchar *interface_name,
+				 const gchar *method_name,
+				 GVariant *parameters,
+				 GDBusMethodInvocation *invocation,
+				 gpointer user_data)
+{
+  if (g_strcmp0 (method_name, "HelloKdbus") == 0)
+  {
+    gchar *string_in;
+    gchar *string_out;
+
+    g_variant_get (parameters, "(&s)", &string_in);
+    string_out = g_strdup_printf ("ok %s", string_in);
+    g_dbus_method_invocation_return_value (invocation, g_variant_new("(s)", string_out));
+    g_free (string_out);
+  }
+}
+
+
+/*
+ * Vtable
+ */
+static const GDBusInterfaceVTable vtable =
+{
+  method_call_handler
+};
+
+
+/*
+ * Main function
+ */
+int main (int argc, char ** argv)
+{
+  GMainLoop *g_main_loop;
+  guint id;
+
+  gchar xml[] =
+  "<node>"
+  "  <interface name= 'com.kdbus.test'>"
+  "    <method name= 'HelloKdbus'>"
+  "      <arg type= 's' name= 'string_in' direction= 'in'/>"
+  "      <arg type= 's' name= 'string_out' direction= 'out'/>"
+  "    </method>"
+  "  </interface>"
+  "</node>";
+
+  introspection_data = g_dbus_node_info_new_for_xml (xml, NULL);
+  id = g_bus_own_name (G_BUS_TYPE_SESSION,DBUS_NAME,G_BUS_NAME_OWNER_FLAGS_NONE,bus_acquired_handler,name_acquired_handler,name_lost_handler,NULL,NULL);
+
+  g_main_loop = g_main_loop_new (NULL, FALSE);
+  g_main_loop_run (g_main_loop);
+
+  g_bus_unown_name (id);
+  g_dbus_node_info_unref (introspection_data);
+  return (0);
+}
+
+
+/*
+ * Handler to invoke when connected to the bus of type bus_type or NULL
+ */
+static void bus_acquired_handler (GDBusConnection *connection, const gchar *name, gpointer user_data)
+{
+  guint registration_id = g_dbus_connection_register_object (connection,DBUS_PATH,introspection_data->interfaces[0],&vtable,NULL,NULL,NULL);
+  g_print ("HANDLER: bus_acquired_handler\n");
+  g_assert (registration_id > 0);
+}
+
+
+/*
+ * Handler to invoke when name is acquired or NULL
+ */
+static void name_acquired_handler (GDBusConnection *connection,const gchar *name,gpointer user_data)
+{
+  g_print ("HANDLER: name_acquired_handler\n");
+}
+
+
+/*
+ * Handler to invoke when name is lost or NULL
+ */
+static void name_lost_handler (GDBusConnection *connection,const gchar *name,gpointer user_data)
+{
+  g_print ("HANDLER: name_lost_handler\n");
+  exit(1);
+}
+
-- 
1.8.4.rc3



More information about the systemd-devel mailing list