From: Christian Babeux Date: Thu, 21 Feb 2013 19:20:25 +0000 (-0500) Subject: Tests: Move tests to tests/regression X-Git-Tag: v2.2.0-rc1~60^2~29 X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=commitdiff_plain;h=9ac429ef32142eaecfec2d1a44569464c4f8f721 Tests: Move tests to tests/regression Also move the utils.sh and utils.h helper files under tests/utils. Signed-off-by: Christian Babeux --- diff --git a/configure.ac b/configure.ac index 71fbb6034..5cb2e90b4 100644 --- a/configure.ac +++ b/configure.ac @@ -309,19 +309,20 @@ AC_CONFIG_FILES([ src/bin/lttng-relayd/Makefile src/bin/lttng/Makefile tests/Makefile - tests/kernel/Makefile - tests/tools/Makefile - tests/tools/streaming/Makefile - tests/tools/filtering/Makefile - tests/tools/health/Makefile - tests/ust/Makefile - tests/ust/nprocesses/Makefile - tests/ust/high-throughput/Makefile - tests/ust/low-throughput/Makefile - tests/ust/before-after/Makefile - tests/ust/multi-session/Makefile - tests/ust/overlap/Makefile - tests/ust/overlap/demo/Makefile + tests/regression/Makefile + tests/regression/kernel/Makefile + tests/regression/tools/Makefile + tests/regression/tools/streaming/Makefile + tests/regression/tools/filtering/Makefile + tests/regression/tools/health/Makefile + tests/regression/ust/Makefile + tests/regression/ust/nprocesses/Makefile + tests/regression/ust/high-throughput/Makefile + tests/regression/ust/low-throughput/Makefile + tests/regression/ust/before-after/Makefile + tests/regression/ust/multi-session/Makefile + tests/regression/ust/overlap/Makefile + tests/regression/ust/overlap/demo/Makefile ]) AC_OUTPUT diff --git a/tests/Makefile.am b/tests/Makefile.am index bc0f0a59a..2a4309e01 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,13 +1 @@ -SUBDIRS = . tools kernel - -AM_CFLAGS = -g -Wall -AM_LDFLAGS = -lurcu -lurcu-cds - -EXTRA_DIST = run-report.py test_list.py utils.sh utils.h runall.sh - -if HAVE_LIBLTTNG_UST_CTL -SUBDIRS += ust -endif # HAVE_LIBLTTNG_UST_CTL - -check-am: - ./runall.sh +SUBDIRS = . regression diff --git a/tests/kernel/Makefile.am b/tests/kernel/Makefile.am deleted file mode 100644 index 8872af425..000000000 --- a/tests/kernel/Makefile.am +++ /dev/null @@ -1,22 +0,0 @@ -AM_CFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/src -I$(top_srcdir)/tests -g -Wall -AM_LDFLAGS = -lurcu -lurcu-cds - -EXTRA_DIST = runall.sh run-kernel-tests.sh - -noinst_PROGRAMS = kernel_all_events_basic kernel_event_basic - -UTILS=../utils.h -LIBLTTNG=$(top_builddir)/src/lib/lttng-ctl/liblttng-ctl.la - -SESSIONDSRC=$(top_srcdir)/src/common/sessiond-comm/sessiond-comm.c \ - $(top_srcdir)/src/common/sessiond-comm/unix.c \ - $(top_srcdir)/src/common/sessiond-comm/inet.c \ - $(top_srcdir)/src/common/sessiond-comm/inet6.c - -kernel_all_events_basic_SOURCES = kernel_all_events_basic.c $(UTILS) \ - $(SESSIONDSRC) -kernel_all_events_basic_LDADD = $(LIBLTTNG) - -kernel_event_basic_SOURCES = kernel_event_basic.c $(UTILS) \ - $(SESSIONDSRC) -kernel_event_basic_LDADD = $(LIBLTTNG) diff --git a/tests/kernel/kernel_all_events_basic.c b/tests/kernel/kernel_all_events_basic.c deleted file mode 100644 index b80dbd322..000000000 --- a/tests/kernel/kernel_all_events_basic.c +++ /dev/null @@ -1,119 +0,0 @@ -/* - * 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 - -#include "utils.h" - -int lttng_opt_quiet; - -int main(int argc, char **argv) -{ - struct lttng_handle *handle = NULL; - struct lttng_domain dom; - struct lttng_event event; - char *channel_name = "channel0"; - char *session_name = "kernel_all_events_basic"; - int ret = 0; - - memset(&dom, 0, sizeof(dom)); - memset(&event, 0, sizeof(event)); - dom.type = LTTNG_DOMAIN_KERNEL; - event.type = LTTNG_EVENT_TRACEPOINT; - event.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL; - - printf("\nTesting tracing all kernel events:\n"); - printf("-----------\n"); - /* Check if root */ - if (getuid() != 0) { - printf("Root access is needed.\nPlease run 'sudo make check' -- Aborting!\n"); - return 0; - } - - if (argc < 2) { - printf("Missing session trace path\n"); - return 1; - } - - printf("Creating tracing session (%s): ", argv[1]); - 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(session_name, &dom)) == NULL) { - printf("error creating handle: %s\n", lttng_strerror(ret)); - goto handle_fail; - } - PRINT_OK(); - - printf("Enabling all kernel events: "); - if ((ret = lttng_enable_event(handle, &event, channel_name)) < 0) { - printf("error enabling event: %s\n", lttng_strerror(ret)); - goto enable_fail; - } - PRINT_OK(); - - printf("Start tracing: "); - if ((ret = lttng_start_tracing(session_name)) < 0) { - printf("error starting tracing: %s\n", lttng_strerror(ret)); - goto start_fail; - } - PRINT_OK(); - - sleep(2); - - printf("Stop tracing: "); - 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(session_name)) < 0) { - printf("error destroying session: %s\n", lttng_strerror(ret)); - } - PRINT_OK(); - - return 0; - -handle_fail: - assert(handle != NULL); -create_fail: - assert(ret != 0); - -stop_fail: -start_fail: -enable_fail: - lttng_destroy_session(session_name); - lttng_destroy_handle(handle); - - return 1; -} diff --git a/tests/kernel/kernel_event_basic.c b/tests/kernel/kernel_event_basic.c deleted file mode 100644 index b0cbf669f..000000000 --- a/tests/kernel/kernel_event_basic.c +++ /dev/null @@ -1,191 +0,0 @@ -/* - * 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 - -#include "utils.h" - -int lttng_opt_quiet; - -int main(int argc, char **argv) -{ - struct lttng_handle *handle = NULL; - struct lttng_domain dom; - struct lttng_channel channel; - struct lttng_event sched_switch; - struct lttng_event sched_process_exit; - struct lttng_event sched_process_free; - char *session_name = "kernel_event_basic"; - int ret = 0; - - memset(&dom, 0, sizeof(dom)); - memset(&channel, 0, sizeof(channel)); - memset(&sched_switch, 0, sizeof(sched_switch)); - memset(&sched_process_exit, 0, sizeof(sched_process_exit)); - memset(&sched_process_free, 0, sizeof(sched_process_free)); - - dom.type = LTTNG_DOMAIN_KERNEL; - - strcpy(channel.name, "mychan"); - channel.attr.overwrite = 0; - channel.attr.subbuf_size = 4096; - channel.attr.num_subbuf = 8; - channel.attr.switch_timer_interval = 0; - channel.attr.read_timer_interval = 200; - channel.attr.output = LTTNG_EVENT_SPLICE; - - strcpy(sched_switch.name, "sched_switch"); - sched_switch.type = LTTNG_EVENT_TRACEPOINT; - sched_switch.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL; - - strcpy(sched_process_exit.name, "sched_process_exit"); - sched_process_exit.type = LTTNG_EVENT_TRACEPOINT; - sched_process_exit.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL; - - strcpy(sched_process_free.name, "sched_process_free"); - sched_process_free.type = LTTNG_EVENT_TRACEPOINT; - sched_process_free.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL; - - printf("\nTesting tracing kernel events:\n"); - printf("-----------\n"); - /* Check if root */ - if (getuid() != 0) { - printf("Root access is needed.\nPlease run 'sudo make check' -- Aborting!\n"); - return 0; - } - - if (argc < 2) { - printf("Missing session trace path\n"); - return 1; - } - - printf("Creating tracing session (%s): ", argv[1]); - 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(session_name, &dom)) == NULL) { - printf("error creating handle: %s\n", lttng_strerror(ret)); - goto handle_fail; - } - PRINT_OK(); - - printf("Enabling %s kernel channel: ", channel.name); - if ((ret = lttng_enable_channel(handle, &channel)) < 0) { - printf("error enable channel: %s\n", lttng_strerror(ret)); - goto enable_fail; - } - - printf("Enabling %s kernel event: ", sched_switch.name); - if ((ret = lttng_enable_event(handle, &sched_switch, channel.name)) < 0) { - printf("error enabling event: %s\n", lttng_strerror(ret)); - goto enable_fail; - } - PRINT_OK(); - - printf("Enabling %s kernel event: ", sched_process_exit.name); - if ((ret = lttng_enable_event(handle, &sched_process_exit, channel.name)) < 0) { - printf("error enabling event: %s\n", lttng_strerror(ret)); - goto enable_fail; - } - PRINT_OK(); - - printf("Enabling %s kernel event: ", sched_process_free.name); - if ((ret = lttng_enable_event(handle, &sched_process_free, channel.name)) < 0) { - printf("error enabling event: %s\n", lttng_strerror(ret)); - goto enable_fail; - } - PRINT_OK(); - - printf("Disabling %s kernel event: ", sched_switch.name); - if ((ret = lttng_disable_event(handle, sched_switch.name, channel.name)) < 0) { - printf("error enabling event: %s\n", lttng_strerror(ret)); - goto enable_fail; - } - PRINT_OK(); - - printf("Disabling %s kernel event: ", sched_process_free.name); - if ((ret = lttng_disable_event(handle, sched_process_free.name, channel.name)) < 0) { - printf("error enabling event: %s\n", lttng_strerror(ret)); - goto enable_fail; - } - PRINT_OK(); - - printf("Renabling %s kernel event: ", sched_switch.name); - if ((ret = lttng_enable_event(handle, &sched_switch, channel.name)) < 0) { - printf("error enabling event: %s\n", lttng_strerror(ret)); - goto enable_fail; - } - PRINT_OK(); - - printf("Renabling %s kernel event: ", sched_process_free.name); - if ((ret = lttng_enable_event(handle, &sched_process_free, channel.name)) < 0) { - printf("error enabling event: %s\n", lttng_strerror(ret)); - goto enable_fail; - } - PRINT_OK(); - - printf("Start tracing: "); - if ((ret = lttng_start_tracing(session_name)) < 0) { - printf("error starting tracing: %s\n", lttng_strerror(ret)); - goto start_fail; - } - PRINT_OK(); - - sleep(2); - - printf("Stop tracing: "); - 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(session_name)) < 0) { - printf("error destroying session: %s\n", lttng_strerror(ret)); - } - PRINT_OK(); - - return 0; - -handle_fail: - assert(handle != NULL); -create_fail: - assert(ret != 0); - -stop_fail: -start_fail: -enable_fail: - lttng_destroy_session(session_name); - lttng_destroy_handle(handle); - - return 1; -} diff --git a/tests/kernel/run-kernel-tests.sh b/tests/kernel/run-kernel-tests.sh deleted file mode 100755 index 6948e1fa2..000000000 --- a/tests/kernel/run-kernel-tests.sh +++ /dev/null @@ -1,59 +0,0 @@ -#!/bin/bash - -SESSIOND_BIN="lttng-sessiond" -CURDIR=$(dirname $0) -TESTDIR=$CURDIR/.. - -source $TESTDIR/utils.sh - -tmpdir=`mktemp -d` -tests=( $CURDIR/kernel_event_basic $CURDIR/kernel_all_events_basic ) -exit_code=0 - -function start_tests () -{ - for bin in ${tests[@]}; - do - if [ ! -e $bin ]; then - echo -e "$bin not found, passing" - continue - fi - - start_lttng_sessiond - - ./$bin $tmpdir - # Test must return 0 to pass. - if [ $? -ne 0 ]; then - exit_code=1 - stop_lttng_sessiond - break - fi - stop_lttng_sessiond - done - - # Cleaning up - rm -rf $tmpdir -} - -function check_lttng_modules () -{ - local 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 -} - - -TEST_DESC="Testing Kernel tracer" - -print_test_banner "$TEST_DESC" - -# Detect lttng-modules installed -check_lttng_modules - -start_tests - -exit $exit_code diff --git a/tests/kernel/runall.sh b/tests/kernel/runall.sh deleted file mode 100755 index 2b76e5355..000000000 --- a/tests/kernel/runall.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/bash - -DIR=$(dirname $0) - -tests=( $DIR/run-kernel-tests.sh ) -exit_code=0 - -function start_tests () -{ - for bin in ${tests[@]}; - do - ./$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/regression/Makefile.am b/tests/regression/Makefile.am new file mode 100644 index 000000000..441354e12 --- /dev/null +++ b/tests/regression/Makefile.am @@ -0,0 +1,13 @@ +SUBDIRS = . tools kernel + +AM_CFLAGS = -g -Wall +AM_LDFLAGS = -lurcu -lurcu-cds + +EXTRA_DIST = run-report.py test_list.py runall.sh + +if HAVE_LIBLTTNG_UST_CTL +SUBDIRS += ust +endif # HAVE_LIBLTTNG_UST_CTL + +check-am: + ./runall.sh diff --git a/tests/regression/kernel/Makefile.am b/tests/regression/kernel/Makefile.am new file mode 100644 index 000000000..5cfe81e3f --- /dev/null +++ b/tests/regression/kernel/Makefile.am @@ -0,0 +1,22 @@ +AM_CFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/src -I$(top_srcdir)/tests/utils -g -Wall +AM_LDFLAGS = -lurcu -lurcu-cds + +EXTRA_DIST = runall.sh run-kernel-tests.sh + +noinst_PROGRAMS = kernel_all_events_basic kernel_event_basic + +UTILS=$(top_srcdir)/tests/utils/utils.h +LIBLTTNG=$(top_builddir)/src/lib/lttng-ctl/liblttng-ctl.la + +SESSIONDSRC=$(top_srcdir)/src/common/sessiond-comm/sessiond-comm.c \ + $(top_srcdir)/src/common/sessiond-comm/unix.c \ + $(top_srcdir)/src/common/sessiond-comm/inet.c \ + $(top_srcdir)/src/common/sessiond-comm/inet6.c + +kernel_all_events_basic_SOURCES = kernel_all_events_basic.c $(UTILS) \ + $(SESSIONDSRC) +kernel_all_events_basic_LDADD = $(LIBLTTNG) + +kernel_event_basic_SOURCES = kernel_event_basic.c $(UTILS) \ + $(SESSIONDSRC) +kernel_event_basic_LDADD = $(LIBLTTNG) diff --git a/tests/regression/kernel/kernel_all_events_basic.c b/tests/regression/kernel/kernel_all_events_basic.c new file mode 100644 index 000000000..b80dbd322 --- /dev/null +++ b/tests/regression/kernel/kernel_all_events_basic.c @@ -0,0 +1,119 @@ +/* + * 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 + +#include "utils.h" + +int lttng_opt_quiet; + +int main(int argc, char **argv) +{ + struct lttng_handle *handle = NULL; + struct lttng_domain dom; + struct lttng_event event; + char *channel_name = "channel0"; + char *session_name = "kernel_all_events_basic"; + int ret = 0; + + memset(&dom, 0, sizeof(dom)); + memset(&event, 0, sizeof(event)); + dom.type = LTTNG_DOMAIN_KERNEL; + event.type = LTTNG_EVENT_TRACEPOINT; + event.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL; + + printf("\nTesting tracing all kernel events:\n"); + printf("-----------\n"); + /* Check if root */ + if (getuid() != 0) { + printf("Root access is needed.\nPlease run 'sudo make check' -- Aborting!\n"); + return 0; + } + + if (argc < 2) { + printf("Missing session trace path\n"); + return 1; + } + + printf("Creating tracing session (%s): ", argv[1]); + 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(session_name, &dom)) == NULL) { + printf("error creating handle: %s\n", lttng_strerror(ret)); + goto handle_fail; + } + PRINT_OK(); + + printf("Enabling all kernel events: "); + if ((ret = lttng_enable_event(handle, &event, channel_name)) < 0) { + printf("error enabling event: %s\n", lttng_strerror(ret)); + goto enable_fail; + } + PRINT_OK(); + + printf("Start tracing: "); + if ((ret = lttng_start_tracing(session_name)) < 0) { + printf("error starting tracing: %s\n", lttng_strerror(ret)); + goto start_fail; + } + PRINT_OK(); + + sleep(2); + + printf("Stop tracing: "); + 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(session_name)) < 0) { + printf("error destroying session: %s\n", lttng_strerror(ret)); + } + PRINT_OK(); + + return 0; + +handle_fail: + assert(handle != NULL); +create_fail: + assert(ret != 0); + +stop_fail: +start_fail: +enable_fail: + lttng_destroy_session(session_name); + lttng_destroy_handle(handle); + + return 1; +} diff --git a/tests/regression/kernel/kernel_event_basic.c b/tests/regression/kernel/kernel_event_basic.c new file mode 100644 index 000000000..b0cbf669f --- /dev/null +++ b/tests/regression/kernel/kernel_event_basic.c @@ -0,0 +1,191 @@ +/* + * 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 + +#include "utils.h" + +int lttng_opt_quiet; + +int main(int argc, char **argv) +{ + struct lttng_handle *handle = NULL; + struct lttng_domain dom; + struct lttng_channel channel; + struct lttng_event sched_switch; + struct lttng_event sched_process_exit; + struct lttng_event sched_process_free; + char *session_name = "kernel_event_basic"; + int ret = 0; + + memset(&dom, 0, sizeof(dom)); + memset(&channel, 0, sizeof(channel)); + memset(&sched_switch, 0, sizeof(sched_switch)); + memset(&sched_process_exit, 0, sizeof(sched_process_exit)); + memset(&sched_process_free, 0, sizeof(sched_process_free)); + + dom.type = LTTNG_DOMAIN_KERNEL; + + strcpy(channel.name, "mychan"); + channel.attr.overwrite = 0; + channel.attr.subbuf_size = 4096; + channel.attr.num_subbuf = 8; + channel.attr.switch_timer_interval = 0; + channel.attr.read_timer_interval = 200; + channel.attr.output = LTTNG_EVENT_SPLICE; + + strcpy(sched_switch.name, "sched_switch"); + sched_switch.type = LTTNG_EVENT_TRACEPOINT; + sched_switch.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL; + + strcpy(sched_process_exit.name, "sched_process_exit"); + sched_process_exit.type = LTTNG_EVENT_TRACEPOINT; + sched_process_exit.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL; + + strcpy(sched_process_free.name, "sched_process_free"); + sched_process_free.type = LTTNG_EVENT_TRACEPOINT; + sched_process_free.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL; + + printf("\nTesting tracing kernel events:\n"); + printf("-----------\n"); + /* Check if root */ + if (getuid() != 0) { + printf("Root access is needed.\nPlease run 'sudo make check' -- Aborting!\n"); + return 0; + } + + if (argc < 2) { + printf("Missing session trace path\n"); + return 1; + } + + printf("Creating tracing session (%s): ", argv[1]); + 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(session_name, &dom)) == NULL) { + printf("error creating handle: %s\n", lttng_strerror(ret)); + goto handle_fail; + } + PRINT_OK(); + + printf("Enabling %s kernel channel: ", channel.name); + if ((ret = lttng_enable_channel(handle, &channel)) < 0) { + printf("error enable channel: %s\n", lttng_strerror(ret)); + goto enable_fail; + } + + printf("Enabling %s kernel event: ", sched_switch.name); + if ((ret = lttng_enable_event(handle, &sched_switch, channel.name)) < 0) { + printf("error enabling event: %s\n", lttng_strerror(ret)); + goto enable_fail; + } + PRINT_OK(); + + printf("Enabling %s kernel event: ", sched_process_exit.name); + if ((ret = lttng_enable_event(handle, &sched_process_exit, channel.name)) < 0) { + printf("error enabling event: %s\n", lttng_strerror(ret)); + goto enable_fail; + } + PRINT_OK(); + + printf("Enabling %s kernel event: ", sched_process_free.name); + if ((ret = lttng_enable_event(handle, &sched_process_free, channel.name)) < 0) { + printf("error enabling event: %s\n", lttng_strerror(ret)); + goto enable_fail; + } + PRINT_OK(); + + printf("Disabling %s kernel event: ", sched_switch.name); + if ((ret = lttng_disable_event(handle, sched_switch.name, channel.name)) < 0) { + printf("error enabling event: %s\n", lttng_strerror(ret)); + goto enable_fail; + } + PRINT_OK(); + + printf("Disabling %s kernel event: ", sched_process_free.name); + if ((ret = lttng_disable_event(handle, sched_process_free.name, channel.name)) < 0) { + printf("error enabling event: %s\n", lttng_strerror(ret)); + goto enable_fail; + } + PRINT_OK(); + + printf("Renabling %s kernel event: ", sched_switch.name); + if ((ret = lttng_enable_event(handle, &sched_switch, channel.name)) < 0) { + printf("error enabling event: %s\n", lttng_strerror(ret)); + goto enable_fail; + } + PRINT_OK(); + + printf("Renabling %s kernel event: ", sched_process_free.name); + if ((ret = lttng_enable_event(handle, &sched_process_free, channel.name)) < 0) { + printf("error enabling event: %s\n", lttng_strerror(ret)); + goto enable_fail; + } + PRINT_OK(); + + printf("Start tracing: "); + if ((ret = lttng_start_tracing(session_name)) < 0) { + printf("error starting tracing: %s\n", lttng_strerror(ret)); + goto start_fail; + } + PRINT_OK(); + + sleep(2); + + printf("Stop tracing: "); + 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(session_name)) < 0) { + printf("error destroying session: %s\n", lttng_strerror(ret)); + } + PRINT_OK(); + + return 0; + +handle_fail: + assert(handle != NULL); +create_fail: + assert(ret != 0); + +stop_fail: +start_fail: +enable_fail: + lttng_destroy_session(session_name); + lttng_destroy_handle(handle); + + return 1; +} diff --git a/tests/regression/kernel/run-kernel-tests.sh b/tests/regression/kernel/run-kernel-tests.sh new file mode 100755 index 000000000..ec2ceaf91 --- /dev/null +++ b/tests/regression/kernel/run-kernel-tests.sh @@ -0,0 +1,59 @@ +#!/bin/bash + +SESSIOND_BIN="lttng-sessiond" +CURDIR=$(dirname $0) +TESTDIR=$CURDIR/../.. + +source $TESTDIR/utils/utils.sh + +tmpdir=`mktemp -d` +tests=( $CURDIR/kernel_event_basic $CURDIR/kernel_all_events_basic ) +exit_code=0 + +function start_tests () +{ + for bin in ${tests[@]}; + do + if [ ! -e $bin ]; then + echo -e "$bin not found, passing" + continue + fi + + start_lttng_sessiond + + ./$bin $tmpdir + # Test must return 0 to pass. + if [ $? -ne 0 ]; then + exit_code=1 + stop_lttng_sessiond + break + fi + stop_lttng_sessiond + done + + # Cleaning up + rm -rf $tmpdir +} + +function check_lttng_modules () +{ + local 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 +} + + +TEST_DESC="Testing Kernel tracer" + +print_test_banner "$TEST_DESC" + +# Detect lttng-modules installed +check_lttng_modules + +start_tests + +exit $exit_code diff --git a/tests/regression/kernel/runall.sh b/tests/regression/kernel/runall.sh new file mode 100755 index 000000000..2b76e5355 --- /dev/null +++ b/tests/regression/kernel/runall.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +DIR=$(dirname $0) + +tests=( $DIR/run-kernel-tests.sh ) +exit_code=0 + +function start_tests () +{ + for bin in ${tests[@]}; + do + ./$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/regression/run-report.py b/tests/regression/run-report.py new file mode 100755 index 000000000..acee18181 --- /dev/null +++ b/tests/regression/run-report.py @@ -0,0 +1,444 @@ +#!/usr/bin/env python + +import os, sys +import subprocess +import threading +import Queue +import time +import shlex + +from signal import signal, SIGTERM, SIGINT, SIGPIPE, SIG_DFL + +SESSIOND_BIN_NAME = "lttng-sessiond" +SESSIOND_BIN_PATH = "src/bin/lttng-sessiond/" +CONSUMERD_BIN_NAME = "lttng-consumerd" +CONSUMERD_BIN_PATH = "src/bin/lttng-consumerd/" +TESTDIR_PATH = "" + +PRINT_BRACKET = "\033[1;34m[\033[1;33m+\033[1;34m]\033[00m" +PRINT_RED_BRACKET = "\033[1;31m[+]\033[00m" +PRINT_GREEN_BRACKET = "\033[1;32m[+]\033[00m" +PRINT_ARROW = "\033[1;32m-->\033[00m" + +is_root = 1 +no_stats = 0 +stop_sampling = 1 + +top_cpu_legend = { 'us': "User CPU time", 'sy': "System CPU time", + 'id': "Idle CPU time", 'ni': "Nice CPU time", 'wa': "iowait", + 'hi': "Hardware IRQ", 'si': "Software Interrupts", 'st': "Steal Time", } + +cpu_ret_q = Queue.Queue() +mem_ret_q = Queue.Queue() +test_ret_q = Queue.Queue() + +global sdaemon_proc +global worker_proc + +def cpu_create_usage_dict(top_line): + """ + Return a dictionnary from a 'top' cpu line. + Ex: Cpu(s): 2.1%us, 1.2%sy, 0.0%ni, 96.2%id, 0.4%wa, 0.0%hi, 0.0%si, 0.0%st + """ + top_dict = {'us': 0, 'sy': 0, 'ni': 0, 'id': 0, 'wa': 0, 'hi': 0, 'si': 0, 'st': 0} + + # Split expression and remove first value which is "Cpu(s)" + top_line = top_line.replace(",","") + words = top_line.split()[1:] + + + for key in top_dict: + index = words.index(key) + # Add the value to the dictionnary + val = words[index-1] + top_dict[key] = float(val) + + return top_dict + +def cpu_average_usage(top_lines): + """ + Return a dictionnary of 'top' CPU stats but averaging all values. + """ + avg_dict = {'us': 0, 'sy': 0, 'ni': 0, 'id': 0, 'wa': 0, 'hi': 0, 'si': 0, 'st': 0} + # Average count + count = 0.0 + + for line in top_lines: + tmp_dict = cpu_create_usage_dict(line) + # Add value to avg dictionnary + for key in tmp_dict: + avg_dict[key] += tmp_dict[key] + + count += 1.0 + + for key in avg_dict: + avg_dict[key] = avg_dict[key] / count + + return (count, avg_dict) + +def cpu_sample_usage(pid=None): + """ + Sample CPU usage for num iterations. + If num is greater than 1, the average will be computed. + """ + args = ["top", "-b", "-n", "1"] + if pid: + args.append("-p") + args.append(str(pid)) + + # Spawn top process + top = subprocess.Popen(args, stdout = subprocess.PIPE) + + grep = subprocess.Popen(["grep", "Cpu"], stdin = top.stdout, + stdout = subprocess.PIPE) + top.stdout.close() + + return grep.communicate()[0].strip("\n") + +def mem_sample_usage(pid): + """ + Sample memory usage using /proc and a pid + """ + args = ["cat", "/proc/" + str(pid) + "/status"] + + if not os.path.isfile(args[1]): + return -1 + + mem_proc = subprocess.Popen(args, stdout = subprocess.PIPE) + + grep = subprocess.Popen(["grep", "^VmRSS"], stdin = mem_proc.stdout, + stdout = subprocess.PIPE) + mem_proc.stdout.close() + + # Return virtual memory size in kilobytes (kB) + #ret = grep.communicate()[0].split() + ret = grep.communicate()[0].split() + + if len(ret) > 1: + ret = ret[1] + else: + ret = 0 + + return int(ret) + +class SamplingWorker(threading.Thread): + def __init__(self, s_type, worker = None, delay = 0.2, pid = 0): + threading.Thread.__init__ (self) + self.s_type = s_type + self.delay = delay + self.pid = pid + self.worker = worker + + def run(self): + count = 1 + lines = [] + + if self.s_type == "cpu": + while 1: + if self.worker == None: + cpu_line = cpu_sample_usage(self.pid) + lines.append(cpu_line) + break + elif self.worker.is_alive(): + cpu_line = cpu_sample_usage(self.pid) + lines.append(cpu_line) + else: + break + + # Delay sec per memory sampling + time.sleep(self.delay) + + count, stats = cpu_average_usage(lines) + cpu_ret_q.put((count, stats)) + # grep process has ended here + + elif self.s_type == "mem": + count = 0 + mem_stat = 0 + + while 1: + if self.worker == None: + cpu_line = cpu_sample_usage(self.pid) + lines.append(cpu_line) + break + elif self.worker.is_alive(): + mem_stat += get_mem_usage(self.pid) + count += 1 + else: + break + + # Delay sec per memory sampling + time.sleep(self.delay) + + mem_ret_q.put((count, mem_stat)) + +class TestWorker(threading.Thread): + def __init__(self, path, name, env): + threading.Thread.__init__(self) + self.path = path + self.name = name + self.env = env + + def run(self): + bin_path_name = os.path.join(self.path, self.name) + + test = subprocess.Popen([bin_path_name], env=self.env, preexec_fn = lambda: signal(SIGPIPE, SIG_DFL)) + test.wait() + + # Send ret value to main thread + test_ret_q.put(test.returncode) + +def get_pid(procname): + """ + Return pid of process name using 'pidof' command + """ + pidof = subprocess.Popen(["pidof", procname], stdout = subprocess.PIPE) + pid = pidof.communicate()[0].split() + + if pid == []: + return 0 + + return int(pid[0]) + +def spawn_session_daemon(): + """ + Exec the session daemon and return PID + """ + global sdaemon_proc + + pid = get_pid(SESSIOND_BIN_NAME) + if pid != 0: + os.kill(pid, SIGTERM) + + bin_path = os.path.join(TESTDIR_PATH, "..", SESSIOND_BIN_PATH, SESSIOND_BIN_NAME) + consumer_path = os.path.join(TESTDIR_PATH, "..", CONSUMERD_BIN_PATH, CONSUMERD_BIN_NAME) + + if not os.path.isfile(bin_path): + print "Error: No session daemon binary found. Compiled?" + return 0 + + try: + args = shlex.split("libtool execute " + bin_path + + " --consumerd32-path=" + consumer_path + + " --consumerd64-path=" + consumer_path) + + sdaemon_proc = subprocess.Popen(args, shell = False, stderr = subprocess.PIPE) + + except OSError, e: + print e + return 0 + + time.sleep(1) + + return get_pid("lt-" + SESSIOND_BIN_NAME) + +def start_test(name): + """ + Spawn test and return exit code + """ + tw = TestWorker(".", name) + tw.start() + + return test_ret_q.get(True) + +def print_cpu_stats(stats, count): + """ + Pretty print on one line the CPU stats + """ + sys.stdout.write(PRINT_ARROW + " Cpu [sampled %d time(s)]:\n " % (count)) + for stat in stats: + sys.stdout.write(" %s: %.2f, " % (stat, stats[stat])) + print "" + +def get_cpu_usage(delay=1, pid=0): + """ + Spawn a worker thread to sample cpu usage. + """ + sw = SamplingWorker("cpu", delay = delay, pid = pid) + sw.start() + + return cpu_ret_q.get(True) + +def get_mem_usage(pid): + """ + Get memory usage for PID + """ + return mem_sample_usage(pid) + +def print_test_success(ret, expect): + """ + Print if test has failed or pass according to the expected value. + """ + if ret != expect: + print "\n" + PRINT_RED_BRACKET + \ + " Failed: ret = %d (expected %d)" % (ret, expect) + return 1 + else: + print "\n" + PRINT_BRACKET + \ + " Passed: ret = %d (expected %d)" % (ret, expect) + return 0 + +def run_test(test): + """ + Run test 'name' and output report of the test with stats. + """ + global worker_proc + global sdaemon_proc + dem_pid = 0 # Session daemon pid + + print PRINT_BRACKET + " %s" % (test['name']) + print PRINT_ARROW + " %s" % (test['desc']) + if no_stats: + print PRINT_ARROW + " Statistics will NOT be collected" + else: + print PRINT_ARROW + " Statistics of the session daemon will be collected" + + if test['kern'] and not is_root: + print "Needs root for kernel tracing. Skipping" + return 0 + + if not os.path.isfile(test['bin']): + print "Unable to find test file '%s'. Skipping" % (test['bin']) + return 0 + + # Session daemon is controlled by the test + if test['daemon'] == "test": + print PRINT_ARROW + " Session daemon is controlled by the test" + env = os.environ + env['TEST_NO_SESSIOND'] = '0' + tw = TestWorker(".", test['bin'], env) + tw.start() + ret = test_ret_q.get(True) + print_test_success(ret, test['success']) + return 0 + elif test['daemon'] == False: + print PRINT_ARROW + " No session daemon needed" + env = os.environ + env['TEST_NO_SESSIOND'] = '1' + tw = TestWorker(".", test['bin'], env) + tw.start() + ret = test_ret_q.get(True) + print_test_success(ret, test['success']) + return 0 + else: + print PRINT_ARROW + " Session daemon needed" + + dem_pid = spawn_session_daemon() + if dem_pid <= 0: + print "Unable to start %s. Stopping" % (SESSIOND_BIN_NAME) + print sdaemon_proc.communicate()[1] + return 0 + + print PRINT_BRACKET + " Session daemon spawned (pid: %d)\n" % (dem_pid) + + if not no_stats: + mem_before = get_mem_usage(dem_pid) + print PRINT_BRACKET + " Stats *before* test:" + print PRINT_ARROW + " Mem (kB): %d" % (mem_before) + cpu_count, cpu_stats = get_cpu_usage(pid = dem_pid) + print_cpu_stats(cpu_stats, cpu_count) + + # Sessiond was already spawned, do not let the test spawn + # an additional sessiond + env = os.environ + env['TEST_NO_SESSIOND'] = '1' + + tw = TestWorker(".", test['bin'], env) + tw.start() + + if not no_stats: + # Start CPU sampling for test + sw_cpu = SamplingWorker("cpu", worker = tw, pid = dem_pid) + sw_cpu.start() + sw_mem = SamplingWorker("mem", worker = tw, pid = dem_pid) + sw_mem.start() + + ret = test_ret_q.get(True) + + if not no_stats: + time.sleep(2) + # Compute memory average + mem_count, mem_during = mem_ret_q.get(True) + mem_during = float(mem_during) / float(mem_count) + cpu_count, cpu_stats = cpu_ret_q.get(True) + + print "\n" + PRINT_BRACKET + " Stats *during* test:" + print PRINT_ARROW + " Mem (kB): %.0f [sampled %d time(s)]" % (mem_during, mem_count) + print_cpu_stats(cpu_stats, cpu_count) + + mem_after = get_mem_usage(dem_pid) + print "\n" + PRINT_BRACKET + " Stats *after* test:" + print PRINT_ARROW + " Mem (kB): %d" % (mem_after) + cpu_count, cpu_stats = get_cpu_usage(pid = dem_pid) + print_cpu_stats(cpu_stats, cpu_count) + + print "\n" + PRINT_BRACKET + " Memory usage differences:" + print PRINT_ARROW + " Diff during and before (kB): %d" % (mem_during - mem_before) + print PRINT_ARROW + " Diff during and after (kB): %d" % (mem_during - mem_after) + print PRINT_ARROW + " Diff before and after (kB): %d" % (mem_after - mem_before) + + # Return value of 0 means that is passed else it failed + ret = print_test_success(ret, test['success']) + + # Stop session daemon + if dem_pid > 0: + print PRINT_BRACKET + " Stopping session daemon (pid: %d)..." % (dem_pid) + try: + os.kill(dem_pid, SIGTERM) + # This call simply does not work... It seems python does not relay the signal + # to the child processes of sdaemon_proc. + # sdaemon_proc.terminate() + if ret != 0: + print sdaemon_proc.communicate()[1] + elif sdaemon_proc.returncode == None: + sdaemon_proc.communicate() + except OSError, e: + print e + + # Make sure all thread are released + if not no_stats: + tw.join() + sw_cpu.join() + sw_mem.join() + + return ret + +def main(): + for test in Tests: + if not test['enabled']: + continue + + ret = run_test(test) + if ret != 0: + # Stop all tests, the last one failed + return + print "" + +def cleanup(signo, stack): + """ Cleanup function """ + sys.exit(0) + +if __name__ == "__main__": + if not os.getuid() == 0: + is_root = 0 + print "NOTICE: Not root. No kernel tracing will be tested\n" + + if os.path.isfile("test_list.py"): + from test_list import Tests + else: + print "No test_list.py found. Stopping" + cleanup(0, 0) + + TESTDIR_PATH = os.getcwd() + + if len(sys.argv) > 1: + if sys.argv[1] == "--no-stats": + no_stats = 1 + + try: + signal(SIGTERM, cleanup) + signal(SIGINT, cleanup) + main() + cleanup(0, 0) + except KeyboardInterrupt: + cleanup(0, 0) diff --git a/tests/regression/runall.sh b/tests/regression/runall.sh new file mode 100755 index 000000000..4db6d5adb --- /dev/null +++ b/tests/regression/runall.sh @@ -0,0 +1,49 @@ +#!/bin/bash +# +# 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 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# + +#### ADD TESTS HERE #### + +tests=( kernel/runall.sh ust/runall.sh tools/runall.sh ) + +#### END TESTS HERE #### + +TESTDIR=$(dirname $0)/.. + +source $TESTDIR/utils/utils.sh + +## lttng-tools unit tests ## +# No session daemon needed +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 + echo -e '\e[1;31mFAIL\e[0m' + echo "" + exit 1 + fi +done + +# All passed +exit 0 diff --git a/tests/regression/test_list.py b/tests/regression/test_list.py new file mode 100755 index 000000000..2a613b92b --- /dev/null +++ b/tests/regression/test_list.py @@ -0,0 +1,146 @@ +Tests = \ +[ + # lttng-tools unit tests + { + 'bin': "tools/test_sessions", 'daemon': False, 'kern': False, 'name': "Test sessions", + 'desc': "Test tracing session data structures and methods.", + 'success': 0, 'enabled': True + }, + { + 'bin': "tools/test_kernel_data_trace", 'daemon': False, 'kern': False, + 'name': "Kernel data structures", + 'desc': "Test Kernel data structures and methods.", + 'success': 0, 'enabled': True + }, + { + 'bin': "tools/test_ust_data_trace", 'daemon': False, 'kern': False, + 'name': "UST data structures", + '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 tests + { + 'bin': "kernel/run-kernel-tests.sh", 'daemon': True, 'kern': True, + 'name': "Kernel tracer - lttng client", + 'desc': "Test the Kernel tracer using the lttng client", + 'success': 0, 'enabled': True + }, + + # UST tests + { + 'bin': "ust/run-ust-global-tests.sh", 'daemon': True, 'kern': False, + 'name': "UST tracer - Global domain", + 'desc': "Test the UST tracer functionnalities for domain LTTNG_DOMAIN_UST", + 'success': 0, 'enabled': True + }, + { + 'bin': "ust/nprocesses/run", 'daemon': True, 'kern': False, + 'name': "UST tracer - Multiple processes", + 'desc': "Test multiple process registering and tracing", + 'success': 0, 'enabled': True + }, + { + 'bin': "ust/high-throughput/run", 'daemon': True, 'kern': False, + 'name': "UST tracer - Testing high events throughput", + 'desc': "Test multiple large number of events with concurrent application", + 'success': 0, 'enabled': True + }, + # Deactivated. This test last 20 minutes... + #{ + #'bin': "ust/low-throughput/run", 'daemon': True, 'kern': False, + #'name': "UST tracer - Testing high events throughput", + #'desc': "Test low throughput of events", + #'success': 0, 'enabled': False + #}, + { + 'bin': "ust/before-after/run", 'daemon': True, 'kern': False, + 'name': "UST tracer - Tracing before and after app execution", + 'desc': "Test tracing before and after app execution", + 'success': 0, 'enabled': True + }, + { + 'bin': "ust/multi-session/run", 'daemon': True, 'kern': False, + 'name': "UST tracer - Multi-session", + 'desc': "Test tracing with 4 sessions for one application", + 'success': 0, 'enabled': True + }, + + # Tools filtering tests + { + 'bin': "tools/filtering/unsupported-ops", 'daemon': True, 'kern': False, + 'name': "Filtering - Unsupported operators", + 'desc': "Test the failure of filter with unsupported operators", + 'success': 0, 'enabled': True + }, + { + 'bin': "tools/filtering/invalid-filters", 'daemon': True, 'kern': False, + 'name': "Filtering - Invalid filters", + 'desc': "Test the failure of invalid filters", + 'success': 0, 'enabled': True + }, + { + 'bin': "tools/filtering/valid-filters", 'daemon': True, 'kern': False, + 'name': "Filtering - Valid filters", + 'desc': "Validate the expected trace output of valid filters", + 'success': 0, 'enabled': True + }, + + # Tools health check tests + { + 'bin': "tools/health/health_thread_exit", 'daemon': "test", 'kern': True, + 'name': "Health check - Thread exit", + 'desc': "Call exit in the various lttng-sessiond threads and ensure that health failure is detected", + 'success': 0, 'enabled': True + }, + { + 'bin': "tools/health/health_thread_stall", 'daemon': "test", 'kern': True, + 'name': "Health check - Thread stall", + 'desc': "Stall the various lttng-sessiond threads and ensure that health failure is detected", + 'success': 0, 'enabled': True + }, + { + 'bin': "tools/health/health_tp_fail", 'daemon': "test", 'kern': True, + 'name': "Health check - Testpoint failure", + 'desc': "Trigger a failure in the testpoint mechanism in each thread to provoke thread teardown", + 'success': 0, 'enabled': True + }, + + # Tools streaming tests + { + 'bin': "tools/streaming/run-kernel", 'daemon': True, 'kern': True, + 'name': "Streaming - Kernel tracing", + 'desc': "Stream a kernel trace across the network", + 'success': 0, 'enabled': True + }, + { + 'bin': "tools/streaming/run-ust", 'daemon': True, 'kern': False, + 'name': "Streaming - Userspace tracing", + 'desc': "Stream a userspace trace across the network", + 'success': 0, 'enabled': True + }, + { + 'bin': "tools/streaming/uri_switch", 'daemon': True, 'kern': False, + 'name': "Streaming - URI switching", + 'desc': "Switch URI and verify that the trace result are in the proper location", + 'success': 0, 'enabled': True + }, + { + 'bin': "tools/streaming/high_throughput_limits", 'daemon': True, 'kern': True, + 'name': "Streaming - High throughput with bandwith limits", + 'desc': "Trace streaming with bandwidth limits", + 'success': 0, 'enabled': True + }, +] diff --git a/tests/regression/tools/Makefile.am b/tests/regression/tools/Makefile.am new file mode 100644 index 000000000..40f3cc0c1 --- /dev/null +++ b/tests/regression/tools/Makefile.am @@ -0,0 +1,41 @@ +SUBDIRS = streaming filtering health + +AM_CFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/src -I$(top_srcdir)/tests/utils -g -Wall +AM_LDFLAGS = -lurcu + +EXTRA_DIST = runall.sh + +noinst_PROGRAMS = test_sessions test_kernel_data_trace + +UTILS=$(top_srcdir)/tests/utils/utils.h +SESSIONS=$(top_srcdir)/src/bin/lttng-sessiond/session.c \ + $(top_srcdir)/src/bin/lttng-sessiond/consumer.c \ + $(top_srcdir)/src/common/uri.c \ + $(top_srcdir)/src/common/utils.c \ + $(top_srcdir)/src/common/error.c +KERN_DATA_TRACE=$(top_srcdir)/src/bin/lttng-sessiond/trace-kernel.c \ + $(top_srcdir)/src/bin/lttng-sessiond/consumer.c \ + $(top_srcdir)/src/common/uri.c \ + $(top_srcdir)/src/common/utils.c +COMMON=$(top_builddir)/src/common/libcommon.la +HASHTABLE=$(top_builddir)/src/common/hashtable/libhashtable.la +SESSIOND_COMM=$(top_builddir)/src/common/sessiond-comm/libsessiond-comm.la + +# Tracing sessions unit tests +test_sessions_SOURCES = test_sessions.c $(UTILS) $(SESSIONS) +test_sessions_LDADD = $(COMMON) $(HASHTABLE) $(SESSIOND_COMM) + +# Kernel trace data unit tests +test_kernel_data_trace_SOURCES = test_kernel_data_trace.c $(UTILS) $(KERN_DATA_TRACE) +test_kernel_data_trace_LDADD = $(COMMON) $(SESSIOND_COMM) $(HASHTABLE) + +if HAVE_LIBLTTNG_UST_CTL +noinst_PROGRAMS += test_ust_data_trace +UST_DATA_TRACE=$(top_srcdir)/src/bin/lttng-sessiond/trace-ust.c \ + $(top_srcdir)/src/bin/lttng-sessiond/consumer.c \ + $(top_srcdir)/src/common/uri.c \ + $(top_srcdir)/src/common/utils.c +# UST trace data unit tests +test_ust_data_trace_SOURCES = test_ust_data_trace.c $(UTILS) $(UST_DATA_TRACE) +test_ust_data_trace_LDADD = $(COMMON) $(HASHTABLE) $(SESSIOND_COMM) +endif diff --git a/tests/regression/tools/filtering/Makefile.am b/tests/regression/tools/filtering/Makefile.am new file mode 100644 index 000000000..e1e715da4 --- /dev/null +++ b/tests/regression/tools/filtering/Makefile.am @@ -0,0 +1,18 @@ +AM_CFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/src -I$(top_srcdir)/tests -I$(srcdir) -O2 -g +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 = runall unsupported-ops invalid-filters valid-filters babelstats.pl +EXTRA_DIST = runall unsupported-ops invalid-filters valid-filters babelstats.pl diff --git a/tests/regression/tools/filtering/babelstats.pl b/tests/regression/tools/filtering/babelstats.pl new file mode 100755 index 000000000..d8d4dd08e --- /dev/null +++ b/tests/regression/tools/filtering/babelstats.pl @@ -0,0 +1,174 @@ +#!/usr/bin/perl + +# Copyright (C) - 2012 Christian Babeux +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License, version 2 only, as +# published by the Free Software Foundation. +# +# 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. + +use strict; +use warnings; + +use Getopt::Long; + +my $opt_tracepoint; + +GetOptions('tracepoint=s' => \$opt_tracepoint) + or die("Invalid command-line option\n"); + +defined($opt_tracepoint) + or die("Missing tracepoint, use --tracepoint "); + +# Parse an array string. +# The format is as follow: [ [index] = value, ... ] +sub parse_array +{ + my ($arr_str) = @_; + my @array = (); + + # Strip leading and ending brackets, remove whitespace + $arr_str =~ s/^\[//; + $arr_str =~ s/\]$//; + $arr_str =~ s/\s//g; + + my @entries = split(',', $arr_str); + + foreach my $entry (@entries) { + if ($entry =~ /^\[(\d+)\]=(\d+)$/) { + my $index = $1; + my $value = $2; + splice @array, $index, 0, $value; + } + } + + return \@array; +} + +# Parse fields values. +# Format can either be a name = array or a name = value pair. +sub parse_fields +{ + my ($fields_str) = @_; + my %fields_hash; + + my $field_name = '[\w\d_]+'; + my $field_value = '[\w\d_\\\*"]+'; + my $array = '\[(?:\s\[\d+\]\s=\s\d+,)*\s\[\d+\]\s=\s\d+\s\]'; + + # Split the various fields + my @fields = ($fields_str =~ /$field_name\s=\s(?:$array|$field_value)/g); + + foreach my $field (@fields) { + if ($field =~ /($field_name)\s=\s($array)/) { + my $name = $1; + my $value = parse_array($2); + $fields_hash{$name} = $value; + } + + if ($field =~ /($field_name)\s=\s($field_value)/) { + my $name = $1; + my $value = $2; + $fields_hash{$name} = $value; + } + } + + return \%fields_hash; +} + +# Using an event array, merge all the fields +# of a particular tracepoint. +sub merge_fields +{ + my ($events_ref) = @_; + my %merged; + + foreach my $event (@{$events_ref}) { + my $tp_provider = $event->{'tp_provider'}; + my $tp_name = $event->{'tp_name'}; + my $tracepoint = "$tp_provider:$tp_name"; + + foreach my $key (keys %{$event->{'fields'}}) { + my $val = $event->{'fields'}->{$key}; + + # TODO: Merge of array is not implemented. + next if (ref($val) eq 'ARRAY'); + $merged{$tracepoint}{$key}{$val} = undef; + } + } + + return \%merged; +} + +# Print the minimum and maximum of each fields +# for a particular tracepoint. +sub print_fields_stats +{ + my ($merged_ref, $tracepoint) = @_; + + return unless ($tracepoint && exists $merged_ref->{$tracepoint}); + + foreach my $field (keys %{$merged_ref->{$tracepoint}}) { + my @sorted; + my @val = keys ($merged_ref->{$tracepoint}->{$field}); + + if ($val[0] =~ /^\d+$/) { + # Sort numerically + @sorted = sort { $a <=> $b } @val; + } elsif ($val[0] =~ /^0x[\da-f]+$/i) { + # Convert the hex values and sort numerically + @sorted = sort { hex($a) <=> hex($b) } @val; + } else { + # Fallback, alphabetical sort + @sorted = sort { lc($a) cmp lc($b) } @val; + } + + my $min = $sorted[0]; + my $max = $sorted[-1]; + + print "$field $min $max\n"; + } +} + +my @events; + +while (<>) +{ + my $timestamp = '\[(.*)\]'; + my $elapsed = '\((.*)\)'; + my $hostname = '.*'; + my $pname = '.*'; + my $pid = '\d+'; + my $tp_provider = '.*'; + my $tp_name = '.*'; + my $cpu_info = '{\scpu_id\s=\s(\d+)\s\}'; + my $fields = '{(.*)}'; + + # Parse babeltrace text output format + if (/$timestamp\s$elapsed\s($hostname):($pname):($pid)\s($tp_provider):($tp_name):\s$cpu_info,\s$fields/) { + my %event_hash; + + $event_hash{'timestamp'} = $1; + $event_hash{'elapsed'} = $2; + $event_hash{'hostname'} = $3; + $event_hash{'pname'} = $4; + $event_hash{'pid'} = $5; + $event_hash{'tp_provider'} = $6; + $event_hash{'tp_name'} = $7; + $event_hash{'cpu_id'} = $8; + $event_hash{'fields'} = parse_fields($9); + + push @events, \%event_hash; + } +} + +my %merged_fields = %{merge_fields(\@{events})}; +print_fields_stats(\%merged_fields, $opt_tracepoint); diff --git a/tests/regression/tools/filtering/gen-ust-events.c b/tests/regression/tools/filtering/gen-ust-events.c new file mode 100644 index 000000000..c789c89d4 --- /dev/null +++ b/tests/regression/tools/filtering/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"; + char escape[10] = "\\*"; + 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), escape, dbl, flt); + usleep(nr_usec); + } + + return 0; +} diff --git a/tests/regression/tools/filtering/invalid-filters b/tests/regression/tools/filtering/invalid-filters new file mode 100755 index 000000000..48db698dd --- /dev/null +++ b/tests/regression/tools/filtering/invalid-filters @@ -0,0 +1,150 @@ +#!/bin/bash +# +# Copyright (C) - 2012 Christian Babeux +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License, version 2 only, as +# published by the Free Software Foundation. +# +# 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. + +TEST_DESC="Filtering - Invalid filters" + +CURDIR=$(dirname $0)/ +TESTDIR=$CURDIR/../../.. +LTTNG_BIN="lttng" +SESSION_NAME="filter-invalid" +EVENT_NAME="bogus" +ENABLE_EVENT_STDERR="/tmp/invalid-filters-stderr" +TRACE_PATH=$(mktemp -d) + +source $TESTDIR/utils/utils.sh + +print_test_banner "$TEST_DESC" + +function enable_ust_lttng_event_filter +{ + sess_name="$1" + event_name="$2" + filter="$3" + echo -n "Enabling lttng event with filtering and invalid filter " + + $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event $event_name -s $sess_name -u --filter "$filter" 2> $ENABLE_EVENT_STDERR 1> /dev/null + + # Enable must fail + if [ $? -eq 0 ]; then + print_fail + return 1 + else + print_ok + return 0 + fi +} + +function test_invalid_filter +{ + test_invalid_filter="$1" + + echo "" + echo -e "=== Testing filter expression with invalid filter" + echo -e "Filter: $test_invalid_filter" + + # Create session + create_lttng_session $SESSION_NAME $TRACE_PATH + + # Apply filter + enable_ust_lttng_event_filter $SESSION_NAME $EVENT_NAME "$test_invalid_filter" + + # Destroy session + destroy_lttng_session $SESSION_NAME +} + +function test_bytecode_limit +{ + # Current bytecode limitation is 65536 bytes long. + # Generate a huge bytecode with some perl-fu + BYTECODE_LIMIT=`perl -e 'print "intfield" . " && 1" x5460'` + + echo "" + echo -e "=== Testing filter bytecode limits (64KiB)" + + # Create session + create_lttng_session $SESSION_NAME $TRACE_PATH + + # Apply filter + enable_ust_lttng_event_filter $SESSION_NAME $EVENT_NAME "$BYTECODE_LIMIT" + + # Destroy session + destroy_lttng_session $SESSION_NAME +} + +IFS=$'\n' +INVALID_FILTERS=( + # Unsupported ops + "intfield*1" + "intfield/1" + "intfield+1" + "intfield-1" + "intfield>>1" + "intfield<<1" + "intfield&1" + "intfield|1" + "intfield^1" + "~intfield" + "1+11111-3333+1" + "(1+2)*(55*666)" + "1+2*55*666" + "asdf + 1 > 1" + "asdfas < 2332 || asdf + 1 > 1" + "!+-+++-------+++++++++++-----!!--!44+1" + "aaa||(gg)+(333----1)" + "1+1" + # Unmatched parenthesis + "((((((((((((((intfield)))))))))))))" + '0 || ("abc" != "def")) && (3 < 4)' + # Field dereference + "a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a" + "a->" + "a-->a" + "a->a" + "a.b.c->d.e.f+1" + "!a.f.d" + "asdf.asdfsd.sadf < 4" + "asdfasdf->asdfasdf < 2" + # String can't be root node + "\"somestring\"" + # Unary op on string not allowed + "!\"somestring\"" + # Comparison with string type not allowed + "\"somestring\" > 42" + "\"somestring\" > 42.0" + "42 > \"somestring\"" + "42.0 > \"somestring\"" + # Logical operator with string type not allowed + "\"somestring\" || 1" + "1 || \"somestring\"" + # Nesting of binary operator not allowed + "1 | (1 | (1 | 1))" + "1 > (1 > (1 > 1))" + ) + +start_lttng_sessiond +for FILTER in ${INVALID_FILTERS[@]}; +do + test_invalid_filter "$FILTER" +done + +test_bytecode_limit + +unset IFS +stop_lttng_sessiond + +rm -f $ENABLE_EVENT_STDERR +rm -rf $TRACE_PATH diff --git a/tests/regression/tools/filtering/runall b/tests/regression/tools/filtering/runall new file mode 100755 index 000000000..c92e39988 --- /dev/null +++ b/tests/regression/tools/filtering/runall @@ -0,0 +1,28 @@ +#!/bin/bash + +DIR=$(dirname $0) + +tests=( $DIR/unsupported-ops $DIR/invalid-filters $DIR/valid-filters ) +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/regression/tools/filtering/tp.c b/tests/regression/tools/filtering/tp.c new file mode 100644 index 000000000..a09561d70 --- /dev/null +++ b/tests/regression/tools/filtering/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/regression/tools/filtering/tp.h b/tests/regression/tools/filtering/tp.h new file mode 100644 index 000000000..15f81e5c0 --- /dev/null +++ b/tests/regression/tools/filtering/tp.h @@ -0,0 +1,57 @@ +#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, + char *, etext, 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_string(stringfield2, etext) + 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/regression/tools/filtering/unsupported-ops b/tests/regression/tools/filtering/unsupported-ops new file mode 100755 index 000000000..9fac9dec8 --- /dev/null +++ b/tests/regression/tools/filtering/unsupported-ops @@ -0,0 +1,114 @@ +#!/bin/bash +# +# Copyright (C) - 2012 Christian Babeux +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License, version 2 only, as +# published by the Free Software Foundation. +# +# 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. + +TEST_DESC="Filtering - Unsupported operators" + +CURDIR=$(dirname $0)/ +TESTDIR=$CURDIR/../../.. +LTTNG_BIN="lttng" +SESSION_NAME="filter-unsupported-ops" +EVENT_NAME="bogus" +ENABLE_EVENT_STDERR="/tmp/unsupported-ops-enable" +TRACE_PATH=$(mktemp -d) + +source $TESTDIR/utils/utils.sh + +print_test_banner "$TEST_DESC" + +function enable_ust_lttng_event_filter_unsupported +{ + sess_name=$1 + event_name=$2 + filter=$3 + + echo -n "Enabling lttng event with filtering and unsupported operator " + enable_cmd="$TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event" + $enable_cmd $event_name -s $sess_name -u --filter "$filter" 2> $ENABLE_EVENT_STDERR 1> /dev/null + + # Enable must fail + if [ $? -eq 0 ]; then + print_fail + return 1 + else + print_ok + return 0 + fi +} + +function test_unsupported_op +{ + test_op_str=$1 + test_op_tkn=$2 + + echo "" + echo -e "=== Testing filter expression with unsupported operator $test_op_str ($test_op_tkn)" + + # Create session + create_lttng_session $SESSION_NAME $TRACE_PATH + + # Create filter + if [ "$test_op_str" == "UNARY_BIN_NOT" ]; then + TEST_FILTER="${test_op_tkn}1" + else + TEST_FILTER="intfield $test_op_tkn 1" + fi + + # Apply filter + enable_ust_lttng_event_filter_unsupported $SESSION_NAME $EVENT_NAME "$TEST_FILTER" + + # Test stderr for unsupported operator + echo -n "Unsupported operator test $test_op_str ($test_op_tkn) " + grep -i -q "not[[:space:]]\+supported" $ENABLE_EVENT_STDERR + + if [ $? -eq 1 ]; then + print_fail + return 1 + else + print_ok + fi + + # Destroy session + destroy_lttng_session $SESSION_NAME + return 0 +} + +# Unsupported operators +OP_STR=("MUL" "DIV" "MOD" "PLUS" "MINUS" "LSHIFT" "RSHIFT" + "BIN_AND" "BIN_OR" "BIN_XOR" "UNARY_BIN_NOT") + +OP_TKN=("*" "/" "%" "+" "-" "<<" ">>" "&" "|" "^" "~") + +OP_COUNT=${#OP_STR[@]} +i=0 + +start_lttng_sessiond + +while [ "$i" -lt "$OP_COUNT" ]; do + test_unsupported_op "${OP_STR[$i]}" "${OP_TKN[$i]}" + + if [ $? -eq 1 ]; then + exit 1 + fi + + let "i++" +done + +stop_lttng_sessiond + +# Cleanup +rm -f $ENABLE_EVENT_STDERR +rm -rf $TRACE_PATH diff --git a/tests/regression/tools/filtering/valid-filters b/tests/regression/tools/filtering/valid-filters new file mode 100755 index 000000000..067d205e7 --- /dev/null +++ b/tests/regression/tools/filtering/valid-filters @@ -0,0 +1,417 @@ +#!/bin/bash +# +# Copyright (C) - 2012 Christian Babeux +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License, version 2 only, as +# published by the Free Software Foundation. +# +# 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. + +TEST_DESC="Filtering - Valid filters" + +CURDIR=$(dirname $0)/ +TESTDIR=$CURDIR/../../.. +LTTNG_BIN="lttng" +BIN_NAME="gen-ust-events" +STATS_BIN="babelstats.pl" +SESSION_NAME="valid_filter" +EVENT_NAME="tp:tptest" +NR_ITER=100 + +source $TESTDIR/utils/utils.sh + +print_test_banner "$TEST_DESC" + +if [ ! -x "$CURDIR/$BIN_NAME" ]; then + echo -e "No UST nevents binary detected. Passing." + exit 0 +fi + +function enable_ust_lttng_event_filter() +{ + sess_name="$1" + event_name="$2" + filter="$3" + echo -n "Enabling lttng event with filtering " + + $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event $event_name -s $sess_name -u --filter "$filter" 2>&1 >/dev/null + + if [ $? -eq 0 ]; then + print_ok + return 0 + else + print_fail + return 1 + fi +} + +function run_apps +{ + ./$CURDIR/$BIN_NAME $NR_ITER & >/dev/null 2>&1 +} + +function wait_apps +{ + echo "Waiting for applications to end" + while [ -n "$(pidof $BIN_NAME)" ]; do + echo -n "." + sleep 1 + done + echo "" +} + +function test_valid_filter +{ + filter="$1" + validator="$2" + + echo "" + echo -e "=== Testing valid filter: $1" + + trace_path=$(mktemp -d) + + # Create session + create_lttng_session $SESSION_NAME $trace_path + + # Enable filter + enable_ust_lttng_event_filter $SESSION_NAME $EVENT_NAME $filter + + # Trace apps + start_lttng_tracing $SESSION_NAME + run_apps + wait_apps + stop_lttng_tracing $SESSION_NAME + + # Destroy session + destroy_lttng_session $SESSION_NAME + + echo -n "Validating filter output " + stats=`babeltrace $trace_path | $CURDIR/$STATS_BIN --tracepoint $EVENT_NAME` + + rm -rf $trace_path + + $validator "$stats" + + if [ $? -eq 0 ]; then + print_ok +# rm -rf $trace_path + return 0 + else + print_fail + return 1 + fi +} + +function validate_min_max +{ + stats="$1" + field=$2 + expected_min=$3 + expected_max=$4 + + echo $stats | grep -q "$field $expected_min $expected_max" + + return $? +} + +function validator_intfield +{ + stats="$1" + status=0 + + validate_min_max "$stats" "intfield" "1" "99" + status=$(($status|$?)) + + validate_min_max "$stats" "intfield2" "0x1" "0x63" + status=$(($status|$?)) + + validate_min_max "$stats" "longfield" "1" "99" + status=$(($status|$?)) + + validate_min_max "$stats" "netintfield" "1" "99" + status=$(($status|$?)) + + validate_min_max "$stats" "netintfieldhex" "0x1" "0x63" + status=$(($status|$?)) + + validate_min_max "$stats" "floatfield" "2222" "2222" + status=$(($status|$?)) + + validate_min_max "$stats" "doublefield" "2" "2" + status=$(($status|$?)) + + return $status +} + +function validator_intfield_gt +{ + stats="$1" + status=0 + + validate_min_max "$stats" "intfield" "2" "99" + status=$(($status|$?)) + + return $status +} + +function validator_intfield_ge +{ + stats="$1" + status=0 + + validate_min_max "$stats" "intfield" "1" "99" + status=$(($status|$?)) + + return $status +} + +function validator_intfield_lt +{ + stats="$1" + status=0 + + validate_min_max "$stats" "intfield" "0" "1" + status=$(($status|$?)) + + return $status +} + +function validator_intfield_le +{ + stats="$1" + status=0 + + validate_min_max "$stats" "intfield" "0" "2" + status=$(($status|$?)) + + return $status +} + +function validator_intfield_eq +{ + stats="$1" + status=0 + + validate_min_max "$stats" "intfield" "1" "1" + status=$(($status|$?)) + + return $status +} + +function validator_intfield_ne +{ + stats="$1" + status=0 + + validate_min_max "$stats" "intfield" "0" "98" + status=$(($status|$?)) + + return $status +} + +function validator_intfield_not +{ + stats="$1" + status=0 + + validate_min_max "$stats" "intfield" "0" "0" + status=$(($status|$?)) + + return $status +} + +function validator_intfield_gt_and_longfield_gt +{ + stats="$1" + status=0 + + validate_min_max "$stats" "intfield" "43" "99" + status=$(($status|$?)) + validate_min_max "$stats" "longfield" "43" "99" + status=$(($status|$?)) + + return $status +} + +function validator_intfield_ge_and_longfield_le +{ + stats="$1" + status=0 + + validate_min_max "$stats" "intfield" "42" "42" + status=$(($status|$?)) + validate_min_max "$stats" "longfield" "42" "42" + status=$(($status|$?)) + + return $status +} + +function validator_intfield_lt_or_longfield_gt +{ + stats="$1" + status=0 + + validate_min_max "$stats" "intfield" "0" "99" + status=$(($status|$?)) + validate_min_max "$stats" "longfield" "0" "99" + status=$(($status|$?)) + + return $status +} + +function validator_mixed_str_or_int_and_int +{ + stats="$1" + status=0 + + validate_min_max "$stats" "intfield" "34" "99" + status=$(($status|$?)) + + validate_min_max "$stats" "stringfield" "\"test\"" "\"test\"" + status=$(($status|$?)) + + return $status +} + +function validator_mixed_int_double +{ + stats="$1" + status=0 + + validate_min_max "$stats" "intfield" "0" "42" + status=$(($status|$?)) + + return $status +} + +function validator_true_statement +{ + stats="$1" + status=0 + + validate_min_max "$stats" "intfield" "0" "99" + status=$(($status|$?)) + + validate_min_max "$stats" "intfield2" "0x0" "0x63" + status=$(($status|$?)) + + validate_min_max "$stats" "longfield" "0" "99" + status=$(($status|$?)) + + validate_min_max "$stats" "netintfield" "0" "99" + status=$(($status|$?)) + + validate_min_max "$stats" "netintfieldhex" "0x0" "0x63" + status=$(($status|$?)) + + validate_min_max "$stats" "floatfield" "2222" "2222" + status=$(($status|$?)) + + validate_min_max "$stats" "doublefield" "2" "2" + status=$(($status|$?)) + + validate_min_max "$stats" "stringfield" "\"test\"" "\"test\"" + status=$(($status|$?)) + + validate_min_max "$stats" "stringfield2" ""\*"" ""\*"" + status=$(($status|$?)) + + return $status +} + +IFS=$'\n' + +issue_356_filter="intfield > 0 && intfield > 1 && " +issue_356_filter+="intfield > 2 && intfield > 3 && " +issue_356_filter+="intfield > 4 && intfield > 5 && " +issue_356_filter+="intfield > 6 && intfield > 7 && " +issue_356_filter+="intfield > 8 || intfield > 0" + +# One to one mapping between filters and validators + +FILTERS=("intfield" #1 + "intfield > 1" #2 + "intfield >= 1" #3 + "intfield < 2" #4 + "intfield <= 2" #5 + "intfield == 1" #6 + "intfield != 99" #7 + "!intfield" #8 + "-intfield" #9 + "--intfield" #10 + "+intfield" #11 + "++intfield" #12 + "intfield > 1 && longfield > 42" #13 + "intfield >= 42 && longfield <= 42" #14 + "intfield < 1 || longfield > 98" #15 + "(stringfield == \"test\" || intfield != 10) && intfield > 33" #16 + "intfield < 42.4242424242" #17 + "\"test\" == \"test\"" #18 #Issue #342 + "stringfield == \"test\"" #19 + "stringfield == \"t*\"" #20 + "stringfield == \"*\"" #21 + $issue_356_filter #22 #Issue #356 + "intfield < 0xDEADBEEF" #23 + "intfield < 0x2" #24 + "intfield < 02" #25 + "stringfield2 == \"\\\*\"" #26 + "1.0 || intfield || 1.0" #27 + "1 < intfield" #28 +) + +VALIDATOR=("validator_intfield" #1 + "validator_intfield_gt" #2 + "validator_intfield_ge" #3 + "validator_intfield_lt" #4 + "validator_intfield_le" #5 + "validator_intfield_eq" #6 + "validator_intfield_ne" #7 + "validator_intfield_not" #8 + "validator_intfield" #9 + "validator_intfield" #10 + "validator_intfield" #11 + "validator_intfield" #12 + "validator_intfield_gt_and_longfield_gt" #13 + "validator_intfield_ge_and_longfield_le" #14 + "validator_intfield_lt_or_longfield_gt" #15 + "validator_mixed_str_or_int_and_int" #16 + "validator_mixed_int_double" #17 + "validator_true_statement" #18 + "validator_true_statement" #19 + "validator_true_statement" #20 + "validator_true_statement" #21 + "validator_intfield" #22 + "validator_true_statement" #23 + "validator_intfield_lt" #24 + "validator_intfield_lt" #25 + "validator_true_statement" #26 + "validator_true_statement" #27 + "validator_intfield_gt" #28 +) + +FILTER_COUNT=${#FILTERS[@]} +i=0 + +start_lttng_sessiond + +while [ "$i" -lt "$FILTER_COUNT" ]; do + + test_valid_filter "${FILTERS[$i]}" "${VALIDATOR[$i]}" + + if [ $? -eq 1 ]; then + stop_lttng_sessiond + exit 1 + fi + + let "i++" +done + +stop_lttng_sessiond diff --git a/tests/regression/tools/health/Makefile.am b/tests/regression/tools/health/Makefile.am new file mode 100644 index 000000000..1a0a8f6d1 --- /dev/null +++ b/tests/regression/tools/health/Makefile.am @@ -0,0 +1,41 @@ +AM_CFLAGS = -I. -O2 -g -I$(top_srcdir)/include +AM_LDFLAGS = + +if LTTNG_TOOLS_BUILD_WITH_LIBDL +AM_LDFLAGS += -ldl +endif +if LTTNG_TOOLS_BUILD_WITH_LIBC_DL +AM_LDFLAGS += -lc +endif + +if NO_SHARED +# Do not build this test if shared libraries support was +# explicitly disabled. +else +# In order to test the health check feature, the libhealth* libs +# must be built as .so to be able to LD_PRELOAD them. +FORCE_SHARED_LIB_OPTIONS = -module -shared -avoid-version \ + -rpath $(abs_builddir) + +# Health thread exit ld_preloaded test lib +libhealthexit_la_SOURCES=health_exit.c +libhealthexit_la_LDFLAGS= $(FORCE_SHARED_LIB_OPTIONS) + +# Health thread stall ld_preloaded test lib +libhealthstall_la_SOURCES=health_stall.c +libhealthstall_la_LDFLAGS= $(FORCE_SHARED_LIB_OPTIONS) + +# Health thread fail ld_preloaded test lib +libhealthtpfail_la_SOURCES=health_fail.c +libhealthtpfail_la_LDFLAGS= $(FORCE_SHARED_LIB_OPTIONS) + +noinst_PROGRAMS = health_check +noinst_LTLIBRARIES = libhealthexit.la libhealthstall.la libhealthtpfail.la + +health_check_SOURCES = health_check.c $(UTILS) +health_check_LDADD = $(top_builddir)/src/lib/lttng-ctl/liblttng-ctl.la \ + $(top_builddir)/src/common/libcommon.la +endif + +noinst_SCRIPTS = runall +EXTRA_DIST = runall diff --git a/tests/regression/tools/health/health_check.c b/tests/regression/tools/health/health_check.c new file mode 100644 index 000000000..3eef11040 --- /dev/null +++ b/tests/regression/tools/health/health_check.c @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2012 - Christian Babeux + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License, version 2 only, as + * published by the Free Software Foundation. + * + * 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. + */ + +#include + +#include "lttng/lttng.h" + +#define HEALTH_CMD_FAIL (1 << 0) +#define HEALTH_APP_MNG_FAIL (1 << 1) +#define HEALTH_APP_REG_FAIL (1 << 2) +#define HEALTH_KERNEL_FAIL (1 << 3) +#define HEALTH_CSMR_FAIL (1 << 4) + +int main(int argc, char *argv[]) +{ + int health = -1; + int status = 0; + + /* Command thread */ + health = lttng_health_check(LTTNG_HEALTH_CMD); + printf("Health check cmd: %d\n", health); + + if (health) { + status |= HEALTH_CMD_FAIL; + } + + /* App manage thread */ + health = lttng_health_check(LTTNG_HEALTH_APP_MANAGE); + printf("Health check app. manage: %d\n", health); + + if (health) { + status |= HEALTH_APP_MNG_FAIL; + } + /* App registration thread */ + health = lttng_health_check(LTTNG_HEALTH_APP_REG); + printf("Health check app. registration: %d\n", health); + + if (health) { + status |= HEALTH_APP_REG_FAIL; + } + + /* Kernel thread */ + health = lttng_health_check(LTTNG_HEALTH_KERNEL); + printf("Health check kernel: %d\n", health); + + if (health) { + status |= HEALTH_KERNEL_FAIL; + } + + /* Consumer thread */ + health = lttng_health_check(LTTNG_HEALTH_CONSUMER); + printf("Health check consumer: %d\n", health); + + if (health) { + status |= HEALTH_CSMR_FAIL; + } + + return status; +} diff --git a/tests/regression/tools/health/health_exit.c b/tests/regression/tools/health/health_exit.c new file mode 100644 index 000000000..8e414053e --- /dev/null +++ b/tests/regression/tools/health/health_exit.c @@ -0,0 +1,91 @@ +/* + * Copyright (C) 2012 - Christian Babeux + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License, version 2 only, as + * published by the Free Software Foundation. + * + * 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. + */ + +#include +#include +#include + +/* + * Check if the specified environment variable is set. + * Return 1 if set, otherwise 0. + */ +int check_env_var(const char *env) +{ + if (env) { + char *env_val = getenv(env); + if (env_val && (strncmp(env_val, "1", 1) == 0)) { + return 1; + } + } + + return 0; +} + +int __testpoint_thread_manage_clients(void) +{ + const char *var = "LTTNG_THREAD_MANAGE_CLIENTS_EXIT"; + + if (check_env_var(var)) { + pthread_exit(NULL); + } + + return 0; +} + +int __testpoint_thread_registration_apps(void) +{ + const char *var = "LTTNG_THREAD_REG_APPS_EXIT"; + + if (check_env_var(var)) { + pthread_exit(NULL); + } + + return 0; +} + +int __testpoint_thread_manage_apps(void) +{ + const char *var = "LTTNG_THREAD_MANAGE_APPS_EXIT"; + + if (check_env_var(var)) { + pthread_exit(NULL); + } + + return 0; +} + +int __testpoint_thread_manage_kernel(void) +{ + const char *var = "LTTNG_THREAD_MANAGE_KERNEL_EXIT"; + + if (check_env_var(var)) { + pthread_exit(NULL); + } + + return 0; +} + +int __testpoint_thread_manage_consumer(void) +{ + const char *var = "LTTNG_THREAD_MANAGE_CONSUMER_EXIT"; + + if (check_env_var(var)) { + pthread_exit(NULL); + } + + return 0; +} diff --git a/tests/regression/tools/health/health_fail.c b/tests/regression/tools/health/health_fail.c new file mode 100644 index 000000000..622782548 --- /dev/null +++ b/tests/regression/tools/health/health_fail.c @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2012 - Christian Babeux + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License, version 2 only, as + * published by the Free Software Foundation. + * + * 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. + */ + +#include +#include +#include + +/* + * Check if the specified environment variable is set. + * Return 1 if set, otherwise 0. + */ +int check_env_var(const char *env) +{ + if (env) { + char *env_val = getenv(env); + if (env_val && (strncmp(env_val, "1", 1) == 0)) { + return 1; + } + } + + return 0; +} + +int __testpoint_thread_manage_clients(void) +{ + const char *var = "LTTNG_THREAD_MANAGE_CLIENTS_TP_FAIL"; + + if (check_env_var(var)) { + return 1; + } + + return 0; +} + +int __testpoint_thread_manage_apps(void) +{ + const char *var = "LTTNG_THREAD_MANAGE_APPS_TP_FAIL"; + + if (check_env_var(var)) { + return 1; + } + + return 0; +} + +int __testpoint_thread_manage_kernel(void) +{ + const char *var = "LTTNG_THREAD_MANAGE_KERNEL_TP_FAIL"; + + if (check_env_var(var)) { + return 1; + } + + return 0; +} diff --git a/tests/regression/tools/health/health_stall.c b/tests/regression/tools/health/health_stall.c new file mode 100644 index 000000000..127f5fcf9 --- /dev/null +++ b/tests/regression/tools/health/health_stall.c @@ -0,0 +1,81 @@ +/* + * Copyright (C) 2012 - Christian Babeux + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License, version 2 only, as + * published by the Free Software Foundation. + * + * 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. + */ + +#include +#include +#include +#include + +#define STALL_TIME 60 + +/* + * Check if the specified environment variable is set. + * Return 1 if set, otherwise 0. + */ +int check_env_var(const char *env) +{ + if (env) { + char *env_val = getenv(env); + if (env_val && (strncmp(env_val, "1", 1) == 0)) { + return 1; + } + } + + return 0; +} + +int __testpoint_thread_manage_clients_before_loop(void) +{ + const char *var = "LTTNG_THREAD_MANAGE_CLIENTS_STALL"; + + if (check_env_var(var)) { + unsigned int sleep_time = STALL_TIME; + while (sleep_time > 0) { + sleep_time = sleep(sleep_time); + } + } + + return 0; +} + +int __testpoint_thread_manage_kernel_before_loop(void) +{ + const char *var = "LTTNG_THREAD_MANAGE_KERNEL_STALL"; + + if (check_env_var(var)) { + unsigned int sleep_time = STALL_TIME; + while (sleep_time > 0) { + sleep_time = sleep(sleep_time); + } + } + + return 0; +} + +int __testpoint_thread_manage_apps_before_loop(void) +{ + const char *var = "LTTNG_THREAD_MANAGE_APPS_STALL"; + + if (check_env_var(var)) { + unsigned int sleep_time = STALL_TIME; + while (sleep_time > 0) { + sleep_time = sleep(sleep_time); + } + } + + return 0; +} diff --git a/tests/regression/tools/health/health_thread_exit b/tests/regression/tools/health/health_thread_exit new file mode 100755 index 000000000..79e0e051d --- /dev/null +++ b/tests/regression/tools/health/health_thread_exit @@ -0,0 +1,105 @@ +#!/bin/bash +# +# Copyright (C) - 2012 Christian Babeux +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License, version 2 only, as +# published by the Free Software Foundation. +# +# 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. + +TEST_DESC="Health check - Thread exit" + +CURDIR=$(dirname $0)/ +TESTDIR=$CURDIR/../../.. +LTTNG_BIN="lttng" +SESSION_NAME="health_thread_exit" +EVENT_NAME="bogus" +HEALTH_CHECK_BIN="health_check" +SESSIOND_PRELOAD=".libs/libhealthexit.so" + +source $TESTDIR/utils/utils.sh + +print_test_banner "$TEST_DESC" + +if [ ! -f "$CURDIR/$SESSIOND_PRELOAD" ]; then + echo -e "libhealthexit.so not available for this test. Skipping." + exit 0 +fi + +function test_thread_exit +{ + test_thread_exit_name="$1" + test_thread_exit_code="$2" + + echo "" + echo -e "=== Testing health failure with ${test_thread_exit_name}" + + # Activate testpoints + export LTTNG_TESTPOINT_ENABLE=1 + + # Activate specific thread exit + export ${test_thread_exit_name}_EXIT=1 + + # Spawn sessiond with preload healthexit lib + export LD_PRELOAD="$CURDIR/$SESSIOND_PRELOAD" + start_lttng_sessiond + + # Cleanup some env. var. + unset LD_PRELOAD + unset ${test_thread_exit_name}_EXIT + + # Check initial health status + $CURDIR/$HEALTH_CHECK_BIN &> /dev/null + + echo -n "Validating thread ${test_thread_exit_name} failure... " + + # Wait + sleep 25 + + # Check health status, exit code should indicate failure + $CURDIR/$HEALTH_CHECK_BIN &> /dev/null + + health_check_exit_code=$? + + if [ $health_check_exit_code -eq $test_thread_exit_code ]; then + print_ok + stop_lttng_sessiond + else + print_fail + echo -e "Health returned: $health_check_exit_code\n" + + stop_lttng_sessiond + return 1 + fi +} + +THREAD=("LTTNG_THREAD_MANAGE_CLIENTS" + "LTTNG_THREAD_MANAGE_APPS" + "LTTNG_THREAD_REG_APPS" + "LTTNG_THREAD_MANAGE_KERNEL") + +# Exit code value to indicate specific thread failure +EXIT_CODE=(1 2 4 8) + +THREAD_COUNT=${#THREAD[@]} +i=0 +while [ "$i" -lt "$THREAD_COUNT" ]; do + test_thread_exit "${THREAD[$i]}" "${EXIT_CODE[$i]}" + + if [ $? -eq 1 ]; then + exit 1 + fi + + let "i++" +done + +# Special case manage consumer, need to spawn consumer via commands. +#"LTTNG_THREAD_MANAGE_CONSUMER" diff --git a/tests/regression/tools/health/health_thread_stall b/tests/regression/tools/health/health_thread_stall new file mode 100755 index 000000000..dc9d850f4 --- /dev/null +++ b/tests/regression/tools/health/health_thread_stall @@ -0,0 +1,128 @@ +#!/bin/bash +# +# Copyright (C) - 2012 Christian Babeux +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License, version 2 only, as +# published by the Free Software Foundation. +# +# 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. + +TEST_DESC="Health check - Thread stall" + +CURDIR=$(dirname $0)/ +TESTDIR=$CURDIR/../../.. +LTTNG_BIN="lttng" +SESSION_NAME="health_thread_stall" +EVENT_NAME="bogus" +HEALTH_CHECK_BIN="health_check" +SESSIOND_PRELOAD=".libs/libhealthstall.so" + +source $TESTDIR/utils/utils.sh + +print_test_banner "$TEST_DESC" + +if [ ! -f "$CURDIR/$SESSIOND_PRELOAD" ]; then + echo -e "libhealthstall.so not available for this test. Skipping." + exit 0 +fi + +function test_thread_stall +{ + test_thread_stall_name="$1" + test_thread_exit_code="$2" + + echo "" + echo -e "=== Testing health failure with ${test_thread_stall_name}" + + # Activate testpoints + export LTTNG_TESTPOINT_ENABLE=1 + + # Activate specific thread exit + export ${test_thread_stall_name}_STALL=1 + + # Spawn sessiond with preload healthexit lib + export LD_PRELOAD="$CURDIR/$SESSIOND_PRELOAD" + start_lttng_sessiond + + # Cleanup some env. var. + unset LD_PRELOAD + unset ${test_thread_stall_name}_STALL + + # Check initial health status + $CURDIR/$HEALTH_CHECK_BIN &> /dev/null + + echo -n "Validating that ${test_thread_stall_name} is stalled... " + + # Wait + sleep 25 + + # Check health status, exit code should indicate failure + $CURDIR/$HEALTH_CHECK_BIN &> /dev/null + + health_check_exit_code=$? + + if [ $health_check_exit_code -eq $test_thread_exit_code ]; then + print_ok + else + print_fail + echo -e "Health returned: $health_check_exit_code\n" + + stop_lttng_sessiond + return 1 + fi + + echo -n "Validating that ${test_thread_stall_name} is no longer stalled... " + + # Wait + sleep 40 + + # Check health status, exit code should now pass + $CURDIR/$HEALTH_CHECK_BIN &> /dev/null + + health_check_exit_code=$? + + if [ $health_check_exit_code -eq 0 ]; then + print_ok + stop_lttng_sessiond + else + print_fail + echo -e "Health returned: $health_check_exit_code\n" + stop_lttng_sessiond + return 1 + fi + + +} + +THREAD=("LTTNG_THREAD_MANAGE_CLIENTS" + "LTTNG_THREAD_MANAGE_APPS" +# This thread is a little bit tricky to stall, +# need to send some commands and setup an app. +# "LTTNG_THREAD_REG_APPS" + "LTTNG_THREAD_MANAGE_KERNEL") + +# Exit code value to indicate specific thread failure +EXIT_CODE=(1 + 2 +# 4 + 8) + +THREAD_COUNT=${#THREAD[@]} +i=0 +while [ "$i" -lt "$THREAD_COUNT" ]; do + test_thread_stall "${THREAD[$i]}" "${EXIT_CODE[$i]}" + + if [ $? -eq 1 ]; then + exit 1 + fi + + let "i++" +done diff --git a/tests/regression/tools/health/health_tp_fail b/tests/regression/tools/health/health_tp_fail new file mode 100755 index 000000000..0b474fa78 --- /dev/null +++ b/tests/regression/tools/health/health_tp_fail @@ -0,0 +1,98 @@ +#!/bin/bash +# +# Copyright (C) - 2012 Christian Babeux +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License, version 2 only, as +# published by the Free Software Foundation. +# +# 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. + +TEST_DESC="Health check - Testpoint failure" + +CURDIR=$(dirname $0)/ +TESTDIR=$CURDIR/../../.. +LTTNG_BIN="lttng" +SESSION_NAME="health_tp_fail" +EVENT_NAME="bogus" +HEALTH_CHECK_BIN="health_check" +SESSIOND_PRELOAD=".libs/libhealthtpfail.so" + +source $TESTDIR/utils/utils.sh + +print_test_banner "$TEST_DESC" + +if [ ! -f "$CURDIR/$SESSIOND_PRELOAD" ]; then + echo -e "libhealthtpfail.so not available for this test. Skipping." + exit 0 +fi + +function test_tp_fail +{ + test_tp_fail_name="$1" + test_tp_fail_code="$2" + + echo "" + echo -e "=== Testing health failure with ${test_tp_fail_name}" + + # Activate testpoints + export LTTNG_TESTPOINT_ENABLE=1 + + # Activate specific testpoint failure + export ${test_tp_fail_name}_TP_FAIL=1 + + # Spawn sessiond with preload healthexit lib + export LD_PRELOAD="$CURDIR/$SESSIOND_PRELOAD" + start_lttng_sessiond + + # Cleanup some env. var. + unset LD_PRELOAD + unset ${test_tp_fail_name}_TP_FAIL + + echo -n "Validating thread ${test_tp_fail_name} failure... " + + # Check health status, exit code should indicate failure + $CURDIR/$HEALTH_CHECK_BIN &> /dev/null + + health_check_exit_code=$? + + if [ $health_check_exit_code -eq $test_tp_fail_code ]; then + print_ok + stop_lttng_sessiond + else + print_fail + echo -e "Health returned: $health_check_exit_code\n" + + stop_lttng_sessiond + return 1 + fi +} + +THREAD=("LTTNG_THREAD_MANAGE_CLIENTS" + "LTTNG_THREAD_MANAGE_APPS" + "LTTNG_THREAD_MANAGE_KERNEL") + +# Exit code value to indicate specific thread failure +EXIT_CODE=(1 2 8) + +THREAD_COUNT=${#THREAD[@]} +i=0 +while [ "$i" -lt "$THREAD_COUNT" ]; do + test_tp_fail "${THREAD[$i]}" "${EXIT_CODE[$i]}" + + if [ $? -eq 1 ]; then + exit 1 + fi + + let "i++" +done + +# Special case manage consumer, need to spawn consumer via commands. +#"LTTNG_THREAD_MANAGE_CONSUMER" diff --git a/tests/regression/tools/health/runall b/tests/regression/tools/health/runall new file mode 100755 index 000000000..d1c8b3446 --- /dev/null +++ b/tests/regression/tools/health/runall @@ -0,0 +1,33 @@ +#!/bin/bash + +DIR=$(dirname $0) + +tests=( $DIR/health_thread_exit $DIR/health_thread_stall $DIR/health_tp_fail) +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 +} + +if [ "$(id -u)" != "0" ]; then + echo -e "Need root for health test." + exit 0 +fi + +start_tests + +exit $exit_code diff --git a/tests/regression/tools/runall.sh b/tests/regression/tools/runall.sh new file mode 100755 index 000000000..b2be91c6c --- /dev/null +++ b/tests/regression/tools/runall.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +DIR=$(dirname $0) + +tests=( $DIR/test_kernel_data_trace $DIR/test_sessions $DIR/test_ust_data_trace \ + $DIR/streaming/runall $DIR/health/runall $DIR/filtering/runall) + +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/regression/tools/streaming/Makefile.am b/tests/regression/tools/streaming/Makefile.am new file mode 100644 index 000000000..3fab87e9b --- /dev/null +++ b/tests/regression/tools/streaming/Makefile.am @@ -0,0 +1,27 @@ +AM_CFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/src -I$(top_srcdir)/tests/utils -I$(srcdir) -O2 -g +AM_LDFLAGS = + +if LTTNG_TOOLS_BUILD_WITH_LIBDL +AM_LDFLAGS += -ldl +endif +if LTTNG_TOOLS_BUILD_WITH_LIBC_DL +AM_LDFLAGS += -lc +endif + +#UTILS=../../utils.h +UTILS= +LIBSESSIOND_COMM=$(top_builddir)/src/common/sessiond-comm/libsessiond-comm.la +LIBCOMMON=$(top_builddir)/src/common/libcommon.la + +noinst_PROGRAMS = unit_tests +unit_tests_SOURCES = unit_tests.c $(UTILS) +unit_tests_LDADD = $(LIBCOMMON) + +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 = runall run-ust run-kernel uri_switch +EXTRA_DIST = runall run-ust run-kernel uri_switch diff --git a/tests/regression/tools/streaming/gen-ust-events.c b/tests/regression/tools/streaming/gen-ust-events.c new file mode 100644 index 000000000..1385119d7 --- /dev/null +++ b/tests/regression/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/regression/tools/streaming/high_throughput_limits b/tests/regression/tools/streaming/high_throughput_limits new file mode 100755 index 000000000..e2f094d22 --- /dev/null +++ b/tests/regression/tools/streaming/high_throughput_limits @@ -0,0 +1,200 @@ +#!/bin/bash +# +# Copyright (C) - 2012 Christian Babeux +# 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 + +TEST_DESC="Streaming - High throughput with bandwidth limits" + +CURDIR=$(dirname $0)/ +TESTDIR=$CURDIR/../../.. +NR_APP_ITER=10 +NR_ITER=1000000 +BIN_NAME="gen-ust-events" +SESSION_NAME="high-throughput" +EVENT_NAME="tp:tptest" +SESSIOND_CTRL_PORT=5342 +SESSIOND_DATA_PORT=5343 +DEFAULT_IF="lo" + +TRACE_PATH=$(mktemp -d) + +source $TESTDIR/utils/utils.sh + +print_test_banner "$TEST_DESC" + +if [ ! -x "$CURDIR/$BIN_NAME" ]; then + echo -e "No UST nevents binary detected. Passing." + exit 0 +fi + +if [ "$(id -u)" != "0" ]; then + echo "This test must be running as root to set bandwidth limits. Aborting" + # Exit status 0 so the tests can continue + exit 0 +fi + +function set_bw_limit +{ + limit=$1 + ctrlportlimit=$(($limit/10)) + # failsafe to have at least 1kbit/s for control (in the case where $1 < 10) + [ $ctrlportlimit = 0 ] && ctrlportlimit=1 + # if $1 < 10, we might bust the limit set here, but the + # parent qdisc (1:) will always limit us to the right max value + dataportlimit=$((9*${ctrlportlimit})) + + echo -n "Setting bandwidth limits to ${limit}kbits, (${ctrlportlimit} for control and ${dataportlimit} for data)... " + tc qdisc add dev $DEFAULT_IF root handle 1: htb default 15 >/dev/null 2>&1 + + # the total bandwidth is the limit set by the user + tc class add dev $DEFAULT_IF parent 1: classid 1:1 htb rate ${limit}kbit ceil ${limit}kbit >/dev/null 2>&1 + # 1/10 of the bandwidth guaranteed and traffic prioritized for the control port + tc class add dev $DEFAULT_IF parent 1:1 classid 1:10 htb rate ${ctrlportlimit}kbit ceil ${limit}kbit prio 1 >/dev/null 2>&1 + # 9/10 of the bandwidth guaranteed and can borrow up to the total bandwidth (if unused) + tc class add dev $DEFAULT_IF parent 1:1 classid 1:11 htb rate ${dataportlimit}kbit ceil ${limit}kbit prio 2 >/dev/null 2>&1 + + # filter to assign control traffic to the 1:10 class + tc filter add dev $DEFAULT_IF parent 1: protocol ip u32 match ip dport $SESSIOND_CTRL_PORT 0xffff flowid 1:10 >/dev/null 2>&1 + # filter to assign data traffic to the 1:11 class + tc filter add dev $DEFAULT_IF parent 1: protocol ip u32 match ip dport $SESSIOND_DATA_PORT 0xffff flowid 1:11 >/dev/null 2>&1 + print_ok +} + +function reset_bw_limit +{ + echo -n "Resetting bandwidth limits... " + tc qdisc del dev $DEFAULT_IF root >/dev/null 2>&1 + print_ok +} + +function create_lttng_session_with_uri +{ + sess_name=$1 + uri=$2 + # Create session with custom URI + $TESTDIR/../src/bin/lttng/$LTTNG_BIN create -U $uri $sess_name >/dev/null 2>&1 +} + +function enable_lttng_consumer +{ + uri=$1 + # Create session with custom URI + $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-consumer -u $uri >/dev/null 2>&1 +} + +function run_apps +{ + for i in `seq 1 $NR_APP_ITER`; do + # With bandwidth limitation, unfortunately, application easily timeout + # due to very slow communication between the consumer and relayd making + # the status reply from the consumer quite slow thus delaying the + # registration done message. + LTTNG_UST_REGISTER_TIMEOUT=-1 ./$CURDIR/$BIN_NAME $NR_ITER & >/dev/null 2>&1 + done +} + +function wait_apps +{ + echo "Waiting for applications to end" + while [ -n "$(pidof $BIN_NAME)" ]; do + echo -n "." + sleep 1 + done + echo "" +} + +function test_high_throughput +{ + NETWORK_URI="net://localhost" + create_lttng_session_with_uri $SESSION_NAME $NETWORK_URI + enable_lttng_consumer $NETWORK_URI + enable_ust_lttng_event $SESSION_NAME $EVENT_NAME + start_lttng_tracing $SESSION_NAME + run_apps + wait_apps + + stop_lttng_tracing $SESSION_NAME + destroy_lttng_session $SESSION_NAME + validate_event_count +} + +function validate_event_count +{ + + TEMP_FILE=$(mktemp) + TEMP_FILE_2=$(mktemp) + + traced=$(babeltrace $TRACE_PATH 2>/dev/null | wc -l) + babeltrace $TRACE_PATH >/dev/null 2>$TEMP_FILE_2 + + cat $TEMP_FILE_2 | cut -f4 -d " " >$TEMP_FILE + + dropped=0 + while read line; + do + let dropped=$dropped+$line + done < $TEMP_FILE + + let total=$dropped+$traced + let wanted=$NR_APP_ITER*$NR_ITER + + if [ $wanted -ne $total ]; then + echo -n "Expected $wanted. Dropped $dropped. Recorded $traced. Total $total... " + print_fail + return 1 + else + echo -n "Expected $wanted. Dropped $dropped. Recorded $traced. Total $total... " + print_ok + + # Cleanup only if everything is ok and passes. + rm -rf $TRACE_PATH + rm $TEMP_FILE $TEMP_FILE_2 + + return 0 + fi +} + +function interrupt_cleanup() +{ + echo -en "\n*** Exiting ***\n" + stop_lttng_relayd + stop_lttng_sessiond + reset_bw_limit + exit 1 +} + +# Catch sigint and try to cleanup limits +trap interrupt_cleanup SIGINT + +BW_LIMITS=(3200 1600 800 400 200 100 50 25) +for BW in ${BW_LIMITS[@]}; +do + echo "" + echo -e "=== Testing high-throughput with bandwidth limit set to ${BW}kbits" + set_bw_limit $BW + + start_lttng_sessiond + start_lttng_relayd "-o $TRACE_PATH" + test_high_throughput + result=$? + stop_lttng_relayd + stop_lttng_sessiond + reset_bw_limit + + if [ $result -ne 0 ]; then + exit 1 + fi +done diff --git a/tests/regression/tools/streaming/run-kernel b/tests/regression/tools/streaming/run-kernel new file mode 100755 index 000000000..f8b813d28 --- /dev/null +++ b/tests/regression/tools/streaming/run-kernel @@ -0,0 +1,119 @@ +#!/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 +TEST_DESC="Streaming - Kernel tracing" + +CURDIR=$(dirname $0)/ +TESTDIR=$CURDIR/../../.. +EVENT_NAME="sched_switch" +PID_RELAYD=0 +SESSION_NAME="" + +TRACE_PATH=$(mktemp -d) + +source $TESTDIR/utils/utils.sh + +print_test_banner "$TEST_DESC" + +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_uri +{ + echo -n "Creating session $SESSION_NAME... " + # Create session with default path + $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $SESSION_NAME -U net://localhost >/dev/null 2>&1 + if [ $? -eq 1 ]; then + print_fail + return 1 + else + print_ok + fi +} + +function test_kernel_before_start () +{ + echo -e "\n=== Testing kernel streaming with event enable BEFORE start\n" + lttng_create_session_uri + lttng_enable_kernel_event $SESSION_NAME $EVENT_NAME + start_lttng_tracing $SESSION_NAME + # Give a second + sleep 1 + stop_lttng_tracing $SESSION_NAME + destroy_lttng_session $SESSION_NAME + + # We can not predict _yet_ when the trace is available so we have to do a + # arbitratry sleep to validate the trace. + echo -n "Waiting 3 seconds for the trace to be written on disk " + for i in `seq 1 3`; do + echo -n "." + sleep 1 + done + echo "" +} + +# Deactivated since this feature is not yet available where we can enable +# an event AFTERE tracing has started. +function test_kernel_after_start () +{ + echo -e "\n=== Testing kernel streaming with event enable AFTER start\n" + lttng_create_session_uri + start_lttng_tracing $SESSION_NAME + lttng_enable_kernel_event $SESSION_NAME $EVENT_NAME + # Give a second + sleep 1 + stop_lttng_tracing $SESSION_NAME + destroy_lttng_session $SESSION_NAME +} + +start_lttng_sessiond +start_lttng_relayd "-o $TRACE_PATH" + +tests=( test_kernel_before_start ) + +for fct_test in ${tests[@]}; +do + SESSION_NAME=$(randstring 16 0) + ${fct_test} + + # Validate test + validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/$SESSION_NAME* + if [ $? -eq 0 ]; then + # Only delete if successful + rm -rf $TRACE_PATH + else + break + fi +done + +echo "" +stop_lttng_sessiond +stop_lttng_relayd + + +exit $out diff --git a/tests/regression/tools/streaming/run-ust b/tests/regression/tools/streaming/run-ust new file mode 100755 index 000000000..6e6e5a752 --- /dev/null +++ b/tests/regression/tools/streaming/run-ust @@ -0,0 +1,110 @@ +#!/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 +TEST_DESC="Streaming - User space tracing" + +CURDIR=$(dirname $0)/ +TESTDIR=$CURDIR/../../.. +BIN_NAME="gen-ust-events" +SESSION_NAME="stream" +EVENT_NAME="tp:tptest" +PID_RELAYD=0 + +TRACE_PATH=$(mktemp -d) + +source $TESTDIR/utils/utils.sh + +print_test_banner "$TEST_DESC" + +if [ ! -x "$CURDIR/$BIN_NAME" ]; then + echo -e "No UST nevents binary detected. Passing." + exit 0 +fi + +function lttng_create_session_uri +{ + # Create session with default path + $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $SESSION_NAME -U net://localhost >/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_uri + 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_lttng_tracing $SESSION_NAME + + wait_apps + stop_lttng_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_uri + enable_ust_lttng_event $SESSION_NAME $EVENT_NAME + start_lttng_tracing $SESSION_NAME + + # Run 5 times with a 1 second delay + ./$CURDIR/$BIN_NAME 5 1000000 >/dev/null 2>&1 & + + wait_apps + stop_lttng_tracing $SESSION_NAME + destroy_lttng_session $SESSION_NAME +} + +start_lttng_sessiond +start_lttng_relayd "-o $TRACE_PATH" + +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 $TRACE_PATH/$HOSTNAME/$SESSION_NAME* + if [ $? -eq 0 ]; then + # Only delete if successful + rm -rf $TRACE_PATH + else + break + fi +done + +echo "" +stop_lttng_sessiond +stop_lttng_relayd + +exit $out diff --git a/tests/regression/tools/streaming/runall b/tests/regression/tools/streaming/runall new file mode 100755 index 000000000..dbf5228ce --- /dev/null +++ b/tests/regression/tools/streaming/runall @@ -0,0 +1,28 @@ +#!/bin/bash + +DIR=$(dirname $0) + +tests=( $DIR/unit_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/regression/tools/streaming/tp.c b/tests/regression/tools/streaming/tp.c new file mode 100644 index 000000000..a09561d70 --- /dev/null +++ b/tests/regression/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/regression/tools/streaming/tp.h b/tests/regression/tools/streaming/tp.h new file mode 100644 index 000000000..6ffbc32ab --- /dev/null +++ b/tests/regression/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/regression/tools/streaming/unit_tests.c b/tests/regression/tools/streaming/unit_tests.c new file mode 100644 index 000000000..d00e34d16 --- /dev/null +++ b/tests/regression/tools/streaming/unit_tests.c @@ -0,0 +1,252 @@ +/* + * Copyright (C) - 2012 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 + +#include +#include + +#include "utils.h" + +/* This path will NEVER be created in this test */ +#define PATH1 "tmp/.test-junk-lttng" + +#define RANDOM_STRING_LEN 16 + +/* For lttngerr.h */ +int lttng_opt_quiet = 1; +int lttng_opt_verbose = 3; + +/* + * Test string URI and if uri_parse works well. + */ +void test_uri_parsing(void) +{ + ssize_t size; + const char *s_uri1; + struct lttng_uri *uri; + + fprintf(stdout, "Testing URIs...\n"); + + s_uri1 = "net://localhost"; + fprintf(stdout, " [+] URI set to %s ", s_uri1); + size = uri_parse(s_uri1, &uri); + assert(size == 2); + assert(uri[0].dtype == LTTNG_DST_IPV4); + assert(uri[0].utype == LTTNG_URI_DST); + assert(uri[0].stype == 0); + assert(uri[0].port == 0); + assert(strlen(uri[0].subdir) == 0); + assert(strcmp(uri[0].dst.ipv4, "127.0.0.1") == 0); + + assert(uri[1].dtype == LTTNG_DST_IPV4); + assert(uri[1].utype == LTTNG_URI_DST); + assert(uri[1].stype == 0); + assert(uri[1].port == 0); + assert(strlen(uri[1].subdir) == 0); + assert(strcmp(uri[1].dst.ipv4, "127.0.0.1") == 0); + PRINT_OK(); + uri_free(uri); + + s_uri1 = "net://localhost:8989:4242/my/test/path"; + fprintf(stdout, " [+] URI set to %s ", s_uri1); + size = uri_parse(s_uri1, &uri); + assert(size == 2); + assert(uri[0].dtype == LTTNG_DST_IPV4); + assert(uri[0].utype == LTTNG_URI_DST); + assert(uri[0].stype == 0); + assert(uri[0].port == 8989); + assert(strcmp(uri[0].subdir, "my/test/path") == 0); + assert(strcmp(uri[0].dst.ipv4, "127.0.0.1") == 0); + + assert(uri[1].dtype == LTTNG_DST_IPV4); + assert(uri[1].utype == LTTNG_URI_DST); + assert(uri[1].stype == 0); + assert(uri[1].port == 4242); + assert(strcmp(uri[0].subdir, "my/test/path") == 0); + assert(strcmp(uri[1].dst.ipv4, "127.0.0.1") == 0); + PRINT_OK(); + uri_free(uri); + + s_uri1 = "net://localhost:8989:4242"; + fprintf(stdout, " [+] URI set to %s ", s_uri1); + size = uri_parse(s_uri1, &uri); + assert(size == 2); + assert(uri[0].dtype == LTTNG_DST_IPV4); + assert(uri[0].utype == LTTNG_URI_DST); + assert(uri[0].stype == 0); + assert(uri[0].port == 8989); + assert(strlen(uri[1].subdir) == 0); + assert(strcmp(uri[0].dst.ipv4, "127.0.0.1") == 0); + + assert(uri[1].dtype == LTTNG_DST_IPV4); + assert(uri[1].utype == LTTNG_URI_DST); + assert(uri[1].stype == 0); + assert(uri[1].port == 4242); + assert(strlen(uri[1].subdir) == 0); + assert(strcmp(uri[1].dst.ipv4, "127.0.0.1") == 0); + PRINT_OK(); + uri_free(uri); + + s_uri1 = "net6://localhost:8989"; + fprintf(stdout, " [+] URI set to %s ", s_uri1); + size = uri_parse(s_uri1, &uri); + assert(size == 2); + assert(uri[0].dtype == LTTNG_DST_IPV6); + assert(uri[0].utype == LTTNG_URI_DST); + assert(uri[0].stype == 0); + assert(uri[0].port == 8989); + assert(strlen(uri[1].subdir) == 0); + assert(strcmp(uri[0].dst.ipv6, "::1") == 0); + + assert(uri[1].dtype == LTTNG_DST_IPV6); + assert(uri[1].utype == LTTNG_URI_DST); + assert(uri[1].stype == 0); + assert(uri[1].port == 0); + assert(strlen(uri[1].subdir) == 0); + assert(strcmp(uri[0].dst.ipv6, "::1") == 0); + PRINT_OK(); + uri_free(uri); + + s_uri1 = "tcp://42.42.42.42/my/test/path"; + fprintf(stdout, " [+] URI set to %s ", s_uri1); + size = uri_parse(s_uri1, &uri); + assert(size == 1); + assert(uri[0].dtype == LTTNG_DST_IPV4); + assert(uri[0].utype == LTTNG_URI_DST); + assert(uri[0].stype == 0); + assert(uri[0].port == 0); + assert(strcmp(uri[0].subdir, "my/test/path") == 0); + assert(strcmp(uri[0].dst.ipv4, "42.42.42.42") == 0); + PRINT_OK(); + uri_free(uri); + + s_uri1 = "tcp6://[fe80::f66d:4ff:fe53:d220]/my/test/path"; + fprintf(stdout, " [+] URI set to %s ", s_uri1); + size = uri_parse(s_uri1, &uri); + assert(size == 1); + assert(uri[0].dtype == LTTNG_DST_IPV6); + assert(uri[0].utype == LTTNG_URI_DST); + assert(uri[0].stype == 0); + assert(uri[0].port == 0); + assert(strcmp(uri[0].subdir, "my/test/path") == 0); + assert(strcmp(uri[0].dst.ipv6, "fe80::f66d:4ff:fe53:d220") == 0); + PRINT_OK(); + uri_free(uri); + + s_uri1 = "file:///my/test/path"; + fprintf(stdout, " [+] URI set to %s ", s_uri1); + size = uri_parse(s_uri1, &uri); + assert(size == 1); + assert(uri[0].dtype == LTTNG_DST_PATH); + assert(uri[0].utype == LTTNG_URI_DST); + assert(uri[0].stype == 0); + assert(uri[0].port == 0); + assert(strlen(uri[0].subdir) == 0); + assert(strcmp(uri[0].dst.path, "/my/test/path") == 0); + PRINT_OK(); + uri_free(uri); + + s_uri1 = "file/my/test/path"; + fprintf(stdout, " [+] Bad URI set to %s ", s_uri1); + size = uri_parse(s_uri1, &uri); + assert(size == -1); + PRINT_OK(); + + s_uri1 = "net://:8999"; + fprintf(stdout, " [+] Bad URI set to %s ", s_uri1); + size = uri_parse(s_uri1, &uri); + assert(size == -1); + PRINT_OK(); +} + +void test_uri_cmp() +{ + struct lttng_uri *uri1, *uri2; + const char *s_uri1 = "net://localhost"; + const char *s_uri2 = "net://localhost:8989:4242"; + ssize_t size1, size2; + int res; + + size1 = uri_parse(s_uri1, &uri1); + + /* Sanity checks */ + assert(size1 == 2); + assert(uri1[0].dtype == LTTNG_DST_IPV4); + assert(uri1[0].utype == LTTNG_URI_DST); + assert(uri1[0].stype == 0); + assert(uri1[0].port == 0); + assert(strlen(uri1[0].subdir) == 0); + assert(strcmp(uri1[0].dst.ipv4, "127.0.0.1") == 0); + assert(uri1[1].dtype == LTTNG_DST_IPV4); + assert(uri1[1].utype == LTTNG_URI_DST); + assert(uri1[1].stype == 0); + assert(uri1[1].port == 0); + assert(strlen(uri1[1].subdir) == 0); + assert(strcmp(uri1[1].dst.ipv4, "127.0.0.1") == 0); + + size2 = uri_parse(s_uri2, &uri2); + + assert(size2 == 2); + assert(uri2[0].dtype == LTTNG_DST_IPV4); + assert(uri2[0].utype == LTTNG_URI_DST); + assert(uri2[0].stype == 0); + assert(uri2[0].port == 8989); + assert(strlen(uri2[1].subdir) == 0); + assert(strcmp(uri2[0].dst.ipv4, "127.0.0.1") == 0); + assert(uri2[1].dtype == LTTNG_DST_IPV4); + assert(uri2[1].utype == LTTNG_URI_DST); + assert(uri2[1].stype == 0); + assert(uri2[1].port == 4242); + assert(strlen(uri2[1].subdir) == 0); + assert(strcmp(uri2[1].dst.ipv4, "127.0.0.1") == 0); + + + res = uri_compare(uri1, uri1); + fprintf(stdout, " [+] %s == %s ", s_uri1, s_uri1); + assert(res == 0); + PRINT_OK(); + + res = uri_compare(uri1, uri2); + fprintf(stdout, " [+] %s != %s ", s_uri1, s_uri2); + assert(res != 0); + PRINT_OK(); + + uri_free(uri1); + uri_free(uri2); +} + +int main(int argc, char **argv) +{ + srand(time(NULL)); + + printf("\nStreaming unit tests\n-----------\n"); + + /* URI tests */ + test_uri_parsing(); + test_uri_cmp(); + + return 0; +} diff --git a/tests/regression/tools/streaming/uri_switch b/tests/regression/tools/streaming/uri_switch new file mode 100755 index 000000000..06a3fbcd4 --- /dev/null +++ b/tests/regression/tools/streaming/uri_switch @@ -0,0 +1,217 @@ +#!/bin/bash +# +# Copyright (C) - 2012 Christian Babeux +# 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 +TEST_DESC="Streaming - URI switching" + +CURDIR=$(dirname $0)/ +TESTDIR=$CURDIR/../../.. +BIN_NAME="gen-ust-events" +SESSION_NAME="stream" +EVENT_NAME="tp:tptest" +PID_RELAYD=0 + +TRACE_PATH=$(mktemp -d) + +source $TESTDIR/utils/utils.sh + +print_test_banner "$TEST_DESC" + +if [ ! -x "$CURDIR/$BIN_NAME" ]; then + echo -e "No UST nevents binary detected. Skipping." + exit 0 +fi + +function lttng_create_session +{ + URI=$1 + # Create session with custom URI + $TESTDIR/../src/bin/lttng/$LTTNG_BIN create -U $URI $SESSION_NAME >/dev/null 2>&1 +} + +function lttng_enable_consumer +{ + URI=$1 + # Create session with custom URI + $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-consumer -u $URI >/dev/null 2>&1 +} + +function run_apps +{ + # Run 5 times with a 1 second delay + COUNT=5 + APP_DELAY=1000000 + ./$CURDIR/$BIN_NAME $COUNT $APP_DELAY >/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 "" +} + +function test_uri_switch_localhost_folder +{ + IPVER=$1 + echo -e "\n=== Testing switch of localhost folder ($IPVER)\n" + + if [ "$IPVER" == "IPv6" ]; then + BASE_URI="net6://localhost" + else + BASE_URI="net://localhost" + fi + + RANDCOUNT=10 + RAND="" + i=1 + + lttng_create_session $BASE_URI + + echo -e "Randomizing output folder on $BASE_URI..." + while [ "$i" -le $RANDCOUNT ] + do + RAND=$(randstring 16 0) + lttng_enable_consumer "$BASE_URI/$RAND" + let "i += 1" + done + + enable_ust_lttng_event $SESSION_NAME $EVENT_NAME + start_lttng_tracing $SESSION_NAME + run_apps + wait_apps + stop_lttng_tracing $SESSION_NAME + destroy_lttng_session $SESSION_NAME + validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/$RAND + + if [ $? -eq 0 ]; then + # Only delete if successful + rm -rf $TRACE_PATH + fi +} + +function test_uri_switch_file_network +{ + IPVER=$1 + echo "" + echo -e "=== Testing switch file -> network ($IPVER)" + + TMP_PATH=$(mktemp -d) + FILE_URI="file://$TMP_PATH" + + if [ "$IPVER" == "IPv6" ]; then + NETWORK_URIS=("net6://localhost" "net6://[::1]") + else + NETWORK_URIS=("net://localhost" "net://127.0.0.1") + fi + + NET_PATHS=("foo/bar" "OohEehOohAhAahTingTangWallaWallaBingBang" ".") + + for NETWORK_URI in ${NETWORK_URIS[@]}; + do + for NET_PATH in ${NET_PATHS[@]}; + do + SESSION_NAME=$(randstring 16 0) + echo "" + echo "$FILE_URI -> $NETWORK_URI/$NET_PATH" + + lttng_create_session $FILE_URI + lttng_enable_consumer "$NETWORK_URI/$NET_PATH" + enable_ust_lttng_event $SESSION_NAME $EVENT_NAME + start_lttng_tracing $SESSION_NAME + run_apps + wait_apps + stop_lttng_tracing $SESSION_NAME + destroy_lttng_session $SESSION_NAME + validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/$NET_PATH + + if [ $? -eq 0 ]; then + # Only delete if successful + rm -rf $TRACE_PATH + else + break + fi + done + done + rm -rf $TMP_PATH +} + +function test_uri_switch_network_file +{ +IPVER=$1 + echo "" + echo -e "=== Testing switch network ($IPVER) -> file" + + if [ "$IPVER" == "IPv6" ]; then + NETWORK_URI="net6://localhost" + else + NETWORK_URI="net://localhost" + fi + + FILE_PATHS=("." "foo/bar" "42") + + for FILE_PATH in ${FILE_PATHS[@]}; + do + TMP_PATH=$(mktemp -d) + FILE_URI="file://$TMP_PATH" + SESSION_NAME=$(randstring 16 0) + + echo "" + echo "$NETWORK_URI -> $FILE_URI/$FILE_PATH" + + lttng_create_session $NETWORK_URI + lttng_enable_consumer "$FILE_URI/$FILE_PATH" + enable_ust_lttng_event $SESSION_NAME $EVENT_NAME + start_lttng_tracing $SESSION_NAME + run_apps + wait_apps + stop_lttng_tracing $SESSION_NAME + destroy_lttng_session $SESSION_NAME + validate_trace $EVENT_NAME $TMP_PATH/$FILE_PATH + + if [ $? -eq 0 ]; then + # Only delete if successful + rm -rf $TMP_PATH + else + break + fi + done +} + + +start_lttng_sessiond + +echo "" +echo "=== Testing with IPv4" +start_lttng_relayd "-o $TRACE_PATH" +test_uri_switch_localhost_folder "IPv4" +test_uri_switch_file_network "IPv4" +test_uri_switch_network_file "IPv4" +stop_lttng_relayd + +echo "" +echo "=== Testing with IPv6" +start_lttng_relayd "-o $TRACE_PATH -C tcp6://localhost:5342 -D tcp6://localhost:5343" +test_uri_switch_localhost_folder "IPv6" +test_uri_switch_file_network "IPv6" +test_uri_switch_network_file "IPv6" +stop_lttng_relayd + +stop_lttng_sessiond diff --git a/tests/regression/tools/test_kernel_data_trace.c b/tests/regression/tools/test_kernel_data_trace.c new file mode 100644 index 000000000..70d71cadb --- /dev/null +++ b/tests/regression/tools/test_kernel_data_trace.c @@ -0,0 +1,203 @@ +/* + * 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 +#include + +#include "utils.h" + +/* This path will NEVER be created in this test */ +#define PATH1 "/tmp/.test-junk-lttng" + +#define RANDOM_STRING_LEN 11 + +/* For lttngerr.h */ +int lttng_opt_quiet = 1; +int lttng_opt_verbose; + +static const char alphanum[] = + "0123456789" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz"; + +static struct ltt_kernel_session *kern; +static char random_string[RANDOM_STRING_LEN]; + +/* + * Return random string of 10 characters. + * Not thread-safe. + */ +static char *get_random_string(void) +{ + int i; + + for (i = 0; i < RANDOM_STRING_LEN - 1; i++) { + random_string[i] = alphanum[rand() % (sizeof(alphanum) - 1)]; + } + + random_string[RANDOM_STRING_LEN - 1] = '\0'; + + return random_string; +} + +static void create_one_kernel_session(void) +{ + printf("Create kernel session: "); + kern = trace_kernel_create_session(PATH1); + assert(kern != NULL); + PRINT_OK(); + + printf("Validating kernel session: "); + assert(kern->fd == -1); + assert(kern->metadata_stream_fd == -1); + assert(kern->consumer_fds_sent == 0); + assert(kern->channel_count == 0); + assert(kern->stream_count_global == 0); + assert(kern->metadata == NULL); + PRINT_OK(); + + /* Init list in order to avoid sefaults from cds_list_del */ + trace_kernel_destroy_session(kern); +} + +static void create_kernel_metadata(void) +{ + assert(kern != NULL); + + printf("Create kernel metadata: "); + kern->metadata = trace_kernel_create_metadata(); + assert(kern->metadata != NULL); + PRINT_OK(); + + printf("Validating kernel session metadata: "); + assert(kern->metadata->fd == -1); + assert(kern->metadata->conf != NULL); + assert(kern->metadata->conf->attr.overwrite + == DEFAULT_CHANNEL_OVERWRITE); + assert(kern->metadata->conf->attr.subbuf_size + == default_get_metadata_subbuf_size()); + assert(kern->metadata->conf->attr.num_subbuf + == DEFAULT_METADATA_SUBBUF_NUM); + assert(kern->metadata->conf->attr.switch_timer_interval + == DEFAULT_CHANNEL_SWITCH_TIMER); + assert(kern->metadata->conf->attr.read_timer_interval + == DEFAULT_CHANNEL_READ_TIMER); + assert(kern->metadata->conf->attr.output + == DEFAULT_KERNEL_CHANNEL_OUTPUT); + PRINT_OK(); + + trace_kernel_destroy_metadata(kern->metadata); +} + +static void create_kernel_channel(void) +{ + struct ltt_kernel_channel *chan; + struct lttng_channel attr; + + memset(&attr, 0, sizeof(attr)); + + printf("Creating kernel channel: "); + chan = trace_kernel_create_channel(&attr); + assert(chan != NULL); + PRINT_OK(); + + printf("Validating kernel channel: "); + assert(chan->fd == -1); + assert(chan->enabled == 1); + assert(chan->stream_count == 0); + assert(chan->ctx == NULL); + assert(chan->channel->attr.overwrite == attr.attr.overwrite); + PRINT_OK(); + + /* Init list in order to avoid sefaults from cds_list_del */ + CDS_INIT_LIST_HEAD(&chan->list); + trace_kernel_destroy_channel(chan); +} + +static void create_kernel_event(void) +{ + struct ltt_kernel_event *event; + struct lttng_event ev; + + memset(&ev, 0, sizeof(ev)); + strncpy(ev.name, get_random_string(), LTTNG_KERNEL_SYM_NAME_LEN); + ev.type = LTTNG_EVENT_TRACEPOINT; + ev.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL; + + printf("Creating kernel event: "); + event = trace_kernel_create_event(&ev); + assert(event != NULL); + PRINT_OK(); + + printf("Validating kernel event: "); + assert(event->fd == -1); + assert(event->enabled == 1); + assert(event->event->instrumentation == LTTNG_KERNEL_TRACEPOINT); + assert(strlen(event->event->name)); + PRINT_OK(); + + /* Init list in order to avoid sefaults from cds_list_del */ + CDS_INIT_LIST_HEAD(&event->list); + trace_kernel_destroy_event(event); +} + +static void create_kernel_stream(void) +{ + struct ltt_kernel_stream *stream; + + printf("Creating kernel stream: "); + stream = trace_kernel_create_stream("stream1", 0); + assert(stream != NULL); + PRINT_OK(); + + printf("Validating kernel stream: "); + assert(stream->fd == -1); + assert(stream->state == 0); + PRINT_OK(); + + /* Init list in order to avoid sefaults from cds_list_del */ + CDS_INIT_LIST_HEAD(&stream->list); + trace_kernel_destroy_stream(stream); +} + +int main(int argc, char **argv) +{ + printf("\nTesting kernel data structures:\n-----------\n"); + + create_one_kernel_session(); + + create_kernel_metadata(); + create_kernel_channel(); + + + create_kernel_event(); + + create_kernel_stream(); + + /* Success */ + return 0; +} diff --git a/tests/regression/tools/test_sessions.c b/tests/regression/tools/test_sessions.c new file mode 100644 index 000000000..a6d76c73d --- /dev/null +++ b/tests/regression/tools/test_sessions.c @@ -0,0 +1,330 @@ +/* + * 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 + +#include +#include +#include + +#include "utils.h" + +#define SESSION1 "test1" + +/* This path will NEVER be created in this test */ +#define PATH1 "/tmp/.test-junk-lttng" + +#define MAX_SESSIONS 10000 +#define RANDOM_STRING_LEN 11 + +/* + * String of 263 caracters. NAME_MAX + "OVERFLOW". If OVERFLOW appears in the + * session name, we have a problem. + * + * NAME_MAX = 255 + */ +#define OVERFLOW_SESSION_NAME \ + "abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd" \ + "abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd" \ + "abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd" \ + "abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabc" \ + "OVERFLOW" + +static struct ltt_session_list *session_list; + +/* For lttngerr.h */ +int lttng_opt_quiet = 1; +int lttng_opt_verbose = 0; + +static const char alphanum[] = + "0123456789" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz"; +static char random_string[RANDOM_STRING_LEN]; + +/* + * Return random string of 10 characters. + * Not thread-safe. + */ +static char *get_random_string(void) +{ + int i; + + for (i = 0; i < RANDOM_STRING_LEN - 1; i++) { + random_string[i] = alphanum[rand() % (sizeof(alphanum) - 1)]; + } + + random_string[RANDOM_STRING_LEN - 1] = '\0'; + + return random_string; +} + +/* + * Return 0 if session name is found, else -1 + */ +static int find_session_name(char *name) +{ + struct ltt_session *iter; + + cds_list_for_each_entry(iter, &session_list->head, list) { + if (strcmp(iter->name, name) == 0) { + return 0; + } + } + + return -1; +} + +static int session_list_count(void) +{ + int count = 0; + struct ltt_session *iter; + + cds_list_for_each_entry(iter, &session_list->head, list) { + count++; + } + return count; +} + +/* + * Empty session list manually. + */ +static void empty_session_list(void) +{ + struct ltt_session *iter, *tmp; + + cds_list_for_each_entry_safe(iter, tmp, &session_list->head, list) { + cds_list_del(&iter->list); + free(iter); + } + + /* Session list must be 0 */ + assert(!session_list_count()); +} + +/* + * Test creation of 1 session + */ +static int create_one_session(char *name, char *path) +{ + int ret; + + ret = session_create(name, path, geteuid(), getegid()); + if (ret == LTTNG_OK) { + /* Validate */ + ret = find_session_name(name); + if (ret < 0) { + /* Session not found by name */ + printf("session not found after creation\n"); + return -1; + } else { + /* Success */ + return 0; + } + } else { + if (ret == LTTNG_ERR_EXIST_SESS) { + printf("(session already exists) "); + } + return -1; + } + + return 0; +} + +/* + * Test deletion of 1 session + */ +static int destroy_one_session(struct ltt_session *session) +{ + int ret; + + ret = session_destroy(session); + + if (ret == LTTNG_OK) { + /* Validate */ + if (session == NULL) { + return 0; + } + ret = find_session_name(session->name); + if (ret < 0) { + /* Success, -1 means that the sesion is NOT found */ + return 0; + } else { + /* Fail */ + return -1; + } + } + + return 0; +} + +static int fuzzing_create_args(void) +{ + int ret; + + ret = create_one_session(NULL, NULL); + if (ret > 0) { + printf("Session created with (null),(null)\n"); + return -1; + } + + ret = create_one_session(NULL, PATH1); + if (ret > 0) { + printf("Session created with (null), %s)\n", PATH1); + return -1; + } + + /* Session list must be 0 */ + assert(!session_list_count()); + + return 0; +} + +/* + * This test is supposed to fail at the second create call. If so, return 0 for + * test success, else -1. + */ +static int two_session_same_name(void) +{ + int ret; + struct ltt_session *sess; + + ret = create_one_session(SESSION1, PATH1); + if (ret < 0) { + /* Fail */ + return -1; + } + + sess = session_find_by_name(SESSION1); + if (sess) { + /* Success */ + return 0; + } + + /* Fail */ + return -1; +} + +int main(int argc, char **argv) +{ + int ret, i; + struct ltt_session *iter, *tmp; + + srand(time(NULL)); + + printf("\nTesting Sessions:\n-----------\n"); + + session_list = session_get_list(); + if (session_list == NULL) { + return -1; + } + + printf("Create 1 session %s: ", SESSION1); + fflush(stdout); + ret = create_one_session(SESSION1, PATH1); + if (ret < 0) { + return -1; + } + PRINT_OK(); + + printf("Validating created session %s: ", SESSION1); + fflush(stdout); + tmp = session_find_by_name(SESSION1); + if (tmp == NULL) { + return -1; + } + /* Basic init session values */ + assert(tmp->kernel_session == NULL); + assert(strlen(tmp->path)); + assert(strlen(tmp->name)); + session_lock(tmp); + session_unlock(tmp); + + PRINT_OK(); + + printf("Destroy 1 session %s: ", SESSION1); + fflush(stdout); + ret = destroy_one_session(tmp); + if (ret < 0) { + return -1; + } + PRINT_OK(); + + printf("Two session with same name: "); + fflush(stdout); + ret = two_session_same_name(); + if (ret < 0) { + return -1; + } + PRINT_OK(); + + empty_session_list(); + + printf("Fuzzing create_session arguments: "); + fflush(stdout); + ret = fuzzing_create_args(); + if (ret < 0) { + return -1; + } + PRINT_OK(); + + printf("Creating %d sessions: ", MAX_SESSIONS); + fflush(stdout); + for (i = 0; i < MAX_SESSIONS; i++) { + char *tmp_name = get_random_string(); + + ret = create_one_session(tmp_name, PATH1); + if (ret < 0) { + printf("session %d (name: %s) creation failed\n", i, tmp_name); + return -1; + } + + if ((i % 1000) == 0) { + fprintf(stdout, "%d..", i); + fflush(stdout); + } + } + PRINT_OK(); + + printf("Destroying %d sessions: ", MAX_SESSIONS); + fflush(stdout); + for (i = 0; i < MAX_SESSIONS; i++) { + cds_list_for_each_entry_safe(iter, tmp, &session_list->head, list) { + ret = destroy_one_session(iter); + if (ret < 0) { + printf("session %d (name: %s) creation failed\n", i, iter->name); + return -1; + } + } + } + PRINT_OK(); + + /* Session list must be 0 */ + assert(!session_list_count()); + + /* Success */ + return 0; +} diff --git a/tests/regression/tools/test_ust_data_trace.c b/tests/regression/tools/test_ust_data_trace.c new file mode 100644 index 000000000..74f282bbb --- /dev/null +++ b/tests/regression/tools/test_ust_data_trace.c @@ -0,0 +1,204 @@ +/* + * 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 +#include +#include +#include + +#include "utils.h" + +/* This path will NEVER be created in this test */ +#define PATH1 "/tmp/.test-junk-lttng" + +#define RANDOM_STRING_LEN 11 + +/* For lttngerr.h */ +int lttng_opt_quiet = 1; +int lttng_opt_verbose; + +static const char alphanum[] = + "0123456789" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz"; +static char random_string[RANDOM_STRING_LEN]; + +static struct ltt_ust_session *usess; +static struct lttng_domain dom; + +/* + * Return random string of 10 characters. + * Not thread-safe. + */ +static char *get_random_string(void) +{ + int i; + + for (i = 0; i < RANDOM_STRING_LEN - 1; i++) { + random_string[i] = alphanum[rand() % (sizeof(alphanum) - 1)]; + } + + random_string[RANDOM_STRING_LEN - 1] = '\0'; + + return random_string; +} + +static void create_one_ust_session(void) +{ + printf("Create UST session: "); + + dom.type = LTTNG_DOMAIN_UST; + + usess = trace_ust_create_session(PATH1, 42); + 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_get_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; + + memset(&attr, 0, sizeof(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; + + memset(&ev, 0, sizeof(ev)); + strncpy(ev.name, get_random_string(), LTTNG_SYMBOL_NAME_LEN); + ev.type = LTTNG_EVENT_TRACEPOINT; + ev.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL; + + printf("Creating UST event: "); + event = trace_ust_create_event(&ev, NULL); + assert(event != NULL); + PRINT_OK(); + + printf("Validating UST event: "); + assert(event->enabled == 0); + 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 ectx; + struct ltt_ust_context *uctx; + + ectx.ctx = LTTNG_EVENT_CONTEXT_VTID; + + printf("Creating UST context: "); + uctx = trace_ust_create_context(&ectx); + assert(uctx != NULL); + PRINT_OK(); + + printf("Validating UST context: "); + assert((int) uctx->ctx.ctx == LTTNG_UST_CONTEXT_VTID); + 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/regression/ust/Makefile.am b/tests/regression/ust/Makefile.am new file mode 100644 index 000000000..9bca8809a --- /dev/null +++ b/tests/regression/ust/Makefile.am @@ -0,0 +1,28 @@ +if HAVE_LIBLTTNG_UST_CTL +SUBDIRS = nprocesses high-throughput low-throughput before-after multi-session \ + overlap + +AM_CFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/tests/utils -I$(top_srcdir)/src -g -Wall +AM_LDFLAGS = -lurcu -lurcu-cds + +EXTRA_DIST = runall.sh run-ust-global-tests.sh + +noinst_PROGRAMS = ust_global_event_basic ust_global_event_wildcard + +UTILS=$(top_srcdir)/tests/utils/utils.h +LIBLTTNG=$(top_builddir)/src/lib/lttng-ctl/liblttng-ctl.la + +SESSIONDSRC=$(top_srcdir)/src/common/sessiond-comm/sessiond-comm.c \ + $(top_srcdir)/src/common/sessiond-comm/unix.c \ + $(top_srcdir)/src/common/sessiond-comm/inet.c \ + $(top_srcdir)/src/common/sessiond-comm/inet6.c + +ust_global_event_wildcard_SOURCES = ust_global_event_wildcard.c $(UTILS) \ + $(SESSIONDSRC) +ust_global_event_wildcard_LDADD = $(LIBLTTNG) + +ust_global_event_basic_SOURCES = ust_global_event_basic.c $(UTILS) \ + $(SESSIONDSRC) +ust_global_event_basic_LDADD = $(LIBLTTNG) + +endif diff --git a/tests/regression/ust/before-after/Makefile.am b/tests/regression/ust/before-after/Makefile.am new file mode 100644 index 000000000..d197d72f5 --- /dev/null +++ b/tests/regression/ust/before-after/Makefile.am @@ -0,0 +1,16 @@ +AM_CFLAGS = -I$(srcdir) -O2 +AM_LDFLAGS = -llttng-ust + +if LTTNG_TOOLS_BUILD_WITH_LIBDL +AM_LDFLAGS += -ldl +endif +if LTTNG_TOOLS_BUILD_WITH_LIBC_DL +AM_LDFLAGS += -lc +endif + +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/regression/ust/before-after/gen-nevents.c b/tests/regression/ust/before-after/gen-nevents.c new file mode 100644 index 000000000..b2c19927f --- /dev/null +++ b/tests/regression/ust/before-after/gen-nevents.c @@ -0,0 +1,56 @@ +/* + * 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); + usleep(100000); + } + + return 0; +} diff --git a/tests/regression/ust/before-after/run b/tests/regression/ust/before-after/run new file mode 100755 index 000000000..cb1f8c2cd --- /dev/null +++ b/tests/regression/ust/before-after/run @@ -0,0 +1,120 @@ +#!/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 +TEST_DESC="UST tracer - Start tracing before and after execution" + +CURDIR=$(dirname $0)/ +TESTDIR=$CURDIR/../../.. +NR_ITER=100 +SESSION_NAME="per-session" +EVENT_NAME="ust_gen_nevents:tptest" + +source $TESTDIR/utils/utils.sh + +print_test_banner "$TEST_DESC" + +if [ ! -x "$CURDIR/gen-nevents" ]; then + echo -e "No UST nevents binary detected. Passing." + exit 0 +fi + +# MUST set TESTDIR before calling those functions + +test_before_apps() { + local out + + # BEFORE application is spawned + create_lttng_session $SESSION_NAME $TRACE_PATH + enable_ust_lttng_event $SESSION_NAME $EVENT_NAME + start_lttng_tracing $SESSION_NAME + # Start test + echo -n "Starting application... " + ./$CURDIR/gen-nevents $NR_ITER + echo -n "Ended " + print_ok + stop_lttng_tracing $SESSION_NAME + destroy_lttng_session $SESSION_NAME + + trace_matches $EVENT_NAME $NR_ITER $TRACE_PATH + + return $? +} + +test_after_apps() { + local out + + echo -n "Starting application... " + ./$CURDIR/gen-nevents 100 & + print_ok + + # BEFORE application is spawned + create_lttng_session $SESSION_NAME $TRACE_PATH + enable_ust_lttng_event $SESSION_NAME $EVENT_NAME + start_lttng_tracing $SESSION_NAME + + # At least hit one event + sleep 2 + + stop_lttng_tracing $SESSION_NAME + destroy_lttng_session $SESSION_NAME + + out=$(babeltrace $TRACE_PATH | grep $EVENT_NAME | wc -l) + if [ $out -eq 0 ]; then + echo -n "No event found. Suppose to have at least one... " + print_fail + out=1 + else + echo -n "Found $out event(s). Coherent... " + print_ok + out=0 + fi + + return $out +} + +# MUST set TESTDIR before calling those functions + +start_lttng_sessiond + +echo "" +echo "=== Start application BEFORE tracing was started ===" + +TRACE_PATH=$(mktemp -d) + +test_before_apps +out=$? +if [ $out -ne 0 ]; then + stop_lttng_sessiond + exit $out +fi + +rm -rf $TRACE_PATH + +echo "" +echo "=== Start application AFTER tracing was started ===" + +TRACE_PATH=$(mktemp -d) + +test_after_apps +out=$? +if [ $out -ne 0 ]; then + stop_lttng_sessiond + exit $out +fi + +stop_lttng_sessiond + +rm -rf $TRACE_PATH diff --git a/tests/regression/ust/before-after/tp.c b/tests/regression/ust/before-after/tp.c new file mode 100644 index 000000000..e291924a3 --- /dev/null +++ b/tests/regression/ust/before-after/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/regression/ust/before-after/ust_gen_nevents.h b/tests/regression/ust/before-after/ust_gen_nevents.h new file mode 100644 index 000000000..bc09c4497 --- /dev/null +++ b/tests/regression/ust/before-after/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/regression/ust/high-throughput/Makefile.am b/tests/regression/ust/high-throughput/Makefile.am new file mode 100644 index 000000000..cff8fe423 --- /dev/null +++ b/tests/regression/ust/high-throughput/Makefile.am @@ -0,0 +1,16 @@ +AM_CFLAGS = -I$(srcdir) -O2 +AM_LDFLAGS = -llttng-ust + +if LTTNG_TOOLS_BUILD_WITH_LIBDL +AM_LDFLAGS += -ldl +endif +if LTTNG_TOOLS_BUILD_WITH_LIBC_DL +AM_LDFLAGS += -lc +endif + +noinst_PROGRAMS = gen-events +gen_events_SOURCES = main.c tp.c tp.h +gen_events_LDADD = -llttng-ust + +noinst_SCRIPTS = run +EXTRA_DIST = run diff --git a/tests/regression/ust/high-throughput/main.c b/tests/regression/ust/high-throughput/main.c new file mode 100644 index 000000000..dbd2998ac --- /dev/null +++ b/tests/regression/ust/high-throughput/main.c @@ -0,0 +1,89 @@ +/* + * Copyright (C) 2009 Pierre-Marc Fournier + * Copyright (C) 2011 Mathieu Desnoyers + * + * 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 "tp.h" + +void inthandler(int sig) +{ +} + +int init_int_handler(void) +{ + int result; + struct sigaction act; + + memset(&act, 0, sizeof(act)); + result = sigemptyset(&act.sa_mask); + if (result == -1) { + perror("sigemptyset"); + return -1; + } + + act.sa_handler = inthandler; + act.sa_flags = SA_RESTART; + + /* Only defer ourselves. Also, try to restart interrupted + * syscalls to disturb the traced program as little as possible. + */ + result = sigaction(SIGUSR1, &act, NULL); + if (result == -1) { + perror("sigaction"); + return -1; + } + + return 0; +} + +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; + int delay = 0; + + init_int_handler(); + + if (argc == 2) + delay = atoi(argv[1]); + + sleep(delay); + + for (i = 0; i < 1000000; i++) { + netint = htonl(i); + tracepoint(tp, tptest, i, netint, values, text, + strlen(text), dbl, flt); + } + + return 0; +} diff --git a/tests/regression/ust/high-throughput/run b/tests/regression/ust/high-throughput/run new file mode 100755 index 000000000..550607328 --- /dev/null +++ b/tests/regression/ust/high-throughput/run @@ -0,0 +1,94 @@ +#!/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 +TEST_DESC="UST tracer - Testing high events throughput" + +CURDIR=$(dirname $0)/ +TESTDIR=$CURDIR/../../.. +NR_ITER=20 +BIN_NAME="gen-events" +SESSION_NAME="high-throughput" +EVENT_NAME="tp:tptest" + +source $TESTDIR/utils/utils.sh + +print_test_banner "$TEST_DESC" + +if [ ! -x "$CURDIR/$BIN_NAME" ]; then + echo -e "No UST nevents binary detected. Passing." + exit 0 +fi + +TRACE_PATH=$(mktemp -d) + +# MUST set TESTDIR before calling those functions + +start_lttng_sessiond + +create_lttng_session $SESSION_NAME $TRACE_PATH + +enable_ust_lttng_event $SESSION_NAME $EVENT_NAME +start_lttng_tracing $SESSION_NAME + +for i in `seq 1 $NR_ITER`; do + ./$CURDIR/$BIN_NAME & >/dev/null 2>&1 +done + +echo "Waiting for applications to end" +while [ -n "$(pidof $BIN_NAME)" ]; do + echo -n "." + sleep 0.5 +done +echo "" + +stop_lttng_tracing $SESSION_NAME +destroy_lttng_session $SESSION_NAME + +stop_lttng_sessiond + +# Validate test + +TEMP_FILE=$(mktemp) +TEMP_FILE_2=$(mktemp) + +traced=$(babeltrace $TRACE_PATH 2>/dev/null | wc -l) +babeltrace $TRACE_PATH >/dev/null 2>$TEMP_FILE_2 + +cat $TEMP_FILE_2 | cut -f4 -d " " >$TEMP_FILE + +dropped=0 +while read line; +do + let dropped=$dropped+$line +done < $TEMP_FILE + +let total=$dropped+$traced +let wanted=$NR_ITER*1000000 + +if [ $wanted -ne $total ]; then + echo -n "Expected $wanted. Dropped $dropped. Recorded $traced. Total $total... " + print_fail + out=1 +else + echo -n "Expected $wanted. Dropped $dropped. Recorded $traced. Total $total... " + print_ok + out=0 +fi + +rm -rf $TRACE_PATH +rm $TEMP_FILE $TEMP_FILE_2 + +exit $out diff --git a/tests/regression/ust/high-throughput/tp.c b/tests/regression/ust/high-throughput/tp.c new file mode 100644 index 000000000..1d6cbdaab --- /dev/null +++ b/tests/regression/ust/high-throughput/tp.c @@ -0,0 +1,18 @@ +/* + * tp.c + * + * Copyright (c) 2011 Mathieu Desnoyers + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + */ + +#define TRACEPOINT_CREATE_PROBES +#include "tp.h" diff --git a/tests/regression/ust/high-throughput/tp.h b/tests/regression/ust/high-throughput/tp.h new file mode 100644 index 000000000..12286b4db --- /dev/null +++ b/tests/regression/ust/high-throughput/tp.h @@ -0,0 +1,61 @@ +#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 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + */ + +#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) + ) +) + +TRACEPOINT_EVENT(tp, tptest_sighandler, + TP_ARGS(), + TP_FIELDS() +) + +#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/regression/ust/low-throughput/Makefile.am b/tests/regression/ust/low-throughput/Makefile.am new file mode 100644 index 000000000..a1df9f5e2 --- /dev/null +++ b/tests/regression/ust/low-throughput/Makefile.am @@ -0,0 +1,16 @@ +AM_CFLAGS = -I$(srcdir) -O2 +AM_LDFLAGS = -llttng-ust + +if LTTNG_TOOLS_BUILD_WITH_LIBDL +AM_LDFLAGS += -ldl +endif +if LTTNG_TOOLS_BUILD_WITH_LIBC_DL +AM_LDFLAGS += -lc +endif + +noinst_PROGRAMS = gen-events +gen_events_SOURCES = main.c tp.c tp.h +gen_events_LDADD = -llttng-ust -lurcu + +noinst_SCRIPTS = run +EXTRA_DIST = run diff --git a/tests/regression/ust/low-throughput/main.c b/tests/regression/ust/low-throughput/main.c new file mode 100644 index 000000000..06ab9ef82 --- /dev/null +++ b/tests/regression/ust/low-throughput/main.c @@ -0,0 +1,81 @@ +/* + * 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 + +#define TRACEPOINT_DEFINE +#include "tp.h" + +/* + * Thread recording a tracepoint every minute for 20 minutes. + */ +static void *th_event_minute(void *data) +{ + int i; + + /* Loop for 20 minutes */ + for (i = 1; i < 21; i++) { + /* Sleep 60 seconds */ + poll(NULL, 0, 60000); + + /* 20 minutes tracepoint */ + if ((i % 20) == 0) { + tracepoint(tp, slow, i, "twenty"); + } + + /* 10 minutes tracepoint */ + if ((i % 10) == 0) { + tracepoint(tp, slow, i, "ten"); + } + + /* 1 minute tracepoint */ + tracepoint(tp, slow, i, "one"); + } + + return NULL; +} + +/* + * main + */ +int main(int argc, char **argv) +{ + int ret; + void *status; + pthread_t thread; + + ret = pthread_create(&thread, NULL, th_event_minute, NULL); + if (ret != 0) { + perror("pthread_create event minute"); + goto error; + } + + ret = pthread_join(thread, &status); + if (ret != 0) { + perror("pthread_join"); + goto error; + } + + return 0; + +error: + return 1; +} diff --git a/tests/regression/ust/low-throughput/run b/tests/regression/ust/low-throughput/run new file mode 100755 index 000000000..2e111336e --- /dev/null +++ b/tests/regression/ust/low-throughput/run @@ -0,0 +1,101 @@ +#!/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 +TEST_DESC="UST tracer - Testing low events throughput" + +CURDIR=$(dirname $0)/ +TESTDIR=$CURDIR/../../.. +BIN_NAME="gen-events" +SESSION_NAME="low-throughput" +EVENT_NAME="tp:slow" + +source $TESTDIR/utils/utils.sh + +print_test_banner "$TEST_DESC" + +if [ ! -x "$CURDIR/$BIN_NAME" ]; then + echo -e "No UST nevents binary detected. Passing." + exit 0 +fi + +TRACE_PATH=$(mktemp -d) + +# MUST set TESTDIR before calling those functions + +start_lttng_sessiond + +create_lttng_session $SESSION_NAME $TRACE_PATH + +enable_ust_lttng_event $SESSION_NAME $EVENT_NAME +start_lttng_tracing $SESSION_NAME + +# This is going to take 20 minutes +./$CURDIR/$BIN_NAME >/dev/null 2>&1 + +stop_lttng_tracing $SESSION_NAME +destroy_lttng_session $SESSION_NAME + +stop_lttng_sessiond + +# Validate test + +last_val=0 +out=0 + +babeltrace $TRACE_PATH | while read event; +do + val=$(echo $event | cut -f10 -d" ") + val=${val%?} + th=$(echo $event | cut -f13 -d " ") + + if [ $th = '"one"' ]; then + ((last_val++)) + # We expect here a continous value from 1 to 20 + if [ $last_val -ne $val ]; then + echo -n "[-] One minute event failed ($val) " + out=1 + break + fi + elif [ $th = '"ten"' ]; then + # Test 10 minutes counter + if [ $val -ne 10 ]; then + # Test 20 minutes counter + if [ $val -ne 20 ]; then + echo -n "[-] Ten minutes event failed ($val) " + out=1 + break + fi + fi + elif [ $th = '"twenty"' ]; then + # Test 20 minutes counter + if [ $val -ne 20 ]; then + echo -n "[-] Twenty minutes event failed ($val) " + out=1 + break + fi + fi +done + +if [ $out -eq 0 ]; then + echo -n "Trace is coherent... " + print_ok +else + print_fail +fi + +rm -rf $TRACE_PATH + +exit $out diff --git a/tests/regression/ust/low-throughput/tp.c b/tests/regression/ust/low-throughput/tp.c new file mode 100644 index 000000000..1d6cbdaab --- /dev/null +++ b/tests/regression/ust/low-throughput/tp.c @@ -0,0 +1,18 @@ +/* + * tp.c + * + * Copyright (c) 2011 Mathieu Desnoyers + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + */ + +#define TRACEPOINT_CREATE_PROBES +#include "tp.h" diff --git a/tests/regression/ust/low-throughput/tp.h b/tests/regression/ust/low-throughput/tp.h new file mode 100644 index 000000000..b45a3dd87 --- /dev/null +++ b/tests/regression/ust/low-throughput/tp.h @@ -0,0 +1,45 @@ +#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 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + */ + +#include + +TRACEPOINT_EVENT(tp, slow, + TP_ARGS(unsigned int, c, char *, thread_name), + TP_FIELDS( + ctf_integer(unsigned int, counter, c) + ctf_string(th_name, thread_name) + ) +) + +#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/regression/ust/multi-session/Makefile.am b/tests/regression/ust/multi-session/Makefile.am new file mode 100644 index 000000000..d197d72f5 --- /dev/null +++ b/tests/regression/ust/multi-session/Makefile.am @@ -0,0 +1,16 @@ +AM_CFLAGS = -I$(srcdir) -O2 +AM_LDFLAGS = -llttng-ust + +if LTTNG_TOOLS_BUILD_WITH_LIBDL +AM_LDFLAGS += -ldl +endif +if LTTNG_TOOLS_BUILD_WITH_LIBC_DL +AM_LDFLAGS += -lc +endif + +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/regression/ust/multi-session/gen-nevents.c b/tests/regression/ust/multi-session/gen-nevents.c new file mode 100644 index 000000000..7add25249 --- /dev/null +++ b/tests/regression/ust/multi-session/gen-nevents.c @@ -0,0 +1,52 @@ +/* + * 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, nr_iter = 100; + long value = 42; + + if (argc == 2) { + nr_iter = atoi(argv[1]); + } + + for (i = 0; i < nr_iter; i++) { + tracepoint(ust_gen_nevents, tptest0, i, value); + tracepoint(ust_gen_nevents, tptest1, i, value); + tracepoint(ust_gen_nevents, tptest2, i, value); + tracepoint(ust_gen_nevents, tptest3, i, value); + } + + return 0; +} diff --git a/tests/regression/ust/multi-session/run b/tests/regression/ust/multi-session/run new file mode 100755 index 000000000..18e220dcf --- /dev/null +++ b/tests/regression/ust/multi-session/run @@ -0,0 +1,91 @@ +#!/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 +TEST_DESC="UST tracer - Multi-session" + +CURDIR=$(dirname $0)/ +TESTDIR=$CURDIR/../../.. +NR_ITER=100 +SESSION_NAME="multi-session" +EVENT_NAME="ust_gen_nevents:tptest" + +source $TESTDIR/utils/utils.sh + +print_test_banner "$TEST_DESC" + +if [ ! -x "$CURDIR/gen-nevents" ]; then + echo -e "No UST nevents binary detected. Passing." + exit 0 +fi + +# MUST set TESTDIR before calling those functions + +test_multi_session() { + local out + + # BEFORE application is spawned + for i in `seq 0 3`; do + create_lttng_session "$SESSION_NAME-$i" "$TRACE_PATH/$i" + enable_ust_lttng_event "$SESSION_NAME-$i" "$EVENT_NAME$i" + start_lttng_tracing "$SESSION_NAME-$i" + done + + echo -n "Starting application generating $NR_ITER events... " + ./$CURDIR/gen-nevents $NR_ITER & + print_ok + + # At least hit one event + echo -n "Waiting for events to record " + while [ -n "$(pidof gen-nevents)" ]; do + echo -n "." + sleep 0.1 + done + print_ok + + for i in `seq 0 3`; do + stop_lttng_tracing "$SESSION_NAME-$i" + destroy_lttng_session "$SESSION_NAME-$i" + out=$(babeltrace "$TRACE_PATH/$i" | grep "$EVENT_NAMEi$i" | wc -l) + if [ $out -ne $NR_ITER ]; then + echo -n "No event found. Suppose to have at least one... " + print_fail + out=1 + else + echo -n "Found $out event(s) for $SESSION_NAME-$i. Coherent... " + print_ok + out=0 + fi + done + + return $out +} + +# MUST set TESTDIR before calling those functions + +start_lttng_sessiond + +TRACE_PATH=$(mktemp -d) + +test_multi_session +out=$? +if [ $out -ne 0 ]; then + stop_lttng_sessiond + exit $out +fi + +stop_lttng_sessiond + +rm -rf "$TRACE_PATH" diff --git a/tests/regression/ust/multi-session/tp.c b/tests/regression/ust/multi-session/tp.c new file mode 100644 index 000000000..e291924a3 --- /dev/null +++ b/tests/regression/ust/multi-session/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/regression/ust/multi-session/ust_gen_nevents.h b/tests/regression/ust/multi-session/ust_gen_nevents.h new file mode 100644 index 000000000..58e4c17e3 --- /dev/null +++ b/tests/regression/ust/multi-session/ust_gen_nevents.h @@ -0,0 +1,68 @@ +#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, tptest0, + TP_ARGS(int, anint, long, value), + TP_FIELDS( + ctf_integer(int, intfield, anint) + ctf_integer(long, longfield, value) + ) +) + +TRACEPOINT_EVENT(ust_gen_nevents, tptest1, + TP_ARGS(int, anint, long, value), + TP_FIELDS( + ctf_integer(int, intfield, anint) + ctf_integer(long, longfield, value) + ) +) + +TRACEPOINT_EVENT(ust_gen_nevents, tptest2, + TP_ARGS(int, anint, long, value), + TP_FIELDS( + ctf_integer(int, intfield, anint) + ctf_integer(long, longfield, value) + ) +) + +TRACEPOINT_EVENT(ust_gen_nevents, tptest3, + TP_ARGS(int, anint, long, value), + TP_FIELDS( + ctf_integer(int, intfield, anint) + ctf_integer(long, longfield, value) + ) +) + +#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/regression/ust/nprocesses/Makefile.am b/tests/regression/ust/nprocesses/Makefile.am new file mode 100644 index 000000000..b07ae0baa --- /dev/null +++ b/tests/regression/ust/nprocesses/Makefile.am @@ -0,0 +1,16 @@ +AM_CFLAGS = -I$(srcdir) -O2 +AM_LDFLAGS = -llttng-ust + +if LTTNG_TOOLS_BUILD_WITH_LIBDL +AM_LDFLAGS += -ldl +endif +if LTTNG_TOOLS_BUILD_WITH_LIBC_DL +AM_LDFLAGS += -lc +endif + +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 ust-nprocesses +EXTRA_DIST = run ust-nprocesses diff --git a/tests/regression/ust/nprocesses/gen-events-time.c b/tests/regression/ust/nprocesses/gen-events-time.c new file mode 100644 index 000000000..bc5b68ca6 --- /dev/null +++ b/tests/regression/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/regression/ust/nprocesses/run b/tests/regression/ust/nprocesses/run new file mode 100755 index 000000000..55ad14811 --- /dev/null +++ b/tests/regression/ust/nprocesses/run @@ -0,0 +1,41 @@ +#!/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 +NR_ITER=100 +TEST_DESC="UST tracer - Generate $NR_ITER process" + +CURDIR=$(dirname $0)/ +TESTDIR=$CURDIR/../../.. +TEST_BIN_NAME="gen-events-time" + +source $TESTDIR/utils/utils.sh + +print_test_banner "$TEST_DESC" + +if [ ! -x "$CURDIR/$TEST_BIN_NAME" ]; then + echo -e "No UST $TEST_BIN_NAME binary detected. Passing." + exit 0 +fi + +# MUST set TESTDIR before calling those functions + +start_lttng_sessiond + +./$CURDIR/ust-nprocesses $NR_ITER + +stop_lttng_sessiond + +exit 0 diff --git a/tests/regression/ust/nprocesses/tp.c b/tests/regression/ust/nprocesses/tp.c new file mode 100644 index 000000000..438139ebc --- /dev/null +++ b/tests/regression/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/regression/ust/nprocesses/ust-nprocesses b/tests/regression/ust/nprocesses/ust-nprocesses new file mode 100755 index 000000000..e1d3fc6bc --- /dev/null +++ b/tests/regression/ust/nprocesses/ust-nprocesses @@ -0,0 +1,69 @@ +#!/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/../../.. +NR_ITER=$1 +TEST_BIN_NAME="gen-events-time" +SESSION_NAME="ust-nprocesses" +EVENT_NAME="ust_gen_event:tptest" +TEST_WAIT_SEC=5 + +source $TESTDIR/utils/utils.sh + +# MUST set TESTDIR before calling those functions + +# Start test for 1000 seconds + +for i in `seq 1 $NR_ITER` +do + ./$CURDIR/$TEST_BIN_NAME 1000 >/dev/null 2>&1 & +done + +echo -n "Validating registered apps in 3 seconds..." + +sleep 3 + +listing=$($TESTDIR/../src/bin/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 " + print_fail +else + print_ok +fi + +TRACE_PATH=$(mktemp -d) + +create_lttng_session $SESSION_NAME $TRACE_PATH + +enable_ust_lttng_event $SESSION_NAME $EVENT_NAME +start_lttng_tracing $SESSION_NAME + +echo "Sleeping $TEST_WAIT_SEC seconds for tracing to start everywhere" +echo "Warning: this arbitrary time can make the test fail on slower system" +sleep $TEST_WAIT_SEC + +stop_lttng_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 & +print_ok +exit 0 diff --git a/tests/regression/ust/nprocesses/ust_gen_event.h b/tests/regression/ust/nprocesses/ust_gen_event.h new file mode 100644 index 000000000..5bdcb37c5 --- /dev/null +++ b/tests/regression/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 diff --git a/tests/regression/ust/overlap/Makefile.am b/tests/regression/ust/overlap/Makefile.am new file mode 100644 index 000000000..7100034f9 --- /dev/null +++ b/tests/regression/ust/overlap/Makefile.am @@ -0,0 +1,4 @@ +SUBDIRS = demo + +noinst_SCRIPTS = run +EXTRA_DIST = run overlap.sh diff --git a/tests/regression/ust/overlap/demo/Makefile.am b/tests/regression/ust/overlap/demo/Makefile.am new file mode 100644 index 000000000..68b6e087f --- /dev/null +++ b/tests/regression/ust/overlap/demo/Makefile.am @@ -0,0 +1,38 @@ +AM_CFLAGS=-I$(srcdir) +if NO_SHARED +# Do not build this test if shared libraries support was +# explicitly disabled. +else +# Force the shared flag on the noinst libraries since they are +# only built static by default +FORCE_SHARED_LIB_OPTIONS = -module -shared -avoid-version \ + -rpath $(abs_builddir) + +#contains ust_tests_demo.h and ust_tests_demo2.h provider probes +liblttng_ust_provider_ust_tests_demo_la_SOURCES = \ + tp.c ust_tests_demo.h \ + tp2.c ust_tests_demo2.h +liblttng_ust_provider_ust_tests_demo_la_LIBADD = -llttng-ust +liblttng_ust_provider_ust_tests_demo_la_LDFLAGS = $(FORCE_SHARED_LIB_OPTIONS) + +#contains ust_tests_demo3.h provider probes +liblttng_ust_provider_ust_tests_demo3_la_SOURCES = tp3.c ust_tests_demo3.h +liblttng_ust_provider_ust_tests_demo3_la_LIBADD = -llttng-ust +liblttng_ust_provider_ust_tests_demo3_la_LDFLAGS = $(FORCE_SHARED_LIB_OPTIONS) + +noinst_LTLIBRARIES = liblttng-ust-provider-ust-tests-demo.la \ + liblttng-ust-provider-ust-tests-demo3.la + +noinst_PROGRAMS = demo +demo_SOURCES = demo.c ust_tests_demo.h +# The demo program only depends on libdl/libc for dlopen(). +if LTTNG_TOOLS_BUILD_WITH_LIBDL +demo_LDADD = -ldl +endif +if LTTNG_TOOLS_BUILD_WITH_LIBC_DL +demo_LDADD = -lc +endif + +noinst_SCRIPTS = demo-trace +EXTRA_DIST = demo-trace +endif diff --git a/tests/regression/ust/overlap/demo/demo-trace b/tests/regression/ust/overlap/demo/demo-trace new file mode 100755 index 000000000..88a1be73c --- /dev/null +++ b/tests/regression/ust/overlap/demo/demo-trace @@ -0,0 +1,3 @@ +#!/bin/sh + +LD_PRELOAD=.libs/liblttng-ust-provider-ust-tests-demo.so:.libs/liblttng-ust-provider-ust-tests-demo3.so ./demo ${*} diff --git a/tests/regression/ust/overlap/demo/demo.c b/tests/regression/ust/overlap/demo/demo.c new file mode 100644 index 000000000..e2b61c2e4 --- /dev/null +++ b/tests/regression/ust/overlap/demo/demo.c @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2009 Pierre-Marc Fournier + * Copyright (C) 2011 Mathieu Desnoyers + * + * 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 +#define TRACEPOINT_PROBE_DYNAMIC_LINKAGE +#include "ust_tests_demo.h" +#include "ust_tests_demo2.h" +#include "ust_tests_demo3.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; + int delay = 0; + + if (argc == 2) + delay = atoi(argv[1]); + + fprintf(stderr, "Demo program starting.\n"); + + sleep(delay); + + fprintf(stderr, "Tracing... "); + tracepoint(ust_tests_demo, starting, 123); + for (i = 0; i < 5; i++) { + netint = htonl(i); + tracepoint(ust_tests_demo2, loop, i, netint, values, + text, strlen(text), dbl, flt); + } + tracepoint(ust_tests_demo, done, 456); + tracepoint(ust_tests_demo3, done, 42); + fprintf(stderr, " done.\n"); + return 0; +} diff --git a/tests/regression/ust/overlap/demo/tp.c b/tests/regression/ust/overlap/demo/tp.c new file mode 100644 index 000000000..288ce6146 --- /dev/null +++ b/tests/regression/ust/overlap/demo/tp.c @@ -0,0 +1,18 @@ +/* + * tp.c + * + * Copyright (c) 2011 Mathieu Desnoyers + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + */ + +#define TRACEPOINT_CREATE_PROBES +#include "ust_tests_demo.h" diff --git a/tests/regression/ust/overlap/demo/tp2.c b/tests/regression/ust/overlap/demo/tp2.c new file mode 100644 index 000000000..718c9db26 --- /dev/null +++ b/tests/regression/ust/overlap/demo/tp2.c @@ -0,0 +1,18 @@ +/* + * tp2.c + * + * Copyright (c) 2011 Mathieu Desnoyers + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + */ + +#define TRACEPOINT_CREATE_PROBES +#include "ust_tests_demo2.h" diff --git a/tests/regression/ust/overlap/demo/tp3.c b/tests/regression/ust/overlap/demo/tp3.c new file mode 100644 index 000000000..b1babc735 --- /dev/null +++ b/tests/regression/ust/overlap/demo/tp3.c @@ -0,0 +1,18 @@ +/* + * tp3.c + * + * Copyright (c) 2011 Mathieu Desnoyers + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + */ + +#define TRACEPOINT_CREATE_PROBES +#include "ust_tests_demo3.h" diff --git a/tests/regression/ust/overlap/demo/ust_tests_demo.h b/tests/regression/ust/overlap/demo/ust_tests_demo.h new file mode 100644 index 000000000..3e024b44e --- /dev/null +++ b/tests/regression/ust/overlap/demo/ust_tests_demo.h @@ -0,0 +1,63 @@ +#undef TRACEPOINT_PROVIDER +#define TRACEPOINT_PROVIDER ust_tests_demo + +#if !defined(_TRACEPOINT_UST_TESTS_DEMO_H) || defined(TRACEPOINT_HEADER_MULTI_READ) +#define _TRACEPOINT_UST_TESTS_DEMO_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Copyright (C) 2011 Mathieu Desnoyers + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + */ + +#include + +TRACEPOINT_EVENT(ust_tests_demo, starting, + TP_ARGS(int, value), + TP_FIELDS( + ctf_integer(int, value, value) + ) +) +TRACEPOINT_LOGLEVEL(ust_tests_demo, starting, TRACE_CRIT) + +/* + * Dummy model information, just for example. TODO: we should check if + * EMF model URI have some standard format we should follow. + */ +TRACEPOINT_MODEL_EMF_URI(ust_tests_demo, starting, + "http://example.com/path_to_model?q=ust_tests_demo:starting") + +TRACEPOINT_EVENT(ust_tests_demo, done, + TP_ARGS(int, value), + TP_FIELDS( + ctf_integer(int, value, value) + ) +) +TRACEPOINT_LOGLEVEL(ust_tests_demo, done, TRACE_CRIT) + +TRACEPOINT_MODEL_EMF_URI(ust_tests_demo, done, + "http://example.com/path_to_model?q=ust_tests_demo:done") + +#endif /* _TRACEPOINT_UST_TESTS_DEMO_H */ + +#undef TRACEPOINT_INCLUDE_FILE +#define TRACEPOINT_INCLUDE_FILE ./ust_tests_demo.h + +/* This part must be outside ifdef protection */ +#include + +#ifdef __cplusplus +} +#endif diff --git a/tests/regression/ust/overlap/demo/ust_tests_demo2.h b/tests/regression/ust/overlap/demo/ust_tests_demo2.h new file mode 100644 index 000000000..cf4424b61 --- /dev/null +++ b/tests/regression/ust/overlap/demo/ust_tests_demo2.h @@ -0,0 +1,60 @@ +#undef TRACEPOINT_PROVIDER +#define TRACEPOINT_PROVIDER ust_tests_demo2 + +#if !defined(_TRACEPOINT_UST_TESTS_DEMO2_H) || defined(TRACEPOINT_HEADER_MULTI_READ) +#define _TRACEPOINT_UST_TESTS_DEMO2_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Copyright (C) 2011 Mathieu Desnoyers + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + */ + +#include + +TRACEPOINT_EVENT(ust_tests_demo2, loop, + 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) + ) +) +TRACEPOINT_LOGLEVEL(ust_tests_demo2, loop, TRACE_WARNING) + +#endif /* _TRACEPOINT_UST_TESTS_DEMO2_H */ + +#undef TRACEPOINT_INCLUDE_FILE +#define TRACEPOINT_INCLUDE_FILE ./ust_tests_demo2.h + +/* This part must be outside ifdef protection */ +#include + +#ifdef __cplusplus +} +#endif diff --git a/tests/regression/ust/overlap/demo/ust_tests_demo3.h b/tests/regression/ust/overlap/demo/ust_tests_demo3.h new file mode 100644 index 000000000..e58ee86f7 --- /dev/null +++ b/tests/regression/ust/overlap/demo/ust_tests_demo3.h @@ -0,0 +1,45 @@ +#undef TRACEPOINT_PROVIDER +#define TRACEPOINT_PROVIDER ust_tests_demo3 + +#if !defined(_TRACEPOINT_UST_TESTS_DEMO3_H) || defined(TRACEPOINT_HEADER_MULTI_READ) +#define _TRACEPOINT_UST_TESTS_DEMO3_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Copyright (C) 2011 Mathieu Desnoyers + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + */ + +#include + +TRACEPOINT_EVENT(ust_tests_demo3, done, + TP_ARGS(int, value), + TP_FIELDS( + ctf_integer(int, value, value) + ) +) +TRACEPOINT_LOGLEVEL(ust_tests_demo3, done, TRACE_WARNING) + +#endif /* _TRACEPOINT_UST_TESTS_DEMO3_H */ + +#undef TRACEPOINT_INCLUDE_FILE +#define TRACEPOINT_INCLUDE_FILE ./ust_tests_demo3.h + +/* This part must be outside ifdef protection */ +#include + +#ifdef __cplusplus +} +#endif diff --git a/tests/regression/ust/overlap/overlap.sh b/tests/regression/ust/overlap/overlap.sh new file mode 100755 index 000000000..8498199bd --- /dev/null +++ b/tests/regression/ust/overlap/overlap.sh @@ -0,0 +1,693 @@ +#!/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 +TEST_DESC="UST - Wildcard overlap" + +CURDIR=$(dirname $0)/ +TESTDIR=$CURDIR/../../.. +SESSION_NAME="wildcard-overlap" + +DEMO_EVENT1="ust_tests_demo:starting" +DEMO_EVENT1_2="ust_tests_demo:done" +DEMO_EVENT2="ust_tests_demo2:loop" +DEMO_EVENT3="ust_tests_demo3:done" + +NUM_DEMO1_EVENT=1 +NUM_DEMO1_2_EVENT=1 +NUM_DEMO2_EVENT=5 +NUM_DEMO3_EVENT=1 + +source $TESTDIR/utils/utils.sh + +print_test_banner "$TEST_DESC" + +if [ ! -x "$CURDIR/demo/demo" ]; then + echo -e "No UST nevents binary detected. Passing." + exit 0 +fi + +# MUST set TESTDIR before calling those functions + +run_demo_app() +{ + cd $CURDIR/demo + + # Start test + echo -n "Starting application... " + ./demo-trace >/dev/null 2>&1 + echo -n "Ended " + print_ok + + cd - +} + +# Ease our life a bit ;) +trace_match_demo1_events() +{ + trace_matches "$DEMO_EVENT1" $NUM_DEMO1_EVENT $TRACE_PATH + trace_matches "$DEMO_EVENT1_2" $NUM_DEMO1_EVENT $TRACE_PATH +} + +# Ease our life a bit ;) +trace_match_all_demo_events() +{ + trace_match_demo1_events + trace_matches "$DEMO_EVENT2" $NUM_DEMO2_EVENT $TRACE_PATH + trace_matches "$DEMO_EVENT3" $NUM_DEMO3_EVENT $TRACE_PATH +} + +# Ease our life a bit ;) +trace_match_no_demo_events() +{ + trace_matches "$DEMO_EVENT1" 0 $TRACE_PATH + trace_matches "$DEMO_EVENT1_2" 0 $TRACE_PATH + trace_matches "$DEMO_EVENT2" 0 $TRACE_PATH + trace_matches "$DEMO_EVENT3" 0 $TRACE_PATH +} + +# Expect all "demo" events, no duplicate. +test_enable_simple_wildcard() +{ + local event_wild1="us*" + local event_wild2="ust*" + + echo "" + echo "=== Simple wildcard overlap" + + enable_ust_lttng_event $SESSION_NAME "$event_wild1" + enable_ust_lttng_event $SESSION_NAME "$event_wild2" + + start_lttng_tracing $SESSION_NAME >/dev/null 2>&1 + + run_demo_app + + stop_lttng_tracing $SESSION_NAME >/dev/null 2>&1 + + trace_match_all_demo_events + + return $? +} + +# Expect all "demo" events, no duplicate. +test_enable_wildcard_filter() +{ + local event_wild1="us*" + local event_wild2="ust*" + + echo "" + echo "=== Wildcard overlap with filter" + + enable_ust_lttng_event_filter $SESSION_NAME "$event_wild1" "1==1" + enable_ust_lttng_event_filter $SESSION_NAME "$event_wild2" "1==0" + + start_lttng_tracing $SESSION_NAME >/dev/null 2>&1 + + run_demo_app + + stop_lttng_tracing $SESSION_NAME >/dev/null 2>&1 + + trace_match_all_demo_events + return $? +} + +# Expect all "demo" events, no duplicate. +test_enable_wildcard_filter_2() +{ + local event_wild1="us*" + local event_wild2="ust*" + + echo "" + echo "=== Wildcard overlap with filter 2" + + enable_ust_lttng_event_filter $SESSION_NAME "$event_wild1" "1==0" + enable_ust_lttng_event_filter $SESSION_NAME "$event_wild2" "1==1" + + start_lttng_tracing $SESSION_NAME >/dev/null 2>&1 + + run_demo_app + + stop_lttng_tracing $SESSION_NAME >/dev/null 2>&1 + + trace_match_all_demo_events + return $? +} + +# Expect all "demo" events, no duplicate. +test_enable_wildcard_filter_3() +{ + local event_wild1="us*" + local event_wild2="ust*" + + echo "" + echo "=== Wildcard overlap with filter 3" + + enable_ust_lttng_event_filter $SESSION_NAME "$event_wild1" "1==1" + enable_ust_lttng_event_filter $SESSION_NAME "$event_wild2" "1==1" + + start_lttng_tracing $SESSION_NAME >/dev/null 2>&1 + + run_demo_app + + stop_lttng_tracing $SESSION_NAME >/dev/null 2>&1 + + trace_match_all_demo_events + return $? +} + +# Expected: No events. +test_enable_wildcard_filter_4() +{ + local event_wild1="us*" + local event_wild2="ust*" + + echo "" + echo "=== Wildcard overlap with filter 4" + + enable_ust_lttng_event_filter $SESSION_NAME "$event_wild1" "1==0" + enable_ust_lttng_event_filter $SESSION_NAME "$event_wild2" "1==0" + + start_lttng_tracing $SESSION_NAME >/dev/null 2>&1 + + run_demo_app + + stop_lttng_tracing $SESSION_NAME >/dev/null 2>&1 + + trace_match_no_demo_events + return $? +} + +# Expect all "demo" events, no duplicate. +test_enable_wildcard_filter_5() +{ + local event_wild1="us*" + local event_wild2="$DEMO_EVENT1" + + echo "" + echo "=== Wildcard overlap with filter 5" + + enable_ust_lttng_event_filter $SESSION_NAME "$event_wild1" "1==1" + enable_ust_lttng_event_filter $SESSION_NAME "$event_wild2" "1==0" + + start_lttng_tracing $SESSION_NAME >/dev/null 2>&1 + + run_demo_app + + stop_lttng_tracing $SESSION_NAME >/dev/null 2>&1 + + trace_match_all_demo_events + return $? +} + +# Expect all $DEMO_EVENT1 events, no duplicate. +test_enable_wildcard_filter_6() +{ + local event_wild1="us*" + local event_wild2="$DEMO_EVENT1" + + echo "" + echo "=== Wildcard overlap with filter 6" + + enable_ust_lttng_event_filter $SESSION_NAME "$event_wild1" "1==0" + enable_ust_lttng_event_filter $SESSION_NAME "$event_wild2" "1==1" + + start_lttng_tracing $SESSION_NAME >/dev/null 2>&1 + + run_demo_app + + stop_lttng_tracing $SESSION_NAME >/dev/null 2>&1 + + trace_matches $DEMO_EVENT1 $NUM_DEMO1_EVENT $TRACE_PATH + trace_matches $DEMO_EVENT1_2 0 $TRACE_PATH + trace_matches $DEMO_EVENT2 0 $TRACE_PATH + trace_matches $DEMO_EVENT3 0 $TRACE_PATH + return $? +} + +# Expect all events, no duplicate. +test_enable_wildcard_filter_7() +{ + local event_wild1="us*" + local event_wild2="$DEMO_EVENT1" + + echo "" + echo "=== Wildcard overlap with filter 7" + + enable_ust_lttng_event_filter $SESSION_NAME "$event_wild1" "1==1" + enable_ust_lttng_event_filter $SESSION_NAME "$event_wild2" "1==1" + + start_lttng_tracing $SESSION_NAME >/dev/null 2>&1 + + run_demo_app + + stop_lttng_tracing $SESSION_NAME >/dev/null 2>&1 + + trace_match_all_demo_events + return $? +} + +# Expected: No events. +test_enable_wildcard_filter_8() +{ + local event_wild1="us*" + local event_wild2="$DEMO_EVENT1" + + echo "" + echo "=== Wildcard overlap with filter 8" + + enable_ust_lttng_event_filter $SESSION_NAME "$event_wild1" "1==0" + enable_ust_lttng_event_filter $SESSION_NAME "$event_wild2" "1==0" + + start_lttng_tracing $SESSION_NAME >/dev/null 2>&1 + + run_demo_app + + stop_lttng_tracing $SESSION_NAME >/dev/null 2>&1 + + trace_match_no_demo_events + return $? +} + +# Expect all events. +test_enable_same_wildcard_filter() +{ + local event_wild1="ust*" + local event_wild2="ust*" + + echo "" + echo "=== Same wildcard overlap with filter" + + enable_ust_lttng_event_filter $SESSION_NAME "$event_wild1" "1==1&&1==1" + enable_ust_lttng_event_filter $SESSION_NAME "$event_wild2" "1==1" + + start_lttng_tracing $SESSION_NAME >/dev/null 2>&1 + + run_demo_app + + stop_lttng_tracing $SESSION_NAME >/dev/null 2>&1 + + trace_match_all_demo_events + return $? +} + +# Expect all events. +test_enable_same_wildcard_filter_2() +{ + local event_wild1="ust*" + local event_wild2="ust*" + + echo "" + echo "=== Same wildcard overlap with filter 2" + + enable_ust_lttng_event_filter $SESSION_NAME "$event_wild1" "1==1" + enable_ust_lttng_event_filter $SESSION_NAME "$event_wild2" "1==1" + if [ $? -eq 1 ]; then + echo -n "FAIL is normal. Same event with same filter is denied by the sessiond " + print_ok + else + print_fail + fi + + start_lttng_tracing $SESSION_NAME >/dev/null 2>&1 + + run_demo_app + + stop_lttng_tracing $SESSION_NAME >/dev/null 2>&1 + + trace_match_all_demo_events + return $? +} + +# Expect all events. +test_enable_same_wildcard_filter_3() +{ + local event_wild1="ust*" + local event_wild2="ust*" + + echo "" + echo "=== Same wildcard overlap with filter 3" + + enable_ust_lttng_event_filter $SESSION_NAME "$event_wild1" "1==1" + enable_ust_lttng_event_filter $SESSION_NAME "$event_wild2" "1==0" + + start_lttng_tracing $SESSION_NAME >/dev/null 2>&1 + + run_demo_app + + stop_lttng_tracing $SESSION_NAME >/dev/null 2>&1 + + trace_match_all_demo_events + return $? +} + +# Expected: No events. +test_enable_same_wildcard_filter_4() +{ + local event_wild1="ust*" + local event_wild2="ust*" + + echo "" + echo "=== Same wildcard overlap with filter 4" + + enable_ust_lttng_event_filter $SESSION_NAME "$event_wild1" "1==0&&1==0" + enable_ust_lttng_event_filter $SESSION_NAME "$event_wild2" "1==0" + + start_lttng_tracing $SESSION_NAME >/dev/null 2>&1 + + run_demo_app + + stop_lttng_tracing $SESSION_NAME >/dev/null 2>&1 + + trace_match_no_demo_events + return $? +} + +# Expected: Only $DEMO_EVENT1 +test_enable_same_event_filter() +{ + local event_wild1="$DEMO_EVENT1" + local event_wild2="$DEMO_EVENT1" + + echo "" + echo "=== Enable same event with filter." + + enable_ust_lttng_event_filter $SESSION_NAME "$event_wild1" "1==1&&1==1" + enable_ust_lttng_event_filter $SESSION_NAME "$event_wild2" "1==1" + + disable_ust_lttng_event $SESSION_NAME "ust*" + + start_lttng_tracing $SESSION_NAME >/dev/null 2>&1 + + run_demo_app + + stop_lttng_tracing $SESSION_NAME >/dev/null 2>&1 + + trace_matches $DEMO_EVENT1 $NUM_DEMO1_EVENT $TRACE_PATH + trace_matches $DEMO_EVENT1_2 0 $TRACE_PATH + trace_matches $DEMO_EVENT2 0 $TRACE_PATH + trace_matches $DEMO_EVENT3 0 $TRACE_PATH + return $? +} + +# Expected: No events. +test_disable_same_wildcard_filter() +{ + local event_wild1="ust*" + local event_wild2="ust*" + + echo "" + echo "=== Disable same wildcard with filter." + + enable_ust_lttng_event_filter $SESSION_NAME "$event_wild1" "1==1&&1==1" + enable_ust_lttng_event_filter $SESSION_NAME "$event_wild2" "1==1" + + disable_ust_lttng_event $SESSION_NAME "ust*" + + start_lttng_tracing $SESSION_NAME >/dev/null 2>&1 + + run_demo_app + + stop_lttng_tracing $SESSION_NAME >/dev/null 2>&1 + + trace_match_no_demo_events + return $? +} + +# Expect no events +test_enable_bad_wildcard() +{ + # Invalid event + local event_wild1="ust_tests_demo" + local event_wild2="ust_tests_demo2" + local event_wild3="ust_tests_demo3" + + echo "" + echo "=== Enable bad wildcard" + + enable_ust_lttng_event $SESSION_NAME "$event_wild1" + enable_ust_lttng_event $SESSION_NAME "$event_wild2" + enable_ust_lttng_event $SESSION_NAME "$event_wild3" + + start_lttng_tracing $SESSION_NAME >/dev/null 2>&1 + + run_demo_app + + stop_lttng_tracing $SESSION_NAME >/dev/null 2>&1 + + trace_match_no_demo_events + return $? +} + +# Expect all "demo" events, no duplicate. +test_enable_simple_wildcard_2() +{ + local event_wild1="us*" + local event_wild2="$DEMO_EVENT1" + + echo "" + echo "=== Simple wildcard 2" + + enable_ust_lttng_event $SESSION_NAME "$event_wild1" + enable_ust_lttng_event $SESSION_NAME "$event_wild2" + + start_lttng_tracing $SESSION_NAME >/dev/null 2>&1 + + run_demo_app + + stop_lttng_tracing $SESSION_NAME >/dev/null 2>&1 + + trace_match_all_demo_events + return $? +} + +# Expected: all CRIT events, + all warning events. +test_enable_loglevel_overlap() +{ + local event_wild1="us*" + local event_wild2="ust*" + + echo "" + echo "=== Enable loglevel overlap" + + enable_ust_lttng_event_loglevel $SESSION_NAME "$event_wild1" "TRACE_WARNING" + enable_ust_lttng_event_loglevel $SESSION_NAME "$event_wild2" "TRACE_CRIT" + + start_lttng_tracing $SESSION_NAME >/dev/null 2>&1 + + run_demo_app + + stop_lttng_tracing $SESSION_NAME >/dev/null 2>&1 + + trace_match_all_demo_events + return $? +} + +# Expected: all CRIT events, + all warning events. +test_enable_loglevel_only_overlap() +{ + local event_wild1="us*" + local event_wild2="ust*" + + echo "" + echo "=== Enable loglevel only overlap" + + enable_ust_lttng_event_loglevel $SESSION_NAME "$event_wild1" "TRACE_WARNING" + enable_ust_lttng_event_loglevel_only $SESSION_NAME "$event_wild2" "TRACE_CRIT" + + start_lttng_tracing $SESSION_NAME >/dev/null 2>&1 + + run_demo_app + + stop_lttng_tracing $SESSION_NAME >/dev/null 2>&1 + + trace_match_all_demo_events + return $? +} + +# Expected: all events +test_enable_loglevel_overlap_2() +{ + local event_wild1="us*" + local event_wild2="$DEMO_EVENT2" + + echo "" + echo "=== Enable loglevel overlap 2" + + enable_ust_lttng_event_loglevel $SESSION_NAME "$event_wild1" "TRACE_WARNING" + enable_ust_lttng_event_loglevel $SESSION_NAME "$event_wild2" "TRACE_CRIT" + + start_lttng_tracing $SESSION_NAME >/dev/null 2>&1 + + run_demo_app + + stop_lttng_tracing $SESSION_NAME >/dev/null 2>&1 + + trace_match_all_demo_events + return $? +} + +# Expected only ust_tests_demo* events. +test_enable_same_wildcard_loglevels() +{ + local event_wild1="ust*" + local event_wild2="ust*" + + echo "" + echo "=== Enable same wildcard with different loglevels" + + enable_ust_lttng_event_loglevel $SESSION_NAME "$event_wild1" "TRACE_CRIT" + enable_ust_lttng_event_loglevel $SESSION_NAME "$event_wild2" "TRACE_WARNING" + + start_lttng_tracing $SESSION_NAME >/dev/null 2>&1 + + run_demo_app + + stop_lttng_tracing $SESSION_NAME >/dev/null 2>&1 + + trace_match_all_demo_events + return $? +} + +# Expected only ust_tests_demo:starting events. +test_enable_same_event_loglevels() +{ + local event_wild1="$DEMO_EVENT1" + local event_wild2="$DEMO_EVENT1" + + echo "" + echo "=== Enable same event with different loglevels" + + enable_ust_lttng_event_loglevel $SESSION_NAME "$event_wild1" "TRACE_CRIT" + enable_ust_lttng_event_loglevel $SESSION_NAME "$event_wild2" "TRACE_WARNING" + + start_lttng_tracing $SESSION_NAME >/dev/null 2>&1 + + run_demo_app + + stop_lttng_tracing $SESSION_NAME >/dev/null 2>&1 + + trace_matches $DEMO_EVENT1 $NUM_DEMO1_EVENT $TRACE_PATH + trace_matches $DEMO_EVENT1_2 0 $TRACE_PATH + trace_matches $DEMO_EVENT2 0 $TRACE_PATH + trace_matches $DEMO_EVENT3 0 $TRACE_PATH + return $? +} + +# Expect 0 event +test_disable_simple_wildcard() +{ + local event_wild1="us*" + local event_wild2="$DEMO_EVENT1" + + echo "" + echo "=== Disable simple wildcard" + + enable_ust_lttng_event $SESSION_NAME "$event_wild1" + enable_ust_lttng_event $SESSION_NAME "$event_wild2" + + disable_ust_lttng_event $SESSION_NAME "$event_wild1" + disable_ust_lttng_event $SESSION_NAME "$event_wild2" + + start_lttng_tracing $SESSION_NAME >/dev/null 2>&1 + + run_demo_app + + stop_lttng_tracing $SESSION_NAME >/dev/null 2>&1 + + # No events are expected. + trace_match_no_demo_events + return $? +} + +# Expect only "ust_tests_demo" events. +test_disable_wildcard_overlap() +{ + local event_wild1="us*" + local event_wild2="$DEMO_EVENT1" + + echo "" + echo "=== Disable wildcard overlap" + + enable_ust_lttng_event $SESSION_NAME "$event_wild1" + enable_ust_lttng_event $SESSION_NAME "$event_wild2" + + disable_ust_lttng_event $SESSION_NAME "$event_wild1" + + start_lttng_tracing $SESSION_NAME >/dev/null 2>&1 + + run_demo_app + + stop_lttng_tracing $SESSION_NAME >/dev/null 2>&1 + + # Expect only "ust_tests_demo" events. + trace_matches "$DEMO_EVENT1" $NUM_DEMO1_EVENT $TRACE_PATH + trace_matches "$DEMO_EVENT1_2" 0 $TRACE_PATH + trace_matches "$DEMO_EVENT2" 0 $TRACE_PATH + trace_matches "$DEMO_EVENT3" 0 $TRACE_PATH + return $? +} + +TESTS=( + "test_enable_wildcard_filter" + "test_enable_wildcard_filter_2" + "test_enable_wildcard_filter_3" + "test_enable_wildcard_filter_4" + "test_enable_wildcard_filter_5" + "test_enable_wildcard_filter_6" + "test_enable_wildcard_filter_7" + "test_enable_wildcard_filter_8" + "test_enable_same_wildcard_filter" + "test_enable_same_wildcard_filter_2" + "test_enable_same_wildcard_filter_3" + "test_enable_same_wildcard_filter_4" + "test_enable_same_event_filter" + "test_enable_loglevel_only_overlap" + "test_enable_same_event_loglevels" + "test_enable_same_wildcard_loglevels" + "test_enable_bad_wildcard" + "test_enable_loglevel_overlap_2" + "test_enable_simple_wildcard" + "test_enable_simple_wildcard_2" + "test_enable_loglevel_overlap" + "test_disable_simple_wildcard" + "test_disable_wildcard_overlap" +) + +TEST_COUNT=${#TESTS[@]} +i=0 + +start_lttng_sessiond + +while [ "$i" -lt "$TEST_COUNT" ]; do + + TRACE_PATH=$(mktemp -d) + + create_lttng_session $SESSION_NAME $TRACE_PATH >/dev/null 2>&1 + + # Execute test + ${TESTS[$i]} + if [ $? -ne 0 ]; then + stop_lttng_sessiond + exit 1 + fi + + destroy_lttng_session $SESSION_NAME >/dev/null 2>&1 + + rm -rf $TRACE_PATH + + let "i++" +done + +stop_lttng_sessiond diff --git a/tests/regression/ust/overlap/run b/tests/regression/ust/overlap/run new file mode 100755 index 000000000..ca8efb34f --- /dev/null +++ b/tests/regression/ust/overlap/run @@ -0,0 +1,24 @@ +#!/bin/bash + +DIR=$(dirname $0) + +tests=( $DIR/overlap.sh) + +exit_code=0 + +function start_tests () +{ + for bin in ${tests[@]}; + do + ./$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/regression/ust/run-ust-global-tests.sh b/tests/regression/ust/run-ust-global-tests.sh new file mode 100755 index 000000000..c09f70c26 --- /dev/null +++ b/tests/regression/ust/run-ust-global-tests.sh @@ -0,0 +1,44 @@ +#!/bin/bash + +SESSIOND_BIN="lttng-sessiond" +CURDIR=$(dirname $0) +TESTDIR=$CURDIR/../.. + +source $TESTDIR/utils/utils.sh + +tmpdir=`mktemp -d` +tests=( $CURDIR/ust_global_event_basic $CURDIR/ust_global_event_wildcard ) +exit_code=0 + +function start_tests () +{ + for bin in ${tests[@]}; + do + if [ ! -e $bin ]; then + echo -e "$bin not found, passing" + continue + fi + + start_lttng_sessiond + + ./$bin $tmpdir + # Test must return 0 to pass. + if [ $? -ne 0 ]; then + exit_code=1 + stop_lttng_sessiond + break + fi + stop_lttng_sessiond + done + + # Cleaning up + rm -rf $tmpdir +} + +TEST_DESC="UST tracer - Global domain (LTTNG_DOMAIN_UST)" + +print_test_banner "$TEST_DESC" + +start_tests + +exit $exit_code diff --git a/tests/regression/ust/runall.sh b/tests/regression/ust/runall.sh new file mode 100755 index 000000000..01afceca7 --- /dev/null +++ b/tests/regression/ust/runall.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +DIR=$(dirname $0) + +tests=( $DIR/run-ust-global-tests.sh $DIR/nprocesses/run \ + $DIR/high-throughput/run $DIR/before-after/run \ + $DIR/multi-session/run $DIR/overlap/run ) + +# $DIR/low-throughput/run --> DEACTIVATED. +# Use only for release. This test last 20 minutes + +exit_code=0 + +function start_tests () +{ + for bin in ${tests[@]}; + do + ./$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/regression/ust/ust_global_event_basic.c b/tests/regression/ust/ust_global_event_basic.c new file mode 100644 index 000000000..497538bac --- /dev/null +++ b/tests/regression/ust/ust_global_event_basic.c @@ -0,0 +1,299 @@ +/* + * 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 + +#include "utils.h" + +int lttng_opt_quiet; + +int main(int argc, char **argv) +{ + struct lttng_handle *handle = NULL; + struct lttng_domain dom; + struct lttng_channel channel, channel2; + struct lttng_event ev1, ev2, ev3; + struct lttng_event_context context; + char *session_name = "ust_global_event_basic"; + char *session_name2 = "ust_global_event_basic2"; + int ret = 0; + + memset(&dom, 0, sizeof(dom)); + memset(&channel, 0, sizeof(channel)); + memset(&channel2, 0, sizeof(channel2)); + memset(&ev1, 0, sizeof(ev1)); + memset(&ev2, 0, sizeof(ev2)); + memset(&ev3, 0, sizeof(ev3)); + memset(&context, 0, sizeof(context)); + + dom.type = LTTNG_DOMAIN_UST; + + /* Setup channel 1 */ + strcpy(channel.name, "mychan"); + channel.attr.overwrite = 0; + channel.attr.subbuf_size = 4096; + channel.attr.num_subbuf = 4; + channel.attr.switch_timer_interval = 0; + channel.attr.read_timer_interval = 200; + channel.attr.output = LTTNG_EVENT_MMAP; + + /* Setup channel 2 */ + strcpy(channel2.name, "mychan2"); + channel2.attr.overwrite = 0; + channel2.attr.subbuf_size = 8192; + channel2.attr.num_subbuf = 8; + channel2.attr.switch_timer_interval = 0; + channel2.attr.read_timer_interval = 500; + channel2.attr.output = LTTNG_EVENT_MMAP; + + strcpy(ev1.name, "tp1"); + ev1.type = LTTNG_EVENT_TRACEPOINT; + ev1.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL; + + strcpy(ev2.name, "ev2"); + ev2.type = LTTNG_EVENT_TRACEPOINT; + ev2.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL; + + strcpy(ev3.name, "ev3"); + ev3.type = LTTNG_EVENT_TRACEPOINT; + ev3.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL; + + printf("\nTesting tracing UST events:\n"); + printf("-----------\n"); + + if (argc < 2) { + printf("Missing session trace path\n"); + return 1; + } + + printf("Creating tracing session (%s): ", argv[1]); + 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 tracing session 2 (%s): ", argv[1]); + if ((ret = lttng_create_session(session_name2, 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(session_name, &dom)) == NULL) { + printf("error creating handle: %s\n", lttng_strerror(ret)); + goto handle_fail; + } + PRINT_OK(); + + printf("Enabling %s UST channel: ", channel.name); + if ((ret = lttng_enable_channel(handle, &channel)) < 0) { + printf("error enable channel: %s\n", lttng_strerror(ret)); + goto enable_fail; + } + PRINT_OK(); + + printf("Enabling %s UST channel2: ", channel2.name); + if ((ret = lttng_enable_channel(handle, &channel2)) < 0) { + printf("error enable channel: %s\n", lttng_strerror(ret)); + goto enable_fail; + } + PRINT_OK(); + + printf("Enabling %s UST event in channel %s: ", ev1.name, channel.name); + if ((ret = lttng_enable_event(handle, &ev1, channel.name)) < 0) { + printf("error enabling event: %s\n", lttng_strerror(ret)); + goto enable_fail; + } + PRINT_OK(); + + printf("Enabling %s UST event in channel %s: ", ev2.name, channel.name); + if ((ret = lttng_enable_event(handle, &ev2, channel.name)) < 0) { + printf("error enabling event: %s\n", lttng_strerror(ret)); + goto enable_fail; + } + PRINT_OK(); + + printf("Enabling %s UST event in channel %s: ", ev3.name, channel2.name); + if ((ret = lttng_enable_event(handle, &ev3, channel2.name)) < 0) { + printf("error enabling event: %s\n", lttng_strerror(ret)); + goto enable_fail; + } + PRINT_OK(); + + context.ctx = LTTNG_EVENT_CONTEXT_VPID; + + printf("Adding context VPID to UST event %s in channel %s: ", ev1.name, + channel.name); + if ((ret = lttng_add_context(handle, &context, ev1.name, + channel.name)) < 0) { + printf("error adding context VPID: %s\n", lttng_strerror(ret)); + goto context_fail; + } + PRINT_OK(); + + context.ctx = LTTNG_EVENT_CONTEXT_VTID; + + printf("Adding context VTID to UST event %s in channel %s: ", ev1.name, + channel.name); + if ((ret = lttng_add_context(handle, &context, ev1.name, + channel.name)) < 0) { + printf("error adding context VTID: %s\n", lttng_strerror(ret)); + goto context_fail; + } + PRINT_OK(); + + context.ctx = LTTNG_EVENT_CONTEXT_PTHREAD_ID; + + printf("Adding context PTHREAD_ID to UST event %s in channel %s: ", + ev1.name, channel.name); + if ((ret = lttng_add_context(handle, &context, ev1.name, + channel.name)) < 0) { + printf("error adding context PTHREAD_ID: %s\n", lttng_strerror(ret)); + goto context_fail; + } + PRINT_OK(); + + context.ctx = LTTNG_EVENT_CONTEXT_PROCNAME; + + printf("Adding context PROCNAME to UST event %s in channel %s: ", + ev1.name, channel.name); + if ((ret = lttng_add_context(handle, &context, ev1.name, + channel.name)) < 0) { + printf("error adding context PROCNAME: %s\n", lttng_strerror(ret)); + goto context_fail; + } + PRINT_OK(); + + context.ctx = LTTNG_EVENT_CONTEXT_PROCNAME; + + printf("Adding context PROCNAME to UST event %s in channel %s: ", + ev3.name, channel2.name); + if ((ret = lttng_add_context(handle, &context, ev3.name, + channel2.name)) < 0) { + printf("error adding context PROCNAME: %s\n", lttng_strerror(ret)); + goto context_fail; + } + PRINT_OK(); + + printf("Disabling %s UST event: ", ev1.name); + if ((ret = lttng_disable_event(handle, ev1.name, channel.name)) < 0) { + printf("error enabling event: %s\n", lttng_strerror(ret)); + goto enable_fail; + } + PRINT_OK(); + + printf("Disabling %s UST event: ", ev3.name); + if ((ret = lttng_disable_event(handle, ev3.name, channel2.name)) < 0) { + printf("error enabling event: %s\n", lttng_strerror(ret)); + goto enable_fail; + } + PRINT_OK(); + + printf("Renabling %s UST event: ", ev1.name); + if ((ret = lttng_enable_event(handle, &ev1, channel.name)) < 0) { + printf("error enabling event: %s\n", lttng_strerror(ret)); + goto enable_fail; + } + PRINT_OK(); + + printf("Renabling %s UST event: ", ev3.name); + if ((ret = lttng_enable_event(handle, &ev3, channel.name)) < 0) { + printf("error enabling event: %s\n", lttng_strerror(ret)); + goto enable_fail; + } + PRINT_OK(); + + printf("Disabling channel %s: ", channel2.name); + if ((ret = lttng_disable_channel(handle, channel2.name)) < 0) { + printf("error disabling channel: %s\n", lttng_strerror(ret)); + goto enable_fail; + } + PRINT_OK(); + + printf("Start tracing: "); + if ((ret = lttng_start_tracing(session_name)) < 0) { + printf("error starting tracing: %s\n", lttng_strerror(ret)); + goto start_fail; + } + PRINT_OK(); + + sleep(2); + + printf("Stop tracing: "); + if ((ret = lttng_stop_tracing(session_name)) < 0) { + printf("error stopping tracing: %s\n", lttng_strerror(ret)); + goto stop_fail; + } + PRINT_OK(); + + printf("Restart tracing: "); + if ((ret = lttng_start_tracing(session_name)) < 0) { + printf("error starting tracing: %s\n", lttng_strerror(ret)); + goto start_fail; + } + PRINT_OK(); + + sleep(2); + + printf("Stop tracing: "); + 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 2: "); + if ((ret = lttng_destroy_session(session_name2)) < 0) { + printf("error destroying session 2: %s\n", lttng_strerror(ret)); + } + PRINT_OK(); + + printf("Destroy tracing session: "); + if ((ret = lttng_destroy_session(session_name)) < 0) { + printf("error destroying session: %s\n", lttng_strerror(ret)); + } + PRINT_OK(); + + return 0; + +handle_fail: + assert(handle != NULL); +create_fail: + assert(ret != 0); + +stop_fail: +start_fail: +context_fail: +enable_fail: + lttng_destroy_session(session_name2); + lttng_destroy_session(session_name); + lttng_destroy_handle(handle); + + return 1; +} diff --git a/tests/regression/ust/ust_global_event_wildcard.c b/tests/regression/ust/ust_global_event_wildcard.c new file mode 100644 index 000000000..198a54168 --- /dev/null +++ b/tests/regression/ust/ust_global_event_wildcard.c @@ -0,0 +1,131 @@ +/* + * 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 + +#include "utils.h" + +int lttng_opt_quiet; + +int main(int argc, char **argv) +{ + struct lttng_handle *handle = NULL; + struct lttng_domain dom; + struct lttng_event event, ev2; + char *channel_name = "channel0"; + char *channel_name2 = "channel2"; + char *session_name = "ust_global_all_events_basic"; + int ret = 0; + + memset(&dom, 0, sizeof(dom)); + memset(&event, 0, sizeof(event)); + memset(&ev2, 0, sizeof(ev2)); + + dom.type = LTTNG_DOMAIN_UST; + + event.type = LTTNG_EVENT_TRACEPOINT; + event.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL; + strcpy(event.name, "*"); + + ev2.type = LTTNG_EVENT_TRACEPOINT; + ev2.loglevel_type = LTTNG_EVENT_LOGLEVEL_RANGE; + ev2.loglevel = LTTNG_LOGLEVEL_NOTICE; + strcpy(ev2.name, "abc*"); + + printf("\nTesting tracing all UST events:\n"); + printf("-----------\n"); + + if (argc < 2) { + printf("Missing session trace path\n"); + return 1; + } + + printf("Creating tracing session (%s): ", argv[1]); + 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(session_name, &dom)) == NULL) { + printf("error creating handle: %s\n", lttng_strerror(ret)); + goto handle_fail; + } + PRINT_OK(); + + printf("Enabling '*' UST events: "); + if ((ret = lttng_enable_event(handle, &event, channel_name)) < 0) { + printf("error enabling event: %s\n", lttng_strerror(ret)); + goto enable_fail; + } + PRINT_OK(); + + printf("Enabling 'abc*' UST events: "); + if ((ret = lttng_enable_event(handle, &ev2, channel_name2)) < 0) { + printf("error enabling event: %s\n", lttng_strerror(ret)); + goto enable_fail; + } + PRINT_OK(); + + printf("Start tracing: "); + if ((ret = lttng_start_tracing(session_name)) < 0) { + printf("error starting tracing: %s\n", lttng_strerror(ret)); + goto start_fail; + } + PRINT_OK(); + + sleep(2); + + printf("Stop tracing: "); + 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(session_name)) < 0) { + printf("error destroying session: %s\n", lttng_strerror(ret)); + } + PRINT_OK(); + + return 0; + +handle_fail: + assert(handle != NULL); +create_fail: + assert(ret != 0); + +stop_fail: +start_fail: +enable_fail: + lttng_destroy_session(session_name); + lttng_destroy_handle(handle); + + return 1; +} diff --git a/tests/run-report.py b/tests/run-report.py deleted file mode 100755 index acee18181..000000000 --- a/tests/run-report.py +++ /dev/null @@ -1,444 +0,0 @@ -#!/usr/bin/env python - -import os, sys -import subprocess -import threading -import Queue -import time -import shlex - -from signal import signal, SIGTERM, SIGINT, SIGPIPE, SIG_DFL - -SESSIOND_BIN_NAME = "lttng-sessiond" -SESSIOND_BIN_PATH = "src/bin/lttng-sessiond/" -CONSUMERD_BIN_NAME = "lttng-consumerd" -CONSUMERD_BIN_PATH = "src/bin/lttng-consumerd/" -TESTDIR_PATH = "" - -PRINT_BRACKET = "\033[1;34m[\033[1;33m+\033[1;34m]\033[00m" -PRINT_RED_BRACKET = "\033[1;31m[+]\033[00m" -PRINT_GREEN_BRACKET = "\033[1;32m[+]\033[00m" -PRINT_ARROW = "\033[1;32m-->\033[00m" - -is_root = 1 -no_stats = 0 -stop_sampling = 1 - -top_cpu_legend = { 'us': "User CPU time", 'sy': "System CPU time", - 'id': "Idle CPU time", 'ni': "Nice CPU time", 'wa': "iowait", - 'hi': "Hardware IRQ", 'si': "Software Interrupts", 'st': "Steal Time", } - -cpu_ret_q = Queue.Queue() -mem_ret_q = Queue.Queue() -test_ret_q = Queue.Queue() - -global sdaemon_proc -global worker_proc - -def cpu_create_usage_dict(top_line): - """ - Return a dictionnary from a 'top' cpu line. - Ex: Cpu(s): 2.1%us, 1.2%sy, 0.0%ni, 96.2%id, 0.4%wa, 0.0%hi, 0.0%si, 0.0%st - """ - top_dict = {'us': 0, 'sy': 0, 'ni': 0, 'id': 0, 'wa': 0, 'hi': 0, 'si': 0, 'st': 0} - - # Split expression and remove first value which is "Cpu(s)" - top_line = top_line.replace(",","") - words = top_line.split()[1:] - - - for key in top_dict: - index = words.index(key) - # Add the value to the dictionnary - val = words[index-1] - top_dict[key] = float(val) - - return top_dict - -def cpu_average_usage(top_lines): - """ - Return a dictionnary of 'top' CPU stats but averaging all values. - """ - avg_dict = {'us': 0, 'sy': 0, 'ni': 0, 'id': 0, 'wa': 0, 'hi': 0, 'si': 0, 'st': 0} - # Average count - count = 0.0 - - for line in top_lines: - tmp_dict = cpu_create_usage_dict(line) - # Add value to avg dictionnary - for key in tmp_dict: - avg_dict[key] += tmp_dict[key] - - count += 1.0 - - for key in avg_dict: - avg_dict[key] = avg_dict[key] / count - - return (count, avg_dict) - -def cpu_sample_usage(pid=None): - """ - Sample CPU usage for num iterations. - If num is greater than 1, the average will be computed. - """ - args = ["top", "-b", "-n", "1"] - if pid: - args.append("-p") - args.append(str(pid)) - - # Spawn top process - top = subprocess.Popen(args, stdout = subprocess.PIPE) - - grep = subprocess.Popen(["grep", "Cpu"], stdin = top.stdout, - stdout = subprocess.PIPE) - top.stdout.close() - - return grep.communicate()[0].strip("\n") - -def mem_sample_usage(pid): - """ - Sample memory usage using /proc and a pid - """ - args = ["cat", "/proc/" + str(pid) + "/status"] - - if not os.path.isfile(args[1]): - return -1 - - mem_proc = subprocess.Popen(args, stdout = subprocess.PIPE) - - grep = subprocess.Popen(["grep", "^VmRSS"], stdin = mem_proc.stdout, - stdout = subprocess.PIPE) - mem_proc.stdout.close() - - # Return virtual memory size in kilobytes (kB) - #ret = grep.communicate()[0].split() - ret = grep.communicate()[0].split() - - if len(ret) > 1: - ret = ret[1] - else: - ret = 0 - - return int(ret) - -class SamplingWorker(threading.Thread): - def __init__(self, s_type, worker = None, delay = 0.2, pid = 0): - threading.Thread.__init__ (self) - self.s_type = s_type - self.delay = delay - self.pid = pid - self.worker = worker - - def run(self): - count = 1 - lines = [] - - if self.s_type == "cpu": - while 1: - if self.worker == None: - cpu_line = cpu_sample_usage(self.pid) - lines.append(cpu_line) - break - elif self.worker.is_alive(): - cpu_line = cpu_sample_usage(self.pid) - lines.append(cpu_line) - else: - break - - # Delay sec per memory sampling - time.sleep(self.delay) - - count, stats = cpu_average_usage(lines) - cpu_ret_q.put((count, stats)) - # grep process has ended here - - elif self.s_type == "mem": - count = 0 - mem_stat = 0 - - while 1: - if self.worker == None: - cpu_line = cpu_sample_usage(self.pid) - lines.append(cpu_line) - break - elif self.worker.is_alive(): - mem_stat += get_mem_usage(self.pid) - count += 1 - else: - break - - # Delay sec per memory sampling - time.sleep(self.delay) - - mem_ret_q.put((count, mem_stat)) - -class TestWorker(threading.Thread): - def __init__(self, path, name, env): - threading.Thread.__init__(self) - self.path = path - self.name = name - self.env = env - - def run(self): - bin_path_name = os.path.join(self.path, self.name) - - test = subprocess.Popen([bin_path_name], env=self.env, preexec_fn = lambda: signal(SIGPIPE, SIG_DFL)) - test.wait() - - # Send ret value to main thread - test_ret_q.put(test.returncode) - -def get_pid(procname): - """ - Return pid of process name using 'pidof' command - """ - pidof = subprocess.Popen(["pidof", procname], stdout = subprocess.PIPE) - pid = pidof.communicate()[0].split() - - if pid == []: - return 0 - - return int(pid[0]) - -def spawn_session_daemon(): - """ - Exec the session daemon and return PID - """ - global sdaemon_proc - - pid = get_pid(SESSIOND_BIN_NAME) - if pid != 0: - os.kill(pid, SIGTERM) - - bin_path = os.path.join(TESTDIR_PATH, "..", SESSIOND_BIN_PATH, SESSIOND_BIN_NAME) - consumer_path = os.path.join(TESTDIR_PATH, "..", CONSUMERD_BIN_PATH, CONSUMERD_BIN_NAME) - - if not os.path.isfile(bin_path): - print "Error: No session daemon binary found. Compiled?" - return 0 - - try: - args = shlex.split("libtool execute " + bin_path - + " --consumerd32-path=" + consumer_path - + " --consumerd64-path=" + consumer_path) - - sdaemon_proc = subprocess.Popen(args, shell = False, stderr = subprocess.PIPE) - - except OSError, e: - print e - return 0 - - time.sleep(1) - - return get_pid("lt-" + SESSIOND_BIN_NAME) - -def start_test(name): - """ - Spawn test and return exit code - """ - tw = TestWorker(".", name) - tw.start() - - return test_ret_q.get(True) - -def print_cpu_stats(stats, count): - """ - Pretty print on one line the CPU stats - """ - sys.stdout.write(PRINT_ARROW + " Cpu [sampled %d time(s)]:\n " % (count)) - for stat in stats: - sys.stdout.write(" %s: %.2f, " % (stat, stats[stat])) - print "" - -def get_cpu_usage(delay=1, pid=0): - """ - Spawn a worker thread to sample cpu usage. - """ - sw = SamplingWorker("cpu", delay = delay, pid = pid) - sw.start() - - return cpu_ret_q.get(True) - -def get_mem_usage(pid): - """ - Get memory usage for PID - """ - return mem_sample_usage(pid) - -def print_test_success(ret, expect): - """ - Print if test has failed or pass according to the expected value. - """ - if ret != expect: - print "\n" + PRINT_RED_BRACKET + \ - " Failed: ret = %d (expected %d)" % (ret, expect) - return 1 - else: - print "\n" + PRINT_BRACKET + \ - " Passed: ret = %d (expected %d)" % (ret, expect) - return 0 - -def run_test(test): - """ - Run test 'name' and output report of the test with stats. - """ - global worker_proc - global sdaemon_proc - dem_pid = 0 # Session daemon pid - - print PRINT_BRACKET + " %s" % (test['name']) - print PRINT_ARROW + " %s" % (test['desc']) - if no_stats: - print PRINT_ARROW + " Statistics will NOT be collected" - else: - print PRINT_ARROW + " Statistics of the session daemon will be collected" - - if test['kern'] and not is_root: - print "Needs root for kernel tracing. Skipping" - return 0 - - if not os.path.isfile(test['bin']): - print "Unable to find test file '%s'. Skipping" % (test['bin']) - return 0 - - # Session daemon is controlled by the test - if test['daemon'] == "test": - print PRINT_ARROW + " Session daemon is controlled by the test" - env = os.environ - env['TEST_NO_SESSIOND'] = '0' - tw = TestWorker(".", test['bin'], env) - tw.start() - ret = test_ret_q.get(True) - print_test_success(ret, test['success']) - return 0 - elif test['daemon'] == False: - print PRINT_ARROW + " No session daemon needed" - env = os.environ - env['TEST_NO_SESSIOND'] = '1' - tw = TestWorker(".", test['bin'], env) - tw.start() - ret = test_ret_q.get(True) - print_test_success(ret, test['success']) - return 0 - else: - print PRINT_ARROW + " Session daemon needed" - - dem_pid = spawn_session_daemon() - if dem_pid <= 0: - print "Unable to start %s. Stopping" % (SESSIOND_BIN_NAME) - print sdaemon_proc.communicate()[1] - return 0 - - print PRINT_BRACKET + " Session daemon spawned (pid: %d)\n" % (dem_pid) - - if not no_stats: - mem_before = get_mem_usage(dem_pid) - print PRINT_BRACKET + " Stats *before* test:" - print PRINT_ARROW + " Mem (kB): %d" % (mem_before) - cpu_count, cpu_stats = get_cpu_usage(pid = dem_pid) - print_cpu_stats(cpu_stats, cpu_count) - - # Sessiond was already spawned, do not let the test spawn - # an additional sessiond - env = os.environ - env['TEST_NO_SESSIOND'] = '1' - - tw = TestWorker(".", test['bin'], env) - tw.start() - - if not no_stats: - # Start CPU sampling for test - sw_cpu = SamplingWorker("cpu", worker = tw, pid = dem_pid) - sw_cpu.start() - sw_mem = SamplingWorker("mem", worker = tw, pid = dem_pid) - sw_mem.start() - - ret = test_ret_q.get(True) - - if not no_stats: - time.sleep(2) - # Compute memory average - mem_count, mem_during = mem_ret_q.get(True) - mem_during = float(mem_during) / float(mem_count) - cpu_count, cpu_stats = cpu_ret_q.get(True) - - print "\n" + PRINT_BRACKET + " Stats *during* test:" - print PRINT_ARROW + " Mem (kB): %.0f [sampled %d time(s)]" % (mem_during, mem_count) - print_cpu_stats(cpu_stats, cpu_count) - - mem_after = get_mem_usage(dem_pid) - print "\n" + PRINT_BRACKET + " Stats *after* test:" - print PRINT_ARROW + " Mem (kB): %d" % (mem_after) - cpu_count, cpu_stats = get_cpu_usage(pid = dem_pid) - print_cpu_stats(cpu_stats, cpu_count) - - print "\n" + PRINT_BRACKET + " Memory usage differences:" - print PRINT_ARROW + " Diff during and before (kB): %d" % (mem_during - mem_before) - print PRINT_ARROW + " Diff during and after (kB): %d" % (mem_during - mem_after) - print PRINT_ARROW + " Diff before and after (kB): %d" % (mem_after - mem_before) - - # Return value of 0 means that is passed else it failed - ret = print_test_success(ret, test['success']) - - # Stop session daemon - if dem_pid > 0: - print PRINT_BRACKET + " Stopping session daemon (pid: %d)..." % (dem_pid) - try: - os.kill(dem_pid, SIGTERM) - # This call simply does not work... It seems python does not relay the signal - # to the child processes of sdaemon_proc. - # sdaemon_proc.terminate() - if ret != 0: - print sdaemon_proc.communicate()[1] - elif sdaemon_proc.returncode == None: - sdaemon_proc.communicate() - except OSError, e: - print e - - # Make sure all thread are released - if not no_stats: - tw.join() - sw_cpu.join() - sw_mem.join() - - return ret - -def main(): - for test in Tests: - if not test['enabled']: - continue - - ret = run_test(test) - if ret != 0: - # Stop all tests, the last one failed - return - print "" - -def cleanup(signo, stack): - """ Cleanup function """ - sys.exit(0) - -if __name__ == "__main__": - if not os.getuid() == 0: - is_root = 0 - print "NOTICE: Not root. No kernel tracing will be tested\n" - - if os.path.isfile("test_list.py"): - from test_list import Tests - else: - print "No test_list.py found. Stopping" - cleanup(0, 0) - - TESTDIR_PATH = os.getcwd() - - if len(sys.argv) > 1: - if sys.argv[1] == "--no-stats": - no_stats = 1 - - try: - signal(SIGTERM, cleanup) - signal(SIGINT, cleanup) - main() - cleanup(0, 0) - except KeyboardInterrupt: - cleanup(0, 0) diff --git a/tests/runall.sh b/tests/runall.sh deleted file mode 100755 index 0adbb2e4b..000000000 --- a/tests/runall.sh +++ /dev/null @@ -1,49 +0,0 @@ -#!/bin/bash -# -# 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 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -# - -#### ADD TESTS HERE #### - -tests=( kernel/runall.sh ust/runall.sh tools/runall.sh ) - -#### END TESTS HERE #### - -TESTDIR=$(dirname $0) - -source $TESTDIR/utils.sh - -## lttng-tools unit tests ## -# No session daemon needed -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 - echo -e '\e[1;31mFAIL\e[0m' - echo "" - exit 1 - fi -done - -# All passed -exit 0 diff --git a/tests/test_list.py b/tests/test_list.py deleted file mode 100755 index 2a613b92b..000000000 --- a/tests/test_list.py +++ /dev/null @@ -1,146 +0,0 @@ -Tests = \ -[ - # lttng-tools unit tests - { - 'bin': "tools/test_sessions", 'daemon': False, 'kern': False, 'name': "Test sessions", - 'desc': "Test tracing session data structures and methods.", - 'success': 0, 'enabled': True - }, - { - 'bin': "tools/test_kernel_data_trace", 'daemon': False, 'kern': False, - 'name': "Kernel data structures", - 'desc': "Test Kernel data structures and methods.", - 'success': 0, 'enabled': True - }, - { - 'bin': "tools/test_ust_data_trace", 'daemon': False, 'kern': False, - 'name': "UST data structures", - '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 tests - { - 'bin': "kernel/run-kernel-tests.sh", 'daemon': True, 'kern': True, - 'name': "Kernel tracer - lttng client", - 'desc': "Test the Kernel tracer using the lttng client", - 'success': 0, 'enabled': True - }, - - # UST tests - { - 'bin': "ust/run-ust-global-tests.sh", 'daemon': True, 'kern': False, - 'name': "UST tracer - Global domain", - 'desc': "Test the UST tracer functionnalities for domain LTTNG_DOMAIN_UST", - 'success': 0, 'enabled': True - }, - { - 'bin': "ust/nprocesses/run", 'daemon': True, 'kern': False, - 'name': "UST tracer - Multiple processes", - 'desc': "Test multiple process registering and tracing", - 'success': 0, 'enabled': True - }, - { - 'bin': "ust/high-throughput/run", 'daemon': True, 'kern': False, - 'name': "UST tracer - Testing high events throughput", - 'desc': "Test multiple large number of events with concurrent application", - 'success': 0, 'enabled': True - }, - # Deactivated. This test last 20 minutes... - #{ - #'bin': "ust/low-throughput/run", 'daemon': True, 'kern': False, - #'name': "UST tracer - Testing high events throughput", - #'desc': "Test low throughput of events", - #'success': 0, 'enabled': False - #}, - { - 'bin': "ust/before-after/run", 'daemon': True, 'kern': False, - 'name': "UST tracer - Tracing before and after app execution", - 'desc': "Test tracing before and after app execution", - 'success': 0, 'enabled': True - }, - { - 'bin': "ust/multi-session/run", 'daemon': True, 'kern': False, - 'name': "UST tracer - Multi-session", - 'desc': "Test tracing with 4 sessions for one application", - 'success': 0, 'enabled': True - }, - - # Tools filtering tests - { - 'bin': "tools/filtering/unsupported-ops", 'daemon': True, 'kern': False, - 'name': "Filtering - Unsupported operators", - 'desc': "Test the failure of filter with unsupported operators", - 'success': 0, 'enabled': True - }, - { - 'bin': "tools/filtering/invalid-filters", 'daemon': True, 'kern': False, - 'name': "Filtering - Invalid filters", - 'desc': "Test the failure of invalid filters", - 'success': 0, 'enabled': True - }, - { - 'bin': "tools/filtering/valid-filters", 'daemon': True, 'kern': False, - 'name': "Filtering - Valid filters", - 'desc': "Validate the expected trace output of valid filters", - 'success': 0, 'enabled': True - }, - - # Tools health check tests - { - 'bin': "tools/health/health_thread_exit", 'daemon': "test", 'kern': True, - 'name': "Health check - Thread exit", - 'desc': "Call exit in the various lttng-sessiond threads and ensure that health failure is detected", - 'success': 0, 'enabled': True - }, - { - 'bin': "tools/health/health_thread_stall", 'daemon': "test", 'kern': True, - 'name': "Health check - Thread stall", - 'desc': "Stall the various lttng-sessiond threads and ensure that health failure is detected", - 'success': 0, 'enabled': True - }, - { - 'bin': "tools/health/health_tp_fail", 'daemon': "test", 'kern': True, - 'name': "Health check - Testpoint failure", - 'desc': "Trigger a failure in the testpoint mechanism in each thread to provoke thread teardown", - 'success': 0, 'enabled': True - }, - - # Tools streaming tests - { - 'bin': "tools/streaming/run-kernel", 'daemon': True, 'kern': True, - 'name': "Streaming - Kernel tracing", - 'desc': "Stream a kernel trace across the network", - 'success': 0, 'enabled': True - }, - { - 'bin': "tools/streaming/run-ust", 'daemon': True, 'kern': False, - 'name': "Streaming - Userspace tracing", - 'desc': "Stream a userspace trace across the network", - 'success': 0, 'enabled': True - }, - { - 'bin': "tools/streaming/uri_switch", 'daemon': True, 'kern': False, - 'name': "Streaming - URI switching", - 'desc': "Switch URI and verify that the trace result are in the proper location", - 'success': 0, 'enabled': True - }, - { - 'bin': "tools/streaming/high_throughput_limits", 'daemon': True, 'kern': True, - 'name': "Streaming - High throughput with bandwith limits", - 'desc': "Trace streaming with bandwidth limits", - 'success': 0, 'enabled': True - }, -] diff --git a/tests/tools/Makefile.am b/tests/tools/Makefile.am deleted file mode 100644 index 4fe494cec..000000000 --- a/tests/tools/Makefile.am +++ /dev/null @@ -1,41 +0,0 @@ -SUBDIRS = streaming filtering health - -AM_CFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/src -I$(top_srcdir)/tests -g -Wall -AM_LDFLAGS = -lurcu - -EXTRA_DIST = runall.sh - -noinst_PROGRAMS = test_sessions test_kernel_data_trace - -UTILS=../utils.h -SESSIONS=$(top_srcdir)/src/bin/lttng-sessiond/session.c \ - $(top_srcdir)/src/bin/lttng-sessiond/consumer.c \ - $(top_srcdir)/src/common/uri.c \ - $(top_srcdir)/src/common/utils.c \ - $(top_srcdir)/src/common/error.c -KERN_DATA_TRACE=$(top_srcdir)/src/bin/lttng-sessiond/trace-kernel.c \ - $(top_srcdir)/src/bin/lttng-sessiond/consumer.c \ - $(top_srcdir)/src/common/uri.c \ - $(top_srcdir)/src/common/utils.c -COMMON=$(top_builddir)/src/common/libcommon.la -HASHTABLE=$(top_builddir)/src/common/hashtable/libhashtable.la -SESSIOND_COMM=$(top_builddir)/src/common/sessiond-comm/libsessiond-comm.la - -# Tracing sessions unit tests -test_sessions_SOURCES = test_sessions.c $(UTILS) $(SESSIONS) -test_sessions_LDADD = $(COMMON) $(HASHTABLE) $(SESSIOND_COMM) - -# Kernel trace data unit tests -test_kernel_data_trace_SOURCES = test_kernel_data_trace.c $(UTILS) $(KERN_DATA_TRACE) -test_kernel_data_trace_LDADD = $(COMMON) $(SESSIOND_COMM) $(HASHTABLE) - -if HAVE_LIBLTTNG_UST_CTL -noinst_PROGRAMS += test_ust_data_trace -UST_DATA_TRACE=$(top_srcdir)/src/bin/lttng-sessiond/trace-ust.c \ - $(top_srcdir)/src/bin/lttng-sessiond/consumer.c \ - $(top_srcdir)/src/common/uri.c \ - $(top_srcdir)/src/common/utils.c -# UST trace data unit tests -test_ust_data_trace_SOURCES = test_ust_data_trace.c $(UTILS) $(UST_DATA_TRACE) -test_ust_data_trace_LDADD = $(COMMON) $(HASHTABLE) $(SESSIOND_COMM) -endif diff --git a/tests/tools/filtering/Makefile.am b/tests/tools/filtering/Makefile.am deleted file mode 100644 index e1e715da4..000000000 --- a/tests/tools/filtering/Makefile.am +++ /dev/null @@ -1,18 +0,0 @@ -AM_CFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/src -I$(top_srcdir)/tests -I$(srcdir) -O2 -g -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 = runall unsupported-ops invalid-filters valid-filters babelstats.pl -EXTRA_DIST = runall unsupported-ops invalid-filters valid-filters babelstats.pl diff --git a/tests/tools/filtering/babelstats.pl b/tests/tools/filtering/babelstats.pl deleted file mode 100755 index d8d4dd08e..000000000 --- a/tests/tools/filtering/babelstats.pl +++ /dev/null @@ -1,174 +0,0 @@ -#!/usr/bin/perl - -# Copyright (C) - 2012 Christian Babeux -# -# This program is free software; you can redistribute it and/or modify it -# under the terms of the GNU General Public License, version 2 only, as -# published by the Free Software Foundation. -# -# 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. - -use strict; -use warnings; - -use Getopt::Long; - -my $opt_tracepoint; - -GetOptions('tracepoint=s' => \$opt_tracepoint) - or die("Invalid command-line option\n"); - -defined($opt_tracepoint) - or die("Missing tracepoint, use --tracepoint "); - -# Parse an array string. -# The format is as follow: [ [index] = value, ... ] -sub parse_array -{ - my ($arr_str) = @_; - my @array = (); - - # Strip leading and ending brackets, remove whitespace - $arr_str =~ s/^\[//; - $arr_str =~ s/\]$//; - $arr_str =~ s/\s//g; - - my @entries = split(',', $arr_str); - - foreach my $entry (@entries) { - if ($entry =~ /^\[(\d+)\]=(\d+)$/) { - my $index = $1; - my $value = $2; - splice @array, $index, 0, $value; - } - } - - return \@array; -} - -# Parse fields values. -# Format can either be a name = array or a name = value pair. -sub parse_fields -{ - my ($fields_str) = @_; - my %fields_hash; - - my $field_name = '[\w\d_]+'; - my $field_value = '[\w\d_\\\*"]+'; - my $array = '\[(?:\s\[\d+\]\s=\s\d+,)*\s\[\d+\]\s=\s\d+\s\]'; - - # Split the various fields - my @fields = ($fields_str =~ /$field_name\s=\s(?:$array|$field_value)/g); - - foreach my $field (@fields) { - if ($field =~ /($field_name)\s=\s($array)/) { - my $name = $1; - my $value = parse_array($2); - $fields_hash{$name} = $value; - } - - if ($field =~ /($field_name)\s=\s($field_value)/) { - my $name = $1; - my $value = $2; - $fields_hash{$name} = $value; - } - } - - return \%fields_hash; -} - -# Using an event array, merge all the fields -# of a particular tracepoint. -sub merge_fields -{ - my ($events_ref) = @_; - my %merged; - - foreach my $event (@{$events_ref}) { - my $tp_provider = $event->{'tp_provider'}; - my $tp_name = $event->{'tp_name'}; - my $tracepoint = "$tp_provider:$tp_name"; - - foreach my $key (keys %{$event->{'fields'}}) { - my $val = $event->{'fields'}->{$key}; - - # TODO: Merge of array is not implemented. - next if (ref($val) eq 'ARRAY'); - $merged{$tracepoint}{$key}{$val} = undef; - } - } - - return \%merged; -} - -# Print the minimum and maximum of each fields -# for a particular tracepoint. -sub print_fields_stats -{ - my ($merged_ref, $tracepoint) = @_; - - return unless ($tracepoint && exists $merged_ref->{$tracepoint}); - - foreach my $field (keys %{$merged_ref->{$tracepoint}}) { - my @sorted; - my @val = keys ($merged_ref->{$tracepoint}->{$field}); - - if ($val[0] =~ /^\d+$/) { - # Sort numerically - @sorted = sort { $a <=> $b } @val; - } elsif ($val[0] =~ /^0x[\da-f]+$/i) { - # Convert the hex values and sort numerically - @sorted = sort { hex($a) <=> hex($b) } @val; - } else { - # Fallback, alphabetical sort - @sorted = sort { lc($a) cmp lc($b) } @val; - } - - my $min = $sorted[0]; - my $max = $sorted[-1]; - - print "$field $min $max\n"; - } -} - -my @events; - -while (<>) -{ - my $timestamp = '\[(.*)\]'; - my $elapsed = '\((.*)\)'; - my $hostname = '.*'; - my $pname = '.*'; - my $pid = '\d+'; - my $tp_provider = '.*'; - my $tp_name = '.*'; - my $cpu_info = '{\scpu_id\s=\s(\d+)\s\}'; - my $fields = '{(.*)}'; - - # Parse babeltrace text output format - if (/$timestamp\s$elapsed\s($hostname):($pname):($pid)\s($tp_provider):($tp_name):\s$cpu_info,\s$fields/) { - my %event_hash; - - $event_hash{'timestamp'} = $1; - $event_hash{'elapsed'} = $2; - $event_hash{'hostname'} = $3; - $event_hash{'pname'} = $4; - $event_hash{'pid'} = $5; - $event_hash{'tp_provider'} = $6; - $event_hash{'tp_name'} = $7; - $event_hash{'cpu_id'} = $8; - $event_hash{'fields'} = parse_fields($9); - - push @events, \%event_hash; - } -} - -my %merged_fields = %{merge_fields(\@{events})}; -print_fields_stats(\%merged_fields, $opt_tracepoint); diff --git a/tests/tools/filtering/gen-ust-events.c b/tests/tools/filtering/gen-ust-events.c deleted file mode 100644 index c789c89d4..000000000 --- a/tests/tools/filtering/gen-ust-events.c +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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"; - char escape[10] = "\\*"; - 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), escape, dbl, flt); - usleep(nr_usec); - } - - return 0; -} diff --git a/tests/tools/filtering/invalid-filters b/tests/tools/filtering/invalid-filters deleted file mode 100755 index b6537055c..000000000 --- a/tests/tools/filtering/invalid-filters +++ /dev/null @@ -1,150 +0,0 @@ -#!/bin/bash -# -# Copyright (C) - 2012 Christian Babeux -# -# This program is free software; you can redistribute it and/or modify it -# under the terms of the GNU General Public License, version 2 only, as -# published by the Free Software Foundation. -# -# 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. - -TEST_DESC="Filtering - Invalid filters" - -CURDIR=$(dirname $0)/ -TESTDIR=$CURDIR/../.. -LTTNG_BIN="lttng" -SESSION_NAME="filter-invalid" -EVENT_NAME="bogus" -ENABLE_EVENT_STDERR="/tmp/invalid-filters-stderr" -TRACE_PATH=$(mktemp -d) - -source $TESTDIR/utils.sh - -print_test_banner "$TEST_DESC" - -function enable_ust_lttng_event_filter -{ - sess_name="$1" - event_name="$2" - filter="$3" - echo -n "Enabling lttng event with filtering and invalid filter " - - $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event $event_name -s $sess_name -u --filter "$filter" 2> $ENABLE_EVENT_STDERR 1> /dev/null - - # Enable must fail - if [ $? -eq 0 ]; then - print_fail - return 1 - else - print_ok - return 0 - fi -} - -function test_invalid_filter -{ - test_invalid_filter="$1" - - echo "" - echo -e "=== Testing filter expression with invalid filter" - echo -e "Filter: $test_invalid_filter" - - # Create session - create_lttng_session $SESSION_NAME $TRACE_PATH - - # Apply filter - enable_ust_lttng_event_filter $SESSION_NAME $EVENT_NAME "$test_invalid_filter" - - # Destroy session - destroy_lttng_session $SESSION_NAME -} - -function test_bytecode_limit -{ - # Current bytecode limitation is 65536 bytes long. - # Generate a huge bytecode with some perl-fu - BYTECODE_LIMIT=`perl -e 'print "intfield" . " && 1" x5460'` - - echo "" - echo -e "=== Testing filter bytecode limits (64KiB)" - - # Create session - create_lttng_session $SESSION_NAME $TRACE_PATH - - # Apply filter - enable_ust_lttng_event_filter $SESSION_NAME $EVENT_NAME "$BYTECODE_LIMIT" - - # Destroy session - destroy_lttng_session $SESSION_NAME -} - -IFS=$'\n' -INVALID_FILTERS=( - # Unsupported ops - "intfield*1" - "intfield/1" - "intfield+1" - "intfield-1" - "intfield>>1" - "intfield<<1" - "intfield&1" - "intfield|1" - "intfield^1" - "~intfield" - "1+11111-3333+1" - "(1+2)*(55*666)" - "1+2*55*666" - "asdf + 1 > 1" - "asdfas < 2332 || asdf + 1 > 1" - "!+-+++-------+++++++++++-----!!--!44+1" - "aaa||(gg)+(333----1)" - "1+1" - # Unmatched parenthesis - "((((((((((((((intfield)))))))))))))" - '0 || ("abc" != "def")) && (3 < 4)' - # Field dereference - "a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a" - "a->" - "a-->a" - "a->a" - "a.b.c->d.e.f+1" - "!a.f.d" - "asdf.asdfsd.sadf < 4" - "asdfasdf->asdfasdf < 2" - # String can't be root node - "\"somestring\"" - # Unary op on string not allowed - "!\"somestring\"" - # Comparison with string type not allowed - "\"somestring\" > 42" - "\"somestring\" > 42.0" - "42 > \"somestring\"" - "42.0 > \"somestring\"" - # Logical operator with string type not allowed - "\"somestring\" || 1" - "1 || \"somestring\"" - # Nesting of binary operator not allowed - "1 | (1 | (1 | 1))" - "1 > (1 > (1 > 1))" - ) - -start_lttng_sessiond -for FILTER in ${INVALID_FILTERS[@]}; -do - test_invalid_filter "$FILTER" -done - -test_bytecode_limit - -unset IFS -stop_lttng_sessiond - -rm -f $ENABLE_EVENT_STDERR -rm -rf $TRACE_PATH diff --git a/tests/tools/filtering/runall b/tests/tools/filtering/runall deleted file mode 100755 index c92e39988..000000000 --- a/tests/tools/filtering/runall +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/bash - -DIR=$(dirname $0) - -tests=( $DIR/unsupported-ops $DIR/invalid-filters $DIR/valid-filters ) -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/filtering/tp.c b/tests/tools/filtering/tp.c deleted file mode 100644 index a09561d70..000000000 --- a/tests/tools/filtering/tp.c +++ /dev/null @@ -1,15 +0,0 @@ -/* - * 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/filtering/tp.h b/tests/tools/filtering/tp.h deleted file mode 100644 index 15f81e5c0..000000000 --- a/tests/tools/filtering/tp.h +++ /dev/null @@ -1,57 +0,0 @@ -#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, - char *, etext, 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_string(stringfield2, etext) - 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/tools/filtering/unsupported-ops b/tests/tools/filtering/unsupported-ops deleted file mode 100755 index 8b743f41c..000000000 --- a/tests/tools/filtering/unsupported-ops +++ /dev/null @@ -1,114 +0,0 @@ -#!/bin/bash -# -# Copyright (C) - 2012 Christian Babeux -# -# This program is free software; you can redistribute it and/or modify it -# under the terms of the GNU General Public License, version 2 only, as -# published by the Free Software Foundation. -# -# 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. - -TEST_DESC="Filtering - Unsupported operators" - -CURDIR=$(dirname $0)/ -TESTDIR=$CURDIR/../.. -LTTNG_BIN="lttng" -SESSION_NAME="filter-unsupported-ops" -EVENT_NAME="bogus" -ENABLE_EVENT_STDERR="/tmp/unsupported-ops-enable" -TRACE_PATH=$(mktemp -d) - -source $TESTDIR/utils.sh - -print_test_banner "$TEST_DESC" - -function enable_ust_lttng_event_filter_unsupported -{ - sess_name=$1 - event_name=$2 - filter=$3 - - echo -n "Enabling lttng event with filtering and unsupported operator " - enable_cmd="$TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event" - $enable_cmd $event_name -s $sess_name -u --filter "$filter" 2> $ENABLE_EVENT_STDERR 1> /dev/null - - # Enable must fail - if [ $? -eq 0 ]; then - print_fail - return 1 - else - print_ok - return 0 - fi -} - -function test_unsupported_op -{ - test_op_str=$1 - test_op_tkn=$2 - - echo "" - echo -e "=== Testing filter expression with unsupported operator $test_op_str ($test_op_tkn)" - - # Create session - create_lttng_session $SESSION_NAME $TRACE_PATH - - # Create filter - if [ "$test_op_str" == "UNARY_BIN_NOT" ]; then - TEST_FILTER="${test_op_tkn}1" - else - TEST_FILTER="intfield $test_op_tkn 1" - fi - - # Apply filter - enable_ust_lttng_event_filter_unsupported $SESSION_NAME $EVENT_NAME "$TEST_FILTER" - - # Test stderr for unsupported operator - echo -n "Unsupported operator test $test_op_str ($test_op_tkn) " - grep -i -q "not[[:space:]]\+supported" $ENABLE_EVENT_STDERR - - if [ $? -eq 1 ]; then - print_fail - return 1 - else - print_ok - fi - - # Destroy session - destroy_lttng_session $SESSION_NAME - return 0 -} - -# Unsupported operators -OP_STR=("MUL" "DIV" "MOD" "PLUS" "MINUS" "LSHIFT" "RSHIFT" - "BIN_AND" "BIN_OR" "BIN_XOR" "UNARY_BIN_NOT") - -OP_TKN=("*" "/" "%" "+" "-" "<<" ">>" "&" "|" "^" "~") - -OP_COUNT=${#OP_STR[@]} -i=0 - -start_lttng_sessiond - -while [ "$i" -lt "$OP_COUNT" ]; do - test_unsupported_op "${OP_STR[$i]}" "${OP_TKN[$i]}" - - if [ $? -eq 1 ]; then - exit 1 - fi - - let "i++" -done - -stop_lttng_sessiond - -# Cleanup -rm -f $ENABLE_EVENT_STDERR -rm -rf $TRACE_PATH diff --git a/tests/tools/filtering/valid-filters b/tests/tools/filtering/valid-filters deleted file mode 100755 index 3d7e921f2..000000000 --- a/tests/tools/filtering/valid-filters +++ /dev/null @@ -1,417 +0,0 @@ -#!/bin/bash -# -# Copyright (C) - 2012 Christian Babeux -# -# This program is free software; you can redistribute it and/or modify it -# under the terms of the GNU General Public License, version 2 only, as -# published by the Free Software Foundation. -# -# 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. - -TEST_DESC="Filtering - Valid filters" - -CURDIR=$(dirname $0)/ -TESTDIR=$CURDIR/../.. -LTTNG_BIN="lttng" -BIN_NAME="gen-ust-events" -STATS_BIN="babelstats.pl" -SESSION_NAME="valid_filter" -EVENT_NAME="tp:tptest" -NR_ITER=100 - -source $TESTDIR/utils.sh - -print_test_banner "$TEST_DESC" - -if [ ! -x "$CURDIR/$BIN_NAME" ]; then - echo -e "No UST nevents binary detected. Passing." - exit 0 -fi - -function enable_ust_lttng_event_filter() -{ - sess_name="$1" - event_name="$2" - filter="$3" - echo -n "Enabling lttng event with filtering " - - $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event $event_name -s $sess_name -u --filter "$filter" 2>&1 >/dev/null - - if [ $? -eq 0 ]; then - print_ok - return 0 - else - print_fail - return 1 - fi -} - -function run_apps -{ - ./$CURDIR/$BIN_NAME $NR_ITER & >/dev/null 2>&1 -} - -function wait_apps -{ - echo "Waiting for applications to end" - while [ -n "$(pidof $BIN_NAME)" ]; do - echo -n "." - sleep 1 - done - echo "" -} - -function test_valid_filter -{ - filter="$1" - validator="$2" - - echo "" - echo -e "=== Testing valid filter: $1" - - trace_path=$(mktemp -d) - - # Create session - create_lttng_session $SESSION_NAME $trace_path - - # Enable filter - enable_ust_lttng_event_filter $SESSION_NAME $EVENT_NAME $filter - - # Trace apps - start_lttng_tracing $SESSION_NAME - run_apps - wait_apps - stop_lttng_tracing $SESSION_NAME - - # Destroy session - destroy_lttng_session $SESSION_NAME - - echo -n "Validating filter output " - stats=`babeltrace $trace_path | $CURDIR/$STATS_BIN --tracepoint $EVENT_NAME` - - rm -rf $trace_path - - $validator "$stats" - - if [ $? -eq 0 ]; then - print_ok -# rm -rf $trace_path - return 0 - else - print_fail - return 1 - fi -} - -function validate_min_max -{ - stats="$1" - field=$2 - expected_min=$3 - expected_max=$4 - - echo $stats | grep -q "$field $expected_min $expected_max" - - return $? -} - -function validator_intfield -{ - stats="$1" - status=0 - - validate_min_max "$stats" "intfield" "1" "99" - status=$(($status|$?)) - - validate_min_max "$stats" "intfield2" "0x1" "0x63" - status=$(($status|$?)) - - validate_min_max "$stats" "longfield" "1" "99" - status=$(($status|$?)) - - validate_min_max "$stats" "netintfield" "1" "99" - status=$(($status|$?)) - - validate_min_max "$stats" "netintfieldhex" "0x1" "0x63" - status=$(($status|$?)) - - validate_min_max "$stats" "floatfield" "2222" "2222" - status=$(($status|$?)) - - validate_min_max "$stats" "doublefield" "2" "2" - status=$(($status|$?)) - - return $status -} - -function validator_intfield_gt -{ - stats="$1" - status=0 - - validate_min_max "$stats" "intfield" "2" "99" - status=$(($status|$?)) - - return $status -} - -function validator_intfield_ge -{ - stats="$1" - status=0 - - validate_min_max "$stats" "intfield" "1" "99" - status=$(($status|$?)) - - return $status -} - -function validator_intfield_lt -{ - stats="$1" - status=0 - - validate_min_max "$stats" "intfield" "0" "1" - status=$(($status|$?)) - - return $status -} - -function validator_intfield_le -{ - stats="$1" - status=0 - - validate_min_max "$stats" "intfield" "0" "2" - status=$(($status|$?)) - - return $status -} - -function validator_intfield_eq -{ - stats="$1" - status=0 - - validate_min_max "$stats" "intfield" "1" "1" - status=$(($status|$?)) - - return $status -} - -function validator_intfield_ne -{ - stats="$1" - status=0 - - validate_min_max "$stats" "intfield" "0" "98" - status=$(($status|$?)) - - return $status -} - -function validator_intfield_not -{ - stats="$1" - status=0 - - validate_min_max "$stats" "intfield" "0" "0" - status=$(($status|$?)) - - return $status -} - -function validator_intfield_gt_and_longfield_gt -{ - stats="$1" - status=0 - - validate_min_max "$stats" "intfield" "43" "99" - status=$(($status|$?)) - validate_min_max "$stats" "longfield" "43" "99" - status=$(($status|$?)) - - return $status -} - -function validator_intfield_ge_and_longfield_le -{ - stats="$1" - status=0 - - validate_min_max "$stats" "intfield" "42" "42" - status=$(($status|$?)) - validate_min_max "$stats" "longfield" "42" "42" - status=$(($status|$?)) - - return $status -} - -function validator_intfield_lt_or_longfield_gt -{ - stats="$1" - status=0 - - validate_min_max "$stats" "intfield" "0" "99" - status=$(($status|$?)) - validate_min_max "$stats" "longfield" "0" "99" - status=$(($status|$?)) - - return $status -} - -function validator_mixed_str_or_int_and_int -{ - stats="$1" - status=0 - - validate_min_max "$stats" "intfield" "34" "99" - status=$(($status|$?)) - - validate_min_max "$stats" "stringfield" "\"test\"" "\"test\"" - status=$(($status|$?)) - - return $status -} - -function validator_mixed_int_double -{ - stats="$1" - status=0 - - validate_min_max "$stats" "intfield" "0" "42" - status=$(($status|$?)) - - return $status -} - -function validator_true_statement -{ - stats="$1" - status=0 - - validate_min_max "$stats" "intfield" "0" "99" - status=$(($status|$?)) - - validate_min_max "$stats" "intfield2" "0x0" "0x63" - status=$(($status|$?)) - - validate_min_max "$stats" "longfield" "0" "99" - status=$(($status|$?)) - - validate_min_max "$stats" "netintfield" "0" "99" - status=$(($status|$?)) - - validate_min_max "$stats" "netintfieldhex" "0x0" "0x63" - status=$(($status|$?)) - - validate_min_max "$stats" "floatfield" "2222" "2222" - status=$(($status|$?)) - - validate_min_max "$stats" "doublefield" "2" "2" - status=$(($status|$?)) - - validate_min_max "$stats" "stringfield" "\"test\"" "\"test\"" - status=$(($status|$?)) - - validate_min_max "$stats" "stringfield2" ""\*"" ""\*"" - status=$(($status|$?)) - - return $status -} - -IFS=$'\n' - -issue_356_filter="intfield > 0 && intfield > 1 && " -issue_356_filter+="intfield > 2 && intfield > 3 && " -issue_356_filter+="intfield > 4 && intfield > 5 && " -issue_356_filter+="intfield > 6 && intfield > 7 && " -issue_356_filter+="intfield > 8 || intfield > 0" - -# One to one mapping between filters and validators - -FILTERS=("intfield" #1 - "intfield > 1" #2 - "intfield >= 1" #3 - "intfield < 2" #4 - "intfield <= 2" #5 - "intfield == 1" #6 - "intfield != 99" #7 - "!intfield" #8 - "-intfield" #9 - "--intfield" #10 - "+intfield" #11 - "++intfield" #12 - "intfield > 1 && longfield > 42" #13 - "intfield >= 42 && longfield <= 42" #14 - "intfield < 1 || longfield > 98" #15 - "(stringfield == \"test\" || intfield != 10) && intfield > 33" #16 - "intfield < 42.4242424242" #17 - "\"test\" == \"test\"" #18 #Issue #342 - "stringfield == \"test\"" #19 - "stringfield == \"t*\"" #20 - "stringfield == \"*\"" #21 - $issue_356_filter #22 #Issue #356 - "intfield < 0xDEADBEEF" #23 - "intfield < 0x2" #24 - "intfield < 02" #25 - "stringfield2 == \"\\\*\"" #26 - "1.0 || intfield || 1.0" #27 - "1 < intfield" #28 -) - -VALIDATOR=("validator_intfield" #1 - "validator_intfield_gt" #2 - "validator_intfield_ge" #3 - "validator_intfield_lt" #4 - "validator_intfield_le" #5 - "validator_intfield_eq" #6 - "validator_intfield_ne" #7 - "validator_intfield_not" #8 - "validator_intfield" #9 - "validator_intfield" #10 - "validator_intfield" #11 - "validator_intfield" #12 - "validator_intfield_gt_and_longfield_gt" #13 - "validator_intfield_ge_and_longfield_le" #14 - "validator_intfield_lt_or_longfield_gt" #15 - "validator_mixed_str_or_int_and_int" #16 - "validator_mixed_int_double" #17 - "validator_true_statement" #18 - "validator_true_statement" #19 - "validator_true_statement" #20 - "validator_true_statement" #21 - "validator_intfield" #22 - "validator_true_statement" #23 - "validator_intfield_lt" #24 - "validator_intfield_lt" #25 - "validator_true_statement" #26 - "validator_true_statement" #27 - "validator_intfield_gt" #28 -) - -FILTER_COUNT=${#FILTERS[@]} -i=0 - -start_lttng_sessiond - -while [ "$i" -lt "$FILTER_COUNT" ]; do - - test_valid_filter "${FILTERS[$i]}" "${VALIDATOR[$i]}" - - if [ $? -eq 1 ]; then - stop_lttng_sessiond - exit 1 - fi - - let "i++" -done - -stop_lttng_sessiond diff --git a/tests/tools/health/Makefile.am b/tests/tools/health/Makefile.am deleted file mode 100644 index 26d246161..000000000 --- a/tests/tools/health/Makefile.am +++ /dev/null @@ -1,41 +0,0 @@ -AM_CFLAGS = -I. -O2 -g -I../../../include -AM_LDFLAGS = - -if LTTNG_TOOLS_BUILD_WITH_LIBDL -AM_LDFLAGS += -ldl -endif -if LTTNG_TOOLS_BUILD_WITH_LIBC_DL -AM_LDFLAGS += -lc -endif - -if NO_SHARED -# Do not build this test if shared libraries support was -# explicitly disabled. -else -# In order to test the health check feature, the libhealth* libs -# must be built as .so to be able to LD_PRELOAD them. -FORCE_SHARED_LIB_OPTIONS = -module -shared -avoid-version \ - -rpath $(abs_builddir) - -# Health thread exit ld_preloaded test lib -libhealthexit_la_SOURCES=health_exit.c -libhealthexit_la_LDFLAGS= $(FORCE_SHARED_LIB_OPTIONS) - -# Health thread stall ld_preloaded test lib -libhealthstall_la_SOURCES=health_stall.c -libhealthstall_la_LDFLAGS= $(FORCE_SHARED_LIB_OPTIONS) - -# Health thread fail ld_preloaded test lib -libhealthtpfail_la_SOURCES=health_fail.c -libhealthtpfail_la_LDFLAGS= $(FORCE_SHARED_LIB_OPTIONS) - -noinst_PROGRAMS = health_check -noinst_LTLIBRARIES = libhealthexit.la libhealthstall.la libhealthtpfail.la - -health_check_SOURCES = health_check.c $(UTILS) -health_check_LDADD = $(top_builddir)/src/lib/lttng-ctl/liblttng-ctl.la \ - $(top_builddir)/src/common/libcommon.la -endif - -noinst_SCRIPTS = runall -EXTRA_DIST = runall diff --git a/tests/tools/health/health_check.c b/tests/tools/health/health_check.c deleted file mode 100644 index 3eef11040..000000000 --- a/tests/tools/health/health_check.c +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (C) 2012 - Christian Babeux - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License, version 2 only, as - * published by the Free Software Foundation. - * - * 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. - */ - -#include - -#include "lttng/lttng.h" - -#define HEALTH_CMD_FAIL (1 << 0) -#define HEALTH_APP_MNG_FAIL (1 << 1) -#define HEALTH_APP_REG_FAIL (1 << 2) -#define HEALTH_KERNEL_FAIL (1 << 3) -#define HEALTH_CSMR_FAIL (1 << 4) - -int main(int argc, char *argv[]) -{ - int health = -1; - int status = 0; - - /* Command thread */ - health = lttng_health_check(LTTNG_HEALTH_CMD); - printf("Health check cmd: %d\n", health); - - if (health) { - status |= HEALTH_CMD_FAIL; - } - - /* App manage thread */ - health = lttng_health_check(LTTNG_HEALTH_APP_MANAGE); - printf("Health check app. manage: %d\n", health); - - if (health) { - status |= HEALTH_APP_MNG_FAIL; - } - /* App registration thread */ - health = lttng_health_check(LTTNG_HEALTH_APP_REG); - printf("Health check app. registration: %d\n", health); - - if (health) { - status |= HEALTH_APP_REG_FAIL; - } - - /* Kernel thread */ - health = lttng_health_check(LTTNG_HEALTH_KERNEL); - printf("Health check kernel: %d\n", health); - - if (health) { - status |= HEALTH_KERNEL_FAIL; - } - - /* Consumer thread */ - health = lttng_health_check(LTTNG_HEALTH_CONSUMER); - printf("Health check consumer: %d\n", health); - - if (health) { - status |= HEALTH_CSMR_FAIL; - } - - return status; -} diff --git a/tests/tools/health/health_exit.c b/tests/tools/health/health_exit.c deleted file mode 100644 index 8e414053e..000000000 --- a/tests/tools/health/health_exit.c +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (C) 2012 - Christian Babeux - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License, version 2 only, as - * published by the Free Software Foundation. - * - * 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. - */ - -#include -#include -#include - -/* - * Check if the specified environment variable is set. - * Return 1 if set, otherwise 0. - */ -int check_env_var(const char *env) -{ - if (env) { - char *env_val = getenv(env); - if (env_val && (strncmp(env_val, "1", 1) == 0)) { - return 1; - } - } - - return 0; -} - -int __testpoint_thread_manage_clients(void) -{ - const char *var = "LTTNG_THREAD_MANAGE_CLIENTS_EXIT"; - - if (check_env_var(var)) { - pthread_exit(NULL); - } - - return 0; -} - -int __testpoint_thread_registration_apps(void) -{ - const char *var = "LTTNG_THREAD_REG_APPS_EXIT"; - - if (check_env_var(var)) { - pthread_exit(NULL); - } - - return 0; -} - -int __testpoint_thread_manage_apps(void) -{ - const char *var = "LTTNG_THREAD_MANAGE_APPS_EXIT"; - - if (check_env_var(var)) { - pthread_exit(NULL); - } - - return 0; -} - -int __testpoint_thread_manage_kernel(void) -{ - const char *var = "LTTNG_THREAD_MANAGE_KERNEL_EXIT"; - - if (check_env_var(var)) { - pthread_exit(NULL); - } - - return 0; -} - -int __testpoint_thread_manage_consumer(void) -{ - const char *var = "LTTNG_THREAD_MANAGE_CONSUMER_EXIT"; - - if (check_env_var(var)) { - pthread_exit(NULL); - } - - return 0; -} diff --git a/tests/tools/health/health_fail.c b/tests/tools/health/health_fail.c deleted file mode 100644 index 622782548..000000000 --- a/tests/tools/health/health_fail.c +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (C) 2012 - Christian Babeux - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License, version 2 only, as - * published by the Free Software Foundation. - * - * 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. - */ - -#include -#include -#include - -/* - * Check if the specified environment variable is set. - * Return 1 if set, otherwise 0. - */ -int check_env_var(const char *env) -{ - if (env) { - char *env_val = getenv(env); - if (env_val && (strncmp(env_val, "1", 1) == 0)) { - return 1; - } - } - - return 0; -} - -int __testpoint_thread_manage_clients(void) -{ - const char *var = "LTTNG_THREAD_MANAGE_CLIENTS_TP_FAIL"; - - if (check_env_var(var)) { - return 1; - } - - return 0; -} - -int __testpoint_thread_manage_apps(void) -{ - const char *var = "LTTNG_THREAD_MANAGE_APPS_TP_FAIL"; - - if (check_env_var(var)) { - return 1; - } - - return 0; -} - -int __testpoint_thread_manage_kernel(void) -{ - const char *var = "LTTNG_THREAD_MANAGE_KERNEL_TP_FAIL"; - - if (check_env_var(var)) { - return 1; - } - - return 0; -} diff --git a/tests/tools/health/health_stall.c b/tests/tools/health/health_stall.c deleted file mode 100644 index 127f5fcf9..000000000 --- a/tests/tools/health/health_stall.c +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (C) 2012 - Christian Babeux - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License, version 2 only, as - * published by the Free Software Foundation. - * - * 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. - */ - -#include -#include -#include -#include - -#define STALL_TIME 60 - -/* - * Check if the specified environment variable is set. - * Return 1 if set, otherwise 0. - */ -int check_env_var(const char *env) -{ - if (env) { - char *env_val = getenv(env); - if (env_val && (strncmp(env_val, "1", 1) == 0)) { - return 1; - } - } - - return 0; -} - -int __testpoint_thread_manage_clients_before_loop(void) -{ - const char *var = "LTTNG_THREAD_MANAGE_CLIENTS_STALL"; - - if (check_env_var(var)) { - unsigned int sleep_time = STALL_TIME; - while (sleep_time > 0) { - sleep_time = sleep(sleep_time); - } - } - - return 0; -} - -int __testpoint_thread_manage_kernel_before_loop(void) -{ - const char *var = "LTTNG_THREAD_MANAGE_KERNEL_STALL"; - - if (check_env_var(var)) { - unsigned int sleep_time = STALL_TIME; - while (sleep_time > 0) { - sleep_time = sleep(sleep_time); - } - } - - return 0; -} - -int __testpoint_thread_manage_apps_before_loop(void) -{ - const char *var = "LTTNG_THREAD_MANAGE_APPS_STALL"; - - if (check_env_var(var)) { - unsigned int sleep_time = STALL_TIME; - while (sleep_time > 0) { - sleep_time = sleep(sleep_time); - } - } - - return 0; -} diff --git a/tests/tools/health/health_thread_exit b/tests/tools/health/health_thread_exit deleted file mode 100755 index de783ad08..000000000 --- a/tests/tools/health/health_thread_exit +++ /dev/null @@ -1,105 +0,0 @@ -#!/bin/bash -# -# Copyright (C) - 2012 Christian Babeux -# -# This program is free software; you can redistribute it and/or modify it -# under the terms of the GNU General Public License, version 2 only, as -# published by the Free Software Foundation. -# -# 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. - -TEST_DESC="Health check - Thread exit" - -CURDIR=$(dirname $0)/ -TESTDIR=$CURDIR/../.. -LTTNG_BIN="lttng" -SESSION_NAME="health_thread_exit" -EVENT_NAME="bogus" -HEALTH_CHECK_BIN="health_check" -SESSIOND_PRELOAD=".libs/libhealthexit.so" - -source $TESTDIR/utils.sh - -print_test_banner "$TEST_DESC" - -if [ ! -f "$CURDIR/$SESSIOND_PRELOAD" ]; then - echo -e "libhealthexit.so not available for this test. Skipping." - exit 0 -fi - -function test_thread_exit -{ - test_thread_exit_name="$1" - test_thread_exit_code="$2" - - echo "" - echo -e "=== Testing health failure with ${test_thread_exit_name}" - - # Activate testpoints - export LTTNG_TESTPOINT_ENABLE=1 - - # Activate specific thread exit - export ${test_thread_exit_name}_EXIT=1 - - # Spawn sessiond with preload healthexit lib - export LD_PRELOAD="$CURDIR/$SESSIOND_PRELOAD" - start_lttng_sessiond - - # Cleanup some env. var. - unset LD_PRELOAD - unset ${test_thread_exit_name}_EXIT - - # Check initial health status - $CURDIR/$HEALTH_CHECK_BIN &> /dev/null - - echo -n "Validating thread ${test_thread_exit_name} failure... " - - # Wait - sleep 25 - - # Check health status, exit code should indicate failure - $CURDIR/$HEALTH_CHECK_BIN &> /dev/null - - health_check_exit_code=$? - - if [ $health_check_exit_code -eq $test_thread_exit_code ]; then - print_ok - stop_lttng_sessiond - else - print_fail - echo -e "Health returned: $health_check_exit_code\n" - - stop_lttng_sessiond - return 1 - fi -} - -THREAD=("LTTNG_THREAD_MANAGE_CLIENTS" - "LTTNG_THREAD_MANAGE_APPS" - "LTTNG_THREAD_REG_APPS" - "LTTNG_THREAD_MANAGE_KERNEL") - -# Exit code value to indicate specific thread failure -EXIT_CODE=(1 2 4 8) - -THREAD_COUNT=${#THREAD[@]} -i=0 -while [ "$i" -lt "$THREAD_COUNT" ]; do - test_thread_exit "${THREAD[$i]}" "${EXIT_CODE[$i]}" - - if [ $? -eq 1 ]; then - exit 1 - fi - - let "i++" -done - -# Special case manage consumer, need to spawn consumer via commands. -#"LTTNG_THREAD_MANAGE_CONSUMER" diff --git a/tests/tools/health/health_thread_stall b/tests/tools/health/health_thread_stall deleted file mode 100755 index 5fd39ed6f..000000000 --- a/tests/tools/health/health_thread_stall +++ /dev/null @@ -1,128 +0,0 @@ -#!/bin/bash -# -# Copyright (C) - 2012 Christian Babeux -# -# This program is free software; you can redistribute it and/or modify it -# under the terms of the GNU General Public License, version 2 only, as -# published by the Free Software Foundation. -# -# 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. - -TEST_DESC="Health check - Thread stall" - -CURDIR=$(dirname $0)/ -TESTDIR=$CURDIR/../.. -LTTNG_BIN="lttng" -SESSION_NAME="health_thread_stall" -EVENT_NAME="bogus" -HEALTH_CHECK_BIN="health_check" -SESSIOND_PRELOAD=".libs/libhealthstall.so" - -source $TESTDIR/utils.sh - -print_test_banner "$TEST_DESC" - -if [ ! -f "$CURDIR/$SESSIOND_PRELOAD" ]; then - echo -e "libhealthstall.so not available for this test. Skipping." - exit 0 -fi - -function test_thread_stall -{ - test_thread_stall_name="$1" - test_thread_exit_code="$2" - - echo "" - echo -e "=== Testing health failure with ${test_thread_stall_name}" - - # Activate testpoints - export LTTNG_TESTPOINT_ENABLE=1 - - # Activate specific thread exit - export ${test_thread_stall_name}_STALL=1 - - # Spawn sessiond with preload healthexit lib - export LD_PRELOAD="$CURDIR/$SESSIOND_PRELOAD" - start_lttng_sessiond - - # Cleanup some env. var. - unset LD_PRELOAD - unset ${test_thread_stall_name}_STALL - - # Check initial health status - $CURDIR/$HEALTH_CHECK_BIN &> /dev/null - - echo -n "Validating that ${test_thread_stall_name} is stalled... " - - # Wait - sleep 25 - - # Check health status, exit code should indicate failure - $CURDIR/$HEALTH_CHECK_BIN &> /dev/null - - health_check_exit_code=$? - - if [ $health_check_exit_code -eq $test_thread_exit_code ]; then - print_ok - else - print_fail - echo -e "Health returned: $health_check_exit_code\n" - - stop_lttng_sessiond - return 1 - fi - - echo -n "Validating that ${test_thread_stall_name} is no longer stalled... " - - # Wait - sleep 40 - - # Check health status, exit code should now pass - $CURDIR/$HEALTH_CHECK_BIN &> /dev/null - - health_check_exit_code=$? - - if [ $health_check_exit_code -eq 0 ]; then - print_ok - stop_lttng_sessiond - else - print_fail - echo -e "Health returned: $health_check_exit_code\n" - stop_lttng_sessiond - return 1 - fi - - -} - -THREAD=("LTTNG_THREAD_MANAGE_CLIENTS" - "LTTNG_THREAD_MANAGE_APPS" -# This thread is a little bit tricky to stall, -# need to send some commands and setup an app. -# "LTTNG_THREAD_REG_APPS" - "LTTNG_THREAD_MANAGE_KERNEL") - -# Exit code value to indicate specific thread failure -EXIT_CODE=(1 - 2 -# 4 - 8) - -THREAD_COUNT=${#THREAD[@]} -i=0 -while [ "$i" -lt "$THREAD_COUNT" ]; do - test_thread_stall "${THREAD[$i]}" "${EXIT_CODE[$i]}" - - if [ $? -eq 1 ]; then - exit 1 - fi - - let "i++" -done diff --git a/tests/tools/health/health_tp_fail b/tests/tools/health/health_tp_fail deleted file mode 100755 index 5b68e62be..000000000 --- a/tests/tools/health/health_tp_fail +++ /dev/null @@ -1,98 +0,0 @@ -#!/bin/bash -# -# Copyright (C) - 2012 Christian Babeux -# -# This program is free software; you can redistribute it and/or modify it -# under the terms of the GNU General Public License, version 2 only, as -# published by the Free Software Foundation. -# -# 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. - -TEST_DESC="Health check - Testpoint failure" - -CURDIR=$(dirname $0)/ -TESTDIR=$CURDIR/../.. -LTTNG_BIN="lttng" -SESSION_NAME="health_tp_fail" -EVENT_NAME="bogus" -HEALTH_CHECK_BIN="health_check" -SESSIOND_PRELOAD=".libs/libhealthtpfail.so" - -source $TESTDIR/utils.sh - -print_test_banner "$TEST_DESC" - -if [ ! -f "$CURDIR/$SESSIOND_PRELOAD" ]; then - echo -e "libhealthtpfail.so not available for this test. Skipping." - exit 0 -fi - -function test_tp_fail -{ - test_tp_fail_name="$1" - test_tp_fail_code="$2" - - echo "" - echo -e "=== Testing health failure with ${test_tp_fail_name}" - - # Activate testpoints - export LTTNG_TESTPOINT_ENABLE=1 - - # Activate specific testpoint failure - export ${test_tp_fail_name}_TP_FAIL=1 - - # Spawn sessiond with preload healthexit lib - export LD_PRELOAD="$CURDIR/$SESSIOND_PRELOAD" - start_lttng_sessiond - - # Cleanup some env. var. - unset LD_PRELOAD - unset ${test_tp_fail_name}_TP_FAIL - - echo -n "Validating thread ${test_tp_fail_name} failure... " - - # Check health status, exit code should indicate failure - $CURDIR/$HEALTH_CHECK_BIN &> /dev/null - - health_check_exit_code=$? - - if [ $health_check_exit_code -eq $test_tp_fail_code ]; then - print_ok - stop_lttng_sessiond - else - print_fail - echo -e "Health returned: $health_check_exit_code\n" - - stop_lttng_sessiond - return 1 - fi -} - -THREAD=("LTTNG_THREAD_MANAGE_CLIENTS" - "LTTNG_THREAD_MANAGE_APPS" - "LTTNG_THREAD_MANAGE_KERNEL") - -# Exit code value to indicate specific thread failure -EXIT_CODE=(1 2 8) - -THREAD_COUNT=${#THREAD[@]} -i=0 -while [ "$i" -lt "$THREAD_COUNT" ]; do - test_tp_fail "${THREAD[$i]}" "${EXIT_CODE[$i]}" - - if [ $? -eq 1 ]; then - exit 1 - fi - - let "i++" -done - -# Special case manage consumer, need to spawn consumer via commands. -#"LTTNG_THREAD_MANAGE_CONSUMER" diff --git a/tests/tools/health/runall b/tests/tools/health/runall deleted file mode 100755 index d1c8b3446..000000000 --- a/tests/tools/health/runall +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/bash - -DIR=$(dirname $0) - -tests=( $DIR/health_thread_exit $DIR/health_thread_stall $DIR/health_tp_fail) -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 -} - -if [ "$(id -u)" != "0" ]; then - echo -e "Need root for health test." - exit 0 -fi - -start_tests - -exit $exit_code diff --git a/tests/tools/runall.sh b/tests/tools/runall.sh deleted file mode 100755 index b2be91c6c..000000000 --- a/tests/tools/runall.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/bash - -DIR=$(dirname $0) - -tests=( $DIR/test_kernel_data_trace $DIR/test_sessions $DIR/test_ust_data_trace \ - $DIR/streaming/runall $DIR/health/runall $DIR/filtering/runall) - -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/Makefile.am b/tests/tools/streaming/Makefile.am deleted file mode 100644 index 3ff8ef0a1..000000000 --- a/tests/tools/streaming/Makefile.am +++ /dev/null @@ -1,27 +0,0 @@ -AM_CFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/src -I$(top_srcdir)/tests -I$(srcdir) -O2 -g -AM_LDFLAGS = - -if LTTNG_TOOLS_BUILD_WITH_LIBDL -AM_LDFLAGS += -ldl -endif -if LTTNG_TOOLS_BUILD_WITH_LIBC_DL -AM_LDFLAGS += -lc -endif - -#UTILS=../../utils.h -UTILS= -LIBSESSIOND_COMM=$(top_builddir)/src/common/sessiond-comm/libsessiond-comm.la -LIBCOMMON=$(top_builddir)/src/common/libcommon.la - -noinst_PROGRAMS = unit_tests -unit_tests_SOURCES = unit_tests.c $(UTILS) -unit_tests_LDADD = $(LIBCOMMON) - -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 = runall run-ust run-kernel uri_switch -EXTRA_DIST = runall run-ust run-kernel uri_switch diff --git a/tests/tools/streaming/gen-ust-events.c b/tests/tools/streaming/gen-ust-events.c deleted file mode 100644 index 1385119d7..000000000 --- a/tests/tools/streaming/gen-ust-events.c +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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/high_throughput_limits b/tests/tools/streaming/high_throughput_limits deleted file mode 100755 index ebe5020a6..000000000 --- a/tests/tools/streaming/high_throughput_limits +++ /dev/null @@ -1,200 +0,0 @@ -#!/bin/bash -# -# Copyright (C) - 2012 Christian Babeux -# 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 - -TEST_DESC="Streaming - High throughput with bandwidth limits" - -CURDIR=$(dirname $0)/ -TESTDIR=$CURDIR/../.. -NR_APP_ITER=10 -NR_ITER=1000000 -BIN_NAME="gen-ust-events" -SESSION_NAME="high-throughput" -EVENT_NAME="tp:tptest" -SESSIOND_CTRL_PORT=5342 -SESSIOND_DATA_PORT=5343 -DEFAULT_IF="lo" - -TRACE_PATH=$(mktemp -d) - -source $TESTDIR/utils.sh - -print_test_banner "$TEST_DESC" - -if [ ! -x "$CURDIR/$BIN_NAME" ]; then - echo -e "No UST nevents binary detected. Passing." - exit 0 -fi - -if [ "$(id -u)" != "0" ]; then - echo "This test must be running as root to set bandwidth limits. Aborting" - # Exit status 0 so the tests can continue - exit 0 -fi - -function set_bw_limit -{ - limit=$1 - ctrlportlimit=$(($limit/10)) - # failsafe to have at least 1kbit/s for control (in the case where $1 < 10) - [ $ctrlportlimit = 0 ] && ctrlportlimit=1 - # if $1 < 10, we might bust the limit set here, but the - # parent qdisc (1:) will always limit us to the right max value - dataportlimit=$((9*${ctrlportlimit})) - - echo -n "Setting bandwidth limits to ${limit}kbits, (${ctrlportlimit} for control and ${dataportlimit} for data)... " - tc qdisc add dev $DEFAULT_IF root handle 1: htb default 15 >/dev/null 2>&1 - - # the total bandwidth is the limit set by the user - tc class add dev $DEFAULT_IF parent 1: classid 1:1 htb rate ${limit}kbit ceil ${limit}kbit >/dev/null 2>&1 - # 1/10 of the bandwidth guaranteed and traffic prioritized for the control port - tc class add dev $DEFAULT_IF parent 1:1 classid 1:10 htb rate ${ctrlportlimit}kbit ceil ${limit}kbit prio 1 >/dev/null 2>&1 - # 9/10 of the bandwidth guaranteed and can borrow up to the total bandwidth (if unused) - tc class add dev $DEFAULT_IF parent 1:1 classid 1:11 htb rate ${dataportlimit}kbit ceil ${limit}kbit prio 2 >/dev/null 2>&1 - - # filter to assign control traffic to the 1:10 class - tc filter add dev $DEFAULT_IF parent 1: protocol ip u32 match ip dport $SESSIOND_CTRL_PORT 0xffff flowid 1:10 >/dev/null 2>&1 - # filter to assign data traffic to the 1:11 class - tc filter add dev $DEFAULT_IF parent 1: protocol ip u32 match ip dport $SESSIOND_DATA_PORT 0xffff flowid 1:11 >/dev/null 2>&1 - print_ok -} - -function reset_bw_limit -{ - echo -n "Resetting bandwidth limits... " - tc qdisc del dev $DEFAULT_IF root >/dev/null 2>&1 - print_ok -} - -function create_lttng_session_with_uri -{ - sess_name=$1 - uri=$2 - # Create session with custom URI - $TESTDIR/../src/bin/lttng/$LTTNG_BIN create -U $uri $sess_name >/dev/null 2>&1 -} - -function enable_lttng_consumer -{ - uri=$1 - # Create session with custom URI - $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-consumer -u $uri >/dev/null 2>&1 -} - -function run_apps -{ - for i in `seq 1 $NR_APP_ITER`; do - # With bandwidth limitation, unfortunately, application easily timeout - # due to very slow communication between the consumer and relayd making - # the status reply from the consumer quite slow thus delaying the - # registration done message. - LTTNG_UST_REGISTER_TIMEOUT=-1 ./$CURDIR/$BIN_NAME $NR_ITER & >/dev/null 2>&1 - done -} - -function wait_apps -{ - echo "Waiting for applications to end" - while [ -n "$(pidof $BIN_NAME)" ]; do - echo -n "." - sleep 1 - done - echo "" -} - -function test_high_throughput -{ - NETWORK_URI="net://localhost" - create_lttng_session_with_uri $SESSION_NAME $NETWORK_URI - enable_lttng_consumer $NETWORK_URI - enable_ust_lttng_event $SESSION_NAME $EVENT_NAME - start_lttng_tracing $SESSION_NAME - run_apps - wait_apps - - stop_lttng_tracing $SESSION_NAME - destroy_lttng_session $SESSION_NAME - validate_event_count -} - -function validate_event_count -{ - - TEMP_FILE=$(mktemp) - TEMP_FILE_2=$(mktemp) - - traced=$(babeltrace $TRACE_PATH 2>/dev/null | wc -l) - babeltrace $TRACE_PATH >/dev/null 2>$TEMP_FILE_2 - - cat $TEMP_FILE_2 | cut -f4 -d " " >$TEMP_FILE - - dropped=0 - while read line; - do - let dropped=$dropped+$line - done < $TEMP_FILE - - let total=$dropped+$traced - let wanted=$NR_APP_ITER*$NR_ITER - - if [ $wanted -ne $total ]; then - echo -n "Expected $wanted. Dropped $dropped. Recorded $traced. Total $total... " - print_fail - return 1 - else - echo -n "Expected $wanted. Dropped $dropped. Recorded $traced. Total $total... " - print_ok - - # Cleanup only if everything is ok and passes. - rm -rf $TRACE_PATH - rm $TEMP_FILE $TEMP_FILE_2 - - return 0 - fi -} - -function interrupt_cleanup() -{ - echo -en "\n*** Exiting ***\n" - stop_lttng_relayd - stop_lttng_sessiond - reset_bw_limit - exit 1 -} - -# Catch sigint and try to cleanup limits -trap interrupt_cleanup SIGINT - -BW_LIMITS=(3200 1600 800 400 200 100 50 25) -for BW in ${BW_LIMITS[@]}; -do - echo "" - echo -e "=== Testing high-throughput with bandwidth limit set to ${BW}kbits" - set_bw_limit $BW - - start_lttng_sessiond - start_lttng_relayd "-o $TRACE_PATH" - test_high_throughput - result=$? - stop_lttng_relayd - stop_lttng_sessiond - reset_bw_limit - - if [ $result -ne 0 ]; then - exit 1 - fi -done diff --git a/tests/tools/streaming/run-kernel b/tests/tools/streaming/run-kernel deleted file mode 100755 index 545cae7c8..000000000 --- a/tests/tools/streaming/run-kernel +++ /dev/null @@ -1,119 +0,0 @@ -#!/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 -TEST_DESC="Streaming - Kernel tracing" - -CURDIR=$(dirname $0)/ -TESTDIR=$CURDIR/../.. -EVENT_NAME="sched_switch" -PID_RELAYD=0 -SESSION_NAME="" - -TRACE_PATH=$(mktemp -d) - -source $TESTDIR/utils.sh - -print_test_banner "$TEST_DESC" - -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_uri -{ - echo -n "Creating session $SESSION_NAME... " - # Create session with default path - $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $SESSION_NAME -U net://localhost >/dev/null 2>&1 - if [ $? -eq 1 ]; then - print_fail - return 1 - else - print_ok - fi -} - -function test_kernel_before_start () -{ - echo -e "\n=== Testing kernel streaming with event enable BEFORE start\n" - lttng_create_session_uri - lttng_enable_kernel_event $SESSION_NAME $EVENT_NAME - start_lttng_tracing $SESSION_NAME - # Give a second - sleep 1 - stop_lttng_tracing $SESSION_NAME - destroy_lttng_session $SESSION_NAME - - # We can not predict _yet_ when the trace is available so we have to do a - # arbitratry sleep to validate the trace. - echo -n "Waiting 3 seconds for the trace to be written on disk " - for i in `seq 1 3`; do - echo -n "." - sleep 1 - done - echo "" -} - -# Deactivated since this feature is not yet available where we can enable -# an event AFTERE tracing has started. -function test_kernel_after_start () -{ - echo -e "\n=== Testing kernel streaming with event enable AFTER start\n" - lttng_create_session_uri - start_lttng_tracing $SESSION_NAME - lttng_enable_kernel_event $SESSION_NAME $EVENT_NAME - # Give a second - sleep 1 - stop_lttng_tracing $SESSION_NAME - destroy_lttng_session $SESSION_NAME -} - -start_lttng_sessiond -start_lttng_relayd "-o $TRACE_PATH" - -tests=( test_kernel_before_start ) - -for fct_test in ${tests[@]}; -do - SESSION_NAME=$(randstring 16 0) - ${fct_test} - - # Validate test - validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/$SESSION_NAME* - if [ $? -eq 0 ]; then - # Only delete if successful - rm -rf $TRACE_PATH - else - break - fi -done - -echo "" -stop_lttng_sessiond -stop_lttng_relayd - - -exit $out diff --git a/tests/tools/streaming/run-ust b/tests/tools/streaming/run-ust deleted file mode 100755 index 28b72f824..000000000 --- a/tests/tools/streaming/run-ust +++ /dev/null @@ -1,110 +0,0 @@ -#!/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 -TEST_DESC="Streaming - User space tracing" - -CURDIR=$(dirname $0)/ -TESTDIR=$CURDIR/../.. -BIN_NAME="gen-ust-events" -SESSION_NAME="stream" -EVENT_NAME="tp:tptest" -PID_RELAYD=0 - -TRACE_PATH=$(mktemp -d) - -source $TESTDIR/utils.sh - -print_test_banner "$TEST_DESC" - -if [ ! -x "$CURDIR/$BIN_NAME" ]; then - echo -e "No UST nevents binary detected. Passing." - exit 0 -fi - -function lttng_create_session_uri -{ - # Create session with default path - $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $SESSION_NAME -U net://localhost >/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_uri - 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_lttng_tracing $SESSION_NAME - - wait_apps - stop_lttng_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_uri - enable_ust_lttng_event $SESSION_NAME $EVENT_NAME - start_lttng_tracing $SESSION_NAME - - # Run 5 times with a 1 second delay - ./$CURDIR/$BIN_NAME 5 1000000 >/dev/null 2>&1 & - - wait_apps - stop_lttng_tracing $SESSION_NAME - destroy_lttng_session $SESSION_NAME -} - -start_lttng_sessiond -start_lttng_relayd "-o $TRACE_PATH" - -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 $TRACE_PATH/$HOSTNAME/$SESSION_NAME* - if [ $? -eq 0 ]; then - # Only delete if successful - rm -rf $TRACE_PATH - else - break - fi -done - -echo "" -stop_lttng_sessiond -stop_lttng_relayd - -exit $out diff --git a/tests/tools/streaming/runall b/tests/tools/streaming/runall deleted file mode 100755 index dbf5228ce..000000000 --- a/tests/tools/streaming/runall +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/bash - -DIR=$(dirname $0) - -tests=( $DIR/unit_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/tp.c b/tests/tools/streaming/tp.c deleted file mode 100644 index a09561d70..000000000 --- a/tests/tools/streaming/tp.c +++ /dev/null @@ -1,15 +0,0 @@ -/* - * 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 deleted file mode 100644 index 6ffbc32ab..000000000 --- a/tests/tools/streaming/tp.h +++ /dev/null @@ -1,56 +0,0 @@ -#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/tools/streaming/unit_tests.c b/tests/tools/streaming/unit_tests.c deleted file mode 100644 index d00e34d16..000000000 --- a/tests/tools/streaming/unit_tests.c +++ /dev/null @@ -1,252 +0,0 @@ -/* - * Copyright (C) - 2012 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 - -#include -#include - -#include "utils.h" - -/* This path will NEVER be created in this test */ -#define PATH1 "tmp/.test-junk-lttng" - -#define RANDOM_STRING_LEN 16 - -/* For lttngerr.h */ -int lttng_opt_quiet = 1; -int lttng_opt_verbose = 3; - -/* - * Test string URI and if uri_parse works well. - */ -void test_uri_parsing(void) -{ - ssize_t size; - const char *s_uri1; - struct lttng_uri *uri; - - fprintf(stdout, "Testing URIs...\n"); - - s_uri1 = "net://localhost"; - fprintf(stdout, " [+] URI set to %s ", s_uri1); - size = uri_parse(s_uri1, &uri); - assert(size == 2); - assert(uri[0].dtype == LTTNG_DST_IPV4); - assert(uri[0].utype == LTTNG_URI_DST); - assert(uri[0].stype == 0); - assert(uri[0].port == 0); - assert(strlen(uri[0].subdir) == 0); - assert(strcmp(uri[0].dst.ipv4, "127.0.0.1") == 0); - - assert(uri[1].dtype == LTTNG_DST_IPV4); - assert(uri[1].utype == LTTNG_URI_DST); - assert(uri[1].stype == 0); - assert(uri[1].port == 0); - assert(strlen(uri[1].subdir) == 0); - assert(strcmp(uri[1].dst.ipv4, "127.0.0.1") == 0); - PRINT_OK(); - uri_free(uri); - - s_uri1 = "net://localhost:8989:4242/my/test/path"; - fprintf(stdout, " [+] URI set to %s ", s_uri1); - size = uri_parse(s_uri1, &uri); - assert(size == 2); - assert(uri[0].dtype == LTTNG_DST_IPV4); - assert(uri[0].utype == LTTNG_URI_DST); - assert(uri[0].stype == 0); - assert(uri[0].port == 8989); - assert(strcmp(uri[0].subdir, "my/test/path") == 0); - assert(strcmp(uri[0].dst.ipv4, "127.0.0.1") == 0); - - assert(uri[1].dtype == LTTNG_DST_IPV4); - assert(uri[1].utype == LTTNG_URI_DST); - assert(uri[1].stype == 0); - assert(uri[1].port == 4242); - assert(strcmp(uri[0].subdir, "my/test/path") == 0); - assert(strcmp(uri[1].dst.ipv4, "127.0.0.1") == 0); - PRINT_OK(); - uri_free(uri); - - s_uri1 = "net://localhost:8989:4242"; - fprintf(stdout, " [+] URI set to %s ", s_uri1); - size = uri_parse(s_uri1, &uri); - assert(size == 2); - assert(uri[0].dtype == LTTNG_DST_IPV4); - assert(uri[0].utype == LTTNG_URI_DST); - assert(uri[0].stype == 0); - assert(uri[0].port == 8989); - assert(strlen(uri[1].subdir) == 0); - assert(strcmp(uri[0].dst.ipv4, "127.0.0.1") == 0); - - assert(uri[1].dtype == LTTNG_DST_IPV4); - assert(uri[1].utype == LTTNG_URI_DST); - assert(uri[1].stype == 0); - assert(uri[1].port == 4242); - assert(strlen(uri[1].subdir) == 0); - assert(strcmp(uri[1].dst.ipv4, "127.0.0.1") == 0); - PRINT_OK(); - uri_free(uri); - - s_uri1 = "net6://localhost:8989"; - fprintf(stdout, " [+] URI set to %s ", s_uri1); - size = uri_parse(s_uri1, &uri); - assert(size == 2); - assert(uri[0].dtype == LTTNG_DST_IPV6); - assert(uri[0].utype == LTTNG_URI_DST); - assert(uri[0].stype == 0); - assert(uri[0].port == 8989); - assert(strlen(uri[1].subdir) == 0); - assert(strcmp(uri[0].dst.ipv6, "::1") == 0); - - assert(uri[1].dtype == LTTNG_DST_IPV6); - assert(uri[1].utype == LTTNG_URI_DST); - assert(uri[1].stype == 0); - assert(uri[1].port == 0); - assert(strlen(uri[1].subdir) == 0); - assert(strcmp(uri[0].dst.ipv6, "::1") == 0); - PRINT_OK(); - uri_free(uri); - - s_uri1 = "tcp://42.42.42.42/my/test/path"; - fprintf(stdout, " [+] URI set to %s ", s_uri1); - size = uri_parse(s_uri1, &uri); - assert(size == 1); - assert(uri[0].dtype == LTTNG_DST_IPV4); - assert(uri[0].utype == LTTNG_URI_DST); - assert(uri[0].stype == 0); - assert(uri[0].port == 0); - assert(strcmp(uri[0].subdir, "my/test/path") == 0); - assert(strcmp(uri[0].dst.ipv4, "42.42.42.42") == 0); - PRINT_OK(); - uri_free(uri); - - s_uri1 = "tcp6://[fe80::f66d:4ff:fe53:d220]/my/test/path"; - fprintf(stdout, " [+] URI set to %s ", s_uri1); - size = uri_parse(s_uri1, &uri); - assert(size == 1); - assert(uri[0].dtype == LTTNG_DST_IPV6); - assert(uri[0].utype == LTTNG_URI_DST); - assert(uri[0].stype == 0); - assert(uri[0].port == 0); - assert(strcmp(uri[0].subdir, "my/test/path") == 0); - assert(strcmp(uri[0].dst.ipv6, "fe80::f66d:4ff:fe53:d220") == 0); - PRINT_OK(); - uri_free(uri); - - s_uri1 = "file:///my/test/path"; - fprintf(stdout, " [+] URI set to %s ", s_uri1); - size = uri_parse(s_uri1, &uri); - assert(size == 1); - assert(uri[0].dtype == LTTNG_DST_PATH); - assert(uri[0].utype == LTTNG_URI_DST); - assert(uri[0].stype == 0); - assert(uri[0].port == 0); - assert(strlen(uri[0].subdir) == 0); - assert(strcmp(uri[0].dst.path, "/my/test/path") == 0); - PRINT_OK(); - uri_free(uri); - - s_uri1 = "file/my/test/path"; - fprintf(stdout, " [+] Bad URI set to %s ", s_uri1); - size = uri_parse(s_uri1, &uri); - assert(size == -1); - PRINT_OK(); - - s_uri1 = "net://:8999"; - fprintf(stdout, " [+] Bad URI set to %s ", s_uri1); - size = uri_parse(s_uri1, &uri); - assert(size == -1); - PRINT_OK(); -} - -void test_uri_cmp() -{ - struct lttng_uri *uri1, *uri2; - const char *s_uri1 = "net://localhost"; - const char *s_uri2 = "net://localhost:8989:4242"; - ssize_t size1, size2; - int res; - - size1 = uri_parse(s_uri1, &uri1); - - /* Sanity checks */ - assert(size1 == 2); - assert(uri1[0].dtype == LTTNG_DST_IPV4); - assert(uri1[0].utype == LTTNG_URI_DST); - assert(uri1[0].stype == 0); - assert(uri1[0].port == 0); - assert(strlen(uri1[0].subdir) == 0); - assert(strcmp(uri1[0].dst.ipv4, "127.0.0.1") == 0); - assert(uri1[1].dtype == LTTNG_DST_IPV4); - assert(uri1[1].utype == LTTNG_URI_DST); - assert(uri1[1].stype == 0); - assert(uri1[1].port == 0); - assert(strlen(uri1[1].subdir) == 0); - assert(strcmp(uri1[1].dst.ipv4, "127.0.0.1") == 0); - - size2 = uri_parse(s_uri2, &uri2); - - assert(size2 == 2); - assert(uri2[0].dtype == LTTNG_DST_IPV4); - assert(uri2[0].utype == LTTNG_URI_DST); - assert(uri2[0].stype == 0); - assert(uri2[0].port == 8989); - assert(strlen(uri2[1].subdir) == 0); - assert(strcmp(uri2[0].dst.ipv4, "127.0.0.1") == 0); - assert(uri2[1].dtype == LTTNG_DST_IPV4); - assert(uri2[1].utype == LTTNG_URI_DST); - assert(uri2[1].stype == 0); - assert(uri2[1].port == 4242); - assert(strlen(uri2[1].subdir) == 0); - assert(strcmp(uri2[1].dst.ipv4, "127.0.0.1") == 0); - - - res = uri_compare(uri1, uri1); - fprintf(stdout, " [+] %s == %s ", s_uri1, s_uri1); - assert(res == 0); - PRINT_OK(); - - res = uri_compare(uri1, uri2); - fprintf(stdout, " [+] %s != %s ", s_uri1, s_uri2); - assert(res != 0); - PRINT_OK(); - - uri_free(uri1); - uri_free(uri2); -} - -int main(int argc, char **argv) -{ - srand(time(NULL)); - - printf("\nStreaming unit tests\n-----------\n"); - - /* URI tests */ - test_uri_parsing(); - test_uri_cmp(); - - return 0; -} diff --git a/tests/tools/streaming/uri_switch b/tests/tools/streaming/uri_switch deleted file mode 100755 index 4eb435983..000000000 --- a/tests/tools/streaming/uri_switch +++ /dev/null @@ -1,217 +0,0 @@ -#!/bin/bash -# -# Copyright (C) - 2012 Christian Babeux -# 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 -TEST_DESC="Streaming - URI switching" - -CURDIR=$(dirname $0)/ -TESTDIR=$CURDIR/../.. -BIN_NAME="gen-ust-events" -SESSION_NAME="stream" -EVENT_NAME="tp:tptest" -PID_RELAYD=0 - -TRACE_PATH=$(mktemp -d) - -source $TESTDIR/utils.sh - -print_test_banner "$TEST_DESC" - -if [ ! -x "$CURDIR/$BIN_NAME" ]; then - echo -e "No UST nevents binary detected. Skipping." - exit 0 -fi - -function lttng_create_session -{ - URI=$1 - # Create session with custom URI - $TESTDIR/../src/bin/lttng/$LTTNG_BIN create -U $URI $SESSION_NAME >/dev/null 2>&1 -} - -function lttng_enable_consumer -{ - URI=$1 - # Create session with custom URI - $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-consumer -u $URI >/dev/null 2>&1 -} - -function run_apps -{ - # Run 5 times with a 1 second delay - COUNT=5 - APP_DELAY=1000000 - ./$CURDIR/$BIN_NAME $COUNT $APP_DELAY >/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 "" -} - -function test_uri_switch_localhost_folder -{ - IPVER=$1 - echo -e "\n=== Testing switch of localhost folder ($IPVER)\n" - - if [ "$IPVER" == "IPv6" ]; then - BASE_URI="net6://localhost" - else - BASE_URI="net://localhost" - fi - - RANDCOUNT=10 - RAND="" - i=1 - - lttng_create_session $BASE_URI - - echo -e "Randomizing output folder on $BASE_URI..." - while [ "$i" -le $RANDCOUNT ] - do - RAND=$(randstring 16 0) - lttng_enable_consumer "$BASE_URI/$RAND" - let "i += 1" - done - - enable_ust_lttng_event $SESSION_NAME $EVENT_NAME - start_lttng_tracing $SESSION_NAME - run_apps - wait_apps - stop_lttng_tracing $SESSION_NAME - destroy_lttng_session $SESSION_NAME - validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/$RAND - - if [ $? -eq 0 ]; then - # Only delete if successful - rm -rf $TRACE_PATH - fi -} - -function test_uri_switch_file_network -{ - IPVER=$1 - echo "" - echo -e "=== Testing switch file -> network ($IPVER)" - - TMP_PATH=$(mktemp -d) - FILE_URI="file://$TMP_PATH" - - if [ "$IPVER" == "IPv6" ]; then - NETWORK_URIS=("net6://localhost" "net6://[::1]") - else - NETWORK_URIS=("net://localhost" "net://127.0.0.1") - fi - - NET_PATHS=("foo/bar" "OohEehOohAhAahTingTangWallaWallaBingBang" ".") - - for NETWORK_URI in ${NETWORK_URIS[@]}; - do - for NET_PATH in ${NET_PATHS[@]}; - do - SESSION_NAME=$(randstring 16 0) - echo "" - echo "$FILE_URI -> $NETWORK_URI/$NET_PATH" - - lttng_create_session $FILE_URI - lttng_enable_consumer "$NETWORK_URI/$NET_PATH" - enable_ust_lttng_event $SESSION_NAME $EVENT_NAME - start_lttng_tracing $SESSION_NAME - run_apps - wait_apps - stop_lttng_tracing $SESSION_NAME - destroy_lttng_session $SESSION_NAME - validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/$NET_PATH - - if [ $? -eq 0 ]; then - # Only delete if successful - rm -rf $TRACE_PATH - else - break - fi - done - done - rm -rf $TMP_PATH -} - -function test_uri_switch_network_file -{ -IPVER=$1 - echo "" - echo -e "=== Testing switch network ($IPVER) -> file" - - if [ "$IPVER" == "IPv6" ]; then - NETWORK_URI="net6://localhost" - else - NETWORK_URI="net://localhost" - fi - - FILE_PATHS=("." "foo/bar" "42") - - for FILE_PATH in ${FILE_PATHS[@]}; - do - TMP_PATH=$(mktemp -d) - FILE_URI="file://$TMP_PATH" - SESSION_NAME=$(randstring 16 0) - - echo "" - echo "$NETWORK_URI -> $FILE_URI/$FILE_PATH" - - lttng_create_session $NETWORK_URI - lttng_enable_consumer "$FILE_URI/$FILE_PATH" - enable_ust_lttng_event $SESSION_NAME $EVENT_NAME - start_lttng_tracing $SESSION_NAME - run_apps - wait_apps - stop_lttng_tracing $SESSION_NAME - destroy_lttng_session $SESSION_NAME - validate_trace $EVENT_NAME $TMP_PATH/$FILE_PATH - - if [ $? -eq 0 ]; then - # Only delete if successful - rm -rf $TMP_PATH - else - break - fi - done -} - - -start_lttng_sessiond - -echo "" -echo "=== Testing with IPv4" -start_lttng_relayd "-o $TRACE_PATH" -test_uri_switch_localhost_folder "IPv4" -test_uri_switch_file_network "IPv4" -test_uri_switch_network_file "IPv4" -stop_lttng_relayd - -echo "" -echo "=== Testing with IPv6" -start_lttng_relayd "-o $TRACE_PATH -C tcp6://localhost:5342 -D tcp6://localhost:5343" -test_uri_switch_localhost_folder "IPv6" -test_uri_switch_file_network "IPv6" -test_uri_switch_network_file "IPv6" -stop_lttng_relayd - -stop_lttng_sessiond diff --git a/tests/tools/test_kernel_data_trace.c b/tests/tools/test_kernel_data_trace.c deleted file mode 100644 index 70d71cadb..000000000 --- a/tests/tools/test_kernel_data_trace.c +++ /dev/null @@ -1,203 +0,0 @@ -/* - * 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 -#include - -#include "utils.h" - -/* This path will NEVER be created in this test */ -#define PATH1 "/tmp/.test-junk-lttng" - -#define RANDOM_STRING_LEN 11 - -/* For lttngerr.h */ -int lttng_opt_quiet = 1; -int lttng_opt_verbose; - -static const char alphanum[] = - "0123456789" - "ABCDEFGHIJKLMNOPQRSTUVWXYZ" - "abcdefghijklmnopqrstuvwxyz"; - -static struct ltt_kernel_session *kern; -static char random_string[RANDOM_STRING_LEN]; - -/* - * Return random string of 10 characters. - * Not thread-safe. - */ -static char *get_random_string(void) -{ - int i; - - for (i = 0; i < RANDOM_STRING_LEN - 1; i++) { - random_string[i] = alphanum[rand() % (sizeof(alphanum) - 1)]; - } - - random_string[RANDOM_STRING_LEN - 1] = '\0'; - - return random_string; -} - -static void create_one_kernel_session(void) -{ - printf("Create kernel session: "); - kern = trace_kernel_create_session(PATH1); - assert(kern != NULL); - PRINT_OK(); - - printf("Validating kernel session: "); - assert(kern->fd == -1); - assert(kern->metadata_stream_fd == -1); - assert(kern->consumer_fds_sent == 0); - assert(kern->channel_count == 0); - assert(kern->stream_count_global == 0); - assert(kern->metadata == NULL); - PRINT_OK(); - - /* Init list in order to avoid sefaults from cds_list_del */ - trace_kernel_destroy_session(kern); -} - -static void create_kernel_metadata(void) -{ - assert(kern != NULL); - - printf("Create kernel metadata: "); - kern->metadata = trace_kernel_create_metadata(); - assert(kern->metadata != NULL); - PRINT_OK(); - - printf("Validating kernel session metadata: "); - assert(kern->metadata->fd == -1); - assert(kern->metadata->conf != NULL); - assert(kern->metadata->conf->attr.overwrite - == DEFAULT_CHANNEL_OVERWRITE); - assert(kern->metadata->conf->attr.subbuf_size - == default_get_metadata_subbuf_size()); - assert(kern->metadata->conf->attr.num_subbuf - == DEFAULT_METADATA_SUBBUF_NUM); - assert(kern->metadata->conf->attr.switch_timer_interval - == DEFAULT_CHANNEL_SWITCH_TIMER); - assert(kern->metadata->conf->attr.read_timer_interval - == DEFAULT_CHANNEL_READ_TIMER); - assert(kern->metadata->conf->attr.output - == DEFAULT_KERNEL_CHANNEL_OUTPUT); - PRINT_OK(); - - trace_kernel_destroy_metadata(kern->metadata); -} - -static void create_kernel_channel(void) -{ - struct ltt_kernel_channel *chan; - struct lttng_channel attr; - - memset(&attr, 0, sizeof(attr)); - - printf("Creating kernel channel: "); - chan = trace_kernel_create_channel(&attr); - assert(chan != NULL); - PRINT_OK(); - - printf("Validating kernel channel: "); - assert(chan->fd == -1); - assert(chan->enabled == 1); - assert(chan->stream_count == 0); - assert(chan->ctx == NULL); - assert(chan->channel->attr.overwrite == attr.attr.overwrite); - PRINT_OK(); - - /* Init list in order to avoid sefaults from cds_list_del */ - CDS_INIT_LIST_HEAD(&chan->list); - trace_kernel_destroy_channel(chan); -} - -static void create_kernel_event(void) -{ - struct ltt_kernel_event *event; - struct lttng_event ev; - - memset(&ev, 0, sizeof(ev)); - strncpy(ev.name, get_random_string(), LTTNG_KERNEL_SYM_NAME_LEN); - ev.type = LTTNG_EVENT_TRACEPOINT; - ev.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL; - - printf("Creating kernel event: "); - event = trace_kernel_create_event(&ev); - assert(event != NULL); - PRINT_OK(); - - printf("Validating kernel event: "); - assert(event->fd == -1); - assert(event->enabled == 1); - assert(event->event->instrumentation == LTTNG_KERNEL_TRACEPOINT); - assert(strlen(event->event->name)); - PRINT_OK(); - - /* Init list in order to avoid sefaults from cds_list_del */ - CDS_INIT_LIST_HEAD(&event->list); - trace_kernel_destroy_event(event); -} - -static void create_kernel_stream(void) -{ - struct ltt_kernel_stream *stream; - - printf("Creating kernel stream: "); - stream = trace_kernel_create_stream("stream1", 0); - assert(stream != NULL); - PRINT_OK(); - - printf("Validating kernel stream: "); - assert(stream->fd == -1); - assert(stream->state == 0); - PRINT_OK(); - - /* Init list in order to avoid sefaults from cds_list_del */ - CDS_INIT_LIST_HEAD(&stream->list); - trace_kernel_destroy_stream(stream); -} - -int main(int argc, char **argv) -{ - printf("\nTesting kernel data structures:\n-----------\n"); - - create_one_kernel_session(); - - create_kernel_metadata(); - create_kernel_channel(); - - - create_kernel_event(); - - create_kernel_stream(); - - /* Success */ - return 0; -} diff --git a/tests/tools/test_sessions.c b/tests/tools/test_sessions.c deleted file mode 100644 index a6d76c73d..000000000 --- a/tests/tools/test_sessions.c +++ /dev/null @@ -1,330 +0,0 @@ -/* - * 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 - -#include -#include -#include - -#include "utils.h" - -#define SESSION1 "test1" - -/* This path will NEVER be created in this test */ -#define PATH1 "/tmp/.test-junk-lttng" - -#define MAX_SESSIONS 10000 -#define RANDOM_STRING_LEN 11 - -/* - * String of 263 caracters. NAME_MAX + "OVERFLOW". If OVERFLOW appears in the - * session name, we have a problem. - * - * NAME_MAX = 255 - */ -#define OVERFLOW_SESSION_NAME \ - "abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd" \ - "abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd" \ - "abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd" \ - "abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabc" \ - "OVERFLOW" - -static struct ltt_session_list *session_list; - -/* For lttngerr.h */ -int lttng_opt_quiet = 1; -int lttng_opt_verbose = 0; - -static const char alphanum[] = - "0123456789" - "ABCDEFGHIJKLMNOPQRSTUVWXYZ" - "abcdefghijklmnopqrstuvwxyz"; -static char random_string[RANDOM_STRING_LEN]; - -/* - * Return random string of 10 characters. - * Not thread-safe. - */ -static char *get_random_string(void) -{ - int i; - - for (i = 0; i < RANDOM_STRING_LEN - 1; i++) { - random_string[i] = alphanum[rand() % (sizeof(alphanum) - 1)]; - } - - random_string[RANDOM_STRING_LEN - 1] = '\0'; - - return random_string; -} - -/* - * Return 0 if session name is found, else -1 - */ -static int find_session_name(char *name) -{ - struct ltt_session *iter; - - cds_list_for_each_entry(iter, &session_list->head, list) { - if (strcmp(iter->name, name) == 0) { - return 0; - } - } - - return -1; -} - -static int session_list_count(void) -{ - int count = 0; - struct ltt_session *iter; - - cds_list_for_each_entry(iter, &session_list->head, list) { - count++; - } - return count; -} - -/* - * Empty session list manually. - */ -static void empty_session_list(void) -{ - struct ltt_session *iter, *tmp; - - cds_list_for_each_entry_safe(iter, tmp, &session_list->head, list) { - cds_list_del(&iter->list); - free(iter); - } - - /* Session list must be 0 */ - assert(!session_list_count()); -} - -/* - * Test creation of 1 session - */ -static int create_one_session(char *name, char *path) -{ - int ret; - - ret = session_create(name, path, geteuid(), getegid()); - if (ret == LTTNG_OK) { - /* Validate */ - ret = find_session_name(name); - if (ret < 0) { - /* Session not found by name */ - printf("session not found after creation\n"); - return -1; - } else { - /* Success */ - return 0; - } - } else { - if (ret == LTTNG_ERR_EXIST_SESS) { - printf("(session already exists) "); - } - return -1; - } - - return 0; -} - -/* - * Test deletion of 1 session - */ -static int destroy_one_session(struct ltt_session *session) -{ - int ret; - - ret = session_destroy(session); - - if (ret == LTTNG_OK) { - /* Validate */ - if (session == NULL) { - return 0; - } - ret = find_session_name(session->name); - if (ret < 0) { - /* Success, -1 means that the sesion is NOT found */ - return 0; - } else { - /* Fail */ - return -1; - } - } - - return 0; -} - -static int fuzzing_create_args(void) -{ - int ret; - - ret = create_one_session(NULL, NULL); - if (ret > 0) { - printf("Session created with (null),(null)\n"); - return -1; - } - - ret = create_one_session(NULL, PATH1); - if (ret > 0) { - printf("Session created with (null), %s)\n", PATH1); - return -1; - } - - /* Session list must be 0 */ - assert(!session_list_count()); - - return 0; -} - -/* - * This test is supposed to fail at the second create call. If so, return 0 for - * test success, else -1. - */ -static int two_session_same_name(void) -{ - int ret; - struct ltt_session *sess; - - ret = create_one_session(SESSION1, PATH1); - if (ret < 0) { - /* Fail */ - return -1; - } - - sess = session_find_by_name(SESSION1); - if (sess) { - /* Success */ - return 0; - } - - /* Fail */ - return -1; -} - -int main(int argc, char **argv) -{ - int ret, i; - struct ltt_session *iter, *tmp; - - srand(time(NULL)); - - printf("\nTesting Sessions:\n-----------\n"); - - session_list = session_get_list(); - if (session_list == NULL) { - return -1; - } - - printf("Create 1 session %s: ", SESSION1); - fflush(stdout); - ret = create_one_session(SESSION1, PATH1); - if (ret < 0) { - return -1; - } - PRINT_OK(); - - printf("Validating created session %s: ", SESSION1); - fflush(stdout); - tmp = session_find_by_name(SESSION1); - if (tmp == NULL) { - return -1; - } - /* Basic init session values */ - assert(tmp->kernel_session == NULL); - assert(strlen(tmp->path)); - assert(strlen(tmp->name)); - session_lock(tmp); - session_unlock(tmp); - - PRINT_OK(); - - printf("Destroy 1 session %s: ", SESSION1); - fflush(stdout); - ret = destroy_one_session(tmp); - if (ret < 0) { - return -1; - } - PRINT_OK(); - - printf("Two session with same name: "); - fflush(stdout); - ret = two_session_same_name(); - if (ret < 0) { - return -1; - } - PRINT_OK(); - - empty_session_list(); - - printf("Fuzzing create_session arguments: "); - fflush(stdout); - ret = fuzzing_create_args(); - if (ret < 0) { - return -1; - } - PRINT_OK(); - - printf("Creating %d sessions: ", MAX_SESSIONS); - fflush(stdout); - for (i = 0; i < MAX_SESSIONS; i++) { - char *tmp_name = get_random_string(); - - ret = create_one_session(tmp_name, PATH1); - if (ret < 0) { - printf("session %d (name: %s) creation failed\n", i, tmp_name); - return -1; - } - - if ((i % 1000) == 0) { - fprintf(stdout, "%d..", i); - fflush(stdout); - } - } - PRINT_OK(); - - printf("Destroying %d sessions: ", MAX_SESSIONS); - fflush(stdout); - for (i = 0; i < MAX_SESSIONS; i++) { - cds_list_for_each_entry_safe(iter, tmp, &session_list->head, list) { - ret = destroy_one_session(iter); - if (ret < 0) { - printf("session %d (name: %s) creation failed\n", i, iter->name); - return -1; - } - } - } - PRINT_OK(); - - /* Session list must be 0 */ - assert(!session_list_count()); - - /* Success */ - return 0; -} diff --git a/tests/tools/test_ust_data_trace.c b/tests/tools/test_ust_data_trace.c deleted file mode 100644 index 74f282bbb..000000000 --- a/tests/tools/test_ust_data_trace.c +++ /dev/null @@ -1,204 +0,0 @@ -/* - * 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 -#include -#include -#include - -#include "utils.h" - -/* This path will NEVER be created in this test */ -#define PATH1 "/tmp/.test-junk-lttng" - -#define RANDOM_STRING_LEN 11 - -/* For lttngerr.h */ -int lttng_opt_quiet = 1; -int lttng_opt_verbose; - -static const char alphanum[] = - "0123456789" - "ABCDEFGHIJKLMNOPQRSTUVWXYZ" - "abcdefghijklmnopqrstuvwxyz"; -static char random_string[RANDOM_STRING_LEN]; - -static struct ltt_ust_session *usess; -static struct lttng_domain dom; - -/* - * Return random string of 10 characters. - * Not thread-safe. - */ -static char *get_random_string(void) -{ - int i; - - for (i = 0; i < RANDOM_STRING_LEN - 1; i++) { - random_string[i] = alphanum[rand() % (sizeof(alphanum) - 1)]; - } - - random_string[RANDOM_STRING_LEN - 1] = '\0'; - - return random_string; -} - -static void create_one_ust_session(void) -{ - printf("Create UST session: "); - - dom.type = LTTNG_DOMAIN_UST; - - usess = trace_ust_create_session(PATH1, 42); - 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_get_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; - - memset(&attr, 0, sizeof(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; - - memset(&ev, 0, sizeof(ev)); - strncpy(ev.name, get_random_string(), LTTNG_SYMBOL_NAME_LEN); - ev.type = LTTNG_EVENT_TRACEPOINT; - ev.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL; - - printf("Creating UST event: "); - event = trace_ust_create_event(&ev, NULL); - assert(event != NULL); - PRINT_OK(); - - printf("Validating UST event: "); - assert(event->enabled == 0); - 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 ectx; - struct ltt_ust_context *uctx; - - ectx.ctx = LTTNG_EVENT_CONTEXT_VTID; - - printf("Creating UST context: "); - uctx = trace_ust_create_context(&ectx); - assert(uctx != NULL); - PRINT_OK(); - - printf("Validating UST context: "); - assert((int) uctx->ctx.ctx == LTTNG_UST_CONTEXT_VTID); - 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/Makefile.am b/tests/ust/Makefile.am deleted file mode 100644 index c59829051..000000000 --- a/tests/ust/Makefile.am +++ /dev/null @@ -1,28 +0,0 @@ -if HAVE_LIBLTTNG_UST_CTL -SUBDIRS = nprocesses high-throughput low-throughput before-after multi-session \ - overlap - -AM_CFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/tests -I$(top_srcdir)/src -g -Wall -AM_LDFLAGS = -lurcu -lurcu-cds - -EXTRA_DIST = runall.sh run-ust-global-tests.sh - -noinst_PROGRAMS = ust_global_event_basic ust_global_event_wildcard - -UTILS=../utils.h -LIBLTTNG=$(top_builddir)/src/lib/lttng-ctl/liblttng-ctl.la - -SESSIONDSRC=$(top_srcdir)/src/common/sessiond-comm/sessiond-comm.c \ - $(top_srcdir)/src/common/sessiond-comm/unix.c \ - $(top_srcdir)/src/common/sessiond-comm/inet.c \ - $(top_srcdir)/src/common/sessiond-comm/inet6.c - -ust_global_event_wildcard_SOURCES = ust_global_event_wildcard.c $(UTILS) \ - $(SESSIONDSRC) -ust_global_event_wildcard_LDADD = $(LIBLTTNG) - -ust_global_event_basic_SOURCES = ust_global_event_basic.c $(UTILS) \ - $(SESSIONDSRC) -ust_global_event_basic_LDADD = $(LIBLTTNG) - -endif diff --git a/tests/ust/before-after/Makefile.am b/tests/ust/before-after/Makefile.am deleted file mode 100644 index d197d72f5..000000000 --- a/tests/ust/before-after/Makefile.am +++ /dev/null @@ -1,16 +0,0 @@ -AM_CFLAGS = -I$(srcdir) -O2 -AM_LDFLAGS = -llttng-ust - -if LTTNG_TOOLS_BUILD_WITH_LIBDL -AM_LDFLAGS += -ldl -endif -if LTTNG_TOOLS_BUILD_WITH_LIBC_DL -AM_LDFLAGS += -lc -endif - -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/before-after/gen-nevents.c b/tests/ust/before-after/gen-nevents.c deleted file mode 100644 index b2c19927f..000000000 --- a/tests/ust/before-after/gen-nevents.c +++ /dev/null @@ -1,56 +0,0 @@ -/* - * 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); - usleep(100000); - } - - return 0; -} diff --git a/tests/ust/before-after/run b/tests/ust/before-after/run deleted file mode 100755 index 46b97f443..000000000 --- a/tests/ust/before-after/run +++ /dev/null @@ -1,120 +0,0 @@ -#!/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 -TEST_DESC="UST tracer - Start tracing before and after execution" - -CURDIR=$(dirname $0)/ -TESTDIR=$CURDIR/../.. -NR_ITER=100 -SESSION_NAME="per-session" -EVENT_NAME="ust_gen_nevents:tptest" - -source $TESTDIR/utils.sh - -print_test_banner "$TEST_DESC" - -if [ ! -x "$CURDIR/gen-nevents" ]; then - echo -e "No UST nevents binary detected. Passing." - exit 0 -fi - -# MUST set TESTDIR before calling those functions - -test_before_apps() { - local out - - # BEFORE application is spawned - create_lttng_session $SESSION_NAME $TRACE_PATH - enable_ust_lttng_event $SESSION_NAME $EVENT_NAME - start_lttng_tracing $SESSION_NAME - # Start test - echo -n "Starting application... " - ./$CURDIR/gen-nevents $NR_ITER - echo -n "Ended " - print_ok - stop_lttng_tracing $SESSION_NAME - destroy_lttng_session $SESSION_NAME - - trace_matches $EVENT_NAME $NR_ITER $TRACE_PATH - - return $? -} - -test_after_apps() { - local out - - echo -n "Starting application... " - ./$CURDIR/gen-nevents 100 & - print_ok - - # BEFORE application is spawned - create_lttng_session $SESSION_NAME $TRACE_PATH - enable_ust_lttng_event $SESSION_NAME $EVENT_NAME - start_lttng_tracing $SESSION_NAME - - # At least hit one event - sleep 2 - - stop_lttng_tracing $SESSION_NAME - destroy_lttng_session $SESSION_NAME - - out=$(babeltrace $TRACE_PATH | grep $EVENT_NAME | wc -l) - if [ $out -eq 0 ]; then - echo -n "No event found. Suppose to have at least one... " - print_fail - out=1 - else - echo -n "Found $out event(s). Coherent... " - print_ok - out=0 - fi - - return $out -} - -# MUST set TESTDIR before calling those functions - -start_lttng_sessiond - -echo "" -echo "=== Start application BEFORE tracing was started ===" - -TRACE_PATH=$(mktemp -d) - -test_before_apps -out=$? -if [ $out -ne 0 ]; then - stop_lttng_sessiond - exit $out -fi - -rm -rf $TRACE_PATH - -echo "" -echo "=== Start application AFTER tracing was started ===" - -TRACE_PATH=$(mktemp -d) - -test_after_apps -out=$? -if [ $out -ne 0 ]; then - stop_lttng_sessiond - exit $out -fi - -stop_lttng_sessiond - -rm -rf $TRACE_PATH diff --git a/tests/ust/before-after/tp.c b/tests/ust/before-after/tp.c deleted file mode 100644 index e291924a3..000000000 --- a/tests/ust/before-after/tp.c +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/before-after/ust_gen_nevents.h b/tests/ust/before-after/ust_gen_nevents.h deleted file mode 100644 index 8d82ecb4e..000000000 --- a/tests/ust/before-after/ust_gen_nevents.h +++ /dev/null @@ -1,56 +0,0 @@ -#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/ust/high-throughput/Makefile.am b/tests/ust/high-throughput/Makefile.am deleted file mode 100644 index cff8fe423..000000000 --- a/tests/ust/high-throughput/Makefile.am +++ /dev/null @@ -1,16 +0,0 @@ -AM_CFLAGS = -I$(srcdir) -O2 -AM_LDFLAGS = -llttng-ust - -if LTTNG_TOOLS_BUILD_WITH_LIBDL -AM_LDFLAGS += -ldl -endif -if LTTNG_TOOLS_BUILD_WITH_LIBC_DL -AM_LDFLAGS += -lc -endif - -noinst_PROGRAMS = gen-events -gen_events_SOURCES = main.c tp.c tp.h -gen_events_LDADD = -llttng-ust - -noinst_SCRIPTS = run -EXTRA_DIST = run diff --git a/tests/ust/high-throughput/main.c b/tests/ust/high-throughput/main.c deleted file mode 100644 index dbd2998ac..000000000 --- a/tests/ust/high-throughput/main.c +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (C) 2009 Pierre-Marc Fournier - * Copyright (C) 2011 Mathieu Desnoyers - * - * 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 "tp.h" - -void inthandler(int sig) -{ -} - -int init_int_handler(void) -{ - int result; - struct sigaction act; - - memset(&act, 0, sizeof(act)); - result = sigemptyset(&act.sa_mask); - if (result == -1) { - perror("sigemptyset"); - return -1; - } - - act.sa_handler = inthandler; - act.sa_flags = SA_RESTART; - - /* Only defer ourselves. Also, try to restart interrupted - * syscalls to disturb the traced program as little as possible. - */ - result = sigaction(SIGUSR1, &act, NULL); - if (result == -1) { - perror("sigaction"); - return -1; - } - - return 0; -} - -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; - int delay = 0; - - init_int_handler(); - - if (argc == 2) - delay = atoi(argv[1]); - - sleep(delay); - - for (i = 0; i < 1000000; i++) { - netint = htonl(i); - tracepoint(tp, tptest, i, netint, values, text, - strlen(text), dbl, flt); - } - - return 0; -} diff --git a/tests/ust/high-throughput/run b/tests/ust/high-throughput/run deleted file mode 100755 index dff5fdd49..000000000 --- a/tests/ust/high-throughput/run +++ /dev/null @@ -1,94 +0,0 @@ -#!/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 -TEST_DESC="UST tracer - Testing high events throughput" - -CURDIR=$(dirname $0)/ -TESTDIR=$CURDIR/../.. -NR_ITER=20 -BIN_NAME="gen-events" -SESSION_NAME="high-throughput" -EVENT_NAME="tp:tptest" - -source $TESTDIR/utils.sh - -print_test_banner "$TEST_DESC" - -if [ ! -x "$CURDIR/$BIN_NAME" ]; then - echo -e "No UST nevents binary detected. Passing." - exit 0 -fi - -TRACE_PATH=$(mktemp -d) - -# MUST set TESTDIR before calling those functions - -start_lttng_sessiond - -create_lttng_session $SESSION_NAME $TRACE_PATH - -enable_ust_lttng_event $SESSION_NAME $EVENT_NAME -start_lttng_tracing $SESSION_NAME - -for i in `seq 1 $NR_ITER`; do - ./$CURDIR/$BIN_NAME & >/dev/null 2>&1 -done - -echo "Waiting for applications to end" -while [ -n "$(pidof $BIN_NAME)" ]; do - echo -n "." - sleep 0.5 -done -echo "" - -stop_lttng_tracing $SESSION_NAME -destroy_lttng_session $SESSION_NAME - -stop_lttng_sessiond - -# Validate test - -TEMP_FILE=$(mktemp) -TEMP_FILE_2=$(mktemp) - -traced=$(babeltrace $TRACE_PATH 2>/dev/null | wc -l) -babeltrace $TRACE_PATH >/dev/null 2>$TEMP_FILE_2 - -cat $TEMP_FILE_2 | cut -f4 -d " " >$TEMP_FILE - -dropped=0 -while read line; -do - let dropped=$dropped+$line -done < $TEMP_FILE - -let total=$dropped+$traced -let wanted=$NR_ITER*1000000 - -if [ $wanted -ne $total ]; then - echo -n "Expected $wanted. Dropped $dropped. Recorded $traced. Total $total... " - print_fail - out=1 -else - echo -n "Expected $wanted. Dropped $dropped. Recorded $traced. Total $total... " - print_ok - out=0 -fi - -rm -rf $TRACE_PATH -rm $TEMP_FILE $TEMP_FILE_2 - -exit $out diff --git a/tests/ust/high-throughput/tp.c b/tests/ust/high-throughput/tp.c deleted file mode 100644 index 1d6cbdaab..000000000 --- a/tests/ust/high-throughput/tp.c +++ /dev/null @@ -1,18 +0,0 @@ -/* - * tp.c - * - * Copyright (c) 2011 Mathieu Desnoyers - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - */ - -#define TRACEPOINT_CREATE_PROBES -#include "tp.h" diff --git a/tests/ust/high-throughput/tp.h b/tests/ust/high-throughput/tp.h deleted file mode 100644 index 23d4d2508..000000000 --- a/tests/ust/high-throughput/tp.h +++ /dev/null @@ -1,61 +0,0 @@ -#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 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - */ - -#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) - ) -) - -TRACEPOINT_EVENT(tp, tptest_sighandler, - TP_ARGS(), - TP_FIELDS() -) - -#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/ust/low-throughput/Makefile.am b/tests/ust/low-throughput/Makefile.am deleted file mode 100644 index a1df9f5e2..000000000 --- a/tests/ust/low-throughput/Makefile.am +++ /dev/null @@ -1,16 +0,0 @@ -AM_CFLAGS = -I$(srcdir) -O2 -AM_LDFLAGS = -llttng-ust - -if LTTNG_TOOLS_BUILD_WITH_LIBDL -AM_LDFLAGS += -ldl -endif -if LTTNG_TOOLS_BUILD_WITH_LIBC_DL -AM_LDFLAGS += -lc -endif - -noinst_PROGRAMS = gen-events -gen_events_SOURCES = main.c tp.c tp.h -gen_events_LDADD = -llttng-ust -lurcu - -noinst_SCRIPTS = run -EXTRA_DIST = run diff --git a/tests/ust/low-throughput/main.c b/tests/ust/low-throughput/main.c deleted file mode 100644 index 06ab9ef82..000000000 --- a/tests/ust/low-throughput/main.c +++ /dev/null @@ -1,81 +0,0 @@ -/* - * 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 - -#define TRACEPOINT_DEFINE -#include "tp.h" - -/* - * Thread recording a tracepoint every minute for 20 minutes. - */ -static void *th_event_minute(void *data) -{ - int i; - - /* Loop for 20 minutes */ - for (i = 1; i < 21; i++) { - /* Sleep 60 seconds */ - poll(NULL, 0, 60000); - - /* 20 minutes tracepoint */ - if ((i % 20) == 0) { - tracepoint(tp, slow, i, "twenty"); - } - - /* 10 minutes tracepoint */ - if ((i % 10) == 0) { - tracepoint(tp, slow, i, "ten"); - } - - /* 1 minute tracepoint */ - tracepoint(tp, slow, i, "one"); - } - - return NULL; -} - -/* - * main - */ -int main(int argc, char **argv) -{ - int ret; - void *status; - pthread_t thread; - - ret = pthread_create(&thread, NULL, th_event_minute, NULL); - if (ret != 0) { - perror("pthread_create event minute"); - goto error; - } - - ret = pthread_join(thread, &status); - if (ret != 0) { - perror("pthread_join"); - goto error; - } - - return 0; - -error: - return 1; -} diff --git a/tests/ust/low-throughput/run b/tests/ust/low-throughput/run deleted file mode 100755 index 26e074997..000000000 --- a/tests/ust/low-throughput/run +++ /dev/null @@ -1,101 +0,0 @@ -#!/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 -TEST_DESC="UST tracer - Testing low events throughput" - -CURDIR=$(dirname $0)/ -TESTDIR=$CURDIR/../.. -BIN_NAME="gen-events" -SESSION_NAME="low-throughput" -EVENT_NAME="tp:slow" - -source $TESTDIR/utils.sh - -print_test_banner "$TEST_DESC" - -if [ ! -x "$CURDIR/$BIN_NAME" ]; then - echo -e "No UST nevents binary detected. Passing." - exit 0 -fi - -TRACE_PATH=$(mktemp -d) - -# MUST set TESTDIR before calling those functions - -start_lttng_sessiond - -create_lttng_session $SESSION_NAME $TRACE_PATH - -enable_ust_lttng_event $SESSION_NAME $EVENT_NAME -start_lttng_tracing $SESSION_NAME - -# This is going to take 20 minutes -./$CURDIR/$BIN_NAME >/dev/null 2>&1 - -stop_lttng_tracing $SESSION_NAME -destroy_lttng_session $SESSION_NAME - -stop_lttng_sessiond - -# Validate test - -last_val=0 -out=0 - -babeltrace $TRACE_PATH | while read event; -do - val=$(echo $event | cut -f10 -d" ") - val=${val%?} - th=$(echo $event | cut -f13 -d " ") - - if [ $th = '"one"' ]; then - ((last_val++)) - # We expect here a continous value from 1 to 20 - if [ $last_val -ne $val ]; then - echo -n "[-] One minute event failed ($val) " - out=1 - break - fi - elif [ $th = '"ten"' ]; then - # Test 10 minutes counter - if [ $val -ne 10 ]; then - # Test 20 minutes counter - if [ $val -ne 20 ]; then - echo -n "[-] Ten minutes event failed ($val) " - out=1 - break - fi - fi - elif [ $th = '"twenty"' ]; then - # Test 20 minutes counter - if [ $val -ne 20 ]; then - echo -n "[-] Twenty minutes event failed ($val) " - out=1 - break - fi - fi -done - -if [ $out -eq 0 ]; then - echo -n "Trace is coherent... " - print_ok -else - print_fail -fi - -rm -rf $TRACE_PATH - -exit $out diff --git a/tests/ust/low-throughput/tp.c b/tests/ust/low-throughput/tp.c deleted file mode 100644 index 1d6cbdaab..000000000 --- a/tests/ust/low-throughput/tp.c +++ /dev/null @@ -1,18 +0,0 @@ -/* - * tp.c - * - * Copyright (c) 2011 Mathieu Desnoyers - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - */ - -#define TRACEPOINT_CREATE_PROBES -#include "tp.h" diff --git a/tests/ust/low-throughput/tp.h b/tests/ust/low-throughput/tp.h deleted file mode 100644 index 74b908b56..000000000 --- a/tests/ust/low-throughput/tp.h +++ /dev/null @@ -1,45 +0,0 @@ -#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 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - */ - -#include - -TRACEPOINT_EVENT(tp, slow, - TP_ARGS(unsigned int, c, char *, thread_name), - TP_FIELDS( - ctf_integer(unsigned int, counter, c) - ctf_string(th_name, thread_name) - ) -) - -#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/ust/multi-session/Makefile.am b/tests/ust/multi-session/Makefile.am deleted file mode 100644 index d197d72f5..000000000 --- a/tests/ust/multi-session/Makefile.am +++ /dev/null @@ -1,16 +0,0 @@ -AM_CFLAGS = -I$(srcdir) -O2 -AM_LDFLAGS = -llttng-ust - -if LTTNG_TOOLS_BUILD_WITH_LIBDL -AM_LDFLAGS += -ldl -endif -if LTTNG_TOOLS_BUILD_WITH_LIBC_DL -AM_LDFLAGS += -lc -endif - -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/multi-session/gen-nevents.c b/tests/ust/multi-session/gen-nevents.c deleted file mode 100644 index 7add25249..000000000 --- a/tests/ust/multi-session/gen-nevents.c +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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, nr_iter = 100; - long value = 42; - - if (argc == 2) { - nr_iter = atoi(argv[1]); - } - - for (i = 0; i < nr_iter; i++) { - tracepoint(ust_gen_nevents, tptest0, i, value); - tracepoint(ust_gen_nevents, tptest1, i, value); - tracepoint(ust_gen_nevents, tptest2, i, value); - tracepoint(ust_gen_nevents, tptest3, i, value); - } - - return 0; -} diff --git a/tests/ust/multi-session/run b/tests/ust/multi-session/run deleted file mode 100755 index 7242fd90e..000000000 --- a/tests/ust/multi-session/run +++ /dev/null @@ -1,91 +0,0 @@ -#!/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 -TEST_DESC="UST tracer - Multi-session" - -CURDIR=$(dirname $0)/ -TESTDIR=$CURDIR/../.. -NR_ITER=100 -SESSION_NAME="multi-session" -EVENT_NAME="ust_gen_nevents:tptest" - -source $TESTDIR/utils.sh - -print_test_banner "$TEST_DESC" - -if [ ! -x "$CURDIR/gen-nevents" ]; then - echo -e "No UST nevents binary detected. Passing." - exit 0 -fi - -# MUST set TESTDIR before calling those functions - -test_multi_session() { - local out - - # BEFORE application is spawned - for i in `seq 0 3`; do - create_lttng_session "$SESSION_NAME-$i" "$TRACE_PATH/$i" - enable_ust_lttng_event "$SESSION_NAME-$i" "$EVENT_NAME$i" - start_lttng_tracing "$SESSION_NAME-$i" - done - - echo -n "Starting application generating $NR_ITER events... " - ./$CURDIR/gen-nevents $NR_ITER & - print_ok - - # At least hit one event - echo -n "Waiting for events to record " - while [ -n "$(pidof gen-nevents)" ]; do - echo -n "." - sleep 0.1 - done - print_ok - - for i in `seq 0 3`; do - stop_lttng_tracing "$SESSION_NAME-$i" - destroy_lttng_session "$SESSION_NAME-$i" - out=$(babeltrace "$TRACE_PATH/$i" | grep "$EVENT_NAMEi$i" | wc -l) - if [ $out -ne $NR_ITER ]; then - echo -n "No event found. Suppose to have at least one... " - print_fail - out=1 - else - echo -n "Found $out event(s) for $SESSION_NAME-$i. Coherent... " - print_ok - out=0 - fi - done - - return $out -} - -# MUST set TESTDIR before calling those functions - -start_lttng_sessiond - -TRACE_PATH=$(mktemp -d) - -test_multi_session -out=$? -if [ $out -ne 0 ]; then - stop_lttng_sessiond - exit $out -fi - -stop_lttng_sessiond - -rm -rf "$TRACE_PATH" diff --git a/tests/ust/multi-session/tp.c b/tests/ust/multi-session/tp.c deleted file mode 100644 index e291924a3..000000000 --- a/tests/ust/multi-session/tp.c +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/multi-session/ust_gen_nevents.h b/tests/ust/multi-session/ust_gen_nevents.h deleted file mode 100644 index cba3994c6..000000000 --- a/tests/ust/multi-session/ust_gen_nevents.h +++ /dev/null @@ -1,68 +0,0 @@ -#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, tptest0, - TP_ARGS(int, anint, long, value), - TP_FIELDS( - ctf_integer(int, intfield, anint) - ctf_integer(long, longfield, value) - ) -) - -TRACEPOINT_EVENT(ust_gen_nevents, tptest1, - TP_ARGS(int, anint, long, value), - TP_FIELDS( - ctf_integer(int, intfield, anint) - ctf_integer(long, longfield, value) - ) -) - -TRACEPOINT_EVENT(ust_gen_nevents, tptest2, - TP_ARGS(int, anint, long, value), - TP_FIELDS( - ctf_integer(int, intfield, anint) - ctf_integer(long, longfield, value) - ) -) - -TRACEPOINT_EVENT(ust_gen_nevents, tptest3, - TP_ARGS(int, anint, long, value), - TP_FIELDS( - ctf_integer(int, intfield, anint) - ctf_integer(long, longfield, value) - ) -) - -#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/ust/nprocesses/Makefile.am b/tests/ust/nprocesses/Makefile.am deleted file mode 100644 index b07ae0baa..000000000 --- a/tests/ust/nprocesses/Makefile.am +++ /dev/null @@ -1,16 +0,0 @@ -AM_CFLAGS = -I$(srcdir) -O2 -AM_LDFLAGS = -llttng-ust - -if LTTNG_TOOLS_BUILD_WITH_LIBDL -AM_LDFLAGS += -ldl -endif -if LTTNG_TOOLS_BUILD_WITH_LIBC_DL -AM_LDFLAGS += -lc -endif - -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 ust-nprocesses -EXTRA_DIST = run ust-nprocesses diff --git a/tests/ust/nprocesses/gen-events-time.c b/tests/ust/nprocesses/gen-events-time.c deleted file mode 100644 index bc5b68ca6..000000000 --- a/tests/ust/nprocesses/gen-events-time.c +++ /dev/null @@ -1,61 +0,0 @@ -/* - * 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 deleted file mode 100755 index f492ed7ed..000000000 --- a/tests/ust/nprocesses/run +++ /dev/null @@ -1,41 +0,0 @@ -#!/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 -NR_ITER=100 -TEST_DESC="UST tracer - Generate $NR_ITER process" - -CURDIR=$(dirname $0)/ -TESTDIR=$CURDIR/../.. -TEST_BIN_NAME="gen-events-time" - -source $TESTDIR/utils.sh - -print_test_banner "$TEST_DESC" - -if [ ! -x "$CURDIR/$TEST_BIN_NAME" ]; then - echo -e "No UST $TEST_BIN_NAME binary detected. Passing." - exit 0 -fi - -# MUST set TESTDIR before calling those functions - -start_lttng_sessiond - -./$CURDIR/ust-nprocesses $NR_ITER - -stop_lttng_sessiond - -exit 0 diff --git a/tests/ust/nprocesses/tp.c b/tests/ust/nprocesses/tp.c deleted file mode 100644 index 438139ebc..000000000 --- a/tests/ust/nprocesses/tp.c +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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-nprocesses b/tests/ust/nprocesses/ust-nprocesses deleted file mode 100755 index 90c0c2e9b..000000000 --- a/tests/ust/nprocesses/ust-nprocesses +++ /dev/null @@ -1,69 +0,0 @@ -#!/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/../.. -NR_ITER=$1 -TEST_BIN_NAME="gen-events-time" -SESSION_NAME="ust-nprocesses" -EVENT_NAME="ust_gen_event:tptest" -TEST_WAIT_SEC=5 - -source $TESTDIR/utils.sh - -# MUST set TESTDIR before calling those functions - -# Start test for 1000 seconds - -for i in `seq 1 $NR_ITER` -do - ./$CURDIR/$TEST_BIN_NAME 1000 >/dev/null 2>&1 & -done - -echo -n "Validating registered apps in 3 seconds..." - -sleep 3 - -listing=$($TESTDIR/../src/bin/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 " - print_fail -else - print_ok -fi - -TRACE_PATH=$(mktemp -d) - -create_lttng_session $SESSION_NAME $TRACE_PATH - -enable_ust_lttng_event $SESSION_NAME $EVENT_NAME -start_lttng_tracing $SESSION_NAME - -echo "Sleeping $TEST_WAIT_SEC seconds for tracing to start everywhere" -echo "Warning: this arbitrary time can make the test fail on slower system" -sleep $TEST_WAIT_SEC - -stop_lttng_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 & -print_ok -exit 0 diff --git a/tests/ust/nprocesses/ust_gen_event.h b/tests/ust/nprocesses/ust_gen_event.h deleted file mode 100644 index 5bdcb37c5..000000000 --- a/tests/ust/nprocesses/ust_gen_event.h +++ /dev/null @@ -1,56 +0,0 @@ -#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 diff --git a/tests/ust/overlap/Makefile.am b/tests/ust/overlap/Makefile.am deleted file mode 100644 index 7100034f9..000000000 --- a/tests/ust/overlap/Makefile.am +++ /dev/null @@ -1,4 +0,0 @@ -SUBDIRS = demo - -noinst_SCRIPTS = run -EXTRA_DIST = run overlap.sh diff --git a/tests/ust/overlap/demo/Makefile.am b/tests/ust/overlap/demo/Makefile.am deleted file mode 100644 index 68b6e087f..000000000 --- a/tests/ust/overlap/demo/Makefile.am +++ /dev/null @@ -1,38 +0,0 @@ -AM_CFLAGS=-I$(srcdir) -if NO_SHARED -# Do not build this test if shared libraries support was -# explicitly disabled. -else -# Force the shared flag on the noinst libraries since they are -# only built static by default -FORCE_SHARED_LIB_OPTIONS = -module -shared -avoid-version \ - -rpath $(abs_builddir) - -#contains ust_tests_demo.h and ust_tests_demo2.h provider probes -liblttng_ust_provider_ust_tests_demo_la_SOURCES = \ - tp.c ust_tests_demo.h \ - tp2.c ust_tests_demo2.h -liblttng_ust_provider_ust_tests_demo_la_LIBADD = -llttng-ust -liblttng_ust_provider_ust_tests_demo_la_LDFLAGS = $(FORCE_SHARED_LIB_OPTIONS) - -#contains ust_tests_demo3.h provider probes -liblttng_ust_provider_ust_tests_demo3_la_SOURCES = tp3.c ust_tests_demo3.h -liblttng_ust_provider_ust_tests_demo3_la_LIBADD = -llttng-ust -liblttng_ust_provider_ust_tests_demo3_la_LDFLAGS = $(FORCE_SHARED_LIB_OPTIONS) - -noinst_LTLIBRARIES = liblttng-ust-provider-ust-tests-demo.la \ - liblttng-ust-provider-ust-tests-demo3.la - -noinst_PROGRAMS = demo -demo_SOURCES = demo.c ust_tests_demo.h -# The demo program only depends on libdl/libc for dlopen(). -if LTTNG_TOOLS_BUILD_WITH_LIBDL -demo_LDADD = -ldl -endif -if LTTNG_TOOLS_BUILD_WITH_LIBC_DL -demo_LDADD = -lc -endif - -noinst_SCRIPTS = demo-trace -EXTRA_DIST = demo-trace -endif diff --git a/tests/ust/overlap/demo/demo-trace b/tests/ust/overlap/demo/demo-trace deleted file mode 100755 index 88a1be73c..000000000 --- a/tests/ust/overlap/demo/demo-trace +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -LD_PRELOAD=.libs/liblttng-ust-provider-ust-tests-demo.so:.libs/liblttng-ust-provider-ust-tests-demo3.so ./demo ${*} diff --git a/tests/ust/overlap/demo/demo.c b/tests/ust/overlap/demo/demo.c deleted file mode 100644 index e2b61c2e4..000000000 --- a/tests/ust/overlap/demo/demo.c +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (C) 2009 Pierre-Marc Fournier - * Copyright (C) 2011 Mathieu Desnoyers - * - * 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 -#define TRACEPOINT_PROBE_DYNAMIC_LINKAGE -#include "ust_tests_demo.h" -#include "ust_tests_demo2.h" -#include "ust_tests_demo3.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; - int delay = 0; - - if (argc == 2) - delay = atoi(argv[1]); - - fprintf(stderr, "Demo program starting.\n"); - - sleep(delay); - - fprintf(stderr, "Tracing... "); - tracepoint(ust_tests_demo, starting, 123); - for (i = 0; i < 5; i++) { - netint = htonl(i); - tracepoint(ust_tests_demo2, loop, i, netint, values, - text, strlen(text), dbl, flt); - } - tracepoint(ust_tests_demo, done, 456); - tracepoint(ust_tests_demo3, done, 42); - fprintf(stderr, " done.\n"); - return 0; -} diff --git a/tests/ust/overlap/demo/tp.c b/tests/ust/overlap/demo/tp.c deleted file mode 100644 index 288ce6146..000000000 --- a/tests/ust/overlap/demo/tp.c +++ /dev/null @@ -1,18 +0,0 @@ -/* - * tp.c - * - * Copyright (c) 2011 Mathieu Desnoyers - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - */ - -#define TRACEPOINT_CREATE_PROBES -#include "ust_tests_demo.h" diff --git a/tests/ust/overlap/demo/tp2.c b/tests/ust/overlap/demo/tp2.c deleted file mode 100644 index 718c9db26..000000000 --- a/tests/ust/overlap/demo/tp2.c +++ /dev/null @@ -1,18 +0,0 @@ -/* - * tp2.c - * - * Copyright (c) 2011 Mathieu Desnoyers - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - */ - -#define TRACEPOINT_CREATE_PROBES -#include "ust_tests_demo2.h" diff --git a/tests/ust/overlap/demo/tp3.c b/tests/ust/overlap/demo/tp3.c deleted file mode 100644 index b1babc735..000000000 --- a/tests/ust/overlap/demo/tp3.c +++ /dev/null @@ -1,18 +0,0 @@ -/* - * tp3.c - * - * Copyright (c) 2011 Mathieu Desnoyers - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - */ - -#define TRACEPOINT_CREATE_PROBES -#include "ust_tests_demo3.h" diff --git a/tests/ust/overlap/demo/ust_tests_demo.h b/tests/ust/overlap/demo/ust_tests_demo.h deleted file mode 100644 index 3e024b44e..000000000 --- a/tests/ust/overlap/demo/ust_tests_demo.h +++ /dev/null @@ -1,63 +0,0 @@ -#undef TRACEPOINT_PROVIDER -#define TRACEPOINT_PROVIDER ust_tests_demo - -#if !defined(_TRACEPOINT_UST_TESTS_DEMO_H) || defined(TRACEPOINT_HEADER_MULTI_READ) -#define _TRACEPOINT_UST_TESTS_DEMO_H - -#ifdef __cplusplus -extern "C" { -#endif - -/* - * Copyright (C) 2011 Mathieu Desnoyers - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - */ - -#include - -TRACEPOINT_EVENT(ust_tests_demo, starting, - TP_ARGS(int, value), - TP_FIELDS( - ctf_integer(int, value, value) - ) -) -TRACEPOINT_LOGLEVEL(ust_tests_demo, starting, TRACE_CRIT) - -/* - * Dummy model information, just for example. TODO: we should check if - * EMF model URI have some standard format we should follow. - */ -TRACEPOINT_MODEL_EMF_URI(ust_tests_demo, starting, - "http://example.com/path_to_model?q=ust_tests_demo:starting") - -TRACEPOINT_EVENT(ust_tests_demo, done, - TP_ARGS(int, value), - TP_FIELDS( - ctf_integer(int, value, value) - ) -) -TRACEPOINT_LOGLEVEL(ust_tests_demo, done, TRACE_CRIT) - -TRACEPOINT_MODEL_EMF_URI(ust_tests_demo, done, - "http://example.com/path_to_model?q=ust_tests_demo:done") - -#endif /* _TRACEPOINT_UST_TESTS_DEMO_H */ - -#undef TRACEPOINT_INCLUDE_FILE -#define TRACEPOINT_INCLUDE_FILE ./ust_tests_demo.h - -/* This part must be outside ifdef protection */ -#include - -#ifdef __cplusplus -} -#endif diff --git a/tests/ust/overlap/demo/ust_tests_demo2.h b/tests/ust/overlap/demo/ust_tests_demo2.h deleted file mode 100644 index cf4424b61..000000000 --- a/tests/ust/overlap/demo/ust_tests_demo2.h +++ /dev/null @@ -1,60 +0,0 @@ -#undef TRACEPOINT_PROVIDER -#define TRACEPOINT_PROVIDER ust_tests_demo2 - -#if !defined(_TRACEPOINT_UST_TESTS_DEMO2_H) || defined(TRACEPOINT_HEADER_MULTI_READ) -#define _TRACEPOINT_UST_TESTS_DEMO2_H - -#ifdef __cplusplus -extern "C" { -#endif - -/* - * Copyright (C) 2011 Mathieu Desnoyers - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - */ - -#include - -TRACEPOINT_EVENT(ust_tests_demo2, loop, - 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) - ) -) -TRACEPOINT_LOGLEVEL(ust_tests_demo2, loop, TRACE_WARNING) - -#endif /* _TRACEPOINT_UST_TESTS_DEMO2_H */ - -#undef TRACEPOINT_INCLUDE_FILE -#define TRACEPOINT_INCLUDE_FILE ./ust_tests_demo2.h - -/* This part must be outside ifdef protection */ -#include - -#ifdef __cplusplus -} -#endif diff --git a/tests/ust/overlap/demo/ust_tests_demo3.h b/tests/ust/overlap/demo/ust_tests_demo3.h deleted file mode 100644 index e58ee86f7..000000000 --- a/tests/ust/overlap/demo/ust_tests_demo3.h +++ /dev/null @@ -1,45 +0,0 @@ -#undef TRACEPOINT_PROVIDER -#define TRACEPOINT_PROVIDER ust_tests_demo3 - -#if !defined(_TRACEPOINT_UST_TESTS_DEMO3_H) || defined(TRACEPOINT_HEADER_MULTI_READ) -#define _TRACEPOINT_UST_TESTS_DEMO3_H - -#ifdef __cplusplus -extern "C" { -#endif - -/* - * Copyright (C) 2011 Mathieu Desnoyers - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - */ - -#include - -TRACEPOINT_EVENT(ust_tests_demo3, done, - TP_ARGS(int, value), - TP_FIELDS( - ctf_integer(int, value, value) - ) -) -TRACEPOINT_LOGLEVEL(ust_tests_demo3, done, TRACE_WARNING) - -#endif /* _TRACEPOINT_UST_TESTS_DEMO3_H */ - -#undef TRACEPOINT_INCLUDE_FILE -#define TRACEPOINT_INCLUDE_FILE ./ust_tests_demo3.h - -/* This part must be outside ifdef protection */ -#include - -#ifdef __cplusplus -} -#endif diff --git a/tests/ust/overlap/overlap.sh b/tests/ust/overlap/overlap.sh deleted file mode 100755 index ebe6cfd1a..000000000 --- a/tests/ust/overlap/overlap.sh +++ /dev/null @@ -1,693 +0,0 @@ -#!/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 -TEST_DESC="UST - Wildcard overlap" - -CURDIR=$(dirname $0)/ -TESTDIR=$CURDIR/../.. -SESSION_NAME="wildcard-overlap" - -DEMO_EVENT1="ust_tests_demo:starting" -DEMO_EVENT1_2="ust_tests_demo:done" -DEMO_EVENT2="ust_tests_demo2:loop" -DEMO_EVENT3="ust_tests_demo3:done" - -NUM_DEMO1_EVENT=1 -NUM_DEMO1_2_EVENT=1 -NUM_DEMO2_EVENT=5 -NUM_DEMO3_EVENT=1 - -source $TESTDIR/utils.sh - -print_test_banner "$TEST_DESC" - -if [ ! -x "$CURDIR/demo/demo" ]; then - echo -e "No UST nevents binary detected. Passing." - exit 0 -fi - -# MUST set TESTDIR before calling those functions - -run_demo_app() -{ - cd $CURDIR/demo - - # Start test - echo -n "Starting application... " - ./demo-trace >/dev/null 2>&1 - echo -n "Ended " - print_ok - - cd - -} - -# Ease our life a bit ;) -trace_match_demo1_events() -{ - trace_matches "$DEMO_EVENT1" $NUM_DEMO1_EVENT $TRACE_PATH - trace_matches "$DEMO_EVENT1_2" $NUM_DEMO1_EVENT $TRACE_PATH -} - -# Ease our life a bit ;) -trace_match_all_demo_events() -{ - trace_match_demo1_events - trace_matches "$DEMO_EVENT2" $NUM_DEMO2_EVENT $TRACE_PATH - trace_matches "$DEMO_EVENT3" $NUM_DEMO3_EVENT $TRACE_PATH -} - -# Ease our life a bit ;) -trace_match_no_demo_events() -{ - trace_matches "$DEMO_EVENT1" 0 $TRACE_PATH - trace_matches "$DEMO_EVENT1_2" 0 $TRACE_PATH - trace_matches "$DEMO_EVENT2" 0 $TRACE_PATH - trace_matches "$DEMO_EVENT3" 0 $TRACE_PATH -} - -# Expect all "demo" events, no duplicate. -test_enable_simple_wildcard() -{ - local event_wild1="us*" - local event_wild2="ust*" - - echo "" - echo "=== Simple wildcard overlap" - - enable_ust_lttng_event $SESSION_NAME "$event_wild1" - enable_ust_lttng_event $SESSION_NAME "$event_wild2" - - start_lttng_tracing $SESSION_NAME >/dev/null 2>&1 - - run_demo_app - - stop_lttng_tracing $SESSION_NAME >/dev/null 2>&1 - - trace_match_all_demo_events - - return $? -} - -# Expect all "demo" events, no duplicate. -test_enable_wildcard_filter() -{ - local event_wild1="us*" - local event_wild2="ust*" - - echo "" - echo "=== Wildcard overlap with filter" - - enable_ust_lttng_event_filter $SESSION_NAME "$event_wild1" "1==1" - enable_ust_lttng_event_filter $SESSION_NAME "$event_wild2" "1==0" - - start_lttng_tracing $SESSION_NAME >/dev/null 2>&1 - - run_demo_app - - stop_lttng_tracing $SESSION_NAME >/dev/null 2>&1 - - trace_match_all_demo_events - return $? -} - -# Expect all "demo" events, no duplicate. -test_enable_wildcard_filter_2() -{ - local event_wild1="us*" - local event_wild2="ust*" - - echo "" - echo "=== Wildcard overlap with filter 2" - - enable_ust_lttng_event_filter $SESSION_NAME "$event_wild1" "1==0" - enable_ust_lttng_event_filter $SESSION_NAME "$event_wild2" "1==1" - - start_lttng_tracing $SESSION_NAME >/dev/null 2>&1 - - run_demo_app - - stop_lttng_tracing $SESSION_NAME >/dev/null 2>&1 - - trace_match_all_demo_events - return $? -} - -# Expect all "demo" events, no duplicate. -test_enable_wildcard_filter_3() -{ - local event_wild1="us*" - local event_wild2="ust*" - - echo "" - echo "=== Wildcard overlap with filter 3" - - enable_ust_lttng_event_filter $SESSION_NAME "$event_wild1" "1==1" - enable_ust_lttng_event_filter $SESSION_NAME "$event_wild2" "1==1" - - start_lttng_tracing $SESSION_NAME >/dev/null 2>&1 - - run_demo_app - - stop_lttng_tracing $SESSION_NAME >/dev/null 2>&1 - - trace_match_all_demo_events - return $? -} - -# Expected: No events. -test_enable_wildcard_filter_4() -{ - local event_wild1="us*" - local event_wild2="ust*" - - echo "" - echo "=== Wildcard overlap with filter 4" - - enable_ust_lttng_event_filter $SESSION_NAME "$event_wild1" "1==0" - enable_ust_lttng_event_filter $SESSION_NAME "$event_wild2" "1==0" - - start_lttng_tracing $SESSION_NAME >/dev/null 2>&1 - - run_demo_app - - stop_lttng_tracing $SESSION_NAME >/dev/null 2>&1 - - trace_match_no_demo_events - return $? -} - -# Expect all "demo" events, no duplicate. -test_enable_wildcard_filter_5() -{ - local event_wild1="us*" - local event_wild2="$DEMO_EVENT1" - - echo "" - echo "=== Wildcard overlap with filter 5" - - enable_ust_lttng_event_filter $SESSION_NAME "$event_wild1" "1==1" - enable_ust_lttng_event_filter $SESSION_NAME "$event_wild2" "1==0" - - start_lttng_tracing $SESSION_NAME >/dev/null 2>&1 - - run_demo_app - - stop_lttng_tracing $SESSION_NAME >/dev/null 2>&1 - - trace_match_all_demo_events - return $? -} - -# Expect all $DEMO_EVENT1 events, no duplicate. -test_enable_wildcard_filter_6() -{ - local event_wild1="us*" - local event_wild2="$DEMO_EVENT1" - - echo "" - echo "=== Wildcard overlap with filter 6" - - enable_ust_lttng_event_filter $SESSION_NAME "$event_wild1" "1==0" - enable_ust_lttng_event_filter $SESSION_NAME "$event_wild2" "1==1" - - start_lttng_tracing $SESSION_NAME >/dev/null 2>&1 - - run_demo_app - - stop_lttng_tracing $SESSION_NAME >/dev/null 2>&1 - - trace_matches $DEMO_EVENT1 $NUM_DEMO1_EVENT $TRACE_PATH - trace_matches $DEMO_EVENT1_2 0 $TRACE_PATH - trace_matches $DEMO_EVENT2 0 $TRACE_PATH - trace_matches $DEMO_EVENT3 0 $TRACE_PATH - return $? -} - -# Expect all events, no duplicate. -test_enable_wildcard_filter_7() -{ - local event_wild1="us*" - local event_wild2="$DEMO_EVENT1" - - echo "" - echo "=== Wildcard overlap with filter 7" - - enable_ust_lttng_event_filter $SESSION_NAME "$event_wild1" "1==1" - enable_ust_lttng_event_filter $SESSION_NAME "$event_wild2" "1==1" - - start_lttng_tracing $SESSION_NAME >/dev/null 2>&1 - - run_demo_app - - stop_lttng_tracing $SESSION_NAME >/dev/null 2>&1 - - trace_match_all_demo_events - return $? -} - -# Expected: No events. -test_enable_wildcard_filter_8() -{ - local event_wild1="us*" - local event_wild2="$DEMO_EVENT1" - - echo "" - echo "=== Wildcard overlap with filter 8" - - enable_ust_lttng_event_filter $SESSION_NAME "$event_wild1" "1==0" - enable_ust_lttng_event_filter $SESSION_NAME "$event_wild2" "1==0" - - start_lttng_tracing $SESSION_NAME >/dev/null 2>&1 - - run_demo_app - - stop_lttng_tracing $SESSION_NAME >/dev/null 2>&1 - - trace_match_no_demo_events - return $? -} - -# Expect all events. -test_enable_same_wildcard_filter() -{ - local event_wild1="ust*" - local event_wild2="ust*" - - echo "" - echo "=== Same wildcard overlap with filter" - - enable_ust_lttng_event_filter $SESSION_NAME "$event_wild1" "1==1&&1==1" - enable_ust_lttng_event_filter $SESSION_NAME "$event_wild2" "1==1" - - start_lttng_tracing $SESSION_NAME >/dev/null 2>&1 - - run_demo_app - - stop_lttng_tracing $SESSION_NAME >/dev/null 2>&1 - - trace_match_all_demo_events - return $? -} - -# Expect all events. -test_enable_same_wildcard_filter_2() -{ - local event_wild1="ust*" - local event_wild2="ust*" - - echo "" - echo "=== Same wildcard overlap with filter 2" - - enable_ust_lttng_event_filter $SESSION_NAME "$event_wild1" "1==1" - enable_ust_lttng_event_filter $SESSION_NAME "$event_wild2" "1==1" - if [ $? -eq 1 ]; then - echo -n "FAIL is normal. Same event with same filter is denied by the sessiond " - print_ok - else - print_fail - fi - - start_lttng_tracing $SESSION_NAME >/dev/null 2>&1 - - run_demo_app - - stop_lttng_tracing $SESSION_NAME >/dev/null 2>&1 - - trace_match_all_demo_events - return $? -} - -# Expect all events. -test_enable_same_wildcard_filter_3() -{ - local event_wild1="ust*" - local event_wild2="ust*" - - echo "" - echo "=== Same wildcard overlap with filter 3" - - enable_ust_lttng_event_filter $SESSION_NAME "$event_wild1" "1==1" - enable_ust_lttng_event_filter $SESSION_NAME "$event_wild2" "1==0" - - start_lttng_tracing $SESSION_NAME >/dev/null 2>&1 - - run_demo_app - - stop_lttng_tracing $SESSION_NAME >/dev/null 2>&1 - - trace_match_all_demo_events - return $? -} - -# Expected: No events. -test_enable_same_wildcard_filter_4() -{ - local event_wild1="ust*" - local event_wild2="ust*" - - echo "" - echo "=== Same wildcard overlap with filter 4" - - enable_ust_lttng_event_filter $SESSION_NAME "$event_wild1" "1==0&&1==0" - enable_ust_lttng_event_filter $SESSION_NAME "$event_wild2" "1==0" - - start_lttng_tracing $SESSION_NAME >/dev/null 2>&1 - - run_demo_app - - stop_lttng_tracing $SESSION_NAME >/dev/null 2>&1 - - trace_match_no_demo_events - return $? -} - -# Expected: Only $DEMO_EVENT1 -test_enable_same_event_filter() -{ - local event_wild1="$DEMO_EVENT1" - local event_wild2="$DEMO_EVENT1" - - echo "" - echo "=== Enable same event with filter." - - enable_ust_lttng_event_filter $SESSION_NAME "$event_wild1" "1==1&&1==1" - enable_ust_lttng_event_filter $SESSION_NAME "$event_wild2" "1==1" - - disable_ust_lttng_event $SESSION_NAME "ust*" - - start_lttng_tracing $SESSION_NAME >/dev/null 2>&1 - - run_demo_app - - stop_lttng_tracing $SESSION_NAME >/dev/null 2>&1 - - trace_matches $DEMO_EVENT1 $NUM_DEMO1_EVENT $TRACE_PATH - trace_matches $DEMO_EVENT1_2 0 $TRACE_PATH - trace_matches $DEMO_EVENT2 0 $TRACE_PATH - trace_matches $DEMO_EVENT3 0 $TRACE_PATH - return $? -} - -# Expected: No events. -test_disable_same_wildcard_filter() -{ - local event_wild1="ust*" - local event_wild2="ust*" - - echo "" - echo "=== Disable same wildcard with filter." - - enable_ust_lttng_event_filter $SESSION_NAME "$event_wild1" "1==1&&1==1" - enable_ust_lttng_event_filter $SESSION_NAME "$event_wild2" "1==1" - - disable_ust_lttng_event $SESSION_NAME "ust*" - - start_lttng_tracing $SESSION_NAME >/dev/null 2>&1 - - run_demo_app - - stop_lttng_tracing $SESSION_NAME >/dev/null 2>&1 - - trace_match_no_demo_events - return $? -} - -# Expect no events -test_enable_bad_wildcard() -{ - # Invalid event - local event_wild1="ust_tests_demo" - local event_wild2="ust_tests_demo2" - local event_wild3="ust_tests_demo3" - - echo "" - echo "=== Enable bad wildcard" - - enable_ust_lttng_event $SESSION_NAME "$event_wild1" - enable_ust_lttng_event $SESSION_NAME "$event_wild2" - enable_ust_lttng_event $SESSION_NAME "$event_wild3" - - start_lttng_tracing $SESSION_NAME >/dev/null 2>&1 - - run_demo_app - - stop_lttng_tracing $SESSION_NAME >/dev/null 2>&1 - - trace_match_no_demo_events - return $? -} - -# Expect all "demo" events, no duplicate. -test_enable_simple_wildcard_2() -{ - local event_wild1="us*" - local event_wild2="$DEMO_EVENT1" - - echo "" - echo "=== Simple wildcard 2" - - enable_ust_lttng_event $SESSION_NAME "$event_wild1" - enable_ust_lttng_event $SESSION_NAME "$event_wild2" - - start_lttng_tracing $SESSION_NAME >/dev/null 2>&1 - - run_demo_app - - stop_lttng_tracing $SESSION_NAME >/dev/null 2>&1 - - trace_match_all_demo_events - return $? -} - -# Expected: all CRIT events, + all warning events. -test_enable_loglevel_overlap() -{ - local event_wild1="us*" - local event_wild2="ust*" - - echo "" - echo "=== Enable loglevel overlap" - - enable_ust_lttng_event_loglevel $SESSION_NAME "$event_wild1" "TRACE_WARNING" - enable_ust_lttng_event_loglevel $SESSION_NAME "$event_wild2" "TRACE_CRIT" - - start_lttng_tracing $SESSION_NAME >/dev/null 2>&1 - - run_demo_app - - stop_lttng_tracing $SESSION_NAME >/dev/null 2>&1 - - trace_match_all_demo_events - return $? -} - -# Expected: all CRIT events, + all warning events. -test_enable_loglevel_only_overlap() -{ - local event_wild1="us*" - local event_wild2="ust*" - - echo "" - echo "=== Enable loglevel only overlap" - - enable_ust_lttng_event_loglevel $SESSION_NAME "$event_wild1" "TRACE_WARNING" - enable_ust_lttng_event_loglevel_only $SESSION_NAME "$event_wild2" "TRACE_CRIT" - - start_lttng_tracing $SESSION_NAME >/dev/null 2>&1 - - run_demo_app - - stop_lttng_tracing $SESSION_NAME >/dev/null 2>&1 - - trace_match_all_demo_events - return $? -} - -# Expected: all events -test_enable_loglevel_overlap_2() -{ - local event_wild1="us*" - local event_wild2="$DEMO_EVENT2" - - echo "" - echo "=== Enable loglevel overlap 2" - - enable_ust_lttng_event_loglevel $SESSION_NAME "$event_wild1" "TRACE_WARNING" - enable_ust_lttng_event_loglevel $SESSION_NAME "$event_wild2" "TRACE_CRIT" - - start_lttng_tracing $SESSION_NAME >/dev/null 2>&1 - - run_demo_app - - stop_lttng_tracing $SESSION_NAME >/dev/null 2>&1 - - trace_match_all_demo_events - return $? -} - -# Expected only ust_tests_demo* events. -test_enable_same_wildcard_loglevels() -{ - local event_wild1="ust*" - local event_wild2="ust*" - - echo "" - echo "=== Enable same wildcard with different loglevels" - - enable_ust_lttng_event_loglevel $SESSION_NAME "$event_wild1" "TRACE_CRIT" - enable_ust_lttng_event_loglevel $SESSION_NAME "$event_wild2" "TRACE_WARNING" - - start_lttng_tracing $SESSION_NAME >/dev/null 2>&1 - - run_demo_app - - stop_lttng_tracing $SESSION_NAME >/dev/null 2>&1 - - trace_match_all_demo_events - return $? -} - -# Expected only ust_tests_demo:starting events. -test_enable_same_event_loglevels() -{ - local event_wild1="$DEMO_EVENT1" - local event_wild2="$DEMO_EVENT1" - - echo "" - echo "=== Enable same event with different loglevels" - - enable_ust_lttng_event_loglevel $SESSION_NAME "$event_wild1" "TRACE_CRIT" - enable_ust_lttng_event_loglevel $SESSION_NAME "$event_wild2" "TRACE_WARNING" - - start_lttng_tracing $SESSION_NAME >/dev/null 2>&1 - - run_demo_app - - stop_lttng_tracing $SESSION_NAME >/dev/null 2>&1 - - trace_matches $DEMO_EVENT1 $NUM_DEMO1_EVENT $TRACE_PATH - trace_matches $DEMO_EVENT1_2 0 $TRACE_PATH - trace_matches $DEMO_EVENT2 0 $TRACE_PATH - trace_matches $DEMO_EVENT3 0 $TRACE_PATH - return $? -} - -# Expect 0 event -test_disable_simple_wildcard() -{ - local event_wild1="us*" - local event_wild2="$DEMO_EVENT1" - - echo "" - echo "=== Disable simple wildcard" - - enable_ust_lttng_event $SESSION_NAME "$event_wild1" - enable_ust_lttng_event $SESSION_NAME "$event_wild2" - - disable_ust_lttng_event $SESSION_NAME "$event_wild1" - disable_ust_lttng_event $SESSION_NAME "$event_wild2" - - start_lttng_tracing $SESSION_NAME >/dev/null 2>&1 - - run_demo_app - - stop_lttng_tracing $SESSION_NAME >/dev/null 2>&1 - - # No events are expected. - trace_match_no_demo_events - return $? -} - -# Expect only "ust_tests_demo" events. -test_disable_wildcard_overlap() -{ - local event_wild1="us*" - local event_wild2="$DEMO_EVENT1" - - echo "" - echo "=== Disable wildcard overlap" - - enable_ust_lttng_event $SESSION_NAME "$event_wild1" - enable_ust_lttng_event $SESSION_NAME "$event_wild2" - - disable_ust_lttng_event $SESSION_NAME "$event_wild1" - - start_lttng_tracing $SESSION_NAME >/dev/null 2>&1 - - run_demo_app - - stop_lttng_tracing $SESSION_NAME >/dev/null 2>&1 - - # Expect only "ust_tests_demo" events. - trace_matches "$DEMO_EVENT1" $NUM_DEMO1_EVENT $TRACE_PATH - trace_matches "$DEMO_EVENT1_2" 0 $TRACE_PATH - trace_matches "$DEMO_EVENT2" 0 $TRACE_PATH - trace_matches "$DEMO_EVENT3" 0 $TRACE_PATH - return $? -} - -TESTS=( - "test_enable_wildcard_filter" - "test_enable_wildcard_filter_2" - "test_enable_wildcard_filter_3" - "test_enable_wildcard_filter_4" - "test_enable_wildcard_filter_5" - "test_enable_wildcard_filter_6" - "test_enable_wildcard_filter_7" - "test_enable_wildcard_filter_8" - "test_enable_same_wildcard_filter" - "test_enable_same_wildcard_filter_2" - "test_enable_same_wildcard_filter_3" - "test_enable_same_wildcard_filter_4" - "test_enable_same_event_filter" - "test_enable_loglevel_only_overlap" - "test_enable_same_event_loglevels" - "test_enable_same_wildcard_loglevels" - "test_enable_bad_wildcard" - "test_enable_loglevel_overlap_2" - "test_enable_simple_wildcard" - "test_enable_simple_wildcard_2" - "test_enable_loglevel_overlap" - "test_disable_simple_wildcard" - "test_disable_wildcard_overlap" -) - -TEST_COUNT=${#TESTS[@]} -i=0 - -start_lttng_sessiond - -while [ "$i" -lt "$TEST_COUNT" ]; do - - TRACE_PATH=$(mktemp -d) - - create_lttng_session $SESSION_NAME $TRACE_PATH >/dev/null 2>&1 - - # Execute test - ${TESTS[$i]} - if [ $? -ne 0 ]; then - stop_lttng_sessiond - exit 1 - fi - - destroy_lttng_session $SESSION_NAME >/dev/null 2>&1 - - rm -rf $TRACE_PATH - - let "i++" -done - -stop_lttng_sessiond diff --git a/tests/ust/overlap/run b/tests/ust/overlap/run deleted file mode 100755 index ca8efb34f..000000000 --- a/tests/ust/overlap/run +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/bash - -DIR=$(dirname $0) - -tests=( $DIR/overlap.sh) - -exit_code=0 - -function start_tests () -{ - for bin in ${tests[@]}; - do - ./$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/ust/run-ust-global-tests.sh b/tests/ust/run-ust-global-tests.sh deleted file mode 100755 index e1a54ad61..000000000 --- a/tests/ust/run-ust-global-tests.sh +++ /dev/null @@ -1,44 +0,0 @@ -#!/bin/bash - -SESSIOND_BIN="lttng-sessiond" -CURDIR=$(dirname $0) -TESTDIR=$CURDIR/.. - -source $TESTDIR/utils.sh - -tmpdir=`mktemp -d` -tests=( $CURDIR/ust_global_event_basic $CURDIR/ust_global_event_wildcard ) -exit_code=0 - -function start_tests () -{ - for bin in ${tests[@]}; - do - if [ ! -e $bin ]; then - echo -e "$bin not found, passing" - continue - fi - - start_lttng_sessiond - - ./$bin $tmpdir - # Test must return 0 to pass. - if [ $? -ne 0 ]; then - exit_code=1 - stop_lttng_sessiond - break - fi - stop_lttng_sessiond - done - - # Cleaning up - rm -rf $tmpdir -} - -TEST_DESC="UST tracer - Global domain (LTTNG_DOMAIN_UST)" - -print_test_banner "$TEST_DESC" - -start_tests - -exit $exit_code diff --git a/tests/ust/runall.sh b/tests/ust/runall.sh deleted file mode 100755 index 01afceca7..000000000 --- a/tests/ust/runall.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/bash - -DIR=$(dirname $0) - -tests=( $DIR/run-ust-global-tests.sh $DIR/nprocesses/run \ - $DIR/high-throughput/run $DIR/before-after/run \ - $DIR/multi-session/run $DIR/overlap/run ) - -# $DIR/low-throughput/run --> DEACTIVATED. -# Use only for release. This test last 20 minutes - -exit_code=0 - -function start_tests () -{ - for bin in ${tests[@]}; - do - ./$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/ust/ust_global_event_basic.c b/tests/ust/ust_global_event_basic.c deleted file mode 100644 index ad14afbb3..000000000 --- a/tests/ust/ust_global_event_basic.c +++ /dev/null @@ -1,299 +0,0 @@ -/* - * 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 - -#include "../utils.h" - -int lttng_opt_quiet; - -int main(int argc, char **argv) -{ - struct lttng_handle *handle = NULL; - struct lttng_domain dom; - struct lttng_channel channel, channel2; - struct lttng_event ev1, ev2, ev3; - struct lttng_event_context context; - char *session_name = "ust_global_event_basic"; - char *session_name2 = "ust_global_event_basic2"; - int ret = 0; - - memset(&dom, 0, sizeof(dom)); - memset(&channel, 0, sizeof(channel)); - memset(&channel2, 0, sizeof(channel2)); - memset(&ev1, 0, sizeof(ev1)); - memset(&ev2, 0, sizeof(ev2)); - memset(&ev3, 0, sizeof(ev3)); - memset(&context, 0, sizeof(context)); - - dom.type = LTTNG_DOMAIN_UST; - - /* Setup channel 1 */ - strcpy(channel.name, "mychan"); - channel.attr.overwrite = 0; - channel.attr.subbuf_size = 4096; - channel.attr.num_subbuf = 4; - channel.attr.switch_timer_interval = 0; - channel.attr.read_timer_interval = 200; - channel.attr.output = LTTNG_EVENT_MMAP; - - /* Setup channel 2 */ - strcpy(channel2.name, "mychan2"); - channel2.attr.overwrite = 0; - channel2.attr.subbuf_size = 8192; - channel2.attr.num_subbuf = 8; - channel2.attr.switch_timer_interval = 0; - channel2.attr.read_timer_interval = 500; - channel2.attr.output = LTTNG_EVENT_MMAP; - - strcpy(ev1.name, "tp1"); - ev1.type = LTTNG_EVENT_TRACEPOINT; - ev1.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL; - - strcpy(ev2.name, "ev2"); - ev2.type = LTTNG_EVENT_TRACEPOINT; - ev2.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL; - - strcpy(ev3.name, "ev3"); - ev3.type = LTTNG_EVENT_TRACEPOINT; - ev3.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL; - - printf("\nTesting tracing UST events:\n"); - printf("-----------\n"); - - if (argc < 2) { - printf("Missing session trace path\n"); - return 1; - } - - printf("Creating tracing session (%s): ", argv[1]); - 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 tracing session 2 (%s): ", argv[1]); - if ((ret = lttng_create_session(session_name2, 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(session_name, &dom)) == NULL) { - printf("error creating handle: %s\n", lttng_strerror(ret)); - goto handle_fail; - } - PRINT_OK(); - - printf("Enabling %s UST channel: ", channel.name); - if ((ret = lttng_enable_channel(handle, &channel)) < 0) { - printf("error enable channel: %s\n", lttng_strerror(ret)); - goto enable_fail; - } - PRINT_OK(); - - printf("Enabling %s UST channel2: ", channel2.name); - if ((ret = lttng_enable_channel(handle, &channel2)) < 0) { - printf("error enable channel: %s\n", lttng_strerror(ret)); - goto enable_fail; - } - PRINT_OK(); - - printf("Enabling %s UST event in channel %s: ", ev1.name, channel.name); - if ((ret = lttng_enable_event(handle, &ev1, channel.name)) < 0) { - printf("error enabling event: %s\n", lttng_strerror(ret)); - goto enable_fail; - } - PRINT_OK(); - - printf("Enabling %s UST event in channel %s: ", ev2.name, channel.name); - if ((ret = lttng_enable_event(handle, &ev2, channel.name)) < 0) { - printf("error enabling event: %s\n", lttng_strerror(ret)); - goto enable_fail; - } - PRINT_OK(); - - printf("Enabling %s UST event in channel %s: ", ev3.name, channel2.name); - if ((ret = lttng_enable_event(handle, &ev3, channel2.name)) < 0) { - printf("error enabling event: %s\n", lttng_strerror(ret)); - goto enable_fail; - } - PRINT_OK(); - - context.ctx = LTTNG_EVENT_CONTEXT_VPID; - - printf("Adding context VPID to UST event %s in channel %s: ", ev1.name, - channel.name); - if ((ret = lttng_add_context(handle, &context, ev1.name, - channel.name)) < 0) { - printf("error adding context VPID: %s\n", lttng_strerror(ret)); - goto context_fail; - } - PRINT_OK(); - - context.ctx = LTTNG_EVENT_CONTEXT_VTID; - - printf("Adding context VTID to UST event %s in channel %s: ", ev1.name, - channel.name); - if ((ret = lttng_add_context(handle, &context, ev1.name, - channel.name)) < 0) { - printf("error adding context VTID: %s\n", lttng_strerror(ret)); - goto context_fail; - } - PRINT_OK(); - - context.ctx = LTTNG_EVENT_CONTEXT_PTHREAD_ID; - - printf("Adding context PTHREAD_ID to UST event %s in channel %s: ", - ev1.name, channel.name); - if ((ret = lttng_add_context(handle, &context, ev1.name, - channel.name)) < 0) { - printf("error adding context PTHREAD_ID: %s\n", lttng_strerror(ret)); - goto context_fail; - } - PRINT_OK(); - - context.ctx = LTTNG_EVENT_CONTEXT_PROCNAME; - - printf("Adding context PROCNAME to UST event %s in channel %s: ", - ev1.name, channel.name); - if ((ret = lttng_add_context(handle, &context, ev1.name, - channel.name)) < 0) { - printf("error adding context PROCNAME: %s\n", lttng_strerror(ret)); - goto context_fail; - } - PRINT_OK(); - - context.ctx = LTTNG_EVENT_CONTEXT_PROCNAME; - - printf("Adding context PROCNAME to UST event %s in channel %s: ", - ev3.name, channel2.name); - if ((ret = lttng_add_context(handle, &context, ev3.name, - channel2.name)) < 0) { - printf("error adding context PROCNAME: %s\n", lttng_strerror(ret)); - goto context_fail; - } - PRINT_OK(); - - printf("Disabling %s UST event: ", ev1.name); - if ((ret = lttng_disable_event(handle, ev1.name, channel.name)) < 0) { - printf("error enabling event: %s\n", lttng_strerror(ret)); - goto enable_fail; - } - PRINT_OK(); - - printf("Disabling %s UST event: ", ev3.name); - if ((ret = lttng_disable_event(handle, ev3.name, channel2.name)) < 0) { - printf("error enabling event: %s\n", lttng_strerror(ret)); - goto enable_fail; - } - PRINT_OK(); - - printf("Renabling %s UST event: ", ev1.name); - if ((ret = lttng_enable_event(handle, &ev1, channel.name)) < 0) { - printf("error enabling event: %s\n", lttng_strerror(ret)); - goto enable_fail; - } - PRINT_OK(); - - printf("Renabling %s UST event: ", ev3.name); - if ((ret = lttng_enable_event(handle, &ev3, channel.name)) < 0) { - printf("error enabling event: %s\n", lttng_strerror(ret)); - goto enable_fail; - } - PRINT_OK(); - - printf("Disabling channel %s: ", channel2.name); - if ((ret = lttng_disable_channel(handle, channel2.name)) < 0) { - printf("error disabling channel: %s\n", lttng_strerror(ret)); - goto enable_fail; - } - PRINT_OK(); - - printf("Start tracing: "); - if ((ret = lttng_start_tracing(session_name)) < 0) { - printf("error starting tracing: %s\n", lttng_strerror(ret)); - goto start_fail; - } - PRINT_OK(); - - sleep(2); - - printf("Stop tracing: "); - if ((ret = lttng_stop_tracing(session_name)) < 0) { - printf("error stopping tracing: %s\n", lttng_strerror(ret)); - goto stop_fail; - } - PRINT_OK(); - - printf("Restart tracing: "); - if ((ret = lttng_start_tracing(session_name)) < 0) { - printf("error starting tracing: %s\n", lttng_strerror(ret)); - goto start_fail; - } - PRINT_OK(); - - sleep(2); - - printf("Stop tracing: "); - 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 2: "); - if ((ret = lttng_destroy_session(session_name2)) < 0) { - printf("error destroying session 2: %s\n", lttng_strerror(ret)); - } - PRINT_OK(); - - printf("Destroy tracing session: "); - if ((ret = lttng_destroy_session(session_name)) < 0) { - printf("error destroying session: %s\n", lttng_strerror(ret)); - } - PRINT_OK(); - - return 0; - -handle_fail: - assert(handle != NULL); -create_fail: - assert(ret != 0); - -stop_fail: -start_fail: -context_fail: -enable_fail: - lttng_destroy_session(session_name2); - lttng_destroy_session(session_name); - lttng_destroy_handle(handle); - - return 1; -} diff --git a/tests/ust/ust_global_event_wildcard.c b/tests/ust/ust_global_event_wildcard.c deleted file mode 100644 index 198a54168..000000000 --- a/tests/ust/ust_global_event_wildcard.c +++ /dev/null @@ -1,131 +0,0 @@ -/* - * 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 - -#include "utils.h" - -int lttng_opt_quiet; - -int main(int argc, char **argv) -{ - struct lttng_handle *handle = NULL; - struct lttng_domain dom; - struct lttng_event event, ev2; - char *channel_name = "channel0"; - char *channel_name2 = "channel2"; - char *session_name = "ust_global_all_events_basic"; - int ret = 0; - - memset(&dom, 0, sizeof(dom)); - memset(&event, 0, sizeof(event)); - memset(&ev2, 0, sizeof(ev2)); - - dom.type = LTTNG_DOMAIN_UST; - - event.type = LTTNG_EVENT_TRACEPOINT; - event.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL; - strcpy(event.name, "*"); - - ev2.type = LTTNG_EVENT_TRACEPOINT; - ev2.loglevel_type = LTTNG_EVENT_LOGLEVEL_RANGE; - ev2.loglevel = LTTNG_LOGLEVEL_NOTICE; - strcpy(ev2.name, "abc*"); - - printf("\nTesting tracing all UST events:\n"); - printf("-----------\n"); - - if (argc < 2) { - printf("Missing session trace path\n"); - return 1; - } - - printf("Creating tracing session (%s): ", argv[1]); - 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(session_name, &dom)) == NULL) { - printf("error creating handle: %s\n", lttng_strerror(ret)); - goto handle_fail; - } - PRINT_OK(); - - printf("Enabling '*' UST events: "); - if ((ret = lttng_enable_event(handle, &event, channel_name)) < 0) { - printf("error enabling event: %s\n", lttng_strerror(ret)); - goto enable_fail; - } - PRINT_OK(); - - printf("Enabling 'abc*' UST events: "); - if ((ret = lttng_enable_event(handle, &ev2, channel_name2)) < 0) { - printf("error enabling event: %s\n", lttng_strerror(ret)); - goto enable_fail; - } - PRINT_OK(); - - printf("Start tracing: "); - if ((ret = lttng_start_tracing(session_name)) < 0) { - printf("error starting tracing: %s\n", lttng_strerror(ret)); - goto start_fail; - } - PRINT_OK(); - - sleep(2); - - printf("Stop tracing: "); - 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(session_name)) < 0) { - printf("error destroying session: %s\n", lttng_strerror(ret)); - } - PRINT_OK(); - - return 0; - -handle_fail: - assert(handle != NULL); -create_fail: - assert(ret != 0); - -stop_fail: -start_fail: -enable_fail: - lttng_destroy_session(session_name); - lttng_destroy_handle(handle); - - return 1; -} diff --git a/tests/utils.h b/tests/utils.h deleted file mode 100644 index 94891c0c6..000000000 --- a/tests/utils.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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. - */ - -#include -#include - -#define BRIGHT 1 -#define GREEN 32 -#define RED 31 - -#define PRINT_OK() \ -do { \ - /* Check for color support */ \ - if (isatty(STDOUT_FILENO)) { \ - printf("%c[%d;%dmOK%c[%dm\n", 0x1B, BRIGHT, GREEN, 0x1B, 0); \ - } else { \ - printf("OK\n"); \ - } \ -} while (0) - -#define PRINT_FAIL() \ -do { \ - /* Check for color support */ \ - if (isatty(STDOUT_FILENO)) { \ - printf("%c[%d;%dmFAIL%c[%dm\n", 0x1B, BRIGHT, RED, 0x1B, 0); \ - } else { \ - printf("FAIL\n"); \ - } \ -} while (0) diff --git a/tests/utils.sh b/tests/utils.sh deleted file mode 100644 index 3bcdcc479..000000000 --- a/tests/utils.sh +++ /dev/null @@ -1,433 +0,0 @@ -#!/src/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" -RELAYD_BIN="lttng-relayd" -LTTNG_BIN="lttng" -BABELTRACE_BIN="babeltrace" - -# Minimal kernel version supported for session daemon tests -KERNEL_MAJOR_VERSION=2 -KERNEL_MINOR_VERSION=6 -KERNEL_PATCHLEVEL_VERSION=27 - -function print_ok () -{ - # Check if we are a terminal - if [ -t 1 ]; then - echo -e "\e[1;32mOK\e[0m" - else - echo -e "OK" - fi -} - -function print_fail () -{ - # Check if we are a terminal - if [ -t 1 ]; then - echo -e "\e[1;31mFAIL\e[0m" - else - echo -e "FAIL" - fi -} - -function print_test_banner () -{ - desc="$1" - - count=$((${#desc}+2)) - str=$(printf "%${count}s"); - echo -e "\n" - echo -e ${str// /-} - echo -e " $desc " - echo -e ${str// /-} -} - -function validate_kernel_version () -{ - kern_version=($(uname -r | awk -F. '{ printf("%d.%d.%d\n",$1,$2,$3); }' | tr '.' '\n')) - if [ ${kern_version[0]} -gt $KERNEL_MAJOR_VERSION ]; then - return 0 - fi - if [ ${kern_version[1]} -gt $KERNEL_MINOR_VERSION ]; then - return 0 - fi - if [ ${kern_version[2]} -ge $KERNEL_PATCHLEVEL_VERSION ]; then - return 0 - fi - 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 "" - echo -n "Starting session daemon... " - validate_kernel_version - if [ $? -ne 0 ]; then - echo -e "\n*** Kernel too old for session daemon tests ***\n" - return 2 - fi - - DIR=$(readlink -f $TESTDIR) - - if [ -z $(pidof lt-$SESSIOND_BIN) ]; then - $DIR/../src/bin/lttng-sessiond/$SESSIOND_BIN --daemonize --quiet --consumerd32-path="$DIR/../src/bin/lttng-consumerd/lttng-consumerd" --consumerd64-path="$DIR/../src/bin/lttng-consumerd/lttng-consumerd" - #$DIR/../src/bin/lttng-sessiond/$SESSIOND_BIN --consumerd32-path="$DIR/../src/bin/lttng-consumerd/lttng-consumerd" --consumerd64-path="$DIR/../src/bin/lttng-consumerd/lttng-consumerd" --verbose-consumer >>/tmp/sessiond.log 2>&1 & - if [ $? -eq 1 ]; then - print_fail - return 1 - else - print_ok - fi - fi - - 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 - print_fail - return 1 - else - print_ok - fi -} - -function start_lttng_relayd -{ - local opt=$1 - - echo -e -n "Starting lttng-relayd (opt: $opt)... " - - DIR=$(readlink -f $TESTDIR) - - if [ -z $(pidof lt-$RELAYD_BIN) ]; then - $DIR/../src/bin/lttng-relayd/$RELAYD_BIN $opt >/dev/null 2>&1 & - #$DIR/../src/bin/lttng-relayd/$RELAYD_BIN $opt -vvv >>/tmp/relayd.log 2>&1 & - if [ $? -eq 1 ]; then - print_fail - return 1 - else - print_ok - fi - else - print_ok - fi -} - -function stop_lttng_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 - print_fail - return 1 - else - out=1 - while [ -n "$out" ]; do - out=$(pidof lt-$RELAYD_BIN) - sleep 0.5 - done - print_ok - return 0 - fi -} - -function start_lttng_sessiond() -{ - if [ -n $TEST_NO_SESSIOND ] && [ "$TEST_NO_SESSIOND" == "1" ]; then - # Env variable requested no session daemon - return - fi - - spawn_sessiond - out=$? - if [ $out -eq 2 ]; then - # Kernel version is not compatible. - exit 0 - elif [ $out -ne 0 ]; then - echo "NOT bad $?" - exit 1 - fi - - # Simply wait for the session daemon bootstrap - echo "Waiting for the session daemon to bootstrap (2 secs)" - sleep 2 -} - -function stop_lttng_sessiond () -{ - if [ -n $TEST_NO_SESSIOND ] && [ "$TEST_NO_SESSIOND" == "1" ]; then - # Env variable requested no session daemon - return - fi - - PID_SESSIOND=`pidof lt-$SESSIOND_BIN` - - echo -e -n "Killing session daemon... " - kill $PID_SESSIOND >/dev/null 2>&1 - if [ $? -eq 1 ]; then - print_fail - return 1 - else - out=1 - while [ -n "$out" ]; do - out=$(pidof lt-$SESSIOND_BIN) - sleep 0.5 - done - print_ok - fi -} - -function create_lttng_session () -{ - sess_name=$1 - trace_path=$2 - - echo -n "Creating lttng session $sess_name in $trace_path " - $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $sess_name -o $trace_path >/dev/null 2>&1 - if [ $? -eq 1 ]; then - print_fail - return 1 - else - print_ok - fi -} - -function enable_lttng_channel() -{ - sess_name=$1 - channel_name=$2 - - echo -n "Enabling lttng channel $channel_name for session $sess_name" - $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel $channel_name -s $sess_name >/dev/null 2>&1 - if [ $? -eq 1 ]; then - print_fail - return 1 - else - print_ok - fi -} - -function disable_lttng_channel() -{ - sess_name=$1 - channel_name=$2 - - echo -n "Disabling lttng channel $channel_name for session $sess_name" - $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-channel $channel_name -s $sess_name >/dev/null 2>&1 - if [ $? -eq 1 ]; then - print_fail - return 1 - else - print_ok - fi -} - -function enable_ust_lttng_event () -{ - sess_name=$1 - event_name="$2" - - echo -n "Enabling lttng event $event_name for session $sess_name " - $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -u >/dev/null 2>&1 - if [ $? -eq 1 ]; then - print_fail - return 1 - else - print_ok - fi -} - -function enable_ust_lttng_event_filter() -{ - sess_name="$1" - event_name="$2" - filter="$3" - echo -n "Enabling lttng event with filtering " - - $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -u --filter "$filter" 2>&1 >/dev/null - if [ $? -eq 0 ]; then - print_ok - return 0 - else - print_fail - return 1 - fi -} - -function enable_ust_lttng_event_loglevel() -{ - sess_name="$1" - event_name="$2" - loglevel="$3" - echo -n "Enabling lttng event $event_name with loglevel $loglevel" - - $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -u --loglevel $loglevel 2>&1 >/dev/null - if [ $? -eq 0 ]; then - print_ok - return 0 - else - print_fail - return 1 - fi -} - -function enable_ust_lttng_event_loglevel_only() -{ - sess_name="$1" - event_name="$2" - loglevel="$3" - echo -n "Enabling lttng event $event_name with loglevel-only $loglevel" - - $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -u --loglevel-only $loglevel 2>&1 >/dev/null - if [ $? -eq 0 ]; then - print_ok - return 0 - else - print_fail - return 1 - fi -} - -function disable_ust_lttng_event () -{ - sess_name="$1" - event_name="$2" - - echo -n "Disabling lttng event $event_name for session $sess_name " - $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name -u >/dev/null 2>&1 - if [ $? -eq 1 ]; then - print_fail - return 1 - else - print_ok - fi -} - -function start_lttng_tracing () -{ - sess_name=$1 - - echo -n "Start lttng tracing for session $sess_name " - $TESTDIR/../src/bin/lttng/$LTTNG_BIN start $sess_name >/dev/null 2>&1 - if [ $? -eq 1 ]; then - print_fail - return 1 - else - print_ok - fi -} - -function stop_lttng_tracing () -{ - sess_name=$1 - - echo -n "Stop lttng tracing for session $sess_name " - $TESTDIR/../src/bin/lttng/$LTTNG_BIN stop $sess_name >/dev/null 2>&1 - if [ $? -eq 1 ]; then - print_fail - return 1 - else - print_ok - fi -} - -function destroy_lttng_session () -{ - sess_name=$1 - - echo -n "Destroy lttng session $sess_name " - $TESTDIR/../src/bin/lttng/$LTTNG_BIN destroy $sess_name >/dev/null 2>&1 - if [ $? -eq 1 ]; then - print_fail - return 1 - else - print_ok - fi -} - -function trace_matches () -{ - event_name=$1 - nr_iter=$2 - trace_path=$3 - - which $BABELTRACE_BIN >/dev/null - if [ $? -eq 1 ]; then - echo "Babeltrace binary not found. Skipping trace matches" - return 0 - fi - - 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 -n "$count found in trace " - print_fail - return 1 - else - echo -n "Trace is coherent " - print_ok - 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 - print_fail - return 1 - else - print_ok - return 0 - fi -} diff --git a/tests/utils/utils.h b/tests/utils/utils.h new file mode 100644 index 000000000..94891c0c6 --- /dev/null +++ b/tests/utils/utils.h @@ -0,0 +1,43 @@ +/* + * 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. + */ + +#include +#include + +#define BRIGHT 1 +#define GREEN 32 +#define RED 31 + +#define PRINT_OK() \ +do { \ + /* Check for color support */ \ + if (isatty(STDOUT_FILENO)) { \ + printf("%c[%d;%dmOK%c[%dm\n", 0x1B, BRIGHT, GREEN, 0x1B, 0); \ + } else { \ + printf("OK\n"); \ + } \ +} while (0) + +#define PRINT_FAIL() \ +do { \ + /* Check for color support */ \ + if (isatty(STDOUT_FILENO)) { \ + printf("%c[%d;%dmFAIL%c[%dm\n", 0x1B, BRIGHT, RED, 0x1B, 0); \ + } else { \ + printf("FAIL\n"); \ + } \ +} while (0) diff --git a/tests/utils/utils.sh b/tests/utils/utils.sh new file mode 100644 index 000000000..d8cc4630e --- /dev/null +++ b/tests/utils/utils.sh @@ -0,0 +1,433 @@ +#!/src/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" +RELAYD_BIN="lttng-relayd" +LTTNG_BIN="lttng" +BABELTRACE_BIN="babeltrace" + +# Minimal kernel version supported for session daemon tests +KERNEL_MAJOR_VERSION=2 +KERNEL_MINOR_VERSION=6 +KERNEL_PATCHLEVEL_VERSION=27 + +function print_ok () +{ + # Check if we are a terminal + if [ -t 1 ]; then + echo -e "\e[1;32mOK\e[0m" + else + echo -e "OK" + fi +} + +function print_fail () +{ + # Check if we are a terminal + if [ -t 1 ]; then + echo -e "\e[1;31mFAIL\e[0m" + else + echo -e "FAIL" + fi +} + +function print_test_banner () +{ + desc="$1" + + count=$((${#desc}+2)) + str=$(printf "%${count}s"); + echo -e "\n" + echo -e ${str// /-} + echo -e " $desc " + echo -e ${str// /-} +} + +function validate_kernel_version () +{ + kern_version=($(uname -r | awk -F. '{ printf("%d.%d.%d\n",$1,$2,$3); }' | tr '.' '\n')) + if [ ${kern_version[0]} -gt $KERNEL_MAJOR_VERSION ]; then + return 0 + fi + if [ ${kern_version[1]} -gt $KERNEL_MINOR_VERSION ]; then + return 0 + fi + if [ ${kern_version[2]} -ge $KERNEL_PATCHLEVEL_VERSION ]; then + return 0 + fi + 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 "" + echo -n "Starting session daemon... " + validate_kernel_version + if [ $? -ne 0 ]; then + echo -e "\n*** Kernel too old for session daemon tests ***\n" + return 2 + fi + + DIR=$(readlink -f $TESTDIR) + + if [ -z $(pidof lt-$SESSIOND_BIN) ]; then + $DIR/../src/bin/lttng-sessiond/$SESSIOND_BIN --daemonize --quiet --consumerd32-path="$DIR/../src/bin/lttng-consumerd/lttng-consumerd" --consumerd64-path="$DIR/../src/bin/lttng-consumerd/lttng-consumerd" + #$DIR/../src/bin/lttng-sessiond/$SESSIOND_BIN --consumerd32-path="$DIR/../src/bin/lttng-consumerd/lttng-consumerd" --consumerd64-path="$DIR/../src/bin/lttng-consumerd/lttng-consumerd" --verbose-consumer >>/tmp/sessiond.log 2>&1 & + if [ $? -eq 1 ]; then + print_fail + return 1 + else + print_ok + fi + fi + + 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 + print_fail + return 1 + else + print_ok + fi +} + +function start_lttng_relayd +{ + local opt=$1 + + echo -e -n "Starting lttng-relayd (opt: $opt)... " + + DIR=$(readlink -f $TESTDIR) + + if [ -z $(pidof lt-$RELAYD_BIN) ]; then + $DIR/../src/bin/lttng-relayd/$RELAYD_BIN $opt >/dev/null 2>&1 & + #$DIR/../src/bin/lttng-relayd/$RELAYD_BIN $opt -vvv >>/tmp/relayd.log 2>&1 & + if [ $? -eq 1 ]; then + print_fail + return 1 + else + print_ok + fi + else + print_ok + fi +} + +function stop_lttng_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 + print_fail + return 1 + else + out=1 + while [ -n "$out" ]; do + out=$(pidof lt-$RELAYD_BIN) + sleep 0.5 + done + print_ok + return 0 + fi +} + +function start_lttng_sessiond() +{ + if [ -n $TEST_NO_SESSIOND ] && [ "$TEST_NO_SESSIOND" == "1" ]; then + # Env variable requested no session daemon + return + fi + + spawn_sessiond + out=$? + if [ $out -eq 2 ]; then + # Kernel version is not compatible. + exit 0 + elif [ $out -ne 0 ]; then + echo "NOT bad $?" + exit 1 + fi + + # Simply wait for the session daemon bootstrap + echo "Waiting for the session daemon to bootstrap (2 secs)" + sleep 2 +} + +function stop_lttng_sessiond () +{ + if [ -n $TEST_NO_SESSIOND ] && [ "$TEST_NO_SESSIOND" == "1" ]; then + # Env variable requested no session daemon + return + fi + + PID_SESSIOND=`pidof lt-$SESSIOND_BIN` + + echo -e -n "Killing session daemon... " + kill $PID_SESSIOND >/dev/null 2>&1 + if [ $? -eq 1 ]; then + print_fail + return 1 + else + out=1 + while [ -n "$out" ]; do + out=$(pidof lt-$SESSIOND_BIN) + sleep 0.5 + done + print_ok + fi +} + +function create_lttng_session () +{ + sess_name=$1 + trace_path=$2 + + echo -n "Creating lttng session $sess_name in $trace_path " + $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $sess_name -o $trace_path >/dev/null 2>&1 + if [ $? -eq 1 ]; then + print_fail + return 1 + else + print_ok + fi +} + +function enable_lttng_channel() +{ + sess_name=$1 + channel_name=$2 + + echo -n "Enabling lttng channel $channel_name for session $sess_name" + $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel $channel_name -s $sess_name >/dev/null 2>&1 + if [ $? -eq 1 ]; then + print_fail + return 1 + else + print_ok + fi +} + +function disable_lttng_channel() +{ + sess_name=$1 + channel_name=$2 + + echo -n "Disabling lttng channel $channel_name for session $sess_name" + $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-channel $channel_name -s $sess_name >/dev/null 2>&1 + if [ $? -eq 1 ]; then + print_fail + return 1 + else + print_ok + fi +} + +function enable_ust_lttng_event () +{ + sess_name=$1 + event_name="$2" + + echo -n "Enabling lttng event $event_name for session $sess_name " + $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -u >/dev/null 2>&1 + if [ $? -eq 1 ]; then + print_fail + return 1 + else + print_ok + fi +} + +function enable_ust_lttng_event_filter() +{ + sess_name="$1" + event_name="$2" + filter="$3" + echo -n "Enabling lttng event with filtering " + + $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -u --filter "$filter" 2>&1 >/dev/null + if [ $? -eq 0 ]; then + print_ok + return 0 + else + print_fail + return 1 + fi +} + +function enable_ust_lttng_event_loglevel() +{ + sess_name="$1" + event_name="$2" + loglevel="$3" + echo -n "Enabling lttng event $event_name with loglevel $loglevel" + + $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -u --loglevel $loglevel 2>&1 >/dev/null + if [ $? -eq 0 ]; then + print_ok + return 0 + else + print_fail + return 1 + fi +} + +function enable_ust_lttng_event_loglevel_only() +{ + sess_name="$1" + event_name="$2" + loglevel="$3" + echo -n "Enabling lttng event $event_name with loglevel-only $loglevel" + + $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -u --loglevel-only $loglevel 2>&1 >/dev/null + if [ $? -eq 0 ]; then + print_ok + return 0 + else + print_fail + return 1 + fi +} + +function disable_ust_lttng_event () +{ + sess_name="$1" + event_name="$2" + + echo -n "Disabling lttng event $event_name for session $sess_name " + $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name -u >/dev/null 2>&1 + if [ $? -eq 1 ]; then + print_fail + return 1 + else + print_ok + fi +} + +function start_lttng_tracing () +{ + sess_name=$1 + + echo -n "Start lttng tracing for session $sess_name " + $TESTDIR/../src/bin/lttng/$LTTNG_BIN start $sess_name >/dev/null 2>&1 + if [ $? -eq 1 ]; then + print_fail + return 1 + else + print_ok + fi +} + +function stop_lttng_tracing () +{ + sess_name=$1 + + echo -n "Stop lttng tracing for session $sess_name " + $TESTDIR/../src/bin/lttng/$LTTNG_BIN stop $sess_name >/dev/null 2>&1 + if [ $? -eq 1 ]; then + print_fail + return 1 + else + print_ok + fi +} + +function destroy_lttng_session () +{ + sess_name=$1 + + echo -n "Destroy lttng session $sess_name " + $TESTDIR/../src/bin/lttng/$LTTNG_BIN destroy $sess_name >/dev/null 2>&1 + if [ $? -eq 1 ]; then + print_fail + return 1 + else + print_ok + fi +} + +function trace_matches () +{ + event_name=$1 + nr_iter=$2 + trace_path=$3 + + which $BABELTRACE_BIN >/dev/null + if [ $? -eq 1 ]; then + echo "Babeltrace binary not found. Skipping trace matches" + return 0 + fi + + 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 -n "$count found in trace " + print_fail + return 1 + else + echo -n "Trace is coherent " + print_ok + 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 + print_fail + return 1 + else + print_ok + return 0 + fi +}