|
| 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 | +} |
0 commit comments