Documentation
¶
Overview ¶
Package testbin places a built program into a test's directory.
On macOS every fresh copy of an executable is a never-seen binary that the system policy scanner assesses on its first exec. One is quick; a package run that copies the same built helper into dozens of fixtures queues them behind the scanner for longer than a test waits. A hard link shares the inode the scanner has already assessed, so the rule is to link first and copy only where a link is impossible: a temp directory on another filesystem, and Windows.
Index ¶
Constants ¶
const ( // MaxDepth is how many test binaries of one tool may stand in a chain; the // MaxDepth-th start is refused, so a chain is at most MaxDepth-1 deep. MaxDepth = 2 // ExitRefuse is the exit code of a refused start. ExitRefuse = 3 )
Variables ¶
This section is empty.
Functions ¶
func DepthEnv ¶
DepthEnv is the environment variable that counts the test binaries of tool standing above a start: NOVA_TEST_DEPTH_<TOOL>, upper case, '-' as '_'.
func Place ¶
Place puts the program at src at dst. It removes dst first, then hard-links src to dst where the platform and filesystem allow it and returns nil; the fallback is a byte copy with the executable bit set (mode 0o755). Windows always takes the copy, because a link there needs a privilege the CI path does not have.
func PlaceCopy ¶
PlaceCopy puts a real byte copy of src at dst, never a link, and is the one entry point a test should use when the SUBJECT of the test is that the file is not the same binary. A hard link shares src's inode, so a guard that asks "is my parent this executable?" answers yes through a link and the test silently stops testing anything. cmd/nova-sandbox's probe-step guard is that test. Everywhere else, Place: a copy there only costs macOS's policy scanner time (see the package comment).
func WriteExecutable ¶
WriteExecutable is os.WriteFile for a file a test is about to exec: a fake tool, a stand-in script, a stub on PATH. It holds syscall.ForkLock for reading while the file is open for writing, so no other goroutine can fork in that window. Without it, a parallel test's fork inherits the write descriptor for the instant before its exec, and this test's exec of the file fails with ETXTBSY, "text file busy": the inherited write descriptor keeps the file busy.
Types ¶
type Handler ¶
Handler reports whether a start is one the package answers itself, given the words after the program name and the environment.
type Start ¶
type Start int
Start is what one start of a test binary is.
func Decide ¶
func Decide(tool string, args []string, getenv func(string) string, handled Handler) (start Start, depth int, why string)
Decide is what a start of tool's test binary is, given its words and its environment: Suite, Handled, or Refused with the reason. depth is how many test binaries of tool stand above it. handled may be nil.
func Enter ¶
Enter decides this start of tool's test binary from os.Args and os.Environ, before any test runs. A refusal prints one line and exits ExitRefuse; any other start counts itself in DepthEnv, so its children see one more test binary above them, and Enter returns Suite or Handled. A Handled start is the caller's to answer: the package's dispatch runs and exits.