Commit a6f60797 authored by Jonathan Shahen's avatar Jonathan Shahen
Browse files

Skeleton code

parent 381632a8
...@@ -5,7 +5,6 @@ import java.io.File; ...@@ -5,7 +5,6 @@ import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.util.Vector;
import java.util.logging.ConsoleHandler; 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;
...@@ -13,6 +12,9 @@ import java.util.logging.Logger; ...@@ -13,6 +12,9 @@ import java.util.logging.Logger;
import mohawk.logging.MohawkCSVFileFormatter; import mohawk.logging.MohawkCSVFileFormatter;
import mohawk.logging.MohawkConsoleFormatter; import mohawk.logging.MohawkConsoleFormatter;
import mohawk.testing.TestingResults;
import mohawk.testing.TestingResultsExport;
import mohawk.testing.TestingSuite;
import org.apache.commons.cli.BasicParser; import org.apache.commons.cli.BasicParser;
import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.CommandLine;
...@@ -31,8 +33,8 @@ import org.apache.commons.lang3.StringUtils; ...@@ -31,8 +33,8 @@ import org.apache.commons.lang3.StringUtils;
public class MohawkMain { public class MohawkMain {
public static String NuSMV_filepath = "NuSMV2"; public static String NuSMV_filepath = "NuSMV2";
public static Vector<String> SpecFiles = new Vector<String>(); public static TestingSuite tests = new TestingSuite();
private static String SpecFileExtension = ".spec";
public static String SMV_filepath = "latestRBAC2SMV.smv"; public static String SMV_filepath = "latestRBAC2SMV.smv";
public static Boolean SMV_deleteFile = false; public static Boolean SMV_deleteFile = false;
// Logger Fields // Logger Fields
...@@ -42,6 +44,7 @@ public class MohawkMain { ...@@ -42,6 +44,7 @@ public class MohawkMain {
private static Level LoggerLevel; private static Level LoggerLevel;
private static FileHandler fileHandler; private static FileHandler fileHandler;
private static Boolean WriteCSVFileHeader = true; private static Boolean WriteCSVFileHeader = true;
private static String ResultsFile = "latestMohawkResults.csv";
public static Level getLoggerLevel() { public static Level getLoggerLevel() {
return LoggerLevel; return LoggerLevel;
...@@ -57,11 +60,11 @@ public class MohawkMain { ...@@ -57,11 +60,11 @@ public class MohawkMain {
Options options = new Options(); Options options = new Options();
// Add Information Options // Add Information Options
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("checknusmv", false, options.addOption("checknusmv", false,
"checks that NuSMV is installed on the system"); "Checks that NuSMV is on the system and displays which version is installed");
// Add Logging Level Options // Add Logging Level Options
options.addOption(OptionBuilder options.addOption(OptionBuilder
...@@ -81,7 +84,8 @@ public class MohawkMain { ...@@ -81,7 +84,8 @@ public class MohawkMain {
+ "default it creates a log called '" + "default it creates a log called '"
+ Logger_filepath + "'").hasArg() + Logger_filepath + "'").hasArg()
.create("output")); .create("output"));
options.addOption("a", false, "does not write the CSV file header"); options.addOption("a", false,
"Does not write the CSV file header to the output log");
options.addOption(OptionBuilder.withArgName("csvfile") options.addOption(OptionBuilder.withArgName("csvfile")
.withDescription("The file where the result should be stored") .withDescription("The file where the result should be stored")
...@@ -111,17 +115,16 @@ public class MohawkMain { ...@@ -111,17 +115,16 @@ public class MohawkMain {
.hasArg().create("nusmv")); .hasArg().create("nusmv"));
options.addOption(OptionBuilder options.addOption(OptionBuilder
.withArgName("smvfile|'u'|'n'") .withArgName("smvfile|'n'")
.withDescription( .withDescription(
"The filepath where the SMV file should be created; " "The file/folder path where the SMV file(s) should be created; "
+ "Only temporary files will be used when equal to 'n'; " + "Only temporary files will be used when equal to 'n'; "
+ "A unique filename will be created when equal to 'u'; " + "by default it creates a SMV called '"
+ "default it creates a SMV called '"
+ SMV_filepath + "'").hasArg() + SMV_filepath + "'").hasArg()
.create("smvfile")); .create("smvfile"));
// Add Functional Options // Add Functional Options
options.addOption("rbacbulk", false, options.addOption("bulk", false,
"Use the folder that rbacspec points to and run against all *.spec"); "Use the folder that rbacspec points to and run against all *.spec");
options.addOption(OptionBuilder options.addOption(OptionBuilder
.withArgName("bmc|smc") .withArgName("bmc|smc")
...@@ -292,13 +295,8 @@ public class MohawkMain { ...@@ -292,13 +295,8 @@ public class MohawkMain {
// Load in SPEC Files // Load in SPEC Files
// SMV File // SMV File
if (cmd.hasOption("smvfile")) { if (cmd.hasOption("smvfile")) {
// Check if no log file was requested if (cmd.getOptionValue("smvfile").equals("n")) {
if (cmd.getOptionValue("output").equals("n")) { SMV_deleteFile = true;
// Create no log file
Logger_filepath = "";
} else if (cmd.getOptionValue("output").equals("u")) {
// Create a unique log file
Logger_filepath = "mohawk-log.%u.%g.txt";
} else { } else {
// Create a log file with a specific name // Create a log file with a specific name
File logfile = new File(cmd.getOptionValue("output")); File logfile = new File(cmd.getOptionValue("output"));
...@@ -319,13 +317,15 @@ public class MohawkMain { ...@@ -319,13 +317,15 @@ public class MohawkMain {
} }
if (cmd.hasOption("rbacspec")) { if (cmd.hasOption("rbacspec")) {
if (cmd.hasOption("rbacbulk")) { if (cmd.hasOption("bulk")) {
// Load all files ending in .spec // Load all files ending in .spec
logger.fine("[OPTION] Importing all SPEC files using the Bulk Import"); logger.fine("[OPTION] Importing all SPEC files using the Bulk Import");
tests.loadSpecFilesFromFolder(cmd.hasOption("rbacspec"),
SpecFileExtension);
} else { } else {
// use only the one file (check that it exists) // use only the one file (check that it exists)
logger.fine("[OPTION] Importing SPEC file using the Single File Import"); logger.fine("[OPTION] Importing SPEC file using the Single File Import");
tests.addSpecFile(cmd.hasOption("rbacspec"));
} }
} }
...@@ -336,10 +336,15 @@ public class MohawkMain { ...@@ -336,10 +336,15 @@ public class MohawkMain {
String runVal = cmd.getOptionValue("run"); String runVal = cmd.getOptionValue("run");
switch (runVal) { switch (runVal) {
case "all": case "all":
TestingResults results = tests.runTests();
TestingResultsExport.writeToConsole(results);
if (!ResultsFile.isEmpty()) {
TestingResultsExport.writeToFile(results, ResultsFile);
}
break; break;
case "smv": case "smv":
tests.convertSpecToSMVFormat();
break; break;
default: default:
logger.severe("The Run Option '" logger.severe("The Run Option '"
......
...@@ -6,13 +6,14 @@ import java.util.Date; ...@@ -6,13 +6,14 @@ import java.util.Date;
import java.util.logging.Formatter; import java.util.logging.Formatter;
import java.util.logging.Handler; import java.util.logging.Handler;
import java.util.logging.LogRecord; import java.util.logging.LogRecord;
import java.util.logging.Logger;
import mohawk.MohawkMain;
import org.apache.commons.lang3.StringEscapeUtils; import org.apache.commons.lang3.StringEscapeUtils;
public class MohawkCSVFileFormatter extends Formatter { public class MohawkCSVFileFormatter extends Formatter {
// public final static Logger logger = MohawkMain.logger;
// Create a DateFormat to format the logger timestamp.
//
private static final DateFormat df = new SimpleDateFormat( private static final DateFormat df = new SimpleDateFormat(
"yyyy/MM/dd hh:mm:ss.SSSZ"); "yyyy/MM/dd hh:mm:ss.SSSZ");
......
...@@ -7,11 +7,14 @@ import java.util.logging.Formatter; ...@@ -7,11 +7,14 @@ import java.util.logging.Formatter;
import java.util.logging.Handler; import java.util.logging.Handler;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.LogRecord; import java.util.logging.LogRecord;
import java.util.logging.Logger;
import mohawk.MohawkMain;
import org.apache.commons.lang3.text.WordUtils; import org.apache.commons.lang3.text.WordUtils;
public class MohawkConsoleFormatter extends Formatter { public class MohawkConsoleFormatter extends Formatter {
// Create a DateFormat to format the logger timestamp. public final static Logger logger = MohawkMain.logger;
private static final DateFormat df = new SimpleDateFormat( private static final DateFormat df = new SimpleDateFormat(
"yyyy/MM/dd hh:mm:ss.SSSZ"); "yyyy/MM/dd hh:mm:ss.SSSZ");
public Integer padLeft = Level.WARNING.toString().length() + 1; public Integer padLeft = Level.WARNING.toString().length() + 1;
......
...@@ -6,6 +6,6 @@ package mohawk.testing; ...@@ -6,6 +6,6 @@ package mohawk.testing;
* *
*/ */
public class TimingResults { public class TestingResults {
} }
package mohawk.testing;
import java.util.logging.Logger;
import mohawk.MohawkMain;
/**
*
* @author Jonathan Shahen
*
*/
public class TestingResultsExport {
public final static Logger logger = MohawkMain.logger;
public static void writeToConsole(TestingResults results) {
// TODO Auto-generated method stub
}
public static void writeToFile(TestingResults results, String resultsFile) {
// TODO Auto-generated method stub
}
}
package mohawk.testing;
import java.util.logging.Logger;
import mohawk.MohawkMain;
public class TestingSuite {
public final static Logger logger = MohawkMain.logger;
public void loadSpecFilesFromFolder(boolean hasOption,
String specFileExtension) {
// TODO Auto-generated method stub
}
public void addSpecFile(boolean hasOption) {
// TODO Auto-generated method stub
}
public TestingResults runTests() {
// TODO Auto-generated method stub
return null;
}
public void convertSpecToSMVFormat() {
logger.info("Converting the Spec file(s) to their SMV format...");
// TODO Complete this function
logger.info("Done converting Spec file(s) to theif SMV format.");
}
}
package mohawk.testing;
/**
*
* @author Jonathan Shahen
*
*/
public class TimingResultsExport {
}
Supports Markdown
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