Skip to content

Commit 0aa1beb

Browse files
committed
JBMC: Regression tests for multi-threaded java programs
1 parent f3b47ea commit 0aa1beb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+778
-0
lines changed
Binary file not shown.
Binary file not shown.
Binary file not shown.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import java.lang.Thread;
2+
import org.cprover.CProver;
3+
4+
public class A
5+
{
6+
int x = 0;
7+
8+
// expected verfication success
9+
public void me()
10+
{
11+
Thread t = new Thread()
12+
{
13+
public void run()
14+
{
15+
x = 44;
16+
int local_x = x;
17+
assert(local_x == 44 || x == 10);
18+
}
19+
};
20+
t.start();
21+
x = 10;
22+
}
23+
24+
// expected verfication failure
25+
public void me2()
26+
{
27+
Thread t = new Thread()
28+
{
29+
public void run()
30+
{
31+
x = 44;
32+
int local_x = x;
33+
assert(local_x == 44);
34+
}
35+
};
36+
t.start();
37+
x = 10;
38+
}
39+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CORE
2+
A.class
3+
--function "A.me:()V" --lazy-methods --cp ../../../src/java_bytecode/library/core-models.jar:. --java-threading
4+
^VERIFICATION SUCCESSFUL$
5+
^EXIT=0$
6+
^SIGNAL=0$
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
CORE
2+
A.class
3+
--function "A.me2:()V" --lazy-methods --java-threading --cp ../../../src/java_bytecode/library/core-models.jar:.
4+
^SIGNAL=0$
5+
^VERIFICATION FAILED$
Binary file not shown.
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
import java.lang.Thread;
2+
import org.cprover.CProver;
3+
4+
public class A
5+
{
6+
public static int g;
7+
8+
// expected verification success
9+
public void me()
10+
{
11+
int g = CProver.getCurrentThreadID();
12+
assert(g == 0);
13+
}
14+
15+
// expected verification success
16+
// --
17+
// KNOWNBUG
18+
public void me_bug()
19+
{
20+
CProver.startThread(333);
21+
int g = 1;
22+
assert(g == 1);
23+
CProver.endThread(333);
24+
}
25+
26+
// expected verification success
27+
// --
28+
// KNOWNBUG: see me_bug()
29+
public void me2()
30+
{
31+
CProver.startThread(333);
32+
g = CProver.getCurrentThreadID();
33+
assert(g == 1);
34+
CProver.endThread(333);
35+
}
36+
37+
// expected verification success
38+
// --
39+
// KNOWNBUG: see me_bug()
40+
public void me3()
41+
{
42+
CProver.startThread(333);
43+
int i = CProver.getCurrentThreadID();
44+
assert(g == 1);
45+
CProver.endThread(333);
46+
}
47+
48+
// expected verification success.
49+
public void me4()
50+
{
51+
CProver.startThread(333);
52+
check();
53+
CProver.endThread(333);
54+
}
55+
56+
// expected verification success.
57+
public void me5()
58+
{
59+
me();
60+
B b = new B();
61+
Thread tmp = new Thread(b);
62+
tmp.start();
63+
}
64+
65+
// expected verification success.
66+
public void me6()
67+
{
68+
me();
69+
C c = new C();
70+
c.start();
71+
}
72+
73+
public void check()
74+
{
75+
g = CProver.getCurrentThreadID();
76+
assert(g == 1);
77+
}
78+
}
79+
80+
class B implements Runnable
81+
{
82+
public static int g;
83+
@Override
84+
public void run()
85+
{
86+
g = CProver.getCurrentThreadID();
87+
assert(g == 1);
88+
}
89+
}
90+
91+
92+
class C extends Thread
93+
{
94+
public static int g;
95+
@Override
96+
public void run()
97+
{
98+
g = CProver.getCurrentThreadID();
99+
assert(g == 1);
100+
}
101+
}
Binary file not shown.
Binary file not shown.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CORE
2+
A.class
3+
--function "A.me:()V" --java-threading --cp ../../../src/java_bytecode/library/core-models.jar:.
4+
5+
^EXIT=0$
6+
^SIGNAL=0$
7+
^VERIFICATION SUCCESSFUL
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
KNOWNBUG
2+
A.class
3+
--function "A.me2:()V" --java-threading --cp ../../../src/java_bytecode/library/core-models.jar:.
4+
5+
^EXIT=0$
6+
^SIGNAL=0$
7+
^VERIFICATION SUCCESSFUL
8+
--
9+
--
10+
Same bug as the one highlighted in 'test_bug.desc'
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
KNOWNBUG
2+
A.class
3+
--function "A.me3:()V" --java-threading --cp ../../../src/java_bytecode/library/core-models.jar:.
4+
5+
^EXIT=0$
6+
^SIGNAL=0$
7+
^VERIFICATION SUCCESSFUL
8+
--
9+
--
10+
Same bug as the one highlighted in 'test_bug.desc'
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CORE
2+
A.class
3+
--function "A.me4:()V" --java-threading --cp ../../../src/java_bytecode/library/core-models.jar:.
4+
5+
^EXIT=0$
6+
^SIGNAL=0$
7+
^VERIFICATION SUCCESSFUL
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CORE
2+
A.class
3+
--function "A.me5:()V" --java-threading --cp ../../../src/java_bytecode/library/core-models.jar:.
4+
5+
^EXIT=0$
6+
^SIGNAL=0$
7+
^VERIFICATION SUCCESSFUL
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CORE
2+
A.class
3+
--function "A.me6:()V" --java-threading --cp ../../../src/java_bytecode/library/core-models.jar:.
4+
5+
^EXIT=0$
6+
^SIGNAL=0$
7+
^VERIFICATION SUCCESSFUL
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
KNOWNBUG
2+
A.class
3+
--function "A.me_bug:()V" --java-threading --cp ../../../src/java_bytecode/library/core-models.jar:.
4+
5+
^EXIT=0$
6+
^SIGNAL=0$
7+
^VERIFICATION SUCCESSFUL
8+
--
9+
--
10+
For some reason symex assigns 'g' to zero, even though it
11+
the only viable assignment should be one.
12+
This issue seems to only occur when a variable is
13+
assigned inside the local scope of a thread-block.
14+
15+
If instead, we call a function from inside the thread-block and
16+
then assign 'g' to 1 then as expected the only viable
17+
assignment to 'g' is 1 (see test4.desc)
18+
19+
Seems related to: https://github.com/diffblue/cbmc/issues/1630/
Binary file not shown.
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
// JBMC, concurrency tests that make use of
2+
// the java.lang.Runnable model
3+
4+
import java.lang.Thread;
5+
import org.cprover.CProver;
6+
7+
public class A
8+
{
9+
// calling start from outside.
10+
// expected verfication success.
11+
public void me3()
12+
{
13+
C c = new C();
14+
Thread tmp = new Thread(c);
15+
tmp.start();
16+
c.setX();
17+
}
18+
19+
// calling start from outside, no race-condition on B.x
20+
// expected verfication success.
21+
public void me4()
22+
{
23+
B b = new B();
24+
Thread tmp = new Thread(b);
25+
tmp.start();
26+
}
27+
28+
// expected verfication failed
29+
public void me2()
30+
{
31+
B b = new B();
32+
b.me();
33+
}
34+
35+
// expected verfication success.
36+
public void me()
37+
{
38+
C c = new C();
39+
c.me();
40+
}
41+
}
42+
43+
class B implements Runnable
44+
{
45+
int x = 0;
46+
47+
@Override
48+
public void run()
49+
{
50+
x = 44;
51+
int local_x = x;
52+
assert(local_x == 44);
53+
}
54+
55+
public void me()
56+
{
57+
Thread tmp = new Thread(this);
58+
tmp.start();
59+
x = 10;
60+
}
61+
}
62+
63+
64+
class C implements Runnable
65+
{
66+
int x = 0;
67+
68+
@Override
69+
public void run()
70+
{
71+
x = 44;
72+
int local_x = x;
73+
assert(local_x == 44 || x == 10);
74+
}
75+
76+
public void me()
77+
{
78+
Thread tmp = new Thread(this);
79+
tmp.start();
80+
setX();
81+
}
82+
83+
public void setX()
84+
{
85+
x = 10;
86+
}
87+
}
Binary file not shown.
Binary file not shown.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CORE
2+
A.class
3+
--function "A.me:()V" --lazy-methods --cp ../../../src/java_bytecode/library/core-models.jar:. --java-threading
4+
5+
^EXIT=0$
6+
^SIGNAL=0$
7+
^VERIFICATION SUCCESSFUL
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CORE
2+
A.class
3+
--function "A.me2:()V" --lazy-methods --cp ../../../src/java_bytecode/library/core-models.jar:. --java-threading
4+
5+
^SIGNAL=0$
6+
^VERIFICATION FAILED
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CORE
2+
A.class
3+
--function "A.me4:()V" --lazy-methods --cp ../../../src/java_bytecode/library/core-models.jar:. --java-threading
4+
5+
^EXIT=0$
6+
^SIGNAL=0$
7+
^VERIFICATION SUCCESSFUL
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CORE
2+
A.class
3+
--function "A.me3:()V" --lazy-methods --cp ../../../src/java_bytecode/library/core-models.jar:. --java-threading
4+
5+
^EXIT=0$
6+
^SIGNAL=0$
7+
^VERIFICATION SUCCESSFUL
Binary file not shown.

0 commit comments

Comments
 (0)