summaryrefslogtreecommitdiffstats
path: root/tools/testh5toh4
blob: e78c4fba9c5ce6e757edbf9f6b49d97cc15d9c20 (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
250
251
252
253
254
255
256
257
258
259
260
261
262
#! /bin/sh
# Test scripts for h5toh4.
# See the USAGE function for command usage.


# Definitions of commands and variables
CMD='../h5toh4'
RM='rm -f'
SED='sed '
H4DUMP='hdp'
DIFF=diff
CMP='cmp -s'
nerrors=0		# number of errors (0)
quitonerr=0		# quit on error (not)
noclean=0		# no cleaning temp. files (yes)
only=""			# dumper sub-command to test only
except=""		# dumper sub-command to test not


# Definitions of functions/shorthands
#

# Print Usage of the command
USAGE()
{
    echo "Usage: $0 [-help] [-noclean] [-quit] [-except <command>] [-only <command>]"
    echo "    -help: display help information"
    echo "    -noclean: do not clean away temporary files"
    echo "    -quit: quit immediately if any test fails"
    echo "    -except: skip one specific command"
    echo "    -only: test one specific command"
    echo "<command> can be one of {list, dumpsds, dumprig, dumpvd, dumpvg, dumpgr}"
}

# Print message with formats according to message level ($1)
MESG()
{
    level=$1
    shift
    case $level in
	0)
	    echo '============================='
	    echo $*
	    echo '============================='
	    ;;
	3)
	    echo '-----------------------------'
	    echo $*
	    echo '-----------------------------'
	    ;;
	6)
	    echo "*** Arguments are $* ***"
	    ;;
	*)
		echo "MESG(): Unknown level ($level)"
	    exit 1
	    ;;
    esac

}


# Run the test to produce an output file which is then
# compared with the expected ($1) output.
# Note that this can be used to produce the expected
# output files by replace "$output" with "$expected"
# in the run-the-test commands.
TEST()
{
    # shift
    # print a id banner
    MESG 6 $@
    # run the test
    ( 
		echo "#############################"
		echo "'$CMD $@'" 
		echo "#############################"
		cd testfiles
        $CMD "$@"
		cd ..
    ) 

	case "$1" in

    "-m")

		shift
		for i in $@
		do
			h4file=testfiles/`echo $i | $SED -e s/\.h5/.hdf/g`

		    	output=`echo $h4file | $SED -e s/\.hdf/.tmp/`
		    	expected=`echo $h4file | $SED -e s/\.hdf/.dmp/`

			$H4DUMP dumpvg $h4file > $output

			$H4DUMP dumpvd $h4file >> $output

			$H4DUMP dumpsds $h4file >> $output


    		$CMP $expected $output
    		if [ $? -ne 0 ]
    		then
				echo $DIFF $expected $output
				$DIFF $expected $output
				echo "   <<< FAILED >>>"
				nerrors=`expr $nerrors + 1`
				if [ $quitonerr -gt 0 ]; 
				then
	    			FINISH
				fi
    		fi

		done

		;;


    * )

   		if [ $# -eq 1 ]
		then 
			h4file=testfiles/`echo $1 | $SED -e s/\.h5/.hdf/`
		else
			h4file=testfiles/$2
		fi

	    output=`echo $h4file | $SED -e s/\.hdf/.tmp/`
	    expected=`echo $h4file | $SED -e s/\.hdf/.dmp/`

		$H4DUMP dumpvg $h4file > $output

		$H4DUMP dumpvd $h4file >> $output

		$H4DUMP dumpsds $h4file >> $output

    	$CMP $expected $output
    	if [ $? -ne 0 ]
    	then
			echo $DIFF $expected $output
			$DIFF $expected $output
			echo "   <<< FAILED >>>"
			nerrors=`expr $nerrors + 1`
			if [ $quitonerr -gt 0 ]; 
			then
	    		FINISH
			fi
    	fi

		;;
    esac

}


# Report the result and exit
FINISH()
{
    if [ $nerrors -eq 0 ]
    then
	MESG 0 "All h5toh4 tests passed"
    else
	MESG 0 "h5toh4 tests failed: $nerrors"
    fi
    exit $nerrors
}


#===============
# Main Body
#===============

# parse arguments
while [ $# -gt 0 ]
do
    case "$1" in
	"-quit")
	    quitonerr=1
	    ;;
	"-noclean")
	    noclean=1
	    ;;
	"-help")
	    USAGE
	    exit 0
	    ;;
	"-only")
	    shift
	    case "$1" in
    		"h5toh4")
		    only="$1"
		    ;;
		*)
		    echo "Unknown command: $1"
		    USAGE
		    exit 1
		    ;;
	    esac
	    ;;
	"-except")
	    shift
	    case "$1" in
    		"h5toh4")
		    except="$1"
		    ;;
		*)
		    echo "Unknown command: $1"
		    USAGE
		    exit 1
		    ;;
	    esac
	    ;;
	* )
	    echo "Unknow option: $1"
	    USAGE
	    exit 1
	    ;;
    esac
    shift
done

# Print a beginning banner
MESG 0 "Running h5toh4 tests"

# Test command list
TestCmd=h5toh4
TestName="Test command $TestCmd"
if [ "$except" != $TestCmd -a \( -z "$only" -o "$only" = $TestCmd \) ]
then
MESG 3 "$TestName"
$RM ./testfiles/*.hdf ./testfiles/*.tmp
TEST tgroup.h5
TEST tdset.h5
TEST tattr.h5
TEST tslink.h5
TEST thlink.h5
TEST tall.h5
TEST tdset2.h5
TEST tcompound2.h5
TEST tmany.h5
$RM ./testfiles/*.tmp
TEST tgroup.h5 tgroup.hdf
TEST tdset.h5 tdset.hdf
TEST tattr.h5 tattr.hdf
TEST tslink.h5 tslink.hdf
TEST thlink.h5 thlink.hdf
TEST tcompound.h5 tcompound.hdf
TEST tall.h5 tall.hdf
TEST tdset2.h5 tdset2.hdf
TEST tcompound2.h5 tcompound2.hdf
TEST tmany.h5 tmany.hdf
$RM ./testfiles/*.hdf ./testfiles/*.tmp
TEST -m tgroup.h5 tdset.h5 tattr.h5 tslink.h5 thlink.h5 tcompound.h5 tall.h5
TEST -m tdset2.h5 tcompound2.h5 tmany.h5
$RM ./testfiles/*.hdf ./testfiles/*.tmp
else
MESG 3 "$TestName <<<SKIPPED>>>"
fi

# End of test
FINISH