|
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 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 # runtests.pl is used to run Interpretsis unit tests. |
|
16 # |
|
17 # |
|
18 |
|
19 use integer; |
|
20 use Cwd; |
|
21 use autouse 'Win32::Process' => qw(Create INFINITE); |
|
22 use File::Copy; |
|
23 |
|
24 $INT_PATH="\\epoc32\\tools\\"; |
|
25 $INT_CMD ="interpretsis.exe"; |
|
26 |
|
27 #$C_DRIVE ="\\epoc32\\winscw\\c"; |
|
28 #$Z_DRIVE ="\\epoc32\\RELEASE\\WINSCW\\UDEB\\Z"; |
|
29 $C_DRIVE ="\\cdrive"; |
|
30 $Z_DRIVE ="\\romdrive"; |
|
31 |
|
32 $SIS_PATH="\\epoc32\\winscw\\c\\tswi\\tinterpretsis\\sis_winscw_udeb\\"; |
|
33 $CONFIG_PATH="\\epoc32\\winscw\\c\\tswi\\tinterpretsis\\"; |
|
34 |
|
35 $PREPARE_SIS="\\epoc32\\winscw\\c\\tswi\\tinterpretsis\\preparesis.pl winscw udeb"; |
|
36 $CMD = "$INT_PATH$INT_CMD"; |
|
37 $PARAMS =" -c $C_DRIVE -z $Z_DRIVE -w INFO -l \\epoc32\\winscw\\c\\interpretsis_test.txt -s "; |
|
38 |
|
39 $logFile = "\\epoc32\\winscw\\c\\interpretsis_test.txt"; |
|
40 $numTotal = 0; |
|
41 $numPassed = 0; |
|
42 $numFailed = 0; |
|
43 my $usif = 0; |
|
44 # |
|
45 #Function to write log into file |
|
46 # |
|
47 sub WriteLog { |
|
48 my ($log) = @_; |
|
49 |
|
50 unless( open($fh, ">> $logFile")) { |
|
51 printf STDERR "Can\'t open $logFile:$!\n"; |
|
52 return; |
|
53 } |
|
54 printf $fh $log; |
|
55 printf $log; |
|
56 close $fh; |
|
57 } |
|
58 |
|
59 sub RunTest($$$) { |
|
60 my $sis = $_[0]; |
|
61 my $expected = $_[1]; |
|
62 my $config_file = $_[2]; |
|
63 $numTotal++; |
|
64 |
|
65 $sis = join(" -s $SIS_PATH", split(',', $sis)); |
|
66 WriteLog("\nInstalling $sis\n"); |
|
67 |
|
68 if ($^O eq "MSWin32") { |
|
69 # do this because system() doesn't handle the return code |
|
70 # correctly on windows :-( |
|
71 sub error () { |
|
72 print Win32::FormatMessage( Win32::GetLastError() ); |
|
73 } |
|
74 |
|
75 Create($ProcessObj, |
|
76 $CMD, |
|
77 "$PARAMS $SIS_PATH$sis -i $CONFIG_PATH$config_file ", |
|
78 0, |
|
79 NORMAL_PRIORITY_CLASS, |
|
80 ".") || die error() ; |
|
81 |
|
82 $ProcessObj->Wait(INFINITE); |
|
83 $ProcessObj->GetExitCode($y); |
|
84 } else { |
|
85 system("$CMD $PARAMS $SIS_PATH$sis -i $CONFIG_PATH$config_file"); |
|
86 $y = $? >> 8; |
|
87 if ($y & 0x80) { |
|
88 $y -= 256; |
|
89 } |
|
90 |
|
91 } |
|
92 |
|
93 |
|
94 my $result = $y; |
|
95 |
|
96 # If a check case |
|
97 if ($expected == '99' ) |
|
98 { |
|
99 $exists = $C_DRIVE."\\test_exists_func.txt"; |
|
100 $approp = $C_DRIVE."\\test_approp_func_true.txt"; |
|
101 $package = $C_DRIVE."\\test_package_func.txt"; |
|
102 # Check to see if the files are installed or not |
|
103 if (-e $exists && -e $approp && -e $package) |
|
104 { |
|
105 WriteLog("*** Success\n\n"); |
|
106 $numPassed++; |
|
107 } |
|
108 else |
|
109 { |
|
110 WriteLog("--- Fail: test result was $result expected 0\n\n"); |
|
111 $numFailed++; |
|
112 } |
|
113 |
|
114 } |
|
115 else |
|
116 { |
|
117 if ($result == $expected) { |
|
118 WriteLog("*** Success\n\n"); |
|
119 $numPassed++; |
|
120 } else { |
|
121 WriteLog("--- Fail: result was $result expected $expected\n\n"); |
|
122 $numFailed++; |
|
123 } |
|
124 } |
|
125 } |
|
126 |
|
127 |
|
128 sub RemoveDir($) |
|
129 { |
|
130 my $dir = $_[0]; |
|
131 opendir(DIRHANDLE, $dir) || die "can't open file $dir"; |
|
132 |
|
133 foreach $name (sort readdir(DIRHANDLE)) { |
|
134 if ($name ne "." && $name ne "..") { |
|
135 if (-d "$dir/$name") { |
|
136 &RemoveDir("$dir/$name"); |
|
137 rmdir("$dir/$name"); |
|
138 } else { |
|
139 unlink("$dir/$name"); |
|
140 } |
|
141 } |
|
142 } |
|
143 closedir(DIRHANDLE); |
|
144 rmdir($dir); |
|
145 } |
|
146 |
|
147 sub PrepareSis() |
|
148 { |
|
149 # Run |
|
150 system "$PREPARE_SIS"; |
|
151 } |
|
152 |
|
153 sub CopyScrDb() |
|
154 { |
|
155 if($usif eq "usif") |
|
156 { |
|
157 $EpocRom = "\\epoc32\\release\\winscw\\udeb\\z"; |
|
158 $ScrPath = "\\sys\\install\\scr\\provisioned\\scr.db"; |
|
159 $ScrDbPath = $EpocRom.$ScrPath; |
|
160 $NewPath = $Z_DRIVE.$ScrPath; |
|
161 |
|
162 copy($ScrDbPath, $NewPath); |
|
163 WriteLog("Copying DB from $ScrDbPath to $NewPath\n"); |
|
164 } |
|
165 } |
|
166 |
|
167 sub SetUpDbEnv() |
|
168 { |
|
169 if($usif eq "usif") |
|
170 { |
|
171 my $current_dir = getcwd(); |
|
172 chdir($Z_DRIVE); |
|
173 mkdir("sys"); |
|
174 chdir("sys"); |
|
175 mkdir("install"); |
|
176 chdir("install"); |
|
177 mkdir("scr"); |
|
178 chdir("scr"); |
|
179 mkdir("provisioned"); |
|
180 chdir $current_dir; |
|
181 CopyScrDb(); |
|
182 } |
|
183 } |
|
184 # if these test cases are being run for the new symbian universal software installer |
|
185 # then copy the scr database to the specified location in the rom drive. |
|
186 $usif="usif" if ($ARGV[0] =~ /\s*usif\s*/i); |
|
187 |
|
188 open(G, ">$logFile"); |
|
189 close(G); |
|
190 |
|
191 PrepareSis(); |
|
192 |
|
193 mkdir($C_DRIVE); |
|
194 mkdir($Z_DRIVE); |
|
195 SetUpDbEnv(); |
|
196 |
|
197 open(F, ">$C_DRIVE/i_am_an_orphan.txt"); |
|
198 print F "orphan I am\n"; |
|
199 close(F); |
|
200 |
|
201 # plain exe & private dir text file should pass |
|
202 RunTest("exe_s.sis",0, "config_normal.ini"); |
|
203 |
|
204 if ($usif) |
|
205 { |
|
206 # Appropriate error message should be generated if SQLite library is not present |
|
207 my $sqlLiteLib = "\\epoc32\\tools\\sqlite3.dll"; |
|
208 my $sqlLiteLibBackup = "\\epoc32\\tools\\sqlite3.dll.test.backup"; |
|
209 |
|
210 if (-e $sqlLiteLib) |
|
211 { |
|
212 rename($sqlLiteLib,$sqlLiteLibBackup); |
|
213 } |
|
214 |
|
215 RunTest("exe_s.sis",-43, "config_normal.ini"); |
|
216 |
|
217 if (-e $sqlLiteLibBackup) |
|
218 { |
|
219 rename($sqlLiteLibBackup,$sqlLiteLib); |
|
220 } |
|
221 |
|
222 # Appropriate error message should be generated if SQLite library is |
|
223 # present but not in one of the paths mentioned in PATH environment variable. |
|
224 my $sqlLiteLibMovePath = "\\epoc32\\winscw\\c\\tswi\\sqlite3.dll"; |
|
225 |
|
226 if (-e $sqlLiteLib) |
|
227 { |
|
228 move($sqlLiteLib,$sqlLiteLibMovePath); |
|
229 } |
|
230 |
|
231 RunTest("exe_s.sis",-43, "config_normal.ini"); |
|
232 |
|
233 if (-e $sqlLiteLibMovePath) |
|
234 { |
|
235 move($sqlLiteLibMovePath,$sqlLiteLib); |
|
236 } |
|
237 |
|
238 # In case of multiple occurences of SQLite library, verify that the one |
|
239 # present in the location mentioned in the PATH environment variable is taken. |
|
240 |
|
241 open(FH,">$sqlLiteLibMovePath"); # create an empty file |
|
242 close(FH); |
|
243 RunTest("exe_s.sis",0, "config_normal.ini"); |
|
244 unlink $sqlLiteLibMovePath; # remove the empty file |
|
245 |
|
246 |
|
247 # Appropriate error message should be generated if "scrtool.exe" library is not present |
|
248 my $scrTool = "\\epoc32\\tools\\scrtool.exe"; |
|
249 my $scrToolBackup = "\\epoc32\\tools\\scrtool.exe.test.backup"; |
|
250 |
|
251 if (-e $scrTool) |
|
252 { |
|
253 rename($scrTool,$scrToolBackup); |
|
254 } |
|
255 |
|
256 RunTest("exe_s.sis",-42, "config_normal.ini"); |
|
257 |
|
258 if (-e $scrToolBackup) |
|
259 { |
|
260 rename($scrToolBackup,$scrTool); |
|
261 } |
|
262 |
|
263 # Appropriate error message should be generated if "scrtool.exe" is |
|
264 # present but not in one of the paths mentioned in PATH environment variable. |
|
265 my $scrToolMovePath = "\\epoc32\\winscw\\c\\tswi\\scrtool.exe"; |
|
266 |
|
267 if (-e $scrTool) |
|
268 { |
|
269 move($scrTool,$scrToolMovePath); |
|
270 } |
|
271 |
|
272 RunTest("exe_s.sis",-42, "config_normal.ini"); |
|
273 |
|
274 if (-e $scrToolMovePath) |
|
275 { |
|
276 move($scrToolMovePath,$scrTool); |
|
277 } |
|
278 |
|
279 # In case of multiple occurences of "scrtool.exe", verify that the one |
|
280 # present in the location mentioned in the PATH environment variable is taken. |
|
281 open(FH,">$scrToolMovePath"); # create an empty file |
|
282 close(FH); |
|
283 RunTest("exe_s.sis",0, "config_normal.ini"); |
|
284 unlink $sqlLiteLibMovePath; # remove the empty file |
|
285 } |
|
286 |
|
287 # reinstall should pass |
|
288 RunTest("exe_s.sis",0, "config_normal.ini"); |
|
289 |
|
290 # patch should pass |
|
291 RunTest("patch_s.sis",0, "config_normal.ini"); |
|
292 |
|
293 # partial upgrade should pass - exe uses different SID |
|
294 RunTest("partial_s.sis",0, "config_normal.ini"); |
|
295 |
|
296 # writing to someone else's private dir |
|
297 RunTest("private_fail_s.sis", -4, "config_normal.ini"); |
|
298 |
|
299 # overwrite an orphaned file |
|
300 RunTest("overwrite_s.sis", 0, "config_normal.ini"); |
|
301 |
|
302 # clean the directory for the next batch of tests |
|
303 RemoveDir($C_DRIVE); |
|
304 mkdir($C_DRIVE); |
|
305 CopyScrDb(); |
|
306 |
|
307 # plain exe & private dir text file should pass |
|
308 RunTest("exe_s.sis",0, "config_normal.ini"); |
|
309 |
|
310 # attempt to eclipse |
|
311 RunTest("eclipse_s.sis", -9, "config_normal.ini"); |
|
312 |
|
313 # duplicate sid |
|
314 RunTest("duplicate_sid_s.sis", -9, "config_normal.ini"); |
|
315 |
|
316 # dll which has a duplicated sid as the exe in exe_s.sis |
|
317 RunTest("dll_exe_dup_sid_s.sis", -9, "config_normal.ini"); |
|
318 |
|
319 # dll which has a duplicated sid as the dll in dll_exe_dup_sid_s.sis |
|
320 RunTest("dll_dll_dup_sid_s.sis", -9, "config_normal.ini"); |
|
321 |
|
322 # depend on exe |
|
323 RunTest("depend1_s.sis", 0, "config_normal.ini"); |
|
324 |
|
325 # depend on depend1 |
|
326 RunTest("depend2_s.sis", 0, "config_normal.ini"); |
|
327 |
|
328 # depend on depend1 and depend2 |
|
329 RunTest("depend3_s.sis", 0, "config_normal.ini"); |
|
330 |
|
331 # depend on depend1 and none existent package |
|
332 RunTest("depend4_s.sis", -1, "config_normal.ini"); |
|
333 |
|
334 # mutually dependent |
|
335 RunTest("depend5_s.sis,depend6_s.sis", -1, "config_normal.ini"); |
|
336 |
|
337 # base |
|
338 RunTest("functions_base_s.sis", 0, "config_normal.ini"); |
|
339 |
|
340 # exists |
|
341 RunTest("functions_s.sis", 99, "config_normal.ini"); |
|
342 |
|
343 # plain text file, with non-critical error in config file; should pass |
|
344 RunTest("testconfig_s.sis",0, "config_warn.ini"); |
|
345 |
|
346 # stub sis file dependancy |
|
347 $ROM_STUB_SYS="\\romdrive\\system"; |
|
348 $ROM_STUB_INS="\\romdrive\\system\\install"; |
|
349 mkdir($ROM_STUB_SYS); |
|
350 mkdir($ROM_STUB_INS); |
|
351 copy ("\\epoc32\\winscw\\c\\tswi\\tinterpretsis\\pkg\\stub_file.sis","\\romdrive\\system\\install\\stub_file.sis"); |
|
352 copy ("\\epoc32\\winscw\\c\\tswi\\tinterpretsis\\pkg\\2000stub.sis", "\\romdrive\\system\\install\\2000stub.sis"); |
|
353 RunTest("stub_file_depend_s.sis", 0, "config_normal.ini"); |
|
354 |
|
355 RemoveDir($C_DRIVE); |
|
356 mkdir($C_DRIVE); |
|
357 |
|
358 # delete file on uninstall |
|
359 RunTest("fn_flag_s.sis", 0, "config_normal.ini"); |
|
360 |
|
361 RemoveDir($C_DRIVE); |
|
362 RemoveDir($Z_DRIVE); |
|
363 |
|
364 $run = "Run: $numTotal\n"; |
|
365 $passed = "Passed: $numPassed\n"; |
|
366 $summary = "$numFailed tests failed out of $numTotal\n"; |
|
367 WriteLog($run); |
|
368 WriteLog($passed); |
|
369 WriteLog($summary); |