summaryrefslogtreecommitdiffstats
path: root/test/vfd.c
diff options
context:
space:
mode:
authorRaymond Lu <songyulu@hdfgroup.org>2009-04-15 21:42:02 (GMT)
committerRaymond Lu <songyulu@hdfgroup.org>2009-04-15 21:42:02 (GMT)
commit04f71d5b13faa2c84f0d88cab3ac0866459fb670 (patch)
treed9105e380d85b3713fdad34047e1870ec96f837a /test/vfd.c
parent745d7ff8356ce970f09081f9b86b71a412d9dbf4 (diff)
downloadhdf5-04f71d5b13faa2c84f0d88cab3ac0866459fb670.zip
hdf5-04f71d5b13faa2c84f0d88cab3ac0866459fb670.tar.gz
hdf5-04f71d5b13faa2c84f0d88cab3ac0866459fb670.tar.bz2
[svn-r16759] The test of family file compatibility with v1.6 used the original family files under the
library source directory. Since the test opens the files with write mode, it's safer to make copies of the original files. I added the copying step in test_family_compat in vfd.c. I changed the Makefile.am to clean up the copied files. I created a new family_v16_00000.h5 with v1.6 library. Tested on jam - supposed to be simple change.
Diffstat (limited to 'test/vfd.c')
-rw-r--r--test/vfd.c64
1 files changed, 54 insertions, 10 deletions
diff --git a/test/vfd.c b/test/vfd.c
index 57798a5..9ca0ac4 100644
--- a/test/vfd.c
+++ b/test/vfd.c
@@ -28,6 +28,7 @@
#define FAMILY_SIZE2 (5*KB)
#define MULTI_SIZE 128
#define CORE_INCREMENT (4*KB)
+#define FILE_COPY_BUF_SIZE 4096
/*Macros for Direct VFD*/
#define MBOUNDARY 512
@@ -44,13 +45,16 @@ const char *FILENAME[] = {
"sec2_file",
"core_file",
"family_file",
+ "family_v16_",
+ "new_family_v16_",
"multi_file",
"direct_file",
NULL
};
-
+/*
#define COMPAT_BASENAME "family_v16_"
-
+#define COMPAT_NEWNAME "new_family_v16_"
+*/
/*-------------------------------------------------------------------------
* Function: test_sec2
@@ -173,7 +177,7 @@ test_direct(void)
fapl = h5_fileaccess();
if(H5Pset_fapl_direct(fapl, MBOUNDARY, FBSIZE, CBSIZE) < 0)
TEST_ERROR;
- h5_fixname(FILENAME[4], fapl, filename, sizeof filename);
+ h5_fixname(FILENAME[6], fapl, filename, sizeof filename);
/* Verify the file access properties */
if(H5Pget_fapl_direct(fapl, &mbound, &fbsize, &cbsize) < 0)
@@ -805,8 +809,14 @@ test_family_compat(void)
hid_t dset;
char dname[]="dataset";
char filename[1024];
- char pathname[1024];
+ char pathname[1024], pathname_individual[1024];
+ char newname[1024], newname_individual[1024];
char *srcdir = getenv("srcdir"); /*where the src code is located*/
+ FILE *tmp_fp, *old_fp; /* Pointers to temp & old files */
+ void *copy_buf; /* Pointer to buffer for copying data */
+ size_t written; /* Amount of data written to new file */
+ size_t read_in; /* Amount of data read in from old file */
+ int counter = 0;
TESTING("FAMILY file driver backward compatibility");
@@ -816,7 +826,8 @@ test_family_compat(void)
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, filename, sizeof filename);
+ h5_fixname(FILENAME[4], fapl, newname, sizeof newname);
pathname[0] = '\0';
/* Generate correct name for test file by prepending the source path */
@@ -826,9 +837,42 @@ test_family_compat(void)
}
HDstrcat(pathname, filename);
+ /* The following code makes the copies of the family files in the source directory.
+ * Since we're going to open the files with write mode, this protects the original
+ * files.
+ */
+ if(NULL == (copy_buf = HDmalloc((size_t)FILE_COPY_BUF_SIZE))) TEST_ERROR
+
+ sprintf(newname_individual, newname, counter);
+ sprintf(pathname_individual, pathname, counter);
+
+ /* Open the original files until no more left. Copy the content into the new files. */
+ while((old_fp = HDfopen(pathname_individual,"rb"))) {
+ /* Open the new file */
+ if(NULL == (tmp_fp = fopen(newname_individual,"wb"))) TEST_ERROR
+
+ /* Copy data from the old file to the new file */
+ while((read_in = HDfread(copy_buf, (size_t)1, (size_t)FILE_COPY_BUF_SIZE, old_fp)) > 0)
+ /* Write the data to the new file */
+ if(read_in != (written = HDfwrite(copy_buf, (size_t)1, read_in, tmp_fp))) TEST_ERROR
+
+ /* Close the old file */
+ if(HDfclose(old_fp)) TEST_ERROR
+
+ /* Close the new file */
+ if(HDfclose(tmp_fp)) TEST_ERROR
+
+ counter++;
+ sprintf(newname_individual, newname, counter);
+ sprintf(pathname_individual, pathname, counter);
+ }
+
+ /* Free the copy buffer */
+ free(copy_buf);
+
/* Make sure we can open the file. Use the read and write mode to flush the
* superblock. */
- if((file = H5Fopen(pathname, H5F_ACC_RDWR, fapl)) < 0)
+ if((file = H5Fopen(newname, H5F_ACC_RDWR, fapl)) < 0)
TEST_ERROR;
if((dset = H5Dopen2(file, dname, H5P_DEFAULT)) < 0)
@@ -841,7 +885,7 @@ test_family_compat(void)
TEST_ERROR;
/* Open the file again to make sure it isn't corrupted. */
- if((file = H5Fopen(pathname, H5F_ACC_RDWR, fapl)) < 0)
+ if((file = H5Fopen(newname, H5F_ACC_RDWR, fapl)) < 0)
TEST_ERROR;
if((dset = H5Dopen2(file, dname, H5P_DEFAULT)) < 0)
@@ -853,8 +897,7 @@ test_family_compat(void)
if(H5Fclose(file) < 0)
TEST_ERROR;
- if(H5Pclose(fapl) < 0)
- TEST_ERROR;
+ h5_cleanup(FILENAME, fapl);
PASSED();
@@ -863,6 +906,7 @@ test_family_compat(void)
error:
H5E_BEGIN_TRY {
H5Fclose(file);
+ H5Pclose(fapl);
} H5E_END_TRY;
return -1;
@@ -979,7 +1023,7 @@ test_multi(void)
if(H5Pset_fapl_multi(fapl, memb_map, memb_fapl, memb_name, memb_addr, TRUE) < 0)
TEST_ERROR;
- h5_fixname(FILENAME[3], fapl, filename, sizeof filename);
+ h5_fixname(FILENAME[5], fapl, filename, sizeof filename);
if((file=H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
TEST_ERROR;