1050
|
1 |
(* Title: HOL/IOA/ABP/Check.ML
|
|
2 |
ID: $Id$
|
|
3 |
Author: Tobias Nipkow & Olaf Mueller
|
|
4 |
Copyright 1995 TU Muenchen
|
|
5 |
|
|
6 |
Simple ModelChecker prototype checking Spec against
|
|
7 |
the finite version of the ABP-protocol.
|
|
8 |
*)
|
|
9 |
|
|
10 |
|
|
11 |
(* model checker function prototype *)
|
|
12 |
|
|
13 |
fun check(extacts,intacts,string_of_a,startsI,string_of_s,
|
|
14 |
nexts,hom,transA,startsS) =
|
|
15 |
let fun check_s(s,unchecked,checked) =
|
|
16 |
let fun check_sa(unchecked,a) =
|
|
17 |
let fun check_sas(unchecked,t) =
|
|
18 |
(if a mem extacts then
|
|
19 |
(if transA(hom s,a,hom t) then ()
|
|
20 |
else (writeln("Error: Mapping of Externals!");
|
|
21 |
string_of_s s; writeln"";
|
|
22 |
string_of_a a; writeln"";
|
|
23 |
string_of_s t;writeln"";writeln""))
|
|
24 |
else (if hom(s)=hom(t) then ()
|
|
25 |
else (writeln("Error: Mapping of Internals!");
|
|
26 |
string_of_s s;writeln"";
|
|
27 |
string_of_a a;writeln"";
|
|
28 |
string_of_s t;writeln"";writeln""));
|
|
29 |
if t mem checked then unchecked else t ins unchecked)
|
|
30 |
in foldl check_sas (unchecked,nexts s a) end;
|
|
31 |
val unchecked' = foldl check_sa (unchecked,extacts @ intacts)
|
|
32 |
in (if s mem startsI then
|
|
33 |
(if hom(s) mem startsS then ()
|
|
34 |
else writeln("Error: At start states!"))
|
|
35 |
else ();
|
|
36 |
checks(unchecked',s::checked)) end
|
|
37 |
and checks([],_) = ()
|
|
38 |
| checks(s::unchecked,checked) = check_s(s,unchecked,checked)
|
|
39 |
in checks(startsI,[]) end;
|
|
40 |
|
|
41 |
|
|
42 |
(* datatypes for ABP example *)
|
|
43 |
|
|
44 |
datatype msg = m;
|
|
45 |
datatype act = Next | S_msg of msg | R_msg of msg
|
|
46 |
| S_pkt of bool * msg | R_pkt of bool * msg
|
|
47 |
| S_ack of bool | R_ack of bool;
|
|
48 |
|
|
49 |
fun transA((u,s),a,(v,t)) =
|
|
50 |
(case a of
|
|
51 |
Next => v andalso t = s |
|
|
52 |
S_msg(m) => u andalso not(v) andalso t = s@[m] |
|
|
53 |
R_msg(m) => u = v andalso s = (m::t) |
|
|
54 |
S_pkt(b,m) => false |
|
|
55 |
R_pkt(b,m) => false |
|
|
56 |
S_ack(b) => false |
|
|
57 |
R_ack(b) => false);
|
|
58 |
|
|
59 |
fun hom((env,p,a,q,b,_,_)) = (env,q@(if (a=b) then tl(p) else p));
|
|
60 |
|
|
61 |
fun nexts (s as (env,p,a,q,b,ch1,ch2)) action =
|
|
62 |
(case action of
|
|
63 |
Next => if p=[] then [(true,p,a,q,b,ch1,ch2)] else [] |
|
|
64 |
S_msg(m) => if env then [(false,p@[m],a,q,b,ch1,ch2)] else [] |
|
|
65 |
R_msg(m) => if (q<>[] andalso m=hd(q))
|
|
66 |
then [(env,p,a,tl(q),b,ch1,ch2)]
|
|
67 |
else [] |
|
|
68 |
S_pkt(h,m) => if (p<>[] andalso m=hd(p) andalso h=a)
|
|
69 |
then (if (ch1<>[] andalso hd(rev(ch1))=(h,m))
|
|
70 |
then [s]
|
|
71 |
else [s,(env,p,a,q,b,ch1@[(h,m)],ch2)])
|
|
72 |
else [] |
|
|
73 |
R_pkt(h,m) => if (ch1<>[] andalso hd(ch1)=(h,m))
|
|
74 |
then (if (h<>b andalso q=[])
|
|
75 |
then [(env,p,a,q@[m],not(b),ch1,ch2),
|
|
76 |
(env,p,a,q@[m],not(b),tl(ch1),ch2)]
|
|
77 |
else [s,(env,p,a,q,b,tl(ch1),ch2)])
|
|
78 |
else [] |
|
|
79 |
S_ack(h) => if (h=b)
|
|
80 |
then (if (ch2<>[] andalso h=hd(rev(ch2)))
|
|
81 |
then [s]
|
|
82 |
else [s,(env,p,a,q,b,ch1,ch2@[h])])
|
|
83 |
else [] |
|
|
84 |
R_ack(h) => if (ch2<>[] andalso hd(ch2)=h)
|
|
85 |
then (if h=a
|
|
86 |
then [(env,tl(p),not(a),q,b,ch1,ch2),
|
|
87 |
(env,tl(p),not(a),q,b,ch1,tl(ch2))]
|
|
88 |
else [s,(env,p,a,q,b,ch1,tl(ch2))])
|
|
89 |
else [])
|
|
90 |
|
|
91 |
|
|
92 |
val extactions = [Next,S_msg(m),R_msg(m)];
|
|
93 |
val intactions = [S_pkt(true,m),R_pkt(true,m),S_ack(true),R_ack(true),
|
|
94 |
S_pkt(false,m),R_pkt(false,m),S_ack(false),R_ack(false)];
|
|
95 |
|
|
96 |
|
|
97 |
(* Input / Output auxiliary functions *)
|
|
98 |
|
|
99 |
fun print_list (lpar, rpar, pre: 'a -> unit) (l : 'a list) =
|
|
100 |
let fun prec x = (prs ","; pre x)
|
|
101 |
in
|
|
102 |
(case l of
|
|
103 |
[] => (prs lpar; prs rpar)
|
|
104 |
| x::l => (prs lpar; pre x; seq prec l; prs rpar))
|
|
105 |
end;
|
|
106 |
|
|
107 |
fun pr_bool true = output(std_out,"true")
|
|
108 |
| pr_bool false = output(std_out,"false");
|
|
109 |
|
|
110 |
fun pr_msg m = output(std_out,"m");
|
|
111 |
|
|
112 |
fun pr_act a = output(std_out, case a of
|
|
113 |
Next => "Next"|
|
|
114 |
S_msg(m) => "S_msg(m)" |
|
|
115 |
R_msg(m) => "R_msg(m)" |
|
|
116 |
S_pkt(b,m) => "S_pkt(b,m)" |
|
|
117 |
R_pkt(b,m) => "R_pkt(b,m)" |
|
|
118 |
S_ack(b) => "S_ack(b)" |
|
|
119 |
R_ack(b) => "R_ack(b)");
|
|
120 |
|
|
121 |
fun pr_pkt (b,m) = (prs "<"; pr_bool b;prs ", "; pr_msg m; prs ">");
|
|
122 |
|
|
123 |
val pr_bool_list = print_list("[","]",pr_bool);
|
|
124 |
val pr_msg_list = print_list("[","]",pr_msg);
|
|
125 |
val pr_pkt_list = print_list("[","]",pr_pkt);
|
|
126 |
|
|
127 |
fun pr_tuple (env,p,a,q,b,ch1,ch2) =
|
|
128 |
(prs "{"; pr_bool env; prs ", "; pr_msg_list p; prs ", ";
|
|
129 |
pr_bool a; prs ", "; pr_msg_list q; prs ", ";
|
|
130 |
pr_bool b; prs ", "; pr_pkt_list ch1; prs ", ";
|
|
131 |
pr_bool_list ch2; prs "}");
|
|
132 |
|
|
133 |
(* ----------------------------*)
|
|
134 |
(* main check function call *)
|
|
135 |
(* ----------------------------*)
|
|
136 |
|
|
137 |
check(extactions,intactions,pr_act, [(true,[],true,[],false,[],[])],
|
|
138 |
pr_tuple, nexts, hom, transA, [(true,[])]);
|
|
139 |
|
|
140 |
|