Description
This is a tracking issue for adding JSON output support to the test/run.go program, which is invoked by cmd/dist to run tests in the GOROOT/test directory. This is a subset of #37486, broken out into a smaller tracking issue.
This can ideally be implemented by refactoring this program into a normal Go test that can be invoked with go test
(which will then automatically have support JSON output via go test's -json
flag), or possibly adding a lightweight Go test on top of the existing test/run.go program. It is in principle also possible to add JSON output support to test/run.go directly, without making it a normal Go test. These are implementation details, need to investigate what approach works out better.
CC @aclements, @golang/release.
Metadata
Metadata
Assignees
Type
Projects
Status
Activity
aclements commentedon Nov 21, 2022
One complication to this I just discovered is that some of the misc/cgo tests (at least misc/cgo/stdio and misc/cgo/life) actually use the run.go runner. We'll need to rewrite those to not use run.go either by 1) just doing the tests directly because they're really not complicated or 2) exporting the functionality of run.go so tests can use it directly. For other tests, having some of run.go's functionality would actually be really nice, but I don't think it's necessary for these tests.
dmitshur commentedon Jan 20, 2023
I've started working on this more actively recently and made enough progress to post an update. I think I have a good idea for the general implementation plan here: as expected, it'll be to migrate to using
go test
for running these test cases, though leave test cases in GOROOT/test as they are. Details follow.The test/run.go runner handles tests, one for each .go file in the directories listed here (relative to GOROOT/test):
go/test/run.go
Line 103 in 27b6ace
For example, using a recent tip commit, there's a total of 2424 test cases:
(That number is before any skips are applied due to build constraints or other factors, so it doesn't depend on the GOOS/GOARCH you're trying it on.)
For each of those test cases, I plan to make a subtest in a new internal Go package. For prototyping I've used
internal/issue56844
as a temporary placeholder, and so far my best idea for the real thing is probablyinternal/testdir
. We'll see. (Edit: Addedcmd/
prefix in #60059.) Assuming that's used, the diff to test/README.md would be something like:I've done some basic timing, and by using the aforementioned subtest arrangement with
testing.T.Parallel
, all 2424 test cases run in approximately 60-80 seconds on my machine, both before and after. So no regression in test timing. (And, repeated test runs benefit from go test's test caching!)It's likely important to keep -shard and -shards flags operational for purposes of sharded test execution, but that turns up to be trivial. There are more flags in run.go, and I plan to keep most of them as they are. A few will go away because they're obsolete (e.g., -n is obsolete given go test's own parallelism controls; -showSkips will likely get replaced by t.Skip, etc.).
I haven't yet decided how I'll deal with misc/cgo/stdio and misc/cgo/life, but I'm aiming to just simplify them.
Given that GOROOT/test/run.go is fairly large (2139 lines), I'm looking to do this in a way that makes it easier to review and be confident we're not dropping some tests on the floor. At least one of the CLs will be large to do migration atomically, but fortunately I should be able to make the diff between GOROOT/test/run.go and GOROOT/src/internal/testdir/main_test.go quite small and readable in it. The rest can be split off into smaller preparatory and clean up changes.
gopherbot commentedon Jan 24, 2023
Change https://go.dev/cl/463276 mentions this issue:
cmd/dist, test: convert test/run.go runner to a cmd/go test
dmitshur commentedon Feb 6, 2023
A few more things for me not to forget to update:
../bin/go run run.go
needs to be update to the new one (CL 463276)gopherbot commentedon Feb 7, 2023
Change https://go.dev/cl/466155 mentions this issue:
internal/testdir: simplify and clean up
gopherbot commentedon Feb 7, 2023
Change https://go.dev/cl/465755 mentions this issue:
misc/cgo/{life,stdio}: remove reliance on test/run.go
3 remaining items
internal/testdir: simplify and clean up
gopherbot commentedon Feb 28, 2023
Change https://go.dev/cl/471895 mentions this issue:
_content/doc: update GOROOT/test invocation in contribution guide
_content/doc: update GOROOT/test invocation in contribution guide
gopherbot commentedon May 9, 2023
Change https://go.dev/cl/493876 mentions this issue:
internal/testdir: move to cmd/internal/testdir
gopherbot commentedon May 9, 2023
Change https://go.dev/cl/493915 mentions this issue:
_content/doc: update testdir import path in contribution guide
gopherbot commentedon May 12, 2023
Change https://go.dev/cl/494656 mentions this issue:
cmd/dist: use registerStdTestSpecially for normal Go tests only
_content/doc: update testdir import path in contribution guide
internal/testdir: move to cmd/internal/testdir
cmd/dist: use registerStdTestSpecially for normal Go tests only
gopherbot commentedon May 26, 2023
Change https://go.dev/cl/498271 mentions this issue:
cmd/internal/testdir: stop manually adding GOROOT/bin to PATH
cmd/internal/testdir: stop manually adding GOROOT/bin to PATH