From: David Goulet Date: Mon, 15 Aug 2011 22:16:07 +0000 (-0400) Subject: Add kernel events tests X-Git-Tag: v2.0-pre12~21 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=c60ddab68a253f696908ed3766207b8443b85982;p=lttng-tools.git Add kernel events tests Signed-off-by: David Goulet --- diff --git a/.gitignore b/.gitignore index 280be42f3..08d44e8e8 100644 --- a/.gitignore +++ b/.gitignore @@ -33,3 +33,4 @@ ltt-kconsumerd/ltt-kconsumerd tests/test_sessions tests/test_kernel_data_trace tests/kernel_all_events_basic +tests/kernel_event_basic diff --git a/tests/Makefile.am b/tests/Makefile.am index 1bca676da..a10390614 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -3,7 +3,8 @@ AM_CFLAGS=-I$(top_srcdir)/include -I$(top_srcdir)/libkernelctl \ EXTRA_DIST = runall.sh lttng/runall.sh -noinst_PROGRAMS = test_sessions test_kernel_data_trace kernel_all_events_basic +noinst_PROGRAMS = test_sessions test_kernel_data_trace kernel_all_events_basic \ + kernel_event_basic UTILS=utils.h SESSIONS=$(top_srcdir)/ltt-sessiond/session.c @@ -17,5 +18,7 @@ test_kernel_data_trace_SOURCES = test_kernel_data_trace.c $(UTILS) $(KERN_DATA_T kernel_all_events_basic_SOURCES = lttng/kernel_all_events_basic.c $(UTILS) $(LIBLTTNG) +kernel_event_basic_SOURCES = lttng/kernel_event_basic.c $(UTILS) $(LIBLTTNG) + check-am: ./runall.sh diff --git a/tests/lttng/kernel_all_events_basic.c b/tests/lttng/kernel_all_events_basic.c index 438dfa00c..65a710e5a 100644 --- a/tests/lttng/kernel_all_events_basic.c +++ b/tests/lttng/kernel_all_events_basic.c @@ -38,7 +38,7 @@ int main(int argc, char **argv) dom.type = LTTNG_DOMAIN_KERNEL; - printf("\nTesting basic kernel tracing use case:\n"); + printf("\nTesting tracing all kernel events:\n"); printf("-----------\n"); /* Check if root */ if (getuid() != 0) { diff --git a/tests/lttng/kernel_event_basic.c b/tests/lttng/kernel_event_basic.c new file mode 100644 index 000000000..a6f4b81a8 --- /dev/null +++ b/tests/lttng/kernel_event_basic.c @@ -0,0 +1,182 @@ +/* + * 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 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 sys_enter; + struct lttng_event sys_exit; + + int ret = 0; + + char *session_name = "kernel_event"; + + 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; + + strcpy(sys_enter.name, "sys_enter"); + sys_enter.type = LTTNG_EVENT_TRACEPOINT; + + strcpy(sys_exit.name, "sys_exit"); + sys_exit.type = LTTNG_EVENT_TRACEPOINT; + + 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_get_readable_code(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_get_readable_code(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_get_readable_code(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_get_readable_code(ret)); + goto enable_fail; + } + PRINT_OK(); + + printf("Enabling %s kernel event: ", sys_enter.name); + if ((ret = lttng_enable_event(handle, &sys_enter, channel.name)) < 0) { + printf("error enabling event: %s\n", lttng_get_readable_code(ret)); + goto enable_fail; + } + PRINT_OK(); + + printf("Enabling %s kernel event: ", sys_exit.name); + if ((ret = lttng_enable_event(handle, &sys_exit, channel.name)) < 0) { + printf("error enabling event: %s\n", lttng_get_readable_code(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_get_readable_code(ret)); + goto enable_fail; + } + PRINT_OK(); + + printf("Disabling %s kernel event: ", sys_exit.name); + if ((ret = lttng_disable_event(handle, sys_exit.name, channel.name)) < 0) { + printf("error enabling event: %s\n", lttng_get_readable_code(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_get_readable_code(ret)); + goto enable_fail; + } + PRINT_OK(); + + printf("Renabling %s kernel event: ", sys_exit.name); + if ((ret = lttng_enable_event(handle, &sys_exit, channel.name)) < 0) { + printf("error enabling event: %s\n", lttng_get_readable_code(ret)); + goto enable_fail; + } + PRINT_OK(); + + printf("Start tracing: "); + if ((ret = lttng_start_tracing(handle)) < 0) { + printf("error starting tracing: %s\n", lttng_get_readable_code(ret)); + goto start_fail; + } + PRINT_OK(); + + sleep(2); + + printf("Stop tracing: "); + if ((ret = lttng_stop_tracing(handle)) < 0) { + printf("error stopping tracing: %s\n", lttng_get_readable_code(ret)); + goto stop_fail; + } + PRINT_OK(); + + printf("Destroy tracing session: "); + if ((ret = lttng_destroy_session(handle)) < 0) { + printf("error destroying session: %s\n", lttng_get_readable_code(ret)); + } + PRINT_OK(); + + return 0; + +create_fail: + assert(ret != 0); +handle_fail: + assert(handle != NULL); + +stop_fail: +start_fail: +enable_fail: + lttng_destroy_session(handle); + lttng_destroy_handle(handle); + + return 1; +} diff --git a/tests/lttng/runall.sh b/tests/lttng/runall.sh index c9ea8b896..3d26bb172 100755 --- a/tests/lttng/runall.sh +++ b/tests/lttng/runall.sh @@ -3,7 +3,7 @@ SESSIOND_BIN="ltt-sessiond" tmpdir=`mktemp -d` -tests=( kernel_all_events_basic ) +tests=( kernel_event_basic kernel_all_events_basic ) exit_code=0 function start_tests () @@ -16,6 +16,8 @@ function start_tests () exit_code=1 break fi + # Cleaning up + rm -rf $tmpdir done } @@ -50,6 +52,4 @@ else echo -e "\e[1;32mOK\e[0m" fi -rm -rf $tmpdir - exit $exit_code