analysis

package
v0.0.0-...-38f63e8 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: Apache-2.0, MIT Imports: 5 Imported by: 0

Documentation

Overview

Package analysis implements common functionality used by generated go_marshal tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AlignmentCheck

func AlignmentCheck(t *testing.T, typ reflect.Type) (ok bool, delta uint64)

AlignmentCheck ensures the definition of the type represented by typ doesn't cause the go compiler to emit implicit padding between elements of the type (i.e. fields in a struct).

AlignmentCheck doesn't explicitly recurse for embedded structs because any struct present in an ABI struct must also be Marshallable, and therefore they're aligned by definition (or their alignment check would have failed).

func RandomizeValue

func RandomizeValue(x any)

RandomizeValue assigns random value(s) to an abitrary type. This is intended for used with ABI structs from go_marshal, meaning the typical restrictions apply (fixed-size types, no pointers, maps, channels, etc), and should only be used on zeroed values to avoid overwriting pointers to active go objects.

Internally, we populate the type with random data by doing an unsafe cast to access the underlying memory of the type and filling it as if it were a byte slice. This almost gets us what we want, but padding fields named "_" are normally not accessible, so we walk the type and recursively zero all "_" fields.

Precondition: x must be a pointer. x must not contain any valid pointers to active go objects (pointer fields aren't allowed in ABI structs anyways), or we'd be violating the go runtime contract and the GC may malfunction.

Types

This section is empty.

Jump to

Keyboard shortcuts

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