testkit

package standard library
go1.22.2 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2024 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	NoString = ""
	NoStack  = []trace.StackFrame{}
)

Functions

func Main

func Main(f func(*Trace))

Types

type Batch

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

Batch represents an event batch.

func (*Batch) Event

func (b *Batch) Event(name string, args ...any)

Event emits an event into a batch. name must correspond to one of the names in Specs() result for the version that was passed to this trace. Callers must omit the timestamp delta.

func (*Batch) RawEvent

func (b *Batch) RawEvent(typ event.Type, data []byte, args ...uint64)

RawEvent emits an event into a batch. name must correspond to one of the names in Specs() result for the version that was passed to this trace.

type Generation

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

Generation represents a single generation in the trace.

func (*Generation) Batch

func (g *Generation) Batch(thread trace.ThreadID, time Time) *Batch

Batch starts a new event batch in the trace data.

This is convenience function for generating correct batches.

func (*Generation) Stack

func (g *Generation) Stack(stk []trace.StackFrame) uint64

Stack registers a stack with the trace.

This is a convenience function for easily adding correct stacks to traces.

func (*Generation) String

func (g *Generation) String(s string) uint64

String registers a string with the trace.

This is a convenience function for easily adding correct strings to traces.

type Seq

type Seq uint64

Seq represents a sequence counter.

type Time

type Time uint64

Time represents a low-level trace timestamp (which does not necessarily correspond to nanoseconds, like trace.Time does).

type Trace

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

Trace represents an execution trace for testing.

It does a little bit of work to ensure that the produced trace is valid, just for convenience. It mainly tracks batches and batch sizes (so they're trivially correct), tracks strings and stacks, and makes sure emitted string and stack batches are valid. That last part can be controlled by a few options.

Otherwise, it performs no validation on the trace at all.

func NewTrace

func NewTrace() *Trace

NewTrace creates a new trace.

func (*Trace) DisableTimestamps

func (t *Trace) DisableTimestamps()

DisableTimestamps makes the timestamps for all events generated after this call zero. Raw events are exempted from this because the caller has to pass their own timestamp into those events anyway.

func (*Trace) ExpectFailure

func (t *Trace) ExpectFailure(pattern string)

ExpectFailure writes down that the trace should be broken. The caller must provide a pattern matching the expected error produced by the parser.

func (*Trace) ExpectSuccess

func (t *Trace) ExpectSuccess()

ExpectSuccess writes down that the trace should successfully parse.

func (*Trace) Generate

func (t *Trace) Generate() []byte

Generate creates a test file for the trace.

func (*Trace) Generation

func (t *Trace) Generation(gen uint64) *Generation

Generation creates a new trace generation.

This provides more structure than Event to allow for more easily creating complex traces that are mostly or completely correct.

func (*Trace) RawEvent

func (t *Trace) RawEvent(typ event.Type, data []byte, args ...uint64)

RawEvent emits an event into the trace. name must correspond to one of the names in Specs() result for the version that was passed to this trace.

Jump to

Keyboard shortcuts

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