Makefile.in (site.exp): Define HAVE_LIBSTDCXX_V3.
[gcc.git] / libstdc++-v3 / mkcheck.in
1 #!/usr/bin/env bash
2
3 # Script to do automated testing and data collection
4 # for various test files, so that we don't have to do this by hand on
5 # every test file. It attempts to collect some diagnostic info about
6 # size and speed that should be useful in the future as the library
7 # gets tuned for size and speed. In addition, it tests static and
8 # shared linkage.
9
10 # Invocation
11 # mkcheck [012] (path to build) (path to src) (path to install)
12
13 #
14 # 1: variables
15 #
16 # WHICH determines if you are
17 # (0) testing the build binary and headers, or
18 # (1) testing the installed binary and headers, or
19 # (2) testing under dejagnu (just print the standard flags needed).
20 WHICH=$1
21 if [ "$WHICH"x = 0x ] && [ $# -eq 3 ]; then
22 echo "running mkcheck"
23 echo "$0: testing the build directory"
24 elif [ "$WHICH"x = 1x ] && [ $# -eq 4 ]; then
25 echo "running mkcheck"
26 echo "$0: testing the install directory $4"
27 elif [ "$WHICH"x = 2x ] && [ $# -eq 3 ]; then
28 true
29 else
30 echo 'Usage: mkcheck 0 (path to build) (path to src)'
31 echo ' mkcheck 1 (path to build) (path to src) (path to install)'
32 echo ' mkcheck 2 (path to build) (path to src)'
33 exit 1;
34 fi
35
36 BUILD_DIR=$2
37 if [ ! -d "$BUILD_DIR" ]; then
38 echo "build directory $BUILD_DIR not found, exiting."
39 exit 1
40 fi
41
42 SRC_DIR=$3
43 if [ ! -d "$SRC_DIR" ]; then
44 echo "source directory $SRC_DIR not found, exiting."
45 exit 1
46 fi
47
48 if [ $WHICH -eq 1 ]; then
49 PREFIX_DIR=$4
50 if [ ! -d "$PREFIX_DIR" ]; then
51 echo "install directory $PREFIX_DIR not found, exiting."
52 exit 1
53 fi
54 fi
55
56 # INC_PATH == include path to new headers for use on gcc command-line
57 top_srcdir=@top_srcdir@
58 C_DIR="`basename @C_INCLUDE_DIR@`"
59 if [ $WHICH != "1" ]; then
60 INC_PATH="@CSHADOW_FLAGS@ -I$BUILD_DIR -I$BUILD_DIR/libio \
61 -I$SRC_DIR/include/std -I$SRC_DIR/include/$C_DIR \
62 -I$SRC_DIR/include -I$SRC_DIR/libsupc++ -I$SRC_DIR/libio \
63 -I$SRC_DIR/testsuite"
64 elif [ $WHICH -eq 1 ]; then
65 INC_PATH="-I$SRC_DIR/testsuite"
66 fi
67
68 if [ $WHICH -eq 2 ]; then
69 echo $INC_PATH -I$SRC_DIR/include/backward -I$SRC_DIR/include/ext
70 exit 0;
71 fi
72
73 #LIB_PATH == where to find the build library binaries.
74 if [ $WHICH != "1" ]; then
75 LIB_PATH="$BUILD_DIR/src/.libs"
76 CXX="$BUILD_DIR/../../gcc/g++ -B$BUILD_DIR/../../gcc/"
77 elif [ $WHICH -eq 1 ]; then
78 LIB_PATH="$PREFIX_DIR/lib"
79 CXX="$PREFIX_DIR/bin/g++"
80 fi
81
82 # gcc compiler flags
83 #CXX_FLAG="-fsquangle -fhonor-std -fnew-exceptions -g -O2 -DDEBUG_ASSERT "
84 #CXX_FLAG="-g -O2 -DDEBUG_ASSERT "
85 CXX_FLAG="-g -DDEBUG_ASSERT @SECTION_FLAGS@ @SECTION_LDFLAGS@"
86
87 # a specific flag(s) to force the use of shared libraries, if any
88 SH_FLAG=""
89
90 # a specific flag(s) to force the use of static libraries, if any
91 ST_FLAG="-static"
92
93 # Set up the testing directory, which should be in a directory called
94 # "testsuite" in the root level of the build directory.
95 TEST_DIR="`pwd`/testsuite"
96 if [ ! -d "$TEST_DIR" ]; then
97 echo "making directory $TEST_DIR"
98 mkdir $TEST_DIR
99 chmod 777 $TEST_DIR
100 fi
101
102 # the name of the file that will collect and hold all this useful data:
103 RESULTS_FILE="$TEST_DIR/$(date +%Y%m%d)-mkcheck.txt"
104
105 # the name of the log file that will append compiler diagnostics:
106 LOG_FILE="$TEST_DIR/$(date +%Y%m%d)-mkchecklog.txt"
107
108 # the names of the specific test files to be run
109 TESTS_FILE="$TEST_DIR/$(date +%Y%m%d)-mkcheckfiles.txt"
110
111 # the heap size limit for testsuite binaries; start with a 2MB limit as per
112 # http://sources.redhat.com/ml/libstdc++/2000-10/msg00029.html
113 MAX_MEM_USAGE=3072
114
115 #
116 # 2: clean, make files, append general test info
117 #
118 if [ -f $RESULTS_FILE ]; then
119 rm $RESULTS_FILE
120 fi
121 if [ -f $LOG_FILE ]; then
122 rm $LOG_FILE
123 fi
124
125 # Make a list of the files we're going to run, or use an old one if it exists.
126 if [ ! -f "$TESTS_FILE" ]; then
127 echo "making file $TESTS_FILE"
128 for LONG_NAME in $SRC_DIR/testsuite/*/*.cc
129 do
130 DIR_NAME=$(dirname $LONG_NAME)
131 SHORT_NAME="`basename $DIR_NAME`/`basename $LONG_NAME`"
132 echo "$SHORT_NAME" >> $TESTS_FILE
133 done
134 fi
135
136 # Nasty solution to replace GNU date(1)'s %s time_t output function.
137 if [ ! -x "$TEST_DIR/printnow" ]; then
138 echo "making utility $TEST_DIR/printnow"
139 gcc -o "$TEST_DIR/printnow" "$SRC_DIR/testsuite/printnow.c"
140 strip "$TEST_DIR/printnow"
141 fi
142
143 # Remove old executables.
144 rm -rf "$TEST_DIR"/*exe
145
146 # Remove old core files (which now get left in cwd, not $TEST_DIR).
147 rm -rf ./*core
148
149 # Copy over the data files for filebufs in read-only mode
150 cp $SRC_DIR/testsuite/27_io/*.txt $TEST_DIR
151 cp $SRC_DIR/testsuite/27_io/*.tst $TEST_DIR
152 chmod u+w $TEST_DIR/*.txt
153 chmod u+w $TEST_DIR/*.tst
154
155 # Emit useful info about compiler and platform
156 echo "host: $(uname -mrsv)" >> $RESULTS_FILE
157 echo "compiler: $($CXX -v 2>&1 | tail -1)" >> $RESULTS_FILE
158 echo "compiler flags: $CXX_FLAG" >> $RESULTS_FILE
159 echo "date: $(date +%Y%m%d)" >> $RESULTS_FILE
160 echo "" >> $RESULTS_FILE
161
162 echo "p == pass/fail execution test" >> $RESULTS_FILE
163 echo "ctime == time to compile and link" >> $RESULTS_FILE
164 echo "etime == time for executable to run" >> $RESULTS_FILE
165 echo "text == size of the executable text section" >> $RESULTS_FILE
166 echo "data == size of the executable data section" >> $RESULTS_FILE
167 echo "total == size of the executable" >> $RESULTS_FILE
168 echo "" >> $RESULTS_FILE
169 echo "(First static, then shared.)" >> $RESULTS_FILE
170
171 echo "p" | awk '{printf("%s ", $1)}' >> $RESULTS_FILE
172 echo "ctime" "etime" | awk '{printf("%s\t%s\t", $1, $2)}' >> $RESULTS_FILE
173 echo "text" "data" | awk '{printf("%s\t%s\t", $1, $2)}' >> $RESULTS_FILE
174 echo "total" "name" | awk '{printf("%s\t%s\t", $1, $2)}' >> $RESULTS_FILE
175 echo "" >> $RESULTS_FILE
176
177
178 #
179 # 3: compile, link, execute, time
180 #
181 # Abstract out the common code for compiling, linking, executing and printing.
182 test_file()
183 {
184 # NB: S_FLAG has to be last argument because it may be null, and
185 # error checking hasn't been invented yet.
186 NAME=$1
187 EXENAME=$2
188 S_FLAG=$3
189
190 SRC_NAME="$SRC_DIR/testsuite/$1"
191 TEST_NAME="$TEST_DIR/`basename $NAME`"
192
193 # This would be deliciously easy if GNU date's %s were always around.
194 # There are three ways to do this: 1) use the builtin 'time' like we
195 # do later; then getting compiler errors into LOG_FILE is a nightmare.
196 # 2) Grab the output of a formatted date(1) and do the math; harder
197 # and harder as we try compiling at, say, top of the hour; we would
198 # eventually have to calculate time_t anyhow. Or 3) just grab two
199 # time_t's (no more overhead than grabbing two date(1)'s).
200 COMP_TIME_START=$($TEST_DIR/printnow)
201 $CXX $CXX_FLAG $S_FLAG $INC_PATH -L$LIB_PATH -Wl,--rpath -Wl,$LIB_PATH \
202 $SRC_NAME -o $EXENAME 2>> $LOG_FILE
203 COMP_TIME_END=$($TEST_DIR/printnow)
204
205 if [ $COMP_TIME_START -lt $COMP_TIME_END ]; then
206 C_TIME=$[ $COMP_TIME_END - $COMP_TIME_START ]
207 else
208 C_TIME="0"
209 fi
210
211 if [ -f $EXENAME ]; then
212 case @host_os@ in
213 *solaris2.8*)
214 # These numbers seem to match up to text/data/total,
215 # although their meanings seem to be different. Very
216 # important to not compare these numbers across platforms.
217 ## Get rid of the banner information. I don't recall this
218 ## happening under previous Solarises. Maybe it's an 8 thing.
219 TEXT="$(size $EXENAME | grep $EXENAME | awk '{print $1}')"
220 DATA="$(size $EXENAME | grep $EXENAME | awk '{print $3}')"
221 SIZE="$(size $EXENAME | grep $EXENAME | awk '{print $7}')"
222 ;;
223 *solaris*)
224 # These numbers seem to match up to text/data/total,
225 # although their meanings seem to be different. Very
226 # important to not compare these numbers across platforms.
227 TEXT="$(size $EXENAME | awk '{print $1}')"
228 DATA="$(size $EXENAME | awk '{print $3}')"
229 SIZE="$(size $EXENAME | awk '{print $7}')"
230 ;;
231 *)
232 TEXT="$(size -A $EXENAME | grep text | awk '{print $2}')"
233 DATA="$(size -A $EXENAME | grep data | awk '{print $2}')"
234 SIZE="$(size -A $EXENAME | grep otal | awk '{print $2}')"
235 ;;
236 esac
237
238 # Actually run the executable and time it . . .
239 TIMEFORMAT='timemark %R'
240 E_TIME_TEXT="$(exec 2>&1; ulimit -d $MAX_MEM_USAGE; time $EXENAME)"
241 E_ABNORMAL_TERMINATION=$?
242 E_TIME="$(echo $E_TIME_TEXT | awk '{print $2}')"
243 # joining those two commands does not work due to quoting problems:
244 #E_TIME="$(exec 2>&1; time $EXENAME | awk '{print $2}')"
245 # this will work as a fallback on certain systems...?
246 #E_TIME=$(exec 2>&1; time $EXENAME | cut -d ' ' -f 2)
247
248 if [ "$E_ABNORMAL_TERMINATION" -ne 0 ]; then
249 RESULT='-'
250 rm -f ./*core
251 # sometimes you want to save all core files for review:
252 #mv ./core $EXENAME.core
253 # sometimes the OS names core files as programname.core:
254 #mv ./*core $EXENAME.core
255 else
256 # XXX this should probably be a function?
257
258 # This checks for emitted output files, which is useful
259 # when testing file-related output. The rules for this
260 # working are as follows: the emitted file must have the
261 # ".txt" extension, and be based on the actual *.cc file's
262 # name. For example, 27/filbuf.cc currently outputs files
263 # named 27/filebuf-2.txt and 27/filebuf-3.txt. Also, the first
264 # emitted file must be in the form $NAME-1.txt. The
265 # control file must follow the same constraints, but have
266 # a ".tst" extension. Thus, you have 27/filebuf-2.tst, etc
267 # etc.
268
269 # NAME contains the source name, like 27/filebuf.cc
270 # From that NAME, we want to generate some possible names, using
271 # ls on MATCH, a pattern description generated with sed.
272
273 # this is the name of the resulting diff file, if any
274 DIFF_FILE="`echo $TEST_NAME | sed 's/cc$/diff/'`"
275 # construct wildcard names,ie for $NAME=filebuf.cc, makes
276 # "filebuf*.tst"
277 DATA_FILES="`echo $NAME | sed 's/\.cc/\*\.tst/g'`"
278 # make sure there is at least one, then go
279 ST_E="`echo $NAME | sed 's/\.cc/\-1\.tst/g'`"
280 if [ -f $ST_E ]; then
281 # list of actual files that match the wildcard above, ie
282 # "filebuf-1.tst"
283 ST_MATCH_LIST="`ls $DATA_FILES`"
284 for i in $ST_MATCH_LIST
285 do
286 # ST_OUT_FILE is generated in the build directory.
287 PRE_NAME2="$TEST_DIR/`basename $i`"
288 ST_OUT_FILE="`echo $PRE_NAME2 | sed 's/tst$/txt/'`"
289 diff $ST_OUT_FILE $i > $DIFF_FILE
290 if [ -s $DIFF_FILE ]; then
291 RESULT="-"
292 echo "$ST_OUT_FILE has some problems, dude"
293 else
294 RESULT="+"
295 fi
296 rm $DIFF_FILE
297 done
298 else
299 # the file does no output, and didn't abnormally
300 # terminate, so assume passed.
301 RESULT="+"
302 fi
303 fi
304 # sometimes you want to save all failing exe files for review:
305 if [ "$RESULT" = "+" ]; then
306 rm "$EXENAME"
307 fi
308 else
309 # the file did not compile. Write out compilation info to the log file.
310 echo "$CXX $CXX_FLAG $S_FLAG $INC_PATH -L$LIB_PATH -Wl,--rpath -Wl,$LIB_PATH \
311 $SRC_NAME -o $EXENAME" 2>> $LOG_FILE
312
313 RESULT="-"
314 TEXT="0"
315 DATA="0"
316 SIZE="0"
317 fi
318
319 echo $RESULT | awk '{printf("%s\t", $1)}'
320 echo $RESULT | awk '{printf ("%.1s ", $1)}'>>$RESULTS_FILE
321 echo $C_TIME $E_TIME |awk '{printf("%d\t%.3f\t", $1, $2)}'>>$RESULTS_FILE
322 echo $TEXT $DATA | awk '{printf("%s\t%s\t", $1, $2)}'>>$RESULTS_FILE
323 echo $SIZE | awk '{printf("%s\t", $1)}'>>$RESULTS_FILE
324 echo $NAME | awk '{printf("%s\n", $1)}'>>$RESULTS_FILE
325 };
326
327 echo "detailed test information in $RESULTS_FILE"
328 echo "------------------------------------------------------------------------"
329 echo "static" | awk '{printf("%s\t", $1)}'
330 echo "shared" | awk '{printf("%s\t", $1)}'
331 echo "test" | awk '{printf("%s\n", $1)}'
332 echo "------------------------------------------------------------------------"
333
334 TEST_TIME_START=$($TEST_DIR/printnow)
335 for NAME in `cat $TESTS_FILE`
336 do
337 PRE_NAME="$TEST_DIR/`basename $NAME`"
338 ST_NAME="`echo $PRE_NAME | sed 's/cc$/st-exe/'`"
339 SH_NAME="`echo $PRE_NAME | sed 's/cc$/sh-exe/'`"
340
341 test_file $NAME $ST_NAME $ST_FLAG
342 test_file $NAME $SH_NAME $SH_FLAG
343 echo "$NAME" | awk '{printf("%s\n", $1)}'
344
345 echo "" >> $RESULTS_FILE
346 done
347 TEST_TIME_END=$($TEST_DIR/printnow)
348
349
350 #
351 # 4: summary
352 #
353 # grep can count faster than we can...
354 total_failures=$(egrep -c "^\-" $RESULTS_FILE)
355 total_successes=$(egrep -c "^\+" $RESULTS_FILE)
356 resultstext="pass/fail results: ${total_successes}/${total_failures}"
357 if [ $total_failures -eq 0 ]; then
358 resultstext="${resultstext}, WIN WIN"
359 fi
360 sed -e "/^date:/a\\
361 $resultstext" $RESULTS_FILE > ${RESULTS_FILE}.tmp
362 mv ${RESULTS_FILE}.tmp $RESULTS_FILE
363
364 if [ $TEST_TIME_START -lt $TEST_TIME_END ]; then
365 TEST_TIME=$[ $TEST_TIME_END - $TEST_TIME_START ]
366 echo "testrun == $TEST_TIME"
367 echo "testrun == $TEST_TIME" >> $RESULTS_FILE
368 fi
369
370 exit 0
371
372
373