1#!/bin/sh
2# Run ACATS with the GNU Ada compiler
3
4# The following functions are to be customized if you run in cross
5# environment or want to change compilation flags.  Note that for
6# tests requiring checks not turned on by default, this script
7# automatically adds the needed flags to pass (ie: -gnato or -gnatE).
8
9# gccflags="-O3 -fomit-frame-pointer -funroll-all-loops -finline-functions"
10# gnatflags="-gnatN"
11
12gccflags="-O2"
13gnatflags="-gnatws"
14
15# End of customization section.
16
17# Perform arithmetic evaluation on the ARGs, and store the result in the
18# global $as_val. Take advantage of shells that can avoid forks. The arguments
19# must be portable across $(()) and expr.
20if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null; then :
21  eval 'as_fn_arith ()
22  {
23    as_val=$(( $* ))
24  }'
25else
26  as_fn_arith ()
27  {
28    as_val=`expr "$@" || test $? -eq 1`
29  }
30fi # as_fn_arith
31
32display_noeol () {
33  printf "$@"
34  printf "$@" >> $dir/acats.sum
35  printf "$@" >> $dir/acats.log
36}
37
38display () {
39  echo "$@"
40  echo "$@" >> $dir/acats.sum
41  echo "$@" >> $dir/acats.log
42}
43
44log () {
45  echo "$@" >> $dir/acats.sum
46  echo "$@" >> $dir/acats.log
47}
48
49dir=`${PWDCMD-pwd}`
50
51if [ "$dir" = "$testdir" ]; then
52  echo "error: srcdir must be different than objdir, exiting."
53  exit 1
54fi
55
56GCC="$BASE/xgcc -B$BASE/"
57
58target_gnatchop () {
59  $BASE/gnatchop --GCC="$BASE/xgcc" $*
60}
61
62target_gnatmake () {
63  echo $BASE/gnatmake --GNATBIND=$BASE/gnatbind --GNATLINK=$BASE/gnatlink --GCC="$GCC" $gnatflags $gccflags $* -largs $EXTERNAL_OBJECTS --GCC="$GCC"
64  $BASE/gnatmake --GNATBIND=$BASE/gnatbind --GNATLINK=$BASE/gnatlink --GCC="$GCC" $gnatflags $gccflags $* -largs $EXTERNAL_OBJECTS --GCC="$GCC"
65}
66
67target_gcc () {
68  $GCC $gccflags $*
69}
70
71target_run () {
72  eval $EXPECT -f $testdir/run_test.exp $*
73}
74
75clean_dir () {
76  rm -f "$binmain" *.o *.ali > /dev/null 2>&1
77}
78
79find_main () {
80  ls ${i}?.adb > ${i}.lst 2> /dev/null
81  ls ${i}*m.adb >> ${i}.lst 2> /dev/null
82  ls ${i}.adb >> ${i}.lst 2> /dev/null
83  main=`tail -1 ${i}.lst`
84}
85
86EXTERNAL_OBJECTS=""
87# Global variable to communicate external objects to link with.
88
89rm -f $dir/acats.sum $dir/acats.log
90
91display "Test Run By $USER on `date`"
92
93display "		=== acats configuration ==="
94
95target=`$GCC -dumpmachine`
96
97display target gcc is $GCC
98display `$GCC -v 2>&1`
99display host=`gcc -dumpmachine`
100display target=$target
101display `type gnatmake`
102gnatls -v >> $dir/acats.log
103display ""
104
105if [ -n "$GCC_RUNTEST_PARALLELIZE_DIR" ]; then
106  dir_support=$dir/../acats/support
107
108  rm -rf $dir/run
109  mv $dir/tests $dir/tests.$$ 2> /dev/null
110  rm -rf $dir/tests.$$ &
111  mkdir -p $dir/run
112
113  cp -pr $dir/../acats/tests $dir/
114else
115  dir_support=$dir/support
116
117display "		=== acats support ==="
118display_noeol "Generating support files..."
119
120rm -rf $dir/support
121mkdir -p $dir/support
122cd $dir/support
123
124cp $testdir/support/*.ada $testdir/support/*.a $testdir/support/*.tst $dir/support
125
126# Find out the size in bit of an address on the target
127target_gnatmake $testdir/support/impbit.adb >> $dir/acats.log 2>&1
128if [ $? -ne 0 ]; then
129   display "**** Failed to compile impbit"
130   exit 1
131fi
132target_run $dir/support/impbit > $dir/support/impbit.out 2>&1
133target_bit=`cat $dir/support/impbit.out`
134echo target_bit="$target_bit" >> $dir/acats.log
135
136case "$target_bit" in
137  *32*)
138    target_max_int="9223372036854775807"
139    target_min_int="-9223372036854775808"
140    ;;
141  *64*)
142    target_max_int="170141183460469231731687303715884105727"
143    target_min_int="-170141183460469231731687303715884105728"
144    ;;
145  *)
146    display "**** Unsupported bits per word"
147    exit 1
148esac
149
150echo target_max_insn="$target_max_int" >> $dir/acats.log
151echo target_min_insn="$target_min_int" >> $dir/acats.log
152
153# Find out a suitable asm statement
154# Adapted from configure.ac gcc_cv_as_dwarf2_debug_line
155case "$target" in
156  ia64*-*-* | s390*-*-*)
157    target_insn="nop 0"
158    ;;
159  mmix-*-*)
160    target_insn="swym 0"
161    ;;
162  *)
163    target_insn="nop"
164    ;;
165esac
166echo target_insn="$target_insn" >> $dir/acats.log
167
168sed -e "s,ACATS4GNATDIR,$dir,g" \
169  < $testdir/support/impdef.a > $dir/support/impdef.a
170sed -e "s,ACATS4GNATDIR,$dir,g" \
171  -e "s,ACATS4GNATBIT,$target_bit,g" \
172  -e "s,ACATS4GNATINSN,$target_insn,g" \
173  -e "s,ACATS4GNATMAXINT,$target_max_int,g" \
174  -e "s,ACATS4GNATMININT,$target_min_int,g" \
175  < $testdir/support/macro.dfs > $dir/support/MACRO.DFS
176sed -e "s,ACATS4GNATDIR,$dir,g" \
177  < $testdir/support/tsttests.dat > $dir/support/TSTTESTS.DAT
178
179cp $testdir/tests/cd/*.c $dir/support
180cp $testdir/tests/cxb/*.c $dir/support
181grep -v '^#' $testdir/norun.lst | sort > $dir/support/norun.lst
182
183rm -rf $dir/run
184mv $dir/tests $dir/tests.$$ 2> /dev/null
185rm -rf $dir/tests.$$ &
186mkdir -p $dir/run
187
188cp -pr $testdir/tests $dir/
189
190for i in $dir/support/*.ada $dir/support/*.a; do
191   host_gnatchop $i >> $dir/acats.log 2>&1
192done
193
194# These tools are used to preprocess some ACATS sources
195# they need to be compiled native on the host.
196
197host_gnatmake -q -gnatws macrosub.adb
198if [ $? -ne 0 ]; then
199   display "**** Failed to compile macrosub"
200   exit 1
201fi
202./macrosub > macrosub.out 2>&1
203
204gcc -c cd300051.c
205host_gnatmake -q -gnatws widechr.adb
206if [ $? -ne 0 ]; then
207   display "**** Failed to compile widechr"
208   exit 1
209fi
210./widechr > widechr.out 2>&1
211
212rm -f $dir/support/macrosub
213rm -f $dir/support/widechr
214rm -f $dir/support/*.ali
215rm -f $dir/support/*.o
216
217display " done."
218
219# From here, all compilations will be made by the target compiler
220
221display_noeol "Compiling support files..."
222
223target_gcc -c *.c
224if [ $? -ne 0 ]; then
225   display "**** Failed to compile C code"
226   exit 1
227fi
228
229target_gnatchop *.adt >> $dir/acats.log 2>&1
230
231target_gnatmake -c -gnato -gnatE *.ads >> $dir/acats.log 2>&1
232target_gnatmake -c -gnato -gnatE *.adb >> $dir/acats.log 2>&1
233
234display " done."
235display ""
236
237fi
238
239display "		=== acats tests ==="
240
241if [ $# -eq 0 ]; then
242   chapters=`cd $dir/tests; echo [a-z]*`
243else
244   chapters=$*
245fi
246
247glob_countn=0
248glob_countok=0
249glob_countu=0
250par_count=0
251par_countm=0
252par_last=
253
254for chapter in $chapters; do
255   # Used to generate support once and finish after that.
256   [ "$chapter" = "NONE" ] && continue
257
258   display Running chapter $chapter ...
259
260   if [ ! -d $dir/tests/$chapter ]; then
261      display "*** CHAPTER $chapter does not exist, skipping."
262      display ""
263      continue
264   fi
265
266   cd $dir/tests/$chapter
267   ls *.a *.ada *.adt *.am *.dep 2> /dev/null | sed -e 's/\(.*\)\..*/\1/g' | \
268   cut -c1-7 | sort | uniq | comm -23 - $dir_support/norun.lst \
269     > $dir/tests/$chapter/${chapter}.lst
270   countn=`wc -l < $dir/tests/$chapter/${chapter}.lst`
271   as_fn_arith $glob_countn + $countn
272   glob_countn=$as_val
273   for i in `cat $dir/tests/$chapter/${chapter}.lst`; do
274
275      # If running multiple run_all.sh jobs in parallel, decide
276      # if we should run this test in the current instance.
277      if [ -n "$GCC_RUNTEST_PARALLELIZE_DIR" ]; then
278	 case "$i" in
279	    # Ugh, some tests have inter-test dependencies, those
280	    # tests have to be scheduled on the same parallel instance
281	    # as previous test.
282	    ce2108f | ce2108h | ce3112d) ;;
283	    # All others can be hopefully scheduled freely.
284	    *)
285	       as_fn_arith $par_countm + 1
286	       par_countm=$as_val
287	       [ $par_countm -eq 10 ] && par_countm=0
288	       if [ $par_countm -eq 1 ]; then
289		  as_fn_arith $par_count + 1
290		  par_count=$as_val
291		  if mkdir $GCC_RUNTEST_PARALLELIZE_DIR/$par_count 2>/dev/null; then
292		     par_last=1
293		  else
294		     par_last=
295		  fi
296	       fi;;
297	 esac
298	 if [ -z "$par_last" ]; then
299	    as_fn_arith $glob_countn - 1
300	    glob_countn=$as_val
301	    continue
302	 fi
303      fi
304
305      extraflags="-gnat95"
306      grep $i $testdir/overflow.lst > /dev/null 2>&1
307      if [ $? -eq 0 ]; then
308         extraflags="$extraflags -gnato"
309      fi
310      grep $i $testdir/elabd.lst > /dev/null 2>&1
311      if [ $? -eq 0 ]; then
312         extraflags="$extraflags -gnatE"
313      fi
314      grep $i $testdir/floatstore.lst > /dev/null 2>&1
315      if [ $? -eq 0 ]; then
316         extraflags="$extraflags -ffloat-store"
317      fi
318      grep $i $testdir/stackcheck.lst > /dev/null 2>&1
319      if [ $? -eq 0 ]; then
320         extraflags="$extraflags -fstack-check"
321      fi
322      test=$dir/tests/$chapter/$i
323      mkdir $test && cd $test >> $dir/acats.log 2>&1
324
325      if [ $? -ne 0 ]; then
326         display "FAIL:	$i"
327         failed="${failed}${i} "
328         clean_dir
329         continue
330      fi
331
332      target_gnatchop -c -w `ls ${test}*.a ${test}*.ada ${test}*.adt ${test}*.am ${test}*.dep 2> /dev/null` >> $dir/acats.log 2>&1
333      main=""
334      find_main
335      if [ -z "$main" ]; then
336         sync
337         find_main
338      fi
339      binmain=`echo $main | sed -e 's/\(.*\)\..*/\1/g'`
340      echo "BUILD $main" >> $dir/acats.log
341      EXTERNAL_OBJECTS=""
342      case $i in
343        cxb30*) EXTERNAL_OBJECTS="$dir_support/cxb30040.o $dir_support/cxb30060.o $dir_support/cxb30130.o $dir_support/cxb30131.o";;
344        ca1020e) rm -f ca1020e_func1.adb ca1020e_func2.adb ca1020e_proc1.adb ca1020e_proc2.adb > /dev/null 2>&1;;
345        ca14028) rm -f ca14028_func2.ads ca14028_func3.ads ca14028_proc1.ads ca14028_proc3.ads > /dev/null 2>&1;;
346      esac
347      if [ "$main" = "" ]; then
348         display "FAIL:	$i"
349         failed="${failed}${i} "
350         clean_dir
351         continue
352      fi
353
354      target_gnatmake $extraflags -I$dir_support $main >> $dir/acats.log 2>&1
355      if [ $? -ne 0 ]; then
356         display "FAIL:	$i"
357         failed="${failed}${i} "
358         clean_dir
359         continue
360      fi
361
362      echo "RUN $binmain" >> $dir/acats.log
363      cd $dir/run
364      if [ ! -x $dir/tests/$chapter/$i/$binmain ]; then
365         sync
366      fi
367      target_run $dir/tests/$chapter/$i/$binmain > $dir/tests/$chapter/$i/${i}.log 2>&1
368      cd $dir/tests/$chapter/$i
369      cat ${i}.log >> $dir/acats.log
370      egrep -e '(==== |\+\+\+\+ |\!\!\!\! )' ${i}.log > /dev/null 2>&1
371      if [ $? -ne 0 ]; then
372         grep 'tasking not implemented' ${i}.log > /dev/null 2>&1
373
374         if [ $? -ne 0 ]; then
375            display "FAIL:	$i"
376            failed="${failed}${i} "
377         else
378            log "UNSUPPORTED:	$i"
379            as_fn_arith $glob_countn - 1
380            glob_countn=$as_val
381            as_fn_arith $glob_countu + 1
382            glob_countu=$as_val
383         fi
384      else
385         log "PASS:	$i"
386         as_fn_arith $glob_countok + 1
387         glob_countok=$as_val
388      fi
389      clean_dir
390   done
391done
392
393display "		=== acats Summary ==="
394display "# of expected passes		$glob_countok"
395display "# of unexpected failures	`expr $glob_countn - $glob_countok`"
396
397if [ $glob_countu -ne 0 ]; then
398   display "# of unsupported tests		$glob_countu"
399fi
400
401if [ $glob_countok -ne $glob_countn ]; then
402   display "*** FAILURES: $failed"
403fi
404
405display "$0 completed at `date`"
406
407exit 0
408