|
1 /* |
|
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 import static org.junit.Assert.fail; |
|
19 |
|
20 import java.io.BufferedReader; |
|
21 import java.io.File; |
|
22 import java.io.FileReader; |
|
23 import java.io.IOException; |
|
24 import java.io.InputStream; |
|
25 import java.util.Arrays; |
|
26 import java.util.HashMap; |
|
27 import java.util.List; |
|
28 import java.util.regex.Matcher; |
|
29 import java.util.regex.Pattern; |
|
30 |
|
31 import org.junit.BeforeClass; |
|
32 import org.junit.Test; |
|
33 |
|
34 import com.nokia.tracecompiler.engine.TraceCompilerEngineGlobals; |
|
35 import com.nokia.tracecompiler.model.TraceCompilerException; |
|
36 |
|
37 |
|
38 public class MultipleMmpTest { |
|
39 |
|
40 public static void main(String args[]) { |
|
41 org.junit.runner.JUnitCore.main(MultipleMmpTest.class.getName()); |
|
42 } |
|
43 |
|
44 /****************************************************UTILITY FUNCTIONS FOR TESTS************************************************************/ |
|
45 |
|
46 private static String epocroot = null; |
|
47 private static String projectdir = "testdata\\MultipleMmpTestCases\\"; //$NON-NLS-1$ |
|
48 private static String dictpath= "epoc32\\ost_dictionaries\\"; //$NON-NLS-1$ |
|
49 private static String autogenpath= "epoc32\\include\\platform\\symbiantraces\\autogen\\"; //$NON-NLS-1$ |
|
50 private static Pattern versionPattern = Pattern.compile("^.*(\\d+\\.\\d+\\.\\d+).*$"); //$NON-NLS-1$ |
|
51 private static Pattern oldversionPat = Pattern.compile("^(1\\..*)|(2\\.1.*)"); //$NON-NLS-1$ |
|
52 //old TC version should be up to 2.12.5 as new functionality was submitted to 2.12.6 (we hope) |
|
53 private static Pattern sbsoldversionPat = Pattern.compile("^(1\\..*)|(2\\.[01]\\..*)|(2\\.1[0-2]\\.[0-3].*)"); //$NON-NLS-1$ |
|
54 private static String TCversion = ""; //$NON-NLS-1$ |
|
55 private static String SBSversion = ""; //$NON-NLS-1$ |
|
56 private static File compilerpath; |
|
57 private static boolean oldTC = false; |
|
58 private static boolean oldBuilder = false; |
|
59 private static HashMap<String, List<File>> headers = new HashMap<String, List<File>>(); |
|
60 private static HashMap<String, List<File>> dicts = new HashMap<String, List<File>>(); |
|
61 private static HashMap<String, List<File>> sources = new HashMap<String, List<File>>(); |
|
62 private static ProcessBuilder sbs_build = new ProcessBuilder("sbs.bat","-k","-c","winscw_udeb.tracecompiler"); |
|
63 private static ProcessBuilder sbs_reallyclean = new ProcessBuilder("sbs.bat","-k","-c","winscw_udeb.tracecompiler", "reallyclean"); |
|
64 |
|
65 |
|
66 @BeforeClass |
|
67 static public void setEnvVariables() { |
|
68 epocroot = System.getenv("EPOCROOT"); //$NON-NLS-1$ |
|
69 if(epocroot == null || (epocroot.length()==0)){ |
|
70 fail(); |
|
71 } |
|
72 |
|
73 // need to check that the path ends in a backslash |
|
74 if(!epocroot.endsWith("\\")){ |
|
75 epocroot += "\\"; |
|
76 } |
|
77 |
|
78 compilerpath = new File (epocroot + "epoc32" + File.separator + "tools" + File.separator +"tracecompiler" + File.separator); //default value to remove warnings. //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ |
|
79 |
|
80 ProcessBuilder tc = new ProcessBuilder("java", "-classpath", compilerpath.getPath(), //$NON-NLS-1$//$NON-NLS-2$ |
|
81 "com.nokia.tracecompiler.TraceCompiler", "-v"); //$NON-NLS-1$//$NON-NLS-2$ |
|
82 System.out.println("compilerPath= " + compilerpath); //$NON-NLS-1$ |
|
83 tc.directory(compilerpath); |
|
84 tc.redirectErrorStream(true); |
|
85 try { |
|
86 Process p = tc.start(); |
|
87 p.waitFor(); |
|
88 |
|
89 |
|
90 String str = readProcessOutput(p); |
|
91 System.out.println("TC version = " + str); //$NON-NLS-1$ |
|
92 Matcher m = versionPattern.matcher(str.trim()); |
|
93 if (m.matches()) { |
|
94 TCversion = m.group(1); |
|
95 System.out.println("TC Version = " + TCversion); //$NON-NLS-1$ |
|
96 } |
|
97 |
|
98 m = oldversionPat.matcher(TCversion); |
|
99 if (m.matches()){ |
|
100 oldTC=true; |
|
101 } |
|
102 |
|
103 System.out.println("TC version = " + TCversion); //$NON-NLS-1$ |
|
104 System.out.println("OLD TC version = " + oldTC); //$NON-NLS-1$ |
|
105 |
|
106 ProcessBuilder sbs = new ProcessBuilder("sbs.bat","-v"); //$NON-NLS-1$ //$NON-NLS-2$ |
|
107 sbs.directory(compilerpath); |
|
108 sbs.redirectErrorStream(true); |
|
109 |
|
110 //start the compiler |
|
111 p = sbs.start(); |
|
112 p.waitFor(); |
|
113 |
|
114 InputStream inp = p.getInputStream(); |
|
115 |
|
116 str = ""; //$NON-NLS-1$ |
|
117 int c; |
|
118 //read the output from the compiler into the input stream |
|
119 while ((c = inp.read()) != -1) { |
|
120 str= str +((char)c); |
|
121 } |
|
122 |
|
123 System.out.println("SBS version = " + str); //$NON-NLS-1$ |
|
124 m = versionPattern.matcher(str.trim()); |
|
125 if (m.matches()) { |
|
126 SBSversion = m.group(1); |
|
127 } |
|
128 |
|
129 m = sbsoldversionPat.matcher(SBSversion); |
|
130 if (m.matches()){ |
|
131 oldBuilder=true; |
|
132 } |
|
133 |
|
134 } catch (Exception e) {// Catch exception if any |
|
135 System.err.println(e.getMessage()); |
|
136 } |
|
137 } |
|
138 |
|
139 |
|
140 public void createListHeadersDicts(String builder) |
|
141 { |
|
142 //The whole logic of what is expected is built here whether we build with sbs |
|
143 //new TC or old, The structure is re-built for each case. |
|
144 |
|
145 |
|
146 Matcher m = sbsoldversionPat.matcher(SBSversion); |
|
147 if (m.matches()){ |
|
148 oldBuilder=true; |
|
149 } else { |
|
150 oldBuilder=false; |
|
151 } |
|
152 |
|
153 |
|
154 System.out.println("OLD Builder :" + builder + ": = " + oldBuilder); //$NON-NLS-1$ |
|
155 |
|
156 File tracesHeader1; |
|
157 File tracesHeader2; |
|
158 File tracesHeader3; |
|
159 File tracesHeader4; |
|
160 File source1; |
|
161 File source2; |
|
162 File source3; |
|
163 File source4; |
|
164 File ostTraceDefinitions; |
|
165 File fixedidDefinitions; |
|
166 File ostDict1; |
|
167 File ostDict2; |
|
168 File autogenDict1; |
|
169 File autogenDict2; |
|
170 String loc = "traces\\"; //$NON-NLS-1$ |
|
171 |
|
172 source1 = new File (epocroot+projectdir+"mmp_traces\\src\\MultipleMmpApp1.cpp"); //$NON-NLS-1$ |
|
173 source2 = new File (epocroot+projectdir+"mmp_traces\\src\\ExtraCppFile1.cpp"); //$NON-NLS-1$ |
|
174 source3 = new File (epocroot+projectdir+"mmp_traces\\src\\MultipleMmpApp2.cpp"); //$NON-NLS-1$ |
|
175 source4 = new File (epocroot+projectdir+"mmp_traces\\src\\ExtraCppFile2.cpp"); //$NON-NLS-1$ |
|
176 sources.put("_traces", Arrays.asList(source1, source2, source3, source4)); |
|
177 |
|
178 tracesHeader1 = new File (epocroot+projectdir+"mmp_traces\\traces\\MultipleMmpApp1Traces.h"); //$NON-NLS-1$ |
|
179 tracesHeader2 = new File (epocroot+projectdir+"mmp_traces\\traces\\ExtraCppFile1Traces.h"); //$NON-NLS-1$ |
|
180 tracesHeader3 = new File (epocroot+projectdir+"mmp_traces\\traces\\MultipleMmpApp2Traces.h"); //$NON-NLS-1$ |
|
181 tracesHeader4 = new File (epocroot+projectdir+"mmp_traces\\traces\\ExtraCppFile2Traces.h"); //$NON-NLS-1$ |
|
182 |
|
183 ostTraceDefinitions = new File(epocroot+projectdir+"mmp_traces\\traces\\OstTraceDefinitions.h"); //$NON-NLS-1$ |
|
184 fixedidDefinitions = new File(epocroot+projectdir+"mmp_traces\\traces\\fixed_id.definitions"); //$NON-NLS-1$) |
|
185 headers.put("_traces", Arrays.asList(tracesHeader1,tracesHeader2,tracesHeader3,tracesHeader4,ostTraceDefinitions,fixedidDefinitions)); //$NON-NLS-1$ |
|
186 |
|
187 ostDict1 = new File(epocroot+dictpath+"mmp_traces1_0xe8576d96_Dictionary.xml"); //$NON-NLS-1$ |
|
188 ostDict2 = new File(epocroot+dictpath+"mmp_traces2_0xe8576d95_Dictionary.xml"); //$NON-NLS-1$ |
|
189 autogenDict1 = new File(epocroot+autogenpath+"mmp_traces1_0xe8576d96_TraceDefinitions.h"); //$NON-NLS-1$ |
|
190 autogenDict2 = new File(epocroot+autogenpath+"mmp_traces2_0xe8576d95_TraceDefinitions.h"); //$NON-NLS-1$ |
|
191 dicts.put("_traces", Arrays.asList(ostDict1, ostDict2, autogenDict1, autogenDict2)); //$NON-NLS-1$ |
|
192 |
|
193 //============================= |
|
194 |
|
195 if (!oldBuilder && !oldTC) { |
|
196 loc = "traces_mmp_traces_mmpname1\\"; //$NON-NLS-1$ |
|
197 } |
|
198 tracesHeader1 = new File (epocroot+projectdir+"mmp_traces_mmpname\\"+ loc + "MultipleMmpApp1Traces.h"); //$NON-NLS-1$ //$NON-NLS-2$ |
|
199 tracesHeader2 = new File (epocroot+projectdir+"mmp_traces_mmpname\\" + loc + "ExtraCppFile1Traces.h"); //$NON-NLS-1$ //$NON-NLS-2$ |
|
200 if (!oldBuilder && !oldTC) { |
|
201 loc = "traces_mmp_traces_mmpname2\\"; //$NON-NLS-1$ |
|
202 } |
|
203 tracesHeader3 = new File (epocroot+projectdir+"mmp_traces_mmpname\\" + loc + "MultipleMmpApp2Traces.h"); //$NON-NLS-1$ //$NON-NLS-2$ |
|
204 tracesHeader4 = new File (epocroot+projectdir+"mmp_traces_mmpname\\" + loc + "ExtraCppFile2Traces.h"); //$NON-NLS-1$ //$NON-NLS-2$ |
|
205 ostTraceDefinitions = new File(epocroot+projectdir+"mmp_traces_mmpname\\" + loc + "OstTraceDefinitions.h"); //$NON-NLS-1$ |
|
206 fixedidDefinitions = new File(epocroot+projectdir+"mmp_traces_mmpname\\" + loc + "fixed_id.definitions"); //$NON-NLS-1$) |
|
207 |
|
208 headers.put("_traces_mmpname", Arrays.asList(tracesHeader1,tracesHeader2,tracesHeader3,tracesHeader4,ostTraceDefinitions,fixedidDefinitions)); //$NON-NLS-1$ |
|
209 |
|
210 source1 = new File (epocroot+projectdir+"mmp_traces_mmpname\\src\\MultipleMmpApp1.cpp"); //$NON-NLS-1$ |
|
211 source2 = new File (epocroot+projectdir+"mmp_traces_mmpname\\src\\ExtraCppFile1.cpp"); //$NON-NLS-1$ |
|
212 source3 = new File (epocroot+projectdir+"mmp_traces_mmpname\\src\\MultipleMmpApp2.cpp"); //$NON-NLS-1$ |
|
213 source4 = new File (epocroot+projectdir+"mmp_traces_mmpname\\src\\ExtraCppFile2.cpp"); //$NON-NLS-1$ |
|
214 sources.put("_traces_mmpname", Arrays.asList(source1, source2, source3, source4)); |
|
215 |
|
216 ostDict1 = new File(epocroot+dictpath+"mmp_traces_mmpname1_0xe8576d96_Dictionary.xml"); //$NON-NLS-1$ |
|
217 ostDict2 = new File(epocroot+dictpath+"mmp_traces_mmpname2_0xe8576d95_Dictionary.xml"); //$NON-NLS-1$ |
|
218 autogenDict1 = new File(epocroot+autogenpath+"mmp_traces_mmpname1_0xe8576d96_TraceDefinitions.h"); //$NON-NLS-1$ |
|
219 autogenDict2 = new File(epocroot+autogenpath+"mmp_traces_mmpname2_0xe8576d95_TraceDefinitions.h"); //$NON-NLS-1$ |
|
220 dicts.put("_traces_mmpname", Arrays.asList(ostDict1, ostDict2, autogenDict1, autogenDict2)); //$NON-NLS-1$ |
|
221 |
|
222 //============================= |
|
223 |
|
224 loc = "traces\\"; //$NON-NLS-1$ |
|
225 if (!oldTC) { |
|
226 loc = "traces\\target7_dll\\"; //$NON-NLS-1$ |
|
227 } |
|
228 tracesHeader1 = new File (epocroot+projectdir+"mmp_traces_slash_target_ext\\" + loc + "MultipleMmpApp1Traces.h"); //$NON-NLS-1$ //$NON-NLS-2$ |
|
229 tracesHeader2 = new File (epocroot+projectdir+"mmp_traces_slash_target_ext\\" + loc + "ExtraCppFile1Traces.h"); //$NON-NLS-1$ //$NON-NLS-2$ |
|
230 if (!oldTC) { |
|
231 loc = "traces\\target8_dll\\"; //$NON-NLS-1$ |
|
232 } |
|
233 tracesHeader3 = new File (epocroot+projectdir+"mmp_traces_slash_target_ext\\" + loc + "MultipleMmpApp2Traces.h"); //$NON-NLS-1$ //$NON-NLS-2$ |
|
234 tracesHeader4 = new File (epocroot+projectdir+"mmp_traces_slash_target_ext\\" + loc + "ExtraCppFile2Traces.h"); //$NON-NLS-1$ //$NON-NLS-2$ |
|
235 ostTraceDefinitions = new File(epocroot+projectdir+"mmp_traces_slash_target_ext\\" + loc + "OstTraceDefinitions.h"); //$NON-NLS-1$ |
|
236 fixedidDefinitions = new File(epocroot+projectdir+"mmp_traces_slash_target_ext\\" + loc + "fixed_id.definitions"); //$NON-NLS-1$) |
|
237 |
|
238 headers.put("_traces_slash_target_ext", Arrays.asList(tracesHeader1,tracesHeader2,tracesHeader3,tracesHeader4,ostTraceDefinitions,fixedidDefinitions)); //$NON-NLS-1$ |
|
239 |
|
240 source1 = new File (epocroot+projectdir+"mmp_traces_slash_target_ext\\src\\MultipleMmpApp1.cpp"); //$NON-NLS-1$ |
|
241 source2 = new File (epocroot+projectdir+"mmp_traces_slash_target_ext\\src\\ExtraCppFile1.cpp"); //$NON-NLS-1$ |
|
242 source3 = new File (epocroot+projectdir+"mmp_traces_slash_target_ext\\src\\MultipleMmpApp2.cpp"); //$NON-NLS-1$ |
|
243 source4 = new File (epocroot+projectdir+"mmp_traces_slash_target_ext\\src\\ExtraCppFile2.cpp"); //$NON-NLS-1$ |
|
244 sources.put("_traces_slash_target_ext", Arrays.asList(source1, source2, source3, source4)); |
|
245 |
|
246 |
|
247 String name1 = ""; |
|
248 String name2 = ""; |
|
249 if (oldTC) { |
|
250 name1 = "mmp_traces_slash_target_ext1"; |
|
251 name2 = "mmp_traces_slash_target_ext2"; |
|
252 } else { |
|
253 name1 = "target7_dll"; |
|
254 name2 = "target8_dll"; |
|
255 } |
|
256 |
|
257 ostDict1 = new File(epocroot+dictpath + name1 + "_0xe8576d96_Dictionary.xml"); //$NON-NLS-1$ |
|
258 ostDict2 = new File(epocroot+dictpath + name2 + "_0xe8576d95_Dictionary.xml"); //$NON-NLS-1$ |
|
259 autogenDict1 = new File(epocroot+autogenpath + name1 + "_0xe8576d96_TraceDefinitions.h"); //$NON-NLS-1$ |
|
260 autogenDict2 = new File(epocroot+autogenpath + name2 + "_0xe8576d95_TraceDefinitions.h"); //$NON-NLS-1$ |
|
261 dicts.put("_traces_slash_target_ext", Arrays.asList(ostDict1, ostDict2, autogenDict1, autogenDict2)); //$NON-NLS-1$ |
|
262 |
|
263 //================================ |
|
264 loc = "traces\\"; //$NON-NLS-1$ |
|
265 if (!oldTC) { |
|
266 loc = "traces\\target9_dll\\"; //$NON-NLS-1$ |
|
267 } |
|
268 tracesHeader1 = new File (epocroot+projectdir+"mmp_traces_slash_target_ext_commonsource\\" + loc + "MultipleMmpApp1Traces.h"); //$NON-NLS-1$ //$NON-NLS-2$ |
|
269 tracesHeader2 = new File (epocroot+projectdir+"mmp_traces_slash_target_ext_commonsource\\" + loc + "ExtraCppFile1Traces.h"); //$NON-NLS-1$ //$NON-NLS-2$ |
|
270 if (!oldTC) { |
|
271 loc = "traces\\target10_dll\\"; //$NON-NLS-1$ |
|
272 } |
|
273 tracesHeader3 = new File (epocroot+projectdir+"mmp_traces_slash_target_ext_commonsource\\" + loc + "MultipleMmpApp1Traces.h"); //$NON-NLS-1$ //$NON-NLS-2$ |
|
274 tracesHeader4 = new File (epocroot+projectdir+"mmp_traces_slash_target_ext_commonsource\\" + loc + "ExtraCppFile1Traces.h"); //$NON-NLS-1$ //$NON-NLS-2$ |
|
275 ostTraceDefinitions = new File(epocroot+projectdir+"mmp_traces_slash_target_ext_commonsource\\" + loc + "OstTraceDefinitions.h"); //$NON-NLS-1$ |
|
276 fixedidDefinitions = new File(epocroot+projectdir+"mmp_traces_slash_target_ext_commonsource\\" + loc + "fixed_id.definitions"); //$NON-NLS-1$) |
|
277 |
|
278 headers.put("_traces_slash_target_ext_commonsource", Arrays.asList(tracesHeader1,tracesHeader2,tracesHeader3,tracesHeader4,ostTraceDefinitions,fixedidDefinitions)); //$NON-NLS-1$ |
|
279 |
|
280 source1 = new File (epocroot+projectdir+"mmp_traces_slash_target_ext_commonsource\\src\\MultipleMmpApp1.cpp"); //$NON-NLS-1$ |
|
281 source2 = new File (epocroot+projectdir+"mmp_traces_slash_target_ext_commonsource\\src\\ExtraCppFile1.cpp"); //$NON-NLS-1$ |
|
282 source3 = new File (epocroot+projectdir+"mmp_traces_slash_target_ext_commonsource\\src\\MultipleMmpApp1.cpp"); //$NON-NLS-1$ |
|
283 source4 = new File (epocroot+projectdir+"mmp_traces_slash_target_ext_commonsource\\src\\ExtraCppFile1.cpp"); //$NON-NLS-1$ |
|
284 sources.put("_traces_slash_target_ext_commonsource", Arrays.asList(source1, source2, source3, source4)); |
|
285 |
|
286 |
|
287 if (oldTC) { |
|
288 name1 = "mmp_traces_slash_target_ext1_cs"; |
|
289 name2 = "mmp_traces_slash_target_ext2_cs"; |
|
290 } else { |
|
291 name1 = "target9_dll"; |
|
292 name2 = "target10_dll"; |
|
293 } |
|
294 ostDict1 = new File(epocroot+dictpath + name1 + "_0xe8576d96_Dictionary.xml"); //$NON-NLS-1$ |
|
295 ostDict2 = new File(epocroot+dictpath + name2 + "_0xe8576d95_Dictionary.xml"); //$NON-NLS-1$ |
|
296 autogenDict1 = new File(epocroot+autogenpath + name1 + "_0xe8576d96_TraceDefinitions.h"); //$NON-NLS-1$ |
|
297 autogenDict2 = new File(epocroot+autogenpath + name2 + "_0xe8576d95_TraceDefinitions.h"); //$NON-NLS-1$ |
|
298 dicts.put("_traces_slash_target_ext_commonsource", Arrays.asList(ostDict1, ostDict2, autogenDict1, autogenDict2)); //$NON-NLS-1$ |
|
299 |
|
300 //================================== |
|
301 loc = "traces\\"; //$NON-NLS-1$ |
|
302 if (!oldTC && !oldBuilder) { |
|
303 loc = "traces_target11_exe\\"; //$NON-NLS-1$ |
|
304 } |
|
305 tracesHeader1 = new File (epocroot+projectdir+"mmp_traces_target_type\\" + loc +"MultipleMmpApp1Traces.h"); //$NON-NLS-1$ //$NON-NLS-2$ |
|
306 tracesHeader2 = new File (epocroot+projectdir+"mmp_traces_target_type\\" + loc +"ExtraCppFile1Traces.h"); //$NON-NLS-1$ //$NON-NLS-2$ |
|
307 if (!oldTC && !oldBuilder) { |
|
308 loc = "traces_target12_exe\\"; //$NON-NLS-1$ |
|
309 } |
|
310 tracesHeader3 = new File (epocroot+projectdir+"mmp_traces_target_type\\" + loc + "MultipleMmpApp2Traces.h"); //$NON-NLS-1$ //$NON-NLS-2$ |
|
311 tracesHeader4 = new File (epocroot+projectdir+"mmp_traces_target_type\\" + loc + "ExtraCppFile2Traces.h"); //$NON-NLS-1$ //$NON-NLS-2$ |
|
312 ostTraceDefinitions = new File(epocroot+projectdir+"mmp_traces_target_type\\" + loc + "OstTraceDefinitions.h"); //$NON-NLS-1$ |
|
313 fixedidDefinitions = new File(epocroot+projectdir+"mmp_traces_target_type\\" + loc + "fixed_id.definitions"); //$NON-NLS-1$) |
|
314 |
|
315 headers.put("_traces_target_type", Arrays.asList(tracesHeader1,tracesHeader2,tracesHeader3,tracesHeader4,ostTraceDefinitions,fixedidDefinitions)); //$NON-NLS-1$ |
|
316 |
|
317 |
|
318 source1 = new File (epocroot+projectdir+"mmp_traces_target_type\\src\\MultipleMmpApp1.cpp"); //$NON-NLS-1$ |
|
319 source2 = new File (epocroot+projectdir+"mmp_traces_target_type\\src\\ExtraCppFile1.cpp"); //$NON-NLS-1$ |
|
320 source3 = new File (epocroot+projectdir+"mmp_traces_target_type\\src\\MultipleMmpApp2.cpp"); //$NON-NLS-1$ |
|
321 source4 = new File (epocroot+projectdir+"mmp_traces_target_type\\src\\ExtraCppFile2.cpp"); //$NON-NLS-1$ |
|
322 sources.put("_traces_target_type", Arrays.asList(source1, source2, source3, source4)); |
|
323 |
|
324 ostDict1 = new File(epocroot+dictpath+"target11_exe_0xe8576d96_Dictionary.xml"); //$NON-NLS-1$ |
|
325 ostDict2 = new File(epocroot+dictpath+"target12_exe_0xe8576d95_Dictionary.xml"); //$NON-NLS-1$ |
|
326 autogenDict1 = new File(epocroot+autogenpath+"target11_exe_0xe8576d96_TraceDefinitions.h"); //$NON-NLS-1$ |
|
327 autogenDict2 = new File(epocroot+autogenpath+"target12_exe_0xe8576d95_TraceDefinitions.h"); //$NON-NLS-1$ |
|
328 dicts.put("_traces_target_type", Arrays.asList(ostDict1, ostDict2, autogenDict1, autogenDict2)); //$NON-NLS-1$ |
|
329 |
|
330 //================================== |
|
331 |
|
332 loc = "traces\\"; //$NON-NLS-1$ |
|
333 if (!oldTC && !oldBuilder) { |
|
334 loc = "traces\\target3_dll\\"; //$NON-NLS-1$ |
|
335 } |
|
336 tracesHeader1 = new File (epocroot+projectdir+"mmp_traces_mixed\\" + loc + "MultipleMmpApp1Traces.h"); //$NON-NLS-1$ //$NON-NLS-2$ |
|
337 tracesHeader2 = new File (epocroot+projectdir+"mmp_traces_mixed\\" + loc + "ExtraCppFile1Traces.h"); //$NON-NLS-1$ //$NON-NLS-2$ |
|
338 if (!oldTC && !oldBuilder) { |
|
339 loc = "traces_target4_kext\\"; //$NON-NLS-1$ |
|
340 } |
|
341 tracesHeader3 = new File (epocroot+projectdir+"mmp_traces_mixed\\" + loc + "MultipleMmpApp2Traces.h"); //$NON-NLS-1$ //$NON-NLS-2$ |
|
342 tracesHeader4 = new File (epocroot+projectdir+"mmp_traces_mixed\\" + loc + "ExtraCppFile2Traces.h"); //$NON-NLS-1$ //$NON-NLS-2$ |
|
343 ostTraceDefinitions = new File(epocroot+projectdir+"mmp_traces_mixed\\" + loc + "OstTraceDefinitions.h"); //$NON-NLS-1$ |
|
344 fixedidDefinitions = new File(epocroot+projectdir+"mmp_traces_mixed\\" + loc + "fixed_id.definitions"); //$NON-NLS-1$) |
|
345 |
|
346 headers.put("_traces_mixed", Arrays.asList(tracesHeader1,tracesHeader2,tracesHeader3,tracesHeader4,ostTraceDefinitions,fixedidDefinitions)); //$NON-NLS-1$ |
|
347 |
|
348 source1 = new File (epocroot+projectdir+"mmp_traces_mixed\\src\\MultipleMmpApp1.cpp"); //$NON-NLS-1$ |
|
349 source2 = new File (epocroot+projectdir+"mmp_traces_mixed\\src\\ExtraCppFile1.cpp"); //$NON-NLS-1$ |
|
350 source3 = new File (epocroot+projectdir+"mmp_traces_mixed\\src\\MultipleMmpApp2.cpp"); //$NON-NLS-1$ |
|
351 source4 = new File (epocroot+projectdir+"mmp_traces_mixed\\src\\ExtraCppFile2.cpp"); //$NON-NLS-1$ |
|
352 sources.put("_traces_mixed", Arrays.asList(source1, source2, source3, source4)); |
|
353 |
|
354 String suffix = ""; //$NON-NLS-1$ |
|
355 String name = ""; |
|
356 if (!oldBuilder) { |
|
357 suffix = "_dll"; //$NON-NLS-1$ |
|
358 name = "target3"; |
|
359 } else { |
|
360 name = "mmp_traces_mixed1"; |
|
361 } |
|
362 |
|
363 ostDict1 = new File(epocroot+dictpath+name + suffix + "_0xe8576d96_Dictionary.xml"); //$NON-NLS-1$ |
|
364 autogenDict1 = new File(epocroot+autogenpath+name + suffix + "_0xe8576d96_TraceDefinitions.h"); //$NON-NLS-1$ |
|
365 if (!oldBuilder) { |
|
366 suffix = "_kext"; //$NON-NLS-1$ |
|
367 name = "target4"; |
|
368 } else { |
|
369 name = "mmp_traces_mixed2"; |
|
370 } |
|
371 ostDict2 = new File(epocroot+dictpath+name + suffix + "_0xe8576d95_Dictionary.xml"); //$NON-NLS-1$ |
|
372 autogenDict2 = new File(epocroot+autogenpath+name + suffix + "_0xe8576d95_TraceDefinitions.h"); //$NON-NLS-1$ |
|
373 dicts.put("_traces_mixed", Arrays.asList(ostDict1, ostDict2, autogenDict1, autogenDict2)); //$NON-NLS-1$ |
|
374 } |
|
375 |
|
376 |
|
377 /** |
|
378 * This function invokes raptor on the desired test c++ project |
|
379 * |
|
380 * @param path String specifying the path the compiler needs |
|
381 * to run from |
|
382 */ |
|
383 public void InvokeCompiler(String path, String builder) { |
|
384 System.out.println ("InvokeCompiler() for : " + builder); |
|
385 |
|
386 List<File> headersList; |
|
387 List<File> dictsList; |
|
388 try{ |
|
389 |
|
390 //set up the directory from which the process will be called |
|
391 if (path.compareTo("_traces")==0){ //$NON-NLS-1$ |
|
392 headersList = headers.get("_traces"); //$NON-NLS-1$ |
|
393 System.out.println("deleting file " + headersList.toString()); //$NON-NLS-1$ |
|
394 for (File header : headersList) { |
|
395 if (header.exists()) header.delete(); |
|
396 } |
|
397 |
|
398 dictsList = dicts.get("_traces"); //$NON-NLS-1$ |
|
399 System.out.println("deleting file " + dictsList.toString()); //$NON-NLS-1$ |
|
400 for (File dict : dictsList) { |
|
401 if (dict.exists()) dict.delete(); |
|
402 } |
|
403 compilerpath = new File (epocroot+projectdir+"mmp_traces\\group\\"); //$NON-NLS-1$ |
|
404 } |
|
405 else if (path.compareTo("_traces_mmpname")==0){ //$NON-NLS-1$ |
|
406 headersList = headers.get("_traces_mmpname"); //$NON-NLS-1$ |
|
407 System.out.println("deleting file " + headersList.toString()); //$NON-NLS-1$ |
|
408 for (File header : headersList) { |
|
409 if (header.exists()) { |
|
410 header.delete(); |
|
411 } |
|
412 } |
|
413 |
|
414 dictsList = dicts.get("_traces_mmpname"); |
|
415 System.out.println("deleting file " + dictsList.toString()); |
|
416 for (File dict : dictsList) { |
|
417 if (dict.exists()) { |
|
418 dict.delete(); |
|
419 } |
|
420 } |
|
421 compilerpath = new File (epocroot+projectdir+"mmp_traces_mmpname\\group\\"); |
|
422 } |
|
423 else if (path.compareTo("_traces_slash_target_ext")==0){ |
|
424 headersList = headers.get("_traces_slash_target_ext"); |
|
425 System.out.println("deleting file " + headersList.toString()); |
|
426 for (File header : headersList) { |
|
427 if (header.exists()) header.delete(); |
|
428 } |
|
429 |
|
430 dictsList = dicts.get("_traces_slash_target_ext"); |
|
431 System.out.println("deleting file " + dictsList.toString()); |
|
432 for (File dict : dictsList) { |
|
433 if (dict.exists()) dict.delete(); |
|
434 } |
|
435 compilerpath = new File (epocroot+projectdir+"mmp_traces_slash_target_ext\\group\\"); |
|
436 } |
|
437 else if (path.compareTo("_traces_slash_target_ext_commonsource")==0){ |
|
438 headersList = headers.get("_traces_slash_target_ext_commonsource"); |
|
439 System.out.println("deleting file " + headersList.toString()); |
|
440 for (File header : headersList) { |
|
441 if (header.exists()) header.delete(); |
|
442 } |
|
443 |
|
444 dictsList = dicts.get("_traces_slash_target_ext_commonsource"); |
|
445 System.out.println("deleting file " + dictsList.toString()); |
|
446 for (File dict : dictsList) { |
|
447 if (dict.exists()) dict.delete(); |
|
448 } |
|
449 compilerpath = new File (epocroot+projectdir+"mmp_traces_slash_target_ext_commonsource\\group\\"); |
|
450 } |
|
451 else if (path.compareTo("_traces_target_type")==0){ |
|
452 headersList = headers.get("_traces_target_type"); |
|
453 System.out.println("deleting file " + headersList.toString()); |
|
454 for (File header : headersList) { |
|
455 if (header.exists()) header.delete(); |
|
456 } |
|
457 |
|
458 dictsList = dicts.get("_traces_target_type"); |
|
459 System.out.println("deleting file " + dictsList.toString()); |
|
460 for (File dict : dictsList) { |
|
461 if (dict.exists()) dict.delete(); |
|
462 } |
|
463 compilerpath = new File (epocroot+projectdir+"mmp_traces_target_type\\group\\"); |
|
464 } |
|
465 else if (path.compareTo("_traces_mixed")==0){ |
|
466 headersList = headers.get("_traces_mixed"); |
|
467 System.out.println("deleting file " + headersList.toString()); |
|
468 for (File header : headersList) { |
|
469 if (header.exists()) header.delete(); |
|
470 } |
|
471 |
|
472 dictsList = dicts.get("_traces_mixed"); |
|
473 System.out.println("deleting file " + dictsList.toString()); |
|
474 for (File dict : dictsList) { |
|
475 if (dict.exists()) dict.delete(); |
|
476 } |
|
477 compilerpath = new File (epocroot+projectdir+"mmp_traces_mixed\\group\\"); |
|
478 } |
|
479 else{ |
|
480 |
|
481 System.out.println("Error: Unrecognised test case."); |
|
482 fail(); |
|
483 } |
|
484 |
|
485 //set up the process builder object |
|
486 sbs_build.directory(compilerpath); |
|
487 sbs_reallyclean.directory(compilerpath); |
|
488 sbs_build.redirectErrorStream(true); |
|
489 |
|
490 |
|
491 |
|
492 Process p; |
|
493 String str = ""; |
|
494 //start the compiler |
|
495 System.out.println("Starting build process ...."); |
|
496 |
|
497 System.out.println("Running sbs reallyclean on : " + compilerpath + " command: " + sbs_reallyclean.command().toString()); |
|
498 p = sbs_reallyclean.start(); |
|
499 readProcessOutput(p); |
|
500 System.out.println("Running sbs on : " + compilerpath + " command: " + sbs_build.command().toString()); |
|
501 p = sbs_build.start(); |
|
502 str = readProcessOutput(p); |
|
503 |
|
504 |
|
505 int ret = p.exitValue(); |
|
506 System.out.println("build process ended...."); |
|
507 if (ret!=0){ |
|
508 System.out.println("build process failed:"+str); |
|
509 } |
|
510 } |
|
511 |
|
512 catch (Exception e){//Catch exception if any |
|
513 System.err.println("Error: " + e.getMessage()); |
|
514 fail(); |
|
515 } |
|
516 |
|
517 } |
|
518 |
|
519 |
|
520 static private String readProcessOutput(Process p) throws IOException { |
|
521 InputStream inp = p.getInputStream(); |
|
522 |
|
523 int c; |
|
524 String str = ""; |
|
525 //read the output from the compiler into the input stream |
|
526 while ((c = inp.read()) != -1) { |
|
527 str= str +((char)c); |
|
528 } |
|
529 return str; |
|
530 } |
|
531 |
|
532 /** |
|
533 * This function checks that the traces header files have been generated in the expected locations |
|
534 * |
|
535 * @param path String specifying where to look for the traces header file. |
|
536 */ |
|
537 public void CheckForTracesHeaders(String path) { |
|
538 System.out.println ("CheckForTracesHeaders()"); |
|
539 System.out.println("Old Builder : " + oldBuilder + "......Old TC : " + oldTC); |
|
540 List<File> headersList = headers.get(path); |
|
541 List<File> sourceList = sources.get(path); |
|
542 System.out.println("checking files " + headersList.toString()); |
|
543 boolean error = false; |
|
544 if ((path.compareTo("_traces_slash_target_ext")==0 || path.compareTo("_traces_slash_target_ext_commonsource")==0) && oldBuilder && !oldTC){ |
|
545 System.out.println("No need to check for header files as old sbs cannot call TC"); |
|
546 } else { |
|
547 try { |
|
548 TraceCompilerEngineGlobals.start(); |
|
549 } catch (TraceCompilerException e) { |
|
550 fail(); |
|
551 } |
|
552 for (File header : headersList) { |
|
553 if (!header.exists()) { |
|
554 error = true; |
|
555 System.out.println("Error: "+header+" does not exist/hasn't been generated by TraceCompiler"); |
|
556 } else { |
|
557 String licenceInSource = null; |
|
558 String licenceInHeader = null; |
|
559 File source = null; |
|
560 // read the licence from the header file |
|
561 if (header.getName().trim().equalsIgnoreCase("OstTraceDefinitions.h")) { |
|
562 licenceInSource = TraceCompilerEngineGlobals.getDefaultLicence(true); |
|
563 System.out.println("Reading default licence for OstTraceDefinitions.h" + licenceInSource); |
|
564 } else { |
|
565 if (header.getName().trim().equalsIgnoreCase("fixed_id.definitions")) { |
|
566 licenceInSource = TraceCompilerEngineGlobals.getDefaultLicence(false); |
|
567 System.out.println("Reading default licence for fixed_id.definitions" + licenceInSource); |
|
568 } else { |
|
569 licenceInHeader = readFirstMultiLineComment(header.getAbsolutePath()); |
|
570 System.out.println("Reading licence from " + header.getAbsolutePath() + " == " + licenceInHeader); |
|
571 source = sourceList.get(headersList.indexOf(header)); |
|
572 |
|
573 licenceInSource = readFirstMultiLineComment(source.getAbsolutePath()); |
|
574 System.out.println("Reading licence from " + source.getAbsolutePath() + " == " + licenceInSource); |
|
575 if (licenceInSource == null) { |
|
576 //licence should be EPL |
|
577 licenceInSource = TraceCompilerEngineGlobals.getDefaultLicence(true); |
|
578 System.out.println("Reading default licence for " + header.getAbsolutePath() + " == " + licenceInSource); |
|
579 } |
|
580 } |
|
581 } |
|
582 if (licenceInHeader != licenceInHeader) { |
|
583 System.out.println("Error: licence in header " + header + " is not the same in source." + source); |
|
584 fail(); |
|
585 } |
|
586 } |
|
587 } |
|
588 |
|
589 if(!error){ |
|
590 System.out.println("All Traces Header files have been generated as expected"); |
|
591 } |
|
592 else { |
|
593 fail(); |
|
594 } |
|
595 } |
|
596 } |
|
597 |
|
598 |
|
599 /** |
|
600 * @param path |
|
601 */ |
|
602 private String readFirstMultiLineComment(String path) { |
|
603 StringBuffer sb = new StringBuffer(); |
|
604 try { |
|
605 FileReader reader = new FileReader(new File(path)); |
|
606 BufferedReader br = new BufferedReader(reader); |
|
607 String line; |
|
608 boolean inComment = false; |
|
609 |
|
610 while ((line = br.readLine()) != null) { |
|
611 if (line.trim().startsWith("/*")) { |
|
612 inComment = true; |
|
613 } |
|
614 if (inComment) { |
|
615 sb.append(line + System.getProperty("line.separator")); |
|
616 } |
|
617 if (line.trim().endsWith("*/") && inComment) { |
|
618 break; |
|
619 } |
|
620 } |
|
621 br.close(); |
|
622 } catch (Exception e) { |
|
623 System.out.println("Failed to open/read file " + path + " " + e.getMessage()); |
|
624 fail(); |
|
625 } |
|
626 String licence = null; |
|
627 if (sb.length()> 0) { |
|
628 licence = sb.toString(); |
|
629 if (!licence.contains("Copyright")) { |
|
630 licence = null; |
|
631 } |
|
632 } |
|
633 |
|
634 return licence; |
|
635 } |
|
636 |
|
637 /** |
|
638 * This function checks that the dictionary files have been generated in the expected locations with the right name |
|
639 * |
|
640 * @param path. |
|
641 */ |
|
642 public void CheckForDictionary(String path) { |
|
643 System.out.println ("CheckForDictionaries()"); |
|
644 |
|
645 List<File> dictsList = dicts.get(path); |
|
646 System.out.println("checking files " + dictsList.toString()); |
|
647 boolean error = false; |
|
648 |
|
649 if ((path.compareTo("_traces_slash_target_ext")==0 || path.compareTo("_traces_slash_target_ext_commonsource")==0) && oldBuilder && !oldTC){ |
|
650 System.out.println("No need to check for dictionary as old sbs cannot call TC"); |
|
651 } else { |
|
652 for (File dict : dictsList) { |
|
653 if(!dict.exists()) { |
|
654 error = true; |
|
655 System.out.println("Error: "+dict+" does not exist/hasn't been generated by TraceCompiler"); |
|
656 } |
|
657 } |
|
658 |
|
659 if (!error) { |
|
660 System.out.println("Dictionary files have been generated as expected"); |
|
661 } |
|
662 else { |
|
663 fail(); |
|
664 } |
|
665 } |
|
666 } |
|
667 |
|
668 |
|
669 /****************************************************ACTUAL TESTS************************************************************/ |
|
670 @Test |
|
671 public void MultipleMmpsTest1 (){ |
|
672 System.out.println ("*********************traces****************************"); |
|
673 createListHeadersDicts("sbs"); |
|
674 //Call Raptor |
|
675 InvokeCompiler("_traces", "sbs"); |
|
676 //Check for header files |
|
677 CheckForTracesHeaders("_traces"); |
|
678 //Check dictionary |
|
679 CheckForDictionary("_traces"); |
|
680 |
|
681 |
|
682 } |
|
683 |
|
684 |
|
685 @Test |
|
686 public void MultipleMmpsTest2 (){ |
|
687 System.out.println ("****************traces_mmpname**********************"); |
|
688 createListHeadersDicts("sbs"); |
|
689 //Call Raptor |
|
690 InvokeCompiler("_traces_mmpname", "sbs"); |
|
691 //Check for header files |
|
692 CheckForTracesHeaders("_traces_mmpname"); |
|
693 //Check dictionary |
|
694 CheckForDictionary("_traces_mmpname"); |
|
695 |
|
696 |
|
697 } |
|
698 |
|
699 |
|
700 @Test |
|
701 public void MultipleMmpsTest3 (){ |
|
702 System.out.println ("**********traces_slash_target_ext****************"); |
|
703 createListHeadersDicts("sbs"); |
|
704 //Call Raptor |
|
705 InvokeCompiler("_traces_slash_target_ext", "sbs"); |
|
706 //Check for header files |
|
707 CheckForTracesHeaders("_traces_slash_target_ext"); |
|
708 //Check dictionary |
|
709 CheckForDictionary("_traces_slash_target_ext"); |
|
710 |
|
711 |
|
712 } |
|
713 |
|
714 @Test |
|
715 public void MultipleMmpsTest4 (){ |
|
716 System.out.println ("**********traces_slash_target_ext_commonsource****************"); |
|
717 createListHeadersDicts("sbs"); |
|
718 //Call Raptor |
|
719 InvokeCompiler("_traces_slash_target_ext_commonsource", "sbs"); |
|
720 //Check for header files |
|
721 CheckForTracesHeaders("_traces_slash_target_ext_commonsource"); |
|
722 //Check dictionary |
|
723 CheckForDictionary("_traces_slash_target_ext_commonsource"); |
|
724 |
|
725 |
|
726 |
|
727 } |
|
728 |
|
729 @Test |
|
730 public void MultipleMmpsTest5 (){ |
|
731 System.out.println ("**********traces_target_type****************"); |
|
732 createListHeadersDicts("sbs"); |
|
733 //Call Raptor |
|
734 InvokeCompiler("_traces_target_type", "sbs"); |
|
735 //Check for header files |
|
736 CheckForTracesHeaders("_traces_target_type"); |
|
737 //Check dictionary |
|
738 CheckForDictionary("_traces_target_type"); |
|
739 |
|
740 |
|
741 } |
|
742 |
|
743 @Test |
|
744 public void MultipleMmpsTest6 (){ |
|
745 System.out.println ("**********traces_mixed****************"); |
|
746 createListHeadersDicts("sbs"); |
|
747 //Call Raptor |
|
748 InvokeCompiler("_traces_mixed", "sbs"); |
|
749 //Check for header files |
|
750 CheckForTracesHeaders("_traces_mixed"); |
|
751 //Check dictionary |
|
752 CheckForDictionary("_traces_mixed"); |
|
753 } |
|
754 } |