Newer
Older

Le Van Truong
committed
package tmltranslator;
import common.ConfigurationTTool;
import common.SpecConfigTTool;

Le Van Truong
committed
import myutil.FileUtils;
import myutil.TraceManager;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import req.ebrdd.EBRDD;
import tepe.TEPE;
import tmltranslator.TMLMapping;

Le Van Truong
committed
import tmltranslator.TMLMappingTextSpecification;
import tmltranslator.TMLSyntaxChecking;
import tmltranslator.tomappingsystemc2.DiploSimulatorFactory;
import tmltranslator.tomappingsystemc2.IDiploSimulatorCodeGenerator;
import tmltranslator.tomappingsystemc2.Penalties;
import ui.AbstractUITest;
import ui.TDiagramPanel;
import ui.TMLArchiPanel;
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 RunToNextBreakpointMaxTransTest extends AbstractTest {
final String DIR_GEN = "test_diplo_simulator/";
final String [] MODELS_RTNBP_MAX_TRANS = {"rtnbmt"};
private String SIM_DIR;
final String [] SIM_TIME_TRANS = {"Simulated time: 1 time units.", "Simulated time: 2 time units.", "Simulated time: 1996 time units."};
static String CPP_DIR = "../../../../simulators/c++2/";
static String mappingName = "ArchitectureSimple";
private TMLArchiDiagramPanel currTdp;
@BeforeClass
public static void setUpBeforeClass() throws Exception {
RESOURCES_DIR = getBaseResourcesDir() + "/tmltranslator/simulator/";
}
public RunToNextBreakpointMaxTransTest() {
super();
}
@Before
public void setUp() throws Exception {
SIM_DIR = getBaseResourcesDir() + CPP_DIR;
}
@Test(timeout = 600000)
public void testRunToNextBreakPointFunction() throws Exception {
for (int i = 0; i < MODELS_RTNBP_MAX_TRANS.length; i++) {
String s = MODELS_RTNBP_MAX_TRANS[i];
SIM_DIR = DIR_GEN + s + "/";

Le Van Truong
committed
System.out.println("executing: loading " + s);
TMLMappingTextSpecification tmts = new TMLMappingTextSpecification(s);
File f = new File(RESOURCES_DIR + s + ".tmap");
System.out.println("executing: new file loaded " + s);
String spec = null;
try {
spec = FileUtils.loadFileData(f);
} catch (Exception e) {
System.out.println("Exception executing: loading " + s);
assertTrue(false);

Le Van Truong
committed
System.out.println("executing: testing spec " + s);
assertTrue(spec != null);
System.out.println("executing: testing parsed " + s);
boolean parsed = tmts.makeTMLMapping(spec, RESOURCES_DIR);
assertTrue(parsed);
System.out.println("executing: checking syntax " + s);
// Checking syntax
TMLMapping tmap = tmts.getTMLMapping();
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
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;

Le Van Truong
committed
Penalties penalty = new Penalties(SIM_DIR + File.separator + "src_simulator");
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
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);
ArrayList<String> arr = new ArrayList<>();
try {
String[] params = new String[3];
params[0] = "./" + SIM_DIR + "run.x";
params[1] = "-cmd";
params[2] = "1 19 1; 1 19 1; 1 19 0";
proc = Runtime.getRuntime().exec(params);
proc_in = new BufferedReader(new InputStreamReader(proc.getInputStream()));
monitorError(proc);
while ((str = proc_in.readLine()) != null) {
if (str.contains("Simulated time")) {
arr.add(str);
}
System.out.println("executing: " + str);
}
} catch (Exception e) {
// Probably make is not installed
System.out.println("FAILED: executing simulation " + e.getCause());
return;
}
for (int j = 0; j < arr.size(); j++) {
System.out.println("check string at " + j + " :pass, content = " + arr.get(j));
assertTrue(arr.get(j).equals(SIM_TIME_TRANS[j]));
}
TraceManager.addDev("Test Done!");
}
}
}