]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
drd/tests: Add the "dlopen" test program
authorBart Van Assche <bvanassche@acm.org>
Tue, 9 May 2017 04:46:20 +0000 (04:46 +0000)
committerBart Van Assche <bvanassche@acm.org>
Tue, 9 May 2017 04:46:20 +0000 (04:46 +0000)
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@16343

drd/tests/Makefile.am
drd/tests/dlopen.stderr.exp [new file with mode: 0644]
drd/tests/dlopen.stdout.exp [new file with mode: 0644]
drd/tests/dlopen.vgtest [new file with mode: 0644]
drd/tests/dlopen_lib.c [new file with mode: 0644]
drd/tests/dlopen_lib.h [new file with mode: 0644]
drd/tests/dlopen_main.c [new file with mode: 0644]

index 13620dc99d2d285c6bf8159921eb63a471e5b456..9896ec5f76d78fbf44ad276e59462ed412f3adea 100644 (file)
@@ -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 (file)
index 0000000..d18786f
--- /dev/null
@@ -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 (file)
index 0000000..1f8a141
--- /dev/null
@@ -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 (file)
index 0000000..ad114e8
--- /dev/null
@@ -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 (file)
index 0000000..ea18fc5
--- /dev/null
@@ -0,0 +1,27 @@
+#include <stdio.h>
+#include <stdint.h>
+#include <pthread.h>
+#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 (file)
index 0000000..7fdb54e
--- /dev/null
@@ -0,0 +1 @@
+extern void foo();
diff --git a/drd/tests/dlopen_main.c b/drd/tests/dlopen_main.c
new file mode 100644 (file)
index 0000000..f879735
--- /dev/null
@@ -0,0 +1,29 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <dlfcn.h>
+#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;
+}