mirror of
git://sourceware.org/git/valgrind.git
synced 2026-01-12 00:19:31 +08:00
drd/tests: Add the "dlopen" test program
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@16343
This commit is contained in:
@@ -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@
|
||||
|
||||
3
drd/tests/dlopen.stderr.exp
Normal file
3
drd/tests/dlopen.stderr.exp
Normal file
@@ -0,0 +1,3 @@
|
||||
|
||||
|
||||
ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
|
||||
2
drd/tests/dlopen.stdout.exp
Normal file
2
drd/tests/dlopen.stdout.exp
Normal file
@@ -0,0 +1,2 @@
|
||||
In main: creating thread 1
|
||||
Hello World! It's me, thread #1!
|
||||
4
drd/tests/dlopen.vgtest
Normal file
4
drd/tests/dlopen.vgtest
Normal file
@@ -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
|
||||
27
drd/tests/dlopen_lib.c
Normal file
27
drd/tests/dlopen_lib.c
Normal file
@@ -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);
|
||||
}
|
||||
1
drd/tests/dlopen_lib.h
Normal file
1
drd/tests/dlopen_lib.h
Normal file
@@ -0,0 +1 @@
|
||||
extern void foo();
|
||||
29
drd/tests/dlopen_main.c
Normal file
29
drd/tests/dlopen_main.c
Normal file
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user