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 #!/usr/bin/perl |
|
17 |
|
18 use File::Copy; |
|
19 use Cwd; |
|
20 use Getopt::Long; |
|
21 use XML::Parser::Expat; |
|
22 use Data::Dumper; |
|
23 |
|
24 #---------------------------------------Initialization------------------------------------------------------# |
|
25 |
|
26 $projectrootname = "/"; #is set to correct at run-time |
|
27 $projectdrive = "z:"; #is set to correct at run-time |
|
28 |
|
29 $unitTestRunner = "unittest_qt.pl"; |
|
30 $scriptLocation = "mmsharinguis/tsrc/unittestrunner"; |
|
31 $coverageResultsDirDefault = "mmsharinguis/tsrc/unittestrunner/qtresults/"; |
|
32 $testConfigDefault = "unittest_qt_config.txt"; |
|
33 $qtProFileDefault = "tsrc.pro"; |
|
34 $buildResults = "BuildResults.txt"; |
|
35 $coverageDat = "MON.dat"; |
|
36 $coverageSymbols = "MON.sym"; |
|
37 $coverageProfile = "profile.txt"; |
|
38 |
|
39 $coverageResultsFile = "CTCHTML/index.html"; |
|
40 $finalResultsFile = "AllResults.html"; |
|
41 $cssFile = "CTCHTML/ctc.css"; |
|
42 $cssLink = "<link rel=\"stylesheet\""; |
|
43 |
|
44 $xmlDllLine = "TestCase"; |
|
45 $xmlResultLine = "Incident"; |
|
46 $xmlCaseFailed = "failed"; |
|
47 $xmlCasePassed = "pass"; |
|
48 $outputString = ""; |
|
49 $outputFileBodyStart = "<body"; |
|
50 |
|
51 $totalCount = 0; |
|
52 $passedCount = 0; |
|
53 $failedCount = 0; |
|
54 |
|
55 $qtestOutputString = ""; |
|
56 |
|
57 my @testNamesAndLogFiles = ( [""],[""] ); # two dimensional array e.g. [name, log1, log2], [name2, log3, log5, log6] |
|
58 |
|
59 # from command line |
|
60 my ($param_noclean, |
|
61 $testConfig, |
|
62 $qtProFile, |
|
63 $coverageResultsDir); |
|
64 |
|
65 #---------------------------------------Main Start----------------------------------------------------------# |
|
66 |
|
67 # read command line parameters |
|
68 my $result = GetOptions("noclean" => \$param_noclean, |
|
69 "config:s" => \$testConfig, |
|
70 "pro:s" => \$qtProFile, |
|
71 "results:s" => \$coverageResultsDir, |
|
72 "help" => \$help); |
|
73 |
|
74 $startdir = cwd; |
|
75 |
|
76 if (defined $help){ |
|
77 print_help(); |
|
78 exit; |
|
79 } |
|
80 |
|
81 findProjectDriveAndRoot(); |
|
82 |
|
83 createResultsDir(); |
|
84 |
|
85 # set target for intrumentation result |
|
86 $ENV{'CTC_DATA_PATH'}= "$coverageResultsDir"; |
|
87 |
|
88 doClean(); |
|
89 |
|
90 parseConfigFile(); |
|
91 |
|
92 buildTests(); |
|
93 |
|
94 runTests(); |
|
95 |
|
96 chdir($startdir); |
|
97 |
|
98 # create textual output |
|
99 chdir("$coverageResultsDir"); |
|
100 doSystemCall("ctcpost $coverageSymbols $coverageDat -p $coverageProfile -T 70"); |
|
101 doSystemCall("ctc2html -i $coverageProfile -t 70"); |
|
102 |
|
103 # clear target for intrumentation result |
|
104 $ENV{'CTC_DATA_PATH'}= ""; |
|
105 |
|
106 combineResults(); |
|
107 |
|
108 chdir($startdir); |
|
109 |
|
110 #---------------------------------------Main Ends-------------------------------------------------------------# |
|
111 |
|
112 # ----------------------------------------------------------------------------- |
|
113 # |
|
114 # ----------------------------------------------------------------------------- |
|
115 # |
|
116 sub findProjectDriveAndRoot() |
|
117 { |
|
118 $tempStartDir = $startdir; |
|
119 if ($tempStartDir =~ m/$scriptLocation/){ |
|
120 # extract project root |
|
121 for ($tempStartDir) { |
|
122 s/$scriptLocation+$//; |
|
123 } |
|
124 # divide it to drive and root |
|
125 if ($tempStartDir =~ /^(.:)(.*)/){ |
|
126 $projectdrive = $1; |
|
127 $projectrootname = $2; |
|
128 } |
|
129 print "project drive: $projectdrive \n"; |
|
130 print "project root: $projectrootname \n"; |
|
131 } |
|
132 else{ |
|
133 print "cannot determine project drive and root, use defaults!\n"; |
|
134 } |
|
135 } |
|
136 |
|
137 # ----------------------------------------------------------------------------- |
|
138 # |
|
139 # ----------------------------------------------------------------------------- |
|
140 # |
|
141 sub createResultsDir() |
|
142 { |
|
143 # create directory for results |
|
144 if ( defined $coverageResultsDir ){ |
|
145 if ($coverageResultsDir =~ /^(.:)/){ |
|
146 print("Drive name given in results dir arg\n"); |
|
147 } |
|
148 else{ |
|
149 $coverageResultsDir = "$projectdrive" . "/" . "$coverageResultsDir"; |
|
150 } |
|
151 } |
|
152 else{ |
|
153 $coverageResultsDir = "$projectdrive$projectrootname$coverageResultsDirDefault"; |
|
154 } |
|
155 print ("Writing results to $coverageResultsDir \n\n"); |
|
156 if (mkdir("$coverageResultsDir", 0755)){ |
|
157 print("The results directory was created successfully! \n"); |
|
158 } |
|
159 else { |
|
160 print("The results directory already exists. \n"); |
|
161 } |
|
162 } |
|
163 |
|
164 # ----------------------------------------------------------------------------- |
|
165 # |
|
166 # ----------------------------------------------------------------------------- |
|
167 # |
|
168 sub doClean() |
|
169 { |
|
170 if (!defined $param_noclean) |
|
171 { |
|
172 # clear previous results |
|
173 print("Cleaning previous results. \n"); |
|
174 unlink("$coverageResultsDir$buildResults"); |
|
175 unlink("$coverageResultsDir$coverageDat"); |
|
176 unlink("$coverageResultsDir$coverageSymbols"); |
|
177 unlink("$coverageResultsDir$coverageProfile"); |
|
178 unlink("$coverageResultsDir$finalResultsFile"); |
|
179 } |
|
180 } |
|
181 |
|
182 # ----------------------------------------------------------------------------- |
|
183 # |
|
184 # ----------------------------------------------------------------------------- |
|
185 # |
|
186 sub parseConfigFile() |
|
187 { |
|
188 if ( !defined $testConfig ){ |
|
189 print("Config file not defined, using default. \n"); |
|
190 $testConfig = $testConfigDefault; |
|
191 } |
|
192 |
|
193 open(CONFIG, $testConfig) or die("file $testConfig not found!\n"); |
|
194 |
|
195 @config_file_content = <CONFIG>; |
|
196 |
|
197 |
|
198 for ($j = 0; $j <= $#config_file_content; $j++) |
|
199 { |
|
200 # remove \n from each line |
|
201 $currline = @config_file_content[$j]; |
|
202 for ($currline) { |
|
203 s/\n+$//; |
|
204 } |
|
205 @{ $testNamesAndLogFiles [$j] } = split( ",", $currline ); |
|
206 } |
|
207 |
|
208 print Dumper( @testNamesAndLogFiles ); |
|
209 |
|
210 close(CONFIG); |
|
211 } |
|
212 |
|
213 # ----------------------------------------------------------------------------- |
|
214 # |
|
215 # ----------------------------------------------------------------------------- |
|
216 # |
|
217 sub buildTests() |
|
218 { |
|
219 if ( !defined $qtProFile ){ |
|
220 print("Pro file not defined, using default. \n"); |
|
221 $qtProFile = $qtProFileDefault; |
|
222 } |
|
223 doSystemCall( "qmake $qtProFile" ); |
|
224 doSystemCall( "sbs reallyclean" ); |
|
225 doSystemCall( "qmake $qtProFile" ); |
|
226 |
|
227 $exclude = "-C \"EXCLUDE+*\tsrc\*\" -C \"EXCLUDE+*/*/tsrc/*\" -C \"EXCLUDE+*/*/*/tsrc/*\" -C \"EXCLUDE+moc_*\""; |
|
228 |
|
229 doSystemCall( "call ctcwrap -i d -n $coverageResultsDir$coverageSymbols $exclude -2comp sbs.bat -c winscw_udeb" ); |
|
230 } |
|
231 |
|
232 # ----------------------------------------------------------------------------- |
|
233 # |
|
234 # ----------------------------------------------------------------------------- |
|
235 # |
|
236 sub runTests() |
|
237 { |
|
238 for $i ( 0 .. $#testNamesAndLogFiles ) { |
|
239 $testName = $testNamesAndLogFiles[$i][0]; |
|
240 print("Running tests for: $testName\n"); |
|
241 |
|
242 $testCall = "\\epoc32\\release\\winscw\\udeb\\" . $testName . " -xml"; |
|
243 doSystemCall( $testCall ); |
|
244 |
|
245 for $j ( 1 .. $#{ $testNamesAndLogFiles [$i] } ) { |
|
246 $logFile = $projectdrive . "\\epoc32\\winscw\\c\\" . $testNamesAndLogFiles[$i][$j]; |
|
247 print("Copying log file: $logFile\n"); |
|
248 copy( $logFile, "$coverageResultsDir" ); |
|
249 } |
|
250 } |
|
251 } |
|
252 |
|
253 # ----------------------------------------------------------------------------- |
|
254 # |
|
255 # ----------------------------------------------------------------------------- |
|
256 # |
|
257 sub combineResults() |
|
258 { |
|
259 open(COVERAGE, "$coverageResultsDir$coverageResultsFile") or die("file $coverageResultsFile not found!\n"); |
|
260 @coverageFileContent = <COVERAGE>; |
|
261 |
|
262 # append coverage information after eunit results |
|
263 |
|
264 for ($j = 0; $j <= $#coverageFileContent; $j++){ |
|
265 $currentLine = @coverageFileContent[$j]; |
|
266 |
|
267 if ($currentLine =~ /$cssLink/){ |
|
268 if ( open(CSSFILE, "$coverageResultsDir$cssFile") ){ |
|
269 # append css styles to results html |
|
270 $outputString .= "<style type=\"text/css\"> body {"; |
|
271 @cssFileContent = <CSSFILE>; |
|
272 my($line); |
|
273 foreach $line (@cssFileContent){ |
|
274 $outputString .= $line; |
|
275 } |
|
276 $outputString .= "}</style>\n"; |
|
277 close(CSSFILE); |
|
278 } |
|
279 } |
|
280 else{ |
|
281 $outputString .= $currentLine; |
|
282 |
|
283 if ($currentLine =~ /$outputFileBodyStart/){ |
|
284 $outputString .= parseXmlResults(); |
|
285 $outputString .= "<br><br>" |
|
286 } |
|
287 } |
|
288 } |
|
289 |
|
290 open(NEWRESULTSFILE, "> $coverageResultsDir$finalResultsFile") or die "Cannot open final results file\n"; |
|
291 print NEWRESULTSFILE "$outputString"; |
|
292 close(NEWRESULTSFILE); |
|
293 close(OUTPUT); |
|
294 close(COVERAGE); |
|
295 } |
|
296 |
|
297 # ----------------------------------------------------------------------------- |
|
298 # |
|
299 # ----------------------------------------------------------------------------- |
|
300 # |
|
301 sub parseXmlResults() |
|
302 { |
|
303 $qtestOutputString = "<span class=\"head1\">QTestLib Results</span><br><br>\n"; |
|
304 |
|
305 |
|
306 for $i ( 0 .. $#testNamesAndLogFiles ) { |
|
307 $testName = $testNamesAndLogFiles[$i][0]; |
|
308 |
|
309 for $j ( 1 .. $#{ $testNamesAndLogFiles [$i] } ) { |
|
310 $logFile = $testNamesAndLogFiles[$i][$j]; |
|
311 if ( -e "$coverageResultsDir$logFile" ){ |
|
312 print("Parsing: $logFile\n"); |
|
313 open(TESTRESULTS, "$coverageResultsDir$logFile"); |
|
314 $parser = new XML::Parser::Expat; |
|
315 $parser->setHandlers('Start' => \&sh, |
|
316 'End' => \&eh, |
|
317 'Char' => \&ch); |
|
318 |
|
319 $totalCount = 0; |
|
320 $passedCount = 0; |
|
321 $failedCount = 0; |
|
322 eval{ |
|
323 ### try block |
|
324 $parser->parse(*TESTRESULTS); |
|
325 }; |
|
326 if ($@){ |
|
327 ### catch block |
|
328 print("$logFile, parsing failed\n"); |
|
329 $qtestOutputString .= "<span class=\"red\">$logFile parsing failed, testcase execution might have failed </span><br>\n"; |
|
330 }; |
|
331 close(TESTRESULTS); |
|
332 |
|
333 } |
|
334 else{ |
|
335 |
|
336 print("$logFile, not found\n"); |
|
337 $qtestOutputString .= "<span class=\"head3\">"; |
|
338 $qtestOutputString .= "$testName => </span>"; |
|
339 $qtestOutputString .= "<span class=\"red\">$logFile not found, testcase building might have failed </span><br>\n"; |
|
340 } |
|
341 } |
|
342 } |
|
343 |
|
344 return $qtestOutputString; |
|
345 } |
|
346 |
|
347 # ----------------------------------------------------------------------------- |
|
348 # |
|
349 # ----------------------------------------------------------------------------- |
|
350 # |
|
351 sub sh |
|
352 { |
|
353 my ($p, $el, %atts) = @_; |
|
354 if ( $el eq $xmlDllLine ) |
|
355 { |
|
356 $qtestOutputString .= "<span class=\"head3\">"; |
|
357 $dllName = %atts->{name}; |
|
358 @dllNameParts = split m!(\\)!, $dllName; |
|
359 $dllName = $dllNameParts[$#dllNameParts]; |
|
360 $qtestOutputString .= "$dllName => </span>"; |
|
361 } |
|
362 |
|
363 if ( $el eq $xmlResultLine ) |
|
364 { |
|
365 $status = %atts->{type}; |
|
366 if ( $status eq $xmlCasePassed ) |
|
367 { |
|
368 $passedCount++; |
|
369 } |
|
370 else |
|
371 { |
|
372 $failedCount++; |
|
373 } |
|
374 } |
|
375 } |
|
376 |
|
377 # ----------------------------------------------------------------------------- |
|
378 # |
|
379 # ----------------------------------------------------------------------------- |
|
380 # |
|
381 sub eh |
|
382 { |
|
383 my ($p, $el) = @_; |
|
384 if ( $el eq $xmlDllLine ) |
|
385 { |
|
386 $totalCount = $passedCount + $failedCount; |
|
387 if ( $failedCount > 0 || $totalCount == 0 ) |
|
388 { |
|
389 $qtestOutputString .= "<span class=\"red\">Testcases passed/run: $passedCount/$totalCount </span><br>\n"; |
|
390 } |
|
391 else |
|
392 { |
|
393 $qtestOutputString .= "<span class=\"blue\">Testcases passed/run: $passedCount/$totalCount </span><br>\n"; |
|
394 } |
|
395 $passedCount = 0; |
|
396 $failedCount = 0; |
|
397 } |
|
398 } |
|
399 |
|
400 # ----------------------------------------------------------------------------- |
|
401 # |
|
402 # ----------------------------------------------------------------------------- |
|
403 # |
|
404 sub ch |
|
405 { |
|
406 my ($p, $el) = @_; |
|
407 #print ("$el\n"); |
|
408 } |
|
409 |
|
410 # ----------------------------------------------------------------------------- |
|
411 # |
|
412 # ----------------------------------------------------------------------------- |
|
413 # |
|
414 sub doSystemCall |
|
415 { |
|
416 #print("\nDoing system call: $_[0]\n"); |
|
417 #system($_[0]); |
|
418 system("echo Doing system call: $_[0] >> $coverageResultsDir$buildResults"); |
|
419 system("$_[0] >> $coverageResultsDir$buildResults 2>&1"); |
|
420 } |
|
421 |
|
422 # ----------------------------------------------------------------------------- |
|
423 # |
|
424 # ----------------------------------------------------------------------------- |
|
425 # |
|
426 sub print_help |
|
427 { |
|
428 print("\n*************************************************************\n\n"); |
|
429 print("Script runs by default all multimediasharing qt tests\n"); |
|
430 print("and creates build, test and coverage results to:\n\n"); |
|
431 print(" mmsharing/src/internal/unittestrunner/qtresults/\n\n"); |
|
432 print("Own configuration file (list of components to be processed)\n"); |
|
433 print("can be used as well:\n\n"); |
|
434 print(" >unittest_ctc.pl -config=myowntestcomponents.txt\n\n"); |
|
435 print("The text file should follow the syntax of default configuration file\n"); |
|
436 print("mmsharing/src/internal/unittestrunner/unittest_qt_config.txt\n\n"); |
|
437 print("When running just some set of components you might want to \"merge\" the results"); |
|
438 print("with existing coverage results.\n"); |
|
439 print("That is possible with command:\n\n"); |
|
440 print(" >unittest_ctc.pl -eunitdlls=myowneunitcomponents.txt -noclean\n"); |
|
441 print("\n*************************************************************\n"); |
|
442 } |
|