From 2b9093e12b00c876f5a5008700ede4e0d234dc43 Mon Sep 17 00:00:00 2001 From: Oussama El Mfadli Date: Fri, 14 May 2010 16:56:55 -0400 Subject: [PATCH] Test for a dynamically linked library Correction of dynamic library marked test --- configure.ac | 1 + tests/Makefile.am | 2 +- tests/dlopen/Makefile.am | 12 ++++++++++ tests/dlopen/dlopen.c | 49 ++++++++++++++++++++++++++++++++++++++++ tests/dlopen/libdummy.c | 23 +++++++++++++++++++ tests/dlopen/run | 3 +++ tests/runtests | 7 ++++++ 7 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 tests/dlopen/Makefile.am create mode 100644 tests/dlopen/dlopen.c create mode 100644 tests/dlopen/libdummy.c create mode 100755 tests/dlopen/run diff --git a/configure.ac b/configure.ac index f9282f88..7b936538 100644 --- a/configure.ac +++ b/configure.ac @@ -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 diff --git a/tests/Makefile.am b/tests/Makefile.am index 8e5c678f..cb00b56b 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -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 index 00000000..89fd9dbf --- /dev/null +++ b/tests/dlopen/Makefile.am @@ -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 index 00000000..9fb0edd9 --- /dev/null +++ b/tests/dlopen/dlopen.c @@ -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 +#include +#include + +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 index 00000000..45507c0e --- /dev/null +++ b/tests/dlopen/libdummy.c @@ -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 + +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 index 00000000..eabab27f --- /dev/null +++ b/tests/dlopen/run @@ -0,0 +1,3 @@ +#!/bin/sh + +UST_AUTOPROBE=1 UST_TRACE=1 LD_LIBRARY_PATH=./.libs $1 ./dlopen diff --git a/tests/runtests b/tests/runtests index 116bb1f0..40f7528e 100755 --- a/tests/runtests +++ b/tests/runtests @@ -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 "************************************" -- 2.34.1