/*------------------------------------------------------------------------- * Function: test_read_with_filters * * Purpose: Tests reading dataset created with dynamically loaded filters * * Return: Success: 0 * Failure: -1 * * Programmer: Raymond Lu * 14 March 2013 * *------------------------------------------------------------------------- */ static herr_t test_read_with_filters(hid_t file) { hid_t dset; /* Dataset ID */ /*---------------------------------------------------------- * STEP 1: Test deflation by itself. *---------------------------------------------------------- */ #ifdef H5_HAVE_FILTER_DEFLATE TESTING("Testing deflate filter"); if(H5Zfilter_avail(H5Z_FILTER_DEFLATE) != TRUE) TEST_ERROR if((dset = H5Dopen2(file,DSET_DEFLATE_NAME,H5P_DEFAULT)) < 0) TEST_ERROR if(test_read_data(dset, (int *)points_deflate) < 0) TEST_ERROR if(H5Dclose(dset) < 0) TEST_ERROR /* Clean up objects used for this test */ #else /* H5_HAVE_FILTER_DEFLATE */ TESTING("deflate filter"); SKIPPED(); puts(" Deflate filter not enabled"); #endif /* H5_HAVE_FILTER_DEFLATE */ /*---------------------------------------------------------- * STEP 2: Test DYNLIB1 by itself. *---------------------------------------------------------- */ TESTING("Testing DYNLIB1 filter"); if((dset = H5Dopen2(file,DSET_DYNLIB1_NAME,H5P_DEFAULT)) < 0) TEST_ERROR if(test_read_data(dset, (int *)points_dynlib1) < 0) TEST_ERROR if(H5Dclose(dset) < 0) TEST_ERROR /*---------------------------------------------------------- * STEP 3: Test Bogus2 by itself. *---------------------------------------------------------- */ TESTING("Testing DYNLIB2 filter"); if((dset = H5Dopen2(file,DSET_DYNLIB2_NAME,H5P_DEFAULT)) < 0) TEST_ERROR if(test_read_data(dset, (int *)points_dynlib2) < 0) TEST_ERROR if(H5Dclose(dset) < 0) TEST_ERROR return 0; error: return -1; }
/*------------------------------------------------------------------------- * Function: test_direct * * Purpose: Tests the file handle interface for DIRECT I/O driver * * Return: Success: 0 * Failure: -1 * * Programmer: Raymond Lu * Wednesday, 20 September 2006 * *------------------------------------------------------------------------- */ static herr_t test_direct(void) { #ifdef H5_HAVE_DIRECT hid_t file=(-1), fapl, access_fapl = -1; hid_t dset1=-1, dset2=-1, space1=-1, space2=-1; char filename[1024]; int *fhandle=NULL; hsize_t file_size; hsize_t dims1[2], dims2[1]; size_t mbound; size_t fbsize; size_t cbsize; int *points, *check, *p1, *p2; int wdata2[DSET2_DIM] = {11,12,13,14}; int rdata2[DSET2_DIM]; int i, j, n; #endif /*H5_HAVE_DIRECT*/ TESTING("Direct I/O file driver"); #ifndef H5_HAVE_DIRECT SKIPPED(); return 0; #else /*H5_HAVE_DIRECT*/ /* Set property list and file name for Direct driver. Set memory alignment boundary * and file block size to 512 which is the minimum for Linux 2.6. */ fapl = h5_fileaccess(); if(H5Pset_fapl_direct(fapl, MBOUNDARY, FBSIZE, CBSIZE) < 0) TEST_ERROR; h5_fixname(FILENAME[5], fapl, filename, sizeof filename); /* Verify the file access properties */ if(H5Pget_fapl_direct(fapl, &mbound, &fbsize, &cbsize) < 0) TEST_ERROR; if(mbound != MBOUNDARY || fbsize != FBSIZE || cbsize != CBSIZE) TEST_ERROR; if(H5Pset_alignment(fapl, (hsize_t)THRESHOLD, (hsize_t)FBSIZE) < 0) TEST_ERROR; H5E_BEGIN_TRY { file=H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl); } H5E_END_TRY; if(file<0) { H5Pclose (fapl); SKIPPED(); printf(" Probably the file system doesn't support Direct I/O\n"); return 0; } /* Retrieve the access property list... */ if ((access_fapl = H5Fget_access_plist(file)) < 0) TEST_ERROR; /* ...and close the property list */ if (H5Pclose(access_fapl) < 0) TEST_ERROR; /* Check file handle API */ if(H5Fget_vfd_handle(file, H5P_DEFAULT, (void **)&fhandle) < 0) TEST_ERROR; if(*fhandle<0) TEST_ERROR; /* Check file size API */ if(H5Fget_filesize(file, &file_size) < 0) TEST_ERROR; /* There is no guarantee of the number of metadata allocations, but it's * 4 currently and the size of the file should be between 3 & 4 file buffer * sizes.. */ if(file_size < (FBSIZE * 3) || file_size >= (FBSIZE * 4)) TEST_ERROR; /* Allocate aligned memory for data set 1. For data set 1, everything is aligned including * memory address, size of data, and file address. */ if(posix_memalign(&points, (size_t)FBSIZE, (size_t)(DSET1_DIM1*DSET1_DIM2*sizeof(int)))!=0) TEST_ERROR; if(posix_memalign(&check, (size_t)FBSIZE, (size_t)(DSET1_DIM1*DSET1_DIM2*sizeof(int)))!=0) TEST_ERROR; /* Initialize the dset1 */ p1 = points; for(i = n = 0; i < DSET1_DIM1; i++) for(j = 0; j < DSET1_DIM2; j++) *p1++ = n++; /* Create the data space1 */ dims1[0] = DSET1_DIM1; dims1[1] = DSET1_DIM2; if((space1 = H5Screate_simple(2, dims1, NULL)) < 0) TEST_ERROR; /* Create the dset1 */ if((dset1 = H5Dcreate2(file, DSET1_NAME, H5T_NATIVE_INT, space1, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR; /* Write the data to the dset1 */ if(H5Dwrite(dset1, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, points) < 0) TEST_ERROR; if(H5Dclose(dset1) < 0) TEST_ERROR; if((dset1 = H5Dopen2(file, DSET1_NAME, H5P_DEFAULT)) < 0) TEST_ERROR; /* Read the data back from dset1 */ if(H5Dread(dset1, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, check) < 0) TEST_ERROR; /* Check that the values read are the same as the values written */ p1 = points; p2 = check; for(i = 0; i < DSET1_DIM1; i++) for(j = 0; j < DSET1_DIM2; j++) if(*p1++ != *p2++) { H5_FAILED(); printf(" Read different values than written in data set 1.\n"); printf(" At index %d,%d\n", i, j); TEST_ERROR; } /* end if */ /* Create the data space2. For data set 2, memory address and data size are not aligned. */ dims2[0] = DSET2_DIM; if((space2 = H5Screate_simple(1, dims2, NULL)) < 0) TEST_ERROR; /* Create the dset2 */ if((dset2 = H5Dcreate2(file, DSET2_NAME, H5T_NATIVE_INT, space2, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR; /* Write the data to the dset1 */ if(H5Dwrite(dset2, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, wdata2) < 0) TEST_ERROR; if(H5Dclose(dset2) < 0) TEST_ERROR; if((dset2 = H5Dopen2(file, DSET2_NAME, H5P_DEFAULT)) < 0) TEST_ERROR; /* Read the data back from dset1 */ if(H5Dread(dset2, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, rdata2) < 0) TEST_ERROR; /* Check that the values read are the same as the values written */ for(i = 0; i < DSET2_DIM; i++) if(wdata2[i] != rdata2[i]) { H5_FAILED(); printf(" Read different values than written in data set 2.\n"); printf(" At index %d\n", i); TEST_ERROR; } /* end if */ if(H5Sclose(space1) < 0) TEST_ERROR; if(H5Dclose(dset1) < 0) TEST_ERROR; if(H5Sclose(space2) < 0) TEST_ERROR; if(H5Dclose(dset2) < 0) TEST_ERROR; if(H5Fclose(file) < 0) TEST_ERROR; if(points) free(points); if(check) free(check); h5_cleanup(FILENAME, fapl); PASSED(); return 0; error: H5E_BEGIN_TRY { H5Pclose (fapl); H5Sclose(space1); H5Dclose(dset1); H5Sclose(space2); H5Dclose(dset2); H5Fclose(file); } H5E_END_TRY; return -1; #endif /*H5_HAVE_DIRECT*/ }
/*------------------------------------------------------------------------- * Function: main * * Purpose: Part 1 of a two-part H5Fflush() test. * * Return: Success: 0 * * Failure: 1 * * Programmer: Robb Matzke * Friday, October 23, 1998 * * Modifications: * Leon Arber * Sept. 26, 2006, expand test to check for failure if H5Fflush is not called. * * *------------------------------------------------------------------------- */ int main(int argc, char* argv[]) { hid_t file1, file2, fapl; MPI_File *mpifh_p = NULL; char name[1024]; const char *envval = NULL; int mpi_size, mpi_rank; MPI_Comm comm = MPI_COMM_WORLD; MPI_Info info = MPI_INFO_NULL; MPI_Init(&argc, &argv); MPI_Comm_size(comm, &mpi_size); MPI_Comm_rank(comm, &mpi_rank); fapl = H5Pcreate(H5P_FILE_ACCESS); H5Pset_fapl_mpio(fapl, comm, info); if(mpi_rank == 0) TESTING("H5Fflush (part1)"); envval = HDgetenv("HDF5_DRIVER"); if(envval == NULL) envval = "nomatch"; if(HDstrcmp(envval, "split")) { /* Create the file */ h5_fixname(FILENAME[0], fapl, name, sizeof name); file1 = create_file(name, fapl); /* Flush and exit without closing the library */ if(H5Fflush(file1, H5F_SCOPE_GLOBAL) < 0) goto error; /* Create the other file which will not be flushed */ h5_fixname(FILENAME[1], fapl, name, sizeof name); file2 = create_file(name, fapl); if(mpi_rank == 0) PASSED(); fflush(stdout); fflush(stderr); } /* end if */ else { SKIPPED(); puts(" Test not compatible with current Virtual File Driver"); } /* end else */ /* * Some systems like AIX do not like files not closed when MPI_Finalize * is called. So, we need to get the MPI file handles, close them by hand. * Then the _exit is still needed to stop at_exit from happening in some systems. * Note that MPIO VFD returns the address of the file-handle in the VFD struct * because MPI_File_close wants to modify the file-handle variable. */ /* close file1 */ if(H5Fget_vfd_handle(file1, fapl, (void **)&mpifh_p) < 0) { printf("H5Fget_vfd_handle for file1 failed\n"); goto error; } /* end if */ if(MPI_File_close(mpifh_p) != MPI_SUCCESS) { printf("MPI_File_close for file1 failed\n"); goto error; } /* end if */ /* close file2 */ if(H5Fget_vfd_handle(file2, fapl, (void **)&mpifh_p) < 0) { printf("H5Fget_vfd_handle for file2 failed\n"); goto error; } /* end if */ if(MPI_File_close(mpifh_p) != MPI_SUCCESS) { printf("MPI_File_close for file2 failed\n"); goto error; } /* end if */ fflush(stdout); fflush(stderr); HD_exit(0); error: fflush(stdout); fflush(stderr); HD_exit(1); }
/*------------------------------------------------------------------------- * Function: main * * Purpose: H5O_mtime_decode() test. * * Return: Success: * * Failure: * * Programmer: Robb Matzke * Thursday, July 30, 1998 * * Modifications: * Added checks for old and new modification time messages * in pre-created datafiles (generated with gen_old_mtime.c and * gen_new_mtime.c). * Quincey Koziol * Friday, January 3, 2003 * *------------------------------------------------------------------------- */ int main(void) { hid_t fapl, file, space, dset; hsize_t size[1] = {2}; time_t now; struct tm *tm; H5O_info_t oi1, oi2; signed char buf1[32], buf2[32]; char filename[1024]; h5_reset(); fapl = h5_fileaccess(); TESTING("modification time messages"); /* Create the file, create a dataset, then close the file */ h5_fixname(FILENAME[0], fapl, filename, sizeof filename); if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR; if((space = H5Screate_simple(1, size, NULL)) < 0) TEST_ERROR; if((dset = H5Dcreate2(file, "dset", H5T_NATIVE_SCHAR, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR; now = HDtime(NULL); if(H5Dclose(dset) < 0) TEST_ERROR; if(H5Sclose(space) < 0) TEST_ERROR; if(H5Fclose(file) < 0) TEST_ERROR; /* * Open the file and get the modification time. We'll test the * H5Oget_info() arguments too: being able to stat something without * knowing its name. */ h5_fixname(FILENAME[0], fapl, filename, sizeof filename); if((file = H5Fopen(filename, H5F_ACC_RDONLY, fapl)) < 0) TEST_ERROR; if(H5Oget_info_by_name(file, "dset", &oi1, H5P_DEFAULT) < 0) TEST_ERROR; if((dset = H5Dopen2(file, "dset", H5P_DEFAULT)) < 0) TEST_ERROR; if(H5Oget_info(dset, &oi2) < 0) TEST_ERROR; if(H5Dclose(dset) < 0) TEST_ERROR; if(H5Fclose(file) < 0) TEST_ERROR; /* Compare addresses & times from the two ways of calling H5Oget_info() */ if(oi1.addr != oi2.addr || oi1.mtime != oi2.mtime) { H5_FAILED(); puts(" Calling H5Oget_info() with the dataset ID returned"); puts(" different values than calling it with a file and dataset"); puts(" name."); goto error; } /* Compare times -- they must be within 60 seconds of one another */ if(0 == oi1.mtime) { SKIPPED(); puts(" The modification time could not be decoded on this OS."); puts(" Modification times will be mantained in the file but"); puts(" cannot be queried on this system. See H5O_mtime_decode()."); return 0; } else if(HDfabs(HDdifftime(now, oi1.mtime)) > 60.0) { H5_FAILED(); tm = HDlocaltime(&(oi1.mtime)); HDstrftime((char*)buf1, sizeof buf1, "%Y-%m-%d %H:%M:%S", tm); tm = HDlocaltime(&now); HDstrftime((char*)buf2, sizeof buf2, "%Y-%m-%d %H:%M:%S", tm); printf(" got: %s\n ans: %s\n", buf1, buf2); goto error; } PASSED(); /* Check opening existing file with old-style modification time information * and make certain that the time is correct */ TESTING("accessing old modification time messages"); { char testfile[512]=""; char *srcdir = HDgetenv("srcdir"); if(srcdir && ((HDstrlen(srcdir) + strlen(TESTFILE1) + 1) < sizeof(testfile))){ HDstrcpy(testfile, srcdir); HDstrcat(testfile, "/"); } HDstrcat(testfile, TESTFILE1); file = H5Fopen(testfile, H5F_ACC_RDONLY, H5P_DEFAULT); if(file >= 0){ if(H5Oget_info_by_name(file, "/Dataset1", &oi1, H5P_DEFAULT) < 0) TEST_ERROR; if(oi1.mtime != MTIME1) { H5_FAILED(); /* If this fails, examine H5Omtime.c. Modification time is very * system dependant (e.g., on Windows DST must be hardcoded). */ puts(" Old modification time incorrect"); goto error; } if(H5Fclose(file) < 0) TEST_ERROR; } else { H5_FAILED(); printf("***cannot open the pre-created old modification test file (%s)\n", testfile); goto error; } /* end else */ } PASSED(); /* Check opening existing file with new-style modification time information * and make certain that the time is correct */ TESTING("accessing new modification time messages"); { char testfile[512]=""; char *srcdir = HDgetenv("srcdir"); if(srcdir && ((HDstrlen(srcdir) + strlen(TESTFILE2) + 1) < sizeof(testfile))){ HDstrcpy(testfile, srcdir); HDstrcat(testfile, "/"); } HDstrcat(testfile, TESTFILE2); file = H5Fopen(testfile, H5F_ACC_RDONLY, H5P_DEFAULT); if(file >= 0){ if(H5Oget_info_by_name(file, "/Dataset1", &oi2, H5P_DEFAULT) < 0) TEST_ERROR; if(oi2.mtime != MTIME2) { H5_FAILED(); puts(" Modification time incorrect."); goto error; } if(H5Fclose(file) < 0) TEST_ERROR; } else { H5_FAILED(); printf("***cannot open the pre-created old modification test file (%s)\n", testfile); goto error; } /* end else */ } PASSED(); /* All looks good */ puts("All modification time tests passed."); h5_cleanup(FILENAME, fapl); return 0; /* Something broke */ error: return 1; }
/*------------------------------------------------------------------------- * Function: read_data * * Purpose: Read data from a data file. * * Return: Success: 0 * Failure: -1 * * Programmer: Raymond Lu * 21 January 2011 * * Modifications: * *------------------------------------------------------------------------- */ static int read_data(char *fname) { char pathname[1024]; char *srcdir = getenv("srcdir"); /*where the src code is located*/ hid_t file, dataset; /* handles */ double data_in[NX+1][NY]; /* input buffer */ double data_out[NX+1][NY]; /* output buffer */ long long int_data_in[NX+1][NY]; /* input buffer */ long long int_data_out[NX+1][NY]; /* output buffer */ int i, j; unsigned nerrors = 0; const char *not_supported= " Scaleoffset filter is not enabled."; pathname[0] = '\0'; /* Generate correct name for test file by prepending the source path */ if(srcdir && ((strlen(srcdir) + strlen(fname) + 1) < sizeof(pathname))) { strcpy(pathname, srcdir); strcat(pathname, "/"); } strcat(pathname, fname); /* * Open the file. */ if((file = H5Fopen(pathname, H5F_ACC_RDONLY, H5P_DEFAULT)) < 0) TEST_ERROR; TESTING("regular dataset"); /* * Open the regular dataset. */ if((dataset = H5Dopen2(file, DATASETNAME, H5P_DEFAULT)) < 0) TEST_ERROR; /* * Data and output buffer initialization. */ for (j = 0; j < NX; j++) { for (i = 0; i < NY; i++) { data_in[j][i] = i + j; data_out[j][i] = 0; } } for (i = 0; i < NY; i++) { data_in[NX][i] = -2.2; data_out[NX][i] = 0; } /* * 0 1 2 3 4 5 * 1 2 3 4 5 6 * 2 3 4 5 6 7 * 3 4 5 6 7 8 * 4 5 6 7 8 9 * 5 6 7 8 9 10 * -2.2 -2.2 -2.2 -2.2 -2.2 -2.2 */ /* * Read data from hyperslab in the file into the hyperslab in * memory and display. */ if(H5Dread(dataset, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, data_out) < 0) TEST_ERROR; /* Check results */ for (j=0; j<(NX+1); j++) { for (i=0; i<NY; i++) { /* if (data_out[j][i] != data_in[j][i]) { */ if (!FLT_ABS_EQUAL(data_out[j][i], data_in[j][i])) { if (!nerrors++) { H5_FAILED(); printf("element [%d][%d] is %g but should have been %g\n", j, i, data_out[j][i], data_in[j][i]); } } } } /* * Close/release resources. */ if(H5Dclose(dataset) < 0) TEST_ERROR /* Failure */ if (nerrors) { printf("total of %d errors out of %d elements\n", nerrors, NX*NY); return 1; } PASSED(); TESTING("dataset of LE FLOAT with scale-offset filter"); #ifdef H5_HAVE_FILTER_SCALEOFFSET /* * Open the dataset with scale-offset filter. */ if((dataset = H5Dopen2(file, DATASETNAME2, H5P_DEFAULT)) < 0) TEST_ERROR; /* * Data and output buffer initialization. */ for (j = 0; j < NX; j++) { for (i = 0; i < NY; i++) { data_in[j][i] = ((double)(i + j + 1))/3; data_out[j][i] = 0; } } for (i = 0; i < NY; i++) { data_in[NX][i] = -2.2; data_out[NX][i] = 0; } /* * Read data from hyperslab in the file into the hyperslab in * memory and display. */ if(H5Dread(dataset, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, data_out) < 0) TEST_ERROR; /* Check results */ for (j=0; j<(NX+1); j++) { for (i=0; i<NY; i++) { if (!DBL_REL_EQUAL(data_out[j][i], data_in[j][i], 0.001)) { if (!nerrors++) { H5_FAILED(); printf("element [%d][%d] is %g but should have been %g\n", j, i, data_out[j][i], data_in[j][i]); } } } } /* * Close/release resources. */ if(H5Dclose(dataset) < 0) TEST_ERROR /* Failure */ if (nerrors) { printf("total of %d errors out of %d elements\n", nerrors, NX*NY); return 1; } PASSED(); #else /*H5_HAVE_FILTER_SCALEOFFSET*/ SKIPPED(); puts(not_supported); #endif /*H5_HAVE_FILTER_SCALEOFFSET*/ TESTING("dataset of BE FLOAT with scale-offset filter"); #ifdef H5_HAVE_FILTER_SCALEOFFSET /* * Open the dataset with scale-offset filter. */ if((dataset = H5Dopen2(file, DATASETNAME3, H5P_DEFAULT)) < 0) TEST_ERROR; /* * Data and output buffer initialization. */ for (j = 0; j < NX; j++) { for (i = 0; i < NY; i++) { data_in[j][i] = ((double)(i + j + 1))/3; data_out[j][i] = 0; } } for (i = 0; i < NY; i++) { data_in[NX][i] = -2.2; data_out[NX][i] = 0; } /* * Read data from hyperslab in the file into the hyperslab in * memory and display. */ if(H5Dread(dataset, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, data_out) < 0) TEST_ERROR; /* Check results */ for (j=0; j<(NX+1); j++) { for (i=0; i<NY; i++) { if (!DBL_REL_EQUAL(data_out[j][i], data_in[j][i], 0.001)) { if (!nerrors++) { H5_FAILED(); printf("element [%d][%d] is %g but should have been %g\n", j, i, data_out[j][i], data_in[j][i]); } } } } /* * Close/release resources. */ if(H5Dclose(dataset) < 0) TEST_ERROR /* Failure */ if (nerrors) { printf("total of %d errors out of %d elements\n", nerrors, NX*NY); return 1; } PASSED(); #else /*H5_HAVE_FILTER_SCALEOFFSET*/ SKIPPED(); puts(not_supported); #endif /*H5_HAVE_FILTER_SCALEOFFSET*/ TESTING("dataset of LE DOUBLE with scale-offset filter"); #ifdef H5_HAVE_FILTER_SCALEOFFSET /* * Open the dataset with scale-offset filter. */ if((dataset = H5Dopen2(file, DATASETNAME4, H5P_DEFAULT)) < 0) TEST_ERROR; /* * Data and output buffer initialization. */ for (j = 0; j < NX; j++) { for (i = 0; i < NY; i++) { data_in[j][i] = ((double)(i + j + 1))/3; data_out[j][i] = 0; } } for (i = 0; i < NY; i++) { data_in[NX][i] = -2.2; data_out[NX][i] = 0; } /* * Read data from hyperslab in the file into the hyperslab in * memory and display. */ if(H5Dread(dataset, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, data_out) < 0) TEST_ERROR; /* Check results */ for (j=0; j<(NX+1); j++) { for (i=0; i<NY; i++) { if (!DBL_REL_EQUAL(data_out[j][i], data_in[j][i], 0.001)) { if (!nerrors++) { H5_FAILED(); printf("element [%d][%d] is %g but should have been %g\n", j, i, data_out[j][i], data_in[j][i]); } } } } /* * Close/release resources. */ if(H5Dclose(dataset) < 0) TEST_ERROR /* Failure */ if (nerrors) { printf("total of %d errors out of %d elements\n", nerrors, NX*NY); return 1; } PASSED(); #else /*H5_HAVE_FILTER_SCALEOFFSET*/ SKIPPED(); puts(not_supported); #endif /*H5_HAVE_FILTER_SCALEOFFSET*/ TESTING("dataset of BE DOUBLE with scale-offset filter"); #ifdef H5_HAVE_FILTER_SCALEOFFSET /* * Open the dataset with scale-offset filter. */ if((dataset = H5Dopen2(file, DATASETNAME5, H5P_DEFAULT)) < 0) TEST_ERROR; /* * Data and output buffer initialization. */ for (j = 0; j < NX; j++) { for (i = 0; i < NY; i++) { data_in[j][i] = ((double)(i + j + 1))/3; data_out[j][i] = 0; } } for (i = 0; i < NY; i++) { data_in[NX][i] = -2.2; data_out[NX][i] = 0; } /* * Read data from hyperslab in the file into the hyperslab in * memory and display. */ if(H5Dread(dataset, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, data_out) < 0) TEST_ERROR; /* Check results */ for (j=0; j<(NX+1); j++) { for (i=0; i<NY; i++) { if (!DBL_REL_EQUAL(data_out[j][i], data_in[j][i], 0.001)) { if (!nerrors++) { H5_FAILED(); printf("element [%d][%d] is %g but should have been %g\n", j, i, data_out[j][i], data_in[j][i]); } } } } /* * Close/release resources. */ if(H5Dclose(dataset) < 0) TEST_ERROR /* Failure */ if (nerrors) { printf("total of %d errors out of %d elements\n", nerrors, NX*NY); return 1; } PASSED(); #else /*H5_HAVE_FILTER_SCALEOFFSET*/ SKIPPED(); puts(not_supported); #endif /*H5_HAVE_FILTER_SCALEOFFSET*/ TESTING("dataset of LE CHAR with scale-offset filter"); #ifdef H5_HAVE_FILTER_SCALEOFFSET /* * Open the dataset with scale-offset filter. */ if((dataset = H5Dopen2(file, DATASETNAME6, H5P_DEFAULT)) < 0) TEST_ERROR; /* * Data and output buffer initialization. */ for (j = 0; j < NX; j++) { for (i = 0; i < NY; i++) { int_data_in[j][i] = i + j; int_data_out[j][i] = 0; } } for (i = 0; i < NY; i++) { int_data_in[NX][i] = -2; int_data_out[NX][i] = 0; } /* * Read data from hyperslab in the file into the hyperslab in * memory and display. */ if(H5Dread(dataset, H5T_NATIVE_LLONG, H5S_ALL, H5S_ALL, H5P_DEFAULT, int_data_out) < 0) TEST_ERROR; /* Check results */ for (j=0; j<(NX+1); j++) { for (i=0; i<NY; i++) { if (int_data_out[j][i] != int_data_in[j][i]) { if (!nerrors++) { H5_FAILED(); printf("element [%d][%d] is %d but should have been %d\n", j, i, (int)int_data_out[j][i], (int)int_data_in[j][i]); } } } } /* * Close/release resources. */ if(H5Dclose(dataset) < 0) TEST_ERROR /* Failure */ if (nerrors) { printf("total of %d errors out of %d elements\n", nerrors, NX*NY); return 1; } PASSED(); #else /*H5_HAVE_FILTER_SCALEOFFSET*/ SKIPPED(); puts(not_supported); #endif /*H5_HAVE_FILTER_SCALEOFFSET*/ TESTING("dataset of BE CHAR with scale-offset filter"); #ifdef H5_HAVE_FILTER_SCALEOFFSET /* * Open the dataset with scale-offset filter. */ if((dataset = H5Dopen2(file, DATASETNAME7, H5P_DEFAULT)) < 0) TEST_ERROR; /* * Data and output buffer initialization. */ for (j = 0; j < NX; j++) { for (i = 0; i < NY; i++) { int_data_in[j][i] = i + j; int_data_out[j][i] = 0; } } for (i = 0; i < NY; i++) { int_data_in[NX][i] = -2; int_data_out[NX][i] = 0; } /* * Read data from hyperslab in the file into the hyperslab in * memory and display. */ if(H5Dread(dataset, H5T_NATIVE_LLONG, H5S_ALL, H5S_ALL, H5P_DEFAULT, int_data_out) < 0) TEST_ERROR; /* Check results */ for (j=0; j<(NX+1); j++) { for (i=0; i<NY; i++) { if (int_data_out[j][i] != int_data_in[j][i]) { if (!nerrors++) { H5_FAILED(); printf("element [%d][%d] is %d but should have been %d\n", j, i, (int)int_data_out[j][i], (int)int_data_in[j][i]); } } } } /* * Close/release resources. */ if(H5Dclose(dataset) < 0) TEST_ERROR /* Failure */ if (nerrors) { printf("total of %d errors out of %d elements\n", nerrors, NX*NY); return 1; } PASSED(); #else /*H5_HAVE_FILTER_SCALEOFFSET*/ SKIPPED(); puts(not_supported); #endif /*H5_HAVE_FILTER_SCALEOFFSET*/ TESTING("dataset of LE SHORT with scale-offset filter"); #ifdef H5_HAVE_FILTER_SCALEOFFSET /* * Open the dataset with scale-offset filter. */ if((dataset = H5Dopen2(file, DATASETNAME8, H5P_DEFAULT)) < 0) TEST_ERROR; /* * Data and output buffer initialization. */ for (j = 0; j < NX; j++) { for (i = 0; i < NY; i++) { int_data_in[j][i] = i + j; int_data_out[j][i] = 0; } } for (i = 0; i < NY; i++) { int_data_in[NX][i] = -2; int_data_out[NX][i] = 0; } /* * Read data from hyperslab in the file into the hyperslab in * memory and display. */ if(H5Dread(dataset, H5T_NATIVE_LLONG, H5S_ALL, H5S_ALL, H5P_DEFAULT, int_data_out) < 0) TEST_ERROR; /* Check results */ for (j=0; j<(NX+1); j++) { for (i=0; i<NY; i++) { if (int_data_out[j][i] != int_data_in[j][i]) { if (!nerrors++) { H5_FAILED(); printf("element [%d][%d] is %d but should have been %d\n", j, i, (int)int_data_out[j][i], (int)int_data_in[j][i]); } } } } /* * Close/release resources. */ if(H5Dclose(dataset) < 0) TEST_ERROR /* Failure */ if (nerrors) { printf("total of %d errors out of %d elements\n", nerrors, NX*NY); return 1; } PASSED(); #else /*H5_HAVE_FILTER_SCALEOFFSET*/ SKIPPED(); puts(not_supported); #endif /*H5_HAVE_FILTER_SCALEOFFSET*/ TESTING("dataset of BE SHORT with scale-offset filter"); #ifdef H5_HAVE_FILTER_SCALEOFFSET /* * Open the dataset with scale-offset filter. */ if((dataset = H5Dopen2(file, DATASETNAME9, H5P_DEFAULT)) < 0) TEST_ERROR; /* * Data and output buffer initialization. */ for (j = 0; j < NX; j++) { for (i = 0; i < NY; i++) { int_data_in[j][i] = i + j; int_data_out[j][i] = 0; } } for (i = 0; i < NY; i++) { int_data_in[NX][i] = -2; int_data_out[NX][i] = 0; } /* * Read data from hyperslab in the file into the hyperslab in * memory and display. */ if(H5Dread(dataset, H5T_NATIVE_LLONG, H5S_ALL, H5S_ALL, H5P_DEFAULT, int_data_out) < 0) TEST_ERROR; /* Check results */ for (j=0; j<(NX+1); j++) { for (i=0; i<NY; i++) { if (int_data_out[j][i] != int_data_in[j][i]) { if (!nerrors++) { H5_FAILED(); printf("element [%d][%d] is %d but should have been %d\n", j, i, (int)int_data_out[j][i], (int)int_data_in[j][i]); } } } } /* * Close/release resources. */ if(H5Dclose(dataset) < 0) TEST_ERROR /* Failure */ if (nerrors) { printf("total of %d errors out of %d elements\n", nerrors, NX*NY); return 1; } PASSED(); #else /*H5_HAVE_FILTER_SCALEOFFSET*/ SKIPPED(); puts(not_supported); #endif /*H5_HAVE_FILTER_SCALEOFFSET*/ TESTING("dataset of LE INT with scale-offset filter"); #ifdef H5_HAVE_FILTER_SCALEOFFSET /* * Open the dataset with scale-offset filter. */ if((dataset = H5Dopen2(file, DATASETNAME10, H5P_DEFAULT)) < 0) TEST_ERROR; /* * Data and output buffer initialization. */ for (j = 0; j < NX; j++) { for (i = 0; i < NY; i++) { int_data_in[j][i] = i + j; int_data_out[j][i] = 0; } } for (i = 0; i < NY; i++) { int_data_in[NX][i] = -2; int_data_out[NX][i] = 0; } /* * Read data from hyperslab in the file into the hyperslab in * memory and display. */ if(H5Dread(dataset, H5T_NATIVE_LLONG, H5S_ALL, H5S_ALL, H5P_DEFAULT, int_data_out) < 0) TEST_ERROR; /* Check results */ for (j=0; j<(NX+1); j++) { for (i=0; i<NY; i++) { if (int_data_out[j][i] != int_data_in[j][i]) { if (!nerrors++) { H5_FAILED(); printf("element [%d][%d] is %d but should have been %d\n", j, i, (int)int_data_out[j][i], (int)int_data_in[j][i]); } } } } /* * Close/release resources. */ if(H5Dclose(dataset) < 0) TEST_ERROR /* Failure */ if (nerrors) { printf("total of %d errors out of %d elements\n", nerrors, NX*NY); return 1; } PASSED(); #else /*H5_HAVE_FILTER_SCALEOFFSET*/ SKIPPED(); puts(not_supported); #endif /*H5_HAVE_FILTER_SCALEOFFSET*/ TESTING("dataset of BE INT with scale-offset filter"); #ifdef H5_HAVE_FILTER_SCALEOFFSET /* * Open the dataset with scale-offset filter. */ if((dataset = H5Dopen2(file, DATASETNAME11, H5P_DEFAULT)) < 0) TEST_ERROR; /* * Data and output buffer initialization. */ for (j = 0; j < NX; j++) { for (i = 0; i < NY; i++) { int_data_in[j][i] = i + j; int_data_out[j][i] = 0; } } for (i = 0; i < NY; i++) { int_data_in[NX][i] = -2; int_data_out[NX][i] = 0; } /* * Read data from hyperslab in the file into the hyperslab in * memory and display. */ if(H5Dread(dataset, H5T_NATIVE_LLONG, H5S_ALL, H5S_ALL, H5P_DEFAULT, int_data_out) < 0) TEST_ERROR; /* Check results */ for (j=0; j<(NX+1); j++) { for (i=0; i<NY; i++) { if (int_data_out[j][i] != int_data_in[j][i]) { if (!nerrors++) { H5_FAILED(); printf("element [%d][%d] is %d but should have been %d\n", j, i, (int)int_data_out[j][i], (int)int_data_in[j][i]); } } } } /* * Close/release resources. */ if(H5Dclose(dataset) < 0) TEST_ERROR /* Failure */ if (nerrors) { printf("total of %d errors out of %d elements\n", nerrors, NX*NY); return 1; } PASSED(); #else /*H5_HAVE_FILTER_SCALEOFFSET*/ SKIPPED(); puts(not_supported); #endif /*H5_HAVE_FILTER_SCALEOFFSET*/ TESTING("dataset of LE LONG LONG with scale-offset filter"); #ifdef H5_HAVE_FILTER_SCALEOFFSET /* * Open the dataset with scale-offset filter. */ if((dataset = H5Dopen2(file, DATASETNAME12, H5P_DEFAULT)) < 0) TEST_ERROR; /* * Data and output buffer initialization. */ for (j = 0; j < NX; j++) { for (i = 0; i < NY; i++) { int_data_in[j][i] = i + j; int_data_out[j][i] = 0; } } for (i = 0; i < NY; i++) { int_data_in[NX][i] = -2; int_data_out[NX][i] = 0; } /* * Read data from hyperslab in the file into the hyperslab in * memory and display. */ if(H5Dread(dataset, H5T_NATIVE_LLONG, H5S_ALL, H5S_ALL, H5P_DEFAULT, int_data_out) < 0) TEST_ERROR; /* Check results */ for (j=0; j<(NX+1); j++) { for (i=0; i<NY; i++) { if (int_data_out[j][i] != int_data_in[j][i]) { if (!nerrors++) { H5_FAILED(); printf("element [%d][%d] is %d but should have been %d\n", j, i, (int)int_data_out[j][i], (int)int_data_in[j][i]); } } } } /* * Close/release resources. */ if(H5Dclose(dataset) < 0) TEST_ERROR /* Failure */ if (nerrors) { printf("total of %d errors out of %d elements\n", nerrors, NX*NY); return 1; } PASSED(); #else /*H5_HAVE_FILTER_SCALEOFFSET*/ SKIPPED(); puts(not_supported); #endif /*H5_HAVE_FILTER_SCALEOFFSET*/ TESTING("dataset of BE LONG LONG with scale-offset filter"); #ifdef H5_HAVE_FILTER_SCALEOFFSET /* * Open the dataset with scale-offset filter. */ if((dataset = H5Dopen2(file, DATASETNAME13, H5P_DEFAULT)) < 0) TEST_ERROR; /* * Data and output buffer initialization. */ for (j = 0; j < NX; j++) { for (i = 0; i < NY; i++) { int_data_in[j][i] = i + j; int_data_out[j][i] = 0; } } for (i = 0; i < NY; i++) { int_data_in[NX][i] = -2; int_data_out[NX][i] = 0; } /* * Read data from hyperslab in the file into the hyperslab in * memory and display. */ if(H5Dread(dataset, H5T_NATIVE_LLONG, H5S_ALL, H5S_ALL, H5P_DEFAULT, int_data_out) < 0) TEST_ERROR; /* Check results */ for (j=0; j<(NX+1); j++) { for (i=0; i<NY; i++) { if (int_data_out[j][i] != int_data_in[j][i]) { if (!nerrors++) { H5_FAILED(); printf("element [%d][%d] is %d but should have been %d\n", j, i, (int)int_data_out[j][i], (int)int_data_in[j][i]); } } } } /* * Close/release resources. */ if(H5Dclose(dataset) < 0) TEST_ERROR /* Failure */ if (nerrors) { printf("total of %d errors out of %d elements\n", nerrors, NX*NY); return 1; } PASSED(); #else /*H5_HAVE_FILTER_SCALEOFFSET*/ SKIPPED(); puts(not_supported); #endif /*H5_HAVE_FILTER_SCALEOFFSET*/ if(H5Fclose(file)) TEST_ERROR return 0; error: H5E_BEGIN_TRY { H5Fclose(file); } H5E_END_TRY; return 1; }
/*------------------------------------------------------------------------- * Function: test_dataset_read_with_filters * * Purpose: Tests reading datasets created with dynamically-loaded * filter plugins. * * Return: SUCCEED/FAIL * *------------------------------------------------------------------------- */ static herr_t test_dataset_read_with_filters(hid_t fid) { hid_t did = -1; /* Dataset ID */ /*---------------------------------------------------------- * STEP 1: Test deflation by itself. *---------------------------------------------------------- */ TESTING("dataset read I/O with deflate filter"); #ifdef H5_HAVE_FILTER_DEFLATE if (H5Zfilter_avail(H5Z_FILTER_DEFLATE) != TRUE) TEST_ERROR; if ((did = H5Dopen2(fid, DSET_DEFLATE_NAME, H5P_DEFAULT)) < 0) TEST_ERROR; if (test_read_data(did, orig_deflate_g[0]) < 0) TEST_ERROR; if (H5Dclose(did) < 0) TEST_ERROR; #else /* H5_HAVE_FILTER_DEFLATE */ SKIPPED(); HDputs(" Deflate filter not enabled"); #endif /* H5_HAVE_FILTER_DEFLATE */ /*---------------------------------------------------------- * STEP 2: Test filter plugin 1 by itself. *---------------------------------------------------------- */ TESTING(" dataset reads with filter plugin 1"); if ((did = H5Dopen2(fid, DSET_FILTER1_NAME, H5P_DEFAULT)) < 0) TEST_ERROR; if (test_read_data(did, orig_dynlib1_g[0]) < 0) TEST_ERROR; if (H5Dclose(did) < 0) TEST_ERROR; /*---------------------------------------------------------- * STEP 3: Test filter plugin 2 by itself. *---------------------------------------------------------- */ TESTING(" dataset reads with filter plugin 2"); if ((did = H5Dopen2(fid, DSET_FILTER2_NAME, H5P_DEFAULT)) < 0) TEST_ERROR; if (test_read_data(did, orig_dynlib2_g[0]) < 0) TEST_ERROR; if (H5Dclose(did) < 0) TEST_ERROR; /*---------------------------------------------------------- * STEP 4: Test filter plugin 3 by itself. *---------------------------------------------------------- */ TESTING(" dataset reads with filter plugin 3"); if ((did = H5Dopen2(fid, DSET_FILTER3_NAME, H5P_DEFAULT)) < 0) TEST_ERROR; if (test_read_data(did, orig_dynlib4_g[0]) < 0) TEST_ERROR; if (H5Dclose(did) < 0) TEST_ERROR; return SUCCEED; error: /* Clean up objects used for this test */ H5E_BEGIN_TRY { H5Dclose(did); } H5E_END_TRY return FAIL; } /* end test_dataset_read_with_filters() */
/*------------------------------------------------------------------------- * Function: test_dataset_write_with_filters * * Purpose: Tests creating datasets and writing data with dynamically loaded filters * * Return: SUCCEED/FAIL * *------------------------------------------------------------------------- */ static herr_t test_dataset_write_with_filters(hid_t fid) { hid_t dcpl_id = -1; /* Dataset creation property list ID */ unsigned int compress_level; /* Deflate compression level */ unsigned int filter1_data; /* Data used by filter 1 */ unsigned int libver_values[4]; /* Used w/ the filter that makes HDF5 calls */ /*---------------------------------------------------------- * STEP 1: Test deflation by itself. *---------------------------------------------------------- */ HDputs("Testing dataset writes with deflate filter"); #ifdef H5_HAVE_FILTER_DEFLATE if ((dcpl_id = H5Pcreate(H5P_DATASET_CREATE)) < 0) TEST_ERROR; if (H5Pset_chunk(dcpl_id, 2, chunk_sizes_g) < 0) TEST_ERROR; compress_level = 6; if (H5Pset_deflate(dcpl_id, compress_level) < 0) TEST_ERROR; /* Ensure the filter works */ if (ensure_filter_works(fid, DSET_DEFLATE_NAME, dcpl_id) < 0) TEST_ERROR; /* Clean up objects used for this test */ if (H5Pclose(dcpl_id) < 0) TEST_ERROR; #else /* H5_HAVE_FILTER_DEFLATE */ SKIPPED(); HDputs(" Deflate filter not enabled"); #endif /* H5_HAVE_FILTER_DEFLATE */ /*---------------------------------------------------------- * STEP 2: Test filter plugin 1 by itself. *---------------------------------------------------------- */ HDputs(" dataset writes with filter plugin 1"); if ((dcpl_id = H5Pcreate(H5P_DATASET_CREATE)) < 0) TEST_ERROR; if (H5Pset_chunk(dcpl_id, 2, chunk_sizes_g) < 0) TEST_ERROR; /* Set up the filter, passing in the amount the filter will add and subtract * from each data element. Note that this value has an arbitrary max of 9. */ filter1_data = 9; if (H5Pset_filter(dcpl_id, FILTER1_ID, H5Z_FLAG_MANDATORY, (size_t)1, &filter1_data) < 0) TEST_ERROR; /* Ensure the filter works */ if (ensure_filter_works(fid, DSET_FILTER1_NAME, dcpl_id) < 0) TEST_ERROR; /* Clean up objects used for this test */ if (H5Pclose(dcpl_id) < 0) TEST_ERROR; /* Unregister the dynamic filter for testing purpose. The next time when this test is run for * the new file format, the library's H5PL code has to search in the table of loaded plugin libraries * for this filter. */ if (H5Zunregister(FILTER1_ID) < 0) TEST_ERROR; /*---------------------------------------------------------- * STEP 3: Test filter plugin 2 by itself. *---------------------------------------------------------- */ HDputs(" dataset writes with filter plugin 2"); if ((dcpl_id = H5Pcreate(H5P_DATASET_CREATE)) < 0) TEST_ERROR; if (H5Pset_chunk(dcpl_id, 2, chunk_sizes_g) < 0) TEST_ERROR; if (H5Pset_filter(dcpl_id, FILTER2_ID, H5Z_FLAG_MANDATORY, 0, NULL) < 0) TEST_ERROR; /* Ensure the filter works */ if (ensure_filter_works(fid, DSET_FILTER2_NAME, dcpl_id) < 0) TEST_ERROR; /* Clean up objects used for this test */ if (H5Pclose(dcpl_id) < 0) TEST_ERROR; /* Unregister the dynamic filter for testing purpose. The next time when this test is run for * the new file format, the library's H5PL code has to search in the table of loaded plugin libraries * for this filter. */ if (H5Zunregister(FILTER2_ID) < 0) TEST_ERROR; /*---------------------------------------------------------- * STEP 4: Test filter plugin 3 by itself. * (This filter plugin makes HDF5 API calls) *---------------------------------------------------------- */ HDputs(" dataset writes with filter plugin 3"); if ((dcpl_id = H5Pcreate(H5P_DATASET_CREATE)) < 0) TEST_ERROR; if (H5Pset_chunk(dcpl_id, 2, chunk_sizes_g) < 0) TEST_ERROR; /* Set the add/subtract value for the filter */ libver_values[0] = 9; /* Get the library bounds and add to the filter data */ if (H5get_libversion(&libver_values[1], &libver_values[2], &libver_values[3]) < 0) TEST_ERROR; if (H5Pset_filter(dcpl_id, FILTER3_ID, H5Z_FLAG_MANDATORY, (size_t)4, libver_values) < 0) TEST_ERROR; /* Ensure the filter works */ if (ensure_filter_works(fid, DSET_FILTER3_NAME, dcpl_id) < 0) TEST_ERROR; /* Clean up objects used for this test */ if (H5Pclose(dcpl_id) < 0) TEST_ERROR; /* Unregister the dynamic filter for testing purpose. The next time when this test is run for * the new file format, the library's H5PL code has to search in the table of loaded plugin libraries * for this filter. */ if (H5Zunregister(FILTER3_ID) < 0) TEST_ERROR; return SUCCEED; error: /* Clean up objects used for this test */ H5E_BEGIN_TRY { H5Pclose(dcpl_id); } H5E_END_TRY return FAIL; } /* end test_dataset_write_with_filters() */
/*------------------------------------------------------------------------- * Function: test_filters_for_datasets * * Purpose: Tests creating datasets and writing data with dynamically * loaded filters * * Return: Success: 0 * Failure: -1 * * Programmer: Raymond Lu * 14 March 2013 * *------------------------------------------------------------------------- */ static herr_t test_filters_for_datasets(hid_t file) { hid_t dc; /* Dataset creation property list ID */ const hsize_t chunk_size[2] = {FILTER_CHUNK_DIM1, FILTER_CHUNK_DIM2}; /* Chunk dimensions */ unsigned int compress_level = 9; /*---------------------------------------------------------- * STEP 1: Test deflation by itself. *---------------------------------------------------------- */ #ifdef H5_HAVE_FILTER_DEFLATE puts("Testing deflate filter"); if((dc = H5Pcreate(H5P_DATASET_CREATE)) < 0) goto error; if(H5Pset_chunk (dc, 2, chunk_size) < 0) goto error; if(H5Pset_deflate (dc, 6) < 0) goto error; if(test_filter_internal(file,DSET_DEFLATE_NAME,dc) < 0) goto error; /* Clean up objects used for this test */ if(H5Pclose (dc) < 0) goto error; #else /* H5_HAVE_FILTER_DEFLATE */ TESTING("deflate filter"); SKIPPED(); puts(" Deflate filter not enabled"); #endif /* H5_HAVE_FILTER_DEFLATE */ /*---------------------------------------------------------- * STEP 2: Test DYNLIB1 by itself. *---------------------------------------------------------- */ puts("Testing DYNLIB1 filter"); if((dc = H5Pcreate(H5P_DATASET_CREATE)) < 0) goto error; if(H5Pset_chunk (dc, 2, chunk_size) < 0) goto error; if(H5Pset_filter (dc, H5Z_FILTER_DYNLIB1, H5Z_FLAG_MANDATORY, (size_t)1, &compress_level) < 0) goto error; if(test_filter_internal(file,DSET_DYNLIB1_NAME,dc) < 0) goto error; /* Clean up objects used for this test */ if(H5Pclose (dc) < 0) goto error; /* Unregister the dynamic filter DYNLIB1 for testing purpose. The next time when this test is run for * the new file format, the library's H5PL code has to search in the table of loaded plugin libraries * for this filter. */ if(H5Zunregister(H5Z_FILTER_DYNLIB1) < 0) goto error; /*---------------------------------------------------------- * STEP 3: Test DYNLIB2 by itself. *---------------------------------------------------------- */ puts("Testing DYNLIB2 filter"); if((dc = H5Pcreate(H5P_DATASET_CREATE)) < 0) goto error; if(H5Pset_chunk (dc, 2, chunk_size) < 0) goto error; if(H5Pset_filter (dc, H5Z_FILTER_DYNLIB2, H5Z_FLAG_MANDATORY, 0, NULL) < 0) goto error; if(test_filter_internal(file,DSET_DYNLIB2_NAME,dc) < 0) goto error; /* Clean up objects used for this test */ if(H5Pclose (dc) < 0) goto error; /* Unregister the dynamic filter DYNLIB2 for testing purpose. The next time when this test is run for * the new file format, the library's H5PL code has to search in the table of loaded plugin libraries * for this filter. */ if(H5Zunregister(H5Z_FILTER_DYNLIB2) < 0) goto error; return 0; error: return -1; }
/*------------------------------------------------------------------------- * Function: reader * * Purpose: Reads some data from random locations in the dataset. * * Return: Success: 0 * * Failure: >0 * * Programmer: Robb Matzke * Friday, April 10, 1998 * * Modifications: * *------------------------------------------------------------------------- */ static int reader(char *filename, hid_t fapl) { FILE *script = NULL; hid_t file = -1, mspace = -1, fspace = -1, d2 = -1; char ln[128], *s; hsize_t hs_offset[1]; hsize_t hs_size[1] = {WRT_SIZE}; int *buf = (int *)HDmalloc(sizeof(int) * WRT_SIZE); int i, j, zero, wrong, nerrors = 0; /* Open script file */ script = HDfopen(DNAME, "r"); /* Open HDF5 file */ if((file = H5Fopen(filename, H5F_ACC_RDONLY, fapl)) < 0) FAIL_STACK_ERROR /* Open the dataset */ if((d2 = H5Dopen2(file, "d2", H5P_DEFAULT)) < 0) FAIL_STACK_ERROR if((fspace = H5Dget_space(d2)) < 0) FAIL_STACK_ERROR /* Describe `buf' */ if((mspace = H5Screate_simple(1, hs_size, hs_size)) < 0) FAIL_STACK_ERROR /* Read each region */ while(HDfgets(ln, (int)sizeof(ln), script)) { if('#' != ln[0]) break; i = (int)HDstrtol(ln + 1, &s, 10); hs_offset[0] = HDstrtoll(s, NULL, 0); HDfprintf(stdout, "#%03d 0x%016Hx%47s", i, hs_offset[0], ""); HDfflush(stdout); if(H5Sselect_hyperslab(fspace, H5S_SELECT_SET, hs_offset, NULL, hs_size, NULL) < 0) FAIL_STACK_ERROR if(H5Dread(d2, H5T_NATIVE_INT, mspace, fspace, H5P_DEFAULT, buf) < 0) FAIL_STACK_ERROR /* Check */ for(j = zero = wrong = 0; j < WRT_SIZE; j++) { if(0 == buf[j]) zero++; else if(buf[j] != i + 1) wrong++; } if(zero) { H5_FAILED(); printf(" %d zero%s\n", zero, 1 == zero ? "" : "s"); } else if(wrong) { SKIPPED(); HDputs(" Possible overlap with another region."); nerrors++; } else { PASSED(); } } if(H5Dclose(d2) < 0) FAIL_STACK_ERROR if(H5Sclose(mspace) < 0) FAIL_STACK_ERROR if(H5Sclose(fspace) < 0) FAIL_STACK_ERROR if(H5Fclose(file) < 0) FAIL_STACK_ERROR HDfree(buf); HDfclose(script); return nerrors; error: H5E_BEGIN_TRY { H5Dclose(d2); H5Sclose(mspace); H5Sclose(fspace); H5Fclose(file); } H5E_END_TRY; if(buf) HDfree(buf); if(script) HDfclose(script); return 1; }
/*------------------------------------------------------------------------- * Function: test_windows * * Purpose: Tests the file handle interface for WINDOWS driver * * Return: Success: 0 * Failure: -1 * * Programmer: Dana Robinson * Tuesday, March 22, 2011 * *------------------------------------------------------------------------- */ static herr_t test_windows(void) { #ifdef H5_HAVE_WINDOWS hid_t file = -1; hid_t fapl = -1; hid_t access_fapl = -1; char filename[1024]; int *fhandle = NULL; hsize_t file_size = 0; #endif /*H5_HAVE_WINDOWS*/ TESTING("WINDOWS file driver"); #ifndef H5_HAVE_WINDOWS SKIPPED(); return 0; #else /* H5_HAVE_WINDOWS */ /* Set property list and file name for WINDOWS driver. */ fapl = h5_fileaccess(); if(H5Pset_fapl_windows(fapl) < 0) TEST_ERROR; h5_fixname(FILENAME[8], fapl, filename, sizeof filename); if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR; /* Retrieve the access property list... */ if((access_fapl = H5Fget_access_plist(file)) < 0) TEST_ERROR; /* Check that the driver is correct */ if(H5FD_WINDOWS!= H5Pget_driver(access_fapl)) TEST_ERROR; /* ...and close the property list */ if(H5Pclose(access_fapl) < 0) TEST_ERROR; /* Check file handle API */ if(H5Fget_vfd_handle(file, H5P_DEFAULT, (void **)&fhandle) < 0) TEST_ERROR; if(*fhandle < 0) TEST_ERROR; /* Check file size API */ if(H5Fget_filesize(file, &file_size) < 0) TEST_ERROR; /* There is no guarantee the size of metadata in file is constant. * Just try to check if it's reasonable. It's 2KB right now. */ if(file_size < 1 * KB || file_size > 4 * KB) TEST_ERROR; if(H5Fclose(file) < 0) TEST_ERROR; h5_cleanup(FILENAME, fapl); PASSED(); return 0; error: H5E_BEGIN_TRY { H5Pclose(fapl); H5Fclose(file); } H5E_END_TRY; return -1; #endif /* H5_HAVE_WINDOWS */ }
/*------------------------------------------------------------------------- * Function: open_dataset * * Purpose: Handle each dataset from the data file. * * Return: Success: 0 * Failure: Number of failures * * Programmer: Raymond Lu * 21 January 2011 * * Modifications: * *------------------------------------------------------------------------- */ static int open_dataset(char *fname) { const char *pathname = H5_get_srcdir_filename(fname); /* Corrected test file name */ hid_t file; /* handles */ unsigned nerrors = 0; const char *not_supported= " filter is not enabled."; /* * Open the file. */ if((file = H5Fopen(pathname, H5F_ACC_RDONLY, H5P_DEFAULT)) < 0) TEST_ERROR; TESTING("regular dataset of LE DOUBLE"); nerrors += check_data(DATASETNAME, file, TRUE); TESTING("regular dataset of BE DOUBLE"); nerrors += check_data(DATASETNAME1, file, TRUE); TESTING("dataset of LE FLOAT with scale-offset filter"); #ifdef H5_HAVE_FILTER_SCALEOFFSET nerrors += check_data(DATASETNAME2, file, TRUE); #else /*H5_HAVE_FILTER_SCALEOFFSET*/ SKIPPED(); puts(not_supported); #endif /*H5_HAVE_FILTER_SCALEOFFSET*/ TESTING("dataset of BE FLOAT with scale-offset filter"); #ifdef H5_HAVE_FILTER_SCALEOFFSET nerrors += check_data(DATASETNAME3, file, TRUE); #else /*H5_HAVE_FILTER_SCALEOFFSET*/ SKIPPED(); puts(not_supported); #endif /*H5_HAVE_FILTER_SCALEOFFSET*/ TESTING("dataset of LE DOUBLE with scale-offset filter"); #ifdef H5_HAVE_FILTER_SCALEOFFSET nerrors += check_data(DATASETNAME4, file, TRUE); #else /*H5_HAVE_FILTER_SCALEOFFSET*/ SKIPPED(); puts(not_supported); #endif /*H5_HAVE_FILTER_SCALEOFFSET*/ TESTING("dataset of BE DOUBLE with scale-offset filter"); #ifdef H5_HAVE_FILTER_SCALEOFFSET nerrors += check_data(DATASETNAME5, file, TRUE); #else /*H5_HAVE_FILTER_SCALEOFFSET*/ SKIPPED(); puts(not_supported); #endif /*H5_HAVE_FILTER_SCALEOFFSET*/ TESTING("dataset of LE CHAR with scale-offset filter"); #ifdef H5_HAVE_FILTER_SCALEOFFSET nerrors += check_data(DATASETNAME6, file, FALSE); #else /*H5_HAVE_FILTER_SCALEOFFSET*/ SKIPPED(); puts(not_supported); #endif /*H5_HAVE_FILTER_SCALEOFFSET*/ TESTING("dataset of BE CHAR with scale-offset filter"); #ifdef H5_HAVE_FILTER_SCALEOFFSET nerrors += check_data(DATASETNAME7, file, FALSE); #else /*H5_HAVE_FILTER_SCALEOFFSET*/ SKIPPED(); puts(not_supported); #endif /*H5_HAVE_FILTER_SCALEOFFSET*/ TESTING("dataset of LE SHORT with scale-offset filter"); #ifdef H5_HAVE_FILTER_SCALEOFFSET nerrors += check_data(DATASETNAME8, file, FALSE); #else /*H5_HAVE_FILTER_SCALEOFFSET*/ SKIPPED(); puts(not_supported); #endif /*H5_HAVE_FILTER_SCALEOFFSET*/ TESTING("dataset of BE SHORT with scale-offset filter"); #ifdef H5_HAVE_FILTER_SCALEOFFSET nerrors += check_data(DATASETNAME9, file, FALSE); #else /*H5_HAVE_FILTER_SCALEOFFSET*/ SKIPPED(); puts(not_supported); #endif /*H5_HAVE_FILTER_SCALEOFFSET*/ TESTING("dataset of LE INT with scale-offset filter"); #ifdef H5_HAVE_FILTER_SCALEOFFSET nerrors += check_data(DATASETNAME10, file, FALSE); #else /*H5_HAVE_FILTER_SCALEOFFSET*/ SKIPPED(); puts(not_supported); #endif /*H5_HAVE_FILTER_SCALEOFFSET*/ TESTING("dataset of BE INT with scale-offset filter"); #ifdef H5_HAVE_FILTER_SCALEOFFSET nerrors += check_data(DATASETNAME11, file, FALSE); #else /*H5_HAVE_FILTER_SCALEOFFSET*/ SKIPPED(); puts(not_supported); #endif /*H5_HAVE_FILTER_SCALEOFFSET*/ TESTING("dataset of LE LONG LONG with scale-offset filter"); #ifdef H5_HAVE_FILTER_SCALEOFFSET nerrors += check_data(DATASETNAME12, file, FALSE); #else /*H5_HAVE_FILTER_SCALEOFFSET*/ SKIPPED(); puts(not_supported); #endif /*H5_HAVE_FILTER_SCALEOFFSET*/ TESTING("dataset of BE LONG LONG with scale-offset filter"); #ifdef H5_HAVE_FILTER_SCALEOFFSET nerrors += check_data(DATASETNAME13, file, FALSE); #else /*H5_HAVE_FILTER_SCALEOFFSET*/ SKIPPED(); puts(not_supported); #endif /*H5_HAVE_FILTER_SCALEOFFSET*/ TESTING("dataset of LE FLOAT with Fletcher32 filter"); #ifdef H5_HAVE_FILTER_FLETCHER32 nerrors += check_data(DATASETNAME14, file, TRUE); #else /*H5_HAVE_FILTER_FLETCHER32*/ SKIPPED(); puts(not_supported); #endif /*H5_HAVE_FILTER_FLETCHER32*/ TESTING("dataset of BE FLOAT with Fletcher32 filter"); #ifdef H5_HAVE_FILTER_FLETCHER32 nerrors += check_data(DATASETNAME15, file, TRUE); #else /*H5_HAVE_FILTER_FLETCHER32*/ SKIPPED(); puts(not_supported); #endif /*H5_HAVE_FILTER_FLETCHER32*/ TESTING("dataset of LE FLOAT with Deflate filter"); #ifdef H5_HAVE_FILTER_DEFLATE nerrors += check_data(DATASETNAME16, file, TRUE); #else /*H5_HAVE_FILTER_DEFLATE*/ SKIPPED(); puts(not_supported); #endif /*H5_HAVE_FILTER_DEFLATE*/ TESTING("dataset of BE FLOAT with Deflate filter"); #ifdef H5_HAVE_FILTER_DEFLATE nerrors += check_data(DATASETNAME17, file, TRUE); #else /*H5_HAVE_FILTER_DEFLATE*/ SKIPPED(); puts(not_supported); #endif /*H5_HAVE_FILTER_DEFLATE*/ TESTING("dataset of LE FLOAT with Szip filter"); #ifdef H5_HAVE_FILTER_SZIP nerrors += check_data(DATASETNAME18, file, TRUE); #else /*H5_HAVE_FILTER_SZIP*/ SKIPPED(); puts(not_supported); #endif /*H5_HAVE_FILTER_SZIP*/ TESTING("dataset of BE FLOAT with Szip filter"); #ifdef H5_HAVE_FILTER_SZIP nerrors += check_data(DATASETNAME19, file, TRUE); #else /*H5_HAVE_FILTER_SZIP*/ SKIPPED(); puts(not_supported); #endif /*H5_HAVE_FILTER_SZIP*/ TESTING("dataset of LE FLOAT with Shuffle filter"); #ifdef H5_HAVE_FILTER_SHUFFLE nerrors += check_data(DATASETNAME20, file, TRUE); #else /*H5_HAVE_FILTER_SHUFFLE*/ SKIPPED(); puts(not_supported); #endif /*H5_HAVE_FILTER_SHUFFLE*/ TESTING("dataset of BE FLOAT with Shuffle filter"); #ifdef H5_HAVE_FILTER_SHUFFLE nerrors += check_data(DATASETNAME21, file, TRUE); #else /*H5_HAVE_FILTER_SHUFFLE*/ SKIPPED(); puts(not_supported); #endif /*H5_HAVE_FILTER_SHUFFLE*/ TESTING("dataset of LE FLOAT with Nbit filter"); #ifdef H5_HAVE_FILTER_NBIT nerrors += check_data(DATASETNAME22, file, TRUE); #else /*H5_HAVE_FILTER_NBIT*/ SKIPPED(); puts(not_supported); #endif /*H5_HAVE_FILTER_NBIT*/ TESTING("dataset of BE FLOAT with Nbit filter"); #ifdef H5_HAVE_FILTER_NBIT nerrors += check_data(DATASETNAME23, file, TRUE); #else /*H5_HAVE_FILTER_NBIT*/ SKIPPED(); puts(not_supported); #endif /*H5_HAVE_FILTER_NBIT*/ if(H5Fclose(file)) TEST_ERROR return 0; error: H5E_BEGIN_TRY { H5Fclose(file); } H5E_END_TRY; return nerrors; }
/*------------------------------------------------------------------------- * Function: test_queue_threaded * * Purpose: Tests that the queue behaves correctly in a multithreaded * environment. Creates many enqueuers and one dequeuer, and * makes sure that elements are dequeued in the expected order. * * Return: Success: 0 * Failure: 1 * * Programmer: Neil Fortner * Wednesday, April 1, 2009 * * Modifications: * *------------------------------------------------------------------------- */ static int test_queue_threaded(threaded_mode_t mode) { #if defined(OPA_HAVE_PTHREAD_H) pthread_t *threads = NULL; /* Threads */ pthread_attr_t ptattr; /* Thread attributes */ static threaded_t *thread_data = NULL; /* User data structs for threads */ OPA_Queue_info_t qhead; /* The queue */ void *ret; /* Thread return value */ unsigned nthreads = num_threads[curr_test]; int nerrors = 0; /* number of errors */ int i; switch (mode) { case THREADED_MODE_DEFAULT: TESTING("multithreaded queue", nthreads); break; case THREADED_MODE_EMPTY: TESTING("multithreaded queue (empty queue)", nthreads); break; case THREADED_MODE_FULL: TESTING("multithreaded queue (full queue)", nthreads); break; default: FAIL_OP_ERROR(printf(" Unknown mode\n")); } /* end switch */ /* Allocate array of threads */ if (NULL == (threads = (pthread_t *) malloc(nthreads * sizeof(pthread_t)))) TEST_ERROR; /* Set threads to be joinable */ pthread_attr_init(&ptattr); pthread_attr_setdetachstate(&ptattr, PTHREAD_CREATE_JOINABLE); /* Allocate array of thread data */ if (NULL == (thread_data = (threaded_t *) calloc(nthreads, sizeof(threaded_t)))) TEST_ERROR; /* Initialize queue */ OPA_Queue_init(&qhead); /* Initialize thread data structs */ for (i = 0; i < nthreads; i++) { thread_data[i].qhead = &qhead; thread_data[i].threadno = i; thread_data[i].mode = mode; } /* end for */ /* Create the threads. */ for (i = 0; i < (nthreads - 1); i++) if (pthread_create(&threads[i], &ptattr, test_queue_threaded_enqueue, &thread_data[i])) TEST_ERROR; nerrors = test_queue_threaded_dequeue(&thread_data[i]); /* Free the attribute */ if (pthread_attr_destroy(&ptattr)) TEST_ERROR; /* Join the threads */ for (i = 0; i < (nthreads - 1); i++) { if (pthread_join(threads[i], &ret)) TEST_ERROR; if (ret) nerrors++; } /* end for */ /* Check for errors */ if (nerrors) FAIL_OP_ERROR(printf(" Unexpected return from %d thread%s\n", nerrors, nerrors == 1 ? "" : "s")); /* Free memory */ free(threads); free(thread_data); PASSED(); #else /* OPA_HAVE_PTHREAD_H */ TESTING("multithreaded queue", 0); SKIPPED(); puts(" pthread.h not available"); #endif /* OPA_HAVE_PTHREAD_H */ return 0; #if defined(OPA_HAVE_PTHREAD_H) error: if (threads) free(threads); if (thread_data) free(thread_data); return 1; #endif /* OPA_HAVE_PTHREAD_H */ } /* end test_barriers_linear_array() */