Documentation
¶
Overview ¶
Package gosim provides machine lifecycle controls for deterministic Go simulations. The fs, net and rt subpackages own filesystem, network and runtime controls.
Running tests ¶
Gosim translates application Go code with Linux source definitions and builds a native executable using an exact selected Go patch. Configure one immutable feature set: rt, rt+fs, rt+net, or rt+fs+net. Filesystem and network require rt. Normal CLI commands require reviewed certification for the exact tuple and source.
GOTOOLCHAIN=go1.25.14 go build -ldflags=-checklinkname=0 -tags=linkname -o .gosim/gosimtool ./cmd/gosim ./.gosim/gosimtool test -go go1.25.14 -features rt -run TestName -seeds 1-20 ./package
See README.md for configuration, the candidate development workflow and current compatibility evidence. Metatesting runs matching prebuilt simulation workers from native Go tests; it validates their identities and contents before execution.
Machines and features ¶
NewMachine returns an unstarted machine. Configure optional services before Start. Returning from Main gracefully ends that epoch. Stop is graceful, Crash retains the filesystem crash outcome, and Restart creates a new epoch with fresh globals. Wait observes the epoch active at entry. Destroy invalidates the control handle. Machine termination cancels its goroutines without executing their pending defers.
Use the fs package for persistence configuration and owned crash snapshots, the net package for IPv4/TCP addressing and directed network policy, and rt for timeout and build/run information. Importing a control package does not enable its feature. Disabled feature use aborts the simulation even when errors are ignored or panics are recovered; it never falls back to host I/O.
Outside simulation, error-returning controls return ErrNotSim, IsSim returns false, and CurrentMachine returns a zero handle. ExitSelf and CrashSelf terminate the current simulated machine without returning; native calls panic with ErrNotSim.
Determinism and scope ¶
An identical complete build identity, replay revision and seed reproduces execution. Scheduler, application, filesystem and network randomness use independent streams. Only one simulation runs at a time in a host process.
The syscall model retains documented limitations in locking, permissions, mappings and process services. UDP, IPv6 and unmodified HTTP/gRPC application stacks are not claimed supported. Capability manifests distinguish implemented, limited, stub and rejected behavior. See docs/design.md for package ownership and native/translated boundaries, and docs/reports/syscall-support-for-gquorum.md for historical gaps.
Index ¶
- Variables
- func CrashSelf()
- func ExitSelf()
- func IsSim() bool
- type DescriptorGroup
- type Exit
- type ExitKind
- type FeatureDisabledError
- type Machine
- func (Machine) Crash() error
- func (Machine) Destroy() error
- func (m Machine) ID() uint64
- func (Machine) Label() (string, error)
- func (Machine) Restart() error
- func (m Machine) RunID() uint64
- func (Machine) SetMain(func()) error
- func (Machine) Start() error
- func (Machine) State() (MachineState, error)
- func (Machine) Stop() error
- func (m Machine) SyscallsMonitor() SyscallsMonitor
- func (Machine) Wait() (Exit, error)
- type MachineConfig
- type MachineState
- type SyscallGroup
- type SyscallInfo
- type SyscallStat
- type SyscallsMonitor
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotSim = contracts.ErrNotSim ErrWrongRun = contracts.ErrWrongRun ErrMachineNotFound = contracts.ErrMachineNotFound ErrInvalidState = contracts.ErrInvalidState ErrNotStarted = contracts.ErrNotStarted ErrSelfTransition = contracts.ErrSelfTransition ErrInvalidConfig = contracts.ErrInvalidConfig )
Functions ¶
Types ¶
type DescriptorGroup ¶ added in v0.9.1
type DescriptorGroup string
DescriptorGroup describes the primary input descriptor's owner at admission.
const ( DescriptorGroupNone DescriptorGroup = "none" // no primary input descriptor DescriptorGroupRT DescriptorGroup = "rt" DescriptorGroupFS DescriptorGroup = "fs" DescriptorGroupNet DescriptorGroup = "net" DescriptorGroupUnknown DescriptorGroup = "unknown" // descriptor lookup failed )
type FeatureDisabledError ¶
FeatureDisabledError describes a run-level failure. Disabled operations abort the simulation; they cannot be ignored or recovered by application code.
func (*FeatureDisabledError) Error ¶
func (e *FeatureDisabledError) Error() string
type Machine ¶
type Machine struct {
// contains filtered or unexported fields
}
Machine is a control reference scoped to one simulation run. Start publishes the first epoch; Restart preserves provider state and initializes fresh globals. A machine's return or explicit termination cancels its goroutines without running their pending defers.
func CurrentMachine ¶
func CurrentMachine() Machine
func NewMachine ¶
func NewMachine(MachineConfig) (Machine, error)
func (Machine) State ¶
func (Machine) State() (MachineState, error)
func (Machine) SyscallsMonitor ¶ added in v0.9.1
func (m Machine) SyscallsMonitor() SyscallsMonitor
SyscallsMonitor returns a non-nil handle without starting or enabling anything. Handles for the same machine share state and become invalid after Destroy.
type MachineConfig ¶
type MachineConfig struct {
Label string
Main func()
}
MachineConfig is copied by NewMachine. Main must be non-nil. The new machine is unstarted so optional providers can be configured before Start.
type MachineState ¶
type MachineState uint8
Machine is a control reference scoped to one simulation run. Start publishes the first epoch; Restart preserves provider state and initializes fresh globals. A machine's return or explicit termination cancels its goroutines without running their pending defers.
const ( New MachineState = iota Starting Running Stopping Stopped Crashed )
type SyscallGroup ¶ added in v0.9.1
type SyscallGroup string
SyscallGroup is a syscall's fixed functional group, independent of its FD.
const ( SyscallGroupRT SyscallGroup = "rt" SyscallGroupFS SyscallGroup = "fs" SyscallGroupNet SyscallGroup = "net" )
type SyscallInfo ¶ added in v0.9.1
type SyscallInfo struct {
Name string
Group SyscallGroup
DescriptorBased bool
}
SyscallInfo describes an available countable name, even if it has not run. DescriptorBased means the route consumes an existing primary input FD; directory-context and returned descriptors are excluded.
func CountableSyscalls ¶ added in v0.9.1
func CountableSyscalls() ([]SyscallInfo, error)
CountableSyscalls returns ErrNotSim outside a simulation, where no feature set is selected.
type SyscallStat ¶ added in v0.9.1
type SyscallStat struct {
Count uint64
Group SyscallGroup
ByDescriptor map[DescriptorGroup]uint64
}
SyscallStat contains a total and its nonzero descriptor-owner buckets. Count equals the sum of ByDescriptor. Group is fixed even for mixed owners.
type SyscallsMonitor ¶ added in v0.9.1
type SyscallsMonitor interface {
// Start enables counting without clearing existing statistics.
Start() error
// Stop pauses counting without clearing existing statistics.
Stop() error
// Reset clears statistics without changing whether counting is enabled.
Reset() error
// Counts returns an owned map of observed syscall names to nonzero totals.
Counts() (map[string]uint64, error)
// Stats returns an owned snapshot, including fresh nested descriptor maps.
Stats() (map[string]SyscallStat, error)
}
SyscallsMonitor controls one machine's routed syscall-attempt counters. Counting starts disabled. State survives machine stop, crash, and restart. All methods validate the machine handle; native methods return ErrNotSim. Calls are scheduling points, so stop counting or use a workload barrier when comparing separate snapshots. Native calls and hook-local errors are excluded.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
gosim
command
Command gosim resolves Go in the caller context and starts a matching worker.
|
Command gosim resolves Go in the caller context and starts a matching worker. |
|
gosim-gen
command
Command gosim-gen generates shared compatibility adapters and transport.
|
Command gosim-gen generates shared compatibility adapters and transport. |
|
gosim-worker
command
Command gosim-worker executes commands using its own compile-time Go family.
|
Command gosim-worker executes commands using its own compile-time Go family. |
|
Package fs controls the optional simulated filesystem provider.
|
Package fs controls the optional simulated filesystem provider. |
|
internal
|
|
|
buildcfg
Package buildcfg resolves immutable host-side build settings.
|
Package buildcfg resolves immutable host-side build settings. |
|
buildrun
Package buildrun compiles an already validated immutable selection.
|
Package buildrun compiles an already validated immutable selection. |
|
buildspec
Package buildspec defines host-side values shared by build configuration and compatibility profiles.
|
Package buildspec defines host-side values shared by build configuration and compatibility profiles. |
|
candidate
Package candidate exposes internal build/run helpers using the same family support policy and artifact checks as ordinary commands.
|
Package candidate exposes internal build/run helpers using the same family support policy and artifact checks as ordinary commands. |
|
compat/hooks/kernel
Package kernel contains translated selected Go adapters, never concrete providers.
|
Package kernel contains translated selected Go adapters, never concrete providers. |
|
compat/profiles
Package profiles exposes cumulative metadata without executable adapters or provenance embeds.
|
Package profiles exposes cumulative metadata without executable adapters or provenance embeds. |
|
compat/shims/cryptorand
Package rand provides a deterministic replacement for crypto/rand when running under gosim simulation.
|
Package rand provides a deterministic replacement for crypto/rand when running under gosim simulation. |
|
compat/shims/debug
Package debug rejects host garbage-collector controls in simulation.
|
Package debug rejects host garbage-collector controls in simulation. |
|
compat/shims/ecdsa
Package ecdsa declares optional signing and key types for translated callers.
|
Package ecdsa declares optional signing and key types for translated callers. |
|
compat/shims/elliptic
Package elliptic preserves the optional curve declarations used by etcd's certificate branch.
|
Package elliptic preserves the optional curve declarations used by etcd's certificate branch. |
|
compat/shims/exec
Package exec exposes process declarations but rejects process execution.
|
Package exec exposes process declarations but rejects process execution. |
|
compat/shims/httppprof
Package httppprof keeps optional profiling handlers fail-closed.
|
Package httppprof keeps optional profiling handlers fail-closed. |
|
compat/shims/maps
Package maps_shim provides a minimal replacement for internal/runtime/maps used when translating hash/maphash.
|
Package maps_shim provides a minimal replacement for internal/runtime/maps used when translating hash/maphash. |
|
compat/shims/metrics
Package metrics provides declarations for dormant runtime metric collectors.
|
Package metrics provides declarations for dormant runtime metric collectors. |
|
compat/shims/ocsp
Package ocsp declares the optional golang.org/x/crypto/ocsp API and rejects its execution.
|
Package ocsp declares the optional golang.org/x/crypto/ocsp API and rejects its execution. |
|
compat/shims/pprof
Package pprof models diagnostic labels.
|
Package pprof models diagnostic labels. |
|
compat/shims/reflect
Package reflect is a shim of the built-in reflect package.
|
Package reflect is a shim of the built-in reflect package. |
|
compat/shims/reflect2
Package reflect2 provides translated type metadata for the pinned jsoniter dependency.
|
Package reflect2 provides translated type metadata for the pinned jsoniter dependency. |
|
compat/shims/rsa
Package rsa preserves optional key declarations for etcd authentication and JWT code.
|
Package rsa preserves optional key declarations for etcd authentication and JWT code. |
|
compat/shims/signal
Package signal keeps imported signal APIs inside the simulation boundary.
|
Package signal keeps imported signal APIs inside the simulation boundary. |
|
compat/shims/synctest
Package synctest models internal standard-library association probes outside bubbles.
|
Package synctest models internal standard-library association probes outside bubbles. |
|
compat/shims/tls
Package tls declares the optional crypto/tls API and rejects its execution.
|
Package tls declares the optional crypto/tls API and rejects its execution. |
|
compat/shims/trace
Package trace models tracing as disabled for simulated application code.
|
Package trace models tracing as disabled for simulated application code. |
|
compat/shims/user
Package user keeps optional account lookup fail-closed.
|
Package user keeps optional account lookup fail-closed. |
|
compat/shims/x509
Package x509 declares the optional crypto/x509 API and rejects its execution.
|
Package x509 declares the optional crypto/x509 API and rejects its execution. |
|
compat/spec
Package spec contains Go compatibility metadata, never executable adapters.
|
Package spec contains Go compatibility metadata, never executable adapters. |
|
compose
Package compose renders translated composition without importing providers or executable adapters into the host generator.
|
Package compose renders translated composition without importing providers or executable adapters into the host generator. |
|
contracts
Package contracts defines translated domain contracts shared by the kernel and optional providers.
|
Package contracts defines translated domain contracts shared by the kernel and optional providers. |
|
control
Package control transports translated public commands to the run's kernel.
|
Package control transports translated public commands to the run's kernel. |
|
fs
Linux O_DIRECTORY follows the simulated architecture, independently of host OS.
|
Linux O_DIRECTORY follows the simulated architecture, independently of host OS. |
|
gosimcli
Gosim translates, builds and executes deterministic simulation tests.
|
Gosim translates, builds and executes deterministic simulation tests. |
|
hostabi
Package hostabi isolates the selected native Go runtime ABI from the engine.
|
Package hostabi isolates the selected native Go runtime ABI from the engine. |
|
kernel
Code generated by gosim-gen.
|
Code generated by gosim-gen. |
|
logging
Package logging installs the translated, per-machine structured log handler.
|
Package logging installs the translated, per-machine structured log handler. |
|
net
Package net implements translated IPv4 TCP services over an owned model.
|
Package net implements translated IPv4 TCP services over an owned model. |
|
prettylog
MIT License
|
MIT License |
|
routegen
Package routegen owns the reviewed transport schema.
|
Package routegen owns the reviewed transport schema. |
|
tests/features
Package features records complete package applicability for candidate testing.
|
Package features records complete package applicability for candidate testing. |
|
testutil
Package testutil contains shared test fixtures, never runtime admission rules.
|
Package testutil contains shared test fixtures, never runtime admission rules. |
|
workerboot
Package workerboot resolves and starts native Go workers.
|
Package workerboot resolves and starts native Go workers. |
|
Package metatesting is a package for writing normal go tests that invoke gosim tests.
|
Package metatesting is a package for writing normal go tests that invoke gosim tests. |
|
Package nemesis contains pre-built scenarios that introduce problems into distributed systems to try and trigger rare bugs.
|
Package nemesis contains pre-built scenarios that introduce problems into distributed systems to try and trigger rare bugs. |
|
Package net controls the optional simulated network provider.
|
Package net controls the optional simulated network provider. |
|
Package rt controls a run's virtual timeout and reports immutable build metadata.
|
Package rt controls a run's virtual timeout and reports immutable build metadata. |
|
runtime
Package gosimruntime simulates the go runtime for programs tested using gosim.
|
Package gosimruntime simulates the go runtime for programs tested using gosim. |
|
runtime/abi
Package abi defines the untranslated memory and identity boundary used by generated code.
|
Package abi defines the untranslated memory and identity boundary used by generated code. |