Commit 9a19cfe3 authored by Jonathan Shahen's avatar Jonathan Shahen
Browse files

MOHAWK-1 #time 2h

MOHAWK-1 #done
parent 200a124a
Pipeline #7931 skipped
<?xml version="1.0" encoding="windows-1252" standalone="no"?>
<!DOCTYPE log SYSTEM "logger.dtd">
<log>
</log>
...@@ -50,8 +50,10 @@ public class AbsRefine { ...@@ -50,8 +50,10 @@ public class AbsRefine {
RBACInstance rbac = reader.getRBAC(); RBACInstance rbac = reader.getRBAC();
RolesAbsRefine absrefine = new RolesAbsRefine(rbac); RolesAbsRefine absrefine = new RolesAbsRefine(rbac);
if (mode != null) if (mode == null)
absrefine.setMode(NuSMVMode.SMC); // Set the SMC mode absrefine.setMode(NuSMVMode.SMC); // Set the SMC mode
else
absrefine.setMode(mode);
absrefine.absrefineloop(); absrefine.absrefineloop();
} }
} }
...@@ -34,8 +34,7 @@ import java.io.IOException; ...@@ -34,8 +34,7 @@ import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
/** /**
* @author Karthick Jayaraman This class is responsible for runnning NuSMV in * @author Karthick Jayaraman
* the BMC mode.
*/ */
public class BoundedModelChecking { public class BoundedModelChecking {
...@@ -66,8 +65,8 @@ public class BoundedModelChecking { ...@@ -66,8 +65,8 @@ public class BoundedModelChecking {
execProcess.getOutputStream().flush(); execProcess.getOutputStream().flush();
execProcess.getOutputStream().close(); execProcess.getOutputStream().close();
bufread = new BufferedReader(new InputStreamReader(execProcess bufread = new BufferedReader(new InputStreamReader(
.getInputStream())); execProcess.getInputStream()));
String strLine = null; String strLine = null;
while ((strLine = bufread.readLine()) != null) { while ((strLine = bufread.readLine()) != null) {
......
package mohawk; package mohawk;
import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.logging.ConsoleHandler;
import java.util.logging.FileHandler; import java.util.logging.FileHandler;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;
import org.apache.commons.cli.BasicParser; import org.apache.commons.cli.BasicParser;
import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.CommandLine;
...@@ -23,11 +27,22 @@ import org.apache.commons.cli.ParseException; ...@@ -23,11 +27,22 @@ import org.apache.commons.cli.ParseException;
public class MohawkMain { public class MohawkMain {
public final static Logger logger = Logger.getLogger("mohawk"); public final static Logger logger = Logger.getLogger("mohawk");
public static String NuSMV_filepath = "NuSMV"; public static String NuSMV_filepath = "NuSMV2";
public static SimpleDateFormat SDF = new SimpleDateFormat( public static SimpleDateFormat SDF = new SimpleDateFormat(
"yyyy-MM-dd_HH-mm-ss-SSS"); "yyyy-MM-dd_HH-mm-ss-SSS");
public static String SMV_filepath = "latestRBAC2SMV.smv"; public static String SMV_filepath = "latestRBAC2SMV.smv";
public static String Logger_filepath = "mohawk.log"; public static String Logger_filepath = "mohawk.log";
private static ConsoleHandler handler = new ConsoleHandler();
private static Level LoggerLevel;
private static FileHandler fileHandler;
public static Level getLoggerLevel() {
return LoggerLevel;
}
public static void setLoggerLevel(Level loggerLevel) {
LoggerLevel = loggerLevel;
}
@SuppressWarnings("static-access") @SuppressWarnings("static-access")
public static void main(String[] args) { public static void main(String[] args) {
...@@ -38,7 +53,7 @@ public class MohawkMain { ...@@ -38,7 +53,7 @@ public class MohawkMain {
options.addOption("help", false, "print this message"); options.addOption("help", false, "print this message");
options.addOption("version", false, options.addOption("version", false,
"print the version information and exit"); "print the version information and exit");
options.addOption("checknusvm", false, options.addOption("checknusmv", false,
"checks that NuSMV is installed on the system"); "checks that NuSMV is installed on the system");
// Add Logging Level Options // Add Logging Level Options
...@@ -86,10 +101,10 @@ public class MohawkMain { ...@@ -86,10 +101,10 @@ public class MohawkMain {
options.addOption("smvdelete", false, options.addOption("smvdelete", false,
"Delete the SMV file when the operation is complete"); "Delete the SMV file when the operation is complete");
options.addOption(OptionBuilder options.addOption(OptionBuilder
.withArgName("y/n/b") .withArgName("bmc|smc")
.withDescription( .withDescription(
"Uses the Bound Estimation when equal to 'y'; Uses NuSMV's default bounds of 10 when equal to 'n'; Runs both tests when equal to 'b'") "Uses the Bound Estimation Checker when equal to 'bmc'; Uses Symbolic Model Checking when equal to 'smc'")
.hasArg().create("bmc")); .hasArg().create("mode"));
// Add Actionable Options // Add Actionable Options
options.addOption(OptionBuilder options.addOption(OptionBuilder
...@@ -103,15 +118,19 @@ public class MohawkMain { ...@@ -103,15 +118,19 @@ public class MohawkMain {
CommandLine cmd = parser.parse(options, args); CommandLine cmd = parser.parse(options, args);
// Logging Level // Logging Level
handler.setFormatter(new SimpleFormatter());
if (cmd.hasOption("quiet")) { if (cmd.hasOption("quiet")) {
logger.setLevel(Level.SEVERE); setLoggerLevel(Level.SEVERE);
} else if (cmd.hasOption("debug")) { } else if (cmd.hasOption("debug")) {
logger.setLevel(Level.FINEST); setLoggerLevel(Level.FINEST);
} else if (cmd.hasOption("verbose")) { } else if (cmd.hasOption("verbose")) {
logger.setLevel(Level.INFO); setLoggerLevel(Level.INFO);
} else { } else {
logger.setLevel(Level.WARNING); setLoggerLevel(Level.WARNING);
} }
logger.setLevel(LoggerLevel);
handler.setLevel(LoggerLevel);
logger.addHandler(handler);
// Custom Configuration // Custom Configuration
if (cmd.hasOption("numsmv")) { if (cmd.hasOption("numsmv")) {
...@@ -127,10 +146,39 @@ public class MohawkMain { ...@@ -127,10 +146,39 @@ public class MohawkMain {
f.printHelp("mohawk", options, true); f.printHelp("mohawk", options, true);
return; return;
} else if (cmd.hasOption("version")) { } else if (cmd.hasOption("version")) {
System.out.println("2.0.0"); logger.info("2.0.0");
return; return;
} else if (cmd.hasOption("checknusvm")) { } else if (cmd.hasOption("checknusmv")) {
logger.fine("Checking the NuSMV version number");
String[] commands = { NuSMV_filepath, "-help" };
ProcessBuilder pb = new ProcessBuilder(commands);
pb.redirectErrorStream(true); // REQUIRED: NuSVM uses STDERR
try {
// will throw error if it cannot find NuSMV
Process proc = pb.start();
BufferedReader br = new BufferedReader(
new InputStreamReader(proc.getInputStream()));
String strLine = null;
if (br.ready()) {
while ((strLine = br.readLine()) != null) {
if (strLine.contains("This is NuSMV")) {
logger.info(strLine);
break;
}
}
} else {
logger.warning("No output was given by NuSMV, "
+ "maybe the commandline arguments have changed "
+ "or the file " + NuSMV_filepath
+ " points to the wrong file");
}
} catch (IOException e) {
logger.severe("No Version of NuSMV was found, "
+ "please check that NuSMV is on the PATH.");
return;
}
} }
// Set IO Configurations // Set IO Configurations
...@@ -157,18 +205,22 @@ public class MohawkMain { ...@@ -157,18 +205,22 @@ public class MohawkMain {
Logger_filepath = logfile.getAbsolutePath(); Logger_filepath = logfile.getAbsolutePath();
} }
} }
// Add // Add Logger File Handler
try { if (!Logger_filepath.isEmpty()) {
if (!Logger_filepath.isEmpty()) { fileHandler = new FileHandler(Logger_filepath);
logger.addHandler(new FileHandler(Logger_filepath)); fileHandler.setLevel(getLoggerLevel());
} logger.addHandler(fileHandler);
} catch (Exception e) {
logger.severe(e.getMessage());
return;
} }
// Execute the test cases
if (cmd.hasOption("run")) {
logger.fine("TODO: Write the 'run' parameter");
}
} catch (ParseException e) { } catch (ParseException e) {
logger.severe(e.getMessage()); logger.severe(e.getMessage());
} catch (Exception e) {
logger.severe(e.getMessage());
return;
} }
} }
} }
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