testkit

Imports

Imports #

"bytes"
"encoding/binary"
"fmt"
"os"
"regexp"
"strings"
"internal/trace"
"internal/trace/event"
"internal/trace/event/go122"
"internal/trace/raw"
"internal/trace/version"
"internal/txtar"

Constants & Variables

NoStack var #

var NoStack = []trace.StackFrame{...}

NoString var #

var NoString = ""

Type Aliases

Seq type #

Seq represents a sequence counter.

type Seq uint64

Time type #

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

type Time uint64

Structs

Batch struct #

Batch represents an event batch.

type Batch struct {
gen *Generation
thread trace.ThreadID
timestamp Time
size uint64
events []raw.Event
}

Generation struct #

Generation represents a single generation in the trace.

type Generation struct {
trace *Trace
gen uint64
batches []*Batch
strings map[string]uint64
stacks map[stack]uint64
ignoreStringBatchSizeLimit bool
ignoreStackBatchSizeLimit bool
}

Trace struct #

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.

type Trace struct {
ver version.Version
names map[string]event.Type
specs []event.Spec
events []raw.Event
gens []*Generation
validTimestamps bool
bad bool
badMatch *regexp.Regexp
}

stack struct #

type stack struct {
stk [32]trace.StackFrame
len int
}

Functions

Batch method #

Batch starts a new event batch in the trace data. This is convenience function for generating correct batches.

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

DisableTimestamps method #

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 (t *Trace) DisableTimestamps()

Event method #

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 (b *Batch) Event(name string, args ...any)

ExpectFailure method #

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

func (t *Trace) ExpectFailure(pattern string)

ExpectSuccess method #

ExpectSuccess writes down that the trace should successfully parse.

func (t *Trace) ExpectSuccess()

Generate method #

Generate creates a test file for the trace.

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

Generation method #

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 (t *Trace) Generation(gen uint64) *Generation

Main function #

func Main(f func(*Trace))

NewTrace function #

NewTrace creates a new trace.

func NewTrace() *Trace

RawEvent method #

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.

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

RawEvent method #

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.

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

Stack method #

Stack registers a stack with the trace. This is a convenience function for easily adding correct stacks to traces.

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

String method #

String registers a string with the trace. This is a convenience function for easily adding correct strings to traces.

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

createEvent method #

func (t *Trace) createEvent(ev event.Type, data []byte, args ...uint64) raw.Event

newStructuralBatch method #

func (g *Generation) newStructuralBatch() *Batch

uintArgFor method #

func (b *Batch) uintArgFor(arg any, argSpec string) uint64

writeEventsTo method #

writeEventsTo emits event batches in the generation to tw.

func (g *Generation) writeEventsTo(tw *raw.TextWriter)

writeEventsTo method #

writeEventsTo emits events in the batch, including the batch header, to tw.

func (b *Batch) writeEventsTo(tw *raw.TextWriter)

Generated with Arrow