From c58ca9e28be060b7053b0c91431479bceed45452 Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Fri, 19 Aug 2016 11:30:05 -0500 Subject: [svn-r30306] Updated vfd test to be better about fapls and h5_reset(). Prevents the test from segfaulting in other sub-tests when a previous test fails. Tested on: 64-bit Ubuntu Linux 16.04 LTS w/ gcc 5.4.0 Autotools serial + direct VFD (vfd test only) Also tested with a forced error to ensure that the test no longer segfaults and confirmed that all test files are cleaned up. --- test/vfd.c | 182 +++++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 110 insertions(+), 72 deletions(-) diff --git a/test/vfd.c b/test/vfd.c index a6d979e..c19e0d0 100644 --- a/test/vfd.c +++ b/test/vfd.c @@ -94,8 +94,6 @@ test_sec2(void) TESTING("SEC2 file driver"); - h5_reset(); - /* Set property list and file name for SEC2 driver. */ if((fapl_id = H5Pcreate(H5P_FILE_ACCESS)) < 0) TEST_ERROR; @@ -137,11 +135,15 @@ test_sec2(void) if(file_size < 1 * KB || file_size > 4 * KB) FAIL_PUTS_ERROR("suspicious file size obtained from H5Fget_filesize"); - /* Close the file */ + /* Close and delete the file */ if(H5Fclose(fid) < 0) TEST_ERROR; + h5_delete_test_file(FILENAME[0], fapl_id); + + /* Close the fapl */ + if(H5Pclose(fapl_id) < 0) + TEST_ERROR; - h5_cleanup(FILENAME, fapl_id); PASSED(); return 0; @@ -194,8 +196,6 @@ test_core(void) TESTING("CORE file driver"); - h5_reset(); - /* Get a file access property list and fix up the file name */ if((fapl_id = H5Pcreate(H5P_FILE_ACCESS)) < 0) TEST_ERROR; @@ -453,13 +453,18 @@ test_core(void) TEST_ERROR; if(H5Dclose(did) < 0) TEST_ERROR; - if(H5Fclose(fid) < 0) - TEST_ERROR; HDfree(data_w); HDfree(data_r); - h5_cleanup(FILENAME, fapl_id); + /* Close and delete the file */ + if(H5Fclose(fid) < 0) + TEST_ERROR; + h5_delete_test_file(FILENAME[1], fapl_id); + + /* Close the fapl */ + if(H5Pclose(fapl_id) < 0) + TEST_ERROR; PASSED(); return 0; @@ -499,7 +504,7 @@ static herr_t test_direct(void) { #ifdef H5_HAVE_DIRECT - hid_t file=(-1), fapl, access_fapl = -1; + hid_t file=-1, fapl=-1, access_fapl = -1; hid_t dset1=-1, dset2=-1, space1=-1, space2=-1; char filename[1024]; int *fhandle=NULL; @@ -508,7 +513,7 @@ test_direct(void) size_t mbound; size_t fbsize; size_t cbsize; - int *points = NULL, *check = NULL, *p1, *p2; + int *points = NULL, *check = NULL, *p1 = NULL, *p2 = NULL; int wdata2[DSET2_DIM] = {11,12,13,14}; int rdata2[DSET2_DIM]; int i, j, n; @@ -521,11 +526,10 @@ test_direct(void) return 0; #else /*H5_HAVE_DIRECT*/ - h5_reset(); - /* 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((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0) + TEST_ERROR; if(H5Pset_fapl_direct(fapl, MBOUNDARY, FBSIZE, CBSIZE) < 0) TEST_ERROR; h5_fixname(FILENAME[5], fapl, filename, sizeof filename); @@ -667,14 +671,19 @@ test_direct(void) TEST_ERROR; if(H5Dclose(dset2) < 0) TEST_ERROR; - if(H5Fclose(file) < 0) - TEST_ERROR; - HDassert(points); + HDfree(points); - HDassert(check); HDfree(check); - h5_cleanup(FILENAME, fapl); + /* Close and delete the file */ + if(H5Fclose(file) < 0) + TEST_ERROR; + h5_delete_test_file(FILENAME[5], fapl); + + /* Close the fapl */ + if(H5Pclose(fapl) < 0) + TEST_ERROR; + PASSED(); return 0; @@ -715,7 +724,7 @@ error: static herr_t test_family_opens(char *fname, hid_t fa_pl) { - hid_t file; + hid_t file=-1; char first_name[1024]; char wrong_name[1024]; int i; @@ -786,7 +795,7 @@ error: static herr_t test_family(void) { - hid_t file=(-1), fapl, fapl2=(-1), space=(-1), dset=(-1); + hid_t file=-1, fapl=-1, fapl2=-1, space=-1, dset=-1; hid_t access_fapl = -1; char filename[1024]; char dname[]="dataset"; @@ -798,14 +807,12 @@ test_family(void) TESTING("FAMILY file driver"); - h5_reset(); - /* Set property list and file name for FAMILY driver */ - fapl = h5_fileaccess(); - + if((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0) + TEST_ERROR; if(H5Pset_fapl_family(fapl, (hsize_t)FAMILY_SIZE, H5P_DEFAULT) < 0) TEST_ERROR; - h5_fixname(FILENAME[2], fapl, filename, sizeof filename); + h5_fixname(FILENAME[2], fapl, filename, sizeof(filename)); if((file=H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR; @@ -912,10 +919,15 @@ test_family(void) if((file = H5Fopen(filename, H5F_ACC_RDWR, fapl)) < 0) TEST_ERROR; + /* Close and delete the file */ if(H5Fclose(file) < 0) TEST_ERROR; + h5_delete_test_file(FILENAME[2], fapl); + + /* Close the fapl */ + if(H5Pclose(fapl) < 0) + TEST_ERROR; - h5_cleanup(FILENAME, fapl); PASSED(); return 0; @@ -923,7 +935,8 @@ error: H5E_BEGIN_TRY { H5Sclose(space); H5Dclose(dset); - H5Pclose (fapl2); + H5Pclose(fapl); + H5Pclose(fapl2); H5Fclose(file); } H5E_END_TRY; return -1; @@ -951,8 +964,8 @@ error: static herr_t test_family_compat(void) { - hid_t file = (-1), fapl; - hid_t dset; + hid_t file = -1, fapl = -1; + hid_t dset = -1; char dname[]="dataset"; char filename[1024]; char pathname[1024], pathname_individual[1024]; @@ -961,16 +974,14 @@ test_family_compat(void) TESTING("FAMILY file driver backward compatibility"); - h5_reset(); - /* Set property list and file name for FAMILY driver */ - fapl = h5_fileaccess(); - + if((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0) + TEST_ERROR; if(H5Pset_fapl_family(fapl, (hsize_t)FAMILY_SIZE2, H5P_DEFAULT) < 0) TEST_ERROR; - h5_fixname(COMPAT_BASENAME, fapl, filename, sizeof filename); - h5_fixname(FILENAME[3], fapl, newname, sizeof newname); + h5_fixname(COMPAT_BASENAME, fapl, filename, sizeof(filename)); + h5_fixname(FILENAME[3], fapl, newname, sizeof(newname)); pathname[0] = '\0'; HDstrcat(pathname, filename); @@ -1012,10 +1023,14 @@ test_family_compat(void) if(H5Dclose(dset) < 0) TEST_ERROR; + /* Close and delete the file */ if(H5Fclose(file) < 0) TEST_ERROR; + h5_delete_test_file(FILENAME[3], fapl); - h5_cleanup(FILENAME, fapl); + /* Close the fapl */ + if(H5Pclose(fapl) < 0) + TEST_ERROR; PASSED(); @@ -1048,7 +1063,7 @@ error: static herr_t test_multi_opens(char *fname) { - hid_t file; + hid_t file=-1; char super_name[1024]; /*name string "%%s-s.h5"*/ char sf_name[1024]; /*name string "multi_file-s.h5"*/ @@ -1080,8 +1095,8 @@ test_multi_opens(char *fname) static herr_t test_multi(void) { - hid_t file=(-1), fapl, fapl2=(-1), dset=(-1), space=(-1); - hid_t root, attr, aspace, atype; + hid_t file=-1, fapl=-1, fapl2=-1, dset=-1, space=-1; + hid_t root=-1, attr=-1, aspace=-1, atype=-1; hid_t access_fapl = -1; char filename[1024]; int *fhandle2=NULL, *fhandle=NULL; @@ -1100,16 +1115,15 @@ test_multi(void) TESTING("MULTI file driver"); - h5_reset(); - /* Set file access property list for MULTI driver */ - fapl = h5_fileaccess(); + if((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0) + TEST_ERROR; - HDmemset(memb_map, 0, sizeof memb_map); - HDmemset(memb_fapl, 0, sizeof memb_fapl); - HDmemset(memb_name, 0, sizeof memb_name); - HDmemset(memb_addr, 0, sizeof memb_addr); - HDmemset(sv, 0, sizeof sv); + HDmemset(memb_map, 0, sizeof(memb_map)); + HDmemset(memb_fapl, 0, sizeof(memb_fapl)); + HDmemset(memb_name, 0, sizeof(memb_name)); + HDmemset(memb_addr, 0, sizeof(memb_addr)); + HDmemset(sv, 0, sizeof(sv)); for(mt=H5FD_MEM_DEFAULT; mt 4 * KB) TEST_ERROR; + /* Close and delete the file */ if(H5Fclose(file) < 0) TEST_ERROR; + h5_delete_test_file(FILENAME[6], fapl); + + /* Close the fapl */ + if(H5Pclose(fapl) < 0) + TEST_ERROR; - h5_cleanup(FILENAME, fapl); PASSED(); return 0; @@ -1552,10 +1579,9 @@ test_stdio(void) TESTING("STDIO file driver"); - h5_reset(); - /* Set property list and file name for STDIO driver. */ - fapl = h5_fileaccess(); + if((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0) + TEST_ERROR; if(H5Pset_fapl_stdio(fapl) < 0) TEST_ERROR; h5_fixname(FILENAME[7], fapl, filename, sizeof filename); @@ -1591,10 +1617,15 @@ test_stdio(void) if(file_size < 1 * KB || file_size > 4 * KB) TEST_ERROR; + /* Close and delete the file */ if(H5Fclose(file) < 0) TEST_ERROR; + h5_delete_test_file(FILENAME[7], fapl); + + /* Close the fapl */ + if(H5Pclose(fapl) < 0) + TEST_ERROR; - h5_cleanup(FILENAME, fapl); PASSED(); return 0; @@ -1644,10 +1675,9 @@ test_windows(void) #else /* H5_HAVE_WINDOWS */ - h5_reset(); - /* Set property list and file name for WINDOWS driver. */ - fapl = h5_fileaccess(); + if((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0) + TEST_ERROR; if(H5Pset_fapl_windows(fapl) < 0) TEST_ERROR; h5_fixname(FILENAME[8], fapl, filename, sizeof filename); @@ -1683,10 +1713,15 @@ test_windows(void) if(file_size < 1 * KB || file_size > 4 * KB) TEST_ERROR; + /* Close and delete the file */ if(H5Fclose(file) < 0) TEST_ERROR; + h5_delete_test_file(FILENAME[8], fapl); + + /* Close the fapl */ + if(H5Pclose(fapl) < 0) + TEST_ERROR; - h5_cleanup(FILENAME, fapl); PASSED(); return 0; @@ -1698,7 +1733,7 @@ error: return -1; #endif /* H5_HAVE_WINDOWS */ -} +} /* end test_windows() */ @@ -1720,7 +1755,9 @@ main(void) { int nerrors = 0; - printf("Testing basic Virtual File Driver functionality.\n"); + h5_reset(); + + HDprintf("Testing basic Virtual File Driver functionality.\n"); nerrors += test_sec2() < 0 ? 1 : 0; nerrors += test_core() < 0 ? 1 : 0; @@ -1734,12 +1771,13 @@ main(void) nerrors += test_windows() < 0 ? 1 : 0; if(nerrors) { - printf("***** %d Virtual File Driver TEST%s FAILED! *****\n", + HDprintf("***** %d Virtual File Driver TEST%s FAILED! *****\n", nerrors, nerrors > 1 ? "S" : ""); return 1; - } + } /* end if */ + + HDprintf("All Virtual File Driver tests passed.\n"); - printf("All Virtual File Driver tests passed.\n"); return 0; -} +} /* end main() */ -- cgit v0.12