2 * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
3 * University Research and Technology
4 * Corporation. All rights reserved.
5 * Copyright (c) 2004-2005 The University of Tennessee and The University
6 * of Tennessee Research Foundation. All rights
8 * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
9 * University of Stuttgart. All rights reserved.
10 * Copyright (c) 2004-2005 The Regents of the University of California.
11 * All rights reserved.
14 * Additional copyrights may follow
19 #include "orte_config.h"
30 #ifdef HAVE_SYS_PARAM_H
31 #include <sys/param.h>
36 #include "orte/orte_constants.h"
37 #include "orte/mca/ns/ns_types.h"
38 #include "orte/util/proc_info.h"
39 #include "orte/util/sys_info.h"
40 #include "opal/util/os_path.h"
41 #include "opal/util/os_create_dirpath.h"
42 #include "orte/util/session_dir.h"
43 #include "orte/util/proc_info.h"
44 #include "orte/runtime/runtime.h"
47 static bool test1(void); /* given prefix, both one that works and one that fails */
48 static bool test2(void); /* no prefix given, ORTE_PREFIX_ENV set, one good and one bad */
49 static bool test3(void); /* no prefix given, TMPDIR set, one good and one bad */
50 static bool test4(void); /* no prefix given, TMP set, one good and one bad */
51 static bool test5(void); /* no prefix given, HOME set, one good and one bad */
52 static bool test6(void); /* no prefix given, nothing set, one good and one bad */
53 static bool test7(void); /* remove session directory tree */
54 static bool test8(void); /* attempt to remove tree when subdirs present */
56 void clear_proc_info(void);
58 static FILE *test_out
=NULL
;
60 int main(int argc
, char* argv
[])
62 orte_sys_info(); /* initialize system */
63 orte_proc_info(); /* initialize proc info structure */
64 orte_process_info
.my_name
= (orte_process_name_t
*)malloc(sizeof(orte_process_name_t
));
65 orte_process_info
.my_name
->cellid
= 0;
66 orte_process_info
.my_name
->jobid
= 0;
67 orte_process_info
.my_name
->vpid
= 0;
69 test_init("orte_session_dir_t");
70 test_out
= fopen( "test_session_dir_out", "w+" );
71 if( test_out
== NULL
) {
72 test_failure("test_session_dir couldn't open test file failed");
78 fprintf(test_out
, "running test1\n");
83 test_failure("orte_session_dir_t test1 failed");
86 fprintf(test_out
, "running test2\n");
91 test_failure("orte_session_dir_t test2 failed");
94 fprintf(test_out
, "running test3\n");
99 test_failure("orte_session_dir_t test3 failed");
102 fprintf(test_out
, "running test4\n");
107 test_failure("orte_session_dir_t test4 failed");
110 fprintf(test_out
, "running test5\n");
115 test_failure("orte_session_dir_t test5 failed");
118 fprintf(test_out
, "running test6\n");
123 test_failure("orte_session_dir_t test6 failed");
126 fprintf(test_out
, "running test7\n");
131 test_failure("orte_session_dir_t test7 failed");
134 fprintf(test_out
, "running test8\n");
139 test_failure("orte_session_dir_t test8 failed");
142 fprintf(test_out
, "completed all tests\n");
147 orte_sys_info_finalize();
148 orte_proc_info_finalize();
155 static bool test1(void)
157 /* Test proper action when given a prefix */
161 /* see if we can create a specified path */
165 prefix
= opal_os_path(false, "tmp", NULL
);
166 if (ORTE_ERROR
== orte_session_dir(true, prefix
, orte_system_info
.user
, NULL
, NULL
, "test-universe", NULL
, NULL
)) {
167 fprintf(test_out
, "test1 - couldn't create specified path\n");
171 /* see if it can access an existing path */
173 if (ORTE_ERROR
== orte_session_dir(false, prefix
, orte_system_info
.user
, NULL
, NULL
, "test-universe", NULL
, NULL
)) {
174 fprintf(test_out
, "test1 - couldn't access existing path\n");
179 orte_session_dir_finalize(orte_process_info
.my_name
);
180 free(orte_process_info
.universe_session_dir
);
187 static bool test2(void)
191 /* use the ORTE_PREFIX_ENV variable */
193 setenv("OMPI_PREFIX_ENV", "/tmp/trythis", 1);
195 if (ORTE_ERROR
== orte_session_dir(true, NULL
, orte_system_info
.user
, NULL
, NULL
, "test-universe", NULL
, NULL
)) {
196 unsetenv("OMPI_PREFIX_ENV");
200 orte_session_dir_finalize(orte_process_info
.my_name
);
202 unsetenv("OMPI_PREFIX_ENV");
209 static bool test3(void)
211 /* use the TMPDIR enviro variable */
214 setenv("TMPDIR", "/tmp/trythis", 1);
216 if (ORTE_ERROR
== orte_session_dir(true, NULL
, orte_system_info
.user
, NULL
, NULL
, "test-universe", NULL
, NULL
)) {
221 orte_session_dir_finalize(orte_process_info
.my_name
);
229 static bool test4(void)
231 /* use the TMP enviro variable */
235 setenv("TMP", "/tmp/trythis", 1);
237 if (ORTE_ERROR
== orte_session_dir(true, NULL
, orte_system_info
.user
, NULL
, NULL
, "test-universe", NULL
, NULL
)) {
242 orte_session_dir_finalize(orte_process_info
.my_name
);
250 static bool test5(void)
252 /* use the HOME enviro variable */
256 setenv("HOME", "/tmp/trythis", 1);
258 if (ORTE_ERROR
== orte_session_dir(true, NULL
, orte_system_info
.user
, NULL
, NULL
, "test-universe", NULL
, NULL
)) {
263 orte_session_dir_finalize(orte_process_info
.my_name
);
271 static bool test6(void)
276 /* no enviro variables set, no prefix given
277 * Program should turn to default of /tmp (where "/" is whatever
278 * top-level directory is appropriate for given system)
280 if (ORTE_ERROR
== orte_session_dir(true, NULL
, orte_system_info
.user
, NULL
, NULL
, "test-universe", NULL
, NULL
)) {
284 orte_session_dir_finalize(orte_process_info
.my_name
);
289 static bool test7(void)
297 /* create test proc session directory tree */
298 if (ORTE_ERROR
== orte_session_dir(true, NULL
, orte_system_info
.user
, "localhost", NULL
, "test-universe", "test-job", "test-proc")) {
302 fprintf(test_out
, "removing directories: %s\n\t%s\n\t%s\n",
303 orte_process_info
.proc_session_dir
,
304 orte_process_info
.job_session_dir
,
305 orte_process_info
.universe_session_dir
);
307 /* create some files */
309 filenm
[0] = opal_os_path(false, orte_process_info
.proc_session_dir
, "dum1", NULL
);
310 fp
= fopen(filenm
[0], "w");
314 filenm
[1] = opal_os_path(false, orte_process_info
.job_session_dir
, "dum2", NULL
);
315 fp
= fopen(filenm
[1], "w");
319 filenm
[2] = opal_os_path(false, orte_process_info
.universe_session_dir
, "dum3", NULL
);
320 fp
= fopen(filenm
[2], "w");
324 if (ORTE_ERROR
== orte_session_dir_finalize(orte_process_info
.my_name
)) {
328 for (i
=0; i
< 3; i
++) unlink(filenm
[i
]);
329 orte_session_dir_finalize(orte_process_info
.my_name
);
334 static bool test8(void)
342 /* create test proc session directory tree */
343 if (ORTE_ERROR
== orte_session_dir(true, NULL
, orte_system_info
.user
, "localhost", NULL
, "test-universe2", "test-job2", "test-proc2")) {
347 fprintf(test_out
, "removing directories: %s\n\t%s\n\t%s\n",
348 orte_process_info
.proc_session_dir
,
349 orte_process_info
.job_session_dir
,
350 orte_process_info
.universe_session_dir
);
352 /* create some files */
354 filenm
[0] = opal_os_path(false, orte_process_info
.proc_session_dir
, "dum1", NULL
);
355 fp
= fopen(filenm
[0], "w");
359 filenm
[1] = opal_os_path(false, orte_process_info
.job_session_dir
, "dum2", NULL
);
360 fp
= fopen(filenm
[1], "w");
364 filenm
[2] = opal_os_path(false, orte_process_info
.universe_session_dir
, "dum3", NULL
);
365 fp
= fopen(filenm
[2], "w");
370 if (ORTE_ERROR
== orte_session_dir_finalize(orte_process_info
.my_name
)) {
374 for (i
=0; i
< 3; i
++) unlink(filenm
[i
]);
375 orte_session_dir_finalize(orte_process_info
.my_name
);
380 void clear_proc_info(void)
382 orte_process_info
.tmpdir_base
= NULL
;
383 orte_process_info
.top_session_dir
= NULL
;
384 orte_process_info
.universe_session_dir
= NULL
;
385 orte_process_info
.job_session_dir
= NULL
;
386 orte_process_info
.proc_session_dir
= NULL
;