Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package tmltranslator;
import common.ConfigurationTTool;
import common.SpecConfigTTool;
import myutil.TraceManager;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import req.ebrdd.EBRDD;
import tepe.TEPE;
import tmltranslator.tomappingsystemc2.DiploSimulatorFactory;
import tmltranslator.tomappingsystemc2.IDiploSimulatorCodeGenerator;
import tmltranslator.tomappingsystemc2.Penalties;
import ui.*;
import ui.interactivesimulation.JFrameInteractiveSimulation;
import ui.interactivesimulation.SimulationTransaction;
import ui.tmldd.TMLArchiCPUNode;
import ui.tmldd.TMLArchiDiagramPanel;
import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import static org.junit.Assert.assertTrue;
public class CPUDoubleClickShowTraceTest extends AbstractUITest {
final String DIR_GEN = "test_diplo_simulator/";
final String [] MODELS_CPU_SHOWTRACE = {"SmartCardProtocol"};
private String SIM_DIR;
static String CPP_DIR = "../../../../simulators/c++2/";
static String mappingName = "Mapping2";
private TMLArchiDiagramPanel currTdp;
@BeforeClass
public static void setUpBeforeClass() throws Exception {
RESOURCES_DIR = getBaseResourcesDir() + "/tmltranslator/simulator/";
}
public CPUDoubleClickShowTraceTest() {
super();
}
@Before
public void setUp() throws Exception {
SIM_DIR = getBaseResourcesDir() + CPP_DIR;
}
@Test(timeout = 600000)
public void testCPUShowTraceOnDoubleClick() throws Exception {
for (int i = 0; i < MODELS_CPU_SHOWTRACE.length; i++) {
String s = MODELS_CPU_SHOWTRACE[i];
SIM_DIR = DIR_GEN + s + "_showTrace/";
System.out.println("executing: checking syntax " + s);
// select architecture tab
mainGUI.openProjectFromFile(new File(RESOURCES_DIR + s + ".xml"));
TMLArchiPanel _tab = findArchiPanel(mappingName);
for (TDiagramPanel tdp : _tab.getPanels()) {
if (tdp instanceof TMLArchiDiagramPanel) {
mainGUI.selectTab(tdp);
currTdp = (TMLArchiDiagramPanel) tdp;
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() + CPP_DIR;
boolean simFiles = SpecConfigTTool.checkAndCreateSystemCDir(SIM_DIR);
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;
}
}
// TTool/ttool/build/test_diplo_simulator/SmartCardProtocol_showTrace/
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);
// Starts simulation and connect to the server
Runtime.getRuntime().exec("./" + SIM_DIR + "run.x -server");
JFrameInteractiveSimulation jfis = mainGUI.getJfis();
if (jfis != null) {
jfis.startSimulation();
Thread.sleep(50);
jfis.sendTestCmd("run-x-transactions 10"); // run 10 transactions
Thread.sleep(50);
jfis.sendTestCmd("lt 1000"); // update transaction list
Thread.sleep(2000);
for (TGComponent tg : currTdp.getComponentList()) {
System.out.println("tgc = " + tg.getName());
// get the transaction list of each CPUs on the panel, if the trans size > 0 then there will be a trace shown on double click
if (tg instanceof TMLArchiCPUNode) {
int _ID = tg.getDIPLOID();
TraceManager.addDev("Component ID = " + _ID);
List<SimulationTransaction> ts = mainGUI.getTransactions(_ID);
Thread.sleep(1000);
if (ts != null) {
TraceManager.addDev("Trans size = " + ts.size());
assertTrue(ts.size() > 0);
} else {
TraceManager.addDev("Transaction size is null with device ID = " + _ID);
assert false;
}
}
}
jfis.killSimulator();
jfis.close();
}
System.out.println("Test done");
}
}
}