1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/f32test/server/t_sysbin.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,390 @@
1.4 +// Copyright (c) 2004-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 +// f32test\server\t_sysbin.cpp
1.18 +//
1.19 +//
1.20 +
1.21 +#define __E32TEST_EXTENSION__
1.22 +#include <e32test.h>
1.23 +#include <f32file.h>
1.24 +#include <e32ldr.h>
1.25 +#include <e32ldr_private.h>
1.26 +
1.27 +_LIT(KCheckFailed,"Check failed %d != %d\n");
1.28 +
1.29 +#define CHECK_EQ(a,b) { if(a!=b) { test.Printf(KCheckFailed,a,b); test(0); } }
1.30 +
1.31 +RTest test(_L("T_SYSBIN"));
1.32 +
1.33 +TBool SysBinEnforced = 0;
1.34 +TBool RunningFromROM;
1.35 +
1.36 +RFs TheFs;
1.37 +CFileMan* TheFileMan;
1.38 +
1.39 +void CheckFileName(RProcess aProcess, const TDesC& aFileName)
1.40 + {
1.41 + TFileName fileName = aProcess.FileName();
1.42 + test(fileName.MatchF(aFileName)==0);
1.43 + }
1.44 +
1.45 +_LIT(KExeAInSysBin,"z:\\sys\\bin\\t_sysbina.exe");
1.46 +_LIT(KExeBInSystemPrograms,"z:\\system\\programs\\t_sysbinb.exe");
1.47 +_LIT(KDllAInSysBin,"z:\\sys\\bin\\t_sysbin_dlla.dll");
1.48 +_LIT(KDllBInSystemLibs,"z:\\system\\libs\\t_sysbin_dllb.dll");
1.49 +#ifndef __WINS__
1.50 +_LIT(KExeBInSysBin,"z:\\sys\\bin\\t_sysbinb.exe");
1.51 +_LIT(KDllBInSysBin,"z:\\sys\\bin\\t_sysbin_dllb.dll");
1.52 +#endif
1.53 +_LIT(KRamDll,"z:\\sys\\bin\\t_sysbin_dll_ram.dll");
1.54 +_LIT(KDllCInCTest,"c:\\sysbin_test\\t_sysbin_dllc.dll");
1.55 +_LIT(KDllC,"t_sysbin_dllc.dll");
1.56 +_LIT(KDllDInCSysBinTest,"c:\\sys\\bin\\test\\t_sysbin_dlld.dll");
1.57 +_LIT(KDllD,"t_sysbin_dlld.dll");
1.58 +
1.59 +
1.60 +void CheckFileName(RLibrary aLibrary, const TDesC& aFileName)
1.61 + {
1.62 + TFileName fileName = aLibrary.FileName();
1.63 + test(fileName.MatchF(aFileName)==0);
1.64 + }
1.65 +
1.66 +
1.67 +
1.68 +void TestExeB(const TDesC& aFileName)
1.69 + {
1.70 + RProcess p;
1.71 + TInt r = p.Create(aFileName,KNullDesC);
1.72 + if(SysBinEnforced)
1.73 + {
1.74 +#ifdef __WINS__
1.75 + CHECK_EQ(r,KErrNotFound)
1.76 +#else
1.77 + CHECK_EQ(r,KErrNone)
1.78 + CheckFileName(p,KExeBInSysBin);
1.79 + p.Terminate(0);
1.80 + p.Close();
1.81 +#endif
1.82 + }
1.83 + else
1.84 + {
1.85 + CHECK_EQ(r,KErrNone)
1.86 + CheckFileName(p,KExeBInSystemPrograms);
1.87 + p.Terminate(0);
1.88 + p.Close();
1.89 + }
1.90 + }
1.91 +
1.92 +
1.93 +
1.94 +void TestDllB(const TDesC& aFileName)
1.95 + {
1.96 + RLibrary l;
1.97 + TInt r = l.Load(aFileName);
1.98 + if(SysBinEnforced)
1.99 + {
1.100 +#ifdef __WINS__
1.101 + CHECK_EQ(r,KErrNotFound)
1.102 +#else
1.103 + CHECK_EQ(r,KErrNone)
1.104 + CheckFileName(l,KDllBInSysBin);
1.105 + l.Close();
1.106 +#endif
1.107 + }
1.108 + else
1.109 + {
1.110 + CHECK_EQ(r,KErrNone)
1.111 + CheckFileName(l,KDllBInSystemLibs);
1.112 + l.Close();
1.113 + }
1.114 + }
1.115 +
1.116 +
1.117 +
1.118 +void TestDllC(const TDesC& aFileName,const TDesC& aPath)
1.119 + {
1.120 + RLibrary l;
1.121 + test.Printf(_L("Load(%S,%S)\n"),&aFileName,&aPath);
1.122 + TInt r = l.Load(aFileName,aPath);
1.123 + if(SysBinEnforced)
1.124 + CHECK_EQ(r,KErrNotFound)
1.125 + else
1.126 + {
1.127 + CHECK_EQ(r,KErrNone)
1.128 + CheckFileName(l,KDllCInCTest);
1.129 + l.Close();
1.130 + }
1.131 + }
1.132 +
1.133 +
1.134 +
1.135 +void TestDllD(const TDesC& aFileName,const TDesC& aPath)
1.136 + {
1.137 + RLibrary l;
1.138 + test.Printf(_L("Load(%S,%S)\n"),&aFileName,&aPath);
1.139 + TInt r = l.Load(aFileName,aPath);
1.140 + CHECK_EQ(r,KErrNone)
1.141 + CheckFileName(l,KDllDInCSysBinTest);
1.142 + l.Close();
1.143 + }
1.144 +
1.145 +
1.146 +
1.147 +GLDEF_C TInt E32Main()
1.148 + {
1.149 + SysBinEnforced=PlatSec::ConfigSetting(PlatSec::EPlatSecEnforceSysBin);
1.150 +
1.151 + TInt r;
1.152 + RProcess p;
1.153 + RLibrary l;
1.154 +
1.155 + test.Title();
1.156 +
1.157 + test( KErrNone == TheFs.Connect() );
1.158 + RunningFromROM = TheFs.IsFileInRom(RProcess().FileName())!=0;
1.159 +
1.160 + // Turn off evil lazy dll unloading
1.161 + {
1.162 + RLoader l;
1.163 + test_KErrNone(l.Connect());
1.164 + test_KErrNone(l.CancelLazyDllUnload());
1.165 + l.Close();
1.166 + }
1.167 +
1.168 + CTrapCleanup* ct = CTrapCleanup::New();
1.169 + test_NotNull(ct);
1.170 + TRAP(r, TheFileMan=CFileMan::NewL(TheFs));
1.171 + test_KErrNone(r);
1.172 +
1.173 + test.Start(_L("Check loading an EXE which lives in \\SYS\\BIN"));
1.174 +
1.175 + test.Start(_L("Load without path or ext"));
1.176 + r = p.Create(_L("T_SYSBINa"),KNullDesC);
1.177 + CHECK_EQ(r,KErrNone)
1.178 + CheckFileName(p,KExeAInSysBin);
1.179 + p.Terminate(0);
1.180 + p.Close();
1.181 +
1.182 + test.Next(_L("Load without path"));
1.183 + r = p.Create(_L("T_SYSBINa.EXE"),KNullDesC);
1.184 + CHECK_EQ(r,KErrNone)
1.185 + CheckFileName(p,KExeAInSysBin);
1.186 + p.Terminate(0);
1.187 + p.Close();
1.188 +
1.189 + test.Next(_L("Load with path but without ext"));
1.190 + r = p.Create(_L("\\Sys\\Bin\\T_SYSBINa"),KNullDesC);
1.191 + CHECK_EQ(r,KErrNone)
1.192 + CheckFileName(p,KExeAInSysBin);
1.193 + p.Terminate(0);
1.194 + p.Close();
1.195 +
1.196 + test.Next(_L("Load with path and ext"));
1.197 + r = p.Create(_L("\\Sys\\Bin\\T_SYSBINa.EXE"),KNullDesC);
1.198 + CHECK_EQ(r,KErrNone)
1.199 + CheckFileName(p,KExeAInSysBin);
1.200 + p.Terminate(0);
1.201 + p.Close();
1.202 +
1.203 + test.Next(_L("Load with SYSTEM\\PROGRAMS path and without ext"));
1.204 + r = p.Create(_L("\\SYSTEM\\PROGRAMS\\T_SYSBINa"),KNullDesC);
1.205 + if(!SysBinEnforced)
1.206 + CHECK_EQ(r,KErrNotFound)
1.207 + else
1.208 + {
1.209 + CHECK_EQ(r,KErrNone)
1.210 + CheckFileName(p,KExeAInSysBin);
1.211 + p.Terminate(0);
1.212 + p.Close();
1.213 + }
1.214 +
1.215 + test.Next(_L("Load with SYSTEM\\PROGRAMS path and with ext"));
1.216 + r = p.Create(_L("\\SYSTEM\\PROGRAMS\\T_SYSBINa.EXE"),KNullDesC);
1.217 + if(!SysBinEnforced)
1.218 + CHECK_EQ(r,KErrNotFound)
1.219 + else
1.220 + {
1.221 + CHECK_EQ(r,KErrNone)
1.222 + CheckFileName(p,KExeAInSysBin);
1.223 + p.Terminate(0);
1.224 + p.Close();
1.225 + }
1.226 +
1.227 + test.End();
1.228 +
1.229 + test.Next(_L("Check loading an EXE which lives in \\SYSTEM\\PROGRAMS"));
1.230 +
1.231 + if(!RunningFromROM)
1.232 + {
1.233 + test.Printf(_L("TESTS NOT RUN - Not running from ROM"));
1.234 + }
1.235 + else
1.236 + {
1.237 + test.Start(_L("Load without path or ext"));
1.238 + TestExeB(_L("T_SYSBINb"));
1.239 +
1.240 + test.Next(_L("Load without path"));
1.241 + TestExeB(_L("T_SYSBINb.EXE"));
1.242 +
1.243 + test.Next(_L("Load with path but without ext"));
1.244 + TestExeB(_L("\\System\\programs\\T_SYSBINb"));
1.245 +
1.246 + test.Next(_L("Load with path and ext"));
1.247 + TestExeB(_L("\\System\\programs\\T_SYSBINb.EXE"));
1.248 +
1.249 + test.End();
1.250 + }
1.251 +
1.252 + test.Next(_L("Check loading an DLL which lives in \\SYS\\BIN"));
1.253 +
1.254 + test.Start(_L("Load without path or ext"));
1.255 + r = l.Load(_L("T_SYSBIN_DLLa"));
1.256 + CHECK_EQ(r,KErrNone)
1.257 + CheckFileName(l,KDllAInSysBin);
1.258 + l.Close();
1.259 +
1.260 + test.Next(_L("Load without path"));
1.261 + r = l.Load(_L("T_SYSBIN_DLLa.DLL"));
1.262 + CHECK_EQ(r,KErrNone)
1.263 + CheckFileName(l,KDllAInSysBin);
1.264 + l.Close();
1.265 +
1.266 + test.Next(_L("Load with path but without ext"));
1.267 + r = l.Load(_L("\\Sys\\Bin\\T_SYSBIN_DLLa"));
1.268 + CHECK_EQ(r,KErrNone)
1.269 + CheckFileName(l,KDllAInSysBin);
1.270 + l.Close();
1.271 +
1.272 + test.Next(_L("Load with path and ext"));
1.273 + r = l.Load(_L("\\Sys\\Bin\\T_SYSBIN_DLLa.DLL"));
1.274 + CHECK_EQ(r,KErrNone)
1.275 + CheckFileName(l,KDllAInSysBin);
1.276 + l.Close();
1.277 +
1.278 + test.Next(_L("Load with SYSTEM\\LIBS path and without ext"));
1.279 + r = l.Load(_L("\\SYSTEM\\LIBS\\T_SYSBIN_DLLa"));
1.280 + if(!SysBinEnforced)
1.281 + CHECK_EQ(r,KErrNotFound)
1.282 + else
1.283 + {
1.284 + CHECK_EQ(r,KErrNone)
1.285 + CheckFileName(l,KDllAInSysBin);
1.286 + l.Close();
1.287 + }
1.288 +
1.289 + test.Next(_L("Load with SYSTEM\\LIBS path and with ext"));
1.290 + r = l.Load(_L("\\SYSTEM\\LIBS\\T_SYSBIN_DLLa.DLL"));
1.291 + if(!SysBinEnforced)
1.292 + CHECK_EQ(r,KErrNotFound)
1.293 + else
1.294 + {
1.295 + CHECK_EQ(r,KErrNone)
1.296 + CheckFileName(l,KDllAInSysBin);
1.297 + l.Close();
1.298 + }
1.299 +
1.300 + test.End();
1.301 +
1.302 + test.Next(_L("Check loading an DLL which lives in \\SYSTEM\\LIBS"));
1.303 +
1.304 + if(!RunningFromROM)
1.305 + {
1.306 + test.Printf(_L("TESTS NOT RUN - Not running from ROM"));
1.307 + }
1.308 + else
1.309 + {
1.310 + test.Start(_L("Load without path or ext"));
1.311 + TestDllB(_L("T_SYSBIN_DLLb"));
1.312 +
1.313 + test.Next(_L("Load without path"));
1.314 + TestDllB(_L("T_SYSBIN_DLLb.DLL"));
1.315 +
1.316 + test.Next(_L("Load with path but without ext"));
1.317 + TestDllB(_L("\\System\\Libs\\T_SYSBIN_DLLb"));
1.318 +
1.319 + test.Next(_L("Load with path and ext"));
1.320 + TestDllB(_L("\\System\\Libs\\T_SYSBIN_DLLb.DLL"));
1.321 +
1.322 + test.End();
1.323 + }
1.324 +
1.325 + test.Next(_L("Check loading an DLL which lives in \\SYSBIN_TEST"));
1.326 +
1.327 + r = TheFileMan->Copy(KRamDll,KDllCInCTest,CFileMan::ERecurse);
1.328 + test_KErrNone(r);
1.329 +
1.330 + test.Start(_L("Load using full path+name"));
1.331 + TestDllC(KDllCInCTest,KNullDesC);
1.332 +
1.333 + test.Next(_L("Load using separate search path"));
1.334 + TestDllC(KDllC,_L("\\sysbin_test\\"));
1.335 +#ifndef __WINS__
1.336 + TestDllC(KDllC,_L("\\sysbin_test"));
1.337 + TestDllC(KDllC,_L("sysbin_test\\"));
1.338 + TestDllC(KDllC,_L("sysbin_test"));
1.339 +#endif
1.340 +
1.341 + TestDllC(KDllC,_L("c:\\sysbin_test\\"));
1.342 +#ifndef __WINS__
1.343 + TestDllC(KDllC,_L("c:\\sysbin_test"));
1.344 + TestDllC(KDllC,_L("c:sysbin_test\\"));
1.345 + TestDllC(KDllC,_L("c:sysbin_test"));
1.346 +#endif
1.347 +
1.348 + test.End();
1.349 +
1.350 + _LIT(KCTestPath,"c:\\sysbin_test\\");
1.351 + r = TheFileMan->RmDir(KCTestPath);
1.352 + test_KErrNone(r);
1.353 +
1.354 + test.Next(_L("Check loading an DLL which lives in \\SYS\\BIN\\TEST"));
1.355 +
1.356 + r = TheFileMan->Copy(KRamDll,KDllDInCSysBinTest,CFileMan::ERecurse);
1.357 + test_KErrNone(r);
1.358 +
1.359 + test.Start(_L("Load using full path+name"));
1.360 + TestDllD(KDllDInCSysBinTest,KNullDesC);
1.361 +
1.362 + test.Next(_L("Load using separate search path"));
1.363 + TestDllD(KDllD,_L("\\sys\\bin\\test\\"));
1.364 +#ifndef __WINS__
1.365 + TestDllD(KDllD,_L("\\sys\\bin\\test"));
1.366 + TestDllD(KDllD,_L("sys\\bin\\test"));
1.367 + TestDllD(KDllD,_L("sys\\bin\\test\\"));
1.368 +#endif
1.369 +
1.370 + TestDllD(KDllD,_L("c:\\sys\\bin\\test\\"));
1.371 +#ifndef __WINS__
1.372 + TestDllD(KDllD,_L("c:\\sys\\bin\\test"));
1.373 + TestDllD(KDllD,_L("c:sys\\bin\\test\\"));
1.374 + TestDllD(KDllD,_L("c:sys\\bin\\test"));
1.375 +#endif
1.376 +
1.377 + TestDllD(KDllD,_L("\\dummy;\\sys\\bin\\test\\"));
1.378 + TestDllD(KDllD,_L("\\sys\\bin\\test\\;\\dummy2"));
1.379 + TestDllD(KDllD,_L("\\dummy1;\\sys\\bin\\test2;\\sys\\bin\\test\\"));
1.380 +
1.381 + TestDllD(KDllD,_L("c:\\dummy;c:\\sys\\bin\\test\\"));
1.382 + TestDllD(KDllD,_L("c:\\sys\\bin\\test\\;c:\\dummy2"));
1.383 + TestDllD(KDllD,_L("c:\\dummy1;c:\\sys\\bin\\test2;c:\\sys\\bin\\test\\"));
1.384 +
1.385 + test.End();
1.386 +
1.387 + _LIT(KCTestPath2,"c:\\sys\\bin\\test\\");
1.388 + r = TheFileMan->RmDir(KCTestPath2);
1.389 + test_KErrNone(r);
1.390 +
1.391 + test.End();
1.392 + return(0);
1.393 + }