fuzztest

package
v0.4.0-rc.3 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2026 License: Apache-2.0 Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package fuzztest provides shared helpers for loader fuzz targets: seed loading from testdata globs, heap allocation bounds against allocation-bomb inputs, and canonical YAML parse/encode round-trip checks.

Index

Constants

View Source
const (
	// DefaultAllocMult is the default per-input-byte allocation multiplier for
	// structured text loaders (YAML, JSON, Yarn).
	DefaultAllocMult uint64 = 256
	// DefaultAllocFloor is the default fixed heap-allocation allowance on top of
	// the per-byte budget, absorbing small fixed buffers and runtime noise while
	// catching unbounded allocation bombs from small inputs.
	DefaultAllocFloor uint64 = 8 << 20
)

Variables

This section is empty.

Functions

func AllocBound

func AllocBound(inputLen int, mult, floor uint64) uint64

AllocBound computes uint64(max(inputLen, 0))*mult + floor, saturating at math.MaxUint64 instead of overflowing.

func CheckAlloc

func CheckAlloc(tb testing.TB, name string, inputLen int, mult, floor uint64, fn func())

CheckAlloc runs fn and fails tb if the heap bytes allocated during fn exceed AllocBound(inputLen, mult, floor).

func MeasureAlloc

func MeasureAlloc(fn func()) uint64

MeasureAlloc returns the cumulative heap bytes allocated while fn runs.

func RoundTripYAML

func RoundTripYAML[T any](
	t *testing.T,
	name string,
	data []byte,
	mult, floor uint64,
	parse func([]byte) (T, error),
	encode func(T) ([]byte, error),
) (T, bool)

RoundTripYAML parses data under an allocation bound and, when parsing succeeds, verifies that encode -> parse -> encode succeeds and produces byte-identical canonical output.

func SeedGlob

func SeedGlob(f *testing.F, patterns ...string)

SeedGlob adds every file matching each glob pattern relative to the package directory as a []byte seed to f. It fails f if any pattern is invalid, matches no files, or cannot be read.

Types

This section is empty.

Jump to

Keyboard shortcuts

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