Tests: Convert the kernel_event_basic test to an equivalent shell test
authorChristian Babeux <christian.babeux@efficios.com>
Fri, 22 Feb 2013 02:49:14 +0000 (21:49 -0500)
committerChristian Babeux <christian.babeux@efficios.com>
Fri, 22 Feb 2013 18:00:25 +0000 (13:00 -0500)
The test_event_basic shell script test has the same behavior has the
kernel_event_basic test. In addition, the resulting trace produced
by the test is now verified for correctness. Finally, the test output
format has been converted to TAP.

Signed-off-by: Christian Babeux <christian.babeux@efficios.com>
tests/regression/kernel/Makefile.am
tests/regression/kernel/kernel_event_basic.c [deleted file]
tests/regression/kernel/test_event_basic [new file with mode: 0755]

index f89ce0102bcb4b77c9a96f57ee75c28a1bb3ae5b..3c479363b232742eed146e2fd58c0d5793fda02a 100644 (file)
@@ -1,18 +1,6 @@
 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 test_all_events
+EXTRA_DIST = runall.sh run-kernel-tests.sh test_all_events test_event_basic
 
-noinst_PROGRAMS = 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_event_basic_SOURCES = kernel_event_basic.c $(UTILS) \
-               $(SESSIONDSRC)
-kernel_event_basic_LDADD = $(LIBLTTNG)
diff --git a/tests/regression/kernel/kernel_event_basic.c b/tests/regression/kernel/kernel_event_basic.c
deleted file mode 100644 (file)
index b0cbf66..0000000
+++ /dev/null
@@ -1,191 +0,0 @@
-/*
- * Copyright (c)  2011 David Goulet <david.goulet@polymtl.ca>
- *
- * 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 <assert.h>
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <time.h>
-
-#include <lttng/lttng.h>
-
-#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/test_event_basic b/tests/regression/kernel/test_event_basic
new file mode 100755 (executable)
index 0000000..4de94dc
--- /dev/null
@@ -0,0 +1,67 @@
+#!/bin/bash
+#
+# Copyright (C) - 2013 Christian Babeux <christian.babeux@efficios.com>
+#
+# 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="Kernel tracer - Basic event"
+
+CURDIR=$(dirname $0)/
+TESTDIR=$CURDIR/../..
+NUM_TESTS=12
+
+source $TESTDIR/utils/utils.sh
+
+print_test_banner "$TEST_DESC"
+
+function test_event_basic()
+{
+       TRACE_PATH=$(mktemp -d)
+       SESSION_NAME="kernel_event_basic"
+
+       create_lttng_session $SESSION_NAME $TRACE_PATH
+
+       lttng_enable_kernel_event $SESSION_NAME "sched_switch"
+       lttng_enable_kernel_event $SESSION_NAME "sched_process_exit"
+       lttng_enable_kernel_event $SESSION_NAME "sched_process_free"
+
+       start_lttng_tracing
+       stop_lttng_tracing
+
+       validate_trace "sched_switch" $TRACE_PATH
+       validate_trace "sched_process_exit" $TRACE_PATH
+       validate_trace "sched_process_free" $TRACE_PATH
+
+       destroy_lttng_session $SESSION_NAME
+
+       rm -rf $TRACE_PATH
+}
+
+# MUST set TESTDIR before calling those functions
+plan_tests $NUM_TESTS
+
+if [ "$(id -u)" == "0" ]; then
+       isroot=1
+else
+       isroot=0
+fi
+
+skip $isroot "Root access is needed. Skipping all tests." $NUM_TESTS ||
+{
+       start_lttng_sessiond
+
+       test_event_basic
+
+       stop_lttng_sessiond
+}
This page took 0.038616 seconds and 4 git commands to generate.