]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: convert tests using testdata/src/testrace to script framework
authorMichael Matloob <matloob@golang.org>
Thu, 2 Jan 2020 20:47:45 +0000 (15:47 -0500)
committerMichael Matloob <matloob@golang.org>
Tue, 7 Jan 2020 18:35:31 +0000 (18:35 +0000)
Part of converting all tests to script framework to improve
test parallelism.

Updates #36320
Updates #17751

Change-Id: Id4c2c58167d5cfc80b0d81ca9ce3db678242c06c
Reviewed-on: https://go-review.googlesource.com/c/go/+/213128
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
src/cmd/go/go_test.go
src/cmd/go/testdata/script/test_race.txt [moved from src/cmd/go/testdata/src/testrace/race_test.go with 57% similarity]
src/cmd/go/testdata/script/test_race_cover_mode_issue20435.txt [new file with mode: 0644]

index ddc29fbff9e6de7e2179856ec7c0c034d31f51ef..76566f3c3a8abd7f324702eca762fc6f4679b096 100644 (file)
@@ -3092,29 +3092,6 @@ func TestGoTestRaceInstallCgo(t *testing.T) {
        }
 }
 
-func TestGoTestRaceFailures(t *testing.T) {
-       tooSlow(t)
-
-       if !canRace {
-               t.Skip("skipping because race detector not supported")
-       }
-
-       tg := testgo(t)
-       tg.parallel()
-       defer tg.cleanup()
-       tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata"))
-
-       tg.run("test", "testrace")
-
-       tg.runFail("test", "-race", "testrace")
-       tg.grepStdout("FAIL: TestRace", "TestRace did not fail")
-       tg.grepBothNot("PASS", "something passed")
-
-       tg.runFail("test", "-race", "testrace", "-run", "XXX", "-bench", ".")
-       tg.grepStdout("FAIL: BenchmarkRace", "BenchmarkRace did not fail")
-       tg.grepBothNot("PASS", "something passed")
-}
-
 func TestGoGetUpdate(t *testing.T) {
        // golang.org/issue/9224.
        // The recursive updating was trying to walk to
@@ -4028,25 +4005,6 @@ func TestCgoFlagContainsSpace(t *testing.T) {
        tg.grepStderrNot(`"-L[^"]+c flags".*"-L[^"]+c flags"`, "found too many quoted ld flags")
 }
 
-// Issue #20435.
-func TestGoTestRaceCoverModeFailures(t *testing.T) {
-       tooSlow(t)
-       if !canRace {
-               t.Skip("skipping because race detector not supported")
-       }
-
-       tg := testgo(t)
-       tg.parallel()
-       defer tg.cleanup()
-       tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata"))
-
-       tg.run("test", "testrace")
-
-       tg.runFail("test", "-race", "-covermode=set", "testrace")
-       tg.grepStderr(`-covermode must be "atomic", not "set", when -race is enabled`, "-race -covermode=set was allowed")
-       tg.grepBothNot("PASS", "something passed")
-}
-
 // Issue 9737: verify that GOARM and GO386 affect the computed build ID.
 func TestBuildIDContainsArchModeEnv(t *testing.T) {
        if testing.Short() {
similarity index 57%
rename from src/cmd/go/testdata/src/testrace/race_test.go
rename to src/cmd/go/testdata/script/test_race.txt
index 7ec0c6d17a33505ac351db73a26176ca3ff8e1d6..5d15189e195722bd68035a760ade8c5744a5a6b2 100644 (file)
@@ -1,3 +1,19 @@
+[short] skip
+[!race] skip
+
+go test testrace
+
+! go test -race testrace
+stdout 'FAIL: TestRace'
+! stdout 'PASS'
+! stderr 'PASS'
+
+! go test -race testrace -run XXX -bench .
+stdout 'FAIL: BenchmarkRace'
+! stdout 'PASS'
+! stderr 'PASS'
+
+-- testrace/race_test.go --
 package testrace
 
 import "testing"
diff --git a/src/cmd/go/testdata/script/test_race_cover_mode_issue20435.txt b/src/cmd/go/testdata/script/test_race_cover_mode_issue20435.txt
new file mode 100644 (file)
index 0000000..bff9502
--- /dev/null
@@ -0,0 +1,44 @@
+[short] skip
+[!race] skip
+
+# Make sure test is functional.
+go test testrace
+
+# Now, check that -race -covermode=set is not allowed.
+! go test -race -covermode=set testrace
+stderr '-covermode must be "atomic", not "set", when -race is enabled'
+! stdout PASS
+! stderr PASS
+
+-- testrace/race_test.go --
+package testrace
+
+import "testing"
+
+func TestRace(t *testing.T) {
+       for i := 0; i < 10; i++ {
+               c := make(chan int)
+               x := 1
+               go func() {
+                       x = 2
+                       c <- 1
+               }()
+               x = 3
+               <-c
+               _ = x
+       }
+}
+
+func BenchmarkRace(b *testing.B) {
+       for i := 0; i < b.N; i++ {
+               c := make(chan int)
+               x := 1
+               go func() {
+                       x = 2
+                       c <- 1
+               }()
+               x = 3
+               <-c
+               _ = x
+       }
+}