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.
10 # invocation == mkcheck [01] (path to build) (path to src) (path to install)
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)'
17 echo "running mkcheck"
22 # WHICH determines if you are testing the installed binary and headers, or
23 # the build binary and headers.
25 if [ $WHICH != "1" ]; then
27 echo "$0: testing the build directory"
28 elif [ $WHICH -eq 1 ]; then
29 echo "$0: testing the install directory $1"
33 if [ ! -d "$BUILD_DIR" ]; then
34 echo "build directory $BUILD_DIR not found, exiting."
39 if [ ! -d "$SRC_DIR" ]; then
40 echo "source directory $SRC_DIR not found, exiting."
44 if [ $WHICH -eq 1 ]; then
46 if [ ! -d "$PREFIX_DIR" ]; then
47 echo "install directory $PREFIX_DIR not found, exiting."
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
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++"
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 "
73 # a specific flag to force the use of shared libraries, if any
76 # a specific flag to force the use of static libraries, if any
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"
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"
91 # the name of the log file that will append compiler diagnostics:
92 LOG_FILE="$TEST_DIR/$(date +%Y%m%d)-mkchecklog.txt"
94 # the names of the specific test files to be run
95 TESTS_FILE="$TEST_DIR/$(date +%Y%m%d)-mkcheckfiles.txt"
99 # 2: clean, make files, append general test info
101 if [ -f $RESULTS_FILE ]; then
104 if [ -f $LOG_FILE ]; then
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
113 DIR_NAME=$(dirname $LONG_NAME)
114 SHORT_NAME="`basename $DIR_NAME`/`basename $LONG_NAME`"
115 echo "$SHORT_NAME" >> $TESTS_FILE
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"
126 # Remove old executables.
127 rm -rf "$TEST_DIR/*exe"
128 rm -rf "$TEST_DIR/core" "$TEST_DIR/*core"
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
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
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
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
157 # 3: compile, link, execute, time
159 for NAME in `cat $TESTS_FILE`
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"
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)
179 if [ $COMP_TIME_START -lt $COMP_TIME_END ]; then
180 C_TIME=$[ $COMP_TIME_END - $COMP_TIME_START ]
185 if [ -f $ST_NAME ]; then
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}')"
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}')"
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)
213 echo "st_fail" | awk '{printf("\t%s\n", $1)}'
216 # XXX this should probably be a function?
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
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.
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
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
243 ST_MATCH_LIST="`ls $ST_DATA_FILES`"
244 for i in $ST_MATCH_LIST
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
252 echo "st_fail" | awk '{printf("\t%s\n", $1)}'
253 echo "$ST_OUT_FILE has some problems, dude"
256 echo "st_pass" | awk '{printf("\t%s\n", $1)}'
261 # the file does no output, and didn't core, so
264 echo "st_pass" | awk '{printf("\t%s\t", $1)}'
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" \
274 echo "st_fail" | awk '{printf("\t%s\t", $1)}'
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
286 echo "" >> $RESULTS_FILE
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"
298 $resultstext" $RESULTS_FILE > ${RESULTS_FILE}.tmp
299 mv ${RESULTS_FILE}.tmp $RESULTS_FILE