ltlfilt.test 10.8 KB
Newer Older
1
#! /bin/sh
2
# -*- coding: utf-8 -*-
3
# Copyright (C) 2013-2020 Laboratoire de Recherche et Développement de
4
# l'Epita (LRDE).
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
#
# This file is part of Spot, a model checking library.
#
# Spot is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# Spot is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
# License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.


# Check several options of ltlfilt

. ./defs || exit 1

set -e

checkopt()
{
  cat >exp
31
  run 0 ltlfilt "$@" formulas > out
32
  diff -u exp out
33
34
}

35
36
# The empty lines in the file are meant, we want to make sure that
# they are ignored.
37
cat >formulas <<EOF
38
39
GFa | FGb /* comment to ignore */
F(GFa | /* tricky /* comment */)*/ Gb)
40

41
42
43
44
F(b W GFa)
GFa | Gb
b W GFa
!{a;b*;c}!
45
!{a:b[*/*ignore me*/]:c/*ignore this comment*/}
46
47
48
49
50
a U Fb
G(a & Xb)
Xa
F(a & !Xa & Xb)
{a & {b|c} }
Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
51
52
((a && b) U (! (X 1)))
((a && b) U (! (X[!] 1)))
53
54
55
56
57
58
59
60
61
62

{a[=2:3]}|->b
{a[->2:3]}|->b
{a[->1];a*}|->b  /* becomes {(!a)*;a[+]}|->b */
{a*;(!a)*;a*}|->b
{a*;(!a)[+];a*}|->b
{a[+];(!a)*;a*}|->b
{a*;(!a)*;a[+]}|->b
{a*;(!a)[+];a[+]}|->b
{a*;(!c)[+];a[+]}|->b
63
{a* ##0 b*}|->c
64
65
EOF

Maximilien Colange's avatar
Maximilien Colange committed
66
67
checkopt --boolean <<EOF
a & (b | c)
Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
68
0
Maximilien Colange's avatar
Maximilien Colange committed
69
70
71
72
73
74
75
76
77
78
79
80
EOF

checkopt --bsize-min=2 --bsize-max=4 <<EOF
a U Fb
Xa
EOF

checkopt --size-min=2 --size-max=4 <<EOF
a U Fb
Xa
EOF

81
82
83
84
85
86
checkopt --eventual <<EOF
GFa | FGb
F(GFa | Gb)
F(b W GFa)
a U Fb
F(a & !Xa & Xb)
Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
87
88
0
(a & b) U !X[!]1
89
90
91
92
93
94
95
EOF

checkopt --universal <<EOF
GFa | FGb
F(GFa | Gb)
GFa | Gb
G(a & Xb)
Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
96
0
97
98
99
100
101
EOF

checkopt --eventual --universal <<EOF
GFa | FGb
F(GFa | Gb)
Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
102
0
103
104
EOF

105
106
107
checkopt --suspendable <<EOF
GFa | FGb
F(GFa | Gb)
Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
108
0
109
110
EOF

111
112
113
114
115
116
checkopt --stutter-invariant <<EOF
GFa | FGb
F(GFa | Gb)
F(b W GFa)
GFa | Gb
b W GFa
117
!{a:b[*]:c}
118
119
120
a U Fb
F(a & !Xa & Xb)
a & (b | c)
Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
121
122
0
(a & b) U !X[!]1
123
124
125
126
127
128
{{!a}[*];a[+]}[]-> b
{a[*];{!a}[*];a[*]}[]-> b
{a[*];{!a}[+];a[*]}[]-> b
{a[+];{!a}[*];a[*]}[]-> b
{a[*];{!a}[*];a[+]}[]-> b
{a[*];{!a}[+];a[+]}[]-> b
129
{a[*]:b[*]}[]-> c
130
131
EOF

132
checkopt -c --stutter-invariant <<EOF
Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
133
18
134
135
136
137
138
139
140
141
142
143
EOF

checkopt --syntactic-stutter-invariant <<EOF
GFa | FGb
F(GFa | Gb)
F(b W GFa)
GFa | Gb
b W GFa
a U Fb
a & (b | c)
Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
144
0
145
{{!a}[*];a[+]}[]-> b
Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
146
{a[*];{!a}[*];a[*]}[]-> b
147
148
149
{a[*];{!a}[+];a[*]}[]-> b
{a[+];{!a}[*];a[*]}[]-> b
{a[*];{!a}[*];a[+]}[]-> b
150
{a[*]:b[*]}[]-> c
151
152
EOF

153
154
155
156
157
158
159
checkopt --simplify <<EOF
F(GFa | Gb)
F(GFa | Gb)
F(b W GFa)
GFa | Gb
b W GFa
!a | X(!b R !c)
160
!{a:b[*]:c}
161
162
163
Fb
G(a & Xb)
Xa
164
F(a & X(!a & b))
165
a & (b | c)
Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
166
167
0
0
168
169
170
171
172
173
174
175
176
a R (!a | X({a[->1..2]}[]-> (b & X(b W a))))
a R (!a | X({a[->1..2]}[]-> b))
a R (b W !a)
{a[*];{!a}[*];a[*]}[]-> b
!a R ((b & X(b W !a)) W a)
(b & X((b W !a) & ((b & X(b W !a)) W a))) W !a
!a R (a R (b W !a))
!a R (a | X(a R (b W !a)))
!a R (c | X(c R (b W !a)))
177
(c W !b) W !a
178
179
180
181
182
183
EOF

checkopt --simplify --eventual --unique <<EOF
F(GFa | Gb)
F(b W GFa)
Fb
184
F(a & X(!a & b))
Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
185
0
186
187
EOF

188
189
190
191
192
193
194
195
196
197
checkopt --liveness <<EOF
GFa | FGb
F(GFa | Gb)
F(b W GFa)
GFa | Gb
b W GFa
a U Fb
F(a & !Xa & Xb)
EOF

198
199
200
201
202
checkopt --safety <<EOF
!({a;b[*];c}!)
G(a & Xb)
Xa
a & (b | c)
Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
203
204
0
(a & b) U !X[!]1
205
206
207
208
209
210
211
212
213
{a[=2..3]}[]-> b
{a[->2..3]}[]-> b
{{!a}[*];a[+]}[]-> b
{a[*];{!a}[*];a[*]}[]-> b
{a[*];{!a}[+];a[*]}[]-> b
{a[+];{!a}[*];a[*]}[]-> b
{a[*];{!a}[*];a[+]}[]-> b
{a[*];{!a}[+];a[+]}[]-> b
{a[*];{!c}[+];a[+]}[]-> b
214
{a[*]:b[*]}[]-> c
215
216
217
218
EOF

checkopt --obligation <<EOF
!({a;b[*];c}!)
219
!{a:b[*]:c}
220
221
222
223
224
a U Fb
G(a & Xb)
Xa
F(a & !Xa & Xb)
a & (b | c)
Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
225
226
0
(a & b) U !X[!]1
227
228
229
230
231
232
233
234
235
{a[=2..3]}[]-> b
{a[->2..3]}[]-> b
{{!a}[*];a[+]}[]-> b
{a[*];{!a}[*];a[*]}[]-> b
{a[*];{!a}[+];a[*]}[]-> b
{a[+];{!a}[*];a[*]}[]-> b
{a[*];{!a}[*];a[+]}[]-> b
{a[*];{!a}[+];a[+]}[]-> b
{a[*];{!c}[+];a[+]}[]-> b
236
{a[*]:b[*]}[]-> c
237
238
239
EOF

checkopt --guarantee <<EOF
240
!{a:b[*]:c}
241
242
243
244
a U Fb
Xa
F(a & !Xa & Xb)
a & (b | c)
Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
245
246
0
(a & b) U !X[!]1
247
248
249
250
EOF

checkopt -v --ltl <<EOF
!({a;b[*];c}!)
251
!{a:b[*]:c}
252
253
254
255
256
257
258
259
260
{a[=2..3]}[]-> b
{a[->2..3]}[]-> b
{{!a}[*];a[+]}[]-> b
{a[*];{!a}[*];a[*]}[]-> b
{a[*];{!a}[+];a[*]}[]-> b
{a[+];{!a}[*];a[*]}[]-> b
{a[*];{!a}[*];a[+]}[]-> b
{a[*];{!a}[+];a[+]}[]-> b
{a[*];{!c}[+];a[+]}[]-> b
261
{a[*]:b[*]}[]-> c
262
263
EOF

264
265
266
267
268
269
270
271
272
273
checkopt -v --ap=3 <<EOF
GFa | FGb
F(GFa | Gb)
F(b W GFa)
GFa | Gb
b W GFa
a U Fb
G(a & Xb)
Xa
F(a & !Xa & Xb)
Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
274
275
0
(a & b) U !X[!]1
276
277
278
279
280
281
282
283
{a[=2..3]}[]-> b
{a[->2..3]}[]-> b
{{!a}[*];a[+]}[]-> b
{a[*];{!a}[*];a[*]}[]-> b
{a[*];{!a}[+];a[*]}[]-> b
{a[+];{!a}[*];a[*]}[]-> b
{a[*];{!a}[*];a[+]}[]-> b
{a[*];{!a}[+];a[+]}[]-> b
284
285
286
287
288
289
290
291
292
293
294
295
296
297
EOF

checkopt --ap=2..3 <<EOF
GFa | FGb
F(GFa | Gb)
F(b W GFa)
GFa | Gb
b W GFa
!({a;b[*];c}!)
!{a:b[*]:c}
a U Fb
G(a & Xb)
F(a & !Xa & Xb)
a & (b | c)
Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
298
(a & b) U !X[!]1
299
300
301
302
303
304
305
306
307
{a[=2..3]}[]-> b
{a[->2..3]}[]-> b
{{!a}[*];a[+]}[]-> b
{a[*];{!a}[*];a[*]}[]-> b
{a[*];{!a}[+];a[*]}[]-> b
{a[+];{!a}[*];a[*]}[]-> b
{a[*];{!a}[*];a[+]}[]-> b
{a[*];{!a}[+];a[+]}[]-> b
{a[*];{!c}[+];a[+]}[]-> b
308
{a[*]:b[*]}[]-> c
309
310
EOF

311
312
313
314
checkopt -v --stutter-invariant <<EOF
!({a;b[*];c}!)
G(a & Xb)
Xa
315
316
317
{a[=2..3]}[]-> b
{a[->2..3]}[]-> b
{a[*];{!c}[+];a[+]}[]-> b
318
319
320
321
322
323
324
EOF

checkopt --equivalent-to 'GFa | FGb' <<EOF
GFa | FGb
F(GFa | Gb)
F(b W GFa)
EOF
325

326
327
328
329
330
331
332
checkopt --ltl --from-ltlf=al <<EOF
al & (G(!al | F(a & al)) | F(al & G(!al | b))) & (al U G!al)
al & F(al & (G(!al | F(a & al)) | G(!al | b))) & (al U G!al)
al & F(al & ((!al | b) W G(!al | F(a & al)))) & (al U G!al)
al & (G(!al | F(a & al)) | G(!al | b)) & (al U G!al)
al & ((!al | b) W G(!al | F(a & al))) & (al U G!al)
al & (a U (al & F(al & b))) & (al U G!al)
Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
333
334
335
al & G(!al | (a & X(!al | b))) & (al U G!al)
al & X(a | !al) & (al U G!al)
al & F(a & al & !X(a | !al) & X(!al | b)) & (al U G!al)
336
a & al & (b | c) & (al U G!al)
Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
337
0
338
al & ((a & b) U (al & !Xal)) & (al U G!al)
339
340
341
EOF

checkopt --ltl --from-ltlf='!dead' <<EOF
342
343
344
345
346
347
!dead & (G(dead | F(a & !dead)) | F(!dead & G(b | dead))) & (!dead U Gdead)
!dead & F(!dead & (G(dead | F(a & !dead)) | G(b | dead))) & (!dead U Gdead)
!dead & F(!dead & ((b | dead) W G(dead | F(a & !dead)))) & (!dead U Gdead)
!dead & (G(dead | F(a & !dead)) | G(b | dead)) & (!dead U Gdead)
!dead & ((b | dead) W G(dead | F(a & !dead))) & (!dead U Gdead)
!dead & (a U (!dead & F(b & !dead))) & (!dead U Gdead)
Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
348
349
350
!dead & G(dead | (a & X(b | dead))) & (!dead U Gdead)
!dead & X(a | dead) & (!dead U Gdead)
!dead & F(a & !dead & !X(a | dead) & X(b | dead)) & (!dead U Gdead)
351
a & !dead & (b | c) & (!dead U Gdead)
Alexandre Duret-Lutz's avatar
Alexandre Duret-Lutz committed
352
0
353
!dead & ((a & b) U (!dead & !X!dead)) & (!dead U Gdead)
354
EOF
355
356
357
358
359
360
361
362

cat >in <<EOF
a & Xb & c
a & b & GF(a | c) & FG(a | c)
b & GF(a | c) & FG(a | c)
G(d & e) | FG(Xf| !c) | h | i
b & !Xc & e & (f | g)
b & GF(a | c) & !GF!(a | c)
363
F(a <-> b) -> (c xor d)
364
365
366
367
368
369
370
EOF

cat >exp <<EOF
p0 & Xp1
p0 & p1 & GF(p0 | p2) & FG(p0 | p2)
p0 & GFp1 & FGp1
p0 | Gp1 | FG(p2 | Xp3)
371
p0 | Gp1
372
373
EOF

374
run 0 ltlfilt -u --nnf --relabel-bool=pnn in >out
375
diff exp out
376

377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
cat >exp <<EOF
#define p0 (a && c)
#define p1 (b)
p0 && Xp1
#define p0 (a)
#define p1 (b)
#define p2 (c)
p0 && p1 && []<>(p0 || p2) && <>[](p0 || p2)
#define p0 (b)
#define p1 (a || c)
p0 && []<>p1 && <>[]p1
#define p0 (h || i)
#define p1 (d && e)
#define p2 (!c)
#define p3 (f)
p0 || []p1 || <>[](p2 || Xp3)
393
394
395
#define p0 ((c && !d) || (!c && d))
#define p1 ((a && !b) || (!a && b))
p0 || []p1
396
397
EOF

398
run 0 ltlfilt -s -u --nnf --relabel-bool=pnn --define in >out
399
400
diff exp out

401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
cat >exp <<EOF
#define p0 (a)
#define p1 (c)
#define p2 (b)
p0 && p1 && Xp2
#define p0 (a)
#define p1 (b)
#define p2 (c)
p0 && p1 && []<>(p0 || p2) && <>[](p0 || p2)
#define p0 (b)
#define p1 (a)
#define p2 (c)
p0 && []<>(p1 || p2) && <>[](p1 || p2)
#define p0 (h)
#define p1 (i)
#define p2 (d)
#define p3 (e)
#define p4 (c)
#define p5 (f)
p0 || p1 || [](p2 && p3) || <>[](!p4 || Xp5)
#define p0 (b)
#define p1 (e)
#define p2 (f)
#define p3 (g)
#define p4 (c)
p0 && p1 && (p2 || p3) && !Xp4
#define p0 (b)
#define p1 (a)
#define p2 (c)
p0 && []<>(p1 || p2) && ![]<>!(p1 || p2)
#define p0 (a)
#define p1 (b)
#define p2 (c)
#define p3 (d)
<>(p0 <-> p1) -> !(p2 <-> p3)
EOF

438
run 0 ltlfilt -s -u --relabel=pnn --define in >out
439
440
441
diff exp out

toolong='((p2=0) * (p3=1))' # work around the 80-col check
442
cat >exp <<EOF
443
444
445
#define p0 (a=1)
#define p1 (c=1)
#define p2 (b=1)
446
(p0=1) * (p1=1) * (X(p2=1))
447
448
449
#define p0 (a=1)
#define p1 (b=1)
#define p2 (c=1)
450
(p0=1) * (p1=1) * (G(F((p0=1) + (p2=1)))) * (F(G((p0=1) + (p2=1))))
451
452
453
#define p0 (b=1)
#define p1 (a=1)
#define p2 (c=1)
454
(p0=1) * (G(F((p1=1) + (p2=1)))) * (F(G((p1=1) + (p2=1))))
455
456
457
458
459
460
#define p0 (h=1)
#define p1 (i=1)
#define p2 (d=1)
#define p3 (e=1)
#define p4 (c=1)
#define p5 (f=1)
461
(p0=1) + (p1=1) + (G((p2=1) * (p3=1))) + (F(G((p4=0) + (X(p5=1)))))
462
463
464
465
466
#define p0 (b=1)
#define p1 (e=1)
#define p2 (f=1)
#define p3 (g=1)
#define p4 (c=1)
467
(p0=1) * (p1=1) * ((p2=1) + (p3=1)) * (X(p4=0))
468
469
470
471
#define p0 (c=1)
#define p1 (d=1)
#define p2 (a=1)
#define p3 (b=1)
472
((p0=1) * (p1=0)) + ((p0=0) * (p1=1)) + (G(((p2=1) * (p3=0)) + $toolong))
473
EOF
474
run 0 ltlfilt -p --wring -u --nnf --relabel=pnn --define in >out
475
476
diff exp out

477
run 0 ltlfilt -0 in > out
478
$PERL -i -pe 's/\0/@\n/g' out
479
480
481
482
483
484
485
cat >exp <<EOF
a & c & Xb@
a & b & GF(a | c) & FG(a | c)@
b & GF(a | c) & FG(a | c)@
h | i | G(d & e) | FG(!c | Xf)@
b & e & (f | g) & !Xc@
b & GF(a | c) & !GF!(a | c)@
486
F(a <-> b) -> (c xor d)@
487
EOF
488
489
diff exp out

490
SPOT_STUTTER_CHECK=0 \
491
ltlfilt --stutter-invariant -f '!{a:b*:c}' 2> stderr && exit 1
492
493
494
495
test $? = 2
grep 'non-LTL' stderr

SPOT_STUTTER_CHECK=555 \
496
ltlfilt --stutter-invariant -f '!{a:b*:c}' 2> stderr && exit 1
497
498
499
500
test $? = 2
grep 'invalid' stderr

SPOT_STUTTER_CHECK=5 \
501
ltlfilt --stutter-invariant -f '!{a:b*:c}'
502
503
504

# This one was incorrectly diagnosed as stutter invariant because of a
# bug in the bitvectors.
505
ltlfilt --stutter-invariant -f 'F(a & XXXXXX!a)' && exit 1
506

Maximilien Colange's avatar
Maximilien Colange committed
507
508
509
ltlfilt --syntactic-stutter-invariant -f 'GFa <-> GFb'
ltlfilt --syntactic-stutter-invariant -f 'GXa <-> GFb' && exit 1

510

511
ltlfilt -c -o 'foo' -f a 2>stderr && exit 1
512
513
grep 'ltlfilt: options --output and --count are incompatible' stderr

514
out=`ltlfilt -f 'G(a xor b) -> F(c <-> Xd)' --unabbreviate='^iF'`
515
516
517
exp='(1 U (c <-> Xd)) | !G!(a <-> b)'
test "$out" = "$exp"

518
ltlfilt -f 'GF"a\"\\b"' > out
519
520
test "`cat out`" = 'GF"a\"\\b"'

521
ltlfilt --lbt-input -f 'G F "a\"\\b"' -l > out
522
523
test "`cat out`" = 'G F "a\"\\b"'

524

525
ltlfilt --size=foo=2..3  2>stderr && exit 1
526
527
grep 'invalid range.*should start with' stderr

528
529
530
531
532
533
534
535
536
537

cat >out <<EOF
test1,"""a b"" U c"
"""a b"" U c",test2
EOF
ltlfilt out/1 > out.1
ltlfilt out/2 > out.2
diff out out.1
diff out out.2

538
539
540
541
542
test a = `ltlfilt -r2 -f a`
ltlfilt -r4 -f a 2>err && exit 1
grep "invalid simplification level '4'" err
ltlfilt -ra -f a 2>err && exit 1
grep "invalid simplification level 'a'" err
Maximilien Colange's avatar
Maximilien Colange committed
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559

ltlfilt --ignore-errors -f 'F' > out 2> out && exit 1
test $? = 1
cat >exp <<EOF
EOF
diff out exp

run 2 ltlfilt --drop-errors -f 'F' > out
cat >exp <<EOF
EOF
diff out exp

run 2 ltlfilt --skip-errors -f 'F' > out
cat >exp <<EOF
F
EOF
diff out exp
560
561
562
563
564

f1=`genltl --pps-arbiter-standard=2`
f2=`genltl --pps-arbiter-strict=2`
run 1 ltlfilt -f "$f2" --implied-by "$f1"
run 0 ltlfilt -f "$f1" --implied-by "$f2"