|
12
|
1 |
#
|
|
|
2 |
# Copyright (c) 2009 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 |
import sys
|
|
|
18 |
import os
|
|
|
19 |
import re
|
|
|
20 |
import time
|
|
|
21 |
import platform
|
|
|
22 |
from xml.dom import minidom
|
|
|
23 |
|
|
|
24 |
TC_DIR = os.getcwd() + os.sep + "TC" + os.sep
|
|
|
25 |
SCRIPTS_DIR = os.getcwd() + os.sep + "scripts" + os.sep
|
|
|
26 |
RESULTS_DIR = os.getcwd() + os.sep + "results" + os.sep
|
|
|
27 |
usage = "-h /h -? /?".split()
|
|
|
28 |
debug = 0
|
|
|
29 |
|
|
|
30 |
def UpdateTimeTaken(tm):
|
|
|
31 |
global time_taken, total_time_taken
|
|
|
32 |
time_taken = tm
|
|
|
33 |
total_time_taken += tm
|
|
|
34 |
|
|
|
35 |
def Usage():
|
|
|
36 |
print "Usage : "+ sys.argv[0] + " <outputfile> | -build [<testcasefile>]"
|
|
|
37 |
print "Execute test case(s): " + sys.argv[0] + " <outputfile> [<testcasefile>]"
|
|
|
38 |
print "Build test case : " + sys.argv[0] + " -build <testcase name>"
|
|
|
39 |
sys.exit()
|
|
|
40 |
|
|
|
41 |
def HABuild():
|
|
|
42 |
if len(sys.argv) != 3:
|
|
|
43 |
Usage()
|
|
|
44 |
cmd = "python " + SCRIPTS_DIR + "hatestbuild.py " + sys.argv[2].upper()
|
|
|
45 |
os.system(cmd)
|
|
|
46 |
sys.exit()
|
|
|
47 |
|
|
|
48 |
def OpenResults():
|
|
|
49 |
result = RESULTS_DIR + sys.argv[1]
|
|
|
50 |
if os.path.exists(result)and os.name == 'nt':
|
|
|
51 |
os.startfile(result)
|
|
|
52 |
return
|
|
|
53 |
|
|
|
54 |
def RunAll():
|
|
|
55 |
global time_taken;
|
|
|
56 |
cases = os.listdir(TC_DIR)
|
|
|
57 |
p = re.compile('^HATC')
|
|
|
58 |
for tc in cases:
|
|
|
59 |
tc = tc.strip().upper()
|
|
|
60 |
if p.match(tc):
|
|
|
61 |
print "\n" + tc
|
|
|
62 |
cmd = "python " + "\""+SCRIPTS_DIR + "hatestrun.py " + "\" "+ tc
|
|
|
63 |
stime = time.clock()
|
|
|
64 |
os.system(cmd)
|
|
|
65 |
etime = time.clock()
|
|
|
66 |
UpdateTimeTaken(etime-stime)
|
|
|
67 |
CompareResult(tc)
|
|
|
68 |
WriteXml()
|
|
|
69 |
if os.name != "posix":
|
|
|
70 |
OpenResults()
|
|
|
71 |
return
|
|
|
72 |
|
|
|
73 |
def RunTC():
|
|
|
74 |
global time_taken;
|
|
|
75 |
file = open( sys.argv[2] )
|
|
|
76 |
cases = file.readlines()
|
|
|
77 |
file.close()
|
|
|
78 |
for tc in cases:
|
|
|
79 |
tc = tc.strip().upper()
|
|
|
80 |
if tc:
|
|
|
81 |
print "\n" + tc
|
|
|
82 |
cmd = "python " + "\"" + SCRIPTS_DIR + "hatestrun.py" + "\" " + tc
|
|
|
83 |
stime = time.clock()
|
|
|
84 |
os.system(cmd)
|
|
|
85 |
etime = time.clock()
|
|
|
86 |
UpdateTimeTaken(etime-stime)
|
|
|
87 |
CompareResult(tc)
|
|
|
88 |
WriteXml()
|
|
|
89 |
if os.name != "posix":
|
|
|
90 |
OpenResults()
|
|
|
91 |
return
|
|
|
92 |
|
|
|
93 |
|
|
|
94 |
def CheckIssues(issue1, issueArr):
|
|
|
95 |
issuefound = 0
|
|
|
96 |
|
|
|
97 |
if debug == 1:
|
|
|
98 |
print >>debfile, "-------------------------------\n"
|
|
|
99 |
if issue1.getElementsByTagName('cause')[0].firstChild != None:
|
|
|
100 |
print >>debfile, "ISSUE: "+ issue1.getElementsByTagName('cause')[0].firstChild.data +" --> "
|
|
|
101 |
else:
|
|
|
102 |
print >>debfile, "ISSUE: --> "
|
|
|
103 |
|
|
|
104 |
for issue2 in issueArr:
|
|
|
105 |
if issue1.getElementsByTagName('typestring')[0].firstChild.data == issue2.getElementsByTagName('typestring')[0].firstChild.data and \
|
|
|
106 |
(( issue1.getElementsByTagName('cause')[0].firstChild == None and issue2.getElementsByTagName('cause')[0].firstChild == None ) or \
|
|
|
107 |
(issue1.getElementsByTagName('cause')[0].firstChild != None and \
|
|
|
108 |
issue1.getElementsByTagName('cause')[0].firstChild.data == issue2.getElementsByTagName('cause')[0].firstChild.data )) and \
|
|
|
109 |
issue1.getElementsByTagName('identitydescription')[0].firstChild.data == issue2.getElementsByTagName('identitydescription')[0].firstChild.data and \
|
|
|
110 |
issue1.getElementsByTagName('severity')[0].getElementsByTagName('typestring')[0].firstChild.data == issue2.getElementsByTagName('severity')[0].getElementsByTagName('typestring')[0].firstChild.data and \
|
|
|
111 |
issue1.getElementsByTagName('severity')[0].getElementsByTagName('typeid')[0].firstChild.data == issue2.getElementsByTagName('severity')[0].getElementsByTagName('typeid')[0].firstChild.data and \
|
|
|
112 |
issue1.getElementsByTagName('scseverity')[0].getElementsByTagName('typestring')[0].firstChild.data == issue2.getElementsByTagName('scseverity')[0].getElementsByTagName('typestring')[0].firstChild.data and \
|
|
|
113 |
issue1.getElementsByTagName('scseverity')[0].getElementsByTagName('typeid')[0].firstChild.data == issue2.getElementsByTagName('scseverity')[0].getElementsByTagName('typeid')[0].firstChild.data and \
|
|
|
114 |
issue1.getElementsByTagName('linenumber')[0].firstChild.data == issue2.getElementsByTagName('linenumber')[0].firstChild.data :
|
|
|
115 |
if debug == 1:
|
|
|
116 |
print >>debfile, "Found.\n"
|
|
|
117 |
issuefound = 1
|
|
|
118 |
break
|
|
|
119 |
|
|
|
120 |
if issuefound == 0:
|
|
|
121 |
if debug == 1:
|
|
|
122 |
print >>debfile, "NOT FOUND.\n"
|
|
|
123 |
|
|
|
124 |
return issuefound
|
|
|
125 |
|
|
|
126 |
def WriteXml():
|
|
|
127 |
global totalCount, passedCount, timeval, outfile, errfile, debug, debfile, time_taken, total_time_taken
|
|
|
128 |
timeval = time.strftime("%a %b %d, %Y at %H:%M:%S", time.localtime())
|
|
|
129 |
|
|
|
130 |
if totalCount > 0:
|
|
|
131 |
passedPercent = "%.2f" % (passedCount/totalCount)*100
|
|
|
132 |
else:
|
|
|
133 |
passedPercent = "0"
|
|
|
134 |
|
|
|
135 |
failedcount = totalCount - passedCount
|
|
|
136 |
ohdr = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
|
|
|
137 |
ohdr = ohdr + "<?xml-stylesheet type=\"text/xsl\" href=\"hatestresults.xsl\"?>\n"
|
|
|
138 |
ohdr = ohdr+"<testsuite errors=\"0\" failures=\""+str(failedcount)+"\" hostname=\""+platform.node()+"\" name=\"HeaderAnalyser\" tests=\""+str(totalCount)+"\" time=\""+str(round(total_time_taken,3))+"\" timestamp=\""+str(timeval)+"\">\n"
|
|
|
139 |
ohdr = ohdr+"<properties>\n</properties>\n"
|
|
|
140 |
ohdr = ohdr+ostr+"</testsuite>\n"
|
|
|
141 |
print >>outfile, ohdr
|
|
|
142 |
outfile.close()
|
|
|
143 |
|
|
|
144 |
if passedCount == totalCount:
|
|
|
145 |
print >>errfile, "No differencies.\n"
|
|
|
146 |
|
|
|
147 |
errfile.close()
|
|
|
148 |
if debug == 1:
|
|
|
149 |
debfile.close()
|
|
|
150 |
|
|
|
151 |
def CompareResult(tc):
|
|
|
152 |
global ostr, totalCount, passedCount, debug, debfile, errfile
|
|
|
153 |
if debug == 1:
|
|
|
154 |
print >>debfile, "\n-----------------------\n"
|
|
|
155 |
print >>debfile, "Testcase "+tc+"\n"
|
|
|
156 |
print >>debfile, "-----------------------\n"
|
|
|
157 |
|
|
|
158 |
# Read expected results (xml report):
|
|
|
159 |
expfilename = "TC"+os.sep+tc+os.sep+"results"+os.sep+tc+"_expected_results.xml"
|
|
|
160 |
if debug == 1:
|
|
|
161 |
print >>debfile, "Reading expected results from file: "+expfilename+"\n"
|
|
|
162 |
|
|
|
163 |
expected = minidom.parse(expfilename)
|
|
|
164 |
|
|
|
165 |
# Read actual results (xml report):
|
|
|
166 |
actfilename = "TC"+os.sep+tc+os.sep+"results"+os.sep+tc+"_results.xml"
|
|
|
167 |
if not os.path.exists(actfilename):
|
|
|
168 |
print "os.path.exists(actfilename)"
|
|
|
169 |
failed = 1
|
|
|
170 |
print >>errfile, "--------------------------------------------\n"
|
|
|
171 |
print >>errfile, "TESTCASE: "+tc+"\n\n"
|
|
|
172 |
print >>errfile, "Difference: Actual results file missing:\n"
|
|
|
173 |
print >>errfile, "Filename: "+actfilename+"\n"
|
|
|
174 |
print >>errfile, "--------------------------------------------\n"
|
|
|
175 |
ostr = ostr+" <testcase classname=\"HeaderAnalyser\" name=\""+tc+"\" time=\""+str(round(time_taken,3))+"\"\">\n"
|
|
|
176 |
ostr = ostr+" <failure message=\"Failed\" type=\"Failed\">Failed</failure>\n"
|
|
|
177 |
ostr = ostr+" <expresults>"+os.pardir+os.sep+expfilename+"</expresults>\n"
|
|
|
178 |
ostr = ostr+" <actresults>"+os.pardir+os.sep+actfilename+"</actresults>\n"
|
|
|
179 |
ostr = ostr+" </testcase>\n"
|
|
|
180 |
totalCount += 1
|
|
|
181 |
return
|
|
|
182 |
|
|
|
183 |
if debug == 1 :
|
|
|
184 |
print >>debfile, "Reading actual results from file: "+actfilename+"\n"
|
|
|
185 |
|
|
|
186 |
actual = minidom.parse(actfilename)
|
|
|
187 |
ostr = ostr + " <testcase classname=\"HeaderAnalyser\" name=\""+tc+"\" time=\""+str(round(time_taken,3))+"\">\n"
|
|
|
188 |
|
|
|
189 |
|
|
|
190 |
totalCount += 1
|
|
|
191 |
|
|
|
192 |
failed = 0
|
|
|
193 |
headerfound = 0
|
|
|
194 |
|
|
|
195 |
for expHeader in expected.getElementsByTagName('headerfile'):
|
|
|
196 |
headerfound = 0
|
|
|
197 |
expHeaderFilename = expHeader.getElementsByTagName('filename')[0].firstChild.data
|
|
|
198 |
expHeaderCompareFilename = expHeader.getElementsByTagName('comparefilename')[0].firstChild.data
|
|
|
199 |
|
|
|
200 |
# Strip off the paths from the filenames:
|
|
|
201 |
|
|
|
202 |
tmpIndex = expHeaderFilename.lower().rindex('\\') # index where the header name begins
|
|
|
203 |
expFile = expHeaderFilename[ tmpIndex+1 : len(expHeaderFilename) ].lower()
|
|
|
204 |
|
|
|
205 |
|
|
|
206 |
tmpIndex = expHeaderCompareFilename.lower().rindex('\\') # index of last backslash.
|
|
|
207 |
expCompareFile = expHeaderCompareFilename[ tmpIndex+1 : len(expHeaderCompareFilename) ].lower()
|
|
|
208 |
|
|
|
209 |
if debug == 1:
|
|
|
210 |
print >>debfile, "********************************\n"
|
|
|
211 |
print >>debfile, "EXP FILE: "+expFile+" -->\n"
|
|
|
212 |
|
|
|
213 |
for actHeader in actual.getElementsByTagName('headerfile'):
|
|
|
214 |
actHeaderFilename = actHeader.getElementsByTagName('filename')[0].firstChild.data
|
|
|
215 |
actHeaderCompareFilename = actHeader.getElementsByTagName('comparefilename')[0].firstChild.data
|
|
|
216 |
|
|
|
217 |
# Strip off the paths from the filenames:
|
|
|
218 |
|
|
|
219 |
tmpIndex = actHeaderFilename.lower().rindex(os.sep) # index of last backslash.
|
|
|
220 |
actFile = actHeaderFilename[ tmpIndex+1 : len(actHeaderFilename) ].lower()
|
|
|
221 |
|
|
|
222 |
tmpIndex = actHeaderCompareFilename.lower().rindex(os.sep) # index of last backslash.
|
|
|
223 |
actCompareFile = actHeaderCompareFilename[ tmpIndex+1 : len(actHeaderCompareFilename) ].lower()
|
|
|
224 |
|
|
|
225 |
if expFile == actFile and expCompareFile == actCompareFile:
|
|
|
226 |
if debug == 1:
|
|
|
227 |
print >>debfile, "Found.\n"
|
|
|
228 |
|
|
|
229 |
for iss1 in expHeader.getElementsByTagName('issue'):
|
|
|
230 |
if CheckIssues(iss1, actHeader.getElementsByTagName('issue')) == 0:
|
|
|
231 |
failed = 1
|
|
|
232 |
print >>errfile, "--------------------------------------------\n"
|
|
|
233 |
print >>errfile, "TESTCASE: "+tc+"\n\n"
|
|
|
234 |
print >>errfile, "Difference: Issue missing from actual results:\n"
|
|
|
235 |
print >>errfile, "Filename: "+expFile+"\n"
|
|
|
236 |
if iss1.getElementsByTagName('cause')[0].firstChild != None:
|
|
|
237 |
print >>errfile, "Issue: "+iss1.getElementsByTagName('cause')[0].firstChild.data+"\n"
|
|
|
238 |
else:
|
|
|
239 |
print >>errfile, "Issue: \n"
|
|
|
240 |
print >>errfile, "Description: "+iss1.getElementsByTagName('identitydescription')[0].firstChild.data +" "+ iss1.getElementsByTagName('typestring')[0].firstChild.data+" \n"
|
|
|
241 |
print >>errfile, "--------------------------------------------\n"
|
|
|
242 |
|
|
|
243 |
headerfound = 1
|
|
|
244 |
break
|
|
|
245 |
|
|
|
246 |
|
|
|
247 |
if headerfound == 0:
|
|
|
248 |
if debug == 1:
|
|
|
249 |
print >>debfile, "NOT FOUND.\n"
|
|
|
250 |
failed = 1
|
|
|
251 |
print >>errfile, "--------------------------------------------\n"
|
|
|
252 |
print >>errfile, "TESTCASE: "+tc+"\n\n"
|
|
|
253 |
print >>errfile, "Difference: Header results missing from actual results:\n"
|
|
|
254 |
print >>errfile, "Filename: "+expFile+"\n"
|
|
|
255 |
if iss1.getElementsByTagName('cause')[0].firstChild != None:
|
|
|
256 |
print >>errfile, "Issue: "+iss1.getElementsByTagName('cause')[0].firstChild.data+"\n"
|
|
|
257 |
else:
|
|
|
258 |
print >>errfile, "Issue: \n"
|
|
|
259 |
print >>errfile, "Description: "+iss1.getElementsByTagName('identitydescription')[0].firstChild.data +" "+ iss1.getElementsByTagName('typestring')[0].firstChild.data+" \n"
|
|
|
260 |
print >>errfile, "--------------------------------------------\n"
|
|
|
261 |
|
|
|
262 |
|
|
|
263 |
for actHeader in actual.getElementsByTagName('headerfile'):
|
|
|
264 |
actHeaderFilename = actHeader.getElementsByTagName('filename')[0].firstChild.data
|
|
|
265 |
actHeaderCompareFilename = actHeader.getElementsByTagName('comparefilename')[0].firstChild.data
|
|
|
266 |
|
|
|
267 |
# Strip off the paths from the filenames:
|
|
|
268 |
|
|
|
269 |
tmpIndex = actHeaderFilename.lower().rindex(os.sep) # index of last backslash.
|
|
|
270 |
actFile = actHeaderFilename[ tmpIndex+1 : len(actHeaderFilename) ].lower()
|
|
|
271 |
|
|
|
272 |
tmpIndex = actHeaderCompareFilename.lower().rindex(os.sep) # index of last backslash.
|
|
|
273 |
actCompareFile = actHeaderCompareFilename[ tmpIndex+1 : len(actHeaderCompareFilename) ].lower()
|
|
|
274 |
|
|
|
275 |
if debug == 1:
|
|
|
276 |
print >>debfile, "********************************\n"
|
|
|
277 |
print >>debfile, "ACT FILE: "+actFile+" -->\n"
|
|
|
278 |
|
|
|
279 |
headerfound = 0
|
|
|
280 |
for expHeader in expected.getElementsByTagName('headerfile'):
|
|
|
281 |
expHeaderFilename = expHeader.getElementsByTagName('filename')[0].firstChild.data
|
|
|
282 |
expHeaderCompareFilename = expHeader.getElementsByTagName('comparefilename')[0].firstChild.data
|
|
|
283 |
|
|
|
284 |
# Strip off the paths from the filenames:
|
|
|
285 |
tmpIndex = expHeaderFilename.lower().rindex('\\') # index where the header name begins
|
|
|
286 |
expFile = expHeaderFilename[ tmpIndex+1 : len(expHeaderFilename) ].lower()
|
|
|
287 |
|
|
|
288 |
tmpIndex = expHeaderCompareFilename.lower().rindex('\\') # index of last backslash.
|
|
|
289 |
expCompareFile = expHeaderCompareFilename[ tmpIndex+1 : len(expHeaderCompareFilename) ].lower()
|
|
|
290 |
|
|
|
291 |
if actFile == expFile and actCompareFile == expCompareFile:
|
|
|
292 |
if debug == 1:
|
|
|
293 |
print >>debfile, "Found.\n"
|
|
|
294 |
|
|
|
295 |
for iss2 in actHeader.getElementsByTagName('issue'):
|
|
|
296 |
if CheckIssues(iss2, expHeader.getElementsByTagName('issue')) == 0:
|
|
|
297 |
failed = 1
|
|
|
298 |
print >>errfile, "--------------------------------------------\n"
|
|
|
299 |
print >>errfile, "TESTCASE: "+tc+"\n\n"
|
|
|
300 |
print >>errfile, "Difference: Issue missing from expected results:\n"
|
|
|
301 |
print >>errfile, "Filename: "+actFile+"\n"
|
|
|
302 |
if iss1.getElementsByTagName('cause')[0].firstChild != None:
|
|
|
303 |
print >>errfile, "Issue: "+iss1.getElementsByTagName('cause')[0].firstChild.data+"\n"
|
|
|
304 |
else:
|
|
|
305 |
print >>errfile, "Issue: \n"
|
|
|
306 |
print >>errfile, "Description: "+iss1.getElementsByTagName('identitydescription')[0].firstChild.data +" "+ iss1.getElementsByTagName('typestring')[0].firstChild.data+" \n"
|
|
|
307 |
print >>errfile, "--------------------------------------------\n"
|
|
|
308 |
|
|
|
309 |
headerfound = 1
|
|
|
310 |
break
|
|
|
311 |
|
|
|
312 |
if headerfound == 0:
|
|
|
313 |
if debug == 1:
|
|
|
314 |
print >>debfile, "NOT FOUND.\n"
|
|
|
315 |
|
|
|
316 |
failed = 1
|
|
|
317 |
print >>errfile, "--------------------------------------------\n"
|
|
|
318 |
print >>errfile, "TESTCASE: "+tc+"\n\n"
|
|
|
319 |
print >>errfile, "Difference: Header results missing from expected results:\n"
|
|
|
320 |
print >>errfile, "Filename: "+actFile+"\n"
|
|
|
321 |
if iss1.getElementsByTagName('cause')[0].firstChild != None:
|
|
|
322 |
print >>errfile, "Issue: "+iss1.getElementsByTagName('cause')[0].firstChild.data+"\n"
|
|
|
323 |
else:
|
|
|
324 |
print >>errfile, "Issue: \n"
|
|
|
325 |
print >>errfile, "Description: "+iss1.getElementsByTagName('identitydescription')[0].firstChild.data +" "+ iss1.getElementsByTagName('typestring')[0].firstChild.data+" \n"
|
|
|
326 |
print >>errfile, "--------------------------------------------\n"
|
|
|
327 |
|
|
|
328 |
if failed == 0:
|
|
|
329 |
passedCount += 1
|
|
|
330 |
ostr = ostr+" <expresults>"+os.pardir+os.sep+expfilename+"</expresults>\n"
|
|
|
331 |
ostr = ostr+" <actresults>"+os.pardir+os.sep+actfilename+"</actresults>\n"
|
|
|
332 |
ostr = ostr+" </testcase>\n"
|
|
|
333 |
else:
|
|
|
334 |
ostr = ostr+" <failure message=\"Failed\" type=\"Failed\">Failed</failure>\n"
|
|
|
335 |
ostr = ostr+" <expresults>"+os.pardir+os.sep+expfilename+"</expresults>\n"
|
|
|
336 |
ostr = ostr+" <actresults>"+os.pardir+os.sep+actfilename+"</actresults>\n"
|
|
|
337 |
ostr = ostr+" </testcase>\n"
|
|
|
338 |
|
|
|
339 |
|
|
|
340 |
if len(sys.argv) == 1:
|
|
|
341 |
Usage()
|
|
|
342 |
if sys.argv[1] in usage:
|
|
|
343 |
Usage()
|
|
|
344 |
|
|
|
345 |
if sys.argv[1] == "-build":
|
|
|
346 |
HABuild()
|
|
|
347 |
|
|
|
348 |
ostr = ""
|
|
|
349 |
if debug == 1:
|
|
|
350 |
debfile = open("log/hatestdebug.txt","w") # Debug information is printed to this file.
|
|
|
351 |
|
|
|
352 |
passedCount = 0
|
|
|
353 |
totalCount = 0
|
|
|
354 |
time_taken = 0
|
|
|
355 |
total_time_taken = 0
|
|
|
356 |
|
|
|
357 |
outfile = open("results/"+ sys.argv[1],"w") # Test execution results are printed here.
|
|
|
358 |
errfile = open("log/hatestdiff.txt","w") # Differences of not passed test cases are printed here.
|
|
|
359 |
|
|
|
360 |
if len(sys.argv) == 2:
|
|
|
361 |
RunAll()
|
|
|
362 |
else:
|
|
|
363 |
RunTC()
|
|
|
364 |
|