1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/dll/t_xxver2.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,775 @@
1.4 +// Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// e32test\dll\t_xxver2.cpp
1.18 +// Overview:
1.19 +// Test matching algorithm for DLL versions. Test aspects of DLL and EXE files.
1.20 +// API Information:
1.21 +// RLibrary
1.22 +// Details:
1.23 +// - This test makes use of 4 versions of a single DLL, and 15 EXEs which link
1.24 +// against it. The EXEs all have different reqirements on which DLL versions
1.25 +// are acceptable
1.26 +// - Test that the correct version of linked libraries are used (Run for each
1.27 +// EXE and for the 16 combinations in which the 4 versions of the DLL can be
1.28 +// available. The test is performed with each EXE run in sequence, and again
1.29 +// with all of them run at the same time)
1.30 +// - Test that the correct version of dynamically loaded libraries are used and
1.31 +// the libary exports are as expected. (Run for each DLL version and for the
1.32 +// 16 combinations of DLL availability)
1.33 +// - Test that RLibrary::GetInfo and RLibrary::GetInfoFromHeader return the
1.34 +// expected data for all DLLs and EXEs
1.35 +// Platforms/Drives/Compatibility:
1.36 +// All.
1.37 +// Assumptions/Requirement/Pre-requisites:
1.38 +// Failures and causes:
1.39 +// Base Port information:
1.40 +//
1.41 +//
1.42 +
1.43 +#include <e32uid.h>
1.44 +#include <e32test.h>
1.45 +#include <f32file.h>
1.46 +#include <d_ldrtst.h>
1.47 +#include <f32image.h>
1.48 +
1.49 +RTest test(_L("T_XXVER2"));
1.50 +RFs gFs;
1.51 +CFileMan* gFileMan;
1.52 +RLdrTest LdrTest;
1.53 +
1.54 +TBuf<8> SourcePath = _S16("Z:\\img\\");
1.55 +
1.56 +
1.57 +TFileName KDestPath()
1.58 + {
1.59 + _LIT(KDestPath, "C:\\system\\bin\\ver");
1.60 + _LIT(KDestPathSysBin, "C:\\sys\\bin\\ver");
1.61 + if(PlatSec::ConfigSetting(PlatSec::EPlatSecEnforceSysBin))
1.62 + return KDestPathSysBin();
1.63 + else
1.64 + return KDestPath();
1.65 + }
1.66 +
1.67 +_LIT(KDllName0, "t_ver2{00010000}.dll");
1.68 +_LIT(KDllName1, "t_ver2{00010001}.dll");
1.69 +_LIT(KDllName2, "t_ver2{00020000}.dll");
1.70 +_LIT(KDllName3, "t_ver2.dll");
1.71 +
1.72 +const TDesC* const DllArray[] =
1.73 + {
1.74 + &KDllName0(),
1.75 + &KDllName1(),
1.76 + &KDllName2(),
1.77 + &KDllName3()
1.78 + };
1.79 +
1.80 +const TInt KNumDlls = sizeof(DllArray)/sizeof(const TDesC* const);
1.81 +
1.82 +const TInt DllVersion[KNumDlls] =
1.83 + {
1.84 + 0x00010000,
1.85 + 0x00010001,
1.86 + 0x00020000,
1.87 + 0x00030000
1.88 + };
1.89 +
1.90 +const TInt KNumTestVersions = 7;
1.91 +const TInt TestDllVersion[KNumTestVersions] =
1.92 + {
1.93 + 0x00000000,
1.94 + 0x00010000,
1.95 + 0x00010001,
1.96 + 0x00010002,
1.97 + 0x00020000,
1.98 + 0x00030000,
1.99 + 0x00040000
1.100 + };
1.101 +
1.102 +_LIT(KExeName0, "t_xver2a.exe"); // request 1.0 work with any
1.103 +_LIT(KExeName1, "t_xver2b.exe"); // request 1.0 work with 2.0 but not 3.0
1.104 +_LIT(KExeName2, "t_xver2c.exe"); // request 1.0 don't work with 2.0
1.105 +_LIT(KExeName3, "t_xver2d.exe"); // request 1.1 work with 1.0 but not 2.0
1.106 +_LIT(KExeName4, "t_xver2e.exe"); // request 1.1 work with any
1.107 +_LIT(KExeName5, "t_xver2f.exe"); // request 1.1 work with 2.0, 3.0 but not with 1.0
1.108 +_LIT(KExeName6, "t_xver2g.exe"); // request 1.1 don't work with 2.0, 3.0 or 1.0
1.109 +_LIT(KExeName7, "t_xver2h.exe"); // request 1.1 work with 1.0 and 2.0 but not 3.0
1.110 +_LIT(KExeName8, "t_xver2i.exe"); // request 1.1 work with 2.0 but not 3.0 or 1.0
1.111 +_LIT(KExeName9, "t_xver2j.exe"); // request 2.0 only use 1.0 exports
1.112 +_LIT(KExeName10, "t_xver2k.exe"); // request 2.0 only use 1.0, 1.1 exports
1.113 +_LIT(KExeName11, "t_xver2l.exe"); // request 2.0 use 2.0 exports work on 3.0
1.114 +_LIT(KExeName12, "t_xver2m.exe"); // request 2.0 use 2.0 exports, don't work on 3.0
1.115 +_LIT(KExeName13, "t_xver2n.exe"); // request 3.0 use 1.0 exports only
1.116 +_LIT(KExeName14, "t_xver2o.exe"); // request 3.0 use all
1.117 +
1.118 +const TDesC* const ExeArray[] =
1.119 + {
1.120 + &KExeName0(),
1.121 + &KExeName1(),
1.122 + &KExeName2(),
1.123 + &KExeName3(),
1.124 + &KExeName4(),
1.125 + &KExeName5(),
1.126 + &KExeName6(),
1.127 + &KExeName7(),
1.128 + &KExeName8(),
1.129 + &KExeName9(),
1.130 + &KExeName10(),
1.131 + &KExeName11(),
1.132 + &KExeName12(),
1.133 + &KExeName13(),
1.134 + &KExeName14()
1.135 + };
1.136 +
1.137 +const TInt KNumExes = sizeof(ExeArray)/sizeof(const TDesC* const);
1.138 +
1.139 +const TInt ResultArray[KNumExes<<KNumDlls] =
1.140 + {
1.141 +// DLLs Present A B C D E F G H I J K L M N O
1.142 +// None
1.143 + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
1.144 +// 1.0
1.145 + 0, 0, 0, 0, 0, -1, -1, 0, -1, -1, -1, -1, -1, -1, -1,
1.146 +// 1.1
1.147 + 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1,
1.148 +// 1.0, 1.1
1.149 + 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1,
1.150 +// 2.0
1.151 + 2, 2, -1, -1, 2, 2, -1, 2, 2, 2, 2, 2, 2, -1, -1,
1.152 +// 2.0, 1.0
1.153 + 0, 0, 0, 0, 2, 2, -1, 2, 2, 2, 2, 2, 2, -1, -1,
1.154 +// 2.0, 1.1
1.155 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, -1, -1,
1.156 +// 2.0, 1.1, 1.0
1.157 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, -1, -1,
1.158 +// 3.0
1.159 + 3, -1, -1, -1, 3, 3, -1, -1, -1, 3, 3, 3, -1, 3, 3,
1.160 +// 3.0, 1.0
1.161 + 0, 0, 0, 0, 3, 3, -1, 0, -1, 3, 3, 3, -1, 3, 3,
1.162 +// 3.0, 1.1
1.163 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3, 3, -1, 3, 3,
1.164 +// 3.0, 1.1, 1.0
1.165 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3, 3, -1, 3, 3,
1.166 +// 3.0, 2.0
1.167 + 2, 2, -1, -1, 2, 2, -1, 2, 2, 2, 2, 2, 2, 3, 3,
1.168 +// 3.0, 2.0, 1.0
1.169 + 0, 0, 0, 0, 2, 2, -1, 2, 2, 2, 2, 2, 2, 3, 3,
1.170 +// 3.0, 2.0, 1.1
1.171 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3,
1.172 +// 3.0, 2.0, 1.1, 1.0
1.173 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3
1.174 +//
1.175 + };
1.176 +
1.177 +const TInt ResultArray2[KNumTestVersions<<KNumDlls] =
1.178 + {
1.179 +// DLLs Present 0.0 1.0 1.1 1.2 2.0 3.0 4.0
1.180 +// None
1.181 + -1, -1, -1, -1, -1, -1, -1,
1.182 +// 1.0
1.183 + -1, 0, -1, -1, -1, -1, -1,
1.184 +// 1.1
1.185 + -1, 1, 1, -1, -1, -1, -1,
1.186 +// 1.0, 1.1
1.187 + -1, 1, 1, -1, -1, -1, -1,
1.188 +// 2.0
1.189 + -1, -1, -1, -1, 2, -1, -1,
1.190 +// 2.0, 1.0
1.191 + -1, 0, -1, -1, 2, -1, -1,
1.192 +// 2.0, 1.1
1.193 + -1, 1, 1, -1, 2, -1, -1,
1.194 +// 2.0, 1.1, 1.0
1.195 + -1, 1, 1, -1, 2, -1, -1,
1.196 +// 3.0
1.197 + -1, -1, -1, -1, -1, 3, -1,
1.198 +// 3.0, 1.0
1.199 + -1, 0, -1, -1, -1, 3, -1,
1.200 +// 3.0, 1.1
1.201 + -1, 1, 1, -1, -1, 3, -1,
1.202 +// 3.0, 1.1, 1.0
1.203 + -1, 1, 1, -1, -1, 3, -1,
1.204 +// 3.0, 2.0
1.205 + -1, -1, -1, -1, 2, 3, -1,
1.206 +// 3.0, 2.0, 1.0
1.207 + -1, 0, -1, -1, 2, 3, -1,
1.208 +// 3.0, 2.0, 1.1
1.209 + -1, 1, 1, -1, 2, 3, -1,
1.210 +// 3.0, 2.0, 1.1, 1.0
1.211 + -1, 1, 1, -1, 2, 3, -1
1.212 +//
1.213 + };
1.214 +
1.215 +struct SExportInfo
1.216 + {
1.217 + TInt iTotal;
1.218 + TInt iHoles;
1.219 + TInt iHole[1];
1.220 + };
1.221 +
1.222 +const TInt Dll0ExportInfo[] = {19,0};
1.223 +const TInt Dll1ExportInfo[] = {29,0};
1.224 +const TInt Dll2ExportInfo[] = {39,4,2,3,23,24};
1.225 +const TInt Dll3ExportInfo[] = {59,6,2,3,4,23,24,39};
1.226 +
1.227 +const SExportInfo* const DllExportInfo[KNumDlls] =
1.228 + {
1.229 + (const SExportInfo*)Dll0ExportInfo,
1.230 + (const SExportInfo*)Dll1ExportInfo,
1.231 + (const SExportInfo*)Dll2ExportInfo,
1.232 + (const SExportInfo*)Dll3ExportInfo
1.233 + };
1.234 +
1.235 +void CheckExports(TInt aDllNum, RLibrary aLib)
1.236 + {
1.237 + test.Printf(_L("Testing exports for DLL %d\n"), aDllNum);
1.238 + const TFileName& fn = aLib.FileName();
1.239 + test.Printf(_L("Filename %S\n"), &fn);
1.240 + const SExportInfo* e = DllExportInfo[aDllNum];
1.241 + TAny* libcs = LdrTest.LibraryCodeSeg(aLib.Handle());
1.242 + test.Printf(_L("Code seg @%08x\n"), libcs);
1.243 + test(libcs != NULL);
1.244 + TInt n = e->iTotal;
1.245 + TInt nh = e->iHoles;
1.246 + TInt ord;
1.247 + for (ord=1; ord<=n+1; ++ord)
1.248 + {
1.249 + TLibraryFunction f = aLib.Lookup(ord);
1.250 + test.Printf(_L("Ord %3d->%08x\n"), ord, f);
1.251 + if (ord>n)
1.252 + {
1.253 + test(!f);
1.254 + continue;
1.255 + }
1.256 + TInt i;
1.257 + for (i=0; i<nh && e->iHole[i]!=ord; ++i) {}
1.258 + if (i<nh)
1.259 + test(!f); // hole
1.260 + else
1.261 + test(f!=NULL);
1.262 + TAny* cs = LdrTest.CodeSegFromAddr((TLinAddr)f);
1.263 + test(f ? (cs==libcs) : !cs);
1.264 + }
1.265 + }
1.266 +
1.267 +void CreateAndPopulateDir(TUint aMask)
1.268 + {
1.269 + test.Printf(_L("CreateAndPopulateDir %d\n"), aMask);
1.270 + TFileName fn = KDestPath();
1.271 + fn.AppendNumFixedWidth(aMask, EDecimal, 2);
1.272 + fn.Append('\\');
1.273 + TInt r = gFs.MkDirAll(fn);
1.274 + test.Printf(_L("MkDir %S->%d\n"), &fn, r);
1.275 + test(r==KErrNone || r==KErrAlreadyExists);
1.276 + TFileName fn2 = fn;
1.277 + fn2.Append(_L("*.*"));
1.278 + TTime now;
1.279 + now.HomeTime();
1.280 + r = gFileMan->Attribs(fn2, 0, KEntryAttReadOnly|KEntryAttHidden|KEntryAttSystem|KEntryAttArchive, now);
1.281 + test.Printf(_L("Attribs %S->%d\n"), &fn2, r);
1.282 + r = gFileMan->Delete(fn2);
1.283 + test.Printf(_L("Delete %S->%d\n"), &fn2, r);
1.284 + TInt n = 0;
1.285 + for (; aMask; aMask>>=1, ++n)
1.286 + {
1.287 + if (!(aMask & 1))
1.288 + continue;
1.289 + fn2 = fn;
1.290 + fn2.Append(*DllArray[n]);
1.291 + TFileName src = SourcePath;
1.292 + src.Append(*DllArray[n]);
1.293 + r = gFileMan->Copy(src, fn2);
1.294 + test.Printf(_L("%S->%S (%d)\n"), &src, &fn2, r);
1.295 + test(r == KErrNone);
1.296 + }
1.297 + for (n=0; n<KNumExes; ++n)
1.298 + {
1.299 + fn2 = fn;
1.300 + fn2.Append(*ExeArray[n]);
1.301 + TFileName src = SourcePath;
1.302 + src.Append(*ExeArray[n]);
1.303 + r = gFileMan->Copy(src, fn2);
1.304 + test.Printf(_L("%S->%S (%d)\n"), &src, &fn2, r);
1.305 + test(r == KErrNone);
1.306 + }
1.307 + }
1.308 +
1.309 +void RunExe(TUint aMask, TInt aExeNum)
1.310 + {
1.311 + test.Printf(_L("RunExe mask %d exenum %d\n"), aMask, aExeNum);
1.312 + RProcess p;
1.313 + TRequestStatus s;
1.314 + TFileName fn = KDestPath();
1.315 + fn.AppendNumFixedWidth(aMask, EDecimal, 2);
1.316 + fn.Append('\\');
1.317 + fn.Append(*ExeArray[aExeNum]);
1.318 + TInt r = p.Create(fn, KNullDesC);
1.319 + test.Printf(_L("Create %S->%d\n"), &fn, r);
1.320 + TInt rix = aExeNum + KNumExes*TInt(aMask);
1.321 + TInt expected = ResultArray[rix];
1.322 + test.Printf(_L("RunExe expected %d\n"), expected);
1.323 + if (expected<0)
1.324 + {
1.325 + test(r<0);
1.326 + return;
1.327 + }
1.328 + p.Logon(s);
1.329 + p.Resume();
1.330 + User::WaitForRequest(s);
1.331 + if (p.ExitType()!=EExitKill)
1.332 + {
1.333 + TInt et = p.ExitType();
1.334 + TInt er = p.ExitReason();
1.335 + const TDesC& ec = p.ExitCategory();
1.336 + test.Printf(_L("Exit %d,%d,%S\n"), et, er, &ec);
1.337 + test(0);
1.338 + }
1.339 + CLOSE_AND_WAIT(p);
1.340 + test.Printf(_L("Return code %08x\n"), s.Int());
1.341 + test(s.Int() == DllVersion[expected]);
1.342 + }
1.343 +
1.344 +void RunExes(TUint aMask)
1.345 + {
1.346 + test.Printf(_L("RunExes mask %d\n"), aMask);
1.347 + RProcess p[KNumExes];
1.348 + TRequestStatus s[KNumExes];
1.349 + TInt xn;
1.350 + for (xn=0; xn<KNumExes; ++xn)
1.351 + {
1.352 + TFileName fn = KDestPath();
1.353 + fn.AppendNumFixedWidth(aMask, EDecimal, 2);
1.354 + fn.Append('\\');
1.355 + fn.Append(*ExeArray[xn]);
1.356 + TInt r = p[xn].Create(fn, KNullDesC);
1.357 + test.Printf(_L("Create %S->%d\n"), &fn, r);
1.358 + TInt rix = xn + KNumExes*TInt(aMask);
1.359 + TInt expected = ResultArray[rix];
1.360 + test.Printf(_L("RunExe expected %d\n"), expected);
1.361 + if (expected<0)
1.362 + {
1.363 + test(r<0);
1.364 + continue;
1.365 + }
1.366 + p[xn].Logon(s[xn]);
1.367 + }
1.368 + for (xn=0; xn<KNumExes; ++xn)
1.369 + {
1.370 + TInt rix = xn + KNumExes*TInt(aMask);
1.371 + TInt expected = ResultArray[rix];
1.372 + if (expected<0)
1.373 + continue;
1.374 + p[xn].Resume();
1.375 + }
1.376 + for (xn=0; xn<KNumExes; ++xn)
1.377 + {
1.378 + TInt rix = xn + KNumExes*TInt(aMask);
1.379 + TInt expected = ResultArray[rix];
1.380 + if (expected<0)
1.381 + continue;
1.382 + User::WaitForRequest(s[xn]);
1.383 + if (p[xn].ExitType()!=EExitKill)
1.384 + {
1.385 + TInt et = p[xn].ExitType();
1.386 + TInt er = p[xn].ExitReason();
1.387 + const TDesC& ec = p[xn].ExitCategory();
1.388 + test.Printf(_L("Exit %d,%d,%S\n"), et, er, &ec);
1.389 + test(0);
1.390 + }
1.391 + CLOSE_AND_WAIT(p[xn]);
1.392 + test.Printf(_L("Return code %08x\n"), s[xn].Int());
1.393 + test(s[xn].Int() == DllVersion[expected]);
1.394 + }
1.395 + }
1.396 +
1.397 +void TestDynamic(TUint aMask, TInt aTN)
1.398 + {
1.399 + TUint32 ver = TestDllVersion[aTN];
1.400 + TInt rix = aTN + KNumTestVersions*TInt(aMask);
1.401 + TInt expected = ResultArray2[rix];
1.402 + test.Printf(_L("ReqVer %08x Expected %d\n"), ver, expected);
1.403 + TFileName path = KDestPath();
1.404 + path.AppendNumFixedWidth(aMask, EDecimal, 2);
1.405 + TFileName fn = path;
1.406 + fn.Append(_L("\\T_VER2.DLL"));
1.407 + RLibrary l;
1.408 + TInt r = l.Load(fn, KNullDesC, TUidType(), ver);
1.409 + test.Printf(_L("Load %S returns %d\n"), &fn, r);
1.410 + if (expected<0)
1.411 + {
1.412 + test(r<0);
1.413 + return;
1.414 + }
1.415 + TLibraryFunction f = l.Lookup(1);
1.416 + test(f != 0);
1.417 + TInt result = (*f)();
1.418 + test.Printf(_L("Ord 1 returns %08x\n"), result);
1.419 + test(result == DllVersion[expected]);
1.420 + l.Close();
1.421 + r = l.Load(_L("T_VER2.DLL"), path, TUidType(), ver);
1.422 + test.Printf(_L("Load T_VER2.DLL path %S returns %d\n"), &path, r);
1.423 + if (expected<0)
1.424 + {
1.425 + test(r<0);
1.426 + return;
1.427 + }
1.428 + f = l.Lookup(1);
1.429 + test(f != 0);
1.430 + result = (*f)();
1.431 + test.Printf(_L("Ord 1 returns %08x\n"), result);
1.432 + test(result == DllVersion[expected]);
1.433 + CheckExports(expected, l);
1.434 + l.Close();
1.435 + }
1.436 +
1.437 +void TestLibraryInfo(TInt aN)
1.438 + {
1.439 + TFileName fn;
1.440 + if(PlatSec::ConfigSetting(PlatSec::EPlatSecEnforceSysBin))
1.441 + fn = _S16("C:\\sys\\bin\\ver15\\");
1.442 + else
1.443 + fn = _S16("C:\\system\\bin\\ver15\\");
1.444 + fn += *DllArray[aN];
1.445 + test.Printf(_L("Getting info for %S\n"), &fn);
1.446 + TBool formHeader=EFalse;
1.447 + for(;;)
1.448 + {
1.449 + RLibrary::TInfoV2 info;
1.450 + TPckg<RLibrary::TInfoV2> infoBuf(info);
1.451 + TInt r;
1.452 + if(formHeader)
1.453 + {
1.454 + TUint8* buf;
1.455 +
1.456 + RFs fs;
1.457 + test(fs.Connect()==KErrNone);
1.458 + RFile file;
1.459 + test((r=file.Open(fs,fn,0))==KErrNone);
1.460 + TInt size;
1.461 + test((r=file.Size(size))==KErrNone);
1.462 + if(size>RLibrary::KRequiredImageHeaderSize)
1.463 + size=RLibrary::KRequiredImageHeaderSize;
1.464 + buf=new TUint8[size];
1.465 + test(buf!=0);
1.466 + TPtr8 header(buf,size);
1.467 + test((r=file.Read(header))==KErrNone);
1.468 + file.Close();
1.469 + fs.Close();
1.470 +
1.471 + r = RLibrary::GetInfoFromHeader(header, infoBuf);
1.472 + test.Printf(_L("GetInfoFromHeader returns %d\n"), r);
1.473 +
1.474 + delete buf;
1.475 + }
1.476 + else
1.477 + {
1.478 + r = RLibrary::GetInfo(fn, infoBuf);
1.479 + test.Printf(_L("GetInfo returns %d\n"), r);
1.480 + }
1.481 +
1.482 + test(r==KErrNone);
1.483 + const TUint32* uid = (const TUint32*)&info.iUids;
1.484 + test.Printf(_L("VER %08x\n"), info.iModuleVersion);
1.485 + test.Printf(_L("UID1 %08x\n"), uid[0]);
1.486 + test.Printf(_L("UID2 %08x\n"), uid[1]);
1.487 + test.Printf(_L("UID3 %08x\n"), uid[2]);
1.488 + test.Printf(_L("SID %08x\n"), (TUint32)info.iSecurityInfo.iSecureId);
1.489 + test.Printf(_L("VID %08x\n"), (TUint32)info.iSecurityInfo.iVendorId);
1.490 + test.Printf(_L("CAP0 %08x\n"), ((SSecurityInfo&)info.iSecurityInfo).iCaps[0]);
1.491 + test.Printf(_L("CAP1 %08x\n"), ((SSecurityInfo&)info.iSecurityInfo).iCaps[1]);
1.492 + TUint32 v = (TUint32)DllVersion[aN];
1.493 + test(info.iModuleVersion == v);
1.494 + test(uid[0] == (TUint32)KDynamicLibraryUidValue);
1.495 + test(uid[2] == (TUint32)0x40abcdef);
1.496 + TUint32 xsid = ((v>>16)<<4)|(v&0x0f)|0x89abcd00u;
1.497 + test(info.iSecurityInfo.iSecureId == xsid);
1.498 + TUint32 xvid = 0x01234500+(xsid&0xff);
1.499 + test(info.iSecurityInfo.iVendorId == xvid);
1.500 + test(((SSecurityInfo&)info.iSecurityInfo).iCaps[0]==0x0002aaab);
1.501 + test(((SSecurityInfo&)info.iSecurityInfo).iCaps[1]==0);
1.502 + if(formHeader)
1.503 +#if defined(__ARMCC__)
1.504 + test(info.iHardwareFloatingPoint == EFpTypeVFPv2);
1.505 +#else
1.506 + test(info.iHardwareFloatingPoint == EFpTypeNone);
1.507 +#endif
1.508 +
1.509 + if(formHeader)
1.510 + break;
1.511 + formHeader = ETrue;
1.512 + }
1.513 + }
1.514 +
1.515 +void TestExeInfo(TInt aN)
1.516 + {
1.517 + TFileName fn;
1.518 + if(PlatSec::ConfigSetting(PlatSec::EPlatSecEnforceSysBin))
1.519 + fn = _S16("C:\\sys\\bin\\ver15\\");
1.520 + else
1.521 + fn = _S16("C:\\system\\bin\\ver15\\");
1.522 + fn += *ExeArray[aN];
1.523 + test.Printf(_L("Getting info for %S\n"), &fn);
1.524 + TBool formHeader=EFalse;
1.525 + for(;;)
1.526 + {
1.527 + RLibrary::TInfoV2 info;
1.528 + TPckg<RLibrary::TInfoV2> infoBuf(info);
1.529 + TInt r;
1.530 + if(formHeader)
1.531 + {
1.532 + TUint8* buf;
1.533 +
1.534 + RFs fs;
1.535 + test(fs.Connect()==KErrNone);
1.536 + RFile file;
1.537 + test((r=file.Open(fs,fn,0))==KErrNone);
1.538 + TInt size;
1.539 + test((r=file.Size(size))==KErrNone);
1.540 + if(size>RLibrary::KRequiredImageHeaderSize)
1.541 + size=RLibrary::KRequiredImageHeaderSize;
1.542 + buf=new TUint8[size];
1.543 + test(buf!=0);
1.544 + TPtr8 header(buf,size);
1.545 + test((r=file.Read(header))==KErrNone);
1.546 + file.Close();
1.547 + fs.Close();
1.548 +
1.549 + r = RLibrary::GetInfoFromHeader(header, infoBuf);
1.550 + test.Printf(_L("GetInfoFromHeader returns %d\n"), r);
1.551 +
1.552 + delete buf;
1.553 + }
1.554 + else
1.555 + {
1.556 + r = RLibrary::GetInfo(fn, infoBuf);
1.557 + test.Printf(_L("GetInfo returns %d\n"), r);
1.558 + }
1.559 +
1.560 + test(r==KErrNone);
1.561 + const TUint32* uid = (const TUint32*)&info.iUids;
1.562 + test.Printf(_L("VER %08x\n"), info.iModuleVersion);
1.563 + test.Printf(_L("UID1 %08x\n"), uid[0]);
1.564 + test.Printf(_L("UID2 %08x\n"), uid[1]);
1.565 + test.Printf(_L("UID3 %08x\n"), uid[2]);
1.566 + test.Printf(_L("SID %08x\n"), (TUint32)info.iSecurityInfo.iSecureId);
1.567 + test.Printf(_L("VID %08x\n"), (TUint32)info.iSecurityInfo.iVendorId);
1.568 + test.Printf(_L("CAP0 %08x\n"), ((SSecurityInfo&)info.iSecurityInfo).iCaps[0]);
1.569 + test.Printf(_L("CAP1 %08x\n"), ((SSecurityInfo&)info.iSecurityInfo).iCaps[1]);
1.570 + #if defined(__EABI__) && !defined(__X86__)
1.571 + test(info.iModuleVersion == 0x000a0000);
1.572 + #else
1.573 + test(info.iModuleVersion == 0x00010000);
1.574 + #endif
1.575 + test(uid[0] == (TUint32)KExecutableImageUidValue);
1.576 + TUint32 xuid3 = 0x40abcd61u + aN;
1.577 + test(uid[2] == xuid3);
1.578 + test(info.iSecurityInfo.iSecureId == xuid3);
1.579 + TUint32 xvid = 0x01234500+(xuid3&0xff);
1.580 + test(info.iSecurityInfo.iVendorId == xvid);
1.581 + test(((SSecurityInfo&)info.iSecurityInfo).iCaps[0]==0x0002aaab);
1.582 + test(((SSecurityInfo&)info.iSecurityInfo).iCaps[1]==0);
1.583 + if(formHeader)
1.584 + test(info.iHardwareFloatingPoint == EFpTypeNone);
1.585 +
1.586 + if(formHeader)
1.587 + break;
1.588 + formHeader = ETrue;
1.589 + }
1.590 + }
1.591 +
1.592 +void TestCompression(void)
1.593 + {
1.594 +
1.595 + // Check target directory
1.596 + TFileName fn;
1.597 + if(PlatSec::ConfigSetting(PlatSec::EPlatSecEnforceSysBin))
1.598 + fn = _S16("c:\\sys\\bin\\");
1.599 + else
1.600 + fn = _S16("c:\\system\\bin\\");
1.601 +
1.602 + TInt r = gFs.MkDirAll(fn);
1.603 + test.Printf(_L("MkDir %S->%d\n"), &fn, r);
1.604 + test(r==KErrNone || r==KErrAlreadyExists);
1.605 +
1.606 + // Make copy from t_xxver2.exe to t_xxvercomp.exe
1.607 + fn.Append(_L("t_xxvercomp.exe"));
1.608 +
1.609 + TFileName fn2 = fn;
1.610 + TTime now;
1.611 + now.HomeTime();
1.612 + r = gFileMan->Attribs(fn2, 0, KEntryAttReadOnly|KEntryAttHidden|KEntryAttSystem|KEntryAttArchive, now);
1.613 + test.Printf(_L("Attribs %S->%d\n"), &fn2, r);
1.614 + r = gFileMan->Delete(fn2);
1.615 + test.Printf(_L("Delete %S->%d\n"), &fn2, r);
1.616 +
1.617 + fn2 = fn;
1.618 + TFileName src = SourcePath;
1.619 + src.Append(*ExeArray[0]);
1.620 + r = gFileMan->Copy(src, fn2);
1.621 + test.Printf(_L("%S->%S (%d)\n"), &src, &fn2, r);
1.622 + test(r == KErrNone);
1.623 +
1.624 +
1.625 + // Check RLibrary::GetInfoFromHeader on a correct executable
1.626 + test.Printf(_L("fn:%S\n"), &fn);
1.627 +
1.628 + RLibrary::TInfoV2 info;
1.629 + TPckg<RLibrary::TInfoV2> infoBuf(info);
1.630 +
1.631 + TUint8* buf;
1.632 +
1.633 + RFs fs;
1.634 + test(fs.Connect()==KErrNone);
1.635 + RFile file;
1.636 + r=file.Open(fs,fn,0);
1.637 + test.Printf(_L("file.Open returns %d\n"), r);
1.638 + test(r==KErrNone);
1.639 + TInt size;
1.640 + test((r=file.Size(size))==KErrNone);
1.641 + if(size>RLibrary::KRequiredImageHeaderSize)
1.642 + size=RLibrary::KRequiredImageHeaderSize;
1.643 + buf=new TUint8[size];
1.644 + test(buf!=0);
1.645 + TPtr8 header(buf,size);
1.646 + test((r=file.Read(header))==KErrNone);
1.647 + file.Close();
1.648 +
1.649 +
1.650 + r = RLibrary::GetInfoFromHeader(header, infoBuf);
1.651 + test.Printf(_L("GetInfoFromHeader returns %d\n"), r);
1.652 + test(r==KErrNone);
1.653 +
1.654 +
1.655 + test.Printf(_L("Write invalid compression info into the header.\n"));
1.656 + E32ImageHeader* e32Header = (E32ImageHeader*) buf;
1.657 +
1.658 + e32Header->iCompressionType = 0x00000001;
1.659 + test((r=file.Open(fs,fn,EFileWrite))==KErrNone);
1.660 + r=file.Write(header);
1.661 + test.Printf(_L("file.Write returns %d\n"), r);
1.662 + test(r==KErrNone);
1.663 + file.Close();
1.664 +
1.665 + // Check RLibrary::GetInfoFromHeader on a wrong compression method.
1.666 +
1.667 + r = RLibrary::GetInfoFromHeader(header, infoBuf);
1.668 + test.Printf(_L("GetInfoFromHeader returns %d\n"), r);
1.669 + test(r==KErrCorrupt);
1.670 +
1.671 +
1.672 + fs.Close();
1.673 + delete buf;
1.674 +
1.675 +
1.676 +
1.677 + } // End of TestCompression()
1.678 +
1.679 +TInt E32Main()
1.680 + {
1.681 + test.Title();
1.682 +
1.683 + // Turn off evil lazy dll unloading
1.684 + RLoader l;
1.685 + test(l.Connect()==KErrNone);
1.686 + test(l.CancelLazyDllUnload()==KErrNone);
1.687 + l.Close();
1.688 +
1.689 + TBuf<256> cmdline;
1.690 + User::CommandLine(cmdline);
1.691 + TLex lex(cmdline);
1.692 + TInt options[8];
1.693 + TInt i;
1.694 + memclr(options, sizeof(options));
1.695 + for (i=0; i<8; ++i)
1.696 + {
1.697 + lex.SkipSpace();
1.698 + if (lex.Eos())
1.699 + break;
1.700 + lex.Val(options[i]);
1.701 + }
1.702 + TUint tm = 0xffffffffu;
1.703 + if (options[0])
1.704 + tm = (TUint)options[0];
1.705 +
1.706 + test.Start(_L("Create cleanup stack"));
1.707 + CTrapCleanup* ct = CTrapCleanup::New();
1.708 + test(ct!=0);
1.709 + test.Next(_L("Connect to file server"));
1.710 + TInt r = gFs.Connect();
1.711 + test(r==KErrNone);
1.712 + test.Next(_L("Create CFileMan"));
1.713 + TRAP(r, gFileMan=CFileMan::NewL(gFs));
1.714 + test(r==KErrNone);
1.715 + test.Next(_L("Connect to test driver"));
1.716 + r = User::LoadLogicalDevice(_L("d_ldrtst"));
1.717 + test(r==KErrNone || r==KErrAlreadyExists);
1.718 + r = LdrTest.Open();
1.719 + test(r==KErrNone);
1.720 + TFileName fn(RProcess().FileName());
1.721 + test.Printf(_L("Process file name = %S\n"), &fn);
1.722 + SourcePath[0] = fn[0]; // use same drive as this EXE
1.723 +
1.724 + TUint mask;
1.725 + TUint nmasks = 1u << KNumDlls;
1.726 + for (mask=0; mask<nmasks; ++mask)
1.727 + {
1.728 + CreateAndPopulateDir(mask);
1.729 + if (!(tm&1))
1.730 + continue;
1.731 + TInt n;
1.732 + for (n=0; n<KNumExes; ++n)
1.733 + {
1.734 + RunExe(mask, n);
1.735 + }
1.736 + RunExes(mask);
1.737 + }
1.738 +
1.739 + if (tm & 2)
1.740 + {
1.741 + test.Next(_L("Test dynamic loading by version"));
1.742 + for (mask=0; mask<nmasks; ++mask)
1.743 + {
1.744 + TInt n;
1.745 + for (n=0; n<KNumTestVersions; ++n)
1.746 + {
1.747 + TestDynamic(mask, n);
1.748 + }
1.749 + }
1.750 + }
1.751 +
1.752 + if (tm & 4)
1.753 + {
1.754 + test.Next(_L("Test get library info"));
1.755 + TInt n;
1.756 + for (n=0; n<KNumDlls; ++n)
1.757 + {
1.758 + TestLibraryInfo(n);
1.759 + }
1.760 + for (n=0; n<KNumExes; ++n)
1.761 + {
1.762 + TestExeInfo(n);
1.763 + }
1.764 + }
1.765 +
1.766 + if( tm & 8)
1.767 + {
1.768 + TestCompression();
1.769 + }
1.770 +
1.771 + delete gFileMan;
1.772 + gFs.Close();
1.773 + delete ct;
1.774 + LdrTest.Close();
1.775 + test.End();
1.776 + return KErrNone;
1.777 + }
1.778 +