Update contrib.
1 // Copyright (c) 2003-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 // e32test\dll\t_xxver2.cpp
16 // Test matching algorithm for DLL versions. Test aspects of DLL and EXE files.
20 // - This test makes use of 4 versions of a single DLL, and 15 EXEs which link
21 // against it. The EXEs all have different reqirements on which DLL versions
23 // - Test that the correct version of linked libraries are used (Run for each
24 // EXE and for the 16 combinations in which the 4 versions of the DLL can be
25 // available. The test is performed with each EXE run in sequence, and again
26 // with all of them run at the same time)
27 // - Test that the correct version of dynamically loaded libraries are used and
28 // the libary exports are as expected. (Run for each DLL version and for the
29 // 16 combinations of DLL availability)
30 // - Test that RLibrary::GetInfo and RLibrary::GetInfoFromHeader return the
31 // expected data for all DLLs and EXEs
32 // Platforms/Drives/Compatibility:
34 // Assumptions/Requirement/Pre-requisites:
35 // Failures and causes:
36 // Base Port information:
46 RTest test(_L("T_XXVER2"));
51 TBuf<8> SourcePath = _S16("Z:\\img\\");
56 _LIT(KDestPath, "C:\\system\\bin\\ver");
57 _LIT(KDestPathSysBin, "C:\\sys\\bin\\ver");
58 if(PlatSec::ConfigSetting(PlatSec::EPlatSecEnforceSysBin))
59 return KDestPathSysBin();
64 _LIT(KDllName0, "t_ver2{00010000}.dll");
65 _LIT(KDllName1, "t_ver2{00010001}.dll");
66 _LIT(KDllName2, "t_ver2{00020000}.dll");
67 _LIT(KDllName3, "t_ver2.dll");
69 const TDesC* const DllArray[] =
77 const TInt KNumDlls = sizeof(DllArray)/sizeof(const TDesC* const);
79 const TInt DllVersion[KNumDlls] =
87 const TInt KNumTestVersions = 7;
88 const TInt TestDllVersion[KNumTestVersions] =
99 _LIT(KExeName0, "t_xver2a.exe"); // request 1.0 work with any
100 _LIT(KExeName1, "t_xver2b.exe"); // request 1.0 work with 2.0 but not 3.0
101 _LIT(KExeName2, "t_xver2c.exe"); // request 1.0 don't work with 2.0
102 _LIT(KExeName3, "t_xver2d.exe"); // request 1.1 work with 1.0 but not 2.0
103 _LIT(KExeName4, "t_xver2e.exe"); // request 1.1 work with any
104 _LIT(KExeName5, "t_xver2f.exe"); // request 1.1 work with 2.0, 3.0 but not with 1.0
105 _LIT(KExeName6, "t_xver2g.exe"); // request 1.1 don't work with 2.0, 3.0 or 1.0
106 _LIT(KExeName7, "t_xver2h.exe"); // request 1.1 work with 1.0 and 2.0 but not 3.0
107 _LIT(KExeName8, "t_xver2i.exe"); // request 1.1 work with 2.0 but not 3.0 or 1.0
108 _LIT(KExeName9, "t_xver2j.exe"); // request 2.0 only use 1.0 exports
109 _LIT(KExeName10, "t_xver2k.exe"); // request 2.0 only use 1.0, 1.1 exports
110 _LIT(KExeName11, "t_xver2l.exe"); // request 2.0 use 2.0 exports work on 3.0
111 _LIT(KExeName12, "t_xver2m.exe"); // request 2.0 use 2.0 exports, don't work on 3.0
112 _LIT(KExeName13, "t_xver2n.exe"); // request 3.0 use 1.0 exports only
113 _LIT(KExeName14, "t_xver2o.exe"); // request 3.0 use all
115 const TDesC* const ExeArray[] =
134 const TInt KNumExes = sizeof(ExeArray)/sizeof(const TDesC* const);
136 const TInt ResultArray[KNumExes<<KNumDlls] =
138 // DLLs Present A B C D E F G H I J K L M N O
140 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
142 0, 0, 0, 0, 0, -1, -1, 0, -1, -1, -1, -1, -1, -1, -1,
144 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1,
146 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1,
148 2, 2, -1, -1, 2, 2, -1, 2, 2, 2, 2, 2, 2, -1, -1,
150 0, 0, 0, 0, 2, 2, -1, 2, 2, 2, 2, 2, 2, -1, -1,
152 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, -1, -1,
154 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, -1, -1,
156 3, -1, -1, -1, 3, 3, -1, -1, -1, 3, 3, 3, -1, 3, 3,
158 0, 0, 0, 0, 3, 3, -1, 0, -1, 3, 3, 3, -1, 3, 3,
160 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3, 3, -1, 3, 3,
162 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3, 3, -1, 3, 3,
164 2, 2, -1, -1, 2, 2, -1, 2, 2, 2, 2, 2, 2, 3, 3,
166 0, 0, 0, 0, 2, 2, -1, 2, 2, 2, 2, 2, 2, 3, 3,
168 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3,
169 // 3.0, 2.0, 1.1, 1.0
170 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3
174 const TInt ResultArray2[KNumTestVersions<<KNumDlls] =
176 // DLLs Present 0.0 1.0 1.1 1.2 2.0 3.0 4.0
178 -1, -1, -1, -1, -1, -1, -1,
180 -1, 0, -1, -1, -1, -1, -1,
182 -1, 1, 1, -1, -1, -1, -1,
184 -1, 1, 1, -1, -1, -1, -1,
186 -1, -1, -1, -1, 2, -1, -1,
188 -1, 0, -1, -1, 2, -1, -1,
190 -1, 1, 1, -1, 2, -1, -1,
192 -1, 1, 1, -1, 2, -1, -1,
194 -1, -1, -1, -1, -1, 3, -1,
196 -1, 0, -1, -1, -1, 3, -1,
198 -1, 1, 1, -1, -1, 3, -1,
200 -1, 1, 1, -1, -1, 3, -1,
202 -1, -1, -1, -1, 2, 3, -1,
204 -1, 0, -1, -1, 2, 3, -1,
206 -1, 1, 1, -1, 2, 3, -1,
207 // 3.0, 2.0, 1.1, 1.0
208 -1, 1, 1, -1, 2, 3, -1
219 const TInt Dll0ExportInfo[] = {19,0};
220 const TInt Dll1ExportInfo[] = {29,0};
221 const TInt Dll2ExportInfo[] = {39,4,2,3,23,24};
222 const TInt Dll3ExportInfo[] = {59,6,2,3,4,23,24,39};
224 const SExportInfo* const DllExportInfo[KNumDlls] =
226 (const SExportInfo*)Dll0ExportInfo,
227 (const SExportInfo*)Dll1ExportInfo,
228 (const SExportInfo*)Dll2ExportInfo,
229 (const SExportInfo*)Dll3ExportInfo
232 void CheckExports(TInt aDllNum, RLibrary aLib)
234 test.Printf(_L("Testing exports for DLL %d\n"), aDllNum);
235 const TFileName& fn = aLib.FileName();
236 test.Printf(_L("Filename %S\n"), &fn);
237 const SExportInfo* e = DllExportInfo[aDllNum];
238 TAny* libcs = LdrTest.LibraryCodeSeg(aLib.Handle());
239 test.Printf(_L("Code seg @%08x\n"), libcs);
244 for (ord=1; ord<=n+1; ++ord)
246 TLibraryFunction f = aLib.Lookup(ord);
247 test.Printf(_L("Ord %3d->%08x\n"), ord, f);
254 for (i=0; i<nh && e->iHole[i]!=ord; ++i) {}
259 TAny* cs = LdrTest.CodeSegFromAddr((TLinAddr)f);
260 test(f ? (cs==libcs) : !cs);
264 void CreateAndPopulateDir(TUint aMask)
266 test.Printf(_L("CreateAndPopulateDir %d\n"), aMask);
267 TFileName fn = KDestPath();
268 fn.AppendNumFixedWidth(aMask, EDecimal, 2);
270 TInt r = gFs.MkDirAll(fn);
271 test.Printf(_L("MkDir %S->%d\n"), &fn, r);
272 test(r==KErrNone || r==KErrAlreadyExists);
274 fn2.Append(_L("*.*"));
277 r = gFileMan->Attribs(fn2, 0, KEntryAttReadOnly|KEntryAttHidden|KEntryAttSystem|KEntryAttArchive, now);
278 test.Printf(_L("Attribs %S->%d\n"), &fn2, r);
279 r = gFileMan->Delete(fn2);
280 test.Printf(_L("Delete %S->%d\n"), &fn2, r);
282 for (; aMask; aMask>>=1, ++n)
287 fn2.Append(*DllArray[n]);
288 TFileName src = SourcePath;
289 src.Append(*DllArray[n]);
290 r = gFileMan->Copy(src, fn2);
291 test.Printf(_L("%S->%S (%d)\n"), &src, &fn2, r);
294 for (n=0; n<KNumExes; ++n)
297 fn2.Append(*ExeArray[n]);
298 TFileName src = SourcePath;
299 src.Append(*ExeArray[n]);
300 r = gFileMan->Copy(src, fn2);
301 test.Printf(_L("%S->%S (%d)\n"), &src, &fn2, r);
306 void RunExe(TUint aMask, TInt aExeNum)
308 test.Printf(_L("RunExe mask %d exenum %d\n"), aMask, aExeNum);
311 TFileName fn = KDestPath();
312 fn.AppendNumFixedWidth(aMask, EDecimal, 2);
314 fn.Append(*ExeArray[aExeNum]);
315 TInt r = p.Create(fn, KNullDesC);
316 test.Printf(_L("Create %S->%d\n"), &fn, r);
317 TInt rix = aExeNum + KNumExes*TInt(aMask);
318 TInt expected = ResultArray[rix];
319 test.Printf(_L("RunExe expected %d\n"), expected);
327 User::WaitForRequest(s);
328 if (p.ExitType()!=EExitKill)
330 TInt et = p.ExitType();
331 TInt er = p.ExitReason();
332 const TDesC& ec = p.ExitCategory();
333 test.Printf(_L("Exit %d,%d,%S\n"), et, er, &ec);
337 test.Printf(_L("Return code %08x\n"), s.Int());
338 test(s.Int() == DllVersion[expected]);
341 void RunExes(TUint aMask)
343 test.Printf(_L("RunExes mask %d\n"), aMask);
344 RProcess p[KNumExes];
345 TRequestStatus s[KNumExes];
347 for (xn=0; xn<KNumExes; ++xn)
349 TFileName fn = KDestPath();
350 fn.AppendNumFixedWidth(aMask, EDecimal, 2);
352 fn.Append(*ExeArray[xn]);
353 TInt r = p[xn].Create(fn, KNullDesC);
354 test.Printf(_L("Create %S->%d\n"), &fn, r);
355 TInt rix = xn + KNumExes*TInt(aMask);
356 TInt expected = ResultArray[rix];
357 test.Printf(_L("RunExe expected %d\n"), expected);
365 for (xn=0; xn<KNumExes; ++xn)
367 TInt rix = xn + KNumExes*TInt(aMask);
368 TInt expected = ResultArray[rix];
373 for (xn=0; xn<KNumExes; ++xn)
375 TInt rix = xn + KNumExes*TInt(aMask);
376 TInt expected = ResultArray[rix];
379 User::WaitForRequest(s[xn]);
380 if (p[xn].ExitType()!=EExitKill)
382 TInt et = p[xn].ExitType();
383 TInt er = p[xn].ExitReason();
384 const TDesC& ec = p[xn].ExitCategory();
385 test.Printf(_L("Exit %d,%d,%S\n"), et, er, &ec);
388 CLOSE_AND_WAIT(p[xn]);
389 test.Printf(_L("Return code %08x\n"), s[xn].Int());
390 test(s[xn].Int() == DllVersion[expected]);
394 void TestDynamic(TUint aMask, TInt aTN)
396 TUint32 ver = TestDllVersion[aTN];
397 TInt rix = aTN + KNumTestVersions*TInt(aMask);
398 TInt expected = ResultArray2[rix];
399 test.Printf(_L("ReqVer %08x Expected %d\n"), ver, expected);
400 TFileName path = KDestPath();
401 path.AppendNumFixedWidth(aMask, EDecimal, 2);
403 fn.Append(_L("\\T_VER2.DLL"));
405 TInt r = l.Load(fn, KNullDesC, TUidType(), ver);
406 test.Printf(_L("Load %S returns %d\n"), &fn, r);
412 TLibraryFunction f = l.Lookup(1);
414 TInt result = (*f)();
415 test.Printf(_L("Ord 1 returns %08x\n"), result);
416 test(result == DllVersion[expected]);
418 r = l.Load(_L("T_VER2.DLL"), path, TUidType(), ver);
419 test.Printf(_L("Load T_VER2.DLL path %S returns %d\n"), &path, r);
428 test.Printf(_L("Ord 1 returns %08x\n"), result);
429 test(result == DllVersion[expected]);
430 CheckExports(expected, l);
434 void TestLibraryInfo(TInt aN)
437 if(PlatSec::ConfigSetting(PlatSec::EPlatSecEnforceSysBin))
438 fn = _S16("C:\\sys\\bin\\ver15\\");
440 fn = _S16("C:\\system\\bin\\ver15\\");
442 test.Printf(_L("Getting info for %S\n"), &fn);
443 TBool formHeader=EFalse;
446 RLibrary::TInfoV2 info;
447 TPckg<RLibrary::TInfoV2> infoBuf(info);
454 test(fs.Connect()==KErrNone);
456 test((r=file.Open(fs,fn,0))==KErrNone);
458 test((r=file.Size(size))==KErrNone);
459 if(size>RLibrary::KRequiredImageHeaderSize)
460 size=RLibrary::KRequiredImageHeaderSize;
461 buf=new TUint8[size];
463 TPtr8 header(buf,size);
464 test((r=file.Read(header))==KErrNone);
468 r = RLibrary::GetInfoFromHeader(header, infoBuf);
469 test.Printf(_L("GetInfoFromHeader returns %d\n"), r);
475 r = RLibrary::GetInfo(fn, infoBuf);
476 test.Printf(_L("GetInfo returns %d\n"), r);
480 const TUint32* uid = (const TUint32*)&info.iUids;
481 test.Printf(_L("VER %08x\n"), info.iModuleVersion);
482 test.Printf(_L("UID1 %08x\n"), uid[0]);
483 test.Printf(_L("UID2 %08x\n"), uid[1]);
484 test.Printf(_L("UID3 %08x\n"), uid[2]);
485 test.Printf(_L("SID %08x\n"), (TUint32)info.iSecurityInfo.iSecureId);
486 test.Printf(_L("VID %08x\n"), (TUint32)info.iSecurityInfo.iVendorId);
487 test.Printf(_L("CAP0 %08x\n"), ((SSecurityInfo&)info.iSecurityInfo).iCaps[0]);
488 test.Printf(_L("CAP1 %08x\n"), ((SSecurityInfo&)info.iSecurityInfo).iCaps[1]);
489 TUint32 v = (TUint32)DllVersion[aN];
490 test(info.iModuleVersion == v);
491 test(uid[0] == (TUint32)KDynamicLibraryUidValue);
492 test(uid[2] == (TUint32)0x40abcdef);
493 TUint32 xsid = ((v>>16)<<4)|(v&0x0f)|0x89abcd00u;
494 test(info.iSecurityInfo.iSecureId == xsid);
495 TUint32 xvid = 0x01234500+(xsid&0xff);
496 test(info.iSecurityInfo.iVendorId == xvid);
497 test(((SSecurityInfo&)info.iSecurityInfo).iCaps[0]==0x0002aaab);
498 test(((SSecurityInfo&)info.iSecurityInfo).iCaps[1]==0);
500 #if defined(__ARMCC__)
501 test(info.iHardwareFloatingPoint == EFpTypeVFPv2);
503 test(info.iHardwareFloatingPoint == EFpTypeNone);
512 void TestExeInfo(TInt aN)
515 if(PlatSec::ConfigSetting(PlatSec::EPlatSecEnforceSysBin))
516 fn = _S16("C:\\sys\\bin\\ver15\\");
518 fn = _S16("C:\\system\\bin\\ver15\\");
520 test.Printf(_L("Getting info for %S\n"), &fn);
521 TBool formHeader=EFalse;
524 RLibrary::TInfoV2 info;
525 TPckg<RLibrary::TInfoV2> infoBuf(info);
532 test(fs.Connect()==KErrNone);
534 test((r=file.Open(fs,fn,0))==KErrNone);
536 test((r=file.Size(size))==KErrNone);
537 if(size>RLibrary::KRequiredImageHeaderSize)
538 size=RLibrary::KRequiredImageHeaderSize;
539 buf=new TUint8[size];
541 TPtr8 header(buf,size);
542 test((r=file.Read(header))==KErrNone);
546 r = RLibrary::GetInfoFromHeader(header, infoBuf);
547 test.Printf(_L("GetInfoFromHeader returns %d\n"), r);
553 r = RLibrary::GetInfo(fn, infoBuf);
554 test.Printf(_L("GetInfo returns %d\n"), r);
558 const TUint32* uid = (const TUint32*)&info.iUids;
559 test.Printf(_L("VER %08x\n"), info.iModuleVersion);
560 test.Printf(_L("UID1 %08x\n"), uid[0]);
561 test.Printf(_L("UID2 %08x\n"), uid[1]);
562 test.Printf(_L("UID3 %08x\n"), uid[2]);
563 test.Printf(_L("SID %08x\n"), (TUint32)info.iSecurityInfo.iSecureId);
564 test.Printf(_L("VID %08x\n"), (TUint32)info.iSecurityInfo.iVendorId);
565 test.Printf(_L("CAP0 %08x\n"), ((SSecurityInfo&)info.iSecurityInfo).iCaps[0]);
566 test.Printf(_L("CAP1 %08x\n"), ((SSecurityInfo&)info.iSecurityInfo).iCaps[1]);
567 #if defined(__EABI__) && !defined(__X86__)
568 test(info.iModuleVersion == 0x000a0000);
570 test(info.iModuleVersion == 0x00010000);
572 test(uid[0] == (TUint32)KExecutableImageUidValue);
573 TUint32 xuid3 = 0x40abcd61u + aN;
574 test(uid[2] == xuid3);
575 test(info.iSecurityInfo.iSecureId == xuid3);
576 TUint32 xvid = 0x01234500+(xuid3&0xff);
577 test(info.iSecurityInfo.iVendorId == xvid);
578 test(((SSecurityInfo&)info.iSecurityInfo).iCaps[0]==0x0002aaab);
579 test(((SSecurityInfo&)info.iSecurityInfo).iCaps[1]==0);
581 test(info.iHardwareFloatingPoint == EFpTypeNone);
589 void TestCompression(void)
592 // Check target directory
594 if(PlatSec::ConfigSetting(PlatSec::EPlatSecEnforceSysBin))
595 fn = _S16("c:\\sys\\bin\\");
597 fn = _S16("c:\\system\\bin\\");
599 TInt r = gFs.MkDirAll(fn);
600 test.Printf(_L("MkDir %S->%d\n"), &fn, r);
601 test(r==KErrNone || r==KErrAlreadyExists);
603 // Make copy from t_xxver2.exe to t_xxvercomp.exe
604 fn.Append(_L("t_xxvercomp.exe"));
609 r = gFileMan->Attribs(fn2, 0, KEntryAttReadOnly|KEntryAttHidden|KEntryAttSystem|KEntryAttArchive, now);
610 test.Printf(_L("Attribs %S->%d\n"), &fn2, r);
611 r = gFileMan->Delete(fn2);
612 test.Printf(_L("Delete %S->%d\n"), &fn2, r);
615 TFileName src = SourcePath;
616 src.Append(*ExeArray[0]);
617 r = gFileMan->Copy(src, fn2);
618 test.Printf(_L("%S->%S (%d)\n"), &src, &fn2, r);
622 // Check RLibrary::GetInfoFromHeader on a correct executable
623 test.Printf(_L("fn:%S\n"), &fn);
625 RLibrary::TInfoV2 info;
626 TPckg<RLibrary::TInfoV2> infoBuf(info);
631 test(fs.Connect()==KErrNone);
633 r=file.Open(fs,fn,0);
634 test.Printf(_L("file.Open returns %d\n"), r);
637 test((r=file.Size(size))==KErrNone);
638 if(size>RLibrary::KRequiredImageHeaderSize)
639 size=RLibrary::KRequiredImageHeaderSize;
640 buf=new TUint8[size];
642 TPtr8 header(buf,size);
643 test((r=file.Read(header))==KErrNone);
647 r = RLibrary::GetInfoFromHeader(header, infoBuf);
648 test.Printf(_L("GetInfoFromHeader returns %d\n"), r);
652 test.Printf(_L("Write invalid compression info into the header.\n"));
653 E32ImageHeader* e32Header = (E32ImageHeader*) buf;
655 e32Header->iCompressionType = 0x00000001;
656 test((r=file.Open(fs,fn,EFileWrite))==KErrNone);
657 r=file.Write(header);
658 test.Printf(_L("file.Write returns %d\n"), r);
662 // Check RLibrary::GetInfoFromHeader on a wrong compression method.
664 r = RLibrary::GetInfoFromHeader(header, infoBuf);
665 test.Printf(_L("GetInfoFromHeader returns %d\n"), r);
666 test(r==KErrCorrupt);
674 } // End of TestCompression()
680 // Turn off evil lazy dll unloading
682 test(l.Connect()==KErrNone);
683 test(l.CancelLazyDllUnload()==KErrNone);
687 User::CommandLine(cmdline);
691 memclr(options, sizeof(options));
699 TUint tm = 0xffffffffu;
701 tm = (TUint)options[0];
703 test.Start(_L("Create cleanup stack"));
704 CTrapCleanup* ct = CTrapCleanup::New();
706 test.Next(_L("Connect to file server"));
707 TInt r = gFs.Connect();
709 test.Next(_L("Create CFileMan"));
710 TRAP(r, gFileMan=CFileMan::NewL(gFs));
712 test.Next(_L("Connect to test driver"));
713 r = User::LoadLogicalDevice(_L("d_ldrtst"));
714 test(r==KErrNone || r==KErrAlreadyExists);
717 TFileName fn(RProcess().FileName());
718 test.Printf(_L("Process file name = %S\n"), &fn);
719 SourcePath[0] = fn[0]; // use same drive as this EXE
722 TUint nmasks = 1u << KNumDlls;
723 for (mask=0; mask<nmasks; ++mask)
725 CreateAndPopulateDir(mask);
729 for (n=0; n<KNumExes; ++n)
738 test.Next(_L("Test dynamic loading by version"));
739 for (mask=0; mask<nmasks; ++mask)
742 for (n=0; n<KNumTestVersions; ++n)
744 TestDynamic(mask, n);
751 test.Next(_L("Test get library info"));
753 for (n=0; n<KNumDlls; ++n)
757 for (n=0; n<KNumExes; ++n)