OSDN Git Service

2000-04-21 Benjamin Kosnik <bkoz@redhat.com>
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / mkcheck.in
1 #!/usr/bin/env bash
2
3 # 1999-07-19 bkoz 
4 # Script to do automated testing and data collection for
5 # various test files, and avoid doing this on every test file.
6 # It attempts to collect some diagnostic info about size
7 # and speed that should be useful in the future as the library gets
8 # tuned for size and speed.
9
10 # invocation == mkcheck [01] (path to build) (path to src) (path to install)
11
12 if [ $# != 3 ] && [ $# != 4 ]; then
13     echo 'Usage: mkcheck 0 (path to build) (path to src)'
14     echo '       mkcheck 1 (path to build) (path to src) (path to install)'
15     exit 1
16 fi
17 echo "running mkcheck"
18
19 #
20 # 1: variables
21 #
22 # WHICH determines if you are testing the installed binary and headers, or
23 # the build binary and headers.
24 WHICH=$1
25 if [ $WHICH != "1" ]; then
26   WHICH=0
27   echo "$0: testing the build directory"
28 elif [ $WHICH -eq 1 ]; then
29   echo "$0: testing the install directory $1"
30 fi
31
32 BUILD_DIR=$2
33 if [ ! -d "$BUILD_DIR" ]; then
34   echo "build directory $BUILD_DIR not found, exiting."
35   exit 1
36 fi
37
38 SRC_DIR=$3
39 if [ ! -d "$SRC_DIR" ]; then
40   echo "source directory $SRC_DIR not found, exiting."
41   exit 1
42 fi
43
44 if [ $WHICH -eq 1 ]; then 
45     PREFIX_DIR=$4
46     if [ ! -d "$PREFIX_DIR" ]; then
47     echo "install directory $PREFIX_DIR not found, exiting."
48     exit 1
49     fi
50 fi
51
52 # INC_PATH == include path to new headers for use on gcc command-line
53 if [ $WHICH != "1" ]; then
54   INC_PATH="-I$BUILD_DIR -I$SRC_DIR/@ctype_include_dir@ -I$SRC_DIR/@cpu_include_dir@  -I$SRC_DIR/std -I$SRC_DIR -I$SRC_DIR/libio"
55 elif [ $WHICH -eq 1 ]; then
56   INC_PATH=""
57 fi
58
59 #LIB_PATH == where to find the build library binaries.
60 if [ $WHICH != "1" ]; then
61   LIB_PATH="-L$BUILD_DIR/src/.libs"
62   CXX="../../gcc/g++ -B../../gcc/"
63 elif [ $WHICH -eq 1 ]; then
64   LIB_PATH="-L$PREFIX_DIR/lib"
65   CXX="$PREFIX_DIR/bin/g++"
66 fi
67
68 # gcc compiler flags
69 #CXX_FLAG="-fsquangle -fhonor-std -fnew-exceptions -g -O2 -DDEBUG_ASSERT "
70 #CXX_FLAG="-g -O2 -DDEBUG_ASSERT "
71 CXX_FLAG="-g -DDEBUG_ASSERT "
72
73 # a specific flag to force the use of shared libraries, if any
74 SH_FLAG=
75
76 # a specific flag to force the use of static libraries, if any
77 ST_FLAG="-static"
78
79 # Set up the testing directory, which should be in a directory called
80 # "testsuite" in the root level of the build directory.
81 TEST_DIR="`pwd`/testsuite"
82 if [ ! -d "$TEST_DIR" ]; then
83     echo "making directory $TEST_DIR"
84     mkdir $TEST_DIR
85     chmod 777 $TEST_DIR
86 fi
87
88 # the name of the file that will collect and hold all this useful data:
89 RESULTS_FILE="$TEST_DIR/$(date +%Y%m%d)-mkcheck.txt"
90
91 # the name of the log file that will append compiler diagnostics:
92 LOG_FILE="$TEST_DIR/$(date +%Y%m%d)-mkchecklog.txt"
93
94 # the names of the specific test files to be run
95 TESTS_FILE="$TEST_DIR/$(date +%Y%m%d)-mkcheckfiles.txt"
96
97
98 #
99 # 2: clean, make files, append general test info
100 #
101 if [ -f $RESULTS_FILE ]; then
102     rm $RESULTS_FILE
103 fi
104 if [ -f $LOG_FILE ]; then
105     rm $LOG_FILE
106 fi
107
108 # Make a list of the files we're going to run, or use an old one if it exists.
109 if [ ! -f "$TESTS_FILE" ]; then
110     echo "making file $TESTS_FILE"
111     for LONG_NAME in $SRC_DIR/testsuite/*/*.cc
112     do
113         DIR_NAME=$(dirname $LONG_NAME)
114         SHORT_NAME="`basename $DIR_NAME`/`basename $LONG_NAME`"
115         echo "$SHORT_NAME" >> $TESTS_FILE
116     done
117 fi
118
119 # Nasty solution to replace GNU date(1)'s %s time_t output function.
120 if [ ! -x "$TEST_DIR/printnow" ]; then
121     echo "making utility $TEST_DIR/printnow"
122     gcc -o "$TEST_DIR/printnow" "$SRC_DIR/testsuite/printnow.c"
123     strip "$TEST_DIR/printnow"
124 fi
125
126 # Remove old executables.
127 rm -rf "$TEST_DIR/*exe"
128 rm -rf "$TEST_DIR/core" "$TEST_DIR/*core"
129
130 # Copy over the data files for filebufs in read-only mode
131 cp $SRC_DIR/testsuite/27_io/*.txt $TEST_DIR
132 cp $SRC_DIR/testsuite/27_io/*.tst $TEST_DIR
133
134 # Emit useful info about compiler and platform
135 echo "host: $(uname -mrsv)" >> $RESULTS_FILE
136 echo "compiler: $(g++ --version)" >> $RESULTS_FILE
137 echo "compiler flags: $CXX_FLAG $ST_FLAG" >> $RESULTS_FILE
138 echo "date: $(date +%Y%m%d)" >> $RESULTS_FILE
139 echo "" >> $RESULTS_FILE
140
141 echo "p == pass/fail execution test" >> $RESULTS_FILE
142 echo "ctime == time to compile and link" >> $RESULTS_FILE
143 echo "etime == time for executable to run (take with salt)" >> $RESULTS_FILE
144 echo "text == size of the executable text section" >> $RESULTS_FILE
145 echo "data == size of the executable data section" >> $RESULTS_FILE
146 echo "total == size of the executable" >> $RESULTS_FILE
147 echo "" >> $RESULTS_FILE
148
149 echo "p" | awk '{printf("%s ", $1)}' >> $RESULTS_FILE
150 echo "ctime" "etime" | awk '{printf("%s\t%s\t", $1, $2)}' >> $RESULTS_FILE
151 echo "text" "data" | awk '{printf("%s\t%s\t", $1, $2)}' >> $RESULTS_FILE
152 echo "total" "name" | awk '{printf("%s\t%s\t", $1, $2)}' >> $RESULTS_FILE
153 echo "" >> $RESULTS_FILE
154     
155
156 #
157 # 3: compile, link, execute, time
158 #
159 for NAME in `cat $TESTS_FILE`
160 do
161     echo "$NAME"
162     PRE_NAME="$TEST_DIR/`basename $NAME`"
163     ST_NAME="`echo $PRE_NAME | sed 's/cc$/st-exe/'`"
164     SH_NAME="`echo $PRE_NAME | sed 's/cc$/sh-exe/'`"
165     CNAME="$SRC_DIR/testsuite/$NAME"
166
167     # This would be deliciously easy if GNU date's %s were always around.
168     # There are three ways to do this:  1) use the builtin 'time' like we
169     # do later; then getting compiler errors into LOG_FILE is a nightmare.
170     # 2) Grab the output of a formatted date(1) and do the math; harder
171     # and harder as we try compiling at, say, top of the hour; we would
172     # eventually have to calculate time_t anyhow.  Or 3) just grab two
173     # time_t's (no more overhead than grabbing two date(1)'s).
174     COMP_TIME_START=$($TEST_DIR/printnow)
175     $CXX $CXX_FLAG $ST_FLAG $INC_PATH $LIB_PATH $CNAME \
176          -o $ST_NAME 2>> $LOG_FILE
177     COMP_TIME_END=$($TEST_DIR/printnow)
178
179     if [ $COMP_TIME_START -lt $COMP_TIME_END ]; then
180         C_TIME=$[ $COMP_TIME_END - $COMP_TIME_START ]
181     else
182         C_TIME="0"
183     fi
184
185     if [ -f $ST_NAME ]; then
186         case @host_os@ in
187           *solaris*)
188             # These numbers seem to match up to text/data/total,
189             # although their meanings seem to be different.  Very
190             # important to not compare these numbers across platforms.
191             ST_TEXT="$(size $ST_NAME | awk '{print $1}')"
192             ST_DATA="$(size $ST_NAME | awk '{print $3}')"
193             ST_SIZE="$(size $ST_NAME | awk '{print $7}')"
194             ;;
195           *)
196             ST_TEXT="$(size -A $ST_NAME | grep text | awk '{print $2}')"
197             ST_DATA="$(size -A $ST_NAME | grep data | awk '{print $2}')"
198             ST_SIZE="$(size -A $ST_NAME | grep otal | awk '{print $2}')"
199             ;;
200         esac
201
202         # Actually run the executable and time it . . .
203         TIMEFORMAT='timemark %R'
204         E_TIME_TEXT="$(exec 2>&1; time $ST_NAME)"
205         E_TIME="$(echo $E_TIME_TEXT | awk '{print $2}')"
206         # joining those two commands does not work due to quoting problems:
207         #E_TIME="$(exec 2>&1; time $ST_NAME | awk '{print $2}')"
208         # this will work as a fallback on certain systems...?
209         #E_TIME=$(exec 2>&1; time $ST_NAME | cut -d ' ' -f 2)
210  
211         if [ -f core ]; then
212             ST_EXEC='-'
213             echo "st_fail" | awk '{printf("\t%s\n", $1)}'
214             rm core
215         else
216             # XXX this should probably be a function? 
217
218             # This checks for emitted output files, which is useful
219             # when testing file-related output. The rules for this
220             # working are as follows: the emitted file must have the
221             # ".txt" extension, and be based on the actual *.cc file's
222             # name. For example, 27/filbuf.cc currently outputs files
223             # named 27/filebuf-2.txt and 27/filebuf-3.txt. Also, the first
224             # emitted file must be in the form $NAME-1.txt. The
225             # control file must follow the same constraints, but have
226             # a ".tst" extension. Thus, you have 27/filebuf-2.tst, etc
227             # etc.
228
229             # NAME contains the source name, like 27/filebuf.cc
230             # From that NAME, we want to generate some possible names, using
231             # ls on MATCH, a pattern description generated with sed.
232
233             # this is the name of the resulting diff file, if any
234             DIFF_FILE="`echo $PRE_NAME | sed 's/cc$/diff/'`"
235             # construct wildcard names,ie for $NAME=filebuf.cc, makes
236             # "filebuf*.tst"
237             ST_DATA_FILES="`echo $NAME | sed 's/\.cc/\*\.tst/g'`"
238             # make sure there is at least one, then go
239             ST_E="`echo $NAME | sed 's/\.cc/\-1\.tst/g'`"
240             if [ -f $ST_E ]; then
241                 # list of actual files that match the wildcard above, ie
242                 # "filebuf-1.tst"
243                 ST_MATCH_LIST="`ls $ST_DATA_FILES`"
244                 for i in $ST_MATCH_LIST
245                     do
246                         # ST_OUT_FILE is generated in the build directory.
247                         PRE_NAME2="$TEST_DIR/`basename $i`"
248                         ST_OUT_FILE="`echo $PRE_NAME2 | sed 's/tst$/txt/'`"
249                         diff $ST_OUT_FILE $i > $DIFF_FILE
250                         if [ -s $DIFF_FILE ]; then
251                             ST_EXEC="-"
252                             echo "st_fail" | awk '{printf("\t%s\n", $1)}'
253                             echo "$ST_OUT_FILE has some problems, dude"
254                         else
255                             ST_EXEC="+"
256                             echo "st_pass" | awk '{printf("\t%s\n", $1)}'
257                         fi
258                         rm $DIFF_FILE
259                     done
260                 else
261                     # the file does no output, and didn't core, so
262                     # assume passed.
263                     ST_EXEC="+"
264                     echo "st_pass" | awk '{printf("\t%s\t", $1)}'
265                 fi
266             fi
267         rm "$ST_NAME"
268     else
269         # the file did not compile. Write out compilation info to the log file.
270         echo "$CXX $CXX_FLAG $ST_FLAG $INC_PATH $LIB_PATH $CNAME -o $ST_NAME" \
271         2>> $LOG_FILE
272
273         ST_EXEC="-"
274         echo "st_fail" | awk '{printf("\t%s\t", $1)}'
275         ST_TEXT="0"
276         ST_DATA="0"
277         ST_SIZE="0"
278     fi
279
280     echo $ST_EXEC | awk '{printf ("%.1s ", $1)}'>>$RESULTS_FILE
281     echo $C_TIME $E_TIME |awk '{printf("%d\t%.3f\t", $1, $2)}'>>$RESULTS_FILE
282     echo $ST_TEXT $ST_DATA | awk '{printf("%s\t%s\t", $1, $2)}'>>$RESULTS_FILE
283     echo $ST_SIZE | awk '{printf("%s\t", $1)}'>>$RESULTS_FILE
284     echo $NAME | awk '{printf("%s\n", $1)}'>>$RESULTS_FILE
285
286     echo "" >> $RESULTS_FILE
287     echo ""
288 done
289
290 # grep can count faster than we can...
291 total_failures=$(egrep -c "^\-" $RESULTS_FILE)
292 total_successes=$(egrep -c "^\+" $RESULTS_FILE)
293 resultstext="pass/fail results:  ${total_successes}/${total_failures}"
294 if [ $total_failures -eq 0 ]; then
295     resultstext="${resultstext}, WIN WIN"
296 fi
297 sed -e "/^date:/a\\
298 $resultstext" $RESULTS_FILE > ${RESULTS_FILE}.tmp
299 mv ${RESULTS_FILE}.tmp $RESULTS_FILE
300
301 exit 0
302