From 3926845f87c72bf5348f6a73e627654fc5035645 Mon Sep 17 00:00:00 2001 From: Xiaowen Wu Date: Mon, 31 Jan 2005 10:14:01 -0500 Subject: [svn-r9895] Purpose: Add test cases of nbit filter, tests are now turned on Description: Six test cases are added for testing the nbit filter with different datatypes including int, float, double, array datatype, a simple compound datatype and a complex compound datatype. Improvements are made to testing of int and floating point. Solution: Platforms tested: AIX 5.1 and Linux 2.4. Misc. update: --- test/dsets.c | 746 ++++++++++++++++++++++++++++++++++------------------------- 1 file changed, 427 insertions(+), 319 deletions(-) diff --git a/test/dsets.c b/test/dsets.c index 851b68f..c647f39 100644 --- a/test/dsets.c +++ b/test/dsets.c @@ -75,11 +75,11 @@ const char *FILENAME[] = { #define DSET_SET_LOCAL_NAME_2 "set_local_2" #define DSET_ONEBYTE_SHUF_NAME "onebyte_shuffle" #define DSET_NBIT_INT_NAME "nbit_int" +#define DSET_NBIT_FLOAT_NAME "nbit_float" +#define DSET_NBIT_DOUBLE_NAME "nbit_double" #define DSET_NBIT_ARRAY_NAME "nbit_array" -#define DSET_NBIT_ARRAY_NAME_2 "nbit_array_2" #define DSET_NBIT_COMPOUND_NAME "nbit_compound" #define DSET_NBIT_COMPOUND_NAME_2 "nbit_compound_2" -#define DSET_NBIT_FLOAT_NAME "nbit_float" #define DSET_COMPARE_DCPL_NAME "compare_dcpl" #define DSET_COMPARE_DCPL_NAME_2 "compare_dcpl_2" @@ -2394,7 +2394,7 @@ error: * Failure: -1 * * Programmer: Kent Yang - * Wednesday, , 2002 Nov. 13th + * Wednesday, Nov. 13th, 2002 * * Modifications: * @@ -2512,7 +2512,7 @@ error: * Failure: -1 * * Programmer: Xiaowen Wu - * Wednesday, , 2004 Dec. 23th + * Wednesday, Dec. 23th, 2004 * * Modifications: * @@ -2527,17 +2527,19 @@ test_nbit_int(hid_t file) const hsize_t chunk_size[2] = {2,5}; int orig_data[2][5]; int new_data[2][5]; + unsigned int mask; size_t precision, offset; hsize_t i, j; #else /* H5_HAVE_FILTER_NBIT */ const char *not_supported= " Nbit is not enabled."; #endif /* H5_HAVE_FILTER_NBIT */ - TESTING("nbit int (setup)"); + puts("Testing nbit filter"); + TESTING(" nbit int (setup)"); #ifdef H5_HAVE_FILTER_NBIT /* Define dataset datatype (integer), and set precision, offset */ datatype = H5Tcopy(H5T_NATIVE_INT); - precision = 16; + precision = 17; /* precision includes sign bit */ if(H5Tset_precision(datatype,precision)<0) goto error; offset = 4; if(H5Tset_offset(datatype,offset)<0) goto error; @@ -2554,28 +2556,150 @@ test_nbit_int(hid_t file) /* Use nbit filter */ if((dc = H5Pcreate(H5P_DATASET_CREATE))<0) goto error; if (H5Pset_chunk(dc, 2, chunk_size)<0) goto error; - /*if (H5Pset_nbit(dc)<0) goto error;*/ + if (H5Pset_nbit(dc)<0) goto error; /* Create the dataset */ if ((dataset = H5Dcreate(file, DSET_NBIT_INT_NAME, datatype, space,dc))<0) goto error; + /* Initialize data, assuming size of long_long >= size of int */ for (i= 0;i< size[0]; i++) - for (j = 0; j < size[1]; j++) + for (j = 0; j < size[1]; j++) { orig_data[i][j] = ((long_long)HDrandom() % (long_long)HDpow(2, precision - 1)) << offset; + /* even-numbered values are negtive */ + if((i*size[1]+j+1)%2 == 0) + orig_data[i][j] = -orig_data[i][j]; + } - /*printf("\n"); - for (i= 0;i< size[0]; i++) - for (j = 0; j < size[1]; j++) { - printf("orig[%d]", i); printf("[%d]: ", j); - printf("%08x ", orig_data[i][j]); - if((i*size[1]+j+1)%4 == 0) printf("\n"); - } - printf("\n"); */ + PASSED(); +#else + SKIPPED(); + puts(not_supported); +#endif + /*---------------------------------------------------------------------- + * STEP 1: Test nbit by setting up a chunked dataset and writing + * to it. + *---------------------------------------------------------------------- + */ + TESTING(" nbit int (write)"); + +#ifdef H5_HAVE_FILTER_NBIT + if (H5Dwrite(dataset, mem_datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT, + orig_data)<0) + goto error; + PASSED(); +#else + SKIPPED(); + puts(not_supported); +#endif + + /*---------------------------------------------------------------------- + * STEP 2: Try to read the data we just wrote. + *---------------------------------------------------------------------- + */ + TESTING(" nbit int (read)"); + +#ifdef H5_HAVE_FILTER_NBIT + /* Read the dataset back */ + if (H5Dread(dataset, mem_datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT, + new_data)<0) + goto error; + + /* Check that the values read are the same as the values written + * Use mask for checking the significant bits, ignoring the padding bits + */ + mask = ~(~0 << (precision + offset)) & (~0 << offset); + for (i=0; i= size of unsigned int */ for (i= 0;i< size[0]; i++) for (j = 0; j < size[1]; j++) for (m = 0; m < adims[0]; m++) for (n = 0; n < adims[1]; n++) orig_data[i][j][m][n] = ((long_long)HDrandom() % (long_long)HDpow(2, precision)) << offset; - /* - printf("\n"); - for (i= 0;i< size[0]; i++) - for (j = 0; j < size[1]; j++) - for (m = 0; m < adims[0]; m++) - for (n = 0; n < adims[1]; n++) { - printf("orig[%d]", i); printf("[%d]", j); - printf("[%d]", m); printf("[%d]: ", n); - printf("%08x ", orig_data[i][j][m][n]); - if((i*size[1]*adims[0]*adims[1]+j*adims[0]*adims[1]+m*adims[1]+n+1)%3 == 0) - printf("\n"); - } - printf("\n");*/ - PASSED(); #else SKIPPED(); @@ -2744,10 +2988,10 @@ test_nbit_array(hid_t file) * to it. *---------------------------------------------------------------------- */ - TESTING("nbit array (write)"); + TESTING(" nbit array (write)"); #ifdef H5_HAVE_FILTER_NBIT - if (H5Dwrite(dataset, mem_array_datatype/*H5T_NATIVE_UINT*/, H5S_ALL, H5S_ALL, H5P_DEFAULT, + if (H5Dwrite(dataset, mem_array_datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT, orig_data)<0) goto error; @@ -2761,16 +3005,18 @@ test_nbit_array(hid_t file) * STEP 2: Try to read the data we just wrote. *---------------------------------------------------------------------- */ - TESTING("nbit array (read)"); + TESTING(" nbit array (read)"); #ifdef H5_HAVE_FILTER_NBIT /* Read the dataset back */ - if (H5Dread(dataset, mem_array_datatype/*H5T_NATIVE_UINT*/, H5S_ALL, H5S_ALL, H5P_DEFAULT, + if (H5Dread(dataset, mem_array_datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT, new_data)<0) goto error; - /* Check that the values read are the same as the values written */ - /*printf("\n");*/ + /* Check that the values read are the same as the values written + * Use mask for checking the significant bits, ignoring the padding bits + */ + mask = ~(~0 << (precision + offset)) & (~0 << offset); for (i=0; i= size of member datatypes */ for (i= 0;i< size[0]; i++) for (j = 0; j < size[1]; j++) { orig_data[i][j].i = ((long_long)HDrandom() % - (long_long)HDpow(2, precision[0])) << offset[0]; + (long_long)HDpow(2, precision[0]-1)) << offset[0]; orig_data[i][j].c = ((long_long)HDrandom() % - (long_long)HDpow(2, precision[1])) << offset[1]; + (long_long)HDpow(2, precision[1]-1)) << offset[1]; orig_data[i][j].s = ((long_long)HDrandom() % - (long_long)HDpow(2, precision[2])) << offset[2]; - } -/* - printf("\n"); - for (i= 0;i< size[0]; i++) - for (j = 0; j < size[1]; j++) { - printf("orig[%d]", i); printf("[%d]: ", j); - printf("i: %08x ", orig_data[i][j].i); - printf("c: %02x ", (unsigned char)orig_data[i][j].c); - printf("s: %04x \n", (unsigned short)orig_data[i][j].s); + (long_long)HDpow(2, precision[2]-1)) << offset[2]; + orig_data[i][j].f = float_val[i][j]; + + /* some even-numbered integer values are negtive */ + if((i*size[1]+j+1)%2 == 0) { + orig_data[i][j].i = -orig_data[i][j].i; + orig_data[i][j].s = -orig_data[i][j].s; + } } - printf("\n"); */ PASSED(); #else @@ -2928,10 +3182,10 @@ test_nbit_compound(hid_t file) * to it. *---------------------------------------------------------------------- */ - TESTING("nbit compound (write)"); + TESTING(" nbit compound (write)"); #ifdef H5_HAVE_FILTER_NBIT - if (H5Dwrite(dataset, mem_cmpd_tid1, H5S_ALL, H5S_ALL, H5P_DEFAULT, + if (H5Dwrite(dataset, mem_cmpd_tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, orig_data)<0) goto error; PASSED(); @@ -2944,25 +3198,30 @@ test_nbit_compound(hid_t file) * STEP 2: Try to read the data we just wrote. *---------------------------------------------------------------------- */ - TESTING("nbit compound (read)"); + TESTING(" nbit compound (read)"); #ifdef H5_HAVE_FILTER_NBIT /* Read the dataset back */ - if (H5Dread(dataset, mem_cmpd_tid1, H5S_ALL, H5S_ALL, H5P_DEFAULT, + if (H5Dread(dataset, mem_cmpd_tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, new_data)<0) goto error; - /* Check that the values read are the same as the values written */ - /*printf("\n");*/ + /* Check that the values read are the same as the values written + * Use mask for checking the significant bits, ignoring the padding bits + */ + i_mask = ~(~0 << (precision[0] + offset[0])) & (~0 << offset[0]); + c_mask = ~(~0 << (precision[1] + offset[1])) & (~0 << offset[1]); + s_mask = ~(~0 << (precision[2] + offset[2])) & (~0 << offset[2]); for (i=0; i= size of member datatypes */ for (i= 0;i< size[0]; i++) for (j = 0; j < size[1]; j++) { orig_data[i][j].a.i = ((long_long)HDrandom() % - (long_long)HDpow(2, precision[0])) << offset[0]; + (long_long)HDpow(2, precision[0]-1)) << offset[0]; orig_data[i][j].a.c = ((long_long)HDrandom() % - (long_long)HDpow(2, precision[1])) << offset[1]; - orig_data[i][j].a.s = ((long_long)HDrandom() % - (long_long)HDpow(2, precision[2])) << offset[2]; + (long_long)HDpow(2, precision[1]-1)) << offset[1]; + orig_data[i][j].a.s = -((long_long)HDrandom() % + (long_long)HDpow(2, precision[2]-1)) << offset[2]; + orig_data[i][j].a.f = float_val[i][j]; orig_data[i][j].v = ((long_long)HDrandom() % (long_long)HDpow(2, precision[3])) << offset[3]; @@ -3139,49 +3416,20 @@ test_nbit_compound_2(hid_t file) for(m = 0; m < array_dims[0]; m++) for(n = 0; n < array_dims[1]; n++) orig_data[i][j].b[m][n] = ((long_long)HDrandom() % - (long_long)HDpow(2, precision[4])) << offset[4]; + (long_long)HDpow(2, precision[4]-1)) << offset[4]; for(m = 0; m < array_dims[0]; m++) for(n = 0; n < array_dims[1]; n++) { - orig_data[i][j].d[m][n].i = ((long_long)HDrandom() % - (long_long)HDpow(2, precision[0])) << offset[0]; + orig_data[i][j].d[m][n].i = -((long_long)HDrandom() % + (long_long)HDpow(2, precision[0]-1)) << offset[0]; orig_data[i][j].d[m][n].c = ((long_long)HDrandom() % - (long_long)HDpow(2, precision[1])) << offset[1]; + (long_long)HDpow(2, precision[1]-1)) << offset[1]; orig_data[i][j].d[m][n].s = ((long_long)HDrandom() % - (long_long)HDpow(2, precision[2])) << offset[2]; + (long_long)HDpow(2, precision[2]-1)) << offset[2]; + orig_data[i][j].d[m][n].f = float_val[i][j]; } } -/* - printf("\n"); - for (i= 0;i< size[0]; i++) - for (j = 0; j < size[1]; j++) { - printf("orig[%d]", i); printf("[%d]: ", j); - printf("a.i: %08x ", orig_data[i][j].a.i); - printf("a.c: %02x ", (unsigned char)orig_data[i][j].a.c); - printf("a.s: %04x\n", (unsigned short)orig_data[i][j].a.s); - printf(" v: %08x\n", orig_data[i][j].v); - - printf(" "); - for(m = 0; m < array_dims[0]; m++) - for(n = 0; n < array_dims[1]; n++) { - printf("b[%d]", m); printf("[%d]: ", n); - printf("%02x ", (unsigned char)orig_data[i][j].b[m][n]); - } - printf("\n"); - - for(m = 0; m < array_dims[0]; m++) - for(n = 0; n < array_dims[1]; n++){ - printf(" d[%d]", m); printf("[%d].i: ", n); - printf("%08x ", orig_data[i][j].d[m][n].i); - printf("d[%d]", m); printf("[%d].c: ", n); - printf("%02x ", (unsigned char)orig_data[i][j].d[m][n].c); - printf("d[%d]", m); printf("[%d].s: ", n); - printf("%04x\n", (unsigned short)orig_data[i][j].d[m][n].s); - } - } - printf("\n"); -*/ PASSED(); #else SKIPPED(); @@ -3193,7 +3441,7 @@ test_nbit_compound_2(hid_t file) * to it. *---------------------------------------------------------------------- */ - TESTING("nbit compound complex (write)"); + TESTING(" nbit compound complex (write)"); #ifdef H5_HAVE_FILTER_NBIT if (H5Dwrite(dataset, mem_cmpd_tid2, H5S_ALL, H5S_ALL, H5P_DEFAULT, @@ -3209,7 +3457,7 @@ test_nbit_compound_2(hid_t file) * STEP 2: Try to read the data we just wrote. *---------------------------------------------------------------------- */ - TESTING("nbit compound complex (read)"); + TESTING(" nbit compound complex (read)"); #ifdef H5_HAVE_FILTER_NBIT /* Read the dataset back */ @@ -3217,14 +3465,20 @@ test_nbit_compound_2(hid_t file) new_data)<0) goto error; - /* Check that the values read are the same as the values written */ - /*printf("\n");*/ + /* Check that the values read are the same as the values written + * Use mask for checking the significant bits, ignoring the padding bits + */ + i_mask = ~(~0 << (precision[0] + offset[0])) & (~0 << offset[0]); + c_mask = ~(~0 << (precision[1] + offset[1])) & (~0 << offset[1]); + s_mask = ~(~0 << (precision[2] + offset[2])) & (~0 << offset[2]); + v_mask = ~(~0 << (precision[3] + offset[3])) & (~0 << offset[3]); + b_mask = ~(~0 << (precision[4] + offset[4])) & (~0 << offset[4]); for (i=0; i