summaryrefslogtreecommitdiffstats
path: root/utils/tools/test/h5dwalk/testh5dwalk.sh.in
blob: 4f6dbdee3ac1a2298b845bda1e0073f24c312296 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
#! /bin/sh
#
# Copyright by The HDF Group.
# All rights reserved.
#
# This file is part of HDF5.  The full HDF5 copyright notice, including
# terms governing use, modification, and redistribution, is contained in
# the COPYING file, which can be found at the root of the source code
# distribution tree, or in https://www.hdfgroup.org/licenses.
# If you do not have access to either file, you may request a copy from
# help@hdfgroup.org.
#

# Tests for the h5dwalk tool

#
#

srcdir=@srcdir@

# Determine which filters are available
USE_FILTER_SZIP="@USE_FILTER_SZIP@"
USE_FILTER_DEFLATE="@USE_FILTER_DEFLATE@"


TESTNAME=h5dwalk

EXIT_SUCCESS=0
EXIT_FAILURE=1

THIS_DIR="`pwd`"
ROOTDIR="`cd ../../../..; pwd`"
cd "$THIS_DIR"
TOP_DIR="$ROOTDIR"


H5DWALK=../../h5dwalk/h5dwalk
H5DWALK_BIN="$TOP_DIR/utils/tools/h5dwalk/h5dwalk"


H5DUMP="$TOP_DIR/src/h5dump/h5dump"
H5DUMP_BIN="$TOP_DIR/tools/src/h5dump/h5dump"

RM='rm -rf'
CMP='cmp -s'
DIFF='diff -c'
CP='cp'
DIRNAME='dirname'
LS='ls'
AWK='awk'
WC='wc'

nerrors=0
verbose=yes

export LD_LIBRARY_PATH=@LL_PATH@

# source dirs
SRC_TOOLS="$TOP_DIR/tools/test"
SRC_TOOLS_TESTFILES="$SRC_TOOLS/testfiles"

# testfiles source dirs for tools
SRC_H5LS_TESTFILES="$SRC_TOOLS_TESTFILES"
SRC_H5DUMP_TESTFILES="$SRC_TOOLS_TESTFILES"
SRC_H5DIFF_TESTFILES="$SRC_TOOLS/h5diff/testfiles"
SRC_H5COPY_TESTFILES="$SRC_TOOLS/h5copy/testfiles"
SRC_H5REPACK_TESTFILES="$SRC_TOOLS/h5repack/testfiles"
SRC_H5JAM_TESTFILES="$SRC_TOOLS/h5jam/testfiles"
SRC_H5DWALK_TESTFILES="$SRC_TOOLS/h5dwalk/testfiles"
SRC_H5IMPORT_TESTFILES="$SRC_TOOLS/h5import/testfiles"

TESTDIR=./testfiles
test -d $TESTDIR || mkdir $TESTDIR

echo "SRC_H5DIFF_TESTFILES = $SRC_H5DIFF_TESTFILES"
echo "Creating demo files"
. ./copy_demo_files.sh



CLEAN_TESTFILES_AND_TESTDIR()
{
    echo "cleaning logfiles"
    $RM $TESTDIR/*log*
}

# Print a line-line message left justified in a field of 70 characters
# beginning with the word "Testing".
#
TESTING() {
   SPACES="                                                               "
   echo "Testing $* $SPACES" | cut -c1-70 | tr -d '\012'
}

# Run a test and print PASS or *FAIL*.  If a test fails then increment
# the `nerrors' global variable and (if $verbose is set) display the
# difference between the actual output and the expected output. The
# expected output is given as the first argument to this function and
# the actual output file is calculated by replacing the `.ddl' with
# `.out'.  The actual output is not removed if $HDF5_NOCLEANUP has a
# non-zero value.
#
TOOLTEST() {
   expect="$TESTDIR/$1"
   expect_err="$TESTDIR/`basename $1`.err"
   actual="$TESTDIR/`basename $1`.out"
   actual_err="$TESTDIR/`basename $1`.out.err"
   actual_sav=${actual}-sav
   actual_err_sav=${actual_err}-sav
   shift

   # Run test.

   TESTING $H5DWALK $@
   (
      cd $TESTDIR
      $RUNSERIAL $H5DWALK_BIN $@
   ) 1> $actual 2> $actual_err

   # save actual and actual_err in case they are needed later.
   cp $actual $actual_sav
   cp $actual_err $actual_err_sav

   if [ ! -f $expect ]; then
      # Compare error files if the expect file doesn't exist.
      if $CMP $expect_err $actual_err; then
         echo " PASSED"
      else
         echo "*FAILED*"
         echo "    Expected result (*.err) differs from actual result (*.out.err)"
         nerrors="`expr $nerrors + 1`"
         test yes = "$verbose" && $DIFF $expect_err $actual_err |sed 's/^/    /'
      fi
   elif $CMP $expect $actual; then
      echo " PASSED"
   else
      echo "*FAILED*"
      echo "    Expected result (*.ddl) differs from actual result (*.out)"
      nerrors="`expr $nerrors + 1`"
      test yes = "$verbose" && $DIFF $expect $actual |sed 's/^/    /'
   fi

   # Clean up output file
   if test -z "$HDF5_NOCLEANUP"; then
      rm -f $actual $actual_err $actual_sav $actual_err_sav
   fi
}

TOOL_LOGTEST() {
   expect="$TESTDIR/`basename $1`.txt"
   expect_err="$TESTDIR/`basename $1`.err"
   actual="$TESTDIR/`basename $1`.log"
   actual_err="$TESTDIR/`basename $1`.out.err"
   actual_sav=${actual}-sav
   actual_err_sav=${actual_err}-sav
   shift

   echo "running logtest"

   # Run test.
   TESTING $H5DWALK $@
   (
      cd $TESTDIR
      $RUNSERIAL $H5DWALK_BIN $@

   ) 1> $actual 2> $actual_err
   expect_len="`wc -l < $expect`"

   if [ ! -f $actual ]; then
      echo "*FAILED*"
      echo "    The expected .log file is missing"
      echo "    Perhaps the test failed to run?"
   else
      actual_len="`wc -l < $actual`"
      if [ $actual_len -eq $expect_len ]; then
         echo " PASSED"
      else
         echo "*FAILED*"
         echo "    The generated .log file length does not match the expected length.  $actual_len != $expected_len"
      fi
   fi

   # Clean up output file
   if test -z "$HDF5_NOCLEANUP"; then
      rm -f $actual $actual_err $actual_sav $actual_err_sav
   fi
}

TOOL_CHK_LOGLEN() {
   expect=$1
   shift

   echo "running tool_chk_loglen"

   # Run test.
   TESTING $H5DWALK $@
   (
      cd $TESTDIR
      $RUNSERIAL $H5DWALK_BIN $@
   )
	   
   expect_len="`wc -l < $expect`"
   if [ "$expect_len" -gt 0 ]; then
	   echo " PASSED"
   else
       echo "*FAILED*"
       echo "    The generated .log file is empty!."
   fi

   # Clean up output file
   if test -z "$HDF5_NOCLEANUP"; then
      rm -f $expect
   fi
}


# Print a "SKIP" message
SKIP() {
    TESTING $H5DWALK $@6
    echo  " -SKIP-"
}



##############################################################################
##############################################################################
###              T H E   T E S T S                                ###
##############################################################################
##############################################################################

TOOLTEST help-1.txt -h
TOOLTEST help-2.txt --help
TOOL_LOGTEST h5diff_basic1.h5_h5dump -l -T $H5DUMP_BIN -n ./h5diff_basic1.h5
TOOL_CHK_LOGLEN showme-h5dump.log -o `pwd`/showme-h5dump.log -T $H5DUMP_BIN -n `pwd`


#
#
# Clean up temporary files/directories
CLEAN_TESTFILES_AND_TESTDIR

if test $nerrors -eq 0 ; then
    echo "All $TESTNAME tests passed."
    exit $EXIT_SUCCESS
else
    echo "$TESTNAME tests failed with $nerrors errors."
    exit $EXIT_FAILURE
fi