Documentation
¶
Overview ¶
Package testutil provides reusable property-based test assertions, invariant validators, and randomized mutation generators for microfat test suites.
Index ¶
- Constants
- func AssertCacheIsolation(t testing.TB, cachePath string)
- func AssertDecompressionBounds(t testing.TB, c codec.Codec, r io.Reader, limit int64)
- func AssertLevelRequirements(t testing.TB, arch string, level string, features []string)
- func AssertNoGoroutineLeaks(t testing.TB)
- func AssertPayloadIntegrity(t testing.TB, binary []byte, entry format.VariantEntry)
- func CheckGoroutineLeaks(w io.Writer) error
- func CheckLeaksIfEnabled(m *testing.M) int
- func MutateBytes(rng *rand.Rand, src []byte, count int) []byte
- func RandomPayload(rng *rand.Rand, length int) []byte
- func RunPropertyTest(t *testing.T, name string, iterations int, seed uint64, ...)
- func RunPropertyTestConcurrent(t *testing.T, name string, iterations int, maxWorkers int, seed uint64, ...)
- func TruncateBytes(rng *rand.Rand, src []byte) []byte
Constants ¶
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 ¶
AssertCacheIsolation verifies that the specified cache path strictly maintains private 0700 permissions and is not accessible to other users or groups.
func AssertDecompressionBounds ¶
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 ¶
AssertLevelRequirements validates microarchitecture feature prerequisites and verifies monotonicity for the specified CPU architecture and target level.
func AssertNoGoroutineLeaks ¶ added in v0.2.4
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
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
CheckLeaksIfEnabled runs the test suite and, if MICROFAT_TEST_LEAKS is enabled, checks for goroutine leaks before process exit.
func MutateBytes ¶
MutateBytes returns a copy of src with randomized bit flips or corrupted bytes.
func RandomPayload ¶
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.
Types ¶
This section is empty.