diff options
Diffstat (limited to 'test/vfd.c')
-rw-r--r-- | test/vfd.c | 299 |
1 files changed, 235 insertions, 64 deletions
@@ -50,13 +50,14 @@ const char *FILENAME[] = { "log_file", /*6*/ "stdio_file", /*7*/ "windows_file", /*8*/ + "new_multi_file_v16",/*9*/ NULL }; #define LOG_FILENAME "log_vfd_out.log" #define COMPAT_BASENAME "family_v16_" - +#define MULTI_COMPAT_BASENAME "multi_file_v16" /*------------------------------------------------------------------------- @@ -75,9 +76,9 @@ const char *FILENAME[] = { static herr_t test_sec2(void) { - hid_t file = -1; - hid_t fapl = -1; - hid_t access_fapl = -1; + hid_t file = -1; + hid_t fapl = -1; + hid_t access_fapl = -1; char filename[1024]; int *fhandle = NULL; hsize_t file_size = 0; @@ -156,18 +157,18 @@ test_direct(void) { #ifdef H5_HAVE_DIRECT hid_t file=(-1), fapl, access_fapl = -1; - hid_t dset1=-1, dset2=-1, space1=-1, space2=-1; + hid_t dset1=-1, dset2=-1, space1=-1, space2=-1; char filename[1024]; int *fhandle=NULL; hsize_t file_size; - hsize_t dims1[2], dims2[1]; - size_t mbound; - size_t fbsize; - size_t cbsize; - int *points, *check, *p1, *p2; - int wdata2[DSET2_DIM] = {11,12,13,14}; - int rdata2[DSET2_DIM]; - int i, j, n; + hsize_t dims1[2], dims2[1]; + size_t mbound; + size_t fbsize; + size_t cbsize; + int *points, *check, *p1, *p2; + int wdata2[DSET2_DIM] = {11,12,13,14}; + int rdata2[DSET2_DIM]; + int i, j, n; #endif /*H5_HAVE_DIRECT*/ TESTING("DIRECT I/O file driver"); @@ -188,10 +189,10 @@ test_direct(void) if(H5Pget_fapl_direct(fapl, &mbound, &fbsize, &cbsize) < 0) TEST_ERROR; if(mbound != MBOUNDARY || fbsize != FBSIZE || cbsize != CBSIZE) - TEST_ERROR; + TEST_ERROR; if(H5Pset_alignment(fapl, (hsize_t)THRESHOLD, (hsize_t)FBSIZE) < 0) - TEST_ERROR; + TEST_ERROR; H5E_BEGIN_TRY { file=H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl); @@ -199,7 +200,7 @@ test_direct(void) if(file<0) { H5Pclose (fapl); SKIPPED(); - printf(" Probably the file system doesn't support Direct I/O\n"); + printf(" Probably the file system doesn't support Direct I/O\n"); return 0; } @@ -243,8 +244,8 @@ test_direct(void) /* Initialize the dset1 */ p1 = points; for(i = n = 0; i < DSET1_DIM1; i++) - for(j = 0; j < DSET1_DIM2; j++) - *p1++ = n++; + for(j = 0; j < DSET1_DIM2; j++) + *p1++ = n++; /* Create the data space1 */ dims1[0] = DSET1_DIM1; @@ -274,13 +275,13 @@ test_direct(void) p1 = points; p2 = check; for(i = 0; i < DSET1_DIM1; i++) - for(j = 0; j < DSET1_DIM2; j++) - if(*p1++ != *p2++) { - H5_FAILED(); - printf(" Read different values than written in data set 1.\n"); - printf(" At index %d,%d\n", i, j); - TEST_ERROR; - } /* end if */ + for(j = 0; j < DSET1_DIM2; j++) + if(*p1++ != *p2++) { + H5_FAILED(); + printf(" Read different values than written in data set 1.\n"); + printf(" At index %d,%d\n", i, j); + TEST_ERROR; + } /* end if */ /* Create the data space2. For data set 2, memory address and data size are not aligned. */ dims2[0] = DSET2_DIM; @@ -307,12 +308,12 @@ test_direct(void) /* Check that the values read are the same as the values written */ for(i = 0; i < DSET2_DIM; i++) - if(wdata2[i] != rdata2[i]) { - H5_FAILED(); - printf(" Read different values than written in data set 2.\n"); - printf(" At index %d\n", i); + if(wdata2[i] != rdata2[i]) { + H5_FAILED(); + printf(" Read different values than written in data set 2.\n"); + printf(" At index %d\n", i); TEST_ERROR; - } /* end if */ + } /* end if */ if(H5Sclose(space1) < 0) TEST_ERROR; @@ -325,9 +326,9 @@ test_direct(void) if(H5Fclose(file) < 0) TEST_ERROR; if(points) - free(points); + free(points); if(check) - free(check); + free(check); h5_cleanup(FILENAME, fapl); PASSED(); @@ -367,10 +368,10 @@ test_core(void) char filename[1024]; void *fhandle=NULL; hsize_t file_size; - int *points, *check, *p1, *p2; - hid_t dset1=-1, space1=-1; - hsize_t dims1[2]; - int i, j, n; + int *points, *check, *p1, *p2; + hid_t dset1=-1, space1=-1; + hsize_t dims1[2]; + int i, j, n; TESTING("CORE file driver"); @@ -432,8 +433,8 @@ test_core(void) /* Initialize the dset1 */ p1 = points; for(i = n = 0; i < DSET1_DIM1; i++) - for(j = 0; j < DSET1_DIM2; j++) - *p1++ = n++; + for(j = 0; j < DSET1_DIM2; j++) + *p1++ = n++; /* Create the data space1 */ dims1[0] = DSET1_DIM1; @@ -463,13 +464,13 @@ test_core(void) p1 = points; p2 = check; for(i = 0; i < DSET1_DIM1; i++) - for(j = 0; j < DSET1_DIM2; j++) - if(*p1++ != *p2++) { - H5_FAILED(); - printf(" Read different values than written in data set 1.\n"); - printf(" At index %d,%d\n", i, j); - TEST_ERROR; - } /* end if */ + for(j = 0; j < DSET1_DIM2; j++) + if(*p1++ != *p2++) { + H5_FAILED(); + printf(" Read different values than written in data set 1.\n"); + printf(" At index %d,%d\n", i, j); + TEST_ERROR; + } /* end if */ if(H5Dclose(dset1) < 0) TEST_ERROR; @@ -501,7 +502,7 @@ test_core(void) /* Reallocate memory for reading buffer. */ if(check) - free(check); + free(check); check = (int*)malloc(DSET1_DIM1 * DSET1_DIM2 * sizeof(int)); @@ -513,13 +514,13 @@ test_core(void) p1 = points; p2 = check; for(i = 0; i < DSET1_DIM1; i++) - for(j = 0; j < DSET1_DIM2; j++) - if(*p1++ != *p2++) { - H5_FAILED(); - printf(" Read different values than written in data set 1.\n"); - printf(" At index %d,%d\n", i, j); - TEST_ERROR; - } /* end if */ + for(j = 0; j < DSET1_DIM2; j++) + if(*p1++ != *p2++) { + H5_FAILED(); + printf(" Read different values than written in data set 1.\n"); + printf(" At index %d,%d\n", i, j); + TEST_ERROR; + } /* end if */ /* Check file size API */ if(H5Fget_filesize(file, &file_size) < 0) @@ -537,9 +538,9 @@ test_core(void) if(H5Fclose(file) < 0) TEST_ERROR; if(points) - free(points); + free(points); if(check) - free(check); + free(check); h5_cleanup(FILENAME, fapl); @@ -1123,6 +1124,176 @@ error: /*------------------------------------------------------------------------- + * Function: test_multi_compat + * + * Purpose: Tests the backward compatibility for MULTI driver. + * See if we can open files created with v1.6 library. + * The source file was created by the test/file_handle.c + * of the v1.6 library. This test verifies the fix for + * Issue 2598. In v1.6 library, there was EOA for the whole + * MULTI file saved in the super block. We took it out in + * v1.8 library because it's meaningless for the MULTI file. + * v1.8 library saves the EOA for the metadata file, instead. + * + * Return: Success: 0 + * Failure: -1 + * + * Programmer: Raymond Lu + * 21 June 2011 + * + *------------------------------------------------------------------------- + */ +static herr_t +test_multi_compat(void) +{ + hid_t file=(-1), fapl, fapl2=(-1), dset=(-1), space=(-1); + hid_t access_fapl = -1; + char filename[1024], newname[1024], tmp[1024]; + char filename_s[1024], newname_s[1024]; + char filename_r[1024], newname_r[1024]; + int *fhandle2=NULL, *fhandle=NULL; + hsize_t file_size; + H5FD_mem_t mt, memb_map[H5FD_MEM_NTYPES]; + hid_t memb_fapl[H5FD_MEM_NTYPES]; + haddr_t memb_addr[H5FD_MEM_NTYPES]; + const char *memb_name[H5FD_MEM_NTYPES]; + char sv[H5FD_MEM_NTYPES][32]; + hsize_t dims[2]={MULTI_SIZE, MULTI_SIZE}; + char dname[]="dataset2"; + int i, j; + int buf[MULTI_SIZE][MULTI_SIZE]; + + TESTING("MULTI file driver backward compatibility"); + + /* Set file access property list for MULTI driver */ + fapl = h5_fileaccess(); + + 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<H5FD_MEM_NTYPES; H5_INC_ENUM(H5FD_mem_t,mt)) + memb_map[mt] = H5FD_MEM_SUPER; + memb_map[H5FD_MEM_DRAW] = H5FD_MEM_DRAW; + + memb_fapl[H5FD_MEM_SUPER] = H5P_DEFAULT; + sprintf(sv[H5FD_MEM_SUPER], "%%s-%c.h5", 's'); + memb_name[H5FD_MEM_SUPER] = sv[H5FD_MEM_SUPER]; + memb_addr[H5FD_MEM_SUPER] = 0; + + memb_fapl[H5FD_MEM_DRAW] = H5P_DEFAULT; + sprintf(sv[H5FD_MEM_DRAW], "%%s-%c.h5", 'r'); + memb_name[H5FD_MEM_DRAW] = sv[H5FD_MEM_DRAW]; + memb_addr[H5FD_MEM_DRAW] = HADDR_MAX/2; + + if(H5Pset_fapl_multi(fapl, memb_map, memb_fapl, memb_name, memb_addr, TRUE)<0) + TEST_ERROR; + + h5_fixname(FILENAME[9], fapl, newname, sizeof newname); + + /* Make copy for the data file in the build directory, to protect the + * original file in the source directory */ + sprintf(filename_s, "%s-%c.h5", MULTI_COMPAT_BASENAME, 's'); + sprintf(newname_s, "%s-%c.h5", FILENAME[9], 's'); + h5_make_local_copy(filename_s, newname_s); + + sprintf(filename_r, "%s-%c.h5", MULTI_COMPAT_BASENAME, 'r'); + sprintf(newname_r, "%s-%c.h5", FILENAME[9], 'r'); + h5_make_local_copy(filename_r, newname_r); + + /* Reopen the file for read only. Verify 1.8 library can open file + * created with 1.6 library. */ + if((file=H5Fopen(newname, H5F_ACC_RDONLY, fapl)) < 0) + TEST_ERROR; + + if((dset = H5Dopen2(file, DSET1_NAME, H5P_DEFAULT)) < 0) + TEST_ERROR; + + if(H5Dclose(dset) < 0) + TEST_ERROR; + + if(H5Fclose(file) < 0) + TEST_ERROR; + + /* Make sure we can reopen the file for read and write */ + if((file=H5Fopen(newname, H5F_ACC_RDWR, fapl)) < 0) + TEST_ERROR; + + if((dset = H5Dopen2(file, DSET1_NAME, H5P_DEFAULT)) < 0) + TEST_ERROR; + + if(H5Dclose(dset) < 0) + TEST_ERROR; + + if(H5Fclose(file) < 0) + TEST_ERROR; + + /* Reopen the file for adding another dataset. The new EOA for metadata file + * should be written to the file */ + if((file=H5Fopen(newname, H5F_ACC_RDWR, fapl)) < 0) + TEST_ERROR; + + /* Create and write data set */ + if((space=H5Screate_simple(2, dims, NULL)) < 0) + TEST_ERROR; + + if((dset=H5Dcreate2(file, DSET2_NAME, H5T_NATIVE_INT, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) + TEST_ERROR; + + for(i=0; i<MULTI_SIZE; i++) + for(j=0; j<MULTI_SIZE; j++) + buf[i][j] = i*10000+j; + if(H5Dwrite(dset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf) < 0) + TEST_ERROR; + + if(H5Dclose(dset) < 0) + TEST_ERROR; + + if(H5Sclose(space) < 0) + TEST_ERROR; + + if(H5Fclose(file) < 0) + TEST_ERROR; + + /* Reopen the file for read only again. Verify the library can handle + * the EOA correctly */ + if((file=H5Fopen(newname, H5F_ACC_RDONLY, fapl)) < 0) + TEST_ERROR; + + if((dset = H5Dopen2(file, DSET1_NAME, H5P_DEFAULT)) < 0) + TEST_ERROR; + + if(H5Dclose(dset) < 0) + TEST_ERROR; + + if((dset = H5Dopen2(file, DSET2_NAME, H5P_DEFAULT)) < 0) + TEST_ERROR; + + if(H5Dclose(dset) < 0) + TEST_ERROR; + + if(H5Fclose(file) < 0) + TEST_ERROR; + + h5_cleanup(FILENAME, fapl); + PASSED(); + + return 0; + +error: + H5E_BEGIN_TRY { + H5Sclose(space); + H5Dclose(dset); + H5Pclose(fapl); + H5Fclose(file); + } H5E_END_TRY; + return -1; +} + + +/*------------------------------------------------------------------------- * Function: test_log * * Purpose: Tests the file handle interface for log driver @@ -1226,7 +1397,6 @@ test_stdio(void) FILE *fhandle = NULL; hsize_t file_size = 0; - TESTING("STDIO file driver"); /* Set property list and file name for STDIO driver. */ @@ -1299,7 +1469,7 @@ error: static herr_t test_windows(void) { -#ifdef _WIN32 +#ifdef H5_HAVE_WINDOWS hid_t file = -1; hid_t fapl = -1; @@ -1308,16 +1478,16 @@ test_windows(void) int *fhandle = NULL; hsize_t file_size = 0; -#endif /*_WIN32*/ +#endif /*H5_HAVE_WINDOWS*/ TESTING("WINDOWS file driver"); -#ifndef _WIN32 +#ifndef H5_HAVE_WINDOWS SKIPPED(); return 0; -#else /*_WIN32*/ +#else /* H5_HAVE_WINDOWS */ /* Set property list and file name for WINDOWS driver. */ fapl = h5_fileaccess(); @@ -1370,7 +1540,7 @@ error: } H5E_END_TRY; return -1; -#endif /*_WIN32*/ +#endif /* H5_HAVE_WINDOWS */ } @@ -1402,15 +1572,16 @@ main(void) nerrors += test_family() < 0 ? 1 : 0; nerrors += test_family_compat() < 0 ? 1 : 0; nerrors += test_multi() < 0 ? 1 : 0; + nerrors += test_multi_compat() < 0 ? 1 : 0; nerrors += test_direct() < 0 ? 1 : 0; nerrors += test_log() < 0 ? 1 : 0; nerrors += test_stdio() < 0 ? 1 : 0; nerrors += test_windows() < 0 ? 1 : 0; if(nerrors) { - printf("***** %d Virtual File Driver TEST%s FAILED! *****\n", - nerrors, nerrors > 1 ? "S" : ""); - return 1; + printf("***** %d Virtual File Driver TEST%s FAILED! *****\n", + nerrors, nerrors > 1 ? "S" : ""); + return 1; } printf("All Virtual File Driver tests passed.\n"); |