KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gov > nasa > jpf > embedded > TestSearchListener


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

20 package gov.nasa.jpf.embedded;
21
22 import gov.nasa.jpf.JPF;
23 import gov.nasa.jpf.Config;
24 import gov.nasa.jpf.Transition;
25 import gov.nasa.jpf.SearchListener;
26 import gov.nasa.jpf.Search;
27
28
29 /**
30  * test client to show embedded JPF usage
31  * <2do> - TestSearchListener is now obsolete, we have real listener tools
32  * like ExecTracker etc.
33  */

34 public class TestSearchListener implements SearchListener {
35   
36   String JavaDoc padLeft (int n, int len) {
37     String JavaDoc s = Integer.toString(n);
38     
39     if (s.length() >= len) {
40       return s;
41     } else {
42       return " ".substring(0, 6 - s.length()) + s;
43     }
44   }
45   
46   void log (String JavaDoc prefix, Search search) {
47     Transition trans = search.getTransition();
48     int depth = search.getSearchDepth();
49     
50     if (trans != null) {
51       System.out.print(prefix);
52     
53       System.out.print('[');
54       System.out.print(trans.getThread());
55       System.out.print("] ");
56
57       System.out.print( padLeft( search.getStateNumber(), 6));
58       System.out.print( padLeft( depth, 4));
59     
60     
61       System.out.print(" : ");
62       System.out.println(trans.getLabel().trim());
63     }
64   }
65   
66   public void stateRestored(Search search) {
67     log( "! ", search);
68   }
69   
70   public void stateBacktracked(Search search) {
71     log( "< ", search);
72   }
73   
74   public void searchStarted(Search search) {
75     System.out.println("-------------------- search started");
76   }
77
78   public void searchFinished(Search search) {
79     System.out.println("-------------------- search finished");
80   }
81   
82   public void propertyViolated(Search search) {
83     // TODO
84
}
85     
86   public void searchConstraintHit(Search search) {
87     // TODO
88
}
89   
90   public void stateAdvanced(Search search) {
91     log( search.hasNextState() ? "> " : "* ", search);
92   }
93   
94   public void stateProcessed (Search search) {
95     log( ".", search);
96   }
97   
98   void filterArgs (String JavaDoc[] args) {
99     // we don't have any
100
}
101   
102   public static void main (String JavaDoc[] args) {
103     TestSearchListener listener = new TestSearchListener();
104     listener.filterArgs(args);
105     
106     Config conf = JPF.createConfig(args);
107     // here we can set our own params
108
JPF jpf = new JPF(conf);
109     jpf.getSearch().addListener(listener);
110
111     // here you can set the option fields explicitly
112
//opts.execute_path=true;
113
System.out.println("---------------- starting JPF on class: " + args[0]);
114     jpf.run();
115     System.out.println("---------------- JPF terminated");
116   }
117 }
118
Popular Tags