2004-05-26 01:38:16 +04:00
|
|
|
/*
|
2005-11-05 22:57:48 +03:00
|
|
|
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
|
|
|
|
* University Research and Technology
|
|
|
|
* Corporation. All rights reserved.
|
|
|
|
* Copyright (c) 2004-2005 The University of Tennessee and The University
|
|
|
|
* of Tennessee Research Foundation. All rights
|
|
|
|
* reserved.
|
2004-11-28 23:09:25 +03:00
|
|
|
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
|
|
|
|
* University of Stuttgart. All rights reserved.
|
2005-03-24 15:43:37 +03:00
|
|
|
* Copyright (c) 2004-2005 The Regents of the University of California.
|
|
|
|
* All rights reserved.
|
2004-11-22 04:38:40 +03:00
|
|
|
* $COPYRIGHT$
|
|
|
|
*
|
|
|
|
* Additional copyrights may follow
|
|
|
|
*
|
2004-05-26 01:38:16 +04:00
|
|
|
* $HEADER$
|
|
|
|
*/
|
|
|
|
|
2005-03-29 23:58:32 +04:00
|
|
|
#include "orte_config.h"
|
2004-05-26 01:38:16 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
2004-10-20 05:03:09 +04:00
|
|
|
#ifdef HAVE_SYS_PARAM_H
|
2004-05-26 01:38:16 +04:00
|
|
|
#include <sys/param.h>
|
2004-10-20 05:03:09 +04:00
|
|
|
#endif
|
2004-05-26 01:38:16 +04:00
|
|
|
|
2005-08-25 20:28:41 +04:00
|
|
|
#include "opal/runtime/opal.h"
|
2005-07-04 05:59:52 +04:00
|
|
|
#include "opal/util/os_path.h"
|
2004-08-10 01:39:31 +04:00
|
|
|
#include "support.h"
|
2004-05-26 01:38:16 +04:00
|
|
|
|
2005-12-13 09:05:37 +03:00
|
|
|
#ifdef __WINDOWS__
|
2005-08-29 23:23:25 +04:00
|
|
|
#define PATH_SEP "\\"
|
|
|
|
#else
|
|
|
|
#define PATH_SEP "/"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static const char *path_sep = PATH_SEP;
|
|
|
|
|
2004-05-26 01:38:16 +04:00
|
|
|
static bool test1(void); /* trivial answer test */
|
|
|
|
static bool test2(void); /* relative path test */
|
|
|
|
static bool test3(void); /* absolute path test */
|
|
|
|
static bool test4(void); /* missing path separator test */
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char* argv[])
|
|
|
|
{
|
2010-02-10 21:29:01 +03:00
|
|
|
opal_init(&argc, &argv);
|
2004-05-26 01:38:16 +04:00
|
|
|
|
2005-07-04 05:59:52 +04:00
|
|
|
test_init("opal_os_path_t");
|
2005-03-29 23:58:32 +04:00
|
|
|
|
2004-05-26 01:38:16 +04:00
|
|
|
if (test1()) {
|
2004-08-10 01:39:31 +04:00
|
|
|
test_success();
|
|
|
|
}
|
|
|
|
else {
|
2005-07-04 05:59:52 +04:00
|
|
|
test_failure("opal_os_path_t test1 failed");
|
2004-05-26 01:38:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (test2()) {
|
2004-08-10 01:39:31 +04:00
|
|
|
test_success();
|
|
|
|
}
|
|
|
|
else {
|
2005-07-04 05:59:52 +04:00
|
|
|
test_failure("opal_os_path_t test2 failed");
|
2004-05-26 01:38:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (test3()) {
|
2004-08-10 01:39:31 +04:00
|
|
|
test_success();
|
|
|
|
}
|
|
|
|
else {
|
2005-07-04 05:59:52 +04:00
|
|
|
test_failure("opal_os_path_t test3 failed");
|
2004-05-26 01:38:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (test4()) {
|
2004-08-10 01:39:31 +04:00
|
|
|
test_success();
|
|
|
|
}
|
|
|
|
else {
|
2005-07-04 05:59:52 +04:00
|
|
|
test_failure("opal_os_path_t test4 failed");
|
2004-05-26 01:38:16 +04:00
|
|
|
}
|
|
|
|
|
2005-08-25 20:28:41 +04:00
|
|
|
opal_finalize();
|
|
|
|
|
2004-08-10 01:39:31 +04:00
|
|
|
test_finalize();
|
|
|
|
return 0;
|
2004-05-26 01:38:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool test1(void)
|
|
|
|
{
|
2005-08-25 20:28:41 +04:00
|
|
|
char *out, answer[100];
|
2004-05-26 01:38:16 +04:00
|
|
|
|
2005-03-29 23:58:32 +04:00
|
|
|
/* Test trivial functionality. Program should return ".[separator]" when called in relative
|
2004-05-26 01:38:16 +04:00
|
|
|
* mode, and the separator character when called in absolute mode. */
|
2005-07-04 05:59:52 +04:00
|
|
|
if (NULL != (out = opal_os_path(true,NULL))) {
|
2005-08-25 20:28:41 +04:00
|
|
|
answer[0] = '\0';
|
|
|
|
strcat(answer, ".");
|
2005-08-29 23:23:25 +04:00
|
|
|
strcat(answer, path_sep);
|
2005-03-29 23:58:32 +04:00
|
|
|
if (0 != strcmp(answer, out))
|
2004-05-26 01:38:16 +04:00
|
|
|
return(false);
|
2005-08-25 20:28:41 +04:00
|
|
|
free(out);
|
2004-05-26 01:38:16 +04:00
|
|
|
}
|
2005-07-04 05:59:52 +04:00
|
|
|
if (NULL != (out = opal_os_path(false,NULL))) {
|
2005-08-29 23:23:25 +04:00
|
|
|
if (0 != strcmp(path_sep, out))
|
2004-05-26 01:38:16 +04:00
|
|
|
return(false);
|
2005-08-25 20:28:41 +04:00
|
|
|
free(out);
|
2004-05-26 01:38:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool test2(void)
|
|
|
|
{
|
2005-08-25 20:28:41 +04:00
|
|
|
char out[1024];
|
|
|
|
char *tmp;
|
2004-05-26 01:38:16 +04:00
|
|
|
char *a[] = { "aaa", "bbb", "ccc", NULL };
|
|
|
|
|
2005-08-29 23:23:25 +04:00
|
|
|
if (NULL == path_sep) {
|
2004-05-26 01:38:16 +04:00
|
|
|
printf("test2 cannot be run\n");
|
|
|
|
return(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Construct a relative path name and see if it comes back correctly. Check multiple depths. */
|
2005-08-25 20:28:41 +04:00
|
|
|
out[0] = '\0';
|
|
|
|
strcat(out, ".");
|
2005-08-29 23:23:25 +04:00
|
|
|
strcat(out, path_sep);
|
2005-08-25 20:28:41 +04:00
|
|
|
strcat(out, a[0]);
|
|
|
|
|
|
|
|
tmp = opal_os_path(true, a[0], NULL);
|
|
|
|
if (0 != strcmp(out, tmp))
|
2004-05-26 01:38:16 +04:00
|
|
|
return(false);
|
2005-08-25 20:28:41 +04:00
|
|
|
free(tmp);
|
2004-05-26 01:38:16 +04:00
|
|
|
|
2005-08-29 23:23:25 +04:00
|
|
|
strcat(out, path_sep);
|
2005-08-25 20:28:41 +04:00
|
|
|
strcat(out, a[1]);
|
|
|
|
tmp = opal_os_path(true, a[0], a[1], NULL);
|
|
|
|
if (0 != strcmp(out, tmp))
|
2004-05-26 01:38:16 +04:00
|
|
|
return(false);
|
2005-08-25 20:28:41 +04:00
|
|
|
free(tmp);
|
2004-05-26 01:38:16 +04:00
|
|
|
|
2005-08-29 23:23:25 +04:00
|
|
|
strcat(out, path_sep);
|
2005-08-25 20:28:41 +04:00
|
|
|
strcat(out, a[2]);
|
|
|
|
tmp = opal_os_path(true, a[0], a[1], a[2], NULL);
|
|
|
|
if (0 != strcmp(out, tmp))
|
2004-05-26 01:38:16 +04:00
|
|
|
return(false);
|
2005-08-25 20:28:41 +04:00
|
|
|
free(tmp);
|
2004-05-26 01:38:16 +04:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool test3(void)
|
|
|
|
{
|
2005-08-25 20:28:41 +04:00
|
|
|
char out[1024];
|
|
|
|
char *tmp;
|
2004-05-26 01:38:16 +04:00
|
|
|
char *a[] = { "aaa", "bbb", "ccc", NULL };
|
|
|
|
|
2005-08-29 23:23:25 +04:00
|
|
|
if (NULL == path_sep) {
|
2004-05-26 01:38:16 +04:00
|
|
|
printf("test3 cannot be run\n");
|
|
|
|
return(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Same as prior test, only with absolute path name */
|
2005-08-25 20:28:41 +04:00
|
|
|
out[0] = '\0';
|
2005-08-29 23:23:25 +04:00
|
|
|
strcat(out, path_sep);
|
2005-08-25 20:28:41 +04:00
|
|
|
strcat(out, a[0]);
|
|
|
|
tmp = opal_os_path(false, a[0], NULL);
|
|
|
|
if (0 != strcmp(out, tmp))
|
2004-05-26 01:38:16 +04:00
|
|
|
return(false);
|
2005-08-25 20:28:41 +04:00
|
|
|
free(tmp);
|
2004-05-26 01:38:16 +04:00
|
|
|
|
2005-08-29 23:23:25 +04:00
|
|
|
strcat(out, path_sep);
|
2005-08-25 20:28:41 +04:00
|
|
|
strcat(out, a[1]);
|
|
|
|
tmp = opal_os_path(false, a[0], a[1], NULL);
|
|
|
|
if (0 != strcmp(out, tmp))
|
2004-05-26 01:38:16 +04:00
|
|
|
return(false);
|
2005-08-25 20:28:41 +04:00
|
|
|
free(tmp);
|
2004-05-26 01:38:16 +04:00
|
|
|
|
2005-08-29 23:23:25 +04:00
|
|
|
strcat(out, path_sep);
|
2005-08-25 20:28:41 +04:00
|
|
|
strcat(out, a[2]);
|
|
|
|
tmp = opal_os_path(false, a[0], a[1], a[2], NULL);
|
|
|
|
if (0 != strcmp(out, tmp))
|
2004-05-26 01:38:16 +04:00
|
|
|
return(false);
|
2005-08-25 20:28:41 +04:00
|
|
|
free(tmp);
|
2004-05-26 01:38:16 +04:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool test4(void)
|
|
|
|
{
|
|
|
|
char a[MAXPATHLEN + 10];
|
|
|
|
int i;
|
|
|
|
|
2005-08-29 23:23:25 +04:00
|
|
|
if (NULL == path_sep) {
|
2004-05-26 01:38:16 +04:00
|
|
|
printf("test4 cannot be run\n");
|
|
|
|
return(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i=0; i< MAXPATHLEN+5; i++) {
|
|
|
|
a[i] = 'a';
|
|
|
|
}
|
2005-08-25 20:28:41 +04:00
|
|
|
a[i] = '\0';
|
2005-07-04 05:59:52 +04:00
|
|
|
if (NULL != opal_os_path(false, a, NULL)) {
|
2004-05-26 01:38:16 +04:00
|
|
|
return(false);
|
|
|
|
}
|
|
|
|
return (true);
|
|
|
|
}
|