summaryrefslogtreecommitdiffstats
path: root/test/test_usecases.sh.in
blob: 3f7d5f1ee5e569abd57449a6fb2b7f23f7bfcdee (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
#! /bin/bash
#
# 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 the use cases of swmr features.
#
# Created:
#   Albert Cheng, 2013/06/01.
# Modified:
#

# This is work in progress.
# For now, it shows how to run the test cases programs. It only verifies the
# exit codes are okay (0).

###############################################################################
## test variables
###############################################################################

# Number of errors encountered during test run.
nerrors=0

# Define variables
verbose=yes

###############################################################################
## Main
###############################################################################
srcdir=@srcdir@
bindir=@bindir@
testdir=@testdir@

# The build (current) directory might be different than the source directory.
if test -z "$srcdir"; then
   srcdir=.
fi

# If the bindir directory is not set just use current (.).
if test -z "$bindir"; then
   bindir=.
fi

# If the testdir directory is not set just use current (.).
if test -z "$testdir"; then
   testdir=.
fi

# Check to see if the VFD specified by the HDF5_DRIVER environment variable
# supports SWMR.
$bindir/swmr_check_compat_vfd
rc=$?
if [[ $rc != 0 ]] ; then
    echo
    echo "The VFD specified by the HDF5_DRIVER environment variable"
    echo "does not support SWMR"
    echo
    echo "SWMR use case tests skipped"
    echo
    exit 0
fi

# Define symbols
EXIT_SUCCESS=0
EXIT_FAILURE=1
EXIT_VALUE=$EXIT_SUCCESS    # Default all tests succeed
RESULT_PASSED=" PASSED"
RESULT_FAILED="*FAILED*"
RESULT_SKIP="-SKIP-"
USECASES_PROGRAMS="use_append_chunk use_append_mchunks"
TESTNAME="Use Case"

# Source in the output filter function definitions.
. $srcdir/../bin/output_filter.sh

# Define functions
# Print a line-line message left justified in a field of 72 characters.
# Results can be " PASSED", "*FAILED*", "-SKIP-", up to 8 characters
# wide.
# SPACES should be at least 71 spaces. ($* + ' ' + 71 + 8 >= 80)
#
TESTING() {
   SPACES="                                                                        "
   echo "$* $SPACES" | cut -c1-72 | 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.
# ADD_H5_TEST
TOOLTEST() {
    program=$1
    shift

    actual="$program.out"
    actual_err="$program.err"
    actual_sav=${actual}-sav
    actual_err_sav=${actual_err}-sav

    # Run test.
    TESTING $program $@
    (
      $RUNSERIAL $testdir/$program "$@"
    ) >$actual 2>$actual_err
    exit_code=$?

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

    if [ $exit_code -eq 0 ];then
    echo "$RESULT_PASSED"
    test yes = "$verbose" && sed 's/^/    /' < $actual
    else
    echo "$RESULT_FAILED"
    nerrors="`expr $nerrors + 1`"
    test yes = "$verbose" && sed 's/^/    /' < $actual
    fi

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

# HDF5 has several tests that create and delete signal files to communicate
# between processes, and it seems that even though the names of the files are
# different, occasionally the wrong file is deleted, interrupting the flow of
# the test.  Running each of these tests in its own directory should eliminate
# the problem.
mkdir usecases_test
cp $bindir/twriteorder usecases_test
for FILE in use_*; do
    case "$FILE" in
        *.o) continue ;;    ## don't copy the .o files
    esac
    if test -f "$FILE" ; then
        cp $FILE usecases_test
    fi
done

# With the --disable-shared option, swmr program files are built in the test
# directory, otherwise they are in test/.libs with a corresponding wrapper
# script in the test directory.  The programs or wrapper scripts in test should
# always be copied, swmr files in .libs should be copied only if they exists.
if [ -f .libs/use_append_chunk ]; then
    mkdir usecases_test/.libs
    for FILE in .libs/use_*; do
        case "$FILE" in
            *.o) continue ;;    ## don't copy the .o files
        esac
        if test -f "$FILE" ; then
            cp $FILE usecases_test/.libs
        fi
    done
    cp .libs/twriteorder usecases_test/.libs
fi

cd usecases_test


# run tests for H5Odisable_mdc_flushes/H5Oenable_mdc_flushes/H5Oare_mdc_flushes_disabled here temporary
USECORK=use_disable_mdc_flushes
for p in $USECORK; do
    TOOLTEST $p
    TOOLTEST $p -y 3
    TOOLTEST $p -n 3000
    TOOLTEST $p -n 5000
done

# run write order test here temporary
WRITEORDER=twriteorder
for p in $WRITEORDER; do
    TOOLTEST $p
    TOOLTEST $p -b 1000
    TOOLTEST $p -p 3000
    TOOLTEST $p -n 2000
    TOOLTEST $p -l w
    TOOLTEST $p -l r
done

# Report test results
if test $nerrors -eq 0 ; then
    echo "$WRITEORDER test passed."
else
    echo "$WRITEORDER test failed with $nerrors errors."
    EXIT_VALUE=$EXIT_FAILURE
    nerrors=0           # reset nerror for the regular tests below.
fi

# main body
for p in $USECASES_PROGRAMS; do
    TOOLTEST $p
    TOOLTEST $p -z 256
    tmpfile=/tmp/datatfile.$$
    TOOLTEST $p -f $tmpfile; rm -f $tmpfile
    TOOLTEST $p -l w
    TOOLTEST $p -l r
    # use case 1.9, testing with multi-planes chunks
    TOOLTEST $p -z 256 -y 5    # 5 planes chunks
    # cleanup temp datafile
    if test -z "$HDF5_NOCLEANUP"; then
    rm -f $p.h5
    fi
done

cd ..
# Report test results and exit
if test $nerrors -eq 0 ; then
    echo "All $TESTNAME tests passed."
    if test -z "$HDF5_NOCLEANUP"; then
        # delete the test directory
        rm -rf usecases_test
    fi
else
    echo "$TESTNAME tests failed with $nerrors errors."
    EXIT_VALUE=$EXIT_FAILURE
fi

exit $EXIT_VALUE