[OptTable] Fix typo VALUE => VALUES (NFCI) (#121523)
[llvm-project.git] / compiler-rt / test / profile / AIX / gcov-dlopen-dlclose.test
blob21a56bd4199e846152d37f5c4a86250a74365027
1 RUN: rm -rf %t && split-file %s %t && cd %t
2 RUN: %clang foo.c -c --coverage
3 RUN: %clang foo2.c -c --coverage
4 RUN: %clang -shared foo.o -o shr.o --coverage
5 RUN: ar -X32_64 r libfoo.a shr.o
6 RUN: %clang -shared foo2.o -o shr.o --coverage
7 RUN: ar -X32_64 r libfoo2.a shr.o
9 RUN: %clang common.c -c --coverage
11 RUN: %clang test1.c common.o  --coverage
12 RUN: ./a.out
14 //--- foo.c
15 void foo() {}
17 //--- foo2.c
18 void foo2() {}
20 //--- common.c
21 #include <dlfcn.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 typedef void (*FN_PTR)();
25 int open_close_libs() {
26   void *handle, *handle2;
27   FN_PTR foo, foo2;
29 #define OPEN_AND_RUN(HANDLE, SUF)                                            \
30   HANDLE = dlopen("./lib" #SUF ".a(shr.o)",RTLD_NOW|RTLD_MEMBER);            \
31   SUF = (void (*)())dlsym(HANDLE, #SUF);                                     \
32   if (SUF == NULL) {                                                         \
33     fprintf(stderr, "unable to lookup symbol '%s': %s\n", #SUF, dlerror());  \
34     return EXIT_FAILURE;                                                     \
35   }                                                                          \
36   SUF();
38 #define CLOSE_AND_CHECK(HANDLE, SUF)                                         \
39   dlclose(HANDLE);                                                           \
40   system("ls " #SUF ".gc*");
42   OPEN_AND_RUN(handle, foo)
43   CLOSE_AND_CHECK(handle, foo)
45   OPEN_AND_RUN(handle2, foo2)
46   OPEN_AND_RUN(handle, foo)
47   CLOSE_AND_CHECK(handle2, foo2)
48   CLOSE_AND_CHECK(handle, foo)
49   return EXIT_SUCCESS;
51 //--- test1.c
52 int open_close_libs();
53 int main() {
54   open_close_libs();