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