github.com/yanyiwu/go@v0.0.0-20150106053140-03d6637dbb7f/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 # TODO(adg): create an environment variable and to permit the builders to 51 # specify the timeout scale. 52 timeout_scale=1 53 # the freebsd-* builders are slow, and there's no easy way to make them faster. 54 [ "$GOOS" == "freebsd" ] && timeout_scale=2 55 # increase timeout for ARM up to 3 times the normal value 56 [ "$GOARCH" == "arm" ] && timeout_scale=3 57 58 echo '##### Testing packages.' 59 time go test std -short -timeout=$(expr 120 \* $timeout_scale)s -gcflags "$GO_GCFLAGS" 60 echo 61 62 # We set GOMAXPROCS=2 in addition to -cpu=1,2,4 in order to test runtime bootstrap code, 63 # creation of first goroutines and first garbage collections in the parallel setting. 64 echo '##### GOMAXPROCS=2 runtime -cpu=1,2,4' 65 GOMAXPROCS=2 go test runtime -short -timeout=$(expr 300 \* $timeout_scale)s -cpu=1,2,4 66 echo 67 68 echo '##### sync -cpu=10' 69 go test sync -short -timeout=$(expr 120 \* $timeout_scale)s -cpu=10 70 71 xcd() { 72 echo 73 echo '#####' $1 74 builtin cd "$GOROOT"/src/$1 || exit 1 75 } 76 77 # NOTE: "set -e" cannot help us in subshells. It works until you test it with ||. 78 # 79 # $ bash --version 80 # GNU bash, version 3.2.48(1)-release (x86_64-apple-darwin12) 81 # Copyright (C) 2007 Free Software Foundation, Inc. 82 # 83 # $ set -e; (set -e; false; echo still here); echo subshell exit status $? 84 # subshell exit status 1 85 # # subshell stopped early, set exit status, but outer set -e didn't stop. 86 # 87 # $ set -e; (set -e; false; echo still here) || echo stopped 88 # still here 89 # # somehow the '|| echo stopped' broke the inner set -e. 90 # 91 # To avoid this bug, every command in a subshell should have '|| exit 1' on it. 92 # Strictly speaking, the test may be unnecessary on the final command of 93 # the subshell, but it aids later editing and may avoid future bash bugs. 94 95 if [ "$GOOS" == "android" ]; then 96 # Disable cgo tests on android. 97 # They are not designed to run off the host. 98 # golang.org/issue/8345 99 CGO_ENABLED=0 100 fi 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 # cgo tests inspect the traceback for runtime functions 116 extlink=0 117 export GOTRACEBACK=2 118 go test -ldflags '-linkmode=auto' || exit 1 119 # linkmode=internal fails on dragonfly since errno is a TLS relocation. 120 [ "$GOHOSTOS" == dragonfly ] || go test -ldflags '-linkmode=internal' || exit 1 121 case "$GOHOSTOS-$GOARCH" in 122 openbsd-386 | openbsd-amd64) 123 # test linkmode=external, but __thread not supported, so skip testtls. 124 go test -ldflags '-linkmode=external' || exit 1 125 extlink=1 126 ;; 127 darwin-386 | darwin-amd64) 128 # linkmode=external fails on OS X 10.6 and earlier == Darwin 129 # 10.8 and earlier. 130 case $(uname -r) in 131 [0-9].* | 10.*) ;; 132 *) 133 go test -ldflags '-linkmode=external' || exit 1 134 extlink=1 135 ;; 136 esac 137 ;; 138 android-arm | dragonfly-386 | dragonfly-amd64 | freebsd-386 | freebsd-amd64 | freebsd-arm | linux-386 | linux-amd64 | linux-arm | netbsd-386 | netbsd-amd64) 139 go test -ldflags '-linkmode=external' || exit 1 140 go test -ldflags '-linkmode=auto' ../testtls || exit 1 141 go test -ldflags '-linkmode=external' ../testtls || exit 1 142 extlink=1 143 144 case "$GOHOSTOS-$GOARCH" in 145 netbsd-386 | netbsd-amd64) ;; # no static linking 146 freebsd-arm) ;; # -fPIC compiled tls code will use __tls_get_addr instead 147 # of __aeabi_read_tp, however, on FreeBSD/ARM, __tls_get_addr 148 # is implemented in rtld-elf, so -fPIC isn't compatible with 149 # static linking on FreeBSD/ARM with clang. (cgo depends on 150 # -fPIC fundamentally.) 151 *) 152 if ! $CC -xc -o /dev/null -static - 2>/dev/null <<<'int main() {}' ; then 153 echo "No support for static linking found (lacks libc.a?), skip cgo static linking test." 154 else 155 go test -ldflags '-linkmode=external -extldflags "-static -pthread"' ../testtls || exit 1 156 go test ../nocgo || exit 1 157 go test -ldflags '-linkmode=external' ../nocgo || exit 1 158 go test -ldflags '-linkmode=external -extldflags "-static -pthread"' ../nocgo || exit 1 159 fi 160 ;; 161 esac 162 ;; 163 esac 164 ) || exit $? 165 166 # Race detector only supported on Linux, FreeBSD and OS X, 167 # and only on amd64, and only when cgo is enabled. 168 # Delayed until here so we know whether to try external linking. 169 case "$GOHOSTOS-$GOOS-$GOARCH-$CGO_ENABLED" in 170 linux-linux-amd64-1 | freebsd-freebsd-amd64-1 | darwin-darwin-amd64-1) 171 echo 172 echo '##### Testing race detector.' 173 go test -race -i runtime/race flag os/exec 174 go test -race -run=Output runtime/race 175 go test -race -short flag os/exec 176 177 # Test with external linking; see issue 9133. 178 if [ "$extlink" = 1 ]; then 179 go test -race -short -ldflags=-linkmode=external flag os/exec 180 fi 181 esac 182 183 # This tests cgo -cdefs. That mode is not supported, 184 # so it's okay if it doesn't work on some systems. 185 # In particular, it works badly with clang on OS X. 186 # It doesn't work at all now that we disallow C code 187 # outside runtime. Once runtime has no C code it won't 188 # even be necessary. 189 # [ "$CGO_ENABLED" != 1 ] || [ "$GOOS" == darwin ] || 190 # (xcd ../misc/cgo/testcdefs 191 # ./test.bash || exit 1 192 # ) || exit $? 193 194 [ "$CGO_ENABLED" != 1 ] || [ "$GOOS" == darwin ] || 195 (xcd ../misc/cgo/testgodefs 196 ./test.bash || exit 1 197 ) || exit $? 198 199 [ "$CGO_ENABLED" != 1 ] || 200 [ "$GOHOSTOS" == windows ] || 201 (xcd ../misc/cgo/testso 202 ./test.bash || exit 1 203 ) || exit $? 204 205 [ "$CGO_ENABLED" != 1 ] || 206 [ "$GOHOSTOS-$GOARCH" != linux-amd64 ] || 207 (xcd ../misc/cgo/testasan 208 go run main.go || exit 1 209 ) || exit $? 210 211 [ "$CGO_ENABLED" != 1 ] || 212 [ "$GOHOSTOS" == windows ] || 213 (xcd ../misc/cgo/errors 214 ./test.bash || exit 1 215 ) || exit $? 216 217 [ "$GOOS" == nacl ] || 218 [ "$GOOS" == android ] || 219 (xcd ../doc/progs 220 time ./run || exit 1 221 ) || exit $? 222 223 [ "$GOOS" == android ] || 224 [ "$GOOS" == nacl ] || 225 [ "$GOARCH" == arm ] || # uses network, fails under QEMU 226 (xcd ../doc/articles/wiki 227 ./test.bash || exit 1 228 ) || exit $? 229 230 [ "$GOOS" == android ] || 231 [ "$GOOS" == nacl ] || 232 (xcd ../doc/codewalk 233 time ./run || exit 1 234 ) || exit $? 235 236 [ "$GOOS" == nacl ] || 237 [ "$GOARCH" == arm ] || 238 (xcd ../test/bench/shootout 239 time ./timing.sh -test || exit 1 240 ) || exit $? 241 242 [ "$GOOS" == android ] || # TODO(crawshaw): get this working 243 [ "$GOOS" == openbsd ] || # golang.org/issue/5057 244 ( 245 echo 246 echo '#####' ../test/bench/go1 247 go test ../test/bench/go1 || exit 1 248 ) || exit $? 249 250 [ "$GOOS" == android ] || 251 (xcd ../test 252 unset GOMAXPROCS 253 GOOS=$GOHOSTOS GOARCH=$GOHOSTARCH go build -o runtest run.go || exit 1 254 time ./runtest || exit 1 255 rm -f runtest 256 ) || exit $? 257 258 [ "$GOOS" == android ] || 259 [ "$GOOS" == nacl ] || 260 ( 261 echo 262 time go run $GOROOT/src/cmd/api/run.go || exit 1 263 ) || exit $? 264 265 echo 266 echo ALL TESTS PASSED