Add timeout settings to the listener!
authoramiraj <amiraj.95@uci.edu>
Mon, 7 Oct 2019 20:15:02 +0000 (13:15 -0700)
committeramiraj <amiraj.95@uci.edu>
Mon, 7 Oct 2019 20:15:02 +0000 (13:15 -0700)
src/main/gov/nasa/jpf/listener/ConflictTracker.java

index 6c9be0edfdf8b0ce826520fd3c00848879a5d56b..e9ca30c6951403a2b77fbc659b70d5b27f3c29c3 100644 (file)
@@ -43,6 +43,8 @@ public class ConflictTracker extends ListenerAdapter {
   private final HashSet<String> appSet = new HashSet<String>(); // Apps we want to find their conflicts
   private final HashMap<Integer, Node> nodes = new HashMap<Integer, Node>(); // Nodes of a graph
   private final DataSet tempSetSet = new DataSet(false, "NA", false, "NA");
+  private long timeout;
+  private long startTime;
   volatile private Node parentNode = new Node(-2);
   volatile private String operation;
   volatile private String detail;
@@ -55,23 +57,26 @@ public class ConflictTracker extends ListenerAdapter {
   String label;
  
   
-  public ConflictTracker(Config conf, JPF jpf) {
+  public ConflictTracker(Config config, JPF jpf) {
     out = new PrintWriter(System.out, true);
 
-    String[] conflictVars = conf.getStringArray("variables");
+    String[] conflictVars = config.getStringArray("variables");
     // We are not tracking anything if it is null
     if (conflictVars != null) {
       for (String var : conflictVars) {
         conflictSet.add(var);
       }
     }
-    String[] apps = conf.getStringArray("apps");
+    String[] apps = config.getStringArray("apps");
     // We are not tracking anything if it is null
     if (apps != null) {
       for (String var : apps) {
         appSet.add(var);
       }
     }
+    // Timeout input from config is in minutes, so we need to convert into millis
+    timeout = config.getInt("timeout", 0) * 60 * 1000;
+    startTime = System.currentTimeMillis();
   }
 
   public void setOutSet(Node currentNode) {
@@ -532,6 +537,16 @@ public class ConflictTracker extends ListenerAdapter {
 
   @Override
   public void instructionExecuted(VM vm, ThreadInfo ti, Instruction nextInsn, Instruction executedInsn) {
+    // Instantiate timeoutTimer
+    if (timeout > 0) {
+      if (System.currentTimeMillis() - startTime > timeout) {
+        StringBuilder sbTimeOut = new StringBuilder();
+        sbTimeOut.append("Execution timeout: " + (timeout / (60 * 1000)) + " minutes have passed!");
+        Instruction nextIns = ti.createAndThrowException("java.lang.RuntimeException", sbTimeOut.toString());
+        ti.setNextPC(nextIns);
+      }
+    }
+
     if (conflictFound) {
       StringBuilder sb = new StringBuilder();
       sb.append("Conflict found between two apps!");