Update version
[official-gcc.git] / libstdc++-v3 / mkcheck.in
blob6d9ef1df914880177be61cd547d90f1c2a7d99ed
1 #!/usr/bin/env bash
3 # Script to do automated testing and data collection for various test
4 # files, so that we don't have to do this by hand on every test file.
5 # It attempts to collect some diagnostic info about size and speed that
6 # should be useful in the future as the library gets tuned for size
7 # and speed. In addition, it tests static and shared linkage, iff each
8 # has been enabled.
10 # Invocation
11 # mkcheck [01]
13 # 1: variables
15 # WHICH determines if you are
16 # (0) testing the build binary and headers, or
17 # (1) testing the installed binary and headers, or
18 WHICH=$1
19 if [ "$WHICH"x = 0x ]; then
20 echo "running mkcheck"
21 echo "$0: testing the build directory"
22 elif [ "$WHICH"x = 1x ]; then
23 echo "running mkcheck"
24 echo "$0: testing the install directory"
25 else
26 echo 'Usage: mkcheck 0 /* test the build directory */'
27 echo ' mkcheck 1 /* test the install directory */'
28 exit 1;
31 # Now that we've successfully translated the numerical option into
32 # a symbolic one, we can safely ignore it.
33 shift
35 # This has been true all along. Found out about it the hard way...
36 case $BASH_VERSION in
37 1*) echo 'You need bash 2.x to run mkcheck. Exiting.'; exit 1 ;;
38 *) ;; # ??
39 esac
41 BUILD_DIR=@glibcpp_builddir@
42 SRC_DIR=@glibcpp_srcdir@
43 PREFIX_DIR=@glibcpp_prefixdir@
44 if [ "$WHICH"x = 0x ]; then
45 CXX=`$BUILD_DIR/testsuite_flags --build-cxx`
46 INCLUDES=`$BUILD_DIR/testsuite_flags --build-includes`
47 else
48 CXX=`$BUILD_DIR/testsuite_flags --install-cxx`
49 INCLUDES=`$BUILD_DIR/testsuite_flags --install-includes`
51 CXXFLAGS=`$BUILD_DIR/testsuite_flags --cxxflags`
52 LIBTOOL="$BUILD_DIR/libtool"
53 LTEXE="$LIBTOOL --mode=execute"
54 #LTCXX="$LIBTOOL --tag=CXX --mode=link $CXX $CXXFLAGS $INCLUDES"
55 LTCXX="$CXX $CXXFLAGS $INCLUDES"
57 # specific libtool flag(s) to use shared libraries, if any
58 SH_FLAG="-Wl,--rpath -Wl,$BUILD_DIR/../../gcc -Wl,--rpath -Wl,$BUILD_DIR/src/.libs"
60 # specific libtool flag(s) to use static libraries, if any
61 ST_FLAG="-static"
62 #ST_FLAG="-all-static"
64 # Set up the testing directory, which should be in a directory called
65 # "testsuite" in the root level of the build directory.
66 TEST_DIR="$BUILD_DIR/testsuite"
67 # help libtool keep quiet
68 if [ ! -d ${TEST_DIR}/.libs ]; then
69 mkdir $TEST_DIR/.libs
72 # the name of the file that will collect and hold all this useful data:
73 RESULTS_FILE="$TEST_DIR/$(date +%Y%m%d)-mkcheck.txt"
75 # the name of the log file that will append compiler diagnostics:
76 LOG_FILE="$TEST_DIR/$(date +%Y%m%d)-mkchecklog.txt"
78 # the names of the specific test files to be run
79 TESTS_FILE="$TEST_DIR/$(date +%Y%m%d)-mkcheckfiles.txt"
81 # the heap size and virtual mem limit for testsuite binaries
82 # See http://gcc.gnu.org/ml/libstdc++/2000-10/msg00029.html
83 MAX_MEM_USAGE=16384
86 # 2: clean, make files, append general test info
89 # Remove old executables.
90 rm -rf "$TEST_DIR"/*exe
91 rm -rf "$TEST_DIR"/compile.out
93 # Remove old core files (which now get left in cwd, not $TEST_DIR).
94 rm -rf ./*core*
96 if [ -f $RESULTS_FILE ]; then
97 rm $RESULTS_FILE
99 if [ -f $LOG_FILE ]; then
100 rm $LOG_FILE
103 # Make a list of the files we're going to run, or use an old one if it exists.
104 if [ ! -f "$TESTS_FILE" ]; then
105 echo "making file $TESTS_FILE"
106 for LONG_NAME in $SRC_DIR/testsuite/*/*.cc
108 DIR_NAME=$(dirname $LONG_NAME)
109 SHORT_NAME="`basename $DIR_NAME`/`basename $LONG_NAME`"
110 echo "$SHORT_NAME" >> $TESTS_FILE
111 done
114 # Nasty solution to replace GNU date(1)'s %s time_t output function.
115 TIMER_COMMAND=$TEST_DIR/printnow.exe
116 if [ ! -x "$TIMER_COMMAND" ]; then
117 echo "making utility $TIMER_COMMAND"
118 gcc -o "$TIMER_COMMAND" "$SRC_DIR/testsuite/printnow.c"
119 strip "$TIMER_COMMAND"
122 # Copy over the data files for filebufs
123 cp $SRC_DIR/testsuite/27_io/*.txt $TEST_DIR
124 cp $SRC_DIR/testsuite/27_io/*.tst $TEST_DIR
125 chmod u+w $TEST_DIR/*.txt
126 chmod u+w $TEST_DIR/*.tst
128 # Emit useful info about compiler and platform
129 echo "host: $(uname -mrsv)" >> $RESULTS_FILE
130 echo "compiler: $($CXX -v 2>&1)" >> $RESULTS_FILE
131 echo "compiler flags: $CXXFLAGS" >> $RESULTS_FILE
132 echo "date: $(date +%Y%m%d)" >> $RESULTS_FILE
133 echo "" >> $RESULTS_FILE
135 explanation='+: pass, -b: build failure, -r: run failure, x: disabled'
136 printf "%s\n %s\n" 'p == pass/fail execution test' "$explanation" \
137 >> $RESULTS_FILE
138 echo "ctime == time to compile and link" >> $RESULTS_FILE
139 echo "etime == time for executable to run" >> $RESULTS_FILE
140 echo "text == size of the executable text section" >> $RESULTS_FILE
141 echo "data == size of the executable data section" >> $RESULTS_FILE
142 echo "total == size of the executable" >> $RESULTS_FILE
143 echo "" >> $RESULTS_FILE
145 echo "p" | awk '{printf("%s ", $1)}' >> $RESULTS_FILE
146 echo "ctime" "etime" | awk '{printf("%s\t%s\t", $1, $2)}' >> $RESULTS_FILE
147 echo "text" "data" | awk '{printf("%s\t%s\t", $1, $2)}' >> $RESULTS_FILE
148 echo "total" "name" | awk '{printf("%s\t%s\t", $1, $2)}' >> $RESULTS_FILE
149 echo "" >> $RESULTS_FILE
151 # Counters. These could be members of an array, but they'd all have to
152 # become individuals anyhow if we ever change this script to super-portable sh.
153 shared_pass=0
154 shared_fail=0
155 static_pass=0
156 static_fail=0
160 # 2.5: support functions
163 # Figure out how to extract size information from binaries. We take
164 # the text of the value we want as an argument, and leave the size in
165 # the appropriate variable.
167 # We discover what kind of size(1) we are using *once* and build a shell
168 # function named 'size_command' to wrap it. (The "function" keyword is
169 # redundant here, but helps me read it, so there.) Previously we were
170 # re-discovering the size(1) arguments three times for each test; sloooow.
172 # It is VERY IMPORTANT not to compare these numbers across platforms.
173 # Different size(1)'s extract section information differently. For
174 # example, using the native Sun size(1) and GNU size(1) built for Suns
175 # on the exact same binary will give very different numbers, due to all
176 # the variance in command-line options and arbitrary names of ELF sections.
178 # and suddenly we go to 2-space indentations...
179 setup_size_command()
181 if size --version 2> /dev/null | grep -c GNU > /dev/null;
182 then # Then we're using a GNU size(1) built for this platform.
183 # We lose .rodata and .data1 and who knows what else... kludge.
184 function size_command()
186 case $1 in
187 TEXT) TEXT=$(size -B $EXENAME | tail -1 | awk '{print $1}') ;;
188 DATA) DATA=$(size -B $EXENAME | tail -1 | awk '{print $2}') ;;
189 SIZE) SIZE=$(size -B $EXENAME | tail -1 | awk '{print $4}') ;;
190 esac
192 else
193 # Not using GNU size; check for platform. These numbers seem to match
194 # up to text/data/total, although their meanings seem to be different.
195 # THIS TABLE IS SORTED. KEEP IT THAT WAY.
196 case @host_os@ in
197 *aix*)
198 function size_command()
200 case $1 in
201 TEXT) TEXT=$(size -X32_64 $EXENAME | awk '{print $2}') ;;
202 DATA) DATA=$(size -X32_64 $EXENAME | awk '{print $4}') ;;
203 SIZE) SIZE=$(size -X32_64 $EXENAME | awk '{print $12}') ;;
204 esac
207 *hpux*)
208 function size_command()
210 case $1 in
211 TEXT) TEXT=$(size $EXENAME | awk '{print $1}') ;;
212 DATA) DATA=$(size $EXENAME | awk '{print $3}') ;;
213 SIZE) SIZE=$(size $EXENAME | awk '{print $7}') ;;
214 esac
217 *irix*)
218 function size_command()
220 case $1 in
221 TEXT) TEXT=$(size -4 $EXENAME | awk '{print $1}') ;;
222 DATA) DATA=$(size -4 $EXENAME | awk '{print $3}') ;;
223 SIZE) SIZE=$(size -4 $EXENAME | awk '{print $7}') ;;
224 esac
227 *solaris*)
228 function size_command()
230 case $1 in
231 TEXT) TEXT=$(size $EXENAME | awk '{print $1}') ;;
232 DATA) DATA=$(size $EXENAME | awk '{print $3}') ;;
233 SIZE) SIZE=$(size $EXENAME | awk '{print $7}') ;;
234 esac
238 echo ' * Warning! Skipping section sizes!' 1>&2
239 function size_command()
241 case $1 in
242 TEXT) TEXT=0 ;;
243 DATA) DATA=0 ;;
244 SIZE) SIZE=0 ;;
245 esac
248 esac
252 # Test for file output
253 test_for_output()
255 # This checks for emitted output files, which is useful when
256 # testing file-related output. The rules for this working are as
257 # follows: the emitted file must have the ".txt" extension, and be
258 # based on the actual *.cc file's name. For example, 27/filbuf.cc
259 # currently outputs files named 27/filebuf-2.txt and 27/filebuf-3.txt.
260 # Also, the first emitted file must be in the form $NAME-1.txt.
261 # The control file must follow the same constraints, but have a
262 # ".tst" extension. Thus, you have 27/filebuf-2.tst, etc.
264 # NAME contains the source name, like 27/filebuf.cc
265 # From that NAME, we want to generate some possible names, using
266 # ls on MATCH, a pattern description generated with sed.
268 # this is the name of the resulting diff file, if any
269 DIFF_FILE="`echo $TEST_NAME | sed 's/cc$/diff/'`"
270 # construct wildcard names, ie for $NAME=filebuf.cc, makes "filebuf*.tst"
271 DATA_FILES="`echo $TEST_NAME | sed 's/\.cc/\*\.tst/g'`"
272 # make sure there is at least one, then go
273 ST_E="`echo $TEST_NAME | sed 's/\.cc/\-1\.tst/g'`"
274 if [ -f $ST_E ]; then
275 # list of actual files that match the wildcard above, ie
276 # "filebuf-1.tst"
277 ST_MATCH_LIST="`ls $DATA_FILES`"
278 for i in $ST_MATCH_LIST; do
279 # ST_OUT_FILE is generated in the build directory.
280 PRE_NAME2="$TEST_DIR/`basename $i`"
281 ST_OUT_FILE="`echo $PRE_NAME2 | sed 's/tst$/txt/'`"
282 diff $ST_OUT_FILE $i > $DIFF_FILE
283 if [ -s $DIFF_FILE ]; then
284 RESULT="-r"
285 else
286 RESULT="+"
288 rm $DIFF_FILE
289 done
290 else
291 # the file does no output, and didn't abnormally
292 # terminate, so assume passed.
293 RESULT="+"
299 # 3: compile, link, execute, time
301 # Abstract out the common code for compiling, linking, executing and printing.
302 test_file()
304 # NB: S_FLAG has to be last argument because it may be null, and
305 # error checking hasn't been invented yet.
306 NAME=$1
307 EXENAME=$2
308 S_FLAG=$3
310 SRC_NAME="$SRC_DIR/testsuite/$1"
311 TEST_NAME="$TEST_DIR/`basename $NAME`"
313 # This would be deliciously easy if GNU date's %s were always around.
314 # There are three ways to do this: 1) use the builtin 'time' like we
315 # do later; then getting compiler errors into LOG_FILE is a nightmare.
316 # 2) Grab the output of a formatted date(1) and do the math; harder
317 # and harder as we try compiling at, say, top of the hour; we would
318 # eventually have to calculate time_t anyhow. Or 3) just grab two
319 # time_t's (no more overhead than grabbing two date(1)'s).
320 compiler_invocation="$LTCXX $S_FLAG $SRC_NAME -o $EXENAME"
321 echo $compiler_invocation >> compile.out 2>&1
322 COMP_TIME_START=$($TIMER_COMMAND)
323 $compiler_invocation >> compile.out 2>&1
324 COMP_TIME_END=$($TIMER_COMMAND)
326 if [ $COMP_TIME_START -lt $COMP_TIME_END ]; then
327 C_TIME=$[ $COMP_TIME_END - $COMP_TIME_START ]
328 else
329 C_TIME="0"
332 if [ -f $EXENAME ]; then
333 # rm compile.out
334 size_command TEXT
335 size_command DATA
336 size_command SIZE
338 # Actually run the executable and time it. Note that output
339 # printed by the executable will be lost and cannot be redirected,
340 # because we need to capture the output of 'time'. Bummer.
341 TIMEFORMAT='timemark %R'
342 E_TIME_TEXT="$(exec 2>&1; \
343 ulimit -d $MAX_MEM_USAGE; ulimit -v $MAX_MEM_USAGE; \
344 time $LTEXE $EXENAME)"
345 E_ABNORMAL_TERMINATION=$?
346 E_TIME="$(echo $E_TIME_TEXT | awk '{print $2}')"
347 # joining those two commands does not work due to quoting problems:
348 #E_TIME="$(exec 2>&1; time $EXENAME | awk '{print $2}')"
349 # this will work as a fallback on certain systems...?
350 #E_TIME=$(exec 2>&1; time $EXENAME | cut -d ' ' -f 2)
352 if [ "$E_ABNORMAL_TERMINATION" -ne 0 ]; then
353 RESULT='-r'
354 rm -f ./*core
355 # sometimes you want to save all core files for review:
356 #mv ./core $EXENAME.core
357 # sometimes the OS allows you to name core files yourself:
358 #mv ./*core $EXENAME.core
359 #mv ./core* $EXENAME.core
360 else
361 test_for_output
364 # sometimes you want to save all failing exe files for review:
365 if [ "$RESULT" = "+" ]; then
366 rm "$EXENAME"
368 else
369 # the file did not compile/link.
370 printf "\n" >> $LOG_FILE
371 # `cat compile.out >> $LOG_FILE`
372 # rm compile.out
373 RESULT="-b"
374 TEXT="0"
375 DATA="0"
376 SIZE="0"
379 # update the counters
380 if test "$RESULT" = "+" ; then
381 if test x"$S_FLAG" = x"$ST_FLAG"; then
382 static_pass=`expr $static_pass + 1`
383 else
384 shared_pass=`expr $shared_pass + 1`
386 else
387 if test x"$S_FLAG" = x"$ST_FLAG"; then
388 static_fail=`expr $static_fail + 1`
389 else
390 shared_fail=`expr $shared_fail + 1`
394 printf "%s\t" "$RESULT"
395 printf "%-2s %d\t%.3f\t%s\t%s\t%s\t%s %s\n" \
396 "$RESULT" $C_TIME $E_TIME $TEXT $DATA $SIZE $NAME >> $RESULTS_FILE
399 setup_size_command
400 echo ""
401 echo "Detailed test results in .${RESULTS_FILE/$BUILD_DIR}"
402 echo $explanation
403 echo "------------------------------------------------------------------------"
404 printf "static\tshared\ttest\n"
405 echo "------------------------------------------------------------------------"
407 TEST_TIME_START=$($TIMER_COMMAND)
408 for NAME in `cat $TESTS_FILE`
410 PRE_NAME="$TEST_DIR/`basename $NAME`"
411 ST_NAME="`echo $PRE_NAME | sed 's/cc$/st-exe/'`"
412 SH_NAME="`echo $PRE_NAME | sed 's/cc$/sh-exe/'`"
414 if test @enable_static@ = yes; then
415 test_file $NAME $ST_NAME "$ST_FLAG"
416 else
417 printf "x\t"
418 printf "static skipped\n" >> $RESULTS_FILE
420 if test @enable_shared@ = yes; then
421 test_file $NAME $SH_NAME "$SH_FLAG"
422 else
423 printf "x\t"
424 printf "shared skipped\n" >> $RESULTS_FILE
426 printf "%s\n" "$NAME"
428 echo "" >> $RESULTS_FILE
429 done
430 TEST_TIME_END=$($TIMER_COMMAND)
434 # 4: summary
436 # grep can count faster than we can...
437 total_failures=`expr ${shared_fail} + ${static_fail}`
438 total_successes=`expr ${shared_pass} + ${static_pass}`
439 resultstext="pass/fail results: ${static_pass}/${static_fail} static + ${shared_pass}/${shared_fail} shared = ${total_successes}/${total_failures} total"
440 if [ $total_failures -eq 0 ]; then
441 resultstext="${resultstext}, WIN WIN"
443 sed -e "/^date:/a\\
444 $resultstext" $RESULTS_FILE > ${RESULTS_FILE}.tmp
445 mv ${RESULTS_FILE}.tmp $RESULTS_FILE
447 if [ $TEST_TIME_START -lt $TEST_TIME_END ]; then
448 TEST_TIME=$[ $TEST_TIME_END - $TEST_TIME_START ]
449 echo "testrun == $TEST_TIME seconds"
450 echo "testrun == $TEST_TIME seconds" >> $RESULTS_FILE
453 exit 0