blob: 876b5d757d4a92240a45da8598217550e6787945 [file] [log] [blame]
Devon H. O'Dell553be842009-11-14 15:29:09 -08001#!/usr/bin/env bash
Russ Coxbbb00c62008-10-08 09:46:54 -07002# 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
6set -e
7
Shenghou Ma6d4da062012-03-10 03:42:23 +08008eval $(go env)
Shenghou Ma6f3f2d02014-04-29 14:43:10 -04009export GOROOT # the api test requires GOROOT to be set.
Russ Cox82905362012-02-04 00:54:08 -050010
Russ Cox69fd2a42010-03-31 19:48:33 -070011unset CDPATH # in case user has it set
Shenghou Ma23322ab2012-03-21 00:47:27 +080012unset GOPATH # we disallow local import for non-local packages, if $GOROOT happens
13 # to be under $GOPATH, then some tests below will fail
Devon H. O'Dell857d4cf2009-12-11 15:14:09 -080014
Russ Coxda776792009-11-09 23:11:36 -080015# no core files, please
16ulimit -c 0
17
Shenghou Ma329b27a2012-09-17 01:11:28 +080018# 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'.
Russ Coxe6e89452014-02-24 16:44:35 -050021#
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.
Shenghou Ma329b27a2012-09-17 01:11:28 +080027[ "$(ulimit -H -n)" == "unlimited" ] || ulimit -S -n $(ulimit -H -n)
Shenghou Maa1a414e2012-09-17 01:26:57 +080028[ "$(ulimit -H -d)" == "unlimited" ] || ulimit -S -d $(ulimit -H -d)
Shenghou Ma329b27a2012-09-17 01:11:28 +080029
Benny Siegert8a4efed2013-06-17 19:31:58 +100030# Thread count limit on NetBSD 7.
31if ulimit -T &> /dev/null; then
32 [ "$(ulimit -H -T)" == "unlimited" ] || ulimit -S -T $(ulimit -H -T)
33fi
34
Russ Cox82905362012-02-04 00:54:08 -050035# allow all.bash to avoid double-build of everything
Russ Cox69fd2a42010-03-31 19:48:33 -070036rebuild=true
37if [ "$1" = "--no-rebuild" ]; then
Russ Cox69fd2a42010-03-31 19:48:33 -070038 shift
Russ Cox82905362012-02-04 00:54:08 -050039else
40 echo '# Building packages and commands.'
41 time go install -a -v std
42 echo
Russ Cox69fd2a42010-03-31 19:48:33 -070043fi
Russ Cox82905362012-02-04 00:54:08 -050044
Shenghou Ma34ace102012-04-04 23:14:54 +080045# 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.
48unset GOROOT_FINAL
49
Shenghou Ma0a517e42013-03-24 16:31:28 +080050# increase timeout for ARM up to 3 times the normal value
51timeout_scale=1
52[ "$GOARCH" == "arm" ] && timeout_scale=3
53
Russ Cox82905362012-02-04 00:54:08 -050054echo '# Testing packages.'
Shenghou Ma0a517e42013-03-24 16:31:28 +080055time go test std -short -timeout=$(expr 120 \* $timeout_scale)s
Russ Cox82905362012-02-04 00:54:08 -050056echo
57
Dmitriy Vyukov13045842014-03-06 13:16:14 +040058# 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.
Rémy Oudomphengaa1aaee2012-03-05 16:40:27 -050060echo '# GOMAXPROCS=2 runtime -cpu=1,2,4'
Shenghou Ma0ce56e602013-07-13 02:00:07 +080061GOMAXPROCS=2 go test runtime -short -timeout=$(expr 300 \* $timeout_scale)s -cpu=1,2,4
Russ Cox82905362012-02-04 00:54:08 -050062echo
63
64echo '# sync -cpu=10'
Shenghou Ma0a517e42013-03-24 16:31:28 +080065go test sync -short -timeout=$(expr 120 \* $timeout_scale)s -cpu=10
Russ Cox82905362012-02-04 00:54:08 -050066
Russ Cox6d888f12013-02-15 13:37:43 -080067# Race detector only supported on Linux and OS X,
68# and only on amd64, and only when cgo is enabled.
Shenghou Maeec96142013-02-23 20:24:38 +080069case "$GOHOSTOS-$GOOS-$GOARCH-$CGO_ENABLED" in
Rémy Oudompheng475e7d02014-02-19 08:19:27 +010070linux-linux-amd64-1 | darwin-darwin-amd64-1)
Dmitriy Vyukov95329d42012-11-01 22:02:52 +040071 echo
72 echo '# Testing race detector.'
Dmitriy Vyukov2791ef02013-08-12 22:04:10 +040073 go test -race -i runtime/race flag
74 go test -race -run=Output runtime/race
Dmitriy Vyukov95329d42012-11-01 22:02:52 +040075 go test -race -short flag
76esac
77
Russ Coxbbb00c62008-10-08 09:46:54 -070078xcd() {
Ken Thompsonb379d542008-10-24 20:14:28 -070079 echo
Russ Coxc3f43192012-03-06 23:27:30 -050080 echo '#' $1
Russ Cox3a8845b2013-07-11 23:24:57 -040081 builtin cd "$GOROOT"/src/$1 || exit 1
Russ Coxbbb00c62008-10-08 09:46:54 -070082}
83
Russ Cox3a8845b2013-07-11 23:24:57 -040084# NOTE: "set -e" cannot help us in subshells. It works until you test it with ||.
85#
86# $ bash --version
87# GNU bash, version 3.2.48(1)-release (x86_64-apple-darwin12)
88# Copyright (C) 2007 Free Software Foundation, Inc.
89#
90# $ set -e; (set -e; false; echo still here); echo subshell exit status $?
91# subshell exit status 1
92# # subshell stopped early, set exit status, but outer set -e didn't stop.
93#
94# $ set -e; (set -e; false; echo still here) || echo stopped
95# still here
96# # somehow the '|| echo stopped' broke the inner set -e.
97#
98# To avoid this bug, every command in a subshell should have '|| exit 1' on it.
99# Strictly speaking, the test may be unnecessary on the final command of
100# the subshell, but it aids later editing and may avoid future bash bugs.
101
Russ Coxc0242392011-08-10 21:36:48 -0400102[ "$CGO_ENABLED" != 1 ] ||
Alex Brainman642c7742011-02-09 12:37:08 +1100103[ "$GOHOSTOS" == windows ] ||
Russ Cox2d72b392009-10-03 11:33:51 -0700104(xcd ../misc/cgo/stdio
Russ Cox3a8845b2013-07-11 23:24:57 -0400105go run $GOROOT/test/run.go - . || exit 1
Russ Cox2d72b392009-10-03 11:33:51 -0700106) || exit $?
107
Russ Coxc0242392011-08-10 21:36:48 -0400108[ "$CGO_ENABLED" != 1 ] ||
Russ Cox0cd34752010-12-17 09:51:55 -0800109(xcd ../misc/cgo/life
Russ Cox3a8845b2013-07-11 23:24:57 -0400110go run $GOROOT/test/run.go - . || exit 1
Russ Cox0cd34752010-12-17 09:51:55 -0800111) || exit $?
112
Russ Coxc0242392011-08-10 21:36:48 -0400113[ "$CGO_ENABLED" != 1 ] ||
Russ Coxec713d62011-03-11 15:09:32 -0500114(xcd ../misc/cgo/test
Russ Cox3a8845b2013-07-11 23:24:57 -0400115go test -ldflags '-linkmode=auto' || exit 1
Aulus Egnatius Varialus2b44b362013-09-04 15:19:21 -0700116# linkmode=internal fails on dragonfly since errno is a TLS relocation.
117[ "$GOHOSTOS" == dragonfly ] || go test -ldflags '-linkmode=internal' || exit 1
Russ Cox3b85b722013-03-11 00:51:42 -0400118case "$GOHOSTOS-$GOARCH" in
Ian Lance Taylor3197be42013-03-29 16:33:35 -0700119openbsd-386 | openbsd-amd64)
Ian Lance Taylor30e29ee2013-03-27 13:27:35 -0700120 # test linkmode=external, but __thread not supported, so skip testtls.
Russ Cox3a8845b2013-07-11 23:24:57 -0400121 go test -ldflags '-linkmode=external' || exit 1
Ian Lance Taylor30e29ee2013-03-27 13:27:35 -0700122 ;;
Ian Lance Taylor3197be42013-03-29 16:33:35 -0700123darwin-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.*) ;;
Russ Cox3a8845b2013-07-11 23:24:57 -0400128 *) go test -ldflags '-linkmode=external' || exit 1;;
Ian Lance Taylor3197be42013-03-29 16:33:35 -0700129 esac
130 ;;
Shenghou Mad31d1972014-04-21 00:08:59 -0400131dragonfly-386 | dragonfly-amd64 | freebsd-386 | freebsd-amd64 | freebsd-arm | linux-386 | linux-amd64 | linux-arm | netbsd-386 | netbsd-amd64)
Russ Cox3a8845b2013-07-11 23:24:57 -0400132 go test -ldflags '-linkmode=external' || exit 1
133 go test -ldflags '-linkmode=auto' ../testtls || exit 1
134 go test -ldflags '-linkmode=external' ../testtls || exit 1
Russ Cox568e3522014-04-15 15:52:02 -0400135
Shenghou Ma560471f2014-04-15 23:54:04 -0400136 case "$GOHOSTOS-$GOARCH" in
Russ Cox568e3522014-04-15 15:52:02 -0400137 netbsd-386 | netbsd-amd64) ;; # no static linking
Shenghou Mad31d1972014-04-21 00:08:59 -0400138 freebsd-arm) ;; # -fPIC compiled tls code will use __tls_get_addr instead
139 # of __aeabi_read_tp, however, on FreeBSD/ARM, __tls_get_addr
140 # is implemented in rtld-elf, so -fPIC isn't compatible with
141 # static linking on FreeBSD/ARM with clang. (cgo depends on
142 # -fPIC fundamentally.)
Russ Cox568e3522014-04-15 15:52:02 -0400143 *)
Shenghou Ma6f3f2d02014-04-29 14:43:10 -0400144 if ! $CC -xc -o /dev/null -static - 2>/dev/null <<<'int main() {}' ; then
145 echo "No support for static linking found (lacks libc.a?), skip cgo static linking test."
146 else
147 go test -ldflags '-linkmode=external -extldflags "-static -pthread"' ../testtls || exit 1
148 fi
Russ Cox568e3522014-04-15 15:52:02 -0400149 ;;
150 esac
151 ;;
Russ Cox3b85b722013-03-11 00:51:42 -0400152esac
Russ Coxec713d62011-03-11 15:09:32 -0500153) || exit $?
154
Russ Cox2ddb6722013-08-02 14:58:27 -0400155# This tests cgo -godefs. That mode is not supported,
156# so it's okay if it doesn't work on some systems.
157# In particular, it works badly with clang on OS X.
158[ "$CGO_ENABLED" != 1 ] || [ "$GOOS" == darwin ] ||
Kevin Kluesf7dfeea2013-07-24 17:27:42 -0700159(xcd ../misc/cgo/testcdefs
160./test.bash || exit 1
161) || exit $?
162
163[ "$CGO_ENABLED" != 1 ] ||
Dmitriy Vyukov11e73b82011-11-22 17:57:49 +0300164[ "$GOHOSTOS" == windows ] ||
Dmitriy Vyukov11e73b82011-11-22 17:57:49 +0300165(xcd ../misc/cgo/testso
Russ Cox3a8845b2013-07-11 23:24:57 -0400166./test.bash || exit 1
Dmitriy Vyukov11e73b82011-11-22 17:57:49 +0300167) || exit $?
168
Dmitriy Vyukova8ad8592013-06-12 18:47:16 +0400169[ "$CGO_ENABLED" != 1 ] ||
170[ "$GOHOSTOS-$GOARCH" != linux-amd64 ] ||
171(xcd ../misc/cgo/testasan
Russ Cox3a8845b2013-07-11 23:24:57 -0400172go run main.go || exit 1
Dmitriy Vyukova8ad8592013-06-12 18:47:16 +0400173) || exit $?
174
Ian Lance Taylorf68c23e2013-09-03 21:15:15 -0700175[ "$CGO_ENABLED" != 1 ] ||
176[ "$GOHOSTOS" == windows ] ||
177(xcd ../misc/cgo/errors
178./test.bash || exit 1
179) || exit $?
180
Rob Pike8d210042009-01-06 15:49:27 -0800181(xcd ../doc/progs
Russ Cox3a8845b2013-07-11 23:24:57 -0400182time ./run || exit 1
Rob Pike8d210042009-01-06 15:49:27 -0800183) || exit $?
184
Russ Cox6b335712011-03-27 23:39:42 -0400185[ "$GOARCH" == arm ] || # uses network, fails under QEMU
Shenghou Ma90010f82012-03-08 06:23:56 +0800186(xcd ../doc/articles/wiki
Russ Cox3a8845b2013-07-11 23:24:57 -0400187./test.bash || exit 1
Alex Brainman3bfd35b2011-01-31 15:58:44 +1100188) || exit $?
Andrew Gerrandadd4e162011-01-26 14:56:52 +1000189
Rob Pike6492cac2012-03-26 16:08:21 +1100190(xcd ../doc/codewalk
Andrew Gerrandfc32bfa2013-07-30 09:42:53 +1000191time ./run || exit 1
Rob Pike6492cac2012-03-26 16:08:21 +1100192) || exit $?
193
Shenghou Ma90010f82012-03-08 06:23:56 +0800194echo
Andrew Gerrand5f1af162013-08-01 13:49:00 +1000195echo '#' ../misc/goplay
196go build ../misc/goplay
Brad Fitzpatrick74d2e092013-08-02 19:14:13 -0700197rm -f goplay
Andrew Gerrand06492d42010-10-21 10:46:10 +1100198
Russ Coxb7cb8442010-09-22 15:30:42 +1000199[ "$GOARCH" == arm ] ||
Russ Coxbcbb2f92011-12-13 17:46:54 -0500200(xcd ../test/bench/shootout
Rémy Oudompheng475e7d02014-02-19 08:19:27 +0100201time ./timing.sh -test || exit 1
Rob Pike266a2c42009-08-09 14:31:05 -0700202) || exit $?
203
Russ Coxa5b26232013-03-15 12:39:14 -0400204[ "$GOOS" == openbsd ] || # golang.org/issue/5057
205(
Shenghou Ma90010f82012-03-08 06:23:56 +0800206echo
207echo '#' ../test/bench/go1
Russ Cox3a8845b2013-07-11 23:24:57 -0400208go test ../test/bench/go1 || exit 1
Russ Coxa5b26232013-03-15 12:39:14 -0400209) || exit $?
Russ Cox6e887552011-12-15 12:32:59 -0500210
Russ Coxbbb00c62008-10-08 09:46:54 -0700211(xcd ../test
Dave Cheneyfa21df32012-11-15 13:59:46 +1100212unset GOMAXPROCS
Russ Cox3a8845b2013-07-11 23:24:57 -0400213time go run run.go || exit 1
Russ Cox527669e2008-10-29 15:23:29 -0700214) || exit $?
Russ Coxbbb00c62008-10-08 09:46:54 -0700215
Brad Fitzpatrickd5e97ea2013-08-07 13:49:37 -0700216echo
217echo '# Checking API compatibility.'
Russ Coxb78410b2013-08-09 18:44:00 -0400218time go run $GOROOT/src/cmd/api/run.go
Brad Fitzpatrickf69132d2012-03-17 11:20:46 -0700219
220echo
Russ Coxb9f94762011-02-14 09:27:02 -0500221echo ALL TESTS PASSED