71
|
1 |
#
|
|
2 |
# Copyright (c) 2007 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 |
|
|
18 |
#------------------------------------------------------------------------------------
|
|
19 |
# Includes
|
|
20 |
#------------------------------------------------------------------------------------
|
|
21 |
#use strict;
|
|
22 |
use warnings;
|
|
23 |
use Cwd; # for cwd
|
|
24 |
use FindBin; # for FindBin:Bin
|
|
25 |
use File::Path; # for mkpath
|
|
26 |
use Date::Calc;
|
|
27 |
|
|
28 |
{ # No globals.
|
|
29 |
# Solve where the script is located.
|
|
30 |
$0=~/^(.+[\\\/])[^\\\/]+[\\\/]*$/;
|
|
31 |
my $cgidir= $1 || "./";
|
|
32 |
|
|
33 |
# And try to solve relative path.
|
|
34 |
if( index( $cgidir, "..\\" ) != -1 )
|
|
35 |
{
|
|
36 |
my $p = cwd;
|
|
37 |
$p =~ s/\//\\/g;
|
|
38 |
$cgidir =~ s/\//\\/g;
|
|
39 |
while(1)
|
|
40 |
{
|
|
41 |
my $pos = index( $cgidir, "..\\" );
|
|
42 |
last if( $pos == -1 );
|
|
43 |
$cgidir = substr( $cgidir, $pos+3 );
|
|
44 |
|
|
45 |
$pos = rindex( $p, "\\" );
|
|
46 |
last if( $pos == -1 );
|
|
47 |
$p = substr( $p, 0, $pos);
|
|
48 |
}
|
|
49 |
$cgidir = $p . "\\" . $cgidir;
|
|
50 |
}
|
|
51 |
|
|
52 |
if ( ! -e( $cgidir . "rerunsubs.pl" ) )
|
|
53 |
{
|
|
54 |
$cgidir = cwd;
|
|
55 |
my $domain = "VideoApp_Domain";
|
|
56 |
my $pos = index( $cgidir, $domain );
|
|
57 |
if( $pos != -1 )
|
|
58 |
{
|
|
59 |
$cgidir = substr( $cgidir, 0, $pos + length( $domain ) ) . "\\videoplayer\\tsrc\\testing\\tools\\";
|
|
60 |
|
|
61 |
}
|
|
62 |
}
|
|
63 |
require( $cgidir . "utils.pl" );
|
|
64 |
}
|
|
65 |
|
|
66 |
#------------------------------------------------------------------------------------
|
|
67 |
# GLOBAL CODE
|
|
68 |
#------------------------------------------------------------------------------------
|
|
69 |
|
|
70 |
my @paramClasses;
|
|
71 |
|
|
72 |
while(scalar(@ARGV) <= 0)
|
|
73 |
{
|
|
74 |
Help();
|
|
75 |
exit;
|
|
76 |
}
|
|
77 |
|
|
78 |
while(scalar(@ARGV) >= 1)
|
|
79 |
{
|
|
80 |
my $argument = shift(@ARGV);
|
|
81 |
|
|
82 |
if($argument eq "-c")
|
|
83 |
{
|
|
84 |
my $class = shift(@ARGV);
|
|
85 |
push @paramClasses, $class;
|
|
86 |
}
|
|
87 |
elsif($argument eq "-h")
|
|
88 |
{
|
|
89 |
Help();
|
|
90 |
exit;
|
|
91 |
}
|
|
92 |
else {
|
|
93 |
Help();
|
|
94 |
exit;
|
|
95 |
}
|
|
96 |
}
|
|
97 |
|
|
98 |
sub Help
|
|
99 |
{
|
|
100 |
print <<USAGE_EOF;
|
|
101 |
|
|
102 |
Creates new STIF CFG files depending if they have the specified class(es) defined. Add line:
|
|
103 |
# CaseClass: <classname>
|
|
104 |
before the case to define the class.
|
|
105 |
|
|
106 |
Usage: genCfgs.pl -c <classname> (-c classname2)
|
|
107 |
|
|
108 |
USAGE_EOF
|
|
109 |
|
|
110 |
exit;
|
|
111 |
}
|
|
112 |
|
|
113 |
ClassifyCfgs( \@paramClasses );
|
|
114 |
|
|
115 |
exit;
|
|
116 |
|
|
117 |
sub ClassifyCfgs
|
|
118 |
{
|
|
119 |
my ( $refClasses ) = @_;
|
|
120 |
|
|
121 |
system("rmdir /s /q conf_temp");
|
|
122 |
mkdir("conf_temp");
|
|
123 |
|
|
124 |
my @cfgFiles;
|
|
125 |
FindFiles( ".", ".cfg", 0, \@cfgFiles );
|
|
126 |
|
|
127 |
my @testframeworkInis;
|
|
128 |
FindFiles( ".", "testframework.ini", 0, \@testframeworkInis );
|
|
129 |
if( scalar( @testframeworkInis ) < 1 )
|
|
130 |
{
|
|
131 |
die("\nThere must be at least one testframework.ini somewhere in the subpath!\n");
|
|
132 |
}
|
|
133 |
print("Using testframework.ini from: " . $testframeworkInis[0] . "\n");
|
|
134 |
|
|
135 |
my @pkgFiles;
|
|
136 |
|
|
137 |
foreach my $file ( @cfgFiles )
|
|
138 |
{
|
|
139 |
my $dst = ".\\conf_temp\\" . GetPathFileName( $file );
|
|
140 |
if( ClassifyCfg( $refClasses, $file, $dst ) )
|
|
141 |
{
|
|
142 |
push @pkgFiles, GetPathFileName( $file );
|
|
143 |
AddCfgToIni( $testframeworkInis[0], ".\\conf_temp\\Testframework.ini", GetPathFileName( $file ) );
|
|
144 |
print("Added: " . GetPathFileName($file) . "\n");
|
|
145 |
}
|
|
146 |
}
|
|
147 |
|
|
148 |
if( scalar(@pkgFiles) > 0 )
|
|
149 |
{
|
|
150 |
MakeSISX( \@pkgFiles );
|
|
151 |
}
|
|
152 |
else
|
|
153 |
{
|
|
154 |
system("rmdir /s /q conf_temp"); # remove empty dir
|
|
155 |
}
|
|
156 |
}
|
|
157 |
|
|
158 |
sub ClassifyCfg
|
|
159 |
{
|
|
160 |
my ( $refClasses, $sourceFile, $destFile ) = @_;
|
|
161 |
|
|
162 |
# Read the cfg.
|
|
163 |
open(FILE_HANDLE, $sourceFile) or die ("ERROR! Could not open file $sourceFile\n");
|
|
164 |
my @cfgLines = <FILE_HANDLE>;
|
|
165 |
close(FILE_HANDLE);
|
|
166 |
|
|
167 |
my @cfgCases;
|
|
168 |
ReadCfgCasesWithClass( \@cfgLines, \@cfgCases, $refClasses );
|
|
169 |
|
|
170 |
if( !@cfgCases or scalar(@cfgCases) < 1 )
|
|
171 |
{
|
|
172 |
return 0;
|
|
173 |
}
|
|
174 |
|
|
175 |
# Write the helium CFG.
|
|
176 |
open(FILE_HANDLE, ">$destFile") or die("Could not write into file $destFile\n");
|
|
177 |
|
|
178 |
# Write everything from CFG before the first case.
|
|
179 |
foreach my $line ( @cfgLines )
|
|
180 |
{
|
|
181 |
if( $line =~ m/\[Test\]/ )
|
|
182 |
{
|
|
183 |
last;
|
|
184 |
}
|
|
185 |
print FILE_HANDLE ( $line );
|
|
186 |
}
|
|
187 |
|
|
188 |
foreach my $refCase ( @cfgCases )
|
|
189 |
{
|
|
190 |
my $refCaseLines = @$refCase[1];
|
|
191 |
print FILE_HANDLE ( @$refCaseLines );
|
|
192 |
print FILE_HANDLE ( "\n" );
|
|
193 |
}
|
|
194 |
|
|
195 |
close( FILE_HANDLE );
|
|
196 |
|
|
197 |
return 1;
|
|
198 |
}
|
|
199 |
|
|
200 |
sub ReadCfgCasesWithClass
|
|
201 |
{
|
|
202 |
my ( $refLines, $refCases, $refClasses ) = @_;
|
|
203 |
|
|
204 |
my $inCase = 0;
|
|
205 |
my @caseLines;
|
|
206 |
my $caseTitle;
|
|
207 |
my @caseClasses = "";
|
|
208 |
|
|
209 |
my $cfgHasClassCases = 0;
|
|
210 |
|
|
211 |
for( my $i = 0; $i < scalar(@$refLines); $i++ )
|
|
212 |
{
|
|
213 |
my $line = @$refLines[$i];
|
|
214 |
|
|
215 |
# Case has class.
|
|
216 |
if( $line =~ m/#[ ]+CaseClass:/ )
|
|
217 |
{
|
|
218 |
my $pos = index( $line, "CaseClass: " );
|
|
219 |
if( $pos == -1 )
|
|
220 |
{
|
|
221 |
$i++;
|
|
222 |
die("Invalid CaseClass at line $i. Must be specified exactly as '# CaseClass: clas1(,class2,class3..)'.\n");
|
|
223 |
}
|
|
224 |
my $classes = substr( $line, $pos + 11 );
|
|
225 |
RemoveWhiteSpaces(\$classes);
|
|
226 |
@caseClasses = split(/,/, $classes);
|
|
227 |
}
|
|
228 |
|
|
229 |
# Case starts here.
|
|
230 |
if( $line =~ m/\[Test\]/ )
|
|
231 |
{
|
|
232 |
undef( @caseLines );
|
|
233 |
$caseTitle = "";
|
|
234 |
$inCase = 1;
|
|
235 |
}
|
|
236 |
|
|
237 |
# Found title for the case.
|
|
238 |
if( $line =~ m/^title / )
|
|
239 |
{
|
|
240 |
$caseTitle = $line;
|
|
241 |
}
|
|
242 |
|
|
243 |
# Save case lines.
|
|
244 |
if( $inCase )
|
|
245 |
{
|
|
246 |
push @caseLines, ( $line );
|
|
247 |
}
|
|
248 |
|
|
249 |
# End of test case.
|
|
250 |
if( $line =~ m/\[Endtest\]/ )
|
|
251 |
{
|
|
252 |
$inCase = 0;
|
|
253 |
|
|
254 |
my $saveCase = 0;
|
|
255 |
|
|
256 |
foreach my $class ( @$refClasses )
|
|
257 |
{
|
|
258 |
foreach my $caseClass (@caseClasses)
|
|
259 |
{
|
|
260 |
if( $caseClass eq $class )
|
|
261 |
{
|
|
262 |
$saveCase = 1;
|
|
263 |
$cfgHasClassCases = 1;
|
|
264 |
#print("Class case: $caseTitle\n");
|
|
265 |
}
|
|
266 |
}
|
|
267 |
}
|
|
268 |
|
|
269 |
if( $caseTitle =~ m/Setup/i or $caseTitle =~ m/not a test/i or $caseTitle =~ m/set up/i
|
|
270 |
or $caseTitle =~m/not test/i or $caseTitle =~m/cleanup/i )
|
|
271 |
{
|
|
272 |
$saveCase = 1;
|
|
273 |
#print("Setup case: $caseTitle\n");
|
|
274 |
}
|
|
275 |
|
|
276 |
if( $saveCase )
|
|
277 |
{
|
|
278 |
# Yes, save it.
|
|
279 |
my @case;
|
|
280 |
$case[0] = $caseTitle;
|
|
281 |
$case[1] = [ @caseLines ];
|
|
282 |
push @$refCases, [ @case ];
|
|
283 |
|
|
284 |
}
|
|
285 |
undef( @caseClasses );
|
|
286 |
}
|
|
287 |
}
|
|
288 |
|
|
289 |
if( !$cfgHasClassCases )
|
|
290 |
{
|
|
291 |
undef( @$refCases );
|
|
292 |
}
|
|
293 |
}
|
|
294 |
|
|
295 |
sub FindFiles
|
|
296 |
{
|
|
297 |
my ($godir, $fileSearch, $searchType, $refIncfiles) = @_;
|
|
298 |
|
|
299 |
my $startDir = cwd;
|
|
300 |
|
|
301 |
chdir($godir);
|
|
302 |
|
|
303 |
opendir(DIR, ".");
|
|
304 |
my @filelist = sort(readdir(DIR));
|
|
305 |
closedir(DIR);
|
|
306 |
|
|
307 |
foreach my $file(@filelist)
|
|
308 |
{
|
|
309 |
if($file eq "." or $file eq "..") {next};
|
|
310 |
|
|
311 |
if (-d $file)
|
|
312 |
{
|
|
313 |
FindFiles( $file, $fileSearch, $searchType, $refIncfiles);
|
|
314 |
} else
|
|
315 |
{
|
|
316 |
if( ($file =~ m/$fileSearch/i and $searchType == 0 ) or ($file =~ m/$fileSearch$/i and $searchType == 1 ) )
|
|
317 |
{
|
|
318 |
$file = cwd . "/" . $file;
|
|
319 |
push @$refIncfiles, $file;
|
|
320 |
}
|
|
321 |
}
|
|
322 |
}
|
|
323 |
|
|
324 |
chdir ($startDir);
|
|
325 |
}
|
|
326 |
|
|
327 |
sub MakeSISX
|
|
328 |
{
|
|
329 |
my ($refFiles) = @_;
|
|
330 |
|
|
331 |
# Continue creating pkg.
|
|
332 |
|
|
333 |
my $startDir = cwd;
|
|
334 |
|
|
335 |
chdir( "conf_temp" );
|
|
336 |
|
|
337 |
my $pkgname = "cfgs.pkg";
|
|
338 |
my $sisname = "cfgs.sis";
|
|
339 |
my $sisnamex = "cfgs.sisx";
|
|
340 |
|
|
341 |
print("Writing pkg $pkgname\n");
|
|
342 |
if( !open(FILE_HANDLE, ">$pkgname") )
|
|
343 |
{
|
|
344 |
print("ERROR: could not write to file: $pkgname\n");
|
|
345 |
return 0;
|
|
346 |
}
|
|
347 |
|
|
348 |
my $lineFeed = "\n";
|
|
349 |
|
|
350 |
print FILE_HANDLE (
|
|
351 |
"&EN" . $lineFeed .
|
|
352 |
"#{\"CFGS\"},(0x10102ae9),0,1,0,TYPE=PU" . $lineFeed .
|
|
353 |
"%{\"Nokia EN\"}" . $lineFeed .
|
|
354 |
":\"Nokia\"" . $lineFeed
|
|
355 |
);
|
|
356 |
|
|
357 |
foreach my $file (@$refFiles)
|
|
358 |
{
|
|
359 |
print FILE_HANDLE ("\"..\\conf_temp\\$file\" - \"c:\\TestFramework\\$file\"" . $lineFeed );
|
|
360 |
}
|
|
361 |
|
|
362 |
my $file = "Testframework.ini";
|
|
363 |
print FILE_HANDLE (";\"..\\conf_temp\\$file\" - \"c:\\TestFramework\\$file\"" . $lineFeed );
|
|
364 |
|
|
365 |
close(FILE_HANDLE);
|
|
366 |
|
|
367 |
# Check that we have signing keys.
|
|
368 |
|
|
369 |
my $derFile = "RDTest_02.der";
|
|
370 |
my $keyFile = "RDTest_02.key";
|
|
371 |
|
|
372 |
if (-e $derFile and -e $keyFile)
|
|
373 |
{
|
|
374 |
# Keys are in current dir
|
|
375 |
}
|
|
376 |
elsif(-e "sis\\$derFile" and -e "sis\\$keyFile")
|
|
377 |
{
|
|
378 |
# Keys are in internal/sis dir
|
|
379 |
$derFile = "sis\\$derFile";
|
|
380 |
$keyFile = "sis\\$keyFile";
|
|
381 |
}
|
|
382 |
elsif(-e "group\\$derFile" and -e "group\\$keyFile")
|
|
383 |
{
|
|
384 |
# Keys are in internal/group dir
|
|
385 |
$derFile = "group\\$derFile";
|
|
386 |
$keyFile = "group\\$keyFile";
|
|
387 |
}
|
|
388 |
else
|
|
389 |
{
|
|
390 |
# Find em.
|
|
391 |
my @derFiles;
|
|
392 |
my @keyFiles;
|
|
393 |
FindFiles( ".", "$derFile", 0, \@derFiles );
|
|
394 |
FindFiles( ".", "$keyFile", 0, \@keyFiles );
|
|
395 |
$derFile = $derFiles[0] if( scalar(@derFiles) > 0 );
|
|
396 |
$keyFile = $keyFiles[0] if( scalar(@keyFiles) > 0 );
|
|
397 |
}
|
|
398 |
|
|
399 |
if (!-e $derFile or !-e $keyFile)
|
|
400 |
{
|
|
401 |
print("\nNeed signing keys: $derFile and $keyFile in current or subdirs.\n");
|
|
402 |
return;
|
|
403 |
}
|
|
404 |
|
|
405 |
my $cmd = "makesis $pkgname $sisname";
|
|
406 |
print("$cmd\n");
|
|
407 |
system $cmd;
|
|
408 |
|
|
409 |
$cmd = "signsis $sisname $sisnamex $derFile $keyFile";
|
|
410 |
print("$cmd\n");
|
|
411 |
system $cmd;
|
|
412 |
|
|
413 |
#system("del $pkgname");
|
|
414 |
system("del $sisname");
|
|
415 |
|
|
416 |
chdir( $startDir );
|
|
417 |
}
|
|
418 |
|
|
419 |
|
|
420 |
sub AddCfgToIni
|
|
421 |
{
|
|
422 |
my ($sourceFile, $destIniFile, $cfgFile) = @_;
|
|
423 |
|
|
424 |
# Rerun ini does not exist. Create one.
|
|
425 |
if( ! (-e $destIniFile) )
|
|
426 |
{
|
|
427 |
if( !open(FILE_HANDLE, $sourceFile) )
|
|
428 |
{
|
|
429 |
print("ERROR! Could not open file '" . $sourceFile . "'\n");
|
|
430 |
return 0;
|
|
431 |
}
|
|
432 |
my @array = <FILE_HANDLE>;
|
|
433 |
close(FILE_HANDLE);
|
|
434 |
|
|
435 |
if( !open(FILE_HANDLE, ">$destIniFile") )
|
|
436 |
{
|
|
437 |
print("ERROR! Could not open file '" . $destIniFile . "'\n");
|
|
438 |
return 0;
|
|
439 |
}
|
|
440 |
|
|
441 |
my $inNew_Module = 0;
|
|
442 |
|
|
443 |
foreach $line ( @array )
|
|
444 |
{
|
|
445 |
if($line =~ m/\[New_Module\]/)
|
|
446 |
{
|
|
447 |
$inNew_Module = 1;
|
|
448 |
print FILE_HANDLE ($line);
|
|
449 |
print FILE_HANDLE ("ModuleName= TestScripter\n");
|
|
450 |
}
|
|
451 |
if($line =~ m/\[End_Module\]/)
|
|
452 |
{
|
|
453 |
$inNew_Module = 0;
|
|
454 |
}
|
|
455 |
|
|
456 |
if($inNew_Module)
|
|
457 |
{
|
|
458 |
# Copy only setup cfgs if they are found.
|
|
459 |
if($line =~ m/setvalidservices/i)
|
|
460 |
{
|
|
461 |
print FILE_HANDLE ($line);
|
|
462 |
}
|
|
463 |
if($line =~ m/testprovisioning/i)
|
|
464 |
{
|
|
465 |
print FILE_HANDLE ($line);
|
|
466 |
}
|
|
467 |
}
|
|
468 |
else
|
|
469 |
{
|
|
470 |
print FILE_HANDLE ($line);
|
|
471 |
}
|
|
472 |
}
|
|
473 |
|
|
474 |
close(FILE_HANDLE);
|
|
475 |
}
|
|
476 |
|
|
477 |
# Read the existing file.
|
|
478 |
|
|
479 |
if( !open(FILE_HANDLE, $destIniFile) )
|
|
480 |
{
|
|
481 |
print("ERROR! Could not open file '" . $destIniFile . "'\n");
|
|
482 |
return 0;
|
|
483 |
}
|
|
484 |
my @array = <FILE_HANDLE>;
|
|
485 |
close(FILE_HANDLE);
|
|
486 |
|
|
487 |
# Check if CFG is already there.
|
|
488 |
|
|
489 |
my $inNew_Module = 0;
|
|
490 |
|
|
491 |
foreach $line ( @array )
|
|
492 |
{
|
|
493 |
if($line =~ m/\[New_Module\]/)
|
|
494 |
{
|
|
495 |
$inNew_Module = 1;
|
|
496 |
}
|
|
497 |
if($line =~ m/\[End_Module\]/)
|
|
498 |
{
|
|
499 |
$inNew_Module = 0;
|
|
500 |
}
|
|
501 |
|
|
502 |
if($inNew_Module)
|
|
503 |
{
|
|
504 |
if($line =~ m/$cfgFile/i)
|
|
505 |
{
|
|
506 |
return 1;
|
|
507 |
}
|
|
508 |
}
|
|
509 |
}
|
|
510 |
|
|
511 |
# Add the cfg to it.
|
|
512 |
|
|
513 |
if( !open(FILE_HANDLE, ">$destIniFile") )
|
|
514 |
{
|
|
515 |
print("ERROR! Could not open file '" . $destIniFile . "'\n");
|
|
516 |
return 0;
|
|
517 |
}
|
|
518 |
|
|
519 |
$inNew_Module = 0;
|
|
520 |
|
|
521 |
foreach $line ( @array )
|
|
522 |
{
|
|
523 |
if($line =~ m/\[End_Module\]/)
|
|
524 |
{
|
|
525 |
$inNew_Module = 0;
|
|
526 |
print FILE_HANDLE ("TestCaseFile= c:\\TestFramework\\$cfgFile\n");
|
|
527 |
}
|
|
528 |
print FILE_HANDLE ($line);
|
|
529 |
}
|
|
530 |
|
|
531 |
close(FILE_HANDLE);
|
|
532 |
|
|
533 |
return 1;
|
|
534 |
} |