root/test/util/orte_session_dir.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. main
  2. test1
  3. test2
  4. test3
  5. test4
  6. test5
  7. test6
  8. test7
  9. test8
  10. clear_proc_info

   1 /*
   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-2011 The University of Tennessee and The University
   6  *                         of Tennessee Research Foundation.  All rights
   7  *                         reserved.
   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.
  12  * $COPYRIGHT$
  13  *
  14  * Additional copyrights may follow
  15  *
  16  * $HEADER$
  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  /* HAVE_UNISTD_H */
  27 #ifdef HAVE_SYS_PARAM_H
  28 #include <sys/param.h>
  29 #endif  /* HAVE_SYS_PARAM_H */
  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);   /* given prefix, both one that works and one that fails */
  41 static bool test2(void);   /* no prefix given, ORTE_PREFIX_ENV set, one good and one bad */
  42 static bool test3(void);   /* no prefix given, TMPDIR set, one good and one bad */
  43 static bool test4(void);   /* no prefix given, TMP set, one good and one bad */
  44 static bool test5(void);   /* no prefix given, HOME set, one good and one bad */
  45 static bool test6(void);   /* no prefix given, nothing set, one good and one bad */
  46 static bool test7(void);   /* remove session directory tree */
  47 static bool test8(void);   /* attempt to remove tree when subdirs present */
  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(); /* initialize proc info structure */
  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     /* clean up */
 139     orte_proc_info_finalize();
 140 
 141     test_finalize();
 142     return 0;
 143 }
 144 
 145 
 146 static bool test1(void)
 147 {
 148     /* Test proper action when given a prefix */
 149 
 150     char *prefix;
 151 
 152     /* see if we can create a specified path */
 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     /* see if it can access an existing path */
 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     /* use the ORTE_PREFIX_ENV variable */
 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     /* use the TMPDIR enviro variable */
 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     /* use the TMP enviro variable */
 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     /* use the HOME enviro variable */
 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     /* no enviro variables set, no prefix given
 268     * Program should turn to default of /tmp (where "/" is whatever
 269     * top-level directory is appropriate for given system)
 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     /* create test proc session directory tree */
 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     /* create some files */
 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     /* create test proc session directory tree */
 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     /* create some files */
 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 }

/* [<][>][^][v][top][bottom][index][help] */