Added latency pingpong dbus test and script
authorMichal Eljasiewicz <m.eljasiewic@samsung.com>
Mon, 26 Aug 2013 08:21:27 +0000 (10:21 +0200)
committerMichal Eljasiewicz <m.eljasiewic@samsung.com>
Mon, 26 Aug 2013 08:34:13 +0000 (10:34 +0200)
Script for automatic Foxp testing adapted for latency tests.

Change-Id: Icee320ec1a6d40e88ad3de335eee5a65803bd6eb

samsung_tools/Makefile [new file with mode: 0644]
samsung_tools/client.c [new file with mode: 0644]
samsung_tools/serwer.c [new file with mode: 0644]
samsung_tools/test-foxp-latency [new file with mode: 0755]

diff --git a/samsung_tools/Makefile b/samsung_tools/Makefile
new file mode 100644 (file)
index 0000000..1fc6174
--- /dev/null
@@ -0,0 +1,22 @@
+SERVER_DBUS_SOURCES=serwer.c
+
+CLIENT_DBUS_SOURCES=client.c
+
+SQLITE_CFLAGS=`pkg-config --cflags sqlite3`
+SQLITE_LIBS=`pkg-config --libs sqlite3`
+
+DBUS_CFLAGS=`pkg-config --cflags dbus-1`
+DBUS_LIBS=`pkg-config --libs dbus-1`
+
+INCLUDES=-Wall -g -O0
+
+all: ping-server ping-client 
+
+ping-server: 
+       gcc -o $@ $(SERVER_DBUS_SOURCES) $(INCLUDES) $(DBUS_CFLAGS) $(CFLAGS) $(DBUS_LIBS) $(SQLITE_CFLAGS) $(SQLITE_LIBS)
+
+ping-client: 
+       gcc -o $@ $(CLIENT_DBUS_SOURCES) $(INCLUDES) $(DBUS_CFLAGS) $(CFLAGS) $(DBUS_LIBS) $(SQLITE_CFLAGS) $(SQLITE_LIBS) 
+
+clean:
+       rm -f *.o ping-server ping-client
diff --git a/samsung_tools/client.c b/samsung_tools/client.c
new file mode 100644 (file)
index 0000000..7ada03f
--- /dev/null
@@ -0,0 +1,114 @@
+#include <stdio.h>
+
+#include <dbus/dbus.h>
+
+#include <string.h>
+#include <sys/time.h>
+#include <stdlib.h>
+
+#define DBUS_NAME "com.samsung.pingpong"
+#define DBUS_PATH "/com/samsung/pingpong"
+#define DBUS_IFACE "com.samsung.pingpong"
+
+DBusConnection *dbus_conn;
+struct timeval tv_start, tv_end;
+unsigned int message_serial;
+long int iterations = 0;
+long int avg = 0;
+long int sum = 0;
+static char* ping = "pingping";
+#define MSG_SIZE 3 * 1024 * 1024
+
+void
+shutdown_dbus ()
+{
+       if (dbus_conn) {
+               dbus_connection_close (dbus_conn);
+       }
+}
+
+DBusHandlerResult handler(DBusConnection *conn, DBusMessage *msg, void *user_data)
+{
+       //char buffer[1024];
+       DBusError error;
+       const char *dbus_data;
+       long int delta = 0;
+       DBusMessage *message;
+       
+       if (dbus_message_get_reply_serial (msg) != message_serial) {
+               return DBUS_HANDLER_RESULT_HANDLED;
+       }
+
+       dbus_error_init (&error);
+       if(!dbus_message_get_args (msg,&error,DBUS_TYPE_STRING,&dbus_data,DBUS_TYPE_INVALID))   {
+               fprintf (stderr,"error: %s\n",error.message);
+               return -1;
+       } else {
+               gettimeofday (&tv_end, NULL);
+               delta = (1000000*tv_end.tv_sec + tv_end.tv_usec) - (1000000*tv_start.tv_sec + tv_start.tv_usec);
+               //printf ("delta: %ld us\n", delta);    
+               sum += delta;
+               iterations++;
+               if(iterations == 120) {
+                       avg = sum / iterations;
+                       printf ("avg RTT: %ld us\n", avg);
+                       shutdown_dbus ();
+               }
+               gettimeofday (&tv_start, NULL);
+               message = dbus_message_new_method_call (DBUS_NAME, DBUS_PATH, DBUS_IFACE, "PING");
+               dbus_message_append_args (message, DBUS_TYPE_STRING, &ping, DBUS_TYPE_INVALID);
+               dbus_connection_send (dbus_conn, message, &message_serial);
+               dbus_message_unref (message);
+       }
+       return DBUS_HANDLER_RESULT_HANDLED;
+}
+
+int
+init_dbus ()
+{
+       DBusError error;
+       dbus_error_init (&error);
+       
+       dbus_conn = dbus_bus_get_private(DBUS_BUS_SESSION, &error);
+
+       if (dbus_error_is_set (&error)) {
+               fprintf (stderr, "Couldn't initialize DBus: %s\n", error.message);
+
+               return -1;
+       }
+
+       return 0;
+}
+
+int
+main (int argc, char **argv)
+{
+       
+       DBusMessage *message;
+       int i;
+       if (init_dbus () < 0) {
+               fprintf (stderr, "Cannot initialize DBus\n");
+               return 1;
+       }
+
+       dbus_connection_add_filter (dbus_conn, handler, NULL, NULL);
+
+       //ping = malloc(MSG_SIZE);
+       //for(i = 0; i < MSG_SIZE; i++) ping[i] = 'v';
+       //ping[MSG_SIZE] = '\0';
+       
+       message = dbus_message_new_method_call (DBUS_NAME, DBUS_PATH, DBUS_IFACE, "PING");
+       dbus_message_append_args (message, DBUS_TYPE_STRING, &ping, DBUS_TYPE_INVALID);
+       dbus_connection_send (dbus_conn, message, &message_serial);
+
+       gettimeofday (&tv_start, NULL);
+
+       dbus_message_unref (message);
+       while (dbus_connection_read_write (dbus_conn, -1)) {
+               while (dbus_connection_dispatch (dbus_conn) != DBUS_DISPATCH_COMPLETE) {
+               }
+       }
+       //free(ping);
+
+       return 0;
+}
diff --git a/samsung_tools/serwer.c b/samsung_tools/serwer.c
new file mode 100644 (file)
index 0000000..d4d010b
--- /dev/null
@@ -0,0 +1,119 @@
+//gcc -o server serwer.c -Wall -g -O0 `pkg-config --cflags --libs dbus-1`
+
+#include <dbus/dbus.h>
+#include <stdio.h>
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#define DBUS_NAME "com.samsung.pingpong"
+#define DBUS_PATH "/com/samsung/pingpong"
+#define DBUS_IFACE "com.samsung.pingpong"
+
+DBusConnection *dbus_conn;
+DBusObjectPathVTable *dbus_vtable;
+
+static DBusHandlerResult
+handler_function(DBusConnection *conn, DBusMessage *msg, void *user_data)
+{
+       DBusMessage *reply;
+
+       DBusError error;
+       dbus_error_init(&error);
+
+       char * ping;
+
+       if (!dbus_message_get_args ( msg,
+                                       &error,
+                                       DBUS_TYPE_STRING,
+                                       &ping,
+                                       DBUS_TYPE_INVALID)) 
+       {
+               fprintf(stderr, "Error - Invalid ping message!");
+               reply = dbus_message_new_error(msg, "com.misiek.pingpong.PingError","ping message corrupted");
+       } else {
+               //printf ("Received from client%s\n", ping);
+               reply = dbus_message_new_method_return(msg);
+               dbus_message_append_args (reply, DBUS_TYPE_STRING, &ping, DBUS_TYPE_INVALID);
+       }
+       dbus_connection_send(dbus_conn, reply, NULL);
+       dbus_message_unref(reply);
+
+       return DBUS_HANDLER_RESULT_HANDLED;
+}
+
+int
+init_dbus()
+{
+       DBusError error;
+       int flag;
+       dbus_error_init(&error);
+
+       dbus_conn = dbus_bus_get_private(DBUS_BUS_SESSION,&error);
+
+       if(dbus_error_is_set(&error)) 
+       {
+               fprintf(stderr,"Error- could not initizalize dbus session: %s \n", error.message);
+               return -1;
+       }
+
+       switch(flag = dbus_bus_request_name(dbus_conn, DBUS_NAME, DBUS_NAME_FLAG_DO_NOT_QUEUE, &error))
+       {
+               case DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER:
+               case DBUS_REQUEST_NAME_REPLY_IN_QUEUE:
+                       //printf("serwer.c request_name flags %d\n",flag);
+                       //printf("serwer.c Name registered as %s\n",DBUS_NAME);
+                       break;
+               default:
+                       printf("serwer.c Error - could not request name\n");
+                       return -1;
+       }
+
+       dbus_vtable = malloc(sizeof(DBusObjectPathVTable));
+       dbus_vtable->unregister_function = NULL;
+
+       dbus_vtable->message_function = handler_function;
+
+       if(!dbus_connection_register_object_path(dbus_conn,
+                                               DBUS_PATH,
+                                               dbus_vtable,
+                                               NULL)) 
+       {
+               printf("Error - could not register object path");
+               return -1;
+       }
+       
+       return 0;
+
+}
+
+void
+shutdown_dbus ()
+{
+       if (dbus_conn) {
+               dbus_connection_close(dbus_conn);
+               free(dbus_vtable);
+       }
+}
+
+
+int 
+main(int argc, char **argv)
+{
+       
+       if (init_dbus() < 0) {
+               fprintf(stderr, "serwer.c Error initializing dbus\n");
+       }
+       fprintf(stderr,"Waiting for clients\n");
+
+       while (dbus_connection_read_write(dbus_conn, -1)) {
+               while (dbus_connection_dispatch( dbus_conn) != DBUS_DISPATCH_COMPLETE){ 
+               }
+       }
+
+       shutdown_dbus();
+       return 0;
+}
+
diff --git a/samsung_tools/test-foxp-latency b/samsung_tools/test-foxp-latency
new file mode 100755 (executable)
index 0000000..c1fc9f7
--- /dev/null
@@ -0,0 +1,135 @@
+#!/usr/bin/expect
+
+set TARGET_HOST "localhost"
+set ROOT_DIR "/home/mike/JJ"
+set NUM_PASSES 50
+set RESULT_FILE [clock format [clock seconds] -format "latency-results-%Y.%m.%d.%H.%M.%S.csv"]
+
+set INVOCATIONS [list \
+    { "TTV default" "DISPLAY=:0" } \
+    [list "Custom lib, kdbus transport" "LD_LIBRARY_PATH=$ROOT_DIR/libs DBUS_SESSION_BUS_ADDRESS='kdbus:path=/dev/kdbus/1000-testtest/bus'"] \
+]
+
+#    [list "Custom lib, dbus transport" "DISPLAY=:0 LD_LIBRARY_PATH=$ROOT_DIR/libs"] \
+
+#set PROBES { \
+#    1000   { 1000 } \
+#    2000   { 1000 2000 } \
+#    5000   { 1000 2000 5000 } \
+#    10000  { 1000 2000 5000 10000 } \
+#    20000  { 1000 2000 5000 10000 20000 } \
+#    50000  { 1000 2000 5000 10000 20000 50000 } \
+#    75000  { 1000 2000 5000 10000 20000 50000 75000 } \
+#    100000 { 1000 2000 5000 10000 20000 50000 75000 } \
+#    200000 { 1000 2000 5000 10000 20000 50000 75000 } \
+#    300000 { 1000 2000 5000 10000 20000 50000 75000 } \
+#}
+
+
+# ***************************************************************************************************************************************************
+
+
+proc run_server { invocation } {
+    global TARGET_HOST ROOT_DIR
+    spawn ssh -t $TARGET_HOST "cd $ROOT_DIR/ipc-test; $invocation ./ping-server"
+    expect {
+        "Waiting for clients"    { return $spawn_id }
+        default                 {
+            puts ">>> ERROR <<<"
+            puts $expect_out(buffer)
+            puts ">>> ----- <<<"
+            return 0
+        }
+    }
+}
+
+
+proc terminate_server { server_id } {
+    set spawn_id $server_id
+    send "\x03"
+    expect {
+        "closed."   { return 1 }
+        default     { return 0 }
+    }
+}
+
+
+proc run_client { invocation } {
+    global TARGET_HOST ROOT_DIR
+    spawn ssh -t $TARGET_HOST "$invocation $ROOT_DIR/ipc-test/ping-client"
+    set round_trip_time 0
+    expect  {
+        -timeout 60
+        -re {avg RTT: (\d+) us} {
+            set round_trip_time $expect_out(1,string)
+        }
+        timeout { puts "ctrl-C"; send "\x03" }
+    }
+    return $round_trip_time
+}
+
+
+proc log_result { data { new_file 0 } } {
+    global RESULT_FILE
+    if { $new_file } {
+        puts "Storing results into file $RESULT_FILE"
+    }
+    set pl [open $RESULT_FILE [expr {$new_file ? "w" : "a"}]]
+    puts $pl [join $data ","]
+    close $pl
+}
+
+# ***************************************************************************************************************************************************
+
+
+log_user 0
+
+log_result { {"Test environment"} {"Round Trip Time [us]"} } 1
+
+# iterate over different invocations
+foreach invocation $INVOCATIONS {
+    set test_env [lindex $invocation 0]
+    puts "Test environment: $test_env"
+    puts ""
+    puts -nonewline "Bringing up server... "
+    set server [run_server [lindex $invocation 1]]
+    if { $server == 0 } {
+        puts "failed!"
+        continue
+    }
+    puts "OK!"        
+        
+    flush stdout
+    # average several passes to get more stable figures
+    set total 0
+    set passes 0
+    for { set run 1 } { $run <= $NUM_PASSES } { incr run } {
+        set result [run_client [lindex $invocation 1]]
+        if { $result > 0 } {
+            #puts -nonewline "."
+           puts "$result us"
+            incr total $result
+            incr passes
+        } else {
+            puts -nonewline "!"
+        }
+        flush stdout
+    }
+    if { $passes > 0 } {
+        set avg [expr $total / $passes]
+        puts " $avg us"
+        log_result [list "\"$test_env\"" $avg]
+    } else {
+        puts " no results!"
+    }
+    flush stdout
+        
+    
+    puts -nonewline "Terminating server... "
+    terminate_server $server
+    puts "OK!"
+    puts ""
+}
+
+log_user 1
+