framework

package
v0.0.0-...-0b2c680 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultSeed int64 = 1

DefaultSeed is the --seed value injected into every `crossfuzz run` invocation made through this framework, unless the caller passes their own --seed. Defaults to 1 so cross-run comparisons in tests are reproducible; the e2e binary's --seed flag overrides it.

Functions

func AnyFailed

func AnyFailed(rs []Result) bool

AnyFailed reports whether any result is Failed or Panicked.

func CorpusFiles

func CorpusFiles(t *T, ws *Workspace, sub string) []string

CorpusFiles returns the list of corpus entry filenames under <ws.Dir>/<sub>. Returns an empty slice if the directory does not exist.

func ParseOutput

func ParseOutput(stdout string) (FinalStats, []TickStats)

ParseOutput extracts every stats tick and the final summary line from captured stdout. Both may be absent (returns zero values).

func Register

func Register(t Test)

Register adds a test to the global registry. Called from package init().

func RequireBinary

func RequireBinary(t *T, name string)

RequireBinary skips the test if `name` is not found on PATH.

func RequireBun

func RequireBun(t *T)

func RequireCargo

func RequireCargo(t *T)

func RequireClang19

func RequireClang19(t *T)

func RequireCrossfuzzBinary

func RequireCrossfuzzBinary(t *T)

RequireCrossfuzzBinary skips if bin/crossfuzz does not exist.

func RequireGo

func RequireGo(t *T)

func RequireGradle

func RequireGradle(t *T)

func RequireJSHarness

func RequireJSHarness(t *T)

RequireJSHarness skips if the JS harness's node_modules is missing.

func RequireJava

func RequireJava(t *T)

func RequireJavaHarness

func RequireJavaHarness(t *T)

RequireJavaHarness skips if harness/java/build/libs/crossfuzz.jar is missing.

func RequirePythonVenv

func RequirePythonVenv(t *T)

RequirePythonVenv skips if harness/python/.venv/bin/python3 is missing.

func RequireRustHarness

func RequireRustHarness(t *T)

RequireRustHarness skips if the rust harness rlib is missing.

Types

type FinalStats

type FinalStats struct {
	Found    bool // true if the "Campaign finished" line was present
	Execs    int
	Rejected int
	Corpus   int
	Findings int
	Crashes  int
	Timeouts int
}

FinalStats is parsed from the "Campaign finished. ..." line printed at shutdown. It is the authoritative end-of-run summary.

type Finding

type Finding struct {
	Hash     string
	Kind     string
	Dir      string
	Metadata map[string]any
	Files    []string
}

Finding is one entry under findings/. Hash is the directory name; Kind is "divergence" (no prefix), "crash", or "timeout".

func Findings

func Findings(t *T, ws *Workspace, sub string) []Finding

Findings returns all subdirectories of <ws.Dir>/<sub>, parsed.

type Outcome

type Outcome int

Outcome classifies the result of one test run.

const (
	Passed Outcome = iota
	Failed
	Skipped
	Panicked // panic that wasn't a fatalSignal / skipSignal
	Flaky    // failed initially but passed on a retry (--flaky N)
)

func (Outcome) String

func (o Outcome) String() string

type Result

type Result struct {
	Test     Test
	Outcome  Outcome
	Reason   string   // skip reason or fail message
	Logs     []string // collected via t.Logf
	Duration time.Duration
}

Result captures everything observable about one test execution.

type RunResult

type RunResult struct {
	ExitCode int
	Stdout   string
	Stderr   string
	Stats    FinalStats
	Ticks    []TickStats
}

RunResult is the captured outcome of one bin/crossfuzz invocation.

func Analyze

func Analyze(t *T, ws *Workspace, args ...string) RunResult

Analyze invokes `bin/crossfuzz analyze ...`.

func Build

func Build(t *T, ws *Workspace, args ...string) RunResult

Build invokes `bin/crossfuzz build <ws.ConfigPath>`.

func Reduce

func Reduce(t *T, ws *Workspace, args ...string) RunResult

Reduce invokes `bin/crossfuzz reduce ...`.

func Run

func Run(t *T, ws *Workspace, args ...string) RunResult

Run invokes `bin/crossfuzz run <ws.ConfigPath> <args...>` in the workspace directory. Exec-level failures (binary missing) fail the test; non-zero exit codes are returned in ExitCode for the caller to assert on.

func RunWithTimeout

func RunWithTimeout(t *T, ws *Workspace, wall time.Duration, args ...string) RunResult

RunWithTimeout is like Run but kills the process if it exceeds wall.

type Runner

type Runner struct {
	Tests       []Test
	Parallel    int  // max concurrent tests; 1 = strictly serial
	Verbose     bool // stream per-test logs as they finish
	FailFast    bool // stop dispatching after the first failure
	StopOnPanic bool // treat panic as fatal to the whole run
	// Flaky, if > 0, rerun each failed/panicked test up to this many extra
	// times after the first pass. A test that passes any retry is reported
	// as Flaky (not Failed) so the user knows to investigate it as
	// instability rather than a real regression.
	Flaky   int
	Out     io.Writer // progress + summary output
	NowFunc func() time.Time
}

Runner orchestrates execution of a slice of tests.

func (*Runner) Run

func (r *Runner) Run() []Result

Run executes every test in r.Tests, returning the results in the order they completed. Live progress (one line per test) is written to r.Out as each test finishes; a summary follows.

type T

type T struct {
	// contains filtered or unexported fields
}

T is the per-test context handed to every test function. It mimics enough of *testing.T's surface (Errorf, Fatalf, Skipf, Logf, Cleanup, TempDir, Helper, Parallel) that the existing helpers ported from go test compile with minimal changes, but it is otherwise independent of the testing package — see orchestrator.go for the runner.

func (*T) Cleanup

func (t *T) Cleanup(f func())

Cleanup registers a function to run after the test, in LIFO order.

func (*T) Error

func (t *T) Error(args ...any)

Errorln/Error are kept minimal — most callers use Errorf/Fatalf.

func (*T) Errorf

func (t *T) Errorf(format string, args ...any)

Errorf records a failure but lets the test continue.

func (*T) Fatal

func (t *T) Fatal(args ...any)

func (*T) Fatalf

func (t *T) Fatalf(format string, args ...any)

Fatalf records a failure and aborts the current test via panic.

func (*T) Helper

func (t *T) Helper()

Helper is a no-op kept for API compatibility — we don't track caller depth.

func (*T) Log

func (t *T) Log(args ...any)

func (*T) Logf

func (t *T) Logf(format string, args ...any)

Logf records a log line; the orchestrator prints them in verbose mode and always after a failure.

func (*T) Name

func (t *T) Name() string

Name returns the test name (e.g. "cli.MaxFindings").

func (*T) Parallel

func (t *T) Parallel()

Parallel is a no-op. The orchestrator manages parallelism; tests do not opt in individually.

func (*T) Skip

func (t *T) Skip(args ...any)

func (*T) Skipf

func (t *T) Skipf(format string, args ...any)

Skipf marks the test as skipped and aborts it.

func (*T) TempDir

func (t *T) TempDir() string

TempDir returns a fresh directory under a per-test root. The root is removed (along with every subdirectory created via TempDir) when the test finishes.

type Test

type Test struct {
	// Name is the dotted identifier shown in output (e.g. "cli.MaxMemory").
	Name string
	// Tags are short labels used by the -tag filter (e.g. "harness", "parallel",
	// "comparer", "go").
	Tags []string
	// Func is the test body.
	Func func(t *T)
}

Test is one registered e2e case.

func Tests

func Tests() []Test

Tests returns all registered tests, sorted by Name. Returns a copy so the caller may mutate the slice without affecting the registry.

func (Test) HasTag

func (t Test) HasTag(tag string) bool

HasTag reports whether t carries the given tag.

type TickStats

type TickStats struct {
	Execs       int
	ExecsPerSec float64
	Rejected    int
	Duplicates  int
	Corpus      int
	Coverage    int // total coverage edges across all targets
	Findings    int
	Crashes     int
	Timeouts    int
	TargetEdges map[string]int // populated only when --debug-edge is set
}

TickStats is one line of the live stats ticker (printed every ~3s).

type Workspace

type Workspace struct {
	Dir        string
	ConfigPath string
	RepoRoot   string
	FixtureDir string
}

Workspace is an isolated tmpdir for one e2e test. It holds a copy of a fixture and a rendered crossfuzz.toml. Removed automatically on test cleanup (via T.TempDir's cleanup).

func NewWorkspace

func NewWorkspace(t *T, fixture string) *Workspace

NewWorkspace creates a tmpdir, copies the named fixture into it, and renders every *.tmpl file with default vars. Fixtures are resolved first from e2e/fixtures/<name>, then from e2e/<name>.

func (*Workspace) RenderConfig

func (w *Workspace) RenderConfig(t *T, vars map[string]any)

RenderConfig walks the workspace, rendering every *.tmpl file with the given vars and writing the result to the same path with the .tmpl suffix removed. {{.RepoRoot}} is always available. Re-callable from tests to vary inputs.

Jump to

Keyboard shortcuts

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