diff options
author | Albert Cheng <acheng@hdfgroup.org> | 2013-05-31 23:20:21 (GMT) |
---|---|---|
committer | Albert Cheng <acheng@hdfgroup.org> | 2013-05-31 23:20:21 (GMT) |
commit | 39a3d4aa3e8441e886a3eb44c1040aad47886537 (patch) | |
tree | e8fb669449be5b6ab7f6439707938f52d43ff121 /test | |
parent | d8b37d28a3cdfbf52fa904e9c25d9d18d5e6dbca (diff) | |
download | hdf5-39a3d4aa3e8441e886a3eb44c1040aad47886537.zip hdf5-39a3d4aa3e8441e886a3eb44c1040aad47886537.tar.gz hdf5-39a3d4aa3e8441e886a3eb44c1040aad47886537.tar.bz2 |
[svn-r23725] Added two new features:
1. "-f filename" can create the test file somewhere other than
the current directory or <progname>.h5. This allows running tests in different
filesystems, for example.
2. "-l w|r" can launch only the writer or the reader (default does both).
This allows launching writer (includes the "create file") in one process and
launching the reader somewhere else. (The "-f" helps too.)
Tested: h5committested.
Diffstat (limited to 'test')
-rw-r--r-- | test/usecase.h | 9 | ||||
-rw-r--r-- | test/usecase1_7.c | 141 | ||||
-rw-r--r-- | test/usecase_common.c | 50 |
3 files changed, 136 insertions, 64 deletions
diff --git a/test/usecase.h b/test/usecase.h index 858359b..8957ac1 100644 --- a/test/usecase.h +++ b/test/usecase.h @@ -34,14 +34,19 @@ #define UC_CTYPE short /* use case C data type */ /* type declarations */ +typedef enum part_t { + UC_READWRITE =0, /* both writer and reader */ + UC_WRITER, /* writer only */ + UC_READER /* reader only */ +} part_t; typedef struct options_t { - int num_dsets; /* number of datasets */ - int use_swmr; /* use swmr open or not */ + int use_swmr; /* use swmr open (1) or not */ int compress; /* 0: no compress */ int h5_use_chunks; /* 0/1: Not use/use chunked dataset */ int chunksize; /* chunks are chunksize^2 planes */ int nplanes; /* number of planes, default chunksize */ char *filename; /* use case data filename */ + part_t launch; /* launch writer, reader or both */ } options_t; /* global variables declarations */ diff --git a/test/usecase1_7.c b/test/usecase1_7.c index 0a4bb9d..604bfbc 100644 --- a/test/usecase1_7.c +++ b/test/usecase1_7.c @@ -67,7 +67,7 @@ options_t UC_opts; /* Use Case Options */ const char *progname_g="usecase1_7"; /* program name */ -/* create the use case file for testing. +/* Create the skeleton use case file for testing. * It has one 3d dataset using chunked storage. * The dataset is (unlimited, chunksize, chunksize). * Dataset type is 2 bytes integer. @@ -105,8 +105,8 @@ int create_uc_file(void) if(H5Pset_chunk(dcpl, 3, chunk_dims) < 0) return -1; - /* create dataset of use case name */ - if((dsid = H5Dcreate2(fid, UC_opts.filename, UC_DATATYPE, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0) + /* create dataset of progname */ + if((dsid = H5Dcreate2(fid, progname_g, UC_DATATYPE, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0) return -1; /* Close everythign */ @@ -151,8 +151,8 @@ int write_uc_file(void) return -1; } - /* Open the dataset of the same name */ - if((dsid = H5Dopen2(fid, name, H5P_DEFAULT)) < 0){ + /* Open the dataset of the program name */ + if((dsid = H5Dopen2(fid, progname_g, H5P_DEFAULT)) < 0){ fprintf(stderr, "H5Dopen2 failed\n"); return -1; } @@ -287,6 +287,7 @@ int read_uc_file(void) int j, k; int nreadererr=0; int nerrs; + int nonewplane; name = UC_opts.filename; @@ -296,8 +297,8 @@ int read_uc_file(void) return -1; } - /* Open the dataset of the same name */ - if((dsid = H5Dopen2(fid, name, H5P_DEFAULT)) < 0){ + /* Open the dataset of the program name */ + if((dsid = H5Dopen2(fid, progname_g, H5P_DEFAULT)) < 0){ fprintf(stderr, "H5Dopen2 failed\n"); return -1; } @@ -345,8 +346,31 @@ int read_uc_file(void) count[0]=1; count[1]=count[2]=cz; /* quit when all nplanes, default cz, have been read */ + nonewplane=0; while (nplane_old < UC_opts.nplanes ){ - printf("enter while with nplane_old=%d, dims[0]=%d\n", nplane_old, (int)dims[0]); + /* print progress message according to if new planes are availalbe */ + if (nplane_old < dims[0]) { + if (nonewplane){ + /* end the previous message */ + printf("\n"); + nonewplane=0; + } + printf("reading planes %d to %d\n", nplane_old, (int)dims[0]); + }else{ + if (nonewplane){ + printf("."); + if (nonewplane>=30){ + fprintf(stderr, "waited too long for new plane, quit.\n"); + return -1; + } + }else{ + /* print mesg only the first time; dots still no new plane */ + printf("no new planes to read "); + } + nonewplane++; + /* pause for a second */ + sleep(1); + } for (nplane=nplane_old; nplane < dims[0]; nplane++){ /* read planes between last old nplanes and current extent */ /* Get the dataset's dataspace */ @@ -404,7 +428,7 @@ int read_uc_file(void) fprintf(stderr, "H5Fopen failed\n"); return -1; } - if((dsid = H5Dopen2(fid, name, H5P_DEFAULT)) < 0){ + if((dsid = H5Dopen2(fid, progname_g, H5P_DEFAULT)) < 0){ fprintf(stderr, "H5Dopen2 failed\n"); return -1; } @@ -432,7 +456,8 @@ int read_uc_file(void) int main(int argc, char *argv[]) { - pid_t childpid, mypid, tmppid; + pid_t childpid=0; + pid_t mypid, tmppid; int child_status; int child_wait_option=0; int ret_value = 0; @@ -443,8 +468,6 @@ main(int argc, char *argv[]) HDmemset(&UC_opts, 0, sizeof(options_t)); UC_opts.h5_use_chunks = 1; /* use chunked datasets */ UC_opts.chunksize = Chunksize_DFT; - UC_opts.num_dsets = 1; - UC_opts.compress = 0; /* no compression */ UC_opts.use_swmr = 1; /* use swmr open */ /* parse options */ @@ -452,61 +475,75 @@ main(int argc, char *argv[]) Hgoto_error(1); } - /* data file name is <progname>.h5 */ - if ((UC_opts.filename=(char*)HDmalloc(HDstrlen(progname_g)+4))==NULL) { - fprintf(stderr, "malloc: failed\n"); - Hgoto_error(1); - }; - HDstrcpy(UC_opts.filename, progname_g); - HDstrcat(UC_opts.filename, ".h5"); - - /* generate files */ - printf("Creating data file for test...\n"); - if (create_uc_file() < 0){ - fprintf(stderr, "***encounter error\n"); - Hgoto_error(1); - }else - printf("File created.\n"); + /* ==============================================================*/ + /* UC_READWRITE: create datafile, launch both reader and writer. */ + /* UC_WRITER: create datafile, skip reader, launch writer. */ + /* UC_READER: skip create, launch reader, exit. */ + /* ==============================================================*/ + /* ============*/ + /* Create file */ + /* ============*/ + if (UC_opts.launch != UC_READER){ + printf("Creating skeleton data file for test...\n"); + if (create_uc_file() < 0){ + fprintf(stderr, "***encounter error\n"); + Hgoto_error(1); + }else + printf("File created.\n"); + } - /* fork process */ - if((childpid = fork()) < 0) { - perror("fork"); - Hgoto_error(1); + if (UC_opts.launch==UC_READWRITE){ + /* fork process */ + if((childpid = fork()) < 0) { + perror("fork"); + Hgoto_error(1); + }; }; mypid = getpid(); - /* child process becomes the reader */ - if(0 == childpid) { - printf("%d: become reader process\n", mypid); - if (read_uc_file() < 0){ - fprintf(stderr, "read_uc_file encountered error\n"); - Hgoto_error(1); + /* ============= */ + /* launch reader */ + /* ============= */ + if (UC_opts.launch != UC_WRITER){ + /* child process launch the reader */ + if(0 == childpid) { + printf("%d: launch reader process\n", mypid); + if (read_uc_file() < 0){ + fprintf(stderr, "read_uc_file encountered error\n"); + exit(1); + } + exit(0); } - exit(0); } - /* this process continues as the writer */ - printf("%d: child pid is %d\n", mypid, childpid); + /* ============= */ + /* launch writer */ + /* ============= */ + /* this process continues to launch the writer */ printf("%d: continue as the writer process\n", mypid); if (write_uc_file() < 0){ fprintf(stderr, "write_uc_file encountered error\n"); Hgoto_error(1); } - /* Collect exit code of child process */ - if ((tmppid = waitpid(childpid, &child_status, child_wait_option)) < 0){ - perror("waitpid"); - Hgoto_error(1); - } - if (WIFEXITED(child_status)){ - if ((child_ret_value=WEXITSTATUS(child_status)) != 0){ - printf("%d: child process exited with non-zero code (%d)\n", - mypid, child_ret_value); + /* ================================================ */ + /* If readwrite, collect exit code of child process */ + /* ================================================ */ + if (UC_opts.launch == UC_READWRITE){ + if ((tmppid = waitpid(childpid, &child_status, child_wait_option)) < 0){ + perror("waitpid"); + Hgoto_error(1); + } + if (WIFEXITED(child_status)){ + if ((child_ret_value=WEXITSTATUS(child_status)) != 0){ + printf("%d: child process exited with non-zero code (%d)\n", + mypid, child_ret_value); + Hgoto_error(2); + } + } else { + printf("%d: child process terminated abnormally\n", mypid); Hgoto_error(2); } - } else { - printf("%d: child process terminated abnormally\n", mypid); - Hgoto_error(2); } done: diff --git a/test/usecase_common.c b/test/usecase_common.c index 0230644..d2d2aa5 100644 --- a/test/usecase_common.c +++ b/test/usecase_common.c @@ -19,9 +19,11 @@ usage(const char *prog) { fprintf(stderr, "usage: %s [OPTIONS]\n", prog); fprintf(stderr, " OPTIONS\n"); - fprintf(stderr, " -h, --help Print a usage message and exit\n"); - fprintf(stderr, " -z N, --chunksize=N Chunk size [default: %d]\n", Chunksize_DFT); - fprintf(stderr, " -s N, --swmr=N Use SWMR mode (0: no, non-0: yes) default is yes\n"); + fprintf(stderr, " -h, --help Print a usage message and exit\n"); + fprintf(stderr, " -f FN Test file name [default: %s.h5]\n", prog); + fprintf(stderr, " -l w|r launch writer or reader only. [default: launch both]\n"); + fprintf(stderr, " -s N, --swmr=N Use SWMR mode (0: no, non-0: yes) default is yes\n"); + fprintf(stderr, " -z N, --chunksize=N Chunk size [default: %d]\n", Chunksize_DFT); fprintf(stderr, "\n"); } @@ -33,7 +35,7 @@ parse_option(int argc, char * const argv[]) int ret_value=0; int c; /* command line options: See function usage for a description */ - const char *nagg_options = "hs:z:"; + const char *nagg_options = "f:hl:s:z:"; /* suppress getopt from printing error */ opterr = 0; @@ -46,17 +48,34 @@ parse_option(int argc, char * const argv[]) case 'h': usage(progname_g); break; - case 'z': /* size of chunk=(z,z) */ - if ((UC_opts.chunksize = atoi(optarg)) <= 0){ - fprintf(stderr, "bad chunksize %s, must be a positive integer\n", optarg); + case 'f': /* usecase data file name */ + UC_opts.filename = optarg; + break; + case 'l': /* launch reader or writer only */ + switch (*optarg) { + case 'r': /* reader only */ + UC_opts.launch = UC_READER; + break; + case 'w': /* writer only */ + UC_opts.launch = UC_WRITER; + break; + default: + fprintf(stderr, "launch value(%c) should be w or r only.\n", *optarg); usage(progname_g); Hgoto_error(-1); - }; + break; + } break; case 's': /* use swmr file open mode */ - UC_opts.use_swmr=0; if ((UC_opts.use_swmr = atoi(optarg)) < 0){ - fprintf(stderr, "use swmr value should be 0(no) or 1(yes)\n"); + fprintf(stderr, "swmr value should be 0(no) or 1(yes)\n"); + usage(progname_g); + Hgoto_error(-1); + }; + break; + case 'z': /* size of chunk=(z,z) */ + if ((UC_opts.chunksize = atoi(optarg)) <= 0){ + fprintf(stderr, "bad chunksize %s, must be a positive integer\n", optarg); usage(progname_g); Hgoto_error(-1); }; @@ -75,6 +94,17 @@ parse_option(int argc, char * const argv[]) if (UC_opts.nplanes == 0) UC_opts.nplanes = UC_opts.chunksize; + /* set test file name if not given */ + if (!UC_opts.filename){ + /* default data file name is <progname>.h5 */ + if ((UC_opts.filename=(char*)HDmalloc(HDstrlen(progname_g)+4))==NULL) { + fprintf(stderr, "malloc: failed\n"); + Hgoto_error(-1); + }; + HDstrcpy(UC_opts.filename, progname_g); + HDstrcat(UC_opts.filename, ".h5"); + } + done: /* All done. */ return(ret_value); |