From bb80ae98543f80779ef726a20460b9b180b5cd2b Mon Sep 17 00:00:00 2001 From: Allen Byrne Date: Tue, 28 Mar 2017 13:35:49 -0500 Subject: HDFFV-10143 add APIs to manipulate plugin path table --- src/H5PL.c | 298 ++++++++++++++++++++++++++ src/H5PLpublic.h | 7 + test/plugin.c | 622 ++++++++++++++++++++++++++++++++++++------------------- 3 files changed, 712 insertions(+), 215 deletions(-) diff --git a/src/H5PL.c b/src/H5PL.c index 1f7bb2a..898e84b 100644 --- a/src/H5PL.c +++ b/src/H5PL.c @@ -390,6 +390,304 @@ done: /*------------------------------------------------------------------------- + * Function: H5PLappend + * + * Purpose: Insert a plugin path at the end of the list. + * + * Return: Non-negative or success. + * + *------------------------------------------------------------------------- + */ +herr_t +H5PLappend(char* plugin_path) +{ + herr_t ret_value = SUCCEED; /* Return value */ + char *dl_path = NULL; + + FUNC_ENTER_API(FAIL) + if(H5PL_num_paths_g == H5PL_MAX_PATH_NUM) + HGOTO_ERROR(H5E_PLUGIN, H5E_NOSPACE, FAIL, "too many directories in path for table") + if(NULL == plugin_path) + HGOTO_ERROR(H5E_PLUGIN, H5E_CANTALLOC, FAIL, "no path provided") + dl_path = H5MM_strdup(plugin_path); + if(NULL == dl_path) + HGOTO_ERROR(H5E_PLUGIN, H5E_CANTALLOC, FAIL, "can't allocate memory for path") +#ifdef H5_HAVE_WIN32_API + else { /* Expand windows env var*/ + long bufCharCount; + char *tempbuf; + if(NULL == (tempbuf = (char *)H5MM_malloc(H5PL_EXPAND_BUFFER_SIZE))) + HGOTO_ERROR(H5E_PLUGIN, H5E_CANTALLOC, FAIL, "can't allocate memory for expanded path") + if((bufCharCount = ExpandEnvironmentStrings(dl_path, tempbuf, H5PL_EXPAND_BUFFER_SIZE)) > H5PL_EXPAND_BUFFER_SIZE) { + tempbuf = (char *)H5MM_xfree(tempbuf); + HGOTO_ERROR(H5E_PLUGIN, H5E_NOSPACE, FAIL, "expanded path is too long") + } + if(bufCharCount == 0) { + tempbuf = (char *)H5MM_xfree(tempbuf); + HGOTO_ERROR(H5E_PLUGIN, H5E_CANTGET, FAIL, "failed to expand path") + } + dl_path = (char *)H5MM_xfree(dl_path); + dl_path = H5MM_strdup(tempbuf); + tempbuf = (char *)H5MM_xfree(tempbuf); + } +#endif /* H5_HAVE_WIN32_API */ + if(NULL == (H5PL_path_table_g[H5PL_num_paths_g] = H5MM_strdup(dl_path))) + HGOTO_ERROR(H5E_PLUGIN, H5E_CANTALLOC, FAIL, "can't allocate memory for path") + H5PL_num_paths_g++; + +done: + if(dl_path) + dl_path = (char *)H5MM_xfree(dl_path); + + FUNC_LEAVE_API(ret_value) +} /* end H5PLappend() */ + + +/*------------------------------------------------------------------------- + * Function: H5PLprepend + * + * Purpose: Insert a plugin path at the beginning of the list. + * + * Return: Non-negative or success. + * + *------------------------------------------------------------------------- + */ +herr_t +H5PLprepend(char* plugin_path) +{ + herr_t ret_value = SUCCEED; /* Return value */ + char *dl_path = NULL; + unsigned int plindex; + + FUNC_ENTER_API(FAIL) + if(H5PL_num_paths_g == H5PL_MAX_PATH_NUM) + HGOTO_ERROR(H5E_PLUGIN, H5E_NOSPACE, FAIL, "too many directories in path for table") + if(NULL == plugin_path) + HGOTO_ERROR(H5E_PLUGIN, H5E_CANTALLOC, FAIL, "no path provided") + dl_path = H5MM_strdup(plugin_path); + if(NULL == dl_path) + HGOTO_ERROR(H5E_PLUGIN, H5E_CANTALLOC, FAIL, "can't allocate memory for path") +#ifdef H5_HAVE_WIN32_API + else { /* Expand windows env var*/ + long bufCharCount; + char *tempbuf; + if (NULL == (tempbuf = (char *)H5MM_malloc(H5PL_EXPAND_BUFFER_SIZE))) + HGOTO_ERROR(H5E_PLUGIN, H5E_CANTALLOC, FAIL, "can't allocate memory for expanded path") + if ((bufCharCount = ExpandEnvironmentStrings(dl_path, tempbuf, H5PL_EXPAND_BUFFER_SIZE)) > H5PL_EXPAND_BUFFER_SIZE) { + tempbuf = (char *)H5MM_xfree(tempbuf); + HGOTO_ERROR(H5E_PLUGIN, H5E_NOSPACE, FAIL, "expanded path is too long") + } + if (bufCharCount == 0) { + tempbuf = (char *)H5MM_xfree(tempbuf); + HGOTO_ERROR(H5E_PLUGIN, H5E_CANTGET, FAIL, "failed to expand path") + } + dl_path = (char *)H5MM_xfree(dl_path); + dl_path = H5MM_strdup(tempbuf); + tempbuf = (char *)H5MM_xfree(tempbuf); + } +#endif /* H5_HAVE_WIN32_API */ + for (plindex = (unsigned int)H5PL_num_paths_g; plindex > 0; plindex--) + H5PL_path_table_g[plindex] = H5PL_path_table_g[plindex - 1]; + if (NULL == (H5PL_path_table_g[0] = H5MM_strdup(dl_path))) + HGOTO_ERROR(H5E_PLUGIN, H5E_CANTALLOC, FAIL, "can't allocate memory for path") + H5PL_num_paths_g++; + +done: + if (dl_path) + dl_path = (char *)H5MM_xfree(dl_path); + + FUNC_LEAVE_API(ret_value) +} /* end H5PLprepend() */ + + +/*------------------------------------------------------------------------- + * Function: H5PLput + * + * Purpose: Replace the path at the specified index. + * + * Return: Non-negative or success. + * + *------------------------------------------------------------------------- + */ +herr_t +H5PLput(char* plugin_path, unsigned int index) +{ + herr_t ret_value = SUCCEED; /* Return value */ + char *dl_path = NULL; + + FUNC_ENTER_API(FAIL) + if(NULL == plugin_path) + HGOTO_ERROR(H5E_PLUGIN, H5E_CANTALLOC, FAIL, "no path provided") + dl_path = H5MM_strdup(plugin_path); + if(NULL == dl_path) + HGOTO_ERROR(H5E_PLUGIN, H5E_CANTALLOC, FAIL, "can't allocate memory for path") +#ifdef H5_HAVE_WIN32_API + else { /* Expand windows env var*/ + long bufCharCount; + char *tempbuf; + if(NULL == (tempbuf = (char *)H5MM_malloc(H5PL_EXPAND_BUFFER_SIZE))) + HGOTO_ERROR(H5E_PLUGIN, H5E_CANTALLOC, FAIL, "can't allocate memory for expanded path") + if((bufCharCount = ExpandEnvironmentStrings(dl_path, tempbuf, H5PL_EXPAND_BUFFER_SIZE)) > H5PL_EXPAND_BUFFER_SIZE) { + tempbuf = (char *)H5MM_xfree(tempbuf); + HGOTO_ERROR(H5E_PLUGIN, H5E_NOSPACE, FAIL, "expanded path is too long") + } + if(bufCharCount == 0) { + tempbuf = (char *)H5MM_xfree(tempbuf); + HGOTO_ERROR(H5E_PLUGIN, H5E_CANTGET, FAIL, "failed to expand path") + } + dl_path = (char *)H5MM_xfree(dl_path); + dl_path = H5MM_strdup(tempbuf); + tempbuf = (char *)H5MM_xfree(tempbuf); + } +#endif /* H5_HAVE_WIN32_API */ + if(H5PL_path_table_g[index]) + H5PL_path_table_g[index] = (char *)H5MM_xfree(H5PL_path_table_g[index]); + if(NULL == (H5PL_path_table_g[index] = H5MM_strdup(dl_path))) + HGOTO_ERROR(H5E_PLUGIN, H5E_CANTALLOC, FAIL, "can't allocate memory for path") + +done: + if(dl_path) + dl_path = (char *)H5MM_xfree(dl_path); + + FUNC_LEAVE_API(ret_value) +} /* end H5PLput() */ + + +/*------------------------------------------------------------------------- + * Function: H5PLinsert + * + * Purpose: Insert a plugin path at the specified index, moving other paths after the index. + * + * Return: Non-negative or success. + * + *------------------------------------------------------------------------- + */ +herr_t +H5PLinsert(char* plugin_path, unsigned int index) +{ + herr_t ret_value = SUCCEED; /* Return value */ + char *dl_path = NULL; + unsigned int plindex; + + FUNC_ENTER_API(FAIL) + if(H5PL_num_paths_g == H5PL_MAX_PATH_NUM) + HGOTO_ERROR(H5E_PLUGIN, H5E_NOSPACE, FAIL, "too many directories in path for table") + if(NULL == plugin_path) + HGOTO_ERROR(H5E_PLUGIN, H5E_CANTALLOC, FAIL, "no path provided") + dl_path = H5MM_strdup(plugin_path); + if(NULL == dl_path) + HGOTO_ERROR(H5E_PLUGIN, H5E_CANTALLOC, FAIL, "can't allocate memory for path") +#ifdef H5_HAVE_WIN32_API + else { /* Expand windows env var*/ + long bufCharCount; + char *tempbuf; + if(NULL == (tempbuf = (char *)H5MM_malloc(H5PL_EXPAND_BUFFER_SIZE))) + HGOTO_ERROR(H5E_PLUGIN, H5E_CANTALLOC, FAIL, "can't allocate memory for expanded path") + if((bufCharCount = ExpandEnvironmentStrings(dl_path, tempbuf, H5PL_EXPAND_BUFFER_SIZE)) > H5PL_EXPAND_BUFFER_SIZE) { + tempbuf = (char *)H5MM_xfree(tempbuf); + HGOTO_ERROR(H5E_PLUGIN, H5E_NOSPACE, FAIL, "expanded path is too long") + } + if(bufCharCount == 0) { + tempbuf = (char *)H5MM_xfree(tempbuf); + HGOTO_ERROR(H5E_PLUGIN, H5E_CANTGET, FAIL, "failed to expand path") + } + dl_path = (char *)H5MM_xfree(dl_path); + dl_path = H5MM_strdup(tempbuf); + tempbuf = (char *)H5MM_xfree(tempbuf); + } +#endif /* H5_HAVE_WIN32_API */ + for(plindex = (unsigned int)H5PL_num_paths_g; plindex > index; plindex--) + H5PL_path_table_g[plindex] = H5PL_path_table_g[plindex - 1]; + if(NULL == (H5PL_path_table_g[index] = H5MM_strdup(dl_path))) + HGOTO_ERROR(H5E_PLUGIN, H5E_CANTALLOC, FAIL, "can't allocate memory for path") + H5PL_num_paths_g++; + +done: + if(dl_path) + dl_path = (char *)H5MM_xfree(dl_path); + + FUNC_LEAVE_API(ret_value) +} /* end H5PLinsert() */ + + +/*------------------------------------------------------------------------- + * Function: H5PLremove + * + * Purpose: Remove the plugin path at the specifed index and compacting the list. + * + * Return: Non-negative or success. + * + *------------------------------------------------------------------------- + */ +herr_t +H5PLremove(unsigned int index) +{ + herr_t ret_value = SUCCEED; /* Return value */ + char *dl_path = NULL; + unsigned int plindex; + + FUNC_ENTER_API(FAIL) + if(H5PL_num_paths_g == 0) + HGOTO_ERROR(H5E_PLUGIN, H5E_NOSPACE, FAIL, "no directories in table") + if(NULL == (dl_path = H5PL_path_table_g[index])) + HGOTO_ERROR(H5E_PLUGIN, H5E_CANTALLOC, FAIL, "no directory path at index") + for(plindex = index; plindex < (unsigned int)H5PL_num_paths_g; plindex++) + H5PL_path_table_g[plindex] = H5PL_path_table_g[plindex + 1]; + if(H5PL_path_table_g[plindex]) + dl_path = (char *)H5MM_xfree(dl_path); + H5PL_num_paths_g--; + H5PL_path_table_g[H5PL_num_paths_g] = NULL; + +done: + if(dl_path) + dl_path = (char *)H5MM_xfree(dl_path); + + FUNC_LEAVE_API(ret_value) +} /* end H5PLremove() */ + + +/*------------------------------------------------------------------------- + * Function: H5PLget + * + * Purpose: Query the plugin path at the specified index. + * + * Return: Non-NULL on success/NULL on failure + * + *------------------------------------------------------------------------- + */ +const char* +H5PLget(unsigned int index) +{ + char* ret_value = NULL; /* Return value */ + + FUNC_ENTER_API(NULL) + if(H5PL_num_paths_g == 0) + HGOTO_ERROR(H5E_PLUGIN, H5E_NOSPACE, FAIL, "no directories in table") + if(NULL == (ret_value = H5PL_path_table_g[index])) + HGOTO_ERROR(H5E_PLUGIN, H5E_CANTALLOC, FAIL, "no directory path at index") + +done: + FUNC_LEAVE_API(ret_value) +} /* end H5PLget() */ + + +/*------------------------------------------------------------------------- + * Function: H5PLsize + * + * Purpose: Query the size of the current list of plugin paths. + * + * Return: Non-negative or success. + * + *------------------------------------------------------------------------- + */ +unsigned int +H5PLsize(void) +{ + return (unsigned int)H5PL_num_paths_g; +} /* end H5PLsize() */ + + +/*------------------------------------------------------------------------- * Function: H5PL__init_path_table * * Purpose: Initialize the path table. diff --git a/src/H5PLpublic.h b/src/H5PLpublic.h index 0528945..f3fe497 100644 --- a/src/H5PLpublic.h +++ b/src/H5PLpublic.h @@ -44,6 +44,13 @@ extern "C" { /* plugin state */ H5_DLL herr_t H5PLset_loading_state(unsigned int plugin_type); H5_DLL herr_t H5PLget_loading_state(unsigned int* plugin_type/*out*/); +H5_DLL herr_t H5PLappend(char* plugin_path); +H5_DLL herr_t H5PLprepend(char* plugin_path); +H5_DLL herr_t H5PLput(char* plugin_path, unsigned int index); +H5_DLL herr_t H5PLinsert(char* plugin_path, unsigned int index); +H5_DLL herr_t H5PLremove(unsigned int index); +H5_DLL const char* H5PLget(unsigned int index); +H5_DLL unsigned int H5PLsize(void); #ifdef __cplusplus } diff --git a/test/plugin.c b/test/plugin.c index a70e885..1d55a5d 100644 --- a/test/plugin.c +++ b/test/plugin.c @@ -12,10 +12,10 @@ * to either file, you may request a copy from help@hdfgroup.org. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* - * Programmer: Raymond Lu - * 13 February 2013 + * Programmer: Raymond Lu + * 13 February 2013 * - * Purpose: Tests the plugin module (H5PL) + * Purpose: Tests the plugin module (H5PL) */ #include "h5test.h" @@ -29,7 +29,7 @@ /* Filters for HDF5 internal test */ #define H5Z_FILTER_DYNLIB1 257 -#define H5Z_FILTER_DYNLIB2 258 +#define H5Z_FILTER_DYNLIB2 258 #define H5Z_FILTER_DYNLIB3 259 #define H5Z_FILTER_DYNLIB4 260 @@ -40,8 +40,8 @@ const char *FILENAME[] = { #define FILENAME_BUF_SIZE 1024 /* Dataset names for testing filters */ -#define DSET_DEFLATE_NAME "deflate" -#define DSET_DYNLIB1_NAME "dynlib1" +#define DSET_DEFLATE_NAME "deflate" +#define DSET_DYNLIB1_NAME "dynlib1" #define DSET_DYNLIB2_NAME "dynlib2" #define DSET_DYNLIB4_NAME "dynlib4" @@ -62,7 +62,7 @@ const char *FILENAME[] = { #define GROUP_ITERATION 1000 -int points_deflate[DSET_DIM1][DSET_DIM2], +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], @@ -70,14 +70,14 @@ int points_deflate[DSET_DIM1][DSET_DIM2], /*------------------------------------------------------------------------- - * Function: test_filter_internal + * Function: test_filter_internal * - * Purpose: Tests writing entire data and partial data with filters + * Purpose: Tests writing entire data and partial data with filters * - * Return: Success: 0 - * Failure: -1 + * Return: Success: 0 + * Failure: -1 * - * Programmer: Raymond Lu + * Programmer: Raymond Lu * 27 February 2013 * *------------------------------------------------------------------------- @@ -85,28 +85,28 @@ int points_deflate[DSET_DIM1][DSET_DIM2], 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 */ + 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) goto error; + 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) goto error; + 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) goto error; + if(H5Pset_buffer(dxpl, (size_t)1000, tconv_buf, NULL) < 0) TEST_ERROR if((write_dxpl = H5Pcopy(dxpl)) < 0) TEST_ERROR; TESTING(" filters (setup)"); @@ -115,12 +115,12 @@ test_filter_internal(hid_t fid, const char *name, hid_t dcpl) if(H5Pall_filters_avail(dcpl)!=TRUE) { H5_FAILED(); printf(" Line %d: Incorrect filter availability\n",__LINE__); - goto error; + TEST_ERROR } /* end if */ /* Create the dataset */ if((dataset = H5Dcreate2(fid, name, H5T_NATIVE_INT, sid, H5P_DEFAULT, - dcpl, H5P_DEFAULT)) < 0) goto error; + dcpl, H5P_DEFAULT)) < 0) TEST_ERROR PASSED(); @@ -131,18 +131,18 @@ test_filter_internal(hid_t fid, const char *name, hid_t dcpl) TESTING(" filters (uninitialized read)"); if(H5Dread(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, dxpl, check) < 0) - TEST_ERROR; + 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(); - printf(" Read a non-zero value.\n"); - printf(" At index %lu,%lu\n", - (unsigned long)i, (unsigned long)j); - goto error; - } - } + for(j=0; j<(size_t)size[1]; j++) { + if(0!=check[i][j]) { + H5_FAILED(); + printf(" Read a non-zero value.\n"); + printf(" At index %lu,%lu\n", + (unsigned long)i, (unsigned long)j); + TEST_ERROR + } + } } PASSED(); @@ -155,13 +155,13 @@ test_filter_internal(hid_t fid, const char *name, hid_t dcpl) n = 0; for(i=0; i 0; i--) { + if (H5PLremove(i-1) < 0) { + fprintf(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++) { + sprintf(pathname, "a_path_%d", i); + if (H5PLappend(pathname) < 0) { + fprintf(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 { + sprintf(pathname, "a_path_%d", 16); + ret = H5PLappend(pathname); + } H5E_END_TRY + if (ret >= 0) + TEST_ERROR + PASSED(); + + TESTING(" remove (verify for prepend)"); + /* Remove one path*/ + if (H5PLremove(8) < 0) TEST_ERROR + + /* Verify that the entries were moved */ + sprintf(pathname, "%s", H5PLget(8)); + if (strcmp(pathname, "a_path_9") != 0) { + fprintf(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*/ + sprintf(pathname, "a_path_%d", 17); + if (H5PLprepend(pathname) < 0) { + fprintf(stderr," prepend 17: %s\n", pathname); + TEST_ERROR + } + + /* Verify the table is full */ + if (H5PLsize() != 16) TEST_ERROR + + /* Verify that the entries were moved */ + sprintf(pathname, "%s", H5PLget(8)); + if (strcmp(pathname, "a_path_7") != 0) { + fprintf(stderr," get 8: %s\n", pathname); + TEST_ERROR + } + sprintf(pathname, "%s", H5PLget(0)); + if (strcmp(pathname, "a_path_17") != 0) { + fprintf(stderr," get 0: %s\n", pathname); + TEST_ERROR + } + PASSED(); + + TESTING(" prepend (exceed)"); + /* Exceed the max path prepend */ + H5E_BEGIN_TRY { + sprintf(pathname, "a_path_%d", 18); + ret = H5PLprepend(pathname); + } H5E_END_TRY + if (ret >= 0) + TEST_ERROR + PASSED(); + + TESTING(" replace"); + /* Replace one path*/ + sprintf(pathname, "a_path_%d", 20); + if (H5PLput(pathname, 1) < 0) { + fprintf(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 */ + sprintf(pathname, "%s", H5PLget(0)); + if (strcmp(pathname, "a_path_17") != 0) { + fprintf(stderr," get 0: %s\n", pathname); + TEST_ERROR + } + sprintf(pathname, "%s", H5PLget(2)); + if (strcmp(pathname, "a_path_1") != 0) { + fprintf(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 */ + sprintf(pathname, "%s", H5PLget(4)); + if (strcmp(pathname, "a_path_4") != 0) { + fprintf(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*/ + sprintf(pathname, "a_path_%d", 21); + if (H5PLinsert(pathname, 3) < 0){ + fprintf(stderr," insert 3: %s\n", pathname); + TEST_ERROR + } + + /* Verify that the entries were moved */ + sprintf(pathname, "%s", H5PLget(4)); + if (strcmp(pathname, "a_path_2") != 0){ + fprintf(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 { + sprintf(pathname, "a_path_%d", 22); + ret = H5PLinsert(pathname, 12); + } H5E_END_TRY + if (ret >= 0) + TEST_ERROR + + PASSED (); + return 0; error: @@ -729,30 +918,30 @@ error: /*------------------------------------------------------------------------- - * Function: main + * Function: main * - * Purpose: Tests the plugin module (H5PL) + * Purpose: Tests the plugin module (H5PL) * - * Return: Success: exit(EXIT_SUCCESS) + * Return: Success: exit(EXIT_SUCCESS) * - * Failure: exit(EXIT_FAILURE) + * Failure: exit(EXIT_FAILURE) * - * Programmer: Raymond Lu - * 14 March 2013 + * Programmer: Raymond Lu + * 14 March 2013 * *------------------------------------------------------------------------- */ int main(void) { - char filename[FILENAME_BUF_SIZE]; - hid_t file, fapl, fapl2; + 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; + int nerrors = 0; /* Testing setup */ h5_reset(); @@ -760,10 +949,10 @@ main(void) /* 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 + TEST_ERROR rdcc_nbytes = 0; if(H5Pset_cache(fapl, mdc_nelmts, rdcc_nelmts, rdcc_nbytes, rdcc_w0) < 0) - TEST_ERROR + TEST_ERROR /* Copy the file access property list */ if((fapl2 = H5Pcopy(fapl)) < 0) TEST_ERROR @@ -789,22 +978,22 @@ main(void) /* Create the file for this test */ if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, my_fapl)) < 0) - TEST_ERROR + TEST_ERROR /* Test dynamically loaded filters for chunked dataset */ - nerrors += (test_filters_for_datasets(file) < 0 ? 1 : 0); + 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 + 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(); @@ -816,13 +1005,13 @@ main(void) /* Reopen the file for testing data reading */ if((file = H5Fopen(filename, H5F_ACC_RDONLY, fapl)) < 0) - TEST_ERROR + TEST_ERROR /* Read the data with filters */ - nerrors += (test_read_with_filters(file) < 0 ? 1 : 0); + nerrors += (test_read_with_filters(file) < 0 ? 1 : 0); /* Open the groups with filters */ - nerrors += (test_groups_with_filters(file) < 0 ? 1 : 0); + nerrors += (test_groups_with_filters(file) < 0 ? 1 : 0); /* Restore the default error handler (set in h5_reset()) */ h5_restore_err(); @@ -839,10 +1028,13 @@ main(void) nerrors += (test_noread_with_filters(file) < 0 ? 1 : 0); if(H5Fclose(file) < 0) - TEST_ERROR + 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 + TEST_ERROR printf("All plugin tests passed.\n"); h5_cleanup(FILENAME, fapl); -- cgit v0.12