| 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 files COPYING and Copyright.html. COPYING can be found at the root |
| 10 |
# of the source code distribution tree; Copyright.html can be found at the |
| 11 |
# root level of an installed copy of the electronic HDF5 document set and |
| 12 |
# is linked from the top-level documents page. It can also be found at |
| 13 |
# http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have |
| 14 |
# access to either file, you may request a copy from [email protected]. |
| 15 |
|
| 16 |
srcdir=@srcdir@ |
| 17 |
builddir=@builddir@ |
| 18 |
verbose=yes |
| 19 |
nerrors=0 |
| 20 |
|
| 21 |
# HDF5 compile commands, assuming they are in your $PATH. |
| 22 |
H5CC=@H5CC@ |
| 23 |
|
| 24 |
case $H5CC in |
| 25 |
*/*) H5DUMP=`echo $H5CC | sed -e 's/\/[^/]*$/\/h5dump/'`; |
| 26 |
test -x $H5DUMP || H5DUMP=h5dump; |
| 27 |
H5REPACK=`echo $H5CC | sed -e 's/\/[^/]*$/\/h5repack/'`; |
| 28 |
test -x $H5REPACK || H5REPACK=h5repack;; |
| 29 |
*) H5DUMP=h5dump; |
| 30 |
H5REPACK=h5repack;; |
| 31 |
esac |
| 32 |
|
| 33 |
# Shell commands used in Makefiles |
| 34 |
RM="rm -rf" |
| 35 |
DIFF="diff -c" |
| 36 |
CMP="cmp -s" |
| 37 |
GREP='grep' |
| 38 |
CP='cp' |
| 39 |
DIRNAME='dirname' |
| 40 |
LS='ls' |
| 41 |
AWK='awk' |
| 42 |
|
| 43 |
ENVCMD="env HDF5_PLUGIN_PATH=`pwd`/../src/.libs" |
| 44 |
|
| 45 |
TESTDIR=$builddir |
| 46 |
SRC_TESTFILES="$srcdir/testfiles" |
| 47 |
LIST_TEST_FILES=" |
| 48 |
$SRC_TESTFILES/h5repack_layout.h5 |
| 49 |
$SRC_TESTFILES/h5ex_d_lz4.ddl |
| 50 |
$SRC_TESTFILES/h5ex_d_lz4.tst |
| 51 |
$SRC_TESTFILES/h5repack_layout.h5-ud_convert.ddl |
| 52 |
$SRC_TESTFILES/ud_convert.h5repack_layout.h5.tst |
| 53 |
" |
| 54 |
|
| 55 |
# |
| 56 |
# copy test files and expected output files from source dirs to test dir |
| 57 |
# |
| 58 |
COPY_TESTFILES="$LIST_TEST_FILES" |
| 59 |
|
| 60 |
COPY_TESTFILES_TO_TESTDIR() |
| 61 |
{ |
| 62 |
# copy test files. Used -f to make sure get a new copy |
| 63 |
for tstfile in $COPY_TESTFILES |
| 64 |
do |
| 65 |
# ignore '#' comment |
| 66 |
echo $tstfile | tr -d ' ' | grep '^#' > /dev/null |
| 67 |
RET=$? |
| 68 |
if [ $RET -eq 1 ]; then |
| 69 |
# skip cp if srcdir is same as destdir |
| 70 |
# this occurs when build/test performed in source dir and |
| 71 |
# make cp fail |
| 72 |
SDIR=`$DIRNAME $tstfile` |
| 73 |
INODE_SDIR=`$LS -i -d $SDIR | $AWK -F' ' '{print $1}'` |
| 74 |
INODE_DDIR=`$LS -i -d $TESTDIR | $AWK -F' ' '{print $1}'` |
| 75 |
if [ "$INODE_SDIR" != "$INODE_DDIR" ]; then |
| 76 |
$CP -f $tstfile $TESTDIR |
| 77 |
if [ $? -ne 0 ]; then |
| 78 |
echo "Error: FAILED to copy $tstfile ." |
| 79 |
|
| 80 |
# Comment out this to CREATE expected file |
| 81 |
exit $EXIT_FAILURE |
| 82 |
fi |
| 83 |
fi |
| 84 |
fi |
| 85 |
done |
| 86 |
} |
| 87 |
|
| 88 |
# Print a $* message left justified in a field of 70 characters |
| 89 |
# |
| 90 |
MESSAGE() { |
| 91 |
SPACES=" " |
| 92 |
echo "$* $SPACES" | cut -c1-70 | tr -d '\012' |
| 93 |
} |
| 94 |
|
| 95 |
# Print a line-line message left justified in a field of 70 characters |
| 96 |
# beginning with the word "Testing". |
| 97 |
# |
| 98 |
TESTING() { |
| 99 |
SPACES=" " |
| 100 |
echo "Testing $* $SPACES" | cut -c1-70 | tr -d '\012' |
| 101 |
} |
| 102 |
|
| 103 |
# Print a line-line message left justified in a field of 70 characters |
| 104 |
# beginning with the word "Verifying". |
| 105 |
# |
| 106 |
VERIFY() { |
| 107 |
MESSAGE "Verifying $*" |
| 108 |
} |
| 109 |
|
| 110 |
# This is different from $srcdir/../../bin/output_filter.sh |
| 111 |
STDOUT_FILTER() { |
| 112 |
result_file=$1 |
| 113 |
tmp_file=/tmp/h5test_tmp_$$ |
| 114 |
# Filter name of files. |
| 115 |
cp $result_file $tmp_file |
| 116 |
sed -e '/^Opening file/d' -e '/^Making file/d' \ |
| 117 |
< $tmp_file > $result_file |
| 118 |
# cleanup |
| 119 |
rm -f $tmp_file |
| 120 |
} |
| 121 |
|
| 122 |
# Compare the two text files |
| 123 |
# PASS if same |
| 124 |
# FAIL if different, and show the diff |
| 125 |
# |
| 126 |
# Assumed arguments: |
| 127 |
# $1 is text file1 (expected output) |
| 128 |
# $2 is text file2 (actual output) |
| 129 |
CMP_OUTPUT() |
| 130 |
{ |
| 131 |
expect=$1 |
| 132 |
actual=$2 |
| 133 |
|
| 134 |
VERIFY $@ |
| 135 |
if [ ! -f $expect ]; then |
| 136 |
# Create the expect file if it doesn't yet exist. |
| 137 |
echo " CREATED" |
| 138 |
cp $actual "$expect.new" |
| 139 |
elif $CMP $expect $actual; then |
| 140 |
echo " PASSED" |
| 141 |
else |
| 142 |
echo "*FAILED*" |
| 143 |
echo " Expected output differs from actual output" |
| 144 |
nerrors="`expr $nerrors + 1`" |
| 145 |
test yes = "$verbose" && $DIFF $expect $actual |sed 's/^/ /' |
| 146 |
fi |
| 147 |
} |
| 148 |
|
| 149 |
|
| 150 |
# Run a test and print PASS or *FAIL*. If a test fails then increment |
| 151 |
# the `nerrors' global variable and (if $verbose is set) display the |
| 152 |
# difference between the actual output and the expected output. The |
| 153 |
# expected output is given as the first argument to this function and |
| 154 |
# the actual output file is calculated by replacing the `.ddl' with |
| 155 |
# `.out'. The actual output is not removed if $HDF5_NOCLEANUP has a |
| 156 |
# non-zero value. |
| 157 |
# ADD_H5_TEST |
| 158 |
DUMPTEST() { |
| 159 |
expect="$1" |
| 160 |
actual="`basename $1 .ddl`.out" |
| 161 |
actual_err="`basename $1 .ddl`.err" |
| 162 |
shift |
| 163 |
|
| 164 |
# Run test. |
| 165 |
TESTING $DUMPER $@ |
| 166 |
( |
| 167 |
$ENVCMD $H5DUMP "$@" |
| 168 |
) >$actual 2>$actual_err |
| 169 |
cat $actual_err >> $actual |
| 170 |
|
| 171 |
CMP_OUTPUT $expect $actual |
| 172 |
|
| 173 |
# Clean up output file |
| 174 |
# rm -f $actual $actual_err |
| 175 |
|
| 176 |
} |
| 177 |
|
| 178 |
REPACKTEST() |
| 179 |
{ |
| 180 |
infile=$1 |
| 181 |
outfile=$2 |
| 182 |
expect="$2.tst" |
| 183 |
actual="$2.out1" |
| 184 |
actual_err="$2.err1" |
| 185 |
shift |
| 186 |
shift |
| 187 |
|
| 188 |
# Run test. |
| 189 |
TESTING $H5REPACK $@ |
| 190 |
( |
| 191 |
$ENVCMD $H5REPACK "$@" $infile $outfile |
| 192 |
) >$actual 2>$actual_err |
| 193 |
RET=$? |
| 194 |
STDOUT_FILTER $actual |
| 195 |
cat $actual_err >> $actual |
| 196 |
|
| 197 |
if [ $RET != 0 ] ; then |
| 198 |
echo "*FAILED*" |
| 199 |
nerrors="`expr $nerrors + 1`" |
| 200 |
else |
| 201 |
echo " PASSED" |
| 202 |
|
| 203 |
CMP_OUTPUT $expect $actual |
| 204 |
fi |
| 205 |
# rm -f $actual $actual_err |
| 206 |
} |
| 207 |
|
| 208 |
|
| 209 |
EXETEST() { |
| 210 |
fname=$1 |
| 211 |
expect="$2" |
| 212 |
actual="`basename $2 .tst`.out1" |
| 213 |
actual_err="`basename $2 .tst`.err1" |
| 214 |
|
| 215 |
# Run test. |
| 216 |
TESTING $fname |
| 217 |
( |
| 218 |
$ENVCMD ./$fname |
| 219 |
) >$actual 2>$actual_err |
| 220 |
cat $actual_err >> $actual |
| 221 |
|
| 222 |
CMP_OUTPUT $expect $actual |
| 223 |
# rm -f $actual $actual_err |
| 224 |
} |
| 225 |
|
| 226 |
################################ |
| 227 |
######### THE TESTS ######### |
| 228 |
################################ |
| 229 |
|
| 230 |
COPY_TESTFILES_TO_TESTDIR |
| 231 |
|
| 232 |
EXETEST h5ex_d_lz4 h5ex_d_lz4.tst |
| 233 |
|
| 234 |
DUMPTEST h5ex_d_lz4.ddl h5ex_d_lz4.h5 |
| 235 |
|
| 236 |
REPACKTEST h5repack_layout.h5 out-ud_convert.h5repack_layout.h5 -v -f UD=307,1,9 |
| 237 |
|
| 238 |
DUMPTEST h5repack_layout.h5-ud_convert.ddl -pH out-ud_convert.h5repack_layout.h5 |
| 239 |
|
| 240 |
#rm -f ud_convert.h5repack_layout.h5 |
| 241 |
|
| 242 |
echo "$nerrors tests failed in example" |
| 243 |
exit $nerrors |