author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 31 Aug 2010 16:34:26 +0300 | |
branch | RCL_3 |
changeset 43 | c1f20ce4abcf |
parent 0 | a41df078684a |
child 44 | 3e88ff8f41d5 |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 1999-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 "Eclipse Public License v1.0" |
|
5 |
// which accompanies this distribution, and is available |
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 |
// |
|
8 |
// Initial Contributors: |
|
9 |
// Nokia Corporation - initial contribution. |
|
10 |
// |
|
11 |
// Contributors: |
|
12 |
// |
|
13 |
// Description: |
|
14 |
// f32test\loader\t_ldrtst.cpp |
|
15 |
// |
|
16 |
// |
|
17 |
||
18 |
#define __E32TEST_EXTENSION__ |
|
19 |
||
20 |
#include "t_hash.h" |
|
21 |
#include "t_ldrtst.h" |
|
22 |
#include "../../../e32test/mmu/d_memorytest.h" |
|
23 |
||
24 |
#if defined(__WINS__) |
|
25 |
#include <e32wins.h> |
|
26 |
#include <emulator.h> |
|
27 |
#elif defined(__EPOC32__) |
|
28 |
#include <f32image.h> |
|
29 |
#endif |
|
30 |
||
31 |
const TInt KNumberOfCorruptFiles = 2; |
|
32 |
||
33 |
RTest test(_L("T_LDRTST")); |
|
34 |
||
35 |
LoaderTest* TheLoaderTest; |
|
36 |
RFs Fs; |
|
37 |
#if defined (__X86__) || defined(__WINS__) |
|
38 |
TBool NoRemovable=ETrue; |
|
39 |
#else |
|
40 |
TBool NoRemovable=EFalse; |
|
41 |
#endif |
|
42 |
||
43 |
/** Error code of simulated RFs error */ |
|
44 |
const TInt KRFsError = -99; |
|
45 |
||
46 |
/** |
|
47 |
Number of drives which are identified by a numeric value, |
|
48 |
which means, e.g., run from an internal pageable drive. |
|
49 |
*/ |
|
50 |
const TInt KSpecialDriveCount = 2; |
|
51 |
||
52 |
/** The real drive letters corresponding to each special drive. */ |
|
53 |
static TFixedArray<TText, KSpecialDriveCount> SpecialDrives; |
|
54 |
||
55 |
/** Bitmask of paged and unpaged module flags. */ |
|
56 |
const TUint32 KModulePagedCodeFlags = (KModuleFlagPagedCode | KModuleFlagUnpagedCode); |
|
57 |
||
58 |
_LIT(KSysHash,"?:\\Sys\\Hash\\"); |
|
59 |
||
60 |
TInt GetModuleFlags(TInt aModule) |
|
61 |
{ |
|
62 |
TInt f = ModuleFlags[aModule]; |
|
63 |
#ifdef __WINS__ |
|
64 |
// paged and unpaged flags are not supported on the emulator |
|
65 |
f &= ~KModulePagedCodeFlags; |
|
66 |
// On emulator, treat all modules as XIP, all EXEs as fixed |
|
67 |
f |= KModuleFlagXIP; |
|
68 |
if (f & KModuleFlagExe) |
|
69 |
f|=KModuleFlagFixed; |
|
70 |
#endif // #ifdef __EPOC32__ |
|
71 |
return f; |
|
72 |
} |
|
73 |
||
74 |
TModuleSet::TModuleSet() |
|
75 |
{ |
|
76 |
Mem::FillZ(this,sizeof(TModuleSet)); |
|
77 |
} |
|
78 |
||
79 |
void TModuleSet::Add(TInt aModule) |
|
80 |
{ |
|
81 |
TUint8 m=(TUint8)(1<<(aModule&7)); |
|
82 |
TInt i=aModule>>3; |
|
83 |
if (!(iBitMap[i]&m)) |
|
84 |
{ |
|
85 |
iBitMap[i]|=m; |
|
86 |
++iCount; |
|
87 |
} |
|
88 |
} |
|
89 |
||
90 |
void TModuleSet::Remove(TInt aModule) |
|
91 |
{ |
|
92 |
TUint8 m=(TUint8)(1<<(aModule&7)); |
|
93 |
TInt i=aModule>>3; |
|
94 |
if (iBitMap[i]&m) |
|
95 |
{ |
|
96 |
iBitMap[i]&=~m; |
|
97 |
--iCount; |
|
98 |
} |
|
99 |
} |
|
100 |
||
101 |
TModuleSet::TModuleSet(const TModuleList& aList, TInt aMask, TInt aVal) |
|
102 |
{ |
|
103 |
Mem::FillZ(this,sizeof(TModuleSet)); |
|
104 |
TInt i; |
|
105 |
for (i=0; i<aList.iCount; ++i) |
|
106 |
{ |
|
107 |
TInt m=aList.iInfo[i].iDllNum; |
|
108 |
if (((GetModuleFlags(m)&aMask)^aVal)==0) |
|
109 |
Add(aList.iInfo[i].iDllNum); |
|
110 |
} |
|
111 |
} |
|
112 |
||
113 |
void TModuleSet::Remove(const TModuleList& aList) |
|
114 |
{ |
|
115 |
TInt i; |
|
116 |
for (i=0; i<aList.iCount; ++i) |
|
117 |
Remove(aList.iInfo[i].iDllNum); |
|
118 |
} |
|
119 |
||
120 |
void TModuleSet::Display(const TDesC& aTitle) const |
|
121 |
{ |
|
122 |
TBuf<256> s=aTitle; |
|
123 |
TInt i; |
|
124 |
for (i=0; i<iCount; ++i) |
|
125 |
{ |
|
126 |
if (Present(i)) |
|
127 |
s.AppendFormat(_L("%3d "),i); |
|
128 |
} |
|
129 |
test.Printf(_L("%S\n"),&s); |
|
130 |
} |
|
131 |
||
132 |
TModuleList::TModuleList() |
|
133 |
{ |
|
134 |
iCount=0; |
|
135 |
Mem::Fill(iInfo, KNumModules*sizeof(SDllInfo), 0xff); |
|
136 |
} |
|
137 |
||
138 |
void TModuleList::SetCount() |
|
139 |
{ |
|
140 |
TInt i; |
|
141 |
for (i=0; i<KNumModules && iInfo[i].iDllNum>=0; ++i) {} |
|
142 |
iCount=i; |
|
143 |
} |
|
144 |
||
145 |
void TModuleList::Display(const TDesC& aTitle) const |
|
146 |
{ |
|
147 |
TBuf<256> s=aTitle; |
|
148 |
TInt i; |
|
149 |
for (i=0; i<iCount; ++i) |
|
150 |
{ |
|
151 |
TInt modnum=iInfo[i].iDllNum; |
|
152 |
s.AppendFormat(_L("%3d "),modnum); |
|
153 |
} |
|
154 |
test.Printf(_L("%S\n"),&s); |
|
155 |
} |
|
156 |
||
157 |
TBool TModuleList::IsPresent(TInt aModNum) const |
|
158 |
{ |
|
159 |
return Find(aModNum)>=0; |
|
160 |
} |
|
161 |
||
162 |
TInt TModuleList::Find(TInt aModNum) const |
|
163 |
{ |
|
164 |
TInt i; |
|
165 |
for (i=iCount-1; i>=0 && iInfo[i].iDllNum!=aModNum; --i) {} |
|
166 |
return i; |
|
167 |
} |
|
168 |
||
169 |
void TModuleList::Add(const SDllInfo& a) |
|
170 |
{ |
|
171 |
iInfo[iCount++]=a; |
|
172 |
} |
|
173 |
||
174 |
||
175 |
RMemoryTestLdd TestLdd; |
|
176 |
||
177 |
TBool AddressReadable(TLinAddr a) |
|
178 |
{ |
|
179 |
TUint32 value; |
|
180 |
return TestLdd.ReadMemory((TAny*)a,value)==KErrNone; |
|
181 |
} |
|
182 |
||
183 |
TInt LoaderTest::DetermineDllLoadResult(TInt aDllNum, TInt aExeNum) |
|
184 |
{ |
|
185 |
TBool proc_sym=(iMemModelAtt & (EMemModelAttrSameVA|EMemModelAttrSupportFixed))==EMemModelAttrSameVA; |
|
186 |
const TInt* exeinfo=ModuleExeInfo[aDllNum]; |
|
187 |
TInt attp=exeinfo[0]; |
|
188 |
TInt linkexe=exeinfo[1]; |
|
189 |
TInt dllflags=GetModuleFlags(aDllNum); |
|
190 |
TInt exeflags=GetModuleFlags(aExeNum); |
|
191 |
||
192 |
#ifdef __EPOC32__ |
|
193 |
// if NP and DEFAULTPAGED or DEFAULTUNPAGED (not NOPAGING or ALWAYSPAGE) then |
|
194 |
// executable identified as corrupt, unless previous conditions in S3.1.3.2 cause |
|
195 |
// it to be paged or unpaged without examining the flags. |
|
196 |
||
197 |
TUint32 policy = E32Loader::PagingPolicy(); |
|
198 |
test.Printf(_L("DetermineDllLoadResult,dll=%d,exe=%d,dllflags=0x%x,policy=0x%x\n"), aDllNum, aExeNum, dllflags, policy); |
|
199 |
||
200 |
TBool flagsChecked = |
|
201 |
policy != EKernelConfigCodePagingPolicyNoPaging // 3.1.3.2.1, policy != no paging |
|
202 |
&& (dllflags & KModuleFlagIDrive) != 0 // 3.1.3.2.2-3, pageable drive |
|
203 |
&& (dllflags & (KModuleFlagUncompressed | KModuleFlagBytePair)) != 0 // 3.1.3.2.4 pageable format |
|
204 |
&& policy != EKernelConfigCodePagingPolicyAlwaysPage; // 3.1.3.2.5, policy != ALWAYS |
|
205 |
||
206 |
if (flagsChecked && (dllflags & KModulePagedCodeFlags) == KModulePagedCodeFlags) |
|
207 |
{ |
|
208 |
TBool codePolDefUnpaged = (policy == EKernelConfigCodePagingPolicyDefaultUnpaged); |
|
209 |
TBool codePolDefPaged = (policy == EKernelConfigCodePagingPolicyDefaultPaged); |
|
210 |
if (codePolDefPaged || codePolDefUnpaged) |
|
211 |
return KErrCorrupt; |
|
212 |
} |
|
213 |
#endif |
|
214 |
||
215 |
if (linkexe>=0 && linkexe!=aExeNum) |
|
216 |
return KErrNotSupported; // if DLL links to a different EXE, no good |
|
217 |
if (!(dllflags&KModuleFlagDataInTree)) |
|
218 |
return KErrNone; // if no data in DLL tree, OK |
|
219 |
if (proc_sym) |
|
220 |
return KErrNone; // if all user processes equivalent, OK |
|
221 |
if (!(dllflags&KModuleFlagXIPDataInTree)) |
|
222 |
return KErrNone; // if no XIP modules with data in DLL tree, OK |
|
223 |
||
224 |
#ifdef __EPOC32__ |
|
225 |
if (attp<0 || !(GetModuleFlags(attp)&KModuleFlagFixed)) |
|
226 |
{ |
|
227 |
// moving processes only |
|
228 |
if (!(exeflags&KModuleFlagFixed)) |
|
229 |
return KErrNone; |
|
230 |
return KErrNotSupported; |
|
231 |
} |
|
232 |
// fixed attach process only |
|
233 |
if (aExeNum!=attp) |
|
234 |
return KErrNotSupported; |
|
235 |
#else |
|
236 |
(void)attp; |
|
237 |
(void)exeflags; |
|
238 |
#endif |
|
239 |
return KErrNone; |
|
240 |
} |
|
241 |
||
242 |
TInt LoaderTest::DetermineDllLoadResult(TInt aDllNum, TInt aExeNum1, TInt aExeNum2) |
|
243 |
{ |
|
244 |
// Determine result of loading aDllNum into aExeNum2 given that it's already loaded into aExeNum1 |
|
245 |
// return KErrNone if code segment can be shared, 1 if it must be duplicated |
|
246 |
||
247 |
TBool proc_sym=(iMemModelAtt & (EMemModelAttrSameVA|EMemModelAttrSupportFixed))==EMemModelAttrSameVA; |
|
248 |
const TInt* exeinfo=ModuleExeInfo[aDllNum]; |
|
249 |
// TInt attp=exeinfo[0]; |
|
250 |
TInt linkexe=exeinfo[1]; |
|
251 |
TInt dllflags=GetModuleFlags(aDllNum); |
|
252 |
TInt exe1flags=GetModuleFlags(aExeNum1); |
|
253 |
TInt exe2flags=GetModuleFlags(aExeNum2); |
|
254 |
if (linkexe>=0 && linkexe!=aExeNum2) |
|
255 |
return KErrNotSupported; // if DLL links to a different EXE, no good |
|
256 |
if (!(dllflags&KModuleFlagDataInTree)) |
|
257 |
return KErrNone; // if no data in DLL tree, OK |
|
258 |
if (proc_sym) |
|
259 |
return KErrNone; // if all user processes equivalent, OK |
|
260 |
if (!((exe1flags|exe2flags)&KModuleFlagFixed)) |
|
261 |
return KErrNone; // if neither process fixed, OK |
|
262 |
if (!(dllflags&KModuleFlagXIPDataInTree)) |
|
263 |
return 1; // if no XIP modules with data in DLL tree, OK but can't share |
|
264 |
#ifdef __WINS__ |
|
265 |
return KErrNone; |
|
266 |
#else |
|
267 |
return KErrNotSupported; |
|
268 |
#endif |
|
269 |
} |
|
270 |
||
271 |
TBool LoaderTest::IsRomAddress(TLinAddr a) |
|
272 |
{ |
|
273 |
const TRomHeader& rh=*(const TRomHeader*)UserSvr::RomHeaderAddress(); |
|
274 |
return (a>=rh.iRomBase && (a-rh.iRomBase)<rh.iRomSize); |
|
275 |
} |
|
276 |
||
277 |
TBool LoaderTest::IsRamCodeAddress(TLinAddr a) |
|
278 |
{ |
|
279 |
switch (iMemModelAtt & EMemModelTypeMask) |
|
280 |
{ |
|
281 |
case EMemModelTypeDirect: |
|
282 |
return ETrue; |
|
283 |
case EMemModelTypeMoving: |
|
284 |
return (a>=0xc0000000u); |
|
285 |
case EMemModelTypeMultiple: |
|
286 |
return (a<0x80000000u); |
|
287 |
case EMemModelTypeFlexible: |
|
288 |
return (a<0x80000000u); |
|
289 |
case EMemModelTypeEmul: |
|
290 |
return (a<0x80000000u); |
|
291 |
default: |
|
292 |
return EFalse; |
|
293 |
} |
|
294 |
} |
|
295 |
||
296 |
TBool LoaderTest::CheckDataAddress(TLinAddr a, TInt aDllNum, TInt aExeNum) |
|
297 |
{ |
|
298 |
TInt xf=GetModuleFlags(aExeNum); |
|
299 |
TInt df=GetModuleFlags(aDllNum); |
|
300 |
switch (iMemModelAtt & EMemModelTypeMask) |
|
301 |
{ |
|
302 |
case EMemModelTypeDirect: |
|
303 |
return ETrue; |
|
304 |
case EMemModelTypeMoving: |
|
305 |
{ |
|
306 |
const TRomHeader& rh=*(const TRomHeader*)UserSvr::RomHeaderAddress(); |
|
307 |
if (!(xf&KModuleFlagFixed)) |
|
308 |
return (a<0x40000000u); |
|
309 |
if ((xf&KModuleFlagXIP) && (df&KModuleFlagXIP)) |
|
310 |
return (a>=rh.iKernDataAddress && a<rh.iKernelLimit); |
|
311 |
return (a>=rh.iKernelLimit && a<0xc0000000u); |
|
312 |
} |
|
313 |
case EMemModelTypeMultiple: |
|
314 |
return (a<0x80000000u); |
|
315 |
case EMemModelTypeFlexible: |
|
316 |
return (a<0x80000000u); |
|
317 |
case EMemModelTypeEmul: |
|
318 |
return (a<0x80000000u); |
|
319 |
default: |
|
320 |
return EFalse; |
|
321 |
} |
|
322 |
} |
|
323 |
||
324 |
void LoaderTest::DumpModuleInfo(const SDllInfo& aInfo, TInt aExeNum) |
|
325 |
{ |
|
326 |
TInt flags=GetModuleFlags(aInfo.iDllNum); |
|
327 |
TUint32 mmtype=iMemModelAtt & EMemModelTypeMask; |
|
328 |
TAny* h=iDev.ModuleCodeSeg(aInfo.iModuleHandle); |
|
329 |
if (!h) |
|
330 |
{ |
|
331 |
#ifdef __EPOC32__ |
|
332 |
test(flags & KModuleFlagXIP); |
|
333 |
test(IsRomAddress(aInfo.iEntryPointAddress)); |
|
334 |
test.Printf(_L("Module handle %08x ROM XIP\n"),aInfo.iModuleHandle); |
|
335 |
#endif |
|
336 |
test(!(flags & KModuleFlagData)); |
|
337 |
return; |
|
338 |
} |
|
339 |
TCodeSegCreateInfo info; |
|
340 |
TInt r=iDev.GetCodeSegInfo(h, info); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
341 |
test_KErrNone(r); |
0 | 342 |
TFileName fn; |
343 |
fn.Copy(info.iFileName); |
|
344 |
test.Printf(_L("DCodeSeg@%08x Data=%08x+%x,%x File %S,attr=0x%x\n"),h,info.iDataRunAddress,info.iDataSize,info.iBssSize,&fn,info.iAttr); |
|
345 |
TInt total_data_size=info.iDataSize+info.iBssSize; |
|
346 |
#ifndef __WINS__ |
|
347 |
// Don't do check below for WINS because: |
|
348 |
// a. It doesn't work on code warrior since it puts constants into .data |
|
349 |
// b. On MSCV with c++ exceptions enabled we also get data |
|
350 |
if (flags & KModuleFlagData) |
|
351 |
test(total_data_size!=0); |
|
352 |
else |
|
353 |
test(total_data_size==0); |
|
354 |
||
355 |
// ensure code paged iff expected. This implements the logic from |
|
356 |
// PREQ1110 Design Sketch SGL.TS0022.008 v1.0 S3.1.3.2 |
|
357 |
||
358 |
TUint policy = E32Loader::PagingPolicy(); |
|
359 |
||
360 |
TBool expected; |
|
361 |
TBool isCodePaged = (info.iAttr & ECodeSegAttCodePaged)!=0; |
|
362 |
||
363 |
// 1. If paging policy is NOPAGING then executable is Unpaged. |
|
364 |
TUint32 memModelAttributes=UserSvr::HalFunction(EHalGroupKernel, EKernelHalMemModelInfo, NULL, NULL); |
|
365 |
if (policy == EKernelConfigCodePagingPolicyNoPaging || !(memModelAttributes&EMemModelAttrCodePaging)) |
|
366 |
{ |
|
367 |
test.Printf(_L("sbcpexp,1\n")); |
|
368 |
expected = false; |
|
369 |
} |
|
370 |
// 2. If ... media ... doesn't have Pageable Media Attribute then it is Unpaged. |
|
371 |
// (this has been superseded by BlockMap check on filesystem / media. During these |
|
372 |
// tests, only the internal media supports paging.) |
|
373 |
else if ((flags & KModuleFlagIDrive) == 0) |
|
374 |
{ |
|
375 |
test.Printf(_L("sbcpexp,2\n")); |
|
376 |
expected = false; |
|
377 |
} |
|
378 |
// 3. If ... removable media then it is Unpaged. |
|
379 |
// Not tested here because removable media (drive 1) covered by above case. |
|
380 |
// else if (MODULE_FILENAME(aInfo.iDllNum)[0] == '1') |
|
381 |
// { |
|
382 |
// test.Printf(_L("sbcpexp,2\n")); |
|
383 |
// expected = false; |
|
384 |
// } |
|
385 |
// 4. [If not bytepair [or uncompressed]] then Unpaged |
|
386 |
else if ((flags & (KModuleFlagBytePair | KModuleFlagUncompressed)) == 0) |
|
387 |
{ |
|
388 |
test.Printf(_L("sbcpexp,3\n")); |
|
389 |
expected = false; |
|
390 |
} |
|
391 |
// 5. If the Paging Policy is ALWAYSPAGE then the executable is Paged. |
|
392 |
else if (policy == EKernelConfigCodePagingPolicyAlwaysPage) |
|
393 |
{ |
|
394 |
test.Printf(_L("sbcpexp,4\n")); |
|
395 |
expected = true; |
|
396 |
} |
|
397 |
// 6. if KImageCodePaged and KImageCodePaged both set, should not reach here |
|
398 |
// because load will have failed with KErrCorrupt. If Paged on its own |
|
399 |
// then paged; if unpaged on its own then unpaged |
|
400 |
else if ((flags & KModuleFlagPagedCode) != 0) |
|
401 |
{ |
|
402 |
test.Printf(_L("sbcpexp,5\n")); |
|
403 |
expected = true; |
|
404 |
} |
|
405 |
else if ((flags & KModuleFlagUnpagedCode) != 0) |
|
406 |
{ |
|
407 |
test.Printf(_L("sbcpexp,6\n")); |
|
408 |
expected = false; |
|
409 |
} |
|
410 |
// 7. Otherwise the PagingPolicy (DEFAULTPAGED or DEFAULTUNPAGED) determines |
|
411 |
// how the executable is treated |
|
412 |
else |
|
413 |
{ |
|
414 |
test.Printf(_L("sbcpexp,7\n")); |
|
415 |
expected = (policy == EKernelConfigCodePagingPolicyDefaultPaged); |
|
416 |
} |
|
417 |
||
418 |
test(expected == isCodePaged); |
|
419 |
#endif |
|
420 |
if ((flags & KModuleFlagXIP) && mmtype!=EMemModelTypeEmul) |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
421 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
422 |
test_Value(aInfo.iEntryPointAddress, IsRomAddress(aInfo.iEntryPointAddress)); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
423 |
} |
0 | 424 |
else |
425 |
{ |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
426 |
test_Value(aInfo.iEntryPointAddress, IsRamCodeAddress(aInfo.iEntryPointAddress)); |
0 | 427 |
if(mmtype==EMemModelTypeFlexible) |
428 |
{ |
|
429 |
// can't make assumtions about current processes address space |
|
430 |
} |
|
431 |
else if (mmtype==EMemModelTypeMultiple) |
|
432 |
{ |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
433 |
test_Value(aInfo.iEntryPointAddress, !AddressReadable(aInfo.iEntryPointAddress)); |
0 | 434 |
} |
435 |
else |
|
436 |
{ |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
437 |
test_Value(aInfo.iEntryPointAddress, AddressReadable(aInfo.iEntryPointAddress)); |
0 | 438 |
} |
439 |
} |
|
440 |
||
441 |
if (total_data_size!=0) |
|
442 |
test(CheckDataAddress(info.iDataRunAddress, aInfo.iDllNum, aExeNum)); |
|
443 |
} |
|
444 |
||
445 |
void LoaderTest::DumpModuleList(const TModuleList& aList, TInt aExeNum) |
|
446 |
{ |
|
447 |
TInt i; |
|
448 |
for (i=0; i<aList.iCount; ++i) |
|
449 |
{ |
|
450 |
TInt modnum=aList.iInfo[i].iDllNum; |
|
451 |
TInt entry=aList.iInfo[i].iEntryPointAddress; |
|
452 |
test.Printf(_L("MODULE %3d: ENTRY %08x "),modnum,entry); |
|
453 |
DumpModuleInfo(aList.iInfo[i],aExeNum); |
|
454 |
} |
|
455 |
} |
|
456 |
||
457 |
void LoaderTest::CheckModuleList(TInt aRoot, const TModuleList& aList) |
|
458 |
{ |
|
459 |
const TInt* deps=ModuleDependencies[aRoot]; |
|
460 |
TInt ndeps=*deps++; |
|
461 |
TInt f=0; |
|
462 |
TInt i; |
|
463 |
for (i=0; i<ndeps; ++i) |
|
464 |
{ |
|
465 |
TInt m=deps[i]; |
|
466 |
f|=GetModuleFlags(m); |
|
467 |
} |
|
468 |
if (!(f&KModuleFlagDllInCycle)) |
|
469 |
{ |
|
470 |
i=0; // indexes aList |
|
471 |
TInt j=0; // indexes deps |
|
472 |
while(i<KNumModules) |
|
473 |
{ |
|
474 |
if (j<ndeps) |
|
475 |
{ |
|
476 |
if (!(GetModuleFlags(deps[j])&KModuleFlagExe)) |
|
477 |
{ |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
478 |
test_Value(aList.iInfo[i].iDllNum, aList.iInfo[i].iDllNum==deps[j]); |
0 | 479 |
++i; |
480 |
} |
|
481 |
++j; |
|
482 |
} |
|
483 |
else if (j==ndeps) |
|
484 |
{ |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
485 |
test_Value(aList.iInfo[i].iDllNum, aList.iInfo[i].iDllNum==aRoot); |
0 | 486 |
++i; |
487 |
++j; |
|
488 |
} |
|
489 |
else |
|
490 |
{ |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
491 |
test_Value(aList.iInfo[i].iDllNum, aList.iInfo[i].iDllNum<0); |
0 | 492 |
++i; |
493 |
} |
|
494 |
} |
|
495 |
} |
|
496 |
TModuleSet ml; |
|
497 |
TInt nd=ndeps; |
|
498 |
TBool root_included=EFalse; |
|
499 |
for (i=0; i<ndeps; ++i) |
|
500 |
{ |
|
501 |
if (deps[i]==aRoot) |
|
502 |
root_included=ETrue; |
|
503 |
if (!(GetModuleFlags(deps[i])&KModuleFlagExe)) |
|
504 |
ml.Add(deps[i]); |
|
505 |
else |
|
506 |
--nd; |
|
507 |
} |
|
508 |
test(ml.iCount==nd); |
|
509 |
for (i=0; i<KNumModules; ++i) |
|
510 |
{ |
|
511 |
if (i<nd) |
|
512 |
{ |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
513 |
test_Value(aList.iInfo[i].iDllNum, aList.iInfo[i].iDllNum>=0); |
0 | 514 |
ml.Remove(aList.iInfo[i].iDllNum); |
515 |
} |
|
516 |
else if (i==nd && !root_included) |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
517 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
518 |
test_Value(aList.iInfo[i].iDllNum, aList.iInfo[i].iDllNum == aRoot); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
519 |
} |
0 | 520 |
else |
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
521 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
522 |
test_Value(aList.iInfo[i].iDllNum, aList.iInfo[i].iDllNum<0); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
523 |
} |
0 | 524 |
} |
525 |
test(ml.iCount==0); |
|
526 |
} |
|
527 |
||
528 |
LoaderTest::LoaderTest() |
|
529 |
{ |
|
530 |
Mem::Fill(iCmdLine, sizeof(iCmdLine), 0xff); |
|
531 |
iMemModelAtt=(TUint32)UserSvr::HalFunction(EHalGroupKernel, EKernelHalMemModelInfo, NULL, NULL); |
|
532 |
test.Printf(_L("MemModelAttributes=%08x\n"),iMemModelAtt); |
|
533 |
} |
|
534 |
||
535 |
LoaderTest::~LoaderTest() |
|
536 |
{ |
|
537 |
iFs.Close(); |
|
538 |
iDev.Close(); |
|
539 |
} |
|
540 |
||
541 |
void LoaderTest::Init() |
|
542 |
{ |
|
543 |
test.Next(_L("Load device driver")); |
|
544 |
TInt r=User::LoadLogicalDevice(_L("D_LDRTST")); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
545 |
test_Value(r, r==KErrNone || r==KErrAlreadyExists); |
0 | 546 |
r=iDev.Open(); |
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
547 |
test_KErrNone(r); |
0 | 548 |
r=iFs.Connect(); |
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
549 |
test_KErrNone(r); |
0 | 550 |
|
551 |
TBuf<256> cmdline; |
|
552 |
User::CommandLine(cmdline); |
|
553 |
TLex lex(cmdline); |
|
554 |
TInt i; |
|
555 |
for (i=0; i<8; ++i) |
|
556 |
{ |
|
557 |
lex.SkipSpace(); |
|
558 |
if (lex.Eos()) |
|
559 |
break; |
|
560 |
lex.Val(iCmdLine[i]); |
|
561 |
} |
|
562 |
} |
|
563 |
||
564 |
LoaderTest* LoaderTest::New() |
|
565 |
{ |
|
566 |
LoaderTest* p=new LoaderTest; |
|
567 |
test(p!=NULL); |
|
568 |
p->Init(); |
|
569 |
return p; |
|
570 |
} |
|
571 |
||
572 |
void LoaderTest::Close() |
|
573 |
{ |
|
574 |
delete this; |
|
575 |
} |
|
576 |
||
577 |
void LoaderTest::TraceOn() |
|
578 |
{ |
|
579 |
iFs.SetDebugRegister(KFLDR); |
|
580 |
User::SetDebugMask(0xefdfffff); |
|
581 |
} |
|
582 |
||
583 |
void LoaderTest::TraceOff() |
|
584 |
{ |
|
585 |
iFs.SetDebugRegister(0); |
|
586 |
User::SetDebugMask(0x80000000); |
|
587 |
} |
|
588 |
||
589 |
void LoaderTest::TestOneByOne() |
|
590 |
{ |
|
591 |
test.Next(_L("Test all single EXE/DLL combinations")); |
|
592 |
TInt i=0; |
|
593 |
TInt r=0; |
|
594 |
TInt x=0; |
|
595 |
for (x=0; x<KNumModules; ++x) |
|
596 |
{ |
|
597 |
if (!(GetModuleFlags(x)&KModuleFlagExe)) |
|
598 |
continue; |
|
599 |
#ifdef __WINS__ |
|
600 |
if (GetModuleFlags(x)&KModuleFlagTargetOnly) |
|
601 |
continue; |
|
602 |
#endif |
|
603 |
RProcess p; |
|
604 |
TUint32 tt; |
|
605 |
r=LoadExe(x, 0, p, tt); |
|
606 |
test.Printf(_L("LoadExe(%d)->%d\n"),x,r); |
|
607 |
test.Printf(_L("BENCHMARK: LoadExe(%d)->%dms\n"),x,tt); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
608 |
test_KErrNone(r); |
0 | 609 |
RLoaderTest lt; |
610 |
r=lt.Connect(x); |
|
611 |
test.Printf(_L("Connect(%d)->%d\n"),x,r); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
612 |
test_KErrNone(r); |
0 | 613 |
TModuleList exe_info; |
614 |
r=lt.GetExeDepList(exe_info.iInfo); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
615 |
test_KErrNone(r); |
0 | 616 |
exe_info.SetCount(); |
617 |
DumpModuleList(exe_info, x); |
|
618 |
CheckModuleList(x, exe_info); |
|
619 |
||
620 |
TInt m; |
|
621 |
for (m=0; m<KNumModules; ++m) |
|
622 |
{ |
|
623 |
if (GetModuleFlags(m)&KModuleFlagExe) |
|
624 |
continue; |
|
625 |
#ifdef __WINS__ |
|
626 |
if (GetModuleFlags(m)&KModuleFlagTargetOnly) |
|
627 |
continue; |
|
628 |
#endif |
|
629 |
||
630 |
if ((GetModuleFlags(m) & KModuleFlagVDrive) && NoRemovable) |
|
631 |
{ |
|
632 |
test.Printf(_L("LoadDll: Not testing dll %d from removable media\n"),m); |
|
633 |
continue; |
|
634 |
} |
|
635 |
TInt predicted=DetermineDllLoadResult(m,x); |
|
636 |
if (x==iCmdLine[1] && m==iCmdLine[2]) |
|
637 |
TraceOn(); |
|
638 |
TModuleList dll_init_info; |
|
639 |
TModuleList dll_c_info; |
|
640 |
TModuleList dll_d_info; |
|
641 |
TInt h=lt.LoadDll(m, dll_init_info.iInfo); |
|
642 |
dll_init_info.SetCount(); |
|
643 |
test.Printf(_L("LoadDll(%d)->%d (%d)\n"),m,h,predicted); |
|
644 |
||
645 |
test(Min(h,0)==predicted); |
|
646 |
if (h>=0) |
|
647 |
{ |
|
648 |
DumpModuleList(dll_init_info, x); |
|
649 |
CheckModuleList(m, dll_init_info); |
|
650 |
test(lt.GetCDList(dll_c_info.iInfo)==KErrNone); |
|
651 |
dll_c_info.SetCount(); |
|
652 |
dll_c_info.Display(_L("Construct: ")); |
|
653 |
if (!(GetModuleFlags(m)&KModuleFlagDllInCycle)) |
|
654 |
{ |
|
655 |
TInt j=0; |
|
656 |
for (i=0; i<dll_init_info.iCount; ++i) |
|
657 |
{ |
|
658 |
TInt modnum=dll_init_info.iInfo[i].iDllNum; |
|
659 |
if ((GetModuleFlags(modnum)&KModuleFlagData) && !exe_info.IsPresent(modnum)) |
|
660 |
{ |
|
661 |
test(modnum==dll_c_info.iInfo[j].iDllNum); |
|
662 |
++j; |
|
663 |
} |
|
664 |
} |
|
665 |
test(j==dll_c_info.iCount); |
|
666 |
} |
|
667 |
else |
|
668 |
{ |
|
669 |
TModuleSet ms(dll_init_info, KModuleFlagData, KModuleFlagData); |
|
670 |
ms.Remove(exe_info); |
|
671 |
test(ms.iCount==dll_c_info.iCount); |
|
672 |
ms.Remove(dll_c_info); |
|
673 |
test(ms.iCount==0); |
|
674 |
} |
|
675 |
TInt y=(7*m+59); |
|
676 |
r=lt.CallRBlkI(h,y); |
|
677 |
r-=y; |
|
678 |
r/=INC_BLOCK_SZ; |
|
679 |
test.Printf(_L("DLL %d RBlkI->%d\n"),m,r); |
|
680 |
y=ModuleRBlkIParams[m][1]+ModuleRBlkIParams[m][0]*DLLNUMOFFSET; |
|
681 |
test(r==y); |
|
682 |
r=lt.CloseDll(h); |
|
683 |
test.Printf(_L("CloseDll(%d)->%d\n"),h,r); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
684 |
test_KErrNone(r); |
0 | 685 |
test(lt.GetCDList(dll_d_info.iInfo)==KErrNone); |
686 |
dll_d_info.SetCount(); |
|
687 |
dll_d_info.Display(_L("Destruct: ")); |
|
688 |
test(dll_d_info.iCount==dll_c_info.iCount); |
|
689 |
for (i=0; i<dll_d_info.iCount; ++i) |
|
690 |
test(dll_d_info.iInfo[i].iDllNum==dll_c_info.iInfo[dll_c_info.iCount-i-1].iDllNum); |
|
691 |
} |
|
692 |
if (x==iCmdLine[1] && m==iCmdLine[2]) |
|
693 |
TraceOff(); |
|
694 |
} |
|
695 |
lt.Exit(); |
|
696 |
p.Close(); |
|
697 |
} |
|
698 |
} |
|
699 |
||
700 |
// return KErrNone if shared code, 1 if not shared |
|
701 |
TInt LoaderTest::DetermineLoadExe2Result(TInt aExeNum) |
|
702 |
{ |
|
703 |
if ( (iMemModelAtt&(EMemModelAttrSameVA|EMemModelAttrSupportFixed))==EMemModelAttrSameVA ) |
|
704 |
return KErrNone; // multiple memory model always supports multiple instances |
|
705 |
TUint32 f=GetModuleFlags(aExeNum); |
|
706 |
if (!(f&KModuleFlagFixed)) |
|
707 |
return KErrNone; // not fixed, so share code segment |
|
708 |
if (!(f&KModuleFlagDataInTree)) |
|
709 |
{ |
|
710 |
#ifdef __EPOC32__ |
|
711 |
return KErrNone; // fixed but no data, so share code segment |
|
712 |
#else |
|
713 |
return 1; // on emulator, never share EXE code segments |
|
714 |
#endif |
|
715 |
} |
|
716 |
#ifdef __EPOC32__ |
|
717 |
if (!(f&KModuleFlagXIP)) |
|
718 |
return 1; // fixed but not XIP, data in tree - create second code segment |
|
719 |
// fixed, XIP, data in tree |
|
720 |
return KErrAlreadyExists; |
|
721 |
#else |
|
722 |
if (f & KModuleFlagExports) |
|
723 |
return KErrAlreadyExists; |
|
724 |
if (!(f & KModuleFlagData)) |
|
725 |
return KErrNone; |
|
726 |
return 1; |
|
727 |
#endif |
|
728 |
} |
|
729 |
||
730 |
void LoaderTest::TestMultipleExeInstances() |
|
731 |
{ |
|
732 |
test.Next(_L("Test multiple instantiation of EXEs")); |
|
733 |
TInt i=0; |
|
734 |
TInt r=0; |
|
735 |
TInt x=0; |
|
736 |
for (x=0; x<KNumModules; ++x) |
|
737 |
{ |
|
738 |
TUint32 f=GetModuleFlags(x); |
|
739 |
if (!(f&KModuleFlagExe)) |
|
740 |
continue; |
|
741 |
#ifdef __WINS__ |
|
742 |
if (f&KModuleFlagTargetOnly) |
|
743 |
continue; |
|
744 |
#endif |
|
745 |
RProcess p1, p2; |
|
746 |
RLoaderTest lt1, lt2; |
|
747 |
TModuleList exe_info1; |
|
748 |
TModuleList exe_info2; |
|
749 |
TUint32 tt; |
|
750 |
r=LoadExe(x, 0, p1, tt); |
|
751 |
test.Printf(_L("LoadExe1(%d)->%d\n"),x,r); |
|
752 |
test.Printf(_L("BENCHMARK: LoadExe1(%d)->%dms\n"),x,tt); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
753 |
test_KErrNone(r); |
0 | 754 |
r=lt1.Connect(x, 0); |
755 |
test.Printf(_L("Connect1(%d)->%d\n"),x,r); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
756 |
test_KErrNone(r); |
0 | 757 |
TInt s=DetermineLoadExe2Result(x); |
758 |
r=LoadExe(x, 1, p2, tt); |
|
759 |
test.Printf(_L("LoadExe2(%d)->%d (%d)\n"),x,r,s); |
|
760 |
if (s==KErrNone) |
|
761 |
test.Printf(_L("BENCHMARK: LoadExe2(%d)->%dms\n"),x,tt); |
|
762 |
test(r==Min(s,0)); |
|
763 |
||
764 |
if (r==KErrNone) |
|
765 |
{ |
|
766 |
r=lt2.Connect(x, 1); |
|
767 |
test.Printf(_L("Connect2(%d)->%d\n"),x,r); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
768 |
test_KErrNone(r); |
0 | 769 |
r=lt1.GetExeDepList(exe_info1.iInfo); |
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
770 |
test_KErrNone(r); |
0 | 771 |
exe_info1.SetCount(); |
772 |
DumpModuleList(exe_info1, x); |
|
773 |
r=lt2.GetExeDepList(exe_info2.iInfo); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
774 |
test_KErrNone(r); |
0 | 775 |
exe_info2.SetCount(); |
776 |
DumpModuleList(exe_info2, x); |
|
777 |
||
778 |
test(exe_info1.iCount==exe_info2.iCount); |
|
779 |
if (s==1) |
|
780 |
{ |
|
781 |
TInt nm=exe_info1.iCount; |
|
782 |
test(exe_info1.iInfo[nm-1].iModuleHandle!=exe_info2.iInfo[nm-1].iModuleHandle); |
|
783 |
} |
|
784 |
#ifdef __WINS__ |
|
785 |
else if((GetModuleFlags(x) & KModuleFlagData)) |
|
786 |
#else |
|
787 |
else |
|
788 |
#endif |
|
789 |
{ |
|
790 |
for (i=0; i<exe_info1.iCount; ++i) |
|
791 |
test(exe_info1.iInfo[i].iModuleHandle==exe_info2.iInfo[i].iModuleHandle); |
|
792 |
} |
|
793 |
||
794 |
const TInt* tests=TC_ExeLoad; |
|
795 |
TInt ntests=*tests++; |
|
796 |
while(ntests--) |
|
797 |
{ |
|
798 |
TInt m=*tests++; |
|
799 |
TModuleList dll_init_info1; |
|
800 |
TModuleList dll_c_info1; |
|
801 |
TModuleList dll_d_info1; |
|
802 |
TModuleList dll_init_info2; |
|
803 |
TModuleList dll_c_info2; |
|
804 |
TModuleList dll_d_info2; |
|
805 |
TInt h1=lt1.LoadDll(m, dll_init_info1.iInfo); |
|
806 |
dll_init_info1.SetCount(); |
|
807 |
test.Printf(_L("LoadDll1(%d)->%d\n"),m,h1); |
|
808 |
if (h1>=0) |
|
809 |
{ |
|
810 |
DumpModuleList(dll_init_info1, x); |
|
811 |
CheckModuleList(m, dll_init_info1); |
|
812 |
test(lt1.GetCDList(dll_c_info1.iInfo)==KErrNone); |
|
813 |
dll_c_info1.SetCount(); |
|
814 |
dll_c_info1.Display(_L("Construct1: ")); |
|
815 |
TInt y=(41*m+487); |
|
816 |
r=lt1.CallRBlkI(h1,y); |
|
817 |
r-=y; |
|
818 |
r/=INC_BLOCK_SZ; |
|
819 |
test.Printf(_L("DLL1 %d RBlkI->%d\n"),m,r); |
|
820 |
y=ModuleRBlkIParams[m][1]+ModuleRBlkIParams[m][0]*DLLNUMOFFSET; |
|
821 |
test(r==y); |
|
822 |
||
823 |
TInt s=DetermineDllLoadResult(m, x, x); |
|
824 |
TInt h2=lt2.LoadDll(m, dll_init_info2.iInfo); |
|
825 |
dll_init_info2.SetCount(); |
|
826 |
test.Printf(_L("LoadDll2(%d)->%d (%d)\n"),m,h2,s); |
|
827 |
test(h2==Min(s,0)); |
|
828 |
if (h2>=0) |
|
829 |
{ |
|
830 |
DumpModuleList(dll_init_info2, x); |
|
831 |
CheckModuleList(m, dll_init_info2); |
|
832 |
test(lt2.GetCDList(dll_c_info2.iInfo)==KErrNone); |
|
833 |
dll_c_info2.SetCount(); |
|
834 |
dll_c_info2.Display(_L("Construct2: ")); |
|
835 |
y=(79*m+257); |
|
836 |
r=lt2.CallRBlkI(h2,y); |
|
837 |
r-=y; |
|
838 |
r/=INC_BLOCK_SZ; |
|
839 |
test.Printf(_L("DLL2 %d RBlkI->%d\n"),m,r); |
|
840 |
y=ModuleRBlkIParams[m][1]+ModuleRBlkIParams[m][0]*DLLNUMOFFSET; |
|
841 |
test(r==y); |
|
842 |
||
843 |
test(dll_init_info1.iCount==dll_init_info2.iCount); |
|
844 |
#ifdef __WINS__ |
|
845 |
if (s==1 && !(ModuleFlags[m]&KModuleFlagDataInTree)) |
|
846 |
#else |
|
847 |
if (s==1) |
|
848 |
#endif |
|
849 |
{ |
|
850 |
TInt nm=dll_init_info1.iCount; |
|
851 |
test(dll_init_info1.iInfo[nm-1].iModuleHandle!=dll_init_info2.iInfo[nm-1].iModuleHandle); |
|
852 |
} |
|
853 |
else |
|
854 |
{ |
|
855 |
for (i=0; i<dll_init_info1.iCount; ++i) |
|
856 |
test(dll_init_info1.iInfo[i].iModuleHandle==dll_init_info2.iInfo[i].iModuleHandle); |
|
857 |
} |
|
858 |
||
859 |
r=lt2.CloseDll(h2); |
|
860 |
test.Printf(_L("CloseDll2(%d)->%d\n"),h2,r); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
861 |
test_KErrNone(r); |
0 | 862 |
test(lt2.GetCDList(dll_d_info2.iInfo)==KErrNone); |
863 |
dll_d_info2.SetCount(); |
|
864 |
dll_d_info2.Display(_L("Destruct2: ")); |
|
865 |
test(dll_d_info2.iCount==dll_c_info2.iCount); |
|
866 |
for (i=0; i<dll_d_info2.iCount; ++i) |
|
867 |
test(dll_d_info2.iInfo[i].iDllNum==dll_c_info2.iInfo[dll_c_info2.iCount-i-1].iDllNum); |
|
868 |
} |
|
869 |
||
870 |
r=lt1.CloseDll(h1); |
|
871 |
test.Printf(_L("CloseDll1(%d)->%d\n"),h1,r); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
872 |
test_KErrNone(r); |
0 | 873 |
test(lt1.GetCDList(dll_d_info1.iInfo)==KErrNone); |
874 |
dll_d_info1.SetCount(); |
|
875 |
dll_d_info1.Display(_L("Destruct1: ")); |
|
876 |
test(dll_d_info1.iCount==dll_c_info1.iCount); |
|
877 |
for (i=0; i<dll_d_info1.iCount; ++i) |
|
878 |
test(dll_d_info1.iInfo[i].iDllNum==dll_c_info1.iInfo[dll_c_info1.iCount-i-1].iDllNum); |
|
879 |
} |
|
880 |
} |
|
881 |
||
882 |
lt2.Exit(); |
|
883 |
p2.Close(); |
|
884 |
} |
|
885 |
lt1.Exit(); |
|
886 |
p1.Close(); |
|
887 |
} |
|
888 |
} |
|
889 |
||
890 |
void SetLoaderFail(TInt aLdr, TInt aKern) |
|
891 |
{ |
|
892 |
test.Printf(_L("ldr=%d, kern=%d\n"),aLdr,aKern); |
|
893 |
RLoader l; |
|
894 |
test(l.Connect()==KErrNone); |
|
895 |
test(l.DebugFunction(ELoaderDebug_SetHeapFail, aLdr, aKern, 0)==KErrNone); |
|
896 |
l.Close(); |
|
897 |
} |
|
898 |
||
899 |
void SetLoaderFailRFs(TInt aError, TInt aCount) |
|
900 |
{ |
|
901 |
test.Printf(_L("SetLoaderFailRFs: error=%d, count=%d\n"),aError,aCount); |
|
902 |
RLoader l; |
|
903 |
test(l.Connect()==KErrNone); |
|
904 |
test(l.DebugFunction(ELoaderDebug_SetRFsFail, aError, aCount, 0)==KErrNone); |
|
905 |
l.Close(); |
|
906 |
} |
|
907 |
||
908 |
class TLoopOOM |
|
909 |
{ |
|
910 |
public: |
|
911 |
enum OomState{EInit, EKernelHeap, EUserHeap, ERFsError}; |
|
912 |
||
913 |
TLoopOOM(); |
|
914 |
void Reset(); |
|
915 |
TBool Iterate(TInt aResult); |
|
916 |
public: |
|
917 |
TInt iLdr; |
|
918 |
TInt iKern; |
|
919 |
TInt iRFsCount; |
|
920 |
OomState iState; |
|
921 |
}; |
|
922 |
||
923 |
TLoopOOM::TLoopOOM() |
|
924 |
{ |
|
925 |
Reset(); |
|
926 |
} |
|
927 |
||
928 |
void TLoopOOM::Reset() |
|
929 |
{ |
|
930 |
iLdr = 0; |
|
931 |
iKern = 0; |
|
932 |
iRFsCount = 0; |
|
933 |
iState = EInit; |
|
934 |
} |
|
935 |
||
936 |
TBool TLoopOOM::Iterate(TInt aResult) |
|
937 |
{ |
|
938 |
TBool noErrors = (aResult==KErrNone||aResult==KErrNotSupported); |
|
939 |
||
940 |
test.Printf(_L("%d %d %d %d\n"), iKern,iLdr,iRFsCount,aResult); |
|
941 |
||
942 |
switch(iState) |
|
943 |
{ |
|
944 |
||
945 |
case EInit: |
|
946 |
iState = EKernelHeap; |
|
947 |
SetLoaderFail(iLdr,++iKern); |
|
948 |
return ETrue; |
|
949 |
||
950 |
case EKernelHeap: |
|
951 |
if (noErrors) |
|
952 |
{ |
|
953 |
iKern = 0; |
|
954 |
iLdr = 1; |
|
955 |
iState = EUserHeap; |
|
956 |
} |
|
957 |
else |
|
958 |
++iKern; |
|
959 |
||
960 |
SetLoaderFail(iLdr,iKern); |
|
961 |
return ETrue; |
|
962 |
||
963 |
case EUserHeap: |
|
964 |
if (noErrors) |
|
965 |
{ |
|
966 |
iLdr = 0; |
|
967 |
iState = ERFsError; |
|
968 |
SetLoaderFail(0,0); |
|
969 |
SetLoaderFailRFs(KRFsError, ++iRFsCount); |
|
970 |
} |
|
971 |
else |
|
972 |
SetLoaderFail(++iLdr,iKern); |
|
973 |
return ETrue; |
|
974 |
||
975 |
case ERFsError: |
|
976 |
if (noErrors) |
|
977 |
break; |
|
978 |
else |
|
979 |
{ |
|
980 |
SetLoaderFailRFs(KRFsError, ++iRFsCount); |
|
981 |
return ETrue; |
|
982 |
} |
|
983 |
} |
|
984 |
||
985 |
SetLoaderFailRFs(KErrNone, 0); |
|
986 |
return EFalse; |
|
987 |
} |
|
988 |
||
989 |
void LoaderTest::TestOOM() |
|
990 |
{ |
|
991 |
test.Next(_L("Test OOM Handling")); |
|
992 |
#ifdef _DEBUG |
|
993 |
TInt r=0; |
|
994 |
TInt x=0; |
|
995 |
TUint32 tt; |
|
996 |
for (x=0; x<KNumModules; ++x) |
|
997 |
{ |
|
998 |
if (!(GetModuleFlags(x)&KModuleFlagExe)) |
|
999 |
continue; |
|
1000 |
#ifdef __WINS__ |
|
1001 |
if (GetModuleFlags(x)&KModuleFlagTargetOnly) |
|
1002 |
continue; |
|
1003 |
#endif |
|
1004 |
||
1005 |
if ((GetModuleFlags(x) & KModuleFlagVDrive) && NoRemovable) |
|
1006 |
{ |
|
1007 |
test.Printf(_L("LoaderTest::TestOOM Not testing dll %d from removable media\n"),x); |
|
1008 |
continue; |
|
1009 |
} |
|
1010 |
if (x==iCmdLine[1]) |
|
1011 |
TraceOn(); |
|
1012 |
TLoopOOM loom; |
|
1013 |
RProcess p; |
|
1014 |
RLoaderTest lt; |
|
1015 |
while(loom.Iterate(r)) |
|
1016 |
{ |
|
1017 |
r=LoadExe(x, 0, p, tt); |
|
1018 |
test.Printf(_L("LoadExe(%d)->%d\n"),x,r); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1019 |
test_Value(r, r==KErrNone || (loom.iState!=TLoopOOM::ERFsError && r==KErrNoMemory) || |
0 | 1020 |
(loom.iState==TLoopOOM::ERFsError && r==KRFsError)); |
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1021 |
if (r != KErrNone) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1022 |
continue; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1023 |
r = lt.Connect(x); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1024 |
test_KErrNone(r); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1025 |
lt.Exit(); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1026 |
p.Close(); |
0 | 1027 |
} |
1028 |
SetLoaderFail(0,0); |
|
1029 |
r=LoadExe(x, 0, p, tt); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1030 |
test_KErrNone(r); |
0 | 1031 |
r=lt.Connect(x); |
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1032 |
test_KErrNone(r); |
0 | 1033 |
const TInt* tests=TC_DllOOM; |
1034 |
TInt ntests=*tests++; |
|
1035 |
TModuleList list; |
|
1036 |
while(ntests--) |
|
1037 |
{ |
|
1038 |
TInt m=*tests++; |
|
1039 |
if ((GetModuleFlags(m) & KModuleFlagVDrive) && NoRemovable) |
|
1040 |
{ |
|
1041 |
test.Printf(_L("LoaderTest::TestOOM Not testing dll %d from removable media\n"),m); |
|
1042 |
continue; |
|
1043 |
} |
|
1044 |
loom.Reset(); |
|
1045 |
r=KErrNone; |
|
1046 |
while(loom.Iterate(r)) |
|
1047 |
{ |
|
1048 |
TInt h=lt.LoadDll(m, list.iInfo); |
|
1049 |
r=Min(h,0); |
|
1050 |
test.Printf(_L("%d:LoadDll(%d)->%d\n"),x,m,h); |
|
1051 |
||
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1052 |
test_Value(r, r==KErrNone || r==KErrNotSupported || r==KErrNoMemory || |
0 | 1053 |
(loom.iState==TLoopOOM::ERFsError && r==KRFsError) ); |
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1054 |
if (r!=KErrNone) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1055 |
continue; |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1056 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1057 |
r=lt.CloseDll(h); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1058 |
test_KErrNone(r); |
0 | 1059 |
} |
1060 |
} |
|
1061 |
lt.Exit(); |
|
1062 |
p.Close(); |
|
1063 |
if (x==iCmdLine[1]) |
|
1064 |
TraceOff(); |
|
1065 |
} |
|
1066 |
#else |
|
1067 |
test.Printf(_L("Only on DEBUG builds\n")); |
|
1068 |
#endif |
|
1069 |
} |
|
1070 |
||
1071 |
class RLoaderTestHandle : public RSessionBase |
|
1072 |
{ |
|
1073 |
public: |
|
1074 |
TInt Connect(); |
|
1075 |
void TryToGetPaniced(); |
|
1076 |
}; |
|
1077 |
||
1078 |
TInt RLoaderTestHandle::Connect() |
|
1079 |
{ |
|
1080 |
return CreateSession(_L("!Loader"),TVersion(KLoaderMajorVersionNumber,KLoaderMinorVersionNumber,KE32BuildVersionNumber)); |
|
1081 |
} |
|
1082 |
||
1083 |
void RLoaderTestHandle::TryToGetPaniced() |
|
1084 |
{ |
|
1085 |
_LIT(KFoo,"foo"); |
|
1086 |
TLdrInfo info; |
|
1087 |
TPckg<TLdrInfo> infoBuf(info); |
|
1088 |
TIpcArgs args; |
|
1089 |
args.Set(0,(TDes8*)&infoBuf); |
|
1090 |
args.Set(1,&KFoo); |
|
1091 |
args.Set(2,&KFoo); |
|
1092 |
SendReceive(ELoadLibrary, args); |
|
1093 |
} |
|
1094 |
||
1095 |
TInt PanicTestThread(TAny*) |
|
1096 |
{ |
|
1097 |
RLoaderTestHandle t; |
|
1098 |
TInt r = t.Connect(); |
|
1099 |
if (r==KErrNone) t.TryToGetPaniced(); |
|
1100 |
return r; |
|
1101 |
} |
|
1102 |
||
1103 |
||
1104 |
void TestCorruptedFiles() |
|
1105 |
{ |
|
1106 |
test.Next(_L("Test corrupted files")); |
|
1107 |
||
1108 |
TInt numCorruptFiles=0; |
|
1109 |
TInt r=0; |
|
1110 |
for (TInt x=0; x<KNumModules; ++x) |
|
1111 |
{ |
|
1112 |
if (!(GetModuleFlags(x)&KModuleFlagExe)) |
|
1113 |
continue; |
|
1114 |
||
1115 |
const TPtrC fn = MODULE_FILENAME(x); |
|
1116 |
if (fn[1] != ':') |
|
1117 |
continue; |
|
1118 |
||
1119 |
if (++numCorruptFiles > KNumberOfCorruptFiles) |
|
1120 |
break; |
|
1121 |
||
1122 |
RProcess p; |
|
1123 |
TUint32 tt; |
|
1124 |
r=LoadExe(x, 0, p, tt); |
|
1125 |
test.Printf(_L("LoadCorruptExe(%d)->%d\n"),x,r); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1126 |
test_Value(r,r==KErrCorrupt); |
0 | 1127 |
} |
1128 |
} |
|
1129 |
||
1130 |
// -------- copying files to non-ROM media -------- |
|
1131 |
||
1132 |
static void GetSpecialDrives() |
|
1133 |
/** |
|
1134 |
Work out which physical drive corresponds to each |
|
1135 |
numeric drive in the list of filenames. This populates |
|
1136 |
SpecialDrives. |
|
1137 |
||
1138 |
@see SpecialDrives |
|
1139 |
*/ |
|
1140 |
{ |
|
1141 |
test.Printf(_L("NoRemovable=%d\n"),NoRemovable); |
|
1142 |
||
1143 |
// mark each special drive as not present |
|
1144 |
for (TInt i = 0; i < KSpecialDriveCount; ++i) |
|
1145 |
{ |
|
1146 |
SpecialDrives[i] = '!'; |
|
1147 |
} |
|
1148 |
||
1149 |
// cannot load binaries from emulated removable drives |
|
1150 |
#if defined (__WINS__) |
|
1151 |
SpecialDrives[1] = 'c'; // "removable" |
|
1152 |
#endif |
|
1153 |
||
1154 |
TBuf<12> hashDir; |
|
1155 |
hashDir = KSysHash; |
|
1156 |
hashDir[0] = (TUint8) RFs::GetSystemDriveChar(); |
|
1157 |
||
1158 |
TInt r = Fs.MkDirAll(hashDir); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1159 |
test_Value(r, r == KErrNone || r == KErrAlreadyExists); |
0 | 1160 |
|
1161 |
for (TInt d = 0; d <= (TInt)sizeof(SpecialDriveList); ++d) |
|
1162 |
{ |
|
1163 |
TInt dr = SpecialDriveList[d]; |
|
1164 |
TDriveInfo di; |
|
1165 |
test.Printf(_L("Drive %d\n"), dr); |
|
1166 |
test(Fs.Drive(di, dr) == KErrNone); |
|
1167 |
if (di.iType == EMediaNotPresent) |
|
1168 |
continue; |
|
1169 |
||
1170 |
TChar ch0; |
|
1171 |
test(RFs::DriveToChar(dr, ch0) == KErrNone); |
|
1172 |
||
1173 |
TText ch = static_cast<TText>(TUint(ch0)); |
|
1174 |
||
1175 |
// drive 0 == internal |
|
1176 |
if ((di.iDriveAtt & KDriveAttInternal) && SpecialDrives[0] == '!') |
|
1177 |
{ |
|
1178 |
SpecialDrives[0] = ch; |
|
1179 |
if (NoRemovable) |
|
1180 |
SpecialDrives[1] = ch; |
|
1181 |
} |
|
1182 |
// drive 1 == removable |
|
1183 |
else if ((di.iDriveAtt & KDriveAttRemovable) && SpecialDrives[1] == '!' && !NoRemovable) |
|
1184 |
SpecialDrives[1] = ch; |
|
1185 |
else |
|
1186 |
{ |
|
1187 |
// drive not useful so continue and don't create \sys\bin |
|
1188 |
continue; |
|
1189 |
} |
|
1190 |
||
1191 |
TFileName fn; |
|
1192 |
fn.Append(ch); |
|
1193 |
fn.Append(_L(":\\sys\\bin\\")); |
|
1194 |
r = Fs.MkDirAll(fn); |
|
1195 |
test.Printf(_L("MkDirAll %S returns %d\n"), &fn, r); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1196 |
test_Value(r, r == KErrNone || r == KErrAlreadyExists); |
0 | 1197 |
} |
1198 |
} |
|
1199 |
||
1200 |
void GetNonZFileName(const TDesC& aOrigName, TDes& aNonZName) |
|
1201 |
/** |
|
1202 |
Resolve a special drive to the target drive using the mappings in |
|
1203 |
SpecialDrives. This is used to load non-XIP binaries from pageable media. |
|
1204 |
||
1205 |
@param aOrigName Fully-qualified filename with special drive number. |
|
1206 |
E.g., "3:\\sys\\bin\\dllt45.dll". |
|
1207 |
@param aNonZName Descriptor to populate with aOrigName and the transformed |
|
1208 |
drive, e.g. "c:\\sys\\bin\\dllt45.dll". |
|
1209 |
*/ |
|
1210 |
{ |
|
1211 |
test.Printf(_L(">GetNonZFileName,\"%S\"\n"), &aOrigName); |
|
1212 |
test(aOrigName[1] == ':'); |
|
1213 |
aNonZName.Copy(aOrigName); |
|
1214 |
TText replaceChar = SpecialDrives[aOrigName[0] - '0']; |
|
1215 |
test(TChar(replaceChar).IsAlpha()); |
|
1216 |
aNonZName[0] = replaceChar; |
|
1217 |
test.Printf(_L("<GetNonZFileName,\"%S\"\n"), &aNonZName); |
|
1218 |
} |
|
1219 |
||
1220 |
static void GetHashFileName(const TDesC& aOrigName, TDes& aHashName) |
|
1221 |
/** |
|
1222 |
Get name of the hash file used for an EXE or DLL which has been |
|
1223 |
copied to writable media. |
|
1224 |
||
1225 |
@param aOrigName Name of EXE or DLL which has been copied to |
|
1226 |
writable media. This does not have to be |
|
1227 |
qualified because only the name and extension |
|
1228 |
are used. |
|
1229 |
@param aHashName On return this is set to the absolute filename |
|
1230 |
which should contain the file's hash. This |
|
1231 |
function does not create the file, or its containing |
|
1232 |
directory. |
|
1233 |
*/ |
|
1234 |
{ |
|
1235 |
aHashName.Copy(KSysHash); |
|
1236 |
aHashName[0] = (TUint8) RFs::GetSystemDriveChar(); |
|
1237 |
const TParsePtrC ppc(aOrigName); |
|
1238 |
aHashName.Append(ppc.NameAndExt()); |
|
1239 |
} |
|
1240 |
||
1241 |
static void CopyExecutablesL(TBool aCorruptMode=EFalse) |
|
1242 |
/** |
|
1243 |
Make a copy of each executable that should be copied |
|
1244 |
to a writable drive. |
|
1245 |
||
1246 |
If aCorruptMode make KNumberOfCorruptFiles corrupted copies: truncated file and a file with corrupted header |
|
1247 |
||
1248 |
*/ |
|
1249 |
{ |
|
1250 |
TInt r; |
|
1251 |
TInt numCorruptFiles = 0; |
|
1252 |
||
1253 |
GetSpecialDrives(); |
|
1254 |
||
1255 |
CFileMan* fm = CFileMan::NewL(Fs); |
|
1256 |
||
1257 |
for (TInt i = 0; i < KNumModules; ++i) |
|
1258 |
{ |
|
1259 |
if (aCorruptMode && numCorruptFiles==KNumberOfCorruptFiles) |
|
1260 |
break; |
|
1261 |
||
1262 |
if (aCorruptMode && !(GetModuleFlags(i)&KModuleFlagExe)) |
|
1263 |
continue; |
|
1264 |
||
1265 |
const TPtrC fn = MODULE_FILENAME(i); |
|
1266 |
||
1267 |
// if this is an absolute filename then copy it to |
|
1268 |
// the appropriate drive. |
|
1269 |
if (fn[1] != ':') |
|
1270 |
continue; |
|
1271 |
||
1272 |
TFileName fnDest; |
|
1273 |
GetNonZFileName(fn, fnDest); |
|
1274 |
||
1275 |
||
1276 |
TFileName fnSrc(fn); |
|
1277 |
fnSrc[0] = 'z'; |
|
1278 |
||
1279 |
test.Printf(_L("CopyExecutables;%S,%S\n"), &fnSrc, &fnDest); |
|
1280 |
||
1281 |
#ifdef __WINS__ |
|
1282 |
const TParsePtrC sppc(fnSrc); |
|
1283 |
TBuf<MAX_PATH> sName; |
|
1284 |
r = MapEmulatedFileName(sName, sppc.NameAndExt()); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1285 |
test_KErrNone(r); |
0 | 1286 |
|
1287 |
TBuf<MAX_PATH> dName; |
|
1288 |
r = MapEmulatedFileName(dName, fnDest); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1289 |
test_KErrNone(r); |
0 | 1290 |
|
1291 |
BOOL b = Emulator::CopyFile((LPCTSTR)sName.PtrZ(),(LPCTSTR)dName.PtrZ(),FALSE); |
|
1292 |
test(b); |
|
1293 |
#else |
|
1294 |
r = fm->Copy(fnSrc, fnDest); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1295 |
test_KErrNone(r); |
0 | 1296 |
#endif |
1297 |
||
1298 |
r = Fs.SetAtt(fnDest, 0, KEntryAttReadOnly); |
|
1299 |
test.Printf(_L("CopyExecutables:setatt=%d\n"), r); |
|
1300 |
User::LeaveIfError(r); |
|
1301 |
||
1302 |
#ifdef __EPOC32__ |
|
1303 |
TInt moduleFlags = GetModuleFlags(i); |
|
1304 |
||
1305 |
// modify the new destination file by applying the required paging flags |
|
1306 |
RFile fNp; |
|
1307 |
r = fNp.Open(Fs, fnDest, EFileWrite | EFileStream); |
|
1308 |
User::LeaveIfError(r); |
|
1309 |
CleanupClosePushL(fNp); |
|
1310 |
||
1311 |
// read the header and get the total number of bytes to checksum. |
|
1312 |
// (This may be greater than sizeof(E32ImageHeader). |
|
1313 |
TPckgBuf<E32ImageHeader> hdrBuf; |
|
1314 |
r = fNp.Read(0, hdrBuf); |
|
1315 |
User::LeaveIfError(r); |
|
1316 |
TInt totalSize = hdrBuf().TotalSize(); |
|
1317 |
test.Printf(_L("np flags=0x%x,totalSize=%d\n"), hdrBuf().iFlags, totalSize); |
|
1318 |
||
1319 |
// read in the actual bytes to checksum |
|
1320 |
TUint8* startBytes0 = (TUint8*) User::AllocLC(totalSize); |
|
1321 |
TPtr8 startBytes(startBytes0, 0, totalSize); |
|
1322 |
r = fNp.Read(0, startBytes); |
|
1323 |
User::LeaveIfError(r); |
|
1324 |
test(startBytes.Length() == totalSize); |
|
1325 |
||
1326 |
// apply the required paging flags to the header |
|
1327 |
E32ImageHeader* hdr2 = reinterpret_cast<E32ImageHeader*>(startBytes0); |
|
1328 |
TUint& flags = hdr2->iFlags; |
|
1329 |
flags &= ~(KImageCodePaged | KImageCodeUnpaged); |
|
1330 |
if (moduleFlags & KModuleFlagPagedCode) |
|
1331 |
flags |= KImageCodePaged; |
|
1332 |
if (moduleFlags & KModuleFlagUnpagedCode) |
|
1333 |
flags |= KImageCodeUnpaged; |
|
1334 |
test.Printf(_L("setting new image flags 0x%x\n"), flags); |
|
1335 |
||
1336 |
// corrupt header of the 2nd file |
|
1337 |
if (aCorruptMode && numCorruptFiles==1 && (moduleFlags&KModuleFlagExe)) |
|
1338 |
{ |
|
1339 |
hdr2->iCodeBase += 3; |
|
1340 |
hdr2->iDataBase += 1; |
|
1341 |
hdr2->iImportOffset += 1; |
|
1342 |
hdr2->iCodeRelocOffset += 3; |
|
1343 |
hdr2->iDataRelocOffset += 3; |
|
1344 |
||
1345 |
++numCorruptFiles; |
|
1346 |
} |
|
1347 |
||
1348 |
// recalculate the checksum |
|
1349 |
hdr2->iHeaderCrc = KImageCrcInitialiser; |
|
1350 |
TUint32 crc = 0; |
|
1351 |
Mem::Crc32(crc, startBytes.Ptr(), totalSize); |
|
1352 |
hdr2->iHeaderCrc = crc; |
|
1353 |
r = fNp.Write(0, startBytes); |
|
1354 |
User::LeaveIfError(r); |
|
1355 |
||
1356 |
// truncate 1st corrupted file |
|
1357 |
if (aCorruptMode && numCorruptFiles==0 && (moduleFlags&KModuleFlagExe)) |
|
1358 |
{ |
|
1359 |
TInt size; |
|
1360 |
r = fNp.Size(size); |
|
1361 |
User::LeaveIfError(r); |
|
1362 |
// if trncate by 1 it managed to load. if trancate by 3 it failed to load with KErrCorrupt as expected |
|
1363 |
r = fNp.SetSize(size-3); |
|
1364 |
User::LeaveIfError(r); |
|
1365 |
++numCorruptFiles; |
|
1366 |
} |
|
1367 |
||
1368 |
CleanupStack::PopAndDestroy(2, &fNp); // startBytes0, fNp |
|
1369 |
#endif |
|
1370 |
||
1371 |
// if copied to removable media, then generate hash |
|
1372 |
if (fn[0] == '0') |
|
1373 |
continue; |
|
1374 |
||
1375 |
CSHA1* sha1 = CSHA1::NewL(); |
|
1376 |
CleanupStack::PushL(sha1); |
|
1377 |
||
1378 |
RFile fDest; |
|
1379 |
r = fDest.Open(Fs, fnDest, EFileRead | EFileStream); |
|
1380 |
User::LeaveIfError(r); |
|
1381 |
CleanupClosePushL(fDest); |
|
1382 |
||
1383 |
TBool done; |
|
1384 |
TBuf8<512> content; |
|
1385 |
do |
|
1386 |
{ |
|
1387 |
r = fDest.Read(content); |
|
1388 |
User::LeaveIfError(r); |
|
1389 |
done = (content.Length() == 0); |
|
1390 |
if (! done) |
|
1391 |
sha1->Update(content); |
|
1392 |
} while (! done); |
|
1393 |
CleanupStack::PopAndDestroy(&fDest); |
|
1394 |
||
1395 |
// write hash to \sys\hash |
|
1396 |
TBuf8<SHA1_HASH> hashVal = sha1->Final(); |
|
1397 |
||
1398 |
// reuse fnSrc to save stack space |
|
1399 |
GetHashFileName(fnDest, fnSrc); |
|
1400 |
RFile fHash; |
|
1401 |
r = fHash.Replace(Fs, fnSrc, EFileWrite | EFileStream); |
|
1402 |
test.Printf(_L("hash file,%S,r=%d\n"), &fnSrc, r); |
|
1403 |
User::LeaveIfError(r); |
|
1404 |
CleanupClosePushL(fHash); |
|
1405 |
r = fHash.Write(hashVal); |
|
1406 |
User::LeaveIfError(r); |
|
1407 |
||
1408 |
CleanupStack::PopAndDestroy(2, sha1); |
|
1409 |
} |
|
1410 |
||
1411 |
delete fm; |
|
1412 |
} |
|
1413 |
||
1414 |
static void DeleteExecutables(TBool aCorruptMode=EFalse) |
|
1415 |
/** |
|
1416 |
Delete any executables which were created by CopyExecutables. |
|
1417 |
This function is defined so the test cleans up when it has finished. |
|
1418 |
*/ |
|
1419 |
{ |
|
1420 |
TInt numCorruptFiles = 0; |
|
1421 |
||
1422 |
for (TInt i = 0; i < KNumModules; ++i) |
|
1423 |
{ |
|
1424 |
if (aCorruptMode && numCorruptFiles==KNumberOfCorruptFiles) |
|
1425 |
break; |
|
1426 |
||
1427 |
if (aCorruptMode && !(GetModuleFlags(i)&KModuleFlagExe)) |
|
1428 |
continue; |
|
1429 |
||
1430 |
const TPtrC fn = MODULE_FILENAME(i); |
|
1431 |
||
1432 |
// if this is an absolute filename then copy it to |
|
1433 |
// the appropriate drive. |
|
1434 |
if (fn[1] != ':') |
|
1435 |
continue; |
|
1436 |
||
1437 |
test.Printf(_L("DeleteExecutables:fn=%S\n"), &fn); |
|
1438 |
TFileName fnDest; |
|
1439 |
GetNonZFileName(fn, fnDest); |
|
1440 |
||
1441 |
TInt r; |
|
1442 |
||
1443 |
r = Fs.Delete(fnDest); |
|
1444 |
test.Printf(_L("DeleteExecutables:fnDest=%S,del=%d\n"), &fnDest, r); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1445 |
test_KErrNone(r); |
0 | 1446 |
|
1447 |
// only need to delete hash files for binaries copied to removable media, |
|
1448 |
// but simpler to delete and test for KErrNotFound |
|
1449 |
TFileName fnHash; |
|
1450 |
GetHashFileName(fnDest, fnHash); |
|
1451 |
r = Fs.Delete(fnHash); |
|
1452 |
test.Printf(_L("DeleteExecutables,h=%S,hdel=%d\n"), &fnHash, r); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1453 |
test_Value(r, r == KErrPathNotFound || r == KErrNotFound || r == KErrNone); |
0 | 1454 |
|
1455 |
if (aCorruptMode) |
|
1456 |
++numCorruptFiles; |
|
1457 |
} |
|
1458 |
} |
|
1459 |
||
1460 |
GLDEF_C TInt E32Main() |
|
1461 |
{ |
|
1462 |
RThread().SetPriority(EPriorityLess); |
|
1463 |
||
1464 |
test.Title(); |
|
1465 |
test.Start(_L("Setup")); |
|
1466 |
||
1467 |
RLoader l; |
|
1468 |
test(l.Connect()==KErrNone); |
|
1469 |
test(l.CancelLazyDllUnload()==KErrNone); |
|
1470 |
l.Close(); |
|
1471 |
||
1472 |
test(TestLdd.Open()==KErrNone); |
|
1473 |
LoaderTest* pL=LoaderTest::New(); |
|
1474 |
TheLoaderTest=pL; |
|
1475 |
||
1476 |
TInt tm=pL->iCmdLine[0]; |
|
1477 |
TInt nr = (tm>>4)&3; |
|
1478 |
if (nr==1) |
|
1479 |
NoRemovable = ETrue; |
|
1480 |
else if (nr==2) |
|
1481 |
NoRemovable = EFalse; |
|
1482 |
||
1483 |
test(Fs.Connect() == KErrNone); |
|
1484 |
||
1485 |
// allocate a cleanup stack so can call CFileMan::NewL in CopyExecutables |
|
1486 |
test.Printf(_L("CopyExecutablesL()\n")); |
|
1487 |
CTrapCleanup* cleanup=CTrapCleanup::New(); |
|
1488 |
TRAPD(r, CopyExecutablesL()); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1489 |
test_KErrNone(r); |
0 | 1490 |
delete cleanup; |
1491 |
||
1492 |
if (tm&1) |
|
1493 |
pL->TestOneByOne(); |
|
1494 |
if (tm&2) |
|
1495 |
pL->TestMultipleExeInstances(); |
|
1496 |
if (tm&4) |
|
1497 |
pL->TestOOM(); |
|
1498 |
if (tm&8) |
|
1499 |
pL->TestMultipleLoads(); |
|
1500 |
||
1501 |
pL->Close(); |
|
1502 |
||
1503 |
// Test loader error handling - will panic the client thread |
|
1504 |
test.Next(_L("Test loader error handling - will panic the client thread")); |
|
1505 |
RThread t; |
|
1506 |
t.Create(_L("Loader panic test"),PanicTestThread,KDefaultStackSize,0x1000,0x1000,NULL); |
|
1507 |
TRequestStatus s; |
|
1508 |
t.Logon(s); |
|
1509 |
TBool justInTime=User::JustInTime(); |
|
1510 |
User::SetJustInTime(EFalse); |
|
1511 |
t.Resume(); |
|
1512 |
User::WaitForRequest(s); |
|
1513 |
test(t.ExitType()==EExitPanic); |
|
1514 |
test(t.ExitCategory().Compare(_L("LOADER"))==0); |
|
1515 |
test(t.ExitReason()==0); |
|
1516 |
t.Close(); |
|
1517 |
User::SetJustInTime(justInTime); |
|
1518 |
||
1519 |
DeleteExecutables(); |
|
1520 |
||
1521 |
#ifdef __EPOC32__ |
|
1522 |
// test corrupted files |
|
1523 |
cleanup=CTrapCleanup::New(); |
|
1524 |
test.Next(_L("CopyExecutablesL(ETrue)")); |
|
1525 |
TRAPD(rr, CopyExecutablesL(ETrue)); |
|
1526 |
test(rr == KErrNone); |
|
1527 |
delete cleanup; |
|
1528 |
test.Next(_L("TestCorruptedFiles()")); |
|
1529 |
TestCorruptedFiles(); |
|
1530 |
test.Next(_L("DeleteExecutables()")); |
|
1531 |
DeleteExecutables(ETrue); |
|
1532 |
#endif |
|
1533 |
||
1534 |
Fs.Close(); |
|
1535 |
||
1536 |
test.End(); |
|
1537 |
return KErrNone; |
|
1538 |
} |
|
1539 |