Add basic kernel tracing tests
authorDavid Goulet <david.goulet@polymtl.ca>
Mon, 15 Aug 2011 20:18:34 +0000 (16:18 -0400)
committerDavid Goulet <david.goulet@polymtl.ca>
Mon, 15 Aug 2011 20:20:13 +0000 (16:20 -0400)
This test is the basic use case of kernel tracing by creating a session,
enabling all events, tracing and destroying the session.

Signed-off-by: David Goulet <david.goulet@polymtl.ca>
.gitignore
tests/Makefile.am
tests/lttng/kernel_all_events_basic.c [new file with mode: 0644]
tests/lttng/runall.sh [new file with mode: 0755]
tests/runall.sh

index b9b2b5491f436171ae435e1ab11e6c16b69535a0..280be42f3b20469d4e463709e87c46af0c4d419f 100644 (file)
@@ -32,3 +32,4 @@ ltt-kconsumerd/ltt-kconsumerd
 
 tests/test_sessions
 tests/test_kernel_data_trace
+tests/kernel_all_events_basic
index 1419545a36a9566542462cdd1cf98ab0698f1379..25351dd51d36bad9c6f961d4dae7e78e49843b99 100644 (file)
@@ -3,15 +3,19 @@ AM_CFLAGS=-I$(top_srcdir)/include -I$(top_srcdir)/libkernelctl \
 
 EXTRA_DIST = runall.sh
 
-noinst_PROGRAMS = test_sessions test_kernel_data_trace
+noinst_PROGRAMS = test_sessions test_kernel_data_trace kernel_all_events_basic
 
 UTILS=utils.h
 SESSIONS=$(top_srcdir)/ltt-sessiond/session.c
 KERN_DATA_TRACE=$(top_srcdir)/ltt-sessiond/trace.c
+LIBLTTNG=$(top_srcdir)/liblttngctl/lttngctl.c \
+                $(top_srcdir)/liblttng-sessiond-comm/lttng-sessiond-comm.c
 
 test_sessions_SOURCES = test_sessions.c $(UTILS) $(SESSIONS)
 
 test_kernel_data_trace_SOURCES = test_kernel_data_trace.c $(UTILS) $(KERN_DATA_TRACE)
 
+kernel_all_events_basic_SOURCES = lttng/kernel_all_events_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
new file mode 100644 (file)
index 0000000..438dfa0
--- /dev/null
@@ -0,0 +1,111 @@
+/*
+ * 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;
+    char *channel_name = "mychan";
+    int ret = 0;
+
+    dom.type = LTTNG_DOMAIN_KERNEL;
+
+       printf("\nTesting basic kernel tracing use case:\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("test", 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("test", &dom)) == NULL) {
+               printf("error creating handle: %s\n", lttng_get_readable_code(ret));
+               goto handle_fail;
+       }
+       PRINT_OK();
+
+       printf("Enabling all kernel events: ");
+    if ((ret = lttng_enable_event(handle, NULL, 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
new file mode 100755 (executable)
index 0000000..c9ea8b8
--- /dev/null
@@ -0,0 +1,55 @@
+#!/bin/bash
+
+SESSIOND_BIN="ltt-sessiond"
+
+tmpdir=`mktemp -d`
+tests=( kernel_all_events_basic )
+exit_code=0
+
+function start_tests ()
+{
+    for bin in ${tests[@]};
+    do
+        ./$bin $tmpdir
+        # Test must return 0 to pass.
+        if [ $? -ne 0 ]; then
+            exit_code=1
+            break
+        fi
+    done
+}
+
+echo -e "\n----------------------------------"
+echo -e "Testing lttng client (liblttngctl)"
+echo -e "----------------------------------"
+
+if [ -z $(pidof $SESSIOND_BIN) ]; then
+       echo -n "Starting session daemon... "
+       ../ltt-sessiond/$SESSIOND_BIN --daemonize --quiet
+       if [ $? -eq 1 ]; then
+               echo -e '\e[1;31mFAILED\e[0m'
+               rm -rf $tmpdir
+               exit 1
+       else
+               echo -e "\e[1;32mOK\e[0m"
+       fi
+fi
+
+PID_SESSIOND=`pidof lt-$SESSIOND_BIN`
+
+# Simply wait for the session daemon bootstrap
+sleep 1
+
+start_tests
+
+echo -e -n "\nKilling session daemon... "
+kill $PID_SESSIOND >/dev/null 2>&1
+if [ $? -eq 1 ]; then
+    echo -e '\e[1;31mFAILED\e[0m'
+else
+    echo -e "\e[1;32mOK\e[0m"
+fi
+
+rm -rf $tmpdir
+
+exit $exit_code
index b0ae4fd4cf7b07eb3056dc794cbb16fb15b602e3..8abc4aaa124944d5c6a9013460efa58b4bc25610 100755 (executable)
@@ -19,7 +19,7 @@
 
 #### ADD TESTS HERE ####
 
-test_suite=( test_sessions test_kernel_data_trace )
+test_suite=( test_sessions test_kernel_data_trace lttng/runall.sh )
 
 #### END TESTS HERE ####
 
This page took 0.028097 seconds and 4 git commands to generate.