|
1 # Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 # All rights reserved. |
|
3 # This component and the accompanying materials are made available |
|
4 # under the terms of the License "Symbian Foundation License v1.0" |
|
5 # which accompanies this distribution, and is available |
|
6 # at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html". |
|
7 # |
|
8 # Initial Contributors: |
|
9 # Nokia Corporation - initial contribution. |
|
10 # |
|
11 # Contributors: |
|
12 # |
|
13 # Description: |
|
14 # The SmokeTestSuite package contains subroutines that are needed to build a |
|
15 # testdriver test suite. |
|
16 # This script was born on 18/04/2005 |
|
17 # |
|
18 # |
|
19 |
|
20 #!/usr/bin/perl -w |
|
21 package SmokeTestSuite; |
|
22 use strict; |
|
23 |
|
24 my $servicename; |
|
25 |
|
26 # |
|
27 # BuildAndPackage: Used to create a test package for remote execution on the ROM |
|
28 # |
|
29 sub BuildAndPackage |
|
30 { |
|
31 # |
|
32 # Build Test Package for $_[0] |
|
33 # |
|
34 print "\n#\n# Build Test Package for $_[0]\n#\n"; |
|
35 SmokeTest::PrintDateTime(); |
|
36 my $testbuild = SmokeTest::ExecCommand ("$SmokeTest::TestDriverCmd build -p $_[0] -b udeb -s $SmokeTest::TestSuite"); |
|
37 |
|
38 # now check for results |
|
39 $testbuild =~ m/fail\:\s(\d+)\s\%/i; |
|
40 |
|
41 if ( ($testbuild =~ m/\*\*error\:/i) || $1 == 100 ) |
|
42 { |
|
43 print "\nREMARK: Smoke Test *** Building the Test failed $!\n"; |
|
44 #&SmokeTest::DieLog("Error In Smoke Test: Building the Test failed"); |
|
45 } |
|
46 else |
|
47 { |
|
48 print "\n*** Test Building successful ***\n"; |
|
49 } |
|
50 |
|
51 SmokeTest::PrintDateTime(); |
|
52 |
|
53 my $testpackage = SmokeTest::ExecCommand ("$SmokeTest::TestDriverCmd package -p $_[0] -b udeb -s $SmokeTest::TestSuite --tp $SmokeTest::SmokeTestDir\\$_[0].tpkg"); |
|
54 print "\n"; |
|
55 |
|
56 if (($testpackage =~ m/\*\*error/i)) |
|
57 { |
|
58 print "\nREMARK: Smoke Test *** Building the Test Package failed\n\"$1\"\n"; |
|
59 #&SmokeTest::DieLog("Error In Smoke Test: Building the Test Package failed"); |
|
60 } |
|
61 else |
|
62 { |
|
63 print "\n*** Building the Test Package successful ***\n"; |
|
64 } |
|
65 |
|
66 SmokeTest::PrintDateTime(); |
|
67 } |
|
68 |
|
69 # |
|
70 # BuildAndPublish: used to build and test the smoketest test suite on an Emulator |
|
71 # |
|
72 sub BuildAndPublish |
|
73 { |
|
74 my $runid = 0; |
|
75 my $buildname; |
|
76 |
|
77 # |
|
78 # Build Test Suite for $_[0] |
|
79 # |
|
80 print "\n#\n# Build Test Suite for $_[0]\n#\n"; |
|
81 SmokeTest::PrintDateTime(); |
|
82 my $testbuildwinscw = SmokeTest::ExecCommand ("$SmokeTest::TestDriverCmd build -p $_[0] -b udeb -s $SmokeTest::TestSuite"); |
|
83 |
|
84 # now check for results |
|
85 $testbuildwinscw =~ m/fail\:\s(\d+)\s\%/i; |
|
86 |
|
87 if ( ($testbuildwinscw =~ m/\*\*error\:/i) || $1 == 100 ) |
|
88 { |
|
89 print "\nREMARK: Smoke Test *** Building the Test for $_[0] failed $!\n"; |
|
90 #&SmokeTest::DieLog("Error In Smoke Test: Building the Test failed"); |
|
91 } |
|
92 else |
|
93 { |
|
94 print "\n*** Test Build successful ***\n"; |
|
95 } |
|
96 |
|
97 # |
|
98 # Run Test Suite for $_[0] |
|
99 # |
|
100 print "\n"; |
|
101 print "#\n# Run Test Package for $_[0]\n#\n"; |
|
102 print "\n"; |
|
103 SmokeTest::PrintDateTime(); |
|
104 |
|
105 SmokeTest::ExecCommand ("$SmokeTest::TestDriverCmd run -p $_[0] -b udeb -s $SmokeTest::TestSuite"); |
|
106 |
|
107 SmokeTest::PrintDateTime(); |
|
108 |
|
109 # |
|
110 # Publish results of emulator onto publish server |
|
111 # |
|
112 print "\n"; |
|
113 print "#\n# Publish results of emulator onto publish server\n#\n"; |
|
114 print "\n"; |
|
115 |
|
116 # |
|
117 # Find the correct directory to publish |
|
118 # |
|
119 my $source = "$SmokeTest::TestDriverDrive\\TestDriver\\Results"; |
|
120 if (opendir Results, $source) |
|
121 { |
|
122 my @dirArray = readdir(Results); |
|
123 |
|
124 #print "@results"; |
|
125 # to remove "." and ".." from this list |
|
126 shift @dirArray; |
|
127 shift @dirArray; |
|
128 |
|
129 if (!scalar(@dirArray)) |
|
130 { |
|
131 print "REMARK: The emulator for $_[0] has an empty $source directory"; |
|
132 return; |
|
133 } |
|
134 else |
|
135 { |
|
136 print "\nContents of $source = @dirArray\n"; |
|
137 $source .= "\\$dirArray[0]"; |
|
138 # dirArray should always have just the one subdir - 0XXXX_Symbian_OS_vX.X |
|
139 |
|
140 $buildname = $dirArray[0]; |
|
141 |
|
142 if (opendir tempDir, "$source") |
|
143 { |
|
144 # to remove "." and ".." from this list |
|
145 @dirArray = readdir(tempDir); |
|
146 shift @dirArray; |
|
147 shift @dirArray; |
|
148 |
|
149 print "\nContents of $source = @dirArray\n"; |
|
150 |
|
151 foreach my $directory (@dirArray) |
|
152 { |
|
153 if ($directory =~ /(?:$_[0])/i) |
|
154 { |
|
155 $source .= "\\$directory"; |
|
156 |
|
157 # added this to remove udeb/xx |
|
158 if (opendir tempDir, "$source") |
|
159 { |
|
160 # to remove "." and ".." from this list |
|
161 @dirArray = readdir(tempDir); |
|
162 shift @dirArray; |
|
163 shift @dirArray; |
|
164 |
|
165 print "\nContents of $source = @dirArray\n"; |
|
166 |
|
167 foreach my $directory (@dirArray) |
|
168 { |
|
169 if ($directory =~ /(udeb|urel)/i) |
|
170 { |
|
171 $source .= "\\$directory"; |
|
172 if (opendir tempDir, "$source") |
|
173 { |
|
174 # to remove "." and ".." from this list |
|
175 @dirArray = readdir(tempDir); |
|
176 shift @dirArray; |
|
177 shift @dirArray; |
|
178 |
|
179 print "\nContents of $source = @dirArray\n"; |
|
180 |
|
181 my @iNumericDirList = (); |
|
182 foreach my $directory (@dirArray) |
|
183 { |
|
184 if ($directory =~ /(^[0-9]+)/i) |
|
185 { |
|
186 push @iNumericDirList, $directory; |
|
187 } |
|
188 } |
|
189 @iNumericDirList = sort { $b <=> $a } @iNumericDirList; |
|
190 $runid = $iNumericDirList[0]; |
|
191 $source .= "\\$runid"; |
|
192 last; |
|
193 } |
|
194 last; |
|
195 } |
|
196 } |
|
197 } |
|
198 |
|
199 } |
|
200 } |
|
201 |
|
202 print "\nThe final source directory = $source\n"; |
|
203 } |
|
204 else |
|
205 { |
|
206 print "REMARK: The emulator for $_[0] has an empty $source directory"; |
|
207 return; |
|
208 } |
|
209 } |
|
210 my $emulatorpublish = "$SmokeTest::PublishServer\\$SmokeTest::ProductType\\$SmokeTest::BuildNum\\logs\\SmokeTest\\Emulator\\$_[0]"; |
|
211 |
|
212 SmokeTest::ExecCommand ("MKDIR $emulatorpublish"); # or GoNext("$publishlocation\\$name\\"); |
|
213 |
|
214 SmokeTest::ExecCommand ("XCOPY /C /Y /E $source\\xml $emulatorpublish\\xml\\"); |
|
215 |
|
216 # |
|
217 # Copy runXX_<snapshot>_SymbianOS_vYY.xml/html to <snapshot>_Symbian_OS_vYY.xml/html |
|
218 # |
|
219 |
|
220 my $xmlfile = "$source\\run".$runid."_".$buildname."\.xml"; |
|
221 my $htmlfile = "$source\\run".$runid."_".$buildname."\.html"; |
|
222 |
|
223 if (-e $xmlfile) |
|
224 { |
|
225 SmokeTest::ExecCommand ("COPY $xmlfile $emulatorpublish\\$buildname.xml"); |
|
226 } |
|
227 |
|
228 if (-e $htmlfile) |
|
229 { |
|
230 SmokeTest::ExecCommand ("COPY $htmlfile $emulatorpublish\\$buildname.html"); |
|
231 } |
|
232 |
|
233 # |
|
234 # Publish results of emulator onto logs dir |
|
235 # |
|
236 print "\n"; |
|
237 print "#\n# Publish results of emulator onto Logs Dir\n#\n"; |
|
238 print "\n"; |
|
239 |
|
240 my $emulatorpublish = "$SmokeTest::LogsDir\\SmokeTest\\Emulator\\$_[0]\\"; |
|
241 |
|
242 SmokeTest::ExecCommand ("MKDIR $emulatorpublish"); # or GoNext("$publishlocation\\$name\\"); |
|
243 |
|
244 SmokeTest::ExecCommand ("XCOPY /C /Y /E $source $emulatorpublish"); |
|
245 } |
|
246 else |
|
247 { |
|
248 print "REMARK: Cannot open dir $source: $!"; |
|
249 return; |
|
250 } |
|
251 SmokeTest::PrintDateTime(); |
|
252 } |
|
253 |
|
254 # |
|
255 # PollServers: Polls all the servers from the Pool and picks out the one with the shortest queue. |
|
256 # |
|
257 sub PollServers |
|
258 { |
|
259 # |
|
260 # Parse ENV and create an array of smoketest servers for $_[0] |
|
261 # |
|
262 print "\n"; |
|
263 print "#\n# Parse ENV and create an array of smoketest servers for $_[0]\n#\n"; |
|
264 print "\n"; |
|
265 SmokeTest::PrintDateTime(); |
|
266 |
|
267 if (($_[0] eq "Lubbock") || ($_[0] eq "LUBBOCK")) |
|
268 { |
|
269 $SmokeTest::servicename = "RemoteTestDriverLubbock"; |
|
270 } |
|
271 elsif ($_[0] eq "H2") |
|
272 { |
|
273 $SmokeTest::servicename = "RemoteTestDriverH2"; |
|
274 } |
|
275 elsif ($_[0] eq "H4HRP") |
|
276 { |
|
277 $SmokeTest::servicename = "RemoteTestDriverH4HRP"; |
|
278 } |
|
279 else |
|
280 { |
|
281 &SmokeTest::DieLog("Cannot poll serverpool for pool \"$_[0]\""); |
|
282 } |
|
283 |
|
284 my @servers = split /\#/, $SmokeTest::serverpool; |
|
285 if (@servers < 1) |
|
286 { |
|
287 &SmokeTest::DieLog("*** Error In Smoke Test ***\nNo SmokeTest Servers specified for $_[0]$!\n"); |
|
288 } |
|
289 else |
|
290 { |
|
291 print "\n*** Retrieved Pool of Smoke Test Servers from ENV for $_[0]***\n"; |
|
292 } |
|
293 |
|
294 # |
|
295 # Poll each of the smoke test servers and parse the results |
|
296 # |
|
297 print "\n"; |
|
298 print "#\n# Poll each of the smoke test servers and parse the results\n#\n"; |
|
299 print "\n"; |
|
300 |
|
301 my %serverlist; |
|
302 |
|
303 print "Checking TestDriver Version\n"; |
|
304 SmokeTest::ExecCommand ("$SmokeTest::TestDriverCmd version"); |
|
305 |
|
306 foreach my $server (@servers) |
|
307 { |
|
308 print "Polling Server: $server\n"; |
|
309 my $masterstatus = SmokeTest::ExecCommand ("$SmokeTest::TestDriverCmd masterstatus --srv //$server/$SmokeTest::servicename"); |
|
310 |
|
311 my $value = -2; |
|
312 if ($masterstatus =~ m/Master: TestDriver is currently (....)/i) |
|
313 { |
|
314 if ($1 eq 'free') |
|
315 { |
|
316 #print "Free!\n"; |
|
317 $value = 0; |
|
318 } |
|
319 else |
|
320 { |
|
321 $masterstatus =~ m/are\s+(\w+)\s+jobs/i; |
|
322 if ($1 =~ m/\D+/) |
|
323 { |
|
324 $value = 1; |
|
325 } |
|
326 else |
|
327 { |
|
328 $value = $1 + 1; |
|
329 } |
|
330 } |
|
331 } |
|
332 else |
|
333 { |
|
334 # The master is not running a service |
|
335 $value = -1; |
|
336 } |
|
337 $serverlist{$server} = $value; |
|
338 print "\n"; |
|
339 } |
|
340 |
|
341 # |
|
342 # Decide which server to use |
|
343 # |
|
344 print "\n"; |
|
345 print "#\n# STEP8 Decide which server to use\n#\n"; |
|
346 print "\n"; |
|
347 |
|
348 my $masterserver; |
|
349 |
|
350 # Loop through first time only to print out all the available servers |
|
351 print "\nAvailable Servers\n"; |
|
352 foreach my $servername (sort { $serverlist{$a} <=> $serverlist{$b} } keys %serverlist) |
|
353 { |
|
354 print "\n$servername : number in queue are $serverlist{$servername}\n"; |
|
355 } |
|
356 |
|
357 # Loop through second time to actually select the correct server |
|
358 foreach my $servername (sort { $serverlist{$a} <=> $serverlist{$b} } keys %serverlist) |
|
359 { |
|
360 if ($serverlist{$servername} > -1) |
|
361 { |
|
362 $masterserver = $servername; |
|
363 last; |
|
364 } |
|
365 } |
|
366 |
|
367 if (defined $masterserver) |
|
368 { |
|
369 print "\n*** The Smoke Test Server to be used for $_[0] is $masterserver ***\n"; |
|
370 } |
|
371 else |
|
372 { |
|
373 print "\nREMARK: Smoke Test *** No available Smoke Test Servers for $_[0] \n"; |
|
374 #&SmokeTest::DieLog("Error In Smoke Test: No available Smoke Test Servers for $_[0]"); |
|
375 } |
|
376 SmokeTest::PrintDateTime(); |
|
377 return $masterserver; |
|
378 } |
|
379 |
|
380 # |
|
381 # Usage: RunRemote(Architecture, Testing Board, Server) |
|
382 # |
|
383 sub RunRemote |
|
384 { |
|
385 my $masterserver = $_[2]; |
|
386 |
|
387 |
|
388 # |
|
389 # Call TestDriver runremote for $_[0] |
|
390 # |
|
391 print "\n"; |
|
392 print "#\n# Call TestDriver runremote for $_[0]\n#\n"; |
|
393 print "\n"; |
|
394 SmokeTest::PrintDateTime(); |
|
395 |
|
396 my $tempZipLocation = "$SmokeTest::SmokeTestDir\\$_[0]\\$_[1]"; |
|
397 if ($_[3] eq "NAND\\") |
|
398 { |
|
399 $tempZipLocation .= "\\NAND"; |
|
400 } |
|
401 elsif ($_[3] eq "NAND\(DP\)\\") |
|
402 { |
|
403 $tempZipLocation .= "\\NAND\(DP\)"; |
|
404 } |
|
405 |
|
406 SmokeTest::ExecCommand ("COPY /Y $tempZipLocation\\sys\$rom.zip $SmokeTest::SmokeTestDir\\sys\$rom.zip"); |
|
407 |
|
408 # Decide whether this is a platsec ROM or not |
|
409 my $platsec; |
|
410 if ($SmokeTest::buildNo eq "9.1" || $SmokeTest::buildNo eq "9.2" || $SmokeTest::buildNo eq "9.3" || $SmokeTest::buildNo eq "Future" || $SmokeTest::buildNo eq "9.4" || $SmokeTest::buildNo eq "9.5" || $SmokeTest::buildNo eq "9.6" || $SmokeTest::buildNo eq "tb91") |
|
411 { |
|
412 $platsec = "ON"; |
|
413 } |
|
414 else |
|
415 { |
|
416 $platsec = "OFF"; |
|
417 } |
|
418 |
|
419 # calling testdriver for $_[0] |
|
420 my $runremote = SmokeTest::ExecCommand ("$SmokeTest::TestDriverCmd runremote -m async -i $SmokeTest::SmokeTestDir --tp $_[0].tpkg -r sys\$rom.zip --srv //$masterserver/$SmokeTest::servicename --platsec $platsec --testexec ON"); |
|
421 |
|
422 # |
|
423 # Parse output to get the job number or error |
|
424 # |
|
425 print "\n"; |
|
426 print "#\n# Parse output to get the job number or error\n#\n"; |
|
427 print "\n"; |
|
428 |
|
429 my $jobid; |
|
430 |
|
431 if ($runremote =~ m/job id/i) |
|
432 { |
|
433 $runremote =~ m/job id: (\d+)/i; |
|
434 $jobid = $1; |
|
435 print "\n*** Job submitted successfully ***\n\nJob Id = $jobid\n"; |
|
436 } |
|
437 else |
|
438 { |
|
439 print "\nREMARK: Smoke Test Job Submission failed\n"; |
|
440 #&SmokeTest::DieLog("Error In Smoke Test: Submitting the Job failed"); |
|
441 return; |
|
442 } |
|
443 |
|
444 # |
|
445 # Create a text file with publish details |
|
446 # |
|
447 print "\n"; |
|
448 print "#\n# Create a text file with publish details\n#\n"; |
|
449 print "\n"; |
|
450 |
|
451 my $publishstring; |
|
452 |
|
453 $publishstring = "Publish: $SmokeTest::PublishServer\\$SmokeTest::ProductType\\$SmokeTest::BuildNum\\logs\\Smoketest\\$_[0]\\$_[1]\\"; |
|
454 print "$publishstring"; |
|
455 |
|
456 if ( (defined $SmokeTest::PublishServer) && (defined $SmokeTest::ProductType) && (defined $SmokeTest::BuildNum) ) |
|
457 { |
|
458 open PublishFile, ">$_[0]$_[1].txt" or &SmokeTest::DieLog("Cannot open File $_[0]$_[1].txt: $!\n"); |
|
459 $publishstring = "$SmokeTest::PublishServer\\$SmokeTest::ProductType\\$SmokeTest::BuildNum\\logs\\Smoketest\\$_[0]\\$_[1]\\"; |
|
460 if ($_[3] eq "NAND\\") |
|
461 { |
|
462 $publishstring .= "NAND\\"; |
|
463 } |
|
464 elsif ($_[3] eq "NAND\(DP\)\\") |
|
465 { |
|
466 $publishstring .= "NAND\(DP\)\\"; |
|
467 } |
|
468 print PublishFile "$publishstring"; |
|
469 $publishstring = "\n$SmokeTest::PublishServer\\$SmokeTest::ProductType\\logs\\$SmokeTest::BuildNum\\Smoketest\\$_[0]\\$_[1]\\"; |
|
470 if ($_[3] eq "NAND\\") |
|
471 { |
|
472 $publishstring .= "NAND\\"; |
|
473 } |
|
474 elsif ($_[3] eq "NAND\(DP\)\\") |
|
475 { |
|
476 $publishstring .= "NAND\(DP\)\\"; |
|
477 } |
|
478 print PublishFile "$publishstring"; |
|
479 close PublishFile; |
|
480 print "\n*** Publish file created successfully ***\n"; |
|
481 } |
|
482 else |
|
483 { |
|
484 print "\nREMARK: Smoke Test *** Could not Create Publish File\n$!"; |
|
485 #&SmokeTest::DieLog("Error In Smoke Test: Could not Create Publish File"); |
|
486 } |
|
487 |
|
488 # |
|
489 # Copy This publish file to the correct directory |
|
490 # |
|
491 print "\n"; |
|
492 print "#\n# Copy This publish file to the correct directory \n#\n"; |
|
493 print "\n"; |
|
494 |
|
495 ###print "\nabout to move /Y $_[0]$_[1].txt \\\\$masterserver\\Jobs\\$jobid\\publish.txt\n"; |
|
496 SmokeTest::ExecCommand ("MOVE /Y $_[0]$_[1].txt \\\\$masterserver\\Jobs\\$jobid\\publish.txt"); |
|
497 |
|
498 SmokeTest::PrintDateTime(); |
|
499 } |
|
500 |
|
501 1; |