1#! /bin/sh 2# 3# Copyright by The HDF Group. 4# All rights reserved. 5# 6# This file is part of HDF5. The full HDF5 copyright notice, including 7# terms governing use, modification, and redistribution, is contained in 8# the COPYING file, which can be found at the root of the source code 9# distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. 10# If you do not have access to either file, you may request a copy from 11# help@hdfgroup.org. 12# 13srcdir=@srcdir@ 14TOP_BUILDDIR=@top_builddir@ 15 16# Determine backward compatibility options enabled 17DEPRECATED_SYMBOLS="@DEPRECATED_SYMBOLS@" 18 19EXIT_SUCCESS=0 20EXIT_FAILURE=1 21 22H5REPACK=../../src/h5repack/h5repack # The tool name 23H5REPACK_BIN=`pwd`/$H5REPACK # The path of the tool binary 24 25H5DUMP=../../src/h5dump/h5dump # The h5dump tool name 26H5DUMP_BIN=`pwd`/$H5DUMP # The path of the h5dump tool binary 27 28nerrors=0 29verbose=yes 30exit_code=$EXIT_SUCCESS 31 32TEST_NAME=ud_plugin 33FROM_DIR=`pwd`/.libs 34PLUGIN_LIB="$FROM_DIR/libdynlibadd.*" 35PLUGIN_LIB2="$FROM_DIR/libdynlibvers.*" 36PLUGIN_LIBDIR=testdir3 37RM='rm -rf' 38 39GREP='grep' 40CP='cp' 41DIRNAME='dirname' 42LS='ls' 43AWK='awk' 44 45# source dirs 46SRC_TOOLS="$srcdir/../.." 47 48# testfiles source dirs for tools 49SRC_H5REPACK_TESTFILES="$SRC_TOOLS/test/h5repack/testfiles" 50 51TESTDIR=testplug 52test -d $TESTDIR || mkdir $TESTDIR 53 54###################################################################### 55# test files 56# -------------------------------------------------------------------- 57# All the test files copy from source directory to test directory 58# NOTE: Keep this framework to add/remove test files. 59# Any test files from other tools can be used in this framework. 60# This list are also used for checking exist. 61# Comment '#' without space can be used. 62# -------------------------------------------------------------------- 63LIST_HDF5_TEST_FILES=" 64$SRC_H5REPACK_TESTFILES/h5repack_layout.h5 65$SRC_H5REPACK_TESTFILES/h5repack_layout.h5-plugin_test.ddl 66$SRC_H5REPACK_TESTFILES/plugin_test.h5repack_layout.h5.tst 67$SRC_H5REPACK_TESTFILES/h5repack_layout.h5-plugin_version_test.ddl 68$SRC_H5REPACK_TESTFILES/plugin_version_test.h5repack_layout.h5.tst 69" 70#$SRC_H5REPACK_TESTFILES/h5repack_layout.UD.h5 71#$SRC_H5REPACK_TESTFILES/h5repack_layout.UD.h5-plugin_none.ddl 72#$SRC_H5REPACK_TESTFILES/plugin_none.h5repack_layout.UD.h5.tst 73#" 74 75# 76# copy test files and expected output files from source dirs to test dir 77# 78COPY_TESTFILES="$LIST_HDF5_TEST_FILES" 79 80# Main Body 81# Create test directories if not exists yet. 82test -d $PLUGIN_LIBDIR || mkdir -p $PLUGIN_LIBDIR 83if [ $? != 0 ]; then 84 echo "Failed to create test directory($PLUGIN_LIBDIR)" 85 exit $EXIT_FAILURE 86fi 87 88# copy plugin library for test 89$CP $PLUGIN_LIB $PLUGIN_LIBDIR 90if [ $? != 0 ]; then 91 echo "Failed to copy plugin library ($PLUGIN_LIB) for test." 92 exit $EXIT_FAILURE 93fi 94$CP $PLUGIN_LIB2 $PLUGIN_LIBDIR 95if [ $? != 0 ]; then 96 echo "Failed to copy plugin library ($PLUGIN_LIB2) for test." 97 exit $EXIT_FAILURE 98fi 99 100# setup plugin path 101ENVCMD="env HDF5_PLUGIN_PATH=../${PLUGIN_LIBDIR}" 102 103COPY_TESTFILES_TO_TESTDIR() 104{ 105 # copy test files. Used -f to make sure get a new copy 106 for tstfile in $COPY_TESTFILES 107 do 108 # ignore '#' comment 109 echo $tstfile | tr -d ' ' | grep '^#' > /dev/null 110 RET=$? 111 if [ $RET -eq 1 ]; then 112 # skip cp if srcdir is same as destdir 113 # this occurs when build/test performed in source dir and 114 # make cp fail 115 SDIR=`$DIRNAME $tstfile` 116 INODE_SDIR=`$LS -i -d $SDIR | $AWK -F' ' '{print $1}'` 117 INODE_DDIR=`$LS -i -d $TESTDIR | $AWK -F' ' '{print $1}'` 118 if [ "$INODE_SDIR" != "$INODE_DDIR" ]; then 119 $CP -f $tstfile $TESTDIR 120 if [ $? -ne 0 ]; then 121 echo "Error: FAILED to copy $tstfile ." 122 123 # Comment out this to CREATE expected file 124 exit $EXIT_FAILURE 125 fi 126 fi 127 fi 128 done 129} 130 131CLEAN_TESTFILES_AND_TESTDIR() 132{ 133 # skip rm if srcdir is same as destdir 134 # this occurs when build/test performed in source dir and 135 # make cp fail 136 SDIR=$SRC_H5REPACK_TESTFILES 137 INODE_SDIR=`$LS -i -d $SDIR | $AWK -F' ' '{print $1}'` 138 INODE_DDIR=`$LS -i -d $TESTDIR | $AWK -F' ' '{print $1}'` 139 if [ "$INODE_SDIR" != "$INODE_DDIR" ]; then 140 $RM $TESTDIR 141 fi 142} 143 144# Print a $* message left justified in a field of 70 characters 145# 146MESSAGE() { 147 SPACES=" " 148 echo "$* $SPACES" | cut -c1-70 | tr -d '\012' 149} 150 151# Print a line-line message left justified in a field of 70 characters 152# beginning with the word "Testing". 153# 154TESTING() { 155 SPACES=" " 156 echo "Testing $* $SPACES" | cut -c1-70 | tr -d '\012' 157} 158 159# Print a line-line message left justified in a field of 70 characters 160# beginning with the word "Verifying". 161# 162VERIFY() { 163 MESSAGE "Verifying $*" 164} 165 166# This is different from $srcdir/../../../bin/output_filter.sh 167STDOUT_FILTER() { 168 result_file=$1 169 tmp_file=/tmp/h5test_tmp_$$ 170 # Filter name of files. 171 cp $result_file $tmp_file 172 sed -e '/^Opening file/d' -e '/^Making file/d' \ 173 < $tmp_file > $result_file 174 # cleanup 175 rm -f $tmp_file 176} 177 178# This runs h5repack comparing output with h5dump output 179# from -pH option 180# 181TOOLTEST_DUMP() 182{ 183 echo $@ 184 infile=$2 185 outfile=out-$1.$2 186 expect1="$TESTDIR/$1.$2.tst" 187 actual1="$TESTDIR/$1.$2.out" 188 actual1_err="$TESTDIR/$1.$2.err" 189 expect2="$TESTDIR/$2-$1.ddl" 190 actual2="$TESTDIR/$2-$1.out" 191 actual2_err="$TESTDIR/$2-$1.err" 192 193 shift 194 shift 195 196 # Run test. 197 TESTING $H5REPACK $@ 198 ( 199 cd $TESTDIR 200 $ENVCMD $H5REPACK_BIN "$@" $infile $outfile 201 ) >$actual1 2>$actual1_err 202 RET=$? 203 STDOUT_FILTER $actual1 204 cat $actual1_err >> $actual1 205 if [ $RET != 0 ] ; then 206 echo "*FAILED*" 207 nerrors="`expr $nerrors + 1`" 208 else 209 echo " PASSED" 210 if cmp -s $expect1 $actual1; then 211 echo " PASSED" 212 else 213 echo "*FAILED*" 214 echo " Expected result (*.tst) differs from actual result (*.out)" 215 nerrors="`expr $nerrors + 1`" 216 test yes = "$verbose" && diff -c $expect1 $actual1 |sed 's/^/ /' 217 fi 218 VERIFY h5dump output -pH $outfile 219 ( 220 cd $TESTDIR 221 $ENVCMD $H5DUMP_BIN -pH $outfile 222 ) >$actual2 2>$actual2_err 223 RET=$? 224 cat $actual2_err >> $actual2 225 226 if cmp -s $expect2 $actual2; then 227 echo " PASSED" 228 else 229 echo "*FAILED*" 230 echo " Expected result (*.ddl) differs from actual result (*.out)" 231 nerrors="`expr $nerrors + 1`" 232 test yes = "$verbose" && diff -c $expect2 $actual2 |sed 's/^/ /' 233 fi 234 235 fi 236 237 238 rm -f $actual1 $actual1_err $actual2 $actual2_err 239 rm -f $outfile 240} 241 242############################################################################## 243### T H E T E S T S 244############################################################################## 245# prepare for test 246COPY_TESTFILES_TO_TESTDIR 247version_str=`echo @H5_VERSION@ | awk -F"-" '{print $1}' | sed 's/\./,/g'` 248 249# Run the test 250arg="h5repack_layout.h5 -v -f UD=260,0,4,9,$version_str" 251TOOLTEST_DUMP plugin_version_test $arg 252 253arg="h5repack_layout.h5 -v -f UD=257,0,1,9" 254TOOLTEST_DUMP plugin_test $arg 255 256#arg="h5repack_layout.UD.h5 -v -f NONE" 257#TOOLTEST_DUMP plugin_none $arg 258 259# print results 260if test $nerrors -ne 0 ; then 261 echo "$nerrors errors encountered" 262 exit_code=$EXIT_FAILURE 263else 264 echo "All Plugin API tests passed." 265 exit_code=$EXIT_SUCCESS 266fi 267 268# Clean up temporary files/directories 269CLEAN_TESTFILES_AND_TESTDIR 270 271# Clean up temporary files/directories and leave 272$RM $PLUGIN_LIBDIR 273 274exit $exit_code 275