KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gov > nasa > jpf > search > RandomSearch


1 //
2
// Copyright (C) 2005 United States Government as represented by the
3
// Administrator of the National Aeronautics and Space Administration
4
// (NASA). All Rights Reserved.
5
//
6
// This software is distributed under the NASA Open Source Agreement
7
// (NOSA), version 1.3. The NOSA has been approved by the Open Source
8
// Initiative. See the file NOSA-1.3-JPF at the top of the distribution
9
// directory tree for the complete NOSA document.
10
//
11
// THE SUBJECT SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY OF ANY
12
// KIND, EITHER EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT
13
// LIMITED TO, ANY WARRANTY THAT THE SUBJECT SOFTWARE WILL CONFORM TO
14
// SPECIFICATIONS, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR
15
// A PARTICULAR PURPOSE, OR FREEDOM FROM INFRINGEMENT, ANY WARRANTY THAT
16
// THE SUBJECT SOFTWARE WILL BE ERROR FREE, OR ANY WARRANTY THAT
17
// DOCUMENTATION, IF PROVIDED, WILL CONFORM TO THE SUBJECT SOFTWARE.
18
//
19
package gov.nasa.jpf.search;
20
21
22 import gov.nasa.jpf.*;
23 import gov.nasa.jpf.util.Debug;
24
25
26 /**
27  * this is a straight execution pseudo-search - it doesn't search at
28  * all (i.e. it doesn't backtrack), but just behaves like a 'normal' VM,
29  * going forward() until there is no next state then it restarts the search
30  * until it hits a certain number of paths executed
31  *
32  */

33 public class RandomSearch extends AbstractSearch {
34     int path_limit = 0;
35     
36   public RandomSearch (Config config, VM vm) {
37     super(config, vm);
38
39     path_limit = config.getInt("search.RandomSearch.path_limit", 0);
40     
41     System.out.println("Path Limit = " + path_limit);
42     
43     Debug.println(Debug.WARNING, "Random Search");
44   }
45
46   public void search () {
47     int depth = 0;
48     int paths = 0;
49     depth++;
50
51     if (hasPropertyTermination()) {
52       return;
53     }
54
55     vm.forward();
56         VMState init_state = vm.getState();
57         init_state.makeRestorable();
58     
59         notifySearchStarted();
60     while (!done) {
61       if (vm.forward()) {
62         notifyStateAdvanced();
63         if (hasPropertyTermination()) {
64           return;
65         }
66         depth++;
67       } else { // no next state
68
// <2do> we could check for more things here. If the last insn wasn't
69
// the main return, or a System.exit() call, we could flag a JPFException
70
isPropertyViolated();
71         done = (paths >= path_limit);
72         paths++;
73         System.out.println("paths = " + paths);
74         depth = 1;
75                 vm.restoreState(init_state);
76         //vm.rewind();
77
}
78     }
79     notifySearchFinished();
80   }
81 }
82
Popular Tags