Download - SPIN / PROMELA
![Page 1: SPIN / PROMELA](https://reader033.vdocument.in/reader033/viewer/2022061616/56814664550346895db383d1/html5/thumbnails/1.jpg)
04/21/23 Master IRAD - SPIN / PROMELA 1
SPIN / PROMELA
![Page 2: SPIN / PROMELA](https://reader033.vdocument.in/reader033/viewer/2022061616/56814664550346895db383d1/html5/thumbnails/2.jpg)
04/21/23 Master IRAD - SPIN / PROMELA 2
Introduction (1)
• SPIN = Simple Promela Interpreter– Analyse de systèmes distribués, notamment des protocoles de
communications,• Modélisation du système en langage PROMELA,• Simulation aléatoire ou interactive du modèle,• Vérification d’invariants / de propriétés LTL sur le modèle.
• PROMELA = Protocol/Processus Meta Language– Langage de spécification de SPIN
• Documentation :
http://spinroot.com/spin/whatispin.html
http://spinroot.com/spin/Man/Manual.html
![Page 3: SPIN / PROMELA](https://reader033.vdocument.in/reader033/viewer/2022061616/56814664550346895db383d1/html5/thumbnails/3.jpg)
04/21/23 Master IRAD - SPIN / PROMELA 3
Introduction (2)
XSPINFront-End
Promelaparser
PLTL parser and Translator
Verifier generator
Interactive Simulation
Syntax Error reports
Optimized Model-checker
Executable On-the-fly
VerifierCounter-examples
![Page 4: SPIN / PROMELA](https://reader033.vdocument.in/reader033/viewer/2022061616/56814664550346895db383d1/html5/thumbnails/4.jpg)
04/21/23 Master IRAD - SPIN / PROMELA 4
Promela
![Page 5: SPIN / PROMELA](https://reader033.vdocument.in/reader033/viewer/2022061616/56814664550346895db383d1/html5/thumbnails/5.jpg)
04/21/23 Master IRAD - SPIN / PROMELA 5
Spécification Promela
• Une spécification Promela peut être composée de :– Variables,
– Canaux de communication,
– Un ou plusieurs processus+ un processus initial « init ».
• Syntaxe proche de celle de C
• Commentaires de la forme : /* …. */
![Page 6: SPIN / PROMELA](https://reader033.vdocument.in/reader033/viewer/2022061616/56814664550346895db383d1/html5/thumbnails/6.jpg)
04/21/23 Master IRAD - SPIN / PROMELA 6
Types, variables et constantes
• Types de base : bit, bool, byte, short, int
• Exemplesbool sa, ra;int i = 0;
Type Taille Domaine
bit 1 0...1
bool 1 0…1
byte 8 0...255
short 16 -215-1...215-1
int 32 -231-1...231-1
![Page 7: SPIN / PROMELA](https://reader033.vdocument.in/reader033/viewer/2022061616/56814664550346895db383d1/html5/thumbnails/7.jpg)
04/21/23 Master IRAD - SPIN / PROMELA 7
Types, variables et constantes
• Types énumérés : – Ensemble de constantes symboliques– Un seul type énuméré autorisé par spécification– mtype = {Partiel,Complet,Ack}
mtype st,rt;
• Structures– typedef Mesg {bool b; int data};
-> Structure Mesg avec un booléen et un entier– Mesg m;
m.b = 0;m.data = 5;
![Page 8: SPIN / PROMELA](https://reader033.vdocument.in/reader033/viewer/2022061616/56814664550346895db383d1/html5/thumbnails/8.jpg)
04/21/23 Master IRAD - SPIN / PROMELA 8
Types, variables et constantes
• Tableaux – int sf[5]; tableau de 5 entiers (0 à 4).
• Canaux– chan ch_bloc = [3] of {int};
canal pouvant contenir 3 messages, chaque message étant un entier.
• Constantes– #define MAX 5;
Constante MAX égale à 5.
![Page 9: SPIN / PROMELA](https://reader033.vdocument.in/reader033/viewer/2022061616/56814664550346895db383d1/html5/thumbnails/9.jpg)
04/21/23 Master IRAD - SPIN / PROMELA 9
Opérateurs
Type Opérateurs
Arithmétiques +, -, *, /, %, --, ++
Relationnels >, >=, <=, <, ==, !=
Logiques &&, ||, !
Bits &, |, ~, ^, >>, <<
Canaux !, ?
![Page 10: SPIN / PROMELA](https://reader033.vdocument.in/reader033/viewer/2022061616/56814664550346895db383d1/html5/thumbnails/10.jpg)
04/21/23 Master IRAD - SPIN / PROMELA 10
Processus
• Déclarationproctype nom_proc (paramètres formels) {
/* Déclarations des variables locales et instructions */
}
• Instanciationrun nom_proc (paramètres effectifs)
• Processus initial
init {
/* Déclarations des variables locales et instructions */
}
![Page 11: SPIN / PROMELA](https://reader033.vdocument.in/reader033/viewer/2022061616/56814664550346895db383d1/html5/thumbnails/11.jpg)
04/21/23 Master IRAD - SPIN / PROMELA 11
Spécification Promela /* Déclaration des constantes *//* Déclaration et initialisation des variables globales */
proctype sender () {/* Déclaration des variables locales et instructions */
}
proctype receiver () {/* Déclarations des variables locales et instructions */
}
init {run sender(); run receiver();
}
![Page 12: SPIN / PROMELA](https://reader033.vdocument.in/reader033/viewer/2022061616/56814664550346895db383d1/html5/thumbnails/12.jpg)
04/21/23 Master IRAD - SPIN / PROMELA 12
Instructions
• Activables ou bloquées– Si une instruction est activable, elle peut être immédiatement
exécutée.– Si une instruction est bloquée, l’exécution du processus dans
lequel elle apparaît est bloquée jusqu’à ce que l’instruction devienne activable.
• Instructions séparées par ; ou ->
• Pas de distinction entre condition et instruction– (a==b) ; b++ : b n’est incrémenté que si a est égal à b. Sinon, on
dit que l’instruction (a==b) est bloquante. On préférera ici la notation (a==b) -> b++
![Page 13: SPIN / PROMELA](https://reader033.vdocument.in/reader033/viewer/2022061616/56814664550346895db383d1/html5/thumbnails/13.jpg)
04/21/23 Master IRAD - SPIN / PROMELA 13
Entrelacement (1)
• 1 processus = 1 automatebyte x=2, y=3;proctype A() { x = x + 1}proctype B() {x = x – 1 ; y = y + x}init {run A() ; run B()}
x=2y=3
initx=3y=3
x=x+1
x=2y=3
initx=1y=3
x=x-1 x=1y=4
y=y+x
![Page 14: SPIN / PROMELA](https://reader033.vdocument.in/reader033/viewer/2022061616/56814664550346895db383d1/html5/thumbnails/14.jpg)
04/21/23 Master IRAD - SPIN / PROMELA 14
Entrelacement (2)
byte x=2, y=3;
proctype A() { x = x + 1}
proctype B() {x = x – 1 ; y = y + x}
init {run A() ; run B()}
x=1y=3
x=2y=5
x=2y=3
init
x=3y=3
x=2y=3
x=1y=4
x=2y=4
x=x+1 x=x-1
y=y+x
x=x-1 x=x+1
x=x+1y=y+x
![Page 15: SPIN / PROMELA](https://reader033.vdocument.in/reader033/viewer/2022061616/56814664550346895db383d1/html5/thumbnails/15.jpg)
04/21/23 Master IRAD - SPIN / PROMELA 15
Instructions atomiques
• atomic {Instr1; Instr2 … ; Instrn}
• Activable si Instr1 est activable.
• Toutes les instructions sont effectuées en un seul pas : aucune autre instruction ne peut être effectuée entre les instructions de « atomic ».
• L’exécution est suspendue si une des instructions Instr2, …, Instrn est bloquante
-> Attention à bien s’assurer que ces instructions ne sont pas bloquantes !
![Page 16: SPIN / PROMELA](https://reader033.vdocument.in/reader033/viewer/2022061616/56814664550346895db383d1/html5/thumbnails/16.jpg)
04/21/23 Master IRAD - SPIN / PROMELA 16
Instructions atomiques
byte x=2, y=3;
proctype A() { x = x + 1}
proctype B() { atomic {x = x – 1 ; y = y + x}}
init {run A() ; run B()}
x=1y=3
x=2y=5
x=2y=3
init
x=3y=3
x=2y=3
x=1y=4
x=2y=4
x=x+1 x=x-1
y=y+x
x=x-1 x=x+1
x=x+1y=y+x
![Page 17: SPIN / PROMELA](https://reader033.vdocument.in/reader033/viewer/2022061616/56814664550346895db383d1/html5/thumbnails/17.jpg)
04/21/23 Master IRAD - SPIN / PROMELA 17
Instruction conditionnelle
• Syntaxe– if
:: instr11 -> instr12 ; … instr1N
:: …:: instrN1 -> instrN2 ; … ; instrNN
:: else -> instructions /* facultatif */fi
• Activable si une des gardes est activable• Si plusieurs gardes activables, choix non-déterministe• Si aucune garde activable et else présent, exécution des
instructions suivant else.
![Page 18: SPIN / PROMELA](https://reader033.vdocument.in/reader033/viewer/2022061616/56814664550346895db383d1/html5/thumbnails/18.jpg)
04/21/23 Master IRAD - SPIN / PROMELA 18
Boucles
• Syntaxe– do
:: instr11 -> instr12 ; … instr1N
:: …:: instrN1 -> instrN2 ; … ; instrNN
:: else -> instructions /* facultatif */od
• Pour sortir de la boucle, on peut utiliser une instruction break ou goto.
do :: …:: goto doneoddone : printf(…);
![Page 19: SPIN / PROMELA](https://reader033.vdocument.in/reader033/viewer/2022061616/56814664550346895db383d1/html5/thumbnails/19.jpg)
04/21/23 Master IRAD - SPIN / PROMELA 19
Canaux• Files d’attente (FIFO)• Déclaration :
– chan ch_bloc = [5] of {int}– chan ch_rdv = [0] of {int} : canal synchrone (un message ne peut être envoyé
que s’il est attendu)
• Envoi : ch_bloc!exprexpr est envoyé sur ch_bloc s’il reste de la place dans la file d’attente du canal. Instruction bloquante sinon.
• Réception : – ch_bloc?variable
variable reçoit pour valeur le premier message du canal. Si aucun message sur le canal, instruction bloquante.
– ch_bloc?constanteExécutable si le premier message du canal a une valeur égale à constante. Instruction bloquante sinon.
![Page 20: SPIN / PROMELA](https://reader033.vdocument.in/reader033/viewer/2022061616/56814664550346895db383d1/html5/thumbnails/20.jpg)
04/21/23 Master IRAD - SPIN / PROMELA 20
Canaux
• Messages de type « tuple »– chan ch = [5] of {bool, int}– Envoi : ch!exprB,exprI ou ch!exprB(exprI)– Réception : ch?varB,varI ou ch?varB(varI)
• Si oubli de paramètres, affectation non déterministe pour les paramètres manquants
• Les paramètres en trop sont perdus (sans avertissements !).
![Page 21: SPIN / PROMELA](https://reader033.vdocument.in/reader033/viewer/2022061616/56814664550346895db383d1/html5/thumbnails/21.jpg)
04/21/23 Master IRAD - SPIN / PROMELA 21
Canaux
• Quelques fonctions sur les canaux :
– len(ch_bloc) : retourne le nombre de messages contenus dans ch_bloc(peut s’utiliser dans une affectation),
– empty(ch_bloc) / nempty(ch_bloc) : permet de savoir si le canal ch_bloc est vide / non vide,
– full(ch_bloc) / nfull(ch_bloc) : permet de savoir si ch_bloc est rempli / non rempli.
![Page 22: SPIN / PROMELA](https://reader033.vdocument.in/reader033/viewer/2022061616/56814664550346895db383d1/html5/thumbnails/22.jpg)
04/21/23 Master IRAD - SPIN / PROMELA 22
Récursivité
• Utilisation des canaux
int final_res;
proctype factorielle (int n ; chan p) {
chan res = [1] of {int};
int tmp_res;
if
:: (n<=1) -> p!1;
:: (n>=2) ->
run factorielle (n-1, res);
res?tmp_res;
p!n*tmp_res
fi
}
init {
chan res = [1] of {int};
run factorielle (5,res);
res?final_res;
printf(« resultat : %d\n », final_res)
}