aboutsummaryrefslogtreecommitdiff
path: root/src/testing/testing.go
AgeCommit message (Collapse)Author
18 hourstesting: print the counter if its greater than 1Shulhan
When test run with "-count=Y" and Y is greater that 1, print a line to indicated the current round of test as "### X/Y".
6 daystesting: document T.Parallel pause-and-resume behaviorMateusz Poliwczak
The behaviour seems important to be documented explicitly. Change-Id: I9aabd0b85d2e5754d2bee4e5d8bcf8816a6a6964 Reviewed-on: https://go-review.googlesource.com/c/go/+/764840 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Alan Donovan <adonovan@google.com>
2026-03-11testing: recognize helper functions that use range-over-functionIan Lance Taylor
This assumes the current behavior of the gc compiler: range functions use a suffix of -rangeNNNN. Fixes #72794 Change-Id: I3c10c60829853cf2cb4c17a75f6243def0313ae9 Reviewed-on: https://go-review.googlesource.com/c/go/+/656775 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: David Chase <drchase@google.com> Auto-Submit: David Chase <drchase@google.com>
2026-03-09testing: annotate output text typeEthan Reesor
Provides a way to disambiguate output produced by (*testing.T).Error{,f} and (*testing.T).Fatal{,f} from other test logging. This allows test tooling such as CI systems to identify which part of the output is most pertinent for constructing summaries of test failures. This is achieved by adding an OutputType field to output events. The output type for an error is "error" for the first line and "error-continue" for subsequentlines. The output type for framing is "frame". This is achieved by bracketing error output with ^O and ^N, escaped with ^[. Fixes golang/go#62728. Change-Id: Ib09c18ed5f729e1ae6d335cd1ec7d818c71532e0 Reviewed-on: https://go-review.googlesource.com/c/go/+/601535 Reviewed-by: Michael Matloob <matloob@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Damien Neil <dneil@google.com> Auto-Submit: Damien Neil <dneil@google.com>
2026-03-06testing: escapes framing markersEthan Reesor
Uses `^[` to escape the framing marker `^V` used to delimit test output. A test that itself executes a go test binary, or otherwise emits that control character, previously would corrupt the test2json parse of the enclosing run. Updates #62728. Change-Id: I0e8790a05fd7af469cd7ee2e8ccc13786cc372dc Reviewed-on: https://go-review.googlesource.com/c/go/+/751940 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Matloob <matloob@google.com> Reviewed-by: Damien Neil <dneil@google.com>
2026-03-06testing: fix construction of the testing artifacts pathRuss Egan
The existing implementation had a few problems: - It constructs a path which starts with a forward slash, which is then immediately rejected by filepath.Localize() as invalid. - It did not correctly remove the module path from the import path if the test was in the root package of the module: it would do the equivalent of strings.TrimPrefix("example.com/jdoe/loader", "example.com/jdoe/loader/"), which trims nothing, and leaves the full module name in the base. - Tests didn't check for any behaviors related to which artifact path was selected. Removed leading slash, handle tests in the root package by omitting the <pkg> component from the artifact dir path, and add tests. Fixes #77763 Change-Id: I00fc7381b939e4d8a8a9811e2a95fc2d8c5a6e84 GitHub-Last-Rev: 9c39392a691a81cef48adde88ab45dc40ed81105 GitHub-Pull-Request: golang/go#77778 Reviewed-on: https://go-review.googlesource.com/c/go/+/748581 Auto-Submit: Damien Neil <dneil@google.com> Reviewed-by: Damien Neil <dneil@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
2025-11-26crypto,testing/cryptotest: ignore random io.Reader params, add SetGlobalRandomFilippo Valsorda
First, we centralize all random bytes generation through drbg.Read. The rest of the FIPS 140-3 module can't use external functions anyway, so drbg.Read needs to have all the logic. Then, make sure that the crypto/... tree uses drbg.Read (or the new crypto/internal/rand.Reader wrapper) instead of crypto/rand, so it is unaffected by applications setting crypto/rand.Reader. Next, pass all unspecified random io.Reader parameters through the new crypto/internal/rand.CustomReader, which just redirects to drbg.Read unless GODEBUG=cryptocustomrand=1 is set. Move all the calls to MaybeReadByte there, since it's only needed for these custom Readers. Finally, add testing/cryptotest.SetGlobalRandom which sets crypto/rand.Reader to a locked deterministic source and overrides drbg.Read. This way SetGlobalRandom should affect all cryptographic randomness in the standard library. Fixes #70942 Co-authored-by: qiulaidongfeng <2645477756@qq.com> Change-Id: I6a6a69641311d9fac318abcc6d79677f0e406100 Reviewed-on: https://go-review.googlesource.com/c/go/+/724480 Reviewed-by: Nicholas Husin <nsh@golang.org> Auto-Submit: Filippo Valsorda <filippo@golang.org> Reviewed-by: Nicholas Husin <husin@google.com> Reviewed-by: Roland Shoemaker <roland@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-10-07cmd/go, testing: add TB.ArtifactDir and -artifacts flagDamien Neil
Add TB.ArtifactDir, which returns a directory for a test to store output files in. Add a -artifacts testflag which enables persistent storage of artifacts in the output directory (-outputdir, or the current directory by default). Fixes #71287 Change-Id: I5f6515a6cd6c103f88588f4c033d5ea11ffd0c3c Reviewed-on: https://go-review.googlesource.com/c/go/+/696399 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Alan Donovan <adonovan@google.com>
2025-09-19testing: fix example for unexported identifierSean Liao
Fixes #75540 Change-Id: I925f893d33660f0b08996d53cc9c564017232b39 Reviewed-on: https://go-review.googlesource.com/c/go/+/705456 Reviewed-by: Alan Donovan <adonovan@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Knyszek <mknyszek@google.com>
2025-08-29testing: allow specify temp dir by GOTMPDIR environment variableAN Long
Allow change the default temp directory returned by t.TempDir() by environment variable GOTMPDIR. Fixes #61585 Change-Id: Iba969bb02744e106cf15d80e0eda0245a55fc290 GitHub-Last-Rev: aeacea00952b11990b49a0fde6a0ce4fe910b777 GitHub-Pull-Request: golang/go#74844 Reviewed-on: https://go-review.googlesource.com/c/go/+/692455 Reviewed-by: Damien Neil <dneil@google.com> Auto-Submit: Sean Liao <sean@liao.dev> Reviewed-by: Sean Liao <sean@liao.dev> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
2025-06-20testing, testing/synctest: handle T.Helper in synctest bubblesDamien Neil
Fixes #74199 Change-Id: I6a15fbd59a3a3f8c496440f56d09d695e1504e4e Reviewed-on: https://go-review.googlesource.com/c/go/+/682576 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Alan Donovan <adonovan@google.com> Auto-Submit: Damien Neil <dneil@google.com>
2025-06-02testing: add Output method to TBMateusz Poliwczak
Updates #59928 Fixes #73937 Change-Id: Ibf7ec61758edccd245841c3acc9096563b44fcd2 Reviewed-on: https://go-review.googlesource.com/c/go/+/677875 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Jonathan Amsterdam <jba@google.com> Reviewed-by: Damien Neil <dneil@google.com>
2025-05-30testing, testing/synctest: report correct duration after panicsDamien Neil
Report the correct wall-clock test duration after handling a panic in a synctest.Test bubble. Fixes #73852 Change-Id: I053262e5eac2dd9d5938b17c3093cbc3fa115a0d Reviewed-on: https://go-review.googlesource.com/c/go/+/676695 Auto-Submit: Damien Neil <dneil@google.com> Reviewed-by: Alan Donovan <adonovan@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-05-29testing, testing/synctest: write bubble errors to parent test logDamien Neil
Ensure that log messages written to the testing.T created by synctest.Test appear in the test output when a test fails. Fixes #73902 Change-Id: Ie97f5efe54eb003e6c0a5394c2def4cac1520ecb Reviewed-on: https://go-review.googlesource.com/c/go/+/676995 Reviewed-by: Alan Donovan <adonovan@google.com> Auto-Submit: Damien Neil <dneil@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-05-21testing: add AttrDamien Neil
Add a new Attr method to testing.TB that emits a test attribute. An attribute is an arbitrary key/value pair. Fixes #43936 Change-Id: I7ef299efae41f2cf39f2dc61ad4cdd4c3975cdb6 Reviewed-on: https://go-review.googlesource.com/c/go/+/662437 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Alan Donovan <adonovan@google.com> Auto-Submit: Damien Neil <dneil@google.com>
2025-05-20testing/synctest: add TestDamien Neil
Add a synctest.Test function, superseding the experimental synctest.Run function. Promote the testing/synctest package out of experimental status. For #67434 For #73567 Change-Id: I3c5ba030860d90fe2ddb517a2f3536efd60181a9 Reviewed-on: https://go-review.googlesource.com/c/go/+/671961 Auto-Submit: Damien Neil <dneil@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Pratt <mpratt@google.com>
2025-05-15testing: fix panic in t.LogJonathan Amsterdam
If a testing.TB is no longer on the stack, t.Log would panic because its outputWriter is nil. Check for nil and drop the write, which is the previous behavior. Change-Id: Ifde97997a3aa26ae604ac9c218588c1980110cbf Reviewed-on: https://go-review.googlesource.com/c/go/+/673215 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Alan Donovan <adonovan@google.com> Auto-Submit: Jonathan Amsterdam <jba@google.com>
2025-05-13testing: add Outputsuntala
Output is a method on T, B and F. It provides an io.Writer that writes to the same test output stream as TB.Log. The new output writer is used to refactor the implementation of Log. It maintains the formatting provided by Log while making call site information optional. Additionally, it provides buffering of log messages. This fixes and expands on https://go-review.googlesource.com/c/go/+/646956. For #59928. Change-Id: I08179c35a681f601cf125c0f4aeb648bc10c7a9f GitHub-Last-Rev: e6e202793c9bc471493187e0556a3a1e7305ff82 GitHub-Pull-Request: golang/go#73703 Reviewed-on: https://go-review.googlesource.com/c/go/+/672395 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Alan Donovan <adonovan@google.com> Reviewed-by: Alan Donovan <adonovan@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Auto-Submit: Jonathan Amsterdam <jba@google.com>
2025-05-13Revert "testing: add Output"Jonathan Amsterdam
This reverts commit 8d189f188e225e4919b34c0c097e75dfda255949. Reason for revert: failing test Change-Id: I951087eaef7818697acf87e3206003bcc8a81ee2 Reviewed-on: https://go-review.googlesource.com/c/go/+/672335 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Jonathan Amsterdam <jba@google.com> Auto-Submit: Michael Knyszek <mknyszek@google.com> Reviewed-by: Michael Knyszek <mknyszek@google.com>
2025-05-13testing: add Outputsuntala
Output is a method on T, B and F. It provides an io.Writer that writes to the same test output stream as TB.Log. The new output writer is used to refactor the implementation of Log. It maintains the formatting provided by Log while making call site information optional. Additionally, it provides buffering of log messages. Co-authored-by: Aleks Fazlieva <britishrum@users.noreply.github.com> Fixes #59928. Change-Id: I29090b3d4f61f7334388b373ec18750d5637aafa GitHub-Last-Rev: 18af0e15262494f2074d545a6042b079d62301a2 GitHub-Pull-Request: golang/go#71575 Reviewed-on: https://go-review.googlesource.com/c/go/+/646956 Reviewed-by: Arati <artichaut2023@gmail.com> Auto-Submit: Jonathan Amsterdam <jba@google.com> Reviewed-by: Jonathan Amsterdam <jba@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Knyszek <mknyszek@google.com>
2025-05-12testing: limit TempDir name lengthSean Liao
Fixes #71742 Change-Id: Ibef8f7f0a36b25f181062c4d2f84279a97e467a4 Reviewed-on: https://go-review.googlesource.com/c/go/+/671577 Reviewed-by: Damien Neil <dneil@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Knyszek <mknyszek@google.com>
2025-04-30testing: use more doc linksSean Liao
Change-Id: Ide372735165b7510fd8d7588451a37fa743e59c1 Reviewed-on: https://go-review.googlesource.com/c/go/+/668915 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Commit-Queue: Alan Donovan <adonovan@google.com> Reviewed-by: Alan Donovan <adonovan@google.com> Auto-Submit: Alan Donovan <adonovan@google.com> Reviewed-by: Carlos Amedee <carlos@golang.org>
2025-03-25testing: document exit codesSean Liao
Fixes #25989 Change-Id: I2e2a2a17854034ff68e69b8973018b1b2e7d59f5 Reviewed-on: https://go-review.googlesource.com/c/go/+/660076 Reviewed-by: Thanyalak Detkhong (Palm’my) <pmy4416@gmail.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Damien Neil <dneil@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-03-24testing: remove redundant variable capture from subtest exampleJake Bailey
Loop variable capturing hasn't been needed like this since Go 1.21; remove it from the example. Change-Id: I231dcfdb57832e32d524f156a605ba36d1c9d6d9 Reviewed-on: https://go-review.googlesource.com/c/go/+/660176 Reviewed-by: Alan Donovan <adonovan@google.com> Auto-Submit: Alan Donovan <adonovan@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2025-03-10testing: warn against calling Log after a test completesSean Liao
Fixes #40343 Change-Id: Id266f4b57131e9e148e5aa2be86b67fe6d73b20a Reviewed-on: https://go-review.googlesource.com/c/go/+/656415 Auto-Submit: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Alan Donovan <adonovan@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2025-02-14testing: panic in AllocsPerRun if parallel tests are runningRuss Cox
If other tests are running, AllocsPerRun's result will be inherently flaky. Saw this with CL 630136 and #70327. Proposed in #70464. Fixes #70464. Change-Id: I190afdf26bc31299f6e5e8665b4fb420ffd554ee Reviewed-on: https://go-review.googlesource.com/c/go/+/630137 Auto-Submit: Russ Cox <rsc@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2025-02-05testing: use strings.SplitSeq and bytes.SplitSeqapocelipes
To simplify the code. This is a follow-up for the CL 646216. Change-Id: Ib09d1074a783482fb293527e9f1abeb3c02137c3 GitHub-Last-Rev: 2e7a6ad40cc22ea855e4d703ff39db9cc2c8a58e GitHub-Pull-Request: golang/go#71568 Reviewed-on: https://go-review.googlesource.com/c/go/+/646755 Reviewed-by: Jorropo <jorropo.pgm@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Salah (Globlost) <globlost@gmail.com> Reviewed-by: Damien Neil <dneil@google.com> Auto-Submit: Damien Neil <dneil@google.com> Reviewed-by: Alan Donovan <adonovan@google.com>
2025-02-03all: remove coverageredesign experimentIan Lance Taylor
The coverageredesign experiment was turned on by default by CL 436236 in September, 2022. We've documented it and people are using it. This CL removes the ability to turn off the experiment. This removes some old code that is no longer being executed. For #51430 Change-Id: I88d4998c8b5ea98eef8145d7ca6ebd96f64fbc2b Cq-Include-Trybots: luci.golang.try:gotip-linux-amd64-longtest,gotip-darwin-amd64-longtest,gotip-linux-arm64-longtest,gotip-windows-amd64-longtest Reviewed-on: https://go-review.googlesource.com/c/go/+/644997 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Than McIntosh <thanm@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com> Commit-Queue: Ian Lance Taylor <iant@google.com>
2025-01-21testing: fix reference to B.N in docstringKir Kolyshkin
Currently, a documentation reference to a struct member (such as [B.N]) does not result in it being rendered as a link, and thus the square brackets remain in the rendered documentation which is mildly confusing. The issue can be seen at https://pkg.go.dev/testing@master#hdr-b_N_style_benchmarks Remove the square brackets to fix. Change-Id: Id374fd2085bd511018220c5d663650f89672302e Reviewed-on: https://go-review.googlesource.com/c/go/+/643496 Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Alan Donovan <adonovan@google.com>
2024-12-18testing: support B.Context and F.ContextIan Lance Taylor
CL 603959 added T.Context for #36532. The discussion on the proposal only mentions t.Context. However, the implementation of CL 603959 also added B.Context and F.Context. They were added to the API listing, and B.Context was mentioned in the release notes. Unfortunately, the new B.Context and F.Context methods always returned nil, rather than a context.Context value. This change adds a working implementation of B.Context and F.Context. For #36532 Fixes #70866 Change-Id: I8a44e6649fb658e4f641ffb7efd08b4374f578ef Reviewed-on: https://go-review.googlesource.com/c/go/+/637236 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Damien Neil <dneil@google.com>
2024-12-15testing: improve B.Loop docs, use B.Loop in examplesAustin Clements
This updates the testing documentation to frame B.Loop as the canonical way to write benchmarks. We retain documentation on b.N benchmarks because people will definitely continue to see them (and write them), but it's demoted to clearly second class. This also attempts to clarify and refine the B.Loop documentation itself. Updates #61515 Fixes #70787 Change-Id: If5123435bfe3a5883a753119ecdf7bbc41afd499 Reviewed-on: https://go-review.googlesource.com/c/go/+/635895 Reviewed-by: Junyang Shao <shaojunyang@google.com> Reviewed-by: Caleb Spare <cespare@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Austin Clements <austin@google.com>
2024-08-21testing: rename testContext to testStateVladimir Varankin
Following up to CL 603959, update internals of testing package to reduce the confusion around "context". The changes rename testContext/benchContext/fuzzContext to testState/benchState/fuzzState. Change-Id: Ib8855dab456d41ab343488fcf5fefff2431f7b72 Reviewed-on: https://go-review.googlesource.com/c/go/+/607555 Auto-Submit: Ian Lance Taylor <iant@golang.org> Reviewed-by: Alan Donovan <adonovan@google.com> Reviewed-by: Damien Neil <dneil@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-08-20testing: add ContextVladimir Varankin
Adds a new Context method to testing.T, that returns a context, that is canceled before the end of its test function. Fixes #36532. Change-Id: I9315ad4dad25529d0b5be809e2d9db4e7528b5f2 GitHub-Last-Rev: 1c3fd6c4d8a9cc68a61f2df284d04d3d080216be GitHub-Pull-Request: golang/go#68828 Reviewed-on: https://go-review.googlesource.com/c/go/+/603959 Auto-Submit: Alan Donovan <adonovan@google.com> Reviewed-by: Alan Donovan <adonovan@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Damien Neil <dneil@google.com>
2024-08-16testing: add ChdirKir Kolyshkin
Some tests need to use os.Chdir, but the use is complicated because - they must change back to the old working directory; - they must not use t.Parallel. Add Chdir that covers these cases, and sets PWD environment variable to the new directory for the duration of the test for Unix platforms. Unify the panic message when t.Parallel is used together with t.Setenv or t.Chdir. Add some tests. For #62516. Change-Id: Ib050d173b26eb28a27dba5a206b2d0d877d761c1 Reviewed-on: https://go-review.googlesource.com/c/go/+/529895 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Carlos Amedee <carlos@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
2024-07-08testing: remove call to os.Exit in documentation for TestMainJulian Dax
In the example for the TestMain function, os.Exit was called explicitly, which is no longer necessary since Go 1.15 (see change #219639). Updates #34129 Change-Id: Ia8021de0d5699742adbb7ab6d28b11c841e596dc Reviewed-on: https://go-review.googlesource.com/c/go/+/596977 Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Damien Neil <dneil@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-05-23all: change from sort functions to slices functions where feasibleIan Lance Taylor
Doing this because the slices functions are slightly faster and slightly easier to use. It also removes one dependency layer. This CL does not change packages that are used during bootstrap, as the bootstrap compiler does not have the required slices functions. It does not change the go/scanner package because the ErrorList Len, Swap, and Less methods are part of the Go 1 API. Change-Id: If52899be791c829198e11d2408727720b91ebe8a Reviewed-on: https://go-review.googlesource.com/c/go/+/587655 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Commit-Queue: Ian Lance Taylor <iant@google.com> Reviewed-by: Damien Neil <dneil@google.com>
2024-05-21runtime/coverage: remove uses of //go:linknameRuss Cox
Move code to internal/coverage/cfile, making it possible to access directly from testing/internal/testdeps, so that we can avoid needing //go:linkname hacks. For #67401. Change-Id: I10b23a9970164afd2165e718ef3b2d9e86783883 Reviewed-on: https://go-review.googlesource.com/c/go/+/585820 Auto-Submit: Russ Cox <rsc@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Than McIntosh <thanm@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
2024-05-02testing: improve the documentation around b.NJorropo
Fixes #67137 - Make it clear the benchmark function is called multiple times. - Demonstrate range over int. Change-Id: I7e993d938b0351012cdd4aed8528951e0ad406ae Reviewed-on: https://go-review.googlesource.com/c/go/+/582835 Auto-Submit: Alan Donovan <adonovan@google.com> Reviewed-by: Alan Donovan <adonovan@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Damien Neil <dneil@google.com>
2024-04-26testing: use QueryPerformanceCounter on WindowsEgon Elbre
Windows time.Now granularity is around 0.5ms on modern systems, which introduces a significant noise into benchmark results. Instead of relying time.Now use QueryPerformanceCounter, which has significantly better granularity compared to time.Now. │ TimeNow-32 │ HighPrecisionTimeNow-32 │ │ sec/op │ sec/op vs base │ 4.812n ± 0% 30.580n ± 0% +535.43% (p=0.000 n=20) Fixes #31160 Change-Id: Ib2a574d638c9c6762a2524212def02265574e267 Reviewed-on: https://go-review.googlesource.com/c/go/+/557315 Reviewed-by: Quim Muntal <quimmuntal@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Alex Brainman <alex.brainman@gmail.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Michael Knyszek <mknyszek@google.com>
2024-03-26all: fix a large number of commentscui fliter
Partial typo corrections, following https://go.dev/wiki/Spelling Change-Id: I2357906ff2ea04305c6357418e4e9556e20375d1 Reviewed-on: https://go-review.googlesource.com/c/go/+/573776 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Than McIntosh <thanm@google.com> Run-TryBot: shuang cui <imcusg@gmail.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
2024-03-22Revert "testing: add TB.SetGOMAXPROCS function"Ian Lance Taylor
This reverts CL 519235. Reason for revert: Proposal is still in incoming. For #62020 Change-Id: Icccb930209f36097f5d930c01eda6b5042bdddc1 Reviewed-on: https://go-review.googlesource.com/c/go/+/573516 Reviewed-by: Than McIntosh <thanm@google.com> Auto-Submit: Ian Lance Taylor <iant@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2024-03-21testing: add TB.SetGOMAXPROCS functionsivchari
Add a new method TB.SetGOMAXPROCS which sets variable of GOMAXPROCS. This method aims to set a variable for the isolated lifetime of the test and cleans up. And unset this when the test ends. This method disables the test or benchmark from running in parallel. Fixes: #62020 Change-Id: Iae44109d0def35cc47049c3ca4cd5306173d52ee Signed-off-by: sivchari <shibuuuu5@gmail.com> Reviewed-on: https://go-review.googlesource.com/c/go/+/519235 Reviewed-by: Bryan Mills <bcmills@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-11-30testing: remove tests from the running log while they are waiting on ↵Bryan C. Mills
parallel subtests The parallel subtests are themselves removed from the running map while they are blocked on calls to t.Parallel, so it is misleading to log their parents as if they are running when we know they cannot be making any kind of meaningful progress. Fixes #64404. Change-Id: Iaad11d5d4f4c86d775d36e5285c49629dccddd74 Reviewed-on: https://go-review.googlesource.com/c/go/+/546018 Run-TryBot: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Bryan Mills <bcmills@google.com> Reviewed-by: Alan Donovan <adonovan@google.com>
2023-11-27Revert "testing: simplify concurrency and cleanup logic"Lasse Folger
reverts CL 506755 Reason for revert: This leads to deadlocks of tests in Google internal testing For #64402 Change-Id: I78329fc9dcc2377e7e880b264ac1d18d577ef99a Reviewed-on: https://go-review.googlesource.com/c/go/+/544895 Auto-Submit: Bryan Mills <bcmills@google.com> Auto-Submit: Lasse Folger <lassefolger@google.com> Reviewed-by: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Bryan Mills <bcmills@google.com>
2023-11-21testing: simplify concurrency and cleanup logicBryan C. Mills
While investigating #60083, I found a couple of bugs (notably #61034) that had slipped through code review in part because the concurrency patterns used in the testing package were too complex for me to fully reason about. This change adjusts those patterns to be more in line with current idioms, and to reduce the number of special cases that depend on details that should be orthogonal. (For example: the details of how we invoke the Cleanup functions should not depend on whether the test happened to run any parallel subtests.) In the process, this change fixes a handful of bugs: - Concurrent calls to Run (explicitly allowed by TestParallelSub) could previously drive the testcontext.running count negative, causing the number of running parallel tests to exceed the -parallel flag. - The -failfast flag now takes effect immediately on failure. It no longer delays until the test finishes, and no longer misses failures during cleanup (fixing #61034). - If a Cleanup function calls runtime.Goexit (typically via t.FailNow) during a panic, Cleanup functions from its parent tests are no longer skipped and buffered logs from its parent tests are now flushed. - The time reported for a test with subtests now includes the time spent running those subtests, regardless of whether they are parallel. (Previously, non-parallel subtests were included but parallel subtests were not.) - Calls to (*B).Run in iterations after the first are now diagnosed with a panic. (This diagnoses badly-behaved benchmarks: if Run is called during the first iteration, no subsequent iterations are supposed to occur.) Fixes #61034. Change-Id: I3797f6ef5210a3d2d5d6c2710d3f35c0219b02ea 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/+/506755 Auto-Submit: Bryan Mills <bcmills@google.com> Reviewed-by: Alan Donovan <adonovan@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-11-08testing: add available godoc linkcui fliter
Change-Id: I8f4d097601796f53176d490cddf8832b7caa4c05 Reviewed-on: https://go-review.googlesource.com/c/go/+/539836 Run-TryBot: shuang cui <imcusg@gmail.com> Reviewed-by: Bryan Mills <bcmills@google.com> Auto-Submit: Bryan Mills <bcmills@google.com> Reviewed-by: Heschi Kreinick <heschi@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-11-06testing: correct comments on runCleanupEvan Jones
The comment on runCleanup states "If catchPanic is true ...", but there is no catchPanic argument or variable. This was introduced in CL 214822, which introduced the panicHandling type. The code was updated during code review, but the comment was missed. Change-Id: Id14c5397e7a026bfdf98ea10ecb1e4c61ce2f924 Reviewed-on: https://go-review.googlesource.com/c/go/+/538695 Auto-Submit: Bryan Mills <bcmills@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Bryan Mills <bcmills@google.com> Reviewed-by: Heschi Kreinick <heschi@google.com>
2023-10-25testing: use monotonic counts to attribute races in subtestsBryan C. Mills
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-10testing: remove unnecessary TempDir implementation detail from its docVille Skyttä
The "by Cleanup" detail about the removal mechanism is not necessary for users. The previous wording could even cause confusion whether they should do something for Cleanup to occur. Change-Id: I617a7a4e118a70a3ad8a83a2d81cd911dde8ee08 GitHub-Last-Rev: fba4cde6362d1f0ea0c730d50fdd3fbaae4e17cf GitHub-Pull-Request: golang/go#63479 Reviewed-on: https://go-review.googlesource.com/c/go/+/534016 Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2023-09-13testing: use strings.LastIndexAny in (*common).decorateTobias Klauser
Change-Id: I14c521f4e599e14c71a52342b0ead5d0d4007f1e Reviewed-on: https://go-review.googlesource.com/c/go/+/527655 Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com> Reviewed-by: Kirill Kolyshkin <kolyshkin@gmail.com> Reviewed-by: Bryan Mills <bcmills@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com>