summaryrefslogtreecommitdiffstats
path: root/tools/misc/testh5clear.sh.in
blob: 8c98fedcf982302a392d692ffa9141decc832be4 (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
#! /bin/sh
#
# Copyright by The HDF Group.
# Copyright by the Board of Trustees of the University of Illinois.
# 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 files COPYING and Copyright.html.  COPYING can be found at the root
# of the source code distribution tree; Copyright.html can be found at the
# root level of an installed copy of the electronic HDF5 document set and
# is linked from the top-level documents page.  It can also be found at
# http://hdfgroup.org/HDF5/doc/Copyright.html.  If you do not have
# access to either file, you may request a copy from help@hdfgroup.org.
#
# Tests for the h5clear tool
#
srcdir=@srcdir@
TESTNAME=h5clear
EXIT_SUCCESS=0
EXIT_FAILURE=1

H5CLEAR=h5clear
H5CLEAR_BIN=`pwd`/$H5CLEAR    	# The path of the tool binary

GENTEST=h5clear_gentest         # Generate test files
GENTEST_BIN=`pwd`/$GENTEST	# The path to the binary

OPENCHK=clear_open_chk		# Try opening the test file
OPENCHK_BIN=`pwd`/$OPENCHK	# The path to the binary

SUCCEED=0
FAIL=1

nerrors=0
verbose=yes

test -d ../testfiles || mkdir ../testfiles

# 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'
}

# Algorithm:
#	Try to open the test file--should fail
#	Use "h5clear" to clear the status_flags in the test file
#	Try to open the test file again--should succeed
# $1 is the filename to H5Fopen() via h5clear
TOOLTEST() {
    TESTING $H5CLEAR $1
    fname=$1
    #
    # Try to open the test file
    $OPENCHK_BIN $fname
    if test $? -eq $SUCCEED; then
       echo ".....$OPENCHK: should fail"
       nerrors=`expr $nerrors + 1`
    else
	# Run h5clear to clear the status_flags in the test file
	$RUNSERIAL $H5CLEAR_BIN $fname
	if test $? -ne $SUCCEED; then
	    echo ".....$H5CLEAR: should succeed"
	    nerrors=`expr $nerrors + 1`
	else
	    # Try to open the test file again
	    $OPENCHK_BIN $fname
	    if test $? -ne $SUCCEED; then
		echo "......$OPENCHK: should succeed"
		nerrors=`expr $nerrors + 1`
	    else
		echo "PASSED"
	    fi
	fi
    fi
}

# The input file has an incorrect superblock version #
# Algorithm:
#	Use "h5clear" to clear status_flags in the test file--should fail not able to open the file
# $1 is the filename to H5Fopen() via h5clear
TOOLFAIL() {
    TESTING $H5CLEAR $1
    fname=$1
    # Run h5clear to clear the status_flags in the test file
    $RUNSERIAL $H5CLEAR_BIN $fname
    if test $? -eq $SUCCEED; then
	echo ".....$H5CLEAR: should fail"
	nerrors=`expr $nerrors + 1`
    else
	echo "PASSED"
    fi
}
##############################################################################
##############################################################################
###			  T H E   T E S T S                                ###
##############################################################################
##############################################################################
#
$GENTEST_BIN				# Create HDF5 test files
if test $? -ne 0; then			# Error returned from generating test files
    echo "$GENTEST: .....fail in generating test files"
    nerrors=`expr $nerrors + 1`
else
    TOOLTEST h5clear_sec2.h5
    TOOLTEST h5clear_core.h5 
    TOOLTEST h5clear_fam_%05d.h5
    TOOLTEST h5clear_split
#
# files created with latest library format
    TOOLTEST latest_h5clear_sec2.h5
    TOOLTEST latest_h5clear_core.h5
    TOOLTEST latest_h5clear_fam_%05d.h5
    TOOLTEST latest_h5clear_split
#
# files created with incorrect superblock version #
TOOLFAIL h5clear_invalid.h5
TOOLFAIL latest_h5clear_invalid.h5
fi
#
# Clean up test files
if test -z "$HDF5_NOCLEANUP"; then
   rm -f h5clear_*.h5 latest_h5clear*.h5
fi

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