Skip to content

Commit 7efa7bf

Browse files
committed
JBMC: Regression tests for multi-threaded java programs
1 parent 4d91aa5 commit 7efa7bf

Some content is hidden

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

64 files changed

+778
-8
lines changed
Binary file not shown.
Binary file not shown.
Binary file not shown.
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+
}
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 `../../../../scripts/format_classpath.sh . ../../../src/java_bytecode/library/core-models.jar` --java-threading
4+
^VERIFICATION SUCCESSFUL$
5+
^EXIT=0$
6+
^SIGNAL=0$
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 `../../../../scripts/format_classpath.sh . ../../../src/java_bytecode/library/core-models.jar`
4+
^SIGNAL=0$
5+
^VERIFICATION FAILED$
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
CORE
22
A.class
3-
--function "A.me:()V" --lazy-methods --java-threading
4-
3+
--function 'A.me:()V' --lazy-methods --java-threading
54
^EXIT=0$
65
^SIGNAL=0$
76
^VERIFICATION SUCCESSFUL
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
4+
^SIGNAL=0$
5+
^VERIFICATION FAILED

jbmc/regression/jbmc-concurrency/explicit_thread_blocks/test2.desc

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

0 commit comments

Comments
 (0)