2005-06-24 22:32:05 +08:00
|
|
|
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
|
|
|
* Copyright by the Board of Trustees of the University of Illinois. *
|
|
|
|
|
* All rights reserved. *
|
|
|
|
|
* *
|
|
|
|
|
* This file is part of HDF5. The full HDF5 copyright notice, including *
|
|
|
|
|
* terms governing use, modification, and redistribution, is contained in *
|
|
|
|
|
* the files COPYING and Copyright.html. COPYING can be found at the root *
|
|
|
|
|
* of the source code distribution tree; Copyright.html can be found at the *
|
|
|
|
|
* root level of an installed copy of the electronic HDF5 document set and *
|
|
|
|
|
* is linked from the top-level documents page. It can also be found at *
|
|
|
|
|
* http://hdf.ncsa.uiuc.edu/HDF5/doc/Copyright.html. If you do not have *
|
|
|
|
|
* access to either file, you may request a copy from hdfhelp@ncsa.uiuc.edu. *
|
|
|
|
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
|
|
|
|
2005-08-14 04:53:35 +08:00
|
|
|
|
/*
|
|
|
|
|
* Programmer: Raymond Lu<slu@ncsa.uiuc.edu>
|
|
|
|
|
* Tuesday, Sept 24, 2002
|
|
|
|
|
*
|
2005-06-24 22:32:05 +08:00
|
|
|
|
* Purpose: Tests the basic features of Virtual File Drivers
|
|
|
|
|
*/
|
2005-08-14 04:53:35 +08:00
|
|
|
|
|
2005-06-24 22:32:05 +08:00
|
|
|
|
#include "h5test.h"
|
|
|
|
|
|
|
|
|
|
#define KB 1024
|
|
|
|
|
#define FAMILY_NUMBER 4
|
|
|
|
|
#define FAMILY_SIZE (1*KB)
|
|
|
|
|
#define FAMILY_SIZE2 (5*KB)
|
2005-08-14 04:53:35 +08:00
|
|
|
|
#define MULTI_SIZE 128
|
2005-06-24 22:32:05 +08:00
|
|
|
|
#define CORE_INCREMENT (4*KB)
|
2006-10-29 05:11:04 +08:00
|
|
|
|
|
|
|
|
|
/*Macros for Direct VFD*/
|
2006-10-19 04:20:32 +08:00
|
|
|
|
#define MBOUNDARY 512
|
2006-10-29 05:11:04 +08:00
|
|
|
|
#define FBSIZE (4*KB)
|
|
|
|
|
#define CBSIZE (8*KB)
|
|
|
|
|
#define THRESHOLD 1
|
|
|
|
|
#define DSET1_NAME "dset1"
|
|
|
|
|
#define DSET1_DIM1 1024
|
|
|
|
|
#define DSET1_DIM2 32
|
|
|
|
|
#define DSET2_NAME "dset2"
|
|
|
|
|
#define DSET2_DIM 4
|
2005-06-24 22:32:05 +08:00
|
|
|
|
|
2005-08-14 04:53:35 +08:00
|
|
|
|
const char *FILENAME[] = {
|
2005-06-24 22:32:05 +08:00
|
|
|
|
"sec2_file",
|
|
|
|
|
"core_file",
|
|
|
|
|
"family_file",
|
|
|
|
|
"multi_file",
|
2006-10-11 04:07:16 +08:00
|
|
|
|
"direct_file",
|
2005-08-14 04:53:35 +08:00
|
|
|
|
NULL
|
2005-06-24 22:32:05 +08:00
|
|
|
|
};
|
2005-08-14 04:53:35 +08:00
|
|
|
|
|
2005-06-24 22:32:05 +08:00
|
|
|
|
#define COMPAT_BASENAME "family_v1.6_"
|
2005-08-14 04:53:35 +08:00
|
|
|
|
|
2005-06-24 22:32:05 +08:00
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
2005-08-14 04:53:35 +08:00
|
|
|
|
* Function: test_sec2
|
2005-06-24 22:32:05 +08:00
|
|
|
|
*
|
|
|
|
|
* Purpose: Tests the file handle interface for SEC2 driver
|
|
|
|
|
*
|
|
|
|
|
* Return: Success: exit(0)
|
|
|
|
|
*
|
|
|
|
|
* Failure: exit(1)
|
|
|
|
|
*
|
|
|
|
|
* Programmer: Raymond Lu
|
|
|
|
|
* Tuesday, Sept 24, 2002
|
|
|
|
|
*
|
|
|
|
|
* Modifications:
|
|
|
|
|
*
|
|
|
|
|
* Raymond Lu
|
|
|
|
|
* Wednesday, June 23, 2004
|
|
|
|
|
* Added test for H5Fget_filesize.
|
|
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
2005-08-14 04:53:35 +08:00
|
|
|
|
static herr_t
|
2005-06-24 22:32:05 +08:00
|
|
|
|
test_sec2(void)
|
|
|
|
|
{
|
|
|
|
|
hid_t file=(-1), fapl, access_fapl = -1;
|
|
|
|
|
char filename[1024];
|
|
|
|
|
int *fhandle=NULL;
|
|
|
|
|
hsize_t file_size;
|
2005-08-14 04:53:35 +08:00
|
|
|
|
|
2005-06-24 22:32:05 +08:00
|
|
|
|
TESTING("SEC2 file driver");
|
2005-08-14 04:53:35 +08:00
|
|
|
|
|
2005-06-24 22:32:05 +08:00
|
|
|
|
/* Set property list and file name for SEC2 driver. */
|
|
|
|
|
fapl = h5_fileaccess();
|
|
|
|
|
if(H5Pset_fapl_sec2(fapl)<0)
|
2005-11-15 10:55:39 +08:00
|
|
|
|
TEST_ERROR;
|
2005-06-24 22:32:05 +08:00
|
|
|
|
h5_fixname(FILENAME[0], fapl, filename, sizeof filename);
|
|
|
|
|
|
|
|
|
|
if((file=H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl))<0)
|
2005-11-15 10:55:39 +08:00
|
|
|
|
TEST_ERROR;
|
2005-06-24 22:32:05 +08:00
|
|
|
|
|
|
|
|
|
/* Retrieve the access property list... */
|
|
|
|
|
if ((access_fapl = H5Fget_access_plist(file)) < 0)
|
2005-11-15 10:55:39 +08:00
|
|
|
|
TEST_ERROR;
|
2005-06-24 22:32:05 +08:00
|
|
|
|
|
|
|
|
|
/* ...and close the property list */
|
|
|
|
|
if (H5Pclose(access_fapl) < 0)
|
2005-11-15 10:55:39 +08:00
|
|
|
|
TEST_ERROR;
|
2005-06-24 22:32:05 +08:00
|
|
|
|
|
|
|
|
|
/* Check file handle API */
|
|
|
|
|
if(H5Fget_vfd_handle(file, H5P_DEFAULT, (void **)&fhandle)<0)
|
2005-11-15 10:55:39 +08:00
|
|
|
|
TEST_ERROR;
|
2005-06-24 22:32:05 +08:00
|
|
|
|
if(*fhandle<0)
|
2005-11-15 10:55:39 +08:00
|
|
|
|
TEST_ERROR;
|
2005-06-24 22:32:05 +08:00
|
|
|
|
|
|
|
|
|
/* Check file size API */
|
|
|
|
|
if(H5Fget_filesize(file, &file_size) < 0)
|
2005-11-15 10:55:39 +08:00
|
|
|
|
TEST_ERROR;
|
2005-06-24 22:32:05 +08:00
|
|
|
|
|
2005-08-14 04:53:35 +08:00
|
|
|
|
/* There is no garantee the size of metadata in file is constant.
|
2005-06-24 22:32:05 +08:00
|
|
|
|
* Just try to check if it's reasonable. It's 2KB right now.
|
2005-08-14 04:53:35 +08:00
|
|
|
|
*/
|
2005-06-24 22:32:05 +08:00
|
|
|
|
if(file_size<1*KB || file_size>4*KB)
|
2005-11-15 10:55:39 +08:00
|
|
|
|
TEST_ERROR;
|
2005-06-24 22:32:05 +08:00
|
|
|
|
|
|
|
|
|
if(H5Fclose(file)<0)
|
2005-11-15 10:55:39 +08:00
|
|
|
|
TEST_ERROR;
|
2005-06-24 22:32:05 +08:00
|
|
|
|
h5_cleanup(FILENAME, fapl);
|
|
|
|
|
PASSED();
|
|
|
|
|
return 0;
|
2005-08-14 04:53:35 +08:00
|
|
|
|
|
2005-06-24 22:32:05 +08:00
|
|
|
|
error:
|
|
|
|
|
H5E_BEGIN_TRY {
|
|
|
|
|
H5Pclose (fapl);
|
|
|
|
|
H5Fclose(file);
|
|
|
|
|
} H5E_END_TRY;
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2006-10-11 04:07:16 +08:00
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
|
* Function: test_direct
|
|
|
|
|
*
|
|
|
|
|
* Purpose: Tests the file handle interface for DIRECT I/O driver
|
|
|
|
|
*
|
|
|
|
|
* Return: Success: exit(0)
|
|
|
|
|
*
|
|
|
|
|
* Failure: exit(1)
|
|
|
|
|
*
|
|
|
|
|
* Programmer: Raymond Lu
|
|
|
|
|
* Wednesday, 20 September 2006
|
|
|
|
|
*
|
|
|
|
|
* Modifications:
|
|
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
static herr_t
|
|
|
|
|
test_direct(void)
|
|
|
|
|
{
|
|
|
|
|
#ifdef H5_HAVE_DIRECT
|
|
|
|
|
hid_t file=(-1), fapl, access_fapl = -1;
|
2006-10-29 05:11:04 +08:00
|
|
|
|
hid_t dset1=-1, dset2=-1, space1=-1, space2=-1;
|
2006-10-11 04:07:16 +08:00
|
|
|
|
char filename[1024];
|
|
|
|
|
int *fhandle=NULL;
|
|
|
|
|
hsize_t file_size;
|
2006-10-29 05:11:04 +08:00
|
|
|
|
hsize_t dims1[2], dims2[1];
|
2006-10-27 10:41:19 +08:00
|
|
|
|
size_t mbound;
|
|
|
|
|
size_t fbsize;
|
|
|
|
|
size_t cbsize;
|
2006-10-29 05:11:04 +08:00
|
|
|
|
int *points, *check, *p1, *p2;
|
|
|
|
|
int wdata2[DSET2_DIM] = {11,12,13,14};
|
|
|
|
|
int rdata2[DSET2_DIM];
|
|
|
|
|
int i, j, n;
|
2006-10-11 04:07:16 +08:00
|
|
|
|
#endif /*H5_HAVE_DIRECT*/
|
|
|
|
|
|
|
|
|
|
TESTING("Direct I/O file driver");
|
|
|
|
|
|
|
|
|
|
#ifndef H5_HAVE_DIRECT
|
|
|
|
|
SKIPPED();
|
|
|
|
|
return 0;
|
|
|
|
|
#else /*H5_HAVE_DIRECT*/
|
|
|
|
|
|
2006-10-17 06:31:27 +08:00
|
|
|
|
/* 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. */
|
2006-10-11 04:07:16 +08:00
|
|
|
|
fapl = h5_fileaccess();
|
2006-10-19 04:20:32 +08:00
|
|
|
|
if(H5Pset_fapl_direct(fapl, MBOUNDARY, FBSIZE, CBSIZE)<0)
|
2006-10-11 04:07:16 +08:00
|
|
|
|
TEST_ERROR;
|
|
|
|
|
h5_fixname(FILENAME[4], fapl, filename, sizeof filename);
|
|
|
|
|
|
2006-10-19 04:20:32 +08:00
|
|
|
|
/* Verify the file access properties */
|
|
|
|
|
if(H5Pget_fapl_direct(fapl, &mbound, &fbsize, &cbsize)<0)
|
|
|
|
|
TEST_ERROR;
|
|
|
|
|
if(mbound != MBOUNDARY || fbsize != FBSIZE || cbsize != CBSIZE)
|
|
|
|
|
TEST_ERROR;
|
|
|
|
|
|
2006-10-29 05:11:04 +08:00
|
|
|
|
if(H5Pset_alignment(fapl, (hsize_t)THRESHOLD, (hsize_t)FBSIZE)<0)
|
|
|
|
|
TEST_ERROR;
|
|
|
|
|
|
2006-10-11 04:07:16 +08:00
|
|
|
|
if((file=H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl))<0)
|
|
|
|
|
TEST_ERROR;
|
|
|
|
|
|
|
|
|
|
/* Retrieve the access property list... */
|
|
|
|
|
if ((access_fapl = H5Fget_access_plist(file)) < 0)
|
|
|
|
|
TEST_ERROR;
|
|
|
|
|
|
|
|
|
|
/* ...and close the property list */
|
|
|
|
|
if (H5Pclose(access_fapl) < 0)
|
|
|
|
|
TEST_ERROR;
|
|
|
|
|
|
|
|
|
|
/* Check file handle API */
|
|
|
|
|
if(H5Fget_vfd_handle(file, H5P_DEFAULT, (void **)&fhandle)<0)
|
|
|
|
|
TEST_ERROR;
|
|
|
|
|
if(*fhandle<0)
|
|
|
|
|
TEST_ERROR;
|
|
|
|
|
|
|
|
|
|
/* Check file size API */
|
|
|
|
|
if(H5Fget_filesize(file, &file_size) < 0)
|
|
|
|
|
TEST_ERROR;
|
|
|
|
|
|
|
|
|
|
/* There is no garantee the size of metadata in file is constant.
|
|
|
|
|
* Just try to check if it's reasonable. It's 2KB right now.
|
|
|
|
|
*/
|
|
|
|
|
if(file_size<1*KB || file_size>4*KB)
|
|
|
|
|
TEST_ERROR;
|
|
|
|
|
|
2006-11-07 06:17:46 +08:00
|
|
|
|
#ifdef H5_HAVE_DIRECT_ALIGN
|
2006-10-29 05:11:04 +08:00
|
|
|
|
/* Allocate aligned memory for data set 1. For data set 1, everything is aligned including
|
|
|
|
|
* memory address, size of data, and file address. */
|
|
|
|
|
if(posix_memalign(&points, (size_t)FBSIZE, (size_t)(DSET1_DIM1*DSET1_DIM2*sizeof(int)))!=0)
|
|
|
|
|
TEST_ERROR;
|
|
|
|
|
|
|
|
|
|
if(posix_memalign(&check, (size_t)FBSIZE, (size_t)(DSET1_DIM1*DSET1_DIM2*sizeof(int)))!=0)
|
|
|
|
|
TEST_ERROR;
|
2006-11-07 06:17:46 +08:00
|
|
|
|
#else
|
|
|
|
|
/* Allocate aligned memory for data set 1. No need for alignment. */
|
|
|
|
|
points=(int*)malloc(DSET1_DIM1*DSET1_DIM2*sizeof(int));
|
|
|
|
|
check=(int*)malloc(DSET1_DIM1*DSET1_DIM2*sizeof(int));
|
|
|
|
|
#endif
|
2006-10-29 05:11:04 +08:00
|
|
|
|
|
|
|
|
|
/* Initialize the dset1 */
|
|
|
|
|
p1 = points;
|
|
|
|
|
for (i = n = 0; i < DSET1_DIM1; i++)
|
|
|
|
|
for (j = 0; j < DSET1_DIM2; j++)
|
|
|
|
|
*p1++ = n++;
|
|
|
|
|
|
|
|
|
|
/* Create the data space1 */
|
|
|
|
|
dims1[0] = DSET1_DIM1;
|
|
|
|
|
dims1[1] = DSET1_DIM2;
|
|
|
|
|
if ((space1 = H5Screate_simple(2, dims1, NULL))<0)
|
|
|
|
|
TEST_ERROR;
|
|
|
|
|
|
|
|
|
|
/* Create the dset1 */
|
|
|
|
|
if ((dset1 = H5Dcreate(file, DSET1_NAME, H5T_NATIVE_INT, space1, H5P_DEFAULT))<0)
|
|
|
|
|
TEST_ERROR;
|
|
|
|
|
|
|
|
|
|
/* Write the data to the dset1 */
|
|
|
|
|
if (H5Dwrite(dset1, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, points)<0)
|
|
|
|
|
TEST_ERROR;
|
|
|
|
|
|
|
|
|
|
if(H5Dclose(dset1)<0)
|
|
|
|
|
TEST_ERROR;
|
|
|
|
|
|
|
|
|
|
if((dset1=H5Dopen(file, DSET1_NAME))<0)
|
|
|
|
|
TEST_ERROR;
|
|
|
|
|
|
|
|
|
|
/* Read the data back from dset1 */
|
|
|
|
|
if (H5Dread(dset1, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, check)<0)
|
|
|
|
|
TEST_ERROR;
|
|
|
|
|
|
|
|
|
|
/* Check that the values read are the same as the values written */
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Create the data space2. For data set 2, memory address and data size are not aligned. */
|
|
|
|
|
dims2[0] = DSET2_DIM;
|
|
|
|
|
if ((space2 = H5Screate_simple(1, dims2, NULL))<0)
|
|
|
|
|
TEST_ERROR;
|
|
|
|
|
|
|
|
|
|
/* Create the dset2 */
|
|
|
|
|
if ((dset2 = H5Dcreate(file, DSET2_NAME, H5T_NATIVE_INT, space2, H5P_DEFAULT))<0)
|
|
|
|
|
TEST_ERROR;
|
|
|
|
|
|
|
|
|
|
/* Write the data to the dset1 */
|
|
|
|
|
if (H5Dwrite(dset2, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, wdata2)<0)
|
|
|
|
|
TEST_ERROR;
|
|
|
|
|
|
|
|
|
|
if(H5Dclose(dset2)<0)
|
|
|
|
|
TEST_ERROR;
|
|
|
|
|
|
|
|
|
|
if((dset2=H5Dopen(file, DSET2_NAME))<0)
|
|
|
|
|
TEST_ERROR;
|
|
|
|
|
|
|
|
|
|
/* Read the data back from dset1 */
|
|
|
|
|
if (H5Dread(dset2, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, rdata2)<0)
|
|
|
|
|
TEST_ERROR;
|
|
|
|
|
|
|
|
|
|
/* 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);
|
|
|
|
|
TEST_ERROR;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(H5Sclose(space1)<0)
|
|
|
|
|
TEST_ERROR;
|
|
|
|
|
if(H5Dclose(dset1)<0)
|
|
|
|
|
TEST_ERROR;
|
|
|
|
|
if(H5Sclose(space2)<0)
|
|
|
|
|
TEST_ERROR;
|
|
|
|
|
if(H5Dclose(dset2)<0)
|
|
|
|
|
TEST_ERROR;
|
2006-10-11 04:07:16 +08:00
|
|
|
|
if(H5Fclose(file)<0)
|
|
|
|
|
TEST_ERROR;
|
2006-10-29 05:11:04 +08:00
|
|
|
|
if(points)
|
|
|
|
|
free(points);
|
|
|
|
|
if(check)
|
|
|
|
|
free(check);
|
|
|
|
|
|
2006-10-11 04:07:16 +08:00
|
|
|
|
h5_cleanup(FILENAME, fapl);
|
|
|
|
|
PASSED();
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
error:
|
|
|
|
|
H5E_BEGIN_TRY {
|
|
|
|
|
H5Pclose (fapl);
|
2006-10-29 05:11:04 +08:00
|
|
|
|
H5Sclose(space1);
|
|
|
|
|
H5Dclose(dset1);
|
|
|
|
|
H5Sclose(space2);
|
|
|
|
|
H5Dclose(dset2);
|
2006-10-11 04:07:16 +08:00
|
|
|
|
H5Fclose(file);
|
|
|
|
|
} H5E_END_TRY;
|
|
|
|
|
return -1;
|
|
|
|
|
#endif /*H5_HAVE_DIRECT*/
|
|
|
|
|
}
|
|
|
|
|
|
2005-06-24 22:32:05 +08:00
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
2005-08-14 04:53:35 +08:00
|
|
|
|
* Function: test_core
|
|
|
|
|
*
|
2005-06-24 22:32:05 +08:00
|
|
|
|
* Purpose: Tests the file handle interface for CORE driver
|
2005-08-14 04:53:35 +08:00
|
|
|
|
*
|
2005-06-24 22:32:05 +08:00
|
|
|
|
* Return: Success: exit(0)
|
2005-08-14 04:53:35 +08:00
|
|
|
|
*
|
2005-06-24 22:32:05 +08:00
|
|
|
|
* Failure: exit(1)
|
2005-08-14 04:53:35 +08:00
|
|
|
|
*
|
2005-06-24 22:32:05 +08:00
|
|
|
|
* Programmer: Raymond Lu
|
|
|
|
|
* Tuesday, Sept 24, 2002
|
2005-08-14 04:53:35 +08:00
|
|
|
|
*
|
2005-06-24 22:32:05 +08:00
|
|
|
|
* Modifications:
|
|
|
|
|
*
|
|
|
|
|
* Raymond Lu
|
|
|
|
|
* Wednesday, June 23, 2004
|
|
|
|
|
* Added test for H5Fget_filesize.
|
2005-08-14 04:53:35 +08:00
|
|
|
|
*
|
2005-06-24 22:32:05 +08:00
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
static herr_t
|
|
|
|
|
test_core(void)
|
|
|
|
|
{
|
|
|
|
|
hid_t file=(-1), fapl, access_fapl = -1;
|
|
|
|
|
char filename[1024];
|
|
|
|
|
void *fhandle=NULL;
|
|
|
|
|
hsize_t file_size;
|
|
|
|
|
|
|
|
|
|
TESTING("CORE file driver");
|
|
|
|
|
|
|
|
|
|
/* Set property list and file name for CORE driver */
|
|
|
|
|
fapl = h5_fileaccess();
|
|
|
|
|
if(H5Pset_fapl_core(fapl, CORE_INCREMENT, TRUE)<0)
|
2005-11-15 10:55:39 +08:00
|
|
|
|
TEST_ERROR;
|
2005-06-24 22:32:05 +08:00
|
|
|
|
h5_fixname(FILENAME[1], fapl, filename, sizeof filename);
|
2005-08-14 04:53:35 +08:00
|
|
|
|
|
2005-06-24 22:32:05 +08:00
|
|
|
|
if((file=H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl))<0)
|
2005-11-15 10:55:39 +08:00
|
|
|
|
TEST_ERROR;
|
2005-06-24 22:32:05 +08:00
|
|
|
|
|
|
|
|
|
/* Retrieve the access property list... */
|
|
|
|
|
if ((access_fapl = H5Fget_access_plist(file)) < 0)
|
2005-11-15 10:55:39 +08:00
|
|
|
|
TEST_ERROR;
|
2005-06-24 22:32:05 +08:00
|
|
|
|
|
|
|
|
|
/* ...and close the property list */
|
|
|
|
|
if (H5Pclose(access_fapl) < 0)
|
2005-11-15 10:55:39 +08:00
|
|
|
|
TEST_ERROR;
|
2005-06-24 22:32:05 +08:00
|
|
|
|
|
|
|
|
|
if(H5Fget_vfd_handle(file, H5P_DEFAULT, &fhandle)<0)
|
2005-11-15 10:55:39 +08:00
|
|
|
|
TEST_ERROR;
|
2005-06-24 22:32:05 +08:00
|
|
|
|
if(fhandle==NULL)
|
|
|
|
|
{
|
|
|
|
|
printf("fhandle==NULL\n");
|
2005-11-15 10:55:39 +08:00
|
|
|
|
TEST_ERROR;
|
2005-06-24 22:32:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Check file size API */
|
|
|
|
|
if(H5Fget_filesize(file, &file_size) < 0)
|
2005-11-15 10:55:39 +08:00
|
|
|
|
TEST_ERROR;
|
2005-06-24 22:32:05 +08:00
|
|
|
|
|
2005-08-14 04:53:35 +08:00
|
|
|
|
/* There is no garantee the size of metadata in file is constant.
|
|
|
|
|
* Just try to check if it's reasonable. Why is this 4KB?
|
|
|
|
|
*/
|
2005-06-24 22:32:05 +08:00
|
|
|
|
if(file_size<2*KB || file_size>6*KB)
|
2005-11-15 10:55:39 +08:00
|
|
|
|
TEST_ERROR;
|
2005-06-24 22:32:05 +08:00
|
|
|
|
|
|
|
|
|
if(H5Fclose(file)<0)
|
2005-11-15 10:55:39 +08:00
|
|
|
|
TEST_ERROR;
|
2005-06-24 22:32:05 +08:00
|
|
|
|
h5_cleanup(FILENAME, fapl);
|
|
|
|
|
PASSED();
|
|
|
|
|
return 0;
|
2005-08-14 04:53:35 +08:00
|
|
|
|
|
2005-06-24 22:32:05 +08:00
|
|
|
|
error:
|
|
|
|
|
H5E_BEGIN_TRY {
|
|
|
|
|
H5Pclose (fapl);
|
|
|
|
|
H5Fclose(file);
|
|
|
|
|
} H5E_END_TRY;
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
|
* Function: test_family_opens
|
|
|
|
|
*
|
|
|
|
|
* Purpose: Private function for test_family() to tests wrong ways of
|
|
|
|
|
* reopening family file.
|
|
|
|
|
*
|
|
|
|
|
* Return: Success: exit(0)
|
|
|
|
|
*
|
|
|
|
|
* Failure: exit(1)
|
|
|
|
|
*
|
|
|
|
|
* Programmer: Raymond Lu
|
|
|
|
|
* Thursday, May 19, 2005
|
|
|
|
|
*
|
|
|
|
|
* Modifications:
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
static herr_t
|
|
|
|
|
test_family_opens(char *fname, hid_t fa_pl)
|
|
|
|
|
{
|
|
|
|
|
hid_t file;
|
|
|
|
|
char first_name[1024];
|
|
|
|
|
char wrong_name[1024];
|
|
|
|
|
int i;
|
|
|
|
|
|
2005-08-14 04:53:35 +08:00
|
|
|
|
/* Case 1: reopen file with 1st member file name and default property list */
|
2005-06-24 22:32:05 +08:00
|
|
|
|
sprintf(first_name, fname, 0);
|
2005-08-14 04:53:35 +08:00
|
|
|
|
|
2005-06-24 22:32:05 +08:00
|
|
|
|
H5E_BEGIN_TRY {
|
|
|
|
|
file=H5Fopen(first_name, H5F_ACC_RDWR, H5P_DEFAULT);
|
|
|
|
|
} H5E_END_TRY;
|
2006-10-03 02:32:46 +08:00
|
|
|
|
if(file >= 0) TEST_ERROR
|
2005-06-24 22:32:05 +08:00
|
|
|
|
|
|
|
|
|
/* Case 2: reopen file with correct name template but default property list */
|
|
|
|
|
H5E_BEGIN_TRY {
|
|
|
|
|
file=H5Fopen(fname, H5F_ACC_RDWR, H5P_DEFAULT);
|
|
|
|
|
} H5E_END_TRY;
|
2006-10-03 02:32:46 +08:00
|
|
|
|
if(file >= 0) TEST_ERROR
|
2005-06-24 22:32:05 +08:00
|
|
|
|
|
|
|
|
|
/* Case 3: reopen file with wrong member size */
|
|
|
|
|
if(H5Pset_fapl_family(fa_pl, (hsize_t)128, H5P_DEFAULT)<0)
|
2005-11-15 10:55:39 +08:00
|
|
|
|
TEST_ERROR;
|
2005-06-24 22:32:05 +08:00
|
|
|
|
|
|
|
|
|
H5E_BEGIN_TRY {
|
|
|
|
|
file=H5Fopen(fname, H5F_ACC_RDWR, fa_pl);
|
|
|
|
|
} H5E_END_TRY;
|
2006-10-03 02:32:46 +08:00
|
|
|
|
if(file >= 0) TEST_ERROR
|
2005-08-14 04:53:35 +08:00
|
|
|
|
|
2005-06-24 22:32:05 +08:00
|
|
|
|
/* Case 4: reopen file with wrong name template */
|
2006-10-03 02:32:46 +08:00
|
|
|
|
HDstrcpy(wrong_name, fname);
|
|
|
|
|
for(i = 0; i < 1024; i++)
|
2005-06-24 22:32:05 +08:00
|
|
|
|
if(wrong_name[i] == '5') {
|
|
|
|
|
wrong_name[i] = '4';
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(H5Pset_fapl_family(fa_pl, (hsize_t)FAMILY_SIZE, H5P_DEFAULT)<0)
|
2005-11-15 10:55:39 +08:00
|
|
|
|
TEST_ERROR;
|
2005-06-24 22:32:05 +08:00
|
|
|
|
|
|
|
|
|
H5E_BEGIN_TRY {
|
|
|
|
|
file=H5Fopen(wrong_name, H5F_ACC_RDWR, fa_pl);
|
|
|
|
|
} H5E_END_TRY;
|
2006-10-03 02:32:46 +08:00
|
|
|
|
if(file >= 0) TEST_ERROR
|
2005-06-24 22:32:05 +08:00
|
|
|
|
|
|
|
|
|
return 0;
|
2006-10-03 02:32:46 +08:00
|
|
|
|
|
2005-06-24 22:32:05 +08:00
|
|
|
|
error:
|
|
|
|
|
return -1;
|
2006-10-03 02:32:46 +08:00
|
|
|
|
} /* end test_family_opens() */
|
2005-06-24 22:32:05 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
|
* Function: test_family
|
|
|
|
|
*
|
|
|
|
|
* Purpose: Tests the file handle interface for FAMILY driver
|
|
|
|
|
*
|
|
|
|
|
* Return: Success: exit(0)
|
|
|
|
|
*
|
|
|
|
|
* Failure: exit(1)
|
|
|
|
|
*
|
|
|
|
|
* Programmer: Raymond Lu
|
|
|
|
|
* Tuesday, Sept 24, 2002
|
|
|
|
|
*
|
|
|
|
|
* Modifications:
|
|
|
|
|
*
|
|
|
|
|
* Raymond Lu
|
|
|
|
|
* Wednesday, June 23, 2004
|
|
|
|
|
* Added test for H5Fget_filesize.
|
|
|
|
|
*
|
|
|
|
|
* Raymond Lu
|
|
|
|
|
* June 2, 2005
|
2005-08-14 04:53:35 +08:00
|
|
|
|
* Added a function test_family_opens() to test different
|
2005-06-24 22:32:05 +08:00
|
|
|
|
* wrong way to reopen family files.
|
|
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
static herr_t
|
|
|
|
|
test_family(void)
|
|
|
|
|
{
|
|
|
|
|
hid_t file=(-1), fapl, fapl2=(-1), space=(-1), dset=(-1);
|
|
|
|
|
hid_t access_fapl = -1;
|
|
|
|
|
char filename[1024];
|
|
|
|
|
char dname[]="dataset";
|
|
|
|
|
int i, j;
|
|
|
|
|
int *fhandle=NULL, *fhandle2=NULL;
|
|
|
|
|
int buf[FAMILY_NUMBER][FAMILY_SIZE];
|
|
|
|
|
hsize_t dims[2]={FAMILY_NUMBER, FAMILY_SIZE};
|
|
|
|
|
hsize_t file_size;
|
|
|
|
|
|
|
|
|
|
TESTING("FAMILY file driver");
|
|
|
|
|
|
|
|
|
|
/* Set property list and file name for FAMILY driver */
|
|
|
|
|
fapl = h5_fileaccess();
|
|
|
|
|
|
|
|
|
|
if(H5Pset_fapl_family(fapl, (hsize_t)FAMILY_SIZE, H5P_DEFAULT)<0)
|
2005-11-15 10:55:39 +08:00
|
|
|
|
TEST_ERROR;
|
2005-06-24 22:32:05 +08:00
|
|
|
|
h5_fixname(FILENAME[2], fapl, filename, sizeof filename);
|
|
|
|
|
|
|
|
|
|
if((file=H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl))<0)
|
2005-11-15 10:55:39 +08:00
|
|
|
|
TEST_ERROR;
|
2005-06-24 22:32:05 +08:00
|
|
|
|
|
|
|
|
|
if(H5Fclose(file)<0)
|
2005-11-15 10:55:39 +08:00
|
|
|
|
TEST_ERROR;
|
2005-06-24 22:32:05 +08:00
|
|
|
|
|
2005-08-14 04:53:35 +08:00
|
|
|
|
/* Test different wrong ways to reopen family files where there's only
|
2005-06-24 22:32:05 +08:00
|
|
|
|
* one member file existing. */
|
2006-10-03 02:32:46 +08:00
|
|
|
|
if(test_family_opens(filename, fapl) < 0)
|
2005-11-15 10:55:39 +08:00
|
|
|
|
TEST_ERROR;
|
2005-06-24 22:32:05 +08:00
|
|
|
|
|
|
|
|
|
/* Reopen the file with default member file size */
|
|
|
|
|
if(H5Pset_fapl_family(fapl, (hsize_t)H5F_FAMILY_DEFAULT, H5P_DEFAULT)<0)
|
2005-11-15 10:55:39 +08:00
|
|
|
|
TEST_ERROR;
|
2005-06-24 22:32:05 +08:00
|
|
|
|
|
|
|
|
|
if((file=H5Fopen(filename, H5F_ACC_RDWR, fapl))<0)
|
2005-11-15 10:55:39 +08:00
|
|
|
|
TEST_ERROR;
|
2005-06-24 22:32:05 +08:00
|
|
|
|
|
|
|
|
|
/* Check file size API */
|
|
|
|
|
if(H5Fget_filesize(file, &file_size) < 0)
|
2005-11-15 10:55:39 +08:00
|
|
|
|
TEST_ERROR;
|
2005-06-24 22:32:05 +08:00
|
|
|
|
|
2006-10-03 02:32:46 +08:00
|
|
|
|
/* The file size is supposed to be about 800 bytes right now. */
|
|
|
|
|
if(file_size < (KB / 2) || file_size > KB)
|
2005-11-15 10:55:39 +08:00
|
|
|
|
TEST_ERROR;
|
2005-06-24 22:32:05 +08:00
|
|
|
|
|
|
|
|
|
/* Create and write dataset */
|
|
|
|
|
if((space=H5Screate_simple(2, dims, NULL))<0)
|
2005-11-15 10:55:39 +08:00
|
|
|
|
TEST_ERROR;
|
2005-06-24 22:32:05 +08:00
|
|
|
|
|
|
|
|
|
/* Retrieve the access property list... */
|
|
|
|
|
if ((access_fapl = H5Fget_access_plist(file)) < 0)
|
2005-11-15 10:55:39 +08:00
|
|
|
|
TEST_ERROR;
|
2005-06-24 22:32:05 +08:00
|
|
|
|
|
|
|
|
|
/* ...and close the property list */
|
|
|
|
|
if (H5Pclose(access_fapl) < 0)
|
2005-11-15 10:55:39 +08:00
|
|
|
|
TEST_ERROR;
|
2005-06-24 22:32:05 +08:00
|
|
|
|
|
|
|
|
|
if((dset=H5Dcreate(file, dname, H5T_NATIVE_INT, space, H5P_DEFAULT))<0)
|
2005-11-15 10:55:39 +08:00
|
|
|
|
TEST_ERROR;
|
2005-06-24 22:32:05 +08:00
|
|
|
|
|
|
|
|
|
for(i=0; i<FAMILY_NUMBER; i++)
|
|
|
|
|
for(j=0; j<FAMILY_SIZE; j++)
|
|
|
|
|
buf[i][j] = i*10000+j;
|
2005-08-14 04:53:35 +08:00
|
|
|
|
if(H5Dwrite(dset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf)<0)
|
2005-11-15 10:55:39 +08:00
|
|
|
|
TEST_ERROR;
|
2005-06-24 22:32:05 +08:00
|
|
|
|
|
|
|
|
|
/* check file handle API */
|
|
|
|
|
if((fapl2=H5Pcreate(H5P_FILE_ACCESS))<0)
|
2005-11-15 10:55:39 +08:00
|
|
|
|
TEST_ERROR;
|
2005-06-24 22:32:05 +08:00
|
|
|
|
if(H5Pset_family_offset(fapl2, (hsize_t)0)<0)
|
2005-11-15 10:55:39 +08:00
|
|
|
|
TEST_ERROR;
|
2005-06-24 22:32:05 +08:00
|
|
|
|
|
|
|
|
|
if(H5Fget_vfd_handle(file, fapl2, (void **)&fhandle)<0)
|
2005-11-15 10:55:39 +08:00
|
|
|
|
TEST_ERROR;
|
2005-06-24 22:32:05 +08:00
|
|
|
|
if(*fhandle<0)
|
2005-11-15 10:55:39 +08:00
|
|
|
|
TEST_ERROR;
|
2005-06-24 22:32:05 +08:00
|
|
|
|
|
|
|
|
|
if(H5Pset_family_offset(fapl2, (hsize_t)(FAMILY_SIZE*2))<0)
|
2005-11-15 10:55:39 +08:00
|
|
|
|
TEST_ERROR;
|
2005-06-24 22:32:05 +08:00
|
|
|
|
if(H5Fget_vfd_handle(file, fapl2, (void **)&fhandle2)<0)
|
2005-11-15 10:55:39 +08:00
|
|
|
|
TEST_ERROR;
|
2005-06-24 22:32:05 +08:00
|
|
|
|
if(*fhandle2<0)
|
2005-11-15 10:55:39 +08:00
|
|
|
|
TEST_ERROR;
|
2005-06-24 22:32:05 +08:00
|
|
|
|
|
|
|
|
|
/* Check file size API */
|
|
|
|
|
if(H5Fget_filesize(file, &file_size) < 0)
|
2005-11-15 10:55:39 +08:00
|
|
|
|
TEST_ERROR;
|
2005-06-24 22:32:05 +08:00
|
|
|
|
|
2005-08-14 04:53:35 +08:00
|
|
|
|
/* Some data has been written. The file size should be bigger(18KB+976
|
|
|
|
|
* bytes if int size is 4 bytes) now. */
|
2005-06-24 22:32:05 +08:00
|
|
|
|
if(sizeof(int)<=4) {
|
|
|
|
|
if(file_size<18*KB || file_size>20*KB)
|
2005-11-15 10:55:39 +08:00
|
|
|
|
TEST_ERROR;
|
2005-06-24 22:32:05 +08:00
|
|
|
|
} else if(sizeof(int)>=8) {
|
|
|
|
|
if(file_size<32*KB || file_size>40*KB)
|
2005-11-15 10:55:39 +08:00
|
|
|
|
TEST_ERROR;
|
2005-06-24 22:32:05 +08:00
|
|
|
|
}
|
2005-08-14 04:53:35 +08:00
|
|
|
|
|
2005-06-24 22:32:05 +08:00
|
|
|
|
if(H5Sclose(space)<0)
|
2005-11-15 10:55:39 +08:00
|
|
|
|
TEST_ERROR;
|
2005-06-24 22:32:05 +08:00
|
|
|
|
if(H5Dclose(dset)<0)
|
2005-11-15 10:55:39 +08:00
|
|
|
|
TEST_ERROR;
|
2005-06-24 22:32:05 +08:00
|
|
|
|
if(H5Pclose(fapl2)<0)
|
2005-11-15 10:55:39 +08:00
|
|
|
|
TEST_ERROR;
|
2005-06-24 22:32:05 +08:00
|
|
|
|
if(H5Fclose(file)<0)
|
2005-11-15 10:55:39 +08:00
|
|
|
|
TEST_ERROR;
|
2005-06-24 22:32:05 +08:00
|
|
|
|
|
|
|
|
|
/* Test different wrong ways to reopen family files when there're multiple
|
|
|
|
|
* member files existing. */
|
|
|
|
|
if(test_family_opens(filename, fapl)<0)
|
2005-11-15 10:55:39 +08:00
|
|
|
|
TEST_ERROR;
|
2005-06-24 22:32:05 +08:00
|
|
|
|
|
|
|
|
|
/* Reopen the file with correct member file size. */
|
|
|
|
|
if(H5Pset_fapl_family(fapl, (hsize_t)FAMILY_SIZE, H5P_DEFAULT)<0)
|
2005-11-15 10:55:39 +08:00
|
|
|
|
TEST_ERROR;
|
2005-06-24 22:32:05 +08:00
|
|
|
|
|
|
|
|
|
if((file=H5Fopen(filename, H5F_ACC_RDWR, fapl))<0)
|
2005-11-15 10:55:39 +08:00
|
|
|
|
TEST_ERROR;
|
2005-06-24 22:32:05 +08:00
|
|
|
|
|
|
|
|
|
if(H5Fclose(file)<0)
|
2005-11-15 10:55:39 +08:00
|
|
|
|
TEST_ERROR;
|
2005-08-14 04:53:35 +08:00
|
|
|
|
|
2005-06-24 22:32:05 +08:00
|
|
|
|
h5_cleanup(FILENAME, fapl);
|
|
|
|
|
PASSED();
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
error:
|
|
|
|
|
H5E_BEGIN_TRY {
|
|
|
|
|
H5Sclose(space);
|
|
|
|
|
H5Dclose(dset);
|
|
|
|
|
H5Pclose (fapl2);
|
|
|
|
|
H5Fclose(file);
|
|
|
|
|
} H5E_END_TRY;
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
|
* Function: test_family_compat
|
|
|
|
|
*
|
2005-08-14 04:53:35 +08:00
|
|
|
|
* Purpose: Tests the backward compatibility for FAMILY driver.
|
2005-06-24 22:32:05 +08:00
|
|
|
|
* 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. Then tools/misc/h5repart.c was
|
|
|
|
|
* used to concantenated. The command was "h5repart -m 5k
|
|
|
|
|
* family_file%05d.h5 family_v1.6_%05d.h5".
|
|
|
|
|
*
|
|
|
|
|
* Return: Success: exit(0)
|
|
|
|
|
*
|
|
|
|
|
* Failure: exit(1)
|
|
|
|
|
*
|
|
|
|
|
* Programmer: Raymond Lu
|
|
|
|
|
* June 3, 2005
|
|
|
|
|
*
|
|
|
|
|
* Modifications:
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
2005-08-14 04:53:35 +08:00
|
|
|
|
static herr_t
|
2005-06-24 22:32:05 +08:00
|
|
|
|
test_family_compat(void)
|
|
|
|
|
{
|
2005-07-06 05:58:50 +08:00
|
|
|
|
#ifdef H5_WANT_H5_V1_6_COMPAT
|
2005-06-24 22:32:05 +08:00
|
|
|
|
hid_t file=(-1), fapl;
|
|
|
|
|
char filename[1024];
|
|
|
|
|
char pathname[1024];
|
2005-08-14 04:53:35 +08:00
|
|
|
|
char *srcdir = getenv("srcdir"); /*where the src code is located*/
|
2005-07-06 05:58:50 +08:00
|
|
|
|
#endif /*H5_WANT_H5_V1_6_COMPAT*/
|
2005-06-24 22:32:05 +08:00
|
|
|
|
|
|
|
|
|
TESTING("FAMILY file driver backward compatibility");
|
|
|
|
|
|
|
|
|
|
#ifndef H5_WANT_H5_V1_6_COMPAT
|
|
|
|
|
SKIPPED();
|
|
|
|
|
return 0;
|
|
|
|
|
#else /*H5_WANT_H5_V1_6_COMPAT*/
|
|
|
|
|
|
|
|
|
|
/* Set property list and file name for FAMILY driver */
|
|
|
|
|
fapl = h5_fileaccess();
|
|
|
|
|
|
|
|
|
|
if(H5Pset_fapl_family(fapl, (hsize_t)FAMILY_SIZE2, H5P_DEFAULT)<0)
|
2005-11-15 10:55:39 +08:00
|
|
|
|
TEST_ERROR;
|
2005-06-24 22:32:05 +08:00
|
|
|
|
|
|
|
|
|
h5_fixname(COMPAT_BASENAME, fapl, filename, sizeof filename);
|
|
|
|
|
|
2005-10-15 03:16:54 +08:00
|
|
|
|
pathname[0] = '\0';
|
2005-06-24 22:32:05 +08:00
|
|
|
|
/* Generate correct name for test file by prepending the source path */
|
|
|
|
|
if(srcdir && ((strlen(srcdir) + strlen(filename) + 1) < sizeof(pathname))) {
|
|
|
|
|
strcpy(pathname, srcdir);
|
|
|
|
|
strcat(pathname, "/");
|
2005-08-14 04:53:35 +08:00
|
|
|
|
}
|
2005-06-24 22:32:05 +08:00
|
|
|
|
strcat(pathname, filename);
|
|
|
|
|
|
|
|
|
|
if((file=H5Fopen(pathname, H5F_ACC_RDONLY, fapl))<0)
|
2005-11-15 10:55:39 +08:00
|
|
|
|
TEST_ERROR;
|
2005-06-24 22:32:05 +08:00
|
|
|
|
|
|
|
|
|
if(H5Fclose(file)<0)
|
2005-11-15 10:55:39 +08:00
|
|
|
|
TEST_ERROR;
|
2005-06-24 22:32:05 +08:00
|
|
|
|
|
|
|
|
|
if(H5Pclose(fapl)<0)
|
2005-11-15 10:55:39 +08:00
|
|
|
|
TEST_ERROR;
|
2005-06-24 22:32:05 +08:00
|
|
|
|
|
|
|
|
|
PASSED();
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
error:
|
|
|
|
|
H5E_BEGIN_TRY {
|
|
|
|
|
H5Fclose(file);
|
|
|
|
|
} H5E_END_TRY;
|
|
|
|
|
return -1;
|
|
|
|
|
#endif /*H5_WANT_H5_V1_6_COMPAT*/
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
|
* Function: test_multi_opens
|
|
|
|
|
*
|
|
|
|
|
* Purpose: Private function for test_multi() to tests wrong ways of
|
|
|
|
|
* reopening multi file.
|
|
|
|
|
*
|
|
|
|
|
* Return: Success: exit(0)
|
|
|
|
|
*
|
|
|
|
|
* Failure: exit(1)
|
|
|
|
|
*
|
|
|
|
|
* Programmer: Raymond Lu
|
|
|
|
|
* Thursday, May 19, 2005
|
|
|
|
|
*
|
|
|
|
|
* Modifications:
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
static herr_t
|
2005-11-15 10:55:39 +08:00
|
|
|
|
test_multi_opens(char *fname)
|
2005-06-24 22:32:05 +08:00
|
|
|
|
{
|
|
|
|
|
hid_t file;
|
|
|
|
|
char super_name[1024]; /*name string "%%s-s.h5"*/
|
|
|
|
|
char sf_name[1024]; /*name string "multi_file-s.h5"*/
|
|
|
|
|
|
2005-08-14 04:53:35 +08:00
|
|
|
|
/* Case: reopen with the name of super file and default property list */
|
2005-06-24 22:32:05 +08:00
|
|
|
|
sprintf(super_name, "%%s-%c.h5", 's');
|
|
|
|
|
sprintf(sf_name, super_name, fname);
|
|
|
|
|
|
|
|
|
|
H5E_BEGIN_TRY {
|
|
|
|
|
file=H5Fopen(sf_name, H5F_ACC_RDWR, H5P_DEFAULT);
|
|
|
|
|
} H5E_END_TRY;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
|
* Function: test_multi
|
|
|
|
|
*
|
|
|
|
|
* Purpose: Tests the file handle interface for MUTLI driver
|
|
|
|
|
*
|
|
|
|
|
* Return: Success: exit(0)
|
|
|
|
|
*
|
|
|
|
|
* Failure: exit(1)
|
|
|
|
|
*
|
|
|
|
|
* Programmer: Raymond Lu
|
|
|
|
|
* Tuesday, Sept 24, 2002
|
|
|
|
|
*
|
|
|
|
|
* Modifications:
|
|
|
|
|
*
|
|
|
|
|
* Raymond Lu
|
|
|
|
|
* Wednesday, June 23, 2004
|
|
|
|
|
* Added test for H5Fget_filesize.
|
2005-08-14 04:53:35 +08:00
|
|
|
|
*
|
2005-06-24 22:32:05 +08:00
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
static herr_t
|
|
|
|
|
test_multi(void)
|
|
|
|
|
{
|
|
|
|
|
hid_t file=(-1), fapl, fapl2=(-1), dset=(-1), space=(-1);
|
|
|
|
|
hid_t access_fapl = -1;
|
|
|
|
|
char filename[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[]="dataset";
|
|
|
|
|
int i, j;
|
|
|
|
|
int buf[MULTI_SIZE][MULTI_SIZE];
|
|
|
|
|
|
|
|
|
|
TESTING("MULTI file driver");
|
|
|
|
|
/* 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;
|
|
|
|
|
|
2005-08-14 04:53:35 +08:00
|
|
|
|
memb_fapl[H5FD_MEM_DRAW] = H5P_DEFAULT;
|
2005-06-24 22:32:05 +08:00
|
|
|
|
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)
|
2005-11-15 10:55:39 +08:00
|
|
|
|
TEST_ERROR;
|
2005-06-24 22:32:05 +08:00
|
|
|
|
h5_fixname(FILENAME[3], fapl, filename, sizeof filename);
|
|
|
|
|
|
|
|
|
|
if((file=H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl))<0)
|
2005-11-15 10:55:39 +08:00
|
|
|
|
TEST_ERROR;
|
2005-06-24 22:32:05 +08:00
|
|
|
|
|
2005-08-14 04:53:35 +08:00
|
|
|
|
if(H5Fclose(file)<0)
|
2005-11-15 10:55:39 +08:00
|
|
|
|
TEST_ERROR;
|
2005-08-14 04:53:35 +08:00
|
|
|
|
|
2005-06-24 22:32:05 +08:00
|
|
|
|
/* Test wrong ways to reopen multi files */
|
2005-11-15 10:55:39 +08:00
|
|
|
|
if(test_multi_opens(filename)<0)
|
|
|
|
|
TEST_ERROR;
|
2005-06-24 22:32:05 +08:00
|
|
|
|
|
|
|
|
|
/* Reopen the file */
|
|
|
|
|
if((file=H5Fopen(filename, H5F_ACC_RDWR, fapl))<0)
|
2005-11-15 10:55:39 +08:00
|
|
|
|
TEST_ERROR;
|
2005-06-24 22:32:05 +08:00
|
|
|
|
|
|
|
|
|
/* Create and write data set */
|
|
|
|
|
if((space=H5Screate_simple(2, dims, NULL))<0)
|
2005-11-15 10:55:39 +08:00
|
|
|
|
TEST_ERROR;
|
2005-06-24 22:32:05 +08:00
|
|
|
|
|
|
|
|
|
/* Retrieve the access property list... */
|
|
|
|
|
if ((access_fapl = H5Fget_access_plist(file)) < 0)
|
2005-11-15 10:55:39 +08:00
|
|
|
|
TEST_ERROR;
|
2005-06-24 22:32:05 +08:00
|
|
|
|
|
|
|
|
|
/* ...and close the property list */
|
|
|
|
|
if (H5Pclose(access_fapl) < 0)
|
2005-11-15 10:55:39 +08:00
|
|
|
|
TEST_ERROR;
|
2005-06-24 22:32:05 +08:00
|
|
|
|
|
|
|
|
|
/* Check file size API */
|
|
|
|
|
if(H5Fget_filesize(file, &file_size) < 0)
|
2005-11-15 10:55:39 +08:00
|
|
|
|
TEST_ERROR;
|
2005-06-24 22:32:05 +08:00
|
|
|
|
|
|
|
|
|
/* Before any data is written, the raw data file is empty. So
|
|
|
|
|
* the file size is only the size of metadata file. It's supposed
|
2006-10-03 02:32:46 +08:00
|
|
|
|
* to be 800 bytes.
|
2005-08-14 04:53:35 +08:00
|
|
|
|
*/
|
2006-10-03 02:32:46 +08:00
|
|
|
|
if(file_size < (KB / 2) || file_size > KB)
|
2005-11-15 10:55:39 +08:00
|
|
|
|
TEST_ERROR;
|
2005-06-24 22:32:05 +08:00
|
|
|
|
|
|
|
|
|
if((dset=H5Dcreate(file, dname, H5T_NATIVE_INT, space, H5P_DEFAULT))<0)
|
2005-11-15 10:55:39 +08:00
|
|
|
|
TEST_ERROR;
|
2005-08-14 04:53:35 +08:00
|
|
|
|
|
2005-06-24 22:32:05 +08:00
|
|
|
|
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)
|
2005-11-15 10:55:39 +08:00
|
|
|
|
TEST_ERROR;
|
2005-06-24 22:32:05 +08:00
|
|
|
|
|
|
|
|
|
if((fapl2=H5Pcreate(H5P_FILE_ACCESS))<0)
|
2005-11-15 10:55:39 +08:00
|
|
|
|
TEST_ERROR;
|
2005-06-24 22:32:05 +08:00
|
|
|
|
if(H5Pset_multi_type(fapl2, H5FD_MEM_SUPER)<0)
|
2005-11-15 10:55:39 +08:00
|
|
|
|
TEST_ERROR;
|
2005-06-24 22:32:05 +08:00
|
|
|
|
if(H5Fget_vfd_handle(file, fapl2, (void **)&fhandle)<0)
|
2005-11-15 10:55:39 +08:00
|
|
|
|
TEST_ERROR;
|
2005-06-24 22:32:05 +08:00
|
|
|
|
if(*fhandle<0)
|
2005-11-15 10:55:39 +08:00
|
|
|
|
TEST_ERROR;
|
2005-06-24 22:32:05 +08:00
|
|
|
|
|
|
|
|
|
if(H5Pset_multi_type(fapl2, H5FD_MEM_DRAW)<0)
|
2005-11-15 10:55:39 +08:00
|
|
|
|
TEST_ERROR;
|
2005-06-24 22:32:05 +08:00
|
|
|
|
if(H5Fget_vfd_handle(file, fapl2, (void **)&fhandle2)<0)
|
2005-11-15 10:55:39 +08:00
|
|
|
|
TEST_ERROR;
|
2005-06-24 22:32:05 +08:00
|
|
|
|
if(*fhandle2<0)
|
2005-11-15 10:55:39 +08:00
|
|
|
|
TEST_ERROR;
|
2005-06-24 22:32:05 +08:00
|
|
|
|
|
|
|
|
|
/* Check file size API */
|
|
|
|
|
if(H5Fget_filesize(file, &file_size) < 0)
|
2005-11-15 10:55:39 +08:00
|
|
|
|
TEST_ERROR;
|
2005-06-24 22:32:05 +08:00
|
|
|
|
|
2005-08-14 04:53:35 +08:00
|
|
|
|
/* After the data is written, the file size is huge because the
|
2005-06-24 22:32:05 +08:00
|
|
|
|
* beginning of raw data file is set at HADDR_MAX/2. It's supposed
|
2005-08-14 04:53:35 +08:00
|
|
|
|
* to be (HADDR_MAX/2 + 128*128*4)
|
2005-06-24 22:32:05 +08:00
|
|
|
|
*/
|
2005-11-15 10:55:39 +08:00
|
|
|
|
#ifdef H5_HAVE_LARGE_HSIZET
|
2005-06-24 22:32:05 +08:00
|
|
|
|
if(file_size < HADDR_MAX/2 || file_size > HADDR_MAX)
|
2005-11-15 10:55:39 +08:00
|
|
|
|
TEST_ERROR;
|
|
|
|
|
#endif /* H5_HAVE_LARGE_HSIZET */
|
2005-06-24 22:32:05 +08:00
|
|
|
|
|
|
|
|
|
if(H5Sclose(space)<0)
|
2005-11-15 10:55:39 +08:00
|
|
|
|
TEST_ERROR;
|
2005-06-24 22:32:05 +08:00
|
|
|
|
if(H5Dclose(dset)<0)
|
2005-11-15 10:55:39 +08:00
|
|
|
|
TEST_ERROR;
|
2005-06-24 22:32:05 +08:00
|
|
|
|
if(H5Pclose(fapl2)<0)
|
2005-11-15 10:55:39 +08:00
|
|
|
|
TEST_ERROR;
|
2005-08-14 04:53:35 +08:00
|
|
|
|
if(H5Fclose(file)<0)
|
2005-11-15 10:55:39 +08:00
|
|
|
|
TEST_ERROR;
|
2005-08-14 04:53:35 +08:00
|
|
|
|
|
|
|
|
|
h5_cleanup(FILENAME, fapl);
|
|
|
|
|
PASSED();
|
2005-06-24 22:32:05 +08:00
|
|
|
|
|
2005-08-14 04:53:35 +08:00
|
|
|
|
return 0;
|
2005-06-24 22:32:05 +08:00
|
|
|
|
|
2005-08-14 04:53:35 +08:00
|
|
|
|
error:
|
|
|
|
|
H5E_BEGIN_TRY {
|
2005-06-24 22:32:05 +08:00
|
|
|
|
H5Sclose(space);
|
|
|
|
|
H5Dclose(dset);
|
|
|
|
|
H5Pclose(fapl);
|
|
|
|
|
H5Pclose(fapl2);
|
2005-08-14 04:53:35 +08:00
|
|
|
|
H5Fclose(file);
|
|
|
|
|
} H5E_END_TRY;
|
|
|
|
|
return -1;
|
2005-06-24 22:32:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
|
* Function: main
|
2005-08-14 04:53:35 +08:00
|
|
|
|
*
|
2005-06-24 22:32:05 +08:00
|
|
|
|
* Purpose: Tests the basic features of Virtual File Drivers
|
2005-08-14 04:53:35 +08:00
|
|
|
|
*
|
2005-06-24 22:32:05 +08:00
|
|
|
|
* Return: Success: exit(0)
|
2005-08-14 04:53:35 +08:00
|
|
|
|
*
|
2005-06-24 22:32:05 +08:00
|
|
|
|
* Failure: exit(1)
|
2005-08-14 04:53:35 +08:00
|
|
|
|
*
|
2005-06-24 22:32:05 +08:00
|
|
|
|
* Programmer: Raymond Lu
|
|
|
|
|
* Tuesday, Sept 24, 2002
|
2005-08-14 04:53:35 +08:00
|
|
|
|
*
|
2005-06-24 22:32:05 +08:00
|
|
|
|
* Modifications:
|
|
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
int
|
|
|
|
|
main(void)
|
2005-08-14 04:53:35 +08:00
|
|
|
|
{
|
2005-06-24 22:32:05 +08:00
|
|
|
|
int nerrors=0;
|
2005-08-14 04:53:35 +08:00
|
|
|
|
|
|
|
|
|
h5_reset();
|
2005-06-24 22:32:05 +08:00
|
|
|
|
|
|
|
|
|
nerrors += test_sec2()<0 ?1:0;
|
|
|
|
|
nerrors += test_core()<0 ?1:0;
|
|
|
|
|
nerrors += test_family()<0 ?1:0;
|
|
|
|
|
nerrors += test_family_compat()<0 ?1:0;
|
|
|
|
|
nerrors += test_multi()<0 ?1:0;
|
2006-10-11 04:07:16 +08:00
|
|
|
|
nerrors += test_direct()<0 ?1:0;
|
2005-06-24 22:32:05 +08:00
|
|
|
|
|
|
|
|
|
if (nerrors){
|
|
|
|
|
printf("***** %d Virtual File Driver TEST%s FAILED! *****\n",
|
|
|
|
|
nerrors, nerrors > 1 ? "S" : "");
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
printf("All Virtual File Driver tests passed.\n");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|