go/src/testing
Bryan C. Mills 55b8e16b2e testing: use monotonic counts to attribute races in subtests
This implements the approach I described in
https://go-review.git.corp.google.com/c/go/+/494057/1#message-5c9773bded2f89b4058848cb036b860aa6716de3.

Specifically:

- Each level of test atomically records the cumulative number of races
  seen as of the last race-induced test failure.

- When a subtest fails, it logs the race error, and then updates its
  parents' counters so that they will not log the same error.

- We check each test or benchmark for races before it starts running
  each of its subtests or sub-benchmark, before unblocking parallel
  subtests, and after running any cleanup functions.

With this implementation, it should be the case that every test that
is running when a race is detected reports that race, and any race
reported for a subtest is not redundantly reported for its parent.

The regression tests are based on those added in CL 494057 and
CL 501895, with a few additions based on my own review of the code.

Fixes #60083.

Change-Id: I578ae929f192a7a951b31b17ecb560cbbf1ef7a1
Cq-Include-Trybots: luci.golang.try:gotip-linux-amd64-longtest,gotip-linux-amd64-longtest-race,gotip-windows-amd64-longtest
Reviewed-on: https://go-review.googlesource.com/c/go/+/506300
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-10-25 20:44:25 +00:00
..
fstest testing/fstest: add godoc links 2023-10-11 20:21:27 +00:00
internal/testdeps all: gofmt -w -r 'interface{} -> any' src 2021-12-13 18:45:54 +00:00
iotest testing: use strings.Builder 2022-09-07 07:03:10 +00:00
quick database/sql,testing/quick: use reflect.Value.SetZero 2023-04-04 07:16:34 +00:00
slogtest testing/slogtest: test no source key with empty PC in record 2023-10-24 15:06:07 +00:00
allocs.go
allocs_test.go all: gofmt -w -r 'interface{} -> any' src 2021-12-13 18:45:54 +00:00
benchmark.go testing: use monotonic counts to attribute races in subtests 2023-10-25 20:44:25 +00:00
benchmark_test.go testing: add an example showcasing B.RunParallel with B.ReportMetric 2022-10-07 17:49:17 +00:00
cover.go cmd/go,testing: re-implement testing.Coverage 2023-05-23 11:37:31 +00:00
example.go testing: enforce -skip in example tests 2023-07-21 21:37:46 +00:00
export_test.go
flag_test.go all: use ^TestName$ regular pattern for invoking a single test 2023-09-05 23:35:29 +00:00
fuzz.go testing: use monotonic counts to attribute races in subtests 2023-10-25 20:44:25 +00:00
helper_test.go cmd/go, testing: add go test -skip flag 2022-09-16 14:48:54 +00:00
helperfuncs_test.go cmd/compile: mark closures made for generic function expressions as wrappers 2022-05-26 21:06:31 +00:00
match.go all: use built-in clear to clear maps 2023-07-27 22:07:13 +00:00
match_test.go cmd/go, testing: add go test -skip flag 2022-09-16 14:48:54 +00:00
newcover.go cmd/go,testing: re-implement testing.Coverage 2023-05-23 11:37:31 +00:00
panic_test.go all: use ^TestName$ regular pattern for invoking a single test 2023-09-05 23:35:29 +00:00
run_example.go all: add wasip1 support 2023-04-11 20:56:32 +00:00
run_example_wasm.go all: add wasip1 support 2023-04-11 20:56:32 +00:00
sub_test.go testing: in TestRacyOutput, ensure that the Run calls complete before cleanup 2022-11-16 17:22:19 +00:00
testing.go testing: use monotonic counts to attribute races in subtests 2023-10-25 20:44:25 +00:00
testing_other.go testing: include ERROR_SHARING_VIOLATION in Windows cleanup retries 2022-03-03 02:39:01 +00:00
testing_test.go testing: use monotonic counts to attribute races in subtests 2023-10-25 20:44:25 +00:00
testing_windows.go testing: include ERROR_SHARING_VIOLATION in Windows cleanup retries 2022-03-03 02:39:01 +00:00