| 1 |
#include <stdlib.h> |
| 2 |
#include <string.h> |
| 3 |
#include <dlfcn.h> |
| 4 |
#include <assert.h> |
| 5 |
|
| 6 |
extern void* rt_loadLibrary(const char*); |
| 7 |
extern int rt_unloadLibrary(void*); |
| 8 |
extern int rt_init(void); |
| 9 |
extern int rt_term(void); |
| 10 |
|
| 11 |
int main(int argc, char* argv[]) |
| 12 |
{ |
| 13 |
if (!rt_init()) return EXIT_FAILURE; |
| 14 |
const size_t pathlen = strrchr(argv[0], '/') - argv[0] + 1; |
| 15 |
char *name = malloc(pathlen + sizeof("lib.so")); |
| 16 |
memcpy(name, argv[0], pathlen); |
| 17 |
memcpy(name+pathlen, "lib.so", sizeof("lib.so")); |
| 18 |
|
| 19 |
void *dlib = rt_loadLibrary(name); |
| 20 |
free(name); |
| 21 |
assert(dlib); |
| 22 |
|
| 23 |
int (*runTests)(void) = dlsym(dlib, "runTests"); |
| 24 |
assert(runTests()); |
| 25 |
assert(rt_unloadLibrary(dlib)); |
| 26 |
if (!rt_term()) return EXIT_FAILURE; |
| 27 |
return EXIT_SUCCESS; |
| 28 |
} |