2004-08-07 01:01:29 +04:00
|
|
|
/*
|
2004-11-22 04:38:40 +03:00
|
|
|
* Copyright (c) 2004-2005 The Trustees of Indiana University.
|
|
|
|
* All rights reserved.
|
|
|
|
* Copyright (c) 2004-2005 The Trustees of the University of Tennessee.
|
|
|
|
* All rights reserved.
|
|
|
|
* $COPYRIGHT$
|
|
|
|
*
|
|
|
|
* Additional copyrights may follow
|
|
|
|
*
|
2004-08-07 01:01:29 +04:00
|
|
|
* $HEADER$
|
|
|
|
*/
|
|
|
|
|
2004-10-20 05:03:09 +04:00
|
|
|
#include "ompi_config.h"
|
2004-08-07 01:01:29 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
2004-10-20 05:03:09 +04:00
|
|
|
#ifdef HAVE_UNISTD_H
|
2004-08-07 01:01:29 +04:00
|
|
|
#include <unistd.h>
|
2004-10-20 05:03:09 +04:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_LIBGEN_H
|
2004-08-07 01:01:29 +04:00
|
|
|
#include <libgen.h>
|
2004-10-20 05:03:09 +04:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SYS_PARAM_H
|
2004-08-07 01:01:29 +04:00
|
|
|
#include <sys/param.h>
|
2004-10-20 05:03:09 +04:00
|
|
|
#endif
|
2004-08-07 01:01:29 +04:00
|
|
|
#include <sys/stat.h>
|
|
|
|
|
|
|
|
#include "include/constants.h"
|
|
|
|
#include "util/sys_info.h"
|
|
|
|
#include "util/os_path.h"
|
2004-08-29 10:50:00 +04:00
|
|
|
#include "util/os_create_dirpath.h"
|
2004-08-07 01:01:29 +04:00
|
|
|
#include "util/session_dir.h"
|
2004-08-29 06:46:31 +04:00
|
|
|
#include "util/proc_info.h"
|
2004-08-10 01:44:07 +04:00
|
|
|
#include "support.h"
|
2004-08-07 01:01:29 +04:00
|
|
|
|
2004-08-08 06:20:33 +04:00
|
|
|
|
2004-08-07 01:01:29 +04:00
|
|
|
static bool test1(void); /* given prefix, both one that works and one that fails */
|
|
|
|
static bool test2(void); /* no prefix given, OMPI_PREFIX_ENV set, one good and one bad */
|
|
|
|
static bool test3(void); /* no prefix given, TMPDIR set, one good and one bad */
|
|
|
|
static bool test4(void); /* no prefix given, TMP set, one good and one bad */
|
|
|
|
static bool test5(void); /* no prefix given, HOME set, one good and one bad */
|
|
|
|
static bool test6(void); /* no prefix given, nothing set, one good and one bad */
|
2004-08-29 06:46:31 +04:00
|
|
|
static bool test7(void); /* remove session directory tree */
|
2004-08-29 20:37:02 +04:00
|
|
|
static bool test8(void); /* attempt to remove tree when subdirs present */
|
|
|
|
|
|
|
|
void clear_proc_info(void);
|
2004-08-07 01:01:29 +04:00
|
|
|
|
2004-08-29 06:46:31 +04:00
|
|
|
static FILE *test_out=NULL;
|
2004-08-07 01:01:29 +04:00
|
|
|
|
|
|
|
int main(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
ompi_sys_info(); /* initialize system */
|
2004-08-10 01:44:07 +04:00
|
|
|
|
|
|
|
test_init("ompi_session_dir_t");
|
2004-08-29 20:37:02 +04:00
|
|
|
test_out = fopen( "test_session_dir_out", "w+" );
|
2004-08-29 06:46:31 +04:00
|
|
|
if( test_out == NULL ) {
|
|
|
|
test_failure("test_session_dir couldn't open test file failed");
|
|
|
|
test_finalize();
|
|
|
|
exit(1);
|
2004-08-29 20:37:02 +04:00
|
|
|
}
|
2004-08-07 01:01:29 +04:00
|
|
|
|
2004-08-29 06:46:31 +04:00
|
|
|
|
|
|
|
fprintf(test_out, "running test1\n");
|
2004-08-07 01:01:29 +04:00
|
|
|
if (test1()) {
|
2004-08-10 01:44:07 +04:00
|
|
|
test_success();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
test_failure("ompi_session_dir_t test1 failed");
|
2004-08-07 01:01:29 +04:00
|
|
|
}
|
|
|
|
|
2004-08-29 06:46:31 +04:00
|
|
|
fprintf(test_out, "running test2\n");
|
2004-08-07 01:01:29 +04:00
|
|
|
if (test2()) {
|
2004-08-10 01:44:07 +04:00
|
|
|
test_success();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
test_failure("ompi_session_dir_t test2 failed");
|
2004-08-07 01:01:29 +04:00
|
|
|
}
|
|
|
|
|
2004-08-29 06:46:31 +04:00
|
|
|
fprintf(test_out, "running test3\n");
|
2004-08-07 01:01:29 +04:00
|
|
|
if (test3()) {
|
2004-08-10 01:44:07 +04:00
|
|
|
test_success();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
test_failure("ompi_session_dir_t test3 failed");
|
2004-08-07 01:01:29 +04:00
|
|
|
}
|
|
|
|
|
2004-08-29 06:46:31 +04:00
|
|
|
fprintf(test_out, "running test4\n");
|
2004-08-07 01:01:29 +04:00
|
|
|
if (test4()) {
|
2004-08-10 01:44:07 +04:00
|
|
|
test_success();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
test_failure("ompi_session_dir_t test4 failed");
|
2004-08-07 01:01:29 +04:00
|
|
|
}
|
|
|
|
|
2004-08-29 06:46:31 +04:00
|
|
|
fprintf(test_out, "running test5\n");
|
2004-08-07 01:01:29 +04:00
|
|
|
if (test5()) {
|
2004-08-10 01:44:07 +04:00
|
|
|
test_success();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
test_failure("ompi_session_dir_t test5 failed");
|
2004-08-07 01:01:29 +04:00
|
|
|
}
|
|
|
|
|
2004-08-29 06:46:31 +04:00
|
|
|
fprintf(test_out, "running test6\n");
|
2004-08-07 01:01:29 +04:00
|
|
|
if (test6()) {
|
2004-08-10 01:44:07 +04:00
|
|
|
test_success();
|
2004-08-07 01:01:29 +04:00
|
|
|
}
|
2004-08-10 01:44:07 +04:00
|
|
|
else {
|
|
|
|
test_failure("ompi_session_dir_t test6 failed");
|
2004-08-07 01:01:29 +04:00
|
|
|
}
|
|
|
|
|
2004-08-29 06:46:31 +04:00
|
|
|
fprintf(test_out, "running test7\n");
|
|
|
|
if (test7()) {
|
|
|
|
test_success();
|
|
|
|
}
|
|
|
|
else {
|
2004-08-29 20:37:02 +04:00
|
|
|
test_failure("ompi_session_dir_t test7 failed");
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(test_out, "running test8\n");
|
|
|
|
if (test8()) {
|
|
|
|
test_success();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
test_failure("ompi_session_dir_t test8 failed");
|
2004-08-29 06:46:31 +04:00
|
|
|
}
|
|
|
|
|
2004-08-29 20:37:02 +04:00
|
|
|
fprintf(test_out, "completed all tests\n");
|
|
|
|
|
2004-08-29 06:46:31 +04:00
|
|
|
fclose(test_out);
|
2004-08-10 01:44:07 +04:00
|
|
|
test_finalize();
|
|
|
|
return 0;
|
2004-08-07 01:01:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool test1(void)
|
|
|
|
{
|
|
|
|
/* Test proper action when given a prefix */
|
|
|
|
|
2004-08-29 20:37:02 +04:00
|
|
|
char *prefix, *tmp;
|
2004-08-07 01:01:29 +04:00
|
|
|
|
|
|
|
/* see if we can create a specified path */
|
|
|
|
|
2004-08-29 20:37:02 +04:00
|
|
|
clear_proc_info();
|
|
|
|
|
2004-08-07 01:01:29 +04:00
|
|
|
prefix = ompi_os_path(false, "tmp", NULL);
|
2004-08-08 06:20:33 +04:00
|
|
|
if (OMPI_ERROR == ompi_session_dir(true, prefix, ompi_system_info.user, NULL, NULL, "test-universe", NULL, NULL)) {
|
2004-08-29 20:37:02 +04:00
|
|
|
fprintf(test_out, "test1 - couldn't create specified path\n");
|
2004-08-07 01:01:29 +04:00
|
|
|
free(prefix);
|
|
|
|
return(false);
|
|
|
|
}
|
|
|
|
/* see if it can access an existing path */
|
|
|
|
|
2004-08-08 06:20:33 +04:00
|
|
|
if (OMPI_ERROR == ompi_session_dir(false, prefix, ompi_system_info.user, NULL, NULL, "test-universe", NULL, NULL)) {
|
2004-08-29 20:37:02 +04:00
|
|
|
fprintf(test_out, "test1 - couldn't access existing path\n");
|
2004-08-07 01:01:29 +04:00
|
|
|
free(prefix);
|
|
|
|
return(false);
|
|
|
|
}
|
|
|
|
|
2004-08-08 06:20:33 +04:00
|
|
|
rmdir(ompi_process_info.universe_session_dir);
|
|
|
|
tmp = strdup(dirname(ompi_process_info.universe_session_dir));
|
2004-08-07 01:01:29 +04:00
|
|
|
rmdir(tmp);
|
2004-08-08 06:20:33 +04:00
|
|
|
free(ompi_process_info.universe_session_dir);
|
2004-08-07 01:01:29 +04:00
|
|
|
free(prefix);
|
|
|
|
free(tmp);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool test2(void)
|
|
|
|
{
|
|
|
|
char *tmp;
|
|
|
|
|
2004-08-29 20:37:02 +04:00
|
|
|
clear_proc_info();
|
|
|
|
|
2004-08-07 01:01:29 +04:00
|
|
|
/* use the OMPI_PREFIX_ENV variable */
|
|
|
|
|
|
|
|
setenv("OMPI_PREFIX_ENV", "/tmp/trythis", 1);
|
|
|
|
|
2004-08-08 06:20:33 +04:00
|
|
|
if (OMPI_ERROR == ompi_session_dir(true, NULL, ompi_system_info.user, NULL, NULL, "test-universe", NULL, NULL)) {
|
2004-08-07 01:01:29 +04:00
|
|
|
unsetenv("OMPI_PREFIX_ENV");
|
|
|
|
return(false);
|
|
|
|
}
|
|
|
|
|
2004-08-08 06:20:33 +04:00
|
|
|
rmdir(ompi_process_info.universe_session_dir);
|
|
|
|
tmp = strdup(dirname(ompi_process_info.universe_session_dir));
|
2004-08-07 01:01:29 +04:00
|
|
|
rmdir(tmp);
|
|
|
|
free(tmp);
|
|
|
|
|
|
|
|
unsetenv("OMPI_PREFIX_ENV");
|
|
|
|
|
|
|
|
return(true);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool test3(void)
|
|
|
|
{
|
|
|
|
/* use the TMPDIR enviro variable */
|
|
|
|
char *tmp;
|
|
|
|
|
2004-08-29 20:37:02 +04:00
|
|
|
clear_proc_info();
|
|
|
|
|
2004-08-07 01:01:29 +04:00
|
|
|
setenv("TMPDIR", "/tmp/trythis", 1);
|
|
|
|
|
2004-08-08 06:20:33 +04:00
|
|
|
if (OMPI_ERROR == ompi_session_dir(true, NULL, ompi_system_info.user, NULL, NULL, "test-universe", NULL, NULL)) {
|
2004-08-07 01:01:29 +04:00
|
|
|
unsetenv("TMPDIR");
|
|
|
|
return(false);
|
|
|
|
}
|
|
|
|
|
2004-08-08 06:20:33 +04:00
|
|
|
rmdir(ompi_process_info.universe_session_dir);
|
|
|
|
tmp = strdup(dirname(ompi_process_info.universe_session_dir));
|
2004-08-07 01:01:29 +04:00
|
|
|
rmdir(tmp);
|
|
|
|
free(tmp);
|
|
|
|
|
|
|
|
unsetenv("TMPDIR");
|
|
|
|
|
|
|
|
return(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool test4(void)
|
|
|
|
{
|
|
|
|
/* use the TMP enviro variable */
|
|
|
|
char *tmp;
|
|
|
|
|
2004-08-29 20:37:02 +04:00
|
|
|
clear_proc_info();
|
|
|
|
|
2004-08-07 01:01:29 +04:00
|
|
|
setenv("TMP", "/tmp/trythis", 1);
|
|
|
|
|
2004-08-08 06:20:33 +04:00
|
|
|
if (OMPI_ERROR == ompi_session_dir(true, NULL, ompi_system_info.user, NULL, NULL, "test-universe", NULL, NULL)) {
|
2004-08-07 01:01:29 +04:00
|
|
|
unsetenv("TMP");
|
|
|
|
return(false);
|
|
|
|
}
|
|
|
|
|
2004-08-08 06:20:33 +04:00
|
|
|
rmdir(ompi_process_info.universe_session_dir);
|
|
|
|
tmp = strdup(dirname(ompi_process_info.universe_session_dir));
|
2004-08-07 01:01:29 +04:00
|
|
|
rmdir(tmp);
|
|
|
|
free(tmp);
|
|
|
|
|
|
|
|
unsetenv("TMP");
|
|
|
|
|
|
|
|
return(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool test5(void)
|
|
|
|
{
|
|
|
|
/* use the HOME enviro variable */
|
|
|
|
char *tmp;
|
|
|
|
|
2004-08-29 20:37:02 +04:00
|
|
|
clear_proc_info();
|
|
|
|
|
2004-08-07 01:01:29 +04:00
|
|
|
setenv("HOME", "/tmp/trythis", 1);
|
|
|
|
|
2004-08-08 06:20:33 +04:00
|
|
|
if (OMPI_ERROR == ompi_session_dir(true, NULL, ompi_system_info.user, NULL, NULL, "test-universe", NULL, NULL)) {
|
2004-08-07 01:01:29 +04:00
|
|
|
unsetenv("HOME");
|
|
|
|
return(false);
|
|
|
|
}
|
|
|
|
|
2004-08-08 06:20:33 +04:00
|
|
|
rmdir(ompi_process_info.universe_session_dir);
|
|
|
|
tmp = strdup(dirname(ompi_process_info.universe_session_dir));
|
2004-08-07 01:01:29 +04:00
|
|
|
rmdir(tmp);
|
|
|
|
free(tmp);
|
|
|
|
|
|
|
|
unsetenv("HOME");
|
|
|
|
|
|
|
|
return(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool test6(void)
|
|
|
|
{
|
|
|
|
char *tmp;
|
|
|
|
|
2004-08-29 20:37:02 +04:00
|
|
|
clear_proc_info();
|
|
|
|
|
2004-08-07 01:01:29 +04:00
|
|
|
/* no enviro variables set, no prefix given
|
|
|
|
* Program should turn to default of /tmp (where "/" is whatever
|
|
|
|
* top-level directory is appropriate for given system)
|
|
|
|
*/
|
2004-08-08 06:20:33 +04:00
|
|
|
if (OMPI_ERROR == ompi_session_dir(true, NULL, ompi_system_info.user, NULL, NULL, "test-universe", NULL, NULL)) {
|
2004-08-07 01:01:29 +04:00
|
|
|
return(false);
|
|
|
|
}
|
|
|
|
|
2004-08-08 06:20:33 +04:00
|
|
|
rmdir(ompi_process_info.universe_session_dir);
|
|
|
|
tmp = strdup(dirname(ompi_process_info.universe_session_dir));
|
2004-08-07 01:01:29 +04:00
|
|
|
rmdir(tmp);
|
|
|
|
|
|
|
|
return(true);
|
|
|
|
}
|
2004-08-29 06:46:31 +04:00
|
|
|
|
|
|
|
static bool test7(void)
|
|
|
|
{
|
2004-08-29 10:50:00 +04:00
|
|
|
char *filenm;
|
|
|
|
FILE *fp;
|
2004-08-29 06:46:31 +04:00
|
|
|
|
2004-08-29 20:37:02 +04:00
|
|
|
clear_proc_info();
|
|
|
|
|
2004-08-29 06:46:31 +04:00
|
|
|
/* create test proc session directory tree */
|
|
|
|
if (OMPI_ERROR == ompi_session_dir(true, NULL, ompi_system_info.user, "localhost", NULL, "test-universe", "test-job", "test-proc")) {
|
|
|
|
return(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(test_out, "removing directories: %s\n\t%s\n\t%s\n",
|
|
|
|
ompi_process_info.proc_session_dir,
|
|
|
|
ompi_process_info.job_session_dir,
|
|
|
|
ompi_process_info.universe_session_dir);
|
|
|
|
|
2004-08-29 10:50:00 +04:00
|
|
|
/* create some files */
|
|
|
|
|
|
|
|
filenm = ompi_os_path(false, ompi_process_info.proc_session_dir, "dum1", NULL);
|
|
|
|
fp = fopen(filenm, "w");
|
|
|
|
fprintf(fp, "ss");
|
|
|
|
fclose(fp);
|
|
|
|
|
|
|
|
filenm = ompi_os_path(false, ompi_process_info.job_session_dir, "dum2", NULL);
|
|
|
|
fp = fopen(filenm, "w");
|
|
|
|
fprintf(fp, "ss");
|
|
|
|
fclose(fp);
|
|
|
|
|
|
|
|
filenm = ompi_os_path(false, ompi_process_info.universe_session_dir, "dum3", NULL);
|
|
|
|
fp = fopen(filenm, "w");
|
|
|
|
fprintf(fp, "ss");
|
|
|
|
fclose(fp);
|
|
|
|
|
2004-08-29 06:46:31 +04:00
|
|
|
if (OMPI_ERROR == ompi_session_dir_finalize()) {
|
|
|
|
return(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2004-08-29 20:37:02 +04:00
|
|
|
|
|
|
|
static bool test8(void)
|
|
|
|
{
|
|
|
|
char *filenm;
|
|
|
|
FILE *fp;
|
|
|
|
|
|
|
|
clear_proc_info();
|
|
|
|
|
|
|
|
/* create test proc session directory tree */
|
|
|
|
if (OMPI_ERROR == ompi_session_dir(true, NULL, ompi_system_info.user, "localhost", NULL, "test-universe2", "test-job", "test-proc")) {
|
|
|
|
return(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(test_out, "removing directories: %s\n\t%s\n\t%s\n",
|
|
|
|
ompi_process_info.proc_session_dir,
|
|
|
|
ompi_process_info.job_session_dir,
|
|
|
|
ompi_process_info.universe_session_dir);
|
|
|
|
|
|
|
|
/* create some files */
|
|
|
|
|
|
|
|
filenm = ompi_os_path(false, ompi_process_info.proc_session_dir, "dum1", NULL);
|
|
|
|
fp = fopen(filenm, "w");
|
|
|
|
fprintf(fp, "ss");
|
|
|
|
fclose(fp);
|
|
|
|
|
|
|
|
filenm = ompi_os_path(false, ompi_process_info.job_session_dir, "dum2", NULL);
|
|
|
|
fp = fopen(filenm, "w");
|
|
|
|
fprintf(fp, "ss");
|
|
|
|
fclose(fp);
|
|
|
|
|
|
|
|
filenm = ompi_os_path(false, ompi_process_info.universe_session_dir, "dum3", NULL);
|
|
|
|
fp = fopen(filenm, "w");
|
|
|
|
fprintf(fp, "ss");
|
|
|
|
fclose(fp);
|
|
|
|
|
|
|
|
|
|
|
|
filenm = ompi_os_path( false, ompi_process_info.job_session_dir, "dir1", NULL);
|
|
|
|
ompi_os_create_dirpath(filenm, 0777);
|
|
|
|
|
|
|
|
if (OMPI_ERROR == ompi_session_dir_finalize()) {
|
|
|
|
return(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void clear_proc_info(void)
|
|
|
|
{
|
|
|
|
ompi_process_info.tmpdir_base = NULL;
|
|
|
|
ompi_process_info.top_session_dir = NULL;
|
|
|
|
ompi_process_info.universe_session_dir = NULL;
|
|
|
|
ompi_process_info.job_session_dir = NULL;
|
|
|
|
ompi_process_info.proc_session_dir = NULL;
|
|
|
|
|
|
|
|
}
|