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
- Variables
- func BeginControlledNondeterminism()
- func ChanCast[V any](v interface{}) V
- func CloneMap(m any) any
- func EndControlledNondeterminism()
- func Envs() []string
- func Fastrand64() uint64
- func Fastrandn(n uint32) uint32
- func GetGoroutine() int
- func GetGoroutineLocalSyscall() unsafe.Pointer
- func GetStacktraceFor(goroutine int, stack []uintptr) int
- func GetStep() int
- func Go(fun func())
- func GoFromTimerHandler(fun func(), machine *Machine)
- func GoWithMachine(fun func(), machine *Machine)
- func InitGlobals(benchmark, initializeShared bool)
- func InitSteps()
- func IsSim() bool
- func Nanotime() int64
- func NextEventID() int
- func Nondeterministic() int
- func NoraceAppend[A any](to []A, from ...A) []A
- func NoraceCopy[A any](a []A) []A
- func PauseGoroutine(goroutineID int)
- func PickRandomOtherGoroutine() (goroutineID int)
- func ResumeGoroutine(goroutineID int)
- func Seed() int64
- func Select(selectors ...ChanSelector) (int, any, bool)
- func Semacquire(addr *uint32, lifo bool)
- func Semrelease(addr *uint32)
- func SetAbortError(err error)
- func SetAllTests(tests []Test)
- func SetFinalizer(obj any, finalizer any)
- func SetSyscallAllocator(f func(goroutineId int) unsafe.Pointer)
- func Sleep(duration int64)
- func Step() int
- func StopMachine(machine *Machine)
- func TestMain(rt Runtime)
- func WriteLog(b []byte)
- func Yield()
- type Chan
- func (c Chan[V]) Cap() int
- func (c Chan[V]) Close()
- func (c Chan[V]) Len() int
- func (c Chan[V]) Range() iter.Seq[V]
- func (c Chan[V]) Recv() V
- func (c Chan[V]) RecvOk() (V, bool)
- func (c Chan[V]) RecvSelector() ChanSelector
- func (c Chan[V]) SelectRecvOrDefault() (int, any, bool)
- func (c Chan[V]) SelectSendOrDefault(v V) (int, any, bool)
- func (c Chan[V]) Send(v V)
- func (c Chan[V]) SendSelector(item V) ChanSelector
- type ChanSelector
- type Global
- type Globaler
- type Globals
- type KV
- type Machine
- type Map
- type MapIter
- type NotifyList
- type PackageInfo
- type RaceToken
- type ReflectMap
- type ReflectMapIter
- type ReflectMapType
- type Runtime
- type Test
- type Timer
- type TraceFlag
- type Uint32Futex
Constants ¶
const AtomicYield = false
const GOOS = "linux"
Variables ¶
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")) )
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 EndControlledNondeterminism ¶
func EndControlledNondeterminism()
func Fastrand64 ¶
func Fastrand64() uint64
func GetStacktraceFor ¶
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 GoFromTimerHandler ¶
func GoFromTimerHandler(fun func(), machine *Machine)
func GoWithMachine ¶
func GoWithMachine(fun func(), machine *Machine)
func InitGlobals ¶
func InitGlobals(benchmark, initializeShared bool)
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 Semacquire ¶
func Semrelease ¶
func Semrelease(addr *uint32)
func SetAbortError ¶
func SetAbortError(err error)
func SetAllTests ¶
func SetAllTests(tests []Test)
func SetFinalizer ¶
func SetSyscallAllocator ¶
func StopMachine ¶
func StopMachine(machine *Machine)
Types ¶
type Chan ¶
type Chan[V any] struct { // contains filtered or unexported fields }
func ExtractChan ¶
func (Chan[V]) RecvSelector ¶
func (c Chan[V]) RecvSelector() ChanSelector
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 KV ¶
type KV[K comparable, V any] struct { K K V V }
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]
type MapIter ¶
type MapIter[K comparable, V any] struct { // contains filtered or unexported fields }
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 ¶
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
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 ReflectMapType ¶
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