From d49f76ace993ef06a9dcea24f38d920f8df48858 Mon Sep 17 00:00:00 2001 From: Pedro Vicente Nunes Date: Wed, 9 Oct 2002 16:23:38 -0500 Subject: [svn-r5972] Purpose: added a test file , a makefile and a script to run h5diff tests Platforms tested: linux 2.4.18 --- tools/h5diff/Makefile.in | 64 +++++++ tools/h5diff/h5difftst.c | 452 +++++++++++++++++++++++++++++++++++++++++++++ tools/h5diff/testh5diff.sh | 53 ++++++ 3 files changed, 569 insertions(+) create mode 100644 tools/h5diff/Makefile.in create mode 100644 tools/h5diff/h5difftst.c create mode 100755 tools/h5diff/testh5diff.sh diff --git a/tools/h5diff/Makefile.in b/tools/h5diff/Makefile.in new file mode 100644 index 0000000..9995cd8 --- /dev/null +++ b/tools/h5diff/Makefile.in @@ -0,0 +1,64 @@ +## HDF5 Library Makefile(.in) +## +## Copyright (C) 2001 National Center for Supercomputing Applications. +## All rights reserved. +## +## +top_srcdir=@top_srcdir@ +top_builddir=../.. +srcdir=@srcdir@ +SUBDIRS= +@COMMENCE@ + +## Add include directory to the C preprocessor flags, add -lh5tools and +## -lhdf5 to the list of libraries. +## +CPPFLAGS=-I. -I$(srcdir) -I$(top_builddir)/src -I$(top_srcdir)/src \ + -I$(top_srcdir)/tools/lib @CPPFLAGS@ + +## Test programs and scripts. +## +TEST_PROGS= +TEST_SCRIPTS=$(srcdir)/testh5diff.sh + +## These are our main targets: library and tools. +## +LIBHDF5=$(top_builddir)/src/libhdf5.la + +PUB_PROGS=h5diff +PROGS=$(PUB_PROGS) $(TEST_PROGS) h5difftst + +## Source and object files for the library; do not install +## +LIB_SRC= +LIB_OBJ=$(LIB_SRC:.c=.lo) +PUB_LIB= + +## Source and object files for programs... +## +PROG_SRC=h5diff.c h5difftst.c +PROG_OBJ=$(PROG_SRC:.c=.lo) + +PRIVATE_HDR= + +## Source and object files for the tests +## +TEST_SRC= +TEST_OBJ=$(TEST_SRC:.c=.lo) + +## Programs have to be built before they can be tested! +## +check test _test: $(PROGS) + +## How to build the programs...They all depend on the hdf5 library and +## the tools library compiled in this directory. +## +$(PROGS): $(LIBTOOLS) $(LIBHDF5) + +h5diff: h5diff.lo + @$(LT_LINK_EXE) $(CFLAGS) -o $@ h5diff.lo $(LIBTOOLS) $(LIBHDF5) $(LDFLAGS) $(LIBS) + +h5difftst: h5difftst.lo + @$(LT_LINK_EXE) $(CFLAGS) -o $@ h5difftst.lo $(LIBTOOLS) $(LIBHDF5) $(LDFLAGS) $(LIBS) + +@CONCLUDE@ diff --git a/tools/h5diff/h5difftst.c b/tools/h5diff/h5difftst.c new file mode 100644 index 0000000..e0065f7 --- /dev/null +++ b/tools/h5diff/h5difftst.c @@ -0,0 +1,452 @@ + + +#include +#include + +#include "hdf5.h" + + +#ifndef FALSE +#define FALSE 0 +#endif +#ifndef TRUE +#define TRUE 1 +#endif + +int do_test_files(); +int h5diff_dataset( hid_t file1_id, hid_t file2_id, const char *dset_name ); +void array_diff( void *buf1, void *buf2, hsize_t tot_cnt, hid_t type_id ); + + + + +/*------------------------------------------------------------------------- + * Function: usage + * + * Purpose: print a usage message + * + * Return: void + * + * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu + * + * Date: October 8, 2002 + * + * Comments: + * + * Modifications: + * + *------------------------------------------------------------------------- + */ + +void usage( const char *progname ) +{ +#define USAGE "\ + [-d dset] Compare only the specified dataset(s)\n\ + file1 File name of the first HDF5 file\n\ + file2 File name of the second HDF5 file\n" + + fprintf(stderr, + "%s [-d] file1 file2\n%s", + progname, + USAGE); + exit(EXIT_FAILURE); +} + + +/*------------------------------------------------------------------------- + * Function: main + * + * Purpose: H5diff + * + * Return: Success: 0, Failure: 1 + * + * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu + * + * Date: October 8, 2002 + * + * Comments: + * + * Modifications: + * + *------------------------------------------------------------------------- + */ + +int main(int argc, const char *argv[]) +{ + + const char *progname = argv[0]; + int dset_only = FALSE; + int argno; + const char *s = NULL; + const char *file1_name = NULL; + const char *file2_name = NULL; + const char *dset_name = NULL; + hid_t file1_id, file2_id; + herr_t status; + + do_test_files(); + + +/*------------------------------------------------------------------------- + * parse command line options + *------------------------------------------------------------------------- + */ + + if (argc < 2) { + usage( progname ); + exit(EXIT_FAILURE); + } + + /* parse command line options */ + for (argno=1; argno tot_cnt2) + tot_cnt = tot_cnt2; + else + tot_cnt = tot_cnt1; + + array_diff(buf1,buf2,tot_cnt,type1_id); + + + free((char *) buf1); + free((char *) buf2); + +/*------------------------------------------------------------------------- + * close + *------------------------------------------------------------------------- + */ + + +out: + + /* Close */ + status = H5Dclose(dset1_id); + status = H5Dclose(dset2_id); + status = H5Sclose(space1_id); + status = H5Sclose(space2_id); + status = H5Tclose(type1_id); + status = H5Tclose(type2_id); + + return 0; + +} + + + +/*------------------------------------------------------------------------- + * Function: array_diff + * + * Purpose: + * + * Return: Success: 0, Failure: -11 + * + * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu + * + * Date: October 8, 2002 + * + * Comments: + * + * Modifications: + * + *------------------------------------------------------------------------- + */ + + +void array_diff( void *buf1, void *buf2, hsize_t tot_cnt, hid_t type_id ) +{ + +#if 0 + char *i1ptr1, *i1ptr2; + short *i2ptr1, *i2ptr2; + float *fptr1, *fptr2; + double *dptr1, *dptr2; +#endif + + int *i4ptr1, *i4ptr2; + int i; + + H5T_class_t type_class; + size_t type_size; + + /* Get the class. */ + type_class = H5Tget_class( type_id ); + + /* Get the size. */ + type_size = H5Tget_size( type_id ); + + + switch(type_class) + { + case H5T_INTEGER: + + + switch(type_size) + { + case 4: + + i4ptr1 = (int *) buf1; + i4ptr2 = (int *) buf2; + for ( i = 0; i < tot_cnt; i++) + { + if (*i4ptr1 != *i4ptr2) + { + printf("Index: %d, File1: %d, File2: %d\n", i, *i4ptr1, *i4ptr2); + } + i4ptr1++; i4ptr2++; + } + + + + break; + + } /*switch*/ + + + + break; /* H5T_INTEGER */ + + + + } /*switch*/ + + + +} + + + + + +/*------------------------------------------------------------------------- + * do some test files + *------------------------------------------------------------------------- + */ + +int do_test_files() +{ + + hid_t file_id; + hid_t dataset_id; + hid_t space_id; + hsize_t dims1[1] = { 5 }; + int data1[5] = {1,2,3,4,5}; + hsize_t dims2[1] = { 5 }; + int data2[5] = {6,7,8,9,10}; + herr_t status; + +/*------------------------------------------------------------------------- + * Create one file + *------------------------------------------------------------------------- + */ + + /* Create a file */ + file_id = H5Fcreate ("h5diff_test1.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); + + /* Create a data space */ + space_id = H5Screate_simple(1,dims1,NULL); + + /* Create a dataset "dset" */ + dataset_id = H5Dcreate(file_id,"dset",H5T_NATIVE_INT,space_id,H5P_DEFAULT); + + /* Write the data */ + status = H5Dwrite(dataset_id,H5T_NATIVE_INT,H5S_ALL,H5S_ALL,H5P_DEFAULT,data1); + + /* Close */ + status = H5Dclose(dataset_id); + status = H5Sclose(space_id); + status = H5Fclose(file_id); + +/*------------------------------------------------------------------------- + * Create another file + *------------------------------------------------------------------------- + */ + + /* Create a file */ + file_id = H5Fcreate ("h5diff_test2.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); + + /* Create a data space */ + space_id = H5Screate_simple(1,dims2,NULL); + + /* Create a dataset "dset" */ + dataset_id = H5Dcreate(file_id,"dset",H5T_NATIVE_INT,space_id,H5P_DEFAULT); + + /* Write the data */ + status = H5Dwrite(dataset_id,H5T_NATIVE_INT,H5S_ALL,H5S_ALL,H5P_DEFAULT,data2); + + /* Close */ + status = H5Dclose(dataset_id); + status = H5Sclose(space_id); + status = H5Fclose(file_id); + + + return 0; + + +} diff --git a/tools/h5diff/testh5diff.sh b/tools/h5diff/testh5diff.sh new file mode 100755 index 0000000..57add44 --- /dev/null +++ b/tools/h5diff/testh5diff.sh @@ -0,0 +1,53 @@ +#! /bin/sh +# +# Copyright (C) 1998-2002 National Center for Supercomputing Applications +# All rights reserved. +# +# Tests for the h5diff tool + +DUMPER=h5diff # The tool name +DUMPER_BIN=`pwd`/$DUMPER # The path of the tool binary + +CMP='cmp -s' +DIFF='diff -c' + +nerrors=0 +verbose=yes + +# The build (current) directory might be different than the source directory. +if test -z "$srcdir"; then + srcdir=. +fi + + +# Print a line-line message left justified in a field of 70 characters +# beginning with the word "Testing". +# +TESTING() { + SPACES=" " + echo "Testing $* $SPACES" | cut -c1-70 | tr -d '\012' +} + +# Run a test and print PASS or *FAIL*. If a test fails then increment +# the `nerrors' global variable and (if $verbose is set) display the +# difference between the actual output and the expected output. The +# expected output is given as the first argument to this function and +# the actual output file is calculated by replacing the `.ddl' with +# `.out'. The actual output is not removed if $HDF5_NOCLEANUP has a +# non-zero value. +# +TOOLTEST() { + # Run test. + $RUNSERIAL $DUMPER_BIN "$@" + +} + +############################################################################## +############################################################################## +### T H E T E S T S ### +############################################################################## +############################################################################## + +# test +TOOLTEST -d dset h5diff_test1.h5 h5diff_test2.h5 + -- cgit v0.12