aboutsummaryrefslogtreecommitdiff
path: root/libphobos/testsuite/libphobos.shared/linkDR.c
blob: 924709c18b6f1ebe9c09226c99cf5a8d0621b7ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <stdlib.h>
#include <string.h>
#include <dlfcn.h>
#include <assert.h>

extern void* rt_loadLibrary(const char*);
extern int rt_unloadLibrary(void*);
extern int rt_init(void);
extern int rt_term(void);

int main(int argc, char* argv[])
{
    if (!rt_init()) return EXIT_FAILURE;
    const size_t pathlen = strrchr(argv[0], '/') - argv[0] + 1;
    char *name = malloc(pathlen + sizeof("lib.so"));
    memcpy(name, argv[0], pathlen);
    memcpy(name+pathlen, "lib.so", sizeof("lib.so"));

    void *dlib = rt_loadLibrary(name);
    free(name);
    assert(dlib);

    int (*runTests)(void) = dlsym(dlib, "runTests");
    assert(runTests());
    assert(rt_unloadLibrary(dlib));
    if (!rt_term()) return EXIT_FAILURE;
    return EXIT_SUCCESS;
}