From d3e8f6bb8554af02b881990fbb5445ac6a4f4d98 Mon Sep 17 00:00:00 2001 From: David Goulet Date: Mon, 16 Jan 2012 17:25:49 -0500 Subject: [PATCH] Add UST test for n events using validation ust-nevents tests an instrumented application generating 100 events and validating that those events are found using babeltrace (need to be installed). Adds the tests/utils.sh which is a family of function used to interact with lttng cli. There is also a trace_matches function which uses babeltrace to find string patterns. Also, the session daemon is spawned at the beginning of runall.sh and killed at the end. This means that all tests are done on a single session daemon instance. Thus, session name across tests have to be unique! From now on, each test should use the file name as a unique identifier for the session name. Finally, fixed the session name for all tests. At this commit, "make check" or "sudo make check" should pass. Signed-off-by: David Goulet --- .gitignore | 1 + configure.ac | 1 + tests/Makefile.am | 2 + tests/lttng/kernel_all_events_basic.c | 13 +- tests/lttng/kernel_event_basic.c | 2 +- tests/lttng/run-kernel-tests.sh | 30 +--- tests/lttng/run-ust-global-tests.sh | 30 +--- tests/lttng/ust_global_all_events_basic.c | 13 +- tests/lttng/ust_global_event_basic.c | 2 +- tests/runall.sh | 14 +- tests/test_ust_data_trace.c | 195 ++++++++++++++++++++++ tests/ust-nevents/Makefile.am | 8 + tests/ust-nevents/gen-nevents.c | 55 ++++++ tests/ust-nevents/run | 45 +++++ tests/ust-nevents/tp.c | 16 ++ tests/ust-nevents/ust_gen_nevents.h | 56 +++++++ tests/utils.sh | 139 +++++++++++++++ 17 files changed, 560 insertions(+), 62 deletions(-) create mode 100644 tests/test_ust_data_trace.c create mode 100644 tests/ust-nevents/Makefile.am create mode 100644 tests/ust-nevents/gen-nevents.c create mode 100755 tests/ust-nevents/run create mode 100644 tests/ust-nevents/tp.c create mode 100644 tests/ust-nevents/ust_gen_nevents.h create mode 100644 tests/utils.sh diff --git a/.gitignore b/.gitignore index d7e624f6a..9c70e0f58 100644 --- a/.gitignore +++ b/.gitignore @@ -42,5 +42,6 @@ tests/kernel_all_events_basic tests/kernel_event_basic tests/ust_global_all_events_basic tests/ust_global_event_basic +tests/ust-nevents/gen-nevents benchmark/ diff --git a/configure.ac b/configure.ac index 9abc477c5..af522eeb0 100644 --- a/configure.ac +++ b/configure.ac @@ -144,6 +144,7 @@ AC_CONFIG_FILES([ lttng-sessiond/Makefile lttng/Makefile tests/Makefile + tests/ust-nevents/Makefile doc/Makefile ]) diff --git a/tests/Makefile.am b/tests/Makefile.am index 10db1bb6b..96d4f6403 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,3 +1,5 @@ +SUBDIRS = . ust-nevents + AM_CFLAGS=-I$(top_srcdir)/include -I$(top_srcdir)/libkernelctl \ -I$(top_srcdir)/liblttngctl -g -Wall -lurcu -lurcu-cds diff --git a/tests/lttng/kernel_all_events_basic.c b/tests/lttng/kernel_all_events_basic.c index fd3926d1f..79c2b66ac 100644 --- a/tests/lttng/kernel_all_events_basic.c +++ b/tests/lttng/kernel_all_events_basic.c @@ -35,6 +35,7 @@ int main(int argc, char **argv) struct lttng_domain dom; struct lttng_event event; char *channel_name = "channel0"; + char *session_name = "kernel_all_events_basic"; int ret = 0; dom.type = LTTNG_DOMAIN_KERNEL; @@ -56,14 +57,14 @@ int main(int argc, char **argv) } printf("Creating tracing session (%s): ", argv[1]); - if ((ret = lttng_create_session("test", argv[1])) < 0) { + if ((ret = lttng_create_session(session_name, argv[1])) < 0) { printf("error creating the session : %s\n", lttng_strerror(ret)); goto create_fail; } PRINT_OK(); printf("Creating session handle: "); - if ((handle = lttng_create_handle("test", &dom)) == NULL) { + if ((handle = lttng_create_handle(session_name, &dom)) == NULL) { printf("error creating handle: %s\n", lttng_strerror(ret)); goto handle_fail; } @@ -77,7 +78,7 @@ int main(int argc, char **argv) PRINT_OK(); printf("Start tracing: "); - if ((ret = lttng_start_tracing("test")) < 0) { + if ((ret = lttng_start_tracing(session_name)) < 0) { printf("error starting tracing: %s\n", lttng_strerror(ret)); goto start_fail; } @@ -86,14 +87,14 @@ int main(int argc, char **argv) sleep(2); printf("Stop tracing: "); - if ((ret = lttng_stop_tracing("test")) < 0) { + if ((ret = lttng_stop_tracing(session_name)) < 0) { printf("error stopping tracing: %s\n", lttng_strerror(ret)); goto stop_fail; } PRINT_OK(); printf("Destroy tracing session: "); - if ((ret = lttng_destroy_session("test")) < 0) { + if ((ret = lttng_destroy_session(session_name)) < 0) { printf("error destroying session: %s\n", lttng_strerror(ret)); } PRINT_OK(); @@ -108,7 +109,7 @@ handle_fail: stop_fail: start_fail: enable_fail: - lttng_destroy_session("test"); + lttng_destroy_session(session_name); lttng_destroy_handle(handle); return 1; diff --git a/tests/lttng/kernel_event_basic.c b/tests/lttng/kernel_event_basic.c index b33f691fd..fb1cf42b0 100644 --- a/tests/lttng/kernel_event_basic.c +++ b/tests/lttng/kernel_event_basic.c @@ -40,7 +40,7 @@ int main(int argc, char **argv) int ret = 0; - char *session_name = "kernel_event"; + char *session_name = "kernel_event_basic"; dom.type = LTTNG_DOMAIN_KERNEL; diff --git a/tests/lttng/run-kernel-tests.sh b/tests/lttng/run-kernel-tests.sh index 04814fc9c..d5a41382b 100755 --- a/tests/lttng/run-kernel-tests.sh +++ b/tests/lttng/run-kernel-tests.sh @@ -1,6 +1,9 @@ #!/bin/bash SESSIOND_BIN="lttng-sessiond" +TESTDIR=$(dirname $0)/.. + +source $TESTDIR/utils.sh tmpdir=`mktemp -d` tests=( kernel_event_basic kernel_all_events_basic ) @@ -16,9 +19,10 @@ function start_tests () exit_code=1 break fi - # Cleaning up - rm -rf $tmpdir done + + # Cleaning up + rm -rf $tmpdir } function check_lttng_modules () @@ -40,31 +44,9 @@ echo -e "--------------------------------------------------" check_lttng_modules -if [ -z $(pidof $SESSIOND_BIN) ]; then - echo -n "Starting session daemon... " - ../lttng-sessiond/$SESSIOND_BIN --daemonize --quiet - if [ $? -eq 1 ]; then - echo -e '\e[1;31mFAILED\e[0m' - rm -rf $tmpdir - exit 1 - else - echo -e "\e[1;32mOK\e[0m" - fi -fi - -PID_SESSIOND=`pidof lt-$SESSIOND_BIN` - # Simply wait for the session daemon bootstrap sleep 1 start_tests -echo -e -n "\nKilling session daemon... " -kill $PID_SESSIOND >/dev/null 2>&1 -if [ $? -eq 1 ]; then - echo -e '\e[1;31mFAILED\e[0m' -else - echo -e "\e[1;32mOK\e[0m" -fi - exit $exit_code diff --git a/tests/lttng/run-ust-global-tests.sh b/tests/lttng/run-ust-global-tests.sh index bfcb974bf..135c8a2b4 100755 --- a/tests/lttng/run-ust-global-tests.sh +++ b/tests/lttng/run-ust-global-tests.sh @@ -1,6 +1,9 @@ #!/bin/bash SESSIOND_BIN="lttng-sessiond" +TESTDIR=$(dirname $0)/.. + +source $TESTDIR/utils.sh tmpdir=`mktemp -d` tests=( ust_global_event_basic ust_global_all_events_basic ) @@ -16,27 +19,16 @@ function start_tests () exit_code=1 break fi - # Cleaning up - rm -rf $tmpdir done + + # Cleaning up + rm -rf $tmpdir } echo -e "\n-------------------------------------------" -echo -e "UST tracer - GLOBAL DOMAIN (LTTNG_DOMAIN_UST)" +echo -e "UST tracer - Global domain (LTTNG_DOMAIN_UST)" echo -e "---------------------------------------------" -if [ -z $(pidof $SESSIOND_BIN) ]; then - echo -n "Starting session daemon... " - ../lttng-sessiond/$SESSIOND_BIN --daemonize --quiet - if [ $? -eq 1 ]; then - echo -e '\e[1;31mFAILED\e[0m' - rm -rf $tmpdir - exit 1 - else - echo -e "\e[1;32mOK\e[0m" - fi -fi - PID_SESSIOND=`pidof lt-$SESSIOND_BIN` # Simply wait for the session daemon bootstrap @@ -44,12 +36,4 @@ sleep 1 start_tests -echo -e -n "\nKilling session daemon... " -kill $PID_SESSIOND >/dev/null 2>&1 -if [ $? -eq 1 ]; then - echo -e '\e[1;31mFAILED\e[0m' -else - echo -e "\e[1;32mOK\e[0m" -fi - exit $exit_code diff --git a/tests/lttng/ust_global_all_events_basic.c b/tests/lttng/ust_global_all_events_basic.c index 7c0a5624e..32c39fb5e 100644 --- a/tests/lttng/ust_global_all_events_basic.c +++ b/tests/lttng/ust_global_all_events_basic.c @@ -35,6 +35,7 @@ int main(int argc, char **argv) struct lttng_domain dom; struct lttng_event event; char *channel_name = "channel0"; + char *session_name = "ust_global_all_events_basic"; int ret = 0; dom.type = LTTNG_DOMAIN_UST; @@ -51,14 +52,14 @@ int main(int argc, char **argv) } printf("Creating tracing session (%s): ", argv[1]); - if ((ret = lttng_create_session("test", argv[1])) < 0) { + if ((ret = lttng_create_session(session_name, argv[1])) < 0) { printf("error creating the session : %s\n", lttng_strerror(ret)); goto create_fail; } PRINT_OK(); printf("Creating session handle: "); - if ((handle = lttng_create_handle("test", &dom)) == NULL) { + if ((handle = lttng_create_handle(session_name, &dom)) == NULL) { printf("error creating handle: %s\n", lttng_strerror(ret)); goto handle_fail; } @@ -72,7 +73,7 @@ int main(int argc, char **argv) PRINT_OK(); printf("Start tracing: "); - if ((ret = lttng_start_tracing("test")) < 0) { + if ((ret = lttng_start_tracing(session_name)) < 0) { printf("error starting tracing: %s\n", lttng_strerror(ret)); goto start_fail; } @@ -81,14 +82,14 @@ int main(int argc, char **argv) sleep(2); printf("Stop tracing: "); - if ((ret = lttng_stop_tracing("test")) < 0) { + if ((ret = lttng_stop_tracing(session_name)) < 0) { printf("error stopping tracing: %s\n", lttng_strerror(ret)); goto stop_fail; } PRINT_OK(); printf("Destroy tracing session: "); - if ((ret = lttng_destroy_session("test")) < 0) { + if ((ret = lttng_destroy_session(session_name)) < 0) { printf("error destroying session: %s\n", lttng_strerror(ret)); } PRINT_OK(); @@ -103,7 +104,7 @@ handle_fail: stop_fail: start_fail: enable_fail: - lttng_destroy_session("test"); + lttng_destroy_session(session_name); lttng_destroy_handle(handle); return 1; diff --git a/tests/lttng/ust_global_event_basic.c b/tests/lttng/ust_global_event_basic.c index baa9ff836..d3a103033 100644 --- a/tests/lttng/ust_global_event_basic.c +++ b/tests/lttng/ust_global_event_basic.c @@ -38,7 +38,7 @@ int main(int argc, char **argv) int ret = 0; - char *session_name = "ust_event_basic"; + char *session_name = "ust_global_event_basic"; dom.type = LTTNG_DOMAIN_UST; diff --git a/tests/runall.sh b/tests/runall.sh index ec6fb3928..17be11817 100755 --- a/tests/runall.sh +++ b/tests/runall.sh @@ -19,10 +19,20 @@ #### ADD TESTS HERE #### -test_suite=( test_sessions test_kernel_data_trace test_ust_data_trace lttng/runall.sh ) +test_suite=( test_sessions test_kernel_data_trace test_ust_data_trace + lttng/runall.sh ust-nevents/run ) #### END TESTS HERE #### +TESTDIR=$(dirname $0) + +source $TESTDIR/utils.sh + +start_sessiond +if [ $? -ne 0 ]; then + exit 1 +fi + for bin in ${test_suite[@]}; do ./$bin @@ -30,9 +40,11 @@ do if [ $? -ne 0 ]; then echo -e '\e[1;31mFAIL\e[0m' echo "" + stop_sessiond exit 1 fi done echo "" +stop_sessiond exit 0 diff --git a/tests/test_ust_data_trace.c b/tests/test_ust_data_trace.c new file mode 100644 index 000000000..4e4b29b32 --- /dev/null +++ b/tests/test_ust_data_trace.c @@ -0,0 +1,195 @@ +/* + * Copyright (c) 2011 David Goulet + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * as published by the Free Software Foundation; only version 2 + * of the License. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include +#include + +#include "lttng/lttng.h" +#include "lttng-sessiond/lttng-ust-abi.h" +#include "lttng-share.h" +#include "lttng-sessiond/trace-ust.h" +#include "utils.h" + +/* This path will NEVER be created in this test */ +#define PATH1 "/tmp/.test-junk-lttng" + +/* For lttngerr.h */ +int opt_quiet = 1; +int opt_verbose = 0; + +static const char alphanum[] = + "0123456789" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz"; + +static struct ltt_ust_session *usess; +static struct lttng_domain dom; + +/* + * Return random string of 10 characters. + */ +static char *get_random_string(void) +{ + int i; + char *str = malloc(11); + + for (i = 0; i < 10; i++) { + str[i] = alphanum[rand() % (sizeof(alphanum) - 1)]; + } + + str[10] = '\0'; + + return str; +} + +static void create_one_ust_session(void) +{ + printf("Create UST session: "); + + dom.type = LTTNG_DOMAIN_UST; + + usess = trace_ust_create_session(PATH1, 42, &dom); + assert(usess != NULL); + PRINT_OK(); + + printf("Validating UST session: "); + assert(usess->id == 42); + assert(usess->start_trace == 0); + assert(usess->domain_global.channels != NULL); + assert(usess->domain_pid != NULL); + assert(usess->domain_exec != NULL); + assert(usess->uid == 0); + assert(usess->gid == 0); + PRINT_OK(); + + trace_ust_destroy_session(usess); +} + +static void create_ust_metadata(void) +{ + struct ltt_ust_metadata *metadata; + + assert(usess != NULL); + + printf("Create UST metadata: "); + metadata = trace_ust_create_metadata(PATH1); + assert(metadata != NULL); + PRINT_OK(); + + printf("Validating UST session metadata: "); + assert(metadata->handle == -1); + assert(strlen(metadata->pathname)); + assert(metadata->attr.overwrite + == DEFAULT_CHANNEL_OVERWRITE); + assert(metadata->attr.subbuf_size + == DEFAULT_METADATA_SUBBUF_SIZE); + assert(metadata->attr.num_subbuf + == DEFAULT_METADATA_SUBBUF_NUM); + assert(metadata->attr.switch_timer_interval + == DEFAULT_CHANNEL_SWITCH_TIMER); + assert(metadata->attr.read_timer_interval + == DEFAULT_CHANNEL_READ_TIMER); + assert(metadata->attr.output == LTTNG_UST_MMAP); + PRINT_OK(); + + trace_ust_destroy_metadata(metadata); +} + +static void create_ust_channel(void) +{ + struct ltt_ust_channel *uchan; + struct lttng_channel attr; + + strncpy(attr.name, "channel0", 8); + + printf("Creating UST channel: "); + uchan = trace_ust_create_channel(&attr, PATH1); + assert(uchan != NULL); + PRINT_OK(); + + printf("Validating UST channel: "); + assert(uchan->enabled == 0); + assert(strcmp(PATH1, uchan->pathname) == 0); + assert(strncmp(uchan->name, "channel0", 8) == 0); + assert(uchan->name[LTTNG_UST_SYM_NAME_LEN - 1] == '\0'); + assert(uchan->ctx != NULL); + assert(uchan->events != NULL); + assert(uchan->attr.overwrite == attr.attr.overwrite); + PRINT_OK(); + + trace_ust_destroy_channel(uchan); +} + +static void create_ust_event(void) +{ + struct ltt_ust_event *event; + struct lttng_event ev; + + strncpy(ev.name, get_random_string(), LTTNG_SYMBOL_NAME_LEN); + ev.type = LTTNG_EVENT_TRACEPOINT; + + printf("Creating UST event: "); + event = trace_ust_create_event(&ev); + assert(event != NULL); + PRINT_OK(); + + printf("Validating UST event: "); + assert(event->enabled == 0); + assert(event->ctx != NULL); + assert(event->attr.instrumentation == LTTNG_UST_TRACEPOINT); + assert(strcmp(event->attr.name, ev.name) == 0); + assert(event->attr.name[LTTNG_UST_SYM_NAME_LEN - 1] == '\0'); + PRINT_OK(); + + trace_ust_destroy_event(event); +} + +static void create_ust_context(void) +{ + struct lttng_event_context ctx; + struct ltt_ust_context *uctx; + + printf("Creating UST context: "); + uctx = trace_ust_create_context(&ctx); + assert(uctx != NULL); + PRINT_OK(); + + printf("Validating UST context: "); + assert(ctx.ctx == uctx->ctx.ctx); + PRINT_OK(); +} + +int main(int argc, char **argv) +{ + printf("\nTesting UST data structures:\n-----------\n"); + + create_one_ust_session(); + create_ust_metadata(); + create_ust_channel(); + create_ust_event(); + create_ust_context(); + + /* Success */ + return 0; +} diff --git a/tests/ust-nevents/Makefile.am b/tests/ust-nevents/Makefile.am new file mode 100644 index 000000000..80078928f --- /dev/null +++ b/tests/ust-nevents/Makefile.am @@ -0,0 +1,8 @@ +AM_CPPFLAGS = -llttng-ust -ldl -I. -O2 + +noinst_PROGRAMS = gen-nevents +gen_nevents_SOURCES = gen-nevents.c tp.c ust_gen_nevents.h +gen_nevents_LDADD = -llttng-ust + +noinst_SCRIPTS = run +EXTRA_DIST = run diff --git a/tests/ust-nevents/gen-nevents.c b/tests/ust-nevents/gen-nevents.c new file mode 100644 index 000000000..03aa6c67e --- /dev/null +++ b/tests/ust-nevents/gen-nevents.c @@ -0,0 +1,55 @@ +/* + * 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_nevents.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; + unsigned int nr_iter = 100; + + if (argc == 2) { + nr_iter = atoi(argv[1]); + } + + for (i = 0; i < nr_iter; i++) { + netint = htonl(i); + tracepoint(ust_gen_nevents, tptest, i, netint, values, text, + strlen(text), dbl, flt); + } + + return 0; +} diff --git a/tests/ust-nevents/run b/tests/ust-nevents/run new file mode 100755 index 000000000..9fbc8d805 --- /dev/null +++ b/tests/ust-nevents/run @@ -0,0 +1,45 @@ +#!/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 +SESSION_NAME="ust-nevents" +EVENT_NAME="ust_gen_nevents:tptest" +TRACE_PATH=$(mktemp -d) + +source $TESTDIR/utils.sh + +echo -e "\n-----------------------------------" +echo -e "UST tracer - Generate $NR_ITER events" +echo -e "-------------------------------------" + +# MUST set TESTDIR before calling those functions + +create_lttng_session $SESSION_NAME $TRACE_PATH + +enable_ust_lttng_event $SESSION_NAME $EVENT_NAME +start_tracing $SESSION_NAME + +# Start test +./$(dirname $0)/gen-nevents $NR_ITER + +stop_tracing $SESSION_NAME +destroy_lttng_session $SESSION_NAME + +trace_matches $EVENT_NAME $NR_ITER $TRACE_PATH + +rm -rf $TRACE_PATH diff --git a/tests/ust-nevents/tp.c b/tests/ust-nevents/tp.c new file mode 100644 index 000000000..e291924a3 --- /dev/null +++ b/tests/ust-nevents/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_nevents.h" diff --git a/tests/ust-nevents/ust_gen_nevents.h b/tests/ust-nevents/ust_gen_nevents.h new file mode 100644 index 000000000..8d82ecb4e --- /dev/null +++ b/tests/ust-nevents/ust_gen_nevents.h @@ -0,0 +1,56 @@ +#undef TRACEPOINT_PROVIDER +#define TRACEPOINT_PROVIDER ust_gen_nevents + +#if !defined(_TRACEPOINT_UST_GEN_NEVENTS_H) || defined(TRACEPOINT_HEADER_MULTI_READ) +#define _TRACEPOINT_UST_GEN_NEVENTS_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_nevents, 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_NEVENTS_H */ + +#undef TRACEPOINT_INCLUDE_FILE +#define TRACEPOINT_INCLUDE_FILE ./ust_gen_nevents.h + +/* This part must be outside ifdef protection */ +#include + +#ifdef __cplusplus +} +#endif diff --git a/tests/utils.sh b/tests/utils.sh new file mode 100644 index 000000000..352a19837 --- /dev/null +++ b/tests/utils.sh @@ -0,0 +1,139 @@ +#!/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 + +SESSIOND_BIN="lttng-sessiond" +LTTNG_BIN="lttng" +BABELTRACE_BIN="babeltrace" + +function start_sessiond () +{ + if [ -z $(pidof $SESSIOND_BIN) ]; then + echo -n "Starting session daemon... " + $TESTDIR/../lttng-sessiond/$SESSIOND_BIN --daemonize --quiet + if [ $? -eq 1 ]; then + echo -e "\e[1;31mFAILED\e[0m" + return 1 + else + echo -e "\e[1;32mOK\e[0m" + fi + fi +} + +function stop_sessiond () +{ + PID_SESSIOND=`pidof lt-$SESSIOND_BIN` + + echo -e -n "Killing session daemon... " + kill $PID_SESSIOND >/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 create_lttng_session () +{ + sess_name=$1 + trace_path=$2 + + echo -n "Creating lttng session $SESSION_NAME in $TRACE_PATH " + $TESTDIR/../lttng/$LTTNG_BIN create $sess_name -o $trace_path >/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" + #echo $out | grep "written in" | cut -d' ' -f6 + fi +} + +function enable_ust_lttng_event () +{ + sess_name=$1 + event_name=$2 + + echo -n "Enabling lttng event $event_name for session $sess_name " + $TESTDIR/../lttng/$LTTNG_BIN enable-event $event_name -s $sess_name -u >/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 start_tracing () +{ + sess_name=$1 + + echo -n "Start lttng tracing for session $sess_name " + $TESTDIR/../lttng/$LTTNG_BIN start $sess_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 stop_tracing () +{ + sess_name=$1 + + echo -n "Stop lttng tracing for session $sess_name " + $TESTDIR/../lttng/$LTTNG_BIN stop $sess_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 destroy_lttng_session () +{ + sess_name=$1 + + echo -n "Destroy lttng session $sess_name " + $TESTDIR/../lttng/$LTTNG_BIN destroy $sess_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 trace_matches () +{ + event_name=$1 + nr_iter=$2 + trace_path=$3 + + echo -n "Looking for $nr_iter $event_name in $trace_path " + + count=$($BABELTRACE_BIN $trace_path | grep $event_name | wc -l) + if [ "$count" -ne "$nr_iter" ]; then + echo -e "$count found in trace \e[1;31mFAILED\e[0m" + return 1 + else + echo -e "Trace is coherent \e[1;32mOK\e[0m" + return 0 + fi +} -- 2.34.1