41
|
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 |
|
|
19 |
import static org.junit.Assert.fail;
|
|
20 |
|
|
21 |
import java.io.BufferedReader;
|
|
22 |
import java.io.DataInputStream;
|
|
23 |
import java.io.File;
|
|
24 |
import java.io.FileInputStream;
|
|
25 |
import java.io.FileOutputStream;
|
|
26 |
import java.io.IOException;
|
|
27 |
import java.io.InputStream;
|
|
28 |
import java.io.InputStreamReader;
|
|
29 |
import java.io.PrintStream;
|
|
30 |
|
|
31 |
public class ErrorLogsTestBase {
|
|
32 |
|
|
33 |
/****************************************************UTILITY FUNCTIONS FOR TESTS************************************************************/
|
|
34 |
|
|
35 |
/**
|
|
36 |
* This function gets an environment variable value given the name.
|
|
37 |
* @param variablename The name of the variable for which the value is required.
|
|
38 |
* @return The variable value.
|
|
39 |
*/
|
|
40 |
public String GetEnvironmentVariablePath(String variablename) {
|
|
41 |
String variablevalue = System.getenv(variablename);
|
|
42 |
if(variablevalue == null || (variablevalue.length()==0)){
|
|
43 |
fail();
|
|
44 |
}
|
|
45 |
|
|
46 |
// need to check that the path ends in a backslash
|
|
47 |
if(!variablevalue.endsWith(File.separator)){
|
|
48 |
variablevalue += File.separator;
|
|
49 |
}
|
|
50 |
return variablevalue;
|
|
51 |
}
|
|
52 |
|
|
53 |
/**
|
|
54 |
* This function invokes the desired compiler for a particular test case depending
|
|
55 |
* on the string passed
|
|
56 |
* @param compiler String specifying the compiler to run, and also specifying where
|
|
57 |
* the logs should be stored.
|
|
58 |
*/
|
|
59 |
public void InvokeCompiler(String compiler) {
|
|
60 |
System.out.println ("InvokeCompiler()");
|
|
61 |
//get epocroot location
|
|
62 |
String e32=GetEnvironmentVariablePath("EPOCROOT");
|
|
63 |
|
|
64 |
String TraceErrorAppPath = e32 + "testdata" + File.separator + "TraceErrorApp" + File.separator;
|
|
65 |
try{
|
|
66 |
File compilerpath = new File (e32 + "epoc32" + File.separator + "tools" + File.separator + "tracecompiler" + File.separator);
|
|
67 |
|
|
68 |
if (compiler.compareTo("_sbs")==0){//raptor
|
|
69 |
compilerpath = new File (e32 + "testdata" + File.separator + "TraceErrorApp" + File.separator +"group" + File.separator);
|
|
70 |
}
|
|
71 |
else if (compiler.compareTo("_mult_cpp")==0){//raptor compiling project with multiple source files
|
|
72 |
compilerpath = new File (e32 + "testdata" + File.separator + "MultipleCppTraceErrorApp" + File.separator + "group" + File.separator);
|
|
73 |
}
|
|
74 |
else if (compiler.compareTo("_mult_mmp")==0){//raptor compiling project with multiple source files
|
|
75 |
compilerpath = new File (e32 + "testdata" + File.separator + "MultipleMmpTraceErrorApps" + File.separator + "group" + File.separator);
|
|
76 |
}
|
|
77 |
else if (compiler.compareTo("_tc")!=0){
|
|
78 |
System.out.println("Error: Unrecognised test case. Use either _tc, _sbs, _mult_cpp or _mult_mmp");
|
|
79 |
fail();
|
|
80 |
}
|
|
81 |
|
|
82 |
//set up the process builder object
|
|
83 |
ProcessBuilder pb;
|
|
84 |
//commands to be used to invoke the compiler
|
|
85 |
if (compiler.compareTo("_tc")==0){//tracecompiler
|
|
86 |
// These EMMA flags are added, because of EMMA reporting in Hudson
|
|
87 |
// EMMA lfags are commented out, because it does not work in Hudson at the moment
|
|
88 |
// String emmaOutputFileFlag = "-Demma.coverage.out.file=" + e32 + "testdata" + File.separator + "reports" + File.separator + "emma" + File.separator + "coverage.emma";
|
|
89 |
// String emmaOutputMergeFlag = "-Demma.coverage.out.merge=true";
|
|
90 |
String emmaOutputFileFlag = "";
|
|
91 |
String emmaOutputMergeFlag = "";
|
|
92 |
pb = new ProcessBuilder("java", emmaOutputFileFlag, emmaOutputMergeFlag, "-classpath",".", "com.nokia.tracecompiler.TraceCompiler", "E8576D92", "TraceErrorApp",TraceErrorAppPath+"group"+File.separator+"TraceErrorApp.mmp",TraceErrorAppPath+"src"+File.separator+"TraceErrorApp.cpp");
|
|
93 |
}
|
|
94 |
else /*if (compiler.compareTo("_sbs")==0)*/{//for all other raptor cases
|
|
95 |
pb = new ProcessBuilder("sbs.bat","-c","armv5.tracecompiler");
|
|
96 |
}
|
|
97 |
|
|
98 |
pb.directory(compilerpath);
|
|
99 |
pb.redirectErrorStream(true);
|
|
100 |
|
|
101 |
//start the compiler
|
|
102 |
Process p = pb.start();
|
|
103 |
InputStream inp = p.getInputStream();
|
|
104 |
int c = -1;
|
|
105 |
|
|
106 |
|
|
107 |
String str = "";
|
|
108 |
|
|
109 |
/*
|
|
110 |
//read the output from the compiler into the input stream
|
|
111 |
while ((c = inp.read()) != -1) {
|
|
112 |
str= str +((char)c);
|
|
113 |
}
|
|
114 |
*/
|
|
115 |
|
|
116 |
StringBuilder sb = new StringBuilder();
|
|
117 |
//read the output from the compiler into the input stream
|
|
118 |
while ((c = inp.read()) != -1) {
|
|
119 |
sb.append(((char)c));
|
|
120 |
}
|
|
121 |
str = sb.toString();
|
|
122 |
|
|
123 |
|
|
124 |
//Declare output file to write logs to
|
|
125 |
FileOutputStream outstream;
|
|
126 |
PrintStream ps;
|
|
127 |
System.out.println ("creating output logs in buildlog"+compiler+".txt");
|
|
128 |
outstream = new FileOutputStream(e32+"epoc32"+File.separator+"build"+File.separator+"buildlog"+compiler+".txt");
|
|
129 |
ps = new PrintStream( outstream );
|
|
130 |
ps.println (str);
|
|
131 |
|
|
132 |
//check return code if tracecompiler.. we don't check error code for raptor:
|
|
133 |
int ret = p.exitValue();
|
|
134 |
if ((ret==0)&&(compiler.compareTo("_tc")==0)){
|
|
135 |
System.out.println("FAIL: TraceCompiler does not exit with error");
|
|
136 |
fail();
|
|
137 |
}
|
|
138 |
inp.close();
|
|
139 |
outstream.close();
|
|
140 |
}
|
|
141 |
|
|
142 |
catch (IOException e){//Catch IOException
|
|
143 |
System.err.println("Error: " + e.getMessage());
|
|
144 |
fail();
|
|
145 |
}
|
|
146 |
|
|
147 |
}
|
|
148 |
|
|
149 |
/**
|
|
150 |
* This function parses the log files (as specified by the passed string) for errors and warnings
|
|
151 |
* and stores them in a separate file (also specified by the same passed string)
|
|
152 |
*
|
|
153 |
* @param pathext String specifying the part of the name of the build log file to parse which is
|
|
154 |
* also part of the name of the file where parsed logs are written to.
|
|
155 |
*/
|
|
156 |
public void ParseLogFile(String pathext) {
|
|
157 |
System.out.println ("ParseLogFile()");
|
|
158 |
//get epocroot location
|
|
159 |
String e32=GetEnvironmentVariablePath("EPOCROOT");
|
|
160 |
|
|
161 |
|
|
162 |
try{
|
|
163 |
// Open the file
|
|
164 |
System.out.println ("opening buildlog"+pathext+".txt");
|
|
165 |
FileInputStream fstream = new FileInputStream(e32+"epoc32"+File.separator+"build"+File.separator+"buildlog"+pathext+".txt");
|
|
166 |
|
|
167 |
// Get the object of DataInputStream
|
|
168 |
//System.out.println ("creating input stream");
|
|
169 |
DataInputStream in = new DataInputStream(fstream);
|
|
170 |
BufferedReader br = new BufferedReader(new InputStreamReader(in));
|
|
171 |
String strLine;
|
|
172 |
|
|
173 |
//Declare output file to write parsed logs to
|
|
174 |
FileOutputStream out;
|
|
175 |
PrintStream p;
|
|
176 |
//System.out.println ("creating output stream");
|
|
177 |
out = new FileOutputStream(e32+"epoc32"+File.separator+"build"+File.separator+"parsedlogs"+pathext+".txt");
|
|
178 |
p = new PrintStream( out );
|
|
179 |
|
|
180 |
//Read File Line By Line and write to parsedlogs.txt
|
|
181 |
System.out.println ("Writing to parsedlogs"+pathext+".txt");
|
|
182 |
while ((strLine = br.readLine()) != null&&(strLine.length()) >= 9) {
|
|
183 |
//remove any leading white spaces because there are spaces when printed to standard output.
|
|
184 |
strLine=strLine.trim();
|
|
185 |
if((strLine.startsWith("error:")==true)||(strLine.startsWith("warning:")==true)){
|
|
186 |
// Write to a separate file
|
|
187 |
p.println (strLine);
|
|
188 |
}
|
|
189 |
|
|
190 |
}
|
|
191 |
|
|
192 |
//Close the input and output streams
|
|
193 |
in.close();
|
|
194 |
out.close();
|
|
195 |
}
|
|
196 |
|
|
197 |
catch (IOException e){//Catch IOException
|
|
198 |
System.err.println("Error: " + e.getMessage());
|
|
199 |
fail();
|
|
200 |
}
|
|
201 |
|
|
202 |
}
|
|
203 |
|
|
204 |
/**
|
|
205 |
* This function validates the parsed log file by comparing it to a reference file containg
|
|
206 |
* the knows warnings and errors
|
|
207 |
* @param project String specifying the name of the project folder that was compiled.
|
|
208 |
* @param pathext String specifying the part of the name of the parsed log file to validate.
|
|
209 |
*/
|
|
210 |
public void ValidateLogs(String project, String pathext) {
|
|
211 |
System.out.println ("ValidateLogs()");
|
|
212 |
//get epocroot location
|
|
213 |
String e32=GetEnvironmentVariablePath("EPOCROOT");
|
|
214 |
|
|
215 |
try{
|
|
216 |
// Open the files
|
|
217 |
System.out.println ("opening referencelog.txt and parsedlogs"+pathext+".txt");
|
|
218 |
FileInputStream fstream1 = new FileInputStream(e32+"testdata"+File.separator+project+File.separator+"data"+File.separator+"referencelog.txt");
|
|
219 |
FileInputStream fstream2 = new FileInputStream(e32+"epoc32"+File.separator+"build"+File.separator+"parsedlogs"+pathext+".txt");
|
|
220 |
|
|
221 |
// Get the objects of DataInputStream
|
|
222 |
//System.out.println ("creating input streams");
|
|
223 |
DataInputStream in1 = new DataInputStream(fstream1);
|
|
224 |
DataInputStream in2 = new DataInputStream(fstream2);
|
|
225 |
//System.out.println ("creating buffered readers");
|
|
226 |
BufferedReader br1 = new BufferedReader(new InputStreamReader(in1));
|
|
227 |
BufferedReader br2 = new BufferedReader(new InputStreamReader(in2));
|
|
228 |
String strLine1;
|
|
229 |
String strLine2;
|
|
230 |
int i=1;
|
|
231 |
|
|
232 |
//compare the two files
|
|
233 |
while (((strLine1 = br1.readLine()) != null)&&(((strLine2 = br2.readLine()) != null))) {
|
|
234 |
if (pathext.compareTo("_mult_mmp")!=0){//if this is not the multiple mmp test, then compare the whole error string
|
|
235 |
if(strLine1.compareTo(strLine2)==0){
|
|
236 |
System.out.println ("Validated line "+i+": "+strLine1);
|
|
237 |
}
|
|
238 |
else{
|
|
239 |
System.out.println ("Line "+i+" ("+strLine2+") is not correct.");
|
|
240 |
fail();
|
|
241 |
}
|
|
242 |
}
|
|
243 |
else{//else if this is the multiple mmp test, compare only the last 40 characters of the string because
|
|
244 |
//raptor does not have a specified order in which it compiles mmps using trace compiler so we can't validate exactly
|
|
245 |
if(strLine1.substring(strLine1.length()-40, strLine1.length()).compareTo(strLine2.substring(strLine1.length()-40, strLine2.length()))==0){
|
|
246 |
System.out.println ("Validated line "+i+": "+strLine1);
|
|
247 |
}
|
|
248 |
else{
|
|
249 |
System.out.println ("Line "+i+" ("+strLine2+") is not correct.");
|
|
250 |
fail();
|
|
251 |
}
|
|
252 |
}
|
|
253 |
i++;
|
|
254 |
}
|
|
255 |
|
|
256 |
if (i==1) {//never entered loop therefore there were no errors or warnings in the build logs
|
|
257 |
System.out.println("FAIL: Compiler did not output any correct errors to logs");
|
|
258 |
fail();
|
|
259 |
}
|
|
260 |
in1.close();
|
|
261 |
in2.close();
|
|
262 |
}
|
|
263 |
|
|
264 |
catch (IOException e){//Catch IOException
|
|
265 |
System.err.println("Error: " + e.getMessage());
|
|
266 |
fail();
|
|
267 |
}
|
|
268 |
}
|
|
269 |
} |