source: trunk/src/gcc/libstdc++-v3/mkcheck.in@ 2

Last change on this file since 2 was 2, checked in by bird, 23 years ago

Initial revision

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