Commit d5f69060 authored by Brad Fitzpatrick's avatar Brad Fitzpatrick

build: convert run.bash, run.bat, and run.rc into a Go program

This will enable test sharding over multiple VMs, to speed trybot answers.

Update #10029

Change-Id: Ie277c6459bc38005e4d6af14d22effeaa0a4667e
Reviewed-on: https://go-review.googlesource.com/6531Reviewed-by: 's avatarRuss Cox <rsc@golang.org>
Reviewed-by: 's avatarAlex Brainman <alex.brainman@gmail.com>
parent 4f6630de
#!/usr/bin/env bash
# Copyright 2013 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.
......
#!/usr/bin/env bash
# Copyright 2014 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.
......
......@@ -13,6 +13,6 @@ main.exe
goto :end
:fail
set FAIL=1
:: echo FAIL
:end
del /F cgoso_c.o libcgosotest.dll main.exe 2>NUL
......@@ -21,6 +21,7 @@ var cmdtab = []struct {
{"clean", cmdclean},
{"env", cmdenv},
{"install", cmdinstall},
{"test", cmdtest},
{"version", cmdversion},
}
......
This diff is collapsed.
......@@ -12,6 +12,9 @@ unset CDPATH # in case user has it set
unset GOPATH # we disallow local import for non-local packages, if $GOROOT happens
# to be under $GOPATH, then some tests below will fail
export GOHOSTOS
export CC
# no core files, please
ulimit -c 0
......@@ -32,237 +35,4 @@ if ulimit -T &> /dev/null; then
[ "$(ulimit -H -T)" == "unlimited" ] || ulimit -S -T $(ulimit -H -T)
fi
# allow all.bash to avoid double-build of everything
rebuild=true
if [ "$1" == "--no-rebuild" ]; then
shift
else
echo '##### Building packages and commands.'
time go install -a -v std cmd
echo
fi
# 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
# TODO(adg): create an environment variable and to permit the builders to
# specify the timeout scale.
timeout_scale=1
# 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
[ "$GOARCH" == "arm" ] && timeout_scale=3
echo '##### Testing packages.'
time go test std cmd -short -timeout=$(expr 120 \* $timeout_scale)s -gcflags "$GO_GCFLAGS"
echo
# 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.
echo '##### GOMAXPROCS=2 runtime -cpu=1,2,4'
GOMAXPROCS=2 go test runtime -short -timeout=$(expr 300 \* $timeout_scale)s -cpu=1,2,4
echo
echo '##### sync -cpu=10'
go test sync -short -timeout=$(expr 120 \* $timeout_scale)s -cpu=10
xcd() {
echo
echo '#####' $1
builtin cd "$GOROOT"/src/$1 || exit 1
}
# 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.
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
[ "$CGO_ENABLED" != 1 ] ||
[ "$GOHOSTOS" == windows ] ||
(xcd ../misc/cgo/stdio
go run $GOROOT/test/run.go - . || exit 1
) || exit $?
[ "$CGO_ENABLED" != 1 ] ||
(xcd ../misc/cgo/life
go run $GOROOT/test/run.go - . || exit 1
) || exit $?
[ "$CGO_ENABLED" != 1 ] ||
(xcd ../misc/cgo/test
# cgo tests inspect the traceback for runtime functions
extlink=0
export GOTRACEBACK=2
go test -ldflags '-linkmode=auto' || exit 1
# linkmode=internal fails on dragonfly since errno is a TLS relocation.
[ "$GOHOSTOS" == dragonfly ] || go test -ldflags '-linkmode=internal' || exit 1
# TODO(austin): Add linux-ppc64(le) once external linking works (issue #8912)
case "$GOHOSTOS-$GOARCH" in
openbsd-386 | openbsd-amd64)
# test linkmode=external, but __thread not supported, so skip testtls.
go test -ldflags '-linkmode=external' || exit 1
extlink=1
;;
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.*) ;;
*)
go test -ldflags '-linkmode=external' || exit 1
extlink=1
;;
esac
;;
android-arm | dragonfly-386 | dragonfly-amd64 | freebsd-386 | freebsd-amd64 | freebsd-arm | linux-386 | linux-amd64 | linux-arm | netbsd-386 | netbsd-amd64)
go test -ldflags '-linkmode=external' || exit 1
go test -ldflags '-linkmode=auto' ../testtls || exit 1
go test -ldflags '-linkmode=external' ../testtls || exit 1
extlink=1
case "$GOHOSTOS-$GOARCH" in
netbsd-386 | netbsd-amd64) ;; # no static linking
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.)
*)
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
go test ../nocgo || exit 1
go test -ldflags '-linkmode=external' ../nocgo || exit 1
go test -ldflags '-linkmode=external -extldflags "-static -pthread"' ../nocgo || exit 1
fi
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
;;
esac
;;
esac
) || exit $?
# 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
echo '##### Testing race detector.'
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
[ "$CGO_ENABLED" != 1 ] || [ "$GOOS" == darwin ] ||
(xcd ../misc/cgo/testgodefs
./test.bash || exit 1
) || exit $?
[ "$CGO_ENABLED" != 1 ] ||
[ "$GOHOSTOS" == windows ] ||
(xcd ../misc/cgo/testso
./test.bash || exit 1
) || exit $?
[ "$CGO_ENABLED" != 1 ] ||
[ "$GOHOSTOS-$GOARCH" != linux-amd64 ] ||
(xcd ../misc/cgo/testasan
go run main.go || exit 1
) || exit $?
[ "$CGO_ENABLED" != 1 ] ||
[ "$GOHOSTOS" == windows ] ||
(xcd ../misc/cgo/errors
./test.bash || exit 1
) || exit $?
[ "$GOOS" == nacl ] ||
[ "$GOOS" == android ] ||
(xcd ../doc/progs
time ./run || exit 1
) || exit $?
[ "$GOOS" == android ] ||
[ "$GOOS" == nacl ] ||
[ "$GOARCH" == arm ] || # uses network, fails under QEMU
(xcd ../doc/articles/wiki
./test.bash || exit 1
) || exit $?
[ "$GOOS" == android ] ||
[ "$GOOS" == nacl ] ||
(xcd ../doc/codewalk
time ./run || exit 1
) || exit $?
[ "$GOOS" == nacl ] ||
[ "$GOARCH" == arm ] ||
(xcd ../test/bench/shootout
time ./timing.sh -test || exit 1
) || exit $?
[ "$GOOS" == android ] || # TODO(crawshaw): get this working
[ "$GOOS" == openbsd ] || # golang.org/issue/5057
(
echo
echo '#####' ../test/bench/go1
go test ../test/bench/go1 || exit 1
) || exit $?
[ "$GOOS" == android ] ||
(xcd ../test
unset GOMAXPROCS
GOOS=$GOHOSTOS GOARCH=$GOHOSTARCH go build -o runtest run.go || exit 1
time ./runtest || exit 1
rm -f runtest
) || exit $?
[ "$GOOS" == android ] ||
[ "$GOOS" == nacl ] ||
(
echo
time go run $GOROOT/src/cmd/api/run.go || exit 1
) || exit $?
echo
echo ALL TESTS PASSED
exec go tool dist test $@
......@@ -37,109 +37,10 @@ call env.bat
del env.bat
echo.
echo ##### Testing packages.
go test std cmd -short -timeout=240s
go tool dist test --no-rebuild
if errorlevel 1 goto fail
echo.
set OLDGOMAXPROCS=%GOMAXPROCS%
:: 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.
echo ##### GOMAXPROCS=2 runtime -cpu=1,2,4
set GOMAXPROCS=2
go test runtime -short -timeout=600s -cpu=1,2,4
if errorlevel 1 goto fail
echo.
set GOMAXPROCS=%OLDGOMAXPROCS%
set OLDGOMAXPROCS=
echo ##### sync -cpu=10
go test sync -short -timeout=240s -cpu=10
if errorlevel 1 goto fail
echo.
:: Race detector only supported on Linux and OS X,
:: and only on amd64, and only when cgo is enabled.
if not "%GOHOSTOS%-%GOOS%-%GOARCH%-%CGO_ENABLED%" == "windows-windows-amd64-1" goto norace
echo ##### Testing race detector.
go test -race -i runtime/race flag
if errorlevel 1 goto fail
go test -race -run=Output runtime/race
if errorlevel 1 goto fail
go test -race -short flag
if errorlevel 1 goto fail
echo.
:norace
echo ##### ..\test\bench\go1
go test ..\test\bench\go1
if errorlevel 1 goto fail
echo.
:: cgo tests
if x%CGO_ENABLED% == x0 goto nocgo
echo ##### ..\misc\cgo\life
go run "%GOROOT%\test\run.go" - ..\misc\cgo\life
if errorlevel 1 goto fail
echo.
echo ##### ..\misc\cgo\stdio
go run "%GOROOT%\test\run.go" - ..\misc\cgo\stdio
if errorlevel 1 goto fail
echo.
:: cgo tests inspect the traceback for runtime functions
set OLDGOTRACEBACK=%GOTRACEBACK%
set GOTRACEBACK=2
echo ##### ..\misc\cgo\test
go test ..\misc\cgo\test
if errorlevel 1 goto fail
echo.
set GOTRACEBACK=%OLDGOTRACEBACK%
set OLDGOTRACEBACK=
echo ##### ..\misc\cgo\testso
cd ..\misc\cgo\testso
set FAIL=0
call test.bat
cd ..\..\..\src
if %FAIL%==1 goto fail
echo.
:nocgo
echo ##### ..\doc\progs
go run "%GOROOT%\test\run.go" - ..\doc\progs
if errorlevel 1 goto fail
echo.
:: TODO: The other tests in run.bash.
set OLDGOMAXPROCS=%GOMAXPROCS%
echo ##### ..\test
cd ..\test
set FAIL=0
set GOMAXPROCS=
go run run.go
if errorlevel 1 set FAIL=1
cd ..\src
echo.
if %FAIL%==1 goto fail
set GOMAXPROCS=%OLDGOMAXPROCS%
set OLDGOMAXPROCS=
:: echo ##### Checking API compatibility.
go run "%GOROOT%\src\cmd\api\run.go"
if errorlevel 1 goto fail
echo.
echo ALL TESTS PASSED
goto end
:fail
......
......@@ -10,60 +10,4 @@ eval `{go env}
GOPATH = () # we disallow local import for non-local packages, if $GOROOT happens
# to be under $GOPATH, then some tests below will fail
# allow all.rc to avoid double-build of everything
rebuild = true
if(~ $1 --no-rebuild)
shift
if not {
# Run only one process at a time on 9vx.
if(~ $sysname vx32)
pflag = (-p 1)
echo '# Building packages and commands.'
time go install -a -v $pflag std cmd
echo
}
# 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.
GOROOT_FINAL = ()
echo '# Testing packages.'
time go test std cmd -short -timeout 120s
echo
# Temporary GCE builder hack until Plan 9 on GCE is fast enough.
# See https://golang.org/issue/9491
if(~ $GOTESTONLY std) {
echo
echo PARTIAL TESTS PASSED: std
exit
}
# 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.
echo '# GOMAXPROCS=2 runtime -cpu=1,2,4'
GOMAXPROCS=2 go test runtime -short -timeout 240s -cpu 1,2,4
echo
echo '# sync -cpu=10'
go test sync -short -timeout 120s -cpu 10
echo
fn xcd {
echo
echo '#' $1
cd $"GOROOT/src/$1
}
echo
echo '#' ../test/bench/go1
go test ../test/bench/go1
@{
xcd ../test
GOMAXPROCS='' time go run run.go -v
}
echo
echo ALL TESTS PASSED
exec go tool dist test $*
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment