Introduction to Spin and PromelaWhat is this all about?RoadmapPowerPoint PresentationHistoryMeanwhile …Currently ..Slide 8Spin capabilitiesSpin overall structureSlide 11PromelaExecutabilityExecutbilityDelimitorsData TypesProcess typesProcess instantiationParameter passingVariable scopingRaces and deadlockAtomic sequencesMessage passingSlide 24Slide 25Slide 26Slide 27Slide 28Queue lengthComposite conditionsSubtle issuesSlide 32RendezvousExampleControl flowCase selectionSlide 37RepetitionSlide 39Unconditional jumpsProcedures and RecursionSlide 42TimeoutsAssertionsSlide 45ReferencesIntroduction to Spin and PromelaSagar ChakiCMUWhat is this all about?SpinOn-the-fly verifier developed at Bell-labs by Gerard Holzmann and othersPromelaModeling language for SPINTargeted at asynchronous systemsSwitching protocolsRoadmapHistorical perspectiveOverview of SpinOverview of PromelaSimulation with SpinOverview of LTLVerification with SpinPart IHistorical PerspectiveHistoryWork leading to Spin started in 1980First bug found on Nov 21, 1980 by PanOne-pass verifier for safety propertiesSucceeded by Pandora (82), Trace (83), SuperTrace (84), SdlValid (88), Spin (89)Spin covered omega-regular propertiesMeanwhile …Temporal logic model checkingClarke et. al. CMU 1981Sifakis et. al. Grenoble 1982Symbolic model checkingMcMillan 1991SMVCurrently ..Theory of symbolic and on-the-fly model checking well-understoodAlgorithms for different logics suited for different implementationsCTL properties – symbolicLTL properties – on-the-flyPart IIOverview of SpinSpin capabilitiesInteractive simulationFor a particular pathFor a random pathExhaustive verificationGenerate C code for verifierCompile the verifier and executeReturns counter-exampleLots of options for fine-tuningSpin overall structureXSpinFront-endPromelaParserLTL Parser andTranslatorSyntaxErrorReportsInteractiveSimulationVerifierGeneratorOptimized ModelChecker (ANSI C)Executable O-T-FVerifierCounter ExamplePart IIIOverview of PromelaPromelaLanguage for asynchronous programsDynamic process creationProcesses execute asynchronouslyCommunicate via shared variables and message channelsRaces must be explicitly avoidedChannels can be queued or rendezvousVery C likeExecutabilityNo difference between conditions and statementsExecution of every statement is conditional on its executabilityExecutability is the basic means of synchronizationExecutbilityDeclarations and assignments are always executableConditionals are executable when they holdThe following are the samewhile (a != b) skip(a == b)DelimitorsSemi-colon is used a statement separator not a statement terminatorLast statement does not need semi-colonOften replaced by -> to indicate causality between two successive statements(a == b); c = c + 1(a == b) -> c = c + 1Data TypesBasic : bit/bool, byte, short, int, chanArrays: fixed sizebyte state[20];state[0] = state[3 * i] + 5 * state[7/j];Symbolic constantsUsually used for message typesmtype = {SEND, RECV};Process typesbyte state = 2;proctype A() { (state == 1) -> state = 3 }proctype B() { state = state – 1 }Process instantiationbyte state = 2;proctype A() { (state == 1) -> state = 3 }proctype B() { state = state – 1 }init { run A(); run B() }run can be used anywhereParameter passingproctype A(byte x; short foo) { (state == 1) -> state = foo }init { run A(1,3); }Data arrays or processes cannot be passedVariable scopingSimilar to Cglobals, locals, parametersbyte foo, bar, baz;proctype A(byte foo) {byte bar;baz = foo + bar; }Races and deadlockbyte state = 1;proctype A() {(state == 1) -> state = state + 1}proctype B() {(state == 1) -> state = state – 1}init { run A(); run B() }Atomic sequencesbyte state = 1;proctype A() { atomic {(state == 1) -> state = state + 1} }proctype B() { atomic {(state == 1) -> state = state – 1} }init() { run A(); run B() }Message passingChannel declarationchan qname = [16] of {short}chan qname = [5] of {byte,int,chan,short}Sending messagesqname!exprqname!expr1,expr2,expr3Receiving messagesqname?varqname?var1,var2,var3Message passingMore parameters sentExtra parameters droppedMore parameters receivedExtra parameters undefinedFewer parameters sentExtra parameters undefinedFewer parameters receivedExtra parameters droppedMessage passingchan x = [1] of {bool};chan y = [1] of {bool,bool};proctype A(bool p, bool q) { x!p,q ; y?p }proctype B(bool p, bool q) { x?p,q ; y!q }init { run A(1,2); run B(3,4) }Message passingConvention: first message field often specifies message type (constant)Alternatively send message type followed by list of message fields in bracesqname!expr1(expr2,expr3)qname?var1(var2,var3)ExecutabilitySend is executable only when the channel is not fullReceive is executable only when the channel is not emptyExecutabilityOptionally some arguments of receive can be constantsqname?RECV,var,10Value of constant fields must match value of corresponding fields of message at the head of channel queueQueue lengthlen(qname) returns the number of messages currently stored in qnameIf used as a statement it will be unexecutable if the channel is emptyComposite conditionsInvalid in Promela(qname?var == 0)(a > b && qname!123)Either send/receive or pure expressionCan evaluate receivesqname?[ack,var]Subtle issuesConsider the followingqname?[msgtype] -> qname?msgtype(len(qname) < MAX) -> qname!msgtypeSecond statement not necessarily executable after the firstRace conditionsTime for example 1RendezvousChannel of size 0 defines a rendezvous portCan be used by two processed for a synchronous handshakeNo queueingThe first process blocksHandshake occurs after the second process arrivesExample#define msgtype 33chan name = [0] of {byte,byte};proctype A() { name!msgtype(99); name!msgtype(100)}proctype B() {byte state; name?msgtype(state)}init { run A(); run B() }Control flowWe have already seen someConcatenation of statements, parallel execution, atomic sequencesThere are a few moreCase selection, repetition, unconditional jumpsCase selectionIf:: (a < b) -> option1:: (a > b) -> option2:: else -> option3 /* optional */fiCases need not be exhaustive or mutually exclusiveNon-deterministic
View Full Document