1#! /bin/sh 2# 3# Copyright by The HDF Group. 4# Copyright by the Board of Trustees of the University of Illinois. 5# All rights reserved. 6# 7# This file is part of HDF5. The full HDF5 copyright notice, including 8# terms governing use, modification, and redistribution, is contained in 9# the COPYING file, which can be found at the root of the source code 10# distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. 11# If you do not have access to either file, you may request a copy from 12# help@hdfgroup.org. 13# 14# Tests for the h5dump tool with vds type files 15 16srcdir=@srcdir@ 17 18# Determine which filters are available 19USE_FILTER_SZIP="@USE_FILTER_SZIP@" 20USE_FILTER_DEFLATE="@USE_FILTER_DEFLATE@" 21 22TESTNAME=h5dump 23EXIT_SUCCESS=0 24EXIT_FAILURE=1 25 26DUMPER=../../src/h5dump/h5dump # The tool name 27DUMPER_BIN=`pwd`/$DUMPER # The path of the tool binary 28 29H5DIFF=../../src/h5diff/h5diff # The h5diff tool name 30H5DIFF_BIN=`pwd`/$H5DIFF # The path of the h5diff tool binary 31 32H5IMPORT=../../src/h5import/h5import # The h5import tool name 33H5IMPORT_BIN=`pwd`/$H5IMPORT # The path of the h5import tool binary 34 35RM='rm -rf' 36CMP='cmp -s' 37DIFF='diff -c' 38CP='cp' 39DIRNAME='dirname' 40LS='ls' 41AWK='awk' 42 43nerrors=0 44verbose=yes 45 46# source dirs 47SRC_TOOLS="$srcdir/../.." 48 49SRC_TOOLS_TESTFILES="$SRC_TOOLS/testfiles" 50# testfiles source dirs for tools 51SRC_H5LS_TESTFILES="$SRC_TOOLS_TESTFILES" 52SRC_H5DUMP_TESTFILES="$SRC_TOOLS_TESTFILES" 53SRC_H5DUMP_ERRORFILES="$srcdir/errfiles" 54SRC_H5DIFF_TESTFILES="$SRC_TOOLS/test/h5diff/testfiles" 55SRC_H5COPY_TESTFILES="$SRC_TOOLS/test/h5copy/testfiles" 56SRC_H5REPACK_TESTFILES="$SRC_TOOLS/test/h5repack/testfiles" 57SRC_H5JAM_TESTFILES="$SRC_TOOLS/test/h5jam/testfiles" 58SRC_H5STAT_TESTFILES="$SRC_TOOLS/test/h5stat/testfiles" 59SRC_H5IMPORT_TESTFILES="$SRC_TOOLS/test/h5import/testfiles" 60 61TEST_P_DIR=./testfiles 62TESTDIR=./testfiles/vds 63test -d $TEST_P_DIR || mkdir -p $TEST_P_DIR 64test -d $TESTDIR || mkdir -p $TESTDIR 65 66###################################################################### 67# test files 68# -------------------------------------------------------------------- 69# All the test files copy from source directory to test directory 70# NOTE: Keep this framework to add/remove test files. 71# Any test files from other tools can be used in this framework. 72# This list are also used for checking exist. 73# Comment '#' without space can be used. 74# -------------------------------------------------------------------- 75LIST_HDF5_TEST_FILES=" 76$SRC_H5DUMP_TESTFILES/vds/1_a.h5 77$SRC_H5DUMP_TESTFILES/vds/1_b.h5 78$SRC_H5DUMP_TESTFILES/vds/1_c.h5 79$SRC_H5DUMP_TESTFILES/vds/1_d.h5 80$SRC_H5DUMP_TESTFILES/vds/1_e.h5 81$SRC_H5DUMP_TESTFILES/vds/1_f.h5 82$SRC_H5DUMP_TESTFILES/vds/1_vds.h5 83$SRC_H5DUMP_TESTFILES/vds/2_a.h5 84$SRC_H5DUMP_TESTFILES/vds/2_b.h5 85$SRC_H5DUMP_TESTFILES/vds/2_c.h5 86$SRC_H5DUMP_TESTFILES/vds/2_d.h5 87$SRC_H5DUMP_TESTFILES/vds/2_e.h5 88$SRC_H5DUMP_TESTFILES/vds/2_vds.h5 89$SRC_H5DUMP_TESTFILES/vds/3_1_vds.h5 90$SRC_H5DUMP_TESTFILES/vds/3_2_vds.h5 91$SRC_H5DUMP_TESTFILES/vds/4_0.h5 92$SRC_H5DUMP_TESTFILES/vds/4_1.h5 93$SRC_H5DUMP_TESTFILES/vds/4_2.h5 94$SRC_H5DUMP_TESTFILES/vds/4_vds.h5 95$SRC_H5DUMP_TESTFILES/vds/5_a.h5 96$SRC_H5DUMP_TESTFILES/vds/5_b.h5 97$SRC_H5DUMP_TESTFILES/vds/5_c.h5 98$SRC_H5DUMP_TESTFILES/vds/5_vds.h5 99$SRC_H5DUMP_TESTFILES/vds/a.h5 100$SRC_H5DUMP_TESTFILES/vds/b.h5 101$SRC_H5DUMP_TESTFILES/vds/c.h5 102$SRC_H5DUMP_TESTFILES/vds/d.h5 103$SRC_H5DUMP_TESTFILES/vds/vds-percival-unlim-maxmin.h5 104$SRC_H5DUMP_TESTFILES/vds/f-0.h5 105$SRC_H5DUMP_TESTFILES/vds/f-3.h5 106$SRC_H5DUMP_TESTFILES/vds/vds-eiger.h5 107" 108 109LIST_OTHER_TEST_FILES=" 110$SRC_H5DUMP_TESTFILES/vds/tvds-1.ddl 111$SRC_H5DUMP_TESTFILES/vds/tvds-2.ddl 112$SRC_H5DUMP_TESTFILES/vds/tvds-3_1.ddl 113$SRC_H5DUMP_TESTFILES/vds/tvds-3_2.ddl 114$SRC_H5DUMP_TESTFILES/vds/tvds-4.ddl 115$SRC_H5DUMP_TESTFILES/vds/tvds-5.ddl 116$SRC_H5DUMP_TESTFILES/vds/tvds_layout-1.ddl 117$SRC_H5DUMP_TESTFILES/vds/tvds_layout-2.ddl 118$SRC_H5DUMP_TESTFILES/vds/tvds_layout-3_1.ddl 119$SRC_H5DUMP_TESTFILES/vds/tvds_layout-3_2.ddl 120$SRC_H5DUMP_TESTFILES/vds/tvds_layout-4.ddl 121$SRC_H5DUMP_TESTFILES/vds/tvds_layout-5.ddl 122$SRC_H5DUMP_TESTFILES/vds/vds-first.ddl 123$SRC_H5DUMP_TESTFILES/vds/vds-gap1.ddl 124$SRC_H5DUMP_TESTFILES/vds/vds-gap2.ddl 125$SRC_H5DUMP_TESTFILES/vds/vds_layout-eiger.ddl 126$SRC_H5DUMP_TESTFILES/vds/vds_layout-maxmin.ddl 127" 128 129LIST_ERROR_TEST_FILES=" 130" 131 132# 133# copy test files and expected output files from source dirs to test dir 134# 135COPY_TESTFILES="$LIST_HDF5_TEST_FILES $LIST_OTHER_TEST_FILES $LIST_ERROR_TEST_FILES" 136 137COPY_TESTFILES_TO_TESTDIR() 138{ 139 # copy test files. Used -f to make sure get a new copy 140 for tstfile in $COPY_TESTFILES 141 do 142 # ignore '#' comment 143 echo $tstfile | tr -d ' ' | grep '^#' > /dev/null 144 RET=$? 145 if [ $RET -eq 1 ]; then 146 # skip cp if srcdir is same as destdir 147 # this occurs when build/test performed in source dir and 148 # make cp fail 149 SDIR=`$DIRNAME $tstfile` 150 INODE_SDIR=`$LS -i -d $SDIR | $AWK -F' ' '{print $1}'` 151 INODE_DDIR=`$LS -i -d $TESTDIR | $AWK -F' ' '{print $1}'` 152 if [ "$INODE_SDIR" != "$INODE_DDIR" ]; then 153 $CP -f $tstfile $TESTDIR 154 if [ $? -ne 0 ]; then 155 echo "Error: FAILED to copy $tstfile ." 156 157 # Comment out this to CREATE expected file 158 exit $EXIT_FAILURE 159 fi 160 fi 161 fi 162 done 163} 164 165CLEAN_TESTFILES_AND_TESTDIR() 166{ 167 # skip rm if srcdir is same as destdir 168 # this occurs when build/test performed in source dir and 169 # make cp fail 170 SDIR=$SRC_H5DUMP_TESTFILES/vds 171 INODE_SDIR=`$LS -i -d $SDIR | $AWK -F' ' '{print $1}'` 172 INODE_DDIR=`$LS -i -d $TESTDIR | $AWK -F' ' '{print $1}'` 173 if [ "$INODE_SDIR" != "$INODE_DDIR" ]; then 174 $RM $TESTDIR 175 fi 176} 177 178# Print a line-line message left justified in a field of 70 characters 179# beginning with the word "Testing". 180# 181TESTING() { 182 SPACES=" " 183 echo "Testing $* $SPACES" | cut -c1-70 | tr -d '\012' 184} 185 186# Source in the output filter function definitions. 187. $srcdir/../../../bin/output_filter.sh 188 189# Run a test and print PASS or *FAIL*. If a test fails then increment 190# the `nerrors' global variable and (if $verbose is set) display the 191# difference between the actual output and the expected output. The 192# expected output is given as the first argument to this function and 193# the actual output file is calculated by replacing the `.ddl' with 194# `.out'. The actual output is not removed if $HDF5_NOCLEANUP has a 195# non-zero value. 196# 197TOOLTEST() { 198 expect="$TESTDIR/$1" 199 actual="$TESTDIR/`basename $1 .ddl`.out" 200 actual_err="$TESTDIR/`basename $1 .ddl`.err" 201 actual_sav=${actual}-sav 202 actual_err_sav=${actual_err}-sav 203 shift 204 205 # Run test. 206 TESTING $DUMPER $@ 207 ( 208 cd $TESTDIR 209 $RUNSERIAL $DUMPER_BIN "$@" 210 ) >$actual 2>$actual_err 211 212 # save actual and actual_err in case they are needed later. 213 cp $actual $actual_sav 214 STDOUT_FILTER $actual 215 cp $actual_err $actual_err_sav 216 STDERR_FILTER $actual_err 217 cat $actual_err >> $actual 218 219 if [ ! -f $expect ]; then 220 # Create the expect file if it doesn't yet exist. 221 echo " CREATED" 222 cp $actual $expect 223 echo " Expected result (*.ddl) missing" 224 nerrors="`expr $nerrors + 1`" 225 elif $CMP $expect $actual; then 226 echo " PASSED" 227 else 228 echo "*FAILED*" 229 echo " Expected result (*.ddl) differs from actual result (*.out)" 230 nerrors="`expr $nerrors + 1`" 231 test yes = "$verbose" && $DIFF $expect $actual |sed 's/^/ /' 232 fi 233 234 # Clean up output file 235 if test -z "$HDF5_NOCLEANUP"; then 236 rm -f $actual $actual_err $actual_sav $actual_err_sav $actual_ext 237 fi 238 239} 240 241 242# same as TOOLTEST1 but compares generated file to expected output 243# and compares the generated data file to the expected data file 244# used for the binary tests that expect a full path in -o without -b 245TOOLTEST2() { 246 247 expectdata="$TESTDIR/$1" 248 expect="$TESTDIR/`basename $1 .exp`.ddl" 249 actualdata="$TESTDIR/`basename $1 .exp`.txt" 250 actual="$TESTDIR/`basename $1 .exp`.out" 251 actual_err="$TESTDIR/`basename $1 .exp`.err" 252 shift 253 254 # Run test. 255 TESTING $DUMPER $@ 256 ( 257 cd $TESTDIR 258 $RUNSERIAL $DUMPER_BIN "$@" 259 ) >$actual 2>$actual_err 260 cat $actual_err >> $actual 261 262 if [ ! -f $expect ]; then 263 # Create the expect file if it doesn't yet exist. 264 echo " CREATED" 265 cp $actual $expect 266 echo " Expected result (*.ddl) missing" 267 nerrors="`expr $nerrors + 1`" 268 elif $CMP $expect $actual; then 269 if [ ! -f $expectdata ]; then 270 # Create the expect data file if it doesn't yet exist. 271 echo " CREATED" 272 cp $actualdata $expectdata 273 echo " Expected data (*.exp) missing" 274 nerrors="`expr $nerrors + 1`" 275 elif $CMP $expectdata $actualdata; then 276 echo " PASSED" 277 else 278 echo "*FAILED*" 279 echo " Expected datafile (*.exp) differs from actual datafile (*.txt)" 280 nerrors="`expr $nerrors + 1`" 281 test yes = "$verbose" && $DIFF $expectdata $actualdata |sed 's/^/ /' 282 fi 283 else 284 echo "*FAILED*" 285 echo " Expected result (*.ddl) differs from actual result (*.out)" 286 nerrors="`expr $nerrors + 1`" 287 test yes = "$verbose" && $DIFF $expect $actual |sed 's/^/ /' 288 fi 289 290 # Clean up output file 291 if test -z "$HDF5_NOCLEANUP"; then 292 rm -f $actual $actualdata $actual_err 293 fi 294 295} 296 297# same as TOOLTEST but filters error stack outp 298# Extract file name, line number, version and thread IDs because they may be different 299TOOLTEST3() { 300 301 expect="$TESTDIR/$1" 302 actual="$TESTDIR/`basename $1 .ddl`.out" 303 actual_err="$TESTDIR/`basename $1 .ddl`.err" 304 actual_ext="$TESTDIR/`basename $1 .ddl`.ext" 305 actual_sav=${actual}-sav 306 actual_err_sav=${actual_err}-sav 307 shift 308 309 # Run test. 310 TESTING $DUMPER $@ 311 ( 312 cd $TESTDIR 313 $RUNSERIAL $DUMPER_BIN "$@" 314 ) >$actual 2>$actual_err 315 316 # save actual and actual_err in case they are needed later. 317 cp $actual $actual_sav 318 STDOUT_FILTER $actual 319 cp $actual_err $actual_err_sav 320 STDERR_FILTER $actual_err 321 322 # Extract file name, line number, version and thread IDs because they may be different 323 sed -e 's/thread [0-9]*/thread (IDs)/' -e 's/: .*\.c /: (file name) /' \ 324 -e 's/line [0-9]*/line (number)/' \ 325 -e 's/v[1-9]*\.[0-9]*\./version (number)\./' \ 326 -e 's/[1-9]*\.[0-9]*\.[0-9]*[^)]*/version (number)/' \ 327 -e 's/H5Eget_auto[1-2]*/H5Eget_auto(1 or 2)/' \ 328 -e 's/H5Eset_auto[1-2]*/H5Eset_auto(1 or 2)/' \ 329 $actual_err > $actual_ext 330 cat $actual_ext >> $actual 331 332 if [ ! -f $expect ]; then 333 # Create the expect file if it doesn't yet exist. 334 echo " CREATED" 335 cp $actual $expect 336 echo " Expected result (*.ddl) missing" 337 nerrors="`expr $nerrors + 1`" 338 elif $CMP $expect $actual; then 339 echo " PASSED" 340 else 341 echo "*FAILED*" 342 echo " Expected result (*.ddl) differs from actual result (*.out)" 343 nerrors="`expr $nerrors + 1`" 344 test yes = "$verbose" && $DIFF $expect $actual |sed 's/^/ /' 345 fi 346 347 # Clean up output file 348 if test -z "$HDF5_NOCLEANUP"; then 349 rm -f $actual $actual_err $actual_sav $actual_err_sav 350 fi 351 352} 353 354# same as TOOLTEST3 but filters error stack output and compares to an error file 355# Extract file name, line number, version and thread IDs because they may be different 356TOOLTEST4() { 357 358 expect="$TESTDIR/$1" 359 expect_err="$TESTDIR/`basename $1 .ddl`.err" 360 actual="$TESTDIR/`basename $1 .ddl`.out" 361 actual_err="$TESTDIR/`basename $1 .ddl`.oerr" 362 actual_ext="$TESTDIR/`basename $1 .ddl`.ext" 363 actual_sav=${actual}-sav 364 actual_err_sav=${actual_err}-sav 365 shift 366 367 # Run test. 368 TESTING $DUMPER $@ 369 ( 370 cd $TESTDIR 371 $RUNSERIAL $DUMPER_BIN "$@" 372 ) >$actual 2>$actual_err 373 374 # save actual and actual_err in case they are needed later. 375 cp $actual $actual_sav 376 STDOUT_FILTER $actual 377 cp $actual_err $actual_err_sav 378 STDERR_FILTER $actual_err 379 380 # Extract file name, line number, version and thread IDs because they may be different 381 sed -e 's/thread [0-9]*/thread (IDs)/' -e 's/: .*\.c /: (file name) /' \ 382 -e 's/line [0-9]*/line (number)/' \ 383 -e 's/v[1-9]*\.[0-9]*\./version (number)\./' \ 384 -e 's/[1-9]*\.[0-9]*\.[0-9]*[^)]*/version (number)/' \ 385 -e 's/H5Eget_auto[1-2]*/H5Eget_auto(1 or 2)/' \ 386 -e 's/H5Eset_auto[1-2]*/H5Eset_auto(1 or 2)/' \ 387 $actual_err > $actual_ext 388 #cat $actual_ext >> $actual 389 390 if [ ! -f $expect ]; then 391 # Create the expect file if it doesn't yet exist. 392 echo " CREATED" 393 cp $actual $expect 394 elif $CMP $expect $actual; then 395 if $CMP $expect_err $actual_ext; then 396 echo " PASSED" 397 else 398 echo "*FAILED*" 399 echo " Expected result (*.err) differs from actual result (*.oerr)" 400 nerrors="`expr $nerrors + 1`" 401 test yes = "$verbose" && $DIFF $expect_err $actual_ext |sed 's/^/ /' 402 fi 403 else 404 echo "*FAILED*" 405 echo " Expected result (*.ddl) differs from actual result (*.out)" 406 nerrors="`expr $nerrors + 1`" 407 test yes = "$verbose" && $DIFF $expect $actual |sed 's/^/ /' 408 fi 409 410 # Clean up output file 411 if test -z "$HDF5_NOCLEANUP"; then 412 rm -f $actual $actual_err $actual_sav $actual_err_sav 413 fi 414 415} 416 417# Print a "SKIP" message 418SKIP() { 419 TESTING $DUMPER $@ 420 echo " -SKIP-" 421} 422 423# Print a line-line message left justified in a field of 70 characters 424# 425PRINT_H5DIFF() { 426 SPACES=" " 427 echo " Running h5diff $* $SPACES" | cut -c1-70 | tr -d '\012' 428} 429 430 431# Call the h5diff tool 432# 433DIFFTEST() 434{ 435 PRINT_H5DIFF $@ 436 ( 437 cd $TESTDIR 438 $RUNSERIAL $H5DIFF_BIN "$@" -q 439 ) 440 RET=$? 441 if [ $RET != 0 ] ; then 442 echo "*FAILED*" 443 nerrors="`expr $nerrors + 1`" 444 else 445 echo " PASSED" 446 fi 447 448} 449 450# Print a line-line message left justified in a field of 70 characters 451# beginning with the word "Verifying". 452# 453PRINT_H5IMPORT() { 454 SPACES=" " 455 echo " Running h5import $* $SPACES" | cut -c1-70 | tr -d '\012' 456} 457 458# Call the h5import tool 459# 460IMPORTTEST() 461{ 462 # remove the output hdf5 file if it exists 463 hdf5_file="$TESTDIR/$5" 464 if [ -f $hdf5_file ]; then 465 rm -f $hdf5_file 466 fi 467 468 PRINT_H5IMPORT $@ 469 ( 470 cd $TESTDIR 471 $RUNSERIAL $H5IMPORT_BIN "$@" 472 ) 473 RET=$? 474 if [ $RET != 0 ] ; then 475 echo "*FAILED*" 476 nerrors="`expr $nerrors + 1`" 477 else 478 echo " PASSED" 479 fi 480 481} 482 483 484############################################################################## 485############################################################################## 486### T H E T E S T S ### 487############################################################################## 488############################################################################## 489# prepare for test 490COPY_TESTFILES_TO_TESTDIR 491 492####### test for dataset vds ###### 493 494 # Data read 495if test $USE_FILTER_DEFLATE = "yes" ; then 496 TOOLTEST tvds-1.ddl --enable-error-stack 1_vds.h5 497 TOOLTEST tvds-2.ddl --enable-error-stack 2_vds.h5 498 TOOLTEST tvds-3_1.ddl --enable-error-stack 3_1_vds.h5 499 TOOLTEST tvds-3_2.ddl --enable-error-stack 3_2_vds.h5 500 TOOLTEST tvds-4.ddl --enable-error-stack 4_vds.h5 501 TOOLTEST tvds-5.ddl --enable-error-stack 5_vds.h5 502 TOOLTEST vds-first.ddl --vds-view-first-missing --enable-error-stack vds-percival-unlim-maxmin.h5 503 TOOLTEST vds-gap1.ddl -d /VDS-Eiger --vds-gap-size=1 --enable-error-stack vds-eiger.h5 504 TOOLTEST vds-gap2.ddl --vds-gap-size=2 --enable-error-stack vds-eiger.h5 505fi 506 507 # Layout read 508if test $USE_FILTER_DEFLATE = "yes" ; then 509 TOOLTEST tvds_layout-1.ddl -p --enable-error-stack 1_vds.h5 510 TOOLTEST tvds_layout-2.ddl -p --enable-error-stack 2_vds.h5 511 TOOLTEST tvds_layout-3_1.ddl -p --enable-error-stack 3_1_vds.h5 512 TOOLTEST tvds_layout-3_2.ddl -p --enable-error-stack 3_2_vds.h5 513 TOOLTEST tvds_layout-4.ddl -p --enable-error-stack 4_vds.h5 514 TOOLTEST tvds_layout-5.ddl -p --enable-error-stack 5_vds.h5 515 TOOLTEST vds_layout-eiger.ddl -p --enable-error-stack vds-eiger.h5 516 TOOLTEST vds_layout-maxmin.ddl -p --enable-error-stack vds-percival-unlim-maxmin.h5 517fi 518 519# Clean up temporary files/directories 520CLEAN_TESTFILES_AND_TESTDIR 521 522# Report test results and exit 523if test $nerrors -eq 0 ; then 524 echo "All $TESTNAME tests passed." 525 exit $EXIT_SUCCESS 526else 527 echo "$TESTNAME tests failed with $nerrors errors." 528 exit $EXIT_FAILURE 529fi 530