Skip to content

Commit c5ee131

Browse files
varad64varad64
and
varad64
authored
Apply patch #212 to fix RandomSearch where one path is explored even with limit > 1 (#401)
Co-authored-by: varad64 <[email protected]>
1 parent 1c2806b commit c5ee131

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

src/main/gov/nasa/jpf/search/RandomSearch.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
* going forward() until there is no next state then it restarts the search
3030
* until it hits a certain number of paths executed
3131
*
32-
* <2do> this needs to be updated & tested
32+
* To explore different paths, cg.randomize_choices shouldn't be set to NONE
33+
*
3334
*/
3435
public class RandomSearch extends Search {
3536
int path_limit = 0;
@@ -55,7 +56,7 @@ public void search () {
5556

5657
notifySearchStarted();
5758
while (!done) {
58-
if ((depth < depthLimit) && forward()) {
59+
if (!isEndState() && (depth < depthLimit) && forward()) {
5960
notifyStateAdvanced();
6061

6162
if (currentError != null){
@@ -65,13 +66,7 @@ public void search () {
6566
return;
6667
}
6768
}
68-
69-
if (isEndState()){
70-
return;
71-
}
72-
7369
depth++;
74-
7570
} else { // no next state or reached depth limit
7671
// <2do> we could check for more things here. If the last insn wasn't
7772
// the main return, or a System.exit() call, we could flag a JPFException

src/tests/gov/nasa/jpf/test/mc/basic/StatelessTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,21 @@ public void testNumberOfPaths(){
4747
assert Verify.getCounter(0) == 6;
4848
}
4949
}
50+
51+
52+
@Test public void testStatelessRandomSearch () {
53+
if (!isJPFRun()){
54+
Verify.resetCounter(0);
55+
}
56+
if (verifyNoPropertyViolation("+search.class=.search.RandomSearch", "+search.RandomSearch.path_limit = 10", "+cg.randomize_choices = FIXED_SEED")){
57+
int d = 0;
58+
Verify.incrementCounter(0);
59+
}
60+
if (!isJPFRun()){
61+
if (Verify.getCounter(0) != 11){ // path variable will be incremented to limit + 1
62+
fail("wrong number of paths");
63+
}
64+
}
65+
}
66+
5067
}

0 commit comments

Comments
 (0)