/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Copyright by The HDF Group. * * All rights reserved. * * * * This file is part of HDF5. The full HDF5 copyright notice, including * * terms governing use, modification, and redistribution, is contained in * * the files COPYING and Copyright.html. COPYING can be found at the root * * of the source code distribution tree; Copyright.html can be found at the * * root level of an installed copy of the electronic document set and is * * linked from the top-level documents page. It can also be found at * * http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have access * * to either file, you may request a copy from help@hdfgroup.org. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* * Programmer: Raymond Lu * 13 February 2013 * * Purpose: Tests the plugin module (H5PL) */ #include "h5test.h" #include "H5srcdir.h" /* * This file needs to access private datatypes from the H5Z and H5PL package. */ #define H5PL_FRIEND #include "H5PLpkg.h" #define H5Z_FRIEND #include "H5Zpkg.h" /* Filters for HDF5 internal test */ #define H5Z_FILTER_DYNLIB1 257 #define H5Z_FILTER_DYNLIB2 258 #define H5Z_FILTER_DYNLIB3 259 #define H5Z_FILTER_DYNLIB4 260 const char *FILENAME[] = { "plugin", NULL }; #define FILENAME_BUF_SIZE 1024 /* Dataset names for testing filters */ #define DSET_DEFLATE_NAME "deflate" #define DSET_DYNLIB1_NAME "dynlib1" #define DSET_DYNLIB2_NAME "dynlib2" #define DSET_DYNLIB4_NAME "dynlib4" /* Parameters for internal filter test */ #define FILTER_CHUNK_DIM1 2 #define FILTER_CHUNK_DIM2 25 #define FILTER_HS_OFFSET1 7 #define FILTER_HS_OFFSET2 30 #define FILTER_HS_SIZE1 4 #define FILTER_HS_SIZE2 50 /* Shared global arrays */ #define DSET_DIM1 100 #define DSET_DIM2 200 /* Limit random number within 20000 */ #define RANDOM_LIMIT 20000 #define GROUP_ITERATION 1000 int points_deflate[DSET_DIM1][DSET_DIM2], points_dynlib1[DSET_DIM1][DSET_DIM2], points_dynlib2[DSET_DIM1][DSET_DIM2], points_dynlib4[DSET_DIM1][DSET_DIM2], points_bzip2[DSET_DIM1][DSET_DIM2]; /*------------------------------------------------------------------------- * Function: test_filter_internal * * Purpose: Tests writing entire data and partial data with filters * * Return: Success: 0 * Failure: -1 * * Programmer: Raymond Lu * 27 February 2013 * *------------------------------------------------------------------------- */ static herr_t test_filter_internal(hid_t fid, const char *name, hid_t dcpl) { hid_t dataset; /* Dataset ID */ hid_t dxpl; /* Dataset xfer property list ID */ hid_t write_dxpl; /* Dataset xfer property list ID for writing */ hid_t sid; /* Dataspace ID */ const hsize_t size[2] = {DSET_DIM1, DSET_DIM2}; /* Dataspace dimensions */ const hsize_t hs_offset[2] = {FILTER_HS_OFFSET1, FILTER_HS_OFFSET2}; /* Hyperslab offset */ const hsize_t hs_size[2] = {FILTER_HS_SIZE1, FILTER_HS_SIZE2}; /* Hyperslab size */ void *tconv_buf = NULL; /* Temporary conversion buffer */ int points[DSET_DIM1][DSET_DIM2], check[DSET_DIM1][DSET_DIM2]; size_t i, j; /* Local index variables */ int n = 0; /* Create the data space */ if((sid = H5Screate_simple(2, size, NULL)) < 0) TEST_ERROR /* * Create a small conversion buffer to test strip mining. We * might as well test all we can! */ if((dxpl = H5Pcreate(H5P_DATASET_XFER)) < 0) TEST_ERROR tconv_buf = HDmalloc((size_t)1000); if(H5Pset_buffer(dxpl, (size_t)1000, tconv_buf, NULL) < 0) TEST_ERROR if((write_dxpl = H5Pcopy(dxpl)) < 0) TEST_ERROR; TESTING(" filters (setup)"); /* Check if all the filters are available */ if(H5Pall_filters_avail(dcpl)!=TRUE) { H5_FAILED(); HDprintf(" Line %d: Incorrect filter availability\n",__LINE__); TEST_ERROR } /* end if */ /* Create the dataset */ if((dataset = H5Dcreate2(fid, name, H5T_NATIVE_INT, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0) TEST_ERROR PASSED(); /*---------------------------------------------------------------------- * STEP 1: Read uninitialized data. It should be zero. *---------------------------------------------------------------------- */ TESTING(" filters (uninitialized read)"); if(H5Dread(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, dxpl, check) < 0) TEST_ERROR; for(i=0; i<(size_t)size[0]; i++) { for(j=0; j<(size_t)size[1]; j++) { if(0!=check[i][j]) { H5_FAILED(); HDprintf(" Read a non-zero value.\n"); HDprintf(" At index %lu,%lu\n", (unsigned long)i, (unsigned long)j); TEST_ERROR } } } PASSED(); /*---------------------------------------------------------------------- * STEP 2: Test filters by setting up a chunked dataset and writing * to it. *---------------------------------------------------------------------- */ TESTING(" filters (write)"); n = 0; for(i=0; i= 0) TEST_ERROR PASSED(); return 0; error: return -1; } /*------------------------------------------------------------------------- * Function: test_noread_with_filters * * Purpose: Tests reading dataset created with dynamically loaded filters disabled * * Return: Success: 0 * Failure: -1 * *------------------------------------------------------------------------- */ static herr_t test_noread_with_filters(hid_t file) { hid_t dset; /* Dataset ID */ unsigned plugin_state; /* status of plugins */ TESTING("DYNLIB1 filter with plugins disabled"); /* disable filter plugin */ if(H5PLget_loading_state(&plugin_state) < 0) TEST_ERROR plugin_state = plugin_state & ~H5PL_FILTER_PLUGIN; if(H5PLset_loading_state(plugin_state) < 0) TEST_ERROR if((dset = H5Dopen2(file,DSET_DYNLIB1_NAME,H5P_DEFAULT)) < 0) TEST_ERROR if(test_noread_data(dset) < 0) TEST_ERROR if(H5Dclose(dset) < 0) TEST_ERROR /* re-enable filter plugin */ plugin_state = plugin_state | H5PL_FILTER_PLUGIN; if(H5PLset_loading_state(plugin_state) < 0) TEST_ERROR return 0; error: /* re-enable filter plugin */ plugin_state = plugin_state | H5PL_FILTER_PLUGIN; if(H5PLset_loading_state(plugin_state) < 0) TEST_ERROR return -1; } /*------------------------------------------------------------------------- * Function: test_filters_for_groups * * Purpose: Tests creating group with dynamically loaded filters * * Return: Success: 0 * Failure: -1 * * Programmer: Raymond Lu * 1 April 2013 * *------------------------------------------------------------------------- */ static herr_t test_filters_for_groups(hid_t file) { hid_t gcpl, gid, group; int i; char gname[256]; TESTING("DYNLIB3 filter for group"); if((gcpl = H5Pcreate(H5P_GROUP_CREATE)) < 0) TEST_ERROR /* Use DYNLIB3 for creating groups */ if(H5Pset_filter (gcpl, H5Z_FILTER_DYNLIB3, H5Z_FLAG_MANDATORY, (size_t)0, NULL) < 0) TEST_ERROR /* Create a group using this filter */ if((gid = H5Gcreate2(file, "group1", H5P_DEFAULT, gcpl, H5P_DEFAULT)) < 0) TEST_ERROR /* Create multiple groups under "group1" */ for (i=0; i < GROUP_ITERATION; i++) { HDsprintf(gname, "group_%d", i); if((group = H5Gcreate2(gid, gname, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR if(H5Gclose(group) < 0) TEST_ERROR } /* Close the group */ if(H5Gclose(gid) < 0) TEST_ERROR /* Clean up objects used for this test */ if(H5Pclose (gcpl) < 0) TEST_ERROR PASSED(); return 0; error: return -1; } /*------------------------------------------------------------------------- * Function: test_groups_with_filters * * Purpose: Tests opening group with dynamically loaded filters * * Return: Success: 0 * Failure: -1 * * Programmer: Raymond Lu * 1 April 2013 * *------------------------------------------------------------------------- */ static herr_t test_groups_with_filters(hid_t file) { hid_t gid, group; int i; char gname[256]; TESTING("opening groups with DYNLIB3 filter"); /* Open the top group */ if((gid = H5Gopen2(file, "group1", H5P_DEFAULT)) < 0) TEST_ERROR /* Create multiple groups under "group1" */ for (i=0; i < GROUP_ITERATION; i++) { HDsprintf(gname, "group_%d", i); if((group = H5Gopen2(gid, gname, H5P_DEFAULT)) < 0) TEST_ERROR if(H5Gclose(group) < 0) TEST_ERROR } /* Close the group */ if(H5Gclose(gid) < 0) TEST_ERROR PASSED(); return 0; error: return -1; } /*------------------------------------------------------------------------- * Function: test_filter_path_apis * * Purpose: Tests accessing the path table for dynamically loaded filters * * Return: Success: 0 * Failure: -1 * *------------------------------------------------------------------------- */ static herr_t test_filter_path_apis(void) { int i; unsigned int ndx; herr_t ret; int pathlen = -1; char pathname[256]; HDputs("Testing access to the filter path table"); ndx = H5PLsize(); TESTING(" remove"); /* Remove all existing paths*/ for (i=ndx; i > 0; i--) { if (H5PLremove(i-1) < 0) { HDfprintf(stderr," at %d: %s\n", i, pathname); TEST_ERROR } } /* Verify the table is empty */ if (H5PLsize() > 0) TEST_ERROR PASSED(); TESTING(" remove (exceed)"); /* Exceed the min path removal */ H5E_BEGIN_TRY { ret = H5PLremove(0); } H5E_END_TRY if (ret >= 0) TEST_ERROR PASSED(); TESTING(" append"); /* Create multiple paths to fill table */ for (i=0; i < 16; i++) { HDsprintf(pathname, "a_path_%d", i); if (H5PLappend(pathname) < 0) { HDfprintf(stderr," at %d: %s\n", i, pathname); TEST_ERROR } } /* Verify the table is full */ if (H5PLsize() != 16) TEST_ERROR PASSED(); TESTING(" append (exceed)"); /* Exceed the max path append */ H5E_BEGIN_TRY { HDsprintf(pathname, "a_path_%d", 16); ret = H5PLappend(pathname); } H5E_END_TRY if (ret >= 0) TEST_ERROR /* Exceed the max path removal */ H5E_BEGIN_TRY { ret = H5PLremove(16); } H5E_END_TRY if (ret >= 0) TEST_ERROR PASSED(); TESTING(" get (path name)"); if ((pathlen = H5PLget(0, NULL, 0)) <= 0) { HDfprintf(stderr," get path 0 length failed\n"); TEST_ERROR } if (pathlen != 8) { TEST_ERROR } if ((pathlen = H5PLget(0, pathname, 256)) <= 0) { HDfprintf(stderr," get 0 len: %d : %s\n", pathlen, pathname); TEST_ERROR } if (strcmp(pathname, "a_path_0") != 0) { HDfprintf(stderr," get 0: %s\n", pathname); TEST_ERROR } PASSED(); TESTING(" get (bounds)"); if ((pathlen = H5PLget(1, pathname, 256)) <= 0) TEST_ERROR if (strcmp(pathname, "a_path_1") != 0) { HDfprintf(stderr," get 1: %s\n", pathname); TEST_ERROR } if ((pathlen = H5PLget(15, pathname, 256)) <= 0) TEST_ERROR if (strcmp(pathname, "a_path_15") != 0) { HDfprintf(stderr," get 15: %s\n", pathname); TEST_ERROR } PASSED(); TESTING(" get (bounds exceed)"); if ((pathlen = H5PLget(16, NULL, 0)) > 0) TEST_ERROR PASSED(); TESTING(" remove (verify for prepend)"); /* Remove one path*/ if (H5PLremove(8) < 0) TEST_ERROR /* Verify that the entries were moved */ if ((pathlen = H5PLget(8, pathname, 256)) <= 0) TEST_ERROR if (strcmp(pathname, "a_path_9") != 0) { HDfprintf(stderr," get 8: %s\n", pathname); TEST_ERROR } PASSED(); /* Verify the table is not full */ if (H5PLsize() != 15) TEST_ERROR TESTING(" prepend"); /* Prepend one path*/ HDsprintf(pathname, "a_path_%d", 17); if (H5PLprepend(pathname) < 0) { HDfprintf(stderr," prepend 17: %s\n", pathname); TEST_ERROR } /* Verify the table is full */ if (H5PLsize() != 16) TEST_ERROR /* Verify that the entries were moved */ if (H5PLget(8, pathname, 256) <= 0) TEST_ERROR if (strcmp(pathname, "a_path_7") != 0) { HDfprintf(stderr," get 8: %s\n", pathname); TEST_ERROR } if (H5PLget(0, pathname, 256) <= 0) TEST_ERROR if (strcmp(pathname, "a_path_17") != 0) { HDfprintf(stderr," get 0: %s\n", pathname); TEST_ERROR } PASSED(); TESTING(" prepend (exceed)"); /* Exceed the max path prepend */ H5E_BEGIN_TRY { HDsprintf(pathname, "a_path_%d", 18); ret = H5PLprepend(pathname); } H5E_END_TRY if (ret >= 0) TEST_ERROR PASSED(); TESTING(" replace"); /* Replace one path*/ HDsprintf(pathname, "a_path_%d", 20); if (H5PLreplace(pathname, 1) < 0) { HDfprintf(stderr," replace 1: %s\n", pathname); TEST_ERROR } /* Verify the table is full */ if (H5PLsize() != 16) TEST_ERROR /* Verify that the entries were not moved */ if (H5PLget(0, pathname, 256) <= 0) TEST_ERROR if (strcmp(pathname, "a_path_17") != 0) { HDfprintf(stderr," get 0: %s\n", pathname); TEST_ERROR } if (H5PLget(2, pathname, 256) <= 0) TEST_ERROR if (strcmp(pathname, "a_path_1") != 0) { HDfprintf(stderr," get 2: %s\n", pathname); TEST_ERROR } PASSED(); TESTING(" remove (verify for insert)"); /* Remove one path*/ if (H5PLremove(4) < 0) TEST_ERROR /* Verify that the entries were moved */ if (H5PLget(4, pathname, 256) <= 0) TEST_ERROR if (strcmp(pathname, "a_path_4") != 0) { HDfprintf(stderr," get 4: %s\n", pathname); TEST_ERROR } PASSED(); /* Verify the table is not full */ if (H5PLsize() != 15) TEST_ERROR TESTING(" insert"); /* Insert one path*/ HDsprintf(pathname, "a_path_%d", 21); if (H5PLinsert(pathname, 3) < 0){ HDfprintf(stderr," insert 3: %s\n", pathname); TEST_ERROR } /* Verify that the entries were moved */ if (H5PLget(4, pathname, 256) <= 0) TEST_ERROR if (strcmp(pathname, "a_path_2") != 0){ HDfprintf(stderr," get 4: %s\n", pathname); TEST_ERROR } PASSED(); /* Verify the table is full */ if (H5PLsize() != 16) TEST_ERROR TESTING(" insert (exceed)"); /* Exceed the max path insert */ H5E_BEGIN_TRY { HDsprintf(pathname, "a_path_%d", 22); ret = H5PLinsert(pathname, 12); } H5E_END_TRY if (ret >= 0) TEST_ERROR PASSED (); return 0; error: return -1; } /*------------------------------------------------------------------------- * Function: main * * Purpose: Tests the plugin module (H5PL) * * Return: Success: exit(EXIT_SUCCESS) * * Failure: exit(EXIT_FAILURE) * * Programmer: Raymond Lu * 14 March 2013 * *------------------------------------------------------------------------- */ int main(void) { char filename[FILENAME_BUF_SIZE]; hid_t file, fapl, fapl2; unsigned new_format; int mdc_nelmts; size_t rdcc_nelmts; size_t rdcc_nbytes; double rdcc_w0; int nerrors = 0; /* Testing setup */ h5_reset(); fapl = h5_fileaccess(); /* Turn off the chunk cache, so all the chunks are immediately written to disk */ if(H5Pget_cache(fapl, &mdc_nelmts, &rdcc_nelmts, &rdcc_nbytes, &rdcc_w0) < 0) TEST_ERROR rdcc_nbytes = 0; if(H5Pset_cache(fapl, mdc_nelmts, rdcc_nelmts, rdcc_nbytes, rdcc_w0) < 0) TEST_ERROR /* Copy the file access property list */ if((fapl2 = H5Pcopy(fapl)) < 0) TEST_ERROR /* Set the "use the latest version of the format" bounds for creating objects in the file */ if(H5Pset_libver_bounds(fapl2, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0) TEST_ERROR h5_fixname(FILENAME[0], fapl, filename, sizeof filename); /* Test with old & new format groups */ for(new_format = FALSE; new_format <= TRUE; new_format++) { hid_t my_fapl; /* Set the FAPL for the type of format */ if(new_format) { HDputs("\nTesting with new file format:"); my_fapl = fapl2; } /* end if */ else { HDputs("Testing with old file format:"); my_fapl = fapl; } /* end else */ /* Create the file for this test */ if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, my_fapl)) < 0) TEST_ERROR /* Test dynamically loaded filters for chunked dataset */ nerrors += (test_filters_for_datasets(file) < 0 ? 1 : 0); /* Test dynamically loaded filters for groups */ nerrors += (test_filters_for_groups(file) < 0 ? 1 : 0); if(H5Fclose(file) < 0) TEST_ERROR } /* end for */ /* Close FAPL */ if(H5Pclose(fapl2) < 0) TEST_ERROR if(H5Pclose(fapl) < 0) TEST_ERROR /* Restore the default error handler (set in h5_reset()) */ h5_restore_err(); HDputs("\nTesting reading data with with dynamic plugin filters:"); /* Close the library so that all loaded plugin libraries are unloaded */ h5_reset(); fapl = h5_fileaccess(); /* Reopen the file for testing data reading */ if((file = H5Fopen(filename, H5F_ACC_RDONLY, fapl)) < 0) TEST_ERROR /* Read the data with filters */ nerrors += (test_read_with_filters(file) < 0 ? 1 : 0); /* Open the groups with filters */ nerrors += (test_groups_with_filters(file) < 0 ? 1 : 0); /* Restore the default error handler (set in h5_reset()) */ h5_restore_err(); /* Close the library so that all loaded plugin libraries are unloaded */ h5_reset(); fapl = h5_fileaccess(); /* Reopen the file for testing data reading */ if((file = H5Fopen(filename, H5F_ACC_RDONLY, fapl)) < 0) TEST_ERROR /* Read the data with disabled filters */ nerrors += (test_noread_with_filters(file) < 0 ? 1 : 0); if(H5Fclose(file) < 0) TEST_ERROR /* Test the APIs for access to the filter plugin path table */ nerrors += (test_filter_path_apis() < 0 ? 1 : 0); if(nerrors) TEST_ERROR HDprintf("All plugin tests passed.\n"); h5_cleanup(FILENAME, fapl); return 0; error: nerrors = MAX(1, nerrors); HDprintf("***** %d PLUGIN TEST%s FAILED! *****\n", nerrors, 1 == nerrors ? "" : "S"); return 1; }