From 04c58b9e5fbdf3acc7565f989e5fcd11f0c23c57 Mon Sep 17 00:00:00 2001 From: Michal Eljasiewicz Date: Tue, 12 Nov 2013 10:09:26 +0100 Subject: [PATCH] [Foxp][Test] simple echo test with custom payload size Change-Id: I1a3dab513e2b64ec48f5c45a2c177e8245a0a5d1 --- samsung_tools/test_foxp_latency/Makefile | 13 ++ samsung_tools/test_foxp_latency/README | 1 + .../packaging/test_foxp_ping.manifest | 5 + .../packaging/test_foxp_ping.spec | 40 ++++++ .../packaging/test_foxp_ping.yaml | 13 ++ samsung_tools/test_foxp_latency/ping-client.c | 125 ++++++++++++++++++ samsung_tools/test_foxp_latency/ping-server.c | 119 +++++++++++++++++ samsung_tools/test_foxp_latency/test-foxp-latency | 144 +++++++++++++++++++++ 8 files changed, 460 insertions(+) create mode 100644 samsung_tools/test_foxp_latency/Makefile create mode 100644 samsung_tools/test_foxp_latency/README create mode 100644 samsung_tools/test_foxp_latency/packaging/test_foxp_ping.manifest create mode 100644 samsung_tools/test_foxp_latency/packaging/test_foxp_ping.spec create mode 100644 samsung_tools/test_foxp_latency/packaging/test_foxp_ping.yaml create mode 100644 samsung_tools/test_foxp_latency/ping-client.c create mode 100644 samsung_tools/test_foxp_latency/ping-server.c create mode 100755 samsung_tools/test_foxp_latency/test-foxp-latency diff --git a/samsung_tools/test_foxp_latency/Makefile b/samsung_tools/test_foxp_latency/Makefile new file mode 100644 index 0000000..5f0d30a --- /dev/null +++ b/samsung_tools/test_foxp_latency/Makefile @@ -0,0 +1,13 @@ +default: ping-client ping-server + +ping-client: + $(CC) -o ping-client ping-client.c -Wall -g -O0 `pkg-config --cflags --libs dbus-1` + +ping-server: + $(CC) -o ping-server ping-server.c -Wall -g -O0 `pkg-config --cflags --libs dbus-1` + +install: + + +clean: + -rm -f ping-client ping-server *~ diff --git a/samsung_tools/test_foxp_latency/README b/samsung_tools/test_foxp_latency/README new file mode 100644 index 0000000..c071446 --- /dev/null +++ b/samsung_tools/test_foxp_latency/README @@ -0,0 +1 @@ +.git directory is needed by GBS, just copy any .git dir here diff --git a/samsung_tools/test_foxp_latency/packaging/test_foxp_ping.manifest b/samsung_tools/test_foxp_latency/packaging/test_foxp_ping.manifest new file mode 100644 index 0000000..f5a44ec --- /dev/null +++ b/samsung_tools/test_foxp_latency/packaging/test_foxp_ping.manifest @@ -0,0 +1,5 @@ + + + + + diff --git a/samsung_tools/test_foxp_latency/packaging/test_foxp_ping.spec b/samsung_tools/test_foxp_latency/packaging/test_foxp_ping.spec new file mode 100644 index 0000000..6f41255 --- /dev/null +++ b/samsung_tools/test_foxp_latency/packaging/test_foxp_ping.spec @@ -0,0 +1,40 @@ +# +# Do not Edit! Generated by: +# spectacle version 0.13 +# +# >> macros +# << macros + +Name: test_foxp_ping +Summary: test_foxp_ping +Version: 1 +Release: 1.0 +Group: System/Base +License: GPLv2 +URL: none +Source0: %{name}-%{version}.tar.gz +Source100: test_foxp_ping.yaml +Source1001: %{name}.manifest +BuildRequires: pkgconfig(dbus-1) +#BuildRequires: pkgconfig(sqlite3) + +%description +Test for foxp + +%prep +%setup -q -n %{name}-%{version} + +# >> setup +# << setup + +%build +# >> build pre +# << build pre + +cp %{SOURCE1001} . +make %{?jobs:-j%jobs} + +# >> build post +# << build post +%install + diff --git a/samsung_tools/test_foxp_latency/packaging/test_foxp_ping.yaml b/samsung_tools/test_foxp_latency/packaging/test_foxp_ping.yaml new file mode 100644 index 0000000..93b3143 --- /dev/null +++ b/samsung_tools/test_foxp_latency/packaging/test_foxp_ping.yaml @@ -0,0 +1,13 @@ +Name: test_foxp_ping +Summary: GDBus example application 2 +Version: 1 +Release: 1.0 +Group: System/Base +License: GPLv2 +URL: none +Sources: + - "%{name}-%{version}.tar.gz" +Description: test_foxp_ping. + +PkgBR: none +Configure: none diff --git a/samsung_tools/test_foxp_latency/ping-client.c b/samsung_tools/test_foxp_latency/ping-client.c new file mode 100644 index 0000000..01584ec --- /dev/null +++ b/samsung_tools/test_foxp_latency/ping-client.c @@ -0,0 +1,125 @@ +#include + +#include + +#include +#include +#include + +#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"; +int MSG_SIZE = 1024*1024; +//#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 { + if(dbus_data[5] != 'v') { + fprintf (stderr,"error: string content not right! \n"); + return -1; + } + + 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 == 10) { + 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 (argc > 1) + MSG_SIZE = atoi(argv[1]); + + 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-1] = '\0'; + //printf("MSG_SIZE: %i\n", MSG_SIZE); + + 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/test_foxp_latency/ping-server.c b/samsung_tools/test_foxp_latency/ping-server.c new file mode 100644 index 0000000..d4d010b --- /dev/null +++ b/samsung_tools/test_foxp_latency/ping-server.c @@ -0,0 +1,119 @@ +//gcc -o server serwer.c -Wall -g -O0 `pkg-config --cflags --libs dbus-1` + +#include +#include + +#include +#include +#include +#include + +#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/test-foxp-latency b/samsung_tools/test_foxp_latency/test-foxp-latency new file mode 100755 index 0000000..8e8eeb8 --- /dev/null +++ b/samsung_tools/test_foxp_latency/test-foxp-latency @@ -0,0 +1,144 @@ +#!/usr/bin/expect + +set TARGET_HOST "foxp2" +set ROOT_DIR "/root" +set NUM_PASSES 3 +#set DATA_SIZE_BYTES 1024 +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/0-kdbus/bus'"] \ +] + +# [list "Custom lib, dbus transport" "DISPLAY=:0 LD_LIBRARY_PATH=$ROOT_DIR/libs"] \ + +set DATA_SIZES_BYTES { 10 100 1024 10240 102400 1048576 10485760 } + +#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 data_size_bytes} { + global TARGET_HOST ROOT_DIR + spawn ssh -t $TARGET_HOST "$invocation $ROOT_DIR/ipc-test/ping-client $data_size_bytes" + 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"} {Data size [Bytes]} {"Round Trip Time [ms]"} } 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!" + puts "Test start, passes: $NUM_PASSES" + flush stdout + + for { set p 0 } { $p < [llength $DATA_SIZES_BYTES] } { incr p } { + set data_size_bytes [lindex $DATA_SIZES_BYTES $p] + # 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] $data_size_bytes] + if { $result >= 0 } { + puts -nonewline "." + #puts "iteration $passes, data_size: $data_size_bytes : $result us" + incr total $result + incr passes + } else { + puts -nonewline "!" + } + flush stdout + } + if { $passes > 0 } { + set avg [expr $total / $passes] + puts " data_size $data_size_bytes B $avg us" + log_result [list "\"$test_env\"" $data_size_bytes $avg] + } else { + puts " no results!" + } + #puts " data_size: $data_size_bytes" + } + + flush stdout + + + puts -nonewline "Terminating server... " + terminate_server $server + puts "OK!" + puts "" +} + +log_user 1 + -- 2.7.4