Live unit test
authorJulien Desfossez <jdesfossez@efficios.com>
Wed, 6 Nov 2013 16:38:52 +0000 (11:38 -0500)
committerDavid Goulet <dgoulet@efficios.com>
Wed, 6 Nov 2013 21:26:38 +0000 (16:26 -0500)
The actual test :
- connect to the relayd on localhost
- list the sessions (should find only one)
- attach to the first session
- receive all the streams
- get all the metadata
- get one index per stream
- get one data packet

Then the session is stopped, destroyed and the daemons killed.

Two tests are also added just to for the lttng commands with a --live
session.

Signed-off-by: Julien Desfossez <jdesfossez@efficios.com>
Signed-off-by: David Goulet <dgoulet@efficios.com>
.gitignore
configure.ac
tests/fast_regression
tests/regression/tools/Makefile.am
tests/regression/tools/live/Makefile.am [new file with mode: 0644]
tests/regression/tools/live/live_test.c [new file with mode: 0644]
tests/regression/tools/live/test_kernel [new file with mode: 0755]
tests/regression/tools/live/test_lttng_kernel [new file with mode: 0755]
tests/regression/tools/live/test_lttng_ust [new file with mode: 0755]
tests/regression/tools/live/test_ust [new file with mode: 0755]
tests/root_regression

index d8c993ef52e2a596d458da250770c9f014c4e58f..5bacea48e0692493b58a170b647f4840960fdb05 100644 (file)
@@ -76,5 +76,6 @@ tests/regression/ust/fork/fork
 tests/regression/ust/fork/fork2
 tests/regression/ust/libc-wrapper/prog
 tests/utils/testapp/gen-ust-nevents/gen-ust-nevents
+tests/regression/tools/live/live_test
 
 benchmark/
index 2b4a340f5e646dfdd4fc1633dd022aa05922ba51..09e434baec1fb029fff6849b63189afd91797a29 100644 (file)
@@ -373,6 +373,7 @@ AC_CONFIG_FILES([
        tests/regression/tools/health/Makefile
        tests/regression/tools/tracefile-limits/Makefile
        tests/regression/tools/snapshots/Makefile
+       tests/regression/tools/live/Makefile
        tests/regression/ust/Makefile
        tests/regression/ust/nprocesses/Makefile
        tests/regression/ust/high-throughput/Makefile
index 69bc06db6d286b9d1e6a4f688be193c9ef3bbd87..678570c86fe7d193a967ec1654bd4e31e98dd9ee 100644 (file)
@@ -2,6 +2,8 @@ regression/tools/filtering/test_invalid_filter
 regression/tools/filtering/test_unsupported_op
 regression/tools/filtering/test_valid_filter
 regression/tools/streaming/test_ust
+regression/tools/live/test_ust
+regression/tools/live/test_lttng_ust
 regression/tools/tracefile-limits/test_tracefile_count
 regression/tools/tracefile-limits/test_tracefile_size
 regression/tools/snapshots/test_ust
index 83c93420ad6c7cec2035f25f1548a8e3e585f965..fa1df870065a2145b4f6d10722c03b501f67d2b5 100644 (file)
@@ -1 +1 @@
-SUBDIRS = streaming filtering health tracefile-limits snapshots
+SUBDIRS = streaming filtering health tracefile-limits snapshots live
diff --git a/tests/regression/tools/live/Makefile.am b/tests/regression/tools/live/Makefile.am
new file mode 100644 (file)
index 0000000..6551f13
--- /dev/null
@@ -0,0 +1,48 @@
+AM_CFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/src -I$(top_srcdir)/tests/utils/ -I$(srcdir)
+AM_LDFLAGS =
+
+if LTTNG_TOOLS_BUILD_WITH_LIBDL
+AM_LDFLAGS += -ldl
+endif
+if LTTNG_TOOLS_BUILD_WITH_LIBC_DL
+AM_LDFLAGS += -lc
+endif
+
+LIBTAP=$(top_builddir)/tests/utils/tap/libtap.la
+
+LIBCOMMON=$(top_builddir)/src/common/libcommon.la
+LIBSESSIOND_COMM=$(top_builddir)/src/common/sessiond-comm/libsessiond-comm.la
+LIBHASHTABLE=$(top_builddir)/src/common/hashtable/libhashtable.la
+LIBRELAYD=$(top_builddir)/src/common/relayd/librelayd.la
+LIBHEALTH=$(top_builddir)/src/common/health/libhealth.la
+
+LIVE=$(top_builddir)/src/bin/lttng-sessiond/session.o \
+        $(top_builddir)/src/bin/lttng-sessiond/consumer.o \
+        $(top_builddir)/src/bin/lttng-sessiond/utils.o \
+        $(top_builddir)/src/bin/lttng-sessiond/snapshot.o
+
+noinst_PROGRAMS = live_test
+EXTRA_DIST = live_test test_kernel
+
+if HAVE_LIBLTTNG_UST_CTL
+EXTRA_DIST += test_ust
+endif
+
+live_test_SOURCES = live_test.c
+live_test_LDADD = $(LIBTAP) $(LIBCOMMON) $(LIBRELAYD) $(LIBSESSIOND_COMM) \
+                                 $(LIBHASHTABLE) $(LIBHEALTH) -lrt -llttng-ctl
+live_test_LDADD += $(LIVE)
+
+all-local:
+       @if [ x"$(srcdir)" != x"$(builddir)" ]; then \
+               for script in $(EXTRA_DIST); do \
+                       cp -f $(srcdir)/$$script $(builddir); \
+               done; \
+       fi
+
+clean-local:
+       @if [ x"$(srcdir)" != x"$(builddir)" ]; then \
+               for script in $(EXTRA_DIST); do \
+                       rm -f $(builddir)/$$script; \
+               done; \
+       fi
diff --git a/tests/regression/tools/live/live_test.c b/tests/regression/tools/live/live_test.c
new file mode 100644 (file)
index 0000000..b2935e1
--- /dev/null
@@ -0,0 +1,598 @@
+/*
+ * Copyright (c) - 2013 Julien Desfossez <jdesfossez@efficios.com>
+ *
+ * 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 <sys/types.h>
+#include <inttypes.h>
+#include <stdlib.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netdb.h>
+#include <fcntl.h>
+#include <sys/mman.h>
+#include <sys/stat.h>
+
+#include <tap/tap.h>
+#include <lttng/lttng.h>
+
+#include <urcu/list.h>
+#include <bin/lttng-sessiond/session.h>
+#include <common/common.h>
+
+#include <bin/lttng-relayd/lttng-viewer.h>
+#include <common/index/lttng-index.h>
+
+#define SESSION1 "test1"
+#define RELAYD_URL "net://localhost"
+#define LIVE_TIMER 2000000
+
+/* Number of TAP tests in this file */
+#define NUM_TESTS 7
+#define mmap_size 524288
+
+int ust_consumerd32_fd;
+int ust_consumerd64_fd;
+
+static int control_sock;
+struct live_session *session;
+
+static int first_packet_offset;
+static int first_packet_len;
+static int first_packet_stream_id;
+
+struct viewer_stream {
+       uint64_t id;
+       uint64_t ctf_trace_id;
+       void *mmap_base;
+       int fd;
+       int metadata_flag;
+       int first_read;
+       char path[PATH_MAX];
+};
+
+struct live_session {
+       struct viewer_stream *streams;
+       uint64_t live_timer_interval;
+       uint64_t stream_count;
+};
+
+static
+int connect_viewer(char *hostname)
+{
+       struct hostent *host;
+       struct sockaddr_in server_addr;
+       int ret;
+
+       host = gethostbyname(hostname);
+       if (!host) {
+               ret = -1;
+               goto end;
+       }
+
+       if ((control_sock = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
+               perror("Socket");
+               ret = -1;
+               goto end;
+       }
+
+       server_addr.sin_family = AF_INET;
+       server_addr.sin_port = htons(5344);
+       server_addr.sin_addr = *((struct in_addr *) host->h_addr);
+       bzero(&(server_addr.sin_zero), 8);
+
+       if (connect(control_sock, (struct sockaddr *) &server_addr,
+                               sizeof(struct sockaddr)) == -1) {
+               perror("Connect");
+               ret = -1;
+               goto end;
+       }
+
+       server_addr.sin_family = AF_INET;
+       server_addr.sin_port = htons(5345);
+       server_addr.sin_addr = *((struct in_addr *) host->h_addr);
+       bzero(&(server_addr.sin_zero), 8);
+
+       ret = 0;
+
+end:
+       return ret;
+}
+
+int establish_connection(void)
+{
+       struct lttng_viewer_cmd cmd;
+       struct lttng_viewer_connect connect;
+       int ret;
+
+       cmd.cmd = htobe32(VIEWER_CONNECT);
+       cmd.data_size = sizeof(connect);
+       cmd.cmd_version = 0;
+
+       connect.major = htobe32(VERSION_MAJOR);
+       connect.minor = htobe32(VERSION_MINOR);
+       connect.type = htobe32(VIEWER_CLIENT_COMMAND);
+
+       do {
+               ret = send(control_sock, &cmd, sizeof(cmd), 0);
+       } while (ret < 0 && errno == EINTR);
+       if (ret < 0) {
+               fprintf(stderr, "Error sending cmd\n");
+               goto error;
+       }
+       do {
+               ret = send(control_sock, &connect, sizeof(connect), 0);
+       } while (ret < 0 && errno == EINTR);
+       if (ret < 0) {
+               fprintf(stderr, "Error sending version\n");
+               goto error;
+       }
+
+       do {
+               ret = recv(control_sock, &connect, sizeof(connect), 0);
+       } while (ret < 0 && errno == EINTR);
+       if (ret < 0) {
+               fprintf(stderr, "Error receiving version\n");
+               goto error;
+       }
+       ret = 0;
+
+error:
+       return ret;
+}
+
+/*
+ * Returns the number of sessions, should be 1 during the unit test.
+ */
+int list_sessions(int *session_id)
+{
+       struct lttng_viewer_cmd cmd;
+       struct lttng_viewer_list_sessions list;
+       struct lttng_viewer_session lsession;
+       int i, ret;
+       int first_session = 0;
+
+       cmd.cmd = htobe32(VIEWER_LIST_SESSIONS);
+       cmd.data_size = 0;
+       cmd.cmd_version = 0;
+
+       do {
+               ret = send(control_sock, &cmd, sizeof(cmd), 0);
+       } while (ret < 0 && errno == EINTR);
+       if (ret < 0) {
+               fprintf(stderr, "Error sending cmd\n");
+               goto error;
+       }
+
+       do {
+               ret = recv(control_sock, &list, sizeof(list), 0);
+       } while (ret < 0 && errno == EINTR);
+       if (ret < 0) {
+               fprintf(stderr, "Error receiving session list\n");
+               goto error;
+       }
+
+       for (i = 0; i < be32toh(list.sessions_count); i++) {
+               do {
+                       ret = recv(control_sock, &lsession, sizeof(lsession), 0);
+               } while (ret < 0 && errno == EINTR);
+               if (ret < 0) {
+                       fprintf(stderr, "Error receiving session\n");
+                       goto error;
+               }
+               if (lsession.streams > 0 && first_session <= 0) {
+                       first_session = be64toh(lsession.id);
+                       *session_id = first_session;
+               }
+       }
+
+       ret = be32toh(list.sessions_count);
+
+error:
+       return ret;
+}
+
+int attach_session(int id)
+{
+       struct lttng_viewer_cmd cmd;
+       struct lttng_viewer_attach_session_request rq;
+       struct lttng_viewer_attach_session_response rp;
+       struct lttng_viewer_stream stream;
+       int ret, i;
+
+       session = zmalloc(sizeof(struct live_session));
+       if (!session) {
+               ret = -1;
+               goto error;
+       }
+
+       cmd.cmd = htobe32(VIEWER_ATTACH_SESSION);
+       cmd.data_size = sizeof(rq);
+       cmd.cmd_version = 0;
+
+       rq.session_id = htobe64(id);
+       rq.seek = htobe32(VIEWER_SEEK_BEGINNING);
+
+       do {
+               ret = send(control_sock, &cmd, sizeof(cmd), 0);
+       } while (ret < 0 && errno == EINTR);
+       if (ret < 0) {
+               fprintf(stderr, "Error sending cmd\n");
+               goto error;
+       }
+       do {
+               ret = send(control_sock, &rq, sizeof(rq), 0);
+       } while (ret < 0 && errno == EINTR);
+       if (ret < 0) {
+               fprintf(stderr, "Error sending attach request\n");
+               goto error;
+       }
+
+       do {
+               ret = recv(control_sock, &rp, sizeof(rp), 0);
+       } while (ret < 0 && errno == EINTR);
+       if (ret < 0) {
+               fprintf(stderr, "Error receiving attach response\n");
+               goto error;
+       }
+       if (be32toh(rp.status) != VIEWER_ATTACH_OK) {
+               ret = -1;
+               goto end;
+       }
+
+       session->stream_count = be32toh(rp.streams_count);
+       session->streams = zmalloc(session->stream_count *
+                       sizeof(struct viewer_stream));
+       if (!session->streams) {
+               ret = -1;
+               goto error;
+       }
+
+       for (i = 0; i < be32toh(rp.streams_count); i++) {
+               do {
+                       ret = recv(control_sock, &stream, sizeof(stream), 0);
+               } while (ret < 0 && errno == EINTR);
+               if (ret < 0) {
+                       fprintf(stderr, "Error receiving stream\n");
+                       goto error;
+               }
+               session->streams[i].id = be64toh(stream.id);
+
+               session->streams[i].ctf_trace_id = be64toh(stream.ctf_trace_id);
+               session->streams[i].first_read = 1;
+               session->streams[i].mmap_base = mmap(NULL, mmap_size, PROT_READ | PROT_WRITE,
+                               MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+               if (session->streams[i].mmap_base == MAP_FAILED) {
+                       fprintf(stderr, "mmap error\n");
+                       ret = -1;
+                       goto error;
+               }
+
+               if (be32toh(stream.metadata_flag)) {
+                       session->streams[i].metadata_flag = 1;
+               }
+       }
+       ret = session->stream_count;
+
+end:
+error:
+       return ret;
+}
+
+int get_metadata(void)
+{
+       struct lttng_viewer_cmd cmd;
+       struct lttng_viewer_get_metadata rq;
+       struct lttng_viewer_metadata_packet rp;
+       int ret;
+       uint64_t i;
+       char *data = NULL;
+       uint64_t len = 0;
+       int metadata_stream_id = -1;
+
+       cmd.cmd = htobe32(VIEWER_GET_METADATA);
+       cmd.data_size = sizeof(rq);
+       cmd.cmd_version = 0;
+
+       for (i = 0; i < session->stream_count; i++) {
+               if (session->streams[i].metadata_flag) {
+                       metadata_stream_id = i;
+                       break;
+               }
+       }
+
+       if (metadata_stream_id < 0) {
+               fprintf(stderr, "No metadata stream found\n");
+               ret = -1;
+               goto error;
+       }
+
+       rq.stream_id = htobe64(session->streams[metadata_stream_id].id);
+
+       do {
+               ret = send(control_sock, &cmd, sizeof(cmd), 0);
+       } while (ret < 0 && errno == EINTR);
+       if (ret < 0) {
+               fprintf(stderr, "Error sending cmd\n");
+               goto error;
+       }
+       do {
+               ret = send(control_sock, &rq, sizeof(rq), 0);
+       } while (ret < 0 && errno == EINTR);
+       if (ret < 0) {
+               fprintf(stderr, "Error sending get_metadata request\n");
+               goto error;
+       }
+       do {
+               ret = recv(control_sock, &rp, sizeof(rp), 0);
+       } while (ret < 0 && errno == EINTR);
+       if (ret < 0) {
+               fprintf(stderr, "Error receiving metadata response\n");
+               goto error;
+       }
+       switch (be32toh(rp.status)) {
+               case VIEWER_METADATA_OK:
+                       break;
+               case VIEWER_NO_NEW_METADATA:
+                       fprintf(stderr, "NO NEW\n");
+                       ret = -1;
+                       goto end;
+               case VIEWER_METADATA_ERR:
+                       fprintf(stderr, "ERR\n");
+                       ret = -1;
+                       goto end;
+               default:
+                       fprintf(stderr, "UNKNOWN\n");
+                       ret = -1;
+                       goto end;
+       }
+
+       len = be64toh(rp.len);
+       if (len <= 0) {
+               goto end;
+       }
+
+       data = zmalloc(len);
+       if (!data) {
+               perror("relay data zmalloc");
+               goto error;
+       }
+       do {
+               ret = recv(control_sock, data, len, MSG_WAITALL);
+       } while (ret < 0 && errno == EINTR);
+       if (ret < 0) {
+               fprintf(stderr, "Error receiving trace packet\n");
+               free(data);
+               goto error;
+       }
+       free(data);
+
+       ret = (int) len;
+end:
+error:
+       return ret;
+}
+
+int get_next_index(void)
+{
+       struct lttng_viewer_cmd cmd;
+       struct lttng_viewer_get_next_index rq;
+       struct lttng_viewer_index rp;
+       int ret;
+       int id;
+
+       cmd.cmd = htobe32(VIEWER_GET_NEXT_INDEX);
+       cmd.data_size = sizeof(rq);
+       cmd.cmd_version = 0;
+
+       for (id = 0; id < session->stream_count; id++) {
+               if (session->streams[id].metadata_flag) {
+                       continue;
+               }
+               rq.stream_id = htobe64(session->streams[id].id);
+
+retry:
+               do {
+                       ret = send(control_sock, &cmd, sizeof(cmd), 0);
+               } while (ret < 0 && errno == EINTR);
+               if (ret < 0) {
+                       fprintf(stderr, "Error sending cmd\n");
+                       goto error;
+               }
+               do {
+                       ret = send(control_sock, &rq, sizeof(rq), 0);
+               } while (ret < 0 && errno == EINTR);
+               if (ret < 0) {
+                       fprintf(stderr, "Error sending get_next_index request\n");
+                       goto error;
+               }
+               do {
+                       ret = recv(control_sock, &rp, sizeof(rp), 0);
+               } while (ret < 0 && errno == EINTR);
+               if (ret < 0) {
+                       fprintf(stderr, "Error receiving index response\n");
+                       goto error;
+               }
+
+               rp.flags = be32toh(rp.flags);
+
+               switch (be32toh(rp.status)) {
+                       case VIEWER_INDEX_INACTIVE:
+                               fprintf(stderr, "(INACTIVE)\n");
+                               break;
+                       case VIEWER_INDEX_OK:
+                               break;
+                       case VIEWER_INDEX_RETRY:
+                               sleep(1);
+                               goto retry;
+                       case VIEWER_INDEX_HUP:
+                               fprintf(stderr, "(HUP)\n");
+                               session->streams[id].id = -1ULL;
+                               session->streams[id].fd = -1;
+                               break;
+                       case VIEWER_INDEX_ERR:
+                               fprintf(stderr, "(ERR)\n");
+                               ret = -1;
+                               goto error;
+                       default:
+                               fprintf(stderr, "SHOULD NOT HAPPEN\n");
+                               ret = -1;
+                               goto error;
+               }
+               if (!first_packet_stream_id) {
+                       first_packet_offset = be64toh(rp.offset);
+                       first_packet_len = be64toh(rp.packet_size) / CHAR_BIT;
+                       first_packet_stream_id = id;
+               }
+       }
+       ret = 0;
+
+error:
+       return ret;
+}
+
+static
+int get_data_packet(int id, uint64_t offset,
+               uint64_t len)
+{
+       struct lttng_viewer_cmd cmd;
+       struct lttng_viewer_get_packet rq;
+       struct lttng_viewer_trace_packet rp;
+       int ret;
+
+       cmd.cmd = htobe32(VIEWER_GET_PACKET);
+       cmd.data_size = sizeof(rq);
+       cmd.cmd_version = 0;
+
+       rq.stream_id = htobe64(session->streams[id].id);
+       /* Already in big endian. */
+       rq.offset = offset;
+       rq.len = htobe32(len);
+
+       do {
+               ret = send(control_sock, &cmd, sizeof(cmd), 0);
+       } while (ret < 0 && errno == EINTR);
+       if (ret < 0) {
+               fprintf(stderr, "Error sending cmd\n");
+               goto error;
+       }
+       do {
+               ret = send(control_sock, &rq, sizeof(rq), 0);
+       } while (ret < 0 && errno == EINTR);
+       if (ret < 0) {
+               fprintf(stderr, "Error sending get_data_packet request\n");
+               goto error;
+       }
+       do {
+               ret = recv(control_sock, &rp, sizeof(rp), 0);
+       } while (ret < 0 && errno == EINTR);
+       if (ret < 0) {
+               fprintf(stderr, "Error receiving data response\n");
+               goto error;
+       }
+       rp.flags = be32toh(rp.flags);
+
+       switch (be32toh(rp.status)) {
+       case VIEWER_GET_PACKET_OK:
+               break;
+       case VIEWER_GET_PACKET_RETRY:
+               fprintf(stderr, "RETRY\n");
+               ret = -1;
+               goto end;
+       case VIEWER_GET_PACKET_ERR:
+               if (rp.flags & LTTNG_VIEWER_FLAG_NEW_METADATA) {
+                       fprintf(stderr, "NEW_METADATA\n");
+                       ret = 0;
+                       goto end;
+               }
+               fprintf(stderr, "ERR\n");
+               ret = -1;
+               goto end;
+       default:
+               fprintf(stderr, "UNKNOWN\n");
+               ret = -1;
+               goto end;
+       }
+
+       len = be32toh(rp.len);
+       if (len <= 0) {
+               goto end;
+       }
+
+       if (len > mmap_size) {
+               fprintf(stderr, "mmap_size not big enough\n");
+               ret = -1;
+               goto error;
+       }
+
+       do {
+               ret = recv(control_sock, session->streams[id].mmap_base, len, MSG_WAITALL);
+       } while (ret < 0 && errno == EINTR);
+       if (ret < 0) {
+               fprintf(stderr, "Error receiving trace packet\n");
+               goto error;
+       }
+       ret = len;
+
+end:
+error:
+       return ret;
+}
+
+int main(int argc, char **argv)
+{
+       int ret;
+       int session_id;
+
+       plan_tests(NUM_TESTS);
+
+       diag("Live unit tests");
+
+       ret = connect_viewer("localhost");
+       ok(ret == 0, "Connect viewer to relayd");
+
+       ret = establish_connection();
+       ok(ret == 0, "Established connection and version check with %d.%d",
+                       VERSION_MAJOR, VERSION_MINOR);
+
+       ret = list_sessions(&session_id);
+       ok(ret > 0, "List sessions : %d session(s)", ret);
+
+       ret = attach_session(session_id);
+       ok(ret > 0, "Attach to session, %d streams received", ret);
+
+       ret = get_metadata();
+       ok(ret > 0, "Get metadata, received %d bytes", ret);
+
+       ret = get_next_index();
+       ok(ret == 0, "Get one index per stream");
+
+       ret = get_data_packet(first_packet_stream_id, first_packet_offset,
+                       first_packet_len);
+       ok(ret == first_packet_len,
+                       "Get one data packet for stream %d, offset %d, len %d",
+                       first_packet_stream_id, first_packet_offset,
+                       first_packet_len);
+
+       return exit_status();
+}
diff --git a/tests/regression/tools/live/test_kernel b/tests/regression/tools/live/test_kernel
new file mode 100755 (executable)
index 0000000..ac4c19f
--- /dev/null
@@ -0,0 +1,117 @@
+#!/bin/bash
+#
+# Copyright (C) - 2013 Julien Desfossez <julien.desfossez@efficios.com>
+#                      David Goulet <dgoulet@efficios.com>
+#
+# This library is free software; you can redistribute it and/or modify it under
+# the terms of the GNU Lesser General Public License as published by the Free
+# Software Foundation; version 2.1 of the License.
+#
+# This library 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 Lesser General Public License for more
+# details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with this library; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
+
+TEST_DESC="Live - Kernel space tracing"
+
+CURDIR=$(dirname $0)/
+TESTDIR=$CURDIR/../../../
+SESSIOND_BIN="lttng-sessiond"
+RELAYD_BIN="lttng-relayd"
+LTTNG_BIN="lttng"
+BABELTRACE_BIN="babeltrace"
+NR_ITER=1
+NR_USEC_WAIT=1
+DELAY_USEC=2000000
+
+SESSION_NAME="live"
+EVENT_NAME="sched_switch"
+
+TRACE_PATH=$(mktemp -d)
+
+DIR=$(readlink -f $TESTDIR)
+
+source $TESTDIR/utils/utils.sh
+
+function setup_live_tracing()
+{
+       # Create session with default path
+       $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $SESSION_NAME --live $DELAY_USEC \
+               -U net://localhost >/dev/null 2>&1
+
+       $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$EVENT_NAME" -s $SESSION_NAME -k >/dev/null 2>&1
+       $TESTDIR/../src/bin/lttng/$LTTNG_BIN start $SESSION_NAME >/dev/null 2>&1
+}
+
+function clean_live_tracing()
+{
+       $TESTDIR/../src/bin/lttng/$LTTNG_BIN stop $SESSION_NAME >/dev/null 2>&1
+       $TESTDIR/../src/bin/lttng/$LTTNG_BIN destroy $SESSION_NAME >/dev/null 2>&1
+       rm -rf $TRACE_PATH
+}
+
+# Need root access for kernel tracing.
+if [ "$(id -u)" == "0" ]; then
+       isroot=1
+else
+       echo "Root access is needed. Skipping all tests."
+       exit 0
+fi
+
+if [ -z $(pidof lt-$SESSIOND_BIN) ]; then
+       $DIR/../src/bin/lttng-sessiond/$SESSIOND_BIN --daemonize --quiet --consumerd32-path="$DIR/../src/bin/lttng-consumerd/lttng-consumerd" --consumerd64-path="$DIR/../src/bin/lttng-consumerd/lttng-consumerd"
+       if [ $? -eq 1 ]; then
+               echo "Fail to start lttng-sessiond"
+               exit 1
+       fi
+       # Wait for sessiond to bootstrap
+       sleep 2
+fi
+
+opt="-o $TRACE_PATH"
+if [ -z $(pidof lt-$RELAYD_BIN) ]; then
+       $DIR/../src/bin/lttng-relayd/$RELAYD_BIN $opt >/dev/null 2>&1 &
+       if [ $? -eq 1 ]; then
+               echo "Fail to start lttng-relayd (opt: $opt)"
+               return 1
+       fi
+fi
+
+setup_live_tracing
+
+# Start the live test
+$TESTDIR/regression/tools/live/live_test
+
+clean_live_tracing
+
+# Kill the relayd
+PID_RELAYD=`pidof lt-$RELAYD_BIN`
+kill $PID_RELAYD >/dev/null 2>&1
+if [ $? -eq 1 ]; then
+       echo "Kill lttng-relayd (pid: $PID_RELAYD)"
+       exit 1
+else
+       out=1
+       while [ -n "$out" ]; do
+               out=$(pidof lt-$RELAYD_BIN)
+               sleep 0.5
+       done
+fi
+
+# Kill the sessiond
+PID_SESSIOND=`pidof lt-$SESSIOND_BIN`
+kill $PID_SESSIOND >/dev/null 2>&1
+if [ $? -eq 1 ]; then
+       echo "Kill sessiond daemon"
+       exit 1
+else
+       out=1
+       while [ -n "$out" ]; do
+               out=$(pidof lt-$SESSIOND_BIN)
+               sleep 0.5
+       done
+fi
diff --git a/tests/regression/tools/live/test_lttng_kernel b/tests/regression/tools/live/test_lttng_kernel
new file mode 100755 (executable)
index 0000000..f4d7d41
--- /dev/null
@@ -0,0 +1,85 @@
+#!/bin/bash
+#
+# Copyright (C) - 2013 Julien Desfossez <julien.desfossez@efficios.com>
+#                      David Goulet <dgoulet@efficios.com>
+#
+# This library is free software; you can redistribute it and/or modify it under
+# the terms of the GNU Lesser General Public License as published by the Free
+# Software Foundation; version 2.1 of the License.
+#
+# This library 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 Lesser General Public License for more
+# details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with this library; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
+
+TEST_DESC="Live - Kernel space tracing"
+
+CURDIR=$(dirname $0)/
+TESTDIR=$CURDIR/../../../
+SESSIOND_BIN="lttng-sessiond"
+RELAYD_BIN="lttng-relayd"
+LTTNG_BIN="lttng"
+DELAY_USEC=2000000
+
+SESSION_NAME="live"
+EVENT_NAME="sched_switch"
+
+TRACE_PATH=$(mktemp -d)
+
+DIR=$(readlink -f $TESTDIR)
+
+NUM_TESTS=10
+
+source $TESTDIR/utils/utils.sh
+
+# MUST set TESTDIR before calling those functions
+plan_tests $NUM_TESTS
+
+print_test_banner "$TEST_DESC"
+
+function setup_live_tracing()
+{
+       # Create session with default path
+       $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $SESSION_NAME --live $DELAY_USEC \
+               -U net://localhost >/dev/null 2>&1
+       ok $? "Create session in live mode with delay $DELAY_USEC"
+
+       lttng_enable_kernel_event $SESSION_NAME $EVENT_NAME
+       start_lttng_tracing $SESSION_NAME
+}
+
+function clean_live_tracing()
+{
+       stop_lttng_tracing $SESSION_NAME
+       destroy_lttng_session $SESSION_NAME
+}
+
+# Need root access for kernel tracing.
+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
+       start_lttng_relayd "-o $TRACE_PATH"
+
+       setup_live_tracing
+
+       # Just hit some events
+       sleep 2
+
+       clean_live_tracing
+
+       validate_trace $EVENT_NAME $TRACE_PATH
+       rm -rf $TRACE_PATH
+
+       stop_lttng_relayd
+       stop_lttng_sessiond
+}
diff --git a/tests/regression/tools/live/test_lttng_ust b/tests/regression/tools/live/test_lttng_ust
new file mode 100755 (executable)
index 0000000..70af043
--- /dev/null
@@ -0,0 +1,85 @@
+#!/bin/bash
+#
+# Copyright (C) - 2013 Julien Desfossez <julien.desfossez@efficios.com>
+#                      David Goulet <dgoulet@efficios.com>
+#
+# This library is free software; you can redistribute it and/or modify it under
+# the terms of the GNU Lesser General Public License as published by the Free
+# Software Foundation; version 2.1 of the License.
+#
+# This library 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 Lesser General Public License for more
+# details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with this library; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
+
+TEST_DESC="Live - User space tracing"
+
+CURDIR=$(dirname $0)/
+TESTDIR=$CURDIR/../../../
+SESSIOND_BIN="lttng-sessiond"
+RELAYD_BIN="lttng-relayd"
+LTTNG_BIN="lttng"
+BABELTRACE_BIN="babeltrace"
+NR_ITER=1
+NR_USEC_WAIT=1
+DELAY_USEC=2000000
+TESTAPP_PATH="$TESTDIR/utils/testapp"
+TESTAPP_NAME="gen-ust-events"
+TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
+
+SESSION_NAME="live"
+EVENT_NAME="tp:tptest"
+
+TRACE_PATH=$(mktemp -d)
+
+DIR=$(readlink -f $TESTDIR)
+
+NUM_TESTS=10
+
+source $TESTDIR/utils/utils.sh
+
+# MUST set TESTDIR before calling those functions
+plan_tests $NUM_TESTS
+
+print_test_banner "$TEST_DESC"
+
+function setup_live_tracing()
+{
+       # Create session with default path
+       $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $SESSION_NAME --live $DELAY_USEC \
+               -U net://localhost >/dev/null 2>&1
+       ok $? "Create session in live mode with delay $DELAY_USEC"
+
+       enable_ust_lttng_event $SESSION_NAME $EVENT_NAME
+       start_lttng_tracing $SESSION_NAME
+}
+
+function clean_live_tracing()
+{
+       stop_lttng_tracing $SESSION_NAME
+       destroy_lttng_session $SESSION_NAME
+}
+
+start_lttng_sessiond
+start_lttng_relayd "-o $TRACE_PATH"
+
+setup_live_tracing
+
+# Run app in background
+$TESTAPP_BIN $NR_ITER $NR_USEC_WAIT >/dev/null 2>&1 &
+# Wait for app to complete
+while [ -n "$(pidof $TESTAPP_NAME)" ]; do
+       sleep 0.5
+done
+
+clean_live_tracing
+
+trace_matches $EVENT_NAME $NR_ITER $TRACE_PATH
+rm -rf $TRACE_PATH
+
+stop_lttng_relayd
+stop_lttng_sessiond
diff --git a/tests/regression/tools/live/test_ust b/tests/regression/tools/live/test_ust
new file mode 100755 (executable)
index 0000000..d4110ce
--- /dev/null
@@ -0,0 +1,121 @@
+#!/bin/bash
+#
+# Copyright (C) - 2013 Julien Desfossez <julien.desfossez@efficios.com>
+#                      David Goulet <dgoulet@efficios.com>
+#
+# This library is free software; you can redistribute it and/or modify it under
+# the terms of the GNU Lesser General Public License as published by the Free
+# Software Foundation; version 2.1 of the License.
+#
+# This library 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 Lesser General Public License for more
+# details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with this library; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
+
+TEST_DESC="Live - User space tracing"
+
+CURDIR=$(dirname $0)/
+TESTDIR=$CURDIR/../../../
+SESSIOND_BIN="lttng-sessiond"
+RELAYD_BIN="lttng-relayd"
+LTTNG_BIN="lttng"
+BABELTRACE_BIN="babeltrace"
+NR_ITER=1
+NR_USEC_WAIT=1
+DELAY_USEC=2000000
+TESTAPP_PATH="$TESTDIR/utils/testapp"
+TESTAPP_NAME="gen-ust-events"
+TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
+
+SESSION_NAME="live"
+EVENT_NAME="tp:tptest"
+
+TRACE_PATH=$(mktemp -d)
+
+DIR=$(readlink -f $TESTDIR)
+
+source $TESTDIR/utils/utils.sh
+
+echo "$TEST_DESC"
+
+function setup_live_tracing()
+{
+       # Create session with default path
+       $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $SESSION_NAME --live $DELAY_USEC \
+               -U net://localhost >/dev/null 2>&1
+
+       $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$EVENT_NAME" -s $SESSION_NAME -u >/dev/null 2>&1
+       $TESTDIR/../src/bin/lttng/$LTTNG_BIN start $SESSION_NAME >/dev/null 2>&1
+}
+
+function clean_live_tracing()
+{
+       $TESTDIR/../src/bin/lttng/$LTTNG_BIN stop $SESSION_NAME >/dev/null 2>&1
+       $TESTDIR/../src/bin/lttng/$LTTNG_BIN destroy $SESSION_NAME >/dev/null 2>&1
+       rm -rf $TRACE_PATH
+}
+
+if [ -z $(pidof lt-$SESSIOND_BIN) ]; then
+       $DIR/../src/bin/lttng-sessiond/$SESSIOND_BIN --daemonize --quiet --consumerd32-path="$DIR/../src/bin/lttng-consumerd/lttng-consumerd" --consumerd64-path="$DIR/../src/bin/lttng-consumerd/lttng-consumerd"
+       if [ $? -eq 1 ]; then
+               echo "Fail to start lttng-sessiond"
+               exit 1
+       fi
+       # Wait for sessiond to bootstrap
+       sleep 2
+fi
+
+opt="-o $TRACE_PATH"
+if [ -z $(pidof lt-$RELAYD_BIN) ]; then
+       $DIR/../src/bin/lttng-relayd/$RELAYD_BIN $opt >/dev/null 2>&1 &
+       if [ $? -eq 1 ]; then
+               echo "Fail to start lttng-relayd (opt: $opt)"
+               return 1
+       fi
+fi
+
+setup_live_tracing
+
+# Run app in background
+$TESTAPP_BIN $NR_ITER $NR_USEC_WAIT >/dev/null 2>&1 &
+# Wait for app to complete
+while [ -n "$(pidof $TESTAPP_NAME)" ]; do
+       sleep 0.5
+done
+
+# Start the live test
+$TESTDIR/regression/tools/live/live_test
+
+clean_live_tracing
+
+# Kill the relayd
+PID_RELAYD=`pidof lt-$RELAYD_BIN`
+kill $PID_RELAYD >/dev/null 2>&1
+if [ $? -eq 1 ]; then
+       echo "Kill lttng-relayd (pid: $PID_RELAYD)"
+       exit 1
+else
+       out=1
+       while [ -n "$out" ]; do
+               out=$(pidof lt-$RELAYD_BIN)
+               sleep 0.5
+       done
+fi
+
+# Kill the sessiond
+PID_SESSIOND=`pidof lt-$SESSIOND_BIN`
+kill $PID_SESSIOND >/dev/null 2>&1
+if [ $? -eq 1 ]; then
+       echo "Kill sessiond daemon"
+       exit 1
+else
+       out=1
+       while [ -n "$out" ]; do
+               out=$(pidof lt-$SESSIOND_BIN)
+               sleep 0.5
+       done
+fi
index 7cd994f4c8bb6e3a9c0e410a1043497893e3e78e..f585cddd13e18d2b2f6c77dfceba3be144bdc1d0 100644 (file)
@@ -1,5 +1,7 @@
 regression/kernel/test_all_events
 regression/kernel/test_event_basic
+regression/tools/live/test_kernel
+regression/tools/live/test_lttng_kernel
 regression/tools/streaming/test_high_throughput_limits
 regression/tools/streaming/test_kernel
 regression/tools/snapshots/test_kernel
This page took 0.05852 seconds and 4 git commands to generate.