Documentation
¶
Index ¶
- func MeasureBaseline(ctx context.Context, projectDir string, packages []string, tags string, ...) (time.Duration, error)
- func RunCoverage(ctx context.Context, projectDir string, packages []string, ...) (string, error)
- func ShortFlagFromEnv() bool
- type ExecOpts
- type Pool
- type ResultCallback
- type TimeoutPolicy
- type Worker
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MeasureBaseline ¶
func MeasureBaseline(ctx context.Context, projectDir string, packages []string, tags string, testFlags []string) (time.Duration, error)
MeasureBaseline runs the test suite once to determine baseline duration. testFlags are the user's --test-flags, forwarded here too so the baseline measures the same work the per-mutant runs will do — otherwise a `-short`-ed mutation run would be sized against a full-cost baseline.
They land *after* the package arguments. `go test` keeps parsing its own flags past one it does not recognize, but that first unrecognized flag marks the package list as already seen, so any package name after it is no longer read as a package — it is forwarded to the test binary as a positional argument and `go test` falls back to `.`. A test-binary flag (`-rapid.checks=N`) ahead of the packages therefore measures the working directory instead of them. See Worker.buildArgs for the same ordering on the mutant builds.
func RunCoverage ¶
func RunCoverage(ctx context.Context, projectDir string, packages []string, coverPkg, tags string, tmpDir string, testFlags []string) (string, error)
RunCoverage runs go test with coverage and returns the profile path. testFlags are the user's --test-flags. Forwarding them here keeps the profile consistent with what the per-mutant runs execute: a test that `-short` skips must not be recorded as covering, or every mutant on its lines would be reported as a survivor instead of NOT_COVERED.
As in MeasureBaseline, the flags land after the package arguments so that an unrecognized one cannot demote them to positional arguments for the test binary — which here would profile the working directory and report every mutant NOT_COVERED.
func ShortFlagFromEnv ¶
func ShortFlagFromEnv() bool
ShortFlagFromEnv reports whether the inner `go test` should be invoked with -short. Extracted from Worker.Test so the env-string equality check is reachable without spinning up a subprocess.
Types ¶
type ExecOpts ¶
ExecOpts bundles the inner `go test` knobs forwarded to each worker: TestCPU (0 omits -cpu, letting go test default to GOMAXPROCS), Tags (empty omits -tags), TestFlags (user-supplied flags appended verbatim; nil appends nothing), GOROOT (the toolchain's, put first on PATH for every test binary as `go test` does; empty leaves PATH alone), and MemoryCap (the memory cap of each build and test run in bytes, see Worker.memCap; 0 keeps config.DefaultMemoryCap, config.NoMemoryCap turns it off). Grouped into one struct so NewPool stays within a sane parameter count.
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
Pool coordinates parallel mutation testing.
type ResultCallback ¶
ResultCallback is called for each completed mutant.
type TimeoutPolicy ¶
type TimeoutPolicy struct {
// Global is the absolute upper bound (baseline*coefficient). Also
// the value used when Adaptive is false.
Global time.Duration
// Margin scales the observed per-test/per-package sum. 1.0 means
// "trust the measurement exactly"; values >1 add headroom for GC,
// scheduler jitter, mutated-code slowdowns, and contention under
// the parallel mutation phase (which runs at higher concurrency
// than the coverage build that produced the measurements).
Margin float64
// Min is the floor — the smallest value For() will return when
// adaptive computation produces something tiny. Absorbs cold-start,
// child fork, and GC-pause overhead that doesn't scale with the
// underlying test work. Without it a 5ms test gets a 15ms deadline
// (with Margin=3) and flakes on a busy machine.
Min time.Duration
// Adaptive is the master switch. When false, For() always returns
// Global; the per-mutant tm/m arguments are ignored.
Adaptive bool
}
TimeoutPolicy decides the per-mutant `go test` deadline. Without adaptive sizing every mutant inherits the same baseline×coefficient timeout, which on multi-package projects pins workers on infinite-loop mutants for whole-suite-sized intervals.
- Adaptive=false → every mutant gets Global. Behavior matches pre- adaptive gomutants exactly; used as the kill switch.
- Adaptive=true → per-mutant timeout = clamp(baseSum*Margin, Min, Global) where baseSum is the sum of the mutant's covering tests' durations from the coverage map. A mutant without it gets Global.
The deadline bounds running the mutant's tests, not building their test binaries, which happens first, outside it (see Worker.runGroups).
All clamps point in the safe direction: a missing measurement falls back to a longer timeout, never a shorter one. Worst-case the user sees pre-adaptive wait times; they never see false TIMED_OUT inflation.
func (TimeoutPolicy) For ¶
For returns the deadline for the run of m's covering tests (see Worker.Test), consulting `tm` for per-test timings.
When adaptive, it is the sum of the selected per-test durations — the actual tests this mutant will run via -test.run=^(TestA|TestB)$, in whichever packages they are — scaled by Margin. It covers no build: the tests' binaries are built with the mutant in place before the deadline starts.
A mutant without covering tests runs its whole package, which gets Global: the map's timings don't describe that run, as a test that failed or hung when run alone has none, and a mutant on a line no test covers rarely hangs.
The output is clamped: max(scaled, Min), then min(that, Global). Both clamps fail safe — too-tight measurements widen to Min, and a pathological multiplication can never escape Global.
type Worker ¶
type Worker struct {
// contains filtered or unexported fields
}
Worker tests a single mutant: it builds the test binary of each package whose tests it runs, with the mutant in place through an overlay, then runs the binary.