]> Cypherpunks.ru repositories - gostls13.git/blob - src/run.bash
[dev.garbage] all: merge dev.cc (493ad916c3b1) into dev.garbage
[gostls13.git] / src / run.bash
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 -gcflags "$GO_GCFLAGS"
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 xcd() {
68         echo
69         echo '#' $1
70         builtin cd "$GOROOT"/src/$1 || exit 1
71 }
72
73 # NOTE: "set -e" cannot help us in subshells. It works until you test it with ||.
74 #
75 #       $ bash --version
76 #       GNU bash, version 3.2.48(1)-release (x86_64-apple-darwin12)
77 #       Copyright (C) 2007 Free Software Foundation, Inc.
78 #
79 #       $ set -e; (set -e; false; echo still here); echo subshell exit status $?
80 #       subshell exit status 1
81 #       # subshell stopped early, set exit status, but outer set -e didn't stop.
82 #
83 #       $ set -e; (set -e; false; echo still here) || echo stopped
84 #       still here
85 #       # somehow the '|| echo stopped' broke the inner set -e.
86 #       
87 # To avoid this bug, every command in a subshell should have '|| exit 1' on it.
88 # Strictly speaking, the test may be unnecessary on the final command of
89 # the subshell, but it aids later editing and may avoid future bash bugs.
90
91 if [ "$GOOS" == "android" ]; then
92         # Disable cgo tests on android.
93         # They are not designed to run off the host.
94         # golang.org/issue/8345
95         CGO_ENABLED=0
96 fi
97
98 [ "$CGO_ENABLED" != 1 ] ||
99 [ "$GOHOSTOS" == windows ] ||
100 (xcd ../misc/cgo/stdio
101 go run $GOROOT/test/run.go - . || exit 1
102 ) || exit $?
103
104 [ "$CGO_ENABLED" != 1 ] ||
105 (xcd ../misc/cgo/life
106 go run $GOROOT/test/run.go - . || exit 1
107 ) || exit $?
108
109 [ "$CGO_ENABLED" != 1 ] ||
110 (xcd ../misc/cgo/test
111 # cgo tests inspect the traceback for runtime functions
112 extlink=0
113 export GOTRACEBACK=2
114 go test -ldflags '-linkmode=auto' || exit 1
115 # linkmode=internal fails on dragonfly since errno is a TLS relocation.
116 [ "$GOHOSTOS" == dragonfly ] || go test -ldflags '-linkmode=internal' || exit 1
117 case "$GOHOSTOS-$GOARCH" in
118 openbsd-386 | openbsd-amd64)
119         # test linkmode=external, but __thread not supported, so skip testtls.
120         go test -ldflags '-linkmode=external' || exit 1
121         extlink=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         *)
129                 go test -ldflags '-linkmode=external'  || exit 1
130                 extlink=1
131                 ;;
132         esac
133         ;;
134 android-arm | dragonfly-386 | dragonfly-amd64 | freebsd-386 | freebsd-amd64 | freebsd-arm | linux-386 | linux-amd64 | linux-arm | netbsd-386 | netbsd-amd64)
135         go test -ldflags '-linkmode=external' || exit 1
136         go test -ldflags '-linkmode=auto' ../testtls || exit 1
137         go test -ldflags '-linkmode=external' ../testtls || exit 1
138         extlink=1
139         
140         case "$GOHOSTOS-$GOARCH" in
141         netbsd-386 | netbsd-amd64) ;; # no static linking
142         freebsd-arm) ;; # -fPIC compiled tls code will use __tls_get_addr instead
143                         # of __aeabi_read_tp, however, on FreeBSD/ARM, __tls_get_addr
144                         # is implemented in rtld-elf, so -fPIC isn't compatible with
145                         # static linking on FreeBSD/ARM with clang. (cgo depends on
146                         # -fPIC fundamentally.)
147         *)
148                 if ! $CC -xc -o /dev/null -static - 2>/dev/null <<<'int main() {}' ; then
149                         echo "No support for static linking found (lacks libc.a?), skip cgo static linking test."
150                 else
151                         go test -ldflags '-linkmode=external -extldflags "-static -pthread"' ../testtls || exit 1
152                         go test ../nocgo || exit 1
153                         go test -ldflags '-linkmode=external' ../nocgo || exit 1
154                         go test -ldflags '-linkmode=external -extldflags "-static -pthread"' ../nocgo || exit 1
155                 fi
156                 ;;
157         esac
158         ;;
159 esac
160 ) || exit $?
161
162 # Race detector only supported on Linux, FreeBSD and OS X,
163 # and only on amd64, and only when cgo is enabled.
164 # Delayed until here so we know whether to try external linking.
165 # DISABLED until we get garbage collection working.
166 case "$GOHOSTOS-$GOOS-$GOARCH-$CGO_ENABLED-XXX-DISABLED" in
167 linux-linux-amd64-1 | freebsd-freebsd-amd64-1 | darwin-darwin-amd64-1)
168         echo
169         echo '# Testing race detector.'
170         go test -race -i runtime/race flag os/exec
171         go test -race -run=Output runtime/race
172         go test -race -short flag os/exec
173         
174         # Test with external linking; see issue 9133.
175         if [ "$extlink" = 1 ]; then
176                 go test -race -short -ldflags=-linkmode=external flag os/exec
177         fi
178 esac
179
180 # This tests cgo -cdefs. That mode is not supported,
181 # so it's okay if it doesn't work on some systems.
182 # In particular, it works badly with clang on OS X.
183 # It doesn't work at all now that we disallow C code
184 # outside runtime. Once runtime has no C code it won't
185 # even be necessary.
186 # [ "$CGO_ENABLED" != 1 ] || [ "$GOOS" == darwin ] ||
187 # (xcd ../misc/cgo/testcdefs
188 # ./test.bash || exit 1
189 # ) || exit $?
190
191 [ "$CGO_ENABLED" != 1 ] || [ "$GOOS" == darwin ] ||
192 (xcd ../misc/cgo/testgodefs
193 ./test.bash || exit 1
194 ) || exit $?
195
196 [ "$CGO_ENABLED" != 1 ] ||
197 [ "$GOHOSTOS" == windows ] ||
198 (xcd ../misc/cgo/testso
199 ./test.bash || exit 1
200 ) || exit $?
201
202 [ "$CGO_ENABLED" != 1 ] ||
203 [ "$GOHOSTOS-$GOARCH" != linux-amd64 ] ||
204 (xcd ../misc/cgo/testasan
205 go run main.go || exit 1
206 ) || exit $?
207
208 [ "$CGO_ENABLED" != 1 ] ||
209 [ "$GOHOSTOS" == windows ] ||
210 (xcd ../misc/cgo/errors
211 ./test.bash || exit 1
212 ) || exit $?
213
214 [ "$GOOS" == nacl ] ||
215 [ "$GOOS" == android ] ||
216 (xcd ../doc/progs
217 time ./run || exit 1
218 ) || exit $?
219
220 [ "$GOOS" == android ] ||
221 [ "$GOOS" == nacl ] ||
222 [ "$GOARCH" == arm ] ||  # uses network, fails under QEMU
223 (xcd ../doc/articles/wiki
224 ./test.bash || exit 1
225 ) || exit $?
226
227 [ "$GOOS" == android ] ||
228 [ "$GOOS" == nacl ] ||
229 (xcd ../doc/codewalk
230 time ./run || exit 1
231 ) || exit $?
232
233 [ "$GOOS" == nacl ] ||
234 [ "$GOARCH" == arm ] ||
235 (xcd ../test/bench/shootout
236 time ./timing.sh -test || exit 1
237 ) || exit $?
238
239 [ "$GOOS" == android ] || # TODO(crawshaw): get this working
240 [ "$GOOS" == openbsd ] || # golang.org/issue/5057
241 (
242 echo
243 echo '#' ../test/bench/go1
244 go test ../test/bench/go1 || exit 1
245 ) || exit $?
246
247 [ "$GOOS" == android ] ||
248 (xcd ../test
249 unset GOMAXPROCS
250 GOOS=$GOHOSTOS GOARCH=$GOHOSTARCH go build -o runtest run.go || exit 1
251 time ./runtest || exit 1
252 rm -f runtest
253 ) || exit $?
254
255 [ "$GOOS" == android ] ||
256 [ "$GOOS" == nacl ] ||
257 (
258 echo
259 echo '# SKIPPING API CHECK UNTIL ALL SYSTEMS BUILD.'
260 # time go run $GOROOT/src/cmd/api/run.go || exit 1
261 ) || exit $?
262
263 echo
264 echo ALL TESTS PASSED