From bc7560ac9fb72a1a2da9efd5b0efb820af687fd6 Mon Sep 17 00:00:00 2001 From: amiraj Date: Mon, 7 Oct 2019 13:15:02 -0700 Subject: [PATCH] Add timeout settings to the listener! --- .../nasa/jpf/listener/ConflictTracker.java | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/main/gov/nasa/jpf/listener/ConflictTracker.java b/src/main/gov/nasa/jpf/listener/ConflictTracker.java index 6c9be0e..e9ca30c 100644 --- a/src/main/gov/nasa/jpf/listener/ConflictTracker.java +++ b/src/main/gov/nasa/jpf/listener/ConflictTracker.java @@ -43,6 +43,8 @@ public class ConflictTracker extends ListenerAdapter { private final HashSet appSet = new HashSet(); // Apps we want to find their conflicts private final HashMap nodes = new HashMap(); // 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!"); -- 2.34.1