This source file includes following definitions.
- main
- try_open
- do_test
- main
1
2
3
4
5
6
7
8
9
10
11 #include "opal_config.h"
12
13 #include <stdio.h>
14 #include <string.h>
15 #include <stdlib.h>
16 #include <unistd.h>
17
18 #include "opal/runtime/opal.h"
19 #include "opal/util/printf.h"
20 #include "opal/mca/dl/base/base.h"
21
22 #if !OPAL_HAVE_DL_SUPPORT
23 int main(int argc, char *argv[])
24 {
25
26 fprintf(stderr, "OPAL was not built with libltdl support; skipping\n");
27 return 77;
28 }
29
30 #else
31
32 static int try_open(const char *filename)
33 {
34 char *err_msg;
35 opal_dl_handle_t *handle;
36 int ret;
37
38 ret = opal_dl_open(filename, true, true, &handle, &err_msg);
39 if (OPAL_SUCCESS == ret) {
40 opal_dl_close(handle);
41 printf("File opened with private namespace, all passed\n");
42 return 0;
43 }
44
45 printf("Failed to open with private namespace: %s\n", err_msg);
46 printf("Retrying with global namespace\n");
47
48 ret = opal_dl_open(filename, true, false, &handle, &err_msg);
49 if (OPAL_SUCCESS == ret) {
50 opal_dl_close(handle);
51 printf("File opened with global namespace\n");
52 return 0;
53 }
54
55 fprintf(stderr, "File failed to open with global namespace: %s\n",
56 err_msg);
57
58 return 2;
59 }
60
61 static int do_test(void)
62 {
63 FILE *fp;
64 char filename[] = "./libompi_dbg_msgq";
65 char full_filename[] = "./libompi_dbg_msgq.la";
66 char line[1024];
67 int happy;
68
69
70
71 fp = fopen(full_filename, "r");
72 if (NULL == fp) {
73 fprintf(stderr,
74 "File %s.la doesn't seem to exist; skipping this test\n",
75 full_filename);
76 exit(77);
77 }
78
79
80
81
82
83
84
85 happy = 0;
86 while (1) {
87 if (0 == fgets(line, sizeof(line) - 1, fp)) {
88 break;
89 }
90 if (0 == strncmp(line, "dlname=", 7)) {
91 if (0 == strncmp(line + 7, "''", 2)) {
92 happy = 0;
93 } else {
94 happy = 1;
95 }
96 break;
97 }
98 }
99 fclose(fp);
100 if (!happy) {
101 fprintf(stderr, "No test file to dlopen (perhaps --enable-static?); skipping\n");
102 exit(77);
103 }
104
105 char cwd[4096];
106 getcwd(cwd, sizeof(cwd) - 1);
107 cwd[sizeof(cwd) - 1] = '\0';
108 printf("Running in CWD: %s\n", cwd);
109
110 printf("Trying to open file with private namespace: %s\n", filename);
111
112
113 if (0 == try_open(filename)) {
114 return 0;
115 }
116
117
118
119
120
121
122
123 char *rel_filename;
124 opal_asprintf(&rel_filename, ".libs/%s", filename);
125 if (NULL == rel_filename) {
126 return 1;
127 }
128 int rc = try_open(rel_filename);
129 free(rel_filename);
130
131 return rc;
132 }
133
134 int main(int argc, char *argv[])
135 {
136 opal_init(&argc, &argv);
137 int ret = do_test();
138 opal_finalize();
139
140 return ret;
141 }
142 #endif