]> Cypherpunks repositories - gostls13.git/commitdiff
testing: shorten some tests.
authorRob Pike <r@golang.org>
Fri, 25 Mar 2011 23:31:10 +0000 (16:31 -0700)
committerRob Pike <r@golang.org>
Fri, 25 Mar 2011 23:31:10 +0000 (16:31 -0700)
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

src/pkg/bytes/buffer_test.go
src/pkg/bytes/bytes_test.go
src/pkg/crypto/openpgp/s2k/s2k_test.go
src/pkg/crypto/rand/rand_test.go
src/pkg/crypto/rsa/pkcs1v15_test.go
src/pkg/crypto/rsa/rsa_test.go
src/pkg/sort/sort_test.go
src/pkg/strings/strings_test.go
src/pkg/sync/atomic/atomic_test.go
src/pkg/sync/rwmutex_test.go
src/pkg/testing/testing.go

index 56a2d927539007b68433df33afb3a5f4f0950b54..14f9501416e1b51f6a77089862ae47cc173c49c0 100644 (file)
@@ -178,7 +178,11 @@ func TestBasicOperations(t *testing.T) {
 
 func TestLargeStringWrites(t *testing.T) {
        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)
                empty(t, "TestLargeStringWrites (2)", &buf, s, make([]byte, len(data)/i))
        }
@@ -188,7 +192,11 @@ func TestLargeStringWrites(t *testing.T) {
 
 func TestLargeByteWrites(t *testing.T) {
        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)
                empty(t, "TestLargeByteWrites (2)", &buf, s, make([]byte, len(data)/i))
        }
index 063686ec5d6e7d01cc28c44b4053bf1da8ef7f8e..4ce291a4f67b2fc05935f1df6405fa406e75d563 100644 (file)
@@ -201,7 +201,10 @@ func TestIndexByte(t *testing.T) {
 
 // test a larger buffer with different sizes and alignments
 func TestIndexByteBig(t *testing.T) {
-       const n = 1024
+       var n = 1024
+       if testing.Short() {
+               n = 128
+       }
        b := make([]byte, n)
        for i := 0; i < n; i++ {
                // different start alignments
index 814b78627f4ddfdaf1c059164df70c5212fe46f6..75bc47ec10b6f25f3bd04f19acaf5fa6594a25a6 100644 (file)
@@ -90,5 +90,8 @@ func TestParse(t *testing.T) {
                if !bytes.Equal(out, expected) {
                        t.Errorf("%d: output got: %x want: %x", i, out, expected)
                }
+               if testing.Short() {
+                       break
+               }
        }
 }
index f64ead4cab46993878dc70dfce1cf2608f4f751e..bfae7ce4f9bf075c82fcede3a2237a22a0e98b21 100644 (file)
@@ -11,7 +11,11 @@ import (
 )
 
 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)
        if n != len(b) || err != nil {
                t.Fatalf("Read(buf) = %d, %s", n, err)
index 7b2ce08cb0bf5c96f43cfcad228e8a46bbc5fb3f..30a4824a6b0566471ec4c92870298299aff0cc47 100644 (file)
@@ -97,7 +97,11 @@ func TestEncryptPKCS1v15(t *testing.T) {
                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`
index 22d4576e8dd527afad8bc87f43fb517bb0356202..bf7c05137a38a4e75b6d7c60bd39407326fb0e27 100644 (file)
@@ -15,7 +15,11 @@ import (
 func TestKeyGeneration(t *testing.T) {
        random := rand.Reader
 
-       priv, err := GenerateKey(random, 1024)
+       size := 1024
+       if testing.Short() {
+               size = 128
+       }
+       priv, err := GenerateKey(random, size)
        if err != nil {
                t.Errorf("failed to generate key")
        }
@@ -99,6 +103,9 @@ func TestDecryptOAEP(t *testing.T) {
                                t.Errorf("#%d,%d (blind) bad result: %#v (want %#v)", i, j, out, message.in)
                        }
                }
+               if testing.Short() {
+                       break
+               }
        }
 }
 
index 1bea8f032621d9fb74014eca96d475b84ff07b49..3d7337fd01007ce6916f98f655d2e8268c05d19d 100644 (file)
@@ -74,7 +74,11 @@ func TestSortStrings(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++ {
                data[i] = rand.Intn(100)
        }
@@ -174,6 +178,9 @@ func lg(n int) int {
 
 func TestBentleyMcIlroy(t *testing.T) {
        sizes := []int{100, 1023, 1024, 1025}
+       if testing.Short() {
+               sizes = []int{100, 127, 128, 129}
+       }
        dists := []string{"sawtooth", "rand", "stagger", "plateau", "shuffle"}
        modes := []string{"copy", "reverse", "reverse1", "reverse2", "sort", "dither"}
        var tmp1, tmp2 [1025]int
index 41e398782e686d6c60ef785de276106973a6dd6e..d75f1ad9c65edda1fb83c5f352d3027068be83e9 100644 (file)
@@ -617,7 +617,11 @@ func equal(m string, s1, s2 string, t *testing.T) bool {
 
 func TestCaseConsistency(t *testing.T) {
        // 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 {
                a[i] = i
        }
@@ -627,10 +631,10 @@ func TestCaseConsistency(t *testing.T) {
        lower := ToLower(s)
 
        // 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)
        }
-       if n := utf8.RuneCountInString(lower); n != unicode.MaxRune+1 {
+       if n := utf8.RuneCountInString(lower); n != numRunes {
                t.Error("rune count wrong in lower:", n)
        }
        if !equal("ToUpper(upper)", ToUpper(upper), upper, t) {
index 7b204b1d9f0e552216ff6ac2279ac0faa4ec64c0..bf8a692b6052e61a2788b5253fae26a0ee7955e9 100644 (file)
@@ -370,10 +370,11 @@ func hammerCompareAndSwapUintptr32(uval *uint32, count int) {
 }
 
 func TestHammer32(t *testing.T) {
-       const (
-               n = 100000
-               p = 4
-       )
+       const p = 4
+       n := 100000
+       if testing.Short() {
+               n = 1000
+       }
        defer runtime.GOMAXPROCS(runtime.GOMAXPROCS(p))
 
        for _, tt := range hammer32 {
@@ -391,7 +392,7 @@ func TestHammer32(t *testing.T) {
                for i := 0; i < p; i++ {
                        <-c
                }
-               if val != n*p {
+               if val != uint32(n)*p {
                        t.Errorf("%s: val=%d want %d", tt.name, val, n*p)
                }
        }
@@ -478,10 +479,11 @@ func hammerCompareAndSwapUintptr64(uval *uint64, count int) {
 }
 
 func TestHammer64(t *testing.T) {
-       const (
-               n = 100000
-               p = 4
-       )
+       const p = 4
+       n := 100000
+       if testing.Short() {
+               n = 1000
+       }
        defer runtime.GOMAXPROCS(runtime.GOMAXPROCS(p))
 
        for _, tt := range hammer64 {
@@ -499,7 +501,7 @@ func TestHammer64(t *testing.T) {
                for i := 0; i < p; i++ {
                        <-c
                }
-               if val != n*p {
+               if val != uint64(n)*p {
                        t.Errorf("%s: val=%d want %d", tt.name, val, n*p)
                }
        }
index 405079270dcc7254c657ac5c241b516d0a1c4962..9fb89f8e8a32a3c5c63d36099b3e63eb00011c07 100644 (file)
@@ -102,16 +102,20 @@ func HammerRWMutex(gomaxprocs, numReaders, num_iterations int) {
 }
 
 func TestRWMutex(t *testing.T) {
-       HammerRWMutex(1, 1, 1000)
-       HammerRWMutex(1, 3, 1000)
-       HammerRWMutex(1, 10, 1000)
-       HammerRWMutex(4, 1, 1000)
-       HammerRWMutex(4, 3, 1000)
-       HammerRWMutex(4, 10, 1000)
-       HammerRWMutex(10, 1, 1000)
-       HammerRWMutex(10, 3, 1000)
-       HammerRWMutex(10, 10, 1000)
-       HammerRWMutex(10, 5, 10000)
+       n := 1000
+       if testing.Short() {
+               n = 5
+       }
+       HammerRWMutex(1, 1, n)
+       HammerRWMutex(1, 3, n)
+       HammerRWMutex(1, 10, n)
+       HammerRWMutex(4, 1, n)
+       HammerRWMutex(4, 3, n)
+       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) {
index cdc98262902e3248f9250c0fa0cbeaf103909083..d1893907a565131fa43af76e8315793cc383570c 100644 (file)
@@ -186,7 +186,7 @@ func RunTests(matchString func(pat, str string) (bool, os.Error), tests []Intern
                go tRunner(t, &tests[i])
                <-t.ch
                ns += time.Nanoseconds()
-               tstr := fmt.Sprintf("(%.1f seconds)", float64(ns)/1e9)
+               tstr := fmt.Sprintf("(%.2f seconds)", float64(ns)/1e9)
                if t.failed {
                        println("--- FAIL:", tests[i].Name, tstr)
                        print(t.errors)