2009-11-14 15:29:09 -08:00
|
|
|
#!/usr/bin/env bash
|
2008-10-08 09:46:54 -07:00
|
|
|
# Copyright 2009 The Go Authors. All rights reserved.
|
|
|
|
|
# Use of this source code is governed by a BSD-style
|
|
|
|
|
# license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
2012-03-10 03:42:23 +08:00
|
|
|
eval $(go env)
|
2014-04-29 14:43:10 -04:00
|
|
|
export GOROOT # the api test requires GOROOT to be set.
|
2012-02-04 00:54:08 -05:00
|
|
|
|
2010-03-31 19:48:33 -07:00
|
|
|
unset CDPATH # in case user has it set
|
2012-03-21 00:47:27 +08:00
|
|
|
unset GOPATH # we disallow local import for non-local packages, if $GOROOT happens
|
|
|
|
|
# to be under $GOPATH, then some tests below will fail
|
2009-12-11 15:14:09 -08:00
|
|
|
|
2009-11-09 23:11:36 -08:00
|
|
|
# no core files, please
|
|
|
|
|
ulimit -c 0
|
|
|
|
|
|
2012-09-17 01:11:28 +08:00
|
|
|
# Raise soft limits to hard limits for NetBSD/OpenBSD.
|
|
|
|
|
# We need at least 256 files and ~300 MB of bss.
|
|
|
|
|
# On OS X ulimit -S -n rejects 'unlimited'.
|
2014-02-24 16:44:35 -05:00
|
|
|
#
|
|
|
|
|
# Note that ulimit -S -n may fail if ulimit -H -n is set higher than a
|
|
|
|
|
# non-root process is allowed to set the high limit.
|
|
|
|
|
# This is a system misconfiguration and should be fixed on the
|
|
|
|
|
# broken system, not "fixed" by ignoring the failure here.
|
|
|
|
|
# See longer discussion on golang.org/issue/7381.
|
2012-09-17 01:11:28 +08:00
|
|
|
[ "$(ulimit -H -n)" == "unlimited" ] || ulimit -S -n $(ulimit -H -n)
|
2012-09-17 01:26:57 +08:00
|
|
|
[ "$(ulimit -H -d)" == "unlimited" ] || ulimit -S -d $(ulimit -H -d)
|
2012-09-17 01:11:28 +08:00
|
|
|
|
2013-06-17 19:31:58 +10:00
|
|
|
# Thread count limit on NetBSD 7.
|
|
|
|
|
if ulimit -T &> /dev/null; then
|
|
|
|
|
[ "$(ulimit -H -T)" == "unlimited" ] || ulimit -S -T $(ulimit -H -T)
|
|
|
|
|
fi
|
|
|
|
|
|
2012-02-04 00:54:08 -05:00
|
|
|
# allow all.bash to avoid double-build of everything
|
2010-03-31 19:48:33 -07:00
|
|
|
rebuild=true
|
2014-05-20 12:10:19 -04:00
|
|
|
if [ "$1" == "--no-rebuild" ]; then
|
2010-03-31 19:48:33 -07:00
|
|
|
shift
|
2012-02-04 00:54:08 -05:00
|
|
|
else
|
2014-12-10 10:45:59 -05:00
|
|
|
echo '##### Building packages and commands.'
|
2015-02-22 12:41:32 -05:00
|
|
|
time go install -a -v std cmd
|
2012-02-04 00:54:08 -05:00
|
|
|
echo
|
2011-02-14 09:27:02 -05:00
|
|
|
fi
|
2008-11-20 10:54:11 -08:00
|
|
|
|
2012-04-04 23:14:54 +08:00
|
|
|
# we must unset GOROOT_FINAL before tests, because runtime/debug requires
|
|
|
|
|
# correct access to source code, so if we have GOROOT_FINAL in effect,
|
|
|
|
|
# at least runtime/debug test will fail.
|
|
|
|
|
unset GOROOT_FINAL
|
|
|
|
|
|
2014-12-23 12:09:38 +11:00
|
|
|
# TODO(adg): create an environment variable and to permit the builders to
|
|
|
|
|
# specify the timeout scale.
|
2013-03-24 16:31:28 +08:00
|
|
|
timeout_scale=1
|
2014-12-23 12:09:38 +11:00
|
|
|
# the freebsd-* builders are slow, and there's no easy way to make them faster.
|
|
|
|
|
[ "$GOOS" == "freebsd" ] && timeout_scale=2
|
|
|
|
|
# increase timeout for ARM up to 3 times the normal value
|
2013-03-24 16:31:28 +08:00
|
|
|
[ "$GOARCH" == "arm" ] && timeout_scale=3
|
|
|
|
|
|
2014-12-10 10:45:59 -05:00
|
|
|
echo '##### Testing packages.'
|
2015-02-22 12:41:32 -05:00
|
|
|
time go test std cmd -short -timeout=$(expr 120 \* $timeout_scale)s -gcflags "$GO_GCFLAGS"
|
2012-01-30 23:43:46 -05:00
|
|
|
echo
|
2012-02-04 00:54:08 -05:00
|
|
|
|
2014-03-06 13:16:14 +04:00
|
|
|
# We set GOMAXPROCS=2 in addition to -cpu=1,2,4 in order to test runtime bootstrap code,
|
|
|
|
|
# creation of first goroutines and first garbage collections in the parallel setting.
|
2014-12-10 10:45:59 -05:00
|
|
|
echo '##### GOMAXPROCS=2 runtime -cpu=1,2,4'
|
2013-07-13 02:00:07 +08:00
|
|
|
GOMAXPROCS=2 go test runtime -short -timeout=$(expr 300 \* $timeout_scale)s -cpu=1,2,4
|
2012-01-30 23:43:46 -05:00
|
|
|
echo
|
2012-02-04 00:54:08 -05:00
|
|
|
|
2014-12-10 10:45:59 -05:00
|
|
|
echo '##### sync -cpu=10'
|
2013-03-24 16:31:28 +08:00
|
|
|
go test sync -short -timeout=$(expr 120 \* $timeout_scale)s -cpu=10
|
2008-12-04 12:51:36 -08:00
|
|
|
|
2012-02-04 00:54:08 -05:00
|
|
|
xcd() {
|
|
|
|
|
echo
|
2014-12-10 10:45:59 -05:00
|
|
|
echo '#####' $1
|
2013-07-11 23:24:57 -04:00
|
|
|
builtin cd "$GOROOT"/src/$1 || exit 1
|
2012-02-04 00:54:08 -05:00
|
|
|
}
|
2012-01-30 23:43:46 -05:00
|
|
|
|
2013-07-11 23:24:57 -04:00
|
|
|
# NOTE: "set -e" cannot help us in subshells. It works until you test it with ||.
|
|
|
|
|
#
|
|
|
|
|
# $ bash --version
|
|
|
|
|
# GNU bash, version 3.2.48(1)-release (x86_64-apple-darwin12)
|
|
|
|
|
# Copyright (C) 2007 Free Software Foundation, Inc.
|
|
|
|
|
#
|
|
|
|
|
# $ set -e; (set -e; false; echo still here); echo subshell exit status $?
|
|
|
|
|
# subshell exit status 1
|
|
|
|
|
# # subshell stopped early, set exit status, but outer set -e didn't stop.
|
|
|
|
|
#
|
|
|
|
|
# $ set -e; (set -e; false; echo still here) || echo stopped
|
|
|
|
|
# still here
|
|
|
|
|
# # somehow the '|| echo stopped' broke the inner set -e.
|
|
|
|
|
#
|
|
|
|
|
# To avoid this bug, every command in a subshell should have '|| exit 1' on it.
|
|
|
|
|
# Strictly speaking, the test may be unnecessary on the final command of
|
|
|
|
|
# the subshell, but it aids later editing and may avoid future bash bugs.
|
|
|
|
|
|
2014-07-08 18:41:07 -04:00
|
|
|
if [ "$GOOS" == "android" ]; then
|
|
|
|
|
# Disable cgo tests on android.
|
|
|
|
|
# They are not designed to run off the host.
|
|
|
|
|
# golang.org/issue/8345
|
|
|
|
|
CGO_ENABLED=0
|
|
|
|
|
fi
|
|
|
|
|
|
2011-08-10 21:36:48 -04:00
|
|
|
[ "$CGO_ENABLED" != 1 ] ||
|
2011-02-09 12:37:08 +11:00
|
|
|
[ "$GOHOSTOS" == windows ] ||
|
2009-10-03 11:33:51 -07:00
|
|
|
(xcd ../misc/cgo/stdio
|
2013-07-11 23:24:57 -04:00
|
|
|
go run $GOROOT/test/run.go - . || exit 1
|
2009-10-03 11:33:51 -07:00
|
|
|
) || exit $?
|
|
|
|
|
|
2011-08-10 21:36:48 -04:00
|
|
|
[ "$CGO_ENABLED" != 1 ] ||
|
2010-12-17 09:51:55 -08:00
|
|
|
(xcd ../misc/cgo/life
|
2013-07-11 23:24:57 -04:00
|
|
|
go run $GOROOT/test/run.go - . || exit 1
|
2010-12-17 09:51:55 -08:00
|
|
|
) || exit $?
|
|
|
|
|
|
2011-08-10 21:36:48 -04:00
|
|
|
[ "$CGO_ENABLED" != 1 ] ||
|
2011-03-11 15:09:32 -05:00
|
|
|
(xcd ../misc/cgo/test
|
runtime: keep g->syscallsp consistent after cgo->Go callbacks
Normally, the caller to runtime.entersyscall() must not return before
calling runtime.exitsyscall(), lest g->syscallsp become a dangling
pointer. runtime.cgocallbackg() violates this constraint. To work around
this, save g->syscallsp and g->syscallpc around cgo->Go callbacks, then
restore them after calling runtime.entersyscall(), which restores the
syscall stack frame pointer saved by cgocall. This allows the GC to
correctly trace a goroutine that is currently returning from a
Go->cgo->Go chain.
This also adds a check to proc.c that panics if g->syscallsp is clearly
invalid. It is not 100% foolproof, as it will not catch a case where the
stack was popped then pushed back beyond g->syscallsp, but it does catch
the present cgo issue and makes existing tests fail without the bugfix.
Fixes #7978.
LGTM=dvyukov, rsc
R=golang-codereviews, dvyukov, minux, bradfitz, iant, gobot, rsc
CC=golang-codereviews, rsc
https://golang.org/cl/131910043
2014-09-24 13:20:25 -04:00
|
|
|
# cgo tests inspect the traceback for runtime functions
|
2014-11-19 20:52:58 -05:00
|
|
|
extlink=0
|
runtime: keep g->syscallsp consistent after cgo->Go callbacks
Normally, the caller to runtime.entersyscall() must not return before
calling runtime.exitsyscall(), lest g->syscallsp become a dangling
pointer. runtime.cgocallbackg() violates this constraint. To work around
this, save g->syscallsp and g->syscallpc around cgo->Go callbacks, then
restore them after calling runtime.entersyscall(), which restores the
syscall stack frame pointer saved by cgocall. This allows the GC to
correctly trace a goroutine that is currently returning from a
Go->cgo->Go chain.
This also adds a check to proc.c that panics if g->syscallsp is clearly
invalid. It is not 100% foolproof, as it will not catch a case where the
stack was popped then pushed back beyond g->syscallsp, but it does catch
the present cgo issue and makes existing tests fail without the bugfix.
Fixes #7978.
LGTM=dvyukov, rsc
R=golang-codereviews, dvyukov, minux, bradfitz, iant, gobot, rsc
CC=golang-codereviews, rsc
https://golang.org/cl/131910043
2014-09-24 13:20:25 -04:00
|
|
|
export GOTRACEBACK=2
|
2013-07-11 23:24:57 -04:00
|
|
|
go test -ldflags '-linkmode=auto' || exit 1
|
2013-09-04 15:19:21 -07:00
|
|
|
# linkmode=internal fails on dragonfly since errno is a TLS relocation.
|
|
|
|
|
[ "$GOHOSTOS" == dragonfly ] || go test -ldflags '-linkmode=internal' || exit 1
|
2014-12-16 18:34:55 -05:00
|
|
|
# TODO(austin): Add linux-ppc64(le) once external linking works (issue #8912)
|
2013-03-11 00:51:42 -04:00
|
|
|
case "$GOHOSTOS-$GOARCH" in
|
2013-03-29 16:33:35 -07:00
|
|
|
openbsd-386 | openbsd-amd64)
|
2013-03-27 13:27:35 -07:00
|
|
|
# test linkmode=external, but __thread not supported, so skip testtls.
|
2013-07-11 23:24:57 -04:00
|
|
|
go test -ldflags '-linkmode=external' || exit 1
|
2014-11-19 20:52:58 -05:00
|
|
|
extlink=1
|
2013-03-27 13:27:35 -07:00
|
|
|
;;
|
2013-03-29 16:33:35 -07:00
|
|
|
darwin-386 | darwin-amd64)
|
|
|
|
|
# linkmode=external fails on OS X 10.6 and earlier == Darwin
|
|
|
|
|
# 10.8 and earlier.
|
|
|
|
|
case $(uname -r) in
|
|
|
|
|
[0-9].* | 10.*) ;;
|
2014-11-19 20:52:58 -05:00
|
|
|
*)
|
|
|
|
|
go test -ldflags '-linkmode=external' || exit 1
|
|
|
|
|
extlink=1
|
|
|
|
|
;;
|
2013-03-29 16:33:35 -07:00
|
|
|
esac
|
|
|
|
|
;;
|
2014-07-08 18:41:07 -04:00
|
|
|
android-arm | dragonfly-386 | dragonfly-amd64 | freebsd-386 | freebsd-amd64 | freebsd-arm | linux-386 | linux-amd64 | linux-arm | netbsd-386 | netbsd-amd64)
|
2013-07-11 23:24:57 -04:00
|
|
|
go test -ldflags '-linkmode=external' || exit 1
|
|
|
|
|
go test -ldflags '-linkmode=auto' ../testtls || exit 1
|
|
|
|
|
go test -ldflags '-linkmode=external' ../testtls || exit 1
|
2014-11-19 20:52:58 -05:00
|
|
|
extlink=1
|
2014-04-15 15:52:02 -04:00
|
|
|
|
2014-04-15 23:54:04 -04:00
|
|
|
case "$GOHOSTOS-$GOARCH" in
|
2014-04-15 15:52:02 -04:00
|
|
|
netbsd-386 | netbsd-amd64) ;; # no static linking
|
2014-04-21 00:08:59 -04:00
|
|
|
freebsd-arm) ;; # -fPIC compiled tls code will use __tls_get_addr instead
|
|
|
|
|
# of __aeabi_read_tp, however, on FreeBSD/ARM, __tls_get_addr
|
|
|
|
|
# is implemented in rtld-elf, so -fPIC isn't compatible with
|
|
|
|
|
# static linking on FreeBSD/ARM with clang. (cgo depends on
|
|
|
|
|
# -fPIC fundamentally.)
|
2014-04-15 15:52:02 -04:00
|
|
|
*)
|
2014-04-29 14:43:10 -04:00
|
|
|
if ! $CC -xc -o /dev/null -static - 2>/dev/null <<<'int main() {}' ; then
|
|
|
|
|
echo "No support for static linking found (lacks libc.a?), skip cgo static linking test."
|
|
|
|
|
else
|
|
|
|
|
go test -ldflags '-linkmode=external -extldflags "-static -pthread"' ../testtls || exit 1
|
2014-05-20 21:36:50 -07:00
|
|
|
go test ../nocgo || exit 1
|
|
|
|
|
go test -ldflags '-linkmode=external' ../nocgo || exit 1
|
|
|
|
|
go test -ldflags '-linkmode=external -extldflags "-static -pthread"' ../nocgo || exit 1
|
2014-04-29 14:43:10 -04:00
|
|
|
fi
|
2015-03-02 12:58:02 -08:00
|
|
|
case "$GOHOSTOS-$GOARCH" in
|
|
|
|
|
freebsd-amd64) ;; # clang -pie fails to link misc/cgo/test
|
|
|
|
|
*)
|
|
|
|
|
if ! $CC -xc -o /dev/null -pie - 2>/dev/null <<<'int main() {}' ; then
|
|
|
|
|
echo "No support for -pie found, skip cgo PIE test."
|
|
|
|
|
else
|
|
|
|
|
go test -ldflags '-linkmode=external -extldflags "-pie"' || exit 1
|
|
|
|
|
go test -ldflags '-linkmode=external -extldflags "-pie"' ../testtls || exit 1
|
|
|
|
|
go test -ldflags '-linkmode=external -extldflags "-pie"' ../nocgo || exit 1
|
|
|
|
|
fi
|
|
|
|
|
;;
|
|
|
|
|
esac
|
2014-04-15 15:52:02 -04:00
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
;;
|
2013-03-11 00:51:42 -04:00
|
|
|
esac
|
2011-03-11 15:09:32 -05:00
|
|
|
) || exit $?
|
|
|
|
|
|
2014-11-19 20:52:58 -05:00
|
|
|
# Race detector only supported on Linux, FreeBSD and OS X,
|
|
|
|
|
# and only on amd64, and only when cgo is enabled.
|
|
|
|
|
# Delayed until here so we know whether to try external linking.
|
|
|
|
|
case "$GOHOSTOS-$GOOS-$GOARCH-$CGO_ENABLED" in
|
|
|
|
|
linux-linux-amd64-1 | freebsd-freebsd-amd64-1 | darwin-darwin-amd64-1)
|
|
|
|
|
echo
|
2014-12-10 10:45:59 -05:00
|
|
|
echo '##### Testing race detector.'
|
2014-11-19 20:52:58 -05:00
|
|
|
go test -race -i runtime/race flag os/exec
|
|
|
|
|
go test -race -run=Output runtime/race
|
|
|
|
|
go test -race -short flag os/exec
|
|
|
|
|
|
|
|
|
|
# Test with external linking; see issue 9133.
|
|
|
|
|
if [ "$extlink" = 1 ]; then
|
|
|
|
|
go test -race -short -ldflags=-linkmode=external flag os/exec
|
|
|
|
|
fi
|
|
|
|
|
esac
|
|
|
|
|
|
2014-08-12 07:13:52 -07:00
|
|
|
[ "$CGO_ENABLED" != 1 ] || [ "$GOOS" == darwin ] ||
|
|
|
|
|
(xcd ../misc/cgo/testgodefs
|
|
|
|
|
./test.bash || exit 1
|
|
|
|
|
) || exit $?
|
|
|
|
|
|
2011-11-22 17:57:49 +03:00
|
|
|
[ "$CGO_ENABLED" != 1 ] ||
|
|
|
|
|
[ "$GOHOSTOS" == windows ] ||
|
|
|
|
|
(xcd ../misc/cgo/testso
|
2013-07-11 23:24:57 -04:00
|
|
|
./test.bash || exit 1
|
2011-11-22 17:57:49 +03:00
|
|
|
) || exit $?
|
|
|
|
|
|
2013-06-12 18:47:16 +04:00
|
|
|
[ "$CGO_ENABLED" != 1 ] ||
|
|
|
|
|
[ "$GOHOSTOS-$GOARCH" != linux-amd64 ] ||
|
|
|
|
|
(xcd ../misc/cgo/testasan
|
2013-07-11 23:24:57 -04:00
|
|
|
go run main.go || exit 1
|
2013-06-12 18:47:16 +04:00
|
|
|
) || exit $?
|
|
|
|
|
|
2013-09-03 21:15:15 -07:00
|
|
|
[ "$CGO_ENABLED" != 1 ] ||
|
|
|
|
|
[ "$GOHOSTOS" == windows ] ||
|
|
|
|
|
(xcd ../misc/cgo/errors
|
|
|
|
|
./test.bash || exit 1
|
|
|
|
|
) || exit $?
|
|
|
|
|
|
2014-05-20 12:10:19 -04:00
|
|
|
[ "$GOOS" == nacl ] ||
|
2014-07-08 18:41:07 -04:00
|
|
|
[ "$GOOS" == android ] ||
|
2009-01-06 15:49:27 -08:00
|
|
|
(xcd ../doc/progs
|
2013-07-11 23:24:57 -04:00
|
|
|
time ./run || exit 1
|
2009-01-06 15:49:27 -08:00
|
|
|
) || exit $?
|
|
|
|
|
|
2014-07-08 18:41:07 -04:00
|
|
|
[ "$GOOS" == android ] ||
|
2014-05-20 12:10:19 -04:00
|
|
|
[ "$GOOS" == nacl ] ||
|
2011-03-27 23:39:42 -04:00
|
|
|
[ "$GOARCH" == arm ] || # uses network, fails under QEMU
|
2012-03-08 06:23:56 +08:00
|
|
|
(xcd ../doc/articles/wiki
|
2013-07-11 23:24:57 -04:00
|
|
|
./test.bash || exit 1
|
2011-01-31 15:58:44 +11:00
|
|
|
) || exit $?
|
2011-01-26 14:56:52 +10:00
|
|
|
|
2014-07-08 18:41:07 -04:00
|
|
|
[ "$GOOS" == android ] ||
|
2014-05-20 12:10:19 -04:00
|
|
|
[ "$GOOS" == nacl ] ||
|
2012-03-26 16:08:21 +11:00
|
|
|
(xcd ../doc/codewalk
|
2013-07-30 09:42:53 +10:00
|
|
|
time ./run || exit 1
|
2012-03-26 16:08:21 +11:00
|
|
|
) || exit $?
|
|
|
|
|
|
2014-05-20 12:10:19 -04:00
|
|
|
[ "$GOOS" == nacl ] ||
|
2010-09-22 15:30:42 +10:00
|
|
|
[ "$GOARCH" == arm ] ||
|
2011-12-13 17:46:54 -05:00
|
|
|
(xcd ../test/bench/shootout
|
2014-02-19 08:19:27 +01:00
|
|
|
time ./timing.sh -test || exit 1
|
2009-08-09 14:31:05 -07:00
|
|
|
) || exit $?
|
|
|
|
|
|
2014-07-08 18:41:07 -04:00
|
|
|
[ "$GOOS" == android ] || # TODO(crawshaw): get this working
|
2013-03-15 12:39:14 -04:00
|
|
|
[ "$GOOS" == openbsd ] || # golang.org/issue/5057
|
|
|
|
|
(
|
2012-03-08 06:23:56 +08:00
|
|
|
echo
|
2014-12-10 10:45:59 -05:00
|
|
|
echo '#####' ../test/bench/go1
|
2013-07-11 23:24:57 -04:00
|
|
|
go test ../test/bench/go1 || exit 1
|
2013-03-15 12:39:14 -04:00
|
|
|
) || exit $?
|
2011-12-15 12:32:59 -05:00
|
|
|
|
2014-07-08 18:41:07 -04:00
|
|
|
[ "$GOOS" == android ] ||
|
2008-10-08 09:46:54 -07:00
|
|
|
(xcd ../test
|
2012-11-15 13:59:46 +11:00
|
|
|
unset GOMAXPROCS
|
2014-05-20 12:10:19 -04:00
|
|
|
GOOS=$GOHOSTOS GOARCH=$GOHOSTARCH go build -o runtest run.go || exit 1
|
|
|
|
|
time ./runtest || exit 1
|
|
|
|
|
rm -f runtest
|
2008-10-29 15:23:29 -07:00
|
|
|
) || exit $?
|
2008-10-08 09:46:54 -07:00
|
|
|
|
2014-07-08 18:41:07 -04:00
|
|
|
[ "$GOOS" == android ] ||
|
2014-05-20 12:10:19 -04:00
|
|
|
[ "$GOOS" == nacl ] ||
|
|
|
|
|
(
|
2013-08-07 13:49:37 -07:00
|
|
|
echo
|
2014-12-05 16:24:20 -05:00
|
|
|
time go run $GOROOT/src/cmd/api/run.go || exit 1
|
2014-05-20 12:10:19 -04:00
|
|
|
) || exit $?
|
2012-03-17 11:20:46 -07:00
|
|
|
|
2011-02-14 09:27:02 -05:00
|
|
|
echo
|
|
|
|
|
echo ALL TESTS PASSED
|