]> Cypherpunks.ru repositories - gostls13.git/blob - src/run.bash
runtime/race: add end-to-end test
[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
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 go test -ldflags '-linkmode=internal' || exit 1
108 case "$GOHOSTOS-$GOARCH" in
109 openbsd-386 | openbsd-amd64)
110         # test linkmode=external, but __thread not supported, so skip testtls.
111         go test -ldflags '-linkmode=external' || exit 1
112         ;;
113 darwin-386 | darwin-amd64)
114         # linkmode=external fails on OS X 10.6 and earlier == Darwin
115         # 10.8 and earlier.
116         case $(uname -r) in
117         [0-9].* | 10.*) ;;
118         *) go test -ldflags '-linkmode=external'  || exit 1;;
119         esac
120         ;;
121 freebsd-386 | freebsd-amd64 | linux-386 | linux-amd64 | netbsd-386 | netbsd-amd64)
122         go test -ldflags '-linkmode=external' || exit 1
123         go test -ldflags '-linkmode=auto' ../testtls || exit 1
124         go test -ldflags '-linkmode=external' ../testtls || exit 1
125 esac
126 ) || exit $?
127
128 # This tests cgo -godefs. That mode is not supported,
129 # so it's okay if it doesn't work on some systems.
130 # In particular, it works badly with clang on OS X.
131 [ "$CGO_ENABLED" != 1 ] || [ "$GOOS" == darwin ] ||
132 (xcd ../misc/cgo/testcdefs
133 ./test.bash || exit 1
134 ) || exit $?
135
136 [ "$CGO_ENABLED" != 1 ] ||
137 [ "$GOHOSTOS" == windows ] ||
138 (xcd ../misc/cgo/testso
139 ./test.bash || exit 1
140 ) || exit $?
141
142 [ "$CGO_ENABLED" != 1 ] ||
143 [ "$GOHOSTOS-$GOARCH" != linux-amd64 ] ||
144 (xcd ../misc/cgo/testasan
145 go run main.go || exit 1
146 ) || exit $?
147
148 (xcd ../doc/progs
149 time ./run || exit 1
150 ) || exit $?
151
152 [ "$GOARCH" == arm ] ||  # uses network, fails under QEMU
153 (xcd ../doc/articles/wiki
154 make clean || exit 1
155 ./test.bash || exit 1
156 ) || exit $?
157
158 (xcd ../doc/codewalk
159 time ./run || exit 1
160 ) || exit $?
161
162 echo
163 echo '#' ../misc/goplay
164 go build ../misc/goplay
165 rm -f goplay
166
167 [ "$GOARCH" == arm ] ||
168 (xcd ../test/bench/shootout
169 ./timing.sh -test || exit 1
170 ) || exit $?
171
172 [ "$GOOS" == openbsd ] || # golang.org/issue/5057
173 (
174 echo
175 echo '#' ../test/bench/go1
176 go test ../test/bench/go1 || exit 1
177 ) || exit $?
178
179 (xcd ../test
180 unset GOMAXPROCS
181 time go run run.go || exit 1
182 ) || exit $?
183
184 echo
185 echo '# Checking API compatibility.'
186 time go run $GOROOT/src/cmd/api/run.go
187
188 echo
189 echo ALL TESTS PASSED