Quantcast

Valgrind: r16343 - in /trunk/drd/tests: Makefile.am dlopen.stderr.exp dlopen.stdout.exp dlopen.vgtest dlopen_lib.c dlopen_lib.h dlopen_main.c

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Valgrind: r16343 - in /trunk/drd/tests: Makefile.am dlopen.stderr.exp dlopen.stdout.exp dlopen.vgtest dlopen_lib.c dlopen_lib.h dlopen_main.c

svn-2
Author: bart
Date: Tue May  9 05:46:20 2017
New Revision: 16343

Log:
drd/tests: Add the "dlopen" test program

Added:
    trunk/drd/tests/dlopen.stderr.exp
    trunk/drd/tests/dlopen.stdout.exp
    trunk/drd/tests/dlopen.vgtest
    trunk/drd/tests/dlopen_lib.c
    trunk/drd/tests/dlopen_lib.h
    trunk/drd/tests/dlopen_main.c
Modified:
    trunk/drd/tests/Makefile.am

Modified: trunk/drd/tests/Makefile.am
==============================================================================
--- trunk/drd/tests/Makefile.am (original)
+++ trunk/drd/tests/Makefile.am Tue May  9 05:46:20 2017
@@ -103,6 +103,8 @@
  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 @@
   bug-235681          \
   custom_alloc        \
   concurrent_close    \
+  dlopen_main         \
+  dlopen_lib.so       \
   fp_race             \
   free_is_write      \
   hold_lock           \
@@ -455,6 +459,10 @@
 
 
 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@

Added: trunk/drd/tests/dlopen.stderr.exp
==============================================================================
--- trunk/drd/tests/dlopen.stderr.exp (added)
+++ trunk/drd/tests/dlopen.stderr.exp Tue May  9 05:46:20 2017
@@ -0,0 +1,3 @@
+
+
+ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

Added: trunk/drd/tests/dlopen.stdout.exp
==============================================================================
--- trunk/drd/tests/dlopen.stdout.exp (added)
+++ trunk/drd/tests/dlopen.stdout.exp Tue May  9 05:46:20 2017
@@ -0,0 +1,2 @@
+In main: creating thread 1
+Hello World! It's me, thread #1!

Added: trunk/drd/tests/dlopen.vgtest
==============================================================================
--- trunk/drd/tests/dlopen.vgtest (added)
+++ trunk/drd/tests/dlopen.vgtest Tue May  9 05:46:20 2017
@@ -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

Added: trunk/drd/tests/dlopen_lib.c
==============================================================================
--- trunk/drd/tests/dlopen_lib.c (added)
+++ trunk/drd/tests/dlopen_lib.c Tue May  9 05:46:20 2017
@@ -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);
+}

Added: trunk/drd/tests/dlopen_lib.h
==============================================================================
--- trunk/drd/tests/dlopen_lib.h (added)
+++ trunk/drd/tests/dlopen_lib.h Tue May  9 05:46:20 2017
@@ -0,0 +1 @@
+extern void foo();

Added: trunk/drd/tests/dlopen_main.c
==============================================================================
--- trunk/drd/tests/dlopen_main.c (added)
+++ trunk/drd/tests/dlopen_main.c Tue May  9 05:46:20 2017
@@ -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;
+}


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Valgrind-developers mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/valgrind-developers
Loading...