2004-08-07 01:01:29 +04:00
|
|
|
/*
|
|
|
|
* $HEADER$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <libgen.h>
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
|
|
|
#include "ompi_config.h"
|
|
|
|
#include "include/constants.h"
|
|
|
|
#include "util/sys_info.h"
|
|
|
|
#include "util/os_path.h"
|
|
|
|
#include "util/session_dir.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
|
|
|
struct ompi_proc_info_t {
|
|
|
|
bool init; /**< Certifies that values have been filled.
|
|
|
|
* Certifies that the ompi_sys_info() function has been
|
|
|
|
* called at least once so fields have valid values
|
|
|
|
*/
|
|
|
|
char *universe_session_dir; /**< Location of universe temp dir.
|
|
|
|
* The session directory has the form
|
|
|
|
* <prefix><openmpi-sessions-user><universe>, where the prefix
|
|
|
|
* can either be provided by the user via the
|
|
|
|
* --tmpdir command-line flag, the use of one of several
|
|
|
|
* environmental variables, or else a default location.
|
|
|
|
*/
|
|
|
|
|
|
|
|
char *job_session_dir; /**< Session directory for job */
|
|
|
|
|
|
|
|
char *proc_session_dir; /**< Session directory for the process */
|
|
|
|
};
|
|
|
|
typedef struct ompi_proc_info_t ompi_proc_info_t;
|
|
|
|
|
|
|
|
ompi_proc_info_t ompi_process_info;
|
|
|
|
|
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 */
|
|
|
|
|
|
|
|
|
|
|
|
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-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
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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-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 */
|
|
|
|
|
|
|
|
char *prefix, *tmp, *tmp2;
|
|
|
|
|
|
|
|
/* see if we can create a specified path */
|
|
|
|
|
|
|
|
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)) {
|
|
|
|
printf("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)) {
|
|
|
|
printf("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);
|
|
|
|
|
|
|
|
/* check what happens when given prefix that won't allow access */
|
|
|
|
tmp2 = ompi_os_path(false, "test", NULL); /* assume we don't have root privileges */
|
2004-08-08 06:20:33 +04:00
|
|
|
if (OMPI_SUCCESS == ompi_session_dir(true, tmp2, ompi_system_info.user, NULL, NULL, "test-universe", NULL, NULL)) {
|
2004-08-07 01:01:29 +04:00
|
|
|
printf("created temp directory in %s - shouldn't have been able to do so\n", tmp2);
|
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);
|
|
|
|
free(tmp2);
|
|
|
|
return(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool test2(void)
|
|
|
|
{
|
|
|
|
char *tmp;
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
/* 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);
|
|
|
|
}
|