gosimruntime

package
v0.0.0-...-ffd3a61 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2024 License: MIT Imports: 29 Imported by: 0

Documentation

Overview

Package gosimruntime simulates the go runtime for programs tested using gosim.

The gosimruntime API is internal to gosim and programs should not directly use it. This package is exported only because translated code must be able to import it. Instead, use the public API in the gosim package.

Index

Constants

View Source
const AtomicYield = false
View Source
const GOOS = "linux"

Variables

View Source
var (
	ErrPaniced      = makeConstErr(errors.New("paniced"))
	ErrAborted      = makeConstErr(errors.New("aborted"))
	ErrMainReturned = makeConstErr(errors.New("main returned"))
	ErrTimeout      = makeConstErr(errors.New("timeout"))
	ErrTestFailed   = makeConstErr(errors.New("test failed"))
)
View Source
var TestRaceToken = MakeRaceToken()

TestRaceToken is a publicly accessible RaceToken to allow synchronization between different machines that otherwise have no common happens-before edges.

Machines do not have any happens-before edges between each other. This is fine in most cases because machines do not share any memory and have their own globals.

In low-level gosim tests, though, it can be convenient to share some memory (eg. atomic.Bool indicating success). To do that without triggering the race detector, call TestRaceToken.Release before creating the machine and then TestRaceToken.Acquire inside the machine.

Functions

func BeginControlledNondeterminism

func BeginControlledNondeterminism()

BeginControlledNondeterminism starts a section of code that is expected to behave non-deterministically inside the section but that will not show that outside the section.

Calls to random in the section always return 0. Any attempt to pause the current thread (eg. mutex.Lock) will panic.

Controlled nondeterminism is useful to cache work that can be shared between different machines that is expensive to recompute and complicated to precompute once before machines start. One use case is the JSON package's type cache, see the translate code that inserts calls.

func ChanCast

func ChanCast[V any](v interface{}) V

func CloneMap

func CloneMap(m any) any

CloneMap clones a map, exposed by the runtime for maps.Clone.

func EndControlledNondeterminism

func EndControlledNondeterminism()

func Envs

func Envs() []string

func Fastrand64

func Fastrand64() uint64

func Fastrandn

func Fastrandn(n uint32) uint32

func GetGoroutine

func GetGoroutine() int

Marked go:norace to read ID

func GetGoroutineLocalSyscall

func GetGoroutineLocalSyscall() unsafe.Pointer

func GetStacktraceFor

func GetStacktraceFor(goroutine int, stack []uintptr) int

GetStacktraceFor captures a stacktrace for any goroutine. It switchers, if necessary, to the requested goroutine and captures its stack with runtime.Callers.

TODO: is this necessary? maybe we make goroutines capture their stacks when doing invoke?

func GetStep

func GetStep() int

func Go

func Go(fun func())

Go starts a new goroutine.

Marked go:norace to let upcall access g.

func GoFromTimerHandler

func GoFromTimerHandler(fun func(), machine *Machine)

func GoWithMachine

func GoWithMachine(fun func(), machine *Machine)

func InitGlobals

func InitGlobals(benchmark, initializeShared bool)

func InitSteps

func InitSteps()

func IsSim

func IsSim() bool

func Nanotime

func Nanotime() int64

func NextEventID

func NextEventID() int

Marked go:norace to read and write nextEventID

func Nondeterministic

func Nondeterministic() int

func NoraceAppend

func NoraceAppend[A any](to []A, from ...A) []A

NoraceAppend is a zero overhead version of NoraceAppend. It wraps append.

func NoraceCopy

func NoraceCopy[A any](a []A) []A

NoraceCopy is a zero overhead version of NoraceCopy. It shallowly copies a slice.

func PauseGoroutine

func PauseGoroutine(goroutineID int)

func PickRandomOtherGoroutine

func PickRandomOtherGoroutine() (goroutineID int)

Marked go:norace to return result.

func ResumeGoroutine

func ResumeGoroutine(goroutineID int)

func Seed

func Seed() int64

func Select

func Select(selectors ...ChanSelector) (int, any, bool)

func Semacquire

func Semacquire(addr *uint32, lifo bool)

func Semrelease

func Semrelease(addr *uint32)

func SetAbortError

func SetAbortError(err error)

func SetAllTests

func SetAllTests(tests []Test)

func SetFinalizer

func SetFinalizer(obj any, finalizer any)

func SetSyscallAllocator

func SetSyscallAllocator(f func(goroutineId int) unsafe.Pointer)

func Sleep

func Sleep(duration int64)

func Step

func Step() int

func StopMachine

func StopMachine(machine *Machine)

func TestMain

func TestMain(rt Runtime)

func WriteLog

func WriteLog(b []byte)

func Yield

func Yield()

Types

type Chan

type Chan[V any] struct {
	// contains filtered or unexported fields
}

func ExtractChan

func ExtractChan[M ~struct{ impl *chanImpl[V] }, V any](m M) Chan[V]

func NewChan

func NewChan[V any](capacity int) Chan[V]

func NilChan

func NilChan[V any]() Chan[V]

func (Chan[V]) Cap

func (c Chan[V]) Cap() int

func (Chan[V]) Close

func (c Chan[V]) Close()

func (Chan[V]) Len

func (c Chan[V]) Len() int

func (Chan[V]) Range

func (c Chan[V]) Range() iter.Seq[V]

func (Chan[V]) Recv

func (c Chan[V]) Recv() V

func (Chan[V]) RecvOk

func (c Chan[V]) RecvOk() (V, bool)

func (Chan[V]) RecvSelector

func (c Chan[V]) RecvSelector() ChanSelector

func (Chan[V]) SelectRecvOrDefault

func (c Chan[V]) SelectRecvOrDefault() (int, any, bool)

func (Chan[V]) SelectSendOrDefault

func (c Chan[V]) SelectSendOrDefault(v V) (int, any, bool)

func (Chan[V]) Send

func (c Chan[V]) Send(v V)

func (Chan[V]) SendSelector

func (c Chan[V]) SendSelector(item V) ChanSelector

type ChanSelector

type ChanSelector interface {
	// contains filtered or unexported methods
}

func DefaultSelector

func DefaultSelector() ChanSelector

type Global

type Global[T any] struct {
	// contains filtered or unexported fields
}

func (Global[T]) Get

func (g Global[T]) Get() *T

type Globaler

type Globaler interface {
	// contains filtered or unexported methods
}

type Globals

type Globals struct {
	Globals      Globaler
	Initializers func(initializeShared bool)
}

type KV

type KV[K comparable, V any] struct {
	K K
	V V
}

type Machine

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

func CurrentMachine

func CurrentMachine() *Machine

Marked go:norace to read machine

func NewMachine

func NewMachine(label string) *Machine

type Map

type Map[K comparable, V any] struct {
	Impl *mapImpl[K, V]
}

Map implements go's builtin map API with deterministic yet varying iteration order.

The Map maintains an ordering of values based on their insertion time. Iterators start at a random index and then visit all items.

Map is a value-type that wraps a pointer to an implementation like go's builtin map.

func ExtractMap

func ExtractMap[M ~struct{ Impl *mapImpl[K, V] }, K comparable, V any](m M) Map[K, V]

ExtractMap extracts a Map from named Map types.

TODO: Consider instead having many generic package-local funcs for MapRange, MapSet, etc.? That would sidestep all the ExtractMap calls.

func MapLiteral

func MapLiteral[K comparable, V any](pairs []KV[K, V]) Map[K, V]

MapLiteral builds a Map from a slice of key-value pairs.

func NewMap

func NewMap[K comparable, V any]() Map[K, V]

func NilMap

func NilMap[K comparable, V any]() Map[K, V]

func (Map[K, V]) Clear

func (m Map[K, V]) Clear()

func (Map[K, V]) Delete

func (m Map[K, V]) Delete(k K)

func (Map[K, V]) Get

func (m Map[K, V]) Get(k K) V

func (Map[K, V]) GetOk

func (m Map[K, V]) GetOk(k K) (V, bool)

func (Map[K, V]) Iter

func (m Map[K, V]) Iter() MapIter[K, V]

func (Map[K, V]) Len

func (m Map[K, V]) Len() int

func (Map[K, V]) Range

func (m Map[K, V]) Range() iter.Seq2[K, V]

func (Map[K, V]) Set

func (m Map[K, V]) Set(k K, v V)

type MapIter

type MapIter[K comparable, V any] struct {
	// contains filtered or unexported fields
}

func (*MapIter[K, V]) Next

func (i *MapIter[K, V]) Next() (K, V, bool)

type NotifyList

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

func (*NotifyList) Add

func (l *NotifyList) Add() uint32

func (*NotifyList) NotifyAll

func (l *NotifyList) NotifyAll()

func (*NotifyList) NotifyOne

func (l *NotifyList) NotifyOne()

func (*NotifyList) Wait

func (l *NotifyList) Wait(t uint32)

type PackageInfo

type PackageInfo struct {
	Path    string
	Globals *Globals
	ForTest *Globals
}

func RegisterPackage

func RegisterPackage(path string) *PackageInfo

type RaceToken

type RaceToken struct{}

RaceToken is a zero overhead version of RaceToken for non-race builds. It does not do anything.

func EmptyRaceToken

func EmptyRaceToken() RaceToken

func MakeRaceToken

func MakeRaceToken() RaceToken

func (RaceToken) Acquire

func (r RaceToken) Acquire()

func (RaceToken) Empty

func (t RaceToken) Empty() bool

func (RaceToken) Release

func (t RaceToken) Release()

type ReflectMap

type ReflectMap interface {
	GetIndex(reflect.Value) (reflect.Value, bool)
	SetIndex(reflect.Value, reflect.Value)
	Iter() ReflectMapIter
	Len() int
	UnsafePointer() unsafe.Pointer
	Type() ReflectMapType
}

ReflectMap provides a reflection API to access a Map, used by gosim's internal/reflect package.

type ReflectMapIter

type ReflectMapIter interface {
	Key() reflect.Value
	Value() reflect.Value
	Next() bool
}

type ReflectMapType

type ReflectMapType interface {
	Make() any
	KeyType() reflect.Type
	ElemType() reflect.Type
}

type Runtime

type Runtime interface {
	Run(fn func())
	Setup()
	TestEntrypoint(match string, skip string, tests []Test) bool
}

type Test

type Test struct {
	Name string
	Test any // func()
}

type Timer

type Timer struct {
	Arg     any
	Machine *Machine
	// contains filtered or unexported fields
}

func NewTimer

func NewTimer(handler func(arg *Timer), arg any, machine *Machine, when int64) *Timer

func (*Timer) Reset

func (t *Timer) Reset(when int64) bool

func (*Timer) Stop

func (t *Timer) Stop() bool

type TraceFlag

type TraceFlag struct {
	// contains filtered or unexported fields
}
var (
	TraceSyscall TraceFlag
	TraceStack   TraceFlag
)

func (*TraceFlag) Enabled

func (t *TraceFlag) Enabled() bool

type Uint32Futex

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

func (*Uint32Futex) Get

func (w *Uint32Futex) Get() uint32

func (*Uint32Futex) Set

func (w *Uint32Futex) Set(val uint32)

func (*Uint32Futex) SetBit

func (w *Uint32Futex) SetBit(index int, value bool)

func (*Uint32Futex) WaitNonzero

func (w *Uint32Futex) WaitNonzero() uint32

Jump to

Keyboard shortcuts

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