Add kernel events tests
authorDavid Goulet <david.goulet@polymtl.ca>
Mon, 15 Aug 2011 22:16:07 +0000 (18:16 -0400)
committerDavid Goulet <david.goulet@polymtl.ca>
Mon, 15 Aug 2011 22:16:07 +0000 (18:16 -0400)
Signed-off-by: David Goulet <david.goulet@polymtl.ca>
.gitignore
tests/Makefile.am
tests/lttng/kernel_all_events_basic.c
tests/lttng/kernel_event_basic.c [new file with mode: 0644]
tests/lttng/runall.sh

index 280be42f3b20469d4e463709e87c46af0c4d419f..08d44e8e8fcbc53c0f94776e2efd896e3605a5f8 100644 (file)
@@ -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
index 1bca676da018756c0a86c80088662bde487856ba..a10390614ca5bc9f872d234f4739b4a93224658d 100644 (file)
@@ -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
index 438dfa00c37566fc97451622b6a9d876bdccb2e0..65a710e5a8d97418fddfadc9bf7d15154ebea19a 100644 (file)
@@ -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 (file)
index 0000000..a6f4b81
--- /dev/null
@@ -0,0 +1,182 @@
+/*
+ * 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 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;
+}
index c9ea8b8960f78ee2aed8cd13e7fc783cf24b606b..3d26bb172ab877074617609a85f63b56a2926d7a 100755 (executable)
@@ -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
This page took 0.028949 seconds and 4 git commands to generate.