diff --git a/dsescripts/script1.dse b/dsescripts/script1.dse new file mode 100644 index 0000000000000000000000000000000000000000..2bb68e6f7dcb65632ec677d51a7e2cb4f6fdf9b7 --- /dev/null +++ b/dsescripts/script1.dse @@ -0,0 +1,67 @@ +# My first DSE script +# Commands are not case sensitive +# To execute this script: java RunDSE -debug script1.dse + + +#Model +ModelPath = /homes/apvrille/TechTTool/TMLCode/ +MappingFile = smartcard.tmap + +#Path +PathToSimulator = /homes/apvrille/TechTTool/SystemCCode/generated/ +PathToResults = /homes/apvrille/TechTTool/SystemCCode/results/ + +#Simulation + +#Use -1 value to unset +SimulationMaxCycle = -1 + +SimulationOutputVCD = true +SimulationOutputHTML = true +#SimulationOutputTXT = true +SimulationOutputXML = true +RecordResults = true +SimulationCompilationCommand = make -j9 -C +SimulationExecutionCommand = run.x + +SimulationExplorationMinimumCommand = 5 +SimulationExplorationMinimumBranch = 5 + +ShowSimulatorRawOutput = false + +NbOfSimulationThreads = 128 + +#Starting simulation +#runSimulation = 100 +#runParallelSimulation = 10000 +#runexplo +#runsimulation = 1 + +#To print in a file all simulation results +#saveAllResults + +#To print in a file a summary of simulation results +#saveResultsSummary + +#To reset results +#resetResults + + +#Automatic DSE +TaskModelFile = smartcard.tml +MinNbOfCPUs = 1 +MaxNbOfCPUs = 3 +MinNbOfCoresPerCPU = 1 +MaxNbOfCoresPerCPU = 3 +NbOfSimulationsPerMapping = 10 +setTap = minSimulationDuration 10 +setTap = averageSimulationDuration 0 +setTap = maxSimulationDuration 0 +setTap = architectureComplexity 1 +setTap = averageCPUUsage -10 +runDSE +#runParallelDSE +saveAllResults +saveResultsSummary + +#End of script diff --git a/executablecode/Makefile.src b/executablecode/Makefile.src index ddc0929c15dc4d85c41f76012a09161c649c9b7c..fd299741e00e93855bb40e4f81a22f48f47c4a0a 100755 --- a/executablecode/Makefile.src +++ b/executablecode/Makefile.src @@ -1 +1 @@ -SRCS = generated_src/main.c generated_src/AlarmActuator.c generated_src/PressureSensor.c generated_src/PressureController.c generated_src/MainController.c generated_src/AlarmManager.c generated_src/Timer__alarmTimer__AlarmManager.c \ No newline at end of file +SRCS = generated_src/main.c generated_src/ResqueTeam.c generated_src/SoftwareOfRoverRobot.c generated_src/RobotWebsite.c generated_src/RobotApplication.c generated_src/Sensors.c \ No newline at end of file diff --git a/src/main/java/dseengine/DSEConfiguration.java b/src/main/java/dseengine/DSEConfiguration.java index 045662e0b184fd282e4723183d2619ac2cb5775e..bbffc409c3d63bde0e1f054946a84c3163069709 100755 --- a/src/main/java/dseengine/DSEConfiguration.java +++ b/src/main/java/dseengine/DSEConfiguration.java @@ -1,26 +1,26 @@ /* Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille - * + * * ludovic.apvrille AT enst.fr - * + * * This software is a computer program whose purpose is to allow the * edition of TURTLE analysis, design and deployment diagrams, to * allow the generation of RT-LOTOS or Java code from this diagram, * and at last to allow the analysis of formal validation traces * obtained from external tools, e.g. RTL from LAAS-CNRS and CADP * from INRIA Rhone-Alpes. - * + * * This software is governed by the CeCILL license under French law and * abiding by the rules of distribution of free software. You can use, * modify and/ or redistribute the software under the terms of the CeCILL * license as circulated by CEA, CNRS and INRIA at the following URL * "http://www.cecill.info". - * + * * As a counterpart to the access to the source code and rights to copy, * modify and redistribute granted by the license, users are provided only * with a limited warranty and the software's author, the holder of the * economic rights, and the successive licensors have only limited * liability. - * + * * In this respect, the user's attention is drawn to the risks associated * with loading, using, modifying and/or developing or reproducing the * software by the user in light of its specific status of free software, @@ -31,7 +31,7 @@ * requirements in conditions enabling the security of their systems and/or * data to be ensured and, more generally, to use and operate it in the * same conditions as regards security. - * + * * The fact that you are presently reading this means that you have had * knowledge of the CeCILL license and that you accept its terms. */ @@ -70,1726 +70,1726 @@ import java.util.List; //import uppaaldesc.*; /** -* Class DSEScriptReader -* Reader of script for Design Space Exploration -* Creation: 28/06/2011 -* @version 1.0 28/06/2011 -* @author Ludovic APVRILLE -*/ + * Class DSEScriptReader + * Reader of script for Design Space Exploration + * Creation: 28/06/2011 + * @version 1.0 28/06/2011 + * @author Ludovic APVRILLE + */ public class DSEConfiguration implements Runnable { - - private String errorMessage; - - private final String PATH_TO_CODE = "No directory selected for putting the generated code"; - private final String PATH_TO_RESULTS = "No directory selected for putting the results"; - private final String PATH_TO_SOURCE = "No source model selected"; - private final String NO_OUTPUT_SELECTED = "No format ofr the output has been selected"; - private final String LOAD_MAPPING_FAILED = "Loading of the mapping failed"; - private final String LOAD_TASKMODEL_FAILED = "Loading of the task model failed"; - private final String SIMULATION_COMPILATION_COMMAND_NOT_SET = "Compilation command missing"; - private final String SIMULATION_EXECUTION_COMMAND_NOT_SET = "Command to start simulation was noit set"; - private final String INVALID_ARGUMENT_NATURAL_VALUE = "The argument is execpted to a be natural value"; - - private String simulationCompilationCommand = null; - private String simulationExecutionCommand = null; - - private String pathToSimulator; - private String pathToResults; - - public String overallResults; - - private File mappingFile = null; - private String modelPath = ""; - - private File taskModelFile = null; - - private boolean outputVCD = false; - private boolean outputHTML = true; - private boolean outputTXT = false; - private boolean outputXML = false; - - private boolean recordResults = false; - - private boolean showSimulatorRawOutput = false; - - public TMLComponentDesignPanel tmlcdp; - public TMLArchiPanel tmlap; - - private TMLMapping<TGComponent> tmap; - private TMLModeling<TGComponent> tmlm; - -// private TMLModeling stmlm; - - private boolean optionChanged = true; - - private int simulationID = 0; - private int resultsID = 0; - private int dseID = 0; - - private int simulationExplorationMinimumCommand = 100; - private int simulationExplorationMinimumBranch = 100; - - - private int simulationMaxCycles = -1; - - private int nbOfSimulationThreads = 1; - - //Security - public boolean addSecurity=false; - public String encComp="100"; - public String decComp="100"; - public String overhead="0"; - public String nonceSize="0"; - - // DSE - private int minNbOfCPUs = 1; - private int maxNbOfCPUs = 2; - private int minNbOfCoresPerCPU = 1; - private int maxNbOfCoresPerCPU = 2; - private int nbOfSimulationsPerMapping = 1; - private TMLModeling<TGComponent> taskModel = null; -// private TMLModeling secModel = null; - private Vector<TMLMapping<TGComponent>> mappings; - private DSEMappingSimulationResults dsemapresults; - List<Integer[]> latencyIds =new ArrayList<Integer[]>(); - public MainGUI mainGUI; - // Taps - private static String[] taps = {"MinSimulationDuration", "AverageSimulationDuration", - "MaxSimulationDuration", - "ArchitectureComplexity", - "MinCPUUsage", "AverageCPUUsage", "MaxCPUUsage", - "MinBusUsage", "AverageBusUsage", "MaxBusUsage", - "MinBusContention", "AverageBusContentione", "MaxBusContention"}; - -/* private int[] tapValues = {1, 1, 1, - 1, // 3 - 1, -10, 1,//4, 5, 6 - 1, 1, 1, // 7, 8, 9 - 1, 1, 1 // 10, 11, 12 - }; */ - - double[] tapValues={1.0,1.0,1.0, 1.0, 1.0, -10.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0}; - - - public static final int LONG_TYPE = 0; - public static final int DOUBLE_TYPE = 1; - - public static int[] tapType = {LONG_TYPE, DOUBLE_TYPE, LONG_TYPE, - LONG_TYPE, - DOUBLE_TYPE, DOUBLE_TYPE, DOUBLE_TYPE, - DOUBLE_TYPE, DOUBLE_TYPE, DOUBLE_TYPE, - LONG_TYPE, DOUBLE_TYPE, LONG_TYPE - }; - - - private DSESimulationResult results; - - private String simulationCmd; - private int nbOfRemainingSimulation; - private int totalNbOfSimulations; - - private int progression = 0; - - //private int nbOfSimulations; - - public DSEConfiguration() { - - } - - public String getErrorMessage() { - return errorMessage; - } - - public int setModelPath(String _path) { - // Trying to read the file - modelPath = _path; - optionChanged = true; - - return 0; - } - - public int setMappingFile(String _fileName) { - // Trying to read the file - mappingFile = new File(modelPath + _fileName); - if (!FileUtils.checkFileForOpen(mappingFile)) { - optionChanged = true; - mappingFile = null; - return -1; - } - - - return 0; - } - - public int setTaskModelFile(String _fileName) { - // Trying to read the file - taskModelFile = new File(modelPath + _fileName); - if (!FileUtils.checkFileForOpen(taskModelFile)) { - optionChanged = true; - taskModelFile = null; - return -1; - } - - return 0; - } - - public int setOutputVCD(String _value) { - if (_value.toLowerCase().compareTo("true") == 0) { - outputVCD = true; - optionChanged = true; - return 0; - } - - if (_value.toLowerCase().compareTo("false") == 0) { - outputVCD = false; - optionChanged = true; - return 0; - } - - return -1; - } - - public int setOutputHTML(String _value) { - if (_value.toLowerCase().compareTo("true") == 0) { - outputHTML = true; - optionChanged = true; - return 0; - } - - if (_value.toLowerCase().compareTo("false") == 0) { - outputHTML = false; - optionChanged = true; - return 0; - } - - return -1; - } - - public int setOutputTXT(String _value) { - if (_value.toLowerCase().compareTo("true") == 0) { - outputTXT = true; - optionChanged = true; - return 0; - } - - if (_value.toLowerCase().compareTo("false") == 0) { - outputTXT = false; - optionChanged = true; - return 0; - } - - return -1; - } - - public int setOutputXML(String _value) { - if (_value.toLowerCase().compareTo("true") == 0) { - outputXML = true; - optionChanged = true; - return 0; - } - - if (_value.toLowerCase().compareTo("false") == 0) { - outputXML = false; - optionChanged = true; - return 0; - } - - return -1; - } - - public int setRecordResults(String _value) { - if (_value.toLowerCase().compareTo("true") == 0) { - recordResults = true; - optionChanged = true; - return 0; - } - - if (_value.toLowerCase().compareTo("false") == 0) { - recordResults = false; - optionChanged = true; - return 0; - } - - return -1; - } - - public int setPathToSimulator(String _value) { - pathToSimulator = _value; - optionChanged = true; - return 0; - } - - public int setPathToResults(String _value) { - pathToResults = _value; - optionChanged = true; - return 0; - } - - public int setSimulationCompilationCommand(String _value) { - simulationCompilationCommand = _value; - optionChanged = true; - return 0; - } - - public int setSimulationExecutionCommand(String _value) { - simulationExecutionCommand = _value; - optionChanged = true; - return 0; - } - - public int setNbOfSimulationThreads(String _value) { - try { - nbOfSimulationThreads = Integer.decode(_value).intValue(); - } catch (Exception e) { - errorMessage = INVALID_ARGUMENT_NATURAL_VALUE; - return -1; - } - - if (nbOfSimulationThreads < 1) { - nbOfSimulationThreads = 1; - errorMessage = INVALID_ARGUMENT_NATURAL_VALUE; - return -1; - } - - return 0; - } - - public int setMinNbOfCPUs(String _value) { - try { - minNbOfCPUs = Integer.decode(_value).intValue(); - } catch (Exception e) { - errorMessage = INVALID_ARGUMENT_NATURAL_VALUE; - return -1; - } - - if (minNbOfCPUs < 1) { - minNbOfCPUs = 1; - errorMessage = INVALID_ARGUMENT_NATURAL_VALUE; - return -1; - } - - return 0; - } - - public int setMaxNbOfCPUs(String _value) { - try { - maxNbOfCPUs = Integer.decode(_value).intValue(); - } catch (Exception e) { - errorMessage = INVALID_ARGUMENT_NATURAL_VALUE; - return -1; - } - - if (maxNbOfCPUs < 1) { - maxNbOfCPUs = 1; - errorMessage = INVALID_ARGUMENT_NATURAL_VALUE; - return -1; - } - - return 0; - } - - public int setMinNbOfCoresPerCPU(String _value) { - try { - minNbOfCoresPerCPU = Integer.decode(_value).intValue(); - } catch (Exception e) { - errorMessage = INVALID_ARGUMENT_NATURAL_VALUE; - return -1; - } - - if (minNbOfCoresPerCPU < 1) { - minNbOfCoresPerCPU = 1; - errorMessage = INVALID_ARGUMENT_NATURAL_VALUE; - return -1; - } - - return 0; - } - - public int setMaxNbOfCoresPerCPU(String _value) { - try { - maxNbOfCoresPerCPU = Integer.decode(_value).intValue(); - } catch (Exception e) { - errorMessage = INVALID_ARGUMENT_NATURAL_VALUE; - return -1; - } - - if (maxNbOfCoresPerCPU < 1) { - maxNbOfCoresPerCPU = 1; - errorMessage = INVALID_ARGUMENT_NATURAL_VALUE; - return -1; - } - - return 0; - } - - public int setNbOfSimulationsPerMapping(String _value) { - try { - nbOfSimulationsPerMapping = Integer.decode(_value).intValue(); - } catch (Exception e) { - errorMessage = INVALID_ARGUMENT_NATURAL_VALUE; - return -1; - } - - if (nbOfSimulationsPerMapping < 1) { - nbOfSimulationsPerMapping = 1; - errorMessage = INVALID_ARGUMENT_NATURAL_VALUE; - return -1; - } - - return 0; - } - - public int setTap(String _value) { - _value = _value.trim(); - - int index = _value.indexOf(" "); - if (index == -1) { - return -1; - } - - String tapName = _value.substring(0, index).trim(); - String valueOfTap = _value.substring(index+1, _value.length()).trim(); - - for(int i=0; i<taps.length; i++) { - if (taps[i].toLowerCase().compareTo(tapName.toLowerCase()) ==0) { - try { - int intval = new Integer(valueOfTap).intValue(); - tapValues[i] = intval; - return 0; - } catch (Exception e) { - return -1; - } - } - } - - return -1; - } - - private boolean loadMapping(boolean _optimize) { - boolean ret = false; - //System.out.println("load"); - String inputData = FileUtils.loadFileData(mappingFile); - TMLMappingTextSpecification<TGComponent> spec = new TMLMappingTextSpecification<>("LoadedSpecification"); - ret = spec.makeTMLMapping(inputData, modelPath); - TraceManager.addDev("load ended"); - List<TMLError> warnings; - - if (!ret) { - TraceManager.addDev("Compilation:\n" + spec.printSummary()); - } - - if (ret) { - //System.out.println("Format OK"); - tmap = spec.getTMLMapping(); - tmlm = tmap.getTMLModeling(); - if (tmap==null || tmlm ==null){ - return false; - } - //System.out.println("\n\n*** TML Modeling *** \n"); - //TMLTextSpecification textspec = new TMLTextSpecification("toto"); - //String s = textspec.toTextFormat(tmlm); - //System.out.println(s); - - // Checking syntax - TraceManager.addDev("--- Checking syntax of the whole specification (TML, TARCHI, TMAP)---"); - TMLSyntaxChecking syntax = new TMLSyntaxChecking(tmap); - syntax.checkSyntax(); - if (syntax.hasErrors() > 0) { - TraceManager.addDev("Printing errors:"); - TraceManager.addDev(syntax.printErrors()); - return false; - } - - - TraceManager.addDev("Compilation:\n" + syntax.printSummary()); - - TraceManager.addDev("Compilation:\n" + spec.printSummary()); - - - if (_optimize) { - warnings = tmlm.optimize(); - TraceManager.addDev(tmlm.printSummary(warnings)); - } - //spec.toTextFormat(tmlm); - //System.out.println("TMLModeling=" + spec); - } - - return true; - } - - private boolean loadTaskModel(boolean _optimize) { - boolean ret = false; - //System.out.println("load"); - String inputData = FileUtils.loadFileData(taskModelFile); - TMLTextSpecification<TGComponent> tmlts = new TMLTextSpecification<>("LoadedTaskModel"); - ret = tmlts.makeTMLModeling(inputData); - TraceManager.addDev("Load of task model done"); - List<TMLError> warnings; - - if (!ret) { - TraceManager.addDev("Compilation:\n" + tmlts.printSummary()); - } - - if (ret) { - //System.out.println("Format OK"); - taskModel = tmlts.getTMLModeling(); - //System.out.println("\n\n*** TML Modeling *** \n"); - //TMLTextSpecification textspec = new TMLTextSpecification("toto"); - //String s = textspec.toTextFormat(tmlm); - //System.out.println(s); - - // Checking syntax - TraceManager.addDev("--- Checking syntax of the whole specification (TML, TARCHI, TMAP)---"); - TMLSyntaxChecking syntax = new TMLSyntaxChecking(taskModel); - syntax.checkSyntax(); - if (syntax.hasErrors() > 0) { - TraceManager.addDev("Printing errors:"); - TraceManager.addDev(syntax.printErrors()); - return false; - } - - - TraceManager.addDev("Compilation:\n" + syntax.printSummary()); - - TraceManager.addDev("Compilation:\n" + tmlts.printSummary()); - - - if (_optimize) { - warnings = tmlm.optimize(); - TraceManager.addDev(taskModel.printSummary(warnings)); - } - //spec.toTextFormat(tmlm); - //System.out.println("TMLModeling=" + spec); - } - - return true; - } - - public int setSimulationExplorationMinimumCommand(String _arguments) { - try { - simulationExplorationMinimumCommand = Integer.decode(_arguments).intValue(); - } catch (Exception e) { - errorMessage = INVALID_ARGUMENT_NATURAL_VALUE; - return -1; - } - return 0; - } - - public int setSimulationExplorationMinimumBranch(String _arguments) { - try { - simulationExplorationMinimumBranch = Integer.decode(_arguments).intValue(); - } catch (Exception e) { - errorMessage = INVALID_ARGUMENT_NATURAL_VALUE; - return -1; - } - return 0; - } - - public int setSimulationMaxCycle(String _arguments) { - try { - simulationMaxCycles = Integer.decode(_arguments).intValue(); - } catch (Exception e) { - errorMessage = INVALID_ARGUMENT_NATURAL_VALUE; - return -1; - } - return 0; - } - - public int setShowSimulatorRawOutput(String _arguments) { - if (_arguments.toLowerCase().compareTo("true") == 0) { - showSimulatorRawOutput = true; - return 0; - } - - if (_arguments.toLowerCase().compareTo("false") == 0) { - showSimulatorRawOutput = false; - return 0; - } - - return -1; - } - public int checkingDSEElements() { - if (pathToSimulator == null) { - errorMessage = PATH_TO_CODE; - return -1; - } - - if (pathToResults == null) { - errorMessage = PATH_TO_RESULTS; - return -1; - } - - - if (!outputVCD && !outputHTML && !outputTXT) { - errorMessage = NO_OUTPUT_SELECTED; - return -1; - } - - if (simulationCompilationCommand == null) { - errorMessage = SIMULATION_COMPILATION_COMMAND_NOT_SET; - return -1; - } - - - if (simulationExecutionCommand == null) { - errorMessage = SIMULATION_EXECUTION_COMMAND_NOT_SET; - return -1; - } - - return 0; - } - - public int checkingSimulationElements() { - if (pathToSimulator == null) { - errorMessage = PATH_TO_CODE; - return -1; - } - - if (pathToResults == null) { - errorMessage = PATH_TO_RESULTS; - return -1; - } - - if (mappingFile == null) { - errorMessage = PATH_TO_SOURCE; - return -1; - } - - if (!outputVCD && !outputHTML && !outputTXT) { - errorMessage = NO_OUTPUT_SELECTED; - return -1; - } - - if (simulationCompilationCommand == null) { - errorMessage = SIMULATION_COMPILATION_COMMAND_NOT_SET; - return -1; - } - - - if (simulationExecutionCommand == null) { - errorMessage = SIMULATION_EXECUTION_COMMAND_NOT_SET; - return -1; - } - - return 0; - } - - public int loadingModel(boolean _debug, boolean _optimize) { - if (optionChanged) { - TraceManager.addDev("Loading mapping"); - if (!loadMapping(_optimize)) { - errorMessage = LOAD_MAPPING_FAILED; - TraceManager.addDev("Loading of the mapping failed!!!!"); - return -1; - } - - // Generating code - TraceManager.addDev("\n\n\n**** Generating simulation code..."); - final IDiploSimulatorCodeGenerator map = DiploSimulatorFactory.INSTANCE.createCodeGenerator( tmap ); -// TML2MappingSystemC map = new TML2MappingSystemC(tmap); - - try { - map.generateSystemC(_debug, _optimize); - map.saveFile(pathToSimulator, "appmodel"); - } catch (Exception e) { - TraceManager.addDev("SystemC generation failed: " + e + " msg=" + e.getMessage()); - e.printStackTrace(); - return -1; - } - - // Compiling the code - makeCommand(simulationCompilationCommand + " " + pathToSimulator); - - optionChanged = false; - } - return 0; - } - - public int loadingTaskModel(boolean _debug, boolean _optimize) { - if (optionChanged) { - TraceManager.addDev("Loading mapping"); - if (!loadTaskModel(_optimize)) { - errorMessage = LOAD_TASKMODEL_FAILED; - TraceManager.addDev("Loading of the taks model failed!!!!"); - return -1; - } - } - return 0; - } - public int generateSecMapping(){ - return 0; - } - public int generateAndCompileMappingCode(TMLMapping<TGComponent> _tmlmap, boolean _debug, boolean _optimize) { - - // Generating code - TraceManager.addDev("\n\n\n**** Generating simulation code from mapping..."); - final IDiploSimulatorCodeGenerator map = DiploSimulatorFactory.INSTANCE.createCodeGenerator( _tmlmap ); - - try { - map.generateSystemC(_debug, _optimize); - map.saveFile(pathToSimulator, "appmodel"); - } catch (Exception e) { - System.out.println("SystemC generation failed: " + e + " msg=" + e.getMessage()); - e.printStackTrace(); - return -1; - } - - // Compiling the code - makeCommand(simulationCompilationCommand + " " + pathToSimulator); - - return 0; - } - - String prepareCommand() { - String cmd; - - cmd = pathToSimulator + simulationExecutionCommand; - - Vector<String> v = new Vector<String>(); - - if (outputVCD) { - v.add("7 0 " + pathToResults + "output$.vcd"); - } - if (outputHTML) { - v.add("7 1 " + pathToResults + "output$.html"); - } - if (outputTXT) { - v.add("7 2 " +pathToResults + "output$.txt"); - } - - if (simulationMaxCycles > -1) { - v.add("1 5 " + simulationMaxCycles); - } else { - v.add("1 0 "); - } - - if (recordResults) { - v.add("10 1 " + pathToResults + "benchmark$.xml"); - } - for (Integer[] latencyId: latencyIds){ - v.add("24 "+latencyId[0] + " " + latencyId[1]); - } - - if (v.size() > 0) { - int cpt = 0; - for (String s: v) { - if (cpt == 0) { - cmd += " -cmd \""; - } else { - cmd += ";"; - } - cmd += s; - cpt ++; - } - cmd += "\""; - } - - if (outputXML) { - cmd += " -oxml " + pathToResults + "output$.xml"; - } - - return cmd; - } - - public String putSimulationNbInCommand(String cmd, int value) { - String val = "" + value; - return Conversion.replaceAllString(cmd, "$", val); - } - - public int runSimulation(String _arguments, boolean _debug, boolean _optimize) { - // Checking for valid arguments - int nbOfSimulations; - try { - nbOfSimulations = Integer.decode(_arguments).intValue(); - } catch (Exception e) { - errorMessage = INVALID_ARGUMENT_NATURAL_VALUE; - return -1; - } - - int nbconfigured = nbOfSimulations; - - // Checking simulation Elements - int ret = checkingSimulationElements(); - if (ret != 0) { - return ret; - } - - // Preparing results - if (recordResults) { - if (results == null) { - results = new DSESimulationResult(); - } - } - - // Loading model - ret = loadingModel(_debug, _optimize); - if (ret != 0) { - return ret; - } - - // Executing the simulation - String cmd = prepareCommand(); - String tmp; - - long t0 = System.currentTimeMillis(); - double t; - double r; - t = nbconfigured; - - while(nbOfSimulations >0) { - tmp = putSimulationNbInCommand(cmd, simulationID); - r = nbOfSimulations; - progression = (int)(((t-r)/t)*100); - - makeCommand(tmp); - - if (recordResults) { - if (loadSimulationResult(simulationID) <0) { - return -1; - } - } - simulationID ++; - nbOfSimulations --; - } - - long t1 = System.currentTimeMillis(); - - if (recordResults) { - long l0 = (int)(Math.ceil((t1 - t0) / 1000)); - long l1 = (t1-t0) - (l0 * 1000); - results.addComment("#Set of " + nbconfigured + " simulations executed in " + l0 + "." + l1 + " s"); - } - return 0; - } - - public synchronized int increaseSimulationID() { - int tmp = simulationID; - simulationID ++; - return tmp; - } - - public int runParallelSimulation(String _arguments, boolean _debug, boolean _optimize) { - // Checking for valid arguments - try { - nbOfRemainingSimulation = Integer.decode(_arguments).intValue(); - } catch (Exception e) { - errorMessage = INVALID_ARGUMENT_NATURAL_VALUE; - return -1; - } - - int nbconfigured = nbOfRemainingSimulation; - totalNbOfSimulations = nbconfigured; - - // Checking simulation Elements - int ret = checkingSimulationElements(); - if (ret != 0) { - return ret; - } - - // Loading model - ret = loadingModel(_debug, _optimize); - if (ret != 0) { - return ret; - } - - // Preparing results - if (recordResults) { - if (results == null) { - results = new DSESimulationResult(); - } - } - - // Executing the simulation - simulationCmd = prepareCommand(); - - long t0 = System.currentTimeMillis(); - - Thread [] t = null; - int nb = nbOfSimulationThreads; - if (nb > 1) { - t = new Thread[nb-1]; - while(nb > 1) { - t[nbOfSimulationThreads-nb] = new Thread(this); - t[nbOfSimulationThreads-nb].start(); - nb --; - } - } - - run(); - - // Must wait for all threads to terminate - if (nbOfSimulationThreads > 1) { - nb = nbOfSimulationThreads; - - while(nb > 1) { - try { - t[nbOfSimulationThreads-nb].join(); - nb --; - } catch (Exception e) { - } - } - } - - long t1 = System.currentTimeMillis(); - - if (recordResults) { - long l0 = (int)(Math.ceil((t1 - t0) / 1000)); - long l1 = (t1-t0) - (l0 * 1000); - results.addComment("#Set of " + nbconfigured + " parallel simulations executed in " + l0 + "." + l1 + " s"); - } - - return 0; - } - - public void run() { - - TraceManager.addDev("Thread thread"); - String tmp; - int id; - - while(hasRemainingSimulations() > 0) { - id = increaseSimulationID(); - tmp = putSimulationNbInCommand(simulationCmd, id); - makeCommand(tmp); - - if (recordResults) { - if (loadSimulationResult(id) <0) { - return; - } - } - } - } - - private synchronized int hasRemainingSimulations() { - double total = (double)totalNbOfSimulations; - double remain = (double)nbOfRemainingSimulation; - progression = (int)(((total - remain)/total)*100); - - //System.out.println("progression = " + progression + " total=" + total + " remain=" + remain); - - if (nbOfRemainingSimulation == 0) { - return 0; - } - - int tmp = nbOfRemainingSimulation; - nbOfRemainingSimulation --; - return tmp; - } - public int replaceTapValues(double[] tap){ - if (tap.length!=tapValues.length){ - - return -1; - } - for (double i:tap){ - if (i>1 || i<-1){ - return -1; - } - } - tapValues = tap; - return 0; - } - - public int printAllResults(String _arguments, boolean _debug, boolean _optimize) { - TraceManager.addDev("Printing all results"); - String sres=""; - DSESimulationResult res; - - if (dsemapresults != null) { - int cpt = resultsID - dsemapresults.nbOfElements(); - for(int i=0; i<dsemapresults.nbOfElements(); i++) { - res = dsemapresults.getResults(i); - try { - sres = DSESimulationResult.getAllExplanationHeader() + "\n"; - sres += "#Mapping description: " + dsemapresults.getMapping(i).getSummaryTaskMapping() + "\n"; - sres += res.getAllComments() + "\n" + res.getAllResults(); - System.out.println("saving file " + pathToResults + "alldseresults_mapping" + cpt + ".txt"); - FileUtils.saveFile(pathToResults + "alldseresults_mapping" + cpt + ".txt", sres); - } catch (Exception e){ - TraceManager.addDev("Error when saving results file" + e.getMessage()); - return -1; - - } - cpt ++; - } - - - - - } else { - - if (results == null) { - TraceManager.addDev("No results"); - return -1; - } - - - // Must compute results - //results.computeResults(); - - //TraceManager.addDev("Results: #" + resultsID + "\n" + results.getWholeResults()); - - // Saving to file - try { - TraceManager.addDev(DSESimulationResult.getAllExplanationHeader()); - TraceManager.addDev("----\n" + results.getAllResults()); - FileUtils.saveFile(pathToResults + "allresults" + resultsID + ".txt", DSESimulationResult.getAllExplanationHeader() + "\n" + results.getAllComments() + "\n" + results.getAllResults()); - } catch (Exception e){ - TraceManager.addDev("Error when saving results file" + e.getMessage()); - return -1; - - } - } - return 0; - } - - public int printResultsSummary(String _arguments, boolean _debug, boolean _optimize) { - TraceManager.addDev("Computing results"); - - String sres; - DSESimulationResult res; - - if (dsemapresults != null) { - int cpt = resultsID - dsemapresults.nbOfElements(); - dsemapresults.computeSummaryResult(); - for(int i=0; i<dsemapresults.nbOfElements(); i++) { - - res = dsemapresults.getResults(i); - try { - sres = DSESimulationResult.getExplanationHeader() + "\n"; - sres += "#Mapping description: " + dsemapresults.getMapping(i).getSummaryTaskMapping() + "\n"; - sres += res.getAllComments() + "\n" + res.getWholeResults(); - FileUtils.saveFile(pathToResults + "summary_dseresults_ofmapping" + cpt + ".txt", sres); - } catch (Exception e){ - TraceManager.addDev("Error when saving results file" + e.getMessage()); - return -1; - - } - cpt ++; - } - StringBuffer sb = new StringBuffer("# Overall results\n"); - sb.append("#Mappings:\n" + dsemapresults.getDescriptionOfAllMappings() + "\n\n"); - - sb.append("\nNumber of cycles:\n"); - sb.append("Mapping with Highest Average Cycle duration: " + dsemapresults.getMappingWithHighestAverageCycleDuration() + "\n"); - sb.append("Mapping with Lowest Average Cycle duration: " + dsemapresults.getMappingWithLowestAverageCycleDuration() + "\n"); - - sb.append("Min Cycle duration: " + dsemapresults.getMinCycleDuration() + "\n"); - sb.append("Max Cycle duration: " + dsemapresults.getMaxCycleDuration() + "\n"); - - - sb.append("\nSimulation duration:\n"); - sb.append("Mapping with Highest min simulation duration: " + dsemapresults.getMappingWithHighestMinSimulationDuration() + "\n"); - sb.append("Mapping with Lowest min simulation duration: " + dsemapresults.getMappingWithLowestMinSimulationDuration() + "\n"); - - sb.append("Mapping with Highest Average simulation duration: " + dsemapresults.getMappingWithHighestAverageSimulationDuration() + "\n"); - sb.append("Mapping with Lowest Average simulation duration: " + dsemapresults.getMappingWithLowestAverageSimulationDuration() + "\n"); - - sb.append("Mapping with Highest max simulation duration: " + dsemapresults.getMappingWithHighestMaxSimulationDuration() + "\n"); - sb.append("Mapping with Lowest max simulation duration: " + dsemapresults.getMappingWithLowestMaxSimulationDuration() + "\n"); - - - - sb.append("\nCPUs:\n"); - sb.append("Mapping with Highest min CPU Usage: " + dsemapresults.getMappingWithHighestMinCPUUsage() + "\n"); - sb.append("Mapping with Lowest min CPU Usage: " + dsemapresults.getMappingWithLowestMinCPUUsage() + "\n"); - - sb.append("Mapping with Highest Average CPU Usage: " + dsemapresults.getMappingWithHighestAverageCPUUsage() + "\n"); - sb.append("Mapping with Lowest Average CPU Usage: " + dsemapresults.getMappingWithLowestAverageCPUUsage() + "\n"); - - sb.append("Mapping with Highest max CPU Usage: " + dsemapresults.getMappingWithHighestMaxCPUUsage() + "\n"); - sb.append("Mapping with Lowest max CPU Usage: " + dsemapresults.getMappingWithLowestMaxCPUUsage() + "\n"); - - - sb.append("\nBus:\n"); - sb.append("Mapping with Highest min Bus Usage: " + dsemapresults.getMappingWithHighestMinBusUsage() + "\n"); - sb.append("Mapping with Lowest min Bus Usage: " + dsemapresults.getMappingWithLowestMinBusUsage() + "\n"); - - sb.append("Mapping with Highest Average Bus Usage: " + dsemapresults.getMappingWithHighestAverageBusUsage() + "\n"); - sb.append("Mapping with Lowest Average Bus Usage: " + dsemapresults.getMappingWithLowestAverageCPUUsage() + "\n"); - - sb.append("Mapping with Highest max Bus Usage: " + dsemapresults.getMappingWithHighestMaxBusUsage() + "\n"); - sb.append("Mapping with Lowest max Bus Usage: " + dsemapresults.getMappingWithLowestMaxBusUsage() + "\n"); - - sb.append("\nContentions:\n"); - sb.append("Mapping with Highest min bus contention: " + dsemapresults.getMappingWithHighestMinBusContention() + "\n"); - sb.append("Mapping with Lowest min Bus contention: " + dsemapresults.getMappingWithLowestMinBusContention() + "\n"); - - sb.append("Mapping with Highest Average Bus contention: " + dsemapresults.getMappingWithHighestAverageBusUsage() + "\n"); - sb.append("Mapping with Lowest Average Bus contention: " + dsemapresults.getMappingWithLowestAverageCPUUsage() + "\n"); - - sb.append("Mapping with Highest max Bus contention: " + dsemapresults.getMappingWithHighestMaxBusUsage() + "\n"); - sb.append("Mapping with Lowest max Bus contention: " + dsemapresults.getMappingWithLowestMaxBusUsage() + "\n"); - - /*sb.append("\nSecurity:\n"); - sb.append("Mapping with Highest added security: " + dsemapresults.getMappingWithHighestAddedSecurity() + "\n"); - sb.append("Mapping with Lowest added security: " + dsemapresults.getMappingWithLowestAddedSecurity() + "\n"); - */ - - rankMappings(dsemapresults); - - sb.append("\nGrades: (Mapping#, grade)\n"); - int[] grades = dsemapresults.getGrades().clone(); - int j; - for(j=0; j<grades.length; j++) { - sb.append("(#" + j + ", " + grades[j] + ")" ); - } - sb.append("\n"); - - TraceManager.addDev("Ranking"); - sb.append("\nRanking (Rank, mapping, grade)\n"); - int[] index = new int[grades.length]; - for(j=0; j<grades.length; j++) { - index[j] = j; - } - - TraceManager.addDev("Ranking 0"); - - Conversion.quickSort(grades, 0, grades.length-1, index); - - TraceManager.addDev("Ranking 1"); - - for(j=grades.length-1; j>=0; j--) { - sb.append("(#" + (grades.length-j) + ", " + index[j] + ", " + grades[j]+ ") "); - } - - TraceManager.addDev("Ranking done"); - - - try { - overallResults=sb.toString(); - FileUtils.saveFile(pathToResults + "Overall_results_AllMappings_From_" + resultsID + ".txt", sb.toString()); - - } catch (Exception e){ - TraceManager.addDev("Error when saving results file" + e.getMessage()); - return -1; - - } - - sb = new StringBuffer(dsemapresults.makeHTMLTableOfResults(tapValues)); - - - try { - FileUtils.saveFile(pathToResults + "Overall_results_AllMappings_From_" + resultsID + ".html", sb.toString()); - } catch (Exception e){ - TraceManager.addDev("Error when saving results file" + e.getMessage()); - return -1; - - } - return 0; - - } else { - - if (results == null) { - TraceManager.addDev("No results"); - return -1; - } - - // Must compute results - results.computeResults(); - - TraceManager.addDev("Results: #" + resultsID + "\n" + results.getWholeResults()); - overallResults=results.getWholeResults(); - // Saving to file - try { - FileUtils.saveFile(pathToResults + "summary" + resultsID + ".txt", DSESimulationResult.getExplanationHeader() + "\n" + results.getAllComments() + "\n" + results.getWholeResults()); - } catch (Exception e){ - TraceManager.addDev("Error when saving results file"); - return -1; - - } - - return 0; - } - } - - public int resetResults(String _arguments) { - if (results == null) { - return 0; - } - - // Reinit results - results.reset(); - - resultsID ++; - return 0; - } - - public int runExplo(String _arguments, boolean _debug, boolean _optimize) { - - // Checking for valid arguments - /*int nbOfSimulations; - try { - nbOfSimulations = Integer.decode(_arguments).intValue(); - } catch (Exception e) { - errorMessage = INVALID_ARGUMENT_NATURAL_VALUE; - return -1; - }*/ - - if (pathToSimulator == null) { - errorMessage = PATH_TO_CODE; - return -1; - } - - if (pathToResults == null) { - errorMessage = PATH_TO_RESULTS; - return -1; - } - - if (mappingFile == null) { - errorMessage = PATH_TO_SOURCE; - return -1; - } - - /*if (!outputVCD && !outputHTML && !outputTXT) { - errorMessage = NO_OUTPUT_SELECTED; - return -1; - }*/ - - if (simulationCompilationCommand == null) { - errorMessage = SIMULATION_COMPILATION_COMMAND_NOT_SET; - return -1; - } - - - if (simulationExecutionCommand == null) { - errorMessage = SIMULATION_EXECUTION_COMMAND_NOT_SET; - return -1; - } - - - // Loading model - // Generating code - if (optionChanged) { - TraceManager.addDev("Loading mapping"); - if (!loadMapping(_optimize)) { - errorMessage = LOAD_MAPPING_FAILED; - TraceManager.addDev("Loading of the mapping faild!!!!"); - return -1; - } - - - TraceManager.addDev("\n\n\n**** Generating simulation code..."); - final IDiploSimulatorCodeGenerator map = DiploSimulatorFactory.INSTANCE.createCodeGenerator( tmap ); -// TML2MappingSystemC map = new TML2MappingSystemC(tmap); - try { - map.generateSystemC(_debug, _optimize); - map.saveFile(pathToSimulator, "appmodel"); - } catch (Exception e) { - TraceManager.addDev("SystemC generation failed: " + e + " msg=" + e.getMessage()); - e.printStackTrace(); - return -1; - } - - // Compiling the code - makeCommand(simulationCompilationCommand + " " + pathToSimulator); - - optionChanged = false; - } - - - // Executing the simulation - String cmd = pathToSimulator + simulationExecutionCommand + " -cmd \"1 7 " +simulationExplorationMinimumCommand + " " + simulationExplorationMinimumBranch + "\" -gpath " + pathToResults; - - makeCommand(cmd); - simulationID ++; - - return 0; - } - - public int runDSE(String _arguments, boolean _debug, boolean _optimize) { - int nbOfSimulations; - - if (nbOfSimulationsPerMapping < 1) { - nbOfSimulationsPerMapping = 1; - } - - // Checking simulation Elements - int ret = checkingDSEElements(); - if (ret != 0) { - return ret; - } - - // Checking simulation Elements - ret = checkingDSEElements(); - if (ret != 0) { - return ret; - } - - // Must generate all possible mappings. - // First : load the task model - if (!loadTaskModel(_optimize)) { - TraceManager.addDev("Could not load the task model"); - return -1; - } - - TraceManager.addDev("Task model loaded"); - - mappings = generateAllMappings(taskModel); - - if (mappings != null) { - TraceManager.addDev("Mapping generated"); - } else { - TraceManager.addDev("Mapping failure"); - return -1; - } - - int cpt = 0; - /*for(TMLMapping tmla: mappings) { - TraceManager.addDev("map " + cpt + ": " + tmla.getSummaryTaskMapping()); - cpt ++; - }*/ - - // For each maping, generate the simulation code - cpt = 0; - if (recordResults) { - if (dsemapresults == null) { - dsemapresults = new DSEMappingSimulationResults(); - } - } - - for(TMLMapping<TGComponent> tmla: mappings) { - TraceManager.addDev("Handling mapping #" + cpt); - progression = cpt * 100 / (mappings.size()); - - cpt ++; - - if (generateAndCompileMappingCode(tmla, _debug, _optimize) >= 0) { - if (recordResults) { - results = new DSESimulationResult(); - resultsID ++; - } - - //System.out.println("After Current TML Mapping: " + tmla.getSummaryTaskMapping()); - - dsemapresults.addElement("Mapping #" + (cpt-1), results, tmla); - nbOfSimulations = nbOfSimulationsPerMapping; - // Executing the simulation - String cmd = prepareCommand(); - String tmp; - - //long t0 = System.currentTimeMillis(); - - while(nbOfSimulations >0) { - tmp = putSimulationNbInCommand(cmd, simulationID); - TraceManager.addDev("Executing: " + tmp); - makeCommand(tmp); - - if (recordResults) { - if (loadSimulationResult(simulationID) <0) { - return -1; - } - } - simulationID ++; - nbOfSimulations --; - } - } else { - return -1; - } - - if (addSecurity){ - System.out.println("ADDING SECURITY TO MAPPING " +(cpt-1)); - - TMLArchiPanel newArch = drawMapping(tmla, "securedMapping"+(cpt-1)); - GTMLModeling gtml =new GTMLModeling(newArch, true); - tmla = gtml.translateToTMLMapping(); -// tmla.tmlap = tmlap; - // tmlcdp = (TMLComponentDesignPanel) mainGUI.tabs.get(0); - // tmla.setTMLDesignPanel(tmlcdp); - // System.out.println("tmlcdp " + tmlcdp); - // - //Repeat for secured mapping - TMLMapping<TGComponent> secMapping = mainGUI.gtm.autoSecure(mainGUI, "mapping" +(cpt-1),tmla, newArch, encComp, overhead, decComp,true,false,false); - - //Run simulations on this mapping - if (generateAndCompileMappingCode(secMapping, _debug, _optimize) >= 0) { - System.out.println("GENERATING>>>"); - if (recordResults) { - results = new DSESimulationResult(); - resultsID ++; - } - - //System.out.println("After Current TML Mapping: " + tmla.getSummaryTaskMapping()); - - dsemapresults.addElement("Secured Mapping #" + (cpt-1), results, secMapping); - nbOfSimulations = nbOfSimulationsPerMapping; - // Executing the simulation - String cmd = prepareCommand(); - String tmp; - - //long t0 = System.currentTimeMillis(); - - while(nbOfSimulations >0) { - tmp = putSimulationNbInCommand(cmd, simulationID); - TraceManager.addDev("Executing: " + tmp); - makeCommand(tmp); - - if (recordResults) { - if (loadSimulationResult(simulationID) <0) { - return -1; - } - } - simulationID ++; - nbOfSimulations --; - } - } else { - return -1; - } - } - } - return 0; - } + + private String errorMessage; + + private final String PATH_TO_CODE = "No directory selected for putting the generated code"; + private final String PATH_TO_RESULTS = "No directory selected for putting the results"; + private final String PATH_TO_SOURCE = "No source model selected"; + private final String NO_OUTPUT_SELECTED = "No format ofr the output has been selected"; + private final String LOAD_MAPPING_FAILED = "Loading of the mapping failed"; + private final String LOAD_TASKMODEL_FAILED = "Loading of the task model failed"; + private final String SIMULATION_COMPILATION_COMMAND_NOT_SET = "Compilation command missing"; + private final String SIMULATION_EXECUTION_COMMAND_NOT_SET = "Command to start simulation was noit set"; + private final String INVALID_ARGUMENT_NATURAL_VALUE = "The argument is execpted to a be natural value"; + + private String simulationCompilationCommand = null; + private String simulationExecutionCommand = null; + + private String pathToSimulator; + private String pathToResults; + + public String overallResults; + + private File mappingFile = null; + private String modelPath = ""; + + private File taskModelFile = null; + + private boolean outputVCD = false; + private boolean outputHTML = true; + private boolean outputTXT = false; + private boolean outputXML = false; + + private boolean recordResults = false; + + private boolean showSimulatorRawOutput = false; + + public TMLComponentDesignPanel tmlcdp; + public TMLArchiPanel tmlap; + + private TMLMapping<TGComponent> tmap; + private TMLModeling<TGComponent> tmlm; + + // private TMLModeling stmlm; + + private boolean optionChanged = true; + + private int simulationID = 0; + private int resultsID = 0; + private int dseID = 0; + + private int simulationExplorationMinimumCommand = 100; + private int simulationExplorationMinimumBranch = 100; + + + private int simulationMaxCycles = -1; + + private int nbOfSimulationThreads = 1; + + //Security + public boolean addSecurity=false; + public String encComp="100"; + public String decComp="100"; + public String overhead="0"; + public String nonceSize="0"; + + // DSE + private int minNbOfCPUs = 1; + private int maxNbOfCPUs = 2; + private int minNbOfCoresPerCPU = 1; + private int maxNbOfCoresPerCPU = 2; + private int nbOfSimulationsPerMapping = 1; + private TMLModeling<TGComponent> taskModel = null; + // private TMLModeling secModel = null; + private Vector<TMLMapping<TGComponent>> mappings; + private DSEMappingSimulationResults dsemapresults; + List<Integer[]> latencyIds =new ArrayList<Integer[]>(); + public MainGUI mainGUI; + // Taps + private static String[] taps = {"MinSimulationDuration", "AverageSimulationDuration", + "MaxSimulationDuration", + "ArchitectureComplexity", + "MinCPUUsage", "AverageCPUUsage", "MaxCPUUsage", + "MinBusUsage", "AverageBusUsage", "MaxBusUsage", + "MinBusContention", "AverageBusContentione", "MaxBusContention"}; + + /* private int[] tapValues = {1, 1, 1, + 1, // 3 + 1, -10, 1,//4, 5, 6 + 1, 1, 1, // 7, 8, 9 + 1, 1, 1 // 10, 11, 12 + }; */ + + double[] tapValues={1.0,1.0,1.0, 1.0, 1.0, -10.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0}; + + + public static final int LONG_TYPE = 0; + public static final int DOUBLE_TYPE = 1; + + public static int[] tapType = {LONG_TYPE, DOUBLE_TYPE, LONG_TYPE, + LONG_TYPE, + DOUBLE_TYPE, DOUBLE_TYPE, DOUBLE_TYPE, + DOUBLE_TYPE, DOUBLE_TYPE, DOUBLE_TYPE, + LONG_TYPE, DOUBLE_TYPE, LONG_TYPE + }; + + + private DSESimulationResult results; + + private String simulationCmd; + private int nbOfRemainingSimulation; + private int totalNbOfSimulations; + + private int progression = 0; + + //private int nbOfSimulations; + + public DSEConfiguration() { + + } + + public String getErrorMessage() { + return errorMessage; + } + + public int setModelPath(String _path) { + // Trying to read the file + modelPath = _path; + optionChanged = true; + + return 0; + } + + public int setMappingFile(String _fileName) { + // Trying to read the file + mappingFile = new File(modelPath + _fileName); + if (!FileUtils.checkFileForOpen(mappingFile)) { + optionChanged = true; + mappingFile = null; + return -1; + } + + + return 0; + } + + public int setTaskModelFile(String _fileName) { + // Trying to read the file + taskModelFile = new File(modelPath + _fileName); + if (!FileUtils.checkFileForOpen(taskModelFile)) { + optionChanged = true; + taskModelFile = null; + return -1; + } + + return 0; + } + + public int setOutputVCD(String _value) { + if (_value.toLowerCase().compareTo("true") == 0) { + outputVCD = true; + optionChanged = true; + return 0; + } + + if (_value.toLowerCase().compareTo("false") == 0) { + outputVCD = false; + optionChanged = true; + return 0; + } + + return -1; + } + + public int setOutputHTML(String _value) { + if (_value.toLowerCase().compareTo("true") == 0) { + outputHTML = true; + optionChanged = true; + return 0; + } + + if (_value.toLowerCase().compareTo("false") == 0) { + outputHTML = false; + optionChanged = true; + return 0; + } + + return -1; + } + + public int setOutputTXT(String _value) { + if (_value.toLowerCase().compareTo("true") == 0) { + outputTXT = true; + optionChanged = true; + return 0; + } + + if (_value.toLowerCase().compareTo("false") == 0) { + outputTXT = false; + optionChanged = true; + return 0; + } + + return -1; + } + + public int setOutputXML(String _value) { + if (_value.toLowerCase().compareTo("true") == 0) { + outputXML = true; + optionChanged = true; + return 0; + } + + if (_value.toLowerCase().compareTo("false") == 0) { + outputXML = false; + optionChanged = true; + return 0; + } + + return -1; + } + + public int setRecordResults(String _value) { + if (_value.toLowerCase().compareTo("true") == 0) { + recordResults = true; + optionChanged = true; + return 0; + } + + if (_value.toLowerCase().compareTo("false") == 0) { + recordResults = false; + optionChanged = true; + return 0; + } + + return -1; + } + + public int setPathToSimulator(String _value) { + pathToSimulator = _value; + optionChanged = true; + return 0; + } + + public int setPathToResults(String _value) { + pathToResults = _value; + optionChanged = true; + return 0; + } + + public int setSimulationCompilationCommand(String _value) { + simulationCompilationCommand = _value; + optionChanged = true; + return 0; + } + + public int setSimulationExecutionCommand(String _value) { + simulationExecutionCommand = _value; + optionChanged = true; + return 0; + } + + public int setNbOfSimulationThreads(String _value) { + try { + nbOfSimulationThreads = Integer.decode(_value).intValue(); + } catch (Exception e) { + errorMessage = INVALID_ARGUMENT_NATURAL_VALUE; + return -1; + } + + if (nbOfSimulationThreads < 1) { + nbOfSimulationThreads = 1; + errorMessage = INVALID_ARGUMENT_NATURAL_VALUE; + return -1; + } + + return 0; + } + + public int setMinNbOfCPUs(String _value) { + try { + minNbOfCPUs = Integer.decode(_value).intValue(); + } catch (Exception e) { + errorMessage = INVALID_ARGUMENT_NATURAL_VALUE; + return -1; + } + + if (minNbOfCPUs < 1) { + minNbOfCPUs = 1; + errorMessage = INVALID_ARGUMENT_NATURAL_VALUE; + return -1; + } + + return 0; + } + + public int setMaxNbOfCPUs(String _value) { + try { + maxNbOfCPUs = Integer.decode(_value).intValue(); + } catch (Exception e) { + errorMessage = INVALID_ARGUMENT_NATURAL_VALUE; + return -1; + } + + if (maxNbOfCPUs < 1) { + maxNbOfCPUs = 1; + errorMessage = INVALID_ARGUMENT_NATURAL_VALUE; + return -1; + } + + return 0; + } + + public int setMinNbOfCoresPerCPU(String _value) { + try { + minNbOfCoresPerCPU = Integer.decode(_value).intValue(); + } catch (Exception e) { + errorMessage = INVALID_ARGUMENT_NATURAL_VALUE; + return -1; + } + + if (minNbOfCoresPerCPU < 1) { + minNbOfCoresPerCPU = 1; + errorMessage = INVALID_ARGUMENT_NATURAL_VALUE; + return -1; + } + + return 0; + } + + public int setMaxNbOfCoresPerCPU(String _value) { + try { + maxNbOfCoresPerCPU = Integer.decode(_value).intValue(); + } catch (Exception e) { + errorMessage = INVALID_ARGUMENT_NATURAL_VALUE; + return -1; + } + + if (maxNbOfCoresPerCPU < 1) { + maxNbOfCoresPerCPU = 1; + errorMessage = INVALID_ARGUMENT_NATURAL_VALUE; + return -1; + } + + return 0; + } + + public int setNbOfSimulationsPerMapping(String _value) { + try { + nbOfSimulationsPerMapping = Integer.decode(_value).intValue(); + } catch (Exception e) { + errorMessage = INVALID_ARGUMENT_NATURAL_VALUE; + return -1; + } + + if (nbOfSimulationsPerMapping < 1) { + nbOfSimulationsPerMapping = 1; + errorMessage = INVALID_ARGUMENT_NATURAL_VALUE; + return -1; + } + + return 0; + } + + public int setTap(String _value) { + _value = _value.trim(); + + int index = _value.indexOf(" "); + if (index == -1) { + return -1; + } + + String tapName = _value.substring(0, index).trim(); + String valueOfTap = _value.substring(index+1, _value.length()).trim(); + + for(int i=0; i<taps.length; i++) { + if (taps[i].toLowerCase().compareTo(tapName.toLowerCase()) ==0) { + try { + int intval = new Integer(valueOfTap).intValue(); + tapValues[i] = intval; + return 0; + } catch (Exception e) { + return -1; + } + } + } + + return -1; + } + + private boolean loadMapping(boolean _optimize) { + boolean ret = false; + //System.out.println("load"); + String inputData = FileUtils.loadFileData(mappingFile); + TMLMappingTextSpecification<TGComponent> spec = new TMLMappingTextSpecification<>("LoadedSpecification"); + ret = spec.makeTMLMapping(inputData, modelPath); + TraceManager.addDev("load ended"); + List<TMLError> warnings; + + if (!ret) { + TraceManager.addDev("Compilation:\n" + spec.printSummary()); + } + + if (ret) { + //System.out.println("Format OK"); + tmap = spec.getTMLMapping(); + tmlm = tmap.getTMLModeling(); + if (tmap==null || tmlm ==null){ + return false; + } + //System.out.println("\n\n*** TML Modeling *** \n"); + //TMLTextSpecification textspec = new TMLTextSpecification("toto"); + //String s = textspec.toTextFormat(tmlm); + //System.out.println(s); + + // Checking syntax + TraceManager.addDev("--- Checking syntax of the whole specification (TML, TARCHI, TMAP)---"); + TMLSyntaxChecking syntax = new TMLSyntaxChecking(tmap); + syntax.checkSyntax(); + if (syntax.hasErrors() > 0) { + TraceManager.addDev("Printing errors:"); + TraceManager.addDev(syntax.printErrors()); + return false; + } + + + TraceManager.addDev("Compilation:\n" + syntax.printSummary()); + + TraceManager.addDev("Compilation:\n" + spec.printSummary()); + + + if (_optimize) { + warnings = tmlm.optimize(); + TraceManager.addDev(tmlm.printSummary(warnings)); + } + //spec.toTextFormat(tmlm); + //System.out.println("TMLModeling=" + spec); + } + + return true; + } + + private boolean loadTaskModel(boolean _optimize) { + boolean ret = false; + //System.out.println("load"); + String inputData = FileUtils.loadFileData(taskModelFile); + TMLTextSpecification<TGComponent> tmlts = new TMLTextSpecification<>("LoadedTaskModel"); + ret = tmlts.makeTMLModeling(inputData); + TraceManager.addDev("Load of task model done"); + List<TMLError> warnings; + + if (!ret) { + TraceManager.addDev("Compilation:\n" + tmlts.printSummary()); + } + + if (ret) { + //System.out.println("Format OK"); + taskModel = tmlts.getTMLModeling(); + //System.out.println("\n\n*** TML Modeling *** \n"); + //TMLTextSpecification textspec = new TMLTextSpecification("toto"); + //String s = textspec.toTextFormat(tmlm); + //System.out.println(s); + + // Checking syntax + TraceManager.addDev("--- Checking syntax of the whole specification (TML, TARCHI, TMAP)---"); + TMLSyntaxChecking syntax = new TMLSyntaxChecking(taskModel); + syntax.checkSyntax(); + if (syntax.hasErrors() > 0) { + TraceManager.addDev("Printing errors:"); + TraceManager.addDev(syntax.printErrors()); + return false; + } + + + TraceManager.addDev("Compilation:\n" + syntax.printSummary()); + + TraceManager.addDev("Compilation:\n" + tmlts.printSummary()); + + + if (_optimize) { + warnings = tmlm.optimize(); + TraceManager.addDev(taskModel.printSummary(warnings)); + } + //spec.toTextFormat(tmlm); + //System.out.println("TMLModeling=" + spec); + } + + return true; + } + + public int setSimulationExplorationMinimumCommand(String _arguments) { + try { + simulationExplorationMinimumCommand = Integer.decode(_arguments).intValue(); + } catch (Exception e) { + errorMessage = INVALID_ARGUMENT_NATURAL_VALUE; + return -1; + } + return 0; + } + + public int setSimulationExplorationMinimumBranch(String _arguments) { + try { + simulationExplorationMinimumBranch = Integer.decode(_arguments).intValue(); + } catch (Exception e) { + errorMessage = INVALID_ARGUMENT_NATURAL_VALUE; + return -1; + } + return 0; + } + + public int setSimulationMaxCycle(String _arguments) { + try { + simulationMaxCycles = Integer.decode(_arguments).intValue(); + } catch (Exception e) { + errorMessage = INVALID_ARGUMENT_NATURAL_VALUE; + return -1; + } + return 0; + } + + public int setShowSimulatorRawOutput(String _arguments) { + if (_arguments.toLowerCase().compareTo("true") == 0) { + showSimulatorRawOutput = true; + return 0; + } + + if (_arguments.toLowerCase().compareTo("false") == 0) { + showSimulatorRawOutput = false; + return 0; + } + + return -1; + } + public int checkingDSEElements() { + if (pathToSimulator == null) { + errorMessage = PATH_TO_CODE; + return -1; + } + + if (pathToResults == null) { + errorMessage = PATH_TO_RESULTS; + return -1; + } + + + if (!outputVCD && !outputHTML && !outputTXT) { + errorMessage = NO_OUTPUT_SELECTED; + return -1; + } + + if (simulationCompilationCommand == null) { + errorMessage = SIMULATION_COMPILATION_COMMAND_NOT_SET; + return -1; + } + + + if (simulationExecutionCommand == null) { + errorMessage = SIMULATION_EXECUTION_COMMAND_NOT_SET; + return -1; + } + + return 0; + } + + public int checkingSimulationElements() { + if (pathToSimulator == null) { + errorMessage = PATH_TO_CODE; + return -1; + } + + if (pathToResults == null) { + errorMessage = PATH_TO_RESULTS; + return -1; + } + + if (mappingFile == null) { + errorMessage = PATH_TO_SOURCE; + return -1; + } + + if (!outputVCD && !outputHTML && !outputTXT) { + errorMessage = NO_OUTPUT_SELECTED; + return -1; + } + + if (simulationCompilationCommand == null) { + errorMessage = SIMULATION_COMPILATION_COMMAND_NOT_SET; + return -1; + } + + + if (simulationExecutionCommand == null) { + errorMessage = SIMULATION_EXECUTION_COMMAND_NOT_SET; + return -1; + } + + return 0; + } + + public int loadingModel(boolean _debug, boolean _optimize) { + if (optionChanged) { + TraceManager.addDev("Loading mapping"); + if (!loadMapping(_optimize)) { + errorMessage = LOAD_MAPPING_FAILED; + TraceManager.addDev("Loading of the mapping failed!!!!"); + return -1; + } + + // Generating code + TraceManager.addDev("\n\n\n**** Generating simulation code..."); + final IDiploSimulatorCodeGenerator map = DiploSimulatorFactory.INSTANCE.createCodeGenerator( tmap ); + // TML2MappingSystemC map = new TML2MappingSystemC(tmap); + + try { + map.generateSystemC(_debug, _optimize); + map.saveFile(pathToSimulator, "appmodel"); + } catch (Exception e) { + TraceManager.addDev("SystemC generation failed: " + e + " msg=" + e.getMessage()); + e.printStackTrace(); + return -1; + } + + // Compiling the code + makeCommand(simulationCompilationCommand + " " + pathToSimulator); + + optionChanged = false; + } + return 0; + } + + public int loadingTaskModel(boolean _debug, boolean _optimize) { + if (optionChanged) { + TraceManager.addDev("Loading mapping"); + if (!loadTaskModel(_optimize)) { + errorMessage = LOAD_TASKMODEL_FAILED; + TraceManager.addDev("Loading of the taks model failed!!!!"); + return -1; + } + } + return 0; + } + public int generateSecMapping(){ + return 0; + } + public int generateAndCompileMappingCode(TMLMapping<TGComponent> _tmlmap, boolean _debug, boolean _optimize) { + + // Generating code + TraceManager.addDev("\n\n\n**** Generating simulation code from mapping..."); + final IDiploSimulatorCodeGenerator map = DiploSimulatorFactory.INSTANCE.createCodeGenerator( _tmlmap ); + + try { + map.generateSystemC(_debug, _optimize); + map.saveFile(pathToSimulator, "appmodel"); + } catch (Exception e) { + System.out.println("SystemC generation failed: " + e + " msg=" + e.getMessage()); + e.printStackTrace(); + return -1; + } + + // Compiling the code + makeCommand(simulationCompilationCommand + " " + pathToSimulator); + + return 0; + } + + String prepareCommand() { + String cmd; + + cmd = pathToSimulator + simulationExecutionCommand; + + Vector<String> v = new Vector<String>(); + + if (outputVCD) { + v.add("7 0 " + pathToResults + "output$.vcd"); + } + if (outputHTML) { + v.add("7 1 " + pathToResults + "output$.html"); + } + if (outputTXT) { + v.add("7 2 " +pathToResults + "output$.txt"); + } + + if (simulationMaxCycles > -1) { + v.add("1 5 " + simulationMaxCycles); + } else { + v.add("1 0 "); + } + + if (recordResults) { + v.add("10 1 " + pathToResults + "benchmark$.xml"); + } + for (Integer[] latencyId: latencyIds){ + v.add("24 "+latencyId[0] + " " + latencyId[1]); + } + + if (v.size() > 0) { + int cpt = 0; + for (String s: v) { + if (cpt == 0) { + cmd += " -cmd \""; + } else { + cmd += ";"; + } + cmd += s; + cpt ++; + } + cmd += "\""; + } + + if (outputXML) { + cmd += " -oxml " + pathToResults + "output$.xml"; + } + + return cmd; + } + + public String putSimulationNbInCommand(String cmd, int value) { + String val = "" + value; + return Conversion.replaceAllString(cmd, "$", val); + } + + public int runSimulation(String _arguments, boolean _debug, boolean _optimize) { + // Checking for valid arguments + int nbOfSimulations; + try { + nbOfSimulations = Integer.decode(_arguments).intValue(); + } catch (Exception e) { + errorMessage = INVALID_ARGUMENT_NATURAL_VALUE; + return -1; + } + + int nbconfigured = nbOfSimulations; + + // Checking simulation Elements + int ret = checkingSimulationElements(); + if (ret != 0) { + return ret; + } + + // Preparing results + if (recordResults) { + if (results == null) { + results = new DSESimulationResult(); + } + } + + // Loading model + ret = loadingModel(_debug, _optimize); + if (ret != 0) { + return ret; + } + + // Executing the simulation + String cmd = prepareCommand(); + String tmp; + + long t0 = System.currentTimeMillis(); + double t; + double r; + t = nbconfigured; + + while(nbOfSimulations >0) { + tmp = putSimulationNbInCommand(cmd, simulationID); + r = nbOfSimulations; + progression = (int)(((t-r)/t)*100); + + makeCommand(tmp); + + if (recordResults) { + if (loadSimulationResult(simulationID) <0) { + return -1; + } + } + simulationID ++; + nbOfSimulations --; + } + + long t1 = System.currentTimeMillis(); + + if (recordResults) { + long l0 = (int)(Math.ceil((t1 - t0) / 1000)); + long l1 = (t1-t0) - (l0 * 1000); + results.addComment("#Set of " + nbconfigured + " simulations executed in " + l0 + "." + l1 + " s"); + } + return 0; + } + + public synchronized int increaseSimulationID() { + int tmp = simulationID; + simulationID ++; + return tmp; + } + + public int runParallelSimulation(String _arguments, boolean _debug, boolean _optimize) { + // Checking for valid arguments + try { + nbOfRemainingSimulation = Integer.decode(_arguments).intValue(); + } catch (Exception e) { + errorMessage = INVALID_ARGUMENT_NATURAL_VALUE; + return -1; + } + + int nbconfigured = nbOfRemainingSimulation; + totalNbOfSimulations = nbconfigured; + + // Checking simulation Elements + int ret = checkingSimulationElements(); + if (ret != 0) { + return ret; + } + + // Loading model + ret = loadingModel(_debug, _optimize); + if (ret != 0) { + return ret; + } + + // Preparing results + if (recordResults) { + if (results == null) { + results = new DSESimulationResult(); + } + } + + // Executing the simulation + simulationCmd = prepareCommand(); + + long t0 = System.currentTimeMillis(); + + Thread [] t = null; + int nb = nbOfSimulationThreads; + if (nb > 1) { + t = new Thread[nb-1]; + while(nb > 1) { + t[nbOfSimulationThreads-nb] = new Thread(this); + t[nbOfSimulationThreads-nb].start(); + nb --; + } + } + + run(); + + // Must wait for all threads to terminate + if (nbOfSimulationThreads > 1) { + nb = nbOfSimulationThreads; + + while(nb > 1) { + try { + t[nbOfSimulationThreads-nb].join(); + nb --; + } catch (Exception e) { + } + } + } + + long t1 = System.currentTimeMillis(); + + if (recordResults) { + long l0 = (int)(Math.ceil((t1 - t0) / 1000)); + long l1 = (t1-t0) - (l0 * 1000); + results.addComment("#Set of " + nbconfigured + " parallel simulations executed in " + l0 + "." + l1 + " s"); + } + + return 0; + } + + public void run() { + + TraceManager.addDev("Thread thread"); + String tmp; + int id; + + while(hasRemainingSimulations() > 0) { + id = increaseSimulationID(); + tmp = putSimulationNbInCommand(simulationCmd, id); + makeCommand(tmp); + + if (recordResults) { + if (loadSimulationResult(id) <0) { + return; + } + } + } + } + + private synchronized int hasRemainingSimulations() { + double total = (double)totalNbOfSimulations; + double remain = (double)nbOfRemainingSimulation; + progression = (int)(((total - remain)/total)*100); + + //System.out.println("progression = " + progression + " total=" + total + " remain=" + remain); + + if (nbOfRemainingSimulation == 0) { + return 0; + } + + int tmp = nbOfRemainingSimulation; + nbOfRemainingSimulation --; + return tmp; + } + + public int replaceTapValues(double[] tap){ + if (tap.length!=tapValues.length){ + + return -1; + } + for (double i:tap){ + if (i>1 || i<-1){ + return -1; + } + } + tapValues = tap; + return 0; + } + + public int printAllResults(String _arguments, boolean _debug, boolean _optimize) { + TraceManager.addDev("Printing all results"); + String sres=""; + DSESimulationResult res; + + if (dsemapresults != null) { + int cpt = resultsID - dsemapresults.nbOfElements(); + for(int i=0; i<dsemapresults.nbOfElements(); i++) { + res = dsemapresults.getResults(i); + try { + sres = DSESimulationResult.getAllExplanationHeader() + "\n"; + sres += "#Mapping description: " + dsemapresults.getMapping(i).getSummaryTaskMapping() + "\n"; + sres += res.getAllComments() + "\n" + res.getAllResults(); + System.out.println("saving file " + pathToResults + "alldseresults_mapping" + cpt + ".txt"); + FileUtils.saveFile(pathToResults + "alldseresults_mapping" + cpt + ".txt", sres); + } catch (Exception e){ + TraceManager.addDev("Error when saving results file" + e.getMessage()); + return -1; + + } + cpt ++; + } + + + + + } else { + + if (results == null) { + TraceManager.addDev("No results"); + return -1; + } + + + // Must compute results + //results.computeResults(); + + //TraceManager.addDev("Results: #" + resultsID + "\n" + results.getWholeResults()); + + // Saving to file + try { + TraceManager.addDev(DSESimulationResult.getAllExplanationHeader()); + TraceManager.addDev("----\n" + results.getAllResults()); + FileUtils.saveFile(pathToResults + "allresults" + resultsID + ".txt", DSESimulationResult.getAllExplanationHeader() + "\n" + results.getAllComments() + "\n" + results.getAllResults()); + } catch (Exception e){ + TraceManager.addDev("Error when saving results file" + e.getMessage()); + return -1; + + } + } + return 0; + } + + public int printResultsSummary(String _arguments, boolean _debug, boolean _optimize) { + TraceManager.addDev("Computing results"); + + String sres; + DSESimulationResult res; + + if (dsemapresults != null) { + int cpt = resultsID - dsemapresults.nbOfElements(); + dsemapresults.computeSummaryResult(); + for(int i=0; i<dsemapresults.nbOfElements(); i++) { + + res = dsemapresults.getResults(i); + try { + sres = DSESimulationResult.getExplanationHeader() + "\n"; + sres += "#Mapping description: " + dsemapresults.getMapping(i).getSummaryTaskMapping() + "\n"; + sres += res.getAllComments() + "\n" + res.getWholeResults(); + FileUtils.saveFile(pathToResults + "summary_dseresults_ofmapping" + cpt + ".txt", sres); + } catch (Exception e){ + TraceManager.addDev("Error when saving results file" + e.getMessage()); + return -1; + + } + cpt ++; + } + StringBuffer sb = new StringBuffer("# Overall results\n"); + sb.append("#Mappings:\n" + dsemapresults.getDescriptionOfAllMappings() + "\n\n"); + + sb.append("\nNumber of cycles:\n"); + sb.append("Mapping with Highest Average Cycle duration: " + dsemapresults.getMappingWithHighestAverageCycleDuration() + "\n"); + sb.append("Mapping with Lowest Average Cycle duration: " + dsemapresults.getMappingWithLowestAverageCycleDuration() + "\n"); + + sb.append("Min Cycle duration: " + dsemapresults.getMinCycleDuration() + "\n"); + sb.append("Max Cycle duration: " + dsemapresults.getMaxCycleDuration() + "\n"); + + + sb.append("\nSimulation duration:\n"); + sb.append("Mapping with Highest min simulation duration: " + dsemapresults.getMappingWithHighestMinSimulationDuration() + "\n"); + sb.append("Mapping with Lowest min simulation duration: " + dsemapresults.getMappingWithLowestMinSimulationDuration() + "\n"); + + sb.append("Mapping with Highest Average simulation duration: " + dsemapresults.getMappingWithHighestAverageSimulationDuration() + "\n"); + sb.append("Mapping with Lowest Average simulation duration: " + dsemapresults.getMappingWithLowestAverageSimulationDuration() + "\n"); + + sb.append("Mapping with Highest max simulation duration: " + dsemapresults.getMappingWithHighestMaxSimulationDuration() + "\n"); + sb.append("Mapping with Lowest max simulation duration: " + dsemapresults.getMappingWithLowestMaxSimulationDuration() + "\n"); + + + + sb.append("\nCPUs:\n"); + sb.append("Mapping with Highest min CPU Usage: " + dsemapresults.getMappingWithHighestMinCPUUsage() + "\n"); + sb.append("Mapping with Lowest min CPU Usage: " + dsemapresults.getMappingWithLowestMinCPUUsage() + "\n"); + + sb.append("Mapping with Highest Average CPU Usage: " + dsemapresults.getMappingWithHighestAverageCPUUsage() + "\n"); + sb.append("Mapping with Lowest Average CPU Usage: " + dsemapresults.getMappingWithLowestAverageCPUUsage() + "\n"); + + sb.append("Mapping with Highest max CPU Usage: " + dsemapresults.getMappingWithHighestMaxCPUUsage() + "\n"); + sb.append("Mapping with Lowest max CPU Usage: " + dsemapresults.getMappingWithLowestMaxCPUUsage() + "\n"); + + + sb.append("\nBus:\n"); + sb.append("Mapping with Highest min Bus Usage: " + dsemapresults.getMappingWithHighestMinBusUsage() + "\n"); + sb.append("Mapping with Lowest min Bus Usage: " + dsemapresults.getMappingWithLowestMinBusUsage() + "\n"); + + sb.append("Mapping with Highest Average Bus Usage: " + dsemapresults.getMappingWithHighestAverageBusUsage() + "\n"); + sb.append("Mapping with Lowest Average Bus Usage: " + dsemapresults.getMappingWithLowestAverageCPUUsage() + "\n"); + + sb.append("Mapping with Highest max Bus Usage: " + dsemapresults.getMappingWithHighestMaxBusUsage() + "\n"); + sb.append("Mapping with Lowest max Bus Usage: " + dsemapresults.getMappingWithLowestMaxBusUsage() + "\n"); + + sb.append("\nContentions:\n"); + sb.append("Mapping with Highest min bus contention: " + dsemapresults.getMappingWithHighestMinBusContention() + "\n"); + sb.append("Mapping with Lowest min Bus contention: " + dsemapresults.getMappingWithLowestMinBusContention() + "\n"); + + sb.append("Mapping with Highest Average Bus contention: " + dsemapresults.getMappingWithHighestAverageBusUsage() + "\n"); + sb.append("Mapping with Lowest Average Bus contention: " + dsemapresults.getMappingWithLowestAverageCPUUsage() + "\n"); + + sb.append("Mapping with Highest max Bus contention: " + dsemapresults.getMappingWithHighestMaxBusUsage() + "\n"); + sb.append("Mapping with Lowest max Bus contention: " + dsemapresults.getMappingWithLowestMaxBusUsage() + "\n"); + + /*sb.append("\nSecurity:\n"); + sb.append("Mapping with Highest added security: " + dsemapresults.getMappingWithHighestAddedSecurity() + "\n"); + sb.append("Mapping with Lowest added security: " + dsemapresults.getMappingWithLowestAddedSecurity() + "\n"); + */ + + rankMappings(dsemapresults); + + sb.append("\nGrades: (Mapping#, grade)\n"); + int[] grades = dsemapresults.getGrades().clone(); + int j; + for(j=0; j<grades.length; j++) { + sb.append("(#" + j + ", " + grades[j] + ")" ); + } + sb.append("\n"); + + TraceManager.addDev("Ranking"); + sb.append("\nRanking (Rank, mapping, grade)\n"); + int[] index = new int[grades.length]; + for(j=0; j<grades.length; j++) { + index[j] = j; + } + + TraceManager.addDev("Ranking 0"); + + Conversion.quickSort(grades, 0, grades.length-1, index); + + TraceManager.addDev("Ranking 1"); + + for(j=grades.length-1; j>=0; j--) { + sb.append("(#" + (grades.length-j) + ", " + index[j] + ", " + grades[j]+ ") "); + } + + TraceManager.addDev("Ranking done"); + + + try { + overallResults=sb.toString(); + FileUtils.saveFile(pathToResults + "Overall_results_AllMappings_From_" + resultsID + ".txt", sb.toString()); + + } catch (Exception e){ + TraceManager.addDev("Error when saving results file" + e.getMessage()); + return -1; + + } + + sb = new StringBuffer(dsemapresults.makeHTMLTableOfResults(tapValues)); + + + try { + FileUtils.saveFile(pathToResults + "Overall_results_AllMappings_From_" + resultsID + ".html", sb.toString()); + } catch (Exception e){ + TraceManager.addDev("Error when saving results file" + e.getMessage()); + return -1; + + } + return 0; + + } else { + + if (results == null) { + TraceManager.addDev("No results"); + return -1; + } + + // Must compute results + results.computeResults(); + + TraceManager.addDev("Results: #" + resultsID + "\n" + results.getWholeResults()); + overallResults=results.getWholeResults(); + // Saving to file + try { + FileUtils.saveFile(pathToResults + "summary" + resultsID + ".txt", DSESimulationResult.getExplanationHeader() + "\n" + results.getAllComments() + "\n" + results.getWholeResults()); + } catch (Exception e){ + TraceManager.addDev("Error when saving results file"); + return -1; + + } + + return 0; + } + } + + public int resetResults(String _arguments) { + if (results == null) { + return 0; + } + + // Reinit results + results.reset(); + + resultsID ++; + return 0; + } + + public int runExplo(String _arguments, boolean _debug, boolean _optimize) { + + // Checking for valid arguments + /*int nbOfSimulations; + try { + nbOfSimulations = Integer.decode(_arguments).intValue(); + } catch (Exception e) { + errorMessage = INVALID_ARGUMENT_NATURAL_VALUE; + return -1; + }*/ + + if (pathToSimulator == null) { + errorMessage = PATH_TO_CODE; + return -1; + } + + if (pathToResults == null) { + errorMessage = PATH_TO_RESULTS; + return -1; + } + + if (mappingFile == null) { + errorMessage = PATH_TO_SOURCE; + return -1; + } + + /*if (!outputVCD && !outputHTML && !outputTXT) { + errorMessage = NO_OUTPUT_SELECTED; + return -1; + }*/ + + if (simulationCompilationCommand == null) { + errorMessage = SIMULATION_COMPILATION_COMMAND_NOT_SET; + return -1; + } + + + if (simulationExecutionCommand == null) { + errorMessage = SIMULATION_EXECUTION_COMMAND_NOT_SET; + return -1; + } + + + // Loading model + // Generating code + if (optionChanged) { + TraceManager.addDev("Loading mapping"); + if (!loadMapping(_optimize)) { + errorMessage = LOAD_MAPPING_FAILED; + TraceManager.addDev("Loading of the mapping faild!!!!"); + return -1; + } + + + TraceManager.addDev("\n\n\n**** Generating simulation code..."); + final IDiploSimulatorCodeGenerator map = DiploSimulatorFactory.INSTANCE.createCodeGenerator( tmap ); + // TML2MappingSystemC map = new TML2MappingSystemC(tmap); + try { + map.generateSystemC(_debug, _optimize); + map.saveFile(pathToSimulator, "appmodel"); + } catch (Exception e) { + TraceManager.addDev("SystemC generation failed: " + e + " msg=" + e.getMessage()); + e.printStackTrace(); + return -1; + } + + // Compiling the code + makeCommand(simulationCompilationCommand + " " + pathToSimulator); + + optionChanged = false; + } + + + // Executing the simulation + String cmd = pathToSimulator + simulationExecutionCommand + " -cmd \"1 7 " +simulationExplorationMinimumCommand + " " + simulationExplorationMinimumBranch + "\" -gpath " + pathToResults; + + makeCommand(cmd); + simulationID ++; + + return 0; + } + + public int runDSE(String _arguments, boolean _debug, boolean _optimize) { + int nbOfSimulations; + + if (nbOfSimulationsPerMapping < 1) { + nbOfSimulationsPerMapping = 1; + } + + // Checking simulation Elements + int ret = checkingDSEElements(); + if (ret != 0) { + return ret; + } + + // Checking simulation Elements + ret = checkingDSEElements(); + if (ret != 0) { + return ret; + } + + // Must generate all possible mappings. + // First : load the task model + if (!loadTaskModel(_optimize)) { + TraceManager.addDev("Could not load the task model"); + return -1; + } + + TraceManager.addDev("Task model loaded"); + + mappings = generateAllMappings(taskModel); + + if (mappings != null) { + TraceManager.addDev("Mapping generated"); + } else { + TraceManager.addDev("Mapping failure"); + return -1; + } + + int cpt = 0; + /*for(TMLMapping tmla: mappings) { + TraceManager.addDev("map " + cpt + ": " + tmla.getSummaryTaskMapping()); + cpt ++; + }*/ + + // For each maping, generate the simulation code + cpt = 0; + if (recordResults) { + if (dsemapresults == null) { + dsemapresults = new DSEMappingSimulationResults(); + } + } + + for(TMLMapping<TGComponent> tmla: mappings) { + TraceManager.addDev("Handling mapping #" + cpt); + progression = cpt * 100 / (mappings.size()); + + cpt ++; + + if (generateAndCompileMappingCode(tmla, _debug, _optimize) >= 0) { + if (recordResults) { + results = new DSESimulationResult(); + resultsID ++; + } + + //System.out.println("After Current TML Mapping: " + tmla.getSummaryTaskMapping()); + + dsemapresults.addElement("Mapping #" + (cpt-1), results, tmla); + nbOfSimulations = nbOfSimulationsPerMapping; + // Executing the simulation + String cmd = prepareCommand(); + String tmp; + + //long t0 = System.currentTimeMillis(); + + while(nbOfSimulations >0) { + tmp = putSimulationNbInCommand(cmd, simulationID); + TraceManager.addDev("Executing: " + tmp); + makeCommand(tmp); + + if (recordResults) { + if (loadSimulationResult(simulationID) <0) { + return -1; + } + } + simulationID ++; + nbOfSimulations --; + } + } else { + return -1; + } + + if (addSecurity){ + System.out.println("ADDING SECURITY TO MAPPING " +(cpt-1)); + + TMLArchiPanel newArch = drawMapping(tmla, "securedMapping"+(cpt-1)); + GTMLModeling gtml =new GTMLModeling(newArch, true); + tmla = gtml.translateToTMLMapping(); + // tmla.tmlap = tmlap; + // tmlcdp = (TMLComponentDesignPanel) mainGUI.tabs.get(0); + // tmla.setTMLDesignPanel(tmlcdp); + // System.out.println("tmlcdp " + tmlcdp); + // + //Repeat for secured mapping + TMLMapping<TGComponent> secMapping = mainGUI.gtm.autoSecure(mainGUI, "mapping" +(cpt-1),tmla, newArch, encComp, overhead, decComp,true,false,false); + + //Run simulations on this mapping + if (generateAndCompileMappingCode(secMapping, _debug, _optimize) >= 0) { + System.out.println("GENERATING>>>"); + if (recordResults) { + results = new DSESimulationResult(); + resultsID ++; + } + + //System.out.println("After Current TML Mapping: " + tmla.getSummaryTaskMapping()); + + dsemapresults.addElement("Secured Mapping #" + (cpt-1), results, secMapping); + nbOfSimulations = nbOfSimulationsPerMapping; + // Executing the simulation + String cmd = prepareCommand(); + String tmp; + + //long t0 = System.currentTimeMillis(); + + while(nbOfSimulations >0) { + tmp = putSimulationNbInCommand(cmd, simulationID); + TraceManager.addDev("Executing: " + tmp); + makeCommand(tmp); + + if (recordResults) { + if (loadSimulationResult(simulationID) <0) { + return -1; + } + } + simulationID ++; + nbOfSimulations --; + } + } else { + return -1; + } + } + } + return 0; + } public TMLArchiPanel drawMapping(TMLMapping<TGComponent> map, String name){ - //Map<HwNode, TGConnectingPoint> connectMap; - Map<HwNode, TMLArchiNode> objMap = new HashMap<HwNode, TMLArchiNode>(); - /*int index =*/ mainGUI.createTMLArchitecture(name); - TMLArchiPanel archPanel = (TMLArchiPanel) mainGUI.tabs.get(mainGUI.tabs.size()-1); - TMLArchiDiagramPanel ap = archPanel.tmlap; - TMLArchitecture arch = map.getArch(); - List<HwNode> hwnodes = arch.getHwNodes(); - List<HwLink> hwlinks = arch.getHwLinks(); - int x=10; - int y=10; - for (HwNode node: hwnodes){ - if (node instanceof HwCPU){ - TMLArchiCPUNode cpu = new TMLArchiCPUNode(x, y, ap.getMinX(), ap.getMaxX(), ap.getMinY(), ap.getMaxY(), false, null, ap); - x+=300; - cpu.setName(node.getName()); - ap.addComponent(cpu, x, y, false, true); - objMap.put(node, cpu); - } - else if (node instanceof HwMemory){ - TMLArchiMemoryNode mem = new TMLArchiMemoryNode(x, y, ap.getMinX(), ap.getMaxX(), ap.getMinY(), ap.getMaxY(), false, null, ap); - x+=300; - mem.setName(node.getName()); - ap.addComponent(mem, x, y, false, true); - objMap.put(node, mem); - } - - } - y = 400; - x=10; - for (HwNode node:hwnodes){ - if (node instanceof HwBus){ - HwBus hwbus = (HwBus) node; - TMLArchiBUSNode bus = new TMLArchiBUSNode(x, y, ap.getMinX(), ap.getMaxX(), ap.getMinY(), ap.getMaxY(), false, null, ap); - bus.setPrivacy(hwbus.privacy); - x+=300; - bus.setName(node.getName()); - ap.addComponent(bus,x,y,false,true); - objMap.put(node,bus); - } - } - for (HwLink link: hwlinks){ - TMLArchiNode n1 = objMap.get(link.hwnode); - TMLArchiNode n2 = objMap.get(link.bus); - TMLArchiConnectorNode conn = new TMLArchiConnectorNode(x, y, ap.getMinX(), ap.getMaxX(), ap.getMinY(), ap.getMaxY(), false, null, ap, n1.getTGConnectingPointAtIndex(0), n2.getTGConnectingPointAtIndex(0), new Vector<Point>()); - ap.addComponent(conn,x,y,false,true); - } - for (TMLTask task: map.getTMLModeling().getTasks()){ - HwNode node = map.getHwNodeOf(task); - TMLArchiArtifact art = new TMLArchiArtifact(objMap.get(node).getX(), objMap.get(node).getY(), ap.getMinX(), ap.getMaxX(), ap.getMinY(), ap.getMaxY(), false, objMap.get(node), ap); - ap.addComponent(art,objMap.get(node).getX(),objMap.get(node).getY(),true,true); - art.setFullName(task.getName().split("__")[1], task.getName().split("__")[0]); - } - ap.repaint(); - return archPanel; + //Map<HwNode, TGConnectingPoint> connectMap; + Map<HwNode, TMLArchiNode> objMap = new HashMap<HwNode, TMLArchiNode>(); + /*int index =*/ mainGUI.createTMLArchitecture(name); + TMLArchiPanel archPanel = (TMLArchiPanel) mainGUI.tabs.get(mainGUI.tabs.size()-1); + TMLArchiDiagramPanel ap = archPanel.tmlap; + TMLArchitecture arch = map.getArch(); + List<HwNode> hwnodes = arch.getHwNodes(); + List<HwLink> hwlinks = arch.getHwLinks(); + int x=10; + int y=10; + for (HwNode node: hwnodes){ + if (node instanceof HwCPU){ + TMLArchiCPUNode cpu = new TMLArchiCPUNode(x, y, ap.getMinX(), ap.getMaxX(), ap.getMinY(), ap.getMaxY(), false, null, ap); + x+=300; + cpu.setName(node.getName()); + ap.addComponent(cpu, x, y, false, true); + objMap.put(node, cpu); + } + else if (node instanceof HwMemory){ + TMLArchiMemoryNode mem = new TMLArchiMemoryNode(x, y, ap.getMinX(), ap.getMaxX(), ap.getMinY(), ap.getMaxY(), false, null, ap); + x+=300; + mem.setName(node.getName()); + ap.addComponent(mem, x, y, false, true); + objMap.put(node, mem); + } + + } + y = 400; + x=10; + for (HwNode node:hwnodes){ + if (node instanceof HwBus){ + HwBus hwbus = (HwBus) node; + TMLArchiBUSNode bus = new TMLArchiBUSNode(x, y, ap.getMinX(), ap.getMaxX(), ap.getMinY(), ap.getMaxY(), false, null, ap); + bus.setPrivacy(hwbus.privacy); + x+=300; + bus.setName(node.getName()); + ap.addComponent(bus,x,y,false,true); + objMap.put(node,bus); + } + } + for (HwLink link: hwlinks){ + TMLArchiNode n1 = objMap.get(link.hwnode); + TMLArchiNode n2 = objMap.get(link.bus); + TMLArchiConnectorNode conn = new TMLArchiConnectorNode(x, y, ap.getMinX(), ap.getMaxX(), ap.getMinY(), ap.getMaxY(), false, null, ap, n1.getTGConnectingPointAtIndex(0), n2.getTGConnectingPointAtIndex(0), new Vector<Point>()); + ap.addComponent(conn,x,y,false,true); + } + for (TMLTask task: map.getTMLModeling().getTasks()){ + HwNode node = map.getHwNodeOf(task); + TMLArchiArtifact art = new TMLArchiArtifact(objMap.get(node).getX(), objMap.get(node).getY(), ap.getMinX(), ap.getMaxX(), ap.getMinY(), ap.getMaxY(), false, objMap.get(node), ap); + ap.addComponent(art,objMap.get(node).getX(),objMap.get(node).getY(),true,true); + art.setFullName(task.getName().split("__")[1], task.getName().split("__")[0]); + } + ap.repaint(); + return archPanel; } - public void makeCommand(String cmd) { - String str = null; - BufferedReader proc_in, proc_err; + public void makeCommand(String cmd) { + String str = null; + BufferedReader proc_in, proc_err; //PrintStream out = null; - + try { //TraceManager.addDev("Going to start command " + cmd); - - ProcessBuilder pb = new ProcessBuilder(constructCommandList(cmd)); - /*Map<String, String> env =*/ pb.environment(); - java.lang.Process proc = pb.start(); - + + ProcessBuilder pb = new ProcessBuilder(constructCommandList(cmd)); + /*Map<String, String> env =*/ pb.environment(); + java.lang.Process proc = pb.start(); + proc_in = new BufferedReader(new InputStreamReader(proc.getInputStream())); proc_err = new BufferedReader(new InputStreamReader(proc.getErrorStream())); - + //et = new ErrorThread(proc_err, mpi); //et.start(); - + while ((str = proc_in.readLine()) != null){ - if (showSimulatorRawOutput) { - System.out.println("Out " + str); + if (showSimulatorRawOutput) { + System.out.println("Out " + str); } - //mpi.appendOut(str+"\n"); + //mpi.appendOut(str+"\n"); } - + //et.stopProcess(); - + } catch (Exception e) { TraceManager.addDev("Exception [" + e.getMessage() + "] occured when executing " + cmd); } TraceManager.addDev("Ending command " + cmd); - - } - - public Vector<String> constructCommandList(String _cmd) { - Vector<String> list = new Vector<String>(); - _cmd = _cmd.trim(); - char c; - String current = ""; - boolean inQuote0 = false; - boolean inQuote1 = false; - - //TraceManager.addDev("Making list from command : " + _cmd); - - for(int i=0; i<_cmd.length(); i++) { - c = _cmd.charAt(i); - - if ((c == ' ') && (!inQuote0) && (!inQuote1)){ - //TraceManager.addDev("Adding " + current); - list.add(current); - current = ""; - } else if (c == '\'') { - inQuote1 = !inQuote1; - } else if (c == '\"') { - inQuote0 = !inQuote0; - } else { - current += c; - } - - } - - if (current.length() > 0) { - list.add(current); - //TraceManager.addDev("Adding " + current); - } - - //TraceManager.addDev("List done\n"); - - return list; - - } - - public void oldMakeCommand(String cmd) { - String str = null; - BufferedReader proc_in, proc_err; + + } + + public Vector<String> constructCommandList(String _cmd) { + Vector<String> list = new Vector<String>(); + _cmd = _cmd.trim(); + char c; + String current = ""; + boolean inQuote0 = false; + boolean inQuote1 = false; + + //TraceManager.addDev("Making list from command : " + _cmd); + + for(int i=0; i<_cmd.length(); i++) { + c = _cmd.charAt(i); + + if ((c == ' ') && (!inQuote0) && (!inQuote1)){ + //TraceManager.addDev("Adding " + current); + list.add(current); + current = ""; + } else if (c == '\'') { + inQuote1 = !inQuote1; + } else if (c == '\"') { + inQuote0 = !inQuote0; + } else { + current += c; + } + + } + + if (current.length() > 0) { + list.add(current); + //TraceManager.addDev("Adding " + current); + } + + //TraceManager.addDev("List done\n"); + + return list; + + } + + public void oldMakeCommand(String cmd) { + String str = null; + BufferedReader proc_in, proc_err; //PrintStream out = null; - + try { TraceManager.addDev("Going to start command " + cmd); - + java.lang.Process proc = Runtime.getRuntime().exec(cmd); - + proc_in = new BufferedReader(new InputStreamReader(proc.getInputStream())); proc_err = new BufferedReader(new InputStreamReader(proc.getErrorStream())); - + //et = new ErrorThread(proc_err, mpi); //et.start(); - - while ((str = proc_in.readLine()) != null){ + + while ((str = proc_in.readLine()) != null){ TraceManager.addDev("Out " + str); - //mpi.appendOut(str+"\n"); + //mpi.appendOut(str+"\n"); } - + //et.stopProcess(); - + } catch (Exception e) { TraceManager.addDev("Exception [" + e.getMessage() + "] occured when executing " + cmd); } TraceManager.addDev("Ending command " + cmd); - - } - - public int loadSimulationResult(int id) { - results.loadResultFromXMLFile(pathToResults + "benchmark" + id + ".xml"); - - return 0; - } - - public Vector<TMLMapping<TGComponent>> generateAllMappings(TMLModeling<TGComponent> _tmlm) { - TraceManager.addDev("Generate all mappings"); - if (_tmlm == null) { - TraceManager.addDev("Null mapping"); - return null; - } - - // At least one CPU as a min, and at least one task per CPU - int nbOfTasks = _tmlm.getTasks().size(); - TraceManager.addDev("Nb of tasks:" + nbOfTasks); - - if (nbOfTasks == 0) { - return null; - } - - int min = Math.max(1, minNbOfCPUs); - int max = Math.min(nbOfTasks, maxNbOfCPUs); - - if (max <= min) { - max = min + 1; - } - - Vector<TMLMapping<TGComponent>> maps = new Vector<>(); - - for(int cpt=min; cpt<=max; cpt++) { - dseID = 0; - TraceManager.addDev("Generating mapping for nb of cpu = " + cpt); - generateMappings(_tmlm, maps, cpt); - TraceManager.addDev("Mappings generated for nb of cpu = " + cpt); - } - - computeCoresOfMappings(maps); - addMemories(maps); - TraceManager.addDev("Mapping generated: " + maps.size()); - - return maps; - } - private void addMemories(Vector<TMLMapping<TGComponent>> maps){ - for (TMLMapping<TGComponent> map: maps){ - TMLArchitecture arch = map.getArch(); - List<HwNode> nodes = arch.getCPUs(); - for (HwNode node:nodes){ - HwBus bus = new HwBus("bus " +node.getName()); - bus.privacy=1; - HwMemory mem = new HwMemory("memory " +node.getName()); - HwLink hwlink = new HwLink("link_memory" +node.getName() + "_to_memorybus"); - hwlink.bus=bus; - hwlink.hwnode=node; - HwLink hwlink2 = new HwLink("link_" +node.getName() + "_to_memorybus"); - hwlink2.bus=bus; - hwlink2.hwnode=mem; - arch.addHwNode(mem); - arch.addHwNode(bus); - arch.addHwLink(hwlink); - arch.addHwLink(hwlink2); - - } - } - } - private void generateMappings(TMLModeling<TGComponent> _tmlm, Vector<TMLMapping<TGComponent>> maps, int nbOfCPUs) { - List<TMLTask> tasks = _tmlm.getTasks(); - CPUWithTasks cpus_tasks[] = new CPUWithTasks[nbOfCPUs]; - - TraceManager.addDev("Nb of cpus = " + nbOfCPUs); - - - for(int i=0; i<nbOfCPUs; i++) { - cpus_tasks[i] = new CPUWithTasks(); - } - - // We first put the first task on a CPU - TMLTask t = tasks.get(0); - cpus_tasks[0].addTask(t); - - // We build a vector of remaining tasks - Vector<TMLTask> vtasks = new Vector<TMLTask>(); - for(TMLTask task: tasks) { - if (task != t) { - vtasks.add(task); - } - } - - // Computing mappings - computeMappings(vtasks, cpus_tasks, maps, _tmlm); - - - - TraceManager.addDev("Nb of computed mappings:" + maps.size()); - } - - private void computeMappings(Vector<TMLTask> remainingTasks, CPUWithTasks[] cpus_tasks, Vector<TMLMapping<TGComponent>> maps, TMLModeling<TGComponent> _tmlm) { - if (remainingTasks.size() == 0) { - // Can generate the mapping from cpus_tasks - makeMapping(cpus_tasks, maps, _tmlm); - return; - } - - // At least one task to map. - // We select the first task - TMLTask t = remainingTasks.get(0); - remainingTasks.remove(t); - - TraceManager.addDev("Mapping task: " + t.getName()); - - // Two solutions: either it is mapped on the first free CPU, or it is mapped on an already occupied CPU - // Memo: all cpus must have at least on task at the end - - // Must it be mapped a free CPU? - if (nbOfFreeCPUs(cpus_tasks) >= (remainingTasks.size()+1)) { - // The task must be mapped on a free CPU - // Search for the first free CPU - TraceManager.addDev("The following task must be mapped on a free CPU: " + t.getName()); - for(int i=0; i<cpus_tasks.length; i++) { - if (cpus_tasks[i].getNbOfTasks() == 0) { - cpus_tasks[i].addTask(t); - computeMappings(remainingTasks, cpus_tasks, maps, _tmlm); - cpus_tasks[i].removeTask(t); - remainingTasks.add(t); - return; - } - } - TraceManager.addDev("Task could not be mapped on a free CPU: " + t.getName()); - } - - TraceManager.addDev("Regular mapping of: " + t.getName()); - // It can be mapped on whatever CPU, until the first free one has been met (the first free CPU is inclusive) - remainingTasks.remove(t); - for(int i=0; i<cpus_tasks.length; i++) { - cpus_tasks[i].addTask(t); - TraceManager.addDev("Mapping " + t.getName() + " on CPU #" + i); - computeMappings(remainingTasks, cpus_tasks, maps, _tmlm); - TraceManager.addDev("Removing " + t.getName() + " from CPU #" + i); - cpus_tasks[i].removeTask(t); - if (cpus_tasks[i].getNbOfTasks() == 0) { - TraceManager.addDev("Stopping mapping since of" + t.getName() + " since CPU #" + i + " is free"); - remainingTasks.add(t); - return; - } - } - remainingTasks.add(t); - - } - - private void makeMapping(CPUWithTasks[] cpus_tasks, Vector<TMLMapping<TGComponent>> maps, TMLModeling<TGComponent> _tmlm) { - TMLArchitecture tmla = new TMLArchitecture(); - TMLMapping<TGComponent> tmap = new TMLMapping<>(_tmlm, tmla, true); - DIPLOElement.setGeneralID(_tmlm.computeMaxID() + 1); - - HwCPU cpu; - - for(int i=0; i<cpus_tasks.length; i++) { - cpu = new HwCPU("CPU__" + (cpus_tasks.length + 1) + "_" + dseID + "_" + (i+1)); - tmla.addHwNode(cpu); - for(TMLTask t: cpus_tasks[i].getTasks()) { - tmap.addTaskToHwExecutionNode(t, cpu); - } - } - dseID ++; - - maps.add(tmap); - - } - - private int nbOfFreeCPUs(CPUWithTasks[] cpus_tasks) { - int nb = 0; - for(int i=0; i<cpus_tasks.length; i++) { - if (cpus_tasks[i].getNbOfTasks() == 0) { - nb ++; - } - } - return nb; - } - - private void rankMappings(DSEMappingSimulationResults _dseresults) { - _dseresults.computeGrades(tapValues); - } - - private void computeCoresOfMappings(Vector<TMLMapping<TGComponent>> maps) { - } - - public void resetProgression() { - progression = 0; - } - - public int getProgression() { - return progression; - } - -} // Class DSEConfiguration + } + + public int loadSimulationResult(int id) { + results.loadResultFromXMLFile(pathToResults + "benchmark" + id + ".xml"); + + return 0; + } + + public Vector<TMLMapping<TGComponent>> generateAllMappings(TMLModeling<TGComponent> _tmlm) { + TraceManager.addDev("Generate all mappings"); + if (_tmlm == null) { + TraceManager.addDev("Null mapping"); + return null; + } + + // At least one CPU as a min, and at least one task per CPU + int nbOfTasks = _tmlm.getTasks().size(); + TraceManager.addDev("Nb of tasks:" + nbOfTasks); + if (nbOfTasks == 0) { + return null; + } + + int min = Math.max(1, minNbOfCPUs); + int max = Math.min(nbOfTasks, maxNbOfCPUs); + + if (max <= min) { + max = min + 1; + } + + Vector<TMLMapping<TGComponent>> maps = new Vector<>(); + + for(int cpt=min; cpt<=max; cpt++) { + dseID = 0; + TraceManager.addDev("Generating mapping for nb of cpu = " + cpt); + generateMappings(_tmlm, maps, cpt); + TraceManager.addDev("Mappings generated for nb of cpu = " + cpt); + } + + computeCoresOfMappings(maps); + addMemories(maps); + TraceManager.addDev("Mapping generated: " + maps.size()); + + return maps; + } + private void addMemories(Vector<TMLMapping<TGComponent>> maps){ + for (TMLMapping<TGComponent> map: maps){ + TMLArchitecture arch = map.getArch(); + List<HwNode> nodes = arch.getCPUs(); + for (HwNode node:nodes){ + HwBus bus = new HwBus("bus " +node.getName()); + bus.privacy=1; + HwMemory mem = new HwMemory("memory " +node.getName()); + HwLink hwlink = new HwLink("link_memory" +node.getName() + "_to_memorybus"); + hwlink.bus=bus; + hwlink.hwnode=node; + HwLink hwlink2 = new HwLink("link_" +node.getName() + "_to_memorybus"); + hwlink2.bus=bus; + hwlink2.hwnode=mem; + arch.addHwNode(mem); + arch.addHwNode(bus); + arch.addHwLink(hwlink); + arch.addHwLink(hwlink2); + + } + } + } + private void generateMappings(TMLModeling<TGComponent> _tmlm, Vector<TMLMapping<TGComponent>> maps, int nbOfCPUs) { + List<TMLTask> tasks = _tmlm.getTasks(); + CPUWithTasks cpus_tasks[] = new CPUWithTasks[nbOfCPUs]; + + TraceManager.addDev("Nb of cpus = " + nbOfCPUs); + + + for(int i=0; i<nbOfCPUs; i++) { + cpus_tasks[i] = new CPUWithTasks(); + } + + // We first put the first task on a CPU + TMLTask t = tasks.get(0); + cpus_tasks[0].addTask(t); + + // We build a vector of remaining tasks + Vector<TMLTask> vtasks = new Vector<TMLTask>(); + for(TMLTask task: tasks) { + if (task != t) { + vtasks.add(task); + } + } + + // Computing mappings + computeMappings(vtasks, cpus_tasks, maps, _tmlm); + + + + TraceManager.addDev("Nb of computed mappings:" + maps.size()); + } + + private void computeMappings(Vector<TMLTask> remainingTasks, CPUWithTasks[] cpus_tasks, Vector<TMLMapping<TGComponent>> maps, TMLModeling<TGComponent> _tmlm) { + if (remainingTasks.size() == 0) { + // Can generate the mapping from cpus_tasks + makeMapping(cpus_tasks, maps, _tmlm); + return; + } + + // At least one task to map. + // We select the first task + TMLTask t = remainingTasks.get(0); + remainingTasks.remove(t); + + TraceManager.addDev("Mapping task: " + t.getName()); + + // Two solutions: either it is mapped on the first free CPU, or it is mapped on an already occupied CPU + // Memo: all cpus must have at least on task at the end + + // Must it be mapped a free CPU? + if (nbOfFreeCPUs(cpus_tasks) >= (remainingTasks.size()+1)) { + // The task must be mapped on a free CPU + // Search for the first free CPU + TraceManager.addDev("The following task must be mapped on a free CPU: " + t.getName()); + for(int i=0; i<cpus_tasks.length; i++) { + if (cpus_tasks[i].getNbOfTasks() == 0) { + cpus_tasks[i].addTask(t); + computeMappings(remainingTasks, cpus_tasks, maps, _tmlm); + cpus_tasks[i].removeTask(t); + remainingTasks.add(t); + return; + } + } + TraceManager.addDev("Task could not be mapped on a free CPU: " + t.getName()); + } + + TraceManager.addDev("Regular mapping of: " + t.getName()); + // It can be mapped on whatever CPU, until the first free one has been met (the first free CPU is inclusive) + remainingTasks.remove(t); + for(int i=0; i<cpus_tasks.length; i++) { + cpus_tasks[i].addTask(t); + TraceManager.addDev("Mapping " + t.getName() + " on CPU #" + i); + computeMappings(remainingTasks, cpus_tasks, maps, _tmlm); + TraceManager.addDev("Removing " + t.getName() + " from CPU #" + i); + cpus_tasks[i].removeTask(t); + if (cpus_tasks[i].getNbOfTasks() == 0) { + TraceManager.addDev("Stopping mapping since of" + t.getName() + " since CPU #" + i + " is free"); + remainingTasks.add(t); + return; + } + } + remainingTasks.add(t); + + } + + private void makeMapping(CPUWithTasks[] cpus_tasks, Vector<TMLMapping<TGComponent>> maps, TMLModeling<TGComponent> _tmlm) { + TMLArchitecture tmla = new TMLArchitecture(); + TMLMapping<TGComponent> tmap = new TMLMapping<>(_tmlm, tmla, true); + DIPLOElement.setGeneralID(_tmlm.computeMaxID() + 1); + + HwCPU cpu; + + for(int i=0; i<cpus_tasks.length; i++) { + cpu = new HwCPU("CPU__" + (cpus_tasks.length + 1) + "_" + dseID + "_" + (i+1)); + tmla.addHwNode(cpu); + for(TMLTask t: cpus_tasks[i].getTasks()) { + tmap.addTaskToHwExecutionNode(t, cpu); + } + } + dseID ++; + + maps.add(tmap); + + } + + private int nbOfFreeCPUs(CPUWithTasks[] cpus_tasks) { + int nb = 0; + for(int i=0; i<cpus_tasks.length; i++) { + if (cpus_tasks[i].getNbOfTasks() == 0) { + nb ++; + } + } + return nb; + } + + private void rankMappings(DSEMappingSimulationResults _dseresults) { + _dseresults.computeGrades(tapValues); + } + + private void computeCoresOfMappings(Vector<TMLMapping<TGComponent>> maps) { + } + + public void resetProgression() { + progression = 0; + } + + public int getProgression() { + return progression; + } + + +} // Class DSEConfiguration diff --git a/src/main/java/dseengine/DSESimulationResult.java b/src/main/java/dseengine/DSESimulationResult.java index 4c812caa799cb8d5840955383f8bf97e378e39e1..ff63cdca7d9f91ecc6bfa7345b924d6a2185edbb 100755 --- a/src/main/java/dseengine/DSESimulationResult.java +++ b/src/main/java/dseengine/DSESimulationResult.java @@ -1,26 +1,26 @@ /* Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille - * + * * ludovic.apvrille AT enst.fr - * + * * This software is a computer program whose purpose is to allow the * edition of TURTLE analysis, design and deployment diagrams, to * allow the generation of RT-LOTOS or Java code from this diagram, * and at last to allow the analysis of formal validation traces * obtained from external tools, e.g. RTL from LAAS-CNRS and CADP * from INRIA Rhone-Alpes. - * + * * This software is governed by the CeCILL license under French law and * abiding by the rules of distribution of free software. You can use, * modify and/ or redistribute the software under the terms of the CeCILL * license as circulated by CEA, CNRS and INRIA at the following URL * "http://www.cecill.info". - * + * * As a counterpart to the access to the source code and rights to copy, * modify and redistribute granted by the license, users are provided only * with a limited warranty and the software's author, the holder of the * economic rights, and the successive licensors have only limited * liability. - * + * * In this respect, the user's attention is drawn to the risks associated * with loading, using, modifying and/or developing or reproducing the * software by the user in light of its specific status of free software, @@ -31,7 +31,7 @@ * requirements in conditions enabling the security of their systems and/or * data to be ensured and, more generally, to use and operate it in the * same conditions as regards security. - * + * * The fact that you are presently reading this means that you have had * knowledge of the CeCILL license and that you accept its terms. */ @@ -61,689 +61,688 @@ import java.util.Vector; //import uppaaldesc.*; /** -* Class DSESimulationResult -* Object for storing a simulation result -* Creation: 06/09/2011 -* @version 1.0 06/09/2011 -* @author Ludovic APVRILLE + * Class DSESimulationResult + * Object for storing a simulation result + * Creation: 06/09/2011 + * @version 1.0 06/09/2011 + * @author Ludovic APVRILLE */ public class DSESimulationResult { - - protected static final String SIMULATION_GLOBAL = "global"; - protected static final String SIMULATION_HEADER = "siminfo"; - protected static final String SIMULATION_DURATION = "simdur"; - protected static final String SIMULATION_CPU = "cpu"; - protected static final String SIMULATION_BUS = "bus"; - protected static final String SIMULATION_TASK = "task"; - - private Vector<String> comments; - - private Vector<Long> simulationDurations; - private Vector<Long> cycleDurations; - private Vector<CPUResult> cpus; - private Vector<BusResult> busses; - private Vector<TaskResult> tasks; - - private SimulationDurationWholeResult sdwr; - private SimulationDurationWholeResult cdwr; - private Vector<CPUWholeResult> wcpus; - private Vector<BusWholeResult> wbusses; - private Vector<TaskWholeResult> wtasks; - private int addedSecurity=0; - - - public DSESimulationResult() { - reset(); - } - - public void reset() { - cpus = new Vector<CPUResult>(); - busses = new Vector<BusResult>(); - tasks = new Vector<TaskResult>(); - comments = new Vector<String>(); - simulationDurations = new Vector<Long>(); - cycleDurations = new Vector<Long>(); - } - - public void addComment(String _comment) { - comments.add(_comment); - } - - public int getAddedSecurity(){ - return addedSecurity; - } - public void setAddedSecurity(int i){ - addedSecurity = i; - } - public int loadResultFromXMLFile(String pathToFile) { - File f = new File(pathToFile); - String data = FileUtils.loadFileData(f); - - if (data == null) { - return -1; - } - - analyzeServerAnswer(data); - - return 0; - } - - protected void analyzeServerAnswer(String s) { - //System.out.println("From server:" + s); - int index0 = s.indexOf("<?xml"); - String ssxml = ""; - - if (index0 != -1) { - //System.out.println("toto1"); - ssxml = s.substring(index0, s.length()) + "\n"; - } else { - //System.out.println("toto2"); - ssxml = ssxml + s + "\n"; - } - - index0 = ssxml.indexOf("</siminfo>"); - - if (index0 != -1) { - //System.out.println("toto3"); - ssxml = ssxml.substring(0, index0+10); - loadXMLInfoFromServer(ssxml); - ssxml = ""; - } - - //TraceManager.addDev("Computing results"); - //TraceManager.addDev("infos on cpus:" + cpus.size()); - //TraceManager.addDev("infos on busses:" + busses.size()); - //TraceManager.addDev("infos on tasks:" + tasks.size()); - - - // Compute results! - - //System.out.println("toto4"); - - } - - protected boolean loadXMLInfoFromServer(String xmldata) { - //jta.append("XML from server:" + xmldata + "\n\n"); - - DocumentBuilderFactory dbf; - DocumentBuilder db; - - try { - dbf = DocumentBuilderFactory.newInstance(); - db = dbf.newDocumentBuilder(); - } catch (ParserConfigurationException e) { - dbf = null; - db = null; - } - - if ((dbf == null) || (db == null)) { - return false; - } - - ByteArrayInputStream bais = new ByteArrayInputStream(decodeString(xmldata).getBytes()); - int i; - - try { - // building nodes from xml String - Document doc = db.parse(bais); - NodeList nl; - Node node; - - nl = doc.getElementsByTagName(SIMULATION_HEADER); - - if (nl == null) { - return false; - } - - for(i=0; i<nl.getLength(); i++) { - node = nl.item(i); - if (node.getNodeType() == Node.ELEMENT_NODE) { - // create design, and get an index for it - return loadConfiguration(node); - } - } - - } catch (IOException e) { - TraceManager.addError("Error when parsing server info:" + e.getMessage()); - return false; - } catch (SAXException saxe) { - TraceManager.addError("Error when parsing server info:" + saxe.getMessage()); - TraceManager.addError("xml:" + xmldata); - return false; - } - return true; - - } - - protected boolean loadConfiguration(Node node1) { - NodeList diagramNl = node1.getChildNodes(); - if (diagramNl == null) { - return false; - } - Element elt, elt0; - Node node, node0, node00; - NodeList nl, nl0; - - try { - for(int j=0; j<diagramNl.getLength(); j++) { - //System.out.println("Ndes: " + j); - node = diagramNl.item(j); - - if (node == null) { - TraceManager.addDev("null node"); - return false; - } - - if (node.getNodeType() == Node.ELEMENT_NODE) { - elt = (Element)node; - - //TraceManager.addDev("Found tag:" + elt.getTagName()); - - if (elt.getTagName().compareTo(SIMULATION_GLOBAL) ==0) { - loadGlobalConfiguration(node); - } - - } - } - } catch (Exception e) { - TraceManager.addError("Exception in xml parsing " + e.getMessage() + " node= " + node1); - return false; - } - - return true; - } - - - protected boolean loadGlobalConfiguration(Node node1) { - - TraceManager.addDev("Global configuration"); - - NodeList diagramNl = node1.getChildNodes(); - if (diagramNl == null) { - return false; - } - Element elt, elt0; - Node node, node0, node00; - NodeList nl, nl0; - - - //int val; - - String id; - String name; - String util = null; - String extime; - String contdel; - String busname; - String busid; - String state; - String simdur; - - int k, l; - - try { - for(int j=0; j<diagramNl.getLength(); j++) { - //System.out.println("Ndes: " + j); - node = diagramNl.item(j); - - if (node == null) { - TraceManager.addDev("null node"); - return false; - } - - if (node.getNodeType() == Node.ELEMENT_NODE) { - elt = (Element)node; - - //TraceManager.addDev("Found tag tag:" + elt.getTagName()); - - // Status - if (elt.getTagName().compareTo(SIMULATION_DURATION) == 0) { - simdur = elt.getTextContent(); - //System.out.println("Simulation duration=" + simdur); - simulationDurations.add(new Long(simdur)); - } - if (elt.getTagName().compareTo("EndTime")==0){ - String end = elt.getTextContent(); - cycleDurations.add(new Long(end)); - } - - if (elt.getTagName().compareTo(SIMULATION_CPU) == 0) { - id = null; - name = null; - contdel = null; - busname = null; - busid = null; - util = null; - - id = elt.getAttribute("id"); - name = elt.getAttribute("name"); - - if ((id != null) && (name != null)) { - nl = elt.getElementsByTagName("util"); - if ((nl != null) && (nl.getLength() > 0)) { - node0 = nl.item(0); - //System.out.println("nl:" + nl + " value=" + node0.getNodeValue() + " content=" + node0.getTextContent()); - util = node0.getTextContent(); - } - - //System.out.println("toto12"); - nl = elt.getElementsByTagName("contdel"); - if ((nl != null) && (nl.getLength() > 0)) { - nl = elt.getElementsByTagName("contdel"); - node0 = nl.item(0); - elt0 = (Element)node0; - busid = elt0.getAttribute("busID"); - busname = elt0.getAttribute("busName"); - //System.out.println("nl:" + nl + " value=" + node0.getNodeValue() + " content=" + node0.getTextContent()); - contdel = node0.getTextContent(); - } - - if ((util != null) || ((contdel != null) && (busid != null) && (busname != null))) { - CPUResult cpur = new CPUResult(); - try { - cpur.id = Integer.decode(id).intValue(); - cpur.name = name; - - if (util != null) { - cpur.utilization = Double.valueOf(util).doubleValue(); - } - - if ((contdel != null) && (busid != null) && (busname != null)) { - BusContentionResult bcr = new BusContentionResult(); - bcr.id = Integer.decode(busid).intValue(); - bcr.name = busname; - bcr.contention = Long.decode(contdel).longValue(); - cpur.addContentionOnBus(bcr); - } - - AddingCPUResult(cpur); - } catch (Exception e) { - } - } - } - - - } - - if (elt.getTagName().compareTo(SIMULATION_BUS) == 0) { - name = null; - id = null; - extime = null; - - - id = elt.getAttribute("id"); - name = elt.getAttribute("name"); - - if ((id != null) && (name != null)) { - nl = elt.getElementsByTagName("util"); - if ((nl != null) && (nl.getLength() > 0)) { - node0 = nl.item(0); - //System.out.println("nl:" + nl + " value=" + node0.getNodeValue() + " content=" + node0.getTextContent()); - util = node0.getTextContent(); - } - - if (util != null) { - BusResult busr = new BusResult(); - try { - busr.id = Integer.decode(id).intValue(); - busr.name = name; - busr.utilization = Double.valueOf(util).doubleValue(); - AddingBusResult(busr); - } catch (Exception e) { - } - } - - } - } - - if (elt.getTagName().compareTo(SIMULATION_TASK) == 0) { - busname = null; - busid = null; - util = null; - extime = null; - state = null; - - id = elt.getAttribute("id"); - name = elt.getAttribute("name"); - - if ((id != null) && (name != null)) { - nl = elt.getElementsByTagName("extime"); - if ((nl != null) && (nl.getLength() > 0)) { - node0 = nl.item(0); - //System.out.println("nl:" + nl + " value=" + node0.getNodeValue() + " content=" + node0.getTextContent()); - extime = node0.getTextContent(); - } - - nl = elt.getElementsByTagName("tskstate"); - if ((nl != null) && (nl.getLength() > 0)) { - node0 = nl.item(0); - //System.out.println("nl:" + nl + " value=" + node0.getNodeValue() + " content=" + node0.getTextContent()); - state = node0.getTextContent(); - } - - if (extime != null) { - TaskResult tr = new TaskResult(); - try { - tr.id = Integer.decode(id).intValue(); - tr.name = name; - tr.nbOfExecutedCycles = Long.decode(extime).longValue(); - tr.state = state; - AddingTaskResult(tr); - } catch (Exception e) { - } - } - - } - } - } - } - } catch (Exception e) { - TraceManager.addError("Exception in xml parsing " + e.getMessage() + " node= " + node1); - return false; - } - - return true; - } - - public synchronized void AddingCPUResult(CPUResult cpur) { - cpus.add(cpur); - } - - public synchronized void AddingBusResult(BusResult br) { - busses.add(br); - } - - public synchronized void AddingTaskResult(TaskResult tr) { - tasks.add(tr); - } - - - public static String decodeString(String s) { - if (s == null) - return s; - byte b[] = null; - try { - b = s.getBytes("ISO-8859-1"); - return new String(b); - } catch (Exception e) { - return null; - } - } - - public void computeResults() { - - Hashtable<Integer, Object> resultsTable = new Hashtable<>(); - Object o; - CPUWholeResult cpuwr; - BusWholeResult buswr; - TaskWholeResult taskwr; - - // Durations - for(Long l: simulationDurations) { - if (sdwr == null) { - sdwr = new SimulationDurationWholeResult(l.longValue()); - } else { - sdwr.updateResults(l.longValue()); - } - } - - for(Long l: cycleDurations) { - if (cdwr == null) { - cdwr = new SimulationDurationWholeResult(l.longValue()); - } else { - cdwr.updateResults(l.longValue()); - } - } - // CPUs - wcpus = new Vector<CPUWholeResult>(); - for(CPUResult rescpu: cpus) { - o = resultsTable.get(rescpu.id); - //TraceManager.addDev("Got o=" + o); - if (o == null) { - cpuwr = new CPUWholeResult(rescpu); - resultsTable.put(rescpu.id, cpuwr); - wcpus.add(cpuwr); - - } else { - cpuwr = (CPUWholeResult)o; - cpuwr.updateResults(rescpu); - } - } - - wbusses = new Vector<BusWholeResult>(); - for(BusResult resbus: busses) { - o = resultsTable.get(resbus.id); - //TraceManager.addDev("Got o=" + o); - if (o == null) { - buswr = new BusWholeResult(resbus); - resultsTable.put(resbus.id, buswr); - wbusses.add(buswr); - - } else { - buswr = (BusWholeResult)o; - buswr.updateResults(resbus); - } - } - - wtasks = new Vector<TaskWholeResult>(); - for(TaskResult restask: tasks) { - o = resultsTable.get(restask.id); - //TraceManager.addDev("Got o=" + o); - if (o == null) { - taskwr = new TaskWholeResult(restask); - resultsTable.put(restask.id, taskwr); - wtasks.add(taskwr); - - } else { - taskwr = (TaskWholeResult)o; - taskwr.updateResults(restask); - } - } - - //TraceManager.addDev("Done compte results"); - } - - - public String getWholeResults() { - StringBuffer sb = new StringBuffer(""); - - // sb.append(sdwr.toStringResult() + "\n"); - sb.append("CYCLE "+cdwr.toStringResult() + "\n"); - for(CPUWholeResult reswcpu: wcpus) { - sb.append(reswcpu.toStringResult() + "\n"); - } - - for(BusWholeResult reswbus: wbusses) { - sb.append(reswbus.toStringResult() + "\n"); - } - - for(TaskWholeResult reswtask: wtasks) { - sb.append(reswtask.toStringResult() + "\n"); - } - - return sb.toString(); - } - - public String getAllResults() { - StringBuffer sb = new StringBuffer(""); - - for(Long l: simulationDurations) { - sb.append("DURATION " + l + "\n"); - } - for(Long l: cycleDurations) { - sb.append("CYCLES " + l + "\n"); - } - - for(CPUResult rescpu: cpus) { - sb.append(rescpu.toStringResult() + "\n"); - } - - for(BusResult resbus: busses) { - sb.append(resbus.toStringResult() + "\n"); - } - - for(TaskResult restask: tasks) { - sb.append(restask.toStringResult() + "\n"); - } - - return sb.toString(); - } - - public String getAllComments() { - String s = ""; - - for(String st: comments) { - s+= "#" + st + "\n"; - } - - return s; - - } - - public static String getExplanationHeader() { - String s; - s = "# Simulation duration: DURATION nbOfResults minDuration averageDuration maxDuration\n"; - s += "# Cycle duration: DURATION nbOfResults minCycles averageCycles maxCycles\n"; - s += "# CPUs: CPU ID Name nbOfResults minUtilization averageUtilization maxUtilization\n"; - s += "# Contention on busses: CPU_BUS_CONTENTION CPUID CPUName BusID BusName nbOfResults minContentionCycles averageContentionCycles maxContentionCycles\n"; - s += "# Busses: BUS ID Name nbOfResults minUtilization averageUtilization maxUtilization\n"; - s += "# Tasks: TASK ID Name nbOfResults minExecutedCycles averageExecutedCycles maxExecutedCycles nbOfRunnable nbOfRunning nbOfsuspended nbOfTerminated\n"; - - s+= "\n"; - - return s; - } - - public static String getAllExplanationHeader() { - String s; - s = "# Simulation duration: DURATION value (in us)\n"; - s += "# Cycle duration: DURATION value (in cycles)\n"; - s += "# CPUs: CPU ID Name utilization\n"; - s += "# Contention on busses: CPU_BUS_CONTENTION CPUID CPUName BusID BusName contentionCycle\n"; - s += "# Busses: BUS ID Name utilization\n"; - s += "# Tasks: TASK ID Name NbOfExecutedCycles state\n"; - return s; - } - - public double getAverageCPUUsage() { - double average = 0; - - for(CPUWholeResult wcpu: wcpus) { - average += wcpu.averageUtilization; - } - - return average / wcpus.size(); - } - - public double getMaxCPUUsage() { - double max = 0; - - for(CPUWholeResult wcpu: wcpus) { - max = Math.max(max, wcpu.maxUtilization); - } - - return max; - } - - public double getMinCPUUsage() { - double min = 1.1; - - for(CPUWholeResult wcpu: wcpus) { - min= Math.min(min, wcpu.minUtilization); - } - - return min; - } - - // Bus - - public double getAverageBusUsage() { - double average = 0; - - for(BusWholeResult wbus: wbusses) { - average += wbus.averageUtilization; - } - - return average / busses.size(); - } - - public double getMaxBusUsage() { - double max = 0; - - for(BusWholeResult wbus: wbusses) { - max = Math.max(max, wbus.maxUtilization); - } - - return max; - } - - public double getMinBusUsage() { - double min = 1.1; - - for(BusWholeResult wbus: wbusses) { - min= Math.min(min, wbus.minUtilization); - } - - return min; - } - - // Bus contention - - - public double getAverageBusContention() { - double average = 0; - - for(CPUWholeResult wcpu: wcpus) { - average += wcpu.getAverageBusContention(); - } - - return average / wcpus.size(); - } - - public long getMaxBusContention() { - long max = 0; - - for(CPUWholeResult wcpu: wcpus) { - max = Math.max(max, wcpu.getMaxBusContention()); - } - - return max; - } - - public long getMinBusContention() { - long min = 0; - - for(CPUWholeResult wcpu: wcpus) { - min= Math.min(min, wcpu.getMinBusContention()); - } - - return min; - } - - public double getAverageSimulationDuration() { - return sdwr.averageDuration; - } - public double getAverageCycleDuration(){ - return cdwr.averageDuration; - } - public long getMaxSimulationDuration() { - return sdwr.maxDuration; - } - - public long getMaxCycleDuration() { - return cdwr.maxDuration; - } - - public long getMinSimulationDuration() { - return sdwr.minDuration; - } - - public long getMinCycleDuration() { - return cdwr.minDuration; - } - - - - -} // Class DSEConfiguration + protected static final String SIMULATION_GLOBAL = "global"; + protected static final String SIMULATION_HEADER = "siminfo"; + protected static final String SIMULATION_DURATION = "simdur"; + protected static final String SIMULATION_CPU = "cpu"; + protected static final String SIMULATION_BUS = "bus"; + protected static final String SIMULATION_TASK = "task"; + + private Vector<String> comments; + + private Vector<Long> simulationDurations; + private Vector<Long> cycleDurations; + private Vector<CPUResult> cpus; + private Vector<BusResult> busses; + private Vector<TaskResult> tasks; + + private SimulationDurationWholeResult sdwr; + private SimulationDurationWholeResult cdwr; + private Vector<CPUWholeResult> wcpus; + private Vector<BusWholeResult> wbusses; + private Vector<TaskWholeResult> wtasks; + private int addedSecurity=0; + + + public DSESimulationResult() { + reset(); + } + + public void reset() { + cpus = new Vector<CPUResult>(); + busses = new Vector<BusResult>(); + tasks = new Vector<TaskResult>(); + comments = new Vector<String>(); + simulationDurations = new Vector<Long>(); + cycleDurations = new Vector<Long>(); + } + + public void addComment(String _comment) { + comments.add(_comment); + } + + public int getAddedSecurity(){ + return addedSecurity; + } + public void setAddedSecurity(int i){ + addedSecurity = i; + } + public int loadResultFromXMLFile(String pathToFile) { + File f = new File(pathToFile); + String data = FileUtils.loadFileData(f); + + if (data == null) { + return -1; + } + + analyzeServerAnswer(data); + + return 0; + } + + protected void analyzeServerAnswer(String s) { + //System.out.println("From server:" + s); + int index0 = s.indexOf("<?xml"); + String ssxml = ""; + + if (index0 != -1) { + //System.out.println("toto1"); + ssxml = s.substring(index0, s.length()) + "\n"; + } else { + //System.out.println("toto2"); + ssxml = ssxml + s + "\n"; + } + + index0 = ssxml.indexOf("</siminfo>"); + + if (index0 != -1) { + //System.out.println("toto3"); + ssxml = ssxml.substring(0, index0+10); + loadXMLInfoFromServer(ssxml); + ssxml = ""; + } + + //TraceManager.addDev("Computing results"); + //TraceManager.addDev("infos on cpus:" + cpus.size()); + //TraceManager.addDev("infos on busses:" + busses.size()); + //TraceManager.addDev("infos on tasks:" + tasks.size()); + + + // Compute results! + + //System.out.println("toto4"); + + } + + protected boolean loadXMLInfoFromServer(String xmldata) { + //jta.append("XML from server:" + xmldata + "\n\n"); + + DocumentBuilderFactory dbf; + DocumentBuilder db; + + try { + dbf = DocumentBuilderFactory.newInstance(); + db = dbf.newDocumentBuilder(); + } catch (ParserConfigurationException e) { + dbf = null; + db = null; + } + + if ((dbf == null) || (db == null)) { + return false; + } + + ByteArrayInputStream bais = new ByteArrayInputStream(decodeString(xmldata).getBytes()); + int i; + + try { + // building nodes from xml String + Document doc = db.parse(bais); + NodeList nl; + Node node; + + nl = doc.getElementsByTagName(SIMULATION_HEADER); + + if (nl == null) { + return false; + } + + for(i=0; i<nl.getLength(); i++) { + node = nl.item(i); + if (node.getNodeType() == Node.ELEMENT_NODE) { + // create design, and get an index for it + return loadConfiguration(node); + } + } + + } catch (IOException e) { + TraceManager.addError("Error when parsing server info:" + e.getMessage()); + return false; + } catch (SAXException saxe) { + TraceManager.addError("Error when parsing server info:" + saxe.getMessage()); + TraceManager.addError("xml:" + xmldata); + return false; + } + return true; + + } + + protected boolean loadConfiguration(Node node1) { + NodeList diagramNl = node1.getChildNodes(); + if (diagramNl == null) { + return false; + } + Element elt, elt0; + Node node, node0, node00; + NodeList nl, nl0; + + try { + for(int j=0; j<diagramNl.getLength(); j++) { + //System.out.println("Ndes: " + j); + node = diagramNl.item(j); + + if (node == null) { + TraceManager.addDev("null node"); + return false; + } + + if (node.getNodeType() == Node.ELEMENT_NODE) { + elt = (Element)node; + + //TraceManager.addDev("Found tag:" + elt.getTagName()); + + if (elt.getTagName().compareTo(SIMULATION_GLOBAL) ==0) { + loadGlobalConfiguration(node); + } + + } + } + } catch (Exception e) { + TraceManager.addError("Exception in xml parsing " + e.getMessage() + " node= " + node1); + return false; + } + + return true; + } + + + protected boolean loadGlobalConfiguration(Node node1) { + + TraceManager.addDev("Global configuration"); + + NodeList diagramNl = node1.getChildNodes(); + if (diagramNl == null) { + return false; + } + Element elt, elt0; + Node node, node0, node00; + NodeList nl, nl0; + + + //int val; + + String id; + String name; + String util = null; + String extime; + String contdel; + String busname; + String busid; + String state; + String simdur; + + int k, l; + + try { + for(int j=0; j<diagramNl.getLength(); j++) { + //System.out.println("Ndes: " + j); + node = diagramNl.item(j); + + if (node == null) { + TraceManager.addDev("null node"); + return false; + } + + if (node.getNodeType() == Node.ELEMENT_NODE) { + elt = (Element)node; + + //TraceManager.addDev("Found tag tag:" + elt.getTagName()); + + // Status + if (elt.getTagName().compareTo(SIMULATION_DURATION) == 0) { + simdur = elt.getTextContent(); + //System.out.println("Simulation duration=" + simdur); + simulationDurations.add(new Long(simdur)); + } + if (elt.getTagName().compareTo("EndTime")==0){ + String end = elt.getTextContent(); + cycleDurations.add(new Long(end)); + } + + if (elt.getTagName().compareTo(SIMULATION_CPU) == 0) { + id = null; + name = null; + contdel = null; + busname = null; + busid = null; + util = null; + + id = elt.getAttribute("id"); + name = elt.getAttribute("name"); + + if ((id != null) && (name != null)) { + nl = elt.getElementsByTagName("util"); + if ((nl != null) && (nl.getLength() > 0)) { + node0 = nl.item(0); + //System.out.println("nl:" + nl + " value=" + node0.getNodeValue() + " content=" + node0.getTextContent()); + util = node0.getTextContent(); + } + + //System.out.println("toto12"); + nl = elt.getElementsByTagName("contdel"); + if ((nl != null) && (nl.getLength() > 0)) { + nl = elt.getElementsByTagName("contdel"); + node0 = nl.item(0); + elt0 = (Element)node0; + busid = elt0.getAttribute("busID"); + busname = elt0.getAttribute("busName"); + //System.out.println("nl:" + nl + " value=" + node0.getNodeValue() + " content=" + node0.getTextContent()); + contdel = node0.getTextContent(); + } + + if ((util != null) || ((contdel != null) && (busid != null) && (busname != null))) { + CPUResult cpur = new CPUResult(); + try { + cpur.id = Integer.decode(id).intValue(); + cpur.name = name; + + if (util != null) { + cpur.utilization = Double.valueOf(util).doubleValue(); + } + + if ((contdel != null) && (busid != null) && (busname != null)) { + BusContentionResult bcr = new BusContentionResult(); + bcr.id = Integer.decode(busid).intValue(); + bcr.name = busname; + bcr.contention = Long.decode(contdel).longValue(); + cpur.addContentionOnBus(bcr); + } + + AddingCPUResult(cpur); + } catch (Exception e) { + } + } + } + + + } + + if (elt.getTagName().compareTo(SIMULATION_BUS) == 0) { + name = null; + id = null; + extime = null; + + + id = elt.getAttribute("id"); + name = elt.getAttribute("name"); + + if ((id != null) && (name != null)) { + nl = elt.getElementsByTagName("util"); + if ((nl != null) && (nl.getLength() > 0)) { + node0 = nl.item(0); + //System.out.println("nl:" + nl + " value=" + node0.getNodeValue() + " content=" + node0.getTextContent()); + util = node0.getTextContent(); + } + + if (util != null) { + BusResult busr = new BusResult(); + try { + busr.id = Integer.decode(id).intValue(); + busr.name = name; + busr.utilization = Double.valueOf(util).doubleValue(); + AddingBusResult(busr); + } catch (Exception e) { + } + } + + } + } + + if (elt.getTagName().compareTo(SIMULATION_TASK) == 0) { + busname = null; + busid = null; + util = null; + extime = null; + state = null; + + id = elt.getAttribute("id"); + name = elt.getAttribute("name"); + + if ((id != null) && (name != null)) { + nl = elt.getElementsByTagName("extime"); + if ((nl != null) && (nl.getLength() > 0)) { + node0 = nl.item(0); + //System.out.println("nl:" + nl + " value=" + node0.getNodeValue() + " content=" + node0.getTextContent()); + extime = node0.getTextContent(); + } + + nl = elt.getElementsByTagName("tskstate"); + if ((nl != null) && (nl.getLength() > 0)) { + node0 = nl.item(0); + //System.out.println("nl:" + nl + " value=" + node0.getNodeValue() + " content=" + node0.getTextContent()); + state = node0.getTextContent(); + } + + if (extime != null) { + TaskResult tr = new TaskResult(); + try { + tr.id = Integer.decode(id).intValue(); + tr.name = name; + tr.nbOfExecutedCycles = Long.decode(extime).longValue(); + tr.state = state; + AddingTaskResult(tr); + } catch (Exception e) { + } + } + + } + } + } + } + } catch (Exception e) { + TraceManager.addError("Exception in xml parsing " + e.getMessage() + " node= " + node1); + return false; + } + + return true; + } + + public synchronized void AddingCPUResult(CPUResult cpur) { + cpus.add(cpur); + } + + public synchronized void AddingBusResult(BusResult br) { + busses.add(br); + } + + public synchronized void AddingTaskResult(TaskResult tr) { + tasks.add(tr); + } + + + public static String decodeString(String s) { + if (s == null) + return s; + byte b[] = null; + try { + b = s.getBytes("ISO-8859-1"); + return new String(b); + } catch (Exception e) { + return null; + } + } + + public void computeResults() { + + Hashtable<Integer, Object> resultsTable = new Hashtable<>(); + Object o; + CPUWholeResult cpuwr; + BusWholeResult buswr; + TaskWholeResult taskwr; + + // Durations + for(Long l: simulationDurations) { + if (sdwr == null) { + sdwr = new SimulationDurationWholeResult(l.longValue()); + } else { + sdwr.updateResults(l.longValue()); + } + } + + for(Long l: cycleDurations) { + if (cdwr == null) { + cdwr = new SimulationDurationWholeResult(l.longValue()); + } else { + cdwr.updateResults(l.longValue()); + } + } + // CPUs + wcpus = new Vector<CPUWholeResult>(); + for(CPUResult rescpu: cpus) { + o = resultsTable.get(rescpu.id); + //TraceManager.addDev("Got o=" + o); + if (o == null) { + cpuwr = new CPUWholeResult(rescpu); + resultsTable.put(rescpu.id, cpuwr); + wcpus.add(cpuwr); + + } else { + cpuwr = (CPUWholeResult)o; + cpuwr.updateResults(rescpu); + } + } + + wbusses = new Vector<BusWholeResult>(); + for(BusResult resbus: busses) { + o = resultsTable.get(resbus.id); + //TraceManager.addDev("Got o=" + o); + if (o == null) { + buswr = new BusWholeResult(resbus); + resultsTable.put(resbus.id, buswr); + wbusses.add(buswr); + + } else { + buswr = (BusWholeResult)o; + buswr.updateResults(resbus); + } + } + + wtasks = new Vector<TaskWholeResult>(); + for(TaskResult restask: tasks) { + o = resultsTable.get(restask.id); + //TraceManager.addDev("Got o=" + o); + if (o == null) { + taskwr = new TaskWholeResult(restask); + resultsTable.put(restask.id, taskwr); + wtasks.add(taskwr); + + } else { + taskwr = (TaskWholeResult)o; + taskwr.updateResults(restask); + } + } + + //TraceManager.addDev("Done compte results"); + } + + + public String getWholeResults() { + StringBuffer sb = new StringBuffer(""); + + // sb.append(sdwr.toStringResult() + "\n"); + sb.append("CYCLE "+cdwr.toStringResult() + "\n"); + for(CPUWholeResult reswcpu: wcpus) { + sb.append(reswcpu.toStringResult() + "\n"); + } + + for(BusWholeResult reswbus: wbusses) { + sb.append(reswbus.toStringResult() + "\n"); + } + + for(TaskWholeResult reswtask: wtasks) { + sb.append(reswtask.toStringResult() + "\n"); + } + + return sb.toString(); + } + + public String getAllResults() { + StringBuffer sb = new StringBuffer(""); + + for(Long l: simulationDurations) { + sb.append("DURATION " + l + "\n"); + } + for(Long l: cycleDurations) { + sb.append("CYCLES " + l + "\n"); + } + + for(CPUResult rescpu: cpus) { + sb.append(rescpu.toStringResult() + "\n"); + } + + for(BusResult resbus: busses) { + sb.append(resbus.toStringResult() + "\n"); + } + + for(TaskResult restask: tasks) { + sb.append(restask.toStringResult() + "\n"); + } + + return sb.toString(); + } + + public String getAllComments() { + String s = ""; + + for(String st: comments) { + s+= "#" + st + "\n"; + } + + return s; + + } + + public static String getExplanationHeader() { + String s; + s = "# Simulation duration: DURATION nbOfResults minDuration averageDuration maxDuration\n"; + s += "# Cycle duration: DURATION nbOfResults minCycles averageCycles maxCycles\n"; + s += "# CPUs: CPU ID Name nbOfResults minUtilization averageUtilization maxUtilization\n"; + s += "# Contention on busses: CPU_BUS_CONTENTION CPUID CPUName BusID BusName nbOfResults minContentionCycles averageContentionCycles maxContentionCycles\n"; + s += "# Busses: BUS ID Name nbOfResults minUtilization averageUtilization maxUtilization\n"; + s += "# Tasks: TASK ID Name nbOfResults minExecutedCycles averageExecutedCycles maxExecutedCycles nbOfRunnable nbOfRunning nbOfsuspended nbOfTerminated\n"; + + s+= "\n"; + + return s; + } + + public static String getAllExplanationHeader() { + String s; + s = "# Simulation duration: DURATION value (in us)\n"; + s += "# Cycle duration: DURATION value (in cycles)\n"; + s += "# CPUs: CPU ID Name utilization\n"; + s += "# Contention on busses: CPU_BUS_CONTENTION CPUID CPUName BusID BusName contentionCycle\n"; + s += "# Busses: BUS ID Name utilization\n"; + s += "# Tasks: TASK ID Name NbOfExecutedCycles state\n"; + return s; + } + + public double getAverageCPUUsage() { + double average = 0; + + for(CPUWholeResult wcpu: wcpus) { + average += wcpu.averageUtilization; + } + + return average / wcpus.size(); + } + + public double getMaxCPUUsage() { + double max = 0; + + for(CPUWholeResult wcpu: wcpus) { + max = Math.max(max, wcpu.maxUtilization); + } + + return max; + } + + public double getMinCPUUsage() { + double min = 1.1; + + for(CPUWholeResult wcpu: wcpus) { + min= Math.min(min, wcpu.minUtilization); + } + + return min; + } + + // Bus + + public double getAverageBusUsage() { + double average = 0; + + for(BusWholeResult wbus: wbusses) { + average += wbus.averageUtilization; + } + + return average / busses.size(); + } + + public double getMaxBusUsage() { + double max = 0; + + for(BusWholeResult wbus: wbusses) { + max = Math.max(max, wbus.maxUtilization); + } + + return max; + } + + public double getMinBusUsage() { + double min = 1.1; + + for(BusWholeResult wbus: wbusses) { + min= Math.min(min, wbus.minUtilization); + } + + return min; + } + + // Bus contention + + + public double getAverageBusContention() { + double average = 0; + + for(CPUWholeResult wcpu: wcpus) { + average += wcpu.getAverageBusContention(); + } + + return average / wcpus.size(); + } + + public long getMaxBusContention() { + long max = 0; + + for(CPUWholeResult wcpu: wcpus) { + max = Math.max(max, wcpu.getMaxBusContention()); + } + + return max; + } + + public long getMinBusContention() { + long min = 0; + + for(CPUWholeResult wcpu: wcpus) { + min= Math.min(min, wcpu.getMinBusContention()); + } + + return min; + } + + public double getAverageSimulationDuration() { + return sdwr.averageDuration; + } + public double getAverageCycleDuration(){ + return cdwr.averageDuration; + } + public long getMaxSimulationDuration() { + return sdwr.maxDuration; + } + + public long getMaxCycleDuration() { + return cdwr.maxDuration; + } + + public long getMinSimulationDuration() { + return sdwr.minDuration; + } + + public long getMinCycleDuration() { + return cdwr.minDuration; + } + + + + +} // Class DSEConfiguration diff --git a/src/main/java/tmltranslator/TMLMapping.java b/src/main/java/tmltranslator/TMLMapping.java index db47137686b5d4ea3abb3e6c2872219955853eb8..e1beb71f31036eaed1f406bd1070bc3e2d29d767 100755 --- a/src/main/java/tmltranslator/TMLMapping.java +++ b/src/main/java/tmltranslator/TMLMapping.java @@ -71,7 +71,7 @@ public class TMLMapping<E> { private List<HwCommunicationNode> oncommnodes; private List<TMLElement> mappedcommelts; - private CorrespondanceTGElement listE; + private CorrespondanceTGElement listE; // Security public boolean firewall = false; @@ -149,13 +149,13 @@ public class TMLMapping<E> { return null; } - public CorrespondanceTGElement getCorrespondanceList(){ - return listE; - } + public CorrespondanceTGElement getCorrespondanceList(){ + return listE; + } - public void setCorrespondanceList(CorrespondanceTGElement cl){ - listE=cl; - } + public void setCorrespondanceList(CorrespondanceTGElement cl){ + listE=cl; + } public void addCustomValue(String custom) { @@ -1501,8 +1501,8 @@ public class TMLMapping<E> { } } - public boolean channelAllowed(TMLChannel chan){ - TMLTask orig = chan.getOriginTask(); + public boolean channelAllowed(TMLChannel chan){ + TMLTask orig = chan.getOriginTask(); TMLTask dest = chan.getDestinationTask(); List<HwNode> path = getPath(orig, dest); for (HwNode node:path){ @@ -1519,10 +1519,10 @@ public class TMLMapping<E> { } } return true; - } + } - public List<HwNode> getPath(TMLTask t1, TMLTask t2){ + public List<HwNode> getPath(TMLTask t1, TMLTask t2){ HwNode node1 = getHwNodeOf(t1); HwNode node2 = getHwNodeOf(t2); List<HwNode> path = new ArrayList<HwNode>(); @@ -1576,20 +1576,20 @@ public class TMLMapping<E> { } - public boolean isAttackerAccessible(TMLChannel chan){ - TMLTask orig = chan.getSystemOriginTask(); + public boolean isAttackerAccessible(TMLChannel chan){ + TMLTask orig = chan.getSystemOriginTask(); TMLTask dest = chan.getSystemDestinationTask(); List<HwNode> path = getPath(orig, dest); for (HwNode node:path){ - if (node instanceof HwBus){ - HwBus bus = (HwBus) node; - if (bus.privacy==HwCommunicationNode.BUS_PUBLIC){ - return true; - } - } - } - return false; - } + if (node instanceof HwBus){ + HwBus bus = (HwBus) node; + if (bus.privacy==HwCommunicationNode.BUS_PUBLIC){ + return true; + } + } + } + return false; + } public String toXML() { String s = "<TMLMAPPING>\n"; diff --git a/src/main/java/ui/tmldd/TMLArchiPortArtifact.java b/src/main/java/ui/tmldd/TMLArchiPortArtifact.java index 24bbb18a2192f6c137969170c0939280f51e15af..ce29476d816fe9e01fe24498766a9fc4b8779efb 100644 --- a/src/main/java/ui/tmldd/TMLArchiPortArtifact.java +++ b/src/main/java/ui/tmldd/TMLArchiPortArtifact.java @@ -225,7 +225,7 @@ public class TMLArchiPortArtifact extends TGCWithoutInternalComponent implements boolean error = false; // Get the list of all other TMLArchiPortArtifact.java and retrieve the mapped ports - Vector<String> portsList = this.getTDiagramPanel().getMGUI().getAllTMLInputPorts(); + Vector<String> portsList = this.getTDiagramPanel().getMGUI().getAllTMLInputPorts(); //TraceManager.addDev( "bufferParameters before opening the window: " + bufferParameters.toString() ); JDialogPortArtifact dialog = new JDialogPortArtifact( frame, "Setting port artifact attributes", this, mappedMemory, portsList, value ); diff --git a/src/main/java/ui/window/JDialogPortArtifact.java b/src/main/java/ui/window/JDialogPortArtifact.java index 52e3f165c5f969d5472a0e0ecc051edf515a26f2..aca45f5a147430d0cfd838f6fc6e90bd8ab823b7 100644 --- a/src/main/java/ui/window/JDialogPortArtifact.java +++ b/src/main/java/ui/window/JDialogPortArtifact.java @@ -1,28 +1,28 @@ /* Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille, * Nokia Bell Labs France, Andrea ENRICI - * + * * ludovic.apvrille AT enst.fr * andrea.enrici AT nokia.com - * + * * This software is a computer program whose purpose is to allow the * edition of TURTLE analysis, design and deployment diagrams, to * allow the generation of RT-LOTOS or Java code from this diagram, * and at last to allow the analysis of formal validation traces * obtained from external tools, e.g. RTL from LAAS-CNRS and CADP * from INRIA Rhone-Alpes. - * + * * This software is governed by the CeCILL license under French law and * abiding by the rules of distribution of free software. You can use, * modify and/ or redistribute the software under the terms of the CeCILL * license as circulated by CEA, CNRS and INRIA at the following URL * "http://www.cecill.info". - * + * * As a counterpart to the access to the source code and rights to copy, * modify and redistribute granted by the license, users are provided only * with a limited warranty and the software's author, the holder of the * economic rights, and the successive licensors have only limited * liability. - * + * * In this respect, the user's attention is drawn to the risks associated * with loading, using, modifying and/or developing or reproducing the * software by the user in light of its specific status of free software, @@ -33,7 +33,7 @@ * requirements in conditions enabling the security of their systems and/or * data to be ensured and, more generally, to use and operate it in the * same conditions as regards security. - * + * * The fact that you are presently reading this means that you have had * knowledge of the CeCILL license and that you accept its terms. */ @@ -74,66 +74,66 @@ import ui.tmldd.TMLArchiPortArtifact; * @author Ludovic APVRILLE, Andrea ENRICI */ public class JDialogPortArtifact extends JDialogBase implements ActionListener { - - private boolean regularClose; - private boolean emptyPortsList = false; - + + private boolean regularClose; + private boolean emptyPortsList = false; + private JPanel panel2; //private Frame frame; private TMLArchiPortArtifact artifact; - private String mappedMemory = "VOID"; - - protected JComboBox<String> mappedPortCB, memoryCB; - protected JTextField baseAddressTF, numSamplesTF, bitsPerSymbolTF; - protected String baseAddress, mappedPort, sampleLength, numSamples, bitsPerSymbol; - protected String bank, dataType, symmetricalValue; - protected JComboBox<String> dataTypeCB, bankCB, symmetricalValueCB; - - //Intl Data In - protected JTextField widthIntl_TF, bitInOffsetIntl_TF, inputOffsetIntl_TF; - protected String widthIntl, bitInOffsetIntl, inputOffsetIntl, packedBinaryInIntl; - protected JComboBox<String> packedBinaryInIntl_CB; - - //Intl Data Out - protected JTextField bitOutOffsetIntl_TF, outputOffsetIntl_TF; - protected JComboBox<String> packedBinaryOutIntl_CB; - protected String packedBinaryOutIntl, bitOutOffsetIntl, outputOffsetIntl; - - //Intl Perm - protected JTextField lengthPermIntl_TF, offsetPermIntl_TF; - protected String lengthPermIntl, offsetPermIntl; - - //Mapper Data In - protected JTextField baseAddressDataInMapp_TF, numSamplesDataInMapp_TF, bitsPerSymbolDataInMapp_TF; - protected String baseAddressDataInMapp, numSamplesDataInMapp, bitsPerSymbolDataInMapp, symmetricalValueDataInMapp; - protected JComboBox<String> symmetricalValueDataInMapp_CB; - //Mapper Data Out - protected JTextField baseAddressDataOutMapp_TF; - protected String baseAddressDataOutMapp; - //Mapper LUT - protected JTextField baseAddressLUTMapp_TF; - protected String baseAddressLUTMapp; - - //Code generation - private JPanel panel3;//, panel4, panel5; - //private JTabbedPane tabbedPane; - //private String HALUnitName = ""; - private Vector<String> portsList; - //private String appName = ""; - + private String mappedMemory = "VOID"; + + protected JComboBox<String> mappedPortCB, memoryCB; + protected JTextField baseAddressTF, numSamplesTF, bitsPerSymbolTF; + protected String baseAddress, mappedPort, sampleLength, numSamples, bitsPerSymbol; + protected String bank, dataType, symmetricalValue; + protected JComboBox<String> dataTypeCB, bankCB, symmetricalValueCB; + + //Intl Data In + protected JTextField widthIntl_TF, bitInOffsetIntl_TF, inputOffsetIntl_TF; + protected String widthIntl, bitInOffsetIntl, inputOffsetIntl, packedBinaryInIntl; + protected JComboBox<String> packedBinaryInIntl_CB; + + //Intl Data Out + protected JTextField bitOutOffsetIntl_TF, outputOffsetIntl_TF; + protected JComboBox<String> packedBinaryOutIntl_CB; + protected String packedBinaryOutIntl, bitOutOffsetIntl, outputOffsetIntl; + + //Intl Perm + protected JTextField lengthPermIntl_TF, offsetPermIntl_TF; + protected String lengthPermIntl, offsetPermIntl; + + //Mapper Data In + protected JTextField baseAddressDataInMapp_TF, numSamplesDataInMapp_TF, bitsPerSymbolDataInMapp_TF; + protected String baseAddressDataInMapp, numSamplesDataInMapp, bitsPerSymbolDataInMapp, symmetricalValueDataInMapp; + protected JComboBox<String> symmetricalValueDataInMapp_CB; + //Mapper Data Out + protected JTextField baseAddressDataOutMapp_TF; + protected String baseAddressDataOutMapp; + //Mapper LUT + protected JTextField baseAddressLUTMapp_TF; + protected String baseAddressLUTMapp; + + //Code generation + private JPanel panel3;//, panel4, panel5; + //private JTabbedPane tabbedPane; + //private String HALUnitName = ""; + private Vector<String> portsList; + //private String appName = ""; + /** Creates new form */ public JDialogPortArtifact(Frame _frame, String _title, TMLArchiPortArtifact _artifact, String _mappedMemory, Vector<String> _portsList, String _mappedPort ) { super(_frame, _title, true); //frame = _frame; - artifact = _artifact; - mappedMemory = _mappedMemory; - portsList = _portsList; - mappedPort = _mappedPort; - //appName = mappedPort.split("::")[0]; - initComponents(); - pack(); + artifact = _artifact; + mappedMemory = _mappedMemory; + portsList = _portsList; + mappedPort = _mappedPort; + //appName = mappedPort.split("::")[0]; + initComponents(); + pack(); } - + private void initComponents() { Container c = getContentPane(); @@ -143,12 +143,12 @@ public class JDialogPortArtifact extends JDialogBase implements ActionListener GridBagConstraints c0 = new GridBagConstraints(); GridBagConstraints c1 = new GridBagConstraints(); GridBagConstraints c2 = new GridBagConstraints(); - + setFont(new Font("Helvetica", Font.PLAIN, 14)); c.setLayout(gridbag0); - + setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); - + panel2 = new JPanel(); panel2.setLayout(gridbag2); panel2.setBorder(new javax.swing.border.TitledBorder("Artifact attributes")); @@ -159,12 +159,12 @@ public class JDialogPortArtifact extends JDialogBase implements ActionListener panel3.setBorder(new javax.swing.border.TitledBorder("Code generation: memory configuration")); panel3.setPreferredSize(new Dimension(650, 350)); - // Issue #41 Ordering of tabbed panes - // tabbedPane = GraphicLib.createTabbedPane();//new JTabbedPane(); + // Issue #41 Ordering of tabbed panes + // tabbedPane = GraphicLib.createTabbedPane();//new JTabbedPane(); //panel4 = new JPanel(); - // panel5 = new JPanel(); - - c1.gridwidth = 1; + // panel5 = new JPanel(); + + c1.gridwidth = 1; c1.gridheight = 1; c1.weighty = 1.0; c1.weightx = 1.0; @@ -178,294 +178,294 @@ public class JDialogPortArtifact extends JDialogBase implements ActionListener else { mappedPortIndex = portsList.indexOf( mappedPort ); } - + mappedPortCB = new JComboBox<String>( portsList ); mappedPortCB.setSelectedIndex( mappedPortIndex ); panel2.add( new JLabel( "Port:" ), c2 ); - mappedPortCB.addActionListener(this); - panel2.add( mappedPortCB, c1 ); - - //Make the list of memories that are available for being mapped - List<TGComponent> componentList = artifact.getTDiagramPanel().getComponentList(); - Vector<String> memoryList = new Vector<String>(); - for( int k = 0; k < componentList.size(); k++ ) { - if( componentList.get(k) instanceof TMLArchiMemoryNode ) { - memoryList.add( componentList.get(k).getName() ); - } - } + mappedPortCB.addActionListener(this); + panel2.add( mappedPortCB, c1 ); + + //Make the list of memories that are available for being mapped + List<TGComponent> componentList = artifact.getTDiagramPanel().getComponentList(); + Vector<String> memoryList = new Vector<String>(); + for( int k = 0; k < componentList.size(); k++ ) { + if( componentList.get(k) instanceof TMLArchiMemoryNode ) { + memoryList.add( componentList.get(k).getName() ); + } + } if( memoryList.size() == 0 ) { // In case there are no memories in the design - memoryList.add( "No available memory" ); + memoryList.add( "No available memory" ); + } + + memoryCB = new JComboBox<String>( memoryList ); + if( !mappedMemory.equals( "VOID" ) && !mappedMemory.equals( "" ) ) { + memoryCB.setSelectedIndex( memoryList.indexOf( mappedMemory ) ); } + else { + memoryCB.setSelectedIndex( 0 ); + } + panel2.add( new JLabel( "Memory: "), c2 ); + memoryCB.addActionListener(this); + panel2.add( memoryCB, c1 ); + + // main panel; + c0.gridheight = 10; + c0.weighty = 1.0; + c0.weightx = 1.0; + c0.gridwidth = GridBagConstraints.REMAINDER; //end row + c0.fill = GridBagConstraints.BOTH; + c.add( panel2, c0 ); + + c0.gridwidth = 1; + c0.gridheight = 1; + c0.fill = GridBagConstraints.HORIZONTAL; + + initButtons(c0, c, this); + } + // + // private String getBufferTypeFromSelectedMemory( String mappedMemory ) { + // + // List<TGComponent> componentList = artifact.getTDiagramPanel().getComponentList(); + // //Vector<String> list = new Vector<String>(); + // + // for( int k = 0; k < componentList.size(); k++ ) { + // if( componentList.get(k) instanceof TMLArchiMemoryNode ) { + // TMLArchiMemoryNode memoryNode = (TMLArchiMemoryNode)componentList.get(k); + // if( memoryNode.getName().equals( mappedMemory ) ) { + // return memoryNode.getName(); + // } + // } + // } + // return "NO MEC"; //default: the main memory buffer + // } - memoryCB = new JComboBox<String>( memoryList ); - if( !mappedMemory.equals( "VOID" ) && !mappedMemory.equals( "" ) ) { - memoryCB.setSelectedIndex( memoryList.indexOf( mappedMemory ) ); - } - else { - memoryCB.setSelectedIndex( 0 ); - } - panel2.add( new JLabel( "Memory: "), c2 ); - memoryCB.addActionListener(this); - panel2.add( memoryCB, c1 ); - - // main panel; - c0.gridheight = 10; - c0.weighty = 1.0; - c0.weightx = 1.0; - c0.gridwidth = GridBagConstraints.REMAINDER; //end row - c0.fill = GridBagConstraints.BOTH; - c.add( panel2, c0 ); - - c0.gridwidth = 1; - c0.gridheight = 1; - c0.fill = GridBagConstraints.HORIZONTAL; - - initButtons(c0, c, this); - } -// -// private String getBufferTypeFromSelectedMemory( String mappedMemory ) { -// -// List<TGComponent> componentList = artifact.getTDiagramPanel().getComponentList(); -// //Vector<String> list = new Vector<String>(); -// -// for( int k = 0; k < componentList.size(); k++ ) { -// if( componentList.get(k) instanceof TMLArchiMemoryNode ) { -// TMLArchiMemoryNode memoryNode = (TMLArchiMemoryNode)componentList.get(k); -// if( memoryNode.getName().equals( mappedMemory ) ) { -// return memoryNode.getName(); -// } -// } -// } -// return "NO MEC"; //default: the main memory buffer -// } - - public void actionPerformed(ActionEvent evt) { - - /*if( evt.getSource() == memoryCB ) { + public void actionPerformed(ActionEvent evt) { + + /*if( evt.getSource() == memoryCB ) { updateBufferPanel(); - }*/ - String command = evt.getActionCommand(); - // Compare the action command to the known actions. - if (command.equals("Save and Close")) { - closeDialog(); - } else if (command.equals("Cancel")) { - cancelDialog(); - } - } -// -// private void updateBufferPanel() { -// -// GridBagConstraints c1 = new GridBagConstraints(); -// GridBagConstraints c2 = new GridBagConstraints(); -// -// c1.gridwidth = 1; -// c1.gridheight = 1; -// c1.weighty = 1.0; -// c1.weightx = 1.0; -// c1.fill = GridBagConstraints.HORIZONTAL; -// c1.gridwidth = GridBagConstraints.REMAINDER; //end row -// -// //flushBuffersStrings(); -// HALUnitName = getBufferTypeFromSelectedMemory( (String)memoryCB.getItemAt( memoryCB.getSelectedIndex() ) ); -// ArrayList<JPanel> panelsList; -// -// switch( HALUnitName ) { -// case "FEP_BUFFER": -// tabbedPane.removeAll(); -// panelsList = FepBuffer.makePanel( c1, c2 ); -// panel3 = panelsList.get(0); -// tabbedPane.addTab( "Data", panel3 ); -// break; -// case "MAPPER_BUFFER": -// tabbedPane.removeAll(); -// panelsList = MapperBuffer.makePanel( c1, c2 ); -// tabbedPane.addTab( "Data In", panelsList.get(0) ); -// tabbedPane.addTab( "Data Out", panelsList.get(1) ); -// tabbedPane.addTab( "Look Up Table", panelsList.get(2) ); -// tabbedPane.setSelectedIndex(0); -// break; -// case "ADAIF_BUFFER": -// tabbedPane.removeAll(); -// panelsList = AdaifBuffer.makePanel( c1, c2 ); -// panel3 = panelsList.get(0); -// tabbedPane.addTab( "Data", panel3 ); -// break; -// case "INTERLEAVER_BUFFER": -// tabbedPane.removeAll(); -// panelsList = InterleaverBuffer.makePanel( c1, c2 ); -// tabbedPane.addTab( "Data In", panelsList.get(0) ); -// tabbedPane.addTab( "Data Out", panelsList.get(1) ); -// tabbedPane.addTab( "Permutation Table", panelsList.get(2) ); -// tabbedPane.setSelectedIndex(0); -// break; -// case "MAIN_MEMORY_BUFFER": -// tabbedPane.removeAll(); -// panelsList = MMBuffer.makePanel( c1, c2 ); -// panel3 = panelsList.get(0); -// tabbedPane.addTab( "Data", panel3 ); -// break; -// default: //the main memory buffer -// tabbedPane.removeAll(); -// panelsList = FepBuffer.makePanel( c1, c2 ); -// panel3 = panelsList.get(0); -// tabbedPane.addTab( "Data", panel3 ); -// break; -// } -// } + }*/ + String command = evt.getActionCommand(); + // Compare the action command to the known actions. + if (command.equals("Save and Close")) { + closeDialog(); + } else if (command.equals("Cancel")) { + cancelDialog(); + } + } + // + // private void updateBufferPanel() { + // + // GridBagConstraints c1 = new GridBagConstraints(); + // GridBagConstraints c2 = new GridBagConstraints(); + // + // c1.gridwidth = 1; + // c1.gridheight = 1; + // c1.weighty = 1.0; + // c1.weightx = 1.0; + // c1.fill = GridBagConstraints.HORIZONTAL; + // c1.gridwidth = GridBagConstraints.REMAINDER; //end row + // + // //flushBuffersStrings(); + // HALUnitName = getBufferTypeFromSelectedMemory( (String)memoryCB.getItemAt( memoryCB.getSelectedIndex() ) ); + // ArrayList<JPanel> panelsList; + // + // switch( HALUnitName ) { + // case "FEP_BUFFER": + // tabbedPane.removeAll(); + // panelsList = FepBuffer.makePanel( c1, c2 ); + // panel3 = panelsList.get(0); + // tabbedPane.addTab( "Data", panel3 ); + // break; + // case "MAPPER_BUFFER": + // tabbedPane.removeAll(); + // panelsList = MapperBuffer.makePanel( c1, c2 ); + // tabbedPane.addTab( "Data In", panelsList.get(0) ); + // tabbedPane.addTab( "Data Out", panelsList.get(1) ); + // tabbedPane.addTab( "Look Up Table", panelsList.get(2) ); + // tabbedPane.setSelectedIndex(0); + // break; + // case "ADAIF_BUFFER": + // tabbedPane.removeAll(); + // panelsList = AdaifBuffer.makePanel( c1, c2 ); + // panel3 = panelsList.get(0); + // tabbedPane.addTab( "Data", panel3 ); + // break; + // case "INTERLEAVER_BUFFER": + // tabbedPane.removeAll(); + // panelsList = InterleaverBuffer.makePanel( c1, c2 ); + // tabbedPane.addTab( "Data In", panelsList.get(0) ); + // tabbedPane.addTab( "Data Out", panelsList.get(1) ); + // tabbedPane.addTab( "Permutation Table", panelsList.get(2) ); + // tabbedPane.setSelectedIndex(0); + // break; + // case "MAIN_MEMORY_BUFFER": + // tabbedPane.removeAll(); + // panelsList = MMBuffer.makePanel( c1, c2 ); + // panel3 = panelsList.get(0); + // tabbedPane.addTab( "Data", panel3 ); + // break; + // default: //the main memory buffer + // tabbedPane.removeAll(); + // panelsList = FepBuffer.makePanel( c1, c2 ); + // panel3 = panelsList.get(0); + // tabbedPane.addTab( "Data", panel3 ); + // break; + // } + // } public void closeDialog() { regularClose = true; -// mappedMemory = memoryCB.getItemAt( memoryCB.getSelectedIndex() ); -// HALUnitName = getBufferTypeFromSelectedMemory(memoryCB.getItemAt( memoryCB.getSelectedIndex() )); -// switch ( HALUnitName ) { -// case "FEP_BUFFER": -// if( !FepBuffer.closePanel( frame ) ) { -// return; -// } -// break; -// case "MAPPER_BUFFER": -// if( !MapperBuffer.closePanel( frame ) ) { -// return; -// } -// break; -// case "ADAIF_BUFFER": -// if( !AdaifBuffer.closePanel( frame ) ) { -// return; -// } -// break; -// case "INTERLEAVER_BUFFER": -// if( !InterleaverBuffer.closePanel( frame ) ) { -// return; -// } -// break; -// case "MAIN_MEMORY_BUFFER": -// if( !MMBuffer.closePanel( frame ) ) { -// return; -// } -// break; -// default: //the main memory buffer -// if( !FepBuffer.closePanel( frame ) ) { -// return; -// } -// break; -// } + // mappedMemory = memoryCB.getItemAt( memoryCB.getSelectedIndex() ); + // HALUnitName = getBufferTypeFromSelectedMemory(memoryCB.getItemAt( memoryCB.getSelectedIndex() )); + // switch ( HALUnitName ) { + // case "FEP_BUFFER": + // if( !FepBuffer.closePanel( frame ) ) { + // return; + // } + // break; + // case "MAPPER_BUFFER": + // if( !MapperBuffer.closePanel( frame ) ) { + // return; + // } + // break; + // case "ADAIF_BUFFER": + // if( !AdaifBuffer.closePanel( frame ) ) { + // return; + // } + // break; + // case "INTERLEAVER_BUFFER": + // if( !InterleaverBuffer.closePanel( frame ) ) { + // return; + // } + // break; + // case "MAIN_MEMORY_BUFFER": + // if( !MMBuffer.closePanel( frame ) ) { + // return; + // } + // break; + // default: //the main memory buffer + // if( !FepBuffer.closePanel( frame ) ) { + // return; + // } + // break; + // } dispose(); } - public String getMappedPort() { - return mappedPort; - } + public String getMappedPort() { + return mappedPort; + } - public String getMappedMemory() { - return mappedMemory; - } + public String getMappedMemory() { + return mappedMemory; + } - public String getStartAddress() { - return baseAddress; - } + public String getStartAddress() { + return baseAddress; + } public void cancelDialog() { dispose(); } - + public boolean isRegularClose() { return regularClose; } - - public String getReferenceCommunicationName() { - if (emptyPortsList) { - return null; - } - String tmp = (String)( mappedPortCB.getSelectedItem() ); + + public String getReferenceCommunicationName() { + if (emptyPortsList) { + return null; + } + String tmp = (String)( mappedPortCB.getSelectedItem() ); if( tmp.length() > 0 ) { - int index = tmp.indexOf("::"); - if (index == -1) { - return tmp; - } + int index = tmp.indexOf("::"); + if (index == -1) { + return tmp; + } return tmp.substring(0, index); } else { return "ERROR EMPTY PORT NAME"; } } - + public String getCommunicationName() { String tmp = (String)( mappedPortCB.getSelectedItem() ); - int index = tmp.indexOf("::"); - if (index == -1) { - return tmp; - } + int index = tmp.indexOf("::"); + if (index == -1) { + return tmp; + } tmp = tmp.substring(index+2, tmp.length()); - - index = tmp.indexOf("("); - if (index > -1) { - tmp = tmp.substring(0, index).trim(); - } - return tmp; + + index = tmp.indexOf("("); + if (index > -1) { + tmp = tmp.substring(0, index).trim(); + } + return tmp; + } + + public String getTypeName() { + String tmp = (String)( mappedPortCB.getSelectedItem() ); + int index1 = tmp.indexOf("("); + int index2 = tmp.indexOf(")"); + if ((index1 > -1) && (index2 > index1)) { + return tmp.substring(index1+1, index2); + } + return ""; } - - public String getTypeName() { - String tmp = (String)( mappedPortCB.getSelectedItem() ); - int index1 = tmp.indexOf("("); - int index2 = tmp.indexOf(")"); - if ((index1 > -1) && (index2 > index1)) { - return tmp.substring(index1+1, index2); - } - return ""; - } - - public int indexOf(Vector<String> _list, String name) { - int i = 0; - for(String s : _list) { - if (s.equals(name)) { - return i; - } - i++; - } - return 0; - } - -// public List<String> getBufferParameters() { -// -// List<String> params = new ArrayList<String>(); - //params.add( String.valueOf( HALUnitName ) ); -// switch( HALUnitName ) { -// case "FEP_BUFFER": -// params = FepBuffer.getBufferParameters(); -// break; -// case "INTERLEAVER_BUFFER": -// params = InterleaverBuffer.getBufferParameters(); -// break; -// case "ADAIF_BUFFER": -// params = AdaifBuffer.getBufferParameters(); -// break; -// case "MAPPER_BUFFER": -// params = MapperBuffer.getBufferParameters(); -// break; -// case "MAIN_MEMORY_BUFFER": -// params = MMBuffer.getBufferParameters(); -// break; -// default: //the main memory buffer -// params = FepBuffer.getBufferParameters(); -// break; -// } -// return params; -// } -// -// private void cleanPanels() { -// panel3.removeAll(); -// panel4.removeAll(); -// panel5.removeAll(); -// tabbedPane.removeAll(); -// } - -// private void revalidateAndRepaintPanels() { -// panel3.revalidate(); -// panel3.repaint(); -// panel4.revalidate(); -// panel4.repaint(); -// panel5.revalidate(); -// panel5.repaint(); -// } - -} //End of class + + public int indexOf(Vector<String> _list, String name) { + int i = 0; + for(String s : _list) { + if (s.equals(name)) { + return i; + } + i++; + } + return 0; + } + + // public List<String> getBufferParameters() { + // + // List<String> params = new ArrayList<String>(); + //params.add( String.valueOf( HALUnitName ) ); + // switch( HALUnitName ) { + // case "FEP_BUFFER": + // params = FepBuffer.getBufferParameters(); + // break; + // case "INTERLEAVER_BUFFER": + // params = InterleaverBuffer.getBufferParameters(); + // break; + // case "ADAIF_BUFFER": + // params = AdaifBuffer.getBufferParameters(); + // break; + // case "MAPPER_BUFFER": + // params = MapperBuffer.getBufferParameters(); + // break; + // case "MAIN_MEMORY_BUFFER": + // params = MMBuffer.getBufferParameters(); + // break; + // default: //the main memory buffer + // params = FepBuffer.getBufferParameters(); + // break; + // } + // return params; + // } + // + // private void cleanPanels() { + // panel3.removeAll(); + // panel4.removeAll(); + // panel5.removeAll(); + // tabbedPane.removeAll(); + // } + + // private void revalidateAndRepaintPanels() { + // panel3.revalidate(); + // panel3.repaint(); + // panel4.revalidate(); + // panel4.repaint(); + // panel5.revalidate(); + // panel5.repaint(); + // } + +} //End of class diff --git a/ttool/src/test/java/ui/TestGTURTLEModeling.java b/ttool/src/test/java/ui/TestGTURTLEModeling.java index 1f8f184c7367fc486fdff092f0b6d6c5d4d0385a..160eb70f6b46ed1457aceb66ba0ccdc5045a693b 100644 --- a/ttool/src/test/java/ui/TestGTURTLEModeling.java +++ b/ttool/src/test/java/ui/TestGTURTLEModeling.java @@ -15,6 +15,7 @@ import fr.tpt.mem4csd.utils.compare.text.TextComparator; import myutil.FileUtils; public class TestGTURTLEModeling extends AbstractUITest { +<<<<<<< Upstream, based on origin/63-implement-project-management-in-ttool private static final String RESOURCES_DIR = "resources/ui/generateccode/"; @@ -59,28 +60,74 @@ public class TestGTURTLEModeling extends AbstractUITest { } } +======= + + private static final String RESOURCES_DIR = "resources/test/ui/generateccode/"; + + private final IComparator textComparator; + + public TestGTURTLEModeling() { + super(); + + mainGui.openProjectFromFile( new File( RESOURCES_DIR + "models/ZigBeeTutorial.xml") ); + + // FIXME: Temporarily ignoring the debug text file due to bug in comparator tool + textComparator = new TextComparator( Collections.singletonList( "txt" ) ); + } + + private void testGenerateCCode( final String mappingDiagName ) { + final TMLArchiPanel panel = findPanel( mappingDiagName ); + final Vector<TGComponent> compos = new Vector<TGComponent>( panel.tmlap.getComponentList() ); + + assertTrue( mainGui.gtm.checkSyntaxTMLMapping( compos, panel, true ) ); + + final String codeDir = RESOURCES_DIR + mappingDiagName + File.separator + "actual" + File.separator; + FileUtils.deleteFiles( codeDir ); + + final String codeDirExpected = RESOURCES_DIR + mappingDiagName + File.separator + "expected" + File.separator; + + mainGui.gtm.generateCCode( codeDir ); + + try { + final IComparisonReport difference = textComparator.compare( new File( codeDir ), new File( codeDirExpected ) ); + + if ( difference.containsDiff() ) { + difference.print(); + + fail( "Generated code files are not the same!!!" ); + } + else { + FileUtils.deleteFiles( codeDir ); + } + } + catch ( final IOException ex ) { + handleException( ex ); + } + } + +>>>>>>> 7f80032 Update on dse scripts private TMLArchiPanel findPanel( final String name ) { - for ( final TMLArchiPanel panel : mainGui.getTMLArchiDiagramPanels() ) { - if ( name.equals( mainGui.getTitleAt( panel ) ) ) { - return panel; - } - } - - return null; + for ( final TMLArchiPanel panel : mainGui.getTMLArchiDiagramPanels() ) { + if ( name.equals( mainGui.getTitleAt( panel ) ) ) { + return panel; + } + } + + return null; } @Test public void testGenerateCCodeMapping0() { - testGenerateCCode( "Mapping_0" ); - } + testGenerateCCode( "Mapping_0" ); + } @Test public void testGenerateCCodeMapping1() { - testGenerateCCode( "Mapping_1" ); - } + testGenerateCCode( "Mapping_1" ); + } @Test public void testGenerateCCodeMapping2() { - testGenerateCCode( "Mapping_2" ); - } + testGenerateCCode( "Mapping_2" ); + } }