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