From b6ca8ef5adf433f7f0bbd4bb4858146ef25cd4fd Mon Sep 17 00:00:00 2001 From: David Goulet Date: Tue, 17 Jan 2012 13:38:48 -0500 Subject: [PATCH] Add UST test ust-nprocesses Simple to test that launches 100 instrumented applications and validate that they are all registered to the session daemon. After that, one event is enabled, tracing starts/stops and finally the tracing session gets destroyed. Signed-off-by: David Goulet --- .gitignore | 1 + configure.ac | 1 + tests/Makefile.am | 2 +- tests/runall.sh | 2 +- tests/ust-nprocesses/Makefile.am | 8 +++ tests/ust-nprocesses/gen-events-time.c | 61 +++++++++++++++++++++++ tests/ust-nprocesses/run | 67 ++++++++++++++++++++++++++ tests/ust-nprocesses/tp.c | 16 ++++++ tests/ust-nprocesses/ust_gen_event.h | 56 +++++++++++++++++++++ 9 files changed, 212 insertions(+), 2 deletions(-) create mode 100644 tests/ust-nprocesses/Makefile.am create mode 100644 tests/ust-nprocesses/gen-events-time.c create mode 100755 tests/ust-nprocesses/run create mode 100644 tests/ust-nprocesses/tp.c create mode 100644 tests/ust-nprocesses/ust_gen_event.h diff --git a/.gitignore b/.gitignore index 9c70e0f58..afa850578 100644 --- a/.gitignore +++ b/.gitignore @@ -43,5 +43,6 @@ tests/kernel_event_basic tests/ust_global_all_events_basic tests/ust_global_event_basic tests/ust-nevents/gen-nevents +tests/ust-nprocesses/gen-events-time benchmark/ diff --git a/configure.ac b/configure.ac index af522eeb0..433e3ad91 100644 --- a/configure.ac +++ b/configure.ac @@ -145,6 +145,7 @@ AC_CONFIG_FILES([ lttng/Makefile tests/Makefile tests/ust-nevents/Makefile + tests/ust-nprocesses/Makefile doc/Makefile ]) diff --git a/tests/Makefile.am b/tests/Makefile.am index 96d4f6403..27c7c7744 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,4 +1,4 @@ -SUBDIRS = . ust-nevents +SUBDIRS = . ust-nevents ust-nprocesses AM_CFLAGS=-I$(top_srcdir)/include -I$(top_srcdir)/libkernelctl \ -I$(top_srcdir)/liblttngctl -g -Wall -lurcu -lurcu-cds diff --git a/tests/runall.sh b/tests/runall.sh index 17be11817..eadeeb912 100755 --- a/tests/runall.sh +++ b/tests/runall.sh @@ -20,7 +20,7 @@ #### ADD TESTS HERE #### test_suite=( test_sessions test_kernel_data_trace test_ust_data_trace - lttng/runall.sh ust-nevents/run ) + lttng/runall.sh ust-nevents/run ust-nprocesses/run ) #### END TESTS HERE #### diff --git a/tests/ust-nprocesses/Makefile.am b/tests/ust-nprocesses/Makefile.am new file mode 100644 index 000000000..e1df41d36 --- /dev/null +++ b/tests/ust-nprocesses/Makefile.am @@ -0,0 +1,8 @@ +AM_CPPFLAGS = -ldl -I. -O2 + +noinst_PROGRAMS = gen-events-time +gen_events_time_SOURCES = gen-events-time.c tp.c ust_gen_event.h +gen_events_time_LDADD = -llttng-ust + +noinst_SCRIPTS = run +EXTRA_DIST = run diff --git a/tests/ust-nprocesses/gen-events-time.c b/tests/ust-nprocesses/gen-events-time.c new file mode 100644 index 000000000..bc5b68ca6 --- /dev/null +++ b/tests/ust-nprocesses/gen-events-time.c @@ -0,0 +1,61 @@ +/* + * Copyright (C) - 2009 Pierre-Marc Fournier + * Copyright (C) - 2011 Mathieu Desnoyers + * 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 +#include +#include + +#define TRACEPOINT_DEFINE +#include "ust_gen_event.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; + /* Default loop time is 60 sec since each round sleeps 1 sec */ + unsigned int nr_iter = 60; + + fclose(stdout); + fclose(stderr); + fclose(stdin); + + if (argc == 2) { + nr_iter = atoi(argv[1]); + } + + for (i = 0; i < nr_iter; i++) { + netint = htonl(i); + tracepoint(ust_gen_event, tptest, i, netint, values, text, + strlen(text), dbl, flt); + sleep(1); + } + + return 0; +} diff --git a/tests/ust-nprocesses/run b/tests/ust-nprocesses/run new file mode 100755 index 000000000..dcaa379ed --- /dev/null +++ b/tests/ust-nprocesses/run @@ -0,0 +1,67 @@ +#!/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 + +TESTDIR=$(dirname $0)/.. +NR_ITER=100 +TEST_BIN_NAME="gen-events-time" +SESSION_NAME="ust-nprocesses" +EVENT_NAME="ust_gen_event:tptest" +TRACE_PATH=$(mktemp -d) +TEST_WAIT_SEC=3 + +source $TESTDIR/utils.sh + +echo -e "\n-------------------------------------" +echo -e "UST tracer - Generate $NR_ITER process" +echo -e "---------------------------------------" + +# MUST set TESTDIR before calling those functions + +# Start test for 1000 seconds + +for i in `seq 1 $NR_ITER` +do + ./$(dirname $0)/$TEST_BIN_NAME 1000 >/dev/null 2>&1 & +done + +echo -n "Validating registered apps: " + +listing=$($TESTDIR/../lttng/$LTTNG_BIN list -u) +reg_app_count=$(echo -n $listing | sed "s/$TEST_BIN_NAME/$TEST_BIN_NAME\n/g" | grep "$TEST_BIN_NAME" | wc -l) +if [ "$reg_app_count" -ne "$NR_ITER" ]; then + echo -e "$reg_app_count apps listed. Expected $NR_ITER \e[1;31mFAILED\e[0m" +else + echo -e "\e[1;32mOK\e[0m" +fi + +create_lttng_session $SESSION_NAME $TRACE_PATH + +enable_ust_lttng_event $SESSION_NAME $EVENT_NAME +start_tracing $SESSION_NAME + +echo "Sleeping $TEST_WAIT_SEC seconds for tracing to start everywhere" +sleep $TEST_WAIT_SEC + +stop_tracing $SESSION_NAME +destroy_lttng_session $SESSION_NAME + +rm -rf $TRACE_PATH + +echo -e -n "Killing all spawned applications..." +killall -q $TEST_BIN_NAME >/dev/null 2>&1 & +echo -e "\e[1;32mOK\e[0m" +exit 0 diff --git a/tests/ust-nprocesses/tp.c b/tests/ust-nprocesses/tp.c new file mode 100644 index 000000000..438139ebc --- /dev/null +++ b/tests/ust-nprocesses/tp.c @@ -0,0 +1,16 @@ +/* + * Copyright (c) - 2011 Mathieu Desnoyers + * 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 "ust_gen_event.h" diff --git a/tests/ust-nprocesses/ust_gen_event.h b/tests/ust-nprocesses/ust_gen_event.h new file mode 100644 index 000000000..df53ccc98 --- /dev/null +++ b/tests/ust-nprocesses/ust_gen_event.h @@ -0,0 +1,56 @@ +#undef TRACEPOINT_PROVIDER +#define TRACEPOINT_PROVIDER ust_gen_event + +#if !defined(_TRACEPOINT_UST_GEN_EVENT_H) || defined(TRACEPOINT_HEADER_MULTI_READ) +#define _TRACEPOINT_UST_GEN_EVENT_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(ust_gen_event, 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_UST_GEN_EVENT_H */ + +#undef TRACEPOINT_INCLUDE_FILE +#define TRACEPOINT_INCLUDE_FILE ./ust_gen_event.h + +/* This part must be outside ifdef protection */ +#include + +#ifdef __cplusplus +} +#endif -- 2.34.1