summaryrefslogtreecommitdiffstats
path: root/test/page_buffer.c
diff options
context:
space:
mode:
authorDavid Young <dyoung@hdfgroup.org>2019-09-17 16:26:18 (GMT)
committerDavid Young <dyoung@hdfgroup.org>2019-09-17 16:26:18 (GMT)
commit9cb455ca871751fe72c1ea8575ad6eb73fa4f915 (patch)
tree16423ffb5ef38f235203826a102bad20c326e5ca /test/page_buffer.c
parentd001d0ec27b93f9676776b385411cad8c3573979 (diff)
downloadhdf5-9cb455ca871751fe72c1ea8575ad6eb73fa4f915.zip
hdf5-9cb455ca871751fe72c1ea8575ad6eb73fa4f915.tar.gz
hdf5-9cb455ca871751fe72c1ea8575ad6eb73fa4f915.tar.bz2
Add the zygote of VFD SWMR-mode page-buffer tests.
Diffstat (limited to 'test/page_buffer.c')
-rw-r--r--test/page_buffer.c311
1 files changed, 311 insertions, 0 deletions
diff --git a/test/page_buffer.c b/test/page_buffer.c
index c537ad7..f88dcba 100644
--- a/test/page_buffer.c
+++ b/test/page_buffer.c
@@ -19,6 +19,8 @@
*
*************************************************************/
+#include <libgen.h>
+
#include "h5test.h"
#include "H5CXprivate.h" /* API Contexts */
@@ -538,6 +540,314 @@ error:
} /* test_args */
+/*
+ * Function: test_basic_meta_data_handling()
+ *
+ * Purpose: Perform a basic check that metadata is not written
+ * immediately to the HDF5 file in VFD SWMR mode.
+ *
+ * Return: 0 if test is sucessful
+ * 1 if test fails
+ *
+ * Programmer: David Young
+ * 16 Sep 2019
+ */
+
+static unsigned
+test_basic_metadata_handling(hid_t orig_fapl, const char *env_h5_drvr)
+{
+ char filename[FILENAME_LEN]; /* Filename to use */
+ hid_t file_id = -1; /* File ID */
+ hid_t fcpl = -1;
+ hid_t fapl = -1;
+ int64_t base_page_cnt;
+ int64_t page_count = 0;
+ int i, num_elements = 2000;
+ haddr_t addr = HADDR_UNDEF;
+ int *data = NULL;
+ H5F_t *f = NULL;
+ H5F_vfd_swmr_config_t *config = NULL; /* Configuration for VFD SWMR */
+ const char *dname;
+ char *tname;
+
+ TESTING("Basic Metadata Handling");
+
+ h5_fixname(FILENAME[0], orig_fapl, filename, sizeof(filename));
+
+ if ((fapl = H5Pcopy(orig_fapl)) < 0)
+ TEST_ERROR
+
+ if (set_multi_split(env_h5_drvr, fapl, sizeof(int) * 200) != 0)
+ TEST_ERROR;
+
+ if ((data = (int *)HDcalloc((size_t)num_elements, sizeof(int))) == NULL)
+ TEST_ERROR;
+
+ if ((fcpl = H5Pcreate(H5P_FILE_CREATE)) < 0)
+ TEST_ERROR;
+ if (H5Pset_file_space_strategy(fcpl, H5F_FSPACE_STRATEGY_PAGE, 0, 1) < 0)
+ TEST_ERROR;
+ if (H5Pset_file_space_page_size(fcpl, sizeof(int) * 200) < 0)
+ TEST_ERROR;
+ if (H5Pset_page_buffer_size(fapl, sizeof(int) * 2000, 0, 0) < 0)
+ TEST_ERROR;
+
+ /* Allocate memory for the configuration structure */
+ config = (H5F_vfd_swmr_config_t *)HDcalloc(1, sizeof(*config));
+ if(config == NULL) {
+ HDfprintf(stderr, "VFD SWMR config allocation failed\n");
+ return H5I_INVALID_HID;
+ }
+
+ config->version = H5F__CURR_VFD_SWMR_CONFIG_VERSION;
+ config->tick_len = 4;
+ config->max_lag = 5;
+ config->vfd_swmr_writer = true;
+ config->md_pages_reserved = 128;
+#if 0
+ config->md_open_tries = 1;
+#endif
+
+ if ((tname = strdup(filename)) == NULL) {
+ HDfprintf(stderr, "temporary string allocation failed\n");
+ return H5I_INVALID_HID;
+ }
+ dname = dirname(tname);
+ snprintf(config->md_file_path, sizeof(config->md_file_path),
+ "%s/my_md_file", dname);
+ free(tname);
+
+ /* Enable VFD SWMR configuration */
+ if(H5Pset_vfd_swmr_config(fapl, config) < 0) {
+ HDfprintf(stderr, "H5Pset_vrd_swmr_config failed\n");
+ return H5I_INVALID_HID;
+ }
+
+ if ((file_id = H5Fcreate(filename, H5F_ACC_TRUNC, fcpl, fapl)) < 0)
+ FAIL_STACK_ERROR;
+
+ /* Get a pointer to the internal file object */
+ if (NULL == (f = (H5F_t *)H5I_object(file_id)))
+ FAIL_STACK_ERROR;
+
+ /* opening the file inserts one or more pages into the page buffer.
+ * Get the number of pages inserted, and verify that it is the
+ * expected value.
+ */
+ base_page_cnt = f->shared->pb_ptr->curr_pages;
+ if (base_page_cnt != 2)
+ TEST_ERROR;
+
+ /* allocate space for a 2000 elements */
+ if (HADDR_UNDEF == (addr = H5MF_alloc(f, H5FD_MEM_DRAW, sizeof(int) * (size_t)num_elements)))
+ FAIL_STACK_ERROR;
+
+ /* initialize all the elements to have a value of -1 */
+ for(i=0 ; i<num_elements ; i++)
+ data[i] = -1;
+ if (H5F_block_write(f, H5FD_MEM_DRAW, addr, sizeof(int) * (size_t)num_elements, data) < 0)
+ FAIL_STACK_ERROR;
+
+ /* update the first 50 elements to have values 0-49 - this will be
+ a page buffer update with 1 page resulting in the page
+ buffer. */
+ /* Changes: 100 */
+ for(i=0 ; i<100 ; i++)
+ data[i] = i;
+
+ if (H5F_block_write(f, H5FD_MEM_DRAW, addr, sizeof(int) * 100, data) < 0)
+ FAIL_STACK_ERROR;
+
+ page_count ++;
+
+ if (f->shared->pb_ptr->curr_pages != page_count + base_page_cnt)
+ FAIL_STACK_ERROR;
+
+ /* update elements 300 - 450, with values 300 - - this will
+ bring two more pages into the page buffer. */
+ for(i=0 ; i<150 ; i++)
+ data[i] = i+300;
+ if (H5F_block_write(f, H5FD_MEM_DRAW, addr + (sizeof(int) * 300), sizeof(int) * 150, data) < 0)
+ FAIL_STACK_ERROR;
+ page_count += 2;
+ if (f->shared->pb_ptr->curr_pages != page_count + base_page_cnt)
+ FAIL_STACK_ERROR;
+
+ /* update elements 100 - 300, this will go to disk but also update
+ existing pages in the page buffer. */
+ for(i=0 ; i<200 ; i++)
+ data[i] = i+100;
+ if (H5F_block_write(f, H5FD_MEM_DRAW, addr + (sizeof(int) * 100), sizeof(int) * 200, data) < 0)
+ FAIL_STACK_ERROR;
+ if (f->shared->pb_ptr->curr_pages != page_count + base_page_cnt)
+ FAIL_STACK_ERROR;
+
+ /* Update elements 225-300 - this will update an existing page in the PB */
+ /* Changes: 450 - 600; 150 */
+ for(i=0 ; i<150 ; i++)
+ data[i] = i+450;
+ if (H5F_block_write(f, H5FD_MEM_DRAW, addr + (sizeof(int) * 450), sizeof(int) * 150, data) < 0)
+ FAIL_STACK_ERROR;
+ if (f->shared->pb_ptr->curr_pages != page_count + base_page_cnt)
+ FAIL_STACK_ERROR;
+
+ /* Do a full page write to block 600-800 - should bypass the PB */
+ for(i=0 ; i<200 ; i++)
+ data[i] = i+600;
+ if (H5F_block_write(f, H5FD_MEM_DRAW, addr + (sizeof(int) * 600), sizeof(int) * 200, data) < 0)
+ FAIL_STACK_ERROR;
+ if (f->shared->pb_ptr->curr_pages != page_count + base_page_cnt)
+ FAIL_STACK_ERROR;
+
+ /* read elements 800 - 1200, this should not affect the PB, and should read -1s */
+ if (H5F_block_read(f, H5FD_MEM_DRAW, addr + (sizeof(int) * 800), sizeof(int) * 400, data) < 0)
+ FAIL_STACK_ERROR;
+ for (i=0; i < 400; i++) {
+ if (data[i] != -1) {
+ HDfprintf(stderr, "Read different values than written\n");
+ HDfprintf(stderr, "data[%d] = %d, %d expected.\n", i, data[i], -1);
+ FAIL_STACK_ERROR;
+ }
+ }
+ if (f->shared->pb_ptr->curr_pages != page_count + base_page_cnt)
+ FAIL_STACK_ERROR;
+
+ /* read elements 1200 - 1201, this should read -1 and bring in an
+ * entire page of addr 1200
+ */
+ if (H5F_block_read(f, H5FD_MEM_DRAW, addr + (sizeof(int) * 1200), sizeof(int) * 1, data) < 0)
+ FAIL_STACK_ERROR;
+ for (i=0; i < 1; i++) {
+ if (data[i] != -1) {
+ HDfprintf(stderr, "Read different values than written\n");
+ HDfprintf(stderr, "data[%d] = %d, %d expected.\n", i, data[i], -1);
+ TEST_ERROR;
+ }
+ }
+ page_count ++;
+ if (f->shared->pb_ptr->curr_pages != page_count + base_page_cnt)
+ TEST_ERROR;
+
+ /* read elements 175 - 225, this should use the PB existing pages */
+ /* Changes: 350 - 450 */
+ /* read elements 175 - 225, this should use the PB existing pages */
+ if (H5F_block_read(f, H5FD_MEM_DRAW, addr + (sizeof(int) * 350), sizeof(int) * 100, data) < 0)
+ FAIL_STACK_ERROR;
+ for (i=0; i < 100; i++) {
+ if (data[i] != i + 350) {
+ HDfprintf(stderr, "Read different values than written\n");
+ HDfprintf(stderr, "data[%d] = %d, %d expected.\n", i, data[i],
+ i + 350);
+ TEST_ERROR;
+ }
+ }
+ if (f->shared->pb_ptr->curr_pages != page_count + base_page_cnt)
+ TEST_ERROR;
+
+ /* read elements 0 - 800 using the VFD.. this should result in -1s
+ except for the writes that went through the PB (100-300 & 600-800) */
+ if (H5FD_read(f->shared->lf, H5FD_MEM_DRAW, addr, sizeof(int) * 800, data) < 0)
+ FAIL_STACK_ERROR;
+ i = 0;
+ while (i < 800) {
+ if((i>=100 && i<300) || i >= 600) {
+ if (data[i] != i) {
+ HDfprintf(stderr, "Read different values than written\n");
+ HDfprintf(stderr, "data[%d] = %d, %d expected.\n",
+ i, data[i], i);
+ TEST_ERROR;
+ }
+ }
+ else {
+ if (data[i] != -1) {
+ HDfprintf(stderr, "Read different values than written\n");
+ HDfprintf(stderr, "data[%d] = %d, %d expected.\n",
+ i, data[i], -1);
+ TEST_ERROR;
+ }
+ }
+ i++;
+ }
+
+ /* read elements 0 - 800 using the PB.. this should result in all
+ * what we have written so far and should get the updates from the PB
+ */
+ if (H5F_block_read(f, H5FD_MEM_DRAW, addr, sizeof(int) * 800, data) < 0)
+ FAIL_STACK_ERROR;
+ if (f->shared->pb_ptr->curr_pages != page_count + base_page_cnt)
+ TEST_ERROR;
+ for (i=0; i < 800; i++) {
+ if (data[i] != i) {
+ HDfprintf(stderr, "Read different values than written\n");
+ HDfprintf(stderr, "data[%d] = %d, %d expected.\n",
+ i, data[i], i);
+ TEST_ERROR;
+ }
+ }
+
+ /* update elements 400 - 1400 to value 0, this will go to disk but
+ * also evict existing pages from the PB (page 400 & 1200 that are
+ * existing).
+ */
+ for(i=0 ; i<1000 ; i++)
+ data[i] = 0;
+ if (H5F_block_write(f, H5FD_MEM_DRAW, addr + (sizeof(int) * 400), sizeof(int) * 1000, data) < 0)
+ FAIL_STACK_ERROR;
+ page_count -= 2;
+ if (f->shared->pb_ptr->curr_pages != page_count + base_page_cnt)
+ TEST_ERROR;
+
+ /* read elements 0 - 1000.. this should go to disk then update the
+ * buffer result 200-400 with existing pages
+ */
+ if (H5F_block_read(f, H5FD_MEM_DRAW, addr, sizeof(int) * 1000, data) < 0)
+ FAIL_STACK_ERROR;
+ i=0;
+ while (i < 1000) {
+ if(i<400) {
+ if (data[i] != i) {
+ HDfprintf(stderr, "Read different values than written\n");
+ HDfprintf(stderr, "data[%d] = %d, %d expected.\n",
+ i, data[i], i);
+ TEST_ERROR;
+ }
+ }
+ else {
+ if (data[i] != 0) {
+ HDfprintf(stderr, "Read different values than written\n");
+ HDfprintf(stderr, "data[%d] = %d, %d expected.\n",
+ i, data[i], 0);
+ TEST_ERROR;
+ }
+ }
+ i++;
+ }
+ if (f->shared->pb_ptr->curr_pages != page_count + base_page_cnt)
+ TEST_ERROR;
+
+ if (H5Fclose(file_id) < 0)
+ FAIL_STACK_ERROR;
+ if (H5Pclose(fcpl) < 0)
+ FAIL_STACK_ERROR;
+ if (H5Pclose(fapl) < 0)
+ FAIL_STACK_ERROR;
+ HDfree(data);
+
+ PASSED()
+ return 0;
+
+error:
+ H5E_BEGIN_TRY {
+ H5Pclose(fapl);
+ H5Pclose(fcpl);
+ H5Fclose(file_id);
+ if (data)
+ HDfree(data);
+ } H5E_END_TRY;
+ return 1;
+}
+
+
/*-------------------------------------------------------------------------
* Function: test_raw_data_handling()
*
@@ -2393,6 +2703,7 @@ main(void)
nerrors += test_args(fapl, env_h5_drvr);
nerrors += test_raw_data_handling(fapl, env_h5_drvr);
+ nerrors += test_basic_metadata_handling(fapl, env_h5_drvr);
nerrors += test_lru_processing(fapl, env_h5_drvr);
nerrors += test_min_threshold(fapl, env_h5_drvr);
nerrors += test_stats_collection(fapl, env_h5_drvr);