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