Commit 89185bf4 authored by Jonathan Shahen's avatar Jonathan Shahen

Add timing to old code and update the TestingResult to add the return code

parent 8c735bb6
...@@ -85,18 +85,20 @@ public class SMVSpecHelper { ...@@ -85,18 +85,20 @@ public class SMVSpecHelper {
} }
try { try {
WriteNuSMV nusmv = new WriteNuSMV(nusmvFile.getAbsolutePath(), "smvtemplate"); WriteNuSMV nusmv = new WriteNuSMV(nusmvFile.getAbsolutePath(), "smvtemplate", settings.timing,
"convertSpecToSMVFormat(" + specFile.getName() + ")");
RBACSpecReader reader = new RBACSpecReader(specFile.getAbsolutePath()); RBACSpecReader reader = new RBACSpecReader(specFile.getAbsolutePath());
RBACInstance rbac = reader.getRBAC(); RBACInstance rbac = reader.getRBAC();
if (settings.sliceRBAC) { if (settings.sliceRBAC) {
logger.info("[Slicing] Slicing the Spec File"); logger.info("[Slicing] Slicing the Spec File");
RoleSlicer roleslicer = new RoleSlicer(rbac); RoleSlicer roleslicer = new RoleSlicer(rbac, settings.timing,
"convertSpecToSMVFormat(" + specFile.getName() + ")");
rbac = roleslicer.getSlicedPolicy(); rbac = roleslicer.getSlicedPolicy();
logger.info("[DETAILS] After Slicing -> Number of Roles: " + rbac.getNumRoles() + "; Number of Rules: " logger.info("[DETAILS] After Slicing -> Number of Roles: " + rbac.getNumRoles() +
+ (rbac.getCA().size() + rbac.getCR().size())); "; Number of Rules: " + (rbac.getCA().size() + rbac.getCR().size()));
} }
if (settings.sliceRBACQuery) { if (settings.sliceRBACQuery) {
...@@ -109,7 +111,8 @@ public class SMVSpecHelper { ...@@ -109,7 +111,8 @@ public class SMVSpecHelper {
if (settings.skipRefine) { if (settings.skipRefine) {
nusmv.fillAttributes(rbac); nusmv.fillAttributes(rbac);
} else { } else {
RolesAbsRefine absrefine = new RolesAbsRefine(rbac); RolesAbsRefine absrefine = new RolesAbsRefine(rbac, settings.timing,
"convertSpecToSMVFormat(" + specFile.getName() + ")");
RBACInstance rbac_refined = absrefine.refineOnly(); RBACInstance rbac_refined = absrefine.refineOnly();
nusmv.fillAttributes(rbac_refined); nusmv.fillAttributes(rbac_refined);
......
This diff is collapsed.
...@@ -12,6 +12,7 @@ import mohawk.collections.RoleDepTree; ...@@ -12,6 +12,7 @@ import mohawk.collections.RoleDepTree;
import mohawk.global.nusmv.NuSMV; import mohawk.global.nusmv.NuSMV;
import mohawk.global.pieces.mohawk.*; import mohawk.global.pieces.mohawk.*;
import mohawk.global.results.ExecutionResult; import mohawk.global.results.ExecutionResult;
import mohawk.global.timing.MohawkTiming;
import mohawk.math.CalculateDiameter; import mohawk.math.CalculateDiameter;
import mohawk.output.WriteNuSMV; import mohawk.output.WriteNuSMV;
import mohawk.output.WriteRBACSpec; import mohawk.output.WriteRBACSpec;
...@@ -46,10 +47,15 @@ public class RolesAbsRefine { ...@@ -46,10 +47,15 @@ public class RolesAbsRefine {
private NuSMVMode mode;// mode private NuSMVMode mode;// mode
public boolean skipSMVFile = false; public boolean skipSMVFile = false;
private Integer returnValue = null; private Integer returnValue = null;
public RolesAbsRefine(RBACInstance inRbac) { // Timing
public MohawkTiming timing;
public String timingPrefix;
public RolesAbsRefine(RBACInstance inRbac, MohawkTiming timing, String timingPrefix) {
this.timing = timing;
this.timingPrefix = timingPrefix;
mode = NuSMVMode.BMC;// Default mode is BMC mode = NuSMVMode.BMC;// Default mode is BMC
k = 2; k = 2;
...@@ -89,8 +95,9 @@ public class RolesAbsRefine { ...@@ -89,8 +95,9 @@ public class RolesAbsRefine {
return sAdminRoles; return sAdminRoles;
} }
public Boolean getResult(RBACInstance curInstance, Integer fileno) throws IOException, InterruptedException { public Boolean getResult(RBACInstance curInstance, Integer fileno) throws Exception {
WriteNuSMV nusmv = new WriteNuSMV("logs/smvinstancefile" + fileno + ".txt", "smvtemplate"); WriteNuSMV nusmv = new WriteNuSMV("logs/smvinstancefile" + fileno + ".txt", "smvtemplate",
timing, timingPrefix);
nusmv.fillAttributes(curInstance); nusmv.fillAttributes(curInstance);
if (!skipSMVFile) { if (!skipSMVFile) {
...@@ -196,25 +203,25 @@ public class RolesAbsRefine { ...@@ -196,25 +203,25 @@ public class RolesAbsRefine {
} }
public boolean refineRoles() { public boolean refineRoles() {
if (nextsetroles.size() == allroles.size()) if (nextsetroles.size() == allroles.size()) { return false; }
return false;
// Set<String> incrementRoles = rdeptree.getRoles(refinementstep); // Set<String> incrementRoles = rdeptree.getRoles(refinementstep);
Set<String> incrementRoles = new HashSet<String>();// = Set<String> incrementRoles = new HashSet<String>();// = rdeptree.getRoles(refinementstep);
// rdeptree.getRoles(refinementstep);
for (int i = 0; i < k; i++) { for (int i = 0; i < k; i++) {
Set<String> sNextQueue = this.rdeptree.getRoles(lastpriority); Set<String> sNextQueue = this.rdeptree.getRoles(lastpriority);
if (sNextQueue != null) { if (sNextQueue != null) {
incrementRoles.addAll(sNextQueue); incrementRoles.addAll(sNextQueue);
lastpriority++; lastpriority++;
} else } else {
break; break;
}
} }
if (incrementRoles.size() == 0) if (incrementRoles.size() == 0) {
return false; return false;
else } else {
nextsetroles.addAll(incrementRoles); nextsetroles.addAll(incrementRoles);
}
refinementstep++; refinementstep++;
......
...@@ -7,6 +7,7 @@ import java.util.*; ...@@ -7,6 +7,7 @@ import java.util.*;
import java.util.logging.Logger; import java.util.logging.Logger;
import mohawk.global.pieces.mohawk.*; import mohawk.global.pieces.mohawk.*;
import mohawk.global.timing.MohawkTiming;
import mohawk.rbac.RBACInstance; import mohawk.rbac.RBACInstance;
/** /**
...@@ -33,13 +34,18 @@ public class RoleSlicer { ...@@ -33,13 +34,18 @@ public class RoleSlicer {
private Vector<String> vPositiveDeps; private Vector<String> vPositiveDeps;
private Vector<String> vNegativeDeps; private Vector<String> vNegativeDeps;
// Timing
public MohawkTiming timing;
public String timingPrefix;
/* /*
* This is a map between role indices of unsliced roles and and sliced roles. * This is a map between role indices of unsliced roles and and sliced roles.
*/ */
private Map<Integer, Integer> mapRoleIndex; private Map<Integer, Integer> mapRoleIndex;
public RoleSlicer(RBACInstance inRbac) { public RoleSlicer(RBACInstance inRbac, MohawkTiming timing, String timingPrefix) {
this.timing = timing;
this.timingPrefix = timingPrefix;
unsliced = inRbac; unsliced = inRbac;
strRole = unsliced.getSpec().get(1); strRole = unsliced.getSpec().get(1);
strUser = unsliced.getSpec().get(0); strUser = unsliced.getSpec().get(0);
...@@ -48,20 +54,41 @@ public class RoleSlicer { ...@@ -48,20 +54,41 @@ public class RoleSlicer {
} }
public RBACInstance getSlicedPolicy() throws Exception { public RBACInstance getSlicedPolicy() throws Exception {
/* TIMING */timing.startTimer(timingPrefix + " (slicingTotal)");
System.out.println("Slicing roles"); System.out.println("[START] getSlicedPolicy()");
System.out.println("[START] Slicing roles");
/* TIMING */timing.startTimer(timingPrefix + " (slicing roles)");
slicedRoles = createSlicedRoles(); slicedRoles = createSlicedRoles();
System.out.println("Slicing users"); /* TIMING */timing.stopTimer(timingPrefix + " (slicing roles)");
System.out.println("[START] Slicing users");
/* TIMING */timing.startTimer(timingPrefix + " (slicing users)");
slicedUsers = sliceUsers(); slicedUsers = sliceUsers();
System.out.println("Slicing admin"); /* TIMING */timing.stopTimer(timingPrefix + " (slicing users)");
System.out.println("[START] Slicing admin");
/* TIMING */timing.startTimer(timingPrefix + " (slicing admin)");
slicedAdmin = unsliced.getAdmin(); slicedAdmin = unsliced.getAdmin();
System.out.println("Slicing UA"); /* TIMING */timing.stopTimer(timingPrefix + " (slicing admin)");
System.out.println("[START] Slicing UA");
/* TIMING */timing.startTimer(timingPrefix + " (slicing UA)");
slicedUA = sliceUA(); slicedUA = sliceUA();
System.out.println("Slicing CA"); /* TIMING */timing.stopTimer(timingPrefix + " (slicing UA)");
System.out.println("[START] Slicing CA");
/* TIMING */timing.startTimer(timingPrefix + " (slicing CA)");
slicedCA = sliceCA(); slicedCA = sliceCA();
System.out.println("Slicing CR"); /* TIMING */timing.stopTimer(timingPrefix + " (slicing CA)");
System.out.println("[START] Slicing CR");
/* TIMING */timing.startTimer(timingPrefix + " (slicing CR)");
slicedCR = sliceCR(); slicedCR = sliceCR();
/* TIMING */timing.stopTimer(timingPrefix + " (slicing CR)");
/* TIMING */timing.stopTimer(timingPrefix + " (slicingTotal)");
return new RBACInstance(slicedRoles, slicedUsers, slicedAdmin, slicedUA, slicedCR, slicedCA, return new RBACInstance(slicedRoles, slicedUsers, slicedAdmin, slicedUA, slicedCR, slicedCA,
unsliced.getSpec()); unsliced.getSpec());
} }
......
...@@ -45,7 +45,7 @@ public class TestRunner implements Callable<TestingResult> { ...@@ -45,7 +45,7 @@ public class TestRunner implements Callable<TestingResult> {
logger.info("[TestRunner] Running the Abstraction-Refinement Step"); logger.info("[TestRunner] Running the Abstraction-Refinement Step");
result = absrefine.absrefineloop(); result = absrefine.absrefineloop();
} }
return new TestingResult(result, (long) 0, "", "Return Result: " + absrefine.getReturnValue()); return new TestingResult(result, (long) 0, "", absrefine.getReturnValue(), "");
} }
} }
...@@ -108,7 +108,7 @@ public class TestingSuite { ...@@ -108,7 +108,7 @@ public class TestingSuite {
logger.info("[Slicing] Slicing the Spec File"); logger.info("[Slicing] Slicing the Spec File");
/* TIMING */settings.timing.startTimer(timerName + " (slicing)"); /* TIMING */settings.timing.startTimer(timerName + " (slicing)");
RoleSlicer roleslicer = new RoleSlicer(rbac); RoleSlicer roleslicer = new RoleSlicer(rbac, settings.timing, timerName);
rbac = roleslicer.getSlicedPolicy(); rbac = roleslicer.getSlicedPolicy();
logger.info("[DETAILS] After Slicing -> Number of Roles: " + rbac.getNumRoles() logger.info("[DETAILS] After Slicing -> Number of Roles: " + rbac.getNumRoles()
...@@ -133,7 +133,7 @@ public class TestingSuite { ...@@ -133,7 +133,7 @@ public class TestingSuite {
logger.severe(e.getMessage()); logger.severe(e.getMessage());
} }
RolesAbsRefine absrefine = new RolesAbsRefine(rbac); RolesAbsRefine absrefine = new RolesAbsRefine(rbac, settings.timing, timerName);
absrefine.setMode(modes.get(j)); absrefine.setMode(modes.get(j));
// Setup Timeout Timer // Setup Timeout Timer
...@@ -142,20 +142,15 @@ public class TestingSuite { ...@@ -142,20 +142,15 @@ public class TestingSuite {
logger.info("[RUNNING] Running Mohawk on testcase " + (i + 1) + "/" + numSpecFiles + " (mode=" logger.info("[RUNNING] Running Mohawk on testcase " + (i + 1) + "/" + numSpecFiles + " (mode="
+ modes.get(j) + "):"); + modes.get(j) + "):");
/* TIMING */settings.timing.startTimer(timerName + " (TestRunner)");
if (settings.TIMEOUT_SECONDS == 0) { if (settings.TIMEOUT_SECONDS == 0) {
settings.lastResult = future.get(); settings.lastResult = future.get();
} else { } else {
settings.lastResult = future.get(settings.TIMEOUT_SECONDS, TimeUnit.SECONDS); settings.lastResult = future.get(settings.TIMEOUT_SECONDS, TimeUnit.SECONDS);
} }
System.out /* TIMING */settings.timing.stopTimer(timerName + " (TestRunner)");
.println("Result: " + settings.lastResult + " for role '" + absrefine.getSpecRole() + "'");
logger.info("[COMPLETED] Result: " + settings.lastResult + ", for the Spec Role: '"
+ absrefine.getSpecRole()
+ "' in following spec file (in mode "
+ modes.get(j) + "): " + specFile);
/* TIMING */settings.timing.stopTimer(timerName); /* TIMING */settings.timing.stopTimer(timerName);
settings.lastResult._duration = settings.timing.getLastElapsedTime(); settings.lastResult._duration = settings.timing.getLastElapsedTime();
settings.lastResult._filename = settings.smvHelper.specFiles.get(i).getAbsolutePath(); settings.lastResult._filename = settings.smvHelper.specFiles.get(i).getAbsolutePath();
if (settings.lastResult._comment == null || settings.lastResult._comment.isEmpty()) { if (settings.lastResult._comment == null || settings.lastResult._comment.isEmpty()) {
...@@ -163,6 +158,14 @@ public class TestingSuite { ...@@ -163,6 +158,14 @@ public class TestingSuite {
} else { } else {
settings.lastResult._comment += "; " + comment; settings.lastResult._comment += "; " + comment;
} }
System.out.println("Result: " + settings.lastResult +
" for role '" + absrefine.getSpecRole() + "'");
logger.info("[COMPLETED] Result: " + settings.lastResult + ", for the Spec Role: '"
+ absrefine.getSpecRole()
+ "' in following spec file (in mode "
+ modes.get(j) + "): " + specFile);
settings.results.add(settings.lastResult); settings.results.add(settings.lastResult);
settings.results.writeOutLast(resultsFW); settings.results.writeOutLast(resultsFW);
} catch (TimeoutException e) { } catch (TimeoutException e) {
...@@ -172,8 +175,9 @@ public class TestingSuite { ...@@ -172,8 +175,9 @@ public class TestingSuite {
settings.lastResult = new TestingResult(ExecutionResult.TIMEOUT, settings.lastResult = new TestingResult(ExecutionResult.TIMEOUT,
settings.timing.getLastElapsedTime(), settings.timing.getLastElapsedTime(),
settings.smvHelper.specFiles.get(i), settings.smvHelper.specFiles.get(i),
comment + "; Retun Value: timeout"); "timeout", comment);
settings.results.writeOutLast(resultsFW);
} catch (OutOfMemoryError e) { } catch (OutOfMemoryError e) {
logger.warning("[OUT OF MEMORY] Mohawk has ran out of memory out for SPEC file: " + specFile); logger.warning("[OUT OF MEMORY] Mohawk has ran out of memory out for SPEC file: " + specFile);
/* TIMING */settings.timing.cancelTimer(timerName); /* TIMING */settings.timing.cancelTimer(timerName);
...@@ -181,8 +185,9 @@ public class TestingSuite { ...@@ -181,8 +185,9 @@ public class TestingSuite {
settings.lastResult = new TestingResult(ExecutionResult.OUT_OF_MEMORY, settings.lastResult = new TestingResult(ExecutionResult.OUT_OF_MEMORY,
settings.timing.getLastElapsedTime(), settings.timing.getLastElapsedTime(),
settings.smvHelper.specFiles.get(i), settings.smvHelper.specFiles.get(i),
comment + "; Retun Value: out_of_memory"); "out_of_memory", comment);
settings.results.writeOutLast(resultsFW);
} catch (InterruptedException e) { } catch (InterruptedException e) {
if (logger.getLevel() == Level.FINEST) { if (logger.getLevel() == Level.FINEST) {
e.printStackTrace(); e.printStackTrace();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment