summaryrefslogtreecommitdiffstats
path: root/test/fillval.c
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2007-07-03 19:20:02 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2007-07-03 19:20:02 (GMT)
commit2bc42b17fb28008ca45c3e29ff0f7bdac631c069 (patch)
tree8e31ad85d28d954074cc62c28ba244a1b5fcfd53 /test/fillval.c
parent4af566ef23bc4f5fdbdf2314b4db3daddc2b44da (diff)
downloadhdf5-2bc42b17fb28008ca45c3e29ff0f7bdac631c069.zip
hdf5-2bc42b17fb28008ca45c3e29ff0f7bdac631c069.tar.gz
hdf5-2bc42b17fb28008ca45c3e29ff0f7bdac631c069.tar.bz2
[svn-r13937] Description:
A few more cleanups for testing [atomic] fill values and extending datasets Tested on: Mac OS X/32 10.4.10 (amazon) Linux/32 2.6 (chicago) Linux/64 2.6 (chicago2)
Diffstat (limited to 'test/fillval.c')
-rw-r--r--test/fillval.c96
1 files changed, 58 insertions, 38 deletions
diff --git a/test/fillval.c b/test/fillval.c
index 7ff57c0..afe6930 100644
--- a/test/fillval.c
+++ b/test/fillval.c
@@ -1177,10 +1177,12 @@ test_rdwr(hid_t fapl, const char *base_name, H5D_layout_t layout)
*-------------------------------------------------------------------------
*/
static int
-test_extend_cases(hid_t file, hid_t dcpl, hsize_t *cur_size, hsize_t *max_size,
- int *fillval)
+test_extend_cases(hid_t file, hid_t _dcpl, const char *dset_name,
+ hsize_t *start_size, hsize_t *max_size, hid_t dtype, int *fillval)
{
- hid_t fspace = -1, mspace = -1, dset = -1;
+ hid_t fspace = -1, mspace = -1; /* File & memory dataspaces */
+ hid_t dset = -1; /* Dataset ID */
+ hid_t dcpl = -1; /* Dataset creation property list */
hsize_t one[5] = {1, 1, 1, 1, 1};
hsize_t hs_size[5], hs_stride[5];
hsize_t hs_offset[5], nelmts;
@@ -1188,20 +1190,34 @@ test_extend_cases(hid_t file, hid_t dcpl, hsize_t *cur_size, hsize_t *max_size,
int i, j, *buf = NULL, odd;
unsigned u;
+ /* Make copy of dataset creation property list */
+ if((dcpl = H5Pcopy(_dcpl)) < 0) TEST_ERROR
+
+#ifndef NO_FILLING
+ if(H5Pset_fill_value(dcpl, dtype, fillval) < 0) TEST_ERROR
+#endif
+
/* Create a dataspace */
- if((fspace = H5Screate_simple(5, cur_size, max_size))<0) TEST_ERROR
+ if((fspace = H5Screate_simple(5, start_size, max_size)) < 0) TEST_ERROR
+
+ /* Create dataset */
+ if((dset = H5Dcreate(file, dset_name, dtype, fspace, dcpl)) < 0) TEST_ERROR
- /* Create a file and dataset */
- if((dset = H5Dcreate(file, "dset", H5T_NATIVE_INT, fspace, dcpl)) < 0) TEST_ERROR
/* Read some data and make sure it's the fill value */
if((mspace = H5Screate_simple(5, one, NULL)) < 0) TEST_ERROR
for(i = 0; i < 1000; i++) {
+ /* Set offset for random element */
for(j = 0; j < 5; j++)
- hs_offset[j] = rand() % cur_size[j];
+ hs_offset[j] = rand() % start_size[j];
+ /* Select the random element */
if(H5Sselect_hyperslab(fspace, H5S_SELECT_SET, hs_offset, NULL, one, NULL) < 0) TEST_ERROR
- if(H5Dread(dset, H5T_NATIVE_INT, mspace, fspace, H5P_DEFAULT, &val_rd) < 0) TEST_ERROR
+
+ /* Read the random element */
+ if(H5Dread(dset, dtype, mspace, fspace, H5P_DEFAULT, &val_rd) < 0) TEST_ERROR
+
+ /* Verify the element read in */
if(val_rd != *fillval) {
H5_FAILED();
HDfprintf(stdout, "%u: Value read was not a fill value.\n", (unsigned)__LINE__);
@@ -1215,18 +1231,16 @@ test_extend_cases(hid_t file, hid_t dcpl, hsize_t *cur_size, hsize_t *max_size,
} /* end for */
if(H5Sclose(mspace) < 0) TEST_ERROR
+
/* Initialize dataspace & hyperslab info */
for(i = 0, nelmts = 1; i < 5; i++) {
- hs_size[i] = cur_size[i] / 2;
+ hs_size[i] = start_size[i] / 2;
hs_offset[i] = 0;
hs_stride[i] = 2;
nelmts *= hs_size[i];
} /* end for */
- /* Create dataspace describing memory buffer */
- if((mspace = H5Screate_simple(5, hs_size, hs_size)) < 0) TEST_ERROR
-
- /*check for overflow*/
+ /* Check for overflow */
assert((nelmts * sizeof(int)) == (hsize_t)((size_t)(nelmts * sizeof(int))));
/* Allocate & initialize buffer */
@@ -1234,11 +1248,14 @@ test_extend_cases(hid_t file, hid_t dcpl, hsize_t *cur_size, hsize_t *max_size,
for(u = 0; u < nelmts; u++)
buf[u] = 9999;
+ /* Create dataspace describing memory buffer */
+ if((mspace = H5Screate_simple(5, hs_size, hs_size)) < 0) TEST_ERROR
+
/* Select elements within file dataspace */
if(H5Sselect_hyperslab(fspace, H5S_SELECT_SET, hs_offset, hs_stride, hs_size, NULL) < 0) TEST_ERROR
/* Write to all odd data locations */
- if(H5Dwrite(dset, H5T_NATIVE_INT, mspace, fspace, H5P_DEFAULT, buf) < 0) TEST_ERROR
+ if(H5Dwrite(dset, dtype, mspace, fspace, H5P_DEFAULT, buf) < 0) TEST_ERROR
/* Close memory dataspace */
if(H5Sclose(mspace) < 0) TEST_ERROR
@@ -1247,12 +1264,13 @@ test_extend_cases(hid_t file, hid_t dcpl, hsize_t *cur_size, hsize_t *max_size,
HDfree(buf);
buf = NULL;
+
/* Read some data and make sure it's the right value */
if((mspace = H5Screate_simple(5, one, NULL)) < 0) TEST_ERROR
for(i = 0; i < 1000; i++) {
/* Set offset for random element */
for(j = 0, odd = 0; j < 5; j++) {
- hs_offset[j] = rand() % cur_size[j];
+ hs_offset[j] = rand() % start_size[j];
odd += (int)(hs_offset[j]%2);
} /* end for */
@@ -1260,7 +1278,7 @@ test_extend_cases(hid_t file, hid_t dcpl, hsize_t *cur_size, hsize_t *max_size,
if(H5Sselect_hyperslab(fspace, H5S_SELECT_SET, hs_offset, NULL, one, NULL) < 0) TEST_ERROR
/* Read the random element */
- if(H5Dread(dset, H5T_NATIVE_INT, mspace, fspace, H5P_DEFAULT, &val_rd) < 0) TEST_ERROR
+ if(H5Dread(dset, dtype, mspace, fspace, H5P_DEFAULT, &val_rd) < 0) TEST_ERROR
/* Verify the element read in */
should_be = odd ? *fillval : 9999;
@@ -1277,8 +1295,9 @@ test_extend_cases(hid_t file, hid_t dcpl, hsize_t *cur_size, hsize_t *max_size,
} /* end for */
if(H5Sclose(mspace) < 0) TEST_ERROR
+
/* Extend the dataset */
- if (H5Dextend(dset, max_size) < 0) TEST_ERROR
+ if(H5Dextend(dset, max_size) < 0) TEST_ERROR
/* Re-open file dataspace */
if(H5Sclose(fspace) < 0) TEST_ERROR
@@ -1290,7 +1309,7 @@ test_extend_cases(hid_t file, hid_t dcpl, hsize_t *cur_size, hsize_t *max_size,
/* Set offset for random element */
for(j = 0, odd = 0; j < 5; j++) {
hs_offset[j] = rand() % max_size[j];
- if((hsize_t)hs_offset[j] >= cur_size[j])
+ if((hsize_t)hs_offset[j] >= start_size[j])
odd = 1;
else
odd += (int)(hs_offset[j]%2);
@@ -1300,7 +1319,7 @@ test_extend_cases(hid_t file, hid_t dcpl, hsize_t *cur_size, hsize_t *max_size,
if(H5Sselect_hyperslab(fspace, H5S_SELECT_SET, hs_offset, NULL, one, NULL) < 0) TEST_ERROR
/* Read the random element */
- if(H5Dread(dset, H5T_NATIVE_INT, mspace, fspace, H5P_DEFAULT, &val_rd) < 0) TEST_ERROR
+ if(H5Dread(dset, dtype, mspace, fspace, H5P_DEFAULT, &val_rd) < 0) TEST_ERROR
/* Verify the element read in */
should_be = odd ? *fillval : 9999;
@@ -1318,13 +1337,17 @@ test_extend_cases(hid_t file, hid_t dcpl, hsize_t *cur_size, hsize_t *max_size,
if(H5Sclose(mspace) < 0) TEST_ERROR
/* Cleanup */
+ if(H5Pclose(dcpl) < 0) TEST_ERROR
if(H5Dclose(dset) < 0) TEST_ERROR
if(H5Sclose(fspace) < 0) TEST_ERROR
return 0;
error:
+ if(buf)
+ HDfree(buf);
H5E_BEGIN_TRY {
+ H5Pclose(dcpl);
H5Dclose(dset);
H5Sclose(fspace);
H5Sclose(mspace);
@@ -1354,7 +1377,7 @@ static int
test_extend(hid_t fapl, const char *base_name, H5D_layout_t layout)
{
hid_t file = -1, dcpl = -1;
- hsize_t cur_size[5] = {32, 16, 8, 4, 2};
+ hsize_t start_size[5] = {32, 16, 8, 4, 2};
hsize_t max_size[5] = {128, 64, 32, 16, 8};
hsize_t ch_size[5] = {1, 16, 8, 4, 2};
#ifdef NO_FILLING
@@ -1375,10 +1398,6 @@ test_extend(hid_t fapl, const char *base_name, H5D_layout_t layout)
if(H5D_CHUNKED == layout)
if(H5Pset_chunk(dcpl, 5, ch_size) < 0) TEST_ERROR
-#ifndef NO_FILLING
- if (H5Pset_fill_value(dcpl, H5T_NATIVE_INT, &fillval)<0) goto error;
-#endif
-
#if 1
/*
* Remove this once contiguous datasets can support extensions in other
@@ -1391,13 +1410,13 @@ test_extend(hid_t fapl, const char *base_name, H5D_layout_t layout)
* below.
*/
if (H5D_CONTIGUOUS==layout) {
- max_size[0] = (max_size[0]*max_size[1]*max_size[2]*
- max_size[3]*max_size[4]) /
- (cur_size[1]*cur_size[2]*cur_size[3]*cur_size[4]);
- max_size[1] = cur_size[1];
- max_size[2] = cur_size[2];
- max_size[3] = cur_size[3];
- max_size[4] = cur_size[4];
+ max_size[0] = (max_size[0] * max_size[1] * max_size[2] *
+ max_size[3] * max_size[4]) /
+ (start_size[1] * start_size[2] * start_size[3] * start_size[4]);
+ max_size[1] = start_size[1];
+ max_size[2] = start_size[2];
+ max_size[3] = start_size[3];
+ max_size[4] = start_size[4];
}
#endif
@@ -1436,28 +1455,28 @@ test_extend(hid_t fapl, const char *base_name, H5D_layout_t layout)
/* Create a file and dataset */
h5_fixname(base_name, fapl, filename, sizeof filename);
- if ((file=H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl))<0)
- goto error;
+ if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR
/* Test integer datatype case */
- if(test_extend_cases(file, dcpl, cur_size, max_size, &fillval) < 0) TEST_ERROR
+ if(test_extend_cases(file, dcpl, "dset", start_size, max_size,
+ H5T_NATIVE_INT, &fillval) < 0) TEST_ERROR
/* Cleanup */
- if(H5Pclose(dcpl) < 0) goto error;
- if(H5Fclose(file) < 0) goto error;
+ if(H5Pclose(dcpl) < 0) TEST_ERROR
+ if(H5Fclose(file) < 0) TEST_ERROR
PASSED();
return 0;
- error:
+error:
H5E_BEGIN_TRY {
H5Pclose(dcpl);
H5Fclose(file);
} H5E_END_TRY;
return 1;
- skip:
+skip:
H5E_BEGIN_TRY {
H5Pclose(dcpl);
H5Fclose(file);
@@ -1465,6 +1484,7 @@ test_extend(hid_t fapl, const char *base_name, H5D_layout_t layout)
return 0;
} /* end test_extend() */
+
/*-------------------------------------------------------------------------
* Function: test_compatible
*