Documentation
¶
Overview ¶
Package pssm reads the OMG PSSM state-machine test suite (ptc/18-11-06, PSSM_TestSuite.xmi), classifies each of its tests by the UML constructs the test's state machine uses, and translates the expressible ones into SysML v2 textual notation for cmd/pssm-referee. The suite is downloaded by scripts/download-pssm-suite.sh and never vendored; docs/project/pssm-referee.md records what a result from it means.
Index ¶
- Constants
- Variables
- func Digest(path string) (string, error)
- func Locate(root string) (string, error)
- func Reproduces(committed, fresh *Report) error
- func Required() bool
- func Validate(m *Model) []string
- func WriteBaseline(path string, r *Report) error
- type Argument
- type Attribute
- type Behavior
- type Body
- type Bucket
- type Class
- type Classification
- type Construct
- type Constructs
- type Diagnostic
- type Document
- type Element
- func (e *Element) Attr(name string) string
- func (e *Element) Descendants() []*Element
- func (e *Element) Describe() string
- func (e *Element) First(tag string) *Element
- func (e *Element) Href() string
- func (e *Element) Name() string
- func (e *Element) Ref(name string) string
- func (e *Element) Refs(name string) []string
- func (e *Element) Tagged(tag string) []*Element
- func (e *Element) Walk(fn func(*Element) bool)
- type Event
- type EventKind
- type Execution
- type Expr
- type ExprKind
- type Expressibility
- type Guard
- type GuardKind
- type Literal
- type LiteralKind
- type Model
- type OpaqueText
- type Operation
- type Options
- type Param
- type Pin
- type Provenance
- type Region
- type Report
- type Row
- type RowKind
- type Signal
- type StateMachine
- type Statement
- type StatementKind
- type Stimulus
- type Suite
- type Test
- type TestReport
- type Transition
- type TransitionKind
- type TranslateError
- type Trigger
- type Use
- type Vertex
- type VertexKind
Constants ¶
const ( DocumentEnv = "PSSM_DOCUMENT" VersionEnv = "PSSM_VERSION" URLEnv = "PSSM_SUITE_URL" SHA256Env = "PSSM_SUITE_SHA256" )
The script's variables; an environment value overrides each for the downloader, so it overrides here too, or the two would fetch and verify different pins.
const BaselinePath = "docs/project/pssm-referee-baseline.json"
BaselinePath is the committed baseline, relative to the repository root.
const DefaultRoot = "build/pssm"
DefaultRoot is the suite root relative to the repository root, where scripts/download-pssm-suite.sh installs the pinned suite.
const LogAttribute = "log"
LogAttribute is the machine attribute the emitted model appends each trace segment to; its value at the end of a run is the run's trace.
const MaxSteps = 100000
MaxSteps is the step budget one run of a translated test has unless the environment names another (runtime.MaxStepsEnvVar). The runtime's own default lets a runaway machine run for minutes before it reports; a translated test that needs more than this many steps is looping, and exhausting the budget is a run error, never a trace.
const Meaning = "A pass checks that the runtime reproduces UML behavior where the model has a " +
"defensible SysML v2 mapping, provides a second opinion on the tool-choice rows, and is " +
"never evidence of SysML v2 conformance."
Meaning is what a pass means, and the first sentence of everything the referee prints about itself.
const PinPath = "scripts/pssm-pin.sh"
PinPath is the script every fetch of the suite sources its pin from.
const RequireEnv = "OPENSYSML_REQUIRE_PSSM_SUITE"
RequireEnv names the environment variable CI sets so an absent suite fails a gate instead of skipping it.
const SuiteFile = "PSSM_TestSuite.xmi"
SuiteFile is the file name of the PSSM test suite within its root.
Variables ¶
var Buckets = []Bucket{BucketPass, BucketFail, BucketNotExpressible, BucketTerminateGap, BucketDiffersByDesign}
Buckets lists every bucket in report order.
var DefaultBudget = runtime.DefaultExploreBudget
DefaultBudget is the exploration budget a translated test is run under; a test that exhausts it fails, since its reachable traces are then unknown.
var ErrSuiteAbsent = errors.New("PSSM test suite is absent")
ErrSuiteAbsent reports that no suite file exists at the root looked in.
var Rows = map[string]Row{ "SM7": {"SM7", RowToolChoice, "Deferral against a transition elsewhere in the configuration"}, "SM11": {"SM11", RowToolChoice, "What the completion of a composite state completes"}, "SM15": {"SM15", RowDiffersByDesign, "A do activity and the machine competing for one occurrence"}, "SM28": {"SM28", RowToolChoice, "History with nothing to restore"}, "SM30": {"SM30", RowToolChoice, "Choice: guards read on arrival"}, "SM32": {"SM32", RowToolChoice, "Junction with no path through"}, }
Rows are the note's rows the suite's tests report on, by row label.
var TestRows = map[string]string{
"Deferred 006 A": "SM15",
"Deferred 006 B": "SM15",
"Deferred 006 C": "SM15",
"Deferred 004 A": "SM7",
"Deferred 004 B": "SM7",
"Deferred 003": "SM7",
"Final001": "SM11",
"Event 016 A": "SM11",
"History 002-C": "SM28",
"Choice 001": "SM30",
"Choice 002": "SM30",
"Junction 002": "SM32",
}
TestRows maps a test to the note row its requirement lands on. It is written by hand from the note, never inferred from a run: a mapped test that fails is `differs-by-design` when its row is v2's verdict and stays `fail` when the row is a tool choice, with the row cited either way; a mapped test that passes is a `pass` reporting on the row.
Functions ¶
func Locate ¶
Locate returns the suite file under root, or an error wrapping ErrSuiteAbsent with the provisioning hint when it does not exist.
func Reproduces ¶
Reproduces is the gate CI applies: the fresh run must measure the same suite as the committed baseline and land the same count in every bucket. The rows are not compared — they are for whoever adjudicates a moved count — and the date and develop commit say when and on what the baseline was recorded.
func Required ¶
func Required() bool
Required reports whether the environment demands the suite be present.
func Validate ¶
Validate parses and validates an emitted model with the front end and lowers its machine, returning every error diagnostic and the lowering error.
func WriteBaseline ¶
WriteBaseline records a fresh report as the committed baseline.
Types ¶
type Behavior ¶
type Behavior struct {
ID string
Name string
Type string
Params []Param
// Body is the activity's content as statements; nil for an opaque behavior.
Body *Body
// Opaque holds an OpaqueBehavior's body and language.
Opaque *OpaqueText
// Source is the Alf text the suite records for the behavior in a comment,
// when it does; it is documentation for a reader, not what is translated.
Source string
}
Behavior is a UML behavior: an activity whose graph is read into Body, or an opaque behavior whose text is Body's single opaque statement.
type Body ¶
Body is an activity read as a sequence of statements in control-flow order, with every node the reading could not express listed under Unsupported.
type Class ¶
type Class struct {
ID string
Name string
Generals []string
// Attributes are the class's own properties.
Attributes []Attribute
// Operations are the class's own operations, with the method that implements each.
Operations []*Operation
// Behaviors are the class's owned behaviors other than the classifier behavior.
Behaviors []*Behavior
// ClassifierBehavior is the behavior a started instance runs: a state
// machine (Machine set) or an activity (Activity set).
Machine *StateMachine
Activity *Behavior
// Standalone marks a class that is itself a state machine: the suite's
// standalone tests give the machine features and operations of its own.
Standalone bool
}
Class is a UML class of the suite: its attributes, operations, owned behaviors and classifier behavior, and its generalizations by name.
type Classification ¶
type Classification struct {
Class Expressibility
// Uses lists every recorded construct, those deciding the class first,
// then by class and document order. A Standard test has at most strays.
Uses []Use
}
Classification is a test's class and the construct uses that decided it.
func Classify ¶
func Classify(t *Test) Classification
Classify decides a test's expressibility from the constructs its state machine uses.
func (Classification) Reason ¶
func (c Classification) Reason() string
Reason spells the uses that decided the class, for a report.
type Construct ¶
type Construct string
Construct is one UML construct the classifier looks for, named as the alignment note's table names it.
const ( // No spelling. ConstructEntryPoint Construct = "entry point" ConstructExitPoint Construct = "exit point" ConstructConnectionPoint Construct = "connection point reference" ConstructLocalTransition Construct = "local transition" ConstructInternalTransition Construct = "internal transition" ConstructExtendedRegion Construct = "extended region" ConstructRedefinedState Construct = "redefined state" ConstructRedefinedTransition Construct = "redefined transition" ConstructRedefinedMachine Construct = "redefined state machine" ConstructSubmachine Construct = "submachine state" ConstructStandalone Construct = "standalone state machine" ConstructUnknownVertex Construct = "unknown pseudostate kind" ConstructNoMachine Construct = "no state machine" // No translation: the model's behaviors read what the notation cannot bind. ConstructBehaviorParameter Construct = "behavior parameter" ConstructOperationResult Construct = "operation result" ConstructTesterTrace Construct = "tester trace" // This project's lowerer refusing a shape UML allows and v2 can spell: // a candidate gap of ours, recorded apart from v2's missing spellings. ConstructForkedRegionNoEntry Construct = "lowerer refuses fork into a region without an entry transition" // Recorded but not deciding: a pseudostate filed as a connection point that // is neither an entry nor an exit point and that no transition reaches. ConstructStrayConnectionPoint Construct = "stray connection point" // The runtime gap. ConstructTerminate Construct = "terminate" // This project's extensions. ConstructDefer Construct = "defer" ConstructFork Construct = "fork" ConstructJoin Construct = "join" ConstructJunction Construct = "junction" ConstructChoice Construct = "choice" ConstructShallowHistory Construct = "shallow history" ConstructDeepHistory Construct = "deep history" )
The constructs that decide a class. Standard constructs are not recorded: they never move a test out of Standard.
type Constructs ¶
Constructs are the UML constructs a state machine uses, by the names the classifier and the baseline record report.
func (Constructs) Sorted ¶
func (c Constructs) Sorted() []string
Sorted lists the constructs in order.
type Diagnostic ¶
Diagnostic is a problem the reader found: which element, and what.
func (Diagnostic) String ¶
func (d Diagnostic) String() string
type Document ¶
type Document struct {
Root *Element
// contains filtered or unexported fields
}
Document is a parsed XMI file: its root and an index of every xmi:id.
type Element ¶
type Element struct {
Tag string
Type string
ID string
Attrs map[string]string
Text string
Children []*Element
Parent *Element
Line int
}
Element is one XML element of an XMI document: its local tag, its xmi:type and xmi:id, every other attribute by local name, and its children in document order. A parsed document is never modified after Parse returns.
func (*Element) Descendants ¶
Descendants returns every descendant (not the element itself) in document order.
func (*Element) Ref ¶
Ref returns the xmi:id a reference names, whether written as an attribute (`guard="_x"`) or as a child element (`<guard xmi:idref="_x"/>`), or "".
func (*Element) Refs ¶
Refs returns every xmi:id a multi-valued reference names: the attribute's space-separated ids and each child element's idref.
type Event ¶
Event is the event a trigger names: a signal event with its signal, a call event with its operation, or another event type named by Type.
type Execution ¶
type Execution struct {
// Reached are the distinct traces exploration reached, sorted.
Reached []string
// Missing are admitted traces no run reached; Extra are reached traces the
// suite does not admit. Either makes the test fail.
Missing []string
Extra []string
// Errors are the distinct errors runs ended in, sorted; any makes the test fail.
Errors []string
// Runs is how many linearizations were run; Status is how exploration ended.
Runs int
Status string
Complete bool
}
Execution is what running a translated model under the exploring scheduler found, compared against the traces the suite admits.
func Execute ¶
func Execute(stop context.Context, m *Model, expected []string, budget runtime.ExploreBudget, jobs int) (*Execution, error)
Execute builds the model's runtime, drives its machine through the queued events once per linearization within budget, jobs at a time, and compares the traces reached against expected. An error is a model that builds no runtime or an exploration that could not be trusted; a run that fails is recorded, not returned.
type Expr ¶
type Expr struct {
Kind ExprKind
// Literal: the literal value.
Literal *Literal
// Param: the parameter's name. Event: the accept result it reads. Read:
// the feature read on Object.
Name string
Object *Expr
// Apply: the behavior applied, by its library name (Concat, ToString, Not,
// ...), and its arguments in parameter order. Call: the operation called on
// Object, with its result used as a value. New: the classifier instantiated, by Name.
Args []Expr
// Unknown: what the reader could not follow, for the diagnostic.
Text string
}
Expr is a value an activity computes: what flows into a pin.
type Expressibility ¶
type Expressibility int
Expressibility is whether a test's model can be spelled in SysML v2 textual notation, decided by the UML constructs its state machine uses, in the order of the alignment note's construct-to-notation table: a construct with no spelling makes the test not expressible whatever else it uses; otherwise `terminate` puts it in the gap, any of this project's extensions makes it an extension test, and it is standard otherwise.
const ( // NotExpressible: the model uses a construct with no SysML v2 spelling. NotExpressible Expressibility = iota // TerminateGap: spellable, but reaches `terminate`, which the runtime refuses. TerminateGap // Extension: spellable with this project's extensions (defer, fork, join, // junction, choice, history). Extension // Standard: spellable in standard SysML v2 notation. Standard )
The four expressibility classes, in decision order.
func (Expressibility) Expressible ¶
func (c Expressibility) Expressible() bool
Expressible reports whether a translated model can be built and run.
func (Expressibility) String ¶
func (c Expressibility) String() string
type Guard ¶
type Guard struct {
Name string
Kind GuardKind
Literal bool
Opaque *OpaqueText
Behavior *Behavior
Type string
}
Guard is a transition guard: its literal value, its opaque text, and the behavior the opaque expression is compiled to, when any.
type Literal ¶
type Literal struct {
Kind LiteralKind
// Text is the value attribute as written; Present is false for a literal
// without one (whose value is the kind's default).
Text string
Present bool
}
Literal is a UML literal specification: its kind and its text as written.
type LiteralKind ¶
type LiteralKind int
LiteralKind is the UML literal kind.
const ( LiteralString LiteralKind = iota LiteralBoolean LiteralInteger LiteralUnlimitedNatural LiteralReal LiteralNull )
The UML literal kinds.
type Model ¶
type Model struct {
Test *Test
// Name is the model's file name, e.g. "Deferred001_SemanticTest.sysml".
Name string
// Package and Machine are the emitted package and the state usage inside
// it; Qualified is the machine's qualified name, e.g. "Deferred001_SemanticTest::M".
Package string
Machine string
Qualified string
// Text is the model.
Text string
// Events are the queued events, in order.
Events []Stimulus
}
Model is one test's state machine spelled in SysML v2 textual notation, with the events the tester's stimulation queues to drive it. The machine keeps a String attribute `log` to which every trace(...) call appends its segment, "::"-joined, so the final log is comparable with Test.Expected.
type OpaqueText ¶
OpaqueText is the body of an opaque behavior or expression in its language.
type Options ¶
type Options struct {
// Jobs is how many linearizations of one test explore at once; the report
// is the same for any value.
Jobs int
// Keep, when set, is a directory each translated model is written to.
Keep string
// Filter, when set, keeps only the tests whose name contains it.
Filter string
// Budget bounds each test's exploration.
Budget runtime.ExploreBudget
}
Options steer a run.
type Param ¶
Param is a behavior or operation parameter: its name, type and direction ("in", "out", "return", "inout").
type Pin ¶
Pin is the suite's identity as scripts/pssm-pin.sh records it.
func ReadPin ¶
ReadPin resolves the pin as scripts/pssm-pin.sh does: the script's defaults under the repository root, each replaced by its environment variable when set.
func (Pin) Provenance ¶
func (p Pin) Provenance(tests int) Provenance
Provenance ties a report to the pin, which Verify has matched to the bytes read.
type Provenance ¶
type Provenance struct {
Document string `json:"document"`
Version string `json:"version"`
URL string `json:"url"`
// Digest is the sha256 of the suite file read, so a report is tied to the
// bytes it measured and not to the pin's promise about them.
Digest string `json:"suiteDigest"`
Tests int `json:"tests"`
// Recorded is the date -update stamped; a plain run leaves it empty.
Recorded string `json:"recorded,omitempty"`
// Develop is the develop commit whose runtime -update measured; a plain
// run leaves it empty.
Develop string `json:"develop,omitempty"`
}
Provenance identifies the suite a report measured.
type Region ¶
type Region struct {
ID string
Name string
Vertices []*Vertex
Transitions []*Transition
// ExtendedRegion names the region this one extends, or "".
ExtendedRegion string
// Comments are the region's documentation comments.
Comments []string
// contains filtered or unexported fields
}
Region is a region of a state machine or composite state.
type Report ¶
type Report struct {
Meaning string `json:"meaning"`
Provenance Provenance `json:"provenance"`
Buckets map[Bucket]int `json:"buckets"`
Tests []TestReport `json:"tests"`
}
Report is one run of the referee over the suite: the buckets' counts, the gate CI compares, and one row per test, for the adjudicator.
func ReadBaseline ¶
ReadBaseline decodes a committed baseline.
func Referee ¶
Referee runs every test of the suite and files it. Only a problem with the harness itself, or a suite the reader could not read whole, is an error; a test that cannot be run is a row in its bucket.
type Row ¶
type Row struct {
// ID is the row's label in the note, e.g. "SM15".
ID string
Kind RowKind
Title string
}
Row is one row of the alignment note a test's requirement lands on.
type RowKind ¶
type RowKind string
RowKind is which verdict the alignment note reached on a row a test reports on.
const ( // RowDiffersByDesign: the note's "differs because v2 differs" — the v2 // library or notation specifies otherwise, so a disagreement is v2's. RowDiffersByDesign RowKind = "differs because v2 differs" // RowToolChoice: the note's "differs, v2 silent" — v2 says nothing, the // runtime chose, and the test is a second opinion on that choice. RowToolChoice RowKind = "differs, v2 silent" )
type StateMachine ¶
type StateMachine struct {
ID string
Name string
// Regions are the machine's top-level regions in document order.
Regions []*Region
// ConnectionPoints are the machine's own entry and exit points.
ConnectionPoints []*Vertex
// Redefines names the state machine this one redefines, or "".
Redefines string
// Owner is the class owning the machine, or "" for a standalone machine.
Owner string
}
StateMachine is a UML state machine with its regions and connection points.
type Statement ¶
type Statement struct {
Kind StatementKind
// Call and Send: the operation, behavior or signal named and its arguments
// in parameter order; Receiver is the object addressed, nil for a behavior.
Name string
Args []Expr
Receiver *Expr
// Accept: the events waited for, and Result the name the accepted
// occurrence is bound to when the body reads it ("" otherwise).
Events []*Event
Result string
// Assign: the feature written on Receiver and the Value written; Replace
// distinguishes `x = v` from `x->add(v)`. Return: the Value returned.
Feature string
Value *Expr
Replace bool
}
Statement is one step of a behavior. Exactly one kind applies.
type StatementKind ¶
type StatementKind int
StatementKind is the kind of a Statement.
const ( StmtCall StatementKind = iota // Receiver.Name(Args...) StmtSend // send Name(Args...) to Receiver StmtAccept // accept one of Events StmtAssign // Receiver.Feature := Value StmtReturn // return Value StmtStart // start Receiver's classifier behavior )
The statement kinds an activity reading produces.
type Stimulus ¶
type Stimulus struct {
Signal string
Call string
// Value is the scalar payload of a signal, nil for a plain signal.
Value *Literal
// Args are the call's arguments in parameter order.
Args []Argument
}
Stimulus is one event the tester sends the target: a signal, with its scalar payload when the signal carries one, or an operation call with its arguments.
type Suite ¶
type Suite struct {
Tests []*Test
// Signals are the protocol signals the tests' machines accept, by name.
Signals map[string]*Signal
// Diagnostics are problems reading the suite that are not tied to one test.
Diagnostics []Diagnostic
}
Suite is the PSSM test suite as read: every registered test in the order the suite registers them, grouped by area in the suite's own area order.
func Read ¶
Read parses an XMI document and reads the suite it contains. Malformed XML is an error; anything the reader cannot interpret inside a well-formed document is a diagnostic on the suite or the test concerned.
func ReadDocument ¶
ReadDocument reads the suite a parsed document contains.
type Test ¶
type Test struct {
// ID is the name of the suite's SemanticTest class, e.g. "Deferred001_SemanticTest".
ID string
// Area is the suite's test area, e.g. "Deferred"; Name its display name, e.g. "Deferred 001".
Area string
Name string
// Expected are the admissible final traces, each segment joined by "::".
Expected []string
// Target is the class under test and Tester the class stimulating it. A
// standalone test has a Machine but no Target class.
Target *Class
Tester *Class
Machine *StateMachine
// Stimulation is the tester's behavior read as a sequence of statements.
Stimulation *Body
// Notes are the suite's own documentation comments on the machine and its
// regions (stimulation sequence, expected execution, run-to-completion
// steps). They are read for the record and never compared.
Notes []string
// Diagnostics are problems reading this test.
Diagnostics []Diagnostic
}
Test is one registered semantic test: its area and name as the suite registers them, the target class whose state machine is under test, the tester whose behavior stimulates it, and the traces the suite admits.
type TestReport ¶
type TestReport struct {
Name string `json:"name"`
Area string `json:"area"`
Class string `json:"class"`
// Row is the alignment note row the test reports on, when the table maps it.
Row string `json:"row,omitempty"`
RowKind string `json:"rowKind,omitempty"`
Bucket Bucket `json:"bucket"`
// Reasons say why the test is in its bucket, one line each; a pass has none.
Reasons []string `json:"reasons,omitempty"`
// Expected and Reached are the admitted and reached trace sets of a test
// that ran; Runs is how many linearizations exploration took.
Expected []string `json:"expected,omitempty"`
Reached []string `json:"reached,omitempty"`
Runs int `json:"runs,omitempty"`
}
TestReport is one test's row.
type Transition ¶
type Transition struct {
ID string
Name string
Kind TransitionKind
Source *Vertex
Target *Vertex
Triggers []*Trigger
Guard *Guard
Effect *Behavior
// Redefines names the transition this one redefines, or "".
Redefines string
// Region is the region owning the transition.
Region *Region
}
Transition is a UML transition with its triggers, guard and effect.
func (*Transition) Describe ¶
func (t *Transition) Describe() string
Describe spells the transition for a diagnostic or report.
type TransitionKind ¶
type TransitionKind int
TransitionKind is a UML transition kind.
const ( TransitionExternal TransitionKind = iota TransitionLocal TransitionInternal )
The three UML transition kinds.
func (TransitionKind) String ¶
func (k TransitionKind) String() string
type TranslateError ¶
TranslateError reports a construct of a test the emitter has no exact translation for. It never drops the construct instead.
func (*TranslateError) Error ¶
func (e *TranslateError) Error() string
type Use ¶
type Use struct {
Construct Construct
// Where names the element using it, e.g. "T3" or "S1.S1.1".
Where string
}
Use is one occurrence of a deciding construct: which, and where.
type Vertex ¶
type Vertex struct {
ID string
Name string
Kind VertexKind
// Region is the region owning the vertex; nil for a connection point owned
// by a state or state machine.
Region *Region
// The state-only parts. Regions are the state's own regions (one for a
// composite state, several for an orthogonal one).
Regions []*Region
Entry, Exit, Do *Behavior
Deferred []*Trigger
ConnectionPoints []*Vertex
// ConnectionPointReferences counts the state's references into a submachine.
ConnectionPointReferences int
// Submachine names the state machine a submachine state references, or "".
Submachine string
// Redefines names the state this one redefines, or "".
Redefines string
// Comments are the state's documentation comments.
Comments []string
}
Vertex is a state, final state or pseudostate in a region.
type VertexKind ¶
type VertexKind int
VertexKind is the kind of a vertex: a state, a final state, or a pseudostate by its kind attribute.
const ( VertexState VertexKind = iota VertexFinal VertexInitial VertexJunction VertexChoice VertexFork VertexJoin VertexShallowHistory VertexDeepHistory VertexEntryPoint VertexExitPoint VertexTerminate VertexUnknown )
The vertex kinds the suite uses. Every UML pseudostate kind has a value so an unknown kind attribute is a diagnostic, not a silent default.
func (VertexKind) IsPseudostate ¶
func (k VertexKind) IsPseudostate() bool
IsPseudostate reports whether the vertex kind is a pseudostate.
func (VertexKind) String ¶
func (k VertexKind) String() string