testbin

package
v1.2.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 10, 2026 License: MIT Imports: 6 Imported by: 0

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

View Source
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

func DepthEnv(tool string) string

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

func Place(src, dst string) error

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

func PlaceCopy(src, dst string) error

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

func WriteExecutable(path string, data []byte, perm os.FileMode) error

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

type Handler func(args []string, getenv func(string) string) bool

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.

const (
	Suite Start = iota
	Handled
	Refused
)

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

func Enter(tool string, handled Handler) Start

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL