-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest_collfs.c
66 lines (55 loc) · 1.5 KB
/
test_collfs.c
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <dlfcn.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <sys/param.h>
#include <unistd.h>
#include <mpi.h>
#include "errmacros.h"
#include "foo.h"
extern int MPI_Init(int *argc, char ***argv) __attribute__ ((weak));
extern int MPI_Finalize() __attribute__ ((weak));
struct libc_collfs_api {
void (*fxstat64)(void);
void (*xstat64)(void);
void (*open)(void);
void (*close)(void);
void (*read)(void);
void (*lseek)(void);
void (*mmap)(void);
void (*munmap)(void);
};
struct libc_collfs_api _dl_collfs_api;
int run_tests(const char *soname, const char *path)
{
void *handle;
int err;
int (*func)(void);
int (*test_fxstat64)(const char *);
handle = dlopen(soname,RTLD_GLOBAL | RTLD_LAZY);
if (!handle) ERR("failed to dlopen(\"%s\",RTLD_GLOBAL | RTLD_LAZY) due to: %s", soname, dlerror());
func = dlsym(handle,"thefunc");
if (!func) ERR("dlsym could not find symbol \"thefunc\" due to: %s", dlerror());
err = (*func)();CHK(err);
err = dlclose(handle);
if (err) ERR("dlclose failed due to: %s", dlerror());
return 0;
}
int main(int argc, char *argv[])
{
int err;
char path[MAXPATHLEN];
if (MPI_Init) {
printf("MPI initialized\n");
MPI_Init(&argc,&argv);
}
if (!getcwd(path,sizeof path)) ERR("getcwd failed");
strcat(path,"/libminimal_thefunc.so");
err = run_tests(path, path);CHK(err);
err = foo(path);CHK(err);
err = foo2("alphabet.txt");CHK(err);
if (MPI_Finalize) MPI_Finalize();
return 0;
}