OSDN Git Service

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