os/kernelhwsrv/kerneltest/f32test/server/t_sysbin.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) 2004-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
// f32test\server\t_sysbin.cpp
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#define __E32TEST_EXTENSION__
sl@0
    19
#include <e32test.h>
sl@0
    20
#include <f32file.h>
sl@0
    21
#include <e32ldr.h>
sl@0
    22
#include <e32ldr_private.h>
sl@0
    23
sl@0
    24
_LIT(KCheckFailed,"Check failed %d != %d\n");
sl@0
    25
sl@0
    26
#define CHECK_EQ(a,b) { if(a!=b) { test.Printf(KCheckFailed,a,b); test(0); } }
sl@0
    27
sl@0
    28
RTest test(_L("T_SYSBIN"));
sl@0
    29
sl@0
    30
TBool SysBinEnforced = 0;
sl@0
    31
TBool RunningFromROM;
sl@0
    32
sl@0
    33
RFs TheFs;
sl@0
    34
CFileMan* TheFileMan;
sl@0
    35
sl@0
    36
void CheckFileName(RProcess aProcess, const TDesC& aFileName)
sl@0
    37
	{
sl@0
    38
	TFileName fileName = aProcess.FileName();
sl@0
    39
	test(fileName.MatchF(aFileName)==0);
sl@0
    40
	}
sl@0
    41
sl@0
    42
_LIT(KExeAInSysBin,"z:\\sys\\bin\\t_sysbina.exe");
sl@0
    43
_LIT(KExeBInSystemPrograms,"z:\\system\\programs\\t_sysbinb.exe");
sl@0
    44
_LIT(KDllAInSysBin,"z:\\sys\\bin\\t_sysbin_dlla.dll");
sl@0
    45
_LIT(KDllBInSystemLibs,"z:\\system\\libs\\t_sysbin_dllb.dll");
sl@0
    46
#ifndef __WINS__
sl@0
    47
_LIT(KExeBInSysBin,"z:\\sys\\bin\\t_sysbinb.exe");
sl@0
    48
_LIT(KDllBInSysBin,"z:\\sys\\bin\\t_sysbin_dllb.dll");
sl@0
    49
#endif
sl@0
    50
_LIT(KRamDll,"z:\\sys\\bin\\t_sysbin_dll_ram.dll");
sl@0
    51
_LIT(KDllCInCTest,"c:\\sysbin_test\\t_sysbin_dllc.dll");
sl@0
    52
_LIT(KDllC,"t_sysbin_dllc.dll");
sl@0
    53
_LIT(KDllDInCSysBinTest,"c:\\sys\\bin\\test\\t_sysbin_dlld.dll");
sl@0
    54
_LIT(KDllD,"t_sysbin_dlld.dll");
sl@0
    55
sl@0
    56
sl@0
    57
void CheckFileName(RLibrary aLibrary, const TDesC& aFileName)
sl@0
    58
	{
sl@0
    59
	TFileName fileName = aLibrary.FileName();
sl@0
    60
	test(fileName.MatchF(aFileName)==0);
sl@0
    61
	}
sl@0
    62
sl@0
    63
sl@0
    64
sl@0
    65
void TestExeB(const TDesC& aFileName)
sl@0
    66
	{
sl@0
    67
	RProcess p;
sl@0
    68
	TInt r = p.Create(aFileName,KNullDesC);
sl@0
    69
	if(SysBinEnforced)
sl@0
    70
		{
sl@0
    71
#ifdef __WINS__
sl@0
    72
		CHECK_EQ(r,KErrNotFound)
sl@0
    73
#else
sl@0
    74
		CHECK_EQ(r,KErrNone)
sl@0
    75
		CheckFileName(p,KExeBInSysBin);
sl@0
    76
		p.Terminate(0);
sl@0
    77
		p.Close();
sl@0
    78
#endif
sl@0
    79
		}
sl@0
    80
	else
sl@0
    81
		{
sl@0
    82
		CHECK_EQ(r,KErrNone)
sl@0
    83
		CheckFileName(p,KExeBInSystemPrograms);
sl@0
    84
		p.Terminate(0);
sl@0
    85
		p.Close();
sl@0
    86
		}
sl@0
    87
	}
sl@0
    88
sl@0
    89
sl@0
    90
sl@0
    91
void TestDllB(const TDesC& aFileName)
sl@0
    92
	{
sl@0
    93
	RLibrary l;
sl@0
    94
	TInt r = l.Load(aFileName);
sl@0
    95
	if(SysBinEnforced)
sl@0
    96
		{
sl@0
    97
#ifdef __WINS__
sl@0
    98
		CHECK_EQ(r,KErrNotFound)
sl@0
    99
#else
sl@0
   100
		CHECK_EQ(r,KErrNone)
sl@0
   101
		CheckFileName(l,KDllBInSysBin);
sl@0
   102
		l.Close();
sl@0
   103
#endif
sl@0
   104
		}
sl@0
   105
	else
sl@0
   106
		{
sl@0
   107
		CHECK_EQ(r,KErrNone)
sl@0
   108
		CheckFileName(l,KDllBInSystemLibs);
sl@0
   109
		l.Close();
sl@0
   110
		}
sl@0
   111
	}
sl@0
   112
sl@0
   113
sl@0
   114
sl@0
   115
void TestDllC(const TDesC& aFileName,const TDesC& aPath)
sl@0
   116
	{
sl@0
   117
	RLibrary l;
sl@0
   118
	test.Printf(_L("Load(%S,%S)\n"),&aFileName,&aPath);
sl@0
   119
	TInt r = l.Load(aFileName,aPath);
sl@0
   120
	if(SysBinEnforced)
sl@0
   121
		CHECK_EQ(r,KErrNotFound)
sl@0
   122
	else
sl@0
   123
		{
sl@0
   124
		CHECK_EQ(r,KErrNone)
sl@0
   125
		CheckFileName(l,KDllCInCTest);
sl@0
   126
		l.Close();
sl@0
   127
		}
sl@0
   128
	}
sl@0
   129
sl@0
   130
sl@0
   131
sl@0
   132
void TestDllD(const TDesC& aFileName,const TDesC& aPath)
sl@0
   133
	{
sl@0
   134
	RLibrary l;
sl@0
   135
	test.Printf(_L("Load(%S,%S)\n"),&aFileName,&aPath);
sl@0
   136
	TInt r = l.Load(aFileName,aPath);
sl@0
   137
	CHECK_EQ(r,KErrNone)
sl@0
   138
	CheckFileName(l,KDllDInCSysBinTest);
sl@0
   139
	l.Close();
sl@0
   140
	}
sl@0
   141
sl@0
   142
sl@0
   143
sl@0
   144
GLDEF_C TInt E32Main()
sl@0
   145
    {
sl@0
   146
	SysBinEnforced=PlatSec::ConfigSetting(PlatSec::EPlatSecEnforceSysBin);
sl@0
   147
sl@0
   148
	TInt r;
sl@0
   149
	RProcess p;
sl@0
   150
	RLibrary l;
sl@0
   151
sl@0
   152
 	test.Title();
sl@0
   153
sl@0
   154
	test( KErrNone == TheFs.Connect() );
sl@0
   155
	RunningFromROM = TheFs.IsFileInRom(RProcess().FileName())!=0;
sl@0
   156
sl@0
   157
	// Turn off evil lazy dll unloading
sl@0
   158
	{
sl@0
   159
	RLoader l;
sl@0
   160
	test_KErrNone(l.Connect());
sl@0
   161
	test_KErrNone(l.CancelLazyDllUnload());
sl@0
   162
	l.Close();
sl@0
   163
	}
sl@0
   164
sl@0
   165
	CTrapCleanup* ct = CTrapCleanup::New();
sl@0
   166
	test_NotNull(ct);
sl@0
   167
	TRAP(r, TheFileMan=CFileMan::NewL(TheFs));
sl@0
   168
	test_KErrNone(r);
sl@0
   169
sl@0
   170
	test.Start(_L("Check loading an EXE which lives in \\SYS\\BIN"));
sl@0
   171
sl@0
   172
		test.Start(_L("Load without path or ext"));
sl@0
   173
		r = p.Create(_L("T_SYSBINa"),KNullDesC);
sl@0
   174
		CHECK_EQ(r,KErrNone)
sl@0
   175
		CheckFileName(p,KExeAInSysBin);
sl@0
   176
		p.Terminate(0);
sl@0
   177
		p.Close();
sl@0
   178
sl@0
   179
		test.Next(_L("Load without path"));
sl@0
   180
		r = p.Create(_L("T_SYSBINa.EXE"),KNullDesC);
sl@0
   181
		CHECK_EQ(r,KErrNone)
sl@0
   182
		CheckFileName(p,KExeAInSysBin);
sl@0
   183
		p.Terminate(0);
sl@0
   184
		p.Close();
sl@0
   185
sl@0
   186
		test.Next(_L("Load with path but without ext"));
sl@0
   187
		r = p.Create(_L("\\Sys\\Bin\\T_SYSBINa"),KNullDesC);
sl@0
   188
		CHECK_EQ(r,KErrNone)
sl@0
   189
		CheckFileName(p,KExeAInSysBin);
sl@0
   190
		p.Terminate(0);
sl@0
   191
		p.Close();
sl@0
   192
sl@0
   193
		test.Next(_L("Load with path and ext"));
sl@0
   194
		r = p.Create(_L("\\Sys\\Bin\\T_SYSBINa.EXE"),KNullDesC);
sl@0
   195
		CHECK_EQ(r,KErrNone)
sl@0
   196
		CheckFileName(p,KExeAInSysBin);
sl@0
   197
		p.Terminate(0);
sl@0
   198
		p.Close();
sl@0
   199
sl@0
   200
		test.Next(_L("Load with SYSTEM\\PROGRAMS path and without ext"));
sl@0
   201
		r = p.Create(_L("\\SYSTEM\\PROGRAMS\\T_SYSBINa"),KNullDesC);
sl@0
   202
		if(!SysBinEnforced)
sl@0
   203
			CHECK_EQ(r,KErrNotFound)
sl@0
   204
		else
sl@0
   205
			{
sl@0
   206
			CHECK_EQ(r,KErrNone)
sl@0
   207
			CheckFileName(p,KExeAInSysBin);
sl@0
   208
			p.Terminate(0);
sl@0
   209
			p.Close();
sl@0
   210
			}
sl@0
   211
sl@0
   212
		test.Next(_L("Load with SYSTEM\\PROGRAMS path and with ext"));
sl@0
   213
		r = p.Create(_L("\\SYSTEM\\PROGRAMS\\T_SYSBINa.EXE"),KNullDesC);
sl@0
   214
		if(!SysBinEnforced)
sl@0
   215
			CHECK_EQ(r,KErrNotFound)
sl@0
   216
		else
sl@0
   217
			{
sl@0
   218
			CHECK_EQ(r,KErrNone)
sl@0
   219
			CheckFileName(p,KExeAInSysBin);
sl@0
   220
			p.Terminate(0);
sl@0
   221
			p.Close();
sl@0
   222
			}
sl@0
   223
sl@0
   224
		test.End();
sl@0
   225
sl@0
   226
	test.Next(_L("Check loading an EXE which lives in \\SYSTEM\\PROGRAMS"));
sl@0
   227
sl@0
   228
	if(!RunningFromROM)
sl@0
   229
		{
sl@0
   230
		test.Printf(_L("TESTS NOT RUN - Not running from ROM"));
sl@0
   231
		}
sl@0
   232
	else
sl@0
   233
		{
sl@0
   234
		test.Start(_L("Load without path or ext"));
sl@0
   235
		TestExeB(_L("T_SYSBINb"));
sl@0
   236
sl@0
   237
		test.Next(_L("Load without path"));
sl@0
   238
		TestExeB(_L("T_SYSBINb.EXE"));
sl@0
   239
sl@0
   240
		test.Next(_L("Load with path but without ext"));
sl@0
   241
		TestExeB(_L("\\System\\programs\\T_SYSBINb"));
sl@0
   242
sl@0
   243
		test.Next(_L("Load with path and ext"));
sl@0
   244
		TestExeB(_L("\\System\\programs\\T_SYSBINb.EXE"));
sl@0
   245
sl@0
   246
		test.End();
sl@0
   247
		}
sl@0
   248
sl@0
   249
	test.Next(_L("Check loading an DLL which lives in \\SYS\\BIN"));
sl@0
   250
sl@0
   251
		test.Start(_L("Load without path or ext"));
sl@0
   252
		r = l.Load(_L("T_SYSBIN_DLLa"));
sl@0
   253
		CHECK_EQ(r,KErrNone)
sl@0
   254
		CheckFileName(l,KDllAInSysBin);
sl@0
   255
		l.Close();
sl@0
   256
sl@0
   257
		test.Next(_L("Load without path"));
sl@0
   258
		r = l.Load(_L("T_SYSBIN_DLLa.DLL"));
sl@0
   259
		CHECK_EQ(r,KErrNone)
sl@0
   260
		CheckFileName(l,KDllAInSysBin);
sl@0
   261
		l.Close();
sl@0
   262
sl@0
   263
		test.Next(_L("Load with path but without ext"));
sl@0
   264
		r = l.Load(_L("\\Sys\\Bin\\T_SYSBIN_DLLa"));
sl@0
   265
		CHECK_EQ(r,KErrNone)
sl@0
   266
		CheckFileName(l,KDllAInSysBin);
sl@0
   267
		l.Close();
sl@0
   268
sl@0
   269
		test.Next(_L("Load with path and ext"));
sl@0
   270
		r = l.Load(_L("\\Sys\\Bin\\T_SYSBIN_DLLa.DLL"));
sl@0
   271
		CHECK_EQ(r,KErrNone)
sl@0
   272
		CheckFileName(l,KDllAInSysBin);
sl@0
   273
		l.Close();
sl@0
   274
sl@0
   275
		test.Next(_L("Load with SYSTEM\\LIBS path and without ext"));
sl@0
   276
		r = l.Load(_L("\\SYSTEM\\LIBS\\T_SYSBIN_DLLa"));
sl@0
   277
		if(!SysBinEnforced)
sl@0
   278
			CHECK_EQ(r,KErrNotFound)
sl@0
   279
		else
sl@0
   280
			{
sl@0
   281
			CHECK_EQ(r,KErrNone)
sl@0
   282
			CheckFileName(l,KDllAInSysBin);
sl@0
   283
			l.Close();
sl@0
   284
			}
sl@0
   285
sl@0
   286
		test.Next(_L("Load with SYSTEM\\LIBS path and with ext"));
sl@0
   287
		r = l.Load(_L("\\SYSTEM\\LIBS\\T_SYSBIN_DLLa.DLL"));
sl@0
   288
		if(!SysBinEnforced)
sl@0
   289
			CHECK_EQ(r,KErrNotFound)
sl@0
   290
		else
sl@0
   291
			{
sl@0
   292
			CHECK_EQ(r,KErrNone)
sl@0
   293
			CheckFileName(l,KDllAInSysBin);
sl@0
   294
			l.Close();
sl@0
   295
			}
sl@0
   296
sl@0
   297
		test.End();
sl@0
   298
sl@0
   299
	test.Next(_L("Check loading an DLL which lives in \\SYSTEM\\LIBS"));
sl@0
   300
sl@0
   301
	if(!RunningFromROM)
sl@0
   302
		{
sl@0
   303
		test.Printf(_L("TESTS NOT RUN - Not running from ROM"));
sl@0
   304
		}
sl@0
   305
	else
sl@0
   306
		{
sl@0
   307
		test.Start(_L("Load without path or ext"));
sl@0
   308
		TestDllB(_L("T_SYSBIN_DLLb"));
sl@0
   309
sl@0
   310
		test.Next(_L("Load without path"));
sl@0
   311
		TestDllB(_L("T_SYSBIN_DLLb.DLL"));
sl@0
   312
sl@0
   313
		test.Next(_L("Load with path but without ext"));
sl@0
   314
		TestDllB(_L("\\System\\Libs\\T_SYSBIN_DLLb"));
sl@0
   315
sl@0
   316
		test.Next(_L("Load with path and ext"));
sl@0
   317
		TestDllB(_L("\\System\\Libs\\T_SYSBIN_DLLb.DLL"));
sl@0
   318
sl@0
   319
		test.End();
sl@0
   320
		}
sl@0
   321
sl@0
   322
	test.Next(_L("Check loading an DLL which lives in \\SYSBIN_TEST"));
sl@0
   323
sl@0
   324
	r = TheFileMan->Copy(KRamDll,KDllCInCTest,CFileMan::ERecurse);
sl@0
   325
	test_KErrNone(r);
sl@0
   326
sl@0
   327
		test.Start(_L("Load using full path+name"));
sl@0
   328
		TestDllC(KDllCInCTest,KNullDesC);
sl@0
   329
sl@0
   330
		test.Next(_L("Load using separate search path"));
sl@0
   331
		TestDllC(KDllC,_L("\\sysbin_test\\"));
sl@0
   332
#ifndef __WINS__
sl@0
   333
		TestDllC(KDllC,_L("\\sysbin_test"));
sl@0
   334
		TestDllC(KDllC,_L("sysbin_test\\"));
sl@0
   335
		TestDllC(KDllC,_L("sysbin_test"));
sl@0
   336
#endif
sl@0
   337
sl@0
   338
		TestDllC(KDllC,_L("c:\\sysbin_test\\"));
sl@0
   339
#ifndef __WINS__
sl@0
   340
		TestDllC(KDllC,_L("c:\\sysbin_test"));
sl@0
   341
		TestDllC(KDllC,_L("c:sysbin_test\\"));
sl@0
   342
		TestDllC(KDllC,_L("c:sysbin_test"));
sl@0
   343
#endif
sl@0
   344
sl@0
   345
		test.End();
sl@0
   346
sl@0
   347
	_LIT(KCTestPath,"c:\\sysbin_test\\");
sl@0
   348
	r = TheFileMan->RmDir(KCTestPath);
sl@0
   349
	test_KErrNone(r);
sl@0
   350
sl@0
   351
	test.Next(_L("Check loading an DLL which lives in \\SYS\\BIN\\TEST"));
sl@0
   352
sl@0
   353
	r = TheFileMan->Copy(KRamDll,KDllDInCSysBinTest,CFileMan::ERecurse);
sl@0
   354
	test_KErrNone(r);
sl@0
   355
sl@0
   356
		test.Start(_L("Load using full path+name"));
sl@0
   357
		TestDllD(KDllDInCSysBinTest,KNullDesC);
sl@0
   358
sl@0
   359
		test.Next(_L("Load using separate search path"));
sl@0
   360
		TestDllD(KDllD,_L("\\sys\\bin\\test\\"));
sl@0
   361
#ifndef __WINS__
sl@0
   362
		TestDllD(KDllD,_L("\\sys\\bin\\test"));
sl@0
   363
		TestDllD(KDllD,_L("sys\\bin\\test"));
sl@0
   364
		TestDllD(KDllD,_L("sys\\bin\\test\\"));
sl@0
   365
#endif
sl@0
   366
sl@0
   367
		TestDllD(KDllD,_L("c:\\sys\\bin\\test\\"));
sl@0
   368
#ifndef __WINS__
sl@0
   369
		TestDllD(KDllD,_L("c:\\sys\\bin\\test"));
sl@0
   370
		TestDllD(KDllD,_L("c:sys\\bin\\test\\"));
sl@0
   371
		TestDllD(KDllD,_L("c:sys\\bin\\test"));
sl@0
   372
#endif
sl@0
   373
sl@0
   374
		TestDllD(KDllD,_L("\\dummy;\\sys\\bin\\test\\"));
sl@0
   375
		TestDllD(KDllD,_L("\\sys\\bin\\test\\;\\dummy2"));
sl@0
   376
		TestDllD(KDllD,_L("\\dummy1;\\sys\\bin\\test2;\\sys\\bin\\test\\"));
sl@0
   377
sl@0
   378
		TestDllD(KDllD,_L("c:\\dummy;c:\\sys\\bin\\test\\"));
sl@0
   379
		TestDllD(KDllD,_L("c:\\sys\\bin\\test\\;c:\\dummy2"));
sl@0
   380
		TestDllD(KDllD,_L("c:\\dummy1;c:\\sys\\bin\\test2;c:\\sys\\bin\\test\\"));
sl@0
   381
sl@0
   382
		test.End();
sl@0
   383
sl@0
   384
	_LIT(KCTestPath2,"c:\\sys\\bin\\test\\");
sl@0
   385
	r = TheFileMan->RmDir(KCTestPath2);
sl@0
   386
	test_KErrNone(r);
sl@0
   387
sl@0
   388
	test.End();
sl@0
   389
	return(0);
sl@0
   390
    }