From cedd2a41f5143834084a6e2f609929f19a55cb2b Mon Sep 17 00:00:00 2001 From: Dana Robinson <43805+derobins@users.noreply.github.com> Date: Thu, 5 Jan 2023 12:51:25 -0800 Subject: Brings mirror VFD test fixes from develop (#2392) --- src/H5FDmirror.c | 72 +- test/mirror_vfd.c | 2913 ++++++++++++++++----------------- test/test_mirror.sh.in | 18 +- test/use_append_chunk_mirror.c | 63 +- utils/mirror_vfd/CMakeLists.txt | 4 +- utils/mirror_vfd/mirror_server.c | 64 +- utils/mirror_vfd/mirror_server_stop.c | 11 + utils/mirror_vfd/mirror_writer.c | 37 +- 8 files changed, 1548 insertions(+), 1634 deletions(-) diff --git a/src/H5FDmirror.c b/src/H5FDmirror.c index f7f79fc..c0efb96 100644 --- a/src/H5FDmirror.c +++ b/src/H5FDmirror.c @@ -244,7 +244,7 @@ H5FD_mirror_init(void) FUNC_ENTER_NOAPI(H5I_INVALID_HID) - LOG_OP_CALL(FUNC); + LOG_OP_CALL(__func__); if (H5I_VFL != H5I_get_type(H5FD_MIRROR_g)) { H5FD_MIRROR_g = H5FD_register(&H5FD_mirror_g, sizeof(H5FD_class_t), FALSE); @@ -268,12 +268,12 @@ done: static herr_t H5FD__mirror_term(void) { - FUNC_ENTER_STATIC_NOERR + FUNC_ENTER_PACKAGE_NOERR /* Reset VFL ID */ H5FD_MIRROR_g = 0; - LOG_OP_CALL(FUNC); + LOG_OP_CALL(__func__); FUNC_LEAVE_NOAPI(SUCCEED) } /* end H5FD__mirror_term() */ @@ -337,7 +337,7 @@ H5FD__mirror_xmit_decode_uint32(uint32_t *out, const unsigned char *_buf) /* --------------------------------------------------------------------------- * Function: is_host_little_endian * - * Purpose: Determine whether the host machine is is little-endian. + * Purpose: Determine whether the host machine is little-endian. * * Store an integer with a known value, re-map the memory to a * character array, and inspect the array's contents. @@ -1127,9 +1127,9 @@ H5FD__mirror_verify_reply(H5FD_mirror_t *file) ssize_t read_ret = 0; herr_t ret_value = SUCCEED; - FUNC_ENTER_STATIC + FUNC_ENTER_PACKAGE - LOG_OP_CALL(FUNC); + LOG_OP_CALL(__func__); HDassert(file && file->sock_fd); @@ -1182,9 +1182,9 @@ H5FD__mirror_fapl_get(H5FD_t *_file) H5FD_mirror_fapl_t *fa = NULL; void *ret_value = NULL; - FUNC_ENTER_STATIC + FUNC_ENTER_PACKAGE - LOG_OP_CALL(FUNC); + LOG_OP_CALL(__func__); fa = (H5FD_mirror_fapl_t *)H5MM_calloc(sizeof(H5FD_mirror_fapl_t)); if (NULL == fa) @@ -1218,9 +1218,9 @@ H5FD__mirror_fapl_copy(const void *_old_fa) H5FD_mirror_fapl_t *new_fa = NULL; void *ret_value = NULL; - FUNC_ENTER_STATIC + FUNC_ENTER_PACKAGE - LOG_OP_CALL(FUNC); + LOG_OP_CALL(__func__); new_fa = (H5FD_mirror_fapl_t *)H5MM_malloc(sizeof(H5FD_mirror_fapl_t)); if (new_fa == NULL) @@ -1250,9 +1250,9 @@ H5FD__mirror_fapl_free(void *_fa) { H5FD_mirror_fapl_t *fa = (H5FD_mirror_fapl_t *)_fa; - FUNC_ENTER_STATIC_NOERR + FUNC_ENTER_PACKAGE_NOERR - LOG_OP_CALL(FUNC); + LOG_OP_CALL(__func__); /* sanity check */ HDassert(fa != NULL); @@ -1283,7 +1283,7 @@ H5Pget_fapl_mirror(hid_t fapl_id, H5FD_mirror_fapl_t *fa_dst) FUNC_ENTER_API(FAIL) H5TRACE2("e", "i*x", fapl_id, fa_dst); - LOG_OP_CALL(FUNC); + LOG_OP_CALL(__func__); if (NULL == fa_dst) HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "fa_dst is NULL"); @@ -1324,7 +1324,7 @@ H5Pset_fapl_mirror(hid_t fapl_id, H5FD_mirror_fapl_t *fa) FUNC_ENTER_API(FAIL) H5TRACE2("e", "i*x", fapl_id, fa); - LOG_OP_CALL(FUNC); + LOG_OP_CALL(__func__); plist = H5P_object_verify(fapl_id, H5P_FILE_ACCESS); if (NULL == plist) @@ -1368,9 +1368,9 @@ H5FD__mirror_open(const char *name, unsigned flags, hid_t fapl_id, haddr_t maxad H5FD_mirror_xmit_open_t *open_xmit = NULL; H5FD_t *ret_value = NULL; - FUNC_ENTER_STATIC + FUNC_ENTER_PACKAGE - LOG_OP_CALL(FUNC); + LOG_OP_CALL(__func__); /* --------------- */ /* Check arguments */ @@ -1493,9 +1493,9 @@ H5FD__mirror_close(H5FD_t *_file) int xmit_encoded = 0; /* monitor point of failure */ herr_t ret_value = SUCCEED; - FUNC_ENTER_STATIC + FUNC_ENTER_PACKAGE - LOG_OP_CALL(FUNC); + LOG_OP_CALL(__func__); /* Sanity check */ HDassert(file); @@ -1565,9 +1565,9 @@ done: static herr_t H5FD__mirror_query(const H5FD_t H5_ATTR_UNUSED *_file, unsigned long *flags) { - FUNC_ENTER_STATIC_NOERR; + FUNC_ENTER_PACKAGE_NOERR; - LOG_OP_CALL(FUNC); + LOG_OP_CALL(__func__); /* Notice: the Mirror VFD Writer currently uses only the Sec2 driver as * the underlying driver -- as such, the Mirror VFD implementation copies @@ -1602,9 +1602,9 @@ H5FD__mirror_get_eoa(const H5FD_t *_file, H5FD_mem_t H5_ATTR_UNUSED type) { const H5FD_mirror_t *file = (const H5FD_mirror_t *)_file; - FUNC_ENTER_STATIC_NOERR + FUNC_ENTER_PACKAGE_NOERR - LOG_OP_CALL(FUNC); + LOG_OP_CALL(__func__); HDassert(file); @@ -1629,9 +1629,9 @@ H5FD__mirror_set_eoa(H5FD_t *_file, H5FD_mem_t type, haddr_t addr) H5FD_mirror_t *file = (H5FD_mirror_t *)_file; herr_t ret_value = SUCCEED; - FUNC_ENTER_STATIC + FUNC_ENTER_PACKAGE - LOG_OP_CALL(FUNC); + LOG_OP_CALL(__func__); HDassert(file); @@ -1684,9 +1684,9 @@ H5FD__mirror_get_eof(const H5FD_t *_file, H5FD_mem_t H5_ATTR_UNUSED type) { const H5FD_mirror_t *file = (const H5FD_mirror_t *)_file; - FUNC_ENTER_STATIC_NOERR + FUNC_ENTER_PACKAGE_NOERR - LOG_OP_CALL(FUNC); + LOG_OP_CALL(__func__); HDassert(file); @@ -1705,9 +1705,9 @@ static herr_t H5FD__mirror_read(H5FD_t H5_ATTR_UNUSED *_file, H5FD_mem_t H5_ATTR_UNUSED type, hid_t H5_ATTR_UNUSED fapl_id, haddr_t H5_ATTR_UNUSED addr, size_t H5_ATTR_UNUSED size, void H5_ATTR_UNUSED *buf) { - FUNC_ENTER_STATIC_NOERR + FUNC_ENTER_PACKAGE_NOERR - LOG_OP_CALL(FUNC); + LOG_OP_CALL(__func__); FUNC_LEAVE_NOAPI(FAIL) } /* end H5FD__mirror_read() */ @@ -1738,9 +1738,9 @@ H5FD__mirror_write(H5FD_t *_file, H5FD_mem_t type, hid_t H5_ATTR_UNUSED dxpl_id, H5FD_mirror_t *file = (H5FD_mirror_t *)_file; herr_t ret_value = SUCCEED; - FUNC_ENTER_STATIC + FUNC_ENTER_PACKAGE - LOG_OP_CALL(FUNC); + LOG_OP_CALL(__func__); HDassert(file); HDassert(buf); @@ -1801,9 +1801,9 @@ H5FD__mirror_truncate(H5FD_t *_file, hid_t H5_ATTR_UNUSED dxpl_id, hbool_t H5_AT H5FD_mirror_t *file = (H5FD_mirror_t *)_file; herr_t ret_value = SUCCEED; - FUNC_ENTER_STATIC + FUNC_ENTER_PACKAGE - LOG_OP_CALL(FUNC); + LOG_OP_CALL(__func__); file->xmit.xmit_count = (file->xmit_i)++; file->xmit.op = H5FD_MIRROR_OP_TRUNCATE; @@ -1849,9 +1849,9 @@ H5FD__mirror_lock(H5FD_t *_file, hbool_t rw) H5FD_mirror_t *file = (H5FD_mirror_t *)_file; herr_t ret_value = SUCCEED; - FUNC_ENTER_STATIC + FUNC_ENTER_PACKAGE - LOG_OP_CALL(FUNC); + LOG_OP_CALL(__func__); file->xmit.xmit_count = (file->xmit_i)++; file->xmit.op = H5FD_MIRROR_OP_LOCK; @@ -1896,9 +1896,9 @@ H5FD__mirror_unlock(H5FD_t *_file) H5FD_mirror_t *file = (H5FD_mirror_t *)_file; herr_t ret_value = SUCCEED; - FUNC_ENTER_STATIC + FUNC_ENTER_PACKAGE - LOG_OP_CALL(FUNC); + LOG_OP_CALL(__func__); file->xmit.xmit_count = (file->xmit_i)++; file->xmit.op = H5FD_MIRROR_OP_UNLOCK; diff --git a/test/mirror_vfd.c b/test/mirror_vfd.c index f8caea8..b4f4c2c 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 { @@ -95,82 +114,57 @@ static herr_t _create_chunking_ids(hid_t file_id, unsigned min_dset, unsigned ma static herr_t _close_chunking_ids(unsigned min_dset, unsigned max_dset, hid_t *dataspace_ids, hid_t *filespace_ids, hid_t *dataset_ids, hid_t *memspace_id); -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 void mybzero(void *dest, size_t size); +static herr_t populate_filepath(const char *dirname, const char *_basename, hid_t fapl_id, char *path_out, + hbool_t h5suffix); -/* ---------------------------------------------------------------------------- - * Function: mybzero - * - * Purpose: Have bzero simplicity and abstraction in (possible) absence of - * it being available. - * - * Programmer: Jacob Smith - * 2020-03-30 - * ---------------------------------------------------------------------------- - */ -static void -mybzero(void *dest, size_t size) -{ - size_t i = 0; - char *s = NULL; - HDassert(dest != NULL); - s = (char *)dest; - for (i = 0; i < size; i++) { - *(s + i) = 0; - } -} /* end mybzero() */ +static hid_t create_mirroring_split_fapl(const char *_basename, struct mirrortest_filenames *names, + const struct mt_opts *opts); /* ---------------------------------------------------------------------------- - * Function: _populate_filepath + * 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 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() - * / / <_basename> + * / / * - * Programmer: Jacob Smith - * 2019-08-16 * ---------------------------------------------------------------------------- */ static herr_t -_populate_filepath(const char *dirname, const char *_basename, hid_t fapl_id, char *path_out, - hbool_t h5suffix) +populate_filepath(const char *dirname, const char *basename, hid_t fapl_id, char *path_out, hbool_t h5suffix) { - char _path[H5FD_SPLITTER_PATH_MAX]; + char *path = NULL; - if ((_basename == NULL) || (*_basename == 0) || (dirname == NULL) || (*dirname == 0) || - (path_out == NULL)) { + if ((basename == NULL) || (*basename == 0) || (dirname == NULL) || (*dirname == 0) || (path_out == NULL)) + TEST_ERROR; + + if (NULL == (path = HDcalloc(H5FD_SPLITTER_PATH_MAX, sizeof(char)))) TEST_ERROR; - } - if (HDsnprintf(_path, H5FD_SPLITTER_PATH_MAX, "%s%s%s", dirname, + if (HDsnprintf(path, H5FD_SPLITTER_PATH_MAX, "%s%s%s", dirname, (dirname[HDstrlen(dirname)] == '/') ? "" : "/", /* slash iff needed */ - _basename) > H5FD_SPLITTER_PATH_MAX) { + basename) > H5FD_SPLITTER_PATH_MAX) TEST_ERROR; - } if (h5suffix == TRUE) { - if (h5_fixname(_path, fapl_id, path_out, H5FD_SPLITTER_PATH_MAX) == NULL) { + if (h5_fixname(path, fapl_id, path_out, H5FD_SPLITTER_PATH_MAX) == NULL) TEST_ERROR; - } } else { - if (h5_fixname_no_suffix(_path, fapl_id, path_out, H5FD_SPLITTER_PATH_MAX) == NULL) { + if (h5_fixname_no_suffix(path, fapl_id, path_out, H5FD_SPLITTER_PATH_MAX) == NULL) TEST_ERROR; - } } + HDfree(path); + return SUCCEED; error: + HDfree(path); return FAIL; -} /* end _populate_filepath() */ +} /* end populate_filepath() */ /* --------------------------------------------------------------------------- * Function: build_paths @@ -179,39 +173,37 @@ error: * most mirror tests. * * Return: SUCCEED/FAIL - * - * Programmer: Jacob Smith - * 2019-08-16 * --------------------------------------------------------------------------- */ static herr_t -build_paths(const char *_basename, H5FD_splitter_vfd_config_t *splitter_config, +build_paths(const char *basename, H5FD_splitter_vfd_config_t *splitter_config, struct mirrortest_filenames *names) { - char baselogname[H5FD_SPLITTER_PATH_MAX]; + char *baselogname = NULL; - if (_populate_filepath(MIRROR_RW_DIR, _basename, splitter_config->rw_fapl_id, names->rw, TRUE) == FAIL) { + if (NULL == (baselogname = HDcalloc(H5FD_SPLITTER_PATH_MAX, sizeof(char)))) TEST_ERROR; - } - if (_populate_filepath(MIRROR_WO_DIR, _basename, splitter_config->wo_fapl_id, names->wo, TRUE) == FAIL) { + if (populate_filepath(MIRROR_RW_DIR, basename, splitter_config->rw_fapl_id, names->rw, TRUE) < 0) TEST_ERROR; - } - if (_basename == NULL || *_basename == 0) - return FAIL; - if (HDsnprintf(baselogname, H5FD_SPLITTER_PATH_MAX, "%s_err.log", _basename) > H5FD_SPLITTER_PATH_MAX) { + if (populate_filepath(MIRROR_WO_DIR, basename, splitter_config->wo_fapl_id, names->wo, TRUE) < 0) TEST_ERROR; - } - if (_populate_filepath(MIRROR_WO_DIR, baselogname, splitter_config->wo_fapl_id, names->log, FALSE) == - FAIL) { + if (basename == NULL || *basename == 0) + TEST_ERROR; + if (HDsnprintf(baselogname, H5FD_SPLITTER_PATH_MAX, "%s_err.log", basename) > H5FD_SPLITTER_PATH_MAX) TEST_ERROR; - } + + if (populate_filepath(MIRROR_WO_DIR, baselogname, splitter_config->wo_fapl_id, names->log, FALSE) < 0) + TEST_ERROR; + + HDfree(baselogname); return SUCCEED; error: + HDfree(baselogname); return FAIL; } /* end build_paths() */ @@ -222,15 +214,12 @@ error: * * Return: Success: 0 * Failure: -1 - * - * Programmer: Jacob Smith - * 2019-03-12 * --------------------------------------------------------------------------- */ static int test_fapl_configuration(void) { - hid_t fapl_id; + hid_t fapl_id = H5I_INVALID_HID; H5FD_mirror_fapl_t mirror_conf = { H5FD_MIRROR_FAPL_MAGIC, /* magic */ H5FD_MIRROR_CURR_FAPL_T_VERSION, /* version */ @@ -241,42 +230,39 @@ test_fapl_configuration(void) TESTING("Mirror fapl configuration (set/get)"); - fapl_id = H5Pcreate(H5P_FILE_ACCESS); - if (H5I_INVALID_HID == fapl_id) { + if ((fapl_id = H5Pcreate(H5P_FILE_ACCESS)) < 0) TEST_ERROR; - } - if (H5Pset_fapl_mirror(fapl_id, &mirror_conf) == FAIL) { + if (H5Pset_fapl_mirror(fapl_id, &mirror_conf) < 0) TEST_ERROR; - } - if (H5Pget_fapl_mirror(fapl_id, &fa_out) == FAIL) { + if (H5Pget_fapl_mirror(fapl_id, &fa_out) < 0) TEST_ERROR; - } - if (H5FD_MIRROR_FAPL_MAGIC != fa_out.magic) { + + if (H5FD_MIRROR_FAPL_MAGIC != fa_out.magic) TEST_ERROR; - } - if (H5FD_MIRROR_CURR_FAPL_T_VERSION != fa_out.version) { + + if (H5FD_MIRROR_CURR_FAPL_T_VERSION != fa_out.version) TEST_ERROR; - } - if (SERVER_HANDSHAKE_PORT != fa_out.handshake_port) { + + if (SERVER_HANDSHAKE_PORT != fa_out.handshake_port) TEST_ERROR; - } - if (HDstrncmp(SERVER_IP_ADDRESS, (const char *)fa_out.remote_ip, H5FD_MIRROR_MAX_IP_LEN)) { + + if (HDstrncmp(SERVER_IP_ADDRESS, (const char *)fa_out.remote_ip, H5FD_MIRROR_MAX_IP_LEN)) TEST_ERROR; - } - if (H5Pclose(fapl_id) == FAIL) { + if (H5Pclose(fapl_id) < 0) TEST_ERROR; - } PASSED(); return 0; error: - if (H5I_INVALID_HID != fapl_id) { - (void)H5Pclose(fapl_id); + H5E_BEGIN_TRY + { + H5Pclose(fapl_id); } + H5E_END_TRY; return -1; } /* end test_fapl_configuration() */ @@ -301,931 +287,904 @@ error: } \ } while (0); /* end PRINT_BUFFER_DIFF */ -/* --------------------------------------------------------------------------- - * Function: test_xmit_encode_decode - * - * Purpose: Test byte-encoding operations for network transport. - * - * Return: Success: 0 - * Failure: -1 - * - * Programmer: Jacob Smith - * 2020-02-02 - * --------------------------------------------------------------------------- - */ +/*******************************************/ +/* Encode/decode tests for various C types */ +/*******************************************/ + +/* Test uint8_t encode/decode */ static int -test_xmit_encode_decode(void) +test_encdec_uint8_t(void) { - H5FD_mirror_xmit_t xmit_mock; /* re-used header in various xmit tests */ + unsigned char buf[8]; + unsigned char expected[8]; + const uint8_t v = 200; + unsigned char out = 0; - TESTING("Mirror encode/decode of xmit elements"); + TESTING("Mirror encode/decode of uint8_t data"); - /* Set bogus values matching expected; encoding doesn't care - * Use sequential values to easily generate the expected buffer with a - * for loop. - */ - xmit_mock.magic = 0x00010203; - xmit_mock.version = 0x04; - xmit_mock.session_token = 0x05060708; - xmit_mock.xmit_count = 0x090A0B0C; - xmit_mock.op = 0x0D; + /* Start of buffer uint8_t */ + HDmemset(buf, 0, 8); + HDmemset(expected, 0, 8); + expected[0] = 200; + out = 0; + if (H5FD__mirror_xmit_encode_uint8(buf, v) != 1) + TEST_ERROR; + if (HDmemcmp(buf, expected, 8) != 0) { + PRINT_BUFFER_DIFF(buf, expected, 8); + TEST_ERROR; + } + if (H5FD__mirror_xmit_decode_uint8(&out, buf) != 1) + TEST_ERROR; + if (v != out) + TEST_ERROR; - /* Test uint8_t encode/decode - */ - do { - unsigned char buf[8]; - unsigned char expected[8]; - const uint8_t v = 200; - unsigned char out = 0; + /* Middle of buffer uint8_t */ + HDmemset(buf, 0, 8); + HDmemset(expected, 0, 8); + expected[3] = v; + out = 0; + if (H5FD__mirror_xmit_encode_uint8((buf + 3), v) != 1) + TEST_ERROR; + if (HDmemcmp(buf, expected, 8) != 0) { + PRINT_BUFFER_DIFF(buf, expected, 8); + TEST_ERROR; + } + if (H5FD__mirror_xmit_decode_uint8(&out, (buf + 3)) != 1) + TEST_ERROR; + if (v != out) + TEST_ERROR; - /* Start of buffer uint8_t - */ - mybzero(buf, 8); - mybzero(expected, 8); - expected[0] = 200; - out = 0; - if (H5FD__mirror_xmit_encode_uint8(buf, v) != 1) { - TEST_ERROR; - } - if (HDmemcmp(buf, expected, 8) != 0) { - PRINT_BUFFER_DIFF(buf, expected, 8); - TEST_ERROR; - } - if (H5FD__mirror_xmit_decode_uint8(&out, buf) != 1) { - TEST_ERROR; - } - if (v != out) { - TEST_ERROR; - } + /* End of buffer uint8_t */ + HDmemset(buf, 0, 8); + HDmemset(expected, 0, 8); + expected[7] = v; + out = 0; + if (H5FD__mirror_xmit_encode_uint8((buf + 7), v) != 1) + TEST_ERROR; + if (HDmemcmp(buf, expected, 8) != 0) { + PRINT_BUFFER_DIFF(buf, expected, 8); + TEST_ERROR; + } + if (H5FD__mirror_xmit_decode_uint8(&out, (buf + 7)) != 1) + TEST_ERROR; + if (v != out) + TEST_ERROR; - /* Middle of buffer uint8_t - */ - mybzero(buf, 8); - mybzero(expected, 8); - expected[3] = v; - out = 0; - if (H5FD__mirror_xmit_encode_uint8((buf + 3), v) != 1) { - TEST_ERROR; - } - if (HDmemcmp(buf, expected, 8) != 0) { - PRINT_BUFFER_DIFF(buf, expected, 8); - TEST_ERROR; - } - if (H5FD__mirror_xmit_decode_uint8(&out, (buf + 3)) != 1) { - TEST_ERROR; - } - if (v != out) { - TEST_ERROR; - } + PASSED(); + return 0; - /* End of buffer uint8_t - */ - mybzero(buf, 8); - mybzero(expected, 8); - expected[7] = v; - out = 0; - if (H5FD__mirror_xmit_encode_uint8((buf + 7), v) != 1) { - TEST_ERROR; - } - if (HDmemcmp(buf, expected, 8) != 0) { - PRINT_BUFFER_DIFF(buf, expected, 8); - TEST_ERROR; - } - if (H5FD__mirror_xmit_decode_uint8(&out, (buf + 7)) != 1) { - TEST_ERROR; - } - if (v != out) { - TEST_ERROR; - } +error: + return -1; +} - } while (0); /* end uint8_t en/decode */ +/* Test uint16_t encode/decode */ +static int +test_encdec_uint16_t(void) +{ + unsigned char buf[8]; + unsigned char expected[8]; + const uint16_t v = 0x8F02; + uint16_t out = 0; - /* Test uint16_t encode/decode - */ - do { - unsigned char buf[8]; - unsigned char expected[8]; - const uint16_t v = 0x8F02; - uint16_t out = 0; + TESTING("Mirror encode/decode of uint16_t data"); - /* Start of buffer uint16_t - */ - mybzero(buf, 8); - mybzero(expected, 8); - expected[0] = 0x8F; - expected[1] = 0x02; - out = 0; - if (H5FD__mirror_xmit_encode_uint16(buf, v) != 2) { - TEST_ERROR; - } - if (HDmemcmp(buf, expected, 8) != 0) { - PRINT_BUFFER_DIFF(buf, expected, 8); - TEST_ERROR; - } - if (H5FD__mirror_xmit_decode_uint16(&out, buf) != 2) { - TEST_ERROR; - } - if (out != v) { - TEST_ERROR; - } + /* Start of buffer uint16_t */ + HDmemset(buf, 0, 8); + HDmemset(expected, 0, 8); + expected[0] = 0x8F; + expected[1] = 0x02; + out = 0; + if (H5FD__mirror_xmit_encode_uint16(buf, v) != 2) + TEST_ERROR; + if (HDmemcmp(buf, expected, 8) != 0) { + PRINT_BUFFER_DIFF(buf, expected, 8); + TEST_ERROR; + } + if (H5FD__mirror_xmit_decode_uint16(&out, buf) != 2) + TEST_ERROR; + if (out != v) + TEST_ERROR; - /* Middle of buffer uint16_t - */ - mybzero(buf, 8); - mybzero(expected, 8); - expected[3] = 0x8F; - expected[4] = 0x02; - out = 0; - if (H5FD__mirror_xmit_encode_uint16((buf + 3), v) != 2) { - TEST_ERROR; - } - if (HDmemcmp(buf, expected, 8) != 0) { - PRINT_BUFFER_DIFF(buf, expected, 8); - TEST_ERROR; - } - if (H5FD__mirror_xmit_decode_uint16(&out, (buf + 3)) != 2) { - TEST_ERROR; - } - if (out != v) { - TEST_ERROR; - } - /* slice */ - if (H5FD__mirror_xmit_decode_uint16(&out, (buf + 4)) != 2) { - TEST_ERROR; - } - if (out != 0x0200) { - TEST_ERROR; - } + /* Middle of buffer uint16_t */ + HDmemset(buf, 0, 8); + HDmemset(expected, 0, 8); + expected[3] = 0x8F; + expected[4] = 0x02; + out = 0; + if (H5FD__mirror_xmit_encode_uint16((buf + 3), v) != 2) + TEST_ERROR; + if (HDmemcmp(buf, expected, 8) != 0) { + PRINT_BUFFER_DIFF(buf, expected, 8); + TEST_ERROR; + } + if (H5FD__mirror_xmit_decode_uint16(&out, (buf + 3)) != 2) + TEST_ERROR; + if (out != v) + TEST_ERROR; - /* End of buffer uint16_t - */ - mybzero(buf, 8); - mybzero(expected, 8); - expected[6] = 0x8F; - expected[7] = 0x02; - out = 0; - if (H5FD__mirror_xmit_encode_uint16((buf + 6), v) != 2) { - TEST_ERROR; - } - if (HDmemcmp(buf, expected, 8) != 0) { - PRINT_BUFFER_DIFF(buf, expected, 8); - TEST_ERROR; - } - if (H5FD__mirror_xmit_decode_uint16(&out, (buf + 6)) != 2) { - TEST_ERROR; - } - if (out != v) { - TEST_ERROR; - } + /* slice */ + if (H5FD__mirror_xmit_decode_uint16(&out, (buf + 4)) != 2) + TEST_ERROR; + if (out != 0x0200) + TEST_ERROR; - } while (0); /* end uint16_t en/decode */ + /* End of buffer uint16_t */ + HDmemset(buf, 0, 8); + HDmemset(expected, 0, 8); + expected[6] = 0x8F; + expected[7] = 0x02; + out = 0; + if (H5FD__mirror_xmit_encode_uint16((buf + 6), v) != 2) + TEST_ERROR; + if (HDmemcmp(buf, expected, 8) != 0) { + PRINT_BUFFER_DIFF(buf, expected, 8); + TEST_ERROR; + } + if (H5FD__mirror_xmit_decode_uint16(&out, (buf + 6)) != 2) + TEST_ERROR; + if (out != v) + TEST_ERROR; - /* Test uint32_t encode/decode - */ - do { - unsigned char buf[8]; - unsigned char expected[8]; - const uint32_t v = 0x8F020048; - uint32_t out = 0; + PASSED(); + return 0; - /* Start of buffer uint32_t - */ - mybzero(buf, 8); - mybzero(expected, 8); - expected[0] = 0x8F; - expected[1] = 0x02; - expected[2] = 0x00; - expected[3] = 0x48; - out = 0; - if (H5FD__mirror_xmit_encode_uint32(buf, v) != 4) { - TEST_ERROR; - } - if (HDmemcmp(buf, expected, 8) != 0) { - PRINT_BUFFER_DIFF(buf, expected, 8); - TEST_ERROR; - } - if (H5FD__mirror_xmit_decode_uint32(&out, buf) != 4) { - TEST_ERROR; - } - if (out != v) { - TEST_ERROR; - } +error: + return -1; +} - /* Middle of buffer uint32_t - */ - mybzero(buf, 8); - mybzero(expected, 8); - expected[3] = 0x8F; - expected[4] = 0x02; - expected[5] = 0x00; - expected[6] = 0x48; - out = 0; - if (H5FD__mirror_xmit_encode_uint32((buf + 3), v) != 4) { - TEST_ERROR; - } - if (HDmemcmp(buf, expected, 8) != 0) { - PRINT_BUFFER_DIFF(buf, expected, 8); - TEST_ERROR; - } - if (H5FD__mirror_xmit_decode_uint32(&out, (buf + 3)) != 4) { - TEST_ERROR; - } - if (out != v) { - TEST_ERROR; - } - /* slice */ - if (H5FD__mirror_xmit_decode_uint32(&out, (buf + 4)) != 4) { - TEST_ERROR; - } - if (out != 0x02004800) { - TEST_ERROR; - } +/* Test uint32_t encode/decode */ +static int +test_encdec_uint32_t(void) +{ + unsigned char buf[8]; + unsigned char expected[8]; + const uint32_t v = 0x8F020048; + uint32_t out = 0; - /* End of buffer uint32_t - */ - mybzero(buf, 8); - mybzero(expected, 8); - expected[4] = 0x8F; - expected[5] = 0x02; - expected[6] = 0x00; - expected[7] = 0x48; - out = 0; - if (H5FD__mirror_xmit_encode_uint32((buf + 4), v) != 4) { - TEST_ERROR; - } - if (HDmemcmp(buf, expected, 8) != 0) { - PRINT_BUFFER_DIFF(buf, expected, 8); - TEST_ERROR; - } - if (H5FD__mirror_xmit_decode_uint32(&out, (buf + 4)) != 4) { - TEST_ERROR; - } - if (out != v) { - TEST_ERROR; - } + TESTING("Mirror encode/decode of uint32_t data"); - } while (0); /* end uint32_t en/decode */ + /* Start of buffer uint32_t */ + HDmemset(buf, 0, 8); + HDmemset(expected, 0, 8); + expected[0] = 0x8F; + expected[1] = 0x02; + expected[2] = 0x00; + expected[3] = 0x48; + out = 0; + if (H5FD__mirror_xmit_encode_uint32(buf, v) != 4) + TEST_ERROR; + if (HDmemcmp(buf, expected, 8) != 0) { + PRINT_BUFFER_DIFF(buf, expected, 8); + TEST_ERROR; + } + if (H5FD__mirror_xmit_decode_uint32(&out, buf) != 4) + TEST_ERROR; + if (out != v) + TEST_ERROR; - /* Test uint64_t encode/decode - */ - do { - unsigned char buf[16]; - unsigned char expected[16]; - const uint64_t v = 0x90DCBE17939CE4BB; - uint64_t out = 0; + /* Middle of buffer uint32_t */ + HDmemset(buf, 0, 8); + HDmemset(expected, 0, 8); + expected[3] = 0x8F; + expected[4] = 0x02; + expected[5] = 0x00; + expected[6] = 0x48; + out = 0; + if (H5FD__mirror_xmit_encode_uint32((buf + 3), v) != 4) + TEST_ERROR; + if (HDmemcmp(buf, expected, 8) != 0) { + PRINT_BUFFER_DIFF(buf, expected, 8); + TEST_ERROR; + } + if (H5FD__mirror_xmit_decode_uint32(&out, (buf + 3)) != 4) + TEST_ERROR; + if (out != v) + TEST_ERROR; + /* slice */ + if (H5FD__mirror_xmit_decode_uint32(&out, (buf + 4)) != 4) + TEST_ERROR; + if (out != 0x02004800) + TEST_ERROR; - /* Start of buffer uint64_t - */ - mybzero(buf, 16); - mybzero(expected, 16); - expected[0] = 0x90; - expected[1] = 0xDC; - expected[2] = 0xBE; - expected[3] = 0x17; - expected[4] = 0x93; - expected[5] = 0x9C; - expected[6] = 0xE4; - expected[7] = 0xBB; - out = 0; - if (H5FD__mirror_xmit_encode_uint64(buf, v) != 8) { - TEST_ERROR; - } - if (HDmemcmp(buf, expected, 16) != 0) { - PRINT_BUFFER_DIFF(buf, expected, 16); - TEST_ERROR; - } - if (H5FD__mirror_xmit_decode_uint64(&out, buf) != 8) { - TEST_ERROR; - } - if (out != v) { - TEST_ERROR; - } + /* End of buffer uint32_t */ + HDmemset(buf, 0, 8); + HDmemset(expected, 0, 8); + expected[4] = 0x8F; + expected[5] = 0x02; + expected[6] = 0x00; + expected[7] = 0x48; + out = 0; + if (H5FD__mirror_xmit_encode_uint32((buf + 4), v) != 4) + TEST_ERROR; + if (HDmemcmp(buf, expected, 8) != 0) { + PRINT_BUFFER_DIFF(buf, expected, 8); + TEST_ERROR; + } + if (H5FD__mirror_xmit_decode_uint32(&out, (buf + 4)) != 4) + TEST_ERROR; + if (out != v) + TEST_ERROR; - /* Middle of buffer uint64_t - */ - mybzero(buf, 16); - mybzero(expected, 16); - expected[3] = 0x90; - expected[4] = 0xDC; - expected[5] = 0xBE; - expected[6] = 0x17; - expected[7] = 0x93; - expected[8] = 0x9C; - expected[9] = 0xE4; - expected[10] = 0xBB; - out = 0; - if (H5FD__mirror_xmit_encode_uint64((buf + 3), v) != 8) { - TEST_ERROR; - } - if (HDmemcmp(buf, expected, 16) != 0) { - PRINT_BUFFER_DIFF(buf, expected, 16); - TEST_ERROR; - } - if (H5FD__mirror_xmit_decode_uint64(&out, (buf + 3)) != 8) { - TEST_ERROR; - } - if (out != v) { - TEST_ERROR; - } - /* slice */ - if (H5FD__mirror_xmit_decode_uint64(&out, (buf + 6)) != 8) { - TEST_ERROR; - } - if (out != 0x17939CE4BB000000) { - TEST_ERROR; - } + PASSED(); + return 0; - /* End of buffer uint64_t - */ - mybzero(buf, 16); - mybzero(expected, 16); - expected[8] = 0x90; - expected[9] = 0xDC; - expected[10] = 0xBE; - expected[11] = 0x17; - expected[12] = 0x93; - expected[13] = 0x9C; - expected[14] = 0xE4; - expected[15] = 0xBB; - out = 0; - if (H5FD__mirror_xmit_encode_uint64((buf + 8), v) != 8) { - TEST_ERROR; - } - if (HDmemcmp(buf, expected, 16) != 0) { - PRINT_BUFFER_DIFF(buf, expected, 16); - TEST_ERROR; - } - if (H5FD__mirror_xmit_decode_uint64(&out, (buf + 8)) != 8) { - TEST_ERROR; - } - if (out != v) { - TEST_ERROR; - } +error: + return -1; +} - } while (0); /* end uint64_t en/decode */ +/* Test uint64_t encode/decode */ +static int +test_encdec_uint64_t(void) +{ + unsigned char buf[16]; + unsigned char expected[16]; + const uint64_t v = 0x90DCBE17939CE4BB; + uint64_t out = 0; - /* Test xmit header structure encode/decode - * Write bogus but easily verifiable data to inside a buffer, and compare. - * Then decode the buffer and compare the structure contents. - * Then repeat from a different offset in the buffer and compare. - */ - do { - unsigned char buf[H5FD_MIRROR_XMIT_HEADER_SIZE + 8]; - unsigned char expected[H5FD_MIRROR_XMIT_HEADER_SIZE + 8]; - H5FD_mirror_xmit_t xmit_out; - size_t i = 0; - - /* sanity check */ - if (14 != H5FD_MIRROR_XMIT_HEADER_SIZE) { - FAIL_PUTS_ERROR("Header size definition does not match test\n"); - } + TESTING("Mirror encode/decode of uint64_t data"); - /* Populate the expected buffer; expect end padding of 0xFF - */ - HDmemset(expected, 0xFF, H5FD_MIRROR_XMIT_HEADER_SIZE + 8); - for (i = 0; i < H5FD_MIRROR_XMIT_HEADER_SIZE; i++) { - expected[i + 2] = (unsigned char)i; - } + /* Start of buffer uint64_t */ + HDmemset(buf, 0, 16); + HDmemset(expected, 0, 16); + expected[0] = 0x90; + expected[1] = 0xDC; + expected[2] = 0xBE; + expected[3] = 0x17; + expected[4] = 0x93; + expected[5] = 0x9C; + expected[6] = 0xE4; + expected[7] = 0xBB; + out = 0; + if (H5FD__mirror_xmit_encode_uint64(buf, v) != 8) + TEST_ERROR; + if (HDmemcmp(buf, expected, 16) != 0) { + PRINT_BUFFER_DIFF(buf, expected, 16); + TEST_ERROR; + } + if (H5FD__mirror_xmit_decode_uint64(&out, buf) != 8) + TEST_ERROR; + if (out != v) + TEST_ERROR; - /* Encode, and compare buffer contents - * Initial buffer is filled with 0xFF to match expected padding - */ - HDmemset(buf, 0xFF, H5FD_MIRROR_XMIT_HEADER_SIZE + 8); - if (H5FD_mirror_xmit_encode_header((buf + 2), &xmit_mock) != H5FD_MIRROR_XMIT_HEADER_SIZE) { - TEST_ERROR; - } - if (HDmemcmp(buf, expected, H5FD_MIRROR_XMIT_HEADER_SIZE + 8) != 0) { - PRINT_BUFFER_DIFF(buf, expected, H5FD_MIRROR_XMIT_HEADER_SIZE + 8); - TEST_ERROR; - } + /* Middle of buffer uint64_t */ + HDmemset(buf, 0, 16); + HDmemset(expected, 0, 16); + expected[3] = 0x90; + expected[4] = 0xDC; + expected[5] = 0xBE; + expected[6] = 0x17; + expected[7] = 0x93; + expected[8] = 0x9C; + expected[9] = 0xE4; + expected[10] = 0xBB; + out = 0; + if (H5FD__mirror_xmit_encode_uint64((buf + 3), v) != 8) + TEST_ERROR; + if (HDmemcmp(buf, expected, 16) != 0) { + PRINT_BUFFER_DIFF(buf, expected, 16); + TEST_ERROR; + } + if (H5FD__mirror_xmit_decode_uint64(&out, (buf + 3)) != 8) + TEST_ERROR; + if (out != v) + TEST_ERROR; + /* Slice */ + if (H5FD__mirror_xmit_decode_uint64(&out, (buf + 6)) != 8) + TEST_ERROR; + if (out != 0x17939CE4BB000000) + TEST_ERROR; - /* Decode from buffer - */ - if (H5FD_mirror_xmit_decode_header(&xmit_out, (buf + 2)) != H5FD_MIRROR_XMIT_HEADER_SIZE) { - TEST_ERROR; - } - if (xmit_out.magic != xmit_mock.magic) - TEST_ERROR; - if (xmit_out.version != xmit_mock.version) - TEST_ERROR; - if (xmit_out.session_token != xmit_mock.session_token) - TEST_ERROR; - if (xmit_out.xmit_count != xmit_mock.xmit_count) - TEST_ERROR; - if (xmit_out.op != xmit_mock.op) - TEST_ERROR; + /* End of buffer uint64_t */ + HDmemset(buf, 0, 16); + HDmemset(expected, 0, 16); + expected[8] = 0x90; + expected[9] = 0xDC; + expected[10] = 0xBE; + expected[11] = 0x17; + expected[12] = 0x93; + expected[13] = 0x9C; + expected[14] = 0xE4; + expected[15] = 0xBB; + out = 0; + if (H5FD__mirror_xmit_encode_uint64((buf + 8), v) != 8) + TEST_ERROR; + if (HDmemcmp(buf, expected, 16) != 0) { + PRINT_BUFFER_DIFF(buf, expected, 16); + TEST_ERROR; + } + if (H5FD__mirror_xmit_decode_uint64(&out, (buf + 8)) != 8) + TEST_ERROR; + if (out != v) + TEST_ERROR; - /* Decode from different offset in buffer - * Observe changes when ingesting the padding - */ - if (H5FD_mirror_xmit_decode_header(&xmit_out, (buf)) != H5FD_MIRROR_XMIT_HEADER_SIZE) { - TEST_ERROR; - } - if (xmit_out.magic != 0xFFFF0001) - TEST_ERROR; - if (xmit_out.version != 0x02) - TEST_ERROR; - if (xmit_out.session_token != 0x03040506) - TEST_ERROR; - if (xmit_out.xmit_count != 0x0708090A) - TEST_ERROR; - if (xmit_out.op != 0x0B) - TEST_ERROR; + PASSED(); + return 0; - } while (0); /* end xmit header en/decode */ +error: + return -1; +} - /* Test xmit set-eoa structure encode/decode - * Write bogus but easily verifiable data to inside a buffer, and compare. - * Then decode the buffer and compare the structure contents. - * Then repeat from a different offset in the buffer and compare. - */ - do { - unsigned char buf[H5FD_MIRROR_XMIT_EOA_SIZE + 8]; - unsigned char expected[H5FD_MIRROR_XMIT_EOA_SIZE + 8]; - H5FD_mirror_xmit_eoa_t xmit_in; - H5FD_mirror_xmit_eoa_t xmit_out; - size_t i = 0; - - /* sanity check */ - if ((14 + 9) != H5FD_MIRROR_XMIT_EOA_SIZE) { - FAIL_PUTS_ERROR("Header size definition does not match test\n"); - } - if (xmit_mock.op != 0x0D) { - FAIL_PUTS_ERROR("shared header structure is not in expected state"); - } +/*****************************/ +/* Other Encode/decode tests */ +/*****************************/ - /* Populate the expected buffer; expect end padding of 0xFF - */ - HDmemset(expected, 0xFF, H5FD_MIRROR_XMIT_EOA_SIZE + 8); - for (i = 0; i < H5FD_MIRROR_XMIT_EOA_SIZE; i++) { - expected[i + 2] = (unsigned char)i; - } +/* Test xmit header structure encode/decode + * Write bogus but easily verifiable data to inside a buffer, and compare. + * Then decode the buffer and compare the structure contents. + * Then repeat from a different offset in the buffer and compare. + */ +static int +test_encdec_header(H5FD_mirror_xmit_t xmit_mock) +{ + unsigned char buf[H5FD_MIRROR_XMIT_HEADER_SIZE + 8]; + unsigned char expected[H5FD_MIRROR_XMIT_HEADER_SIZE + 8]; + H5FD_mirror_xmit_t xmit_out; + size_t i = 0; - /* Set xmit_in - */ - xmit_in.pub = xmit_mock; /* shared/common */ - xmit_in.type = 0x0E; - xmit_in.eoa_addr = 0x0F10111213141516; + TESTING("Mirror encode/decode of xmit header"); - /* Encode, and compare buffer contents - * Initial buffer is filled with 0xFF to match expected padding - */ - HDmemset(buf, 0xFF, H5FD_MIRROR_XMIT_EOA_SIZE + 8); - if (H5FD_mirror_xmit_encode_set_eoa((buf + 2), &xmit_in) != H5FD_MIRROR_XMIT_EOA_SIZE) { - TEST_ERROR; - } - if (HDmemcmp(buf, expected, H5FD_MIRROR_XMIT_EOA_SIZE + 8) != 0) { - PRINT_BUFFER_DIFF(buf, expected, H5FD_MIRROR_XMIT_EOA_SIZE + 8); - TEST_ERROR; - } + /* Sanity check */ + if (14 != H5FD_MIRROR_XMIT_HEADER_SIZE) + FAIL_PUTS_ERROR("Header size definition does not match test\n"); - /* Decode from buffer - */ - if (H5FD_mirror_xmit_decode_set_eoa(&xmit_out, (buf + 2)) != H5FD_MIRROR_XMIT_EOA_SIZE) { - TEST_ERROR; - } - if (xmit_out.pub.magic != xmit_mock.magic) - TEST_ERROR; - if (xmit_out.pub.version != xmit_mock.version) - TEST_ERROR; - if (xmit_out.pub.session_token != xmit_mock.session_token) - TEST_ERROR; - if (xmit_out.pub.xmit_count != xmit_mock.xmit_count) - TEST_ERROR; - if (xmit_out.pub.op != xmit_mock.op) - TEST_ERROR; - if (xmit_out.type != 0x0E) - TEST_ERROR; - if (xmit_out.eoa_addr != 0x0F10111213141516) - TEST_ERROR; + /* Populate the expected buffer; expect end padding of 0xFF */ + HDmemset(expected, 0xFF, H5FD_MIRROR_XMIT_HEADER_SIZE + 8); + for (i = 0; i < H5FD_MIRROR_XMIT_HEADER_SIZE; i++) { + expected[i + 2] = (unsigned char)i; + } - /* Decode from different offset in buffer - * Observe changes when ingesting the padding - */ - if (H5FD_mirror_xmit_decode_set_eoa(&xmit_out, (buf)) != H5FD_MIRROR_XMIT_EOA_SIZE) { - TEST_ERROR; - } - if (xmit_out.pub.magic != 0xFFFF0001) - TEST_ERROR; - if (xmit_out.pub.version != 0x02) - TEST_ERROR; - if (xmit_out.pub.session_token != 0x03040506) - TEST_ERROR; - if (xmit_out.pub.xmit_count != 0x0708090A) - TEST_ERROR; - if (xmit_out.pub.op != 0x0B) - TEST_ERROR; - if (xmit_out.type != 0x0C) - TEST_ERROR; - if (xmit_out.eoa_addr != 0x0D0E0F1011121314) - TEST_ERROR; + /* Encode, and compare buffer contents + * Initial buffer is filled with 0xFF to match expected padding + */ + HDmemset(buf, 0xFF, H5FD_MIRROR_XMIT_HEADER_SIZE + 8); + if (H5FD_mirror_xmit_encode_header((buf + 2), &xmit_mock) != H5FD_MIRROR_XMIT_HEADER_SIZE) + TEST_ERROR; + if (HDmemcmp(buf, expected, H5FD_MIRROR_XMIT_HEADER_SIZE + 8) != 0) { + PRINT_BUFFER_DIFF(buf, expected, H5FD_MIRROR_XMIT_HEADER_SIZE + 8); + TEST_ERROR; + } - } while (0); /* end xmit set-eoa en/decode */ + /* Decode from buffer */ + if (H5FD_mirror_xmit_decode_header(&xmit_out, (buf + 2)) != H5FD_MIRROR_XMIT_HEADER_SIZE) + TEST_ERROR; + if (xmit_out.magic != xmit_mock.magic) + TEST_ERROR; + if (xmit_out.version != xmit_mock.version) + TEST_ERROR; + if (xmit_out.session_token != xmit_mock.session_token) + TEST_ERROR; + if (xmit_out.xmit_count != xmit_mock.xmit_count) + TEST_ERROR; + if (xmit_out.op != xmit_mock.op) + TEST_ERROR; - /* Test xmit lock structure encode/decode - * Write bogus but easily verifiable data to inside a buffer, and compare. - * Then decode the buffer and compare the structure contents. - * Then repeat from a different offset in the buffer and compare. + /* Decode from different offset in buffer + * Observe changes when ingesting the padding */ - do { - unsigned char buf[H5FD_MIRROR_XMIT_LOCK_SIZE + 8]; - unsigned char expected[H5FD_MIRROR_XMIT_LOCK_SIZE + 8]; - H5FD_mirror_xmit_lock_t xmit_in; - H5FD_mirror_xmit_lock_t xmit_out; - size_t i = 0; - - /* sanity check */ - if ((14 + 8) != H5FD_MIRROR_XMIT_LOCK_SIZE) { - FAIL_PUTS_ERROR("Header size definition does not match test\n"); - } - if (xmit_mock.op != 0x0D) { - FAIL_PUTS_ERROR("shared header structure is not in expected state"); - } + if (H5FD_mirror_xmit_decode_header(&xmit_out, buf) != H5FD_MIRROR_XMIT_HEADER_SIZE) + TEST_ERROR; + if (xmit_out.magic != 0xFFFF0001) + TEST_ERROR; + if (xmit_out.version != 0x02) + TEST_ERROR; + if (xmit_out.session_token != 0x03040506) + TEST_ERROR; + if (xmit_out.xmit_count != 0x0708090A) + TEST_ERROR; + if (xmit_out.op != 0x0B) + TEST_ERROR; - /* Populate the expected buffer; expect end padding of 0xFF - */ - HDmemset(expected, 0xFF, H5FD_MIRROR_XMIT_LOCK_SIZE + 8); - for (i = 0; i < H5FD_MIRROR_XMIT_LOCK_SIZE; i++) { - expected[i + 2] = (unsigned char)i; - } + PASSED(); + return 0; - /* Set xmit_in - */ - xmit_in.pub = xmit_mock; /* shared/common */ - xmit_in.rw = 0x0E0F101112131415; +error: + return -1; +} - /* Encode, and compare buffer contents - * Initial buffer is filled with 0xFF to match expected padding - */ - HDmemset(buf, 0xFF, H5FD_MIRROR_XMIT_LOCK_SIZE + 8); - if (H5FD_mirror_xmit_encode_lock((buf + 2), &xmit_in) != H5FD_MIRROR_XMIT_LOCK_SIZE) { - TEST_ERROR; - } - if (HDmemcmp(buf, expected, H5FD_MIRROR_XMIT_LOCK_SIZE + 8) != 0) { - PRINT_BUFFER_DIFF(buf, expected, H5FD_MIRROR_XMIT_LOCK_SIZE + 8); - TEST_ERROR; - } +/* Test xmit set-eoa structure encode/decode + * Write bogus but easily verifiable data to inside a buffer, and compare. + * Then decode the buffer and compare the structure contents. + * Then repeat from a different offset in the buffer and compare. + */ +static int +test_encdec_set_eoa(H5FD_mirror_xmit_t xmit_mock) +{ + unsigned char buf[H5FD_MIRROR_XMIT_EOA_SIZE + 8]; + unsigned char expected[H5FD_MIRROR_XMIT_EOA_SIZE + 8]; + H5FD_mirror_xmit_eoa_t xmit_in; + H5FD_mirror_xmit_eoa_t xmit_out; + size_t i = 0; + + TESTING("Mirror encode/decode of xmit set-eoa"); + + /* Sanity check */ + if ((14 + 9) != H5FD_MIRROR_XMIT_EOA_SIZE) + FAIL_PUTS_ERROR("Header size definition does not match test\n"); + if (xmit_mock.op != 0x0D) + FAIL_PUTS_ERROR("shared header structure is not in expected state"); + + /* Populate the expected buffer; expect end padding of 0xFF */ + HDmemset(expected, 0xFF, H5FD_MIRROR_XMIT_EOA_SIZE + 8); + for (i = 0; i < H5FD_MIRROR_XMIT_EOA_SIZE; i++) + expected[i + 2] = (unsigned char)i; + + /* Set xmit_in */ + xmit_in.pub = xmit_mock; /* shared/common */ + xmit_in.type = 0x0E; + xmit_in.eoa_addr = 0x0F10111213141516; + + /* Encode, and compare buffer contents + * Initial buffer is filled with 0xFF to match expected padding + */ + HDmemset(buf, 0xFF, H5FD_MIRROR_XMIT_EOA_SIZE + 8); + if (H5FD_mirror_xmit_encode_set_eoa((buf + 2), &xmit_in) != H5FD_MIRROR_XMIT_EOA_SIZE) + TEST_ERROR; + if (HDmemcmp(buf, expected, H5FD_MIRROR_XMIT_EOA_SIZE + 8) != 0) { + PRINT_BUFFER_DIFF(buf, expected, H5FD_MIRROR_XMIT_EOA_SIZE + 8); + TEST_ERROR; + } - /* Decode from buffer - */ - if (H5FD_mirror_xmit_decode_lock(&xmit_out, (buf + 2)) != H5FD_MIRROR_XMIT_LOCK_SIZE) { - TEST_ERROR; - } - if (xmit_out.pub.magic != xmit_mock.magic) - TEST_ERROR; - if (xmit_out.pub.version != xmit_mock.version) - TEST_ERROR; - if (xmit_out.pub.session_token != xmit_mock.session_token) - TEST_ERROR; - if (xmit_out.pub.xmit_count != xmit_mock.xmit_count) - TEST_ERROR; - if (xmit_out.pub.op != xmit_mock.op) - TEST_ERROR; - if (xmit_out.rw != 0x0E0F101112131415) - TEST_ERROR; + /* Decode from buffer */ + if (H5FD_mirror_xmit_decode_set_eoa(&xmit_out, (buf + 2)) != H5FD_MIRROR_XMIT_EOA_SIZE) + TEST_ERROR; + if (xmit_out.pub.magic != xmit_mock.magic) + TEST_ERROR; + if (xmit_out.pub.version != xmit_mock.version) + TEST_ERROR; + if (xmit_out.pub.session_token != xmit_mock.session_token) + TEST_ERROR; + if (xmit_out.pub.xmit_count != xmit_mock.xmit_count) + TEST_ERROR; + if (xmit_out.pub.op != xmit_mock.op) + TEST_ERROR; + if (xmit_out.type != 0x0E) + TEST_ERROR; + if (xmit_out.eoa_addr != 0x0F10111213141516) + TEST_ERROR; - /* Decode from different offset in buffer - * Observe changes when ingesting the padding - */ - if (H5FD_mirror_xmit_decode_lock(&xmit_out, (buf)) != H5FD_MIRROR_XMIT_LOCK_SIZE) { - TEST_ERROR; - } - if (xmit_out.pub.magic != 0xFFFF0001) - TEST_ERROR; - if (xmit_out.pub.version != 0x02) - TEST_ERROR; - if (xmit_out.pub.session_token != 0x03040506) - TEST_ERROR; - if (xmit_out.pub.xmit_count != 0x0708090A) - TEST_ERROR; - if (xmit_out.pub.op != 0x0B) - TEST_ERROR; - if (xmit_out.rw != 0x0C0D0E0F10111213) - TEST_ERROR; + /* Decode from different offset in buffer + * Observe changes when ingesting the padding + */ + if (H5FD_mirror_xmit_decode_set_eoa(&xmit_out, buf) != H5FD_MIRROR_XMIT_EOA_SIZE) + TEST_ERROR; + if (xmit_out.pub.magic != 0xFFFF0001) + TEST_ERROR; + if (xmit_out.pub.version != 0x02) + TEST_ERROR; + if (xmit_out.pub.session_token != 0x03040506) + TEST_ERROR; + if (xmit_out.pub.xmit_count != 0x0708090A) + TEST_ERROR; + if (xmit_out.pub.op != 0x0B) + TEST_ERROR; + if (xmit_out.type != 0x0C) + TEST_ERROR; + if (xmit_out.eoa_addr != 0x0D0E0F1011121314) + TEST_ERROR; + + PASSED(); + return 0; - } while (0); /* end xmit lock en/decode */ +error: + return -1; +} - /* Test xmit open structure encode/decode - * Write bogus but easily verifiable data to inside a buffer, and compare. - * Then decode the buffer and compare the structure contents. - * Then repeat from a different offset in the buffer and compare. - * - * Verifies that the first zero character in the filepath will end the - * string, with all following bytes in the encoded buffer being zeroed. +/* Test xmit lock structure encode/decode + * Write bogus but easily verifiable data to inside a buffer, and compare. + * Then decode the buffer and compare the structure contents. + * Then repeat from a different offset in the buffer and compare. + */ +static int +test_encdec_lock(H5FD_mirror_xmit_t xmit_mock) +{ + unsigned char buf[H5FD_MIRROR_XMIT_LOCK_SIZE + 8]; + unsigned char expected[H5FD_MIRROR_XMIT_LOCK_SIZE + 8]; + H5FD_mirror_xmit_lock_t xmit_in; + H5FD_mirror_xmit_lock_t xmit_out; + size_t i = 0; + + TESTING("Mirror encode/decode of xmit lock"); + + /* Sanity check */ + if ((14 + 8) != H5FD_MIRROR_XMIT_LOCK_SIZE) + FAIL_PUTS_ERROR("Header size definition does not match test\n"); + if (xmit_mock.op != 0x0D) + FAIL_PUTS_ERROR("shared header structure is not in expected state"); + + /* Populate the expected buffer; expect end padding of 0xFF */ + HDmemset(expected, 0xFF, H5FD_MIRROR_XMIT_LOCK_SIZE + 8); + for (i = 0; i < H5FD_MIRROR_XMIT_LOCK_SIZE; i++) + expected[i + 2] = (unsigned char)i; + + /* Set xmit_in */ + xmit_in.pub = xmit_mock; /* shared/common */ + xmit_in.rw = 0x0E0F101112131415; + + /* Encode, and compare buffer contents + * Initial buffer is filled with 0xFF to match expected padding */ - do { - unsigned char buf[H5FD_MIRROR_XMIT_OPEN_SIZE + 8]; - unsigned char expected[H5FD_MIRROR_XMIT_OPEN_SIZE + 8]; - H5FD_mirror_xmit_open_t xmit_in; - H5FD_mirror_xmit_open_t xmit_out; - size_t i = 0; - - /* sanity check */ - if ((14 + 20 + 4097) != H5FD_MIRROR_XMIT_OPEN_SIZE) { - FAIL_PUTS_ERROR("Header size definition does not match test\n"); - } - if (xmit_mock.op != 0x0D) { - FAIL_PUTS_ERROR("shared header structure is not in expected state"); - } + HDmemset(buf, 0xFF, H5FD_MIRROR_XMIT_LOCK_SIZE + 8); + if (H5FD_mirror_xmit_encode_lock((buf + 2), &xmit_in) != H5FD_MIRROR_XMIT_LOCK_SIZE) + TEST_ERROR; + if (HDmemcmp(buf, expected, H5FD_MIRROR_XMIT_LOCK_SIZE + 8) != 0) { + PRINT_BUFFER_DIFF(buf, expected, H5FD_MIRROR_XMIT_LOCK_SIZE + 8); + TEST_ERROR; + } - /* Populate the expected buffer; expect end padding of 0xFF - */ - HDmemset(expected, 0xFF, H5FD_MIRROR_XMIT_OPEN_SIZE + 8); - for (i = 0; i < H5FD_MIRROR_XMIT_OPEN_SIZE; i++) { - /* 0x100 is "zero" in a byte, so encode will treat it as a NULL- - * terminator in the filepath string. Expect all zeroes following. - */ - expected[i + 2] = (i > 0xFF) ? 0 : (unsigned char)i; - } + /* Decode from buffer */ + if (H5FD_mirror_xmit_decode_lock(&xmit_out, (buf + 2)) != H5FD_MIRROR_XMIT_LOCK_SIZE) + TEST_ERROR; + if (xmit_out.pub.magic != xmit_mock.magic) + TEST_ERROR; + if (xmit_out.pub.version != xmit_mock.version) + TEST_ERROR; + if (xmit_out.pub.session_token != xmit_mock.session_token) + TEST_ERROR; + if (xmit_out.pub.xmit_count != xmit_mock.xmit_count) + TEST_ERROR; + if (xmit_out.pub.op != xmit_mock.op) + TEST_ERROR; + if (xmit_out.rw != 0x0E0F101112131415) + TEST_ERROR; + + /* Decode from different offset in buffer + * Observe changes when ingesting the padding + */ + if (H5FD_mirror_xmit_decode_lock(&xmit_out, buf) != H5FD_MIRROR_XMIT_LOCK_SIZE) + TEST_ERROR; + if (xmit_out.pub.magic != 0xFFFF0001) + TEST_ERROR; + if (xmit_out.pub.version != 0x02) + TEST_ERROR; + if (xmit_out.pub.session_token != 0x03040506) + TEST_ERROR; + if (xmit_out.pub.xmit_count != 0x0708090A) + TEST_ERROR; + if (xmit_out.pub.op != 0x0B) + TEST_ERROR; + if (xmit_out.rw != 0x0C0D0E0F10111213) + TEST_ERROR; + + PASSED(); + return 0; - /* Set xmit_in - */ - xmit_in.pub = xmit_mock; /* shared/common */ - xmit_in.flags = 0x0E0F1011; - xmit_in.maxaddr = 0x1213141516171819; - xmit_in.size_t_blob = 0x1A1B1C1D1E1F2021; - for (i = 0x22; i < H5FD_MIRROR_XMIT_FILEPATH_MAX + 0x22; i++) { - /* nonzero values repeat after 0x100, but will not be encoded */ - xmit_in.filename[i - 0x22] = (char)(i % 0x100); - } - xmit_in.filename[H5FD_MIRROR_XMIT_FILEPATH_MAX - 1] = 0; +error: + return -1; +} - /* Encode, and compare buffer contents - * Initial buffer is filled with 0xFF to match expected padding +/* Test xmit open structure encode/decode + * Write bogus but easily verifiable data to inside a buffer, and compare. + * Then decode the buffer and compare the structure contents. + * Then repeat from a different offset in the buffer and compare. + * + * Verifies that the first zero character in the filepath will end the + * string, with all following bytes in the encoded buffer being zeroed. + */ +static int +test_encdec_open(H5FD_mirror_xmit_t xmit_mock) +{ + unsigned char *buf = NULL; + unsigned char *expected = NULL; + H5FD_mirror_xmit_open_t *xmit_in = NULL; + H5FD_mirror_xmit_open_t *xmit_out = NULL; + + TESTING("Mirror encode/decode of xmit open"); + + /* Sanity check */ + if ((14 + 20 + 4097) != H5FD_MIRROR_XMIT_OPEN_SIZE) + FAIL_PUTS_ERROR("Header size definition does not match test\n"); + if (xmit_mock.op != 0x0D) + FAIL_PUTS_ERROR("shared header structure is not in expected state"); + + /* Allocate memory */ + if (NULL == (buf = HDmalloc((H5FD_MIRROR_XMIT_OPEN_SIZE + 8) * sizeof(unsigned char)))) + FAIL_PUTS_ERROR("Unable to allocate memory for buf"); + if (NULL == (expected = HDmalloc((H5FD_MIRROR_XMIT_OPEN_SIZE + 8) * sizeof(unsigned char)))) + FAIL_PUTS_ERROR("Unable to allocate memory for expected"); + if (NULL == (xmit_in = HDmalloc(sizeof(H5FD_mirror_xmit_open_t)))) + FAIL_PUTS_ERROR("Unable to allocate memory for xmit_in"); + if (NULL == (xmit_out = HDmalloc(sizeof(H5FD_mirror_xmit_open_t)))) + FAIL_PUTS_ERROR("Unable to allocate memory for xmit_out"); + + /* Populate the expected buffer; expect end padding of 0xFF */ + HDmemset(expected, 0xFF, H5FD_MIRROR_XMIT_OPEN_SIZE + 8); + for (size_t i = 0; i < H5FD_MIRROR_XMIT_OPEN_SIZE; i++) { + /* 0x100 is "zero" in a byte, so encode will treat it as a NULL- + * terminator in the filepath string. Expect all zeroes following. */ - HDmemset(buf, 0xFF, H5FD_MIRROR_XMIT_OPEN_SIZE + 8); - if (H5FD_mirror_xmit_encode_open((buf + 2), &xmit_in) != H5FD_MIRROR_XMIT_OPEN_SIZE) { - TEST_ERROR; - } - if (HDmemcmp(buf, expected, H5FD_MIRROR_XMIT_OPEN_SIZE + 8) != 0) { - PRINT_BUFFER_DIFF(buf, expected, H5FD_MIRROR_XMIT_OPEN_SIZE + 8); - TEST_ERROR; - } + expected[i + 2] = (i > 0xFF) ? 0 : (unsigned char)i; + } - /* Decode from buffer - */ - if (H5FD_mirror_xmit_decode_open(&xmit_out, (buf + 2)) != H5FD_MIRROR_XMIT_OPEN_SIZE) { - TEST_ERROR; - } - if (xmit_out.pub.magic != xmit_mock.magic) - TEST_ERROR; - if (xmit_out.pub.version != xmit_mock.version) - TEST_ERROR; - if (xmit_out.pub.session_token != xmit_mock.session_token) - TEST_ERROR; - if (xmit_out.pub.xmit_count != xmit_mock.xmit_count) - TEST_ERROR; - if (xmit_out.pub.op != xmit_mock.op) - TEST_ERROR; - if (xmit_out.flags != xmit_in.flags) - TEST_ERROR; - if (xmit_out.maxaddr != xmit_in.maxaddr) - TEST_ERROR; - if (xmit_out.size_t_blob != xmit_in.size_t_blob) - TEST_ERROR; - if (HDstrncmp(xmit_out.filename, xmit_in.filename, H5FD_MIRROR_XMIT_FILEPATH_MAX) != 0) { - PRINT_BUFFER_DIFF(xmit_out.filename, xmit_in.filename, H5FD_MIRROR_XMIT_FILEPATH_MAX); - TEST_ERROR; - } + /* Set xmit_in */ + xmit_in->pub = xmit_mock; /* shared/common */ + xmit_in->flags = 0x0E0F1011; + xmit_in->maxaddr = 0x1213141516171819; + xmit_in->size_t_blob = 0x1A1B1C1D1E1F2021; + for (size_t i = 0x22; i < H5FD_MIRROR_XMIT_FILEPATH_MAX + 0x22; i++) { + /* Non-zero values repeat after 0x100, but will not be encoded */ + xmit_in->filename[i - 0x22] = (char)(i % 0x100); + } + xmit_in->filename[H5FD_MIRROR_XMIT_FILEPATH_MAX - 1] = 0; - /* Decode from different offset in buffer - * Observe changes when ingesting the padding - */ - if (H5FD_mirror_xmit_decode_open(&xmit_out, (buf)) != H5FD_MIRROR_XMIT_OPEN_SIZE) { - TEST_ERROR; - } - if (xmit_out.pub.magic != 0xFFFF0001) - TEST_ERROR; - if (xmit_out.pub.version != 0x02) - TEST_ERROR; - if (xmit_out.pub.session_token != 0x03040506) - TEST_ERROR; - if (xmit_out.pub.xmit_count != 0x0708090A) - TEST_ERROR; - if (xmit_out.pub.op != 0x0B) - TEST_ERROR; - if (xmit_out.flags != 0x0C0D0E0F) - TEST_ERROR; - if (xmit_out.maxaddr != 0x1011121314151617) - TEST_ERROR; - if (xmit_out.size_t_blob != 0x18191A1B1C1D1E1F) - TEST_ERROR; - /* update expected "filepath" in structure */ - for (i = 0x20; i < H5FD_MIRROR_XMIT_FILEPATH_MAX + 0x20; i++) { - xmit_in.filename[i - 0x20] = (i > 0xFF) ? 0 : (char)i; - } - if (HDstrncmp(xmit_out.filename, xmit_in.filename, H5FD_MIRROR_XMIT_FILEPATH_MAX) != 0) { - PRINT_BUFFER_DIFF(xmit_out.filename, xmit_in.filename, H5FD_MIRROR_XMIT_FILEPATH_MAX); - TEST_ERROR; - } + /* Encode, and compare buffer contents + * Initial buffer is filled with 0xFF to match expected padding + */ + HDmemset(buf, 0xFF, H5FD_MIRROR_XMIT_OPEN_SIZE + 8); + if (H5FD_mirror_xmit_encode_open((buf + 2), xmit_in) != H5FD_MIRROR_XMIT_OPEN_SIZE) + TEST_ERROR; + if (HDmemcmp(buf, expected, H5FD_MIRROR_XMIT_OPEN_SIZE + 8) != 0) { + PRINT_BUFFER_DIFF(buf, expected, H5FD_MIRROR_XMIT_OPEN_SIZE + 8); + TEST_ERROR; + } - } while (0); /* end xmit open en/decode */ + /* Decode from buffer */ + if (H5FD_mirror_xmit_decode_open(xmit_out, (buf + 2)) != H5FD_MIRROR_XMIT_OPEN_SIZE) + TEST_ERROR; + if (xmit_out->pub.magic != xmit_mock.magic) + TEST_ERROR; + if (xmit_out->pub.version != xmit_mock.version) + TEST_ERROR; + if (xmit_out->pub.session_token != xmit_mock.session_token) + TEST_ERROR; + if (xmit_out->pub.xmit_count != xmit_mock.xmit_count) + TEST_ERROR; + if (xmit_out->pub.op != xmit_mock.op) + TEST_ERROR; + if (xmit_out->flags != xmit_in->flags) + TEST_ERROR; + if (xmit_out->maxaddr != xmit_in->maxaddr) + TEST_ERROR; + if (xmit_out->size_t_blob != xmit_in->size_t_blob) + TEST_ERROR; + if (HDstrncmp(xmit_out->filename, xmit_in->filename, H5FD_MIRROR_XMIT_FILEPATH_MAX) != 0) { + PRINT_BUFFER_DIFF(xmit_out->filename, xmit_in->filename, H5FD_MIRROR_XMIT_FILEPATH_MAX); + TEST_ERROR; + } - /* Test xmit reply structure encode/decode - * Write bogus but easily verifiable data to inside a buffer, and compare. - * Then decode the buffer and compare the structure contents. - * Then repeat from a different offset in the buffer and compare. - * - * Verifies that the first zero character in the filepath will end the - * string, with all following bytes in the encoded buffer being zeroed. + /* Decode from different offset in buffer + * Observe changes when ingesting the padding */ - do { - unsigned char buf[H5FD_MIRROR_XMIT_REPLY_SIZE + 8]; - unsigned char expected[H5FD_MIRROR_XMIT_REPLY_SIZE + 8]; - H5FD_mirror_xmit_reply_t xmit_in; - H5FD_mirror_xmit_reply_t xmit_out; - size_t i = 0; - - /* sanity check */ - if ((14 + 4 + 256) != H5FD_MIRROR_XMIT_REPLY_SIZE) { - FAIL_PUTS_ERROR("Header size definition does not match test\n"); - } - if (xmit_mock.op != 0x0D) { - FAIL_PUTS_ERROR("shared header structure is not in expected state"); - } + if (H5FD_mirror_xmit_decode_open(xmit_out, buf) != H5FD_MIRROR_XMIT_OPEN_SIZE) + TEST_ERROR; + if (xmit_out->pub.magic != 0xFFFF0001) + TEST_ERROR; + if (xmit_out->pub.version != 0x02) + TEST_ERROR; + if (xmit_out->pub.session_token != 0x03040506) + TEST_ERROR; + if (xmit_out->pub.xmit_count != 0x0708090A) + TEST_ERROR; + if (xmit_out->pub.op != 0x0B) + TEST_ERROR; + if (xmit_out->flags != 0x0C0D0E0F) + TEST_ERROR; + if (xmit_out->maxaddr != 0x1011121314151617) + TEST_ERROR; + if (xmit_out->size_t_blob != 0x18191A1B1C1D1E1F) + TEST_ERROR; + /* Update expected "filepath" in structure */ + for (size_t i = 0x20; i < H5FD_MIRROR_XMIT_FILEPATH_MAX + 0x20; i++) + xmit_in->filename[i - 0x20] = (i > 0xFF) ? 0 : (char)i; + if (HDstrncmp(xmit_out->filename, xmit_in->filename, H5FD_MIRROR_XMIT_FILEPATH_MAX) != 0) { + PRINT_BUFFER_DIFF(xmit_out->filename, xmit_in->filename, H5FD_MIRROR_XMIT_FILEPATH_MAX); + TEST_ERROR; + } - /* Populate the expected buffer; expect end padding of 0xFF - */ - HDmemset(expected, 0xFF, H5FD_MIRROR_XMIT_REPLY_SIZE + 8); - for (i = 0; i < H5FD_MIRROR_XMIT_REPLY_SIZE; i++) { - /* 0x100 is "zero" in a byte, so encode will treat it as a NULL- - * terminator in the filepath string. Expect all zeroes following. - */ - expected[i + 2] = (i > 0xFF) ? 0 : (unsigned char)i; - } + HDfree(buf); + HDfree(expected); + HDfree(xmit_in); + HDfree(xmit_out); - /* Set xmit_in - */ - xmit_in.pub = xmit_mock; /* shared/common */ - xmit_in.status = 0x0E0F1011; - for (i = 0x12; i < H5FD_MIRROR_STATUS_MESSAGE_MAX + 0x12; i++) { - /* nonzero values repeat after 0x100, but will not be encoded */ - xmit_in.message[i - 0x12] = (char)(i % 0x100); - } - xmit_in.message[H5FD_MIRROR_STATUS_MESSAGE_MAX - 1] = 0; + PASSED(); + return 0; - /* Encode, and compare buffer contents - * Initial buffer is filled with 0xFF to match expected padding - */ - HDmemset(buf, 0xFF, H5FD_MIRROR_XMIT_REPLY_SIZE + 8); - if (H5FD_mirror_xmit_encode_reply((buf + 2), &xmit_in) != H5FD_MIRROR_XMIT_REPLY_SIZE) { - TEST_ERROR; - } - if (HDmemcmp(buf, expected, H5FD_MIRROR_XMIT_REPLY_SIZE + 8) != 0) { - PRINT_BUFFER_DIFF(buf, expected, H5FD_MIRROR_XMIT_REPLY_SIZE + 8); - TEST_ERROR; - } +error: + HDfree(buf); + HDfree(expected); + HDfree(xmit_in); + HDfree(xmit_out); - /* Decode from buffer - */ - if (H5FD_mirror_xmit_decode_reply(&xmit_out, (buf + 2)) != H5FD_MIRROR_XMIT_REPLY_SIZE) { - TEST_ERROR; - } - if (xmit_out.pub.magic != xmit_mock.magic) - TEST_ERROR; - if (xmit_out.pub.version != xmit_mock.version) - TEST_ERROR; - if (xmit_out.pub.session_token != xmit_mock.session_token) - TEST_ERROR; - if (xmit_out.pub.xmit_count != xmit_mock.xmit_count) - TEST_ERROR; - if (xmit_out.pub.op != xmit_mock.op) - TEST_ERROR; - if (xmit_out.status != xmit_in.status) - TEST_ERROR; - if (HDstrncmp(xmit_out.message, xmit_in.message, H5FD_MIRROR_STATUS_MESSAGE_MAX) != 0) { - PRINT_BUFFER_DIFF(xmit_out.message, xmit_in.message, H5FD_MIRROR_STATUS_MESSAGE_MAX); - TEST_ERROR; - } + return -1; +} - /* Decode from different offset in buffer - * Observe changes when ingesting the padding +/* Test xmit reply structure encode/decode + * Write bogus but easily verifiable data to inside a buffer, and compare. + * Then decode the buffer and compare the structure contents. + * Then repeat from a different offset in the buffer and compare. + * + * Verifies that the first zero character in the filepath will end the + * string, with all following bytes in the encoded buffer being zeroed. + */ +static int +test_encdec_reply(H5FD_mirror_xmit_t xmit_mock) +{ + unsigned char buf[H5FD_MIRROR_XMIT_REPLY_SIZE + 8]; + unsigned char expected[H5FD_MIRROR_XMIT_REPLY_SIZE + 8]; + H5FD_mirror_xmit_reply_t xmit_in; + H5FD_mirror_xmit_reply_t xmit_out; + size_t i = 0; + + TESTING("Mirror encode/decode of xmit reply"); + + /* Sanity check */ + if ((14 + 4 + 256) != H5FD_MIRROR_XMIT_REPLY_SIZE) + FAIL_PUTS_ERROR("Header size definition does not match test\n"); + if (xmit_mock.op != 0x0D) + FAIL_PUTS_ERROR("shared header structure is not in expected state"); + + /* Populate the expected buffer; expect end padding of 0xFF */ + HDmemset(expected, 0xFF, H5FD_MIRROR_XMIT_REPLY_SIZE + 8); + for (i = 0; i < H5FD_MIRROR_XMIT_REPLY_SIZE; i++) { + /* 0x100 is "zero" in a byte, so encode will treat it as a NULL- + * terminator in the filepath string. Expect all zeroes following. */ - if (H5FD_mirror_xmit_decode_reply(&xmit_out, (buf)) != H5FD_MIRROR_XMIT_REPLY_SIZE) { - TEST_ERROR; - } - if (xmit_out.pub.magic != 0xFFFF0001) - TEST_ERROR; - if (xmit_out.pub.version != 0x02) - TEST_ERROR; - if (xmit_out.pub.session_token != 0x03040506) - TEST_ERROR; - if (xmit_out.pub.xmit_count != 0x0708090A) - TEST_ERROR; - if (xmit_out.pub.op != 0x0B) - TEST_ERROR; - if (xmit_out.status != 0x0C0D0E0F) - TEST_ERROR; - /* update expected "message" in structure */ - for (i = 0x10; i < H5FD_MIRROR_STATUS_MESSAGE_MAX + 0x10; i++) { - xmit_in.message[i - 0x10] = (i > 0xFF) ? 0 : (char)i; - } - if (HDstrncmp(xmit_out.message, xmit_in.message, H5FD_MIRROR_STATUS_MESSAGE_MAX) != 0) { - PRINT_BUFFER_DIFF(xmit_out.message, xmit_in.message, H5FD_MIRROR_STATUS_MESSAGE_MAX); - TEST_ERROR; - } + expected[i + 2] = (i > 0xFF) ? 0 : (unsigned char)i; + } - } while (0); /* end xmit reply en/decode */ + /* Set xmit_in */ + xmit_in.pub = xmit_mock; /* shared/common */ + xmit_in.status = 0x0E0F1011; + for (i = 0x12; i < H5FD_MIRROR_STATUS_MESSAGE_MAX + 0x12; i++) { + /* Non-zero values repeat after 0x100, but will not be encoded */ + xmit_in.message[i - 0x12] = (char)(i % 0x100); + } + xmit_in.message[H5FD_MIRROR_STATUS_MESSAGE_MAX - 1] = 0; - /* Test xmit write structure encode/decode - * Write bogus but easily verifiable data to inside a buffer, and compare. - * Then decode the buffer and compare the structure contents. - * Then repeat from a different offset in the buffer and compare. + /* Encode, and compare buffer contents + * Initial buffer is filled with 0xFF to match expected padding */ - do { - unsigned char buf[H5FD_MIRROR_XMIT_WRITE_SIZE + 8]; - unsigned char expected[H5FD_MIRROR_XMIT_WRITE_SIZE + 8]; - H5FD_mirror_xmit_write_t xmit_in; - H5FD_mirror_xmit_write_t xmit_out; - size_t i = 0; - - /* sanity check */ - if ((14 + 17) != H5FD_MIRROR_XMIT_WRITE_SIZE) { - FAIL_PUTS_ERROR("Header size definition does not match test\n"); - } - if (xmit_mock.op != 0x0D) { - FAIL_PUTS_ERROR("shared header structure is not in expected state"); - } + HDmemset(buf, 0xFF, H5FD_MIRROR_XMIT_REPLY_SIZE + 8); + if (H5FD_mirror_xmit_encode_reply((buf + 2), &xmit_in) != H5FD_MIRROR_XMIT_REPLY_SIZE) + TEST_ERROR; + if (HDmemcmp(buf, expected, H5FD_MIRROR_XMIT_REPLY_SIZE + 8) != 0) { + PRINT_BUFFER_DIFF(buf, expected, H5FD_MIRROR_XMIT_REPLY_SIZE + 8); + TEST_ERROR; + } - /* Populate the expected buffer; expect end padding of 0xFF - */ - HDmemset(expected, 0xFF, H5FD_MIRROR_XMIT_WRITE_SIZE + 8); - for (i = 0; i < H5FD_MIRROR_XMIT_WRITE_SIZE; i++) { - expected[i + 2] = (unsigned char)i; - } + /* Decode from buffer */ + if (H5FD_mirror_xmit_decode_reply(&xmit_out, (buf + 2)) != H5FD_MIRROR_XMIT_REPLY_SIZE) + TEST_ERROR; + if (xmit_out.pub.magic != xmit_mock.magic) + TEST_ERROR; + if (xmit_out.pub.version != xmit_mock.version) + TEST_ERROR; + if (xmit_out.pub.session_token != xmit_mock.session_token) + TEST_ERROR; + if (xmit_out.pub.xmit_count != xmit_mock.xmit_count) + TEST_ERROR; + if (xmit_out.pub.op != xmit_mock.op) + TEST_ERROR; + if (xmit_out.status != xmit_in.status) + TEST_ERROR; + if (HDstrncmp(xmit_out.message, xmit_in.message, H5FD_MIRROR_STATUS_MESSAGE_MAX) != 0) { + PRINT_BUFFER_DIFF(xmit_out.message, xmit_in.message, H5FD_MIRROR_STATUS_MESSAGE_MAX); + TEST_ERROR; + } - /* Set xmit_in - */ - xmit_in.pub = xmit_mock; /* shared/common */ - xmit_in.type = 0x0E; - xmit_in.offset = 0x0F10111213141516; - xmit_in.size = 0x1718191A1B1C1D1E; + /* Decode from different offset in buffer + * Observe changes when ingesting the padding + */ + if (H5FD_mirror_xmit_decode_reply(&xmit_out, buf) != H5FD_MIRROR_XMIT_REPLY_SIZE) + TEST_ERROR; + if (xmit_out.pub.magic != 0xFFFF0001) + TEST_ERROR; + if (xmit_out.pub.version != 0x02) + TEST_ERROR; + if (xmit_out.pub.session_token != 0x03040506) + TEST_ERROR; + if (xmit_out.pub.xmit_count != 0x0708090A) + TEST_ERROR; + if (xmit_out.pub.op != 0x0B) + TEST_ERROR; + if (xmit_out.status != 0x0C0D0E0F) + TEST_ERROR; + /* Update expected "message" in structure */ + for (i = 0x10; i < H5FD_MIRROR_STATUS_MESSAGE_MAX + 0x10; i++) + xmit_in.message[i - 0x10] = (i > 0xFF) ? 0 : (char)i; + if (HDstrncmp(xmit_out.message, xmit_in.message, H5FD_MIRROR_STATUS_MESSAGE_MAX) != 0) { + PRINT_BUFFER_DIFF(xmit_out.message, xmit_in.message, H5FD_MIRROR_STATUS_MESSAGE_MAX); + TEST_ERROR; + } - /* Encode, and compare buffer contents - * Initial buffer is filled with 0xFF to match expected padding - */ - HDmemset(buf, 0xFF, H5FD_MIRROR_XMIT_WRITE_SIZE + 8); - if (H5FD_mirror_xmit_encode_write((buf + 2), &xmit_in) != H5FD_MIRROR_XMIT_WRITE_SIZE) { - TEST_ERROR; - } - if (HDmemcmp(buf, expected, H5FD_MIRROR_XMIT_WRITE_SIZE + 8) != 0) { - PRINT_BUFFER_DIFF(buf, expected, H5FD_MIRROR_XMIT_WRITE_SIZE + 8); - TEST_ERROR; - } + PASSED(); + return 0; - /* Decode from buffer - */ - if (H5FD_mirror_xmit_decode_write(&xmit_out, (buf + 2)) != H5FD_MIRROR_XMIT_WRITE_SIZE) { - TEST_ERROR; - } - if (xmit_out.pub.magic != xmit_mock.magic) - TEST_ERROR; - if (xmit_out.pub.version != xmit_mock.version) - TEST_ERROR; - if (xmit_out.pub.session_token != xmit_mock.session_token) - TEST_ERROR; - if (xmit_out.pub.xmit_count != xmit_mock.xmit_count) - TEST_ERROR; - if (xmit_out.pub.op != xmit_mock.op) - TEST_ERROR; - if (xmit_out.type != 0x0E) - TEST_ERROR; - if (xmit_out.offset != 0x0F10111213141516) - TEST_ERROR; - if (xmit_out.size != 0x1718191A1B1C1D1E) - TEST_ERROR; +error: + return -1; +} - /* Decode from different offset in buffer - * Observe changes when ingesting the padding - */ - if (H5FD_mirror_xmit_decode_write(&xmit_out, (buf)) != H5FD_MIRROR_XMIT_WRITE_SIZE) { - TEST_ERROR; - } - if (xmit_out.pub.magic != 0xFFFF0001) - TEST_ERROR; - if (xmit_out.pub.version != 0x02) - TEST_ERROR; - if (xmit_out.pub.session_token != 0x03040506) - TEST_ERROR; - if (xmit_out.pub.xmit_count != 0x0708090A) - TEST_ERROR; - if (xmit_out.pub.op != 0x0B) - TEST_ERROR; - if (xmit_out.type != 0x0C) - TEST_ERROR; - if (xmit_out.offset != 0x0D0E0F1011121314) - TEST_ERROR; - if (xmit_out.size != 0x15161718191A1B1C) - TEST_ERROR; +/* Test xmit write structure encode/decode + * Write bogus but easily verifiable data to inside a buffer, and compare. + * Then decode the buffer and compare the structure contents. + * Then repeat from a different offset in the buffer and compare. + */ +static int +test_encdec_write(H5FD_mirror_xmit_t xmit_mock) +{ + unsigned char buf[H5FD_MIRROR_XMIT_WRITE_SIZE + 8]; + unsigned char expected[H5FD_MIRROR_XMIT_WRITE_SIZE + 8]; + H5FD_mirror_xmit_write_t xmit_in; + H5FD_mirror_xmit_write_t xmit_out; + size_t i = 0; + + TESTING("Mirror encode/decode of xmit write"); + + /* Sanity check */ + if ((14 + 17) != H5FD_MIRROR_XMIT_WRITE_SIZE) + FAIL_PUTS_ERROR("Header size definition does not match test\n"); + if (xmit_mock.op != 0x0D) + FAIL_PUTS_ERROR("shared header structure is not in expected state"); + + /* Populate the expected buffer; expect end padding of 0xFF */ + HDmemset(expected, 0xFF, H5FD_MIRROR_XMIT_WRITE_SIZE + 8); + for (i = 0; i < H5FD_MIRROR_XMIT_WRITE_SIZE; i++) + expected[i + 2] = (unsigned char)i; + + /* Set xmit_in */ + xmit_in.pub = xmit_mock; /* shared/common */ + xmit_in.type = 0x0E; + xmit_in.offset = 0x0F10111213141516; + xmit_in.size = 0x1718191A1B1C1D1E; + + /* Encode, and compare buffer contents + * Initial buffer is filled with 0xFF to match expected padding + */ + HDmemset(buf, 0xFF, H5FD_MIRROR_XMIT_WRITE_SIZE + 8); + if (H5FD_mirror_xmit_encode_write((buf + 2), &xmit_in) != H5FD_MIRROR_XMIT_WRITE_SIZE) + TEST_ERROR; + if (HDmemcmp(buf, expected, H5FD_MIRROR_XMIT_WRITE_SIZE + 8) != 0) { + PRINT_BUFFER_DIFF(buf, expected, H5FD_MIRROR_XMIT_WRITE_SIZE + 8); + TEST_ERROR; + } + + /* Decode from buffer */ + if (H5FD_mirror_xmit_decode_write(&xmit_out, (buf + 2)) != H5FD_MIRROR_XMIT_WRITE_SIZE) + TEST_ERROR; + if (xmit_out.pub.magic != xmit_mock.magic) + TEST_ERROR; + if (xmit_out.pub.version != xmit_mock.version) + TEST_ERROR; + if (xmit_out.pub.session_token != xmit_mock.session_token) + TEST_ERROR; + if (xmit_out.pub.xmit_count != xmit_mock.xmit_count) + TEST_ERROR; + if (xmit_out.pub.op != xmit_mock.op) + TEST_ERROR; + if (xmit_out.type != 0x0E) + TEST_ERROR; + if (xmit_out.offset != 0x0F10111213141516) + TEST_ERROR; + if (xmit_out.size != 0x1718191A1B1C1D1E) + TEST_ERROR; - } while (0); /* end xmit write en/decode */ + /* Decode from different offset in buffer + * Observe changes when ingesting the padding + */ + if (H5FD_mirror_xmit_decode_write(&xmit_out, buf) != H5FD_MIRROR_XMIT_WRITE_SIZE) + TEST_ERROR; + if (xmit_out.pub.magic != 0xFFFF0001) + TEST_ERROR; + if (xmit_out.pub.version != 0x02) + TEST_ERROR; + if (xmit_out.pub.session_token != 0x03040506) + TEST_ERROR; + if (xmit_out.pub.xmit_count != 0x0708090A) + TEST_ERROR; + if (xmit_out.pub.op != 0x0B) + TEST_ERROR; + if (xmit_out.type != 0x0C) + TEST_ERROR; + if (xmit_out.offset != 0x0D0E0F1011121314) + TEST_ERROR; + if (xmit_out.size != 0x15161718191A1B1C) + TEST_ERROR; PASSED(); return 0; error: return -1; -} /* end test_xmit_encode_decode */ +} /* --------------------------------------------------------------------------- * Function: create_mirroring_split_fapl @@ -1240,100 +1199,84 @@ error: * Return: Success: HID of the top-level (splitter) FAPL, a non-negative * value. * Failure: H5I_INVALID_HID, a negative value. - * - * Programmer: Jacob Smith - * 2019 * --------------------------------------------------------------------------- */ 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; - hid_t ret_value = H5I_INVALID_HID; + H5FD_splitter_vfd_config_t *splitter_config = NULL; + H5FD_mirror_fapl_t mirror_conf; + hid_t ret_value = H5I_INVALID_HID; - if (_basename == NULL || *_basename == '\0') { + if (NULL == (splitter_config = HDmalloc(sizeof(H5FD_splitter_vfd_config_t)))) TEST_ERROR; - } - - splitter_config.magic = H5FD_SPLITTER_MAGIC; - splitter_config.version = H5FD_CURR_SPLITTER_VFD_CONFIG_VERSION; - splitter_config.ignore_wo_errs = FALSE; - /* Create Splitter R/W channel driver (sec2) + /* Initialize the fapls, too, so the library doesn't try to + * close non-existing IDs on errors */ - splitter_config.rw_fapl_id = H5Pcreate(H5P_FILE_ACCESS); - if (H5I_INVALID_HID == splitter_config.rw_fapl_id) { + splitter_config->magic = H5FD_SPLITTER_MAGIC; + splitter_config->version = H5FD_CURR_SPLITTER_VFD_CONFIG_VERSION; + splitter_config->ignore_wo_errs = FALSE; + splitter_config->rw_fapl_id = H5I_INVALID_HID; + splitter_config->wo_fapl_id = H5I_INVALID_HID; + + if (basename == NULL || *basename == '\0') TEST_ERROR; - } - if (H5Pset_fapl_sec2(splitter_config.rw_fapl_id) == FAIL) { + + /* Create Splitter R/W channel driver (sec2) */ + if ((splitter_config->rw_fapl_id = H5Pcreate(H5P_FILE_ACCESS)) < 0) + TEST_ERROR; + if (H5Pset_fapl_sec2(splitter_config->rw_fapl_id) < 0) TEST_ERROR; - } - /* Create Splitter W/O channel driver (mirror) - */ + /* Create Splitter W/O channel driver (mirror) */ 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); - if (H5I_INVALID_HID == splitter_config.wo_fapl_id) { + if ((splitter_config->wo_fapl_id = H5Pcreate(H5P_FILE_ACCESS)) < 0) TEST_ERROR; - } - if (H5Pset_fapl_mirror(splitter_config.wo_fapl_id, &mirror_conf) == FAIL) { + if (H5Pset_fapl_mirror(splitter_config->wo_fapl_id, &mirror_conf) < 0) TEST_ERROR; - } - /* Build r/w, w/o, and log file paths - */ - if (build_paths(_basename, &splitter_config, names) < 0) { + /* Build r/w, w/o, and log file paths */ + if (build_paths(basename, splitter_config, names) < 0) TEST_ERROR; - } - /* Set file paths for w/o and logfile - */ - if (HDstrncpy(splitter_config.wo_path, (const char *)names->wo, H5FD_SPLITTER_PATH_MAX) == NULL) { + /* Set file paths for w/o and logfile */ + if (HDstrncpy(splitter_config->wo_path, (const char *)names->wo, H5FD_SPLITTER_PATH_MAX) == NULL) TEST_ERROR; - } - if (HDstrncpy(splitter_config.log_file_path, (const char *)names->log, H5FD_SPLITTER_PATH_MAX) == NULL) { + if (HDstrncpy(splitter_config->log_file_path, (const char *)names->log, H5FD_SPLITTER_PATH_MAX) == NULL) TEST_ERROR; - } - /* Create Splitter FAPL - */ - ret_value = H5Pcreate(H5P_FILE_ACCESS); - if (H5I_INVALID_HID == ret_value) { + /* Create Splitter FAPL */ + if ((ret_value = H5Pcreate(H5P_FILE_ACCESS)) < 0) TEST_ERROR; - } - if (H5Pset_fapl_splitter(ret_value, &splitter_config) == FAIL) { + if (H5Pset_fapl_splitter(ret_value, splitter_config) < 0) TEST_ERROR; - } - /* Close FAPLs created for child channels - */ - if (H5Pclose(splitter_config.rw_fapl_id) < 0) { + /* Close FAPLs created for child channels */ + if (H5Pclose(splitter_config->rw_fapl_id) < 0) TEST_ERROR; - } - splitter_config.rw_fapl_id = H5I_INVALID_HID; - if (H5Pclose(splitter_config.wo_fapl_id) < 0) { + if (H5Pclose(splitter_config->wo_fapl_id) < 0) TEST_ERROR; - } - splitter_config.wo_fapl_id = H5I_INVALID_HID; + + HDfree(splitter_config); return ret_value; error: - if (splitter_config.wo_fapl_id >= 0) { - (void)H5Pclose(splitter_config.wo_fapl_id); - } - if (splitter_config.rw_fapl_id >= 0) { - (void)H5Pclose(splitter_config.rw_fapl_id); - } - if (ret_value >= 0) { - (void)H5Pclose(ret_value); + HDfree(splitter_config); + H5E_BEGIN_TRY + { + H5Pclose(splitter_config->wo_fapl_id); + H5Pclose(splitter_config->rw_fapl_id); + H5Pclose(ret_value); } + H5E_END_TRY; + return H5I_INVALID_HID; } /* end create_mirroring_split_fapl() */ @@ -1348,55 +1291,43 @@ error: * * Return: Success: 0 * Failure: -1 - * - * Programmer: Jacob Smith - * 2019-12-17 * --------------------------------------------------------------------------- */ 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; - hid_t fapl_id = H5P_DEFAULT; + struct mirrortest_filenames *names = NULL; + hid_t file_id = H5I_INVALID_HID; + hid_t fapl_id = H5I_INVALID_HID; TESTING("File creation and immediate close"); - /* Create FAPL for Splitter[sec2|mirror] - */ - fapl_id = create_mirroring_split_fapl("basic_create", &names); - if (H5I_INVALID_HID == fapl_id) { + if (NULL == (names = HDmalloc(sizeof(struct mirrortest_filenames)))) TEST_ERROR; - } - - /* -------------------- */ - /* TEST: Create and Close */ - file_id = H5Fcreate(names.rw, H5F_ACC_TRUNC, H5P_DEFAULT, fapl_id); - if (H5I_INVALID_HID == file_id) { + /* Create FAPL for splitter[sec2|mirror] */ + if ((fapl_id = create_mirroring_split_fapl("basic_create", names, opts)) < 0) TEST_ERROR; - } - /* -------------------- */ - /* Standard cleanup */ + if ((file_id = H5Fcreate(names->rw, H5F_ACC_TRUNC, H5P_DEFAULT, fapl_id)) < 0) + TEST_ERROR; - if (H5Fclose(file_id) == FAIL) { + if (H5Fclose(file_id) < 0) TEST_ERROR; - } - if (fapl_id != H5P_DEFAULT && fapl_id >= 0) { - if (H5Pclose(fapl_id) == FAIL) { - TEST_ERROR; - } - } + if (H5Pclose(fapl_id) < 0) + TEST_ERROR; + + HDfree(names); PASSED(); return 0; error: + HDfree(names); H5E_BEGIN_TRY { - (void)H5Fclose(file_id); - (void)H5Pclose(fapl_id); + H5Fclose(file_id); + H5Pclose(fapl_id); } H5E_END_TRY; return -1; @@ -1412,9 +1343,6 @@ error: * and values. * * Return: SUCCEED/FAIL - * - * Programmer: Jacob Smith - * 2019-08-14 * ---------------------------------------------------------------------------- */ static herr_t @@ -1437,10 +1365,7 @@ create_datasets(hid_t file_id, unsigned min_dset, unsigned max_dset) LOGPRINT(2, "create_dataset()\n"); - /* --------------------------------- - * "Clear" ID arrays - */ - + /* Initialize ID arrays */ for (i = 0; i < MAX_DSET_COUNT; i++) { LOGPRINT(3, "clearing IDs [%d]\n", i); dataspace_ids[i] = H5I_INVALID_HID; @@ -1448,20 +1373,14 @@ create_datasets(hid_t file_id, unsigned min_dset, unsigned max_dset) filespace_ids[i] = H5I_INVALID_HID; } - /* --------------------------------- - * Generate dataspace, dataset, and 'filespace' IDs - */ - + /* Generate dataspace, dataset, and 'filespace' IDs */ if (_create_chunking_ids(file_id, min_dset, max_dset, chunk_dims, dset_dims, dataspace_ids, filespace_ids, - dataset_ids, &memspace_id) == FAIL) { + dataset_ids, &memspace_id) < 0) TEST_ERROR; - } - /* --------------------------------- - * Initialize (write) all datasets in a "round robin"... + /* Initialize (write) all datasets in a "round robin"... * for a given chunk 'location', write chunk data to each dataset. */ - for (i = 0; i < DSET_DIM; i += CHUNK_DIM) { LOGPRINT(3, "i: %d\n", i); for (j = 0; j < DSET_DIM; j += CHUNK_DIM) { @@ -1475,39 +1394,28 @@ create_datasets(hid_t file_id, unsigned min_dset, unsigned max_dset) } } - /* select on disk hyperslab */ + /* Select on disk hyperslab */ offset[0] = (hsize_t)i; offset[1] = (hsize_t)j; LOGPRINT(3, " H5Sselect_hyperslab()\n"); - if (H5Sselect_hyperslab(filespace_ids[m], H5S_SELECT_SET, offset, NULL, a_size, NULL) < 0) { + if (H5Sselect_hyperslab(filespace_ids[m], H5S_SELECT_SET, offset, NULL, a_size, NULL) < 0) TEST_ERROR; - } LOGPRINT(3, " H5Dwrite()\n"); if (H5Dwrite(dataset_ids[m], H5T_NATIVE_INT, memspace_id, filespace_ids[m], H5P_DEFAULT, - data_chunk) < 0) { + data_chunk) < 0) TEST_ERROR; - } } } } - /* --------------------------------- - * Read and verify data from datasets - */ - - if (_verify_datasets(min_dset, max_dset, filespace_ids, dataset_ids, memspace_id) == FAIL) { + /* Read and verify data from datasets */ + if (_verify_datasets(min_dset, max_dset, filespace_ids, dataset_ids, memspace_id) < 0) TEST_ERROR; - } - - /* --------------------------------- - * Cleanup - */ - if (_close_chunking_ids(min_dset, max_dset, dataspace_ids, filespace_ids, dataset_ids, &memspace_id) == - FAIL) { + /* Cleanup */ + if (_close_chunking_ids(min_dset, max_dset, dataspace_ids, filespace_ids, dataset_ids, &memspace_id) < 0) TEST_ERROR; - } return SUCCEED; @@ -1523,9 +1431,6 @@ error: * Purpose: Create new IDs to be used with the associated file. * * Return: SUCCEED/FAIL - * - * Programer: Jacob Smith - * 2019 * ---------------------------------------------------------------------------- */ static herr_t @@ -1533,92 +1438,69 @@ _create_chunking_ids(hid_t file_id, unsigned min_dset, unsigned max_dset, hsize_ hsize_t *dset_dims, hid_t *dataspace_ids, hid_t *filespace_ids, hid_t *dataset_ids, hid_t *memspace_id) { - char dset_name[DSET_NAME_LEN + 1]; - unsigned m = 0; - hid_t dcpl_id = H5I_INVALID_HID; + char dset_name[DSET_NAME_LEN + 1]; + hid_t dcpl_id = H5I_INVALID_HID; LOGPRINT(2, "_create_chunking_ids()\n"); - /* -------------------- - * Create chunking DCPL - */ - - dcpl_id = H5Pcreate(H5P_DATASET_CREATE); - if (dcpl_id < 0) { + /* Create chunking DCPL */ + if ((dcpl_id = H5Pcreate(H5P_DATASET_CREATE)) < 0) TEST_ERROR; - } - if (H5Pset_chunk(dcpl_id, 2, chunk_dims) == FAIL) { + if (H5Pset_chunk(dcpl_id, 2, chunk_dims) < 0) TEST_ERROR; - } - - /* -------------------- - * Create dataspace IDs - */ - for (m = min_dset; m <= max_dset; m++) { - dataspace_ids[m] = H5Screate_simple(2, dset_dims, NULL); - if (dataspace_ids[m] < 0) { + /* Create dataspace IDs */ + for (unsigned m = min_dset; m <= max_dset; m++) { + if ((dataspace_ids[m] = H5Screate_simple(2, dset_dims, NULL)) < 0) { HDsnprintf(mesg, MIRR_MESG_SIZE, "unable to create dataspace ID %d\n", m); FAIL_PUTS_ERROR(mesg); } } - /* -------------------- - * Create dataset IDs - */ - - for (m = min_dset; m <= max_dset; m++) { + /* Create dataset IDs */ + for (unsigned m = min_dset; m <= max_dset; m++) { if (HDsnprintf(dset_name, DSET_NAME_LEN, "/dset%03d", m) > DSET_NAME_LEN) { HDsnprintf(mesg, MIRR_MESG_SIZE, "unable to compose dset name %d\n", m); FAIL_PUTS_ERROR(mesg); } - dataset_ids[m] = H5Dcreate2(file_id, dset_name, H5T_STD_I32BE, dataspace_ids[m], H5P_DEFAULT, dcpl_id, - H5P_DEFAULT); - if (dataset_ids[m] < 0) { + if ((dataset_ids[m] = H5Dcreate2(file_id, dset_name, H5T_STD_I32BE, dataspace_ids[m], H5P_DEFAULT, + dcpl_id, H5P_DEFAULT)) < 0) { HDsnprintf(mesg, MIRR_MESG_SIZE, "unable to create dset ID %d\n", m); FAIL_PUTS_ERROR(mesg); } } - /* -------------------- - * Get file space IDs - */ - - for (m = min_dset; m <= max_dset; m++) { - filespace_ids[m] = H5Dget_space(dataset_ids[m]); - if (filespace_ids[m] < 0) { + /* Get file space IDs */ + for (unsigned m = min_dset; m <= max_dset; m++) { + if ((filespace_ids[m] = H5Dget_space(dataset_ids[m])) < 0) { HDsnprintf(mesg, MIRR_MESG_SIZE, "unable to create filespace ID %d\n", m); FAIL_PUTS_ERROR(mesg); } } - /* -------------------- - * Create mem space to be used to read and write chunks - */ - - *memspace_id = H5Screate_simple(2, chunk_dims, NULL); - if (*memspace_id < 0) { + /* Create mem space to be used to read and write chunks */ + if ((*memspace_id = H5Screate_simple(2, chunk_dims, NULL)) < 0) TEST_ERROR; - } - /* -------------------- - * Clean up the DCPL, even if there were errors before - */ - - if (dcpl_id != H5P_DEFAULT && dcpl_id != H5I_INVALID_HID) { - if (H5Pclose(dcpl_id) == FAIL) { - TEST_ERROR; - } - } + /* Clean up the DCPL */ + if (H5Pclose(dcpl_id) < 0) + TEST_ERROR; return SUCCEED; error: - if (dcpl_id != H5P_DEFAULT && dcpl_id != H5I_INVALID_HID) { - (void)H5Pclose(dcpl_id); + H5E_BEGIN_TRY + { + /* Note that it's the caller's responsibility to clean up any IDs + * passed back via out parameters + */ + H5Pclose(dcpl_id); } + H5E_END_TRY; + LOGPRINT(1, "_create_chunking_ids() FAILED\n"); + return FAIL; } /* end _create_chunking_ids() */ @@ -1628,61 +1510,47 @@ error: * Purpose: Open/access IDs from the given file. * * Return: SUCCEED/FAIL - * - * Programmer: Jacob Smith - * 2019 * ---------------------------------------------------------------------------- */ static herr_t _open_chunking_ids(hid_t file_id, unsigned min_dset, unsigned max_dset, hsize_t *chunk_dims, hid_t *filespace_ids, hid_t *dataset_ids, hid_t *memspace_id) { - char dset_name[DSET_NAME_LEN + 1]; - unsigned m = 0; + char dset_name[DSET_NAME_LEN + 1]; LOGPRINT(2, "_open_chunking_ids()\n"); - /* -------------------- - * Open dataset IDs - */ - - for (m = min_dset; m <= max_dset; m++) { + /* Open dataset IDs */ + for (unsigned m = min_dset; m <= max_dset; m++) { if (HDsnprintf(dset_name, DSET_NAME_LEN, "/dset%03d", m) > DSET_NAME_LEN) { HDsnprintf(mesg, MIRR_MESG_SIZE, "unable to compose dset name %d\n", m); FAIL_PUTS_ERROR(mesg); } - dataset_ids[m] = H5Dopen2(file_id, dset_name, H5P_DEFAULT); - if (dataset_ids[m] < 0) { + if ((dataset_ids[m] = H5Dopen2(file_id, dset_name, H5P_DEFAULT)) < 0) { HDsnprintf(mesg, MIRR_MESG_SIZE, "unable to open dset ID %d\n", m); FAIL_PUTS_ERROR(mesg); } } - /* -------------------- - * Open filespace IDs - */ - - for (m = min_dset; m <= max_dset; m++) { - filespace_ids[m] = H5Dget_space(dataset_ids[m]); - if (filespace_ids[m] < 0) { + /* Open filespace IDs */ + for (unsigned m = min_dset; m <= max_dset; m++) { + if ((filespace_ids[m] = H5Dget_space(dataset_ids[m])) < 0) { HDsnprintf(mesg, MIRR_MESG_SIZE, "unable to get filespace ID %d\n", m); FAIL_PUTS_ERROR(mesg); } } - /* -------------------- - * Create mem space to be used to read and write chunks - */ - - *memspace_id = H5Screate_simple(2, chunk_dims, NULL); - if (*memspace_id < 0) { + /* Create mem space to be used to read and write chunks */ + if ((*memspace_id = H5Screate_simple(2, chunk_dims, NULL)) < 0) TEST_ERROR; - } return SUCCEED; error: + /* Note that the caller is responsible for cleaning up IDs returned + * as out parameters + */ LOGPRINT(1, "_open_chunking_ids() FAILED\n"); return FAIL; } /* end _open_chunking_ids() */ @@ -1695,20 +1563,15 @@ error: * _open_chunking_ids(). (as opposed to created IDs) * * Return: SUCCEED/FAIL - * - * Programmer: Jacob Smith - * 2019 * --------------------------------------------------------------------------- */ static herr_t _close_chunking_ids(unsigned min_dset, unsigned max_dset, hid_t *dataspace_ids, hid_t *filespace_ids, hid_t *dataset_ids, hid_t *memspace_id) { - unsigned m; - LOGPRINT(2, "_close_chunking_ids()\n"); - for (m = min_dset; m <= max_dset; m++) { + for (unsigned m = min_dset; m <= max_dset; m++) { LOGPRINT(3, "closing ids[%d]\n", m); if (dataspace_ids) { if (H5Sclose(dataspace_ids[m]) < 0) { @@ -1726,9 +1589,9 @@ _close_chunking_ids(unsigned min_dset, unsigned max_dset, hid_t *dataspace_ids, } } - if ((*memspace_id != H5I_INVALID_HID) && (H5Sclose(*memspace_id) < 0)) { - TEST_ERROR; - } + if (*memspace_id != H5I_INVALID_HID) + if (H5Sclose(*memspace_id) < 0) + TEST_ERROR; return SUCCEED; @@ -1744,9 +1607,6 @@ error: * to create_datasets(). * * Return: SUCCEED/FAIL - * - * Programmer: Jacob Smith - * 2019 * --------------------------------------------------------------------------- */ static herr_t @@ -1770,9 +1630,8 @@ _verify_datasets(unsigned min_dset, unsigned max_dset, hid_t *filespace_ids, hid /* select on disk hyperslab */ offset[0] = (hsize_t)i; offset[1] = (hsize_t)j; - if (H5Sselect_hyperslab(filespace_ids[m], H5S_SELECT_SET, offset, NULL, a_size, NULL) < 0) { + if (H5Sselect_hyperslab(filespace_ids[m], H5S_SELECT_SET, offset, NULL, a_size, NULL) < 0) TEST_ERROR; - } if (H5Dread(dataset_ids[m], H5T_NATIVE_INT, memspace_id, filespace_ids[m], H5P_DEFAULT, data_chunk) < 0) { @@ -1809,19 +1668,15 @@ error: * tears down accessor information. * * Return: SUCCEED/FAIL - * - * Programmer: Jacob Smith - * 2019 * --------------------------------------------------------------------------- */ static herr_t verify_datasets(hid_t file_id, unsigned min_dset, unsigned max_dset) { - hid_t dataset_ids[MAX_DSET_COUNT + 1]; - hid_t filespace_ids[MAX_DSET_COUNT + 1]; - unsigned i; - hid_t memspace_id = H5I_INVALID_HID; - hsize_t chunk_dims[2] = {CHUNK_DIM, CHUNK_DIM}; + hid_t dataset_ids[MAX_DSET_COUNT + 1]; + hid_t filespace_ids[MAX_DSET_COUNT + 1]; + hid_t memspace_id = H5I_INVALID_HID; + hsize_t chunk_dims[2] = {CHUNK_DIM, CHUNK_DIM}; HDassert(file_id >= 0); HDassert(min_dset <= max_dset); @@ -1829,40 +1684,25 @@ verify_datasets(hid_t file_id, unsigned min_dset, unsigned max_dset) LOGPRINT(2, "verify_datasets()\n"); - /* --------------------------------- - * "Clear" ID arrays - */ - - for (i = 0; i < MAX_DSET_COUNT; i++) { + /* Initialize ID arrays */ + for (unsigned i = 0; i < MAX_DSET_COUNT; i++) { LOGPRINT(3, "clearing IDs [%d]\n", i); dataset_ids[i] = H5I_INVALID_HID; filespace_ids[i] = H5I_INVALID_HID; } - /* --------------------------------- - * Generate dataspace, dataset, and 'filespace' IDs - */ - + /* Generate dataspace, dataset, and 'filespace' IDs */ if (_open_chunking_ids(file_id, min_dset, max_dset, chunk_dims, filespace_ids, dataset_ids, - &memspace_id) == FAIL) { + &memspace_id) < 0) TEST_ERROR; - } - - /* --------------------------------- - * Read and verify data from datasets - */ - if (_verify_datasets(min_dset, max_dset, filespace_ids, dataset_ids, memspace_id) == FAIL) { + /* Read and verify data from datasets */ + if (_verify_datasets(min_dset, max_dset, filespace_ids, dataset_ids, memspace_id) < 0) TEST_ERROR; - } - - /* --------------------------------- - * Cleanup - */ - if (_close_chunking_ids(min_dset, max_dset, NULL, filespace_ids, dataset_ids, &memspace_id) == FAIL) { + /* Cleanup */ + if (_close_chunking_ids(min_dset, max_dset, NULL, filespace_ids, dataset_ids, &memspace_id) < 0) TEST_ERROR; - } return SUCCEED; @@ -1883,40 +1723,34 @@ error: * * Return: Success: 0 * Failure: -1 - * - * Programmer: Jacob Smith - * 2019 * --------------------------------------------------------------------------- */ 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; - hid_t fapl_id = H5P_DEFAULT; - hid_t dset_id = H5I_INVALID_HID; - hid_t dspace_id = H5I_INVALID_HID; - hid_t dtype_id = H5T_NATIVE_INT; - hsize_t dims[2] = {DATABUFFER_SIZE, DATABUFFER_SIZE}; - int *buf = NULL; - int i = 0; - int j = 0; + struct mirrortest_filenames *names = NULL; + 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 dtype_id = H5T_NATIVE_INT; + hsize_t dims[2] = {DATABUFFER_SIZE, DATABUFFER_SIZE}; + int *buf = NULL; + int i = 0; + int j = 0; TESTING("Mirror open and dataset writing"); - /* Create FAPL for Splitter[sec2|mirror] - */ - fapl_id = create_mirroring_split_fapl("basic_write", &names); - if (H5I_INVALID_HID == fapl_id) { + if (NULL == (names = HDmalloc(sizeof(struct mirrortest_filenames)))) TEST_ERROR; - } - /* Prepare data to be written - */ - buf = (int *)HDmalloc(DATABUFFER_SIZE * DATABUFFER_SIZE * sizeof(int)); - if (NULL == buf) { + /* Create FAPL for Splitter[sec2|mirror] */ + if ((fapl_id = create_mirroring_split_fapl("basic_write", names, opts)) < 0) + TEST_ERROR; + + /* Prepare data to be written */ + if (NULL == (buf = HDmalloc(DATABUFFER_SIZE * DATABUFFER_SIZE * sizeof(int)))) TEST_ERROR; - } for (i = 0; i < DATABUFFER_SIZE; i++) { for (j = 0; j < DATABUFFER_SIZE; j++) { int k = i * DATABUFFER_SIZE + j; @@ -1927,78 +1761,59 @@ test_basic_dataset_write(void) /* -------------------- */ /* TEST: Create and Close */ - file_id = H5Fcreate(names.rw, H5F_ACC_TRUNC, H5P_DEFAULT, fapl_id); - if (H5I_INVALID_HID == file_id) { + if ((file_id = H5Fcreate(names->rw, H5F_ACC_TRUNC, H5P_DEFAULT, fapl_id)) < 0) TEST_ERROR; - } - if (H5Fclose(file_id) == FAIL) { + if (H5Fclose(file_id) < 0) TEST_ERROR; - } - file_id = H5I_INVALID_HID; /* -------------------- */ /* TEST: Repoen and Write */ - file_id = H5Fopen(names.rw, H5F_ACC_RDWR, fapl_id); - if (H5I_INVALID_HID == file_id) { + if ((file_id = H5Fopen(names->rw, H5F_ACC_RDWR, fapl_id)) < 0) TEST_ERROR; - } - dspace_id = H5Screate_simple(2, dims, NULL); - if (H5I_INVALID_HID == dspace_id) { + if ((dspace_id = H5Screate_simple(2, dims, NULL)) < 0) TEST_ERROR; - } - dset_id = H5Dcreate2(file_id, "dataset", dtype_id, dspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); - if (H5I_INVALID_HID == dset_id) { + if ((dset_id = + H5Dcreate2(file_id, "dataset", dtype_id, dspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR; - } - if (H5Dwrite(dset_id, dtype_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf) == FAIL) { + if (H5Dwrite(dset_id, dtype_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf) < 0) TEST_ERROR; - } - /* -------------------- */ - /* Standard cleanup */ + /* Cleanup */ - HDfree(buf); - buf = NULL; - if (H5Dclose(dset_id) == FAIL) { + if (H5Dclose(dset_id) < 0) TEST_ERROR; - } - if (H5Sclose(dspace_id) == FAIL) { + if (H5Sclose(dspace_id) < 0) TEST_ERROR; - } - if (H5Fclose(file_id) == FAIL) { + if (H5Fclose(file_id) < 0) + TEST_ERROR; + if (H5Pclose(fapl_id) < 0) TEST_ERROR; - } - if (fapl_id != H5P_DEFAULT && fapl_id > 0) { - if (H5Pclose(fapl_id) == FAIL) { - TEST_ERROR; - } - } /* -------------------- */ /* TEST: Verify that the R/W and W/O files are identical */ - if (h5_compare_file_bytes(names.rw, names.wo) < 0) { + if (h5_compare_file_bytes(names->rw, names->wo) < 0) TEST_ERROR; - } + + HDfree(buf); + HDfree(names); PASSED(); return 0; error: + HDfree(buf); + HDfree(names); + H5E_BEGIN_TRY { - (void)H5Fclose(file_id); - if (buf) { - HDfree(buf); - } - (void)H5Dclose(dset_id); - (void)H5Sclose(dspace_id); - if (fapl_id != H5P_DEFAULT && fapl_id > 0) { - (void)H5Pclose(fapl_id); - } + H5Fclose(file_id); + H5Dclose(dset_id); + H5Sclose(dspace_id); + H5Pclose(fapl_id); } H5E_END_TRY; return -1; @@ -2014,104 +1829,79 @@ error: * * Return: Success: 0 * Failure: -1 - * - * Programmer: Jacob Smith - * 2019 * --------------------------------------------------------------------------- */ 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; - hid_t fapl_id = H5P_DEFAULT; + struct mirrortest_filenames *names = NULL; + + hid_t file_id = H5I_INVALID_HID; + hid_t fapl_id = H5P_DEFAULT; TESTING("Mirror open and dataset writing (chunked)"); - /* Create FAPL for Splitter[sec2|mirror] - */ - fapl_id = create_mirroring_split_fapl("chunked_write", &names); - if (H5I_INVALID_HID == fapl_id) { + if (NULL == (names = HDmalloc(sizeof(struct mirrortest_filenames)))) + TEST_ERROR; + + /* Create FAPL for Splitter[sec2|mirror] */ + if ((fapl_id = create_mirroring_split_fapl("chunked_write", names, opts)) < 0) TEST_ERROR; - } /* -------------------- */ /* TEST: Create and Close */ - file_id = H5Fcreate(names.rw, H5F_ACC_TRUNC, H5P_DEFAULT, fapl_id); - if (H5I_INVALID_HID == file_id) { + if ((file_id = H5Fcreate(names->rw, H5F_ACC_TRUNC, H5P_DEFAULT, fapl_id)) < 0) TEST_ERROR; - } - if (H5Fclose(file_id) == FAIL) { + if (H5Fclose(file_id) < 0) TEST_ERROR; - } - file_id = H5I_INVALID_HID; /* -------------------- */ /* TEST: Reopen and Write */ - file_id = H5Fopen(names.rw, H5F_ACC_RDWR, fapl_id); - if (H5I_INVALID_HID == file_id) { + if ((file_id = H5Fopen(names->rw, H5F_ACC_RDWR, fapl_id)) < 0) TEST_ERROR; - } - /* Write datasets to file - */ - if (create_datasets(file_id, 0, MAX_DSET_COUNT) == FAIL) { + /* Write datasets to file */ + if (create_datasets(file_id, 0, MAX_DSET_COUNT) < 0) TEST_ERROR; - } - /* Close to 'flush to disk', and reopen file - */ - if (H5Fclose(file_id) == FAIL) { + /* Close to 'flush to disk', and reopen file */ + if (H5Fclose(file_id) < 0) TEST_ERROR; - } - file_id = H5I_INVALID_HID; - /* Reopen file - */ - file_id = H5Fopen(names.rw, H5F_ACC_RDWR, fapl_id); - if (H5I_INVALID_HID == file_id) { + /* Reopen file */ + if ((file_id = H5Fopen(names->rw, H5F_ACC_RDWR, fapl_id)) < 0) TEST_ERROR; - } - /* Verify written data integrity - */ - if (verify_datasets(file_id, 0, MAX_DSET_COUNT) == FAIL) { + /* Verify written data integrity */ + if (verify_datasets(file_id, 0, MAX_DSET_COUNT) < 0) TEST_ERROR; - } - - /* -------------------- */ - /* Standard cleanup */ - if (H5Fclose(file_id) == FAIL) { + /* Cleanup */ + if (H5Fclose(file_id) < 0) + TEST_ERROR; + if (H5Pclose(fapl_id) < 0) TEST_ERROR; - } - file_id = H5I_INVALID_HID; - if (fapl_id != H5P_DEFAULT && fapl_id > 0) { - if (H5Pclose(fapl_id) == FAIL) { - TEST_ERROR; - } - fapl_id = H5I_INVALID_HID; - } /* -------------------- */ /* TEST: Verify that the R/W and W/O files are identical */ - if (h5_compare_file_bytes(names.rw, names.wo) < 0) { + if (h5_compare_file_bytes(names->rw, names->wo) < 0) { TEST_ERROR; } + HDfree(names); + PASSED(); return 0; error: + HDfree(names); H5E_BEGIN_TRY { - (void)H5Fclose(file_id); - if (fapl_id != H5P_DEFAULT && fapl_id > 0) { - (void)H5Pclose(fapl_id); - } + H5Fclose(file_id); + H5Pclose(fapl_id); } H5E_END_TRY; return -1; @@ -2128,99 +1918,82 @@ error: * * Return: Success: 0 * Failure: -1 - * - * Programmer: Jacob Smith - * 2019 * --------------------------------------------------------------------------- */ 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; - hid_t file_id = H5I_INVALID_HID; - hid_t grp_id = H5I_INVALID_HID; - hid_t fapl_id = H5P_DEFAULT; + const char grp_name[] = "/only"; + struct mirrortest_filenames *names = NULL; + hid_t file_id = H5I_INVALID_HID; + hid_t grp_id = H5I_INVALID_HID; + hid_t fapl_id = H5I_INVALID_HID; TESTING("'Zoo' of on-disk structures"); - /* Create FAPL for Splitter[sec2|mirror] - */ - fapl_id = create_mirroring_split_fapl("zoo", &names); - if (H5I_INVALID_HID == fapl_id) { + if (NULL == (names = HDmalloc(sizeof(struct mirrortest_filenames)))) + TEST_ERROR; + + /* Create FAPL for Splitter[sec2|mirror] */ + if ((fapl_id = create_mirroring_split_fapl("zoo", names, opts)) < 0) TEST_ERROR; - } /* -------------------- */ /* TEST: Create file */ - file_id = H5Fcreate(names.rw, H5F_ACC_TRUNC, H5P_DEFAULT, fapl_id); - if (H5I_INVALID_HID == file_id) { + if ((file_id = H5Fcreate(names->rw, H5F_ACC_TRUNC, H5P_DEFAULT, fapl_id)) < 0) TEST_ERROR; - } - grp_id = H5Gcreate2(file_id, grp_name, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); - if (grp_id == H5I_INVALID_HID) { + if ((grp_id = H5Gcreate2(file_id, grp_name, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR; - } /* Create datasets in file, close (flush) and reopen, validate. * Use of ( pass ) a conceit required for using create_ and validate_zoo() * from cache_common and/or genall5. */ - if (pass) { + if (pass) create_zoo(file_id, grp_name, 0); - } if (pass) { - if (H5Fclose(file_id) == FAIL) { + if (H5Fclose(file_id) < 0) TEST_ERROR; - } - file_id = H5Fopen(names.rw, H5F_ACC_RDWR, fapl_id); - if (H5I_INVALID_HID == file_id) { + if ((file_id = H5Fopen(names->rw, H5F_ACC_RDWR, fapl_id)) < 0) TEST_ERROR; - } } - if (pass) { + if (pass) validate_zoo(file_id, grp_name, 0); /* sanity-check */ - } + if (!pass) { - HDprintf(failure_mssg); + HDprintf("%s", failure_mssg); TEST_ERROR; } - /* -------------------- */ - /* Standard cleanup */ + /* Cleanup */ - if (fapl_id != H5P_DEFAULT && fapl_id >= 0) { - if (H5Pclose(fapl_id) == FAIL) { - TEST_ERROR; - } - } - if (H5Gclose(grp_id) == FAIL) { + if (H5Pclose(fapl_id) < 0) TEST_ERROR; - } - if (H5Fclose(file_id) == FAIL) { + if (H5Gclose(grp_id) < 0) + TEST_ERROR; + if (H5Fclose(file_id) < 0) TEST_ERROR; - } /* -------------------- */ /* TEST: Verify that the R/W and W/O files are identical */ - if (h5_compare_file_bytes(names.rw, names.wo) < 0) { + if (h5_compare_file_bytes(names->rw, names->wo) < 0) TEST_ERROR; - } + + HDfree(names); PASSED(); return 0; error: + HDfree(names); H5E_BEGIN_TRY { - (void)H5Fclose(file_id); - (void)H5Gclose(grp_id); - if (fapl_id != H5P_DEFAULT && fapl_id > 0) { - (void)H5Pclose(fapl_id); - } + H5Fclose(file_id); + H5Gclose(grp_id); + H5Pclose(fapl_id); } H5E_END_TRY; return -1; @@ -2241,164 +2014,128 @@ error: * * Return: Success: 0 * Failure: -1 - * - * Programmer: Jacob Smith - * 2019 * --------------------------------------------------------------------------- */ 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}; - uint32_t buf[DATABUFFER_SIZE][DATABUFFER_SIZE]; /* consider malloc? */ - H5G_info_t group_info; - unsigned int i, j, k; - const unsigned int max_loops = 20; - const unsigned int max_at_one_time = 3; + struct mirrortest_filenames *names = NULL; + 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}; + H5G_info_t group_info; + unsigned int i, j, k; + const unsigned int max_loops = 20; + const unsigned int max_at_one_time = 3; + struct { + uint32_t arr[DATABUFFER_SIZE][DATABUFFER_SIZE]; + } *buf = NULL; TESTING("Vanishing Datasets"); + if (NULL == (names = HDmalloc(sizeof(struct mirrortest_filenames)))) + TEST_ERROR; + if (NULL == (buf = HDcalloc(1, sizeof(*buf)))) + TEST_ERROR; + /* -------------------- */ /* Set up recurrent data (FAPL, dataspace) */ - /* Create FAPL for Splitter[sec2|mirror] - */ - fapl_id = create_mirroring_split_fapl("vanishing", &names); - if (H5I_INVALID_HID == fapl_id) { + /* Create FAPL for Splitter[sec2|mirror] */ + if ((fapl_id = create_mirroring_split_fapl("vanishing", names, opts)) < 0) TEST_ERROR; - } - dspace_id = H5Screate_simple(2, dims, NULL); - if (dspace_id < 0) { + if ((dspace_id = H5Screate_simple(2, dims, NULL)) < 0) TEST_ERROR; - } - /* create file */ - file_id = H5Fcreate(names.rw, H5F_ACC_TRUNC, H5P_DEFAULT, fapl_id); - if (H5I_INVALID_HID == file_id) { + /* Create file */ + if ((file_id = H5Fcreate(names->rw, H5F_ACC_TRUNC, H5P_DEFAULT, fapl_id)) < 0) TEST_ERROR; - } for (i = 0; i < max_loops; i++) { char namebuf[DSET_NAME_LEN + 1]; - /* deleting datasets */ + /* Delete datasets */ if (i >= max_at_one_time) { - if (HDsnprintf(namebuf, DSET_NAME_LEN, "/dset%02d", (i - max_at_one_time)) > DSET_NAME_LEN) { + if (HDsnprintf(namebuf, DSET_NAME_LEN, "/dset%02d", (i - max_at_one_time)) > DSET_NAME_LEN) TEST_ERROR; - } - if (H5Ldelete(file_id, namebuf, H5P_DEFAULT) < 0) { + if (H5Ldelete(file_id, namebuf, H5P_DEFAULT) < 0) TEST_ERROR; - } - } /* end if deleting a dataset */ + } - /* writing datasets */ + /* Write to datasets */ if (i < (max_loops - max_at_one_time)) { - if (HDsnprintf(namebuf, DSET_NAME_LEN, "/dset%02d", i) > DSET_NAME_LEN) { + if (HDsnprintf(namebuf, DSET_NAME_LEN, "/dset%02d", i) > DSET_NAME_LEN) TEST_ERROR; - } - dset_id = - H5Dcreate2(file_id, namebuf, H5T_STD_U32LE, dspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); - if (H5I_INVALID_HID == dset_id) { + if ((dset_id = H5Dcreate2(file_id, namebuf, H5T_STD_U32LE, dspace_id, H5P_DEFAULT, H5P_DEFAULT, + H5P_DEFAULT)) < 0) TEST_ERROR; - } - for (j = 0; j < DATABUFFER_SIZE; j++) { - for (k = 0; k < DATABUFFER_SIZE; k++) { - buf[j][k] = (uint32_t)i; - } - } + for (j = 0; j < DATABUFFER_SIZE; j++) + for (k = 0; k < DATABUFFER_SIZE; k++) + buf->arr[j][k] = (uint32_t)i; - if (H5Dwrite(dset_id, H5T_STD_U32LE, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf) < 0) { + if (H5Dwrite(dset_id, H5T_STD_U32LE, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf) < 0) TEST_ERROR; - } - if (H5Dclose(dset_id) < 0) { + if (H5Dclose(dset_id) < 0) TEST_ERROR; - } - dset_id = H5I_INVALID_HID; - } /* end if writing a dataset */ + } } /* end for dataset create-destroy cycles */ - if (H5Fclose(file_id) < 0) { + if (H5Fclose(file_id) < 0) TEST_ERROR; - } - file_id = H5I_INVALID_HID; /* verify there are no datasets in file */ - file_id = H5Fopen(names.rw, H5F_ACC_RDONLY, H5P_DEFAULT); - if (file_id < 0) { + if ((file_id = H5Fopen(names->rw, H5F_ACC_RDONLY, fapl_id)) < 0) TEST_ERROR; - } - if (H5Gget_info(file_id, &group_info) < 0) { + if (H5Gget_info(file_id, &group_info) < 0) TEST_ERROR; - } if (group_info.nlinks > 0) { HDfprintf(stderr, "links in rw file: %" PRIuHSIZE "\n", group_info.nlinks); - HDfflush(stderr); TEST_ERROR; } - if (H5Fclose(file_id) < 0) { + if (H5Fclose(file_id) < 0) TEST_ERROR; - } - file_id = H5Fopen(names.wo, H5F_ACC_RDONLY, H5P_DEFAULT); - if (file_id < 0) { + if ((file_id = H5Fopen(names->wo, H5F_ACC_RDONLY, fapl_id)) < 0) TEST_ERROR; - } - if (H5Gget_info(file_id, &group_info) < 0) { + if (H5Gget_info(file_id, &group_info) < 0) TEST_ERROR; - } if (group_info.nlinks > 0) { HDfprintf(stderr, "links in wo file: %" PRIuHSIZE "\n", group_info.nlinks); - HDfflush(stderr); TEST_ERROR; } - if (H5Fclose(file_id) < 0) { + if (H5Fclose(file_id) < 0) TEST_ERROR; - } - file_id = H5I_INVALID_HID; - if (h5_compare_file_bytes(names.rw, names.wo) < 0) + if (h5_compare_file_bytes(names->rw, names->wo) < 0) TEST_ERROR; - /* -------------------- */ /* Teardown */ - if (H5Sclose(dspace_id) < 0) { + if (H5Sclose(dspace_id) < 0) TEST_ERROR; - } - if (H5Pclose(fapl_id) < 0) { + if (H5Pclose(fapl_id) < 0) TEST_ERROR; - } + + HDfree(names); + HDfree(buf); PASSED(); return 0; error: + HDfree(names); + HDfree(buf); 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; @@ -2413,20 +2150,20 @@ error: * * Return: Success: 0 * Failure: -1 - * - * Programmer: Jacob Smith - * 2020-03-09 * --------------------------------------------------------------------------- */ static int -test_concurrent_access(void) +test_concurrent_access(const struct mt_opts *opts) { struct file_bundle { struct mirrortest_filenames names; hid_t dset_id; hid_t fapl_id; hid_t file_id; - } bundle[CONCURRENT_COUNT]; + }; + + struct file_bundle *bundle = NULL; + hid_t dspace_id = H5I_INVALID_HID; hid_t dtype_id = H5T_NATIVE_INT; hsize_t dims[2] = {DATABUFFER_SIZE, DATABUFFER_SIZE}; @@ -2436,7 +2173,10 @@ test_concurrent_access(void) TESTING("Concurrent opened mirrored files"); - /* blank bundle */ + if (NULL == (bundle = HDmalloc(sizeof(struct file_bundle) * CONCURRENT_COUNT))) + TEST_ERROR; + + /* Initialize bundle */ for (i = 0; i < CONCURRENT_COUNT; i++) { bundle[i].dset_id = H5I_INVALID_HID; bundle[i].fapl_id = H5I_INVALID_HID; @@ -2446,25 +2186,20 @@ test_concurrent_access(void) *bundle[i].names.log = '\0'; } - /* Create FAPL for Splitter[sec2|mirror] - */ + /* Create FAPL for Splitter[sec2|mirror] */ for (i = 0; i < CONCURRENT_COUNT; i++) { - 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); - if (H5I_INVALID_HID == _fapl_id) { + char name[16] = ""; + hid_t fapl_id = H5I_INVALID_HID; + + HDsnprintf(name, 15, "concurrent%d", i); + if ((fapl_id = create_mirroring_split_fapl(name, &bundle[i].names, opts)) < 0) TEST_ERROR; - } - bundle[i].fapl_id = _fapl_id; + bundle[i].fapl_id = fapl_id; } - /* Prepare data to be written - */ - buf = (int *)HDmalloc(DATABUFFER_SIZE * DATABUFFER_SIZE * sizeof(int)); - if (NULL == buf) { + /* Prepare data to be written */ + if (NULL == (buf = HDmalloc(DATABUFFER_SIZE * DATABUFFER_SIZE * sizeof(int)))) TEST_ERROR; - } for (i = 0; i < DATABUFFER_SIZE; i++) { for (j = 0; j < DATABUFFER_SIZE; j++) { int k = i * DATABUFFER_SIZE + j; @@ -2472,76 +2207,59 @@ test_concurrent_access(void) } } - /* Prepare generic dataspace - */ - dspace_id = H5Screate_simple(2, dims, NULL); - if (H5I_INVALID_HID == dspace_id) { + /* Prepare generic dataspace */ + if ((dspace_id = H5Screate_simple(2, dims, NULL)) < 0) TEST_ERROR; - } /* -------------------- */ /* TEST: Create file and open elements */ for (i = 0; i < CONCURRENT_COUNT; i++) { - hid_t _file_id = H5I_INVALID_HID; - hid_t _dset_id = H5I_INVALID_HID; + hid_t file_id = H5I_INVALID_HID; + hid_t dset_id = H5I_INVALID_HID; - _file_id = H5Fcreate(bundle[i].names.rw, H5F_ACC_TRUNC, H5P_DEFAULT, bundle[i].fapl_id); - if (H5I_INVALID_HID == _file_id) { + if ((file_id = H5Fcreate(bundle[i].names.rw, H5F_ACC_TRUNC, H5P_DEFAULT, bundle[i].fapl_id)) < 0) TEST_ERROR; - } - bundle[i].file_id = _file_id; + bundle[i].file_id = file_id; - _dset_id = - H5Dcreate2(_file_id, "dataset", dtype_id, dspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); - if (H5I_INVALID_HID == _dset_id) { + if ((dset_id = H5Dcreate2(file_id, "dataset", dtype_id, dspace_id, H5P_DEFAULT, H5P_DEFAULT, + H5P_DEFAULT)) < 0) TEST_ERROR; - } - bundle[i].dset_id = _dset_id; + bundle[i].dset_id = dset_id; } /* -------------------- */ /* TEST: Write to files */ - for (i = 0; i < CONCURRENT_COUNT; i++) { - if (H5Dwrite(bundle[i].dset_id, dtype_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf) == FAIL) { + for (i = 0; i < CONCURRENT_COUNT; i++) + if (H5Dwrite(bundle[i].dset_id, dtype_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf) < 0) TEST_ERROR; - } - } /* -------------------- */ /* TEST: Close elements */ for (i = 0; i < CONCURRENT_COUNT; i++) { - if (H5Dclose(bundle[i].dset_id) == FAIL) { + if (H5Dclose(bundle[i].dset_id) < 0) TEST_ERROR; - } - if (H5Fclose(bundle[i].file_id) == FAIL) { + if (H5Fclose(bundle[i].file_id) < 0) TEST_ERROR; - } - if (H5Pclose(bundle[i].fapl_id) == FAIL) { + if (H5Pclose(bundle[i].fapl_id) < 0) TEST_ERROR; - } } - /* -------------------- */ - /* Standard cleanup */ - - HDfree(buf); - buf = NULL; - if (H5Sclose(dspace_id) == FAIL) { + if (H5Sclose(dspace_id) < 0) TEST_ERROR; - } /* -------------------- */ /* TEST: Verify that the R/W and W/O files are identical */ - for (i = 0; i < CONCURRENT_COUNT; i++) { - if (h5_compare_file_bytes(bundle[i].names.rw, bundle[i].names.wo) < 0) { + for (i = 0; i < CONCURRENT_COUNT; i++) + if (h5_compare_file_bytes(bundle[i].names.rw, bundle[i].names.wo) < 0) TEST_ERROR; - } - } + + HDfree(bundle); + HDfree(buf); PASSED(); return 0; @@ -2549,36 +2267,134 @@ test_concurrent_access(void) error: H5E_BEGIN_TRY { - if (buf) { - HDfree(buf); - } - (void)H5Sclose(dspace_id); + H5Sclose(dspace_id); for (i = 0; i < CONCURRENT_COUNT; i++) { - (void)H5Dclose(bundle[i].dset_id); - (void)H5Fclose(bundle[i].file_id); - (void)H5Pclose(bundle[i].fapl_id); + H5Dclose(bundle[i].dset_id); + H5Fclose(bundle[i].file_id); + H5Pclose(bundle[i].fapl_id); } } H5E_END_TRY; + HDfree(bundle); + HDfree(buf); 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 NUL 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 * - * Purpose: Run tests. + * Purpose: Run tests * * Return: Success: 0 * Failure: 1 - * - * Programmer: Jacob Smith - * 2019 * --------------------------------------------------------------------------- */ int -main(void) +main(int argc, char **argv) { - int nerrors = 0; + struct mt_opts opts; + int nerrors = 0; h5_reset(); @@ -2586,35 +2402,63 @@ main(void) HDprintf("Testing Mirror VFD functionality.\n"); - /* -------------------- */ /* SETUP */ - /* Create directories for test-generated .h5 files - */ + /* Create directories for test-generated .h5 files */ if (nerrors == 0) { - if ((HDmkdir(MIRROR_RW_DIR, (mode_t)0755) < 0) && (errno != EEXIST)) { + if ((HDmkdir(MIRROR_RW_DIR, (mode_t)0755) < 0) && (errno != EEXIST)) nerrors++; - } } if (nerrors == 0) { - if ((HDmkdir(MIRROR_WO_DIR, (mode_t)0755) < 0) && (errno != EEXIST)) { + if ((HDmkdir(MIRROR_WO_DIR, (mode_t)0755) < 0) && (errno != EEXIST)) nerrors++; - } } - /* -------------------- */ + 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 */ 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(); + H5FD_mirror_xmit_t xmit_mock; /* Re-used header in various xmit tests */ + + /* Set bogus values matching expected; encoding doesn't care + * Use sequential values to easily generate the expected buffer with a + * for loop. + */ + xmit_mock.magic = 0x00010203; + xmit_mock.version = 0x04; + xmit_mock.session_token = 0x05060708; + xmit_mock.xmit_count = 0x090A0B0C; + xmit_mock.op = 0x0D; + + nerrors += test_fapl_configuration() < 0 ? 1 : 0; + + nerrors += test_encdec_uint8_t() < 0 ? 1 : 0; + nerrors += test_encdec_uint16_t() < 0 ? 1 : 0; + nerrors += test_encdec_uint32_t() < 0 ? 1 : 0; + nerrors += test_encdec_uint64_t() < 0 ? 1 : 0; + + nerrors += test_encdec_header(xmit_mock) < 0 ? 1 : 0; + nerrors += test_encdec_set_eoa(xmit_mock) < 0 ? 1 : 0; + nerrors += test_encdec_lock(xmit_mock) < 0 ? 1 : 0; + nerrors += test_encdec_open(xmit_mock) < 0 ? 1 : 0; + nerrors += test_encdec_reply(xmit_mock) < 0 ? 1 : 0; + nerrors += test_encdec_write(xmit_mock) < 0 ? 1 : 0; + + nerrors += test_create_and_close(&opts) < 0 ? 1 : 0; + nerrors += test_basic_dataset_write(&opts) < 0 ? 1 : 0; + nerrors += test_chunked_dataset_write(&opts) < 0 ? 1 : 0; + nerrors += test_on_disk_zoo(&opts) < 0 ? 1 : 0; + nerrors += test_vanishing_datasets(&opts) < 0 ? 1 : 0; + nerrors += test_concurrent_access(&opts) < 0 ? 1 : 0; } if (nerrors) { @@ -2631,7 +2475,6 @@ main(void) int main(void) { - h5_reset(); HDprintf("Testing Mirror VFD functionality.\n"); HDprintf("SKIPPED - Mirror VFD not built.\n"); return EXIT_SUCCESS; diff --git a/test/test_mirror.sh.in b/test/test_mirror.sh.in index b3e75c6..fbc7ede 100644 --- a/test/test_mirror.sh.in +++ b/test/test_mirror.sh.in @@ -22,7 +22,10 @@ nerrors=0 SERVER_VERBOSITY="--verbosity=1" -SERVER_PORT="--port=3000" +# Choose random ephemeral port number +RANDOM_PORT=$[ $RANDOM % 16384 + 49152 ] +echo "Using port: $RANDOM_PORT" +SERVER_PORT="--port=$RANDOM_PORT" ############################################################################### @@ -45,7 +48,9 @@ done RUN_DIR=mirror_vfd_test MIRROR_UTILS=../utils/mirror_vfd # TODO: presupposes from test/ -mkdir $RUN_DIR +if [[ ! -d $RUN_DIR ]] ; then + mkdir $RUN_DIR +fi # Copy program files into dedicated test directory for FILE in $MIRROR_UTILS/mirror_* ; do @@ -61,6 +66,10 @@ cp mirror_vfd $RUN_DIR # wrapper script. Copy these libs builds if appropriate. if [ -f $MIRROR_UTILS/.libs/mirror_server ] ; then RUN_LIBS=$RUN_DIR/.libs + # Delete previous .libs directory, to remove any generated libtool files + if [[ -d $RUN_LIBS ]] ; then + rm -rf $RUN_LIBS + fi mkdir $RUN_LIBS for FILE in $MIRROR_UTILS/.libs/mirror_* ; do case "$FILE" in @@ -77,12 +86,15 @@ echo "Launching Mirror Server" SERVER_ARGS="$SERVER_PORT $SERVER_VERBOSITY" ./mirror_server $SERVER_ARGS & -./mirror_vfd +./mirror_vfd $SERVER_PORT nerrors=$? echo "Stopping Mirror Server" ./mirror_server_stop $SERVER_PORT +# Wait for background server process to exit +wait + ############################################################################### ## Report and exit ############################################################################### diff --git a/test/use_append_chunk_mirror.c b/test/use_append_chunk_mirror.c index b19c510..788cf83 100644 --- a/test/use_append_chunk_mirror.c +++ b/test/use_append_chunk_mirror.c @@ -139,7 +139,7 @@ setup_parameters(int argc, char *const argv[], options_t *opts) opts->nplanes = (hsize_t)opts->chunksize; show_parameters(opts); - return (0); + return 0; } /* setup_parameters() */ /* Overall Algorithm: @@ -152,17 +152,17 @@ setup_parameters(int argc, char *const argv[], options_t *opts) int main(int argc, char *argv[]) { - pid_t childpid = 0; - pid_t mypid, tmppid; - int child_status; - int child_wait_option = 0; - int ret_value = 0; - int child_ret_value; - hbool_t send_wait = FALSE; - hid_t fid = -1; /* File ID */ - H5FD_mirror_fapl_t mirr_fa; - H5FD_splitter_vfd_config_t split_fa; - hid_t mirr_fapl_id = H5I_INVALID_HID; + pid_t childpid = 0; + pid_t mypid, tmppid; + int child_status; + int child_wait_option = 0; + int ret_value = 0; + int child_ret_value; + hbool_t send_wait = FALSE; + hid_t fid = H5I_INVALID_HID; + H5FD_mirror_fapl_t mirr_fa; + H5FD_splitter_vfd_config_t *split_fa = NULL; + hid_t mirr_fapl_id = H5I_INVALID_HID; if (setup_parameters(argc, argv, &UC_opts) < 0) { Hgoto_error(1); @@ -173,13 +173,18 @@ main(int argc, char *argv[]) mirr_fa.handshake_port = SERVER_PORT; HDstrncpy(mirr_fa.remote_ip, SERVER_IP, H5FD_MIRROR_MAX_IP_LEN); - split_fa.wo_fapl_id = H5I_INVALID_HID; - split_fa.rw_fapl_id = H5I_INVALID_HID; - split_fa.magic = H5FD_SPLITTER_MAGIC; - split_fa.version = H5FD_CURR_SPLITTER_VFD_CONFIG_VERSION; - split_fa.log_file_path[0] = '\0'; /* none */ - split_fa.ignore_wo_errs = FALSE; - HDstrncpy(split_fa.wo_path, MIRROR_FILE_NAME, H5FD_SPLITTER_PATH_MAX); + if (NULL == (split_fa = HDcalloc(1, sizeof(H5FD_splitter_vfd_config_t)))) { + HDfprintf(stderr, "can't allocate memory for splitter config\n"); + Hgoto_error(1); + } + + split_fa->wo_fapl_id = H5I_INVALID_HID; + split_fa->rw_fapl_id = H5I_INVALID_HID; + split_fa->magic = H5FD_SPLITTER_MAGIC; + split_fa->version = H5FD_CURR_SPLITTER_VFD_CONFIG_VERSION; + split_fa->log_file_path[0] = '\0'; /* none */ + split_fa->ignore_wo_errs = FALSE; + HDstrncpy(split_fa->wo_path, MIRROR_FILE_NAME, H5FD_SPLITTER_PATH_MAX); /* Determine the need to send/wait message file*/ if (UC_opts.launch == UC_READWRITE) { @@ -211,14 +216,14 @@ main(int argc, char *argv[]) } /* Prepare parent "splitter" driver in UC_opts */ - split_fa.wo_fapl_id = mirr_fapl_id; - split_fa.rw_fapl_id = H5P_DEFAULT; - UC_opts.fapl_id = H5Pcreate(H5P_FILE_ACCESS); + split_fa->wo_fapl_id = mirr_fapl_id; + split_fa->rw_fapl_id = H5P_DEFAULT; + UC_opts.fapl_id = H5Pcreate(H5P_FILE_ACCESS); if (UC_opts.fapl_id == H5I_INVALID_HID) { HDfprintf(stderr, "can't create creation FAPL\n"); Hgoto_error(1); } - if (H5Pset_fapl_splitter(UC_opts.fapl_id, &split_fa) < 0) { + if (H5Pset_fapl_splitter(UC_opts.fapl_id, split_fa) < 0) { HDfprintf(stderr, "can't set creation FAPL\n"); H5Eprint2(H5E_DEFAULT, stdout); Hgoto_error(1); @@ -300,14 +305,14 @@ main(int argc, char *argv[]) } /* Prepare parent "splitter" driver in UC_opts */ - split_fa.wo_fapl_id = mirr_fapl_id; - split_fa.rw_fapl_id = H5P_DEFAULT; - UC_opts.fapl_id = H5Pcreate(H5P_FILE_ACCESS); + split_fa->wo_fapl_id = mirr_fapl_id; + split_fa->rw_fapl_id = H5P_DEFAULT; + UC_opts.fapl_id = H5Pcreate(H5P_FILE_ACCESS); if (UC_opts.fapl_id == H5I_INVALID_HID) { HDfprintf(stderr, "can't create creation FAPL\n"); Hgoto_error(1); } - if (H5Pset_fapl_splitter(UC_opts.fapl_id, &split_fa) < 0) { + if (H5Pset_fapl_splitter(UC_opts.fapl_id, split_fa) < 0) { HDfprintf(stderr, "can't set creation FAPL\n"); H5Eprint2(H5E_DEFAULT, stdout); Hgoto_error(1); @@ -368,6 +373,8 @@ main(int argc, char *argv[]) } done: + HDfree(split_fa); + if (ret_value != 0) { HDprintf("Error(s) encountered\n"); } @@ -375,7 +382,7 @@ done: HDprintf("All passed\n"); } - return (ret_value); + return ret_value; } #else /* H5_HAVE_MIRROR_VFD */ diff --git a/utils/mirror_vfd/CMakeLists.txt b/utils/mirror_vfd/CMakeLists.txt index 92212e0..4765e2c 100644 --- a/utils/mirror_vfd/CMakeLists.txt +++ b/utils/mirror_vfd/CMakeLists.txt @@ -12,7 +12,7 @@ set (mirror_server_SOURCES ${HDF5_UTILS_MIRRORVFD_SOURCE_DIR}/mirror_remote.h ) add_executable (mirror_server ${mirror_server_SOURCES}) -target_include_directories (mirror_server PRIVATE "${HDF5_UITLS_DIR};${HDF5_SRC_DIR};${HDF5_SRC_BINARY_DIR};$<$:${MPI_C_INCLUDE_DIRS}>") +target_include_directories (mirror_server PRIVATE "${HDF5_UTILS_DIR};${HDF5_SRC_DIR};${HDF5_SRC_BINARY_DIR};$<$:${MPI_C_INCLUDE_DIRS}>") if (NOT BUILD_SHARED_LIBS) TARGET_C_PROPERTIES (mirror_server STATIC) target_link_libraries (mirror_server PRIVATE ${HDF5_LIB_TARGET}) @@ -37,7 +37,7 @@ endif () set (mirror_server_stop_SOURCES ${HDF5_UTILS_MIRRORVFD_SOURCE_DIR}/mirror_server_stop.c) add_executable (mirror_server_stop ${mirror_server_stop_SOURCES}) -target_include_directories (mirror_server_stop PRIVATE "${HDF5_UITLS_DIR};${HDF5_SRC_DIR};${HDF5_SRC_BINARY_DIR};$<$:${MPI_C_INCLUDE_DIRS}>") +target_include_directories (mirror_server_stop PRIVATE "${HDF5_UTILS_DIR};${HDF5_SRC_DIR};${HDF5_SRC_BINARY_DIR};$<$:${MPI_C_INCLUDE_DIRS}>") if (NOT BUILD_SHARED_LIBS) TARGET_C_PROPERTIES (mirror_server_stop STATIC) target_link_libraries (mirror_server_stop PRIVATE ${HDF5_LIB_TARGET}) diff --git a/utils/mirror_vfd/mirror_server.c b/utils/mirror_vfd/mirror_server.c index ef41aa5..79c9d80 100644 --- a/utils/mirror_vfd/mirror_server.c +++ b/utils/mirror_vfd/mirror_server.c @@ -46,11 +46,8 @@ #ifdef H5_HAVE_MIRROR_VFD -#define MAXBUF 2048 /* max buffer length. */ -#define LISTENQ 80 /* max pending mirrorS requests */ -#define DEFAULT_PORT 3000 /* default listening port */ -#define MAX_PORT_LOOPS 20 /* max iteratations through port range */ -#define PORT_LOOP_RETRY_DELAY 1 /* seconds to wait between port scans */ +#define LISTENQ 80 /* max pending mirrorS requests */ +#define DEFAULT_PORT 3000 /* default listening port */ /* semi-unique "magic" numbers to sanity-check structure pointers */ #define OP_ARGS_MAGIC 0xCF074379u @@ -211,8 +208,8 @@ parse_args(int argc, char **argv, struct op_args *args_out) return -1; } - /* Loop over arguments after program name and writer_path */ - for (i = 2; i < argc; i++) { + /* Loop over arguments after program name */ + for (i = 1; i < argc; i++) { if (!HDstrncmp(argv[i], "-h", 3) || !HDstrncmp(argv[i], "--help", 7)) { mirror_log(NULL, V_INFO, "found help argument"); args_out->help = 1; @@ -474,12 +471,13 @@ wait_for_child(int H5_ATTR_UNUSED sig) static int handle_requests(struct server_run *run) { - int connfd = -1; /**/ - char mybuf[H5FD_MIRROR_XMIT_OPEN_SIZE]; /**/ - ssize_t ret; /* general-purpose error-checking */ - int pid; /* process ID of fork */ - struct sigaction sa; - int ret_value = 0; + int connfd = -1; + char *mybuf = NULL; + ssize_t ret; /* general-purpose error-checking */ + int pid; /* process ID of fork */ + struct sigaction sa; + H5FD_mirror_xmit_open_t *xopen = NULL; + int ret_value = 0; if (run == NULL || run->magic != SERVER_RUN_MAGIC) { mirror_log(NULL, V_ERR, "invalid server_run pointer"); @@ -504,6 +502,15 @@ handle_requests(struct server_run *run) return 1; } + if (NULL == (mybuf = HDmalloc(H5FD_MIRROR_XMIT_OPEN_SIZE * sizeof(char)))) { + mirror_log(NULL, V_ERR, "out of memory"); + goto error; + } + if (NULL == (xopen = HDmalloc(sizeof(H5FD_mirror_xmit_open_t)))) { + mirror_log(NULL, V_ERR, "out of memory"); + goto error; + } + /* Keep listening for attempts to connect. */ @@ -521,7 +528,7 @@ handle_requests(struct server_run *run) /* Read handshake from port connection. */ - if ((ret = HDread(connfd, &mybuf, H5FD_MIRROR_XMIT_OPEN_SIZE)) < 0) { + if ((ret = HDread(connfd, mybuf, H5FD_MIRROR_XMIT_OPEN_SIZE)) < 0) { mirror_log(run->loginfo, V_ERR, "read:%d", ret); goto error; } @@ -536,17 +543,33 @@ handle_requests(struct server_run *run) if (!HDstrncmp("SHUTDOWN", mybuf, 8)) { /* Stop operation if told to stop */ mirror_log(run->loginfo, V_INFO, "received SHUTDOWN!", ret); + + /* Confirm operation */ + if ((ret = HDwrite(connfd, "CLOSING", 8)) < 0) { + mirror_log(run->loginfo, V_ERR, "write:%d", ret); + HDclose(connfd); + connfd = -1; + goto error; + } + HDclose(connfd); connfd = -1; goto done; } /* end if explicit "SHUTDOWN" directive */ + if (!HDstrncmp("CONFIRM", mybuf, 7)) { + /* Confirm operation */ + if ((ret = HDwrite(connfd, "ALIVE", 6)) < 0) { + mirror_log(run->loginfo, V_ERR, "write:%d", ret); + goto error; + } + HDclose(connfd); + } /* end if "CONFIRM" directive */ else if (H5FD_MIRROR_XMIT_OPEN_SIZE == ret) { - H5FD_mirror_xmit_open_t xopen; mirror_log(run->loginfo, V_INFO, "probable OPEN xmit received"); - H5FD_mirror_xmit_decode_open(&xopen, (const unsigned char *)mybuf); - if (FALSE == H5FD_mirror_xmit_is_open(&xopen)) { + H5FD_mirror_xmit_decode_open(xopen, (const unsigned char *)mybuf); + if (FALSE == H5FD_mirror_xmit_is_open(xopen)) { mirror_log(run->loginfo, V_WARN, "expected OPEN xmit was malformed"); HDclose(connfd); continue; @@ -561,7 +584,7 @@ handle_requests(struct server_run *run) } /* end if fork error */ else if (pid == 0) { /* child process (writer side of fork) */ mirror_log(run->loginfo, V_INFO, "executing writer"); - if (run_writer(connfd, &xopen) < 0) { + if (run_writer(connfd, xopen) < 0) { HDprintf("can't run writer\n"); } else { @@ -591,12 +614,17 @@ done: HDclose(connfd); } + HDfree(mybuf); + HDfree(xopen); + return ret_value; error: if (connfd >= 0) { HDclose(connfd); } + HDfree(mybuf); + HDfree(xopen); return -1; } /* end handle_requests() */ diff --git a/utils/mirror_vfd/mirror_server_stop.c b/utils/mirror_vfd/mirror_server_stop.c index abc4c1e..44386bf 100644 --- a/utils/mirror_vfd/mirror_server_stop.c +++ b/utils/mirror_vfd/mirror_server_stop.c @@ -128,6 +128,7 @@ parse_args(int argc, char **argv, struct mshs_opts *opts) static int send_shutdown(struct mshs_opts *opts) { + char mybuf[16]; int live_socket; struct sockaddr_in target_addr; @@ -157,6 +158,16 @@ send_shutdown(struct mshs_opts *opts) 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("CLOSING", mybuf, 8)) { + 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; diff --git a/utils/mirror_vfd/mirror_writer.c b/utils/mirror_vfd/mirror_writer.c index a69ea73..ad7cd91 100644 --- a/utils/mirror_vfd/mirror_writer.c +++ b/utils/mirror_vfd/mirror_writer.c @@ -929,25 +929,33 @@ static int process_instructions(struct mirror_session *session) { struct sock_comm comm; - char xmit_buf[H5FD_MIRROR_XMIT_BUFFER_MAX]; /* raw bytes */ - H5FD_mirror_xmit_t xmit_recd; /* for decoded xmit header */ + char *xmit_buf = NULL; /* raw bytes */ + size_t buf_size; + H5FD_mirror_xmit_t xmit_recd; /* for decoded xmit header */ HDassert(session && (session->magic == MW_SESSION_MAGIC)); mirror_log(session->loginfo, V_INFO, "process_instructions()"); + buf_size = H5FD_MIRROR_XMIT_BUFFER_MAX * sizeof(char); + + if (NULL == (xmit_buf = HDmalloc(buf_size))) { + mirror_log(session->loginfo, V_ERR, "out of memory"); + goto error; + } + comm.magic = MW_SOCK_COMM_MAGIC; comm.recd_die = 0; /* Flag for program to terminate */ comm.xmit_recd = &xmit_recd; comm.raw = xmit_buf; - comm.raw_size = sizeof(xmit_buf); + comm.raw_size = buf_size; while (1) { /* sill-listening infinite loop */ /* Use convenience structure for raw/decoded info in/out */ if (receive_communique(session, &comm) < 0) { mirror_log(session->loginfo, V_ERR, "problem reading socket"); - return -1; + goto error; } if (comm.recd_die) { @@ -957,42 +965,42 @@ process_instructions(struct mirror_session *session) switch (xmit_recd.op) { case H5FD_MIRROR_OP_CLOSE: if (do_close(session) < 0) { - return -1; + goto error; } goto done; case H5FD_MIRROR_OP_LOCK: if (do_lock(session, (const unsigned char *)xmit_buf) < 0) { - return -1; + goto error; } break; case H5FD_MIRROR_OP_OPEN: mirror_log(session->loginfo, V_ERR, "OPEN xmit during session"); reply_error(session, "illegal OPEN xmit during session"); - return -1; + goto error; case H5FD_MIRROR_OP_SET_EOA: if (do_set_eoa(session, (const unsigned char *)xmit_buf) < 0) { - return -1; + goto error; } break; case H5FD_MIRROR_OP_TRUNCATE: if (do_truncate(session) < 0) { - return -1; + goto error; } break; case H5FD_MIRROR_OP_UNLOCK: if (do_unlock(session) < 0) { - return -1; + goto error; } break; case H5FD_MIRROR_OP_WRITE: if (do_write(session, (const unsigned char *)xmit_buf) < 0) { - return -1; + goto error; } break; default: mirror_log(session->loginfo, V_ERR, "unrecognized transmission"); reply_error(session, "unrecognized transmission"); - return -1; + goto error; } /* end switch (xmit_recd.op) */ } /* end while still listening */ @@ -1000,7 +1008,12 @@ process_instructions(struct mirror_session *session) done: comm.magic = 0; /* invalidate structure, on principle */ xmit_recd.magic = 0; /* invalidate structure, on principle */ + HDfree(xmit_buf); return 0; + +error: + HDfree(xmit_buf); + return -1; } /* end process_instructions() */ /* --------------------------------------------------------------------------- -- cgit v0.12