Test for a dynamically linked library
authorOussama El Mfadli <oussama@el-mfadli@polymtl.ca>
Fri, 14 May 2010 20:56:55 +0000 (16:56 -0400)
committerPierre-Marc Fournier <pierre-marc.fournier@polymtl.ca>
Fri, 21 May 2010 20:48:55 +0000 (16:48 -0400)
Correction of dynamic library marked test

configure.ac
tests/Makefile.am
tests/dlopen/Makefile.am [new file with mode: 0644]
tests/dlopen/dlopen.c [new file with mode: 0644]
tests/dlopen/libdummy.c [new file with mode: 0644]
tests/dlopen/run [new file with mode: 0755]
tests/runtests

index f9282f8844a86d86a9bf8e32ab0da84a204fe8f2..7b93653834781cf6b5f91820daee284e44bc20e9 100644 (file)
@@ -119,6 +119,7 @@ AC_CONFIG_FILES([
        tests/snprintf/Makefile
        tests/test-nevents/Makefile
        tests/test-libustinstr-malloc/Makefile
+       tests/dlopen/Makefile
        libustinstr-malloc/Makefile
        libustfork/Makefile
        ustd/Makefile
index 8e5c678f44f056b72fedf9f04ebd6df8e075df0b..cb00b56b0b2d949993b4d458f9f9570e0214c7c4 100644 (file)
@@ -1,3 +1,3 @@
-SUBDIRS = hello hello2 basic basic_long fork simple_include snprintf test-nevents test-libustinstr-malloc
+SUBDIRS = hello hello2 basic basic_long fork simple_include snprintf test-nevents test-libustinstr-malloc dlopen
 
 dist_noinst_SCRIPTS = test_loop runtests trace_matches
diff --git a/tests/dlopen/Makefile.am b/tests/dlopen/Makefile.am
new file mode 100644 (file)
index 0000000..89fd9db
--- /dev/null
@@ -0,0 +1,12 @@
+AM_CPPFLAGS = -I$(top_srcdir)/include
+
+noinst_PROGRAMS = dlopen
+noinst_LTLIBRARIES = libdummy.la
+libdummy_la_SOURCES = libdummy.c
+libdummy_la_LIBADD = $(top_builddir)/libust/libust.la $(top_builddir)/libust-initializer.o
+libdummy_la_LDFLAGS = -rpath /nowhere
+dlopen_SOURCES = dlopen.c
+dlopen_LDADD = -ldl $(top_builddir)/libust/libust.la $(top_builddir)/libust-initializer.o
+
+noinst_SCRIPTS = run
+EXTRA_DIST = run
diff --git a/tests/dlopen/dlopen.c b/tests/dlopen/dlopen.c
new file mode 100644 (file)
index 0000000..9fb0edd
--- /dev/null
@@ -0,0 +1,49 @@
+/* Copyright (C) 2010  Oussama El Mfadli, Alexis Hallé
+ *
+ * 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 <dlfcn.h>
+#include <stdio.h>
+#include <ust/marker.h>
+
+int main()
+{
+       int (*fptr)();
+
+       trace_mark(ust, from_main_before_lib, "%s", "Event occured in the main program before"
+                                               " the opening of the library\n");
+       void *lib_handle = dlopen("libdummy.so", RTLD_LAZY);
+
+       if (lib_handle == NULL) {
+               fprintf(stderr, "%s\n", dlerror());
+               return 1;
+       }
+
+       fptr = (int (*)())dlsym(lib_handle, "exported_function");
+
+       if ( fptr == NULL) {
+               fprintf(stderr, "%s\n", dlerror());
+               return 1;
+       }
+
+       (*fptr)();
+       dlclose(lib_handle);
+
+       trace_mark(ust, from_main_after_lib,"%s", "Event occured in the main program after "
+                                               "the library has been closed\n");
+
+       return 0;
+}
diff --git a/tests/dlopen/libdummy.c b/tests/dlopen/libdummy.c
new file mode 100644 (file)
index 0000000..45507c0
--- /dev/null
@@ -0,0 +1,23 @@
+/* Copyright (C) 2010  Oussama El Mfadli, Alexis Hallé
+ *
+ * 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/marker.h>
+
+void exported_function()
+{
+  trace_mark(ust, from_library, "%s", "Event occured in library function");
+}
diff --git a/tests/dlopen/run b/tests/dlopen/run
new file mode 100755 (executable)
index 0000000..eabab27
--- /dev/null
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+UST_AUTOPROBE=1 UST_TRACE=1 LD_LIBRARY_PATH=./.libs $1 ./dlopen
index 116bb1f069ea97330e0d9667eca532458972c0d4..40f7528e99df04509c57d31e9d87450b4cd2fcfe 100755 (executable)
@@ -109,6 +109,13 @@ wait $!
 echo "Valgrind output is in $VALG_OUT"
 NOFAIL [ -z "$(<$VALG_OUT)" ]
 
+### dlopen ###
+starttest "dlopen"
+LD_LIBRARY_PATH=$TESTDIR/dlopen/.libs NOFAIL usttrace $TESTDIR/dlopen/dlopen
+trace_loc=$(usttrace -W)
+NOFAIL $MATCHES -N "from_library" -n 1 "^ust.from_library:" $trace_loc
+NOFAIL $MATCHES -N "from_main_before_lib" -n 1 "^ust.from_main_before_lib:" $trace_loc
+NOFAIL $MATCHES -N "from_main_after_lib" -n 1 "^ust.from_main_after_lib:" $trace_loc
 echo "************************************"
 echo "$0: All passed"
 echo "************************************"
This page took 0.0269239999999999 seconds and 4 git commands to generate.