github.com/xushiwei/go@v0.0.0-20130601165731-2b9d83f45bc9/test/run (about)

     1  #!/usr/bin/env bash
     2  # Copyright 2009 The Go Authors. All rights reserved.
     3  # Use of this source code is governed by a BSD-style
     4  # license that can be found in the LICENSE file.
     5  
     6  eval $(go tool dist env)
     7  export GOARCH GOOS GOROOT
     8  export E=
     9  
    10  case X"$GOARCH" in
    11  Xamd64)
    12  	export A=6
    13  	;;
    14  X386)
    15  	export A=8
    16  	;;
    17  Xarm)
    18  	export A=5
    19  	export E="$GORUN"
    20  	;;
    21  *)
    22  	echo 1>&2 run: unsupported '$GOARCH'
    23  	exit 1
    24  esac
    25  
    26  export G="${A}g ${GCFLAGS}"
    27  export L=${A}l
    28  export GOTRACEBACK=0
    29  export LANG=C
    30  unset GREP_OPTIONS	# in case user has a non-standard set
    31  
    32  unset GOROOT_FINAL  # breaks ./ imports
    33  
    34  failed=0
    35  
    36  PATH=${GOBIN:-$GOROOT/bin}:`pwd`:/bin:/usr/bin:/usr/local/bin
    37  
    38  # TODO: We add the tool directory to the PATH to avoid thinking about a better way.
    39  PATH="$GOTOOLDIR:$PATH"
    40  
    41  RUNFILE="${TMPDIR:-/tmp}/gorun-$$-$USER"
    42  TMP1FILE="${TMPDIR:-/tmp}/gotest1-$$-$USER"
    43  TMP2FILE="${TMPDIR:-/tmp}/gotest2-$$-$USER"
    44  
    45  # don't run the machine out of memory: limit individual processes to 4GB.
    46  # on thresher, 3GB suffices to run the tests; with 2GB, peano fails.
    47  ulimit -v 4000000
    48  
    49  # no core files please
    50  ulimit -c 0
    51  
    52  true >pass.out >times.out
    53  
    54  exclude=false	# exclude nothing
    55  golden=golden.out
    56  
    57  rm -f tmp.go  # generated by some tests, left behind if interrupted
    58  
    59  filterout() {
    60  	grep '^'"$2"'$' $1 >/dev/null
    61  }
    62  
    63  for dir in . ken chan interface syntax dwarf safe fixedbugs bugs
    64  do
    65  	echo
    66  	echo '==' $dir'/'
    67  	for i in $(ls $dir/*.go 2>/dev/null)
    68  	do (
    69  		if $exclude $i; then
    70  			exit 0  # continues for loop
    71  		fi
    72  		export F=$(basename $i .go)
    73  		export D=$dir
    74  		echo '. ./testlib' >"$RUNFILE"
    75  		sed '/^\/\//!q' $i | sed 's@//@@; $d' |sed 's|./\$A.out|$E &|g' >>"$RUNFILE"
    76  		if ! { time -p bash -c "bash '$RUNFILE' >'$TMP1FILE' 2>&1" ; } 2>"$TMP2FILE"
    77  		then
    78  			echo
    79  			echo "===========" $i
    80  			cat "$TMP1FILE"
    81  			echo >&2 fail: $i
    82  			echo "# $i	# fail" >>pass.out
    83  		elif test -s "$TMP1FILE"
    84  		then
    85  			echo
    86  			echo "===========" $i
    87  			cat "$TMP1FILE"
    88  			if grep -q '^BUG' "$TMP1FILE"
    89  			then
    90  				if [ $dir != bugs ]
    91  				then
    92  					echo >&2 bug: $i
    93  				fi
    94  				echo "# $i	# fail, BUG" >>pass.out
    95  			else
    96  				echo $i >>pass.out
    97  			fi
    98  		elif [ $dir = "bugs" ]
    99  		then
   100  			echo $i succeeded with no output.
   101  		else
   102  			echo $i >>pass.out
   103  		fi
   104  		echo $(awk 'NR==1{print $2}' "$TMP2FILE") $D/$F >>times.out
   105  		rm -f $F.$A $A.out tmp.go
   106  	) done
   107  done | # clean up some stack noise
   108  	egrep -v '^(r[0-9a-z]+|[cfg]s)  +0x'  |
   109  	sed '/tmp.*Bus error/s/.*Bus/Bus/; /tmp.*Trace.BPT/s/.*Trace/Trace/
   110  		s!'"$RUNFILE"'!$RUNFILE!g
   111  		s/^PC=0x[0-9a-f]*/pc: xxx/
   112  		s/^pc: 0x[0-9a-f]*/pc: xxx/
   113  		s/PC=0x[0-9a-f]*/PC=xxx/
   114  		/^Trace\/breakpoint trap/d
   115  		/^Trace\/BPT trap/d
   116  		/RUNFILE/ s/line 1: *[0-9]*/line 1: PID/
   117  		/^\$RUNFILE: line 1: PID Trace\/breakpoint trap/d
   118  		/Segmentation fault/d
   119  		/^qemu: uncaught target signal 11 (Segmentation fault) - exiting/d' > run.out
   120  
   121  rm -f "$RUNFILE" "$TMP1FILE" "$TMP2FILE" *.$A *.a $A.out
   122  diffmsg=""
   123  if ! diff $golden run.out
   124  then
   125  	diffmsg="; test output differs"
   126  	failed=1
   127  fi
   128  
   129  notinbugs=$(sed '/^== bugs/q' run.out | grep -c '^BUG')
   130  inbugs=$(sed '1,/^== bugs/d' run.out | grep -c '^BUG')
   131  
   132  echo 2>&1 $inbugs known bugs';' $notinbugs unexpected bugs$diffmsg
   133  
   134  if [ "$failed" != "0" ]; then
   135  	echo FAILED
   136  fi
   137  
   138  exit $failed