|
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 |
|
22 #---------------------------------------Initialization------------------------------------------------------# |
|
23 |
|
24 $coverageResultsDirDefault = "mmsharinguis/tsrc/unittestrunner/results/"; |
|
25 |
|
26 $eunitExe = "/epoc32/release/winscw/udeb/EUnitExeRunner.exe"; |
|
27 $eunitParams = "/l xml /e S60AppEnv /w 90 /p All /t 3600"; |
|
28 $eunitParams2 = "/d alloc"; |
|
29 $eunitResults = "EUnitLog.xml"; |
|
30 $eunitDllsDefault = "eunitdlls_ctc.txt"; |
|
31 $buildResults = "BuildResults.txt"; |
|
32 |
|
33 $eunitSrcDllLocation = "/epoc32/release/winscw/udeb/"; |
|
34 $eunitDstDllLocation = "/epoc32/release/winscw/udeb/z/sys/bin/"; |
|
35 |
|
36 $eunitLog = "/epoc32/winscw/c/DigiaEUnit/Logs/DigiaEUnit_log.xml"; |
|
37 $eunitLog2 = "/epoc32/winscw/c/shared/Eunit/Logs/EUnit_log.xml"; |
|
38 |
|
39 $eunitTestBuildMode = "1"; |
|
40 |
|
41 $ignoredFileName = "ignored_ctc.txt"; |
|
42 $ignoredmodeSourceRelative = "1"; |
|
43 |
|
44 $coverageSymbols = "MON.sym"; |
|
45 #$ctcCommandPart1 = "ctcwrap -i d -2comp -no-conf-check -n"; |
|
46 $ctcCommandPart1 = "ctcwrap -i d -2comp -n"; |
|
47 $ctcCommandPart2 = "sbs.bat -c winscw_udeb"; |
|
48 $ctcCommandPart2Test = "sbs -c winscw_udeb.test"; |
|
49 $ctcIgnoredPart1 = " -C \"EXCLUDE+"; |
|
50 $ctcIgnoredPart2 = "\" "; |
|
51 |
|
52 # from command line |
|
53 my ($param_noclean, |
|
54 $projectrootname, |
|
55 $projectdrive, |
|
56 $eunitDlls, |
|
57 $allocFailure); |
|
58 |
|
59 #---------------------------------------Main Start----------------------------------------------------------# |
|
60 |
|
61 # read command line parameters |
|
62 my $result = GetOptions("noclean" => \$param_noclean, |
|
63 "drive=s" => \$projectdrive, |
|
64 "root=s" => \$projectrootname, |
|
65 "eunitdlls:s" => \$eunitDlls, |
|
66 "allocfailure:i" => \$allocFailure, |
|
67 "results:s" => \$coverageResultsDir ); |
|
68 |
|
69 |
|
70 if (!defined $projectdrive) |
|
71 { |
|
72 die("Project drive not defined!\n"); |
|
73 } |
|
74 |
|
75 if (!defined $projectrootname) |
|
76 { |
|
77 die("Project root not defined!\n"); |
|
78 } |
|
79 |
|
80 if (!defined $eunitDlls || length($eunitDlls) == 0 ) |
|
81 { |
|
82 print("Project dlls not defined, using defaults!\n"); |
|
83 $eunitDlls = $eunitDllsDefault; |
|
84 } |
|
85 |
|
86 if (defined $allocFailure && $allocFailure > 0 ) |
|
87 { |
|
88 print("Alloc failure mode active!\n"); |
|
89 } |
|
90 |
|
91 if ( !defined $coverageResultsDir ) |
|
92 { |
|
93 print("Project results dir not defined, using default!\n"); |
|
94 $coverageResultsDir = "$projectdrive$projectrootname$coverageResultsDirDefault"; |
|
95 } |
|
96 |
|
97 $startdir = cwd; |
|
98 |
|
99 # remove previous results |
|
100 unlink("$coverageResultsDir$eunitResults"); |
|
101 |
|
102 # open file including eunit test dlls path and names |
|
103 open(EUNITDLLS, $eunitDlls) or die("file $eunitDlls not found!\n"); |
|
104 @dllsFileContent = <EUNITDLLS>; |
|
105 |
|
106 # open file containing files exluded from measurements |
|
107 open(IGNOREDFILE, $ignoredFileName) or die("file $ignoredFileName not found!\n"); |
|
108 |
|
109 $excludedCmd = parseExcluded(); |
|
110 |
|
111 # build |
|
112 doBuild(); |
|
113 |
|
114 #run all tests (with or without alloc) |
|
115 if (defined $allocFailure && $allocFailure > 0) |
|
116 { |
|
117 doSystemCall("$eunitExe $eunitParams $eunitParams2"); |
|
118 } |
|
119 else |
|
120 { |
|
121 doSystemCall("$eunitExe $eunitParams"); |
|
122 } |
|
123 |
|
124 # cleanup |
|
125 doBuild( "clean" ); |
|
126 |
|
127 # fix incorrect xml syntax |
|
128 if ( -e "$eunitLog2" ) |
|
129 { |
|
130 sanitizeResultFile(); |
|
131 } |
|
132 |
|
133 # store results file |
|
134 copy($eunitLog, "$coverageResultsDir$eunitResults"); |
|
135 copy($eunitLog2, "$coverageResultsDir$eunitResults"); |
|
136 |
|
137 close (EUNITDLLS); |
|
138 close (IGNOREDFILE); |
|
139 |
|
140 #---------------------------------------Main Ends-------------------------------------------------------------# |
|
141 |
|
142 sub parseExcluded() |
|
143 { |
|
144 #exclude headers and test sources from measurements |
|
145 @ignoredFileContent = <IGNOREDFILE>; |
|
146 $ignoredText = ""; |
|
147 for ($j = 0; $j <= $#ignoredFileContent; $j++) |
|
148 { |
|
149 my $currentIgnoredMode = @ignoredFileContent[$j]; |
|
150 # remove \n from path |
|
151 for ($currentIgnoredMode) { |
|
152 s/\n+$//; |
|
153 } |
|
154 |
|
155 $j++; |
|
156 |
|
157 my $currentIgnoredLine = @ignoredFileContent[$j]; |
|
158 # remove \n from dll name |
|
159 for ($currentIgnoredLine) { |
|
160 s/\n+$//; |
|
161 } |
|
162 |
|
163 #print("ignore mode: $currentIgnoredMode\n"); |
|
164 #print("ignore txt: $currentIgnoredLine\n"); |
|
165 |
|
166 if ($currentIgnoredMode =~ /$ignoredmodeSourceRelative/) |
|
167 { |
|
168 $ignoredText .= "$ctcIgnoredPart1$projectdrive$projectrootname$currentIgnoredLine$ctcIgnoredPart2"; |
|
169 } |
|
170 else |
|
171 { |
|
172 $ignoredText .= "$ctcIgnoredPart1$projectdrive$currentIgnoredLine$ctcIgnoredPart2"; |
|
173 } |
|
174 } |
|
175 return $ignoredText; |
|
176 } |
|
177 |
|
178 sub doBuild() |
|
179 { |
|
180 my $previousPathLine = ""; |
|
181 for ($j = 0; $j <= $#dllsFileContent; $j++) |
|
182 { |
|
183 my $currentPathLine = @dllsFileContent[$j]; |
|
184 # remove \n from path |
|
185 for ($currentPathLine) { |
|
186 s/\n+$//; |
|
187 } |
|
188 |
|
189 $j++; |
|
190 |
|
191 my $currentDllNameLine = @dllsFileContent[$j]; |
|
192 # remove \n from dll name |
|
193 for ($currentDllNameLine) { |
|
194 s/\n+$//; |
|
195 } |
|
196 |
|
197 $j++; |
|
198 |
|
199 my $currentBuildModeLine = @dllsFileContent[$j]; |
|
200 # remove \n from build mode |
|
201 for ($currentBuildModeLine) { |
|
202 s/\n+$//; |
|
203 } |
|
204 |
|
205 $j++; |
|
206 |
|
207 my $currentExtraCommandsLine = @dllsFileContent[$j]; |
|
208 # remove \n from extra commands |
|
209 for ($currentExtraCommandsLine) { |
|
210 s/\n+$//; |
|
211 } |
|
212 |
|
213 print("DLL path: $currentPathLine\n"); |
|
214 print("DLL name: $currentDllNameLine\n"); |
|
215 print("DLL build mode: $currentBuildModeLine\n"); |
|
216 print("DLL extra commands: $currentExtraCommandsLine\n"); |
|
217 |
|
218 chdir($projectrootname); |
|
219 chdir($currentPathLine); |
|
220 |
|
221 $temp = cwd; |
|
222 print("current directory is $temp\n"); |
|
223 |
|
224 if ( defined $_[0] ) |
|
225 { |
|
226 # check whether test dll was even built succesfully |
|
227 |
|
228 if ( ! -e "$eunitDstDllLocation$currentDllNameLine" ) |
|
229 { |
|
230 # modify results to contain information about total failure of this particular test dll |
|
231 open(TEMPEUNITLOG, ">> $eunitLog2"); |
|
232 print TEMPEUNITLOG "<dll name=\"Z:\\sys\\bin\\$currentDllNameLine\" size=\"180\">eunittest_ctc.pl generated failure info</dll>\n"; |
|
233 close(TEMPEUNITLOG); |
|
234 } |
|
235 |
|
236 if (!defined $param_noclean) |
|
237 { |
|
238 # do cleaning |
|
239 unlink("$eunitSrcDllLocation$currentDllNameLine"); |
|
240 unlink("$eunitDstDllLocation$currentDllNameLine"); |
|
241 if ($currentBuildModeLine =~ /$eunitTestBuildMode/) |
|
242 { |
|
243 doSystemCall("sbs -c winscw_udeb.test reallyclean "); |
|
244 } |
|
245 else |
|
246 { |
|
247 #doSystemCall("sbs -c winscw_udeb reallyclean "); |
|
248 doSystemCall("sbs REALLYCLEAN "); |
|
249 } |
|
250 } |
|
251 else |
|
252 { |
|
253 print("no_cleanup param defined!\n"); |
|
254 } |
|
255 } |
|
256 else |
|
257 { |
|
258 #delete old test dll |
|
259 unlink("$eunitDstDllLocation$currentDllNameLine"); |
|
260 |
|
261 # clean possibly old coverage build but take in account that directory can contain other |
|
262 # tests also, those are not allowed to be cleaned! |
|
263 # it would be most easy if dlls would match with mmp file name but this is not true everywhere |
|
264 $prevLen = length($previousPathLine); |
|
265 if (($currentPathLine =~ /$previousPathLine/) && ($prevLen > 0)) |
|
266 { |
|
267 print("previous dll was from same path - don't build again!\n"); |
|
268 } |
|
269 else |
|
270 { |
|
271 print("previous dll was not from same path - build all!\n"); |
|
272 |
|
273 if ($currentBuildModeLine =~ /$eunitTestBuildMode/) |
|
274 { |
|
275 doSystemCall("sbs -c winscw_udeb.test reallyclean "); |
|
276 doSystemCall("$ctcCommandPart1 $coverageResultsDir$coverageSymbols $excludedCmd $ctcCommandPart2Test"); |
|
277 } |
|
278 else |
|
279 { |
|
280 doSystemCall("sbs REALLYCLEAN "); |
|
281 doSystemCall("$ctcCommandPart1 $coverageResultsDir$coverageSymbols $excludedCmd $ctcCommandPart2"); |
|
282 } |
|
283 } |
|
284 |
|
285 #copy test dll to correct location |
|
286 print("copying test dll to: $eunitDstDllLocation$currentDllNameLine \n"); |
|
287 copy ("$eunitSrcDllLocation$currentDllNameLine", "$eunitDstDllLocation$currentDllNameLine"); |
|
288 |
|
289 #do additional commands |
|
290 chdir($projectrootname); |
|
291 if ( length($currentExtraCommandsLine) > 0 ) |
|
292 { |
|
293 doSystemCall("$currentExtraCommandsLine"); |
|
294 } |
|
295 } |
|
296 |
|
297 # store current pathline for previous loop increment |
|
298 $previousPathLine = $currentPathLine; |
|
299 } |
|
300 } |
|
301 |
|
302 sub sanitizeResultFile |
|
303 { |
|
304 my $testResultEndTag = "</testreport>"; |
|
305 open(TEMPEUNITLOG, "< $eunitLog2"); |
|
306 @tempEunitResultFileContent = <TEMPEUNITLOG>; |
|
307 my $line; |
|
308 my $outputString = ""; |
|
309 foreach $line (@tempEunitResultFileContent) |
|
310 { |
|
311 if ( $line =~ m/$testResultEndTag/ ) |
|
312 { |
|
313 print("End tag ignored\n"); |
|
314 } |
|
315 else |
|
316 { |
|
317 $outputString .= "$line"; |
|
318 } |
|
319 } |
|
320 $outputString .= "$testResultEndTag\n"; |
|
321 close(TEMPEUNITLOG); |
|
322 open(TEMPEUNITLOG, "> $eunitLog2"); |
|
323 print TEMPEUNITLOG "$outputString"; |
|
324 close(TEMPEUNITLOG); |
|
325 } |
|
326 |
|
327 sub doSystemCall |
|
328 { |
|
329 system("echo Doing system call: $_[0] >> $coverageResultsDir$buildResults"); |
|
330 system("$_[0] >> $coverageResultsDir$buildResults 2>&1"); |
|
331 } |