diff options
author | Larry Knox <lrknox@hdfgroup.org> | 2009-10-20 15:08:56 (GMT) |
---|---|---|
committer | Larry Knox <lrknox@hdfgroup.org> | 2009-10-20 15:08:56 (GMT) |
commit | a99a73d20ecd7ed2c9c65a2979f600f805d01099 (patch) | |
tree | 252d65e11b3542322b0e73b510a1a3ef3036b7c4 | |
parent | 4feddbbbcc655ba2ff2e07b10647bd12f06d2d84 (diff) | |
download | hdf5-a99a73d20ecd7ed2c9c65a2979f600f805d01099.zip hdf5-a99a73d20ecd7ed2c9c65a2979f600f805d01099.tar.gz hdf5-a99a73d20ecd7ed2c9c65a2979f600f805d01099.tar.bz2 |
[svn-r17688] Merge make local copy of svn test data files for write access from v1.8 to trunk.
Tested:
amani, jam, linew (h5committest).
-rw-r--r-- | test/dsets.c | 31 | ||||
-rw-r--r-- | test/h5test.c | 55 | ||||
-rw-r--r-- | test/h5test.h | 1 | ||||
-rw-r--r-- | test/stab.c | 78 | ||||
-rw-r--r-- | test/tmisc.c | 33 | ||||
-rw-r--r-- | test/vfd.c | 33 |
6 files changed, 91 insertions, 140 deletions
diff --git a/test/dsets.c b/test/dsets.c index 2876dad..0522bd0 100644 --- a/test/dsets.c +++ b/test/dsets.c @@ -34,6 +34,7 @@ #define H5Z_PACKAGE #include "H5Zpkg.h" + const char *FILENAME[] = { "dataset", "compact_dataset", @@ -140,6 +141,7 @@ const char *FILENAME[] = { /* Names for noencoder test */ #ifdef H5_HAVE_FILTER_SZIP #define NOENCODER_FILENAME "noencoder.h5" +#define NOENCODER_COPY_FILENAME "noencoder.h5.copy" #define NOENCODER_TEST_DATASET "noencoder_tdset.h5" #define NOENCODER_SZIP_DATASET "noencoder_szip_dset.h5" #define NOENCODER_SZIP_SHUFF_FLETCH_DATASET "noencoder_szip_shuffle_fletcher_dset.h5" @@ -1691,6 +1693,8 @@ error: * Monday, June 7, 2004 * * Modifications: + * Make copy of data file since the test writes to the file. + * Larry Knox, October 14, 2009 * *------------------------------------------------------------------------- */ @@ -1708,20 +1712,14 @@ test_filter_noencoder(const char *dset_name) int test_ints[10] = { 12 }; int read_buf[10]; int i; - char * srcdir = HDgetenv("srcdir"); /* The source directory */ - char testfile[512]=""; /* Buffer to hold name of test file */ - - /* - * Create the name of the file to open (in case we are using the --srcdir - * option and the file is in a different directory from this test). - */ - if(srcdir && ((HDstrlen(srcdir) + HDstrlen(NOENCODER_FILENAME) + 1) < sizeof(testfile))) { - HDstrcpy(testfile, srcdir); - HDstrcat(testfile, "/"); - } - HDstrcat(testfile, NOENCODER_FILENAME); - - file_id = H5Fopen(testfile, H5F_ACC_RDWR, H5P_DEFAULT); + + /* Make a local copy of the file since this test writes to the data file + from svn. */ + if (h5_make_local_copy(NOENCODER_FILENAME, NOENCODER_COPY_FILENAME) < 0) + goto error; + + /* Open file */ + file_id = H5Fopen(NOENCODER_COPY_FILENAME, H5F_ACC_RDWR, H5P_DEFAULT); if(file_id < 0) goto error; dset_id = H5Dopen2(file_id, dset_name, H5P_DEFAULT); @@ -1803,6 +1801,7 @@ error: H5Pclose(dcpl_id); if(file_id != -1) H5Fclose(file_id); + return -1; } #endif /* H5_HAVE_FILTER_SZIP */ @@ -7377,6 +7376,10 @@ main(void) if(nerrors) goto error; printf("All dataset tests passed.\n"); +#ifdef H5_HAVE_FILTER_SZIP + if (GetTestCleanup()) + HDremove(NOENCODER_COPY_FILENAME); +#endif /* H5_HAVE_FILTER_SZIP */ h5_cleanup(FILENAME, fapl); return 0; diff --git a/test/h5test.c b/test/h5test.c index 03e857f..a5b50d3 100644 --- a/test/h5test.c +++ b/test/h5test.c @@ -71,6 +71,9 @@ char *paraprefix = NULL; /* for command line option para-prefix */ MPI_Info h5_io_info_g=MPI_INFO_NULL;/* MPI INFO object for IO */ #endif +#define FILENAME_BUF_SIZE 1024 +#define READ_BUF_SIZE 4096 + /* * These are the letters that are appended to the file name when generating * names for the split and multi drivers. They are: @@ -1088,3 +1091,55 @@ getenv_all(MPI_Comm comm, int root, const char* name) #endif +/*------------------------------------------------------------------------- + * Function: h5_make_local_copy + * + * Purpose: Make copy of file. Some tests write to data files under that + * are under version control. Those tests should make a copy of + * the versioned file and write to the copy. This function + * prepends srcdir to the name of the file to be copied and uses + * the name of the copy as is. + * + * Return: Success: 0 + * + * Failure: -1 + * + * Programmer: Larry Knox + * Monday, October 13, 2009 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +hid_t +h5_make_local_copy(char *origfilename, char *local_copy_name) +{ + char filename[FILENAME_BUF_SIZE] = ""; + int fd_old = (-1), fd_new = (-1); /* File descriptors for copying data */ + ssize_t nread; /* Number of bytes read in */ + char buf[READ_BUF_SIZE]; /* Buffer for copying data */ + char * srcdir = HDgetenv("srcdir"); /* The source directory */ + + if(srcdir && ((HDstrlen(srcdir) + + HDstrlen(origfilename) + 6) < FILENAME_BUF_SIZE)) { + HDstrcpy(filename, srcdir); + HDstrcat(filename, "/"); + } + HDstrcat(filename, origfilename); + + /* Copy old file into temporary file */ + if((fd_old = HDopen(filename, O_RDONLY, 0666)) < 0) return -1; + if((fd_new = HDopen(local_copy_name, O_RDWR|O_CREAT|O_TRUNC, 0666)) + < 0) return -1; + + /* Copy data */ + while((nread = HDread(fd_old, buf, (size_t)READ_BUF_SIZE)) > 0) + HDwrite(fd_new, buf, (size_t)nread); + + /* Close files */ + if(HDclose(fd_old) < 0) return -1; + if(HDclose(fd_new) < 0) return -1; + + return 0; +} + diff --git a/test/h5test.h b/test/h5test.h index e3b3596..315b504 100644 --- a/test/h5test.h +++ b/test/h5test.h @@ -152,6 +152,7 @@ H5TEST_DLL void h5_reset(void); H5TEST_DLL void h5_show_hostname(void); H5TEST_DLL h5_stat_size_t h5_get_file_size(const char *filename, hid_t fapl); H5TEST_DLL int print_func(const char *format, ...); +H5TEST_DLL int h5_make_local_copy(char *origfilename, char *local_copy_name); /* Routines for operating on the list of tests (for the "all in one" tests) */ H5TEST_DLL void TestUsage(void); diff --git a/test/stab.c b/test/stab.c index 319046e..c2655a8 100644 --- a/test/stab.c +++ b/test/stab.c @@ -59,6 +59,7 @@ const char *FILENAME[] = { * for version 1.6. To get this data file, simply compile gen_old_group.c with * the HDF5 library in that branch and run it. */ #define FILE_OLD_GROUPS "group_old.h5" +#define FILE_OLD_GROUPS_COPY "group_old.h5.copy" /* Definitions for 'no_compact' test */ #define NO_COMPACT_TOP_GROUP "top" @@ -665,45 +666,22 @@ error: static int read_old(void) { - int fd_old = (-1), fd_new = (-1); /* File descriptors for copying data */ hid_t fid = (-1); /* File ID */ hid_t gid = (-1); /* Group ID */ hid_t gid2 = (-1); /* Group ID */ - char buf[READ_OLD_BUFSIZE]; /* Buffer for copying data */ - ssize_t nread; /* Number of bytes read in */ char objname[NAME_BUF_SIZE]; /* Object name */ unsigned u; /* Local index variable */ - char *srcdir = HDgetenv("srcdir"); /* where the src code is located */ - char filename[512] = ""; /* old test file name */ - char filename2[NAME_BUF_SIZE]; /* copy of old test file */ TESTING("reading old groups"); - /* Generate correct name for test file by prepending the source path */ - if(srcdir && ((HDstrlen(srcdir) + HDstrlen(FILE_OLD_GROUPS) + 1) < sizeof(filename))) { - HDstrcpy(filename, srcdir); - HDstrcat(filename, "/"); - } - HDstrcat(filename, FILE_OLD_GROUPS); - - /* Create filename */ - h5_fixname(FILENAME[0], H5P_DEFAULT, filename2, sizeof(filename2)); - - /* Copy old file into temporary file */ - if((fd_old = HDopen(filename, O_RDONLY, 0666)) < 0) TEST_ERROR - if((fd_new = HDopen(filename2, O_RDWR|O_CREAT|O_TRUNC, 0666)) < 0) TEST_ERROR - - /* Copy data */ - while((nread = HDread(fd_old, buf, (size_t)READ_OLD_BUFSIZE)) > 0) - HDwrite(fd_new, buf, (size_t)nread); - - /* Close files */ - if(HDclose(fd_old) < 0) TEST_ERROR - if(HDclose(fd_new) < 0) TEST_ERROR + /* Make a copy of the data file from svn. */ + if(h5_make_local_copy(FILE_OLD_GROUPS, FILE_OLD_GROUPS_COPY) < 0) TEST_ERROR + /* Open copied file */ + if((fid = H5Fopen(FILE_OLD_GROUPS_COPY, H5F_ACC_RDWR, H5P_DEFAULT)) < 0) TEST_ERROR /* Open copied file */ - if((fid = H5Fopen(filename2, H5F_ACC_RDWR, H5P_DEFAULT)) < 0) TEST_ERROR + if((fid = H5Fopen(FILE_OLD_GROUPS_COPY, H5F_ACC_RDWR, H5P_DEFAULT)) < 0) TEST_ERROR /* Attempt to open "old" group */ if((gid = H5Gopen2(fid, "old", H5P_DEFAULT)) < 0) TEST_ERROR @@ -1106,46 +1084,13 @@ error: static int corrupt_stab_msg(void) { - char testfile[512]=""; /* Character buffer for corrected test file name */ - char *srcdir = HDgetenv("srcdir"); /* Pointer to the directory the source code is located within */ - 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 */ hid_t fid = (-1); /* File ID */ hid_t did = (-1); /* Dataset ID */ TESTING("corrupt symbol table message"); - /* Generate the correct name for the test file, by prepending the source path */ - if(srcdir && ((HDstrlen(srcdir) + HDstrlen(CORRUPT_STAB_FILE) + 1) < sizeof(testfile))) { - HDstrcpy(testfile, srcdir); - HDstrcat(testfile, "/"); - } - HDstrcat(testfile, CORRUPT_STAB_FILE); - - /* Open the temporary file */ - if(NULL == (tmp_fp = HDfopen(CORRUPT_STAB_TMP_FILE,"wb"))) TEST_ERROR - - /* Open the old file */ - if(NULL == (old_fp = fopen(testfile,"rb"))) TEST_ERROR - - /* Allocate space for the copy buffer */ - if(NULL == (copy_buf = HDmalloc((size_t)CORRUPT_STAB_COPY_BUF_SIZE))) TEST_ERROR - - /* Copy data from the old file to the new file */ - while((read_in = HDfread(copy_buf, (size_t)1, (size_t)CORRUPT_STAB_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 - - /* Free the copy buffer */ - free(copy_buf); + /* Make a copy of the data file from svn. */ + if(h5_make_local_copy(CORRUPT_STAB_FILE, CORRUPT_STAB_TMP_FILE) < 0) TEST_ERROR #ifndef H5_STRICT_FORMAT_CHECKS /* Open temp file through HDF5 library */ @@ -1186,8 +1131,6 @@ corrupt_stab_msg(void) if(H5Fclose(fid) < 0) TEST_ERROR #endif /* H5_STRICT_FORMAT_CHECKS */ - /* Remove temporary file */ - if(HDremove(CORRUPT_STAB_TMP_FILE)) TEST_ERROR PASSED(); @@ -1198,7 +1141,6 @@ error: H5Dclose(did); H5Fclose(fid); } H5E_END_TRY; - HDremove(CORRUPT_STAB_TMP_FILE); return 1; } /* end old_api() */ @@ -1266,6 +1208,10 @@ main(void) puts("All symbol table tests passed."); /* Cleanup */ + if (GetTestCleanup()) { + HDremove(FILE_OLD_GROUPS_COPY); + HDremove(CORRUPT_STAB_TMP_FILE); + } h5_cleanup(FILENAME, fapl); return 0; diff --git a/test/tmisc.c b/test/tmisc.c index 21715b4..55e4c27 100644 --- a/test/tmisc.c +++ b/test/tmisc.c @@ -32,9 +32,6 @@ #include "testhdf5.h" #include "H5Dpkg.h" /* Datasets */ -#define NAME_BUF_SIZE 1024 -#define READ_OLD_BUFSIZE 1024 - /* Definitions for misc. test #1 */ #define MISC1_FILE "tmisc1.h5" #define MISC1_VAL (13417386) /* 0xccbbaa */ @@ -5124,39 +5121,15 @@ test_misc28(void) static void test_misc29(void) { - int fd_old = (-1), fd_new = (-1); /* File descriptors for copying data */ - char buf[READ_OLD_BUFSIZE]; /* Buffer for copying data */ - ssize_t nread; /* Number of bytes read in */ - char *srcdir = HDgetenv("srcdir"); /* where the src code is located */ - char filename[NAME_BUF_SIZE] = ""; /* old test file name */ hid_t fid; /* File ID */ herr_t ret; /* Generic return value */ /* Output message about test being performed */ MESSAGE(5, ("Speculative metadata reads\n")); - /* Generate correct name for test file by prepending the source path */ - if(srcdir && ((HDstrlen(srcdir) + HDstrlen(MISC29_ORIG_FILE) + 1) < sizeof(filename))) { - HDstrcpy(filename, srcdir); - HDstrcat(filename, "/"); - } /* end if */ - HDstrcat(filename, MISC29_ORIG_FILE); - - /* Copy old file into temporary file */ - fd_old = HDopen(filename, O_RDONLY, 0666); - CHECK(fd_old, -1, "HDopen"); - fd_new = HDopen(MISC29_COPY_FILE, O_RDWR|O_CREAT|O_TRUNC, 0666); - CHECK(fd_new, -1, "HDopen"); - - /* Copy data */ - while((nread = HDread(fd_old, buf, (size_t)READ_OLD_BUFSIZE)) > 0) - HDwrite(fd_new, buf, (size_t)nread); - - /* Close files */ - ret = HDclose(fd_old); - CHECK(ret, -1, "HDclose"); - ret = HDclose(fd_new); - CHECK(ret, -1, "HDclose"); + /* Make a copy of the data file from svn. */ + ret = h5_make_local_copy(MISC29_ORIG_FILE, MISC29_COPY_FILE); + CHECK(ret, -1, "h5_make_local_copy"); /* Open the copied file */ fid = H5Fopen(MISC29_COPY_FILE, H5F_ACC_RDWR, H5P_DEFAULT); @@ -28,7 +28,6 @@ #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 @@ -809,11 +808,7 @@ test_family_compat(void) char filename[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"); @@ -828,45 +823,23 @@ test_family_compat(void) h5_fixname(FILENAME[3], fapl, newname, sizeof newname); pathname[0] = '\0'; - /* Generate correct name for test file by prepending the source path */ - if(srcdir && ((HDstrlen(srcdir) + HDstrlen(filename) + 1) < sizeof(pathname))) { - HDstrcpy(pathname, srcdir); - HDstrcat(pathname, "/"); - } 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 - + while (h5_make_local_copy(pathname_individual, newname_individual) >= 0) { counter++; sprintf(newname_individual, newname, counter); sprintf(pathname_individual, pathname, counter); } - /* Free the copy buffer */ - free(copy_buf); + if (old_fp = HDfopen(pathname_individual,"rb") + && (tmp_fp = fopen(newname_individual,"wb"))) TEST_ERROR /* Make sure we can open the file. Use the read and write mode to flush the * superblock. */ |