Commit f0cf7d29 authored by Rob Pike's avatar Rob Pike

testing: shorten some tests.

These are the top runners.  More to come.
Also print two digits of timing info under -test.v.

R=rsc
CC=golang-dev
https://golang.org/cl/4317044
parent 4cb660aa
...@@ -178,7 +178,11 @@ func TestBasicOperations(t *testing.T) { ...@@ -178,7 +178,11 @@ func TestBasicOperations(t *testing.T) {
func TestLargeStringWrites(t *testing.T) { func TestLargeStringWrites(t *testing.T) {
var buf Buffer var buf Buffer
for i := 3; i < 30; i += 3 { limit := 30
if testing.Short() {
limit = 9
}
for i := 3; i < limit; i += 3 {
s := fillString(t, "TestLargeWrites (1)", &buf, "", 5, data) s := fillString(t, "TestLargeWrites (1)", &buf, "", 5, data)
empty(t, "TestLargeStringWrites (2)", &buf, s, make([]byte, len(data)/i)) empty(t, "TestLargeStringWrites (2)", &buf, s, make([]byte, len(data)/i))
} }
...@@ -188,7 +192,11 @@ func TestLargeStringWrites(t *testing.T) { ...@@ -188,7 +192,11 @@ func TestLargeStringWrites(t *testing.T) {
func TestLargeByteWrites(t *testing.T) { func TestLargeByteWrites(t *testing.T) {
var buf Buffer var buf Buffer
for i := 3; i < 30; i += 3 { limit := 30
if testing.Short() {
limit = 9
}
for i := 3; i < limit; i += 3 {
s := fillBytes(t, "TestLargeWrites (1)", &buf, "", 5, bytes) s := fillBytes(t, "TestLargeWrites (1)", &buf, "", 5, bytes)
empty(t, "TestLargeByteWrites (2)", &buf, s, make([]byte, len(data)/i)) empty(t, "TestLargeByteWrites (2)", &buf, s, make([]byte, len(data)/i))
} }
......
...@@ -201,7 +201,10 @@ func TestIndexByte(t *testing.T) { ...@@ -201,7 +201,10 @@ func TestIndexByte(t *testing.T) {
// test a larger buffer with different sizes and alignments // test a larger buffer with different sizes and alignments
func TestIndexByteBig(t *testing.T) { func TestIndexByteBig(t *testing.T) {
const n = 1024 var n = 1024
if testing.Short() {
n = 128
}
b := make([]byte, n) b := make([]byte, n)
for i := 0; i < n; i++ { for i := 0; i < n; i++ {
// different start alignments // different start alignments
......
...@@ -90,5 +90,8 @@ func TestParse(t *testing.T) { ...@@ -90,5 +90,8 @@ func TestParse(t *testing.T) {
if !bytes.Equal(out, expected) { if !bytes.Equal(out, expected) {
t.Errorf("%d: output got: %x want: %x", i, out, expected) t.Errorf("%d: output got: %x want: %x", i, out, expected)
} }
if testing.Short() {
break
}
} }
} }
...@@ -11,7 +11,11 @@ import ( ...@@ -11,7 +11,11 @@ import (
) )
func TestRead(t *testing.T) { func TestRead(t *testing.T) {
b := make([]byte, 4e6) var n int = 4e6
if testing.Short() {
n = 1e5
}
b := make([]byte, n)
n, err := Read(b) n, err := Read(b)
if n != len(b) || err != nil { if n != len(b) || err != nil {
t.Fatalf("Read(buf) = %d, %s", n, err) t.Fatalf("Read(buf) = %d, %s", n, err)
......
...@@ -97,7 +97,11 @@ func TestEncryptPKCS1v15(t *testing.T) { ...@@ -97,7 +97,11 @@ func TestEncryptPKCS1v15(t *testing.T) {
return true return true
} }
quick.Check(tryEncryptDecrypt, nil) config := new(quick.Config)
if testing.Short() {
config.MaxCount = 10
}
quick.Check(tryEncryptDecrypt, config)
} }
// These test vectors were generated with `openssl rsautl -pkcs -encrypt` // These test vectors were generated with `openssl rsautl -pkcs -encrypt`
......
...@@ -15,7 +15,11 @@ import ( ...@@ -15,7 +15,11 @@ import (
func TestKeyGeneration(t *testing.T) { func TestKeyGeneration(t *testing.T) {
random := rand.Reader random := rand.Reader
priv, err := GenerateKey(random, 1024) size := 1024
if testing.Short() {
size = 128
}
priv, err := GenerateKey(random, size)
if err != nil { if err != nil {
t.Errorf("failed to generate key") t.Errorf("failed to generate key")
} }
...@@ -99,6 +103,9 @@ func TestDecryptOAEP(t *testing.T) { ...@@ -99,6 +103,9 @@ func TestDecryptOAEP(t *testing.T) {
t.Errorf("#%d,%d (blind) bad result: %#v (want %#v)", i, j, out, message.in) t.Errorf("#%d,%d (blind) bad result: %#v (want %#v)", i, j, out, message.in)
} }
} }
if testing.Short() {
break
}
} }
} }
......
...@@ -74,7 +74,11 @@ func TestSortStrings(t *testing.T) { ...@@ -74,7 +74,11 @@ func TestSortStrings(t *testing.T) {
} }
func TestSortLarge_Random(t *testing.T) { func TestSortLarge_Random(t *testing.T) {
data := make([]int, 1000000) n := 1000000
if testing.Short() {
n /= 100
}
data := make([]int, n)
for i := 0; i < len(data); i++ { for i := 0; i < len(data); i++ {
data[i] = rand.Intn(100) data[i] = rand.Intn(100)
} }
...@@ -174,6 +178,9 @@ func lg(n int) int { ...@@ -174,6 +178,9 @@ func lg(n int) int {
func TestBentleyMcIlroy(t *testing.T) { func TestBentleyMcIlroy(t *testing.T) {
sizes := []int{100, 1023, 1024, 1025} sizes := []int{100, 1023, 1024, 1025}
if testing.Short() {
sizes = []int{100, 127, 128, 129}
}
dists := []string{"sawtooth", "rand", "stagger", "plateau", "shuffle"} dists := []string{"sawtooth", "rand", "stagger", "plateau", "shuffle"}
modes := []string{"copy", "reverse", "reverse1", "reverse2", "sort", "dither"} modes := []string{"copy", "reverse", "reverse1", "reverse2", "sort", "dither"}
var tmp1, tmp2 [1025]int var tmp1, tmp2 [1025]int
......
...@@ -617,7 +617,11 @@ func equal(m string, s1, s2 string, t *testing.T) bool { ...@@ -617,7 +617,11 @@ func equal(m string, s1, s2 string, t *testing.T) bool {
func TestCaseConsistency(t *testing.T) { func TestCaseConsistency(t *testing.T) {
// Make a string of all the runes. // Make a string of all the runes.
a := make([]int, unicode.MaxRune+1) numRunes := unicode.MaxRune + 1
if testing.Short() {
numRunes = 1000
}
a := make([]int, numRunes)
for i := range a { for i := range a {
a[i] = i a[i] = i
} }
...@@ -627,10 +631,10 @@ func TestCaseConsistency(t *testing.T) { ...@@ -627,10 +631,10 @@ func TestCaseConsistency(t *testing.T) {
lower := ToLower(s) lower := ToLower(s)
// Consistency checks // Consistency checks
if n := utf8.RuneCountInString(upper); n != unicode.MaxRune+1 { if n := utf8.RuneCountInString(upper); n != numRunes {
t.Error("rune count wrong in upper:", n) t.Error("rune count wrong in upper:", n)
} }
if n := utf8.RuneCountInString(lower); n != unicode.MaxRune+1 { if n := utf8.RuneCountInString(lower); n != numRunes {
t.Error("rune count wrong in lower:", n) t.Error("rune count wrong in lower:", n)
} }
if !equal("ToUpper(upper)", ToUpper(upper), upper, t) { if !equal("ToUpper(upper)", ToUpper(upper), upper, t) {
......
...@@ -370,10 +370,11 @@ func hammerCompareAndSwapUintptr32(uval *uint32, count int) { ...@@ -370,10 +370,11 @@ func hammerCompareAndSwapUintptr32(uval *uint32, count int) {
} }
func TestHammer32(t *testing.T) { func TestHammer32(t *testing.T) {
const ( const p = 4
n = 100000 n := 100000
p = 4 if testing.Short() {
) n = 1000
}
defer runtime.GOMAXPROCS(runtime.GOMAXPROCS(p)) defer runtime.GOMAXPROCS(runtime.GOMAXPROCS(p))
for _, tt := range hammer32 { for _, tt := range hammer32 {
...@@ -391,7 +392,7 @@ func TestHammer32(t *testing.T) { ...@@ -391,7 +392,7 @@ func TestHammer32(t *testing.T) {
for i := 0; i < p; i++ { for i := 0; i < p; i++ {
<-c <-c
} }
if val != n*p { if val != uint32(n)*p {
t.Errorf("%s: val=%d want %d", tt.name, val, n*p) t.Errorf("%s: val=%d want %d", tt.name, val, n*p)
} }
} }
...@@ -478,10 +479,11 @@ func hammerCompareAndSwapUintptr64(uval *uint64, count int) { ...@@ -478,10 +479,11 @@ func hammerCompareAndSwapUintptr64(uval *uint64, count int) {
} }
func TestHammer64(t *testing.T) { func TestHammer64(t *testing.T) {
const ( const p = 4
n = 100000 n := 100000
p = 4 if testing.Short() {
) n = 1000
}
defer runtime.GOMAXPROCS(runtime.GOMAXPROCS(p)) defer runtime.GOMAXPROCS(runtime.GOMAXPROCS(p))
for _, tt := range hammer64 { for _, tt := range hammer64 {
...@@ -499,7 +501,7 @@ func TestHammer64(t *testing.T) { ...@@ -499,7 +501,7 @@ func TestHammer64(t *testing.T) {
for i := 0; i < p; i++ { for i := 0; i < p; i++ {
<-c <-c
} }
if val != n*p { if val != uint64(n)*p {
t.Errorf("%s: val=%d want %d", tt.name, val, n*p) t.Errorf("%s: val=%d want %d", tt.name, val, n*p)
} }
} }
......
...@@ -102,16 +102,20 @@ func HammerRWMutex(gomaxprocs, numReaders, num_iterations int) { ...@@ -102,16 +102,20 @@ func HammerRWMutex(gomaxprocs, numReaders, num_iterations int) {
} }
func TestRWMutex(t *testing.T) { func TestRWMutex(t *testing.T) {
HammerRWMutex(1, 1, 1000) n := 1000
HammerRWMutex(1, 3, 1000) if testing.Short() {
HammerRWMutex(1, 10, 1000) n = 5
HammerRWMutex(4, 1, 1000) }
HammerRWMutex(4, 3, 1000) HammerRWMutex(1, 1, n)
HammerRWMutex(4, 10, 1000) HammerRWMutex(1, 3, n)
HammerRWMutex(10, 1, 1000) HammerRWMutex(1, 10, n)
HammerRWMutex(10, 3, 1000) HammerRWMutex(4, 1, n)
HammerRWMutex(10, 10, 1000) HammerRWMutex(4, 3, n)
HammerRWMutex(10, 5, 10000) HammerRWMutex(4, 10, n)
HammerRWMutex(10, 1, n)
HammerRWMutex(10, 3, n)
HammerRWMutex(10, 10, n)
HammerRWMutex(10, 5, n)
} }
func TestRLocker(t *testing.T) { func TestRLocker(t *testing.T) {
......
...@@ -186,7 +186,7 @@ func RunTests(matchString func(pat, str string) (bool, os.Error), tests []Intern ...@@ -186,7 +186,7 @@ func RunTests(matchString func(pat, str string) (bool, os.Error), tests []Intern
go tRunner(t, &tests[i]) go tRunner(t, &tests[i])
<-t.ch <-t.ch
ns += time.Nanoseconds() ns += time.Nanoseconds()
tstr := fmt.Sprintf("(%.1f seconds)", float64(ns)/1e9) tstr := fmt.Sprintf("(%.2f seconds)", float64(ns)/1e9)
if t.failed { if t.failed {
println("--- FAIL:", tests[i].Name, tstr) println("--- FAIL:", tests[i].Name, tstr)
print(t.errors) print(t.errors)
......
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