|
| 1 | +enable_experimental; |
| 2 | +c <- java_load_class "Test"; |
| 3 | + |
| 4 | +//////////////////////////////////////////////////////////////////////////////// |
| 5 | +// Specs with missing side effects |
| 6 | + |
| 7 | +print "Verification fails for add1 spec with missing side effect."; |
| 8 | +fails ( |
| 9 | + jvm_verify c "add1" [] false |
| 10 | + do { |
| 11 | + this <- jvm_alloc_object "Test"; |
| 12 | + x <- jvm_fresh_var "x" java_int; |
| 13 | + y <- jvm_fresh_var "y" java_int; |
| 14 | + jvm_execute_func [this, jvm_term x, jvm_term y]; |
| 15 | + jvm_return (jvm_term {{ x + y }}); |
| 16 | + } z3 |
| 17 | + ); |
| 18 | + |
| 19 | +print "Verification fails for add2 spec with missing side effect."; |
| 20 | +fails ( |
| 21 | + jvm_verify c "add2" [] false |
| 22 | + do { |
| 23 | + this <- jvm_alloc_object "Test"; |
| 24 | + x <- jvm_fresh_var "x" java_int; |
| 25 | + y <- jvm_fresh_var "y" java_int; |
| 26 | + jvm_execute_func [this, jvm_term x, jvm_term y]; |
| 27 | + jvm_return (jvm_term {{ x + y }}); |
| 28 | + } z3 |
| 29 | + ); |
| 30 | + |
| 31 | +print "Verification fails for add3 spec with missing side effect."; |
| 32 | +fails ( |
| 33 | + jvm_verify c "add3" [] false |
| 34 | + do { |
| 35 | + this <- jvm_alloc_object "Test"; |
| 36 | + arr <- jvm_alloc_array 2 java_int; |
| 37 | + jvm_field_is this "c" arr; |
| 38 | + x <- jvm_fresh_var "x" java_int; |
| 39 | + y <- jvm_fresh_var "y" java_int; |
| 40 | + jvm_execute_func [this, jvm_term x, jvm_term y]; |
| 41 | + jvm_return (jvm_term {{ x + y }}); |
| 42 | + } z3 |
| 43 | + ); |
| 44 | + |
| 45 | +//////////////////////////////////////////////////////////////////////////////// |
| 46 | +// Full specifications with side effects |
| 47 | + |
| 48 | +let spec1 = |
| 49 | + do { |
| 50 | + this <- jvm_alloc_object "Test"; |
| 51 | + x <- jvm_fresh_var "x" java_int; |
| 52 | + y <- jvm_fresh_var "y" java_int; |
| 53 | + jvm_execute_func [this, jvm_term x, jvm_term y]; |
| 54 | + jvm_field_is this "a" (jvm_term x); |
| 55 | + jvm_return (jvm_term {{ x + y }}); |
| 56 | + }; |
| 57 | + |
| 58 | +let spec2 = |
| 59 | + do { |
| 60 | + this <- jvm_alloc_object "Test"; |
| 61 | + x <- jvm_fresh_var "x" java_int; |
| 62 | + y <- jvm_fresh_var "y" java_int; |
| 63 | + jvm_execute_func [this, jvm_term x, jvm_term y]; |
| 64 | + jvm_static_field_is "b" (jvm_term x); |
| 65 | + jvm_return (jvm_term {{ x + y }}); |
| 66 | + }; |
| 67 | + |
| 68 | +let spec3 = |
| 69 | + do { |
| 70 | + this <- jvm_alloc_object "Test"; |
| 71 | + arr <- jvm_alloc_array 2 java_int; |
| 72 | + jvm_field_is this "c" arr; |
| 73 | + x <- jvm_fresh_var "x" java_int; |
| 74 | + y <- jvm_fresh_var "y" java_int; |
| 75 | + jvm_execute_func [this, jvm_term x, jvm_term y]; |
| 76 | + jvm_elem_is arr 1 (jvm_term x); |
| 77 | + jvm_return (jvm_term {{ x + y }}); |
| 78 | + }; |
| 79 | + |
| 80 | +print "Verification succeeds for complete add1 spec."; |
| 81 | +add1_full <- jvm_verify c "add1" [] false spec1 z3; |
| 82 | + |
| 83 | +print "Verification succeeds for complete add2 spec."; |
| 84 | +add2_full <- jvm_verify c "add2" [] false spec2 z3; |
| 85 | + |
| 86 | +print "Verification succeeds for complete add3 spec."; |
| 87 | +add3_full <- jvm_verify c "add3" [] false spec3 z3; |
| 88 | + |
| 89 | +//////////////////////////////////////////////////////////////////////////////// |
| 90 | +// Partial specifications with jvm_modifies |
| 91 | + |
| 92 | +print "Verification succeeds for partial add1 spec (jvm_modifies_field)."; |
| 93 | +add1_part <- |
| 94 | + jvm_verify c "add1" [] false |
| 95 | + do { |
| 96 | + this <- jvm_alloc_object "Test"; |
| 97 | + x <- jvm_fresh_var "x" java_int; |
| 98 | + y <- jvm_fresh_var "y" java_int; |
| 99 | + jvm_execute_func [this, jvm_term x, jvm_term y]; |
| 100 | + jvm_modifies_field this "a"; |
| 101 | + jvm_return (jvm_term {{ x + y }}); |
| 102 | + } z3; |
| 103 | + |
| 104 | +print "Verification succeeds for partial add2 spec (jvm_modifies_static_field)."; |
| 105 | +add2_part <- |
| 106 | + jvm_verify c "add2" [] false |
| 107 | + do { |
| 108 | + this <- jvm_alloc_object "Test"; |
| 109 | + x <- jvm_fresh_var "x" java_int; |
| 110 | + y <- jvm_fresh_var "y" java_int; |
| 111 | + jvm_execute_func [this, jvm_term x, jvm_term y]; |
| 112 | + jvm_modifies_static_field "b"; |
| 113 | + jvm_return (jvm_term {{ x + y }}); |
| 114 | + } z3; |
| 115 | + |
| 116 | +print "Verification succeeds for partial add3 spec (jvm_modifies_elem)."; |
| 117 | +add3_part <- |
| 118 | + jvm_verify c "add3" [] false |
| 119 | + do { |
| 120 | + this <- jvm_alloc_object "Test"; |
| 121 | + arr <- jvm_alloc_array 2 java_int; |
| 122 | + jvm_field_is this "c" arr; |
| 123 | + x <- jvm_fresh_var "x" java_int; |
| 124 | + y <- jvm_fresh_var "y" java_int; |
| 125 | + jvm_execute_func [this, jvm_term x, jvm_term y]; |
| 126 | + jvm_modifies_elem arr 1; |
| 127 | + jvm_return (jvm_term {{ x + y }}); |
| 128 | + } z3; |
| 129 | + |
| 130 | +print "Verification succeeds for partial add3 spec (jvm_modifies_array)."; |
| 131 | +add3_part_a <- |
| 132 | + jvm_verify c "add3" [] false |
| 133 | + do { |
| 134 | + this <- jvm_alloc_object "Test"; |
| 135 | + arr <- jvm_alloc_array 2 java_int; |
| 136 | + jvm_field_is this "c" arr; |
| 137 | + x <- jvm_fresh_var "x" java_int; |
| 138 | + y <- jvm_fresh_var "y" java_int; |
| 139 | + jvm_execute_func [this, jvm_term x, jvm_term y]; |
| 140 | + jvm_modifies_array arr; |
| 141 | + jvm_return (jvm_term {{ x + y }}); |
| 142 | + } z3; |
| 143 | + |
| 144 | +//////////////////////////////////////////////////////////////////////////////// |
| 145 | +// Compositional verification with full specs |
| 146 | + |
| 147 | +print "Compositional verification succeeds with full add1 spec."; |
| 148 | +wrap1_full <- jvm_verify c "wrap1" [add1_full] false spec1 z3; |
| 149 | + |
| 150 | +print "Compositional verification succeeds with full add1 spec."; |
| 151 | +wrap2_full <- jvm_verify c "wrap2" [add2_full] false spec2 z3; |
| 152 | + |
| 153 | +print "Compositional verification succeeds with full add1 spec."; |
| 154 | +wrap3_full <- jvm_verify c "wrap3" [add3_full] false spec3 z3; |
| 155 | + |
| 156 | +//////////////////////////////////////////////////////////////////////////////// |
| 157 | +// Compositional verification with partial specs |
| 158 | + |
| 159 | +// TODO: Improve misleading "Ill-formed value for type int" error message. |
| 160 | + |
| 161 | +print "Compositional verification fails with partial add1 spec."; |
| 162 | +fails (jvm_verify c "wrap1" [add1_part] false spec1 z3); |
| 163 | + |
| 164 | +print "Compositional verification fails with partial add2 spec."; |
| 165 | +fails (jvm_verify c "wrap2" [add2_part] false spec2 z3); |
| 166 | + |
| 167 | +print "Compositional verification fails with partial add3 spec."; |
| 168 | +fails (jvm_verify c "wrap3" [add3_part] false spec3 z3); |
| 169 | + |
| 170 | +print "DONE!"; |
0 commit comments