Documentation
¶
Overview ¶
Package fakeexe is test support for tests that need an executable named like a tool (ffmpeg, ffprobe) which is the running test binary itself, re-executed as the stand-in (the helper-process trick: the package's init or TestMain sees the tool's name in os.Args[0] and answers as the tool).
It exists because four packages each carried the same helper, and it hard-linked the test binary to the tool's name. On Windows that cannot be cleaned up: a link names the same file as the running test binary, and Windows refuses to unlink any name of a file a live process has mapped as its image, so testing's TempDir cleanup failed with "unlinkat ...\ffmpeg.exe: Access is denied" on a host where the refusal applies (measured there: a link that nothing had ever run was still locked after 20 s, a byte copy was removed at once; on another Windows host both removed fine). A retry cannot help, because the lock lasts as long as the test process does. So on Windows the stand-in is always a copy, and elsewhere a hard link (free, and unlinking one is fine), falling back to a copy.
Where the stand-ins live. Dir is the calling test's own t.TempDir, so a test run that is killed before its cleanups run leaves them inside the run's temp root (which a harness deletes), never as a folder of their own in the shared temp directory. Dir also registers its own removal, with a bounded retry on Windows (a just-run executable can stay held for a moment by a scanner). Cleanups run last-in first-out and Dir registers its after t.TempDir's, so the retry runs before testing's own TempDir removal, which then finds nothing to refuse.
A copy has a price the link did not: the first start of a newly written executable is slow where a scanner inspects it (measured on a development host: 1.7 to 2 s for the first start, 30 ms for the second), and a test that gives the whole call a short deadline would pay it inside its budget. So Install on Windows starts the stand-in once before it returns. That start is a leaf by construction: it carries warmEnv, and this package's init exits the process the moment it sees it, before any package's own init or any test can run. It therefore asks nothing of a package's stand-in dispatcher.
The recursion guard. A stand-in is the test binary, so a stand-in started under a name the package's dispatcher does not recognise runs the whole test suite instead of answering as the tool, and every test that installs a stand-in would start another one: a fork bomb, one directory and one process per level (a runaway of this kind has happened: thousands of copies in minutes). Install records every directory it puts a stand-in in, in dirsEnv, which child processes inherit. A process that finds itself running from one of those directories is a stand-in; if it reaches Dir or Install it is running tests, and it exits with nestedExit at once, so the depth of any such chain is two.
It is a separate package so a production package never imports "testing" (the shape internal/gpuprobe/smitest has).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Dir ¶
Dir returns a new empty directory for stand-in executables. It is inside the calling test's own temp directory (t.TempDir) and is removed, with a bounded retry on Windows, when the test ends.
Types ¶
This section is empty.