os/kernelhwsrv/kerneltest/e32test/dll/t_xxver2.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of the License "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// e32test\dll\t_xxver2.cpp
sl@0
    15
// Overview:
sl@0
    16
// Test matching algorithm for DLL versions. Test aspects of DLL and EXE files.
sl@0
    17
// API Information:
sl@0
    18
// RLibrary
sl@0
    19
// Details:
sl@0
    20
// - This test makes use of 4 versions of a single DLL, and 15 EXEs which link
sl@0
    21
// against it.  The EXEs all have different reqirements on which DLL versions
sl@0
    22
// are acceptable
sl@0
    23
// - Test that the correct version of linked libraries are used (Run for each
sl@0
    24
// EXE and for the 16 combinations in which the 4 versions of the DLL can be
sl@0
    25
// available.  The test is performed with each EXE run in sequence, and again
sl@0
    26
// with all of them run at the same time)
sl@0
    27
// - Test that the correct version of dynamically loaded libraries are used and
sl@0
    28
// the libary exports are as expected.  (Run for each DLL version and for the
sl@0
    29
// 16 combinations of DLL availability)
sl@0
    30
// - Test that RLibrary::GetInfo and RLibrary::GetInfoFromHeader return the
sl@0
    31
// expected data for all DLLs and EXEs
sl@0
    32
// Platforms/Drives/Compatibility:
sl@0
    33
// All.
sl@0
    34
// Assumptions/Requirement/Pre-requisites:
sl@0
    35
// Failures and causes:
sl@0
    36
// Base Port information:
sl@0
    37
// 
sl@0
    38
//
sl@0
    39
sl@0
    40
#include <e32uid.h>
sl@0
    41
#include <e32test.h>
sl@0
    42
#include <f32file.h>
sl@0
    43
#include <d_ldrtst.h>
sl@0
    44
#include <f32image.h>
sl@0
    45
sl@0
    46
RTest test(_L("T_XXVER2"));
sl@0
    47
RFs	gFs;
sl@0
    48
CFileMan* gFileMan;
sl@0
    49
RLdrTest LdrTest;
sl@0
    50
sl@0
    51
TBuf<8> SourcePath = _S16("Z:\\img\\");
sl@0
    52
sl@0
    53
sl@0
    54
TFileName KDestPath()
sl@0
    55
	{
sl@0
    56
	_LIT(KDestPath, "C:\\system\\bin\\ver");
sl@0
    57
	_LIT(KDestPathSysBin, "C:\\sys\\bin\\ver");
sl@0
    58
	if(PlatSec::ConfigSetting(PlatSec::EPlatSecEnforceSysBin))
sl@0
    59
		return KDestPathSysBin();
sl@0
    60
	else
sl@0
    61
		return KDestPath();
sl@0
    62
	}
sl@0
    63
sl@0
    64
_LIT(KDllName0, "t_ver2{00010000}.dll");
sl@0
    65
_LIT(KDllName1, "t_ver2{00010001}.dll");
sl@0
    66
_LIT(KDllName2, "t_ver2{00020000}.dll");
sl@0
    67
_LIT(KDllName3, "t_ver2.dll");
sl@0
    68
sl@0
    69
const TDesC* const DllArray[] =
sl@0
    70
	{
sl@0
    71
	&KDllName0(),
sl@0
    72
	&KDllName1(),
sl@0
    73
	&KDllName2(),
sl@0
    74
	&KDllName3()
sl@0
    75
	};
sl@0
    76
sl@0
    77
const TInt KNumDlls = sizeof(DllArray)/sizeof(const TDesC* const);
sl@0
    78
sl@0
    79
const TInt DllVersion[KNumDlls] =
sl@0
    80
	{
sl@0
    81
	0x00010000,
sl@0
    82
	0x00010001,
sl@0
    83
	0x00020000,
sl@0
    84
	0x00030000
sl@0
    85
	};
sl@0
    86
sl@0
    87
const TInt KNumTestVersions = 7;
sl@0
    88
const TInt TestDllVersion[KNumTestVersions] =
sl@0
    89
	{
sl@0
    90
	0x00000000,
sl@0
    91
	0x00010000,
sl@0
    92
	0x00010001,
sl@0
    93
	0x00010002,
sl@0
    94
	0x00020000,
sl@0
    95
	0x00030000,
sl@0
    96
	0x00040000
sl@0
    97
	};
sl@0
    98
sl@0
    99
_LIT(KExeName0, "t_xver2a.exe");	// request 1.0 work with any
sl@0
   100
_LIT(KExeName1, "t_xver2b.exe");	// request 1.0 work with 2.0 but not 3.0
sl@0
   101
_LIT(KExeName2, "t_xver2c.exe");	// request 1.0 don't work with 2.0
sl@0
   102
_LIT(KExeName3, "t_xver2d.exe");	// request 1.1 work with 1.0 but not 2.0
sl@0
   103
_LIT(KExeName4, "t_xver2e.exe");	// request 1.1 work with any
sl@0
   104
_LIT(KExeName5, "t_xver2f.exe");	// request 1.1 work with 2.0, 3.0 but not with 1.0
sl@0
   105
_LIT(KExeName6, "t_xver2g.exe");	// request 1.1 don't work with 2.0, 3.0 or 1.0
sl@0
   106
_LIT(KExeName7, "t_xver2h.exe");	// request 1.1 work with 1.0 and 2.0 but not 3.0
sl@0
   107
_LIT(KExeName8, "t_xver2i.exe");	// request 1.1 work with 2.0 but not 3.0 or 1.0
sl@0
   108
_LIT(KExeName9, "t_xver2j.exe");	// request 2.0 only use 1.0 exports
sl@0
   109
_LIT(KExeName10, "t_xver2k.exe");	// request 2.0 only use 1.0, 1.1 exports
sl@0
   110
_LIT(KExeName11, "t_xver2l.exe");	// request 2.0 use 2.0 exports work on 3.0
sl@0
   111
_LIT(KExeName12, "t_xver2m.exe");	// request 2.0 use 2.0 exports, don't work on 3.0
sl@0
   112
_LIT(KExeName13, "t_xver2n.exe");	// request 3.0 use 1.0 exports only
sl@0
   113
_LIT(KExeName14, "t_xver2o.exe");	// request 3.0 use all
sl@0
   114
sl@0
   115
const TDesC* const ExeArray[] =
sl@0
   116
	{
sl@0
   117
	&KExeName0(),
sl@0
   118
	&KExeName1(),
sl@0
   119
	&KExeName2(),
sl@0
   120
	&KExeName3(),
sl@0
   121
	&KExeName4(),
sl@0
   122
	&KExeName5(),
sl@0
   123
	&KExeName6(),
sl@0
   124
	&KExeName7(),
sl@0
   125
	&KExeName8(),
sl@0
   126
	&KExeName9(),
sl@0
   127
	&KExeName10(),
sl@0
   128
	&KExeName11(),
sl@0
   129
	&KExeName12(),
sl@0
   130
	&KExeName13(),
sl@0
   131
	&KExeName14()
sl@0
   132
	};
sl@0
   133
sl@0
   134
const TInt KNumExes = sizeof(ExeArray)/sizeof(const TDesC* const);
sl@0
   135
sl@0
   136
const TInt ResultArray[KNumExes<<KNumDlls] =
sl@0
   137
	{
sl@0
   138
//	DLLs Present			A	B	C	D	E	F	G	H	I	J	K	L	M	N	O
sl@0
   139
// None
sl@0
   140
							-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,	-1,
sl@0
   141
// 1.0
sl@0
   142
							0,	0,	0,	0,	0,	-1,	-1,	0,	-1,	-1,	-1,	-1,	-1,	-1,	-1,
sl@0
   143
// 1.1
sl@0
   144
							1,	1,	1,	1,	1,	1,	1,	1,	1,	-1,	-1,	-1,	-1,	-1,	-1,
sl@0
   145
// 1.0, 1.1
sl@0
   146
							1,	1,	1,	1,	1,	1,	1,	1,	1,	-1,	-1,	-1,	-1,	-1,	-1,
sl@0
   147
// 2.0
sl@0
   148
							2,	2,	-1,	-1,	2,	2,	-1,	2,	2,	2,	2,	2,	2,	-1,	-1,
sl@0
   149
// 2.0, 1.0
sl@0
   150
							0,	0,	0,	0,	2,	2,	-1,	2,	2,	2,	2,	2,	2,	-1,	-1,
sl@0
   151
// 2.0, 1.1
sl@0
   152
							1,	1,	1,	1,	1,	1,	1,	1,	1,	2,	2,	2,	2,	-1,	-1,
sl@0
   153
// 2.0, 1.1, 1.0
sl@0
   154
							1,	1,	1,	1,	1,	1,	1,	1,	1,	2,	2,	2,	2,	-1,	-1,
sl@0
   155
// 3.0
sl@0
   156
							3,	-1,	-1,	-1,	3,	3,	-1,	-1,	-1,	3,	3,	3,	-1,	3,	3,
sl@0
   157
// 3.0, 1.0
sl@0
   158
							0,	0,	0,	0,	3,	3,	-1,	0,	-1,	3,	3,	3,	-1,	3,	3,
sl@0
   159
// 3.0, 1.1
sl@0
   160
							1,	1,	1,	1,	1,	1,	1,	1,	1,	3,	3,	3,	-1,	3,	3,
sl@0
   161
// 3.0, 1.1, 1.0
sl@0
   162
							1,	1,	1,	1,	1,	1,	1,	1,	1,	3,	3,	3,	-1,	3,	3,
sl@0
   163
// 3.0, 2.0
sl@0
   164
							2,	2,	-1,	-1,	2,	2,	-1,	2,	2,	2,	2,	2,	2,	3,	3,
sl@0
   165
// 3.0, 2.0, 1.0
sl@0
   166
							0,	0,	0,	0,	2,	2,	-1,	2,	2,	2,	2,	2,	2,	3,	3,
sl@0
   167
// 3.0, 2.0, 1.1
sl@0
   168
							1,	1,	1,	1,	1,	1,	1,	1,	1,	2,	2,	2,	2,	3,	3,
sl@0
   169
// 3.0, 2.0, 1.1, 1.0
sl@0
   170
							1,	1,	1,	1,	1,	1,	1,	1,	1,	2,	2,	2,	2,	3,	3
sl@0
   171
//
sl@0
   172
	};
sl@0
   173
sl@0
   174
const TInt ResultArray2[KNumTestVersions<<KNumDlls] =
sl@0
   175
	{
sl@0
   176
//	DLLs Present			0.0	1.0	1.1	1.2	2.0	3.0	4.0
sl@0
   177
// None
sl@0
   178
							-1,	-1,	-1,	-1,	-1,	-1,	-1,
sl@0
   179
// 1.0
sl@0
   180
							-1,	0,	-1,	-1,	-1,	-1,	-1,
sl@0
   181
// 1.1
sl@0
   182
							-1,	1,	1,	-1,	-1,	-1,	-1,
sl@0
   183
// 1.0, 1.1
sl@0
   184
							-1,	1,	1,	-1,	-1,	-1,	-1,
sl@0
   185
// 2.0
sl@0
   186
							-1,	-1,	-1,	-1,	2,	-1,	-1,
sl@0
   187
// 2.0, 1.0
sl@0
   188
							-1,	0,	-1,	-1,	2,	-1,	-1,
sl@0
   189
// 2.0, 1.1
sl@0
   190
							-1,	1,	1,	-1,	2,	-1,	-1,
sl@0
   191
// 2.0, 1.1, 1.0
sl@0
   192
							-1,	1,	1,	-1,	2,	-1,	-1,
sl@0
   193
// 3.0
sl@0
   194
							-1,	-1,	-1,	-1,	-1,	3,	-1,
sl@0
   195
// 3.0, 1.0
sl@0
   196
							-1,	0,	-1,	-1,	-1,	3,	-1,
sl@0
   197
// 3.0, 1.1
sl@0
   198
							-1,	1,	1,	-1,	-1,	3,	-1,
sl@0
   199
// 3.0, 1.1, 1.0
sl@0
   200
							-1,	1,	1,	-1,	-1,	3,	-1,
sl@0
   201
// 3.0, 2.0
sl@0
   202
							-1,	-1,	-1,	-1,	2,	3,	-1,
sl@0
   203
// 3.0, 2.0, 1.0
sl@0
   204
							-1,	0,	-1,	-1,	2,	3,	-1,
sl@0
   205
// 3.0, 2.0, 1.1
sl@0
   206
							-1,	1,	1,	-1,	2,	3,	-1,
sl@0
   207
// 3.0, 2.0, 1.1, 1.0
sl@0
   208
							-1,	1,	1,	-1,	2,	3,	-1
sl@0
   209
//
sl@0
   210
	};
sl@0
   211
sl@0
   212
struct SExportInfo
sl@0
   213
	{
sl@0
   214
	TInt	iTotal;
sl@0
   215
	TInt	iHoles;
sl@0
   216
	TInt	iHole[1];
sl@0
   217
	};
sl@0
   218
sl@0
   219
const TInt Dll0ExportInfo[] = {19,0};
sl@0
   220
const TInt Dll1ExportInfo[] = {29,0};
sl@0
   221
const TInt Dll2ExportInfo[] = {39,4,2,3,23,24};
sl@0
   222
const TInt Dll3ExportInfo[] = {59,6,2,3,4,23,24,39};
sl@0
   223
sl@0
   224
const SExportInfo* const DllExportInfo[KNumDlls] =
sl@0
   225
	{
sl@0
   226
	(const SExportInfo*)Dll0ExportInfo,
sl@0
   227
	(const SExportInfo*)Dll1ExportInfo,
sl@0
   228
	(const SExportInfo*)Dll2ExportInfo,
sl@0
   229
	(const SExportInfo*)Dll3ExportInfo
sl@0
   230
	};
sl@0
   231
sl@0
   232
void CheckExports(TInt aDllNum, RLibrary aLib)
sl@0
   233
	{
sl@0
   234
	test.Printf(_L("Testing exports for DLL %d\n"), aDllNum);
sl@0
   235
	const TFileName& fn = aLib.FileName();
sl@0
   236
	test.Printf(_L("Filename %S\n"), &fn);
sl@0
   237
	const SExportInfo* e = DllExportInfo[aDllNum];
sl@0
   238
	TAny* libcs = LdrTest.LibraryCodeSeg(aLib.Handle());
sl@0
   239
	test.Printf(_L("Code seg @%08x\n"), libcs);
sl@0
   240
	test(libcs != NULL);
sl@0
   241
	TInt n = e->iTotal;
sl@0
   242
	TInt nh = e->iHoles;
sl@0
   243
	TInt ord;
sl@0
   244
	for (ord=1; ord<=n+1; ++ord)
sl@0
   245
		{
sl@0
   246
		TLibraryFunction f = aLib.Lookup(ord);
sl@0
   247
		test.Printf(_L("Ord %3d->%08x\n"), ord, f);
sl@0
   248
		if (ord>n)
sl@0
   249
			{
sl@0
   250
			test(!f);
sl@0
   251
			continue;
sl@0
   252
			}
sl@0
   253
		TInt i;
sl@0
   254
		for (i=0; i<nh && e->iHole[i]!=ord; ++i) {}
sl@0
   255
		if (i<nh)
sl@0
   256
			test(!f);	// hole
sl@0
   257
		else
sl@0
   258
			test(f!=NULL);
sl@0
   259
		TAny* cs = LdrTest.CodeSegFromAddr((TLinAddr)f);
sl@0
   260
		test(f ? (cs==libcs) : !cs);
sl@0
   261
		}
sl@0
   262
	}
sl@0
   263
sl@0
   264
void CreateAndPopulateDir(TUint aMask)
sl@0
   265
	{
sl@0
   266
	test.Printf(_L("CreateAndPopulateDir %d\n"), aMask);
sl@0
   267
	TFileName fn = KDestPath();
sl@0
   268
	fn.AppendNumFixedWidth(aMask, EDecimal, 2);
sl@0
   269
	fn.Append('\\');
sl@0
   270
	TInt r = gFs.MkDirAll(fn);
sl@0
   271
	test.Printf(_L("MkDir %S->%d\n"), &fn, r);
sl@0
   272
	test(r==KErrNone || r==KErrAlreadyExists);
sl@0
   273
	TFileName fn2 = fn;
sl@0
   274
	fn2.Append(_L("*.*"));
sl@0
   275
	TTime now;
sl@0
   276
	now.HomeTime();
sl@0
   277
	r = gFileMan->Attribs(fn2, 0, KEntryAttReadOnly|KEntryAttHidden|KEntryAttSystem|KEntryAttArchive, now);
sl@0
   278
	test.Printf(_L("Attribs %S->%d\n"), &fn2, r);
sl@0
   279
	r = gFileMan->Delete(fn2);
sl@0
   280
	test.Printf(_L("Delete %S->%d\n"), &fn2, r);
sl@0
   281
	TInt n = 0;
sl@0
   282
	for (; aMask; aMask>>=1, ++n)
sl@0
   283
		{
sl@0
   284
		if (!(aMask & 1))
sl@0
   285
			continue;
sl@0
   286
		fn2 = fn;
sl@0
   287
		fn2.Append(*DllArray[n]);
sl@0
   288
		TFileName src = SourcePath;
sl@0
   289
		src.Append(*DllArray[n]);
sl@0
   290
		r = gFileMan->Copy(src, fn2);
sl@0
   291
		test.Printf(_L("%S->%S (%d)\n"), &src, &fn2, r);
sl@0
   292
		test(r == KErrNone);
sl@0
   293
		}
sl@0
   294
	for (n=0; n<KNumExes; ++n)
sl@0
   295
		{
sl@0
   296
		fn2 = fn;
sl@0
   297
		fn2.Append(*ExeArray[n]);
sl@0
   298
		TFileName src = SourcePath;
sl@0
   299
		src.Append(*ExeArray[n]);
sl@0
   300
		r = gFileMan->Copy(src, fn2);
sl@0
   301
		test.Printf(_L("%S->%S (%d)\n"), &src, &fn2, r);
sl@0
   302
		test(r == KErrNone);
sl@0
   303
		}
sl@0
   304
	}
sl@0
   305
sl@0
   306
void RunExe(TUint aMask, TInt aExeNum)
sl@0
   307
	{
sl@0
   308
	test.Printf(_L("RunExe mask %d exenum %d\n"), aMask, aExeNum);
sl@0
   309
	RProcess p;
sl@0
   310
	TRequestStatus s;
sl@0
   311
	TFileName fn = KDestPath();
sl@0
   312
	fn.AppendNumFixedWidth(aMask, EDecimal, 2);
sl@0
   313
	fn.Append('\\');
sl@0
   314
	fn.Append(*ExeArray[aExeNum]);
sl@0
   315
	TInt r = p.Create(fn, KNullDesC);
sl@0
   316
	test.Printf(_L("Create %S->%d\n"), &fn, r);
sl@0
   317
	TInt rix = aExeNum + KNumExes*TInt(aMask);
sl@0
   318
	TInt expected = ResultArray[rix];
sl@0
   319
	test.Printf(_L("RunExe expected %d\n"), expected);
sl@0
   320
	if (expected<0)
sl@0
   321
		{
sl@0
   322
		test(r<0);
sl@0
   323
		return;
sl@0
   324
		}
sl@0
   325
	p.Logon(s);
sl@0
   326
	p.Resume();
sl@0
   327
	User::WaitForRequest(s);
sl@0
   328
	if (p.ExitType()!=EExitKill)
sl@0
   329
		{
sl@0
   330
		TInt et = p.ExitType();
sl@0
   331
		TInt er = p.ExitReason();
sl@0
   332
		const TDesC& ec = p.ExitCategory();
sl@0
   333
		test.Printf(_L("Exit %d,%d,%S\n"), et, er, &ec);
sl@0
   334
		test(0);
sl@0
   335
		}
sl@0
   336
	CLOSE_AND_WAIT(p);
sl@0
   337
	test.Printf(_L("Return code %08x\n"), s.Int());
sl@0
   338
	test(s.Int() == DllVersion[expected]);
sl@0
   339
	}
sl@0
   340
sl@0
   341
void RunExes(TUint aMask)
sl@0
   342
	{
sl@0
   343
	test.Printf(_L("RunExes mask %d\n"), aMask);
sl@0
   344
	RProcess p[KNumExes];
sl@0
   345
	TRequestStatus s[KNumExes];
sl@0
   346
	TInt xn;
sl@0
   347
	for (xn=0; xn<KNumExes; ++xn)
sl@0
   348
		{
sl@0
   349
		TFileName fn = KDestPath();
sl@0
   350
		fn.AppendNumFixedWidth(aMask, EDecimal, 2);
sl@0
   351
		fn.Append('\\');
sl@0
   352
		fn.Append(*ExeArray[xn]);
sl@0
   353
		TInt r = p[xn].Create(fn, KNullDesC);
sl@0
   354
		test.Printf(_L("Create %S->%d\n"), &fn, r);
sl@0
   355
		TInt rix = xn + KNumExes*TInt(aMask);
sl@0
   356
		TInt expected = ResultArray[rix];
sl@0
   357
		test.Printf(_L("RunExe expected %d\n"), expected);
sl@0
   358
		if (expected<0)
sl@0
   359
			{
sl@0
   360
			test(r<0);
sl@0
   361
			continue;
sl@0
   362
			}
sl@0
   363
		p[xn].Logon(s[xn]);
sl@0
   364
		}
sl@0
   365
	for (xn=0; xn<KNumExes; ++xn)
sl@0
   366
		{
sl@0
   367
		TInt rix = xn + KNumExes*TInt(aMask);
sl@0
   368
		TInt expected = ResultArray[rix];
sl@0
   369
		if (expected<0)
sl@0
   370
			continue;
sl@0
   371
		p[xn].Resume();
sl@0
   372
		}
sl@0
   373
	for (xn=0; xn<KNumExes; ++xn)
sl@0
   374
		{
sl@0
   375
		TInt rix = xn + KNumExes*TInt(aMask);
sl@0
   376
		TInt expected = ResultArray[rix];
sl@0
   377
		if (expected<0)
sl@0
   378
			continue;
sl@0
   379
		User::WaitForRequest(s[xn]);
sl@0
   380
		if (p[xn].ExitType()!=EExitKill)
sl@0
   381
			{
sl@0
   382
			TInt et = p[xn].ExitType();
sl@0
   383
			TInt er = p[xn].ExitReason();
sl@0
   384
			const TDesC& ec = p[xn].ExitCategory();
sl@0
   385
			test.Printf(_L("Exit %d,%d,%S\n"), et, er, &ec);
sl@0
   386
			test(0);
sl@0
   387
			}
sl@0
   388
		CLOSE_AND_WAIT(p[xn]);
sl@0
   389
		test.Printf(_L("Return code %08x\n"), s[xn].Int());
sl@0
   390
		test(s[xn].Int() == DllVersion[expected]);
sl@0
   391
		}
sl@0
   392
	}
sl@0
   393
sl@0
   394
void TestDynamic(TUint aMask, TInt aTN)
sl@0
   395
	{
sl@0
   396
	TUint32 ver = TestDllVersion[aTN];
sl@0
   397
	TInt rix = aTN + KNumTestVersions*TInt(aMask);
sl@0
   398
	TInt expected = ResultArray2[rix];
sl@0
   399
	test.Printf(_L("ReqVer %08x Expected %d\n"), ver, expected);
sl@0
   400
	TFileName path = KDestPath();
sl@0
   401
	path.AppendNumFixedWidth(aMask, EDecimal, 2);
sl@0
   402
	TFileName fn = path;
sl@0
   403
	fn.Append(_L("\\T_VER2.DLL"));
sl@0
   404
	RLibrary l;
sl@0
   405
	TInt r = l.Load(fn, KNullDesC, TUidType(), ver);
sl@0
   406
	test.Printf(_L("Load %S returns %d\n"), &fn, r);
sl@0
   407
	if (expected<0)
sl@0
   408
		{
sl@0
   409
		test(r<0);
sl@0
   410
		return;
sl@0
   411
		}
sl@0
   412
	TLibraryFunction f = l.Lookup(1);
sl@0
   413
	test(f != 0);
sl@0
   414
	TInt result = (*f)();
sl@0
   415
	test.Printf(_L("Ord 1 returns %08x\n"), result);
sl@0
   416
	test(result == DllVersion[expected]);
sl@0
   417
	l.Close();
sl@0
   418
	r = l.Load(_L("T_VER2.DLL"), path, TUidType(), ver);
sl@0
   419
	test.Printf(_L("Load T_VER2.DLL path %S returns %d\n"), &path, r);
sl@0
   420
	if (expected<0)
sl@0
   421
		{
sl@0
   422
		test(r<0);
sl@0
   423
		return;
sl@0
   424
		}
sl@0
   425
	f = l.Lookup(1);
sl@0
   426
	test(f != 0);
sl@0
   427
	result = (*f)();
sl@0
   428
	test.Printf(_L("Ord 1 returns %08x\n"), result);
sl@0
   429
	test(result == DllVersion[expected]);
sl@0
   430
	CheckExports(expected, l);
sl@0
   431
	l.Close();
sl@0
   432
	}
sl@0
   433
sl@0
   434
void TestLibraryInfo(TInt aN)
sl@0
   435
	{
sl@0
   436
	TFileName fn;
sl@0
   437
	if(PlatSec::ConfigSetting(PlatSec::EPlatSecEnforceSysBin))
sl@0
   438
		fn = _S16("C:\\sys\\bin\\ver15\\");
sl@0
   439
	else
sl@0
   440
		fn = _S16("C:\\system\\bin\\ver15\\");
sl@0
   441
	fn += *DllArray[aN];
sl@0
   442
	test.Printf(_L("Getting info for %S\n"), &fn);
sl@0
   443
	TBool formHeader=EFalse;
sl@0
   444
	for(;;)
sl@0
   445
		{
sl@0
   446
		RLibrary::TInfoV2 info;
sl@0
   447
		TPckg<RLibrary::TInfoV2> infoBuf(info);
sl@0
   448
		TInt r;
sl@0
   449
		if(formHeader)
sl@0
   450
			{
sl@0
   451
			TUint8* buf;
sl@0
   452
sl@0
   453
			RFs fs;
sl@0
   454
			test(fs.Connect()==KErrNone);
sl@0
   455
			RFile file;
sl@0
   456
			test((r=file.Open(fs,fn,0))==KErrNone);
sl@0
   457
			TInt size;
sl@0
   458
			test((r=file.Size(size))==KErrNone);
sl@0
   459
			if(size>RLibrary::KRequiredImageHeaderSize)
sl@0
   460
				size=RLibrary::KRequiredImageHeaderSize;
sl@0
   461
			buf=new TUint8[size];
sl@0
   462
			test(buf!=0);
sl@0
   463
			TPtr8 header(buf,size);
sl@0
   464
			test((r=file.Read(header))==KErrNone);
sl@0
   465
			file.Close();
sl@0
   466
			fs.Close();
sl@0
   467
sl@0
   468
			r = RLibrary::GetInfoFromHeader(header, infoBuf);
sl@0
   469
			test.Printf(_L("GetInfoFromHeader returns %d\n"), r);
sl@0
   470
sl@0
   471
			delete buf;
sl@0
   472
			}
sl@0
   473
		else
sl@0
   474
			{
sl@0
   475
			r = RLibrary::GetInfo(fn, infoBuf);
sl@0
   476
			test.Printf(_L("GetInfo returns %d\n"), r);
sl@0
   477
			}
sl@0
   478
sl@0
   479
		test(r==KErrNone);
sl@0
   480
		const TUint32* uid = (const TUint32*)&info.iUids;
sl@0
   481
		test.Printf(_L("VER  %08x\n"), info.iModuleVersion);
sl@0
   482
		test.Printf(_L("UID1 %08x\n"), uid[0]);
sl@0
   483
		test.Printf(_L("UID2 %08x\n"), uid[1]);
sl@0
   484
		test.Printf(_L("UID3 %08x\n"), uid[2]);
sl@0
   485
		test.Printf(_L("SID  %08x\n"), (TUint32)info.iSecurityInfo.iSecureId);
sl@0
   486
		test.Printf(_L("VID  %08x\n"), (TUint32)info.iSecurityInfo.iVendorId);
sl@0
   487
		test.Printf(_L("CAP0 %08x\n"), ((SSecurityInfo&)info.iSecurityInfo).iCaps[0]);
sl@0
   488
		test.Printf(_L("CAP1 %08x\n"), ((SSecurityInfo&)info.iSecurityInfo).iCaps[1]);
sl@0
   489
		TUint32 v = (TUint32)DllVersion[aN];
sl@0
   490
		test(info.iModuleVersion == v);
sl@0
   491
		test(uid[0] == (TUint32)KDynamicLibraryUidValue);
sl@0
   492
		test(uid[2] == (TUint32)0x40abcdef);
sl@0
   493
		TUint32 xsid = ((v>>16)<<4)|(v&0x0f)|0x89abcd00u;
sl@0
   494
		test(info.iSecurityInfo.iSecureId == xsid);
sl@0
   495
		TUint32 xvid = 0x01234500+(xsid&0xff);
sl@0
   496
		test(info.iSecurityInfo.iVendorId == xvid);
sl@0
   497
		test(((SSecurityInfo&)info.iSecurityInfo).iCaps[0]==0x0002aaab);
sl@0
   498
		test(((SSecurityInfo&)info.iSecurityInfo).iCaps[1]==0);
sl@0
   499
		if(formHeader)
sl@0
   500
#if defined(__ARMCC__)
sl@0
   501
			test(info.iHardwareFloatingPoint == EFpTypeVFPv2);
sl@0
   502
#else
sl@0
   503
			test(info.iHardwareFloatingPoint == EFpTypeNone);
sl@0
   504
#endif
sl@0
   505
sl@0
   506
		if(formHeader)
sl@0
   507
			break;
sl@0
   508
		formHeader = ETrue;
sl@0
   509
		}
sl@0
   510
	}
sl@0
   511
sl@0
   512
void TestExeInfo(TInt aN)
sl@0
   513
	{
sl@0
   514
	TFileName fn;
sl@0
   515
	if(PlatSec::ConfigSetting(PlatSec::EPlatSecEnforceSysBin))
sl@0
   516
		fn = _S16("C:\\sys\\bin\\ver15\\");
sl@0
   517
	else
sl@0
   518
		fn = _S16("C:\\system\\bin\\ver15\\");
sl@0
   519
	fn += *ExeArray[aN];
sl@0
   520
	test.Printf(_L("Getting info for %S\n"), &fn);
sl@0
   521
	TBool formHeader=EFalse;
sl@0
   522
	for(;;)
sl@0
   523
		{
sl@0
   524
		RLibrary::TInfoV2 info;
sl@0
   525
		TPckg<RLibrary::TInfoV2> infoBuf(info);
sl@0
   526
		TInt r;
sl@0
   527
		if(formHeader)
sl@0
   528
			{
sl@0
   529
			TUint8* buf;
sl@0
   530
sl@0
   531
			RFs fs;
sl@0
   532
			test(fs.Connect()==KErrNone);
sl@0
   533
			RFile file;
sl@0
   534
			test((r=file.Open(fs,fn,0))==KErrNone);
sl@0
   535
			TInt size;
sl@0
   536
			test((r=file.Size(size))==KErrNone);
sl@0
   537
			if(size>RLibrary::KRequiredImageHeaderSize)
sl@0
   538
				size=RLibrary::KRequiredImageHeaderSize;
sl@0
   539
			buf=new TUint8[size];
sl@0
   540
			test(buf!=0);
sl@0
   541
			TPtr8 header(buf,size);
sl@0
   542
			test((r=file.Read(header))==KErrNone);
sl@0
   543
			file.Close();
sl@0
   544
			fs.Close();
sl@0
   545
sl@0
   546
			r = RLibrary::GetInfoFromHeader(header, infoBuf);
sl@0
   547
			test.Printf(_L("GetInfoFromHeader returns %d\n"), r);
sl@0
   548
sl@0
   549
			delete buf;
sl@0
   550
			}
sl@0
   551
		else
sl@0
   552
			{
sl@0
   553
			r = RLibrary::GetInfo(fn, infoBuf);
sl@0
   554
			test.Printf(_L("GetInfo returns %d\n"), r);
sl@0
   555
			}
sl@0
   556
sl@0
   557
		test(r==KErrNone);
sl@0
   558
		const TUint32* uid = (const TUint32*)&info.iUids;
sl@0
   559
		test.Printf(_L("VER  %08x\n"), info.iModuleVersion);
sl@0
   560
		test.Printf(_L("UID1 %08x\n"), uid[0]);
sl@0
   561
		test.Printf(_L("UID2 %08x\n"), uid[1]);
sl@0
   562
		test.Printf(_L("UID3 %08x\n"), uid[2]);
sl@0
   563
		test.Printf(_L("SID  %08x\n"), (TUint32)info.iSecurityInfo.iSecureId);
sl@0
   564
		test.Printf(_L("VID  %08x\n"), (TUint32)info.iSecurityInfo.iVendorId);
sl@0
   565
		test.Printf(_L("CAP0 %08x\n"), ((SSecurityInfo&)info.iSecurityInfo).iCaps[0]);
sl@0
   566
		test.Printf(_L("CAP1 %08x\n"), ((SSecurityInfo&)info.iSecurityInfo).iCaps[1]);
sl@0
   567
	#if defined(__EABI__) && !defined(__X86__)
sl@0
   568
		test(info.iModuleVersion == 0x000a0000);
sl@0
   569
	#else
sl@0
   570
		test(info.iModuleVersion == 0x00010000);
sl@0
   571
	#endif
sl@0
   572
		test(uid[0] == (TUint32)KExecutableImageUidValue);
sl@0
   573
		TUint32 xuid3 = 0x40abcd61u + aN;
sl@0
   574
		test(uid[2] == xuid3);
sl@0
   575
		test(info.iSecurityInfo.iSecureId == xuid3);
sl@0
   576
		TUint32 xvid = 0x01234500+(xuid3&0xff);
sl@0
   577
		test(info.iSecurityInfo.iVendorId == xvid);
sl@0
   578
		test(((SSecurityInfo&)info.iSecurityInfo).iCaps[0]==0x0002aaab);
sl@0
   579
		test(((SSecurityInfo&)info.iSecurityInfo).iCaps[1]==0);
sl@0
   580
		if(formHeader)
sl@0
   581
			test(info.iHardwareFloatingPoint == EFpTypeNone);
sl@0
   582
sl@0
   583
		if(formHeader)
sl@0
   584
			break;
sl@0
   585
		formHeader = ETrue;
sl@0
   586
		}
sl@0
   587
	}
sl@0
   588
	
sl@0
   589
void TestCompression(void)
sl@0
   590
	{
sl@0
   591
	
sl@0
   592
	// Check target directory
sl@0
   593
	TFileName fn;
sl@0
   594
	if(PlatSec::ConfigSetting(PlatSec::EPlatSecEnforceSysBin))
sl@0
   595
		fn = _S16("c:\\sys\\bin\\");
sl@0
   596
	else
sl@0
   597
		fn = _S16("c:\\system\\bin\\");
sl@0
   598
	
sl@0
   599
	TInt r = gFs.MkDirAll(fn);
sl@0
   600
	test.Printf(_L("MkDir %S->%d\n"), &fn, r);
sl@0
   601
	test(r==KErrNone || r==KErrAlreadyExists);
sl@0
   602
	
sl@0
   603
	// Make copy from t_xxver2.exe to t_xxvercomp.exe 
sl@0
   604
	fn.Append(_L("t_xxvercomp.exe"));
sl@0
   605
	
sl@0
   606
	TFileName fn2 = fn;
sl@0
   607
	TTime now;
sl@0
   608
	now.HomeTime();
sl@0
   609
	r = gFileMan->Attribs(fn2, 0, KEntryAttReadOnly|KEntryAttHidden|KEntryAttSystem|KEntryAttArchive, now);
sl@0
   610
	test.Printf(_L("Attribs %S->%d\n"), &fn2, r);
sl@0
   611
	r = gFileMan->Delete(fn2);
sl@0
   612
	test.Printf(_L("Delete %S->%d\n"), &fn2, r);
sl@0
   613
sl@0
   614
	fn2 = fn;
sl@0
   615
	TFileName src = SourcePath;
sl@0
   616
	src.Append(*ExeArray[0]);
sl@0
   617
	r = gFileMan->Copy(src, fn2);
sl@0
   618
	test.Printf(_L("%S->%S (%d)\n"), &src, &fn2, r);
sl@0
   619
	test(r == KErrNone);
sl@0
   620
	
sl@0
   621
	
sl@0
   622
	// Check RLibrary::GetInfoFromHeader  on a correct executable
sl@0
   623
	test.Printf(_L("fn:%S\n"), &fn);
sl@0
   624
	
sl@0
   625
	RLibrary::TInfoV2 info;
sl@0
   626
	TPckg<RLibrary::TInfoV2> infoBuf(info);
sl@0
   627
		
sl@0
   628
	TUint8* buf;
sl@0
   629
sl@0
   630
	RFs fs;
sl@0
   631
	test(fs.Connect()==KErrNone);
sl@0
   632
	RFile file;
sl@0
   633
	r=file.Open(fs,fn,0);
sl@0
   634
	test.Printf(_L("file.Open returns %d\n"), r);
sl@0
   635
	test(r==KErrNone);
sl@0
   636
	TInt size;
sl@0
   637
	test((r=file.Size(size))==KErrNone);
sl@0
   638
	if(size>RLibrary::KRequiredImageHeaderSize)
sl@0
   639
		size=RLibrary::KRequiredImageHeaderSize;
sl@0
   640
	buf=new TUint8[size];
sl@0
   641
	test(buf!=0);
sl@0
   642
	TPtr8 header(buf,size);
sl@0
   643
	test((r=file.Read(header))==KErrNone);
sl@0
   644
	file.Close();
sl@0
   645
	
sl@0
   646
sl@0
   647
	r = RLibrary::GetInfoFromHeader(header, infoBuf);
sl@0
   648
	test.Printf(_L("GetInfoFromHeader returns %d\n"), r);
sl@0
   649
	test(r==KErrNone);
sl@0
   650
sl@0
   651
sl@0
   652
	test.Printf(_L("Write invalid compression info into the header.\n"));
sl@0
   653
	E32ImageHeader* e32Header = (E32ImageHeader*) buf;
sl@0
   654
	
sl@0
   655
	e32Header->iCompressionType = 0x00000001;
sl@0
   656
	test((r=file.Open(fs,fn,EFileWrite))==KErrNone);
sl@0
   657
	r=file.Write(header);
sl@0
   658
	test.Printf(_L("file.Write returns %d\n"), r);
sl@0
   659
	test(r==KErrNone);
sl@0
   660
	file.Close();
sl@0
   661
sl@0
   662
	// Check RLibrary::GetInfoFromHeader on a wrong compression method.
sl@0
   663
	
sl@0
   664
	r = RLibrary::GetInfoFromHeader(header, infoBuf);
sl@0
   665
	test.Printf(_L("GetInfoFromHeader returns %d\n"), r);
sl@0
   666
	test(r==KErrCorrupt);
sl@0
   667
sl@0
   668
sl@0
   669
	fs.Close();
sl@0
   670
	delete buf;
sl@0
   671
	
sl@0
   672
	
sl@0
   673
	
sl@0
   674
	} // End of TestCompression()
sl@0
   675
sl@0
   676
TInt E32Main()
sl@0
   677
	{
sl@0
   678
	test.Title();
sl@0
   679
sl@0
   680
	// Turn off evil lazy dll unloading
sl@0
   681
	RLoader l;
sl@0
   682
	test(l.Connect()==KErrNone);
sl@0
   683
	test(l.CancelLazyDllUnload()==KErrNone);
sl@0
   684
	l.Close();
sl@0
   685
sl@0
   686
	TBuf<256> cmdline;
sl@0
   687
	User::CommandLine(cmdline);
sl@0
   688
	TLex lex(cmdline);
sl@0
   689
	TInt options[8];
sl@0
   690
	TInt i;
sl@0
   691
	memclr(options, sizeof(options));
sl@0
   692
	for (i=0; i<8; ++i)
sl@0
   693
		{
sl@0
   694
		lex.SkipSpace();
sl@0
   695
		if (lex.Eos())
sl@0
   696
			break;
sl@0
   697
		lex.Val(options[i]);
sl@0
   698
		}
sl@0
   699
	TUint tm = 0xffffffffu;
sl@0
   700
	if (options[0])
sl@0
   701
		tm = (TUint)options[0];
sl@0
   702
sl@0
   703
	test.Start(_L("Create cleanup stack"));
sl@0
   704
	CTrapCleanup* ct = CTrapCleanup::New();
sl@0
   705
	test(ct!=0);
sl@0
   706
	test.Next(_L("Connect to file server"));
sl@0
   707
	TInt r = gFs.Connect();
sl@0
   708
	test(r==KErrNone);
sl@0
   709
	test.Next(_L("Create CFileMan"));
sl@0
   710
	TRAP(r, gFileMan=CFileMan::NewL(gFs));
sl@0
   711
	test(r==KErrNone);
sl@0
   712
	test.Next(_L("Connect to test driver"));
sl@0
   713
	r = User::LoadLogicalDevice(_L("d_ldrtst"));
sl@0
   714
	test(r==KErrNone || r==KErrAlreadyExists);
sl@0
   715
	r = LdrTest.Open();
sl@0
   716
	test(r==KErrNone);
sl@0
   717
	TFileName fn(RProcess().FileName());
sl@0
   718
	test.Printf(_L("Process file name = %S\n"), &fn);
sl@0
   719
	SourcePath[0] = fn[0];	// use same drive as this EXE
sl@0
   720
sl@0
   721
	TUint mask;
sl@0
   722
	TUint nmasks = 1u << KNumDlls;
sl@0
   723
	for (mask=0; mask<nmasks; ++mask)
sl@0
   724
		{
sl@0
   725
		CreateAndPopulateDir(mask);
sl@0
   726
		if (!(tm&1))
sl@0
   727
			continue;
sl@0
   728
		TInt n;
sl@0
   729
		for (n=0; n<KNumExes; ++n)
sl@0
   730
			{
sl@0
   731
			RunExe(mask, n);
sl@0
   732
			}
sl@0
   733
		RunExes(mask);
sl@0
   734
		}
sl@0
   735
sl@0
   736
	if (tm & 2)
sl@0
   737
		{
sl@0
   738
		test.Next(_L("Test dynamic loading by version"));
sl@0
   739
		for (mask=0; mask<nmasks; ++mask)
sl@0
   740
			{
sl@0
   741
			TInt n;
sl@0
   742
			for (n=0; n<KNumTestVersions; ++n)
sl@0
   743
				{
sl@0
   744
				TestDynamic(mask, n);
sl@0
   745
				}
sl@0
   746
			}
sl@0
   747
		}
sl@0
   748
sl@0
   749
	if (tm & 4)
sl@0
   750
		{
sl@0
   751
		test.Next(_L("Test get library info"));
sl@0
   752
		TInt n;
sl@0
   753
		for (n=0; n<KNumDlls; ++n)
sl@0
   754
			{
sl@0
   755
			TestLibraryInfo(n);
sl@0
   756
			}
sl@0
   757
		for (n=0; n<KNumExes; ++n)
sl@0
   758
			{
sl@0
   759
			TestExeInfo(n);
sl@0
   760
			}
sl@0
   761
		}
sl@0
   762
sl@0
   763
	if( tm & 8)
sl@0
   764
		{
sl@0
   765
		TestCompression();
sl@0
   766
		}
sl@0
   767
	
sl@0
   768
	delete gFileMan;
sl@0
   769
	gFs.Close();
sl@0
   770
	delete ct;
sl@0
   771
	LdrTest.Close();
sl@0
   772
	test.End();
sl@0
   773
	return KErrNone;
sl@0
   774
	}
sl@0
   775