Add kernel trace data structure test
authorDavid Goulet <david.goulet@polymtl.ca>
Mon, 25 Jul 2011 20:50:12 +0000 (16:50 -0400)
committerDavid Goulet <david.goulet@polymtl.ca>
Mon, 25 Jul 2011 20:53:27 +0000 (16:53 -0400)
Test all kernel data structure found in ltt-sessiond/trace.c/.h.

Also adds a utils.h having a pretty print for OK and FAIL. The session
test is modified to use those prints.

Better runall.sh which iterates over an array containing test binaries
name and terminates when one test fails.

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

index 7fe9bf16af2eebcceafd416c318283a20baee7b2..e2c7857cc26fe1d8b7450b431787a7226f3062fa 100644 (file)
@@ -29,3 +29,4 @@ lttng/lttng
 ltt-kconsumerd/ltt-kconsumerd
 
 tests/test_sessions
+tests/test_kernel_data_trace
index 761586e4c6bf18d81d28c463c1db666973f6ca00..29b8ba4f925d8d519dcff407e9f2acd33b521fa1 100644 (file)
@@ -1,11 +1,14 @@
 AM_CFLAGS=-I$(top_srcdir)/include -I$(top_srcdir)/libkernelctl \
                  -I$(top_srcdir)/liblttngctl -g -Wall
 
-noinst_PROGRAMS = test_sessions
+noinst_PROGRAMS = test_sessions test_kernel_data_trace
 
 SESSIONS=$(top_srcdir)/ltt-sessiond/session.c
+KERN_DATA_TRACE=$(top_srcdir)/ltt-sessiond/trace.c
 
 test_sessions_SOURCES = test_sessions.c $(SESSIONS)
 
+test_kernel_data_trace_SOURCES = test_kernel_data_trace.c $(KERN_DATA_TRACE)
+
 check-am:
        ./runall.sh
index e7f83ed11e2a89e09bd7b2737a4b9d13d80776dd..b0ae4fd4cf7b07eb3056dc794cbb16fb15b602e3 100755 (executable)
 
 #### ADD TESTS HERE ####
 
-for bin in test_sessions;
+test_suite=( test_sessions test_kernel_data_trace )
+
+#### END TESTS HERE ####
+
+for bin in ${test_suite[@]};
 do
        ./$bin
+       # Test must return 0 to pass.
+       if [ $? -ne 0 ]; then
+               echo -e '\e[1;31mFAIL\e[0m'
+               echo ""
+               exit 1
+       fi
 done
 
-#### END TESTS HERE ####
-
 echo ""
 exit 0
diff --git a/tests/test_kernel_data_trace.c b/tests/test_kernel_data_trace.c
new file mode 100644 (file)
index 0000000..93fa64c
--- /dev/null
@@ -0,0 +1,198 @@
+/*
+ * 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 "ltt-sessiond/trace.h"
+#include "utils.h"
+
+/* This path will NEVER be created in this test */
+#define PATH1 "/tmp/.test-junk-lttng"
+
+/* For lttngerr.h */
+int opt_quiet = 1;
+int opt_verbose = 0;
+
+static const char alphanum[] =
+       "0123456789"
+       "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+       "abcdefghijklmnopqrstuvwxyz";
+
+static struct ltt_kernel_session *kern;
+
+/*
+ * Return random string of 10 characters.
+ */
+static char *get_random_string(void)
+{
+       int i;
+       char *str = malloc(11);
+
+       for (i = 0; i < 10; i++) {
+               str[i] = alphanum[rand() % (sizeof(alphanum) - 1)];
+       }
+
+       str[10] = '\0';
+
+       return str;
+}
+
+static void create_one_kernel_session(void)
+{
+       printf("Create kernel session: ");
+       kern = trace_create_kernel_session();
+       assert(kern != NULL);
+       PRINT_OK();
+
+       printf("Validating kernel session: ");
+       assert(kern->fd == 0);
+       assert(kern->metadata_stream_fd == 0);
+       assert(kern->kconsumer_fds_sent == 0);
+       assert(kern->channel_count == 0);
+       assert(kern->stream_count_global == 0);
+       assert(kern->metadata == NULL);
+       PRINT_OK();
+
+       /* Init list in order to avoid sefaults from cds_list_del */
+       trace_destroy_kernel_session(kern);
+}
+
+static void create_kernel_metadata(void)
+{
+       assert(kern != NULL);
+
+       printf("Create kernel metadata: ");
+       kern->metadata = trace_create_kernel_metadata(PATH1);
+       assert(kern->metadata != NULL);
+       PRINT_OK();
+
+       printf("Validating kernel session metadata: ");
+       assert(kern->metadata->fd == 0);
+       assert(strlen(kern->metadata->pathname));
+       assert(kern->metadata->conf != NULL);
+       assert(kern->metadata->conf->attr.overwrite
+                       == DEFAULT_CHANNEL_OVERWRITE);
+       assert(kern->metadata->conf->attr.subbuf_size
+                       == DEFAULT_CHANNEL_SUBBUF_SIZE);
+       assert(kern->metadata->conf->attr.num_subbuf
+                       == DEFAULT_CHANNEL_SUBBUF_NUM);
+       assert(kern->metadata->conf->attr.switch_timer_interval
+                       == DEFAULT_CHANNEL_SWITCH_TIMER);
+       assert(kern->metadata->conf->attr.read_timer_interval
+                       == DEFAULT_CHANNEL_READ_TIMER);
+       assert(kern->metadata->conf->attr.output
+                       == DEFAULT_KERNEL_CHANNEL_OUTPUT);
+       PRINT_OK();
+
+       trace_destroy_kernel_metadata(kern->metadata);
+}
+
+static void create_kernel_channel(void)
+{
+       struct ltt_kernel_channel *chan;
+       struct lttng_channel attr;
+
+       printf("Creating kernel channel: ");
+       chan = trace_create_kernel_channel(&attr, PATH1);
+       assert(chan != NULL);
+       PRINT_OK();
+
+       printf("Validating kernel channel: ");
+       assert(chan->fd == 0);
+       assert(chan->enabled == 1);
+       assert(strcmp(PATH1, chan->pathname) == 0);
+       assert(chan->stream_count == 0);
+       assert(chan->ctx == NULL);
+       assert(chan->channel->attr.overwrite  == attr.attr.overwrite);
+       PRINT_OK();
+
+       /* Init list in order to avoid sefaults from cds_list_del */
+       CDS_INIT_LIST_HEAD(&chan->list);
+       trace_destroy_kernel_channel(chan);
+}
+
+static void create_kernel_event(void)
+{
+       struct ltt_kernel_event *event;
+       struct lttng_event ev;
+
+       strncpy(ev.name, get_random_string(), LTTNG_SYM_NAME_LEN);
+       ev.type = LTTNG_EVENT_TRACEPOINT;
+
+       printf("Creating kernel event: ");
+       event = trace_create_kernel_event(&ev);
+       assert(event != NULL);
+       PRINT_OK();
+
+       printf("Validating kernel event: ");
+       assert(event->fd == 0);
+       assert(event->enabled == 1);
+       assert(event->ctx == NULL);
+       assert(event->event->instrumentation == LTTNG_KERNEL_TRACEPOINT);
+       assert(strlen(event->event->name));
+       PRINT_OK();
+
+       /* Init list in order to avoid sefaults from cds_list_del */
+       CDS_INIT_LIST_HEAD(&event->list);
+       trace_destroy_kernel_event(event);
+}
+
+static void create_kernel_stream(void)
+{
+       struct ltt_kernel_stream *stream;
+
+       printf("Creating kernel stream: ");
+       stream = trace_create_kernel_stream();
+       assert(stream != NULL);
+       PRINT_OK();
+
+       printf("Validating kernel stream: ");
+       assert(stream->fd == 0);
+       assert(stream->pathname == NULL);
+       assert(stream->state == 0);
+       PRINT_OK();
+
+       /* Init list in order to avoid sefaults from cds_list_del */
+       CDS_INIT_LIST_HEAD(&stream->list);
+       trace_destroy_kernel_stream(stream);
+}
+
+int main(int argc, char **argv)
+{
+       printf("\nTesting kernel data structures:\n-----------\n");
+
+       create_one_kernel_session();
+
+       create_kernel_metadata();
+       create_kernel_channel();
+
+
+       create_kernel_event();
+
+       create_kernel_stream();
+
+       /* Success */
+       return 0;
+}
index f3ffe6a43932d8b03ca8c833bcce7753b077da27..422c4160387575fff6e6929cf15685ceb9f8f393 100644 (file)
@@ -26,6 +26,7 @@
 #include <time.h>
 
 #include "ltt-sessiond/session.h"
+#include "utils.h"
 
 #define SESSION1 "test1"
 
@@ -259,7 +260,7 @@ int main(int argc, char **argv)
        if (ret < 0) {
                return -1;
        }
-       printf("Success\n");
+       PRINT_OK();
 
        printf("Validating created session %s: ", SESSION1);
        tmp = find_session_by_name(SESSION1);
@@ -274,21 +275,21 @@ int main(int argc, char **argv)
        lock_session(tmp);
        unlock_session(tmp);
 
-       printf("Success\n");
+       PRINT_OK();
 
        printf("Destroy 1 session %s: ", SESSION1);
        ret = destroy_one_session(SESSION1);
        if (ret < 0) {
                return -1;
        }
-       printf("Success\n");
+       PRINT_OK();
 
        printf("Two session with same name: ");
        ret = two_session_same_name();
        if (ret < 0) {
                return -1;
        }
-       printf("Success\n");
+       PRINT_OK();
 
        empty_session_list();
 
@@ -297,14 +298,14 @@ int main(int argc, char **argv)
        if (ret < 0) {
                return -1;
        }
-       printf("Success\n");
+       PRINT_OK();
 
        printf("Fuzzing destroy_session argument: ");
        ret = fuzzing_destroy_args();
        if (ret < 0) {
                return -1;
        }
-       printf("Success\n");
+       PRINT_OK();
 
        printf("Creating %d sessions: ", MAX_SESSIONS);
        for (i = 0; i < MAX_SESSIONS; i++) {
@@ -316,7 +317,7 @@ int main(int argc, char **argv)
                }
                free(tmp_name);
        }
-       printf("Success\n");
+       PRINT_OK();
 
        printf("Destroying %d sessions: ", MAX_SESSIONS);
        for (i = 0; i < MAX_SESSIONS; i++) {
@@ -328,7 +329,7 @@ int main(int argc, char **argv)
                        }
                }
        }
-       printf("Success\n");
+       PRINT_OK();
 
        /* Session list must be 0 */
        assert(!session_list->count);
diff --git a/tests/utils.h b/tests/utils.h
new file mode 100644 (file)
index 0000000..52893b2
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * 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.
+ */
+
+#include <stdio.h>
+
+#define BRIGHT 1
+#define GREEN 32
+#define RED 31
+
+#define PRINT_OK() printf("%c[%d;%dmOK%c[%dm\n", 0x1B, BRIGHT, GREEN, 0x1B, 0);
+#define PRINT_FAIL() printf("%c[%d;%dmFAIL%c[%dm\n", 0x1B, BRIGHT, RED, 0x1B, 0);
This page took 0.043121 seconds and 4 git commands to generate.