testutil

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package testutil provides reusable property-based test assertions, invariant validators, and randomized mutation generators for microfat test suites.

Index

Constants

View Source
const (
	PrivatePermissionMode os.FileMode = 0o700
	PermMaskOtherGroup    os.FileMode = 0o077
	DefaultPropertyIters              = 100
	DefaultMutationCount              = 3
	DefaultSafetyCeiling  int64       = 1024 * 1024 * 1024 // 1 GiB

)

Invariant testing constants.

Variables

This section is empty.

Functions

func AssertCacheIsolation

func AssertCacheIsolation(t testing.TB, cachePath string)

AssertCacheIsolation verifies that the specified cache path strictly maintains private 0700 permissions and is not accessible to other users or groups.

func AssertDecompressionBounds

func AssertDecompressionBounds(t testing.TB, c codec.Codec, r io.Reader, limit int64)

AssertDecompressionBounds verifies that decompressing stream r via codec c strictly respects the byte limit ceiling and does not exceed limit bytes written, even when processing corrupted, malformed, or hostile streams.

func AssertLevelRequirements

func AssertLevelRequirements(t testing.TB, arch string, level string, features []string)

AssertLevelRequirements validates microarchitecture feature prerequisites and verifies monotonicity for the specified CPU architecture and target level.

func AssertNoGoroutineLeaks added in v0.2.4

func AssertNoGoroutineLeaks(t testing.TB)

AssertNoGoroutineLeaks asserts that no goroutines have leaked according to the Go 1.27 goroutineleak profiler.

func AssertPayloadIntegrity

func AssertPayloadIntegrity(t testing.TB, binary []byte, entry format.VariantEntry)

AssertPayloadIntegrity verifies that a variant payload within binary satisfies uncompressed size boundaries and SHA-256 payload integrity.

func CheckGoroutineLeaks added in v0.2.4

func CheckGoroutineLeaks(w io.Writer) error

CheckGoroutineLeaks inspects the Go 1.27 runtime "goroutineleak" profile. If any leaked goroutines are detected, it writes the leak profile to w (if w != nil) and returns an error describing the leak count.

func CheckLeaksIfEnabled added in v0.2.4

func CheckLeaksIfEnabled(m *testing.M) int

CheckLeaksIfEnabled runs the test suite and, if MICROFAT_TEST_LEAKS is enabled, checks for goroutine leaks before process exit.

func MutateBytes

func MutateBytes(rng *rand.Rand, src []byte, count int) []byte

MutateBytes returns a copy of src with randomized bit flips or corrupted bytes.

func RandomPayload

func RandomPayload(rng *rand.Rand, length int) []byte

RandomPayload generates semi-compressible random payload bytes of the given length.

func RunPropertyTest

func RunPropertyTest(t *testing.T, name string, iterations int, seed uint64, fn func(t *testing.T, iter int, rng *rand.Rand))

RunPropertyTest executes a property-based testing function sequentially for the specified iterations with deterministic per-iteration PRNG instances. If seed is 0, a timestamp seed is selected and logged on error.

func RunPropertyTestConcurrent

func RunPropertyTestConcurrent(
	t *testing.T,
	name string,
	iterations int,
	maxWorkers int,
	seed uint64,
	fn func(t *testing.T, iter int, rng *rand.Rand),
)

RunPropertyTestConcurrent executes property iterations using a bounded worker pool. maxWorkers is capped between 1 and runtime.GOMAXPROCS(0) if <= 0.

func TruncateBytes

func TruncateBytes(rng *rand.Rand, src []byte) []byte

TruncateBytes returns a truncated subslice copy of src.

Types

This section is empty.

Directories

Path Synopsis
Package seccomp provides test utilities for Linux BPF seccomp filter installation and TSYNC classification.
Package seccomp provides test utilities for Linux BPF seccomp filter installation and TSYNC classification.

Jump to

Keyboard shortcuts

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