From: Dmitry Vyukov Date: Wed, 27 Jan 2016 18:22:28 +0000 (+0100) Subject: runtime/race: run tests with GOMAXPROCS=1 X-Git-Tag: go1.6rc1~8 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=572f7660a774ebd8552408a6058b36cc90f6f563;p=gostls13.git runtime/race: run tests with GOMAXPROCS=1 We set GOMAXPROCS=1 to prevent test flakiness. There are two sources of flakiness: 1. Some tests rely on particular execution order. If the order is different, race does not happen at all. 2. Ironically, ThreadSanitizer runtime contains a logical race condition that can lead to false negatives if racy accesses happen literally at the same time. Tests used to work reliably in the good old days of GOMAXPROCS=1. So let's set it for now. A more reliable solution is to explicitly annotate tests with required execution order by means of a special "invisible" synchronization primitive (that's what is done for C++ ThreadSanitizer tests). This is issue #14119. This reduces flakes on RaceAsFunc3 test from 60/3000 to 1/3000. Fixes #14086 Fixes #14079 Fixes #14035 Change-Id: Ibaec6b2b21e27b62563bffbb28473a854722cf41 Reviewed-on: https://go-review.googlesource.com/18968 Reviewed-by: Austin Clements Run-TryBot: Austin Clements Reviewed-by: Russ Cox TryBot-Result: Gobot Gobot --- diff --git a/src/runtime/race/output_test.go b/src/runtime/race/output_test.go index a9f9f0fbd5..0c71a019dd 100644 --- a/src/runtime/race/output_test.go +++ b/src/runtime/race/output_test.go @@ -51,7 +51,10 @@ func TestOutput(t *testing.T) { } cmd.Env = append(cmd.Env, env) } - cmd.Env = append(cmd.Env, "GORACE="+test.gorace) + cmd.Env = append(cmd.Env, + "GOMAXPROCS=1", // see comment in race_test.go + "GORACE="+test.gorace, + ) got, _ := cmd.CombinedOutput() if !regexp.MustCompile(test.re).MatchString(string(got)) { t.Fatalf("failed test case %v, expect:\n%v\ngot:\n%s", diff --git a/src/runtime/race/race_test.go b/src/runtime/race/race_test.go index 6898e74900..748f33883b 100644 --- a/src/runtime/race/race_test.go +++ b/src/runtime/race/race_test.go @@ -155,7 +155,20 @@ func runTests() ([]byte, error) { } cmd.Env = append(cmd.Env, env) } - cmd.Env = append(cmd.Env, `GORACE=suppress_equal_stacks=0 suppress_equal_addresses=0 exitcode=0`) + // We set GOMAXPROCS=1 to prevent test flakiness. + // There are two sources of flakiness: + // 1. Some tests rely on particular execution order. + // If the order is different, race does not happen at all. + // 2. Ironically, ThreadSanitizer runtime contains a logical race condition + // that can lead to false negatives if racy accesses happen literally at the same time. + // Tests used to work reliably in the good old days of GOMAXPROCS=1. + // So let's set it for now. A more reliable solution is to explicitly annotate tests + // with required execution order by means of a special "invisible" synchronization primitive + // (that's what is done for C++ ThreadSanitizer tests). This is issue #14119. + cmd.Env = append(cmd.Env, + "GOMAXPROCS=1", + "GORACE=suppress_equal_stacks=0 suppress_equal_addresses=0 exitcode=0", + ) return cmd.CombinedOutput() }