Skip to content

Commit 2d71171

Browse files
committed
Add tests for properties of excluded methods
The tests from the previous commit show that the right methods are excluded. The tests from this commit show that an excluded method has the right properties: meta-information such as parameter types and identifiers should be preserved, while the real method should not be loaded and a stub-like "return nondet" body should be used instead. The tests from this commit would not have passed without the fixes from this PR.
1 parent 875eed9 commit 2d71171

File tree

11 files changed

+86
-0
lines changed

11 files changed

+86
-0
lines changed
Binary file not shown.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import org.cprover.other.MyOther;
2+
import org.cprover.other.Parent;
3+
import org.cprover.other.Child;
4+
5+
public class ExcludedProperties {
6+
7+
public static void parameters() {
8+
int i = MyOther.identity(21);
9+
assert (i == 21);
10+
}
11+
12+
public static void compileTimeReturnType() {
13+
Parent p = MyOther.subclass();
14+
assert (p == null || p instanceof Parent);
15+
if (p == null) {
16+
assert false; // reachable with "return nondet" body
17+
} else {
18+
if (p.num() == 1) {
19+
assert false; // reachable with "return nondet" body
20+
} else {
21+
assert false; // reachable with "return nondet" body
22+
}
23+
}
24+
}
25+
26+
public static void runtimeReturnType() {
27+
Parent p = MyOther.subclass();
28+
assert (p == null || p instanceof Child);
29+
}
30+
}
Binary file not shown.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package org.cprover.other;
2+
3+
public class Child extends Parent {
4+
5+
public int num() { return 2; }
6+
}
Binary file not shown.

jbmc/regression/jbmc/context-include-exclude/org/cprover/other/MyOther.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@
33
public class MyOther {
44

55
public static int identity(int x) { return x; }
6+
7+
public static Parent subclass() { return new Child(); }
68
}
Binary file not shown.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package org.cprover.other;
2+
3+
public class Parent {
4+
5+
int field = 1;
6+
7+
public int num() { return field; }
8+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
CORE
2+
ExcludedProperties.class
3+
--context-exclude org.cprover.other --function ExcludedProperties.runtimeReturnType
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
.* line 28 assertion at file ExcludedProperties.java line 28.*: FAILURE
7+
--
8+
--
9+
Test that for an excluded method, we do not convert its "real" body from the
10+
bytecode.
11+
We instead assign it a "return nondet" body as for stubbed methods, which is
12+
tested by test_excluded_has_nondet_body.desc.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
CORE
2+
ExcludedProperties.class
3+
--context-exclude org.cprover.other --function ExcludedProperties.compileTimeReturnType
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
.* line 14 assertion at file ExcludedProperties.java line 14 .*: SUCCESS
7+
.* line 16 assertion at file ExcludedProperties.java line 16 .*: FAILURE
8+
.* line 19 assertion at file ExcludedProperties.java line 19 .*: FAILURE
9+
.* line 21 assertion at file ExcludedProperties.java line 21 .*: FAILURE
10+
--
11+
--
12+
Test that for an excluded method, we keep the information about the
13+
(compile-time) return type of the method and return a nondet object of that
14+
type, or null.
15+
Note that we do this in the same way as for stubbed methods.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
CORE
2+
ExcludedProperties.class
3+
--context-exclude org.cprover.other --show-symbol-table --function ExcludedProperties.parameters
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
java::org\.cprover\.other\.MyOther\.identity:\(I\)I::arg0i
7+
--
8+
java::org\.cprover\.other\.MyOther\.identity:\(I\)I::stub
9+
--
10+
Test that for an excluded method, we still create a symbol for its parameter(s)
11+
just like for non-excluded methods.
12+
Only the body of excluded methods should be missing, not their signature or
13+
other "meta-information".

0 commit comments

Comments
 (0)