Écrire et vérifier un modèle › Analyse functions

Écrire et vérifier un modèle

Cette page n’est pas encore traduite : voici la version anglaise.

Functional analysis

Say who uses the system and what for, what it must do as functions, and how those functions hand work to each other. Each function is then allocated to the parts that perform it, so a chain of functions with a time budget is measured on the parts when their tests run.

These declarations are the functional extension: actors, missions, use cases, system functions and their flows and chains, operating modes, workflows, deliverables and verification means. They are outside the 1.0 core (archec check --core names each), and the example examples/functional-chain uses all of them on a baggage line.

A first analysis#

A doorbell: a visitor presses a button, and the owner's phone is told within half a second. Write it top down, from who uses it to the parts that do it:

project Doorbell "Doorbell" { edition "1.2" }

// Who uses it, and what for
actor visitor "Visitor" { description "Presses the bell at the door." }
actor owner "Owner" { description "Is told on the phone." }

mission answer-door "Every visitor is answered" { involves visitor, owner }

/// A press at the door reaches the owner's phone.
use-case UC-RING "Ring the bell" {
  involves visitor, owner, SF-RING, FC-RING
}

requirement REQ-RING "Ring in time" {
  text "The owner's phone shall be told within 500 ms of a press."
}

// What the system does, and what flows between its functions
system-function SF-RING "Announce a visitor" {
  system-function SF-SENSE "Sense the press" {
    allocated Home.button
    out press "Press" sends RING
  }
  system-function SF-NOTIFY "Notify the owner" {
    allocated Home.hub
    in press "Press" receives RING
    out note "Note" sends NOTIFY
  }
}

function-flow SF-SENSE.press -> SF-NOTIFY.press as fl-press { name "Button pressed" }

function-chain FC-RING "Press to phone" {
  functions SF-SENSE, SF-NOTIFY
  budget "500 ms"
  satisfies REQ-RING
}

// The parts that perform the functions
message PUSH:   bool
message RING:   bool
message NOTIFY: bool

component Button "Button" {
  power 0.2W
  in finger: data receives PUSH { handler PUSH -> pressed }
  out press: data sends RING
  fn pressed() { send press RING(true) }
}

component Hub "Hub" {
  power 1.5W
  in press:  data   receives RING { handler RING -> relay }
  out phone: data   sends NOTIFY
  var sent:  uint32 = 0
  fn relay() {
    sent += 1
    send phone NOTIFY(true)
  }
}

component Phone "Phone" {
  in note: data receives NOTIFY
}

system Home "Home" {
  part button: Button
  part hub:    Hub
  part phone:  Phone
  button.press -> hub.press
  hub.phone -> phone.note
}

// The modes it runs in
operating-mode DAY "Day" {
  initial
  components button, hub
  to NIGHT on RING
  budget power 2W
}

operating-mode NIGHT "Night" {
  components hub
  to DAY on PUSH
  budget power 2W
}

test-plan TP-RING "Ring" {
  case TC-RING "A press reaches the phone" {
    verifies REQ-RING
    at 0ms do send button.finger PUSH(true)
    within 1s expect hub.sent == 1
  }
}
Diagramme : Home
Ce qu’archec dessine depuis ce code : Home
Essayer

Then run it:

archec check main.arche                 # every name resolves, the budget is a duration
archec sim main.arche --test            # TC-RING runs FC-RING and measures it
archec diagram main.arche FC-RING       # the chain as Mermaid
archec diagram main.arche SF-RING --format svg -o functions.svg
archec doc main.arche                   # the missions, actors and modes in the document

Who uses it: actors, missions, use cases#

  • An actor is someone or something outside the system: a person, another system, the weather.
  • A mission is what the system is for, and the actors it serves (involves).
  • A use-case is one thing an actor does with it. It involves actors, components, functions, chains and scenarios by name. includes, extends and generalizes relate it to other use cases.

archec check resolves every name these write: an actor a mission involves that does not exist is an error (Unknown actor 'ownr'. Did you mean 'owner'?), and so is a name in a use case's involves.

What it does: system functions#

A system-function is something the system does, independent of how. A function written inside another is one of its parts. Its in and out ports say what it receives and sends, with the messages of the model.

allocated names the part, or parts, that perform it, as a path from the system (Home.hub). A path that names no part is an error. kind marks a function that only moves work around: duplicate, gather, route, select or split.

A function-flow is what goes from one function to another, from port to port: function-flow SF-SENSE.press -> SF-NOTIFY.press. Its id comes after as, its name after name, and carries lists what it carries when that is more than one message.

archec diagram main.arche SF-RING draws a function's parts and the flows between them. --format svg and --format d2 draw it in other formats.

Function chains and their budget#

A function-chain is a path through the functions, with its end-to-end time as budget. Write it as a list when it is one path:

function-chain FC-RING "Press to phone" {
  functions SF-SENSE, SF-NOTIFY
  budget "500 ms"
}

Write it as steps and edges when it branches. A step runs one function, or is a control node (kind or, kind and, kind iterate). An edge may name the flow it carries after :, and when says on what condition it is taken:

function-chain FC-ANY-TAG "Bag to its lateral, any tag" {
  budget "10 s"
  step identify { function SF-IDENTIFY }
  step read { kind or }
  step code { function SF-CODE }
  step screen { function SF-SCREEN }
  edge identify -> read
  edge read -> screen : fl-read { when "the tag is read" }
  edge read -> code : fl-no-read { when "no read" }
  edge code -> screen : fl-keyed
}

Each path from a step no edge reaches to a step no edge leaves is one path of the chain. A budget that is not a duration is an error (chain-budget).

The budget is checked in two places:

  • On a run. archec sim --test measures the chain on each case that runs it. The chain starts when the part the first function is allocated to receives a message its in ports receive. It ends when the part of the last function sends a message on one of its out ports, caused by that start. A case where that took longer than the budget fails:

    ✗ TP-RING TC-RING A press reaches the phone
        within 0.000 ms..500.000 ms: FC-RING end to end within its budget, 500 ms (function-chain) — never so
  • On a deployment. archec analyze (and archec check) bound the chain through the parts its functions are allocated to: their @wcet, their threads and the links between them, as for a deployment's chain. It is a lower bound, since what a state machine waits for (after timers) is not in it. A lower bound already over the budget is a warning (e2e-budget).

A chain or flow that names a function the model does not have, an edge between steps the chain does not have, or a flow end on a port its function does not have is a warning (unknown-function). A chain with such a name is not measured, so the warning says why.

Operating modes#

An operating-mode is a mode the whole system is in: day, night, standby.

  • initial marks the mode it starts in.
  • components names the parts active in it, from the top of the system; none named means all of them.
  • requirements names the requirements that apply in it.
  • to NIGHT on RING is a mode it goes to, and on what. A guard may follow in brackets: to TRACKING on TRACK [a service is offered].
  • budget power 2W adds up the power of the parts active in it, and warns when they draw more (budget-over). set radio.power = 8W gives a part another number in this mode.

A mode's numbers are what profiles over time add up phase by phase. archec doc lists the modes in a table: the parts active in each, its requirements and where it goes.

Workflows#

A workflow is a process people or teams follow: who does what, in which order. Its lanes are blocks of the model (a team is a block too), and each line is an activity in one lane or a hand-off between two:

workflow install "Install the bell" in Home {
  lanes button, hub
  button: pair "Pair with the hub"
  button -> hub : join "Join request"
}
Diagramme : Install the bell
Ce qu’archec dessine depuis ce code : Install the bell

in Home lets the lanes be written by their names in that system. A workflow is a scenario with one sequence: archec diagram main.arche seq:install draws it as a sequence diagram. alt, loop, opt and par branch it as in a sequence.

Deliverables and verification means#

A deliverable is a document the project delivers: a specification, an ICD, a plan. It says its kind, status, owner, version, due date and what it covers. A requirement says which deliverable it belongs to with document SRS, and archec doc groups the requirements by deliverable when there are several:

deliverable SRS "Doorbell specification" {
  kind specification
  status draft
  covers UC-RING
}

A means names a means of verification once (a bench, a simulator, a review), so that a requirement's verify { means bench } can say it by name:

means bench "Door bench: a button, a hub and a test phone"

What the build writes#

archec build writes each of these to the Arche project: actors.yaml, missions.yaml, usecases.yaml, functional.yaml (the functions, flows and chains), modes.yaml and deliverables.yaml. The Arche app shows them and its Documentation page assembles each deliverable. archec capella and archec sysml export them too: see importing for what each tool holds.

Limits#

  • Operating modes are not simulated. A run does not switch mode, and a mode's components do not turn parts on or off in archec sim. A mode's trigger (on RING) and guard are not checked against the model's messages.
  • A function chain is measured only to a part that is linked: the end is a message the last function's part sends on a link. A send on a port that no link leaves is not seen, and the case then says nothing about the chain.
  • archec analyze gives a lower bound of a chain, not its time: the time a state machine waits is left out. The simulator's run is the measure.
  • A use case has no diagram of its own, and archec doc does not list use cases, functions or chains: the Arche app and archec diagram show them.
  • A system function's states (the modes it is active in) is written to the Arche project, and archec does not check it.
  • What a use case involves sits at several levels at once: an exporter to a tool with fixed levels, such as Capella, leaves out what it cannot place and says so.