Add two basic tests for UST global domain
authorDavid Goulet <dgoulet@efficios.com>
Mon, 16 Jan 2012 16:08:35 +0000 (11:08 -0500)
committerDavid Goulet <dgoulet@efficios.com>
Mon, 16 Jan 2012 16:11:38 +0000 (11:11 -0500)
They test basic functionnality of UST meaning creating
channel/session/event, enabling/disabling, start/stop and destroy the
session.

Those two tests *does not* use UST instrumented application. They only
test support and communication between lttng cli and session daemon.

Integrated with "make check"

Signed-off-by: David Goulet <dgoulet@efficios.com>
tests/Makefile.am
tests/lttng/run-ust-global-tests.sh [new file with mode: 0755]
tests/lttng/runall.sh
tests/lttng/ust_global_all_events_basic.c [new file with mode: 0644]
tests/lttng/ust_global_event_basic.c [new file with mode: 0644]

index d775644c56913aadbdb573a043fbe0d3c717c8d9..77bed35ca99e41961fd2fab7fd3cd57ee0339bd0 100644 (file)
@@ -1,10 +1,10 @@
 AM_CFLAGS=-I$(top_srcdir)/include -I$(top_srcdir)/libkernelctl \
                  -I$(top_srcdir)/liblttngctl -g -Wall -lurcu -lurcu-cds
 
-EXTRA_DIST = runall.sh lttng/runall.sh lttng/run-kernel-tests.sh
+EXTRA_DIST = runall.sh lttng/runall.sh lttng/run-kernel-tests.sh lttng/run-ust-tests.sh
 
 noinst_PROGRAMS = test_sessions test_kernel_data_trace kernel_all_events_basic \
-                                 kernel_event_basic
+                                 kernel_event_basic ust_global_event_basic ust_global_all_events_basic
 
 UTILS=utils.h
 SESSIONS=$(top_srcdir)/lttng-sessiond/session.c
@@ -21,5 +21,9 @@ kernel_all_events_basic_SOURCES = lttng/kernel_all_events_basic.c $(UTILS) $(LIB
 
 kernel_event_basic_SOURCES = lttng/kernel_event_basic.c $(UTILS) $(LIBLTTNG)
 
+ust_global_all_events_basic_SOURCES = lttng/ust_global_all_events_basic.c $(UTILS) $(LIBLTTNG)
+
+ust_global_event_basic_SOURCES = lttng/ust_global_event_basic.c $(UTILS) $(LIBLTTNG)
+
 check-am:
        ./runall.sh
diff --git a/tests/lttng/run-ust-global-tests.sh b/tests/lttng/run-ust-global-tests.sh
new file mode 100755 (executable)
index 0000000..bfcb974
--- /dev/null
@@ -0,0 +1,55 @@
+#!/bin/bash
+
+SESSIOND_BIN="lttng-sessiond"
+
+tmpdir=`mktemp -d`
+tests=( ust_global_event_basic ust_global_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
+               # Cleaning up
+               rm -rf $tmpdir
+    done
+}
+
+echo -e "\n-------------------------------------------"
+echo -e "UST tracer - GLOBAL DOMAIN (LTTNG_DOMAIN_UST)"
+echo -e "---------------------------------------------"
+
+if [ -z $(pidof $SESSIOND_BIN) ]; then
+       echo -n "Starting session daemon... "
+       ../lttng-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
+
+exit $exit_code
index 0817f681371573da83e213acbb68cab4b76e3a2e..c5446c9902a45c152af2cbbaab9d6c29b95c41b6 100755 (executable)
@@ -1,6 +1,6 @@
 #!/bin/bash
 
-tests=( lttng/run-kernel-tests.sh )
+tests=( lttng/run-kernel-tests.sh lttng/run-ust-global-tests.sh )
 exit_code=0
 
 function start_tests ()
diff --git a/tests/lttng/ust_global_all_events_basic.c b/tests/lttng/ust_global_all_events_basic.c
new file mode 100644 (file)
index 0000000..7c0a562
--- /dev/null
@@ -0,0 +1,110 @@
+/*
+ * 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_event event;
+    char *channel_name = "channel0";
+    int ret = 0;
+
+    dom.type = LTTNG_DOMAIN_UST;
+
+       memset(&event, 0, sizeof(struct lttng_event));
+       event.type = LTTNG_EVENT_TRACEPOINT;
+
+       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("test", 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("test", &dom)) == NULL) {
+               printf("error creating handle: %s\n", lttng_strerror(ret));
+               goto handle_fail;
+       }
+       PRINT_OK();
+
+       printf("Enabling all 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("Start tracing: ");
+    if ((ret = lttng_start_tracing("test")) < 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("test")) < 0) {
+               printf("error stopping tracing: %s\n", lttng_strerror(ret));
+               goto stop_fail;
+       }
+       PRINT_OK();
+
+       printf("Destroy tracing session: ");
+       if ((ret = lttng_destroy_session("test")) < 0) {
+               printf("error destroying session: %s\n", lttng_strerror(ret));
+       }
+       PRINT_OK();
+
+       return 0;
+
+create_fail:
+       assert(ret != 0);
+handle_fail:
+       assert(handle != NULL);
+
+stop_fail:
+start_fail:
+enable_fail:
+       lttng_destroy_session("test");
+       lttng_destroy_handle(handle);
+
+    return 1;
+}
diff --git a/tests/lttng/ust_global_event_basic.c b/tests/lttng/ust_global_event_basic.c
new file mode 100644 (file)
index 0000000..baa9ff8
--- /dev/null
@@ -0,0 +1,176 @@
+/*
+ * 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 ev1, ev2, ev3;
+
+    int ret = 0;
+
+       char *session_name = "ust_event_basic";
+
+    dom.type = LTTNG_DOMAIN_UST;
+
+       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;
+
+       strcpy(ev1.name, "tp1");
+       ev1.type = LTTNG_EVENT_TRACEPOINT;
+
+       strcpy(ev2.name, "ev2");
+       ev2.type = LTTNG_EVENT_TRACEPOINT;
+
+       strcpy(ev3.name, "ev3");
+       ev3.type = LTTNG_EVENT_TRACEPOINT;
+
+       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 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 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("Enabling %s UST event: ", ev2.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: ", 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 %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, channel.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("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;
+
+create_fail:
+       assert(ret != 0);
+handle_fail:
+       assert(handle != NULL);
+
+stop_fail:
+start_fail:
+enable_fail:
+       lttng_destroy_session(session_name);
+       lttng_destroy_handle(handle);
+
+    return 1;
+}
This page took 0.03054 seconds and 4 git commands to generate.