This source file includes following definitions.
- main
- test1
- test2
- test3
- test4
- test5
- test6
- test7
- test8
- clear_proc_info
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 #include "orte_config.h"
20
21 #include <stdio.h>
22 #include <string.h>
23 #include <stdlib.h>
24 #ifdef HAVE_UNISTD_H
25 #include <unistd.h>
26 #endif
27 #ifdef HAVE_SYS_PARAM_H
28 #include <sys/param.h>
29 #endif
30 #include <sys/stat.h>
31
32 #include "support.h"
33 #include "orte/constants.h"
34 #include "orte/util/proc_info.h"
35 #include "opal/util/os_path.h"
36 #include "orte/util/session_dir.h"
37 #include "orte/util/proc_info.h"
38
39
40 static bool test1(void);
41 static bool test2(void);
42 static bool test3(void);
43 static bool test4(void);
44 static bool test5(void);
45 static bool test6(void);
46 static bool test7(void);
47 static bool test8(void);
48
49 void clear_proc_info(void);
50
51 static FILE *test_out=NULL;
52
53 int main(int argc, char* argv[])
54 {
55 orte_proc_info();
56 orte_process_info.my_name = (orte_process_name_t*)malloc(sizeof(orte_process_name_t));
57 orte_process_info.my_name->cellid = 0;
58 orte_process_info.my_name->jobid = 0;
59 orte_process_info.my_name->vpid = 0;
60
61 test_init("orte_session_dir_t");
62 test_out = fopen( "test_session_dir_out", "w+" );
63 if( test_out == NULL ) {
64 test_failure("test_session_dir couldn't open test file failed");
65 test_finalize();
66 exit(1);
67 }
68
69
70 fprintf(test_out, "running test1\n");
71 if (test1()) {
72 test_success();
73 }
74 else {
75 test_failure("orte_session_dir_t test1 failed");
76 }
77
78 fprintf(test_out, "running test2\n");
79 if (test2()) {
80 test_success();
81 }
82 else {
83 test_failure("orte_session_dir_t test2 failed");
84 }
85
86 fprintf(test_out, "running test3\n");
87 if (test3()) {
88 test_success();
89 }
90 else {
91 test_failure("orte_session_dir_t test3 failed");
92 }
93
94 fprintf(test_out, "running test4\n");
95 if (test4()) {
96 test_success();
97 }
98 else {
99 test_failure("orte_session_dir_t test4 failed");
100 }
101
102 fprintf(test_out, "running test5\n");
103 if (test5()) {
104 test_success();
105 }
106 else {
107 test_failure("orte_session_dir_t test5 failed");
108 }
109
110 fprintf(test_out, "running test6\n");
111 if (test6()) {
112 test_success();
113 }
114 else {
115 test_failure("orte_session_dir_t test6 failed");
116 }
117
118 fprintf(test_out, "running test7\n");
119 if (test7()) {
120 test_success();
121 }
122 else {
123 test_failure("orte_session_dir_t test7 failed");
124 }
125
126 fprintf(test_out, "running test8\n");
127 if (test8()) {
128 test_success();
129 }
130 else {
131 test_failure("orte_session_dir_t test8 failed");
132 }
133
134 fprintf(test_out, "completed all tests\n");
135
136 fclose(test_out);
137
138
139 orte_proc_info_finalize();
140
141 test_finalize();
142 return 0;
143 }
144
145
146 static bool test1(void)
147 {
148
149
150 char *prefix;
151
152
153
154 clear_proc_info();
155
156 prefix = opal_os_path(false, "tmp", NULL);
157 if (ORTE_SUCCESS != orte_session_dir(true, prefix, NULL, NULL, "test-universe", NULL, NULL)) {
158 fprintf(test_out, "test1 - couldn't create specified path\n");
159 free(prefix);
160 return(false);
161 }
162
163
164 if (ORTE_SUCCESS != orte_session_dir(false, prefix, NULL, NULL, "test-universe", NULL, NULL)) {
165 fprintf(test_out, "test1 - couldn't access existing path\n");
166 free(prefix);
167 return(false);
168 }
169
170 orte_session_dir_finalize(orte_process_info.my_name);
171 free(orte_process_info.universe_session_dir);
172 free(prefix);
173
174 return true;
175 }
176
177
178 static bool test2(void)
179 {
180 clear_proc_info();
181
182
183
184 setenv("OMPI_PREFIX_ENV", "/tmp/trythis", 1);
185
186 if (ORTE_SUCCESS != orte_session_dir(true, NULL, NULL, NULL, "test-universe", NULL, NULL)) {
187 unsetenv("OMPI_PREFIX_ENV");
188 return(false);
189 }
190
191 orte_session_dir_finalize(orte_process_info.my_name);
192
193 unsetenv("OMPI_PREFIX_ENV");
194
195 return(true);
196
197 }
198
199
200 static bool test3(void)
201 {
202
203 clear_proc_info();
204
205 setenv("TMPDIR", "/tmp/trythis", 1);
206
207 if (ORTE_SUCCESS != orte_session_dir(true, NULL, NULL, NULL, "test-universe", NULL, NULL)) {
208 unsetenv("TMPDIR");
209 return(false);
210 }
211
212 orte_session_dir_finalize(orte_process_info.my_name);
213
214 unsetenv("TMPDIR");
215
216 return(true);
217 }
218
219
220 static bool test4(void)
221 {
222
223
224 clear_proc_info();
225
226 setenv("TMP", "/tmp/trythis", 1);
227
228 if (ORTE_SUCCESS != orte_session_dir(true, NULL, NULL, NULL, "test-universe", NULL, NULL)) {
229 unsetenv("TMP");
230 return(false);
231 }
232
233 orte_session_dir_finalize(orte_process_info.my_name);
234
235 unsetenv("TMP");
236
237 return(true);
238 }
239
240
241 static bool test5(void)
242 {
243
244
245 clear_proc_info();
246
247 setenv("HOME", "/tmp/trythis", 1);
248
249 if (ORTE_SUCCESS != orte_session_dir(true, NULL, NULL, NULL, "test-universe", NULL, NULL)) {
250 unsetenv("HOME");
251 return(false);
252 }
253
254 orte_session_dir_finalize(orte_process_info.my_name);
255
256 unsetenv("HOME");
257
258 return(true);
259 }
260
261
262 static bool test6(void)
263 {
264
265 clear_proc_info();
266
267
268
269
270
271 if (ORTE_SUCCESS != orte_session_dir(true, NULL, NULL, NULL, "test-universe", NULL, NULL)) {
272 return(false);
273 }
274
275 orte_session_dir_finalize(orte_process_info.my_name);
276
277 return(true);
278 }
279
280 static bool test7(void)
281 {
282 char *filenm[5];
283 FILE *fp;
284 int i;
285
286 clear_proc_info();
287
288
289 if (ORTE_SUCCESS != orte_session_dir(true, NULL, "localhost", NULL, "test-universe", "test-job", "test-proc")) {
290 return(false);
291 }
292
293 fprintf(test_out, "removing directories: %s\n\t%s\n\t%s\n",
294 orte_process_info.proc_session_dir,
295 orte_process_info.job_session_dir,
296 orte_process_info.universe_session_dir);
297
298
299
300 filenm[0] = opal_os_path(false, orte_process_info.proc_session_dir, "dum1", NULL);
301 fp = fopen(filenm[0], "w");
302 fprintf(fp, "ss");
303 fclose(fp);
304
305 filenm[1] = opal_os_path(false, orte_process_info.job_session_dir, "dum2", NULL);
306 fp = fopen(filenm[1], "w");
307 fprintf(fp, "ss");
308 fclose(fp);
309
310 filenm[2] = opal_os_path(false, orte_process_info.universe_session_dir, "dum3", NULL);
311 fp = fopen(filenm[2], "w");
312 fprintf(fp, "ss");
313 fclose(fp);
314
315 if (ORTE_SUCCESS != orte_session_dir_finalize(orte_process_info.my_name)) {
316 return(false);
317 }
318
319 for (i=0; i < 3; i++) unlink(filenm[i]);
320 orte_session_dir_finalize(orte_process_info.my_name);
321
322 return true;
323 }
324
325 static bool test8(void)
326 {
327 char *filenm[5];
328 FILE *fp;
329 int i;
330
331 clear_proc_info();
332
333
334 if (ORTE_SUCCESS != orte_session_dir(true, NULL, "localhost", NULL, "test-universe2", "test-job2", "test-proc2")) {
335 return(false);
336 }
337
338 fprintf(test_out, "removing directories: %s\n\t%s\n\t%s\n",
339 orte_process_info.proc_session_dir,
340 orte_process_info.job_session_dir,
341 orte_process_info.universe_session_dir);
342
343
344
345 filenm[0] = opal_os_path(false, orte_process_info.proc_session_dir, "dum1", NULL);
346 fp = fopen(filenm[0], "w");
347 fprintf(fp, "ss");
348 fclose(fp);
349
350 filenm[1] = opal_os_path(false, orte_process_info.job_session_dir, "dum2", NULL);
351 fp = fopen(filenm[1], "w");
352 fprintf(fp, "ss");
353 fclose(fp);
354
355 filenm[2] = opal_os_path(false, orte_process_info.universe_session_dir, "dum3", NULL);
356 fp = fopen(filenm[2], "w");
357 fprintf(fp, "ss");
358 fclose(fp);
359
360
361 if (ORTE_SUCCESS != orte_session_dir_finalize(orte_process_info.my_name)) {
362 return(false);
363 }
364
365 for (i=0; i < 3; i++) unlink(filenm[i]);
366 orte_session_dir_finalize(orte_process_info.my_name);
367
368 return true;
369 }
370
371 void clear_proc_info(void)
372 {
373 orte_process_info.tmpdir_base = NULL;
374 orte_process_info.top_session_dir = NULL;
375 orte_process_info.universe_session_dir = NULL;
376 orte_process_info.job_session_dir = NULL;
377 orte_process_info.proc_session_dir = NULL;
378
379 }