Commit d406f8f6 authored by Rob Pike's avatar Rob Pike

testing: set up structure for faster testing using the new -test.short flag.

New make target "testshort" runs "gotest -test.short" and is invoked
by run.bash, which is invoked by all.bash.

Use -test.short to make one package (crypto ecdsa) run much faster.
More changes to come.

Once this is in, I will update the long-running tests to use the new flag.

R=rsc
CC=golang-dev
https://golang.org/cl/4317043
parent 47c1cef5
...@@ -60,6 +60,9 @@ CLEANFILES+=*.so _obj _test _testmain.go *.exe _cgo* *.cgo[12].* ...@@ -60,6 +60,9 @@ CLEANFILES+=*.so _obj _test _testmain.go *.exe _cgo* *.cgo[12].*
test: test:
gotest gotest
testshort:
gotest -test.short
bench: bench:
gotest -test.bench=. -test.run="Do not run tests" gotest -test.bench=. -test.run="Do not run tests"
......
...@@ -15,3 +15,6 @@ include ../../Make.cmd ...@@ -15,3 +15,6 @@ include ../../Make.cmd
test: test:
gotest gotest
testshort:
gotest -test.short
...@@ -24,3 +24,6 @@ syslist.go: ...@@ -24,3 +24,6 @@ syslist.go:
test: test:
gotest gotest
testshort:
gotest -test.short
...@@ -66,5 +66,9 @@ the environment variable GOGC=off to disable the garbage collector, ...@@ -66,5 +66,9 @@ the environment variable GOGC=off to disable the garbage collector,
provided the test can run in the available memory without garbage provided the test can run in the available memory without garbage
collection. collection.
The -test.short package tells long-running tests to shorten their
run time. It is off by default but set by all.bash so installations
of the Go tree can do a sanity check but not spend time running the
full test suite.
*/ */
package documentation package documentation
...@@ -12,3 +12,6 @@ include ../../Make.cmd ...@@ -12,3 +12,6 @@ include ../../Make.cmd
test: test:
gotest gotest
testshort:
gotest -test.short
...@@ -222,6 +222,7 @@ clean.dirs: $(addsuffix .clean, $(DIRS)) ...@@ -222,6 +222,7 @@ clean.dirs: $(addsuffix .clean, $(DIRS))
install.dirs: $(addsuffix .install, $(DIRS)) install.dirs: $(addsuffix .install, $(DIRS))
nuke.dirs: $(addsuffix .nuke, $(DIRS)) nuke.dirs: $(addsuffix .nuke, $(DIRS))
test.dirs: $(addsuffix .test, $(TEST)) test.dirs: $(addsuffix .test, $(TEST))
testshort.dirs: $(addsuffix .testshort, $(TEST))
bench.dirs: $(addsuffix .bench, $(BENCH)) bench.dirs: $(addsuffix .bench, $(BENCH))
%.clean: %.clean:
...@@ -236,6 +237,9 @@ bench.dirs: $(addsuffix .bench, $(BENCH)) ...@@ -236,6 +237,9 @@ bench.dirs: $(addsuffix .bench, $(BENCH))
%.test: %.test:
+$(MAKE) -C $* test +$(MAKE) -C $* test
%.testshort:
+$(MAKE) -C $* testshort
%.bench: %.bench:
+$(MAKE) -C $* bench +$(MAKE) -C $* bench
...@@ -245,6 +249,8 @@ install: install.dirs ...@@ -245,6 +249,8 @@ install: install.dirs
test: test.dirs test: test.dirs
testshort: testshort.dirs
bench: bench.dirs ../../test/garbage.bench bench: bench.dirs ../../test/garbage.bench
nuke: nuke.dirs nuke: nuke.dirs
......
...@@ -26,6 +26,9 @@ func testKeyGeneration(t *testing.T, c *elliptic.Curve, tag string) { ...@@ -26,6 +26,9 @@ func testKeyGeneration(t *testing.T, c *elliptic.Curve, tag string) {
func TestKeyGeneration(t *testing.T) { func TestKeyGeneration(t *testing.T) {
testKeyGeneration(t, elliptic.P224(), "p224") testKeyGeneration(t, elliptic.P224(), "p224")
if testing.Short() {
return
}
testKeyGeneration(t, elliptic.P256(), "p256") testKeyGeneration(t, elliptic.P256(), "p256")
testKeyGeneration(t, elliptic.P384(), "p384") testKeyGeneration(t, elliptic.P384(), "p384")
testKeyGeneration(t, elliptic.P521(), "p521") testKeyGeneration(t, elliptic.P521(), "p521")
...@@ -53,6 +56,9 @@ func testSignAndVerify(t *testing.T, c *elliptic.Curve, tag string) { ...@@ -53,6 +56,9 @@ func testSignAndVerify(t *testing.T, c *elliptic.Curve, tag string) {
func TestSignAndVerify(t *testing.T) { func TestSignAndVerify(t *testing.T) {
testSignAndVerify(t, elliptic.P224(), "p224") testSignAndVerify(t, elliptic.P224(), "p224")
if testing.Short() {
return
}
testSignAndVerify(t, elliptic.P256(), "p256") testSignAndVerify(t, elliptic.P256(), "p256")
testSignAndVerify(t, elliptic.P384(), "p384") testSignAndVerify(t, elliptic.P384(), "p384")
testSignAndVerify(t, elliptic.P521(), "p521") testSignAndVerify(t, elliptic.P521(), "p521")
...@@ -214,5 +220,8 @@ func TestVectors(t *testing.T) { ...@@ -214,5 +220,8 @@ func TestVectors(t *testing.T) {
if Verify(&pub, hashed, r, s) != test.ok { if Verify(&pub, hashed, r, s) != test.ok {
t.Errorf("%d: bad result", i) t.Errorf("%d: bad result", i)
} }
if testing.Short() {
break
}
} }
} }
...@@ -48,6 +48,13 @@ import ( ...@@ -48,6 +48,13 @@ import (
) )
var ( var (
// The short flag requests that tests run more quickly, but its functionality
// is provided by test writers themselves. The testing package is just its
// home. The all.bash installation script sets it to make installation more
// efficient, but by default the flag is off so a plain "gotest" will do a
// full test of the package.
short = flag.Bool("test.short", false, "run smaller test suite to save time")
// Report as tests are run; default is silent for success. // Report as tests are run; default is silent for success.
chatty = flag.Bool("test.v", false, "verbose: print additional output") chatty = flag.Bool("test.v", false, "verbose: print additional output")
match = flag.String("test.run", "", "regular expression to select tests to run") match = flag.String("test.run", "", "regular expression to select tests to run")
...@@ -56,6 +63,11 @@ var ( ...@@ -56,6 +63,11 @@ var (
cpuProfile = flag.String("test.cpuprofile", "", "write a cpu profile to the named file during execution") cpuProfile = flag.String("test.cpuprofile", "", "write a cpu profile to the named file during execution")
) )
// Short reports whether the -test.short flag is set.
func Short() bool {
return *short
}
// Insert final newline if needed and tabs after internal newlines. // Insert final newline if needed and tabs after internal newlines.
func tabify(s string) string { func tabify(s string) string {
......
...@@ -39,7 +39,7 @@ if $rebuild; then ...@@ -39,7 +39,7 @@ if $rebuild; then
fi fi
(xcd pkg (xcd pkg
gomake test gomake testshort
) || exit $? ) || exit $?
(xcd pkg/sync; (xcd pkg/sync;
...@@ -47,7 +47,7 @@ if $rebuild; then ...@@ -47,7 +47,7 @@ if $rebuild; then
gomake clean; gomake clean;
time gomake time gomake
fi fi
GOMAXPROCS=10 gomake test GOMAXPROCS=10 gomake testshort
) || exit $? ) || exit $?
[ "$GOARCH" == arm ] || [ "$GOARCH" == arm ] ||
......
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