summaryrefslogtreecommitdiffstats
path: root/tools/h5repack/h5repacktst.c
diff options
context:
space:
mode:
authorPedro Vicente Nunes <pvn@hdfgroup.org>2008-08-22 15:53:07 (GMT)
committerPedro Vicente Nunes <pvn@hdfgroup.org>2008-08-22 15:53:07 (GMT)
commita72dc6c92c78650589a9f13d7221318dd1032efe (patch)
tree761d5b07a4814de36d88adc5bfebc161e29adabe /tools/h5repack/h5repacktst.c
parente9f3b20b64d3c2ffe2e134a5c4bf974c916472b8 (diff)
downloadhdf5-a72dc6c92c78650589a9f13d7221318dd1032efe.zip
hdf5-a72dc6c92c78650589a9f13d7221318dd1032efe.tar.gz
hdf5-a72dc6c92c78650589a9f13d7221318dd1032efe.tar.bz2
[svn-r15521] #1184
Add a userblock to an HDF5 file during the repack. The user gives give a filename and userblock size as command line parameters to h5repack and the contents of that file are stored in the userblock for the HDF5 file created by h5repack. New flags to handle this -u and -b Tested : windows, linux
Diffstat (limited to 'tools/h5repack/h5repacktst.c')
-rw-r--r--tools/h5repack/h5repacktst.c89
1 files changed, 84 insertions, 5 deletions
diff --git a/tools/h5repack/h5repacktst.c b/tools/h5repack/h5repacktst.c
index 3796179..e7024f2 100644
--- a/tools/h5repack/h5repacktst.c
+++ b/tools/h5repack/h5repacktst.c
@@ -71,6 +71,9 @@
#define FNAME16 "h5repack_ub.h5"
#define FNAME16OUT "h5repack_ub_out.h5"
+#define FNAME_UB "ublock.bin"
+
+
const char *H5REPACK_FILENAMES[] = {
"h5repack_big_out",
@@ -123,7 +126,8 @@ int make_attr(hid_t loc_id,int rank,hsize_t *dims,const char *attr_name,hid_t ty
void make_dset_reg_ref(hid_t loc_id);
int make_external(hid_t loc_id);
static int make_userblock(void);
-static int verify_userblock(void);
+static int verify_userblock( const char* filename);
+static int make_userblock_file(void);
/*-------------------------------------------------------------------------
@@ -1332,7 +1336,7 @@ if (szip_can_encode) {
GOERROR;
if(h5repack_verify(FNAME16OUT, &pack_options) <= 0)
GOERROR;
- if(verify_userblock() < 0)
+ if(verify_userblock(FNAME16OUT) < 0)
GOERROR;
if(h5repack_end(&pack_options) < 0)
GOERROR;
@@ -1394,6 +1398,32 @@ if (szip_can_encode) {
#endif
+ /*-------------------------------------------------------------------------
+ * test file with userblock
+ *-------------------------------------------------------------------------
+ */
+ TESTING(" file with added userblock");
+ if(h5repack_init(&pack_options, 0) < 0)
+ GOERROR;
+
+ /* add the options for a user block size and user block filename */
+ pack_options.ublock_size = USERBLOCK_SIZE;
+ pack_options.ublock_filename = FNAME_UB;
+
+ if(h5repack(FNAME8, FNAME8OUT, &pack_options) < 0)
+ GOERROR;
+ if(h5diff(FNAME8, FNAME8OUT, NULL, NULL, &diff_options) > 0)
+ GOERROR;
+ if(h5repack_verify(FNAME8OUT, &pack_options) <= 0)
+ GOERROR;
+ if(verify_userblock(FNAME8OUT) < 0)
+ GOERROR;
+ if(h5repack_end(&pack_options) < 0)
+ GOERROR;
+ PASSED();
+
+
+
/*-------------------------------------------------------------------------
* clean temporary test files
*-------------------------------------------------------------------------
@@ -1600,6 +1630,13 @@ int make_testfiles(void)
if(make_userblock() < 0)
goto out;
+ /*-------------------------------------------------------------------------
+ * create a userblock file
+ *-------------------------------------------------------------------------
+ */
+ if(make_userblock_file() < 0)
+ goto out;
+
return 0;
out:
@@ -2879,7 +2916,7 @@ out:
*-------------------------------------------------------------------------
*/
static int
-verify_userblock(void)
+verify_userblock( const char* filename)
{
hid_t fid = -1;
hid_t fcpl = -1;
@@ -2890,7 +2927,7 @@ verify_userblock(void)
size_t u; /* Local index variable */
/* Open file with userblock */
- if((fid = H5Fopen(FNAME16OUT, H5F_ACC_RDONLY, H5P_DEFAULT)) < 0)
+ if((fid = H5Fopen(filename, H5F_ACC_RDONLY, H5P_DEFAULT)) < 0)
goto out;
/* Retrieve file creation property list & userblock size */
@@ -2912,7 +2949,7 @@ verify_userblock(void)
/* Re-open HDF5 file, as "plain" file */
- if((fd = HDopen(FNAME16, O_RDONLY, 0)) < 0)
+ if((fd = HDopen(filename, O_RDONLY, 0)) < 0)
goto out;
/* Read userblock data */
@@ -2942,6 +2979,48 @@ out:
/*-------------------------------------------------------------------------
+ * Function: make_userblock_file
+ *
+ * Purpose: create a file for the userblock add test
+ *
+ *-------------------------------------------------------------------------
+ */
+static int
+make_userblock_file(void)
+{
+ hid_t fid = -1;
+ hid_t fcpl = -1;
+ int fd = -1; /* File descriptor for writing userblock */
+ char ub[USERBLOCK_SIZE]; /* User block data */
+ ssize_t nwritten; /* # of bytes written */
+ size_t u; /* Local index variable */
+
+ /* initialize userblock data */
+ for(u = 0; u < USERBLOCK_SIZE; u++)
+ ub[u] = 'a' + (u % 26);
+
+ /* open file */
+ if((fd = HDopen(FNAME_UB,O_WRONLY|O_CREAT|O_TRUNC, 0644 )) < 0)
+ goto out;
+
+ /* write userblock data */
+ nwritten = HDwrite(fd, ub, (size_t)USERBLOCK_SIZE);
+ assert(nwritten == USERBLOCK_SIZE);
+
+ /* close file */
+ HDclose(fd);
+
+ return 0;
+
+out:
+
+ if(fd > 0)
+ HDclose(fd);
+
+ return -1;
+}
+
+/*-------------------------------------------------------------------------
* Function: write_dset_in
*
* Purpose: write datasets in LOC_ID