diff options
author | Albert Cheng <acheng@hdfgroup.org> | 2005-12-11 04:28:31 (GMT) |
---|---|---|
committer | Albert Cheng <acheng@hdfgroup.org> | 2005-12-11 04:28:31 (GMT) |
commit | 8ec440e959d5ad75eb655c55129228c000dffe6b (patch) | |
tree | 2068cd01589c122ca6d7016fe3ac9f989767bce2 /testpar | |
parent | 67f39db8a0b332b10a66128da900bb48faca9b40 (diff) | |
download | hdf5-8ec440e959d5ad75eb655c55129228c000dffe6b.zip hdf5-8ec440e959d5ad75eb655c55129228c000dffe6b.tar.gz hdf5-8ec440e959d5ad75eb655c55129228c000dffe6b.tar.bz2 |
[svn-r11783] Purpose:
bug fix.
Description:
Fixed the segmentation fault errors in modi4, copper and tg-login.
It was due to the misuse of trying to realloc a pointer returned by
getenv_all. (not supposed to.)
Also rearranged the code so that option is checked first, then check
with environment variable, then use default setup. This saves the
need to do realloc at all.
Platforms tested:
Heping, modi4, shanti, copper (copper showed a different error now.)
Diffstat (limited to 'testpar')
-rw-r--r-- | testpar/t_posix_compliant.c | 48 |
1 files changed, 32 insertions, 16 deletions
diff --git a/testpar/t_posix_compliant.c b/testpar/t_posix_compliant.c index b863788..cf82388 100644 --- a/testpar/t_posix_compliant.c +++ b/testpar/t_posix_compliant.c @@ -38,6 +38,7 @@ #include <stdlib.h> #include <mpi.h> #include "h5test.h" +#define TESTFNAME "posix_test" /* test file name */ static char* testfile = NULL; static int err_flag = 0; @@ -669,6 +670,7 @@ int main(int argc, char* argv[]) int lb, ub, inc; int write_size = 0; char optstring[] = "h x m p: s: v:"; + char *prefix; err_flag = 0; @@ -676,18 +678,6 @@ int main(int argc, char* argv[]) MPI_Comm_size(MPI_COMM_WORLD, &numprocs); MPI_Comm_rank(MPI_COMM_WORLD, &rank); - testfile = getenv_all(MPI_COMM_WORLD, 0, "HDF5_PARAPREFIX"); - if(!testfile) - { - testfile = strdup("posix_test"); - } - else - { - testfile = (char*) realloc(testfile, strlen(testfile) + 1 + strlen("posix_test")); - strcat(testfile, "/posix_test"); - } - - while((opt = getopt(argc, argv, optstring)) != -1) { switch(opt) @@ -711,12 +701,11 @@ int main(int argc, char* argv[]) posix_tests = 1; break; case 'p': - testfile = (char*) realloc(testfile, strlen(optarg) + 1 + strlen("posix_test")); - memset(testfile, 0, strlen(optarg)+1+strlen("posix_test")); + /* need 2 extra--1 for the / and 1 for the terminating NULL. */ + testfile = (char*) HDmalloc(strlen(optarg) + 2 + strlen(TESTFNAME)); strcpy(testfile, optarg); /* Append a / just in case they didn't end their path with one */ - strcat(testfile, "/posix_test"); - fprintf(stderr, "Task %d setting testfile to: %s\n", rank, testfile); + strcat(testfile, "/" TESTFNAME); break; case 's': write_size = atoi(optarg); @@ -730,6 +719,24 @@ int main(int argc, char* argv[]) if( (optind < argc) && (rank == 0)) fprintf(stderr, "Unkown command-line argument passed. Continuing anyway...\n"); + if (!testfile){ + /* Try environment variable if not given as option. */ + prefix = getenv_all(MPI_COMM_WORLD, 0, "HDF5_PARAPREFIX"); + if (prefix) + { + /* need 2 extra--1 for the / and 1 for the terminating NULL. */ + testfile = (char*) HDmalloc(strlen(prefix) + 2 + strlen(TESTFNAME)); + strcpy(testfile, prefix); + /* Append a / just in case they didn't end their path with one */ + strcat(testfile, "/" TESTFNAME); + } + else + { + testfile = strdup(TESTFNAME); + } + } + printf("Proc %d: testfile=%s\n", rank, testfile); + if(write_size == 0) { lb = 1024; @@ -743,6 +750,9 @@ int main(int argc, char* argv[]) inc = 2; } + /* set alarm. */ + ALARM_ON; + for(write_size = lb; write_size <= ub; write_size*=inc) { if(rank == 0) @@ -809,7 +819,13 @@ int main(int argc, char* argv[]) */ } } + + /* turn off alarm */ + ALARM_OFF; + done: + if (testfile) + HDfree(testfile); MPI_Barrier(MPI_COMM_WORLD); MPI_Finalize(); |