Skip to content

Commit c757390

Browse files
authored
Adding test files for old permission semantics (#838)
1 parent fb86777 commit c757390

File tree

6 files changed

+359
-0
lines changed

6 files changed

+359
-0
lines changed
+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Any copyright is dedicated to the Public Domain.
2+
// http://creativecommons.org/publicdomain/zero/1.0/
3+
4+
5+
field f: Int
6+
field g: Int
7+
8+
predicate P(x: Ref) {
9+
acc(x.f)
10+
}
11+
12+
function foo(x: Ref): Int
13+
requires acc(x.f)
14+
15+
function foow(x: Ref): Int
16+
requires acc(x.f, wildcard)
17+
18+
function foop(x: Ref): Int
19+
requires P(x)
20+
21+
method caller_foo(x: Ref, y: Ref)
22+
{
23+
inhale acc(x.f) && acc(y.f, 1/2)
24+
var f1 : Int
25+
f1 := foo(x)
26+
//:: ExpectedOutput(application.precondition:insufficient.permission)
27+
f1 := foo(y)
28+
}
29+
30+
method caller_foop(x: Ref, y: Ref)
31+
{
32+
inhale P(x) && acc(P(y), 1/2)
33+
var f1 : Int
34+
f1 := foop(x)
35+
//:: ExpectedOutput(application.precondition:insufficient.permission)
36+
f1 := foop(y)
37+
}
38+
39+
method caller_foow(x: Ref, y: Ref)
40+
{
41+
inhale acc(x.f, 1/2)
42+
var f1 : Int
43+
f1 := foow(x)
44+
//:: ExpectedOutput(application.precondition:insufficient.permission)
45+
f1 := foow(y)
46+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
// Any copyright is dedicated to the Public Domain.
2+
// http://creativecommons.org/publicdomain/zero/1.0/
3+
4+
5+
field f: Int
6+
field g: Int
7+
8+
predicate P(x: Ref) {
9+
acc(x.f)
10+
}
11+
12+
function double(x: Ref): Int
13+
requires acc(x.f) && acc(x.f)
14+
ensures false
15+
{ 4 }
16+
17+
function double2(x: Ref, y: Ref): Int
18+
requires acc(x.f) && acc(y.f)
19+
ensures x != y
20+
{ 4 }
21+
22+
function takesFull(x: Ref): Int
23+
requires acc(x.f)
24+
{ 4 }
25+
26+
function takesFull2(x: Ref): Int
27+
requires acc(x.f)
28+
{ takesFull(x) }
29+
30+
function takesHalf(x: Ref): Int
31+
requires acc(x.f, 1/2)
32+
//:: ExpectedOutput(application.precondition:insufficient.permission)
33+
{ takesFull(x)}
34+
35+
//:: ExpectedOutput(function.not.wellformed:insufficient.permission)
36+
function pred(x: Ref): Int
37+
requires acc(P(x), 1/2)
38+
{
39+
unfolding P(x) in x.f
40+
}
41+
42+
function pred2(x: Ref): Int
43+
requires acc(P(x), 1/2)
44+
{
45+
unfolding acc(P(x), 1/2) in x.f
46+
}
47+
48+
function pred3(x: Ref): Int
49+
requires acc(P(x), 1/2)
50+
{
51+
unfolding acc(P(x), wildcard) in x.f
52+
}
53+
54+
function pred4(x: Ref): Int
55+
requires acc(P(x), wildcard)
56+
{
57+
unfolding acc(P(x), wildcard) in (unfolding acc(P(x), wildcard) in x.f)
58+
}
59+
60+
//:: ExpectedOutput(function.not.wellformed:insufficient.permission)
61+
function pred5(x: Ref): Int
62+
requires acc(P(x), none)
63+
{
64+
unfolding acc(P(x), wildcard) in x.f
65+
}
66+
67+
//:: ExpectedOutput(function.not.wellformed:insufficient.permission)
68+
function pred6(x: Ref): Int
69+
requires acc(P(x), 1/2)
70+
{
71+
unfolding acc(P(x), 1/2) in (unfolding acc(P(x), 1/2) in x.f)
72+
}
73+
74+
function pred7(x: Ref): Int
75+
requires acc(P(x), write)
76+
{
77+
unfolding acc(P(x), 1/2) in (unfolding acc(P(x), 1/2) in x.f)
78+
}
+116
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
// Any copyright is dedicated to the Public Domain.
2+
// http://creativecommons.org/publicdomain/zero/1.0/
3+
4+
5+
predicate P(r: Ref) {forall e : Ref :: e in refs(r) ==> acc(Q(e), wildcard)}
6+
predicate P2(r: Ref) {forall e : Ref :: e in refs(r) ==> acc(Q(e), 1/2)}
7+
predicate R(r: Ref) {forall e : Ref :: e in refs(r) ==> acc(e.q, wildcard)}
8+
predicate R2(r: Ref) {forall e : Ref :: e in refs(r) ==> acc(e.q, 1/2)}
9+
predicate Q(r: Ref)
10+
11+
field q: Ref
12+
13+
function refs(r: Ref) : Set[Ref]
14+
15+
function get(r: Ref): Ref
16+
ensures result in refs(r)
17+
18+
function tester(r: Ref): Ref
19+
requires acc(Q(r), wildcard)
20+
21+
function testerFull(r: Ref): Ref
22+
requires acc(Q(r), write)
23+
24+
function testerfield(r: Ref): Ref
25+
requires acc(r.q, wildcard)
26+
27+
function testerfieldFull(r: Ref): Ref
28+
requires acc(r.q, write)
29+
30+
method pred1(r: Ref)
31+
requires acc(P(r), wildcard)
32+
{
33+
unfold acc(P(r), wildcard)
34+
fold acc(P(r), wildcard)
35+
unfold acc(P(r), wildcard)
36+
var r2 : Ref := tester(get(r))
37+
//:: ExpectedOutput(application.precondition:insufficient.permission)
38+
var r3 : Ref := testerFull(get(r))
39+
}
40+
41+
method pred2(r: Ref)
42+
requires acc(P(r), write)
43+
{
44+
unfold acc(P(r))
45+
fold acc(P(r))
46+
unfold acc(P(r))
47+
var r2 : Ref := tester(get(r))
48+
//:: ExpectedOutput(application.precondition:insufficient.permission)
49+
var r3 : Ref := testerFull(get(r))
50+
}
51+
52+
method pred3(r: Ref)
53+
requires acc(P(r), write)
54+
{
55+
unfold acc(P(r), 1/2)
56+
fold acc(P(r), 1/2)
57+
unfold acc(P(r), 1/2)
58+
var r2 : Ref := tester(get(r))
59+
//:: ExpectedOutput(application.precondition:insufficient.permission)
60+
var r3 : Ref := testerFull(get(r))
61+
}
62+
63+
method pred4(r: Ref)
64+
requires acc(P2(r), write)
65+
{
66+
unfold acc(P2(r), wildcard)
67+
fold acc(P2(r), wildcard)
68+
unfold acc(P2(r), wildcard)
69+
var r2 : Ref := tester(get(r))
70+
//:: ExpectedOutput(application.precondition:insufficient.permission)
71+
var r3 : Ref := testerFull(get(r))
72+
}
73+
74+
method func1(r: Ref)
75+
requires acc(R(r), wildcard)
76+
{
77+
unfold acc(R(r), wildcard)
78+
fold acc(R(r), wildcard)
79+
unfold acc(R(r), wildcard)
80+
var r2 : Ref := testerfield(get(r))
81+
//:: ExpectedOutput(application.precondition:insufficient.permission)
82+
var r3 : Ref := testerfieldFull(get(r))
83+
}
84+
85+
method func2(r: Ref)
86+
requires acc(R(r), write)
87+
{
88+
unfold acc(R(r))
89+
fold acc(R(r))
90+
unfold acc(R(r))
91+
var r2 : Ref := testerfield(get(r))
92+
//:: ExpectedOutput(application.precondition:insufficient.permission)
93+
var r3 : Ref := testerfieldFull(get(r))
94+
}
95+
96+
method func3(r: Ref)
97+
requires acc(R(r), write)
98+
{
99+
unfold acc(R(r), 1/2)
100+
fold acc(R(r), 1/2)
101+
unfold acc(R(r), 1/2)
102+
var r2 : Ref := testerfield(get(r))
103+
//:: ExpectedOutput(application.precondition:insufficient.permission)
104+
var r3 : Ref := testerfieldFull(get(r))
105+
}
106+
107+
method func4(r: Ref)
108+
requires acc(R2(r), write)
109+
{
110+
unfold acc(R2(r), wildcard)
111+
fold acc(R2(r), wildcard)
112+
unfold acc(R2(r), wildcard)
113+
var r2 : Ref := testerfield(get(r))
114+
//:: ExpectedOutput(application.precondition:insufficient.permission)
115+
var r3 : Ref := testerfieldFull(get(r))
116+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// Any copyright is dedicated to the Public Domain.
2+
// http://creativecommons.org/publicdomain/zero/1.0/
3+
4+
field next: Ref
5+
field data: Int
6+
7+
predicate list(this: Ref) {
8+
acc(this.next)
9+
&& acc(this.data)
10+
&& (this.next != null ==>
11+
acc(list(this.next))
12+
&& unfolding list(this.next) in this.data <= this.next.data)
13+
}
14+
method test01(this: Ref)
15+
requires acc(list(this))
16+
{
17+
unfold acc(list(this), 1/2)
18+
/* Unexpectedly fails:
19+
* Unfolding list(this) might fail.
20+
* There might be insufficient permission to access list(this.next)
21+
*/
22+
}
23+
function foo(this: Ref): Bool
24+
requires acc(list(this))
25+
{ true }
26+
predicate bla(this: Ref) {
27+
acc(list(this))
28+
&& foo(this)
29+
}
30+
method test02(this: Ref)
31+
requires acc(bla(this), 1/2)
32+
{
33+
unfold acc(bla(this), 1/2)
34+
}
35+
method test03(this: Ref)
36+
requires acc(list(this), 1/2)
37+
{
38+
fold acc(bla(this), 1/2)
39+
}
40+
method test04a(this: Ref)
41+
requires acc(bla(this), 1/2)
42+
{
43+
assert unfolding acc(bla(this), 1/2) in true
44+
}
45+
method test04b(this: Ref)
46+
requires acc(bla(this), 1/2)
47+
{
48+
//:: ExpectedOutput(application.precondition:insufficient.permission)
49+
assert unfolding acc(bla(this), 1/2) in foo(this)
50+
}
51+
52+
predicate blabla(this: Ref) { bla(this) }
53+
method test05(this: Ref)
54+
requires blabla(this)
55+
{
56+
assert unfolding acc(blabla(this), 1/3) in unfolding acc(bla(this), 1/5) in true
57+
}
58+
function foo_qp(xs: Set[Ref]): Bool
59+
requires forall x: Ref :: x in xs ==> acc(x.data)
60+
{ true }
61+
predicate bla_qp(xs: Set[Ref]) {
62+
(forall x: Ref :: x in xs ==> acc(x.data))
63+
&& foo_qp(xs)
64+
}
65+
method test02_qp(xs: Set[Ref])
66+
requires acc(bla_qp(xs), 1/2)
67+
{
68+
unfold acc(bla_qp(xs), 1/2)
69+
}
70+
method test03_qp(xs: Set[Ref])
71+
requires forall x: Ref :: x in xs ==> acc(x.data, 1/2)
72+
{
73+
fold acc(bla_qp(xs), 1/2)
74+
}
75+
method test04a_qp(xs: Set[Ref])
76+
requires acc(bla_qp(xs), 1/2)
77+
{
78+
assert unfolding acc(bla_qp(xs), 1/2) in true
79+
}
80+
81+
method test04b_qp(xs: Set[Ref])
82+
requires acc(bla_qp(xs), 1/2)
83+
{
84+
//:: ExpectedOutput(application.precondition:insufficient.permission)
85+
assert unfolding acc(bla_qp(xs), 1/2) in foo_qp(xs)
86+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Any copyright is dedicated to the Public Domain.
2+
// http://creativecommons.org/publicdomain/zero/1.0/
3+
4+
5+
field f: Int
6+
field g: Int
7+
8+
function test1(x: Ref): Bool
9+
decreases
10+
requires acc(x.f) && acc(x.g)
11+
{
12+
//:: ExpectedOutput(termination.failed:termination.condition.false)
13+
nonTerminating(x)
14+
}
15+
16+
function test2(x: Ref): Bool
17+
decreases
18+
requires acc(x.f) && acc(x.f) && acc(x.g)
19+
{
20+
nonTerminating(x)
21+
}
22+
23+
function nonTerminating(x: Ref): Bool
24+
decreases *
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Any copyright is dedicated to the Public Domain.
2+
// http://creativecommons.org/publicdomain/zero/1.0/
3+
4+
5+
field f: Int
6+
7+
function foo2w(x: Ref, b: Bool): Int
8+
//:: ExpectedOutput(consistency.error)
9+
requires acc(x.f, b ? wildcard : none)

0 commit comments

Comments
 (0)