forked from diffblue/cbmc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
One of this test is an exhaustive comparison with the result of a reference implementation.
- Loading branch information
1 parent
d599dfc
commit 0c56151
Showing
6 changed files
with
104 additions
and
3 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Must be compiled with CProverString: | ||
// javac Test.java ../cprover/CProverString.java | ||
public class Test { | ||
|
||
// Reference implementation | ||
public static boolean referenceStartsWith(String s, String prefix, int offset) { | ||
if (offset < 0 || offset > s.length() - prefix.length()) { | ||
return false; | ||
} | ||
|
||
for (int i = 0; i < prefix.length(); i++) { | ||
if (org.cprover.CProverString.charAt(s, offset + i) | ||
!= org.cprover.CProverString.charAt(prefix, i)) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
public static boolean check(String s, String t, int offset) { | ||
// Filter out null strings | ||
if(s == null || t == null) { | ||
return false; | ||
} | ||
|
||
// Act | ||
final boolean result = s.startsWith(t, offset); | ||
|
||
// Assert | ||
final boolean referenceResult = referenceStartsWith(s, t, offset); | ||
assert(result == referenceResult); | ||
|
||
// Check reachability | ||
assert(result == false); | ||
return result; | ||
} | ||
|
||
public static boolean checkDet() { | ||
boolean result = false; | ||
result = "foo".startsWith("foo", 0); | ||
assert(result); | ||
result = "foo".startsWith("f", -1); | ||
assert(!result); | ||
result = "foo".startsWith("oo", 1); | ||
assert(result); | ||
result = "foo".startsWith("f", 1); | ||
assert(!result); | ||
result = "foo".startsWith("bar", 0); | ||
assert(!result); | ||
result = "foo".startsWith("oo", 2); | ||
assert(!result); | ||
assert(false); | ||
return result; | ||
} | ||
|
||
public static boolean checkNonDet(String s) { | ||
// Filter | ||
if (s == null) { | ||
return false; | ||
} | ||
|
||
// Act | ||
final boolean result = s.startsWith(s, 1); | ||
|
||
// Assert | ||
assert(!result); | ||
|
||
// Check reachability | ||
assert(false); | ||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
CORE | ||
Test.class | ||
--refine-strings --string-max-input-length 10 --unwind 10 --function Test.check | ||
^EXIT=10$ | ||
^SIGNAL=0$ | ||
assertion at file Test.java line 31 .*: SUCCESS | ||
assertion at file Test.java line 34 .*: FAILURE | ||
-- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
CORE | ||
Test.class | ||
--refine-strings --string-max-input-length 100 --unwind 10 --function Test.checkDet | ||
^EXIT=10$ | ||
^SIGNAL=0$ | ||
assertion at file Test.java line 41 .*: SUCCESS | ||
assertion at file Test.java line 43 .*: SUCCESS | ||
assertion at file Test.java line 45 .*: SUCCESS | ||
assertion at file Test.java line 47 .*: SUCCESS | ||
assertion at file Test.java line 49 .*: SUCCESS | ||
assertion at file Test.java line 51 .*: SUCCESS | ||
assertion at file Test.java line 52 .*: FAILURE | ||
-- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
CORE | ||
Test.class | ||
--refine-strings --string-max-input-length 100 --unwind 10 --function Test.checkNonDet | ||
^EXIT=10$ | ||
^SIGNAL=0$ | ||
assertion at file Test.java line 66 .*: SUCCESS | ||
assertion at file Test.java line 69 .*: FAILURE | ||
-- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,14 +21,14 @@ Author: Romain Brenguier, [email protected] | |
/// These axioms are: | ||
/// 1. \f$ {\tt isprefix} \Rightarrow {\tt offset_within_bounds}\f$ | ||
/// 2. \f$ \forall 0 \le qvar<|{\tt prefix}|.\ {\tt isprefix} | ||
/// \Rightarrow s0[witness+{\tt offset}]=s2[witness] \f$ | ||
/// \Rightarrow s0[qvar+{\tt offset}]=s2[qvar] \f$ | ||
/// 3. \f$ (\lnot {\tt isprefix} \Rightarrow | ||
/// \lnot {\tt offset_within_bounds} | ||
/// \lor (0 \le witness<|{\tt prefix}| | ||
/// \land {\tt str}[witness+{\tt offset}] \ne {\tt prefix}[witness])\f$ | ||
/// where \f$ {\tt offset_within_bounds} \f$ is | ||
/// \f$ offset \ge 0 \land offset < |str| \land | ||
/// |str| - |{\tt prefix}| \ge offset \f$ | ||
/// \f$ offset \ge 0 \land offset \le |str| \land | ||
/// |str| - offset \ge |{\tt prefix}| \f$ | ||
/// \param prefix: an array of characters | ||
/// \param str: an array of characters | ||
/// \param offset: an integer | ||
|