Documentation
¶
Overview ¶
Package merilo explores and fuzzes systems of hand-written state machines through an adapter. It is imported only from _test.go files.
Index ¶
Constants ¶
const ErrModeChange = constError("merilo: undeclared system-mode change")
ErrModeChange is wrapped by an adapter's Apply when the system mode changes in a way the adapter does not allow.
Variables ¶
This section is empty.
Functions ¶
func Fuzz ¶
func Fuzz(f *testing.F, sys System, o FuzzOptions)
Fuzz turns sys into a native Go fuzz target. Each input decodes into a schedule; a violation fails with the readable trace. With Explore set, the shortest schedule to each tuple the search reaches seeds the fuzzer, so fuzzing starts at the edge of the exhaustive search.
Types ¶
type FuzzOptions ¶
type FuzzOptions struct {
MaxDepth int // steps per input, drain included
Explore Options // when set, a search with this bound runs first, as Explore does, and seeds the fuzzer
}
FuzzOptions bounds a fuzz run. MaxDepth has no default.
type Options ¶
type Options struct {
MaxStates int // the most worlds the search stores
RequireComplete bool // stopping at MaxStates fails the test
}
Options bounds a search. MaxStates has no default.
type Result ¶
type Result struct {
Complete bool // every reachable world was checked
States int // worlds stored
Depth int // every world within this many steps of the start was checked
Tuples []string // control-state tuples reached, sorted
Violation Violation
}
Result is what a search reached and the first violation, if any.
type System ¶
type System interface {
Reset() // return to the initial world
Kinds() int // number of step kinds
Enabled(k int) bool // whether step kind k can be taken in the current world
Apply(k int) error // take step kind k; non-nil error is a violation
World() any // the current world as a strictly comparable value
Check() error // invariants on the current world
Tuple() string // every machine's control state, formatted
Settled() bool // stopped by design, including by an exhausted budget
Describe(k int) string // one readable trace line for step kind k
Invariants() []string // names of the checks Check performs
}
System is the adapter between the harness and the adopter's machines. Steps are kinds, numbered 0 to Kinds()-1; the harness asks which are enabled one at a time, so nothing but integers crosses the interface.
type Totality ¶
type Totality interface {
Machines() int // machine values to check; position 0 is the zero machine
Events() int // events to fire; position 0 is the zero event
// Fire builds machine m, fires event e, and returns the outcome and
// whether the machine and its actions were unchanged.
Fire(m, e int) (out fsm.Outcome, unchanged bool)
Name(m, e int) string // a readable name for the pair
}
Totality exposes one machine's state–event table to Total by position. Positions are indexes the test chooses, never domain values.
type Trace ¶
type Trace []int
Trace is the step kinds taken from the initial world, in order.
type Violation ¶
type Violation struct {
Kind ViolationKind
Trace Trace // shortest path to the violating world
Detail string // the error from Check or Apply
}
Violation is the first rule broken, with the shortest path to it.
type ViolationKind ¶
type ViolationKind uint8
ViolationKind classifies a violation. The zero value means none.
const ( Invariant ViolationKind Deadlock ApplyError ModeChange Nondeterminism )
Violation kinds.
func (ViolationKind) String ¶
func (k ViolationKind) String() string
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
merilovet
command
Command merilovet enforces merilo's FSM rules on every package of the main module.
|
Command merilovet enforces merilo's FSM rules on every package of the main module. |
|
examples
|
|
|
bom
Package bom rolls up a bill of materials by tail recursion, as a state machine.
|
Package bom rolls up a bill of materials by tail recursion, as a state machine. |
|
bom/rollup
Package rollup is the holder for package bom.
|
Package rollup is the holder for package bom. |
|
fib
Package fib computes Fibonacci numbers by tail recursion, as a state machine:
|
Package fib computes Fibonacci numbers by tail recursion, as a state machine: |
|
fib/cmd/fib
command
Command fib prints the nth Fibonacci number.
|
Command fib prints the nth Fibonacci number. |
|
mutex/client
Package client is one client of a lock server: it asks for the lock, holds it once granted, and releases it.
|
Package client is one client of a lock server: it asks for the lock, holds it once granted, and releases it. |
|
order
Package order is a payment-order state machine: submit a charge to a provider, resend on timeout up to MaxRetries, and finish as Paid, Failed or Cancelled.
|
Package order is a payment-order state machine: submit a charge to a provider, resend on timeout up to MaxRetries, and finish as Paid, Failed or Cancelled. |
|
order/cmd/orderd
command
Command orderd drives one order from commands on standard input ("submit", "ack", "cancel"), with a real timer for timeouts.
|
Command orderd drives one order from commands on standard input ("submit", "ack", "cancel"), with a real timer for timeouts. |
|
turnstile
Package turnstile is the smallest machine merilo checks: one mode, no actions, so Fire returns only the next machine and the outcome.
|
Package turnstile is the smallest machine merilo checks: one mode, no actions, so Fire returns only the next machine and the outcome. |
|
twophase/coord
Package coord is a two-phase-commit coordinator for two participants.
|
Package coord is a two-phase-commit coordinator for two participants. |
|
watchdog
Package watchdog fires when it is not kicked in time.
|
Package watchdog fires when it is not kicked in time. |
|
Package fsm is what every merilo machine imports: the outcome Fire returns, the error a holder reports for a refused event, and the bounded counter a machine keeps instead of a raw integer.
|
Package fsm is what every merilo machine imports: the outcome Fire returns, the error a holder reports for a refused event, and the bounded counter a machine keeps instead of a raw integer. |
|
internal
|
|
|
impure
Package impure is an acceptance-test fixture: a machine whose Fire consults a helper package's hidden state, so replaying the same path can reach a different world.
|
Package impure is an acceptance-test fixture: a machine whose Fire consults a helper package's hidden state, so replaying the same path can reach a different world. |
|
impure/clock
Package clock is a helper with hidden state, standing in for a wall clock: each call returns a different value.
|
Package clock is a helper with hidden state, standing in for a wall clock: each call returns a different value. |