diff options
Diffstat (limited to 'test/mirror_vfd.c')
-rw-r--r-- | test/mirror_vfd.c | 224 |
1 files changed, 175 insertions, 49 deletions
diff --git a/test/mirror_vfd.c b/test/mirror_vfd.c index 3556cd2..34a4481 100644 --- a/test/mirror_vfd.c +++ b/test/mirror_vfd.c @@ -75,6 +75,25 @@ static unsigned int g_verbosity = DEFAULT_VERBOSITY; #define MIRR_MESG_SIZE 128 static char mesg[MIRR_MESG_SIZE + 1]; +/* ---------------------------------------------------------------------------- + * Structure: struct mt_opts + * + * Purpose: Convenience structure to hold options as parsed from the + * command line. + * + * `portno` (int) + * Port number, as received from arguments. + * + * `ip` (char *) + * IP address string as received from arguments. + * + * ---------------------------------------------------------------------------- + */ +struct mt_opts { + int portno; + char ip[H5FD_MIRROR_MAX_IP_LEN + 1]; +}; + /* Convenience structure for passing file names via helper functions. */ struct mirrortest_filenames { @@ -98,7 +117,8 @@ static herr_t _close_chunking_ids(unsigned min_dset, unsigned max_dset, hid_t *d static herr_t _populate_filepath(const char *dirname, const char *_basename, hid_t fapl_id, char *path_out, hbool_t h5suffix); -static hid_t create_mirroring_split_fapl(const char *_basename, struct mirrortest_filenames *names); +static hid_t create_mirroring_split_fapl(const char *_basename, struct mirrortest_filenames *names, + const struct mt_opts *opts); static void mybzero(void *dest, size_t size); @@ -128,7 +148,7 @@ mybzero(void *dest, size_t size) * Function: _populate_filepath * * Purpose: Given a directory name and a base name, concatenate the two and - * run h5fixname() to get the "actual" path to the intented target. + * run h5fixname() to get the "actual" path to the intended target. * `h5suffix' should be FALSE to keep the base name unaltered; * TRUE will append the '.h5' h5suffix to the basename... * FALSE -> h5fixname_no_suffix(), TRUE -> h5fixname() @@ -1246,7 +1266,8 @@ error: * --------------------------------------------------------------------------- */ static hid_t -create_mirroring_split_fapl(const char *_basename, struct mirrortest_filenames *names) +create_mirroring_split_fapl(const char *_basename, struct mirrortest_filenames *names, + const struct mt_opts *opts) { H5FD_splitter_vfd_config_t splitter_config; H5FD_mirror_fapl_t mirror_conf; @@ -1274,8 +1295,8 @@ create_mirroring_split_fapl(const char *_basename, struct mirrortest_filenames * */ mirror_conf.magic = H5FD_MIRROR_FAPL_MAGIC; mirror_conf.version = H5FD_MIRROR_CURR_FAPL_T_VERSION; - mirror_conf.handshake_port = SERVER_HANDSHAKE_PORT; - if (HDstrncpy(mirror_conf.remote_ip, SERVER_IP_ADDRESS, H5FD_MIRROR_MAX_IP_LEN) == NULL) { + mirror_conf.handshake_port = opts->portno; + if (HDstrncpy(mirror_conf.remote_ip, opts->ip, H5FD_MIRROR_MAX_IP_LEN) == NULL) { TEST_ERROR; } splitter_config.wo_fapl_id = H5Pcreate(H5P_FILE_ACCESS); @@ -1354,7 +1375,7 @@ error: * --------------------------------------------------------------------------- */ static int -test_create_and_close(void) +test_create_and_close(const struct mt_opts *opts) { struct mirrortest_filenames names; hid_t file_id = H5I_INVALID_HID; @@ -1364,7 +1385,7 @@ test_create_and_close(void) /* Create FAPL for Splitter[sec2|mirror] */ - fapl_id = create_mirroring_split_fapl("basic_create", &names); + fapl_id = create_mirroring_split_fapl("basic_create", &names, opts); if (H5I_INVALID_HID == fapl_id) { TEST_ERROR; } @@ -1889,7 +1910,7 @@ error: * --------------------------------------------------------------------------- */ static int -test_basic_dataset_write(void) +test_basic_dataset_write(const struct mt_opts *opts) { struct mirrortest_filenames names; hid_t file_id = H5I_INVALID_HID; @@ -1906,7 +1927,7 @@ test_basic_dataset_write(void) /* Create FAPL for Splitter[sec2|mirror] */ - fapl_id = create_mirroring_split_fapl("basic_write", &names); + fapl_id = create_mirroring_split_fapl("basic_write", &names, opts); if (H5I_INVALID_HID == fapl_id) { TEST_ERROR; } @@ -2020,7 +2041,7 @@ error: * --------------------------------------------------------------------------- */ static int -test_chunked_dataset_write(void) +test_chunked_dataset_write(const struct mt_opts *opts) { struct mirrortest_filenames names; hid_t file_id = H5I_INVALID_HID; @@ -2030,7 +2051,7 @@ test_chunked_dataset_write(void) /* Create FAPL for Splitter[sec2|mirror] */ - fapl_id = create_mirroring_split_fapl("chunked_write", &names); + fapl_id = create_mirroring_split_fapl("chunked_write", &names, opts); if (H5I_INVALID_HID == fapl_id) { TEST_ERROR; } @@ -2134,7 +2155,7 @@ error: * --------------------------------------------------------------------------- */ static int -test_on_disk_zoo(void) +test_on_disk_zoo(const struct mt_opts *opts) { const char grp_name[] = "/only"; struct mirrortest_filenames names; @@ -2146,7 +2167,7 @@ test_on_disk_zoo(void) /* Create FAPL for Splitter[sec2|mirror] */ - fapl_id = create_mirroring_split_fapl("zoo", &names); + fapl_id = create_mirroring_split_fapl("zoo", &names, opts); if (H5I_INVALID_HID == fapl_id) { TEST_ERROR; } @@ -2183,8 +2204,9 @@ test_on_disk_zoo(void) if (pass) { validate_zoo(file_id, grp_name, 0); /* sanity-check */ } + if (!pass) { - HDprintf(failure_mssg); + HDprintf("%s", failure_mssg); TEST_ERROR; } @@ -2247,15 +2269,14 @@ error: * --------------------------------------------------------------------------- */ static int -test_vanishing_datasets(void) +test_vanishing_datasets(const struct mt_opts *opts) { struct mirrortest_filenames names; - hid_t file_id = H5I_INVALID_HID; - hid_t fapl_id = H5I_INVALID_HID; - hid_t dset_id = H5I_INVALID_HID; - hid_t dspace_id = H5I_INVALID_HID; - hid_t mirror_fapl_id = H5I_INVALID_HID; - hsize_t dims[2] = {DATABUFFER_SIZE, DATABUFFER_SIZE}; + hid_t file_id = H5I_INVALID_HID; + hid_t fapl_id = H5I_INVALID_HID; + hid_t dset_id = H5I_INVALID_HID; + hid_t dspace_id = H5I_INVALID_HID; + hsize_t dims[2] = {DATABUFFER_SIZE, DATABUFFER_SIZE}; uint32_t buf[DATABUFFER_SIZE][DATABUFFER_SIZE]; /* consider malloc? */ H5G_info_t group_info; unsigned int i, j, k; @@ -2269,7 +2290,7 @@ test_vanishing_datasets(void) /* Create FAPL for Splitter[sec2|mirror] */ - fapl_id = create_mirroring_split_fapl("vanishing", &names); + fapl_id = create_mirroring_split_fapl("vanishing", &names, opts); if (H5I_INVALID_HID == fapl_id) { TEST_ERROR; } @@ -2333,7 +2354,7 @@ test_vanishing_datasets(void) file_id = H5I_INVALID_HID; /* verify there are no datasets in file */ - file_id = H5Fopen(names.rw, H5F_ACC_RDONLY, H5P_DEFAULT); + file_id = H5Fopen(names.rw, H5F_ACC_RDONLY, fapl_id); if (file_id < 0) { TEST_ERROR; } @@ -2348,7 +2369,7 @@ test_vanishing_datasets(void) if (H5Fclose(file_id) < 0) { TEST_ERROR; } - file_id = H5Fopen(names.wo, H5F_ACC_RDONLY, H5P_DEFAULT); + file_id = H5Fopen(names.wo, H5F_ACC_RDONLY, fapl_id); if (file_id < 0) { TEST_ERROR; } @@ -2384,21 +2405,10 @@ test_vanishing_datasets(void) error: H5E_BEGIN_TRY { - if (mirror_fapl_id != H5I_INVALID_HID) { - H5Pclose(mirror_fapl_id); - } - if (fapl_id != H5I_INVALID_HID) { - H5Pclose(fapl_id); - } - if (file_id != H5I_INVALID_HID) { - H5Fclose(file_id); - } - if (dset_id != H5I_INVALID_HID) { - H5Dclose(dset_id); - } - if (dspace_id != H5I_INVALID_HID) { - H5Sclose(dspace_id); - } + H5Pclose(fapl_id); + H5Fclose(file_id); + H5Dclose(dset_id); + H5Sclose(dspace_id); } H5E_END_TRY; return -1; @@ -2419,7 +2429,7 @@ error: * --------------------------------------------------------------------------- */ static int -test_concurrent_access(void) +test_concurrent_access(const struct mt_opts *opts) { struct file_bundle { struct mirrortest_filenames names; @@ -2452,7 +2462,7 @@ test_concurrent_access(void) char _name[16] = ""; hid_t _fapl_id = H5I_INVALID_HID; HDsnprintf(_name, 15, "concurrent%d", i); - _fapl_id = create_mirroring_split_fapl(_name, &bundle[i].names); + _fapl_id = create_mirroring_split_fapl(_name, &bundle[i].names, opts); if (H5I_INVALID_HID == _fapl_id) { TEST_ERROR; } @@ -2563,6 +2573,111 @@ error: return -1; } /* end test_concurrent_access() */ +/* ---------------------------------------------------------------------------- + * Function: parse_args + * + * Purpose: Parse command-line arguments, populating the options struct + * pointer as appropriate. + * Default values will be set for unspecified options. + * + * Return: 0 on success, negative (-1) if error. + * ---------------------------------------------------------------------------- + */ +static int +parse_args(int argc, char **argv, struct mt_opts *opts) +{ + int i = 0; + + opts->portno = SERVER_HANDSHAKE_PORT; + HDstrncpy(opts->ip, SERVER_IP_ADDRESS, H5FD_MIRROR_MAX_IP_LEN); + + for (i = 1; i < argc; i++) { /* start with first possible option argument */ + if (!HDstrncmp(argv[i], "--ip=", 5)) { + HDstrncpy(opts->ip, argv[i] + 5, H5FD_MIRROR_MAX_IP_LEN); + } + else if (!HDstrncmp(argv[i], "--port=", 7)) { + opts->portno = HDatoi(argv[i] + 7); + } + else { + HDprintf("Unrecognized option: '%s'\n", argv[i]); + return -1; + } + } /* end for each argument from command line */ + + /* auto-replace 'localhost' with numeric IP */ + if (!HDstrncmp(opts->ip, "localhost", 10)) { /* include null terminator */ + HDstrncpy(opts->ip, "127.0.0.1", H5FD_MIRROR_MAX_IP_LEN); + } + + return 0; +} /* end parse_args() */ + +/* ---------------------------------------------------------------------------- + * Function: confirm_server + * + * Purpose: Create socket and confirm remote server is available. + * + * Return: 0 on success, negative (-1) if error. + * ---------------------------------------------------------------------------- + */ +static int +confirm_server(struct mt_opts *opts) +{ + char mybuf[16]; + int live_socket; + struct sockaddr_in target_addr; + unsigned attempt = 0; + + live_socket = HDsocket(AF_INET, SOCK_STREAM, 0); + if (live_socket < 0) { + HDprintf("ERROR socket()\n"); + return -1; + } + + target_addr.sin_family = AF_INET; + target_addr.sin_port = HDhtons((uint16_t)opts->portno); + target_addr.sin_addr.s_addr = HDinet_addr(opts->ip); + HDmemset(target_addr.sin_zero, '\0', sizeof(target_addr.sin_zero)); + + while (1) { + if (HDconnect(live_socket, (struct sockaddr *)&target_addr, (socklen_t)sizeof(target_addr)) < 0) { + if (attempt > 10) { + HDprintf("ERROR connect() (%d)\n%s\n", errno, HDstrerror(errno)); + return -1; + } + attempt++; + HDsleep(1); + HDprintf("attempt #%u: ERROR connect() (%d)\n%s\n", attempt, errno, HDstrerror(errno)); + } + else { + break; + } + } + + /* Request confirmation from the server */ + if (HDwrite(live_socket, "CONFIRM", 8) == -1) { + HDprintf("ERROR write() (%d)\n%s\n", errno, HDstrerror(errno)); + return -1; + } + + /* Read & verify response from port connection. */ + if (HDread(live_socket, &mybuf, sizeof(mybuf)) == -1) { + HDprintf("ERROR read() can't receive data\n"); + return -1; + } + if (HDstrncmp("ALIVE", mybuf, 6)) { + HDprintf("ERROR read() didn't receive data from server\n"); + return -1; + } + + if (HDclose(live_socket) < 0) { + HDprintf("ERROR close() can't close socket\n"); + return -1; + } + + return 0; +} /* end confirm_server() */ + /* --------------------------------------------------------------------------- * Function: main * @@ -2576,9 +2691,10 @@ error: * --------------------------------------------------------------------------- */ int -main(void) +main(int argc, char **argv) { - int nerrors = 0; + struct mt_opts opts; + int nerrors = 0; h5_reset(); @@ -2602,6 +2718,16 @@ main(void) } } + if (parse_args(argc, argv, &opts) < 0) { + HDprintf("Unable to parse arguments\n"); + HDexit(EXIT_FAILURE); + } + + if (confirm_server(&opts) < 0) { + HDprintf("Unable to confirm server is running\n"); + HDexit(EXIT_FAILURE); + } + /* -------------------- */ /* TESTS */ /* Tests return negative values; `-=' increments nerrors count */ @@ -2609,12 +2735,12 @@ main(void) if (nerrors == 0) { nerrors -= test_fapl_configuration(); nerrors -= test_xmit_encode_decode(); - nerrors -= test_create_and_close(); - nerrors -= test_basic_dataset_write(); - nerrors -= test_chunked_dataset_write(); - nerrors -= test_on_disk_zoo(); - nerrors -= test_vanishing_datasets(); - nerrors -= test_concurrent_access(); + nerrors -= test_create_and_close(&opts); + nerrors -= test_basic_dataset_write(&opts); + nerrors -= test_chunked_dataset_write(&opts); + nerrors -= test_on_disk_zoo(&opts); + nerrors -= test_vanishing_datasets(&opts); + nerrors -= test_concurrent_access(&opts); } if (nerrors) { |