Home | History | Annotate | Download | only in test
      1 #!/bin/bash
      2 # //===--------------------------- testit ---------------------------------===//
      3 # //
      4 # //                     The LLVM Compiler Infrastructure
      5 # //
      6 # // This file is distributed under the University of Illinois Open Source
      7 # // License. See LICENSE.TXT for details.
      8 # //
      9 # //===--------------------------------------------------------------------===//
     10 
     11 if [ -z $CXX ]
     12 then
     13 	CXX=clang++
     14 fi
     15 
     16 if [ -z "$OPTIONS" ]
     17 then
     18 	OPTIONS="-std=c++0x -stdlib=libc++"
     19 fi
     20 
     21 if [ -z "$QEMU" ]
     22 then
     23     QEMU=qemu-system-arm
     24 fi
     25 
     26 case $TRIPLE in
     27   *-*-mingw* | *-*-cygwin* | *-*-win*)
     28     TEST_EXE_SUFFIX=.exe
     29     ;;
     30   *)
     31     TEST_EXE_SUFFIX=.out
     32     ;;
     33 esac
     34 
     35 FAIL=0
     36 PASS=0
     37 UNIMPLEMENTED=0
     38 IMPLEMENTED_FAIL=0
     39 IMPLEMENTED_PASS=0
     40 
     41 function compile
     42 {
     43   echo "  [COMPILE] $1"
     44   echo $CXX $OPTIONS $HEADER_INCLUDE $SOURCE_LIB $LIBS -o $1$TEST_EXE_SUFFIX $1 test_wrapper.cc
     45   $CXX $OPTIONS $HEADER_INCLUDE $SOURCE_LIB $LIBS -o $1$TEST_EXE_SUFFIX $1 test_wrapper.cc
     46 }
     47 
     48 function run
     49 {
     50   echo "  [RUN    ] $1"
     51   case $TRIPLE in
     52     armv4-none-eabi)
     53       echo $QEMU -semihosting -M integratorcp -cpu arm1026 -kernel $1
     54       $QEMU -semihosting -M integratorcp -cpu arm1026 -kernel $1 | awk 'BEGIN { f=0; } /PASS/ { next } /FAIL/ { f=1; print; next } { print } END { exit f }'
     55       ;;
     56     thumbv4t-none-eabi)
     57       echo $QEMU -semihosting -M integratorcp -cpu arm926 -kernel $1
     58       $QEMU -semihosting -M integratorcp -cpu arm1026 -kernel $1 | awk 'BEGIN { f=0; } /PASS/ { next } /FAIL/ { f=1; print; next } { print } END { exit f }'
     59       ;;
     60     thumbv6m-none-eabi)
     61       echo $QEMU -semihosting -M integratorcp -cpu cortex-m3 -kernel $1
     62       $QEMU -semihosting -M integratorcp -cpu cortex-m3 -kernel $1 | awk 'BEGIN { f=0; } /PASS/ { next } /FAIL/ { f=1; print; next } { print } END { exit f }'
     63       ;;
     64     thumbv7t-none-eabi)
     65       echo $QEMU -semihosting -M integratorcp -cpu cortex-a8 -kernel $1
     66       $QEMU -semihosting -M integratorcp -cpu cortex-a8 -kernel $1 | awk 'BEGIN { f=0; } /PASS/ { next } /FAIL/ { f=1; print; next } { print } END { exit f }'
     67       ;;
     68     *)
     69       $1
     70       ;;
     71   esac
     72 }
     73 
     74 function afunc
     75 {
     76 	fail=0
     77 	pass=0
     78 	if (ls *.fail.cpp &> /dev/null)
     79 	then
     80 		for FILE in $(ls *.fail.cpp); do
     81 			if compile $FILE &> /dev/null
     82 			then
     83 				rm $FILE$TEST_EXE_SUFFIX
     84 				echo "  [FAIL   ] $FILE should not compile"
     85 				let "fail+=1"
     86 			else
     87 				let "pass+=1"
     88 			fi
     89 		done
     90 	fi
     91 
     92 	if (ls *.cpp &> /dev/null)
     93 	then
     94 		for FILE in $(ls *.cpp); do
     95 			if compile $FILE
     96 			then
     97 				if run $FILE$TEST_EXE_SUFFIX
     98 				then
     99 					let "pass+=1"
    100 				else
    101 					echo "  [FAIL   ] $FILE failed at run time"
    102 					let "fail+=1"
    103 				fi
    104 			else
    105 				echo "  [FAIL   ] $FILE failed to compile"
    106 				let "fail+=1"
    107 			fi
    108 		done
    109 	fi
    110 
    111 	if [ $fail -gt 0 ]
    112 	then
    113 		echo "failed $fail tests in `pwd`"
    114 		let "IMPLEMENTED_FAIL+=1"
    115 	fi
    116 	if [ $pass -gt 0 ]
    117 	then
    118 		echo "passed $pass tests in `pwd`"
    119 		if [ $fail -eq 0 ]
    120 		then
    121 			let "IMPLEMENTED_PASS+=1"
    122 		fi
    123 	fi
    124 	if [ $fail -eq 0 -a $pass -eq 0 ]
    125 	then
    126 		echo "not implemented:  `pwd`"
    127 		let "UNIMPLEMENTED+=1"
    128 	fi
    129 
    130 	let "FAIL+=$fail"
    131 	let "PASS+=$pass"
    132 
    133 	for FILE in *
    134 	do
    135 		if [ -d "$FILE" ];
    136 		then
    137 			cd $FILE
    138 			afunc
    139 			cd ..
    140 		fi
    141 	done
    142 }
    143 
    144 afunc
    145 
    146 echo "****************************************************"
    147 echo "Results for `pwd`:"
    148 echo "using `$CXX --version`"
    149 echo "with $OPTIONS $HEADER_INCLUDE $SOURCE_LIB"
    150 echo "----------------------------------------------------"
    151 echo "sections without tests   : $UNIMPLEMENTED"
    152 echo "sections with failures   : $IMPLEMENTED_FAIL"
    153 echo "sections without failures: $IMPLEMENTED_PASS"
    154 echo "                       +   ----"
    155 echo "total number of sections : $(($UNIMPLEMENTED+$IMPLEMENTED_FAIL+$IMPLEMENTED_PASS))"
    156 echo "----------------------------------------------------"
    157 echo "number of tests failed   : $FAIL"
    158 echo "number of tests passed   : $PASS"
    159 echo "                       +   ----"
    160 echo "total number of tests    : $(($FAIL+$PASS))"
    161 echo "****************************************************"
    162 
    163 exit $FAIL
    164