-
Notifications
You must be signed in to change notification settings - Fork 21
/
SpecTE.tla
350 lines (304 loc) · 9.73 KB
/
SpecTE.tla
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
@!@!@STARTMSG 1000:0 @!@!@
Will generate a SpecTE file pair if error states are encountered.
@!@!@ENDMSG 1000 @!@!@
@!@!@STARTMSG 2262:0 @!@!@
TLC2 Version 2.15 of Day Month 20?? (rev: 2a12f60)
@!@!@ENDMSG 2262 @!@!@
@!@!@STARTMSG 2187:0 @!@!@
Running breadth-first search Model-Checking with fp 21 and seed 647230902156660305 with 1 worker on 4 cores with 5301MB heap and 64MB offheap memory (Linux 4.18.0-16-generic amd64, Oracle Corporation 1.8.0_201 x86_64, MSBDiskFPSet, DiskStateQueue).
@!@!@ENDMSG 2187 @!@!@
@!@!@STARTMSG 2220:0 @!@!@
Starting SANY...
@!@!@ENDMSG 2220 @!@!@
Parsing file /home/markus/src/TLA/_specs/models/tutorials/BlockingQueueTLA/BlockingQueue.tla
Parsing file /tmp/Naturals.tla
Parsing file /tmp/Sequences.tla
Parsing file /tmp/FiniteSets.tla
Parsing file /tmp/TLC.tla
Semantic processing of module Naturals
Semantic processing of module Sequences
Semantic processing of module FiniteSets
Semantic processing of module TLC
Semantic processing of module BlockingQueue
@!@!@STARTMSG 2219:0 @!@!@
SANY finished.
@!@!@ENDMSG 2219 @!@!@
@!@!@STARTMSG 2185:0 @!@!@
Starting... (2020-01-16 22:25:03)
@!@!@ENDMSG 2185 @!@!@
@!@!@STARTMSG 2189:0 @!@!@
Computing initial states...
@!@!@ENDMSG 2189 @!@!@
@!@!@STARTMSG 2269:0 @!@!@
Computed 2 initial states...
@!@!@ENDMSG 2269 @!@!@
@!@!@STARTMSG 2190:0 @!@!@
Finished computing initial states: 3 distinct states generated at 2020-01-16 22:25:03.
@!@!@ENDMSG 2190 @!@!@
@!@!@STARTMSG 2110:1 @!@!@
Invariant Invariant is violated.
@!@!@ENDMSG 2110 @!@!@
@!@!@STARTMSG 2121:1 @!@!@
The behavior up to this point is:
@!@!@ENDMSG 2121 @!@!@
@!@!@STARTMSG 2217:4 @!@!@
1: <Initial predicate>
/\ buffer = <<>>
/\ waitSet = {}
/\ thread = p1
@!@!@ENDMSG 2217 @!@!@
@!@!@STARTMSG 2217:4 @!@!@
2: <Next line 58, col 12 to line 63, col 31 of module BlockingQueue>
/\ buffer = <<F>>
/\ waitSet = {}
/\ thread = p1
@!@!@ENDMSG 2217 @!@!@
@!@!@STARTMSG 2217:4 @!@!@
3: <Next line 58, col 12 to line 63, col 31 of module BlockingQueue>
/\ buffer = <<F>>
/\ waitSet = {p1}
/\ thread = p2
@!@!@ENDMSG 2217 @!@!@
@!@!@STARTMSG 2217:4 @!@!@
4: <Next line 58, col 12 to line 63, col 31 of module BlockingQueue>
/\ buffer = <<F>>
/\ waitSet = {p1, p2}
/\ thread = c1
@!@!@ENDMSG 2217 @!@!@
@!@!@STARTMSG 2217:4 @!@!@
5: <Next line 58, col 12 to line 63, col 31 of module BlockingQueue>
/\ buffer = <<>>
/\ waitSet = {p2}
/\ thread = c1
@!@!@ENDMSG 2217 @!@!@
@!@!@STARTMSG 2217:4 @!@!@
6: <Next line 58, col 12 to line 63, col 31 of module BlockingQueue>
/\ buffer = <<>>
/\ waitSet = {p2, c1}
/\ thread = p1
@!@!@ENDMSG 2217 @!@!@
@!@!@STARTMSG 2217:4 @!@!@
7: <Next line 58, col 12 to line 63, col 31 of module BlockingQueue>
/\ buffer = <<N>>
/\ waitSet = {c1}
/\ thread = p1
@!@!@ENDMSG 2217 @!@!@
@!@!@STARTMSG 2217:4 @!@!@
8: <Next line 58, col 12 to line 63, col 31 of module BlockingQueue>
/\ buffer = <<N>>
/\ waitSet = {p1, c1}
/\ thread = p2
@!@!@ENDMSG 2217 @!@!@
@!@!@STARTMSG 2217:4 @!@!@
9: <Next line 58, col 12 to line 63, col 31 of module BlockingQueue>
/\ buffer = <<N>>
/\ waitSet = {p1, p2, c1}
/\ thread = p1
@!@!@ENDMSG 2217 @!@!@
@!@!@STARTMSG 2200:0 @!@!@
Progress(9) at 2020-01-16 22:25:03: 235 states generated (28,200 s/min), 106 distinct states found (12,720 ds/min), 13 states left on queue.
@!@!@ENDMSG 2200 @!@!@
@!@!@STARTMSG 2199:0 @!@!@
235 states generated, 106 distinct states found, 13 states left on queue.
@!@!@ENDMSG 2199 @!@!@
@!@!@STARTMSG 2194:0 @!@!@
The depth of the complete state graph search is 9.
@!@!@ENDMSG 2194 @!@!@
@!@!@STARTMSG 2268:0 @!@!@
The average outdegree of the complete state graph is 1 (minimum is 0, the maximum 6 and the 95th percentile is 3).
@!@!@ENDMSG 2268 @!@!@
@!@!@STARTMSG 1000:0 @!@!@
The model check run produced error-states - we will generate the SpecTE files now.
@!@!@ENDMSG 1000 @!@!@
@!@!@STARTMSG 1000:0 @!@!@
The file /home/markus/src/TLA/_specs/models/tutorials/BlockingQueueTLA/SpecTE.tla has been created.
@!@!@ENDMSG 1000 @!@!@
@!@!@STARTMSG 1000:0 @!@!@
The file /home/markus/src/TLA/_specs/models/tutorials/BlockingQueueTLA/SpecTE.cfg has been created.
@!@!@ENDMSG 1000 @!@!@
@!@!@STARTMSG 2186:0 @!@!@
Finished in 542ms at (2020-01-16 22:25:03)
@!@!@ENDMSG 2186 @!@!@
--------------------------- MODULE SpecTE ----
EXTENDS Sequences, Toolbox, TLC, Naturals, FiniteSets
\*
\* SpecTE follows
\*
CONSTANTS Producers, (* the (nonempty) set of producers *)
Consumers, (* the (nonempty) set of consumers *)
BufCapacity, (* the maximum number of messages in the bounded buffer *)
Data
ASSUME Assumption ==
/\ Producers # {} (* at least one producer *)
/\ Consumers # {} (* at least one consumer *)
/\ Producers \intersect Consumers = {} (* no thread is both consumer and producer *)
/\ BufCapacity \in (Nat \ {0}) (* buffer capacity is at least 1 *)
-----------------------------------------------------------------------------
VARIABLES buffer, waitSet, thread
vars == <<buffer, waitSet, thread>>
RunningThreads == (Producers \cup Consumers) \ waitSet
(* @see java.lang.Object#notify *)
Notify == IF waitSet # {}
THEN \E x \in waitSet: waitSet' = waitSet \ {x}
ELSE UNCHANGED waitSet
(* @see java.lang.Object#wait *)
Wait(t) == /\ waitSet' = waitSet \cup {t}
/\ UNCHANGED <<buffer>>
-----------------------------------------------------------------------------
Put(t, d) ==
\/ /\ Len(buffer) < BufCapacity
/\ buffer' = Append(buffer, d)
/\ Notify
\/ /\ Len(buffer) = BufCapacity
/\ Wait(t)
Get(t) ==
\/ /\ buffer # <<>>
/\ buffer' = Tail(buffer)
/\ Notify
\/ /\ buffer = <<>>
/\ Wait(t)
-----------------------------------------------------------------------------
(* Initially, the buffer is empty and no thread is waiting. *)
Init == /\ buffer = <<>>
/\ waitSet = {}
/\ thread \in (Producers \cup Consumers)
(* Then, pick a thread out of all running threads and have it do its thing. *)
\* Next rewritten to predict the value of a prophecy variable
\* http://lamport.azurewebsites.net/pubs/auxiliary.pdf
\* (https://github.com/lorin/tla-prophecy)
Next == \/ /\ thread \notin waitSet \* Pred_A(i)
/\ thread' \in (Producers \cup Consumers) \* Setp
/\ \/ /\ thread \in Producers \* A
/\ Put(thread, RandomElement(Data)) \* Add some data to buffer
\/ /\ thread \in Consumers
/\ Get(thread)
\/ /\ thread \in waitSet
/\ UNCHANGED vars
-----------------------------------------------------------------------------
(* TLA+ is untyped, thus lets verify the range of some values in each state. *)
TypeInv == /\ buffer \in Seq(Data)
/\ Len(buffer) \in 0..BufCapacity
/\ waitSet \subseteq (Producers \cup Consumers)
(* No Deadlock *)
Invariant == waitSet # (Producers \cup Consumers)
CONSTANTS p1, A, p2, B, C, D, E, F, G, H, I, J, K, L, M, c1, N, O, P, Q, R, S, T
\* TRACE Sub-Action definition 0
Next_sa_0 ==
(
/\ buffer = (<<>>)
/\ waitSet = ({})
/\ thread = (p1)
/\ buffer' = (<<F>>)
/\ waitSet' = ({})
/\ thread' = (p1)
)
\* TRACE Sub-Action definition 1
Next_sa_1 ==
(
/\ buffer = (<<F>>)
/\ waitSet = ({})
/\ thread = (p1)
/\ buffer' = (<<F>>)
/\ waitSet' = ({p1})
/\ thread' = (p2)
)
\* TRACE Sub-Action definition 2
Next_sa_2 ==
(
/\ buffer = (<<F>>)
/\ waitSet = ({p1})
/\ thread = (p2)
/\ buffer' = (<<F>>)
/\ waitSet' = ({p1, p2})
/\ thread' = (c1)
)
\* TRACE Sub-Action definition 3
Next_sa_3 ==
(
/\ buffer = (<<F>>)
/\ waitSet = ({p1, p2})
/\ thread = (c1)
/\ buffer' = (<<>>)
/\ waitSet' = ({p2})
/\ thread' = (c1)
)
\* TRACE Sub-Action definition 4
Next_sa_4 ==
(
/\ buffer = (<<>>)
/\ waitSet = ({p2})
/\ thread = (c1)
/\ buffer' = (<<>>)
/\ waitSet' = ({p2, c1})
/\ thread' = (p1)
)
\* TRACE Sub-Action definition 5
Next_sa_5 ==
(
/\ buffer = (<<>>)
/\ waitSet = ({p2, c1})
/\ thread = (p1)
/\ buffer' = (<<N>>)
/\ waitSet' = ({c1})
/\ thread' = (p1)
)
\* TRACE Sub-Action definition 6
Next_sa_6 ==
(
/\ buffer = (<<N>>)
/\ waitSet = ({c1})
/\ thread = (p1)
/\ buffer' = (<<N>>)
/\ waitSet' = ({p1, c1})
/\ thread' = (p2)
)
\* TRACE Action Constraint definition traceExploreActionConstraint
_SpecTEActionConstraint ==
<<
Next_sa_0,
Next_sa_1,
Next_sa_2,
Next_sa_3,
Next_sa_4,
Next_sa_5,
Next_sa_6
>>[TLCGet("level")]
----
def_ov_15792423033492000 ==
<<
([buffer |-> <<>>,waitSet |-> {},thread |-> p1]),
([buffer |-> <<F>>,waitSet |-> {},thread |-> p1]),
([buffer |-> <<F>>,waitSet |-> {p1},thread |-> p2]),
([buffer |-> <<F>>,waitSet |-> {p1, p2},thread |-> c1]),
([buffer |-> <<>>,waitSet |-> {p2},thread |-> c1]),
([buffer |-> <<>>,waitSet |-> {p2, c1},thread |-> p1]),
([buffer |-> <<N>>,waitSet |-> {c1},thread |-> p1]),
([buffer |-> <<N>>,waitSet |-> {p1, c1},thread |-> p2])
>>
----
INSTANCE BlockingQueueAnim
VARIABLE TraceExp
\* TRACE INIT definition traceExploreInit
_SpecTEInit ==
/\ buffer = (
<<>>
)
/\ waitSet = (
{}
)
/\ thread = (
p1
)
/\ TraceExp = Animation
----
\* TRACE NEXT definition traceExploreNext
_SpecTENext ==
/\ \/ Next_sa_0
\/ Next_sa_1
\/ Next_sa_2
\/ Next_sa_3
\/ Next_sa_4
\/ Next_sa_5
\/ Next_sa_6
/\ TraceExp' = Animation
=============================================================================