Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // f32test\loader\t_ldrtst2.cpp
20 extern TInt GetModuleFlags(TInt);
22 inline TBool AlwaysLoaded(TInt aModule)
25 TUint32 f=GetModuleFlags(aModule);
26 return ( (f&(KModuleFlagExe|KModuleFlagDataInTree|KModuleFlagXIP)) == (TUint32)KModuleFlagXIP );
28 TUint32 f=GetModuleFlags(aModule);
29 return ( (f&(KModuleFlagExe|KModuleFlagDataInTree)) == 0 );
33 TInt Order(const SModuleInstance& m1, const SModuleInstance& m2)
35 return TInt(m1.iCodeSeg)-TInt(m2.iCodeSeg);
38 CGlobalModuleList::CGlobalModuleList()
39 : iModules(KNumModules)
43 CGlobalModuleList::~CGlobalModuleList()
46 User::Free(iModuleAlloc);
48 for (i=0; i<KNumModules; ++i)
54 void CGlobalModuleList::Init()
56 TBool proc_sym=(iMemModelAtt & (EMemModelAttrSameVA|EMemModelAttrSupportFixed))==EMemModelAttrSameVA;
58 for (i=0; i<KNumModules; ++i)
60 TUint32 f=GetModuleFlags(i);
64 if (!proc_sym && (f&KModuleFlagFixed))
68 iMaxModules=(1+iFixedExes)*(KNumModules-iNumExes)+iNumExes;
69 test.Printf(_L("iNumExes=%d iFixedExes=%d iMaxModules=%d\n"),iNumExes,iFixedExes,iMaxModules);
70 SModuleInstance* mi=(SModuleInstance*)User::Alloc(iMaxModules*sizeof(SModuleInstance));
74 SModuleInstance* miE=mi+iMaxModules;
77 SModuleInstance* miN=mi+1;
78 mi->iCodeSeg=(miN<miE)?miN:NULL;
80 for (i=0; i<KNumModules; ++i)
82 TUint32 f=GetModuleFlags(i);
85 CPerProcessInfo* p=CPerProcessInfo::New(i,*this);
91 CGlobalModuleList* CGlobalModuleList::New(const LoaderTest& a)
93 CGlobalModuleList* p=new CGlobalModuleList;
95 test.Printf(_L("CGlobalModuleList at %08x\n"),p);
97 p->iMemModelAtt=a.iMemModelAtt;
102 void CGlobalModuleList::Free(SModuleInstance* a)
104 a->iCodeSeg=iFreeModules;
108 SModuleInstance* CGlobalModuleList::GetMI()
110 SModuleInstance* p=iFreeModules;
112 iFreeModules=(SModuleInstance*)p->iCodeSeg;
116 TAny* CGlobalModuleList::CodeSegFromHandle(TModuleHandle aModHandle)
118 return iDev.ModuleCodeSeg(aModHandle);
121 void CGlobalModuleList::Close(SModuleInstance* a)
123 test.Printf(_L("Module %d@%08x Close(%d)\n"),a->iModNum,a->iCodeSeg,a->iAccessCount);
124 if (!--a->iAccessCount)
126 TCodeSegCreateInfo codeSeg;
127 TInt r=iDev.GetCodeSegInfo(a->iCodeSeg, codeSeg);
128 test(r==KErrArgument);
129 r=iModules.FindInOrder(a, Order);
137 void CGlobalModuleList::CheckAll()
140 for (i=0; i<KNumModules; ++i)
147 TInt CGlobalModuleList::Load(TInt aExeNum, TInt aDllNum)
149 return iPPInfo[aExeNum]->Load(aDllNum);
152 TInt CGlobalModuleList::CloseHandle(TInt aExeNum, TInt aDllNum)
154 CPerProcessInfo* p=iPPInfo[aExeNum];
156 for (i=0; i<KMaxHandles && p->iModuleNum[i]!=aDllNum; ++i) {}
159 return p->CloseHandle(i);
162 CPerProcessInfo::CPerProcessInfo()
164 Mem::Fill(iModuleNum, sizeof(iModuleNum), 0xff);
167 CPerProcessInfo::~CPerProcessInfo()
169 if (iSession.Handle())
173 User::WaitForRequest(iStatus);
174 test(iProcess.ExitType()==EExitKill);
175 test(iProcess.ExitReason()==KErrNone);
180 CPerProcessInfo* CPerProcessInfo::New(TInt aExeNum, CGlobalModuleList& aG)
182 CPerProcessInfo* p=new CPerProcessInfo;
184 test.Printf(_L("CPerProcessInfo for %d at %08x\n"),aExeNum,p);
195 TInt CPerProcessInfo::Init()
198 TInt r=LoadExe(iExeNum, 0, iProcess, tt);
199 test.Printf(_L("LoadExe(%d)->%d\n"),iExeNum,r);
202 test.Printf(_L("BENCHMARK: LoadExe(%d)->%dms\n"),iExeNum,tt);
204 test(r==KErrNone || r==KErrNotSupported);
208 iProcess.Logon(iStatus);
209 test(iStatus==KRequestPending);
210 r=iSession.Connect(iExeNum);
211 test.Printf(_L("Connect(%d)->%d\n"),iExeNum,r);
213 TModuleList exe_info;
214 r=iSession.GetExeDepList(exe_info.iInfo);
216 test.Printf(_L("GetExeDepList(%d)->%d count %d\n"),iExeNum,r,exe_info.iCount);
218 r=AddModules(iExeNum, NULL, &exe_info);
219 test.Printf(_L("AddModules->%d\n"),r);
224 void CPerProcessInfo::GetModuleSet(TModuleSet& aSet)
227 for (m=0; m<KNumModules; ++m)
229 if (iHandleCount[m]==0 && m!=iExeNum)
232 const TInt* deps=ModuleDependencies[m];
235 for (i=0; i<ndeps; ++i)
239 // Emulator doesn't register subtrees without data
240 TInt f = GetModuleFlags(dm);
241 if (f & KModuleFlagDataInTree)
248 void CPerProcessInfo::Check()
250 test.Printf(_L("%d:Check\n"),iExeNum);
251 TBool code_prot=iGlobalList->iMemModelAtt&EMemModelAttrRamCodeProt;
252 TBool data_prot=iGlobalList->iMemModelAtt&EMemModelAttrProcessProt;
253 TInt mmtype=iGlobalList->iMemModelAtt&EMemModelTypeMask;
257 for (m=0; m<KNumModules; ++m)
259 TUint32 f=GetModuleFlags(m);
262 test.Printf(_L("%d "),m);
263 SModuleInstance* pM=iModules[m];
265 test(iSession.CheckReadable(pM->iEntryPointAddress)==KErrNone);
266 if (f&KModuleFlagData)
267 test(iSession.CheckReadable(pM->iData)==KErrNone);
271 SModuleInstance* pM=iModules[m];
276 TInt c=iGlobalList->iModules.Count();
277 test.Printf(_L("\n%d:CheckNP\n"),iExeNum);
278 for (ix=0; ix<c; ++ix)
280 const SModuleInstance* pM=iGlobalList->iModules[ix];
281 if (set.Present(pM->iModNum))
283 test.Printf(_L("%d "),pM->iModNum);
284 TUint32 f=GetModuleFlags(pM->iModNum);
285 if (!(f&KModuleFlagXIP) && code_prot)
287 if(mmtype==EMemModelTypeFlexible && (f&KModuleFlagExe))
289 // don't test EXEs on FlexibleMM because they don't live at unique addresses
293 // check code not loaded into this porcess....
294 test(iSession.CheckReadable(pM->iEntryPointAddress)==KErrGeneral);
297 TBool check_data=(f&(KModuleFlagData|KModuleFlagExe))==(TUint32)KModuleFlagData;
298 if (check_data && mmtype==EMemModelTypeMoving)
300 if (f&KModuleFlagXIP)
302 const TInt* exeinfo=ModuleExeInfo[pM->iModNum];
303 TInt attp=exeinfo[0];
304 if (attp>=0 && (GetModuleFlags(attp)&KModuleFlagFixed))
308 if (check_data && data_prot)
309 test(iSession.CheckReadable(pM->iData)==KErrGeneral);
312 for (h=0; h<KMaxHandles; ++h)
317 test(set.Present(m));
318 TInt y=++iGlobalList->iParam;
319 TInt r=iSession.CallRBlkI(h,y);
322 test.Printf(_L("DLL %d RBlkI->%d\n"),m,r);
323 y=ModuleRBlkIParams[m][1]+ModuleRBlkIParams[m][0]*DLLNUMOFFSET;
328 void CPerProcessInfo::Unlink(const SDllInfo& a, TModuleList& aList)
330 test.Printf(_L("%d:Unlink %d %08x\n"),iExeNum,a.iDllNum,a.iModuleHandle);
331 test(iHandleCount[a.iDllNum]==0);
332 TBool code_prot=iGlobalList->iMemModelAtt&EMemModelAttrRamCodeProt;
333 TBool data_prot=iGlobalList->iMemModelAtt&EMemModelAttrProcessProt;
334 TInt mmtype=iGlobalList->iMemModelAtt&EMemModelTypeMask;
337 set.Display(_L("set: "));
339 for (m=0; m<KNumModules; ++m)
343 SModuleInstance* pM=iModules[m];
347 TUint32 f=GetModuleFlags(m);
350 info.iEntryPointAddress=pM->iEntryPointAddress;
351 info.iModuleHandle=pM->iModuleHandle;
353 test(pM->iModNum==m);
354 if (!(f&KModuleFlagXIP) && code_prot)
355 test(iSession.CheckReadable(pM->iEntryPointAddress)==KErrGeneral);
356 TBool check_data=f&KModuleFlagData;
357 if (check_data && mmtype==EMemModelTypeMoving)
359 if (f&KModuleFlagXIP)
361 const TInt* exeinfo=ModuleExeInfo[pM->iModNum];
362 TInt attp=exeinfo[0];
363 if (attp>=0 && (GetModuleFlags(attp)&KModuleFlagFixed))
367 if (check_data && data_prot)
368 test(iSession.CheckReadable(pM->iData)==KErrGeneral);
369 iGlobalList->Close(pM);
373 TInt CPerProcessInfo::CloseHandle(TInt aHandle)
375 TInt m=iModuleNum[aHandle];
377 iModuleNum[aHandle]=-1;
378 SModuleInstance* pM=iModules[m];
382 dll_info.iEntryPointAddress=pM->iEntryPointAddress;
383 dll_info.iModuleHandle=pM->iModuleHandle;
385 TInt r=iSession.CloseDll(aHandle);
387 r=iSession.GetCDList(d_list.iInfo);
390 if (--iHandleCount[m])
392 test(d_list.iCount==0);
396 if (!AlwaysLoaded(m))
397 Unlink(dll_info, xd_list);
400 for (i=0; i<xd_list.iCount; ++i)
402 TInt mn=xd_list.iInfo[i].iDllNum;
403 TUint32 f=GetModuleFlags(mn);
404 if (f&KModuleFlagData)
407 test(d_list.IsPresent(mn));
410 d_list.Display(_L("d_list: "));
411 xd_list.Display(_L("xd_list: "));
412 test(dcount==d_list.iCount);
416 TInt CPerProcessInfo::Load(TInt aDllNum)
418 TModuleList init_list;
420 TInt h=iSession.LoadDll(aDllNum, init_list.iInfo);
421 init_list.SetCount();
422 test.Printf(_L("%d:Load(%d)->%d Icount %d\n"),iExeNum,aDllNum,h,init_list.iCount);
427 test(iSession.GetCDList(c_list.iInfo)==KErrNone);
429 iModuleNum[h]=aDllNum;
430 return AddModules(aDllNum, &c_list, &init_list);
433 TInt CPerProcessInfo::AddModules(TInt aDllNum, TModuleList* aCList, TModuleList* aIList)
436 if (++iHandleCount[aDllNum]>1)
439 test(aCList->iCount==0);
443 if (!iModules[aDllNum] && !AlwaysLoaded(aDllNum))
445 const TInt* deps=ModuleDependencies[aDllNum];
449 for (i=0; i<ndeps; ++i)
452 if (!iModules[dm] && !AlwaysLoaded(dm))
455 if (GetModuleFlags(dm)&KModuleFlagData)
460 test(ccount==aCList->iCount);
461 for (i=0; i<KNumModules; ++i)
468 if (GetModuleFlags(i)&KModuleFlagData)
471 test(aCList->Find(i)>=0);
473 TInt j=aIList->Find(i);
475 mi.iEntryPointAddress=aIList->iInfo[j].iEntryPointAddress;
476 mi.iModuleHandle=aIList->iInfo[j].iModuleHandle;
477 mi.iCodeSeg=iGlobalList->CodeSegFromHandle(mi.iModuleHandle);
478 test(mi.iCodeSeg!=NULL);
479 if (GetModuleFlags(i)&KModuleFlagData)
481 TCodeSegCreateInfo cs_info;
482 r=iDev.GetCodeSegInfo(mi.iCodeSeg, cs_info);
484 mi.iData=cs_info.iDataRunAddress;
491 r=iGlobalList->iModules.FindInOrder(&mi, Order);
494 test.Printf(_L("Module %d@%08x already exists\n"),mi.iModNum,mi.iCodeSeg);
495 SModuleInstance& mi0=*iGlobalList->iModules[r];
497 test(mi.iEntryPointAddress==mi0.iEntryPointAddress);
498 test(mi.iModuleHandle==mi0.iModuleHandle);
499 test(mi.iData==mi0.iData);
500 test(mi.iModNum==mi0.iModNum);
505 test.Printf(_L("Module %d@%08x new\n"),mi.iModNum,mi.iCodeSeg);
506 SModuleInstance* pM=iGlobalList->GetMI();
510 r=iGlobalList->iModules.InsertInOrder(pM, Order);
517 void LoaderTest::TestMultipleLoads()
519 CGlobalModuleList* p=CGlobalModuleList::New(*this);
523 const TInt* multiLoad[] = {TC_MultLoad,0};
525 const TInt* multiLoad[] = {TC_MultLoad,TC_MultLoadTargetOnly,0};
527 const TInt** multiLoadLists = multiLoad;
529 while((tests=*multiLoadLists++)!=0)
531 TInt ntests=*tests++;
539 TUint32 xf1=GetModuleFlags(exe1);
540 TUint32 xf2=GetModuleFlags(exe2);
541 if (xf1&KModuleFlagExe)
543 TInt r=p->Load(exe1, dll1);
544 test.Printf(_L("%d:Load %d->%d"),exe1,dll1,r);
547 if (xf2&KModuleFlagExe)
549 TInt r=p->CloseHandle(exe2, dll2);
550 test.Printf(_L("%d:Close %d->%d"),exe2,dll2,r);