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