Add a tracepoint test program
authorDavid Goulet <david.goulet@polymtl.ca>
Fri, 1 Oct 2010 19:19:57 +0000 (21:19 +0200)
committerNils Carlson <nils.carlson@ericsson.com>
Mon, 11 Oct 2010 13:41:19 +0000 (15:41 +0200)
This test is aimed at testing different tracepoint case and
be used to ensure no bugs are added.

Complete description of the test in tracepoint_test.c

Signed-off-by: David Goulet <david.goulet@polymtl.ca>
Acked-by: Nils Carlson <nils.carlson@ericsson.com>
configure.ac
tests/Makefile.am
tests/runtests
tests/tracepoint/Makefile.am [new file with mode: 0644]
tests/tracepoint/run [new file with mode: 0755]
tests/tracepoint/tracepoint_test.c [new file with mode: 0644]
tests/tracepoint/tracepoint_test.h [new file with mode: 0644]

index 10a02e0e8204d23e88216b514353c7749bb349f6..42982c5b0df7f05e2c4c077ff811e9ba0a28d2e1 100644 (file)
@@ -122,6 +122,7 @@ AC_CONFIG_FILES([
        tests/dlopen/Makefile
        tests/same_line_marker/Makefile
        tests/trace_event/Makefile
+       tests/tracepoint/Makefile
        tests/register_test/Makefile
        libustinstr-malloc/Makefile
        libustfork/Makefile
index 1d31c3f646fa2de80d9bdab082ab13c8df8710d8..69801c0162a1bf24996de59a18469258492e2431 100644 (file)
@@ -1,3 +1,3 @@
-SUBDIRS = hello hello2 basic basic_long fork simple_include snprintf test-nevents test-libustinstr-malloc dlopen same_line_marker trace_event register_test
+SUBDIRS = hello hello2 basic basic_long fork simple_include snprintf test-nevents test-libustinstr-malloc dlopen same_line_marker trace_event register_test tracepoint
 
 dist_noinst_SCRIPTS = test_loop runtests trace_matches
index 602fc1e49210021f93864c8eda783332c9fc2e57..ff0025393b217f3c322a1e0e21d41760f7ddbbb8 100755 (executable)
@@ -43,6 +43,8 @@ simple_harness_run dlopen/dlopen.sh
 
 simple_harness_run same_line_marker/same_line_marker.sh
 
+simple_harness_run tracepoint/run
+
 echo "************************************"
 if [[ $tests_failed -eq 0 ]]; then
     echo "$0: All passed"
diff --git a/tests/tracepoint/Makefile.am b/tests/tracepoint/Makefile.am
new file mode 100644 (file)
index 0000000..37c8f20
--- /dev/null
@@ -0,0 +1,9 @@
+AM_CPPFLAGS = -I$(top_srcdir)/include
+
+noinst_PROGRAMS = tracepoint_test
+tracepoint_test_SOURCES = tracepoint_test.c tracepoint_test.h
+tracepoint_test_LDADD = $(top_builddir)/libust/libust.la $(top_builddir)/libust-initializer.o
+
+CFLAGS_tracepoint_test.o = -I$(src)
+noinst_SCRIPTS = run
+EXTRA_DIST = run
diff --git a/tests/tracepoint/run b/tests/tracepoint/run
new file mode 100755 (executable)
index 0000000..0da9864
--- /dev/null
@@ -0,0 +1,17 @@
+#!/bin/bash
+
+TESTDIR=$(dirname $0)/..
+
+source $TESTDIR/test_functions.sh
+source $TESTDIR/tap.sh
+
+starttest "Testing Tracepoints"
+plan_tests 6
+
+okx usttrace $TESTDIR/tracepoint/tracepoint_test
+trace_loc=$(usttrace -W)
+trace_matches -N "probe1" -n "5" "probe = 13" $trace_loc
+trace_matches -N "probe2" -n "5" "probe = 42" $trace_loc
+trace_matches -N "probe3" -n "1" "probe = \"probe3\"" $trace_loc
+trace_matches -N "probe4" -n "100" "probe4 = 42" $trace_loc
+check_trace_logs "$trace_loc"
diff --git a/tests/tracepoint/tracepoint_test.c b/tests/tracepoint/tracepoint_test.c
new file mode 100644 (file)
index 0000000..cd3939c
--- /dev/null
@@ -0,0 +1,107 @@
+/* Copyright (C) 2010 David Goulet <david.goulet@polymtl.ca>
+ *
+ * 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; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * 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
+ */
+
+/*
+ * This test is aimed at testing tracepoint *with* trace_mark :
+ *
+ * 1) tracepoint named : "ust_event"
+ *     -) Probe 1 registered and recording the value 13 (x5)
+ *     -) Probe 2 registered and recording the value 42 (x5)
+ *     -) Probe 3 registered and recording the payload of the struct message
+ *     but using a *different* tracepoint (event_msg)
+ *
+ * 2) tracepoint named : "ust_event2"
+ *     -) Probe 4 registered and recording the value 42 (x100)
+ */
+
+#include <stdio.h>
+#include <ust/marker.h>
+#include "tracepoint_test.h"
+
+DEFINE_TRACE(ust_event);
+DEFINE_TRACE(ust_event2);
+
+static struct message msg_probe3 = {
+       .payload = "probe3",
+};
+
+/*
+ * Probe 4 --> ust_event2
+ *     Will record 100 times the value 42
+ */
+void tp_probe4(void *data, unsigned int p4)
+{
+       int i;
+       for (i = 0; i < 100; i++) {
+               trace_mark_tp(ust, event2, ust_event2, tp_probe4, "probe4 %u", p4);
+       }
+}
+
+/*
+ * Probe 3 --> ust_event *and* event_msg (from inside)
+ *     Will record the payload of msg_prob3 struct
+ *     from the data pointer of the probe
+ */
+void tp_probe3(void *data, unsigned int p3)
+{
+       struct message *msg;
+       msg = (struct message*) data;
+       trace_mark_tp(ust, event_msg, ust_event_msg,
+                       tp_probe3, "probe %s", msg->payload);
+}
+
+/*
+ * Probe 2 --> ust_event
+ *     Will record 5 times the number 13
+ */
+void tp_probe2(void *data, unsigned int p2)
+{
+       int i;
+       for (i = 0; i < 5; i++) {
+               trace_mark_tp(ust, event, ust_event, tp_probe2, "probe %u", 13);
+       }
+}
+
+/*
+ * Probe 1 --> ust_event
+ *     Will record 5 times the unsigned int v = 42
+ */
+void tp_probe(void *data, unsigned int p1)
+{
+       int i;
+       for (i = 0; i < 5; i++) {
+               trace_mark_tp(ust, event, ust_event, tp_probe, "probe %u", p1);
+       }
+}
+
+static void __attribute__((constructor)) init()
+{
+       register_trace_ust_event(tp_probe, NULL);
+       register_trace_ust_event(tp_probe2, NULL);
+       register_trace_ust_event(tp_probe3, &msg_probe3);
+       register_trace_ust_event2(tp_probe4, NULL);
+}
+
+int main(int argc, char **argv) {
+       unsigned int v = 42;
+       /* Tracepoint 1 : ust_event */
+       trace_ust_event(v);
+       /* Tracepoint 2 : ust_event2 */
+       trace_ust_event2(v);
+
+       return 0;
+}
diff --git a/tests/tracepoint/tracepoint_test.h b/tests/tracepoint/tracepoint_test.h
new file mode 100644 (file)
index 0000000..6b4dcdb
--- /dev/null
@@ -0,0 +1,8 @@
+#include <ust/tracepoint.h>
+
+DECLARE_TRACE(ust_event, TP_PROTO(unsigned int v), TP_ARGS(v));
+DECLARE_TRACE(ust_event2, TP_PROTO(unsigned int v), TP_ARGS(v));
+
+struct message {
+       char *payload;
+};
This page took 0.027405 seconds and 4 git commands to generate.