diff options
author | Raymond Lu <songyulu@hdfgroup.org> | 2010-09-21 16:46:38 (GMT) |
---|---|---|
committer | Raymond Lu <songyulu@hdfgroup.org> | 2010-09-21 16:46:38 (GMT) |
commit | d6c6a34a8f5876d21dee052c74426b0606b62d13 (patch) | |
tree | 67b0dddc97926eae54a6fd23a563a4e2296dabab /test | |
parent | ba71366f9867bd2d817abf6715a5445237023c6f (diff) | |
download | hdf5-d6c6a34a8f5876d21dee052c74426b0606b62d13.zip hdf5-d6c6a34a8f5876d21dee052c74426b0606b62d13.tar.gz hdf5-d6c6a34a8f5876d21dee052c74426b0606b62d13.tar.bz2 |
[svn-r19457] Bug fix for 1707 - H5Eset_auto causes a seg fault when an application uses -DH5_USE_16_API with the 1.8 library to compile. The cause is from the mismatch of H5Eprint1 and H5Eprint2 set
through H5Eset_auto. I changed the union in the structure H5E_auto_t. Another change is to
make H5Eget_auto fail if H5Eset_auto is called to set the printing function. I'll write a
document for it.
Tested on heiwa, jam, and amani.
The property change in configure.in, config, and Makefile.am came from the merge of the 1.8
library change.
Diffstat (limited to 'test')
-rw-r--r-- | test/dtransform.c | 18 | ||||
-rw-r--r-- | test/enum.c | 6 | ||||
-rw-r--r-- | test/err_compat.c | 175 | ||||
-rw-r--r-- | test/error_test.c | 7 | ||||
-rw-r--r-- | test/flush2.c | 35 | ||||
-rw-r--r-- | test/h5test.c | 6 | ||||
-rw-r--r-- | test/testerror.sh.in | 2 | ||||
-rw-r--r-- | test/testfiles/err_compat_1 | 14 | ||||
-rw-r--r-- | test/testframe.c | 6 | ||||
-rw-r--r-- | test/ttsafe_error.c | 20 |
10 files changed, 240 insertions, 49 deletions
diff --git a/test/dtransform.c b/test/dtransform.c index 5d5cefe..15c5934 100644 --- a/test/dtransform.c +++ b/test/dtransform.c @@ -641,7 +641,7 @@ static int test_set(void) { hid_t dxpl_id = -1; - H5E_auto2_t func; + H5E_auto_t func; const char *str = "(9/5.0)*x + 32"; char *ptrgetTest = NULL; @@ -654,9 +654,15 @@ test_set(void) TEST_ERROR /* Test get before set */ - H5Eget_auto2(H5E_DEFAULT, &func, NULL); +#ifdef H5_USE_16_API_DEFAULT + H5Eget_auto(&func, NULL); - H5Eset_auto2(H5E_DEFAULT, NULL, NULL); + H5Eset_auto(NULL, NULL); +#else /* H5_USE_16_API_DEFAULT */ + H5Eget_auto(H5E_DEFAULT, &func, NULL); + + H5Eset_auto(H5E_DEFAULT, NULL, NULL); +#endif /* H5_USE_16_API_DEFAULT */ if(H5Pget_data_transform(dxpl_id, ptrgetTest, HDstrlen(str) + 1) < 0) PASSED() @@ -693,7 +699,11 @@ test_set(void) TESTING("H5Pset_data_transform (set with invalid transform 8)") INVALID_SET_TEST("(9/5)*x + x^2"); - H5Eset_auto2(H5E_DEFAULT, func, NULL); +#ifdef H5_USE_16_API_DEFAULT + H5Eset_auto(func, NULL); +#else /* H5_USE_16_API_DEFAULT */ + H5Eset_auto(H5E_DEFAULT, func, NULL); +#endif /* H5_USE_16_API_DEFAULT */ if(H5Pclose(dxpl_id) < 0) TEST_ERROR diff --git a/test/enum.c b/test/enum.c index c627af1..0033c44 100644 --- a/test/enum.c +++ b/test/enum.c @@ -383,7 +383,11 @@ test_value_dsnt_exist(void) TESTING("for non-existing name and value"); /* Turn off error reporting since we expect failure in this test */ - if (H5Eset_auto2(H5E_DEFAULT, NULL, NULL) < 0) goto error; +#ifdef H5_USE_16_API_DEFAULT + if (H5Eset_auto(NULL, NULL) < 0) goto error; +#else /* H5_USE_16_API_DEFAULT */ + if (H5Eset_auto(H5E_DEFAULT, NULL, NULL) < 0) goto error; +#endif /* H5_USE_16_API_DEFAULT */ if ((datatype_id = H5Tenum_create(H5T_NATIVE_INT))< 0) goto error; diff --git a/test/err_compat.c b/test/err_compat.c index be86a2d..4c0df06 100644 --- a/test/err_compat.c +++ b/test/err_compat.c @@ -44,9 +44,144 @@ int ipoints2[DIM0][DIM1], icheck2[DIM0][DIM1]; herr_t custom_print_cb(int n, H5E_error1_t *err_desc, void* client_data); +#ifdef H5_USE_16_API_DEFAULT /*------------------------------------------------------------------------- - * Function: test_error + * Function: test_error1 + * + * Purpose: Test the backward compatibility of H5Eset/get_auto. + * + * Return: Success: 0 + * + * Failure: -1 + * + * Programmer: Raymond Lu + * 17 September 2010 + * + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +static herr_t +test_error1(void) +{ + hid_t dataset, space; + hsize_t dims[2]; + H5E_auto1_t old_func1; + H5E_auto2_t old_func2; + void *old_data; + herr_t ret; + + TESTING("error API H5Eset/get_auto"); + fprintf(stderr, "\n"); + + /* Create the data space */ + dims[0] = DIM0; + dims[1] = DIM1; + if ((space = H5Screate_simple(2, dims, NULL))<0) TEST_ERROR; + + /* Test whether the printing function is mismatched. The library should indicate + * H5Eprint1 as the default. */ + if (H5Eget_auto2(H5E_DEFAULT, &old_func2, &old_data)<0) + TEST_ERROR; + if (old_data != NULL) + TEST_ERROR; + if (!old_func2) + TEST_ERROR; + + /* This function changes the default printing function to be H5Eprint2. */ + if(H5Eset_auto2(H5E_DEFAULT, old_func2, old_data)<0) + TEST_ERROR; + + /* Dataset creation should fail because the file doesn't exist. */ + dataset = H5Dcreate2(FAKE_ID, DSET_NAME, H5T_STD_I32BE, space, H5P_DEFAULT, + H5P_DEFAULT, H5P_DEFAULT); + if(dataset >= 0) + TEST_ERROR; + + /* This call should fail because the test mixes H5Eget_auto1 with H5Eset_auto2. + * Once the H5Eset_auto2 is called, a call to H5Eget_auto1 will fail. */ + if((ret = H5Eget_auto1(&old_func1, &old_data)) >= 0) + TEST_ERROR; + + return 0; + + error: + return -1; +} + +#else /*H5_USE_16_API_DEFAULT*/ + +/*------------------------------------------------------------------------- + * Function: test_error2 + * + * Purpose: Test the backward compatibility of H5Eset/get_auto. + * + * Return: Success: 0 + * + * Failure: -1 + * + * Programmer: Raymond Lu + * 17 September 2010 + * + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +static herr_t +test_error2(void) +{ + hid_t dataset, space; + hsize_t dims[2]; + H5E_auto1_t old_func1; + H5E_auto2_t old_func2; + void *old_data; + herr_t ret; + + TESTING("error API H5Eset/get_auto"); + fprintf(stderr, "\n"); + + /* Create the data space */ + dims[0] = DIM0; + dims[1] = DIM1; + if ((space = H5Screate_simple(2, dims, NULL))<0) TEST_ERROR; + + /* Test whether the printing function is mismatched. The library should indicate + * H5Eprint2 as the default. */ + if (H5Eget_auto1(&old_func1, &old_data)<0) + TEST_ERROR; + if (old_data != NULL) + TEST_ERROR; + if (!old_func1) + TEST_ERROR; + + /* This function changes the default printing function to be H5Eprint1. */ + if(H5Eset_auto1(old_func1, old_data)<0) + TEST_ERROR; + + /* Dataset creation should fail because the file doesn't exist. */ + dataset = H5Dcreate2(FAKE_ID, DSET_NAME, H5T_STD_I32BE, space, H5P_DEFAULT, + H5P_DEFAULT, H5P_DEFAULT); + if(dataset >= 0) + TEST_ERROR; + + /* This call should fail because it mixed H5Eget_auto2 with H5Eset_auto1. + * Once the H5Eset_auto1 is called, a call to H5Eget_auto2 will fail. */ + if((ret = H5Eget_auto2(H5E_DEFAULT, &old_func2, &old_data)) >= 0) + TEST_ERROR; + + return 0; + + error: + return -1; +} +#endif /*H5_USE_16_API_DEFAULT*/ + + +/*------------------------------------------------------------------------- + * Function: test_error3 * * Purpose: Test error API functions * @@ -63,7 +198,7 @@ herr_t custom_print_cb(int n, H5E_error1_t *err_desc, void* client_data); *------------------------------------------------------------------------- */ static herr_t -test_error(hid_t file) +test_error3(hid_t file) { hid_t dataset, space; hsize_t dims[2]; @@ -92,35 +227,21 @@ test_error(hid_t file) goto error; } - /* Test enabling and disabling default printing */ - if (H5Eget_auto1(&old_func, &old_data)<0) - TEST_ERROR; - if (old_data != NULL) - TEST_ERROR; - if (!old_func) - TEST_ERROR; -#ifdef H5_USE_16_API - if (old_func != (H5E_auto1_t)H5Eprint1) - TEST_ERROR; -#else /* H5_USE_16_API */ - if (old_func != (H5E_auto1_t)H5Eprint2) - TEST_ERROR; -#endif /* H5_USE_16_API */ - - if(H5Eset_auto1(NULL, NULL)<0) + /* Disable the library's default printing function */ +#ifdef H5_USE_16_API_DEFAULT + if(H5Eset_auto(NULL, NULL)<0) +#else + if(H5Eset_auto(H5E_DEFAULT, NULL, NULL)<0) +#endif TEST_ERROR; - /* Make H5Dwrite fail, verify default print is disabled */ + /* Make H5Dwrite fail, verify default printing is disabled */ if (H5Dwrite(FAKE_ID, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, ipoints2)<0) { H5Epush1(__FILE__, FUNC_test_error, __LINE__, H5E_ERROR, H5E_WRITEERROR, "H5Dwrite shouldn't succeed"); goto error; } - if(H5Eset_auto1(old_func, old_data)<0) - TEST_ERROR; - - /* In case program comes to this point, close dataset */ if(H5Dclose(dataset)<0) TEST_ERROR; TEST_ERROR; @@ -258,7 +379,13 @@ main(void) H5Eclear1(); /* Test error API */ - if(test_error(file) < 0) { +#ifdef H5_USE_16_API_DEFAULT + if(test_error1() < 0) TEST_ERROR ; +#else /*H5_USE_16_API_DEFAULT*/ + if(test_error2() < 0) TEST_ERROR ; +#endif /*H5_USE_16_API_DEFAULT*/ + + if(test_error3(file) < 0) { H5Epush1(__FILE__, FUNC_main, __LINE__, H5E_ERROR, H5E_BADMESG, "Error test failed"); H5Eprint1(stderr); diff --git a/test/error_test.c b/test/error_test.c index 52dcc0c..6a37b80 100644 --- a/test/error_test.c +++ b/test/error_test.c @@ -21,7 +21,7 @@ */ #include "h5test.h" -#ifdef H5_USE_16_API +#ifdef H5_USE_16_API_DEFAULT int main(void) { printf("Test skipped because backward compatbility with v1.6 is configured in\n"); @@ -127,13 +127,8 @@ test_error(hid_t file) TEST_ERROR; if(old_data != NULL) TEST_ERROR; -#ifdef H5_USE_16_API - if (old_func != (H5E_auto_t)H5Eprint) - TEST_ERROR; -#else /* H5_USE_16_API */ if (old_func != (H5E_auto2_t)H5Eprint2) TEST_ERROR; -#endif /* H5_USE_16_API */ if(H5Eset_auto2(H5E_DEFAULT, NULL, NULL) < 0) TEST_ERROR; diff --git a/test/flush2.c b/test/flush2.c index 5675856..c674426 100644 --- a/test/flush2.c +++ b/test/flush2.c @@ -158,7 +158,7 @@ int main(void) { hid_t fapl; - H5E_auto2_t func; + H5E_auto_t func; char name[1024]; h5_reset(); @@ -178,8 +178,14 @@ main(void) /* Check the case where the file was not flushed. This should give an error * so we turn off the error stack temporarily */ TESTING("H5Fflush (part2 without flush)"); - H5Eget_auto2(H5E_DEFAULT,&func,NULL); - H5Eset_auto2(H5E_DEFAULT, NULL, NULL); + +#ifdef H5_USE_16_API_DEFAULT + H5Eget_auto(&func,NULL); + H5Eset_auto(NULL, NULL); +#else /* H5_USE_16_API_DEFAULT */ + H5Eget_auto(H5E_DEFAULT,&func,NULL); + H5Eset_auto(H5E_DEFAULT, NULL, NULL); +#endif /* H5_USE_16_API_DEFAULT */ h5_fixname(FILENAME[1], fapl, name, sizeof name); if(check_file(name, fapl, FALSE)) @@ -196,13 +202,23 @@ main(void) goto error; #endif } - H5Eset_auto2(H5E_DEFAULT, func, NULL); +#ifdef H5_USE_16_API_DEFAULT + H5Eset_auto(func, NULL); +#else /* H5_USE_16_API_DEFAULT */ + H5Eset_auto(H5E_DEFAULT, func, NULL); +#endif /* H5_USE_16_API_DEFAULT */ /* Check the case where the file was flushed, but more data was added afterward. This should give an error * so we turn off the error stack temporarily */ TESTING("H5Fflush (part2 with flush and later addition)"); - H5Eget_auto2(H5E_DEFAULT,&func,NULL); - H5Eset_auto2(H5E_DEFAULT, NULL, NULL); + +#ifdef H5_USE_16_API_DEFAULT + H5Eget_auto(&func,NULL); + H5Eset_auto(NULL, NULL); +#else /* H5_USE_16_API_DEFAULT */ + H5Eget_auto(H5E_DEFAULT,&func,NULL); + H5Eset_auto(H5E_DEFAULT, NULL, NULL); +#endif /* H5_USE_16_API_DEFAULT */ h5_fixname(FILENAME[2], fapl, name, sizeof name); if(check_file(name, fapl, TRUE)) @@ -220,7 +236,12 @@ main(void) #endif } - H5Eset_auto2(H5E_DEFAULT, func, NULL); +#ifdef H5_USE_16_API_DEFAULT + H5Eset_auto(func, NULL); +#else /* H5_USE_16_API_DEFAULT */ + H5Eset_auto(H5E_DEFAULT, func, NULL); +#endif /* H5_USE_16_API_DEFAULT */ + h5_cleanup(FILENAME, fapl); diff --git a/test/h5test.c b/test/h5test.c index 229efec..d02fea9 100644 --- a/test/h5test.c +++ b/test/h5test.c @@ -212,7 +212,11 @@ h5_reset(void) HDfflush(stdout); HDfflush(stderr); H5close(); - H5Eset_auto2(H5E_DEFAULT, h5_errors, NULL); +#ifdef H5_USE_16_API_DEFAULT + H5Eset_auto(h5_errors, NULL); +#else /* H5_USE_16_API_DEFAULT */ + H5Eset_auto(H5E_DEFAULT, h5_errors, NULL); +#endif /* H5_USE_16_API_DEFAULT */ /* * I commented this chunk of code out because it's not clear what diagnostics diff --git a/test/testerror.sh.in b/test/testerror.sh.in index 7f9657a..440be4f 100644 --- a/test/testerror.sh.in +++ b/test/testerror.sh.in @@ -71,6 +71,8 @@ TEST() { -e 's/line [0-9]*/line (number)/' \ -e 's/v[1-9]*\.[0-9]*\./version (number)\./' \ -e 's/[1-9]*\.[0-9]*\.[0-9]*[^)]*/version (number)/' \ + -e 's/H5Eget_auto[1-2]*/H5Eget_auto(1 or 2)/' \ + -e 's/H5Eset_auto[1-2]*/H5Eset_auto(1 or 2)/' \ $actual_err > $actual_ext cat $actual_ext >> $actual diff --git a/test/testfiles/err_compat_1 b/test/testfiles/err_compat_1 index 032e7bc..f3d11a3 100644 --- a/test/testfiles/err_compat_1 +++ b/test/testfiles/err_compat_1 @@ -1,7 +1,7 @@ ############################# Expected output for err_compat ############################# -Testing error API based on data I/O All error API tests passed. +Testing error API H5Eset/get_auto Testing error API based on data I/O All error API tests passed. This program tests the Error API compatible with HDF5 version (number). There're supposed to be some error messages ********* Print error stack in HDF5 default way ********* HDF5-DIAG: Error detected in HDF5 (version (number)) thread (IDs): @@ -15,6 +15,18 @@ HDF5-DIAG: Error detected in HDF5 (version (number)) thread (IDs): minor: Bad value HDF5-DIAG: Error detected in HDF5 (version (number)) thread (IDs): + #000: (file name) line (number) in H5Dcreate2(): not a location ID + major: Invalid arguments to routine + minor: Inappropriate type + #001: (file name) line (number) in H5G_loc(): invalid object ID + major: Invalid arguments to routine + minor: Bad value +HDF5-DIAG: Error detected in HDF5 (version (number)) thread (IDs): + #000: (file name) line (number) in H5Eget_auto(1 or 2)(): wrong API function, H5Eset_auto(1 or 2) has been called + major: Error API + minor: Can't get value + +HDF5-DIAG: Error detected in HDF5 (version (number)) thread (IDs): #000: (file name) line (number) in main(): Error test failed major: Error API minor: Unrecognized message diff --git a/test/testframe.c b/test/testframe.c index 082a27f..f933d8b 100644 --- a/test/testframe.c +++ b/test/testframe.c @@ -135,7 +135,11 @@ void TestInit(const char *ProgName, void (*private_usage)(void), int (*private_p * half the functions this test calls are private, so automatic error * reporting wouldn't do much good since it's triggered at the API layer. */ - H5Eset_auto2(H5E_DEFAULT, NULL, NULL); +#ifdef H5_USE_16_API_DEFAULT + H5Eset_auto(NULL, NULL); +#else /* H5_USE_16_API_DEFAULT */ + H5Eset_auto(H5E_DEFAULT, NULL, NULL); +#endif /* H5_USE_16_API_DEFAULT */ /* * Record the program name and private routines if provided. diff --git a/test/ttsafe_error.c b/test/ttsafe_error.c index f55afdc..edc5c07 100644 --- a/test/ttsafe_error.c +++ b/test/ttsafe_error.c @@ -158,16 +158,24 @@ void *tts_error_thread(void UNUSED *arg) { hid_t dataspace, datatype, dataset; hsize_t dimsf[1]; /* dataset dimensions */ - H5E_auto2_t old_error_cb; + H5E_auto_t old_error_cb; void *old_error_client_data; int value; int ret; +#ifdef H5_USE_16_API_DEFAULT /* preserve previous error stack handler */ - H5Eget_auto2(H5E_DEFAULT, &old_error_cb, &old_error_client_data); + H5Eget_auto(&old_error_cb, &old_error_client_data); /* set each thread's error stack handler */ - H5Eset_auto2(H5E_DEFAULT, error_callback, NULL); + H5Eset_auto(error_callback, NULL); +#else /* H5_USE_16_API_DEFAULT */ + /* preserve previous error stack handler */ + H5Eget_auto(H5E_DEFAULT, &old_error_cb, &old_error_client_data); + + /* set each thread's error stack handler */ + H5Eset_auto(H5E_DEFAULT, error_callback, NULL); +#endif /* H5_USE_16_API_DEFAULT */ /* define dataspace for dataset */ dimsf[0] = 1; @@ -193,7 +201,11 @@ void *tts_error_thread(void UNUSED *arg) assert(ret >= 0); /* turn our error stack handler off */ - H5Eset_auto2(H5E_DEFAULT, old_error_cb, old_error_client_data); +#ifdef H5_USE_16_API_DEFAULT + H5Eset_auto(old_error_cb, old_error_client_data); +#else /* H5_USE_16_API_DEFAULT */ + H5Eset_auto(H5E_DEFAULT, old_error_cb, old_error_client_data); +#endif /* H5_USE_16_API_DEFAULT */ return NULL; } |