testutils

package
v0.0.0-...-6c7272e Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2022 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package testutils implements reusable helpers for writing compiler tests.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ExternA will be called whenever the test_extern_a extern function is
	// called.
	ExternA func(*executor.Env, uint64, float32, bool) uint64

	// ExternB will be called whenever the test_extern_b extern function is
	// called.
	ExternB func(*executor.Env, string) bool
)

Functions

func Encode

func Encode(vals ...interface{}) []byte

Encode encodes all the vals to the returned byte slice with little-endianness. Struct alignment and padding is ignored.

func Pad

func Pad(n int) []byte

Pad returns a slice of n zero bytes. Pad can be used to align data passed to Encode.

Types

type Cmd

type Cmd struct {
	N string  // Command name
	D []byte  // Encoded command used by the compiler generated execute function
	E *Extras // Command extras
	T uint64  // Command thread
}

Cmd is a custom implementation of the api.Cmd interface that simplifies testing compiler generated commands.

func (*Cmd) API

func (c *Cmd) API() api.API

API stubs the api.Cmd interface.

func (*Cmd) Alive

func (c *Cmd) Alive() bool

Alive returns true if this command should be marked alive for DCE

func (*Cmd) Caller

func (c *Cmd) Caller() api.CmdID

Caller stubs the api.Cmd interface.

func (*Cmd) Clone

func (c *Cmd) Clone(arena.Arena) api.Cmd

Clone makes a shallow copy of this command.

func (*Cmd) CmdFlags

CmdFlags stubs the api.Cmd interface.

func (*Cmd) CmdName

func (c *Cmd) CmdName() string

CmdName stubs the api.Cmd interface.

func (*Cmd) CmdParams

func (c *Cmd) CmdParams() api.Properties

CmdParams stubs the api.Cmd interface.

func (*Cmd) CmdResult

func (c *Cmd) CmdResult() *api.Property

CmdResult stubs the api.Cmd interface.

func (Cmd) Encode

func (c Cmd) Encode(out []byte) bool

Encode implements the executor.Encodable interface to encode the command to a buffer used by the compiler generated execute function.

func (*Cmd) Extras

func (c *Cmd) Extras() *api.CmdExtras

Extras stubs the api.Cmd interface.

func (*Cmd) Mutate

Mutate stubs the api.Cmd interface.

func (*Cmd) SetCaller

func (c *Cmd) SetCaller(api.CmdID)

SetCaller stubs the api.Cmd interface.

func (*Cmd) SetTerminated

func (c *Cmd) SetTerminated(terminated bool)

SetTerminated stubs the api.Cmd interface.

func (*Cmd) SetThread

func (c *Cmd) SetThread(thread uint64)

SetThread stubs the api.Cmd interface.

func (*Cmd) Terminated

func (c *Cmd) Terminated() bool

Terminated stubs the api.Cmd interface.

func (*Cmd) Thread

func (c *Cmd) Thread() uint64

Thread stubs the api.Cmd interface.

type Extras

type Extras struct {
	// contains filtered or unexported fields
}

Extras is a helper wrapper around an api.CmdExtras has helpers methods for adding read and writ observations.

func R

func R(base uint64, size uint64, id id.ID) *Extras

R creates and returns a new Extras containing a single read using the given range and data.

func W

func W(base uint64, size uint64, id id.ID) *Extras

W creates and returns a new Extras containing a single write using the given range and data.

func (*Extras) R

func (e *Extras) R(base uint64, size uint64, id id.ID) *Extras

R adds a read using the given range and data, returning this Extras so calls can be chained.

func (*Extras) W

func (e *Extras) W(base uint64, size uint64, id id.ID) *Extras

W adds a write using the given range and data, returning this Extras so calls can be chained.

Jump to

Keyboard shortcuts

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