kerneltest/e32test/secure/t_sprocess.cpp
changeset 0 a41df078684a
child 109 b3a1d9898418
equal deleted inserted replaced
-1:000000000000 0:a41df078684a
       
     1 // Copyright (c) 2001-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 // e32test\secure\t_sprocess.cpp
       
    15 // Overview:
       
    16 // Test the platform security aspects of the RProcess class
       
    17 // API Information:
       
    18 // RProcess
       
    19 // Details:
       
    20 // - Test SetJustInTime on the current process, a new un-Resumed process
       
    21 // and between processes. Verify results are as expected.
       
    22 // - Test process renaming and verify results are as expected.
       
    23 // - Test killing, terminating and panicking different processes, verify
       
    24 // results are as expected.
       
    25 // - Test resuming a process from a different process, verify results.
       
    26 // - Test setting process priority in a variety of ways, verify results
       
    27 // are as expected.
       
    28 // - Test the RProcess SetType(), SetProtected(), CommandLineLength(), 
       
    29 // CommandLine(), SetSystem(), SetOwner() and Owner() methods. Verify
       
    30 // results are as expected.
       
    31 // Platforms/Drives/Compatibility:
       
    32 // All.
       
    33 // Assumptions/Requirement/Pre-requisites:
       
    34 // Failures and causes:
       
    35 // Base Port information:
       
    36 // 
       
    37 //
       
    38 
       
    39 #include <e32test.h>
       
    40 
       
    41 LOCAL_D RTest test(_L("T_SPROCESS"));
       
    42 
       
    43 _LIT(KSyncMutext,"T_SPROCESS-sync-mutex");
       
    44 RMutex SyncMutex;
       
    45 
       
    46 void Wait()
       
    47 	{
       
    48 	RMutex syncMutex;
       
    49 	if(syncMutex.OpenGlobal(KSyncMutext)!=KErrNone)
       
    50 		User::Invariant();
       
    51 	syncMutex.Wait();
       
    52 	syncMutex.Signal();
       
    53 	syncMutex.Close();
       
    54 	}
       
    55 
       
    56 enum TTestProcessFunctions
       
    57 	{
       
    58 	ETestProcessNull,
       
    59 	ETestProcessSetJustInTime,
       
    60 	ETestProcessKill,
       
    61 	ETestProcessTerminate,
       
    62 	ETestProcessPanic,
       
    63 	ETestProcessKillSelf,
       
    64 	ETestProcessTerminateSelf,
       
    65 	ETestProcessPanicSelf,
       
    66 	ETestProcessResume,
       
    67 	ETestProcessPriority,
       
    68 	ETestProcessPriorityControlOff,
       
    69 	ETestProcessPriorityControlOn,
       
    70 	ETestProcessPriorityControlOnAndLowPriority,
       
    71 	ETestProcessSetPriority,
       
    72 	};
       
    73 
       
    74 #include "testprocess.h"
       
    75 
       
    76 _LIT(KTestPanicCategory,"TEST PANIC");
       
    77 _LIT(KTestProcessName,"TestName");
       
    78 _LIT(KTestProcessName2,"TestName2");
       
    79 
       
    80 
       
    81 TInt DoTestProcess(TInt aTestNum,TInt aArg1,TInt aArg2)
       
    82 	{
       
    83 	RTestProcess process;
       
    84 	TInt r;
       
    85 
       
    86 	switch(aTestNum)
       
    87 		{
       
    88 
       
    89 	case ETestProcessNull:
       
    90 		Wait();
       
    91 		return KErrNone;
       
    92 
       
    93 	case ETestProcessSetJustInTime:
       
    94 		{
       
    95 		r = process.Open(aArg1);
       
    96 		if(r==KErrNone)
       
    97 			process.SetJustInTime(!process.JustInTime()); // Should panic us
       
    98 		return r;
       
    99 		}
       
   100 
       
   101 	case ETestProcessResume:
       
   102 		{
       
   103 		r = process.Open(aArg1);
       
   104 		if(r==KErrNone)
       
   105 			process.Resume(); // Should panic us
       
   106 		return r;
       
   107 		}
       
   108 
       
   109 	case ETestProcessKill:
       
   110 		{
       
   111 		r = process.Open(aArg1);
       
   112 		if(r==KErrNone)
       
   113 			process.Kill(999);
       
   114 		return r;
       
   115 		}
       
   116 
       
   117 	case ETestProcessTerminate:
       
   118 		{
       
   119 		r = process.Open(aArg1);
       
   120 		if(r==KErrNone)
       
   121 			process.Terminate(999);
       
   122 		return r;
       
   123 		}
       
   124 
       
   125 	case ETestProcessPanic:
       
   126 		{
       
   127 		r = process.Open(aArg1);
       
   128 		if(r==KErrNone)
       
   129 			process.Panic(KTestPanicCategory,999);
       
   130 		return r;
       
   131 		}
       
   132 
       
   133 	case ETestProcessKillSelf:
       
   134 		{
       
   135 		RProcess().Kill(999);
       
   136 		return KErrNone;
       
   137 		}
       
   138 
       
   139 	case ETestProcessTerminateSelf:
       
   140 		{
       
   141 		RProcess().Terminate(999);
       
   142 		return KErrNone;
       
   143 		}
       
   144 
       
   145 	case ETestProcessPanicSelf:
       
   146 		{
       
   147 		RProcess().Panic(KTestPanicCategory,999);
       
   148 		return KErrNone;
       
   149 		}
       
   150 
       
   151 	case ETestProcessSetPriority:
       
   152 		{
       
   153 		r = process.Open(aArg1);
       
   154 		if(r==KErrNone)
       
   155 			process.SetPriority((TProcessPriority)aArg2);
       
   156 		return r;
       
   157 		}
       
   158 
       
   159 
       
   160 	case ETestProcessPriority:
       
   161 		{
       
   162 		r = process.Open(aArg1);
       
   163 		if(r!=KErrNone)
       
   164 			return r;
       
   165 		TProcessPriority priority;
       
   166 		priority = process.Priority();
       
   167 		process.SetPriority(EPriorityLow);
       
   168 		if(process.Priority()!=priority) // priority shouldn't have changed
       
   169 			return KErrGeneral;
       
   170 		process.SetPriority(EPriorityBackground);
       
   171 		if(process.Priority()!=priority) // priority shouldn't have changed
       
   172 			return KErrGeneral;
       
   173 		process.SetPriority(EPriorityForeground);
       
   174 		if(process.Priority()!=priority) // priority shouldn't have changed
       
   175 			return KErrGeneral;
       
   176 		return KErrNone;
       
   177 		}
       
   178 
       
   179 	case ETestProcessPriorityControlOnAndLowPriority:
       
   180 		RProcess().SetPriority(EPriorityLow);
       
   181 		// fall through...
       
   182 	case ETestProcessPriorityControlOn:
       
   183 		User::SetPriorityControl(ETrue);
       
   184 		// fall through...
       
   185 	case ETestProcessPriorityControlOff:
       
   186 		RProcess::Rendezvous(0);
       
   187 		Wait();
       
   188 		return KErrNone;
       
   189 
       
   190 	default:
       
   191 		User::Panic(_L("T_SPROCESS"),1);
       
   192 		}
       
   193 
       
   194 	return KErrNone;
       
   195 	}
       
   196 
       
   197 
       
   198 
       
   199 void TestProcessForPlatformSecurityTrap(TTestProcessFunctions aFunction)
       
   200 	{
       
   201 	TRequestStatus logonStatus2;
       
   202 	RTestProcess process;
       
   203 	process.Create(~0u,aFunction,RProcess().Id(),EPriorityAbsoluteLow);
       
   204 	process.Logon(logonStatus2);
       
   205 	process.Resume();
       
   206 	User::WaitForRequest(logonStatus2);
       
   207 	test(process.ExitType()==EExitPanic); // Process should have got a Platform Security panic
       
   208 	test(logonStatus2==EPlatformSecurityTrap);
       
   209 	}
       
   210 
       
   211 
       
   212 
       
   213 void TestSetJustInTime()
       
   214 	{
       
   215 	RTestProcess process;
       
   216 	RTestProcess process2;
       
   217 	TRequestStatus logonStatus;
       
   218 
       
   219 	test.Start(_L("Test SetJustInTime on current process"));
       
   220 	TBool jit = process.JustInTime();
       
   221 	process.SetJustInTime(!jit);
       
   222 	test((process.JustInTime()!=EFalse)!=(jit!=EFalse));
       
   223 	process.SetJustInTime(jit);
       
   224 	test((process.JustInTime()!=EFalse)==(jit!=EFalse));
       
   225 
       
   226 	test.Next(_L("Test SetJustInTime on a new un-Resumed process"));
       
   227 	process.RProcess::Create(RProcess().FileName(),_L(""));
       
   228 	jit = process.JustInTime();
       
   229 	process.SetJustInTime(!jit);
       
   230 	test((process.JustInTime()!=EFalse)!=(jit!=EFalse));
       
   231 	process.SetJustInTime(jit);
       
   232 	test((process.JustInTime()!=EFalse)==(jit!=EFalse));
       
   233 	process.Kill(0);
       
   234 	CLOSE_AND_WAIT(process);
       
   235 
       
   236 	test.Next(_L("Try other process using SetJustInTime on our created process"));
       
   237 	process2.Create(0,ETestProcessNull);
       
   238 	process.Create(~0u,ETestProcessSetJustInTime,process2.Id());
       
   239 	process.Logon(logonStatus);
       
   240 	process.Resume();
       
   241 	User::WaitForRequest(logonStatus);
       
   242 	test(process.ExitType()==EExitPanic); // Process should have got a Platform Security panic
       
   243 	test(logonStatus==EPlatformSecurityTrap);
       
   244 	CLOSE_AND_WAIT(process);
       
   245 	process2.Kill(0);
       
   246 	CLOSE_AND_WAIT(process2);
       
   247 
       
   248 	test.Next(_L("Try other process to using SetJustInTime on us"));
       
   249 	process.Create(~0u,ETestProcessSetJustInTime);
       
   250 	process.Logon(logonStatus);
       
   251 	process.Resume();
       
   252 	User::WaitForRequest(logonStatus);
       
   253 	test(process.ExitType()==EExitPanic); // Process should have got a Platform Security panic
       
   254 	test(logonStatus==EPlatformSecurityTrap);
       
   255 	CLOSE_AND_WAIT(process);
       
   256 
       
   257 	test.End();
       
   258 	}
       
   259 
       
   260 
       
   261 
       
   262 void TestRename()
       
   263 	{
       
   264 	TName name;
       
   265 
       
   266 	test.Start(_L("Renaming the current process with User::RenameProcess"));
       
   267 	name = RProcess().Name();
       
   268 	name.SetLength(KTestProcessName().Length());
       
   269 	test(name.CompareF(KTestProcessName)!=0);
       
   270 	User::RenameProcess(KTestProcessName);
       
   271 	name = RProcess().Name();
       
   272 	name.SetLength(KTestProcessName().Length());
       
   273 	test(name.CompareF(KTestProcessName)==0);
       
   274 
       
   275 
       
   276 	test.End();
       
   277 	}
       
   278 
       
   279 
       
   280 
       
   281 void TestKill()
       
   282 	{
       
   283 	RTestProcess process;
       
   284 	RTestProcess process2;
       
   285 	TRequestStatus logonStatus;
       
   286 	TRequestStatus logonStatus2;
       
   287 
       
   288 	process2.Create(0,ETestProcessNull);
       
   289 	process2.Logon(logonStatus2);
       
   290 
       
   291 	// Test RProcess::Kill()
       
   292 
       
   293 	test.Start(_L("Test killing an un-resumed process created by us"));
       
   294 	process.Create(0,ETestProcessNull);
       
   295 	process.Logon(logonStatus);
       
   296 	process.Kill(999);
       
   297 	User::WaitForRequest(logonStatus);
       
   298 	test(process.ExitType()==EExitKill);
       
   299 	test(logonStatus==999);
       
   300 	CLOSE_AND_WAIT(process);
       
   301 
       
   302 	test.Next(_L("Try killing un-resumed process not created by self"));
       
   303 	process.Create(~(1u<<ECapabilityPowerMgmt),ETestProcessKill,process2.Id());
       
   304 	process.Logon(logonStatus);
       
   305 	process.Resume();
       
   306 	User::WaitForRequest(logonStatus);
       
   307 	test(process.ExitType()==EExitPanic); // Process should have got a Platform Security panic
       
   308 	test(logonStatus==EPlatformSecurityTrap);
       
   309 	test(logonStatus2==KRequestPending); // the process should still be alive
       
   310 	CLOSE_AND_WAIT(process);
       
   311 
       
   312 	test.Next(_L("Test a process killing itself"));
       
   313 	process.Create(0,ETestProcessKillSelf);
       
   314 	process.Logon(logonStatus);
       
   315 	process.Resume();
       
   316 	User::WaitForRequest(logonStatus);
       
   317 	test(process.ExitType()==EExitKill);
       
   318 	test(logonStatus==999);
       
   319 	CLOSE_AND_WAIT(process);
       
   320 
       
   321 	test.Next(_L("Try killing running process"));
       
   322 	process.Create(~(1u<<ECapabilityPowerMgmt),ETestProcessKill,RProcess().Id());
       
   323 	process.Logon(logonStatus);
       
   324 	process.Resume();
       
   325 	User::WaitForRequest(logonStatus);
       
   326 	test(process.ExitType()==EExitPanic); // Process should have got a Platform Security panic
       
   327 	test(logonStatus==EPlatformSecurityTrap);
       
   328 	CLOSE_AND_WAIT(process);
       
   329 
       
   330 	// Test RProcess::Teminate()
       
   331 
       
   332 	test.Next(_L("Test terminating an un-resumed process created by us"));
       
   333 	process.Create(0,ETestProcessNull);
       
   334 	process.Logon(logonStatus);
       
   335 	process.Terminate(999);
       
   336 	User::WaitForRequest(logonStatus);
       
   337 	test(process.ExitType()==EExitTerminate);
       
   338 	test(logonStatus==999);
       
   339 	CLOSE_AND_WAIT(process);
       
   340 
       
   341 	test.Next(_L("Try terminating un-resumed process not created by self"));
       
   342 	process.Create(~(1u<<ECapabilityPowerMgmt),ETestProcessTerminate,process2.Id());
       
   343 	process.Logon(logonStatus);
       
   344 	process.Resume();
       
   345 	User::WaitForRequest(logonStatus);
       
   346 	test(process.ExitType()==EExitPanic); // Process should have got a Platform Security panic
       
   347 	test(logonStatus==EPlatformSecurityTrap);
       
   348 	test(logonStatus2==KRequestPending); // the process should still be alive
       
   349 	CLOSE_AND_WAIT(process);
       
   350 
       
   351 	test.Next(_L("Test a process terminating itself"));
       
   352 	process.Create(0,ETestProcessTerminateSelf);
       
   353 	process.Logon(logonStatus);
       
   354 	process.Resume();
       
   355 	User::WaitForRequest(logonStatus);
       
   356 	test(process.ExitType()==EExitTerminate);
       
   357 	test(logonStatus==999);
       
   358 	CLOSE_AND_WAIT(process);
       
   359 
       
   360 	test.Next(_L("Try terminating running process"));
       
   361 	process.Create(~(1u<<ECapabilityPowerMgmt),ETestProcessTerminate,RProcess().Id());
       
   362 	process.Logon(logonStatus);
       
   363 	process.Resume();
       
   364 	User::WaitForRequest(logonStatus);
       
   365 	test(process.ExitType()==EExitPanic); // Process should have got a Platform Security panic
       
   366 	test(logonStatus==EPlatformSecurityTrap);
       
   367 	CLOSE_AND_WAIT(process);
       
   368 
       
   369 	// Test RProcess::Panic()
       
   370 
       
   371 	test.Next(_L("Test panicking an un-resumed process created by us"));
       
   372 	process.Create(0,ETestProcessNull);
       
   373 	process.Logon(logonStatus);
       
   374 	process.Panic(KTestPanicCategory,999);
       
   375 	User::WaitForRequest(logonStatus);
       
   376 	test(process.ExitType()==EExitPanic);
       
   377 	test(logonStatus==999);
       
   378 	CLOSE_AND_WAIT(process);
       
   379 
       
   380 	test.Next(_L("Try panicking un-resumed process not created by self"));
       
   381 	process.Create(~(1u<<ECapabilityPowerMgmt),ETestProcessPanic,process2.Id());
       
   382 	process.Logon(logonStatus);
       
   383 	process.Resume();
       
   384 	User::WaitForRequest(logonStatus);
       
   385 	test(process.ExitType()==EExitPanic); // Process should have got a Platform Security panic
       
   386 	test(logonStatus==EPlatformSecurityTrap);
       
   387 	test(logonStatus2==KRequestPending); // the process should still be alive
       
   388 	CLOSE_AND_WAIT(process);
       
   389 
       
   390 	test.Next(_L("Test a process panicking itself"));
       
   391 	process.Create(0,ETestProcessPanicSelf);
       
   392 	process.Logon(logonStatus);
       
   393 	process.Resume();
       
   394 	User::WaitForRequest(logonStatus);
       
   395 	test(process.ExitType()==EExitPanic);
       
   396 	test(logonStatus==999);
       
   397 	CLOSE_AND_WAIT(process);
       
   398 
       
   399 	test.Next(_L("Try panicking running process"));
       
   400 	process.Create(~(1u<<ECapabilityPowerMgmt),ETestProcessPanic,RProcess().Id());
       
   401 	process.Logon(logonStatus);
       
   402 	process.Resume();
       
   403 	User::WaitForRequest(logonStatus);
       
   404 	test(process.ExitType()==EExitPanic); // Process should have got a Platform Security panic
       
   405 	test(logonStatus==EPlatformSecurityTrap);
       
   406 	CLOSE_AND_WAIT(process);
       
   407 
       
   408 	// 
       
   409 
       
   410 	test(logonStatus2==KRequestPending); // the process should still be alive
       
   411 	process2.Resume();
       
   412 	User::WaitForRequest(logonStatus2);
       
   413 	test(logonStatus2==KErrNone);
       
   414 	CLOSE_AND_WAIT(process2);
       
   415 
       
   416 	// Checks with ECapabilityPowerMgmt
       
   417 
       
   418 	test.Next(_L("Test kill running process ECapabilityPowerMgmt"));
       
   419 	process2.Create(0,ETestProcessNull);
       
   420 	process2.Logon(logonStatus2);
       
   421 	process.Create((1<<ECapabilityPowerMgmt),ETestProcessKill,process2.Id());
       
   422 	process.Logon(logonStatus);
       
   423 	SyncMutex.Wait();
       
   424 	process2.Resume();
       
   425 	process.Resume();
       
   426 	User::WaitForRequest(logonStatus);
       
   427 	test(process.ExitType()==EExitKill);
       
   428 	test(logonStatus==0);
       
   429 	CLOSE_AND_WAIT(process);
       
   430 	User::WaitForRequest(logonStatus2);
       
   431 	test(process2.ExitType()==EExitKill);
       
   432 	test(logonStatus2==999);
       
   433 	process2.Close();
       
   434 	SyncMutex.Signal();
       
   435 
       
   436 	test.Next(_L("Test terminating running process ECapabilityPowerMgmt"));
       
   437 	process2.Create(0,ETestProcessNull);
       
   438 	process2.Logon(logonStatus2);
       
   439 	process.Create((1<<ECapabilityPowerMgmt),ETestProcessTerminate,process2.Id());
       
   440 	process.Logon(logonStatus);
       
   441 	SyncMutex.Wait();
       
   442 	process2.Resume();
       
   443 	process.Resume();
       
   444 	User::WaitForRequest(logonStatus);
       
   445 	test(process.ExitType()==EExitKill);
       
   446 	test(logonStatus==0);
       
   447 	CLOSE_AND_WAIT(process);
       
   448 	User::WaitForRequest(logonStatus2);
       
   449 	test(process2.ExitType()==EExitTerminate);
       
   450 	test(logonStatus2==999);
       
   451 	CLOSE_AND_WAIT(process2);
       
   452 	SyncMutex.Signal();
       
   453 
       
   454 	test.Next(_L("Test panicking running process ECapabilityPowerMgmt"));
       
   455 	process2.Create(0,ETestProcessNull);
       
   456 	process2.Logon(logonStatus2);
       
   457 	process.Create((1<<ECapabilityPowerMgmt),ETestProcessPanic,process2.Id());
       
   458 	process.Logon(logonStatus);
       
   459 	SyncMutex.Wait();
       
   460 	process2.Resume();
       
   461 	process.Resume();
       
   462 	User::WaitForRequest(logonStatus);
       
   463 	test(process.ExitType()==EExitKill);
       
   464 	test(logonStatus==0);
       
   465 	CLOSE_AND_WAIT(process);
       
   466 	User::WaitForRequest(logonStatus2);
       
   467 	test(process2.ExitType()==EExitPanic);
       
   468 	test(logonStatus2==999);
       
   469 	CLOSE_AND_WAIT(process2);
       
   470 	SyncMutex.Signal();
       
   471 
       
   472 	//
       
   473 
       
   474 	test.End();
       
   475 	}
       
   476 
       
   477 
       
   478 
       
   479 void TestResume()
       
   480 	{
       
   481 	RTestProcess process;
       
   482 	RTestProcess process2;
       
   483 	TRequestStatus logonStatus;
       
   484 	TRequestStatus logonStatus2;
       
   485 
       
   486 	test.Start(_L("Try to get another process to resume one we've created"));
       
   487 	process2.Create(0,ETestProcessNull);
       
   488 	process2.Logon(logonStatus2);
       
   489 	process.Create(~0u,ETestProcessResume,process2.Id());
       
   490 	process.Logon(logonStatus);
       
   491 	process.Resume();
       
   492 	User::WaitForRequest(logonStatus);
       
   493 	test(process.ExitType()==EExitPanic); // Process should have got a Platform Security panic
       
   494 	test(logonStatus==EPlatformSecurityTrap);
       
   495 	User::After(1*1000*1000); // Give time for process to run (if it had been resumed)...
       
   496 	test(logonStatus2==KRequestPending); // It shouldn't have, so logon will be pending
       
   497 	process2.Kill(0);
       
   498 	CLOSE_AND_WAIT(process2);
       
   499 
       
   500 //	test.Next(_L("Test resuming a process we've created"));
       
   501 //
       
   502 //  No code for this, because this whole test program wouldn't work if this wasn't OK
       
   503 //
       
   504 
       
   505 	test.End();
       
   506 	}
       
   507 
       
   508 
       
   509 
       
   510 void TestSetPriority()
       
   511 	{
       
   512 	RTestProcess process;
       
   513 	RTestProcess process2;
       
   514 	TProcessPriority priority;
       
   515 	TRequestStatus rendezvousStatus;
       
   516 	TRequestStatus logonStatus;
       
   517 
       
   518 	test.Start(_L("Test changing our own process priority"));
       
   519 	priority = process.Priority();
       
   520 	process.SetPriority(EPriorityLow);
       
   521 	test(process.Priority()==EPriorityLow);
       
   522 	process.SetPriority(EPriorityBackground);
       
   523 	test(process.Priority()==EPriorityBackground);
       
   524 	process.SetPriority(EPriorityForeground);
       
   525 	test(process.Priority()==EPriorityForeground);
       
   526 	process.SetPriority(priority);
       
   527 
       
   528 	test.Next(_L("Test changing unresumed process priority (which we created)"));
       
   529 	process.Create(0,ETestProcessNull);
       
   530 	priority = process.Priority();
       
   531 	process.SetPriority(EPriorityLow);
       
   532 	test(process.Priority()==EPriorityLow);
       
   533 	process.SetPriority(EPriorityBackground);
       
   534 	test(process.Priority()==EPriorityBackground);
       
   535 	process.SetPriority(EPriorityForeground);
       
   536 	test(process.Priority()==EPriorityForeground);
       
   537 	process.SetPriority(priority);
       
   538 	process.Kill(0);
       
   539 	CLOSE_AND_WAIT(process);
       
   540 
       
   541 	test.Next(_L("Try other process changing the priority of our created process"));
       
   542 	process2.Create(0,ETestProcessNull);
       
   543 	process.Create(~0u,ETestProcessPriority,process2.Id());
       
   544 	process.Logon(logonStatus);
       
   545 	process.Resume();
       
   546 	User::WaitForRequest(logonStatus);
       
   547 	test(logonStatus==KErrNone);
       
   548 	CLOSE_AND_WAIT(process);
       
   549 	process2.Kill(0);
       
   550 	CLOSE_AND_WAIT(process2);
       
   551 
       
   552 	test.Next(_L("Try changing other process's priority (no priority-control enabled)"));
       
   553 	process.Create(~0u,ETestProcessPriorityControlOff);
       
   554 	process.Rendezvous(rendezvousStatus);
       
   555 	process.Logon(logonStatus);
       
   556 	SyncMutex.Wait();
       
   557 	process.Resume();
       
   558 	User::WaitForRequest(rendezvousStatus); // Process has started
       
   559 	priority = process.Priority();
       
   560 	TInt result = process.SetPriority(EPriorityLow);
       
   561 	test(result == KErrPermissionDenied);
       
   562 	test(process.Priority()==priority); // priority shouldn't have changed
       
   563 	process.SetPriority(EPriorityBackground);
       
   564 	test(result == KErrPermissionDenied);
       
   565 	test(process.Priority()==priority); // priority shouldn't have changed
       
   566 	process.SetPriority(EPriorityForeground);
       
   567 	test(result == KErrPermissionDenied);
       
   568 	test(process.Priority()==priority); // priority shouldn't have changed
       
   569 	test(logonStatus==KRequestPending); // wait for process to end
       
   570 	SyncMutex.Signal();
       
   571 	User::WaitForRequest(logonStatus);
       
   572 	CLOSE_AND_WAIT(process);
       
   573 
       
   574 	test.Next(_L("Try changing other process's priority (priority-control enabled)"));
       
   575 	process.Create(~0u,ETestProcessPriorityControlOn);
       
   576 	process.Rendezvous(rendezvousStatus);
       
   577 	process.Logon(logonStatus);
       
   578 	SyncMutex.Wait();
       
   579 	process.Resume();
       
   580 	User::WaitForRequest(rendezvousStatus); // Process has started
       
   581 	priority = process.Priority();
       
   582 	result = process.SetPriority(EPriorityForeground);
       
   583 	test(result == KErrNone);
       
   584 	test(process.Priority()==EPriorityForeground);
       
   585 	result = process.SetPriority(EPriorityBackground);
       
   586 	test(result == KErrNone);
       
   587 	test(process.Priority()==EPriorityBackground);
       
   588 	result = process.SetPriority(EPriorityForeground);
       
   589 	test(result == KErrNone);
       
   590 	test(process.Priority()==EPriorityForeground);
       
   591 	result = process.SetPriority(EPriorityLow);
       
   592 	test(result == KErrPermissionDenied);
       
   593 	test(process.Priority()==EPriorityForeground); // should still be foreground priority
       
   594 	result = process.SetPriority(EPriorityHigh);
       
   595 	test(result == KErrNone);
       
   596 	test(process.Priority()==EPriorityHigh);
       
   597 	result = process.SetPriority(priority);
       
   598 	test(result == KErrNone);
       
   599 	test(logonStatus==KRequestPending); // wait for process to end
       
   600 	SyncMutex.Signal();
       
   601 	User::WaitForRequest(logonStatus);
       
   602 	CLOSE_AND_WAIT(process);
       
   603 
       
   604 	test.Next(_L("Try changing other process's priority (priority-control enabled and low priority)"));
       
   605 	process.Create(~0u,ETestProcessPriorityControlOnAndLowPriority);
       
   606 	process.Rendezvous(rendezvousStatus);
       
   607 	process.Logon(logonStatus);
       
   608 	SyncMutex.Wait();
       
   609 	process.Resume();
       
   610 	User::WaitForRequest(rendezvousStatus); // Process has started
       
   611 	test(process.Priority()==EPriorityLow);
       
   612 	result = process.SetPriority(EPriorityForeground);
       
   613 	test(result == KErrPermissionDenied);
       
   614 	test(process.Priority()==EPriorityLow);
       
   615 	result = process.SetPriority(EPriorityBackground);
       
   616 	test(result == KErrPermissionDenied);
       
   617 	test(process.Priority()==EPriorityLow);
       
   618 	result = process.SetPriority(EPriorityForeground);
       
   619 	test(result == KErrPermissionDenied);
       
   620 	test(process.Priority()==EPriorityLow);
       
   621 	result = process.SetPriority(EPriorityLow);
       
   622 	test(result == KErrPermissionDenied);
       
   623 	test(process.Priority()==EPriorityLow);
       
   624 	result = process.SetPriority(EPriorityHigh);
       
   625 	test(result == KErrPermissionDenied);
       
   626 	test(process.Priority()==EPriorityLow);
       
   627 	test(logonStatus==KRequestPending); // wait for process to end
       
   628 	SyncMutex.Signal();
       
   629 	User::WaitForRequest(logonStatus);
       
   630 	CLOSE_AND_WAIT(process);
       
   631 
       
   632 	test.End();
       
   633 	}
       
   634 
       
   635 
       
   636 
       
   637 GLDEF_C TInt E32Main()
       
   638     {
       
   639 	TBuf16<512> cmd;
       
   640 	User::CommandLine(cmd);
       
   641 	if(cmd.Length() && TChar(cmd[0]).IsDigit())
       
   642 		{
       
   643 		TInt function = -1;
       
   644 		TInt arg1 = -1;
       
   645 		TInt arg2 = -1;
       
   646 		TLex lex(cmd);
       
   647 
       
   648 		lex.Val(function);
       
   649 		lex.SkipSpace();
       
   650 		lex.Val(arg1);
       
   651 		lex.SkipSpace();
       
   652 		lex.Val(arg2);
       
   653 		return DoTestProcess(function,arg1,arg2);
       
   654 		}
       
   655 
       
   656 	test.Title();
       
   657 
       
   658 	if((!PlatSec::ConfigSetting(PlatSec::EPlatSecProcessIsolation))||(!PlatSec::ConfigSetting(PlatSec::EPlatSecEnforcement)))
       
   659 		{
       
   660 		test.Start(_L("TESTS NOT RUN - PlatSecProcessIsolation is not enforced"));
       
   661 		test.End();
       
   662 		return 0;
       
   663 		}
       
   664 
       
   665 	test(SyncMutex.CreateGlobal(KSyncMutext)==KErrNone);
       
   666 	
       
   667 	test.Start(_L("Test SetJustInTime"));
       
   668 	TestSetJustInTime();
       
   669 
       
   670 	test.Next(_L("Test Rename"));
       
   671 	TestRename();
       
   672 
       
   673 	test.Next(_L("Test Kill, Panic and Teminate"));
       
   674 	TestKill();
       
   675 
       
   676 	test.Next(_L("Test Resume"));
       
   677 	TestResume();
       
   678 
       
   679 	test.Next(_L("Test SetPriority"));
       
   680 	TestSetPriority();
       
   681 
       
   682 
       
   683 	SyncMutex.Close();
       
   684 	test.End();
       
   685 
       
   686 	return(0);
       
   687     }
       
   688