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