summaryrefslogtreecommitdiffstats
path: root/c++/examples/testh5c++.sh.in
blob: f3a973cabc9258ddf28211819af8226f4079787a (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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
#! /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 h5c++ compiler tool

srcdir=@srcdir@

# Initializations
TESTNAME=h5c++
EXIT_SUCCESS=0
EXIT_FAILURE=1

# Where the tool is installed.
prefix="${prefix:-@prefix@}"
AR="@AR@"
RANLIB="@RANLIB@"
H5TOOL="h5c++"           	# The tool name
H5TOOL_BIN="${prefix}/bin/${H5TOOL}"   # The path of the tool binary

CMP='cmp -s'
DIFF='diff -c'

nerrors=$EXIT_SUCCESS
verbose=yes

# setup my machine information.
myos=`uname -s`
myhostnama=`uname -n`

# Generate some source files and library for tests.
suffix=cpp		# source file suffix
hdf5main=${H5TOOL}_hdf5main.$suffix
hdf5main_o=${H5TOOL}_hdf5main.o
appmain=${H5TOOL}_appmain.$suffix
appmain_o=${H5TOOL}_appmain.o
prog1=${H5TOOL}_prog1.$suffix
prog1_o=${H5TOOL}_prog1.o
prog2=${H5TOOL}_prog2.$suffix
prog2_o=${H5TOOL}_prog2.o
applib=libapp${H5TOOL}.a
args=${H5TOOL}_args.$suffix
args_o=${H5TOOL}_args.o

# short hands
# Caution: if some *.h5 files must be cleaned here, list them by names.
# Don't use the wildcard form of *.h5 as it will wipe out even *.h5 generated
# by other test programs. This will cause a racing condition error when
# parallel make (e.g., gmake -j 4) is used.
temp_SRC="$hdf5main $appmain $prog1 $prog2"
temp_OBJ=`echo $temp_SRC | sed -e "s/\.${suffix}/.o/g"`
temp_FILES="a.out $applib"

# Generate appmain:
# An application Main that calls hdf5 and application's own functions.
cat > $appmain <<EOF
#include <string>

#include <iostream>

#include "H5Cpp.h"

#ifndef H5_NO_NAMESPACE
using namespace H5;
#endif

const H5std_string	FILE_NAME( "tmpapp.h5" );
int sub1(void);
int sub2(void);

int main (void)
{
    sub1();
    sub2();
    H5File file( FILE_NAME, H5F_ACC_TRUNC );
    return 0;
}

EOF

# generate prog1
cat > $prog1 <<EOF
#include <iostream>
#include <string>

using std::cout;
using std::endl;
int sub1(void)
{
    cout << "in sub1" << endl;
    return 0;
}
EOF

# generate prog2
cat > $prog2 <<EOF
#include <iostream>
#include <string>

using std::cout;
using std::endl;
int sub2(void)
{
    cout << "in sub2" << endl;
    return 0;
}
EOF

# Generate HDF5 Main Program:
# An HDF5 sample program that calls hdf5 functions.
cat > $hdf5main <<EOF
#include <string>

#include <iostream>

#include "H5Cpp.h"

#ifndef H5_NO_NAMESPACE
using namespace H5;
#endif

const H5std_string	FILE_NAME( "tmphdf5.h5" );

int main (void)
{
    H5File file( FILE_NAME, H5F_ACC_TRUNC );
    return 0;
}
EOF

# Generate args:
# An application main that test misc command line arguments being passed.
cat > $args <<EOF
#include <string>
#include <iostream>
#include "H5Cpp.h"
#ifndef H5_NO_NAMESPACE
using namespace H5;
#endif

const H5std_string FILE_NAME( "args.h5" );

int main (void)
{
    char c = SGL_QUOTE; // 'H'
    char *s = DBL_QUOTE; // "HDF"
    int val = MISC; // 42

    H5File file( FILE_NAME, H5F_ACC_TRUNC );
    return 0;
}
EOF

# Parse option
#   None

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


# Debug printing
# Change : to echo to print the debug statement
DPRINT() {
    : $*
}

# 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
# failed output.  The actual output is not removed if $HDF5_NOCLEANUP is
# defined.
#
TOOLTEST() {
    out=test_$H5TOOL_$$.out
    err=test_$H5TOOL_$$.err

    # Run test.
    TESTING $H5TOOL $@
    $H5TOOL_BIN $@ > $out 2>&1
    result=$?
    if [ $result = 0 ]; then
	echo " PASSED"
    else
	echo "*FAILED*"
	nerrors="`expr $nerrors + 1`"
	test yes = "$verbose" && \
	    ( echo "========== results ==========="; cat $out;
	      echo "===============================================") |sed 's/^/    /'
    fi

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

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


##############################################################################
###			  T H E   T E S T S                                ###
##############################################################################
#
# HDF5 program that calls HDF5 APIs.
echo "***"Simple Compile and Link in one step.
TOOLTEST $hdf5main
# Application program that calls HDF5 and its own functions.
TOOLTEST $appmain $prog1 $prog2

# Compile, then link.
echo "***"Compile and Link in two steps.
TOOLTEST -c $hdf5main
TOOLTEST $hdf5main_o
TOOLTEST -c $appmain $prog1 $prog2
TOOLTEST $appmain_o $prog1_o $prog2_o

# Build external library, then link with it.
echo "***"Build external library and link with it.
TOOLTEST -c $prog1 $prog2
rm -f $applib
$AR cru $applib $prog1_o $prog2_o
$RANLIB $applib
TOOLTEST $appmain $applib
TOOLTEST $appmain_o $applib
# This is peculiar but should work. (See bug ID 729)
TOOLTEST -c $hdf5main
rm -f $applib
$AR cru $applib $hdf5main_o
$RANLIB $applib
# SunOS does not support this. Skip it.
if [ $myos = SunOS ]; then
    SKIP -o a.out $applib
else
    TOOLTEST -o a.out $applib
fi

# Just preprocess, no compile, no link.
echo "***"Just preprocess, no compile, no link.
TOOLTEST -E $hdf5main
TOOLTEST -E $appmain $prog1 $prog2

# HDF5 program that depends on input args.
echo "***"Simple Compile and Link in one step with user-supplied arguments.
TOOLTEST -DSGL_QUOTE=\'H\' -DDBL_QUOTE=\"HDF\" -DMISC=42 $args

##############################################################################
# END
##############################################################################

# Clean up  file
if test -z "$HDF5_NOCLEANUP"; then
    rm -f $temp_SRC $temp_OBJ $temp_FILES
fi

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