| 1 |
#include <stdlib.h> |
| 2 |
#include <string.h> |
| 3 |
#include <dlfcn.h> |
| 4 |
#include <assert.h> |
| 5 |
|
| 6 |
int main(int argc, char* argv[]) |
| 7 |
{ |
| 8 |
#if defined(__FreeBSD__) |
| 9 |
// workaround for Bugzilla 14824 |
| 10 |
void *druntime = dlopen(argv[1], RTLD_LAZY); // load druntime |
| 11 |
assert(druntime); |
| 12 |
#endif |
| 13 |
#if defined(__DragonFly__) |
| 14 |
// workaround for Bugzilla 14824 |
| 15 |
void *druntime = dlopen(argv[1], RTLD_LAZY); // load druntime |
| 16 |
assert(druntime); |
| 17 |
#endif |
| 18 |
|
| 19 |
const size_t pathlen = strrchr(argv[0], '/') - argv[0] + 1; |
| 20 |
char *name = malloc(pathlen + sizeof("plugin1.so")); |
| 21 |
memcpy(name, argv[0], pathlen); |
| 22 |
memcpy(name+pathlen, "plugin1.so", sizeof("plugin1.so")); |
| 23 |
|
| 24 |
void* plugin1 = dlopen(name, RTLD_LAZY); |
| 25 |
name[pathlen + sizeof("plugin1.so") - 5] = '2'; |
| 26 |
void* plugin2 = dlopen(name, RTLD_LAZY); |
| 27 |
|
| 28 |
int (*plugin1_init)() = dlsym(plugin1, "plugin_init"); |
| 29 |
int (*plugin1_term)() = dlsym(plugin1, "plugin_term"); |
| 30 |
int (*runTests1)() = dlsym(plugin1, "runTests"); |
| 31 |
int (*plugin2_init)() = dlsym(plugin2, "plugin_init"); |
| 32 |
int (*plugin2_term)() = dlsym(plugin2, "plugin_term"); |
| 33 |
int (*runTests2)() = dlsym(plugin2, "runTests"); |
| 34 |
assert(plugin1_init()); |
| 35 |
assert(runTests1()); |
| 36 |
assert(plugin2_init()); |
| 37 |
assert(runTests2()); |
| 38 |
|
| 39 |
assert(plugin1_term()); |
| 40 |
assert(dlclose(plugin1) == 0); |
| 41 |
assert(runTests2()); |
| 42 |
|
| 43 |
name[pathlen + sizeof("plugin1.so") - 5] = '1'; |
| 44 |
plugin1 = dlopen(name, RTLD_LAZY); |
| 45 |
plugin1_init = dlsym(plugin1, "plugin_init"); |
| 46 |
plugin1_term = dlsym(plugin1, "plugin_term"); |
| 47 |
runTests1 = dlsym(plugin1, "runTests"); |
| 48 |
assert(plugin1_init()); |
| 49 |
assert(runTests1()); |
| 50 |
assert(runTests2()); |
| 51 |
|
| 52 |
assert(plugin2_term()); |
| 53 |
assert(dlclose(plugin2) == 0); |
| 54 |
assert(runTests1()); |
| 55 |
|
| 56 |
assert(plugin1_term()); |
| 57 |
assert(dlclose(plugin1) == 0); |
| 58 |
|
| 59 |
free(name); |
| 60 |
|
| 61 |
#if defined(__FreeBSD__) |
| 62 |
dlclose(druntime); |
| 63 |
#endif |
| 64 |
#if defined(__DragonFly__) |
| 65 |
dlclose(druntime); |
| 66 |
#endif |
| 67 |
return EXIT_SUCCESS; |
| 68 |
} |