os/kernelhwsrv/kerneltest/e32test/dll/t_xxver2w.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/dll/t_xxver2w.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,280 @@
     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_xxver2w.cpp
    1.18 +// Overview:
    1.19 +// Check of DLL & EXE module info and DDL function ordinals
    1.20 +// API Information:
    1.21 +// RLibrary
    1.22 +// Details:
    1.23 +// - Use RLibrary::GetInfoFromHeader() and RLibrary::GetInfo() to get DLL 
    1.24 +// information. Verify results are as expected.
    1.25 +// - Use RLibrary::GetInfoFromHeader() and RLibrary::GetInfo() to get EXE 
    1.26 +// information. Verify results are as expected.
    1.27 +// - Load a DLL, lookup and verify the function at the specified ordinal 
    1.28 +// within the DLL.
    1.29 +// Platforms/Drives/Compatibility:
    1.30 +// All.
    1.31 +// Assumptions/Requirement/Pre-requisites:
    1.32 +// Failures and causes:
    1.33 +// Base Port information:
    1.34 +// 
    1.35 +//
    1.36 +
    1.37 +#include <e32uid.h>
    1.38 +#include <e32test.h>
    1.39 +#include <f32file.h>
    1.40 +
    1.41 +#include <e32wins.h>
    1.42 +#include <emulator.h>
    1.43 +#include <d_ldrtst.h>
    1.44 +
    1.45 +RTest test(_L("T_XXVER2W"));
    1.46 +RLdrTest LdrTest;
    1.47 +
    1.48 +TFileName CopyBinaryFromZ(const TFileName& aFileName)
    1.49 +	{
    1.50 +	TParse parse;
    1.51 +	test(parse.Set(aFileName,0,0)==KErrNone);
    1.52 +	TFileName source = _L("z:");
    1.53 +	source.Append(parse.NameAndExt());
    1.54 +
    1.55 +	TBuf<MAX_PATH> sName;
    1.56 +	TInt r = MapEmulatedFileName(sName, parse.NameAndExt());
    1.57 +	test(r==KErrNone);
    1.58 +
    1.59 +	TFileName destination = _S16("C:\\t_zzver2w.tmp");
    1.60 +	TBuf<MAX_PATH> dName;
    1.61 +	r = MapEmulatedFileName(dName, destination);
    1.62 +	test(r==KErrNone);
    1.63 +
    1.64 +	r=Emulator::CopyFile((LPCTSTR)sName.PtrZ(),(LPCTSTR)dName.PtrZ(),FALSE);
    1.65 +	test(r);
    1.66 +
    1.67 +	return destination;
    1.68 +	}
    1.69 +
    1.70 +
    1.71 +void TestDllInfo()
    1.72 +	{
    1.73 +	TFileName fn;
    1.74 +	if(PlatSec::ConfigSetting(PlatSec::EPlatSecEnforceSysBin))
    1.75 +		fn = _S16("Z:\\sys\\bin\\t_ver2.dll");
    1.76 +	else
    1.77 +		fn = _S16("Z:\\system\\bin\\t_ver2.dll");
    1.78 +	test.Printf(_L("Getting info for %S\n"), &fn);
    1.79 +	TBool formHeader=EFalse;
    1.80 +	for(;;)
    1.81 +		{
    1.82 +		RLibrary::TInfo info;
    1.83 +		TPckg<RLibrary::TInfo> infoBuf(info);
    1.84 +		TInt r;
    1.85 +		if(formHeader)
    1.86 +			{
    1.87 +			TUint8* buf;
    1.88 +
    1.89 +			RFs fs;
    1.90 +			test(fs.Connect()==KErrNone);
    1.91 +			RFile file;
    1.92 +			test((r=file.Open(fs,CopyBinaryFromZ(fn),0))==KErrNone);
    1.93 +			TInt size;
    1.94 +			test((r=file.Size(size))==KErrNone);
    1.95 +			buf=new TUint8[size];
    1.96 +			test(buf!=0);
    1.97 +			TPtr8 header(buf,size);
    1.98 +			test((r=file.Read(header))==KErrNone);
    1.99 +			file.Close();
   1.100 +			fs.Close();
   1.101 +
   1.102 +			r = RLibrary::GetInfoFromHeader(header, infoBuf);
   1.103 +			test.Printf(_L("GetInfoFromHeader returns %d\n"), r);
   1.104 +
   1.105 +			delete buf;
   1.106 +			}
   1.107 +		else
   1.108 +			{
   1.109 +			r = RLibrary::GetInfo(fn, infoBuf);
   1.110 +			test.Printf(_L("GetInfo returns %d\n"), r);
   1.111 +			}
   1.112 +
   1.113 +		test(r==KErrNone);
   1.114 +		const TUint32* uid = (const TUint32*)&info.iUids;
   1.115 +		test.Printf(_L("VER  %08x\n"), info.iModuleVersion);
   1.116 +		test.Printf(_L("UID1 %08x\n"), uid[0]);
   1.117 +		test.Printf(_L("UID2 %08x\n"), uid[1]);
   1.118 +		test.Printf(_L("UID3 %08x\n"), uid[2]);
   1.119 +		test.Printf(_L("SID  %08x\n"), info.iSecurityInfo.iSecureId);
   1.120 +		test.Printf(_L("VID  %08x\n"), info.iSecurityInfo.iVendorId);
   1.121 +		test.Printf(_L("CAP0 %08x\n"), ((SSecurityInfo&)info.iSecurityInfo).iCaps[0]);
   1.122 +		test.Printf(_L("CAP1 %08x\n"), ((SSecurityInfo&)info.iSecurityInfo).iCaps[1]);
   1.123 +		TUint32 v = 0x00030000u;
   1.124 +		test(info.iModuleVersion == v);
   1.125 +		test(uid[0] == (TUint32)KDynamicLibraryUidValue);
   1.126 +		test(uid[2] == (TUint32)0x40abcdef);
   1.127 +		TUint32 xsid = ((v>>16)<<4)|(v&0x0f)|0x89abcd00u;
   1.128 +		test(info.iSecurityInfo.iSecureId == xsid);
   1.129 +		test(info.iSecurityInfo.iVendorId == 0x01234500+(xsid&0xff));
   1.130 +		test(((SSecurityInfo&)info.iSecurityInfo).iCaps[0]==0x0002aaab);
   1.131 +		test(((SSecurityInfo&)info.iSecurityInfo).iCaps[1]==0);
   1.132 +
   1.133 +		if(formHeader)
   1.134 +			break;
   1.135 +		formHeader = ETrue;
   1.136 +		}
   1.137 +	}
   1.138 +
   1.139 +void TestExeInfo()
   1.140 +	{
   1.141 +	TFileName fn;
   1.142 +	if(PlatSec::ConfigSetting(PlatSec::EPlatSecEnforceSysBin))
   1.143 +		fn = _S16("Z:\\sys\\bin\\t_xxver2w.exe");
   1.144 +	else
   1.145 +		fn = _S16("Z:\\system\\bin\\t_xxver2w.exe");
   1.146 +	test.Printf(_L("Getting info for %S\n"), &fn);
   1.147 +	TBool formHeader=EFalse;
   1.148 +	for(;;)
   1.149 +		{
   1.150 +		RLibrary::TInfo info;
   1.151 +		TPckg<RLibrary::TInfo> infoBuf(info);
   1.152 +		TInt r;
   1.153 +		if(formHeader)
   1.154 +			{
   1.155 +			TUint8* buf;
   1.156 +
   1.157 +			RFs fs;
   1.158 +			test(fs.Connect()==KErrNone);
   1.159 +			RFile file;
   1.160 +			test((r=file.Open(fs,CopyBinaryFromZ(fn),0))==KErrNone);
   1.161 +			TInt size;
   1.162 +			test((r=file.Size(size))==KErrNone);
   1.163 +			buf=new TUint8[size];
   1.164 +			test(buf!=0);
   1.165 +			TPtr8 header(buf,size);
   1.166 +			test((r=file.Read(header))==KErrNone);
   1.167 +			file.Close();
   1.168 +			fs.Close();
   1.169 +
   1.170 +			r = RLibrary::GetInfoFromHeader(header, infoBuf);
   1.171 +			test.Printf(_L("GetInfoFromHeader returns %d\n"), r);
   1.172 +
   1.173 +			delete buf;
   1.174 +			}
   1.175 +		else
   1.176 +			{
   1.177 +			r = RLibrary::GetInfo(fn, infoBuf);
   1.178 +			test.Printf(_L("GetInfo returns %d\n"), r);
   1.179 +			}
   1.180 +
   1.181 +		test(r==KErrNone);
   1.182 +		const TUint32* uid = (const TUint32*)&info.iUids;
   1.183 +		test.Printf(_L("VER  %08x\n"), info.iModuleVersion);
   1.184 +		test.Printf(_L("UID1 %08x\n"), uid[0]);
   1.185 +		test.Printf(_L("UID2 %08x\n"), uid[1]);
   1.186 +		test.Printf(_L("UID3 %08x\n"), uid[2]);
   1.187 +		test.Printf(_L("SID  %08x\n"), info.iSecurityInfo.iSecureId);
   1.188 +		test.Printf(_L("VID  %08x\n"), info.iSecurityInfo.iVendorId);
   1.189 +		test.Printf(_L("CAP0 %08x\n"), ((SSecurityInfo&)info.iSecurityInfo).iCaps[0]);
   1.190 +		test.Printf(_L("CAP1 %08x\n"), ((SSecurityInfo&)info.iSecurityInfo).iCaps[1]);
   1.191 +		test(info.iModuleVersion == 0x00010000);
   1.192 +		test(uid[0] == (TUint32)KExecutableImageUidValue);
   1.193 +		TUint32 xuid3 = 0x40abcd77u;
   1.194 +		test(uid[2] == xuid3);
   1.195 +		test(info.iSecurityInfo.iSecureId == xuid3);
   1.196 +		test(info.iSecurityInfo.iVendorId == 0x01234577);
   1.197 +		test(((SSecurityInfo&)info.iSecurityInfo).iCaps[0]==0x0002aaab);
   1.198 +		test(((SSecurityInfo&)info.iSecurityInfo).iCaps[1]==0);
   1.199 +
   1.200 +		if(formHeader)
   1.201 +			break;
   1.202 +		formHeader = ETrue;
   1.203 +		}
   1.204 +	}
   1.205 +
   1.206 +
   1.207 +struct SExportInfo
   1.208 +	{
   1.209 +	TInt	iTotal;
   1.210 +	TInt	iHoles;
   1.211 +	TInt	iHole[1];
   1.212 +	};
   1.213 +
   1.214 +const TInt DllExportInfo[] = {59,6,2,3,4,23,24,39};
   1.215 +void CheckExports(RLibrary aLib)
   1.216 +	{
   1.217 +	const TFileName& fn = aLib.FileName();
   1.218 +	test.Printf(_L("Filename %S\n"), &fn);
   1.219 +	const SExportInfo* e = (const SExportInfo*)DllExportInfo;
   1.220 +	TAny* libcs = LdrTest.LibraryCodeSeg(aLib.Handle());
   1.221 +	test.Printf(_L("Code seg @%08x\n"), libcs);
   1.222 +	test(libcs != NULL);
   1.223 +	TInt n = e->iTotal;
   1.224 +	TInt nh = e->iHoles;
   1.225 +	TInt ord;
   1.226 +	for (ord=1; ord<=n+1; ++ord)
   1.227 +		{
   1.228 +		TLibraryFunction f = aLib.Lookup(ord);
   1.229 +		test.Printf(_L("Ord %3d->%08x\n"), ord, f);
   1.230 +		if (ord>n)
   1.231 +			{
   1.232 +			test(!f);
   1.233 +			continue;
   1.234 +			}
   1.235 +		TInt i;
   1.236 +		for (i=0; i<nh && e->iHole[i]!=ord; ++i) {}
   1.237 +		if (i<nh)
   1.238 +			test(!f);	// hole
   1.239 +		else
   1.240 +			test(f!=NULL);
   1.241 +		TAny* cs = LdrTest.CodeSegFromAddr((TLinAddr)f);
   1.242 +		test(f ? (cs==libcs) : !cs);
   1.243 +		}
   1.244 +	}
   1.245 +
   1.246 +void TestMissingOrdinals()
   1.247 +	{
   1.248 +	RLibrary l;
   1.249 +	TFileName fn;
   1.250 +	if(PlatSec::ConfigSetting(PlatSec::EPlatSecEnforceSysBin))
   1.251 +		fn = _S("Z:\\sys\\bin\\t_ver2.dll");
   1.252 +	else
   1.253 +		fn = _S("Z:\\system\\bin\\t_ver2.dll");
   1.254 +	TInt r = l.Load(fn);
   1.255 +	test.Printf(_L("Load %S returns %d\n"), &fn, r);
   1.256 +	CheckExports(l);
   1.257 +	l.Close();
   1.258 +	}
   1.259 +
   1.260 +TInt E32Main()
   1.261 +	{
   1.262 +	test.Title();
   1.263 +
   1.264 +	test.Start(_L("Connect to test driver"));
   1.265 +	TInt r = User::LoadLogicalDevice(_L("d_ldrtst"));
   1.266 +	test(r==KErrNone || r==KErrAlreadyExists);
   1.267 +	r = LdrTest.Open();
   1.268 +	test(r==KErrNone);
   1.269 +
   1.270 +	test.Next(_L("Test DLL Info"));
   1.271 +	TestDllInfo();
   1.272 +
   1.273 +	test.Next(_L("Test EXE Info"));
   1.274 +	TestExeInfo();
   1.275 +
   1.276 +	test.Next(_L("Test Missing Ordinals"));
   1.277 +	TestMissingOrdinals();
   1.278 +
   1.279 +	LdrTest.Close();
   1.280 +	test.End();
   1.281 +	return KErrNone;
   1.282 +	}
   1.283 +