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
- func AllocBound(inputLen int, mult, floor uint64) uint64
- func CheckAlloc(tb testing.TB, name string, inputLen int, mult, floor uint64, fn func())
- func MeasureAlloc(fn func()) uint64
- func RoundTripYAML[T any](t *testing.T, name string, data []byte, mult, floor uint64, ...) (T, bool)
- func SeedGlob(f *testing.F, patterns ...string)
Constants ¶
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 ¶
AllocBound computes uint64(max(inputLen, 0))*mult + floor, saturating at math.MaxUint64 instead of overflowing.
func CheckAlloc ¶
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.
Types ¶
This section is empty.