From: Bart Van Assche Date: Tue, 9 May 2017 04:46:20 +0000 (+0000) Subject: drd/tests: Add the "dlopen" test program X-Git-Tag: svn/VALGRIND_3_13_0~91 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dca461cf60f14422b35d4521ea1f6212b7bc29b6;p=thirdparty%2Fvalgrind.git drd/tests: Add the "dlopen" test program git-svn-id: svn://svn.valgrind.org/valgrind/trunk@16343 --- diff --git a/drd/tests/Makefile.am b/drd/tests/Makefile.am index 13620dc99d..9896ec5f76 100644 --- a/drd/tests/Makefile.am +++ b/drd/tests/Makefile.am @@ -103,6 +103,8 @@ EXTRA_DIST = \ custom_alloc.vgtest \ custom_alloc_fiw.stderr.exp \ custom_alloc_fiw.vgtest \ + dlopen.stderr.exp \ + dlopen.vgtest \ fp_race.stderr.exp \ fp_race.stderr.exp-mips32-be \ fp_race.stderr.exp-mips32-le \ @@ -361,6 +363,8 @@ check_PROGRAMS = \ bug-235681 \ custom_alloc \ concurrent_close \ + dlopen_main \ + dlopen_lib.so \ fp_race \ free_is_write \ hold_lock \ @@ -455,6 +459,10 @@ LDADD = -lpthread concurrent_close_SOURCES = concurrent_close.cpp +dlopen_main_LDADD = -ldl +dlopen_lib_so_SOURCES = dlopen_lib.c +dlopen_lib_so_CFLAGS = -fPIC +dlopen_lib_so_LDFLAGS = -shared -fPIC monitor_example_SOURCES = monitor_example.cpp new_delete_SOURCES = new_delete.cpp new_delete_CXXFLAGS = $(AM_CXXFLAGS) @FLAG_W_NO_MISMATCHED_NEW_DELETE@ diff --git a/drd/tests/dlopen.stderr.exp b/drd/tests/dlopen.stderr.exp new file mode 100644 index 0000000000..d18786f806 --- /dev/null +++ b/drd/tests/dlopen.stderr.exp @@ -0,0 +1,3 @@ + + +ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) diff --git a/drd/tests/dlopen.stdout.exp b/drd/tests/dlopen.stdout.exp new file mode 100644 index 0000000000..1f8a1413f2 --- /dev/null +++ b/drd/tests/dlopen.stdout.exp @@ -0,0 +1,2 @@ +In main: creating thread 1 +Hello World! It's me, thread #1! diff --git a/drd/tests/dlopen.vgtest b/drd/tests/dlopen.vgtest new file mode 100644 index 0000000000..ad114e88eb --- /dev/null +++ b/drd/tests/dlopen.vgtest @@ -0,0 +1,4 @@ +prereq: test -e dlopen_main && ./supported_libpthread +vgopts: --read-var-info=yes --check-stack-var=yes --show-confl-seg=no +prog: dlopen_main ./dlopen_lib.so +stderr_filter: filter_stderr diff --git a/drd/tests/dlopen_lib.c b/drd/tests/dlopen_lib.c new file mode 100644 index 0000000000..ea18fc5439 --- /dev/null +++ b/drd/tests/dlopen_lib.c @@ -0,0 +1,27 @@ +#include +#include +#include +#include "dlopen_lib.h" + +void *PrintHello(void *threadid) +{ + const long tid = (uintptr_t)threadid; + + printf("Hello World! It's me, thread #%ld!\n", tid); + pthread_exit(NULL); +} + + +void foo() +{ + pthread_t thread; + int rc; + uintptr_t t = 1; + + printf("In main: creating thread %ld\n", t); + rc = pthread_create(&thread, NULL, PrintHello, (void *)t); + if (rc) + printf("ERROR; return code from pthread_create() is %d\n", rc); + else + pthread_join(thread, NULL); +} diff --git a/drd/tests/dlopen_lib.h b/drd/tests/dlopen_lib.h new file mode 100644 index 0000000000..7fdb54e1b2 --- /dev/null +++ b/drd/tests/dlopen_lib.h @@ -0,0 +1 @@ +extern void foo(); diff --git a/drd/tests/dlopen_main.c b/drd/tests/dlopen_main.c new file mode 100644 index 0000000000..f879735b38 --- /dev/null +++ b/drd/tests/dlopen_main.c @@ -0,0 +1,29 @@ +#include +#include +#include +#include "dlopen_lib.h" + +int main(int argc, char **argv) +{ + const char *lib = argc > 1 ? argv[1] : "./libfoo.so"; + void *handle; + void (*function)(); + const char *error; + + handle = dlopen(lib, RTLD_NOW); + if (!handle) { + fputs (dlerror(), stderr); + exit(1); + } + + function = dlsym(handle, "foo"); + error = dlerror(); + if (error) { + fputs(error, stderr); + exit(1); + } + + (*function)(); + dlclose(handle); + return 0; +}