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