github.com/ader1990/go@v0.0.0-20140630135419-8c24447fa791/src/run.bash (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  set -e
     7  
     8  eval $(go env)
     9  export GOROOT   # the api test requires GOROOT to be set.
    10  
    11  unset CDPATH	# in case user has it set
    12  unset GOPATH    # we disallow local import for non-local packages, if $GOROOT happens
    13                  # to be under $GOPATH, then some tests below will fail
    14  
    15  # no core files, please
    16  ulimit -c 0
    17  
    18  # Raise soft limits to hard limits for NetBSD/OpenBSD.
    19  # We need at least 256 files and ~300 MB of bss.
    20  # On OS X ulimit -S -n rejects 'unlimited'.
    21  #
    22  # Note that ulimit -S -n may fail if ulimit -H -n is set higher than a
    23  # non-root process is allowed to set the high limit.
    24  # This is a system misconfiguration and should be fixed on the
    25  # broken system, not "fixed" by ignoring the failure here.
    26  # See longer discussion on golang.org/issue/7381. 
    27  [ "$(ulimit -H -n)" == "unlimited" ] || ulimit -S -n $(ulimit -H -n)
    28  [ "$(ulimit -H -d)" == "unlimited" ] || ulimit -S -d $(ulimit -H -d)
    29  
    30  # Thread count limit on NetBSD 7.
    31  if ulimit -T &> /dev/null; then
    32  	[ "$(ulimit -H -T)" == "unlimited" ] || ulimit -S -T $(ulimit -H -T)
    33  fi
    34  
    35  # allow all.bash to avoid double-build of everything
    36  rebuild=true
    37  if [ "$1" == "--no-rebuild" ]; then
    38  	shift
    39  else
    40  	echo '# Building packages and commands.'
    41  	time go install -a -v std
    42  	echo
    43  fi
    44  
    45  # we must unset GOROOT_FINAL before tests, because runtime/debug requires
    46  # correct access to source code, so if we have GOROOT_FINAL in effect,
    47  # at least runtime/debug test will fail.
    48  unset GOROOT_FINAL
    49  
    50  # increase timeout for ARM up to 3 times the normal value
    51  timeout_scale=1
    52  [ "$GOARCH" == "arm" ] && timeout_scale=3
    53  
    54  echo '# Testing packages.'
    55  time go test std -short -timeout=$(expr 120 \* $timeout_scale)s
    56  echo
    57  
    58  # We set GOMAXPROCS=2 in addition to -cpu=1,2,4 in order to test runtime bootstrap code,
    59  # creation of first goroutines and first garbage collections in the parallel setting.
    60  echo '# GOMAXPROCS=2 runtime -cpu=1,2,4'
    61  GOMAXPROCS=2 go test runtime -short -timeout=$(expr 300 \* $timeout_scale)s -cpu=1,2,4
    62  echo
    63  
    64  echo '# sync -cpu=10'
    65  go test sync -short -timeout=$(expr 120 \* $timeout_scale)s -cpu=10
    66  
    67  # Race detector only supported on Linux and OS X,
    68  # and only on amd64, and only when cgo is enabled.
    69  case "$GOHOSTOS-$GOOS-$GOARCH-$CGO_ENABLED" in
    70  linux-linux-amd64-1 | darwin-darwin-amd64-1)
    71  	echo
    72  	echo '# Testing race detector.'
    73  	go test -race -i runtime/race flag
    74  	go test -race -run=Output runtime/race
    75  	go test -race -short flag
    76  esac
    77  
    78  xcd() {
    79  	echo
    80  	echo '#' $1
    81  	builtin cd "$GOROOT"/src/$1 || exit 1
    82  }
    83  
    84  # NOTE: "set -e" cannot help us in subshells. It works until you test it with ||.
    85  #
    86  #	$ bash --version
    87  #	GNU bash, version 3.2.48(1)-release (x86_64-apple-darwin12)
    88  #	Copyright (C) 2007 Free Software Foundation, Inc.
    89  #
    90  #	$ set -e; (set -e; false; echo still here); echo subshell exit status $?
    91  #	subshell exit status 1
    92  #	# subshell stopped early, set exit status, but outer set -e didn't stop.
    93  #
    94  #	$ set -e; (set -e; false; echo still here) || echo stopped
    95  #	still here
    96  #	# somehow the '|| echo stopped' broke the inner set -e.
    97  #	
    98  # To avoid this bug, every command in a subshell should have '|| exit 1' on it.
    99  # Strictly speaking, the test may be unnecessary on the final command of
   100  # the subshell, but it aids later editing and may avoid future bash bugs.
   101  
   102  [ "$CGO_ENABLED" != 1 ] ||
   103  [ "$GOHOSTOS" == windows ] ||
   104  (xcd ../misc/cgo/stdio
   105  go run $GOROOT/test/run.go - . || exit 1
   106  ) || exit $?
   107  
   108  [ "$CGO_ENABLED" != 1 ] ||
   109  (xcd ../misc/cgo/life
   110  go run $GOROOT/test/run.go - . || exit 1
   111  ) || exit $?
   112  
   113  [ "$CGO_ENABLED" != 1 ] ||
   114  (xcd ../misc/cgo/test
   115  go test -ldflags '-linkmode=auto' || exit 1
   116  # linkmode=internal fails on dragonfly since errno is a TLS relocation.
   117  [ "$GOHOSTOS" == dragonfly ] || go test -ldflags '-linkmode=internal' || exit 1
   118  case "$GOHOSTOS-$GOARCH" in
   119  openbsd-386 | openbsd-amd64)
   120  	# test linkmode=external, but __thread not supported, so skip testtls.
   121  	go test -ldflags '-linkmode=external' || exit 1
   122  	;;
   123  darwin-386 | darwin-amd64)
   124  	# linkmode=external fails on OS X 10.6 and earlier == Darwin
   125  	# 10.8 and earlier.
   126  	case $(uname -r) in
   127  	[0-9].* | 10.*) ;;
   128  	*) go test -ldflags '-linkmode=external'  || exit 1;;
   129  	esac
   130  	;;
   131  dragonfly-386 | dragonfly-amd64 | freebsd-386 | freebsd-amd64 | freebsd-arm | linux-386 | linux-amd64 | linux-arm | netbsd-386 | netbsd-amd64)
   132  	go test -ldflags '-linkmode=external' || exit 1
   133  	go test -ldflags '-linkmode=auto' ../testtls || exit 1
   134  	go test -ldflags '-linkmode=external' ../testtls || exit 1
   135  	
   136  	case "$GOHOSTOS-$GOARCH" in
   137  	netbsd-386 | netbsd-amd64) ;; # no static linking
   138  	freebsd-arm) ;; # -fPIC compiled tls code will use __tls_get_addr instead
   139  	                # of __aeabi_read_tp, however, on FreeBSD/ARM, __tls_get_addr
   140  	                # is implemented in rtld-elf, so -fPIC isn't compatible with
   141  	                # static linking on FreeBSD/ARM with clang. (cgo depends on
   142  			# -fPIC fundamentally.)
   143  	*)
   144  		if ! $CC -xc -o /dev/null -static - 2>/dev/null <<<'int main() {}' ; then
   145  			echo "No support for static linking found (lacks libc.a?), skip cgo static linking test."
   146  		else
   147  			go test -ldflags '-linkmode=external -extldflags "-static -pthread"' ../testtls || exit 1
   148  			go test ../nocgo || exit 1
   149  			go test -ldflags '-linkmode=external' ../nocgo || exit 1
   150  			go test -ldflags '-linkmode=external -extldflags "-static -pthread"' ../nocgo || exit 1
   151  		fi
   152  		;;
   153  	esac
   154  	;;
   155  esac
   156  ) || exit $?
   157  
   158  # This tests cgo -godefs. That mode is not supported,
   159  # so it's okay if it doesn't work on some systems.
   160  # In particular, it works badly with clang on OS X.
   161  [ "$CGO_ENABLED" != 1 ] || [ "$GOOS" == darwin ] ||
   162  (xcd ../misc/cgo/testcdefs
   163  ./test.bash || exit 1
   164  ) || exit $?
   165  
   166  [ "$CGO_ENABLED" != 1 ] ||
   167  [ "$GOHOSTOS" == windows ] ||
   168  (xcd ../misc/cgo/testso
   169  ./test.bash || exit 1
   170  ) || exit $?
   171  
   172  [ "$CGO_ENABLED" != 1 ] ||
   173  [ "$GOHOSTOS-$GOARCH" != linux-amd64 ] ||
   174  (xcd ../misc/cgo/testasan
   175  go run main.go || exit 1
   176  ) || exit $?
   177  
   178  [ "$CGO_ENABLED" != 1 ] ||
   179  [ "$GOHOSTOS" == windows ] ||
   180  (xcd ../misc/cgo/errors
   181  ./test.bash || exit 1
   182  ) || exit $?
   183  
   184  [ "$GOOS" == nacl ] ||
   185  (xcd ../doc/progs
   186  time ./run || exit 1
   187  ) || exit $?
   188  
   189  [ "$GOOS" == nacl ] ||
   190  [ "$GOARCH" == arm ] ||  # uses network, fails under QEMU
   191  (xcd ../doc/articles/wiki
   192  ./test.bash || exit 1
   193  ) || exit $?
   194  
   195  [ "$GOOS" == nacl ] ||
   196  (xcd ../doc/codewalk
   197  time ./run || exit 1
   198  ) || exit $?
   199  
   200  [ "$GOOS" == nacl ] ||
   201  [ "$GOARCH" == arm ] ||
   202  (xcd ../test/bench/shootout
   203  time ./timing.sh -test || exit 1
   204  ) || exit $?
   205  
   206  [ "$GOOS" == openbsd ] || # golang.org/issue/5057
   207  (
   208  echo
   209  echo '#' ../test/bench/go1
   210  go test ../test/bench/go1 || exit 1
   211  ) || exit $?
   212  
   213  (xcd ../test
   214  unset GOMAXPROCS
   215  GOOS=$GOHOSTOS GOARCH=$GOHOSTARCH go build -o runtest run.go || exit 1
   216  time ./runtest || exit 1
   217  rm -f runtest
   218  ) || exit $?
   219  
   220  [ "$GOOS" == nacl ] ||
   221  (
   222  echo
   223  echo '# Checking API compatibility.'
   224  time go run $GOROOT/src/cmd/api/run.go || exit 1
   225  ) || exit $?
   226  
   227  echo
   228  echo ALL TESTS PASSED