/* Overall Algorithm: * Parse options from user; * Generate/pre-created test files needed and close it; * Write to the file. */ int main(int argc, char *argv[]) { int ret_value = 0; /* initialization */ if(setup_parameters(argc, argv) < 0) Hgoto_error(1); /* ============*/ /* Create file */ /* ============*/ printf("Creating skeleton data file for testing H5Odisable_mdc_flushes()...\n"); if(create_file() < 0) { fprintf(stderr, "***encounter error\n"); Hgoto_error(1); } /* end if */ else printf("File created.\n"); printf("writing to the file\n"); if(write_file() < 0) { fprintf(stderr, "write_file encountered error\n"); Hgoto_error(1); } done: /* Print result and exit */ if(ret_value != 0) printf("Error(s) encountered\n"); else printf("All passed\n"); return(ret_value); }
/* * Setup Use Case parameters by parsing command line options. * Setup default values if not set by options. */ static int parse_option(int argc, char * const argv[]) { int ret_value=0; int c; /* command line options: See function usage for a description */ const char *cmd_options = "f:hn:s:y:z:"; /* suppress getopt from printing error */ opterr = 0; while (1){ c = getopt (argc, argv, cmd_options); if (-1 == c) break; switch (c) { case 'h': usage(progname_g); exit(0); break; case 'f': /* usecase data file name */ filename_g = optarg; break; case 'n': /* number of planes to write/read */ if ((nplanes_g = atoi(optarg)) <= 0){ fprintf(stderr, "bad number of planes %s, must be a positive integer\n", optarg); usage(progname_g); Hgoto_error(-1); }; break; case 's': /* use swmr file open mode */ if ((use_swmr_g = atoi(optarg)) < 0){ fprintf(stderr, "swmr value should be 0(no) or 1(yes)\n"); usage(progname_g); Hgoto_error(-1); }; break; case 'y': /* Number of planes per chunk */ if ((chunkplanes_g = atoi(optarg)) <= 0){ fprintf(stderr, "bad number of planes per chunk %s, must be a positive integer\n", optarg); usage(progname_g); Hgoto_error(-1); }; break; case 'z': /* size of chunk=(z,z) */ if ((chunksize_g = atoi(optarg)) <= 0){ fprintf(stderr, "bad chunksize %s, must be a positive integer\n", optarg); usage(progname_g); Hgoto_error(-1); }; break; case '?': fprintf(stderr, "getopt returned '%c'.\n", c); Hgoto_error(-1); default: fprintf(stderr, "getopt returned unexpected value.\n"); fprintf(stderr, "Unexpected value is %d\n", c); Hgoto_error(-1); } } /* set test file name if not given */ if (!filename_g){ /* default data file name is <progname>.h5 */ if ((filename_g = (char*)HDmalloc(HDstrlen(progname_g)+4))==NULL) { fprintf(stderr, "malloc: failed\n"); Hgoto_error(-1); }; HDstrcpy(filename_g, progname_g); HDstrcat(filename_g, ".h5"); } done: /* All done. */ return(ret_value); } /* parse_option() */
/* Overall Algorithm: * Parse options from user; * Generate/pre-created the test file needed and close it; * fork: child processes become the reader processes; * while parent process continues as the writer process; * both run till ending conditions are met. */ int main(int argc, char *argv[]) { /*pid_t childpid[READERS_MAX]; int child_ret_value[READERS_MAX];*/ pid_t childpid=0; int child_ret_value; pid_t mypid, tmppid; int child_status; int child_wait_option=0; int ret_value = 0; /* initialization */ if (setup_parameters(argc, argv) < 0){ Hgoto_error(1); } /* ==============================================================*/ /* 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 (launch_g != UC_READER){ printf("Creating skeleton data file for test...\n"); if (create_wo_file() < 0){ fprintf(stderr, "***encounter error\n"); Hgoto_error(1); }else printf("File created.\n"); } /* flush output before possible fork */ HDfflush(stdout); if (launch_g==UC_READWRITE){ /* fork process */ if((childpid = fork()) < 0) { perror("fork"); Hgoto_error(1); }; }; mypid = getpid(); /* ============= */ /* launch reader */ /* ============= */ if (launch_g != UC_WRITER){ /* child process launch the reader */ if(0 == childpid) { printf("%d: launch reader process\n", mypid); if (read_wo_file() < 0){ fprintf(stderr, "read_wo_file encountered error\n"); exit(1); } /* Reader is done. Clean up by removing the data file */ HDremove(DATAFILE); exit(0); } } /* ============= */ /* launch writer */ /* ============= */ /* this process continues to launch the writer */ printf("%d: continue as the writer process\n", mypid); if (write_wo_file() < 0){ fprintf(stderr, "write_wo_file encountered error\n"); Hgoto_error(1); } /* ================================================ */ /* If readwrite, collect exit code of child process */ /* ================================================ */ if (launch_g == 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); } } done: /* Print result and exit */ if (ret_value != 0){ printf("Error(s) encountered\n"); }else{ printf("All passed\n"); } return(ret_value); }
/* Setup test parameters by parsing command line options. * Setup default values if not set by options. */ int parse_option(int argc, char * const argv[]) { int ret_value=0; int c; /* command line options: See function usage for a description */ const char *cmd_options = "hb:l:n:p:"; /* suppress getopt from printing error */ opterr = 0; while (1){ c = getopt (argc, argv, cmd_options); if (-1 == c) break; switch (c) { case 'h': usage(progname_g); exit(0); break; case 'b': /* number of planes to write/read */ if ((blocksize_g = atoi(optarg)) <= 0){ fprintf(stderr, "bad blocksize %s, must be a positive integer\n", optarg); usage(progname_g); Hgoto_error(-1); }; break; case 'n': /* number of planes to write/read */ if ((nlinkedblock_g = atoi(optarg)) < 2){ fprintf(stderr, "bad number of linked blocks %s, must be greater than 1.\n", optarg); usage(progname_g); Hgoto_error(-1); }; break; case 'p': /* number of planes to write/read */ if ((part_size_g = atoi(optarg)) <= 0){ fprintf(stderr, "bad partition size %s, must be a positive integer\n", optarg); usage(progname_g); Hgoto_error(-1); }; break; case 'l': /* launch reader or writer only */ switch (*optarg) { case 'r': /* reader only */ launch_g = UC_READER; break; case 'w': /* writer only */ launch_g = UC_WRITER; break; default: fprintf(stderr, "launch value(%c) should be w or r only.\n", *optarg); usage(progname_g); Hgoto_error(-1); break; } printf("launch = %d\n", launch_g); break; case '?': fprintf(stderr, "getopt returned '%c'.\n", c); usage(progname_g); Hgoto_error(-1); default: fprintf(stderr, "getopt returned unexpected value.\n"); fprintf(stderr, "Unexpected value is %d\n", c); Hgoto_error(-1); } } /* verify partition size must be >= blocksize */ if (part_size_g < blocksize_g ){ fprintf(stderr, "Blocksize %d should not be bigger than partition size %d\n", blocksize_g, part_size_g); Hgoto_error(-1); } done: /* All done. */ return(ret_value); }