diff --git a/simulators/c++2/src_simulator/sim/Simulator.cpp b/simulators/c++2/src_simulator/sim/Simulator.cpp index 94683807172f54446ed015a203f68f3a98102b4d..6a6fd458f5bffc0de151ae7bee081a1aa0ec0d6d 100644 --- a/simulators/c++2/src_simulator/sim/Simulator.cpp +++ b/simulators/c++2/src_simulator/sim/Simulator.cpp @@ -1550,6 +1550,54 @@ void Simulator::decodeCommand(std::string iCmd, std::ostream& iXmlOutStream){ std::cout << "End Run until FPGA x executes." << std::endl; break; } + case 16:{ //Write x samples/events to channel y + std::cout << "\nAdd virtual signals." << std::endl; + aInpStream >> aStrParam; + std::string channelName =_simComp->getChannelList(aStrParam); + TMLChannel* aChannel = _simComp->getChannelByName(channelName); + //aGlobMsg << TAG_MSGo << MSG_CMDNIMPL << TAG_MSGc << std::endl; + //anErrorCode=1; + if (aChannel==0){ + aGlobMsg << TAG_MSGo << MSG_CMPNFOUND << TAG_MSGc << std::endl; + anErrorCode=2; + } else { + aInpStream >> aParam1; + TMLEventChannel* anEventChannel = dynamic_cast<TMLEventChannel*>(aChannel); + if (anEventChannel==0){ + aChannel->insertSamples(aParam1, 0); + } else { + //Parameter<ParamType> anInsertParam((dynamic_cast<TMLEventChannel*>(aChannel))->getParamNo()); + std::string str, tempParameter=""; + aInpStream >> str; + while (1) { + std::size_t const n = str.find_first_of("0123456789"); + if(n != std::string::npos){ + std::size_t const m = str.find_first_not_of("0123456789", n); + tempParameter += str.substr(n, m != std::string::npos ? m-n : m) + " "; + if(m != std::string::npos) + str = str.substr(m, str.length()); + else { + std::cout << "End of parameter." << std::endl; + break; + } + + } + else { + std::cout << "There is no more number in the parameter." << std::endl; + break; + } + + } + std::istringstream ss(tempParameter); + Parameter* anInsertParam = anEventChannel->buildParameter(); + ss >> anInsertParam; + aChannel->insertSamples(aParam1, anInsertParam); + } + aGlobMsg << TAG_MSGo << "Write data/event to channel." << TAG_MSGc << std::endl; + } + std::cout << "End virtual signals." << std::endl; + break; + } default: aGlobMsg << TAG_MSGo << MSG_CMDNFOUND<< TAG_MSGc << std::endl; anErrorCode=3; diff --git a/src/main/java/remotesimulation/CommandParser.java b/src/main/java/remotesimulation/CommandParser.java index 682eef208aeba6eeae242e6e6c29af363aa1bade..ca8a201bdae2dfbe4ea6871136735206625fb209 100755 --- a/src/main/java/remotesimulation/CommandParser.java +++ b/src/main/java/remotesimulation/CommandParser.java @@ -490,6 +490,18 @@ public class CommandParser { sc = new SimulationCommand("write-in-channel", "wic", "6", params, paramNames, "Writes y samples / events to channel / event x"); commandList.add(sc); + // add signals + params = new int[3]; + paramNames = new String[3]; + params[0] = 2; + paramNames[0] = "Channel name"; + params[1] = 2; + paramNames[1] = "Nb of samples"; + params[2] = 2; + paramNames[2] = "value of samples"; + sc = new SimulationCommand("add-virtual-signals", "avs", "1 16", params, paramNames, "Send virtual events to channel"); + commandList.add(sc); + diff --git a/ttool/src/test/java/tmltranslator/DiplodocusDelayTest.java b/ttool/src/test/java/tmltranslator/DiplodocusDelayTest.java index c85334a23120b2caa37df1d2b7b0848b3779ddd5..f09fa3b2549a5d2e770dafe3ff93d94db94b010c 100644 --- a/ttool/src/test/java/tmltranslator/DiplodocusDelayTest.java +++ b/ttool/src/test/java/tmltranslator/DiplodocusDelayTest.java @@ -776,4 +776,163 @@ public class DiplodocusDelayTest extends AbstractUITest { assertTrue(MAX_SIGNAL_CYCLES[i] == maxValue); } } + + @Test + public void testInsertSignalsByCommand() throws Exception { + for (int i = 0; i < MODELS_SIGNALS.length; i++) { + String s = MODELS_SIGNALS[i]; + SIM_DIR = DIR_GEN + s + "Cmd/"; + System.out.println("executing: checking syntax " + s); + // select architecture tab + mainGUI.openProjectFromFile(new File(RESOURCES_DIR + s + ".xml")); + for(TURTLEPanel _tab : mainGUI.getTabs()) { + if(_tab instanceof TMLArchiPanel) { + for (TDiagramPanel tdp : _tab.getPanels()) { + if (tdp instanceof TMLArchiDiagramPanel) { + mainGUI.selectTab(tdp); + break; + } + } + break; + } + } + mainGUI.checkModelingSyntax(true); + TMLMapping tmap = mainGUI.gtm.getTMLMapping(); + TMLSyntaxChecking syntax = new TMLSyntaxChecking(tmap); + syntax.checkSyntax(); + assertTrue(syntax.hasErrors() == 0); + // Generate SystemC code + System.out.println("executing: sim code gen for " + s); + final IDiploSimulatorCodeGenerator tml2systc; + List<EBRDD> al = new ArrayList<EBRDD>(); + List<TEPE> alTepe = new ArrayList<TEPE>(); + tml2systc = DiploSimulatorFactory.INSTANCE.createCodeGenerator(tmap, al, alTepe); + tml2systc.setModelName(s); + String error = tml2systc.generateSystemC(false, true); + assertTrue(error == null); + + File directory = new File(SIM_DIR); + if (!directory.exists()) { + directory.mkdirs(); + } + + // Putting sim files + System.out.println("SIM executing: sim lib code copying for " + s); + ConfigurationTTool.SystemCCodeDirectory = getBaseResourcesDir() + "../../../../simulators/c++2/"; + boolean simFiles = SpecConfigTTool.checkAndCreateSystemCDir(SIM_DIR); + File signals = new File(RESOURCES_DIR + "signals.txt"); + File f_signal = new File(SIM_DIR); + FileUtils.copyFileToDirectory(signals, f_signal, false); + + + System.out.println("SIM executing: sim lib code copying done with result " + simFiles); + assertTrue(simFiles); + + System.out.println("SIM Saving file in: " + SIM_DIR); + tml2systc.saveFile(SIM_DIR, "appmodel"); + + // Compile it + System.out.println("executing: compile"); + Process proc; + BufferedReader proc_in; + String str; + boolean mustRecompileAll; + Penalties penalty = new Penalties(SIM_DIR + "src_simulator"); + int changed = penalty.handlePenalties(false); + + if (changed == 1) { + mustRecompileAll = true; + } else { + mustRecompileAll = false; + } + + if (mustRecompileAll) { + System.out.println("executing: " + "make -C " + SIM_DIR + " clean"); + try { + proc = Runtime.getRuntime().exec("make -C " + SIM_DIR + " clean"); + proc_in = new BufferedReader(new InputStreamReader(proc.getInputStream())); + while ((str = proc_in.readLine()) != null) { + // TraceManager.addDev( "Sending " + str + " from " + port + " to client..." ); + System.out.println("executing: " + str); + } + } catch (Exception e) { + // probably make is not installed + System.out.println("FAILED: executing: " + "make -C " + SIM_DIR + " clean"); + return; + } + } + + System.out.println("executing: " + "make -C " + SIM_DIR); + try { + + proc = Runtime.getRuntime().exec("make -C " + SIM_DIR + ""); + proc_in = new BufferedReader(new InputStreamReader(proc.getInputStream())); + + monitorError(proc); + + while ((str = proc_in.readLine()) != null) { + // TraceManager.addDev( "Sending " + str + " from " + port + " to client..." ); + System.out.println("executing: " + str); + } + } catch (Exception e) { + // Probably make is not installed + System.out.println("FAILED: executing: " + "make -C " + SIM_DIR); + return; + } + System.out.println("SUCCESS: executing: " + "make -C " + SIM_DIR); + + // Run the simulator + String graphPath = SIM_DIR + "testgraph_" + s; + try { + + String[] params = new String[3]; + + params[0] = "./" + SIM_DIR + "run.x"; + params[1] = "-cmd"; + params[2] = "1 5 10; 1 16 evt1to2 1 (101); 1 5 21; 1 16 evt1to2 1 (50); 1 0;1 7 100 100 " + graphPath; + proc = Runtime.getRuntime().exec(params); + //proc = Runtime.getRuntime().exec("./" + SIM_DIR + "run.x -explo -gname testgraph_" + s); + proc_in = new BufferedReader(new InputStreamReader(proc.getInputStream())); + + monitorError(proc); + + while ((str = proc_in.readLine()) != null) { + // TraceManager.addDev( "Sending " + str + " from " + port + " to client..." ); + System.out.println("executing: " + str); + } + } catch (Exception e) { + // Probably make is not installed + System.out.println("FAILED: executing simulation"); + return; + } + + // Compare results with expected ones + // Must load the graph + File graphFile = new File(graphPath + ".aut"); + String graphData = ""; + try { + graphData = FileUtils.loadFileData(graphFile); + } catch (Exception e) { + assertTrue(false); + } + + AUTGraph graph = new AUTGraph(); + graph.buildGraph(graphData); + + // States and transitions + System.out.println("executing: nb states of " + s + " " + graph.getNbOfStates()); + assertTrue(NB_Of_SIGNAL_STATES[i] == graph.getNbOfStates()); + System.out.println("executing: nb transitions of " + s + " " + graph.getNbOfTransitions()); + assertTrue(NB_Of_SIGNAL_TRANSTIONS[i] == graph.getNbOfTransitions()); + + // Min and max cycles + int minValue = graph.getMinValue("allCPUsFPGAsTerminated"); + System.out.println("executing: minvalue of " + s + " " + minValue); + assertTrue(MIN_SIGNAL_CYCLES[i] == minValue); + + int maxValue = graph.getMaxValue("allCPUsFPGAsTerminated"); + System.out.println("executing: maxvalue of " + s + " " + maxValue); + assertTrue(MAX_SIGNAL_CYCLES[i] == maxValue); + } + } }