aboutsummaryrefslogtreecommitdiff
path: root/src/internal/testenv/exec.go
AgeCommit message (Collapse)Author
2026-02-03internal/testenv: exclude GOMAXPROCS when building test programmakepkgShulhan
In the environment where GOMAXPROCS set explicitly, for example to 3 in shell profile, the runtime tests will fail with the following error, ---- ok regexp/syntax 0.428s --- FAIL: TestCgroupGOMAXPROCS (0.81s) crash_test.go:186: running /home/ms/src/go/bin/go build -o /tmp/go-build1753772192/testprog.exe crash_test.go:208: built testprog in 796.664277ms --- FAIL: TestCgroupGOMAXPROCS/containermaxprocs=0 (0.00s) cgroup_linux_test.go:60: /tmp/go-build1753772192/testprog.exe PrintGOMAXPROCS (907.06µs): ok cgroup_linux_test.go:63: output got "3\n" want "4\n" --- FAIL: TestCgroupGOMAXPROCSNoLimit (0.00s) cgroup_linux_test.go:82: /tmp/go-build1753772192/testprog.exe PrintGOMAXPROCS (879.194µs): ok cgroup_linux_test.go:85: output got "3\n" want "4\n" --- FAIL: TestCgroupGOMAXPROCSHigherThanNumCPU (0.00s) cgroup_linux_test.go:102: /tmp/go-build1753772192/testprog.exe PrintGOMAXPROCS (852.396µs): ok cgroup_linux_test.go:105: output got "3\n" want "4\n" --- FAIL: TestCgroupGOMAXPROCSRound (0.01s) --- FAIL: TestCgroupGOMAXPROCSRound/50000 (0.00s) cgroup_linux_test.go:156: /tmp/go-build1753772192/testprog.exe PrintGOMAXPROCS (852.099µs): ok cgroup_linux_test.go:159: output got "3\n" want "2\n" --- FAIL: TestCgroupGOMAXPROCSRound/100000 (0.00s) cgroup_linux_test.go:156: /tmp/go-build1753772192/testprog.exe PrintGOMAXPROCS (894.001µs): ok cgroup_linux_test.go:159: output got "3\n" want "2\n" --- FAIL: TestCgroupGOMAXPROCSRound/150000 (0.00s) cgroup_linux_test.go:156: /tmp/go-build1753772192/testprog.exe PrintGOMAXPROCS (850.897µs): ok cgroup_linux_test.go:159: output got "3\n" want "2\n" --- FAIL: TestCgroupGOMAXPROCSSchedAffinity (0.00s) cgroup_linux_test.go:229: /tmp/go-build1753772192/testprog.exe PrintGOMAXPROCS (867.987µs): ok cgroup_linux_test.go:232: output got "3\n" want "2\n" FAIL FAIL runtime 23.088s ---- This changes exclude the GOMAXPROCS when building program for testing so it does not affect the tests.
2024-09-03math,os,os/*: use testenv.ExecutableKir Kolyshkin
As some callers don't have a testing context, modify testenv.Executable to accept nil (similar to how testenv.GOROOT works). Change-Id: I39112a7869933785a26b5cb6520055b3cc42b847 Reviewed-on: https://go-review.googlesource.com/c/go/+/609835 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: Dmitri Shuralyov <dmitshur@google.com>
2024-09-03internal/testenv: add missing t.Helper callsKir Kolyshkin
...and move a few so they won't be called when not needed. Change-Id: I024b9552ed5ed839cde4fbae4815ec6ba8b67265 Reviewed-on: https://go-review.googlesource.com/c/go/+/609300 Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-09-03internal/testenv: add ExecutableKir Kolyshkin
Tests commonly use code to get os.Executable value, and some cache the resulting value. To reduce code duplication, add a helper that does just that. Change-Id: I9dd7eb24e24a3abd92be2b87227e823f0fca5cb3 Reviewed-on: https://go-review.googlesource.com/c/go/+/609301 Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: 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> Auto-Submit: Ian Lance Taylor <iant@google.com>
2024-08-30internal/testenv: MustHaveExec: use sync.OnceValueKir Kolyshkin
Change-Id: I048474fc93bb8c149672b66f98d71eec0eb8aad7 Reviewed-on: https://go-review.googlesource.com/c/go/+/609795 Reviewed-by: 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> Auto-Submit: Ian Lance Taylor <iant@google.com>
2023-10-27internal/testenv: use cmd.Environ in CleanCmdEnvCherry Mui
In CleanCmdEnv, use cmd.Environ instead of os.Environ, so it sets the PWD environment variable if cmd.Dir is set. This ensures the child process sees a canonical path for its working directory. Change-Id: Ia769552a488dc909eaf6bb7d21937adba06d1072 Reviewed-on: https://go-review.googlesource.com/c/go/+/538215 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Bryan Mills <bcmills@google.com>
2023-07-12all: fix typos and remove repeated wordsDan Kortschak
Change-Id: I5f06a4ef1d827eb0fe32a8d98444142108b0d573 Reviewed-on: https://go-review.googlesource.com/c/go/+/508996 Run-TryBot: Ian Lance Taylor <iant@google.com> Auto-Submit: Keith Randall <khr@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Keith Randall <khr@google.com>
2023-05-05internal/testenv: reduce init-time work for MustHaveExecBryan C. Mills
In CL 486275 I added a somewhat complex init function that sets up a callback to probe for exec support. A lot of the complexity was simply to avoid an unnecessary call to os.Environ during init. In CL 491660, I made the os.Environ call unconditional on all platforms anyway in order to make HasGoBuild more robust. Since the init-function indirection no longer serves a useful purpose, I would like to simplify it to a package-level function, avoiding the complexity of changing package variables at init time. Change-Id: Ie0041d52cbde06ff14540192c8fba869a851158e Reviewed-on: https://go-review.googlesource.com/c/go/+/492977 Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2023-05-04internal/testenv: remove HasExec and simplify other support checks againBryan C. Mills
HasExec is an attractive nuisance: it is tempting to check in a TestMain function, but TestMain really shouldn't be running subprocesses eagerly anyway (they add needless overhead for operations like 'go test -list=.'), and the trick of re-executing the test binary to determine whether 'exec' works ends up in infinite recursion if TestMain itself calls HasExec. Instead, tests that need to execute a subprocess should call MustHaveExec or MustHaveExecPath from within a specific test, or just try to exec the program and check its error status (perhaps using testenv.SyscallIsNotSupported). While I'm in here and testing on the SlowBots anyway, a few other cleanups relating to subprocesses: - Add more t.Helper calls to support checks where appropriate. - Remove findGoTool, which can be simplified to exec.LookPath as of CL 404134. - Add tests confirming the expected behavior of the support functions on the Go project's builders. Change-Id: I163c701b2dd6eb6b7a036c6848f99b64dd9f0838 Reviewed-on: https://go-review.googlesource.com/c/go/+/491660 Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Bryan Mills <bcmills@google.com> Auto-Submit: Bryan Mills <bcmills@google.com>
2023-04-24internal/testenv: actually try to exec on ios and wasmBryan C. Mills
Due to a stray edit in CL 486275, the assignment to tryExecOk in tryExec on ios would be immediately overwritten back to false. This change fixes the stray edit. Change-Id: I4f45fbf130dc912305e5f453b0d1a622ba199ad4 Reviewed-on: https://go-review.googlesource.com/c/go/+/488076 Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com>
2023-04-22internal/testenv: in HasExec, try to actually exec on ios and wasm platformsBryan C. Mills
Some iOS environments may support exec. wasip1 and js do not, but trying to exec on those platforms is inexpensive anyway and gives better test coverage for the ios path. Change-Id: I4baffb2ef5dc7d81e6a260f69033bfb229f13d92 Reviewed-on: https://go-review.googlesource.com/c/go/+/486275 TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Bryan Mills <bcmills@google.com>
2023-04-07internal: add wasip1 supportJohan Brandhorst-Satzkorn
For #58141 Co-authored-by: Richard Musiol <neelance@gmail.com> Co-authored-by: Achille Roussel <achille.roussel@gmail.com> Co-authored-by: Julien Fabre <ju.pryz@gmail.com> Co-authored-by: Evan Phoenix <evan@phx.io> Change-Id: I1488726e5b43cd21c5f83900476afd2fb63d70c9 Reviewed-on: https://go-review.googlesource.com/c/go/+/479622 Auto-Submit: Ian Lance Taylor <iant@google.com> Run-TryBot: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Ian Lance Taylor <iant@google.com>
2022-11-01internal/testenv: adjust timeout calculations in CommandContextBryan C. Mills
I noticed some test failures in the build dashboard after CL 445597 that made me realize the grace period should be based on the test timeout, not the Context timeout: if the test itself sets a short timeout for a command, we still want to give the test process enough time to consume and log its output. I also put some more thought into how one might debug a test hang, and realized that in that case we don't want to set a WaitDelay at all: instead, we want to leave the processes in their stuck state so that they can be investigated with tools like `ps` and 'lsof'. Updates #50436. Change-Id: I65421084f44eeaaaec5dd2741cd836e9e68dd380 Reviewed-on: https://go-review.googlesource.com/c/go/+/446875 Auto-Submit: Bryan Mills <bcmills@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-11-01internal/testenv: move helpers related to os/exec to a separate fileBryan C. Mills
(Suggested by Austin in CL 445596.) Change-Id: Ic774d551e8085d15435ef2b3c78d0169a365ce41 Reviewed-on: https://go-review.googlesource.com/c/go/+/446642 Auto-Submit: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>