From f4e40ab68a515750cdde6877b53fafb5210ceac6 Mon Sep 17 00:00:00 2001 From: David Goulet Date: Tue, 24 Jul 2012 18:31:58 -0400 Subject: [PATCH] Add UST and kernel streaming tests 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 --- .gitignore | 1 + configure.ac | 1 + tests/test_list.py | 12 +++ tests/tools/Makefile.am | 2 + tests/tools/runall.sh | 3 +- tests/tools/streaming/Makefile.am | 18 ++++ tests/tools/streaming/gen-ust-events.c | 59 ++++++++++++ tests/tools/streaming/run | 28 ++++++ tests/tools/streaming/run-kernel | 123 +++++++++++++++++++++++++ tests/tools/streaming/run-ust | 118 ++++++++++++++++++++++++ tests/tools/streaming/tp.c | 15 +++ tests/tools/streaming/tp.h | 56 +++++++++++ tests/utils.sh | 91 ++++++++++++++++++ 13 files changed, 526 insertions(+), 1 deletion(-) create mode 100644 tests/tools/streaming/Makefile.am create mode 100644 tests/tools/streaming/gen-ust-events.c create mode 100755 tests/tools/streaming/run create mode 100755 tests/tools/streaming/run-kernel create mode 100755 tests/tools/streaming/run-ust create mode 100644 tests/tools/streaming/tp.c create mode 100644 tests/tools/streaming/tp.h diff --git a/.gitignore b/.gitignore index a4eb73bcf..b1295d4be 100644 --- a/.gitignore +++ b/.gitignore @@ -53,5 +53,6 @@ ust_global_event_basic gen-nevents gen-events-time gen-events +gen-ust-events benchmark/ diff --git a/configure.ac b/configure.ac index 7934a5b27..17e6b67e0 100644 --- a/configure.ac +++ b/configure.ac @@ -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 diff --git a/tests/test_list.py b/tests/test_list.py index 818f660a4..cf16094c4 100644 --- a/tests/test_list.py +++ b/tests/test_list.py @@ -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 #### { diff --git a/tests/tools/Makefile.am b/tests/tools/Makefile.am index 0f4b69c04..8bd7830c3 100644 --- a/tests/tools/Makefile.am +++ b/tests/tools/Makefile.am @@ -1,3 +1,5 @@ +SUBDIR = . streaming + AM_CFLAGS = -g -Wall -I../ AM_LDFLAGS = -lurcu -lurcu-cds diff --git a/tests/tools/runall.sh b/tests/tools/runall.sh index 96c217cf5..b90e42489 100755 --- a/tests/tools/runall.sh +++ b/tests/tools/runall.sh @@ -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 index 000000000..251a378f8 --- /dev/null +++ b/tests/tools/streaming/Makefile.am @@ -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 index 000000000..1385119d7 --- /dev/null +++ b/tests/tools/streaming/gen-ust-events.c @@ -0,0 +1,59 @@ +/* + * Copyright (C) - 2012 David Goulet + * + * 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 +#include +#include +#include +#include +#include +#include +#include +#include + +#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 index 000000000..d7ca754fd --- /dev/null +++ b/tests/tools/streaming/run @@ -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 index 000000000..8674edfac --- /dev/null +++ b/tests/tools/streaming/run-kernel @@ -0,0 +1,123 @@ +#!/bin/bash +# +# Copyright (C) - 2012 David Goulet +# +# 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 index 000000000..068920162 --- /dev/null +++ b/tests/tools/streaming/run-ust @@ -0,0 +1,118 @@ +#!/bin/bash +# +# Copyright (C) - 2012 David Goulet +# +# 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 index 000000000..a09561d70 --- /dev/null +++ b/tests/tools/streaming/tp.c @@ -0,0 +1,15 @@ +/* + * Copyright (c) - 2012 David Goulet + * + * 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 index 000000000..6ffbc32ab --- /dev/null +++ b/tests/tools/streaming/tp.h @@ -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 + * + * 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 + +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 + +#ifdef __cplusplus +} +#endif diff --git a/tests/utils.sh b/tests/utils.sh index 24defc7f8..e1fd5cb91 100644 --- a/tests/utils.sh +++ b/tests/utils.sh @@ -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 +} -- 2.34.1