2 * Copyright (C) 2014, United States Government, as represented by the
3 * Administrator of the National Aeronautics and Space Administration.
6 * The Java Pathfinder core (jpf-core) platform is licensed under the
7 * Apache License, Version 2.0 (the "License"); you may not use this file except
8 * in compliance with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0.
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 package gov.nasa.jpf.listener;
20 import gov.nasa.jpf.Config;
21 import gov.nasa.jpf.ListenerAdapter;
22 import gov.nasa.jpf.search.Search;
23 import gov.nasa.jpf.vm.ChoiceGenerator;
24 import gov.nasa.jpf.vm.VM;
25 import java.io.PrintStream;
28 * listener to report out what CGs and choices are processed during the search.
29 * This is a simple tool to find out about the SUT state space
31 public class CGMonitor extends ListenerAdapter {
33 protected PrintStream out;
38 protected boolean showInsn = false; // show the insn that caused the CG
39 protected boolean showChoice = false; // show the choice value (-> show each CG.advance())
40 protected boolean showDepth = true; // show search depth at point of CG set/advance
42 public CGMonitor (Config conf) {
43 showInsn = conf.getBoolean("cgm.show_insn", showInsn);
44 showChoice = conf.getBoolean("cgm.show_choice", showChoice);
45 showDepth = conf.getBoolean("cgm.show_depth", showDepth);
51 public void stateAdvanced (Search search) {
56 public void stateBacktracked (Search search) {
61 public void stateRestored (Search search) {
62 depth = search.getDepth();
65 void printPrefix(char c) {
66 for (int i=0; i<depth; i++) {
71 void printCG (ChoiceGenerator<?> cg, boolean printChoice){
80 out.print(cg.getNextChoice());
85 out.print(cg.getInsn());
93 public void choiceGeneratorSet (VM vm, ChoiceGenerator<?> currentCG) {
95 printCG( vm.getChoiceGenerator(), false);
100 public void choiceGeneratorAdvanced (VM vm, ChoiceGenerator<?> currentCG) {
102 printCG( vm.getChoiceGenerator(), true);