diff options
-rw-r--r-- | tools/testh5toh4 | 260 |
1 files changed, 260 insertions, 0 deletions
diff --git a/tools/testh5toh4 b/tools/testh5toh4 new file mode 100644 index 0000000..5b5e85f --- /dev/null +++ b/tools/testh5toh4 @@ -0,0 +1,260 @@ +#! /bin/sh +# Test scripts for h5toh4. +# See the USAGE function for command usage. + + +# Definitions of commands and variables +CMD='../h5toh4' +RM='rm -f' +SED='sed ' +H4DUMP='hdp' +DIFF=diff +CMP='cmp -s' +nerrors=0 # number of errors (0) +quitonerr=0 # quit on error (not) +noclean=0 # no cleaning temp. files (yes) +only="" # dumper sub-command to test only +except="" # dumper sub-command to test not + + +# Definitions of functions/shorthands +# + +# Print Usage of the command +USAGE() +{ + echo "Usage: $0 [-help] [-noclean] [-quit] [-except <command>] [-only <command>]" + echo " -help: display help information" + echo " -noclean: do not clean away temporary files" + echo " -quit: quit immediately if any test fails" + echo " -except: skip one specific command" + echo " -only: test one specific command" + echo "<command> can be one of {list, dumpsds, dumprig, dumpvd, dumpvg, dumpgr}" +} + +# Print message with formats according to message level ($1) +MESG() +{ + level=$1 + shift + case $level in + 0) + echo '=============================' + echo $* + echo '=============================' + ;; + 3) + echo '-----------------------------' + echo $* + echo '-----------------------------' + ;; + 6) + echo "*** Arguments are $* ***" + ;; + *) + echo "MESG(): Unknown level ($level)" + exit 1 + ;; + esac + +} + + +# Run the test to produce an output file which is then +# compared with the expected ($1) output. +# Note that this can be used to produce the expected +# output files by replace "$output" with "$expected" +# in the run-the-test commands. +TEST() +{ + # shift + # print a id banner + MESG 6 $@ + # run the test + ( + echo "#############################" + echo "'$CMD $@'" + echo "#############################" + cd testfiles + $CMD "$@" + cd .. + ) + + case "$1" in + + "-m") + + shift + for i in $@ + do + h4file=testfiles/`echo $i | $SED -e s/\.h5/.hdf/g` + + output=`echo $h4file | $SED -e s/\.hdf/.tmp/` + expected=`echo $h4file | $SED -e s/\.hdf/.dmp/` + + $H4DUMP dumpvg $h4file > $output + + $H4DUMP dumpvd $h4file >> $output + + $H4DUMP dumpsds $h4file >> $output + + + $CMP $expected $output + if [ $? -ne 0 ] + then + echo $DIFF $expected $output + $DIFF $expected $output + echo " <<< FAILED >>>" + nerrors=`expr $nerrors + 1` + if [ $quitonerr -gt 0 ]; + then + FINISH + fi + fi + + done + + ;; + + + * ) + + if [ $# -eq 1 ] + then + h4file=testfiles/`echo $1 | $SED -e s/\.h5/.hdf/` + else + h4file=testfiles/$2 + fi + + output=`echo $h4file | $SED -e s/\.hdf/.tmp/` + expected=`echo $h4file | $SED -e s/\.hdf/.dmp/` + + $H4DUMP dumpvg $h4file > $output + + $H4DUMP dumpvd $h4file >> $output + + $H4DUMP dumpsds $h4file >> $output + + $CMP $expected $output + if [ $? -ne 0 ] + then + echo $DIFF $expected $output + $DIFF $expected $output + echo " <<< FAILED >>>" + nerrors=`expr $nerrors + 1` + if [ $quitonerr -gt 0 ]; + then + FINISH + fi + fi + + ;; + esac + +# if [ $noclean -eq 0 ] +# then +# $RM $output +# fi +} + + +# Report the result and exit +FINISH() +{ + if [ $nerrors -eq 0 ] + then + MESG 0 "All h5toh4 tests passed" + else + MESG 0 "h5toh4 tests failed: $nerrors" + fi + exit $nerrors +} + + +#=============== +# Main Body +#=============== + +# parse arguments +while [ $# -gt 0 ] +do + case "$1" in + "-quit") + quitonerr=1 + ;; + "-noclean") + noclean=1 + ;; + "-help") + USAGE + exit 0 + ;; + "-only") + shift + case "$1" in + "h5toh4") + only="$1" + ;; + *) + echo "Unknown command: $1" + USAGE + exit 1 + ;; + esac + ;; + "-except") + shift + case "$1" in + "h5toh4") + except="$1" + ;; + *) + echo "Unknown command: $1" + USAGE + exit 1 + ;; + esac + ;; + * ) + echo "Unknow option: $1" + USAGE + exit 1 + ;; + esac + shift +done + +# Print a beginning banner +MESG 0 "Running h5toh4 tests" + +# Test command list +TestCmd=h5toh4 +TestName="Test command $TestCmd" +if [ "$except" != $TestCmd -a \( -z "$only" -o "$only" = $TestCmd \) ] +then +MESG 3 "$TestName" +$RM ./testfiles/*.hdf ./testfiles/*.tmp +TEST tgroup.h5 +TEST tdset.h5 +TEST tattr.h5 +TEST tslink.h5 +TEST thlink.h5 +TEST tcompound.h5 +TEST tall.h5 +$RM ./testfiles/*.tmp +TEST tgroup.h5 tgroup.hdf +TEST tdset.h5 tdset.hdf +TEST tattr.h5 tattr.hdf +TEST tslink.h5 tslink.hdf +TEST thlink.h5 thlink.hdf +TEST tcompound.h5 tcompound.hdf +TEST tall.h5 tall.hdf +$RM ./testfiles/*.hdf ./testfiles/*.tmp +TEST -m tgroup.h5 tdset.h5 tattr.h5 tslink.h5 thlink.h5 tcompound.h5 tall.h5 +$RM ./testfiles/*.hdf ./testfiles/*.tmp +else +MESG 3 "$TestName <<<SKIPPED>>>" +fi + +# End of test +FINISH |