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
12 # mkcheck [01] (path to build) (path to src) (path to install)
14 ### XXX There are a lot of tests in here for OS-specific stuff. If we
15 ### move to a 'configure.target' method of determining those extra
16 ### flags and whatnot, we can take out all those things and source
17 ### that file from here. (Write that file with this in mind...)
19 ### XXX Note that breaking out of this with ^C will not work. Dunno why.
24 # WHICH determines if you are
25 # (0) testing the build binary and headers, or
26 # (1) testing the installed binary and headers, or
28 if [ "$WHICH"x
= 0x
] && [ $# -eq 3 ]; then
29 echo "running mkcheck"
30 echo "$0: testing the build directory"
31 query
="--built-library"
32 elif [ "$WHICH"x
= 1x
] && [ $# -eq 4 ]; then
33 echo "running mkcheck"
34 echo "$0: testing the install directory $4"
35 query
="--installed-library"
37 echo 'Usage: mkcheck 0 (path to build) (path to src)'
38 echo ' mkcheck 1 (path to build) (path to src) (path to install)'
42 # Now that we've successfully translated the numerical option into
43 # a symbolic one, we can safely ignore it.
46 # This has been true all along. Found out about it the hard way...
48 1*) echo 'You need bash 2.x to run mkcheck. Exiting.'; exit 1 ;;
52 # Compute the flags necessary to run the testsuite.
55 set `./tests_flags ${query} $*` ||
exit 1
56 BUILD_DIR
=$1; SRC_DIR
=$2; PREFIX_DIR
=$3; LTCXX
=$4; LIBS
=$5; LTEXE
=$6;
59 # Set up the testing directory, which should be in a directory called
60 # "testsuite" in the root level of the build directory.
61 TEST_DIR
="`pwd`/testsuite"
62 if [ ! -d "$TEST_DIR" ]; then
63 echo "making directory $TEST_DIR"
65 mkdir
$TEST_DIR/.libs
# help libtool keep quiet
69 # the name of the file that will collect and hold all this useful data:
70 RESULTS_FILE
="$TEST_DIR/$(date +%Y%m%d)-mkcheck.txt"
72 # the name of the log file that will append compiler diagnostics:
73 LOG_FILE
="$TEST_DIR/$(date +%Y%m%d)-mkchecklog.txt"
75 # the names of the specific test files to be run
76 TESTS_FILE
="$TEST_DIR/$(date +%Y%m%d)-mkcheckfiles.txt"
78 # the heap size limit for testsuite binaries; start with a 2MB limit as per
79 # http://sources.redhat.com/ml/libstdc++/2000-10/msg00029.html
83 # 2: clean, make files, append general test info
85 if [ -f $RESULTS_FILE ]; then
88 if [ -f $LOG_FILE ]; then
92 # Make a list of the files we're going to run, or use an old one if it exists.
93 if [ ! -f "$TESTS_FILE" ]; then
94 echo "making file $TESTS_FILE"
95 for LONG_NAME
in $SRC_DIR/testsuite
/*/*.cc
97 DIR_NAME
=$
(dirname $LONG_NAME)
98 SHORT_NAME
="`basename $DIR_NAME`/`basename $LONG_NAME`"
99 echo "$SHORT_NAME" >> $TESTS_FILE
103 # Nasty solution to replace GNU date(1)'s %s time_t output function.
104 if [ ! -x "$TEST_DIR/printnow" ]; then
105 echo "making utility $TEST_DIR/printnow"
106 gcc
-o "$TEST_DIR/printnow" "$SRC_DIR/testsuite/printnow.c"
107 strip
"$TEST_DIR/printnow"
110 # Remove old executables.
111 rm -rf "$TEST_DIR"/*exe
113 # Remove old core files (which now get left in cwd, not $TEST_DIR).
116 # Copy over the data files for filebufs
117 cp $SRC_DIR/testsuite
/27_io
/*.txt
$TEST_DIR
118 cp $SRC_DIR/testsuite
/27_io
/*.tst
$TEST_DIR
119 chmod u
+w
$TEST_DIR/*.txt
120 chmod u
+w
$TEST_DIR/*.tst
122 # Emit useful info about compiler and platform
123 echo "host: $(uname -mrsv)" >> $RESULTS_FILE
124 echo "compiler: $($CXX -v 2>&1)" >> $RESULTS_FILE
125 echo "compiler flags: $CXX_FLAG" >> $RESULTS_FILE
126 echo "date: $(date +%Y%m%d)" >> $RESULTS_FILE
127 echo "" >> $RESULTS_FILE
129 explanation
='+: pass, -b: build failure, -r: run failure, x: disabled'
130 printf "%s\n %s\n" 'p == pass/fail execution test' "$explanation" \
132 echo "ctime == time to compile and link" >> $RESULTS_FILE
133 echo "etime == time for executable to run" >> $RESULTS_FILE
134 echo "text == size of the executable text section" >> $RESULTS_FILE
135 echo "data == size of the executable data section" >> $RESULTS_FILE
136 echo "total == size of the executable" >> $RESULTS_FILE
137 echo "" >> $RESULTS_FILE
138 echo "(First static, then shared.)" >> $RESULTS_FILE
140 echo "p" |
awk '{printf("%s ", $1)}' >> $RESULTS_FILE
141 echo "ctime" "etime" |
awk '{printf("%s\t%s\t", $1, $2)}' >> $RESULTS_FILE
142 echo "text" "data" |
awk '{printf("%s\t%s\t", $1, $2)}' >> $RESULTS_FILE
143 echo "total" "name" |
awk '{printf("%s\t%s\t", $1, $2)}' >> $RESULTS_FILE
144 echo "" >> $RESULTS_FILE
148 # 2.5: support functions
151 # Figure out how to extract size information from binaries. We take
152 # the text of the value we want as an argument, and leave the size in
153 # the appropriate variable.
155 # We discover what kind of size(1) we are using *once* and build a shell
156 # function named 'size_command' to wrap it. (The "function" keyword is
157 # redundant here, but helps me read it, so there.) Previously we were
158 # re-discovering the size(1) arguments three times for each test; sloooow.
160 # It is VERY IMPORTANT not to compare these numbers across platforms.
161 # Different size(1)'s extract section information differently. For
162 # example, using the native Sun size(1) and GNU size(1) built for Suns
163 # on the exact same binary will give very different numbers, due to all
164 # the variance in command-line options and arbitrary names of ELF sections.
166 # and suddenly we go to 2-space indentations...
169 if size
--version 2> /dev
/null |
grep -c GNU
> /dev
/null
;
170 then # Then we're using a GNU size(1) built for this platform.
171 # We lose .rodata and .data1 and who knows what else... kludge.
172 function size_command
()
175 TEXT
) TEXT
=$
(size
-A $EXENAME |
grep ^.text |
awk '{print $2}') ;;
176 DATA
) DATA
=$
(size
-A $EXENAME |
grep -w ^.data |
awk '{print $2}') ;;
177 SIZE
) SIZE
=$
(size
-A $EXENAME |
grep otal |
awk '{print $2}') ;;
181 # Not using GNU size; check for platform. These numbers seem to match
182 # up to text/data/total, although their meanings seem to be different.
183 # THIS TABLE IS SORTED. KEEP IT THAT WAY.
186 function size_command
()
189 TEXT
) TEXT
=$
(size
-X32_64 $EXENAME |
awk '{print $2}') ;;
190 DATA
) DATA
=$
(size
-X32_64 $EXENAME |
awk '{print $4}') ;;
191 SIZE
) SIZE
=$
(size
-X32_64 $EXENAME |
awk '{print $12}') ;;
196 function size_command
()
199 TEXT
) TEXT
=$
(size
-4 $EXENAME |
awk '{print $1}') ;;
200 DATA
) DATA
=$
(size
-4 $EXENAME |
awk '{print $3}') ;;
201 SIZE
) SIZE
=$
(size
-4 $EXENAME |
awk '{print $7}') ;;
206 function size_command
()
209 TEXT
) TEXT
=$
(size
$EXENAME |
awk '{print $1}') ;;
210 DATA
) DATA
=$
(size
$EXENAME |
awk '{print $3}') ;;
211 SIZE
) SIZE
=$
(size
$EXENAME |
awk '{print $7}') ;;
216 echo ' * Warning! Skipping section sizes!' 1>&2
217 function size_command
()
230 # Test for file output
233 # This checks for emitted output files, which is useful when
234 # testing file-related output. The rules for this working are as
235 # follows: the emitted file must have the ".txt" extension, and be
236 # based on the actual *.cc file's name. For example, 27/filbuf.cc
237 # currently outputs files named 27/filebuf-2.txt and 27/filebuf-3.txt.
238 # Also, the first emitted file must be in the form $NAME-1.txt.
239 # The control file must follow the same constraints, but have a
240 # ".tst" extension. Thus, you have 27/filebuf-2.tst, etc.
242 # NAME contains the source name, like 27/filebuf.cc
243 # From that NAME, we want to generate some possible names, using
244 # ls on MATCH, a pattern description generated with sed.
246 # this is the name of the resulting diff file, if any
247 DIFF_FILE
="`echo $TEST_NAME | sed 's/cc$/diff/'`"
248 # construct wildcard names, ie for $NAME=filebuf.cc, makes "filebuf*.tst"
249 DATA_FILES
="`echo $NAME | sed 's/\.cc/\*\.tst/g'`"
250 # make sure there is at least one, then go
251 ST_E
="`echo $NAME | sed 's/\.cc/\-1\.tst/g'`"
252 if [ -f $ST_E ]; then
253 # list of actual files that match the wildcard above, ie
255 ST_MATCH_LIST
="`ls $DATA_FILES`"
256 for i
in $ST_MATCH_LIST; do
257 # ST_OUT_FILE is generated in the build directory.
258 PRE_NAME2
="$TEST_DIR/`basename $i`"
259 ST_OUT_FILE
="`echo $PRE_NAME2 | sed 's/tst$/txt/'`"
260 diff $ST_OUT_FILE $i > $DIFF_FILE
261 if [ -s $DIFF_FILE ]; then
263 echo "$ST_OUT_FILE has some problems, dude"
270 # the file does no output, and didn't abnormally
271 # terminate, so assume passed.
278 # 3: compile, link, execute, time
280 # Abstract out the common code for compiling, linking, executing and printing.
283 # NB: S_FLAG has to be last argument because it may be null, and
284 # error checking hasn't been invented yet.
289 SRC_NAME
="$SRC_DIR/testsuite/$1"
290 TEST_NAME
="$TEST_DIR/`basename $NAME`"
292 # This would be deliciously easy if GNU date's %s were always around.
293 # There are three ways to do this: 1) use the builtin 'time' like we
294 # do later; then getting compiler errors into LOG_FILE is a nightmare.
295 # 2) Grab the output of a formatted date(1) and do the math; harder
296 # and harder as we try compiling at, say, top of the hour; we would
297 # eventually have to calculate time_t anyhow. Or 3) just grab two
298 # time_t's (no more overhead than grabbing two date(1)'s).
299 compiler_invocation
="$LTCXX $S_FLAG $SRC_NAME -o $EXENAME $LIBS"
300 COMP_TIME_START
=$
($TEST_DIR/printnow
)
301 $compiler_invocation >> compile.out
2>&1
302 COMP_TIME_END
=$
($TEST_DIR/printnow
)
304 if [ $COMP_TIME_START -lt $COMP_TIME_END ]; then
305 C_TIME
=$
[ $COMP_TIME_END - $COMP_TIME_START ]
310 if [ -f $EXENAME ]; then
316 # Actually run the executable and time it. Note that output
317 # printed by the executable will be lost and cannot be redirected,
318 # because we need to capture the output of 'time'. Bummer.
319 TIMEFORMAT
='timemark %R'
320 E_TIME_TEXT
="$(exec 2>&1; ulimit -d $MAX_MEM_USAGE; \
321 time $LTEXE $EXENAME)"
322 E_ABNORMAL_TERMINATION
=$?
323 E_TIME
="$(echo $E_TIME_TEXT | awk '{print $2}')"
324 # joining those two commands does not work due to quoting problems:
325 #E_TIME="$(exec 2>&1; time $EXENAME | awk '{print $2}')"
326 # this will work as a fallback on certain systems...?
327 #E_TIME=$(exec 2>&1; time $EXENAME | cut -d ' ' -f 2)
329 if [ "$E_ABNORMAL_TERMINATION" -ne 0 ]; then
332 # sometimes you want to save all core files for review:
333 #mv ./core $EXENAME.core
334 # sometimes the OS allows you to name core files yourself:
335 #mv ./*core $EXENAME.core
336 #mv ./core* $EXENAME.core
341 # sometimes you want to save all failing exe files for review:
342 if [ "$RESULT" = "+" ]; then
346 # the file did not compile/link.
347 printf "\n" >> $LOG_FILE
348 `cat compile.out >> $LOG_FILE`
356 printf "%s\t" "$RESULT"
357 printf "%-2s %d\t%.3f\t%s\t%s\t%s\t%s\n" \
358 "$RESULT" $C_TIME $E_TIME $TEXT $DATA $SIZE $NAME >> $RESULTS_FILE
363 echo "Detailed test results in .${RESULTS_FILE/$BUILD_DIR}"
365 echo "------------------------------------------------------------------------"
366 printf "static\tshared\ttest\n"
367 echo "------------------------------------------------------------------------"
369 TEST_TIME_START
=$
($TEST_DIR/printnow
)
370 for NAME
in `cat $TESTS_FILE`
372 PRE_NAME
="$TEST_DIR/`basename $NAME`"
373 ST_NAME
="`echo $PRE_NAME | sed 's/cc$/st-exe/'`"
374 SH_NAME
="`echo $PRE_NAME | sed 's/cc$/sh-exe/'`"
376 if test @enable_static@
= yes; then
377 test_file
$NAME $ST_NAME $ST_FLAG
380 printf "static skipped\n" >> $RESULTS_FILE
382 if test @enable_shared@
= yes; then
383 test_file
$NAME $SH_NAME $SH_FLAG
386 printf "shared skipped\n" >> $RESULTS_FILE
388 printf "%s\n" "$NAME"
390 echo "" >> $RESULTS_FILE
392 TEST_TIME_END
=$
($TEST_DIR/printnow
)
398 # grep can count faster than we can...
399 total_failures
=$
(egrep -c "^\-" $RESULTS_FILE)
400 total_successes
=$
(egrep -c "^\+" $RESULTS_FILE)
401 resultstext
="pass/fail results: ${total_successes}/${total_failures}"
402 if [ $total_failures -eq 0 ]; then
403 resultstext
="${resultstext}, WIN WIN"
406 $resultstext" $RESULTS_FILE > ${RESULTS_FILE}.tmp
407 mv ${RESULTS_FILE}.tmp
$RESULTS_FILE
409 if [ $TEST_TIME_START -lt $TEST_TIME_END ]; then
410 TEST_TIME
=$
[ $TEST_TIME_END - $TEST_TIME_START ]
411 echo "testrun == $TEST_TIME seconds"
412 echo "testrun == $TEST_TIME seconds" >> $RESULTS_FILE