Documentation
¶
Overview ¶
Package guesttest holds what the tests of the guest packages share: a hand-assembled probe module that exercises the memory allocator without a guest, the lock-limit machinery those tests need, and the skip rules for hosts that cannot run them. Internal, and imported only by _test files, so nothing here is API.
Index ¶
- Constants
- Variables
- func AssertMappingProtected(t *testing.T, alloc *guest.Allocator, addr uintptr)
- func HostReserves(t *testing.T) bool
- func InChild(t *testing.T) bool
- func LockOrSkip(t *testing.T, alloc *guest.Allocator)
- func MemoryBase(t *testing.T, mem api.Memory) uintptr
- func ProbeMemory(t *testing.T, alloc *guest.Allocator) (base func() uintptr, grow func(pages uint32) (old uint32, ok bool), ...)
- func SetMemlockLimit(n uint64) error
- func SkipUnlessLockRequired(t *testing.T, what string, detail any)
Constants ¶
const RequireLock = "STACK_ENCRYPT_TESTS_REQUIRE_LOCK"
RequireLock is set in CI, where RLIMIT_MEMLOCK has been raised, so the lock cannot quietly go untested. Without it a refused lock is reported and the assertion skipped: a developer laptop's default limit is not a bug in these packages.
const WasmPage = 64 * 1024
WasmPage is the size of one wasm memory page.
Variables ¶
var GrowProbe = []byte{
0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00,
0x01, 0x06, 0x01, 0x60, 0x01, 0x7f, 0x01, 0x7f,
0x03, 0x02, 0x01, 0x00,
0x05, 0x03, 0x01, 0x00, 0x01,
0x07, 0x11, 0x02,
0x06, 'm', 'e', 'm', 'o', 'r', 'y', 0x02, 0x00,
0x04, 'g', 'r', 'o', 'w', 0x00, 0x00,
0x0a, 0x08, 0x01, 0x06, 0x00, 0x20, 0x00, 0x40, 0x00, 0x0b,
}
GrowProbe is a hand-assembled module with one page of memory and one export that grows it, so the allocator can be exercised without a guest:
(module
(memory (export "memory") 1)
(func (export "grow") (param i32) (result i32)
local.get 0 memory.grow))
Like the guests, it declares no maximum, so wazero asks the allocator for wasm's 4 GiB default.
Functions ¶
func AssertMappingProtected ¶
AssertMappingProtected checks the smaps entry containing addr: dd (MADV_DONTDUMP) whenever there is a reservation at all, and, where the lock was granted, lo (mlock) with the whole resident range locked. A refused lock skips the second half after the first has run; a failed first half fails the test whatever the second does.
func HostReserves ¶
HostReserves reports whether this host can back a guest with a reservation at all. Where it cannot (a 32-bit host asked for wasm's 4 GiB default, which CI exercises on purpose under GOARCH=386) the heap fallback is in use, no lock is possible, and the tests of a lock granted or refused have nothing to test: they skip, whatever RequireLock says.
func InChild ¶
InChild re-runs the calling test in a child process, for tests that lower RLIMIT_MEMLOCK: the change is process-wide and irreversible for a non-root process. It returns true in the child, which prints "case ok" when done or "case skipped: <why>" when the host cannot provoke the condition; the parent judges that output and returns false.
func LockOrSkip ¶
LockOrSkip continues if alloc's memory is locked, skips if the host refused the lock (or has no reservation to lock), and fails the skip when RequireLock says the host was meant to grant it.
func MemoryBase ¶
MemoryBase is the host address of a module memory's first byte. Read returns a view into the buffer, not a copy.
func ProbeMemory ¶
func ProbeMemory(t *testing.T, alloc *guest.Allocator) (base func() uintptr, grow func(pages uint32) (old uint32, ok bool), done func())
ProbeMemory instantiates GrowProbe under alloc and returns the base address of its memory and a grow function reporting the old page count.
func SetMemlockLimit ¶
SetMemlockLimit lowers RLIMIT_MEMLOCK to n bytes for this process. Only a child test process calls it.
Types ¶
This section is empty.