diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/dsets.c | 135 | ||||
-rw-r--r-- | test/fillval.c | 411 | ||||
-rw-r--r-- | test/tmisc.c | 47 |
3 files changed, 398 insertions, 195 deletions
diff --git a/test/dsets.c b/test/dsets.c index 890aa2f..73f9392 100644 --- a/test/dsets.c +++ b/test/dsets.c @@ -12,12 +12,15 @@ const char *FILENAME[] = { "dataset", + "compact_dataset", NULL }; #define DSET_DEFAULT_NAME "default" #define DSET_CHUNKED_NAME "chunked" +#define DSET_COMPACT_NAME "compact" #define DSET_SIMPLE_IO_NAME "simple_io" +#define DSET_COMPACT_IO_NAME "compact_io" #define DSET_TCONV_NAME "tconv" #define DSET_COMPRESS_NAME "compressed" #define DSET_BOGUS_NAME "bogus" @@ -41,14 +44,17 @@ int points[100][200], check[100][200]; * Tuesday, December 9, 1997 * * Modifications: + * Added test for compact dataset creation. + * Raymond Lu + * August 8, 2002 * *------------------------------------------------------------------------- */ static herr_t test_create(hid_t file) { - hid_t dataset, space, create_parms; - hsize_t dims[2]; + hid_t dataset, space, small_space, create_parms; + hsize_t dims[2], small_dims[2]; herr_t status; hsize_t csize[2]; @@ -60,6 +66,12 @@ test_create(hid_t file) space = H5Screate_simple(2, dims, NULL); assert(space>=0); + /* Create a small data space for compact dataset */ + small_dims[0] = 16; + small_dims[1] = 8; + small_space = H5Screate_simple(2, small_dims, NULL); + assert(space>=0); + /* * Create a dataset using the default dataset creation properties. We're * not sure what they are, so we won't check. @@ -148,6 +160,22 @@ test_create(hid_t file) */ if (H5Dclose(dataset) < 0) goto error; + /* + * Create a compact dataset, then close it. + */ + create_parms = H5Pcreate(H5P_DATASET_CREATE); + assert(create_parms >= 0); + status = H5Pset_layout(create_parms, H5D_COMPACT); + assert(status >= 0); + status = H5Pset_space_time(create_parms, H5D_SPACE_ALLOC_EARLY); + assert(status >= 0); + + dataset = H5Dcreate(file, DSET_COMPACT_NAME, H5T_NATIVE_DOUBLE, + small_space, create_parms); + if(dataset < 0) goto error; + H5Pclose(create_parms); + if(H5Dclose(dataset) <0) goto error; + PASSED(); return 0; @@ -235,6 +263,108 @@ test_simple_io(hid_t file) error: return -1; } + + +/*------------------------------------------------------------------------- + * Function: test_compact_io + * + * Purpose: Tests compact dataset I/O. That is, reading and writing a + * complete multi-dimensional array without data type or data + * space conversions, without compression, and store in + * compact dataset. + * + * Return: Success: 0 + * + * Failure: -1 + * + * Programmer: Raymond Lu + * August 8, 2002 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +static herr_t +test_compact_io(void) +{ + hid_t file, dataset, space, plist; + hsize_t dims[2]; + herr_t status; + int wbuf[16][8], rbuf[16][8]; + int i, j, n; + + TESTING("compact dataset I/O"); + + /* Initialize data */ + n=0; + for(i=0; i<16; i++) { + for(j=0; j<8; j++) { + wbuf[i][j] = n++; + } + } + + /* Create a small data space for compact dataset */ + dims[0] = 16; + dims[1] = 8; + space = H5Screate_simple(2, dims, NULL); + assert(space>=0); + + /* Create a file */ + if((file=H5Fcreate(FILENAME[1], H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT))<0) + goto error; + + /* Create property list for compact dataset creation */ + plist = H5Pcreate(H5P_DATASET_CREATE); + assert(plist >= 0); + status = H5Pset_layout(plist, H5D_COMPACT); + assert(status >= 0); + status = H5Pset_space_time(plist, H5D_SPACE_ALLOC_EARLY); + assert(status >= 0); + + /* Create and write to a compact dataset */ + if((dataset = H5Dcreate(file, DSET_COMPACT_IO_NAME, H5T_NATIVE_INT, space, + plist))<0) + goto error; + if(H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, wbuf)<0) + goto error; + + /* Close file */ + H5Sclose(space); + H5Pclose(plist); + H5Dclose(dataset); + H5Fclose(file); + + /* + * Open the file and check data + */ + if((file=H5Fopen(FILENAME[1], H5F_ACC_RDONLY, H5P_DEFAULT))<0) + goto error; + if((dataset = H5Dopen(file, DSET_COMPACT_IO_NAME))<0) + goto error; + if(H5Dread(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, rbuf)<0) + goto error; + + /* Check that the values read are the same as the values written */ + for (i = 0; i < 16; i++) { + for (j = 0; j < 8; j++) { + if (rbuf[i][j] != wbuf[i][j]) { + H5_FAILED(); + printf(" Read different values than written.\n"); + printf(" At index %d,%d\n", i, j); + goto error; + } + } + } + + H5Dclose(dataset); + H5Fclose(file); + PASSED(); + return 0; + + error: + return -1; +} + /*------------------------------------------------------------------------- * Function: test_tconv @@ -868,6 +998,7 @@ main(void) nerrors += test_create(file)<0 ?1:0; nerrors += test_simple_io(file)<0 ?1:0; + nerrors += test_compact_io()<0 ?1:0; nerrors += test_tconv(file)<0 ?1:0; nerrors += test_compression(file)<0 ?1:0; nerrors += test_multiopen (file)<0 ?1:0; diff --git a/test/fillval.c b/test/fillval.c index fd9045f..c9925f9 100644 --- a/test/fillval.c +++ b/test/fillval.c @@ -22,6 +22,8 @@ const char *FILENAME[] = { "fillval_4", "fillval_5", "fillval_6", + "fillval_7", + "fillval_8", NULL }; @@ -226,7 +228,7 @@ test_create(hid_t fapl, const char *base_name, H5D_layout_t layout) hid_t file=-1, space=-1, dcpl=-1, comp_type_id=-1; hid_t dset1=-1, dset2=-1, dset3=-1, dset4=-1, dset5=-1, dset6=-1, /* dset7=-1, */ dset8=-1, dset9=-1; - hsize_t cur_size[5] = {32, 16, 8, 4, 2}; + hsize_t cur_size[5] = {2, 16, 8, 4, 2}; hsize_t ch_size[5] = {1, 1, 1, 4, 2}; short rd_s, fill_s = 0x1234; long rd_l, fill_l = 0x4321; @@ -238,6 +240,8 @@ test_create(hid_t fapl, const char *base_name, H5D_layout_t layout) if (H5D_CHUNKED==layout) { TESTING("chunked dataset creation"); + } else if (H5D_COMPACT==layout) { + TESTING("compact dataset creation"); } else { TESTING("contiguous dataset creation"); } @@ -252,68 +256,74 @@ test_create(hid_t fapl, const char *base_name, H5D_layout_t layout) if ((dcpl=H5Pcreate(H5P_DATASET_CREATE))<0) goto error; if (H5D_CHUNKED==layout) { if (H5Pset_chunk(dcpl, 5, ch_size)<0) goto error; + } else if (H5D_COMPACT==layout) { + if (H5Pset_layout(dcpl, H5D_COMPACT)<0) goto error; } + /* Create a compound datatype */ if((comp_type_id = create_compound_type())<0) goto error; - /* I. Test cases for late space allocation */ - if(H5Pset_space_time(dcpl, H5D_SPACE_ALLOC_LATE) < 0) goto error; - if(H5Pset_fill_time(dcpl, H5D_FILL_TIME_ALLOC) < 0) goto error; + /* I. Test cases for late space allocation except compact dataset */ - /* 1. Compound datatype test */ - if(H5Pget_fill_value(dcpl, comp_type_id, &fill_ctype)<0) goto error; - fill_ctype.y = 4444; - if(H5Pset_fill_value(dcpl, comp_type_id, &fill_ctype)<0) goto error; - if((dset9 = H5Dcreate(file, "dset9", comp_type_id, space, dcpl))<0) - goto error; + if(H5D_COMPACT!=layout) { + if(H5Pset_space_time(dcpl, H5D_SPACE_ALLOC_LATE) < 0) goto error; + if(H5Pset_fill_time(dcpl, H5D_FILL_TIME_ALLOC) < 0) goto error; - /* The three datasets test three fill - * conversion paths: small to large, large to small, and no conversion. - * They depend on `short' being smaller than `long'. - */ - /* 2. Small to large fill conversion */ + /* 1. Compound datatype test */ + if(H5Pget_fill_value(dcpl, comp_type_id, &fill_ctype)<0) goto error; + fill_ctype.y = 4444; + if(H5Pset_fill_value(dcpl, comp_type_id, &fill_ctype)<0) goto error; + if((dset9 = H5Dcreate(file, "dset9", comp_type_id, space, dcpl))<0) + goto error; + + /* The three datasets test three fill + * conversion paths: small to large, large to small, and no conversion. + * They depend on `short' being smaller than `long'. + */ + /* 2. Small to large fill conversion */ #ifndef NO_FILLING - if (H5Pset_fill_value(dcpl, H5T_NATIVE_SHORT, &fill_s)<0) goto error; + if (H5Pset_fill_value(dcpl, H5T_NATIVE_SHORT, &fill_s)<0) goto error; #endif - if ((dset1=H5Dcreate(file, "dset1", H5T_NATIVE_LONG, space, dcpl))<0) - goto error; + if ((dset1=H5Dcreate(file, "dset1", H5T_NATIVE_LONG, space, dcpl))<0) + goto error; - /* 3. Large to small fill conversion */ + /* 3. Large to small fill conversion */ #ifndef NO_FILLING - if (H5Pset_fill_value(dcpl, H5T_NATIVE_LONG, &fill_l)<0) goto error; + if (H5Pset_fill_value(dcpl, H5T_NATIVE_LONG, &fill_l)<0) goto error; #endif - if ((dset2=H5Dcreate(file, "dset2", H5T_NATIVE_SHORT, space, dcpl))<0) - goto error; + if ((dset2=H5Dcreate(file, "dset2", H5T_NATIVE_SHORT, space, dcpl))<0) + goto error; - /* 4. No conversion */ + /* 4. No conversion */ #ifndef NO_FILLING - if (H5Pset_fill_value(dcpl, H5T_NATIVE_LONG, &fill_l)<0) goto error; + if (H5Pset_fill_value(dcpl, H5T_NATIVE_LONG, &fill_l)<0) goto error; #endif - if ((dset3=H5Dcreate(file, "dset3", H5T_NATIVE_LONG, space, dcpl))<0) - goto error; - - /* 5. late space allocation and never write fill value */ - if(H5Pset_fill_time(dcpl, H5D_FILL_TIME_NEVER) < 0) goto error; - if ((dset4=H5Dcreate(file, "dset4", H5T_NATIVE_LONG, space, dcpl))<0) - goto error; + if ((dset3=H5Dcreate(file, "dset3", H5T_NATIVE_LONG, space, dcpl))<0) + goto error; - /* 6. fill value is undefined while fill write time is H5D_FILL_TIME_ALLOC. - * Supposed to fail. */ - if(H5Pset_fill_value(dcpl, -1, NULL)<0) goto error; - if(H5Pset_fill_time(dcpl, H5D_FILL_TIME_ALLOC) < 0) goto error; - H5E_BEGIN_TRY { - if(H5Dcreate(file, "dset7", H5T_NATIVE_LONG, space, dcpl)!=FAIL) + /* 5. late space allocation and never write fill value */ + if(H5Pset_fill_time(dcpl, H5D_FILL_TIME_NEVER) < 0) goto error; + if ((dset4=H5Dcreate(file, "dset4", H5T_NATIVE_LONG, space, dcpl))<0) goto error; - } H5E_END_TRY; - - - + /* 6. fill value is undefined while fill write time is H5D_FILL_TIME_ALLOC. + * Supposed to fail. */ + if(H5Pset_fill_value(dcpl, -1, NULL)<0) goto error; + if(H5Pset_fill_time(dcpl, H5D_FILL_TIME_ALLOC) < 0) goto error; + H5E_BEGIN_TRY { + if(H5Dcreate(file, "dset7", H5T_NATIVE_LONG, space, dcpl)!=FAIL) + goto error; + } H5E_END_TRY; + } + /* II. Test early space allocation cases */ + if (H5Pclose(dcpl)<0) goto error; if ((dcpl=H5Pcreate(H5P_DATASET_CREATE))<0) goto error; if (H5D_CHUNKED==layout) { if (H5Pset_chunk(dcpl, 5, ch_size)<0) goto error; + } else if (H5D_COMPACT==layout) { + if (H5Pset_layout(dcpl, H5D_COMPACT)<0) goto error; } if(H5Pset_space_time(dcpl, H5D_SPACE_ALLOC_EARLY) < 0) goto error; @@ -345,16 +355,17 @@ test_create(hid_t fapl, const char *base_name, H5D_layout_t layout) goto error; } H5E_END_TRY; - /* Close everything */ - if (H5Dclose(dset1)<0) goto error; - if (H5Dclose(dset2)<0) goto error; - if (H5Dclose(dset3)<0) goto error; - if (H5Dclose(dset4)<0) goto error; + if(H5D_COMPACT != layout) { + if (H5Dclose(dset1)<0) goto error; + if (H5Dclose(dset2)<0) goto error; + if (H5Dclose(dset3)<0) goto error; + if (H5Dclose(dset4)<0) goto error; + if (H5Dclose(dset9)<0) goto error; + } if (H5Dclose(dset5)<0) goto error; if (H5Dclose(dset6)<0) goto error; if (H5Dclose(dset8)<0) goto error; - if (H5Dclose(dset9)<0) goto error; if (H5Sclose(space)<0) goto error; if (H5Pclose(dcpl)<0) goto error; if (H5Fclose(file)<0) goto error; @@ -363,101 +374,114 @@ test_create(hid_t fapl, const char *base_name, H5D_layout_t layout) if ((file=H5Fopen(filename, H5F_ACC_RDONLY, fapl))<0) goto error; - /* I. Test cases for late space allocation */ - - /* 1. Large to small conversion */ - if ((dset1=H5Dopen(file, "dset1"))<0) goto error; - if ((dcpl=H5Dget_create_plist(dset1))<0) goto error; + /* I. Check cases for late space allocation except compact dataset */ + if(H5D_COMPACT != layout) { + /* 1. Large to small conversion */ + if ((dset1=H5Dopen(file, "dset1"))<0) goto error; + if ((dcpl=H5Dget_create_plist(dset1))<0) goto error; #ifndef NO_FILLING - if (H5Pget_fill_value(dcpl, H5T_NATIVE_SHORT, &rd_s)<0) goto error; - if (rd_s!=fill_s) { - H5_FAILED(); - printf(" %d: Got a different fill value than what was set.",__LINE__); - printf(" Got %d, set %d\n", rd_s, fill_s); - goto error; - } + if (H5Pget_fill_value(dcpl, H5T_NATIVE_SHORT, &rd_s)<0) goto error; + if (rd_s!=fill_s) { + H5_FAILED(); + printf(" %d: Got a different fill value than what was set.",__LINE__); + printf(" Got %d, set %d\n", rd_s, fill_s); + goto error; + } #endif - if (H5Dclose(dset1)<0) goto error; - if (H5Pclose(dcpl)<0) goto error; + if (H5Dclose(dset1)<0) goto error; + if (H5Pclose(dcpl)<0) goto error; - /* 2. Small to large conversion */ - if ((dset2=H5Dopen(file, "dset2"))<0) goto error; - if ((dcpl=H5Dget_create_plist(dset2))<0) goto error; + /* 2. Small to large conversion */ + if ((dset2=H5Dopen(file, "dset2"))<0) goto error; + if ((dcpl=H5Dget_create_plist(dset2))<0) goto error; #ifndef NO_FILLING - if (H5Pget_fill_value(dcpl, H5T_NATIVE_LONG, &rd_l)<0) goto error; - if (rd_l!=fill_l) { - H5_FAILED(); - printf(" %d: Got a different fill value than what was set.",__LINE__); - printf(" Got %ld, set %ld\n", rd_l, fill_l); - goto error; - } + if (H5Pget_fill_value(dcpl, H5T_NATIVE_LONG, &rd_l)<0) goto error; + if (rd_l!=fill_l) { + H5_FAILED(); + printf(" %d: Got a different fill value than what was set.",__LINE__); + printf(" Got %ld, set %ld\n", rd_l, fill_l); + goto error; + } #endif - if (H5Dclose(dset2)<0) goto error; - if (H5Pclose(dcpl)<0) goto error; + if (H5Dclose(dset2)<0) goto error; + if (H5Pclose(dcpl)<0) goto error; - /* 3. No conversion */ - if ((dset3=H5Dopen(file, "dset3"))<0) goto error; - if ((dcpl=H5Dget_create_plist(dset3))<0) goto error; + /* 3. No conversion */ + if ((dset3=H5Dopen(file, "dset3"))<0) goto error; + if ((dcpl=H5Dget_create_plist(dset3))<0) goto error; #ifndef NO_FILLING - if (H5Pget_fill_value(dcpl, H5T_NATIVE_LONG, &rd_l)<0) goto error; - if (rd_l!=fill_l) { - H5_FAILED(); - printf(" %d: Got a different fill value than what was set.",__LINE__); - printf(" Got %ld, set %ld\n", rd_l, fill_l); - goto error; - } + if (H5Pget_fill_value(dcpl, H5T_NATIVE_LONG, &rd_l)<0) goto error; + if (rd_l!=fill_l) { + H5_FAILED(); + printf(" %d: Got a different fill value than what was set.",__LINE__); + printf(" Got %ld, set %ld\n", rd_l, fill_l); + goto error; + } #endif - if(H5Pget_space_time(dcpl, &alloc_time)<0) goto error; - if(H5Pget_fill_time(dcpl, &fill_time)<0) goto error; - if(alloc_time != H5D_SPACE_ALLOC_LATE) { - H5_FAILED(); - puts(" Got non-H5D_SPACE_ALLOC_LATE space allocation time."); - printf(" Got %d\n", alloc_time); - } - if(fill_time != H5D_FILL_TIME_ALLOC) { - H5_FAILED(); - puts(" Got non-H5D_FILL_TIME_ALLOC fill value write time."); - printf(" Got %d\n", fill_time); - } - if (H5Dclose(dset3)<0) goto error; - if (H5Pclose(dcpl)<0) goto error; + if(H5Pget_space_time(dcpl, &alloc_time)<0) goto error; + if(H5Pget_fill_time(dcpl, &fill_time)<0) goto error; + if(alloc_time != H5D_SPACE_ALLOC_LATE) { + H5_FAILED(); + puts(" Got non-H5D_SPACE_ALLOC_LATE space allocation time."); + printf(" Got %d\n", alloc_time); + } + if(fill_time != H5D_FILL_TIME_ALLOC) { + H5_FAILED(); + puts(" Got non-H5D_FILL_TIME_ALLOC fill value write time."); + printf(" Got %d\n", fill_time); + } + if (H5Dclose(dset3)<0) goto error; + if (H5Pclose(dcpl)<0) goto error; - /* 4. late space allocation and never write fill value */ - if ((dset4=H5Dopen(file, "dset4"))<0) goto error; - if (H5Dget_space_status(dset4, &allocation)<0) goto error; + /* 4. late space allocation and never write fill value */ + if ((dset4=H5Dopen(file, "dset4"))<0) goto error; + if (H5Dget_space_status(dset4, &allocation)<0) goto error; #ifndef H5_HAVE_PARALLEL - if (layout == H5D_CONTIGUOUS && allocation != H5D_SPACE_STATUS_NOT_ALLOCATED) { - H5_FAILED(); - puts(" Got allocated space instead of unallocated."); - printf(" Got %d\n", allocation); - goto error; - } + if (layout == H5D_CONTIGUOUS && allocation != H5D_SPACE_STATUS_NOT_ALLOCATED) { + H5_FAILED(); + puts(" Got allocated space instead of unallocated."); + printf(" Got %d\n", allocation); + goto error; + } #else - if (layout == H5D_CONTIGUOUS && allocation == H5D_SPACE_STATUS_NOT_ALLOCATED) { - H5_FAILED(); - printf(" %d: Got unallocated space instead of allocated.\n",__LINE__); - printf(" Got %d\n", allocation); - goto error; - } + if (layout == H5D_CONTIGUOUS && allocation == H5D_SPACE_STATUS_NOT_ALLOCATED) { + H5_FAILED(); + printf(" %d: Got unallocated space instead of allocated.\n",__LINE__); + printf(" Got %d\n", allocation); + goto error; + } #endif - if ((dcpl=H5Dget_create_plist(dset4))<0) goto error; - if(H5Pget_space_time(dcpl, &alloc_time)<0) goto error; - if(H5Pget_fill_time(dcpl, &fill_time)<0) goto error; - if(alloc_time != H5D_SPACE_ALLOC_LATE) { - H5_FAILED(); - puts(" Got non-H5D_SPACE_ALLOC_LATE space allocation time."); - printf(" Got %d\n", alloc_time); - } - if(fill_time != H5D_FILL_TIME_NEVER) { - H5_FAILED(); - puts(" Got non-H5D_FILL_TIME_NEVER fill value write time."); - printf(" Got %d\n", fill_time); + if ((dcpl=H5Dget_create_plist(dset4))<0) goto error; + if(H5Pget_space_time(dcpl, &alloc_time)<0) goto error; + if(H5Pget_fill_time(dcpl, &fill_time)<0) goto error; + if(alloc_time != H5D_SPACE_ALLOC_LATE) { + H5_FAILED(); + puts(" Got non-H5D_SPACE_ALLOC_LATE space allocation time."); + printf(" Got %d\n", alloc_time); + } + if(fill_time != H5D_FILL_TIME_NEVER) { + H5_FAILED(); + puts(" Got non-H5D_FILL_TIME_NEVER fill value write time."); + printf(" Got %d\n", fill_time); + } + if (H5Dclose(dset4)<0) goto error; + if (H5Pclose(dcpl)<0) goto error; + + /* 5. Compound datatype test */ + if ((dset9=H5Dopen(file, "dset9"))<0) goto error; + if ((dcpl=H5Dget_create_plist(dset9))<0) goto error; + if (H5Pget_fill_value(dcpl, comp_type_id, &rd_c)<0) goto error; + if( rd_c.a!=0 || rd_c.y != fill_ctype.y || rd_c.x != 0 || rd_c.z != '\0') { + H5_FAILED(); + puts(" Got wrong fill value"); + printf(" Got rd_c.a=%f, rd_c.y=%f and rd_c.x=%d, rd_c.z=%c\n", + rd_c.a, rd_c.y, rd_c.x, rd_c.z); + } + if (H5Dclose(dset9)<0) goto error; + if (H5Pclose(dcpl)<0) goto error; } - if (H5Dclose(dset4)<0) goto error; - if (H5Pclose(dcpl)<0) goto error; - - /* II. Check early space allocation case */ + /* II. Check early space allocation cases */ /* 1. Never write fill value */ if ((dset5=H5Dopen(file, "dset5"))<0) goto error; @@ -529,21 +553,6 @@ test_create(hid_t fapl, const char *base_name, H5D_layout_t layout) if (H5Dclose(dset8)<0) goto error; if (H5Pclose(dcpl)<0) goto error; - /* 4. Compound datatype test */ - if ((dset9=H5Dopen(file, "dset9"))<0) goto error; - if ((dcpl=H5Dget_create_plist(dset9))<0) goto error; - if (H5Pget_fill_value(dcpl, comp_type_id, &rd_c)<0) goto error; - if( rd_c.a!=0 || rd_c.y != fill_ctype.y || rd_c.x != 0 || rd_c.z != '\0') { - H5_FAILED(); - puts(" Got wrong fill value"); - printf(" Got rd_c.a=%f, rd_c.y=%f and rd_c.x=%d, rd_c.z=%c\n", - rd_c.a, rd_c.y, rd_c.x, rd_c.z); - } - if (H5Dclose(dset9)<0) goto error; - if (H5Pclose(dcpl)<0) goto error; - - - if (H5Tclose(comp_type_id)<0) goto error; if (H5Fclose(file)<0) goto error; PASSED(); return 0; @@ -552,14 +561,16 @@ test_create(hid_t fapl, const char *base_name, H5D_layout_t layout) H5E_BEGIN_TRY { H5Pclose(dcpl); H5Sclose(space); - H5Dclose(dset1); - H5Dclose(dset2); - H5Dclose(dset3); - H5Dclose(dset4); + if(H5D_COMPACT != layout) { + H5Dclose(dset1); + H5Dclose(dset2); + H5Dclose(dset3); + H5Dclose(dset4); + H5Dclose(dset9); + } H5Dclose(dset5); H5Dclose(dset6); H5Dclose(dset8); - H5Dclose(dset9); H5Fclose(file); } H5E_END_TRY; return 1; @@ -589,7 +600,7 @@ test_rdwr_cases(hid_t file, hid_t dcpl, const char *dname, void *_fillval, H5T_class_t datatype, hid_t ctype_id) { hid_t fspace=-1, mspace=-1, dset1=-1, dset2=-1; - hsize_t cur_size[5] = {32, 16, 8, 4, 2}; + hsize_t cur_size[5] = {2, 16, 8, 4, 2}; hsize_t one[5] = {1, 1, 1, 1, 1}; hsize_t hs_size[5], hs_stride[5]; hssize_t hs_offset[5], nelmts; @@ -819,6 +830,7 @@ test_rdwr_cases(hid_t file, hid_t dcpl, const char *dname, void *_fillval, H5Sclose(fspace); H5Sclose(mspace); } H5E_END_TRY; + return 1; } @@ -846,13 +858,15 @@ test_rdwr(hid_t fapl, const char *base_name, H5D_layout_t layout) { char filename[1024]; hid_t file=-1, dcpl=-1, ctype_id=-1; - hsize_t ch_size[5] = {1, 16, 8, 4, 2}; + hsize_t ch_size[5] = {2, 16, 8, 4, 2}; int nerrors=0; int fillval = 0x4c70f1cd; comp_datatype fill_ctype={0,0,0,0}; if (H5D_CHUNKED==layout) { TESTING("chunked dataset I/O"); + } else if (H5D_COMPACT==layout) { + TESTING("compact dataset I/O"); } else { TESTING("contiguous dataset I/O"); } @@ -864,62 +878,65 @@ test_rdwr(hid_t fapl, const char *base_name, H5D_layout_t layout) if ((dcpl=H5Pcreate(H5P_DATASET_CREATE))<0) goto error; if (H5D_CHUNKED==layout) { if (H5Pset_chunk(dcpl, 5, ch_size)<0) goto error; + } else if (H5D_COMPACT==layout) { + if (H5Pset_layout(dcpl, H5D_COMPACT)<0) goto error; } if ((ctype_id=create_compound_type())<0) goto error; /* I. Test H5D_SPACE_ALLOC_LATE space allocation cases */ - if(H5Pset_space_time(dcpl, H5D_SPACE_ALLOC_LATE) < 0) goto error; - - /* case for H5D_FILL_TIME_ALLOC as fill write time and fill value to be default */ - if(H5Pset_fill_time(dcpl, H5D_FILL_TIME_ALLOC) < 0) goto error; - fillval = 0; - nerrors += test_rdwr_cases(file, dcpl, "dset1", &fillval, H5D_FILL_TIME_ALLOC, + if(H5D_COMPACT != layout) { + if(H5Pset_space_time(dcpl, H5D_SPACE_ALLOC_LATE) < 0) goto error; + + /* case for H5D_FILL_TIME_ALLOC as fill write time and fill value to be default */ + if(H5Pset_fill_time(dcpl, H5D_FILL_TIME_ALLOC) < 0) goto error; + fillval = 0; + nerrors += test_rdwr_cases(file, dcpl, "dset1", &fillval, H5D_FILL_TIME_ALLOC, + layout, H5T_INTEGER, -1); + + /* case for H5D_FILL_TIME_NEVER as fill write time and fill value to be default */ + if (H5Pset_fill_time(dcpl, H5D_FILL_TIME_NEVER) < 0) goto error; + nerrors += test_rdwr_cases(file, dcpl, "dset2", &fillval, H5D_FILL_TIME_NEVER, layout, H5T_INTEGER, -1); - /* case for H5D_FILL_TIME_NEVER as fill write time and fill value to be default */ - if (H5Pset_fill_time(dcpl, H5D_FILL_TIME_NEVER) < 0) goto error; - nerrors += test_rdwr_cases(file, dcpl, "dset2", &fillval, H5D_FILL_TIME_NEVER, + /* case for H5D_FILL_TIME_ALLOC as fill write time and fill value is user-defined */ + if(H5Pset_fill_time(dcpl, H5D_FILL_TIME_ALLOC) < 0) goto error; + fillval = 0x4c70f1cd; + if (H5Pset_fill_value(dcpl, H5T_NATIVE_INT, &fillval)<0) goto error; + nerrors += test_rdwr_cases(file, dcpl, "dset3", &fillval, H5D_FILL_TIME_ALLOC, layout, H5T_INTEGER, -1); - /* case for H5D_FILL_TIME_ALLOC as fill write time and fill value is user-defined */ - if(H5Pset_fill_time(dcpl, H5D_FILL_TIME_ALLOC) < 0) goto error; - fillval = 0x4c70f1cd; - if (H5Pset_fill_value(dcpl, H5T_NATIVE_INT, &fillval)<0) goto error; - nerrors += test_rdwr_cases(file, dcpl, "dset3", &fillval, H5D_FILL_TIME_ALLOC, + /* case for H5D_FILL_TIME_NEVER as fill write time and fill value is user-defined */ + if (H5Pset_fill_time(dcpl, H5D_FILL_TIME_NEVER) < 0) goto error; + if (H5Pset_fill_value(dcpl, H5T_NATIVE_INT, &fillval)<0) goto error; + nerrors += test_rdwr_cases(file, dcpl, "dset4", &fillval, H5D_FILL_TIME_NEVER, layout, H5T_INTEGER, -1); - /* case for H5D_FILL_TIME_NEVER as fill write time and fill value is user-defined */ - if (H5Pset_fill_time(dcpl, H5D_FILL_TIME_NEVER) < 0) goto error; - if (H5Pset_fill_value(dcpl, H5T_NATIVE_INT, &fillval)<0) goto error; - nerrors += test_rdwr_cases(file, dcpl, "dset4", &fillval, H5D_FILL_TIME_NEVER, - layout, H5T_INTEGER, -1); + /* case for H5D_FILL_TIME_ALLOC as fill write time and fill value is undefined */ + /* This case has been tested in test_create() function */ - /* case for H5D_FILL_TIME_ALLOC as fill write time and fill value is undefined */ - /* This case has been tested in test_create() function */ - - /* case for H5D_FILL_TIME_NEVER as fill write time and fill value is undefined */ - if(H5Pset_fill_time(dcpl, H5D_FILL_TIME_NEVER) < 0) goto error; - if (H5Pset_fill_value(dcpl, -1, NULL)<0) goto error; - nerrors += test_rdwr_cases(file, dcpl, "dset5", &fillval, H5D_FILL_TIME_NEVER, + /* case for H5D_FILL_TIME_NEVER as fill write time and fill value is undefined */ + if(H5Pset_fill_time(dcpl, H5D_FILL_TIME_NEVER) < 0) goto error; + if (H5Pset_fill_value(dcpl, -1, NULL)<0) goto error; + nerrors += test_rdwr_cases(file, dcpl, "dset5", &fillval, H5D_FILL_TIME_NEVER, layout, H5T_INTEGER, -1); - /* case for H5D_FILL_TIME_ALLOC as fill write time and fill value is user-defined - * as compound type */ - if(H5Pset_fill_time(dcpl, H5D_FILL_TIME_ALLOC) < 0) goto error; - fill_ctype.y = 4444.4444; - if(H5Pset_fill_value(dcpl, ctype_id, &fill_ctype)<0) goto error; - nerrors += test_rdwr_cases(file, dcpl, "dset11", &fill_ctype, H5D_FILL_TIME_ALLOC, + /* case for H5D_FILL_TIME_ALLOC as fill write time and fill value is user-defined + * as compound type */ + if(H5Pset_fill_time(dcpl, H5D_FILL_TIME_ALLOC) < 0) goto error; + fill_ctype.y = 4444.4444; + if(H5Pset_fill_value(dcpl, ctype_id, &fill_ctype)<0) goto error; + nerrors += test_rdwr_cases(file, dcpl, "dset11", &fill_ctype, H5D_FILL_TIME_ALLOC, layout, H5T_COMPOUND, ctype_id); - if (H5Pclose(dcpl)<0) goto error; - if ((dcpl=H5Pcreate(H5P_DATASET_CREATE))<0) goto error; - if (H5D_CHUNKED==layout) { - if (H5Pset_chunk(dcpl, 5, ch_size)<0) goto error; + if (H5Pclose(dcpl)<0) goto error; + if ((dcpl=H5Pcreate(H5P_DATASET_CREATE))<0) goto error; + if (H5D_CHUNKED==layout) { + if (H5Pset_chunk(dcpl, 5, ch_size)<0) goto error; + } } - /* II. Test H5D_SPACE_ALLOC_EARLY space allocation cases */ if(H5Pset_space_time(dcpl, H5D_SPACE_ALLOC_EARLY) < 0) goto error; @@ -932,7 +949,7 @@ test_rdwr(hid_t fapl, const char *base_name, H5D_layout_t layout) /* case for H5D_FILL_TIME_NEVER as fill write time and fill value to be default */ if (H5Pset_fill_time(dcpl, H5D_FILL_TIME_NEVER) < 0) goto error; nerrors += test_rdwr_cases(file, dcpl, "dset7", &fillval, H5D_FILL_TIME_NEVER, layout, - H5T_INTEGER, -1); + H5T_INTEGER, -1); /* case for H5D_FILL_TIME_ALLOC as fill write time and fill value is user-defined */ if(H5Pset_fill_time(dcpl, H5D_FILL_TIME_ALLOC) < 0) goto error; @@ -1381,18 +1398,20 @@ error: int main(int argc, char *argv[]) { - int nerrors=0, argno, test_contig=1, test_chunk=1; + int nerrors=0, argno, test_contig=1, test_chunk=1, test_compact=1; hid_t fapl=-1; if (argc>=2) { - test_contig = test_chunk = 0; + test_contig = test_chunk = test_compact = 0; for (argno=1; argno<argc; argno++) { if (!strcmp(argv[argno], "contiguous")) { test_contig = 1; } else if (!strcmp(argv[argno], "chunked")) { test_chunk = 1; - } else { - fprintf(stderr, "usage: %s [contiguous] [chunked]\n", argv[0]); + } else if (!strcmp(argv[argno], "compact")) { + test_compact =1; + } else { + fprintf(stderr, "usage: %s [contiguous] [chunked] [compact]\n", argv[0]); exit(1); } } @@ -1417,7 +1436,13 @@ main(int argc, char *argv[]) nerrors += test_extend(fapl, FILENAME[5], H5D_CONTIGUOUS); nerrors += test_compatible(); } - + + /* Compact dataset storage tests */ + if (test_compact) { + nerrors += test_create(fapl, FILENAME[6], H5D_COMPACT); + nerrors += test_rdwr (fapl, FILENAME[7], H5D_COMPACT); + } + if (nerrors) goto error; puts("All fill value tests passed."); if (h5_cleanup(FILENAME, fapl)) remove(FILE_NAME_RAW); diff --git a/test/tmisc.c b/test/tmisc.c index e0b3d92..7f6eaa1 100644 --- a/test/tmisc.c +++ b/test/tmisc.c @@ -127,6 +127,7 @@ typedef struct #define MISC8_DSETNAME4 "Dataset4" #define MISC8_DSETNAME5 "Dataset5" #define MISC8_DSETNAME6 "Dataset6" +#define MISC8_DSETNAME7 "Dataset7" #define MISC8_RANK 2 #define MISC8_DIM0 100 #define MISC8_DIM1 100 @@ -1114,6 +1115,11 @@ test_misc8(void) dcpl = H5Pcreate(H5P_DATASET_CREATE); CHECK(dcpl, FAIL, "H5Pcreate"); + /* I. contiguous dataset tests */ + + ret = H5Pset_layout(dcpl, H5D_CONTIGUOUS); + CHECK(ret, FAIL, "H5Pset_layout"); + /* Set the space allocation time to early */ ret = H5Pset_space_time(dcpl,H5D_SPACE_ALLOC_EARLY); CHECK(ret, FAIL, "H5Pset_space_time"); @@ -1158,6 +1164,33 @@ test_misc8(void) CHECK(ret, FAIL, "H5Dclose"); #endif /* H5_HAVE_PARALLEL */ + /* II. compact dataset tests */ + ret = H5Pset_layout(dcpl, H5D_COMPACT); + CHECK(ret, FAIL, "H5Pset_layout"); + + /* Set the space allocation time to early */ + ret = H5Pset_space_time(dcpl,H5D_SPACE_ALLOC_EARLY); + CHECK(ret, FAIL, "H5Pset_space_time"); + + /* Create a contiguous dataset, with space allocation early */ + did = H5Dcreate(fid, MISC8_DSETNAME7, H5T_NATIVE_INT, sid, dcpl); + CHECK(did, FAIL, "H5Dcreate"); + + /* Check the storage size */ + storage_size=H5Dget_storage_size(did); + CHECK(storage_size, 0, "H5Dget_storage_size"); + VERIFY(storage_size, MISC8_DIM0*MISC8_DIM1*H5Tget_size(H5T_NATIVE_INT), "H5Dget_storage_size"); + + /* Close dataset ID */ + ret = H5Dclose(did); + CHECK(ret, FAIL, "H5Dclose"); + + + /* III. chunked dataset tests */ + + ret = H5Pset_layout(dcpl, H5D_CHUNKED); + CHECK(ret, FAIL, "H5Pset_layout"); + /* Set the space allocation time to early */ ret = H5Pset_space_time(dcpl,H5D_SPACE_ALLOC_EARLY); CHECK(ret, FAIL, "H5Pset_space_time"); @@ -1271,10 +1304,17 @@ test_misc8(void) /* Check the storage size after only four chunks are written */ storage_size=H5Dget_storage_size(did); CHECK(storage_size, 0, "H5Dget_storage_size"); +#ifdef H5_HAVE_COMPRESSION if(storage_size>=(4*MISC8_CHUNK_DIM0*MISC8_CHUNK_DIM1*H5Tget_size(H5T_NATIVE_INT))) { num_errs++; printf("Error on line %d: data wasn't compressed! storage_size=%u\n",__LINE__,(unsigned)storage_size); } +#else /* Compression is not configured */ + if(storage_size!=(4*MISC8_CHUNK_DIM0*MISC8_CHUNK_DIM1*H5Tget_size(H5T_NATIVE_INT))) { + num_errs++; + printf("Error on line %d: wrong storage size! storage_size=%u\n",__LINE__,(unsigned)storage_size); + } +#endif /* H5_HAVE_COMPRESSION */ /* Write entire dataset */ ret = H5Dwrite(did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, wdata); @@ -1299,10 +1339,17 @@ test_misc8(void) /* Check the storage size after data is written */ storage_size=H5Dget_storage_size(did); CHECK(storage_size, 0, "H5Dget_storage_size"); +#ifdef H5_HAVE_COMPRESSION if(storage_size>=(MISC8_DIM0*MISC8_DIM1*H5Tget_size(H5T_NATIVE_INT))) { num_errs++; printf("Error on line %d: data wasn't compressed! storage_size=%u\n",__LINE__,(unsigned)storage_size); } +#else + if(storage_size!=(MISC8_DIM0*MISC8_DIM1*H5Tget_size(H5T_NATIVE_INT))) { + num_errs++; + printf("Error on line %d: wrong storage size! storage_size=%u\n",__LINE__,(unsigned)storage_size); + } +#endif /*H5_HAVE_COMPRESSION*/ /* Close dataset ID */ ret = H5Dclose(did); |