|
1 # |
|
2 # Copyright (c) 2007-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 the License "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 # Perl script that test Dumpchainvaliditytoool with different ranges |
|
16 # |
|
17 |
|
18 use File::Basename; |
|
19 my $scriptdir= dirname $0; |
|
20 print "Changing dir to $scriptdir\n"; |
|
21 chdir $scriptdir; |
|
22 |
|
23 |
|
24 $logFile = "\\epoc32\\winscw\\c\\dumpchainvalidity_test.txt"; |
|
25 use File::Copy; |
|
26 use Cwd; |
|
27 use File::Find ; |
|
28 |
|
29 # |
|
30 #Function to write log into file |
|
31 # |
|
32 sub WriteLog |
|
33 { |
|
34 my ($log) = @_; |
|
35 unless( open($fh, ">> $logFile")) |
|
36 { |
|
37 printf STDERR "Can\'t open $logfile:$!\n"; |
|
38 return; |
|
39 } |
|
40 printf $fh $log; |
|
41 printf $log; |
|
42 close $fh; |
|
43 } |
|
44 |
|
45 sub chainvalidity |
|
46 { |
|
47 my ($pkgfile) = @_[0]; |
|
48 my ($expectedResult) = @_[1]; |
|
49 my ($outputLog) = @_[2]; |
|
50 $outputLog =~ s/\.log//; |
|
51 $neededfolder=""; |
|
52 $neededfile=""; |
|
53 @retval = system("DumpChainValidityTool.exe $pkgfile> $outputLog.log"); |
|
54 $logMsg = sprintf "Expected code:%5d result Code:%5d\n", $expectedResult, $?; |
|
55 WriteLog( $logMsg); |
|
56 $NumberOfTests++; |
|
57 if( $? == $expectedResult) |
|
58 { |
|
59 sleep(2); |
|
60 my $res=`diff "$outputLog.out" "$outputLog.log"`; |
|
61 if(length($res) == 0) |
|
62 { |
|
63 $NumberOfPassed++; |
|
64 WriteLog("Passed\n\n"); |
|
65 } |
|
66 else |
|
67 { |
|
68 $NumberOfFailed++; |
|
69 WriteLog("Failed: Files $outputLog.out and $outputLog.log are not matched\n\n"); |
|
70 WriteLog("Failed\n\n"); |
|
71 } |
|
72 } |
|
73 else |
|
74 { |
|
75 $NumberOfFailed++; |
|
76 WriteLog("Failed\n\n"); |
|
77 } |
|
78 unlink("$outputLog.log"); |
|
79 |
|
80 } |
|
81 |
|
82 |
|
83 unlink($logFile); |
|
84 WriteLog("DumpChainValidityTool test.\n\n"); |
|
85 |
|
86 # |
|
87 # Counters for results |
|
88 # |
|
89 $NumberOfTests = 0; |
|
90 $NUmberOfPassed = 0; |
|
91 $NumberOfFailed = 0; |
|
92 |
|
93 # |
|
94 # Array of contents of tests and expected results |
|
95 # |
|
96 # file name, expected , expected log, Title |
|
97 # result message |
|
98 # ---------------------------------------------------------------------------------------------------- |
|
99 @TestItems = ( ["data\\onechain.sis data\\swicertstore.dat" ,0, , "Created", "Test for chainvalidity with one valid chain", "chainvalidity-output\\onechain.log"], |
|
100 ["data\\somevalidchain.sis data\\swicertstore.dat" ,0, , "Created", "Test for chainvalidity with some valid chains", "chainvalidity-output\\somevalidchain.log"], |
|
101 ["data\\multichain_allValid.sis data\\swicertstore.dat" ,0, , "Created", "Test for chainvalidity with all chains valid", "chainvalidity-output\\allvalidchain.log"], |
|
102 ["data\\selfsigned.SIS data\\swicertstore.dat" ,0, , "Created", "Test for SIS file signed with a selfsigned certificate", "chainvalidity-output\\selfsigned.log"], |
|
103 ["data\\simple_devsimplesigned.SIS data\\swicertstore.dat" ,0, , "Created", "Test for SIS file signed with a developer certificate", "chainvalidity-output\\devcert2.log"], |
|
104 ["data\\unsigned.sis data\\swicertstore.dat" ,0, , "Created", "Test for chainvalidity with sis file having no chain", "chainvalidity-output\\unsigned.log"], |
|
105 ["data\\multichain_allValid.sis data\\AllMandatory.dat" ,0, , "Created", "Test for chainvalidity with sis files not signed by all the mandatory certificates present in certstore", "chainvalidity-output\\missing_mandatory.log"], |
|
106 ["data\\multichain_allValid.sis data\\Mandatory.dat" ,0, , "Created", "Test for chainvalidity with sis files not signed by all the mandatory certificates present in certstore", "chainvalidity-output\\mandatory.log"], |
|
107 ["data\\multichain_allValid.sis data\\corrupted.dat" ,1792, , "File format error", "Test for chainvalidity with corrupted certstore", "chainvalidity-output\\corrupteddat.log"], |
|
108 ["data\\corrupted.sis data\\swicertstore.dat" ,1536, , "File format error", "Test for chainvalidity with corrupted sis file", "chainvalidity-output\\corruptedsis.log"], |
|
109 ); |
|
110 |
|
111 |
|
112 |
|
113 |
|
114 # |
|
115 # Do test for each elements of TestItems array |
|
116 # |
|
117 for my $Test ( @TestItems ) |
|
118 { |
|
119 $testid = sprintf "SEC-SWI-I-CHAINVAL-00%d\n",$NumberOfTests+1; |
|
120 WriteLog($testid); |
|
121 $logMsg = sprintf "%s\n", $Test->[3]; |
|
122 WriteLog($logMsg); |
|
123 chainvalidity($Test->[0], $Test->[1],$Test->[4]); |
|
124 } |
|
125 |
|
126 opendir(DIR, ".\\Chain"); |
|
127 while (defined($files=readdir(DIR))) |
|
128 { |
|
129 $dirname="chain\\"; |
|
130 $files =~ s/\.pem//; |
|
131 $dirname.= $files; |
|
132 if(-e "$dirname.pem") |
|
133 { |
|
134 unlink("$dirname.pem"); |
|
135 } |
|
136 close(DIR); |
|
137 } |
|
138 |
|
139 $dirpath = "Chain"; |
|
140 rmdir($dirpath); |
|
141 |
|
142 # |
|
143 # Display the result |
|
144 # |
|
145 WriteLog("\n\nTests completed OK\n"); |
|
146 WriteLog(sprintf "Run: %d\n", $NumberOfTests ); |
|
147 WriteLog(sprintf "Passed: %d\n", $NumberOfPassed ); |
|
148 WriteLog(sprintf "%d tests failed out of %d\n", $NumberOfFailed, $NumberOfTests ); |
|
149 |