diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/filter_plugin.c | 99 | ||||
-rw-r--r-- | test/h5test.h | 59 | ||||
-rw-r--r-- | test/vfd_plugin.c | 65 |
3 files changed, 166 insertions, 57 deletions
diff --git a/test/filter_plugin.c b/test/filter_plugin.c index 276141a..c373b3b 100644 --- a/test/filter_plugin.c +++ b/test/filter_plugin.c @@ -1305,6 +1305,102 @@ error: } /* end test_path_api_calls() */ /*------------------------------------------------------------------------- + * Function: test_filter_numbers + * + * Purpose: Tests the filter numbers are handled correctly + * + * Return: SUCCEED/FAIL + * + *------------------------------------------------------------------------- + */ +static herr_t +test_filter_numbers(void) +{ + hid_t dcpl_id = H5I_INVALID_HID; + H5Z_filter_t id; + herr_t status = SUCCEED; + size_t nelmts = 0; + unsigned int flags; + unsigned int filter_config; + + HDputs("Testing filter number handling"); + + /* Check that out-of-range filter numbers are handled correctly */ + TESTING(" Filter # out of range"); + + /* Create property list */ + if ((dcpl_id = H5Pcreate(H5P_DATASET_CREATE)) < 0) + TEST_ERROR; + + nelmts = 0; + + /* Test id > H5Z_FILTER_MAX and < 0, current version */ + + H5E_BEGIN_TRY + { + id = H5Z_FILTER_MAX + 1; + status = H5Pget_filter_by_id2(dcpl_id, id, &flags, &nelmts, NULL, 0, NULL, &filter_config); + } + H5E_END_TRY; + + /* Should fail */ + if (status != FAIL) + TEST_ERROR; + + H5E_BEGIN_TRY + { + id = -1; + status = H5Pget_filter_by_id2(dcpl_id, id, &flags, &nelmts, NULL, 0, NULL, &filter_config); + } + H5E_END_TRY; + + /* Should fail */ + if (status != FAIL) + TEST_ERROR; + + /* Test id > H5Z_FILTER_MAX and < 0, deprecated version */ + +#ifndef H5_NO_DEPRECATED_SYMBOLS + H5E_BEGIN_TRY + { + id = H5Z_FILTER_MAX + 1; + status = H5Pget_filter_by_id1(dcpl_id, id, &flags, &nelmts, NULL, 0, NULL); + } + H5E_END_TRY; + + /* Should fail */ + if (status != FAIL) + TEST_ERROR; + + H5E_BEGIN_TRY + { + id = -1; + status = H5Pget_filter_by_id1(dcpl_id, id, &flags, &nelmts, NULL, 0, NULL); + } + H5E_END_TRY; + + /* Should fail */ + if (status != FAIL) + TEST_ERROR; +#endif + + if (H5Pclose(dcpl_id) < 0) + TEST_ERROR; + + PASSED(); + + return SUCCEED; + +error: + H5E_BEGIN_TRY + { + H5Pclose(dcpl_id); + } + H5E_END_TRY; + return FAIL; +} /* end test_filter_numbers() */ + +/*------------------------------------------------------------------------- * Function: disable_chunk_cache * * Purpose: Turns the chunk cache off @@ -1523,6 +1619,9 @@ main(void) /* Test the APIs for access to the filter plugin path table */ nerrors += (test_path_api_calls() < 0 ? 1 : 0); + /* Test filter numbers */ + nerrors += (test_filter_numbers() < 0 ? 1 : 0); + if (nerrors) TEST_ERROR; diff --git a/test/h5test.h b/test/h5test.h index 914a534..7b82b68 100644 --- a/test/h5test.h +++ b/test/h5test.h @@ -172,60 +172,19 @@ H5TEST_DLLVAR MPI_Info h5_io_info_g; /* MPI INFO object for IO */ #define H5_EXCLUDE_MULTIPART_DRIVERS 0x01 #define H5_EXCLUDE_NON_MULTIPART_DRIVERS 0x02 -/* Macros to create and fill 2D arrays with a single heap allocation. - * These can be used to replace large stack and global arrays which raise - * warnings. - * - * The macros make a single heap allocation large enough to hold all the - * pointers and the data elements. The first part of the allocation holds - * the pointers, and the second part holds the data as a contiguous block - * in row-major order. - * - * To pass the data block to calls like H5Dread(), pass a pointer to the - * first array element as the data pointer (e.g., array[0] in a 2D array). - * - * The fill macro just fills the array with an increasing count value. - * - * Usage: - * - * int **array; - * - * H5TEST_ALLOCATE_2D_ARRAY(array, int, 5, 10); - * - * H5TEST_FILL_2D_ARRAY(array, int, 5, 10); - * - * (do stuff) - * - * HDfree(array); +/* Fill an array on the heap with an increasing count value. BUF + * is expected to point to a `struct { TYPE arr[...][...]; }`. */ -#define H5TEST_ALLOCATE_2D_ARRAY(ARR, TYPE, DIMS_I, DIMS_J) \ - do { \ - /* Prefix with h5taa to avoid shadow warnings */ \ - size_t h5taa_pointers_size = 0; \ - size_t h5taa_data_size = 0; \ - int h5taa_i; \ - \ - h5taa_pointers_size = (DIMS_I) * sizeof(TYPE *); \ - h5taa_data_size = (DIMS_I) * (DIMS_J) * sizeof(TYPE); \ - \ - ARR = (TYPE **)HDmalloc(h5taa_pointers_size + h5taa_data_size); \ - \ - ARR[0] = (TYPE *)(ARR + (DIMS_I)); \ - \ - for (h5taa_i = 1; h5taa_i < (DIMS_I); h5taa_i++) \ - ARR[h5taa_i] = ARR[h5taa_i - 1] + (DIMS_J); \ - } while (0) - -#define H5TEST_FILL_2D_ARRAY(ARR, TYPE, DIMS_I, DIMS_J) \ +#define H5TEST_FILL_2D_HEAP_ARRAY(BUF, TYPE) \ do { \ /* Prefix with h5tfa to avoid shadow warnings */ \ - int h5tfa_i = 0; \ - int h5tfa_j = 0; \ - TYPE h5tfa_count = 0; \ + size_t h5tfa_i = 0; \ + size_t h5tfa_j = 0; \ + TYPE h5tfa_count = 0; \ \ - for (h5tfa_i = 0; h5tfa_i < (DIMS_I); h5tfa_i++) \ - for (h5tfa_j = 0; h5tfa_j < (DIMS_J); h5tfa_j++) { \ - ARR[h5tfa_i][h5tfa_j] = h5tfa_count; \ + for (h5tfa_i = 0; h5tfa_i < NELMTS((BUF)->arr); h5tfa_i++) \ + for (h5tfa_j = 0; h5tfa_j < NELMTS((BUF)->arr[0]); h5tfa_j++) { \ + (BUF)->arr[h5tfa_i][h5tfa_j] = h5tfa_count; \ h5tfa_count++; \ } \ } while (0) diff --git a/test/vfd_plugin.c b/test/vfd_plugin.c index df211cc..182c048 100644 --- a/test/vfd_plugin.c +++ b/test/vfd_plugin.c @@ -313,8 +313,53 @@ test_get_config_str(void) if (H5Pclose(fapl_id) < 0) TEST_ERROR; + PASSED(); + + return SUCCEED; + +error: + H5E_BEGIN_TRY + { + H5Pclose(fapl_id); + } + H5E_END_TRY; + + return FAIL; +} + +/*------------------------------------------------------------------------- + * Function: test_env_var + * + * Purpose: Tests loading of NULL VFD plugin with HDF5_DRIVER + * environment variable and setting of VFD configuration + * string with HDF5_DRIVER_CONFIG environment variable + * + * Return: EXIT_SUCCESS/EXIT_FAILURE + * + *------------------------------------------------------------------------- + */ +static int +test_env_var(void) +{ + const char *const config_str = "{name: null}"; + ssize_t config_str_len = 0; + htri_t driver_is_registered; + char config_str_buf[128]; + + TESTING("Loading of VFD plugin with HDF5_DRIVER environment variable"); + + /* Try to retrieve length of default configuration string - should be 0 */ + HDmemset(config_str_buf, 0, 128); + + if ((config_str_len = H5Pget_driver_config_str(H5P_FILE_ACCESS_DEFAULT, config_str_buf, 128)) < 0) + TEST_ERROR; + if (0 != config_str_len) + TEST_ERROR; + if (HDstrlen(config_str_buf) > 0) + TEST_ERROR; + /* Set default driver and driver configuration using environment variables */ - if (HDsetenv(HDF5_DRIVER, "sec2", 1) < 0) + if (HDsetenv(HDF5_DRIVER, "null_vfd_plugin", 1) < 0) TEST_ERROR; if (HDsetenv(HDF5_DRIVER_CONFIG, config_str, 1) < 0) TEST_ERROR; @@ -325,7 +370,15 @@ test_get_config_str(void) if (H5open() < 0) TEST_ERROR; - /* Retrieve configuration string from default FAPL */ + /* Check driver */ + if ((driver_is_registered = H5FDis_driver_registered_by_name("null_vfd_plugin")) < 0) + TEST_ERROR; + if (!driver_is_registered) + TEST_ERROR; + if (H5Pget_driver(H5P_FILE_ACCESS_DEFAULT) == H5_DEFAULT_VFD) + TEST_ERROR; + + /* Check driver configuration string */ HDmemset(config_str_buf, 0, 128); if ((config_str_len = H5Pget_driver_config_str(H5P_FILE_ACCESS_DEFAULT, config_str_buf, 128)) < 0) TEST_ERROR; @@ -345,11 +398,8 @@ test_get_config_str(void) return SUCCEED; error: - H5E_BEGIN_TRY - { - H5Pclose(fapl_id); - } - H5E_END_TRY; + HDsetenv(HDF5_DRIVER, "", 1); + HDsetenv(HDF5_DRIVER_CONFIG, "", 1); return FAIL; } @@ -376,6 +426,7 @@ main(void) nerrors += (test_set_by_value() < 0) ? 1 : 0; nerrors += (test_set_multi() < 0) ? 1 : 0; nerrors += (test_get_config_str() < 0) ? 1 : 0; + nerrors += (test_env_var() < 0) ? 1 : 0; if (nerrors) { HDprintf("***** %d VFD plugin TEST%s FAILED! *****\n", nerrors, nerrors > 1 ? "S" : ""); |