Update test-case for tracepoints and add a new test-case
authorNils Carlson <nils.carlson@ericsson.com>
Tue, 31 Aug 2010 13:45:08 +0000 (15:45 +0200)
committerNils Carlson <nils.carlson@ericsson.com>
Wed, 1 Sep 2010 12:04:37 +0000 (14:04 +0200)
Update the test-case for probes to handle a new data pointer
in the probe function. Also add a new test-case that stress-tests
probe registration and unregistration.

configure.ac
tests/Makefile.am
tests/hello/hello.c
tests/hello/tp.c
tests/register_test/Makefile.am [new file with mode: 0644]
tests/register_test/register_test.c [new file with mode: 0644]
tests/register_test/tp.h [new file with mode: 0644]

index dee974fcc92e1af2c865ba7fff3fb44c1c0ddb19..10a02e0e8204d23e88216b514353c7749bb349f6 100644 (file)
@@ -122,6 +122,7 @@ AC_CONFIG_FILES([
        tests/dlopen/Makefile
        tests/same_line_marker/Makefile
        tests/trace_event/Makefile
+       tests/register_test/Makefile
        libustinstr-malloc/Makefile
        libustfork/Makefile
        libustd/Makefile
index ab13cd73bb1b30c8cd1c51c777e915afd2d473ad..1d31c3f646fa2de80d9bdab082ab13c8df8710d8 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
+SUBDIRS = hello hello2 basic basic_long fork simple_include snprintf test-nevents test-libustinstr-malloc dlopen same_line_marker trace_event register_test
 
 dist_noinst_SCRIPTS = test_loop runtests trace_matches
index 86c5c71cacc9f4f27ee8308db3bffde85528db0e..8147860a9c9f36716b60e6249f15564802d0fd10 100644 (file)
@@ -26,8 +26,8 @@
 
 #include <ust/marker.h>
 #include "usterr.h"
-#include "tp.h"
 #include "tracer.h"
+#include "tp.h"
 
 void inthandler(int sig)
 {
index be10615a26d57f680100c19138fb1278d7eac794..3a4c6fcaf15ac93ff85b183ba8dc3dbeeedb6036 100644 (file)
 #include <ust/marker.h>
 #include "usterr.h"
 
+struct hello_trace_struct {
+       char *message;
+};
+
+struct hello_trace_struct hello_struct = {
+       .message = "ehlo\n",
+};
+
 DEFINE_TRACE(hello_tptest);
 
-void tptest_probe(int anint)
+void tptest_probe(void *data, int anint)
 {
+       struct hello_trace_struct *hello;
+       hello=(struct hello_trace_struct *)data;
        DBG("in tracepoint probe...");
-       trace_mark(ust, tptest, "anint %d", anint);
+       printf("this is the message: %s\n", hello->message);
 }
 
 static void __attribute__((constructor)) init()
 {
-       DBG("connecting tracepoint...");
-       register_trace_hello_tptest(tptest_probe);
+       DBG("connecting tracepoint...\n");
+       register_trace_hello_tptest(tptest_probe, &hello_struct);
 }
diff --git a/tests/register_test/Makefile.am b/tests/register_test/Makefile.am
new file mode 100644 (file)
index 0000000..ff25e08
--- /dev/null
@@ -0,0 +1,5 @@
+AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/libust
+
+noinst_PROGRAMS = register_test
+register_test_SOURCES = register_test.c tp.h
+register_test_LDADD = $(top_builddir)/libust/libust.la $(top_builddir)/libust-initializer.o
diff --git a/tests/register_test/register_test.c b/tests/register_test/register_test.c
new file mode 100644 (file)
index 0000000..8b65ffb
--- /dev/null
@@ -0,0 +1,97 @@
+/* Copyright (C) 2010 Nils Carlson
+ *
+ * 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
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+#include <sys/mman.h>
+#include <stdarg.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/timerfd.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <pthread.h>
+
+#include <ust/marker.h>
+#include "usterr.h"
+#include "tracer.h"
+#include "tp.h"
+
+DEFINE_TRACE(hello_tptest);
+
+
+struct hello_trace_struct {
+       char *message;
+};
+
+struct hello_trace_struct hello_struct = {
+       .message = "ehlo\n",
+};
+
+void tptest_probe(void *data, int anint)
+{
+       struct hello_trace_struct *hello;
+       char message[30];
+       hello=(struct hello_trace_struct *)data;
+       //printf("this is the message: %s\n", hello->message);
+       snprintf(message, 30, "this is the %s\n", hello->message);
+}
+
+
+#define HELLO_LENGTH 100
+
+static void * register_thread_main(void *data)
+{
+       int ret, i, j = 0;
+
+       struct hello_trace_struct hello[HELLO_LENGTH];
+
+       for (i=0; i<HELLO_LENGTH; i++) {
+               hello[i].message = malloc(6*sizeof(char));
+               hello[i].message[0] = 'a'+i%25;
+               memcpy(&hello[i].message[1], "ello", 5);
+       }
+
+       for (i=0; i<1000; i++) {
+               while (!register_trace_hello_tptest(tptest_probe,
+                                                   &hello[j%HELLO_LENGTH])) {
+                       usleep(10);
+                       j++;
+               }
+               printf("Registered all\n");
+               while (!unregister_trace_hello_tptest(tptest_probe,
+                                                     &hello[j%HELLO_LENGTH])) {
+                       usleep(10);
+                       j++;
+               }
+               printf("Unregistered all\n");
+       }
+}
+
+
+int main()
+{
+       pthread_t register_thread;
+       int i;
+
+       pthread_create(&register_thread, NULL, register_thread_main, NULL);
+       for(i=0; i<1000000; i++) {
+               trace_hello_tptest(i);
+       }
+
+       return 0;
+}
diff --git a/tests/register_test/tp.h b/tests/register_test/tp.h
new file mode 100644 (file)
index 0000000..f34f305
--- /dev/null
@@ -0,0 +1,22 @@
+/* Copyright (C) 2009  Pierre-Marc Fournier
+ *
+ * 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
+ */
+
+#include <ust/tracepoint.h>
+
+DECLARE_TRACE(hello_tptest,
+             TP_PROTO(int anint),
+             TP_ARGS(anint));
This page took 0.027441 seconds and 4 git commands to generate.