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 h5import tool 15 16srcdir=@srcdir@ 17 18# Determine which filters are available 19USE_FILTER_DEFLATE="@USE_FILTER_DEFLATE@" 20 21TESTNAME=h5import 22EXIT_SUCCESS=0 23EXIT_FAILURE=1 24 25DUMPER=../h5dump/h5dump # The tool name 26DUMPER_BIN=`pwd`/$DUMPER # The path of the tool binary 27 28H5DIFF=../h5diff/h5diff # The h5diff tool name 29H5DIFF_BIN=`pwd`/$H5DIFF # The path of the h5diff tool binary 30 31H5IMPORT=./h5import # The h5import tool name 32H5IMPORT_BIN=`pwd`/$H5IMPORT # The path of the h5import tool binary 33 34RM='rm -rf' 35CP='cp' 36DIRNAME='dirname' 37LS='ls' 38AWK='awk' 39 40# initialize errors variable 41nerrors=0 42 43# source dirs 44SRC_TOOLS="$srcdir/.." 45SRC_TOOLS_TESTFILES="$SRC_TOOLS/testfiles" 46 47# testfiles source dirs for tools 48SRC_H5LS_TESTFILES="$SRC_TOOLS_TESTFILES" 49SRC_H5DUMP_TESTFILES="$SRC_TOOLS_TESTFILES" 50SRC_H5DIFF_TESTFILES="$SRC_TOOLS/h5diff/testfiles" 51SRC_H5COPY_TESTFILES="$SRC_TOOLS/h5copy/testfiles" 52SRC_H5REPACK_TESTFILES="$SRC_TOOLS/h5repack/testfiles" 53SRC_H5JAM_TESTFILES="$SRC_TOOLS/h5jam/testfiles" 54SRC_H5STAT_TESTFILES="$SRC_TOOLS/h5stat/testfiles" 55SRC_H5IMPORT_TESTFILES="$SRC_TOOLS/h5import/testfiles" 56 57TESTDIR=./testfiles 58test -d $TESTDIR || mkdir $TESTDIR 59 60###################################################################### 61# test files 62# -------------------------------------------------------------------- 63# All the test files copy from source directory to test directory 64# NOTE: Keep this framework to add/remove test files. 65# Any test files from other tools can be used in this framework. 66# This list are also used for checking exist. 67# Comment '#' without space can be used. 68# -------------------------------------------------------------------- 69LIST_HDF5_TEST_FILES=" 70$SRC_H5IMPORT_TESTFILES/binfp64.h5 71$SRC_H5IMPORT_TESTFILES/binin8.h5 72$SRC_H5IMPORT_TESTFILES/binin8w.h5 73$SRC_H5IMPORT_TESTFILES/binin16.h5 74$SRC_H5IMPORT_TESTFILES/binin32.h5 75$SRC_H5IMPORT_TESTFILES/binuin16.h5 76$SRC_H5IMPORT_TESTFILES/binuin32.h5 77$SRC_H5IMPORT_TESTFILES/txtfp32.h5 78$SRC_H5IMPORT_TESTFILES/txtfp64.h5 79$SRC_H5IMPORT_TESTFILES/txtin8.h5 80$SRC_H5IMPORT_TESTFILES/txtin16.h5 81$SRC_H5IMPORT_TESTFILES/txtin32.h5 82$SRC_H5IMPORT_TESTFILES/txtuin16.h5 83$SRC_H5IMPORT_TESTFILES/txtuin32.h5 84$SRC_H5IMPORT_TESTFILES/txtstr.h5 85$SRC_H5IMPORT_TESTFILES/textpfe.h5 86$SRC_TOOLS_TESTFILES/tall.h5 87$SRC_TOOLS_TESTFILES/tintsattrs.h5 88" 89 90LIST_OTHER_TEST_FILES=" 91$SRC_H5IMPORT_TESTFILES/txtfp32.conf 92$SRC_H5IMPORT_TESTFILES/txtfp64.conf 93$SRC_H5IMPORT_TESTFILES/txtin8.conf 94$SRC_H5IMPORT_TESTFILES/txtin16.conf 95$SRC_H5IMPORT_TESTFILES/txtin32.conf 96$SRC_H5IMPORT_TESTFILES/txtuin16.conf 97$SRC_H5IMPORT_TESTFILES/txtuin32.conf 98$SRC_H5IMPORT_TESTFILES/textpfe.conf 99$SRC_H5IMPORT_TESTFILES/txtstr.conf 100$SRC_H5IMPORT_TESTFILES/txtfp32.txt 101$SRC_H5IMPORT_TESTFILES/txtfp64.txt 102$SRC_H5IMPORT_TESTFILES/txtuin16.txt 103$SRC_H5IMPORT_TESTFILES/txtuin32.txt 104$SRC_H5IMPORT_TESTFILES/txtin8.txt 105$SRC_H5IMPORT_TESTFILES/txtin16.txt 106$SRC_H5IMPORT_TESTFILES/txtin32.txt 107$SRC_H5IMPORT_TESTFILES/textpfe64.txt 108$SRC_H5IMPORT_TESTFILES/txtstr.txt 109$SRC_H5IMPORT_TESTFILES/dbinfp64.h5.txt 110$SRC_H5IMPORT_TESTFILES/dbinin8.h5.txt 111$SRC_H5IMPORT_TESTFILES/dbinin8w.h5.txt 112$SRC_H5IMPORT_TESTFILES/dbinin16.h5.txt 113$SRC_H5IMPORT_TESTFILES/dbinin32.h5.txt 114$SRC_H5IMPORT_TESTFILES/dbinuin16.h5.txt 115$SRC_H5IMPORT_TESTFILES/dbinuin32.h5.txt 116$SRC_H5IMPORT_TESTFILES/dtxtstr.h5.txt 117$SRC_H5IMPORT_TESTFILES/tall_fp32.ddl 118$SRC_H5IMPORT_TESTFILES/tall_i32.ddl 119$SRC_H5IMPORT_TESTFILES/tintsattrs_u32.ddl 120" 121 122# 123# copy test files and expected output files from source dirs to test dir 124# 125COPY_TESTFILES="$LIST_HDF5_TEST_FILES $LIST_OTHER_TEST_FILES" 126 127COPY_TESTFILES_TO_TESTDIR() 128{ 129 # copy test files. Used -f to make sure get a new copy 130 for tstfile in $COPY_TESTFILES 131 do 132 # ignore '#' comment 133 echo $tstfile | tr -d ' ' | grep '^#' > /dev/null 134 RET=$? 135 if [ $RET -eq 1 ]; then 136 # skip cp if srcdir is same as destdir 137 # this occurs when build/test performed in source dir and 138 # make cp fail 139 SDIR=`$DIRNAME $tstfile` 140 INODE_SDIR=`$LS -i -d $SDIR | $AWK -F' ' '{print $1}'` 141 INODE_DDIR=`$LS -i -d $TESTDIR | $AWK -F' ' '{print $1}'` 142 if [ "$INODE_SDIR" != "$INODE_DDIR" ]; then 143 $CP -f $tstfile $TESTDIR 144 if [ $? -ne 0 ]; then 145 echo "Error: FAILED to copy $tstfile ." 146 147 # Comment out this to CREATE expected file 148 exit $EXIT_FAILURE 149 fi 150 fi 151 fi 152 done 153} 154 155CLEAN_TESTFILES_AND_TESTDIR() 156{ 157 # skip rm if srcdir is same as destdir 158 # this occurs when build/test performed in source dir and 159 # make cp fail 160 SDIR=$SRC_H5IMPORT_TESTFILES 161 INODE_SDIR=`$LS -i -d $SDIR | $AWK -F' ' '{print $1}'` 162 INODE_DDIR=`$LS -i -d $TESTDIR | $AWK -F' ' '{print $1}'` 163 if [ "$INODE_SDIR" != "$INODE_DDIR" ]; then 164 $RM $TESTDIR 165 fi 166} 167 168# Print a line-line message left justified in a field of 70 characters 169# beginning with the word "Testing". 170# 171TESTING() { 172 SPACES=" " 173 echo "Testing $* $SPACES" | cut -c1-70 | tr -d '\012' 174} 175 176# Print a "SKIP" message 177SKIP() { 178 TESTING $TESTNAME $@ 179 echo " -SKIP-" 180} 181 182TOOLTEST() 183{ 184err=0 185$RUNSERIAL $H5IMPORT_BIN $* 186$RUNSERIAL $DUMPER_BIN $5 >log2 187 188cd tmp_testfiles 189$RUNSERIAL $DUMPER_BIN $5 >log1 190cd .. 191 192cmp -s tmp_testfiles/log1 log2 || err=1 193rm -f log2 tmp_testfiles/log1 194if [ $err -eq 1 ]; then 195nerrors="` expr $nerrors + 1 `"; 196 echo "*FAILED*" 197else 198 echo " PASSED" 199fi 200} 201 202# Use h5dump output as input to h5import for binary numbers 203# Use h5diff to verify results 204TOOLTEST2() 205{ 206err=0 207$RUNSERIAL $DUMPER_BIN -p -d $1 -o d$2.bin -b NATIVE tmp_testfiles/$2 > d$2.dmp 208$RUNSERIAL $H5IMPORT_BIN d$2.bin -c d$2.dmp -o d$2 > d$2.imp 209$RUNSERIAL $H5DIFF_BIN -v d$2 tmp_testfiles/$2 $1 $1 > log2 210$CP -f $SRC_H5IMPORT_TESTFILES/d$2.txt log1 211 212cmp -s log1 log2 || err=1 213rm -f log1 log2 214if [ $err -eq 1 ]; then 215nerrors="` expr $nerrors + 1 `"; 216 echo "*FAILED*" 217else 218 echo " PASSED" 219fi 220} 221 222# Same as TOOLTEST2 except for strings 223# Use h5dump output as input to h5import for strings 224# Use h5diff to verify results 225TOOLTEST3() 226{ 227err=0 228$RUNSERIAL $DUMPER_BIN -p -d $1 -o d$2.bin -y --width=1 tmp_testfiles/$2 > d$2.dmp 229$RUNSERIAL $H5IMPORT_BIN d$2.bin -c d$2.dmp -o d$2 > d$2.imp 230$RUNSERIAL $H5DIFF_BIN -v d$2 tmp_testfiles/$2 $1 $1 > log2 231$CP -f $SRC_H5IMPORT_TESTFILES/d$2.txt log1 232 233cmp -s log1 log2 || err=1 234rm -f log1 log2 235if [ $err -eq 1 ]; then 236nerrors="` expr $nerrors + 1 `"; 237 echo "*FAILED*" 238else 239 echo " PASSED" 240fi 241} 242 243# Same as TOOLTEST3 except for h5diff uses report mode without warnings 244# Use h5dump output as input to h5import for strings 245# Use h5diff to verify results 246TOOLTEST4() 247{ 248err=0 249$RUNSERIAL $DUMPER_BIN -p -d $1 -o d$2.bin -y --width=1 tmp_testfiles/$2 > d$2.dmp 250$RUNSERIAL $H5IMPORT_BIN d$2.bin -c d$2.dmp -o d$2 > d$2.imp 251$RUNSERIAL $H5DIFF_BIN -r d$2 tmp_testfiles/$2 $1 $1 > log2 252$CP -f $SRC_H5IMPORT_TESTFILES/d$2.txt log1 253 254 255cmp -s log1 log2 || err=1 256rm -f log1 log2 257if [ $err -eq 1 ]; then 258nerrors="` expr $nerrors + 1 `"; 259 echo "*FAILED*" 260else 261 echo " PASSED" 262fi 263} 264 265# Same as TOOLTEST2 except for subsets 266# Use h5dump output as input to h5import for binary numbers 267# Use h5dump to verify results 268TOOLTEST5() 269{ 270err=0 271$RUNSERIAL $DUMPER_BIN -p -d $3 $4 -o d-$1.bin -b NATIVE tmp_testfiles/$2 > d-$1.dmp 272$RUNSERIAL $H5IMPORT_BIN d-$1.bin -c d-$1.dmp -o d-$1.h5 > d-$1.imp 273$RUNSERIAL $DUMPER_BIN -p d-$1.h5 > log2 274$CP -f $SRC_H5IMPORT_TESTFILES/$1.ddl log1 275 276cmp -s log1 log2 || err=1 277rm -f log1 log2 278if [ $err -eq 1 ]; then 279nerrors="` expr $nerrors + 1 `"; 280 echo "*FAILED*" 281else 282 echo " PASSED" 283fi 284} 285 286echo "" 287echo "==============================" 288echo "H5IMPORT tests started" 289echo "==============================" 290 291#echo "** Testing h5import ***" 292 293rm -f output.h5 log1 tx* b* *.dat 294 295# prepare for test 296COPY_TESTFILES_TO_TESTDIR 297 298mkdir tmp_testfiles 299$CP $TESTDIR/*.h5 ./tmp_testfiles/ 300 301$RUNSERIAL ./h5importtest 302 303################################################ 304### T H E T E S T S 305################################################ 306 307TESTING "ASCII I32 rank 3 - Output BE " ; 308TOOLTEST $TESTDIR/txtin32.txt -c $TESTDIR/txtin32.conf -o txtin32.h5 309 310TESTING "ASCII I16 rank 3 - Output LE - CHUNKED - extended" 311TOOLTEST $TESTDIR/txtin16.txt -c $TESTDIR/txtin16.conf -o txtin16.h5 312 313TESTING "ASCII I8 - rank 3 - Output I8 LE-Chunked+Extended+Compressed " 314TOOLTEST $TESTDIR/txtin8.txt -c $TESTDIR/txtin8.conf -o txtin8.h5 315 316 317TESTING "ASCII UI16 - rank 2 - Output LE+Chunked+Compressed " 318TOOLTEST $TESTDIR/txtuin16.txt -c $TESTDIR/txtuin16.conf -o txtuin16.h5 319 320TESTING "ASCII UI32 - rank 3 - Output BE" 321TOOLTEST $TESTDIR/txtuin32.txt -c $TESTDIR/txtuin32.conf -o txtuin32.h5 322 323 324TESTING "ASCII F32 - rank 3 - Output LE " 325TOOLTEST $TESTDIR/txtfp32.txt -c $TESTDIR/txtfp32.conf -o txtfp32.h5 326 327TESTING "ASCII F64 - rank 3 - Output BE + CHUNKED+Extended+Compressed " 328TOOLTEST $TESTDIR/txtfp64.txt -c $TESTDIR/txtfp64.conf -o txtfp64.h5 329 330 331TESTING "BINARY F64 - rank 3 - Output LE+CHUNKED+Extended+Compressed " 332TOOLTEST binfp64.bin -c binfp64.conf -o binfp64.h5 333TESTING "H5DUMP-BINARY F64 - rank 3 - Output LE+CHUNKED+Extended+Compressed " 334if test $USE_FILTER_DEFLATE != "yes"; then 335 SKIP "/fp/bin/64-bit" binfp64.h5 336else 337 TOOLTEST2 "/fp/bin/64-bit" binfp64.h5 338fi 339 340 341TESTING "BINARY I8 - rank 3 - Output I16LE + Chunked+Extended+Compressed " 342TOOLTEST binin8.bin -c binin8.conf -o binin8.h5 343TESTING "H5DUMP-BINARY I8 - rank 3 - Output I16LE + Chunked+Extended+Compressed " 344if test $USE_FILTER_DEFLATE != "yes"; then 345 SKIP "/int/bin/8-bit" binin8.h5 346else 347 TOOLTEST2 "/int/bin/8-bit" binin8.h5 348fi 349 350TESTING "BINARY I16 - rank 3 - Output order LE + CHUNKED + extended " 351TOOLTEST binin16.bin -c binin16.conf -o binin16.h5 352TESTING "H5DUMP-BINARY I16 - rank 3 - Output order LE + CHUNKED + extended " 353TOOLTEST2 "/int/bin/16-bit" binin16.h5 354 355TESTING "BINARY I32 - rank 3 - Output BE + CHUNKED " 356TOOLTEST binin32.bin -c binin32.conf -o binin32.h5 357TESTING "H5DUMP-BINARY I32 - rank 3 - Output BE + CHUNKED " 358TOOLTEST2 "/int/bin/32-bit" binin32.h5 359 360 361TESTING "BINARY UI16 - rank 3 - Output byte BE + CHUNKED " 362TOOLTEST binuin16.bin -c binuin16.conf -o binuin16.h5 363TESTING "H5DUMP-BINARY UI16 - rank 3 - Output byte BE + CHUNKED " 364TOOLTEST2 "/int/buin/16-bit" binuin16.h5 365 366TESTING "BINARY UI32 - rank 3 - Output LE + CHUNKED " 367TOOLTEST binuin32.bin -c binuin32.conf -o binuin32.h5 368TESTING "H5DUMP-BINARY UI32 - rank 3 - Output LE + CHUNKED " 369TOOLTEST2 "/int/buin/32-bit" binuin32.h5 370 371 372TESTING "STR" 373TOOLTEST $TESTDIR/txtstr.txt -c $TESTDIR/txtstr.conf -o txtstr.h5 374TESTING "H5DUMP-STR" 375TOOLTEST4 "/mytext/data" txtstr.h5 376 377 378TESTING "BINARY I8 CR LF EOF" 379TOOLTEST binin8w.bin -c binin8w.conf -o binin8w.h5 380TESTING "H5DUMP-BINARY I8 CR LF EOF" 381TOOLTEST2 "/dataset0" binin8w.h5 382 383TESTING "ASCII F64 - rank 1 - INPUT-CLASS TEXTFPE " 384TOOLTEST $TESTDIR/textpfe64.txt -c $TESTDIR/textpfe.conf -o textpfe.h5 385 386TESTING "Binary Subset FP" 387TOOLTEST5 tall_fp32 tall.h5 "/g2/dset2.2" "--start=1,1 --stride=2,3 --count=1,2 --block=1,1" 388TESTING "Binary Subset INT" 389TOOLTEST5 tall_i32 tall.h5 "/g1/g1.1/dset1.1.1" "--start=1,1 --stride=2,3 --count=3,2 --block=1,1" 390TESTING "Binary Subset UINT" 391TOOLTEST5 tintsattrs_u32 tintsattrs.h5 "/DU32BITS" "--start=1,1 --stride=2,3 --count=3,2 --block=1,1" 392 393 394rm -f txtin32.txt txtin16.txt txtin8.txt txtuin32.txt txtuin16.txt *.bin *.dmp *.conf *.imp *.h5 395rm -rf tmp_testfiles 396 397# Clean up temporary files/directories 398CLEAN_TESTFILES_AND_TESTDIR 399 400# 401# Check errors result 402if test $nerrors -eq 0 ; then 403 echo "All $TESTNAME tests passed." 404 exit $EXIT_SUCCESS 405else 406 echo "$TESTNAME tests failed with $nerrors errors." 407 exit $EXIT_FAILURE 408fi 409