Add UST and kernel streaming tests
authorDavid Goulet <dgoulet@efficios.com>
Tue, 24 Jul 2012 22:31:58 +0000 (18:31 -0400)
committerDavid Goulet <dgoulet@efficios.com>
Wed, 25 Jul 2012 14:27:44 +0000 (10:27 -0400)
Add four tests for network streaming. For user space, we have two tests
where tracing is started before and after the applications.

For kernel tests, we enable an event before and after the start command.

At this stage, some tests fails which indicates a bug.

Signed-off-by: David Goulet <dgoulet@efficios.com>
13 files changed:
.gitignore
configure.ac
tests/test_list.py
tests/tools/Makefile.am
tests/tools/runall.sh
tests/tools/streaming/Makefile.am [new file with mode: 0644]
tests/tools/streaming/gen-ust-events.c [new file with mode: 0644]
tests/tools/streaming/run [new file with mode: 0755]
tests/tools/streaming/run-kernel [new file with mode: 0755]
tests/tools/streaming/run-ust [new file with mode: 0755]
tests/tools/streaming/tp.c [new file with mode: 0644]
tests/tools/streaming/tp.h [new file with mode: 0644]
tests/utils.sh

index a4eb73bcfa9d08131d312dd5e66512d8d79310b9..b1295d4be3f931acb9cbf159232b30745f9cb5c8 100644 (file)
@@ -53,5 +53,6 @@ ust_global_event_basic
 gen-nevents
 gen-events-time
 gen-events
+gen-ust-events
 
 benchmark/
index 7934a5b27575ab6d7ed0f0cb1e74a8ba1128fa4b..17e6b67e02b339a9a28ef693f834442d94cc8ec4 100644 (file)
@@ -217,6 +217,7 @@ AC_CONFIG_FILES([
        tests/Makefile
        tests/kernel/Makefile
        tests/tools/Makefile
+       tests/tools/streaming/Makefile
        tests/ust/Makefile
        tests/ust/nprocesses/Makefile
        tests/ust/high-throughput/Makefile
index 818f660a4608cfc35328dab35a9a88e177d9ba06..cf16094c421404376d2f6c3d573eef40ca64bcba 100644 (file)
@@ -18,6 +18,18 @@ Tests = \
     'desc': "Test UST data structures and methods.",
     'success': 0, 'enabled': True
     },
+    {
+    'bin': "tools/streaming/run-ust", 'daemon': True, 'kern': False,
+    'name': "UST network streaming",
+    'desc': "Test user space tracing network streaming support",
+    'success': 0, 'enabled': True
+    },
+    {
+    'bin': "tools/streaming/run-kernel", 'daemon': True, 'kern': True,
+    'name': "Kernel network streaming",
+    'desc': "Test kernel tracing network streaming support",
+    'success': 0, 'enabled': True
+    },
 
     #### KERNEL ####
     {
index 0f4b69c04bbe735045f7d40a0cc62e5989c44d50..8bd7830c322f1ad2d31e208fff7ac841d658136b 100644 (file)
@@ -1,3 +1,5 @@
+SUBDIR = . streaming
+
 AM_CFLAGS = -g -Wall -I../
 AM_LDFLAGS = -lurcu -lurcu-cds
 
index 96c217cf591c7f4f817e8dcb1779dfda5d4147c4..b90e424893ed787bc1a5b799b6d1a4f659eb8767 100755 (executable)
@@ -2,7 +2,8 @@
 
 DIR=$(dirname $0)
 
-tests=( $DIR/test_kernel_data_trace $DIR/test_sessions $DIR/test_ust_data_trace )
+tests=( $DIR/test_kernel_data_trace $DIR/test_sessions $DIR/test_ust_data_trace \
+               $DIR/streaming/run )
 exit_code=0
 
 function start_tests ()
diff --git a/tests/tools/streaming/Makefile.am b/tests/tools/streaming/Makefile.am
new file mode 100644 (file)
index 0000000..251a378
--- /dev/null
@@ -0,0 +1,18 @@
+AM_CFLAGS = -I. -O2
+AM_LDFLAGS =
+
+if LTTNG_TOOLS_BUILD_WITH_LIBDL
+AM_LDFLAGS += -ldl
+endif
+if LTTNG_TOOLS_BUILD_WITH_LIBC_DL
+AM_LDFLAGS += -lc
+endif
+
+if HAVE_LIBLTTNG_UST_CTL
+noinst_PROGRAMS = gen-ust-events
+gen_ust_events_SOURCES = gen-ust-events.c tp.c tp.h
+gen_ust_events_LDADD = -llttng-ust
+endif
+
+noinst_SCRIPTS = run
+EXTRA_DIST = run
diff --git a/tests/tools/streaming/gen-ust-events.c b/tests/tools/streaming/gen-ust-events.c
new file mode 100644 (file)
index 0000000..1385119
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) - 2012 David Goulet <dgoulet@efficios.com>
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by the
+ * Free Software Foundation; version 2.1 of the License.
+ *
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
+ */
+
+#include <arpa/inet.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/mman.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#define TRACEPOINT_DEFINE
+#include "tp.h"
+
+int main(int argc, char **argv)
+{
+       int i, netint;
+       long values[] = { 1, 2, 3 };
+       char text[10] = "test";
+       double dbl = 2.0;
+       float flt = 2222.0;
+       /* Generate 30 events. */
+       unsigned int nr_iter = 100;
+       useconds_t nr_usec = 0;
+
+       if (argc >= 2) {
+               nr_iter = atoi(argv[1]);
+       }
+
+       if (argc == 3) {
+               /* By default, don't wait unless user specifies. */
+               nr_usec = atoi(argv[2]);
+       }
+
+       for (i = 0; i < nr_iter; i++) {
+               netint = htonl(i);
+               tracepoint(tp, tptest, i, netint, values, text, strlen(text), dbl,
+                               flt);
+               usleep(nr_usec);
+       }
+
+       return 0;
+}
diff --git a/tests/tools/streaming/run b/tests/tools/streaming/run
new file mode 100755 (executable)
index 0000000..d7ca754
--- /dev/null
@@ -0,0 +1,28 @@
+#!/bin/bash
+
+DIR=$(dirname $0)
+
+tests=( $DIR/run-kernel $DIR/run-ust )
+exit_code=0
+
+function start_tests ()
+{
+    for bin in ${tests[@]};
+    do
+               if [ ! -e $bin ]; then
+                       echo -e "$bin not found, passing"
+                       continue
+               fi
+
+        ./$bin
+        # Test must return 0 to pass.
+        if [ $? -ne 0 ]; then
+            exit_code=1
+            break
+        fi
+    done
+}
+
+start_tests
+
+exit $exit_code
diff --git a/tests/tools/streaming/run-kernel b/tests/tools/streaming/run-kernel
new file mode 100755 (executable)
index 0000000..8674edf
--- /dev/null
@@ -0,0 +1,123 @@
+#!/bin/bash
+#
+# Copyright (C) - 2012 David Goulet <dgoulet@efficios.com>
+#
+# This library is free software; you can redistribute it and/or modify it under
+# the terms of the GNU Lesser General Public License as published by the Free
+# Software Foundation; version 2.1 of the License.
+#
+# This library is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
+# details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with this library; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
+
+CURDIR=$(dirname $0)/
+TESTDIR=$CURDIR/../..
+EVENT_NAME="sched_switch"
+PID_RELAYD=0
+SESSION_NAME=""
+
+source $TESTDIR/utils.sh
+
+echo -e "\n---------------------------"
+echo -e " Streaming - Kernel tracing "
+echo -e "----------------------------"
+
+if [ "$(id -u)" != "0" ]; then
+       echo "This test must be running as root. Aborting"
+       # Exit status 0 so the tests can continue
+       exit 0
+fi
+
+# LTTng kernel modules check
+out=`ls /lib/modules/$(uname -r)/extra | grep lttng`
+if [ -z "$out" ]; then
+       echo "LTTng modules not detected. Aborting kernel tests!"
+       echo ""
+       # Exit status 0 so the tests can continue
+       exit 0
+fi
+
+function lttng_create_session
+{
+       echo -n "Creating session $SESSION_NAME... "
+       # Create session with default path
+       $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $SESSION_NAME >/dev/null 2>&1
+       if [ $? -eq 1 ]; then
+               echo -e '\e[1;31mFAILED\e[0m'
+               return 1
+       else
+               echo -e "\e[1;32mOK\e[0m"
+       fi
+}
+
+function lttng_enable_consumer_localhost
+{
+       echo -n "Enabling network consumer... "
+       # Create session with default path
+       $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-consumer -k net://localhost >/dev/null 2>&1
+       if [ $? -eq 1 ]; then
+               echo -e '\e[1;31mFAILED\e[0m'
+               return 1
+       else
+               echo -e "\e[1;32mOK\e[0m"
+       fi
+}
+
+function test_kernel_before_start ()
+{
+       echo -e "\n=== Testing kernel streaming with event enable BEFORE start\n"
+       lttng_create_session
+       lttng_enable_consumer_localhost
+       lttng_enable_kernel_event $SESSION_NAME $EVENT_NAME
+       start_tracing $SESSION_NAME
+       # Give a second
+       sleep 1
+       stop_tracing $SESSION_NAME
+       destroy_lttng_session $SESSION_NAME
+}
+
+function test_kernel_after_start ()
+{
+       echo -e "\n=== Testing kernel streaming with event enable AFTER start\n"
+       lttng_create_session
+       lttng_enable_consumer_localhost
+       start_tracing $SESSION_NAME
+       lttng_enable_kernel_event $SESSION_NAME $EVENT_NAME
+       # Give a second
+       sleep 1
+       stop_tracing $SESSION_NAME
+       destroy_lttng_session $SESSION_NAME
+}
+
+start_sessiond
+lttng_start_relayd
+
+tests=( test_kernel_before_start test_kernel_after_start )
+
+for fct_test in ${tests[@]};
+do
+       SESSION_NAME=$(randstring 16 0)
+       ${fct_test}
+
+       # Validate test
+       validate_trace $EVENT_NAME ~/lttng-traces/$HOSTNAME/$SESSION_NAME*
+       if [ $? -eq 0 ]; then
+               # Only delete if successful
+               rm -rf ~/lttng-traces/$HOSTNAME/$SESSION_NAME*
+               rm -rf ~/lttng-traces/$SESSION_NAME*
+       else
+               break
+       fi
+done
+
+echo ""
+stop_sessiond
+lttng_stop_relayd
+
+
+exit $out
diff --git a/tests/tools/streaming/run-ust b/tests/tools/streaming/run-ust
new file mode 100755 (executable)
index 0000000..0689201
--- /dev/null
@@ -0,0 +1,118 @@
+#!/bin/bash
+#
+# Copyright (C) - 2012 David Goulet <dgoulet@efficios.com>
+#
+# This library is free software; you can redistribute it and/or modify it under
+# the terms of the GNU Lesser General Public License as published by the Free
+# Software Foundation; version 2.1 of the License.
+#
+# This library is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
+# details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with this library; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
+
+CURDIR=$(dirname $0)/
+TESTDIR=$CURDIR/../..
+BIN_NAME="gen-ust-events"
+SESSION_NAME="stream"
+EVENT_NAME="tp:tptest"
+PID_RELAYD=0
+
+source $TESTDIR/utils.sh
+
+echo -e "\n-------------------------------"
+echo -e " Streaming - User space tracing "
+echo -e "--------------------------------"
+
+if [ ! -x "$CURDIR/$BIN_NAME" ]; then
+       echo -e "No UST nevents binary detected. Passing."
+       exit 0
+fi
+
+function lttng_create_session
+{
+       # Create session with default path
+       $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $SESSION_NAME >/dev/null 2>&1
+}
+
+function lttng_enable_consumer
+{
+       # Create session with default path
+       $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-consumer -u net://localhost/test >/dev/null 2>&1
+}
+
+function wait_apps
+{
+       echo -n "Waiting for applications to end"
+       while [ -n "$(pidof $BIN_NAME)" ]; do
+               echo -n "."
+               sleep 0.5
+       done
+       echo ""
+}
+
+# MUST set TESTDIR before calling those functions
+
+function test_ust_before_start ()
+{
+       echo -e "\n=== Testing UST streaming BEFORE tracing starts\n"
+       lttng_create_session
+       lttng_enable_consumer
+       enable_ust_lttng_event $SESSION_NAME $EVENT_NAME
+
+       # Run 5 times with a 1 second delay
+       ./$CURDIR/$BIN_NAME 5 1000000 >/dev/null 2>&1 &
+
+       start_tracing $SESSION_NAME
+
+       wait_apps
+       stop_tracing $SESSION_NAME
+       destroy_lttng_session $SESSION_NAME
+}
+
+function test_ust_after_start ()
+{
+       echo -e "\n=== Testing UST streaming AFTER tracing starts\n"
+       lttng_create_session
+       lttng_enable_consumer
+       enable_ust_lttng_event $SESSION_NAME $EVENT_NAME
+       start_tracing $SESSION_NAME
+
+       # Run 5 times with a 1 second delay
+       ./$CURDIR/$BIN_NAME 5 1000000 >/dev/null 2>&1 &
+
+       wait_apps
+       stop_tracing $SESSION_NAME
+       destroy_lttng_session $SESSION_NAME
+}
+
+start_sessiond
+lttng_start_relayd
+
+tests=( test_ust_before_start test_ust_after_start )
+
+for fct_test in ${tests[@]};
+do
+       SESSION_NAME=$(randstring 16 0)
+       ${fct_test}
+
+       # Validate test
+       validate_trace $EVENT_NAME ~/lttng-traces/$HOSTNAME/$SESSION_NAME*
+       if [ $? -eq 0 ]; then
+               # Only delete if successful
+               rm -rf ~/lttng-traces/$HOSTNAME/$SESSION_NAME*
+               rm -rf ~/lttng-traces/$SESSION_NAME*
+       else
+               break
+       fi
+done
+
+echo ""
+stop_sessiond
+lttng_stop_relayd
+
+exit $out
diff --git a/tests/tools/streaming/tp.c b/tests/tools/streaming/tp.c
new file mode 100644 (file)
index 0000000..a09561d
--- /dev/null
@@ -0,0 +1,15 @@
+/*
+ * Copyright (c) - 2012 David Goulet <dgoulet@efficios.com>
+ *
+ * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED OR
+ * IMPLIED. ANY USE IS AT YOUR OWN RISK.
+ *
+ * Permission is hereby granted to use or copy this program for any purpose,
+ * provided the above notices are retained on all copies.  Permission to modify
+ * the code and to distribute modified code is granted, provided the above
+ * notices are retained, and a notice that the code was modified is included
+ * with the above copyright notice.
+ */
+
+#define TRACEPOINT_CREATE_PROBES
+#include "tp.h"
diff --git a/tests/tools/streaming/tp.h b/tests/tools/streaming/tp.h
new file mode 100644 (file)
index 0000000..6ffbc32
--- /dev/null
@@ -0,0 +1,56 @@
+#undef TRACEPOINT_PROVIDER
+#define TRACEPOINT_PROVIDER tp
+
+#if !defined(_TRACEPOINT_TP_H) || defined(TRACEPOINT_HEADER_MULTI_READ)
+#define _TRACEPOINT_TP_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * Copyright (C) 2011  Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
+ * OR IMPLIED.  ANY USE IS AT YOUR OWN RISK.
+ *
+ * Permission is hereby granted to use or copy this program
+ * for any purpose,  provided the above notices are retained on all copies.
+ * Permission to modify the code and to distribute modified code is granted,
+ * provided the above notices are retained, and a notice that the code was
+ * modified is included with the above copyright notice.
+ */
+
+#include <lttng/tracepoint.h>
+
+TRACEPOINT_EVENT(tp, tptest,
+       TP_ARGS(int, anint, int, netint, long *, values,
+               char *, text, size_t, textlen,
+               double, doublearg, float, floatarg),
+       TP_FIELDS(
+               ctf_integer(int, intfield, anint)
+               ctf_integer_hex(int, intfield2, anint)
+               ctf_integer(long, longfield, anint)
+               ctf_integer_network(int, netintfield, netint)
+               ctf_integer_network_hex(int, netintfieldhex, netint)
+               ctf_array(long, arrfield1, values, 3)
+               ctf_array_text(char, arrfield2, text, 10)
+               ctf_sequence(char, seqfield1, text, size_t, textlen)
+               ctf_sequence_text(char, seqfield2, text, size_t, textlen)
+               ctf_string(stringfield, text)
+               ctf_float(float, floatfield, floatarg)
+               ctf_float(double, doublefield, doublearg)
+       )
+)
+
+#endif /* _TRACEPOINT_TP_H */
+
+#undef TRACEPOINT_INCLUDE_FILE
+#define TRACEPOINT_INCLUDE_FILE ./tp.h
+
+/* This part must be outside ifdef protection */
+#include <lttng/tracepoint-event.h>
+
+#ifdef __cplusplus
+}
+#endif
index 24defc7f8d67c7172ef37c73cb4e60f673845623..e1fd5cb91403a2fbfc41d51323594dcfc51ef663 100644 (file)
@@ -16,6 +16,7 @@
 # 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
 
 SESSIOND_BIN="lttng-sessiond"
+RELAYD_BIN="lttng-relayd"
 LTTNG_BIN="lttng"
 BABELTRACE_BIN="babeltrace"
 
@@ -39,6 +40,16 @@ function validate_kernel_version ()
        return 1
 }
 
+# Generate a random string 
+#  $1 = number of characters; defaults to 16
+#  $2 = include special characters; 1 = yes, 0 = no; defaults to yes
+function randstring() 
+{
+       [ "$2" == "0" ] && CHAR="[:alnum:]" || CHAR="[:graph:]"
+       cat /dev/urandom | tr -cd "$CHAR" | head -c ${1:-16}
+       echo
+}
+
 function spawn_sessiond ()
 {
        echo ""
@@ -64,6 +75,64 @@ function spawn_sessiond ()
        return 0
 }
 
+function lttng_enable_kernel_event
+{
+       sess_name=$1
+       event_name=$2
+
+       if [ -z $event_name ]; then
+               # Enable all event if no event name specified
+               $event_name="-a"
+       fi
+
+       echo -n "Enabling kernel event $event_name for session $sess_name"
+       $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event $event_name -s $sess_name -k >/dev/null 2>&1
+       if [ $? -eq 1 ]; then
+               echo -e '\e[1;31mFAILED\e[0m'
+               return 1
+       else
+               echo -e "\e[1;32mOK\e[0m"
+       fi
+}
+
+function lttng_start_relayd
+{
+       echo -e -n "Starting lttng-relayd... "
+       DIR=$(readlink -f $TESTDIR)
+
+       if [ -z $(pidof lt-$RELAYD_BIN) ]; then
+               $DIR/../src/bin/lttng-relayd/$RELAYD_BIN >/dev/null 2>&1 &
+               if [ $? -eq 1 ]; then
+                       echo -e "\e[1;31mFAILED\e[0m"
+                       return 1
+               else
+                       echo -e "\e[1;32mOK\e[0m"
+               fi
+       else
+               echo -e "\e[1;32mOK\e[0m"
+       fi
+}
+
+function lttng_stop_relayd
+{
+       PID_RELAYD=`pidof lt-$RELAYD_BIN`
+
+       echo -e -n "Killing lttng-relayd (pid: $PID_RELAYD)... "
+       kill $PID_RELAYD >/dev/null 2>&1
+       if [ $? -eq 1 ]; then
+               echo -e "\e[1;31mFAILED\e[0m"
+               return 1
+       else
+               out=1
+               while [ -n "$out" ]; do
+                       out=$(pidof lt-$RELAYD_BIN)
+                       sleep 0.5
+               done
+               echo -e "\e[1;32mOK\e[0m"
+               return 0
+       fi
+}
+
 function start_sessiond()
 {
        if [ -n $TEST_NO_SESSIOND ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
@@ -235,3 +304,25 @@ function trace_matches ()
                return 0
        fi
 }
+
+function validate_trace
+{
+       event_name=$1
+       trace_path=$2
+
+       which $BABELTRACE_BIN >/dev/null
+       if [ $? -eq 1 ]; then
+               echo "Babeltrace binary not found. Skipping trace matches"
+               return 0
+       fi
+
+       echo -n "Validating trace for event $event_name... "
+       traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | grep $event_name | wc -l)
+       if [ $traced -eq 0 ]; then
+               echo -e "\e[1;31mFAILED\e[0m"
+               return 1
+       else
+               echo -e "\e[1;32mOK\e[0m"
+               return 0
+       fi
+}
This page took 0.035263 seconds and 5 git commands to generate.