summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2006-12-18 17:52:43 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2006-12-18 17:52:43 (GMT)
commitddbc06fce64bc49ff6b3e83da3ff74d08251fc2c (patch)
tree2fd1ab62b539b7c05a2adf461006e1c07d6f3535 /test
parent9236c9a148aaf206294be0554cf78e7ab769bd51 (diff)
downloadhdf5-ddbc06fce64bc49ff6b3e83da3ff74d08251fc2c.zip
hdf5-ddbc06fce64bc49ff6b3e83da3ff74d08251fc2c.tar.gz
hdf5-ddbc06fce64bc49ff6b3e83da3ff74d08251fc2c.tar.bz2
[svn-r13067] Description:
Add [quite] limited ability to update (ie. write) data for objects in fractal heap. Limited to just updating objects in managed heap blocks (i.e. not 'tiny' or 'huge' objects) and must be updated with data of the same length as the object in the heap. Updating objects in compressed heaps does work though [as long as the data isn't 'tiny' or 'huge']. Needed for changing the data value or the name of an attribute that is stored in dense or shared storage. Tested on: Linux/32 2.6 (chicago) Linux/64 2.6 (chicago2)
Diffstat (limited to 'test')
-rw-r--r--test/fheap.c229
1 files changed, 229 insertions, 0 deletions
diff --git a/test/fheap.c b/test/fheap.c
index 6daa7c0..c8087fa 100644
--- a/test/fheap.c
+++ b/test/fheap.c
@@ -14090,6 +14090,7 @@ error:
#endif /* QAK */
#endif /* QAK2 */
+#ifndef QAK
/*-------------------------------------------------------------------------
* Function: test_filtered_man_root_direct
@@ -14564,6 +14565,7 @@ error:
} H5E_END_TRY;
return(1);
} /* test_filtered_man_root_indirect() */
+#endif /* QAK */
#ifndef QAK
@@ -14989,6 +14991,213 @@ error:
/*-------------------------------------------------------------------------
+ * Function: test_write
+ *
+ * Purpose: Test inserting objects, then changing the value for them.
+ *
+ * Return: Success: 0
+ * Failure: 1
+ *
+ * Programmer: Quincey Koziol
+ * Monday, December 18, 2006
+ *
+ *-------------------------------------------------------------------------
+ */
+static int
+test_write(hid_t fapl, H5HF_create_t *cparam, fheap_test_param_t *tparam)
+{
+ hid_t file = -1; /* File ID */
+ hid_t dxpl = H5P_DATASET_XFER_DEFAULT; /* DXPL to use */
+ char filename[FHEAP_FILENAME_LEN]; /* Filename to use */
+ H5F_t *f = NULL; /* Internal file object pointer */
+ H5HF_t *fh = NULL; /* Fractal heap wrapper */
+ haddr_t fh_addr; /* Address of fractal heap */
+ H5HF_create_t tmp_cparam; /* Local heap creation parameters */
+ size_t id_len; /* Size of fractal heap IDs */
+ unsigned char tiny_heap_id[HEAP_ID_LEN]; /* Heap ID for 'tiny' object */
+ unsigned char huge_heap_id[HEAP_ID_LEN]; /* Heap ID for 'huge' object */
+ hbool_t id_changed = FALSE; /* Whether the heap ID changed */
+ unsigned char *rewrite_obj; /* Pointer to re-write buffer for objects */
+ fheap_heap_ids_t keep_ids; /* Structure to retain heap IDs */
+ h5_stat_size_t empty_size; /* Size of a file with an empty heap */
+ size_t obj_size; /* Size of object */
+ size_t obj_loc; /* Location of object in buffer */
+ fheap_heap_state_t state; /* State of fractal heap */
+ unsigned u; /* Local index variable */
+ herr_t ret; /* Generic return value */
+
+ /*
+ * Display testing message
+ */
+ if(tparam->comp == FHEAP_TEST_COMPRESS)
+ TESTING("writing objects in heap with compressed blocks")
+ else
+ TESTING("writing objects in heap")
+
+ /* Copy heap creation properties */
+ HDmemcpy(&tmp_cparam, cparam, sizeof(H5HF_create_t));
+
+ /* Check if we are compressing the blocks */
+ if(tparam->comp == FHEAP_TEST_COMPRESS) {
+ unsigned deflate_level; /* Deflation level */
+
+ /* Set an I/O filter for heap data */
+ deflate_level = 6;
+ if(H5Z_append(&tmp_cparam.pline, H5Z_FILTER_DEFLATE, H5Z_FLAG_OPTIONAL, (size_t)1, &deflate_level) < 0)
+ FAIL_STACK_ERROR
+ } /* end if */
+
+ /* Perform common file & heap open operations */
+ if(open_heap(filename, fapl, dxpl, &tmp_cparam, tparam, &file, &f, &fh, &fh_addr, &state, &empty_size) < 0)
+ TEST_ERROR
+
+ /* Get information about heap ID lengths */
+ if(H5HF_get_id_len(fh, &id_len) < 0)
+ FAIL_STACK_ERROR
+ if(id_len > MAX_HEAP_ID_LEN)
+ TEST_ERROR
+
+ /* Initialize the heap ID structure */
+ HDmemset(&keep_ids, 0, sizeof(fheap_heap_ids_t));
+
+
+ /* Create 'tiny' and 'huge' objects */
+ obj_size = id_len / 2;
+ if(H5HF_insert(fh, dxpl, obj_size, shared_wobj_g, tiny_heap_id) < 0)
+ FAIL_STACK_ERROR
+
+ obj_size = tmp_cparam.max_man_size + 1;
+ if(H5HF_insert(fh, dxpl, obj_size, shared_wobj_g, huge_heap_id) < 0)
+ FAIL_STACK_ERROR
+
+ /* Verify that writing to 'tiny' and 'huge' objects return failure (for now) */
+ H5E_BEGIN_TRY {
+ ret = H5HF_write(fh, dxpl, tiny_heap_id, &id_changed, shared_wobj_g);
+ } H5E_END_TRY;
+ HDassert(!id_changed);
+ if(ret >= 0)
+ TEST_ERROR
+
+ H5E_BEGIN_TRY {
+ ret = H5HF_write(fh, dxpl, huge_heap_id, &id_changed, shared_wobj_g);
+ } H5E_END_TRY;
+ HDassert(!id_changed);
+ if(ret >= 0)
+ TEST_ERROR
+
+ /* Initialize data to overwrite with */
+ rewrite_obj = H5MM_malloc(shared_obj_size_g);
+ for(u = 0; u < shared_obj_size_g; u++)
+ rewrite_obj[u] = shared_wobj_g[u] * 2;
+
+ /* Insert different sized objects, but stay out of "tiny" and "huge" zones */
+ obj_size = 20;
+ for(u = 0; u < 40; u++) {
+ obj_loc = u;
+ if(add_obj(fh, dxpl, obj_loc, obj_size, NULL, &keep_ids))
+ TEST_ERROR
+
+ /* Check for closing & re-opening the heap */
+ if(reopen_heap(f, dxpl, &fh, fh_addr, tparam) < 0)
+ TEST_ERROR
+
+ /* Overwrite data just written */
+ if(H5HF_write(fh, dxpl, &keep_ids.ids[id_len * u], &id_changed, rewrite_obj) < 0)
+ FAIL_STACK_ERROR
+ HDassert(!id_changed);
+
+ /* Read data back in */
+ if(H5HF_read(fh, dxpl, &keep_ids.ids[id_len * u], shared_robj_g) < 0)
+ FAIL_STACK_ERROR
+
+ /* Compare data read in */
+ if(HDmemcmp(rewrite_obj, shared_robj_g, obj_size))
+ TEST_ERROR
+
+ /* Change size of data to write */
+ if(u < 20)
+ obj_size *= 1.3;
+ else
+ obj_size /= 1.3;
+ } /* end for */
+
+ /* Close the fractal heap */
+ if(H5HF_close(fh, dxpl) < 0)
+ FAIL_STACK_ERROR
+ fh = NULL;
+
+ /* Close the file */
+ if(H5Fclose(file) < 0)
+ FAIL_STACK_ERROR
+
+
+ /* Re-open the file */
+ if((file = H5Fopen(filename, H5F_ACC_RDONLY, fapl)) < 0)
+ FAIL_STACK_ERROR
+
+ /* Get a pointer to the internal file object */
+ if(NULL == (f = H5I_object(file)))
+ FAIL_STACK_ERROR
+
+ /* Re-open the heap */
+ if(NULL == (fh = H5HF_open(f, H5P_DATASET_XFER_DEFAULT, fh_addr)))
+ FAIL_STACK_ERROR
+
+ /* Verify changed objects */
+ obj_size = 20;
+ for(u = 0; u < 40; u++) {
+ /* Read data back in */
+ if(H5HF_read(fh, dxpl, &keep_ids.ids[id_len * u], shared_robj_g) < 0)
+ FAIL_STACK_ERROR
+
+ /* Compare data read in */
+ if(HDmemcmp(rewrite_obj, shared_robj_g, obj_size))
+ TEST_ERROR
+
+ /* Change size of data to write */
+ if(u < 20)
+ obj_size *= 1.3;
+ else
+ obj_size /= 1.3;
+ } /* end for */
+
+ /* Close the fractal heap */
+ if(H5HF_close(fh, dxpl) < 0)
+ FAIL_STACK_ERROR
+ fh = NULL;
+
+ /* Close the file */
+ if(H5Fclose(file) < 0)
+ FAIL_STACK_ERROR
+
+
+ /* Free resources */
+ H5MM_xfree(keep_ids.ids);
+ H5MM_xfree(keep_ids.lens);
+ H5MM_xfree(keep_ids.offs);
+ H5MM_xfree(rewrite_obj);
+
+ /* All tests passed */
+ PASSED()
+
+ return(0);
+
+error:
+ H5E_BEGIN_TRY {
+ H5MM_xfree(keep_ids.ids);
+ H5MM_xfree(keep_ids.lens);
+ H5MM_xfree(keep_ids.offs);
+ H5MM_xfree(rewrite_obj);
+ if(fh)
+ H5HF_close(fh, dxpl);
+ H5Fclose(file);
+ } H5E_END_TRY;
+ return(1);
+} /* test_write() */
+
+#ifndef QAK
+
+/*-------------------------------------------------------------------------
* Function: test_bug1
*
* Purpose: Test inserting several objects, then deleting one and
@@ -15154,6 +15363,7 @@ error:
} H5E_END_TRY;
return(1);
} /* test_bug1() */
+#endif /* QAK */
/*-------------------------------------------------------------------------
@@ -15529,6 +15739,7 @@ HDfprintf(stderr, "Uncomment tests!\n");
/* Test I/O filter support */
+#ifndef QAK
/* Try several different methods of deleting objects */
{
fheap_test_del_dir_t del_dir; /* Deletion direction */
@@ -15550,6 +15761,9 @@ HDfprintf(stderr, "Uncomment tests!\n");
tparam.comp = FHEAP_TEST_NO_COMPRESS;
} /* end for */
} /* end block */
+#else /* QAK */
+HDfprintf(stderr, "Uncomment tests!\n");
+#endif /* QAK */
#ifndef QAK
/* Random object insertion & deletion */
@@ -15598,12 +15812,27 @@ HDfprintf(stderr, "Uncomment tests!\n");
HDfprintf(stderr, "Uncomment tests!\n");
#endif /* QAK */
+ /* Test object writing support */
+
+ /* Basic object writing */
+ nerrors += test_write(fapl, &small_cparam, &tparam);
+
+ /* Writing objects in heap with filters */
+ tparam.comp = FHEAP_TEST_COMPRESS;
+ nerrors += test_write(fapl, &small_cparam, &tparam);
+
+ /* Reset block compression */
+ tparam.comp = FHEAP_TEST_NO_COMPRESS;
#ifndef QAK
} /* end for */
#endif /* QAK */
/* Tests that address specific bugs */
+#ifndef QAK
nerrors += test_bug1(fapl, &small_cparam, &tparam);
+#else /* QAK */
+HDfprintf(stderr, "Uncomment tests!\n");
+#endif /* QAK */
if(nerrors)
goto error;