os/kernelhwsrv/kerneltest/e32test/secure/t_suser.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     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_suser.cpp
    15 // Overview:
    16 // Test the platform security aspects of the User and UserSvr classes.
    17 // API Information:
    18 // User, UserSvr
    19 // Details:
    20 // - Attempt to get and set the machine configuration with and without 
    21 // the proper privileges. Verify results are as expected.
    22 // - Test various critical threads and processes with different capabilities,
    23 // verify results are as expected.
    24 // - Verify that the SetPriorityControl and PriorityControl methods work as
    25 // expected.
    26 // - Verify that the UserSvr::CaptureEventHook, ReleaseEventHook, RequestEvent,
    27 // and RequestEventCancel work as expected.
    28 // - Test handled and unhandled exceptions work as expected.
    29 // - Test ResetInactivityTime() with different capabilities. Verify results.
    30 // - Test SetHomeTime() with different capabilities. Verify results.
    31 // - Test SetMemoryThresholds() with different capabilities. Verify results.
    32 // Platforms/Drives/Compatibility:
    33 // All.
    34 // Assumptions/Requirement/Pre-requisites:
    35 // Failures and causes:
    36 // Base Port information:
    37 // 
    38 //
    39 
    40 #define __E32TEST_EXTENSION__
    41 
    42 #include <e32test.h>
    43 #include <e32svr.h>
    44 #include <nkern/nk_trace.h>
    45 
    46 LOCAL_D RTest test(_L("T_SUSER"));
    47 
    48 _LIT(KSyncSemaphoreName,"T_SUSER-SyncSemaphore");
    49 RSemaphore SyncSemaphore;
    50 
    51 
    52 void SlaveWait()
    53 	{
    54 	RSemaphore sem;
    55 	if(sem.OpenGlobal(KSyncSemaphoreName,EOwnerThread)!=KErrNone)
    56 		User::Invariant();
    57 	sem.Wait();
    58 	sem.Close();
    59 	}
    60 
    61 
    62 void SignalSlave()
    63 	{
    64 	RSemaphore sem;
    65 	if(sem.OpenGlobal(KSyncSemaphoreName,EOwnerThread)!=KErrNone)
    66 		User::Invariant();
    67 	sem.Signal();
    68 	sem.Close();
    69 	}
    70 
    71 
    72 class RTestThread : public RThread
    73 	{
    74 public:
    75 	void Create(TThreadFunction aFunction,TInt aArg=0);
    76 	};
    77 
    78 TInt GetCriticalValue(TAny* aArg)
    79 	{
    80 	TUint id = (TUint)aArg;
    81 	RThread thread;
    82 	TInt r = thread.Open(TThreadId(id));
    83 	if (r == KErrNone)
    84 		r = (TInt)User::Critical(thread);
    85 	thread.Close();
    86 	return r;
    87 	}
    88 
    89 void SetThreadCritical(User::TCritical aCritical)
    90 	{
    91 	// set thread critical as specified
    92 	if(User::SetCritical(aCritical)!=KErrNone)
    93 		User::Invariant();
    94 	// check critical value was as we set
    95 	if(User::Critical()!=aCritical) 
    96 		User::Invariant();
    97 	// check from another thread
    98 	RTestThread thread;
    99 	thread.Create(GetCriticalValue, (TUint)thread.Id());
   100 	TRequestStatus logonStatus;
   101 	thread.Logon(logonStatus);
   102 	thread.Resume();
   103 	User::WaitForRequest(logonStatus);
   104 	if (logonStatus!=(TInt)aCritical)
   105 		User::Invariant();
   106 	}
   107 
   108 TInt TestThreadProcessCritical(TAny* aArg)
   109 	{
   110 	// check thread is not critical
   111 	if(User::Critical()!=User::ENotCritical)
   112 		User::Invariant();
   113 	// set thread as process critical
   114 	SetThreadCritical(User::EProcessCritical);
   115 	// complete rendezvous to let test code know we got this far ok
   116 	RProcess::Rendezvous(KErrNone);
   117 	// Kill this thread which should also kill the process
   118 	switch((TExitType)(TInt)aArg)
   119 		{
   120 		case EExitKill:
   121 			RThread().Kill(999);
   122 			break;
   123 		case EExitTerminate:
   124 			RThread().Terminate(999);
   125 			break;
   126 		case EExitPanic:
   127 			User::Panic(_L("TestPanic"),999);
   128 			break;
   129 		default:
   130 			break;
   131 		}
   132 	return KErrNone;
   133 	}
   134 
   135 TInt TestThreadSystemCritical(TAny*)
   136 	{
   137 	User::TCritical critical = User::Critical();
   138 	// check thread is not already system critical
   139 	if(User::Critical()==User::ESystemCritical)
   140 		User::Invariant();
   141 	// set thread as system critical
   142 	SetThreadCritical(User::ESystemCritical);
   143 	// Can't test system critical thread dying so put back to normal and end
   144 	SetThreadCritical(critical);
   145 	// complete rendezvous to let test code know we got this far ok
   146 	RProcess::Rendezvous(KErrNone);
   147 	return KErrNone;
   148 	}
   149 
   150 TInt TestThreadSystemPermanent(TAny*)
   151 	{
   152 	User::TCritical critical = User::Critical();
   153 	// check thread is not already system permanent
   154 	if(User::Critical()==User::ESystemPermanent)
   155 		User::Invariant();
   156 	// set thread as system permanent
   157 	SetThreadCritical(User::ESystemPermanent);
   158 	// Can't test system permanent thread dying so put back to normal and end
   159 	SetThreadCritical(critical);
   160 	// complete rendezvous to let test code know we got this far ok
   161 	RProcess::Rendezvous(KErrNone);
   162 	return KErrNone;
   163 	}
   164 
   165 TInt TestThreadSystemProcessCritical(TAny*)
   166 	{
   167 	User::TCritical critical = User::ProcessCritical();
   168 	// check thread is not already system critical
   169 	if(User::ProcessCritical()==User::ESystemCritical)
   170 		User::Invariant();
   171 	// set thread as system critical
   172 	if(User::SetProcessCritical(User::ESystemCritical)!=KErrNone)
   173 		User::Invariant();
   174 	// check critical value was as we set
   175 	if(User::ProcessCritical()!=User::ESystemCritical) 
   176 		User::Invariant();
   177 	// complete rendezvous to let test code know we got this far ok
   178 	RProcess::Rendezvous(KErrNone);
   179 	// wait for main test thread to tell us to continue...
   180 	SlaveWait();
   181 	// Can't test system critical thread dying so put back to normal and end
   182 	if(User::SetProcessCritical(critical)!=KErrNone)
   183 		User::Invariant();
   184 	if(User::ProcessCritical()!=critical) 
   185 		User::Invariant();
   186 	return KErrNone;
   187 	}
   188 
   189 TInt TestThreadSystemProcessPermanent(TAny*)
   190 	{
   191 	User::TCritical critical = User::ProcessCritical();
   192 	// check thread is not already system permanent
   193 	if(User::ProcessCritical()==User::ESystemPermanent)
   194 		User::Invariant();
   195 	// set thread as system permanent
   196 	if(User::SetProcessCritical(User::ESystemPermanent)!=KErrNone)
   197 		User::Invariant();
   198 	// check critical value was as we set
   199 	if(User::ProcessCritical()!=User::ESystemPermanent) 
   200 		User::Invariant();
   201 	// complete rendezvous to let test code know we got this far ok
   202 	RProcess::Rendezvous(KErrNone);
   203 	// wait for main test thread to tell us to continue...
   204 	SlaveWait();
   205 	// Can't test system permanent thread dying so put back to normal and end
   206 	if(User::SetProcessCritical(critical)!=KErrNone)
   207 		User::Invariant();
   208 	if(User::ProcessCritical()!=critical) 
   209 		User::Invariant();
   210 	return KErrNone;
   211 	}
   212 
   213 TInt TestThreadTraceKallthreadssystem(TAny*)
   214 	{
   215 	TUint32 mask = UserSvr::DebugMask(DEBUGMASKWORD2);
   216 	// check thread does not already have KALLTHREADSSYSTEM bit set
   217 	if (mask & (1 << (KALLTHREADSSYSTEM%32)))
   218 		User::Invariant();
   219 	// set KALLTHREADSSYSTEM bit
   220 	User::SetDebugMask(mask | (1 << (KALLTHREADSSYSTEM%32)), DEBUGMASKWORD2);
   221 	// check KALLTHREADSSYSTEM bit was as we set
   222 	if(!(UserSvr::DebugMask(DEBUGMASKWORD2) & (1 << (KALLTHREADSSYSTEM%32)))) 
   223 		User::Invariant();
   224 	// restore original mask
   225 	User::SetDebugMask(mask, DEBUGMASKWORD2);
   226 	if(UserSvr::DebugMask(DEBUGMASKWORD2) & (1 << (KALLTHREADSSYSTEM%32))) 
   227 		User::Invariant();
   228 	// complete rendezvous to let test code know we got this far ok
   229 	RProcess::Rendezvous(KErrNone);
   230 	return KErrNone;
   231 	}
   232 
   233 TInt TestThreadAllThreadsCritical(TAny* aArg)
   234 	{
   235 	// check that thread was created process critical 
   236 	if(User::Critical()!=User::EProcessCritical)
   237 		User::Invariant();
   238 	// complete rendezvous to let test code know we got this far ok
   239 	RProcess::Rendezvous(KErrNone);
   240 	// Kill this thread which should also kill the process
   241 	switch((TExitType)(TInt)aArg)
   242 		{
   243 		case EExitKill:
   244 			RThread().Kill(999);
   245 			break;
   246 		case EExitTerminate:
   247 			RThread().Terminate(999);
   248 			break;
   249 		case EExitPanic:
   250 			User::Panic(_L("TestPanic"),999);
   251 			break;
   252 		default:
   253 			break;
   254 		}
   255 	return KErrNone;
   256 	}
   257 
   258 TInt TestAllThreadsCritical(TExitType aExitType)
   259 	{
   260 	// check process does not already have all threads critical
   261 	if(User::ProcessCritical()==User::EAllThreadsCritical)
   262 		User::Panic(_L("TestAllThreadsCritical"),__LINE__);
   263 	// set process as all threads critical
   264 	if(User::SetProcessCritical(User::EAllThreadsCritical)!=KErrNone)
   265 		User::Panic(_L("TestAllThreadsCritical"),__LINE__);
   266 	// check critical value was as we set
   267 	if(User::ProcessCritical()!=User::EAllThreadsCritical)
   268 		User::Panic(_L("TestAllThreadsCritical"),__LINE__);
   269 	// spawn a thread that exits in the specifed way
   270 	RTestThread thread;
   271 	thread.Create(TestThreadAllThreadsCritical,aExitType);
   272 	TRequestStatus logonStatus;
   273 	thread.Logon(logonStatus);
   274 	thread.Resume();
   275 	User::WaitForRequest(logonStatus);
   276 	return KErrNone;
   277 	}
   278 
   279 void RTestThread::Create(TThreadFunction aFunction,TInt aArg)
   280 	{
   281 	TInt r=RThread::Create(_L(""),aFunction,KDefaultStackSize,KDefaultStackSize,KDefaultStackSize,(TAny*)aArg);
   282 	test(r==KErrNone);
   283 	}
   284 
   285 
   286 
   287 enum TTestProcessFunctions
   288 	{
   289 	ETestProcessMachineConfigGet,
   290 	ETestProcessMachineConfigSet,
   291 	ETestProcessProcessCriticalNormalEnd,
   292 	ETestProcessProcessCriticalKill,
   293 	ETestProcessProcessCriticalTerminate,
   294 	ETestProcessProcessCriticalPanic,
   295 	ETestProcessAllThreadsCriticalNormalEnd,
   296 	ETestProcessAllThreadsCriticalKill,
   297 	ETestProcessAllThreadsCriticalTerminate,
   298 	ETestProcessAllThreadsCriticalPanic,
   299 	ETestProcessSystemCritical,
   300 	ETestProcessSystemPermanent,
   301 	ETestProcessSystemProcessCritical,
   302 	ETestProcessSystemProcessPermanent,
   303 	ETestProcessCaptureEventHook,
   304 	ETestProcessReleaseEventHook,
   305 	ETestProcessRequestEvent,
   306 	ETestProcessRequestEventCancel,
   307 	ETestProcessSetHomeTime,
   308 	ETestProcessSetMemoryThresholds,
   309 	ETestProcessSetUTCOffset,
   310 	ETestProcessSetUTCTime,
   311 	ETestProcessSetUTCTimeAndOffset,
   312 	ETestProcessTraceKallthreadssystem,
   313 	ETestProcessLocaleSet,
   314 	ETestProcessUserSetCurrencySymbol,
   315 	ETestProcessChangeLocale,
   316 	ETestProcessSaveSystemSettings,
   317 	ETestProcessSetCurrencySymbol,
   318 	ETestProcessAddEventESwitchOff,
   319 	ETestProcessAddEventECaseOpen,
   320 	ETestProcessAddEventECaseClose
   321 	};
   322 
   323 #include "testprocess.h"
   324 
   325 const TInt KMachineConfigSize = 1024;
   326 TBuf8<KMachineConfigSize> MachineConfig;
   327 
   328 TInt DoTestProcess(TInt aTestNum,TInt aArg1,TInt aArg2)
   329 	{
   330 	(void)aArg1;
   331 	(void)aArg2;
   332 
   333 	RThread me;
   334 	me.SetPriority(EPriorityLess);
   335 	
   336 	switch(aTestNum)
   337 		{
   338 
   339 	case ETestProcessMachineConfigGet:
   340 		{
   341 		TInt size=0;
   342 		TInt r=User::MachineConfiguration(MachineConfig,size);
   343 		if(r!=KErrNone)
   344 			User::Invariant();
   345 		MachineConfig.SetLength(size);
   346 		return KErrNone;
   347 		}
   348 
   349 	case ETestProcessMachineConfigSet:
   350 		{
   351 		TInt size=0;
   352 		TInt r=User::MachineConfiguration(MachineConfig,size);
   353 		if(r!=KErrNone)
   354 			User::Invariant();
   355 		MachineConfig.SetLength(size);
   356 
   357 		r=User::SetMachineConfiguration(MachineConfig);
   358 		if(r!=KErrNone)
   359 			User::Invariant();
   360 		return KErrNone;
   361 		}
   362 
   363 	case ETestProcessProcessCriticalNormalEnd:
   364 		{
   365 		RTestThread thread;
   366 		thread.Create(TestThreadProcessCritical,-1);
   367 		TRequestStatus logonStatus;
   368 		thread.Logon(logonStatus);
   369 		thread.Resume();
   370 		User::WaitForRequest(logonStatus);
   371 		return KErrNone;
   372 		}
   373 		
   374 	case ETestProcessProcessCriticalKill:
   375 		{
   376 		RTestThread thread;
   377 		thread.Create(TestThreadProcessCritical,EExitKill);
   378 		TRequestStatus logonStatus;
   379 		thread.Logon(logonStatus);
   380 		thread.Resume();
   381 		User::WaitForRequest(logonStatus);
   382 		return KErrNone;
   383 		}
   384 
   385 	case ETestProcessProcessCriticalTerminate:
   386 		{
   387 		RTestThread thread;
   388 		thread.Create(TestThreadProcessCritical,EExitTerminate);
   389 		TRequestStatus logonStatus;
   390 		thread.Logon(logonStatus);
   391 		thread.Resume();
   392 		User::WaitForRequest(logonStatus);
   393 		return KErrNone;
   394 		}
   395 
   396 	case ETestProcessProcessCriticalPanic:
   397 		{
   398 		RTestThread thread;
   399 		thread.Create(TestThreadProcessCritical,EExitPanic);
   400 		TRequestStatus logonStatus;
   401 		thread.Logon(logonStatus);
   402 		thread.Resume();
   403 		User::WaitForRequest(logonStatus);
   404 		return KErrNone;
   405 		}
   406 
   407 	case ETestProcessAllThreadsCriticalNormalEnd:
   408 		return TestAllThreadsCritical((TExitType)-1);
   409 		
   410 	case ETestProcessAllThreadsCriticalKill:
   411 		return TestAllThreadsCritical(EExitKill);
   412 
   413 	case ETestProcessAllThreadsCriticalTerminate:
   414 		return TestAllThreadsCritical(EExitTerminate);
   415 
   416 	case ETestProcessAllThreadsCriticalPanic:
   417 		return TestAllThreadsCritical(EExitPanic);
   418 
   419 	case ETestProcessSystemCritical:
   420 		return TestThreadSystemCritical(NULL);
   421 
   422 	case ETestProcessSystemPermanent:
   423 		return TestThreadSystemPermanent(NULL);
   424 
   425 	case ETestProcessSystemProcessCritical:
   426 		return TestThreadSystemProcessCritical(NULL);
   427 
   428 	case ETestProcessSystemProcessPermanent:
   429 		return TestThreadSystemProcessPermanent(NULL);
   430 
   431 	case ETestProcessCaptureEventHook:
   432 		UserSvr::CaptureEventHook();
   433 		break;
   434 
   435 	case ETestProcessReleaseEventHook:
   436 		UserSvr::ReleaseEventHook();
   437 		break;
   438 
   439 	case ETestProcessRequestEvent:
   440 		{
   441 		TRawEventBuf event;
   442 		TRequestStatus status;
   443 		UserSvr::RequestEvent(event,status);
   444 		}
   445 		break;
   446 
   447 	case ETestProcessRequestEventCancel:
   448 		UserSvr::RequestEventCancel();
   449 		break;
   450 
   451 	case ETestProcessSetHomeTime:
   452 		{
   453 		TTime time;
   454 		time.HomeTime();
   455 		User::SetHomeTime(time);
   456 		}
   457 		break;
   458 
   459 	case ETestProcessSetUTCOffset:
   460 		{
   461 		User::SetUTCOffset(0);
   462 		}
   463 		break;
   464 
   465 	case ETestProcessSetUTCTime:
   466 		{
   467 		TTime time;
   468 		time.UniversalTime();
   469 		User::SetUTCTime(time);
   470 		}
   471 		break;
   472 
   473 	case ETestProcessSetUTCTimeAndOffset:
   474 		{
   475 		TTime time;
   476 		time.UniversalTime();
   477 		User::SetUTCTimeAndOffset(time,0);
   478 		}
   479 		break;
   480 
   481 	case ETestProcessSetMemoryThresholds:
   482 		{
   483 		return UserSvr::SetMemoryThresholds(0,KMaxTInt);
   484 		}
   485 
   486 	case ETestProcessTraceKallthreadssystem:
   487 		return TestThreadTraceKallthreadssystem(NULL);
   488 
   489 	case ETestProcessLocaleSet:
   490 		return TLocale().Set();
   491 
   492 	case ETestProcessUserSetCurrencySymbol:
   493 		return User::SetCurrencySymbol(TCurrencySymbol());
   494 
   495 	case ETestProcessChangeLocale:
   496 		return UserSvr::ChangeLocale(KNullDesC);
   497 
   498 	case ETestProcessSaveSystemSettings:
   499 		{
   500 		TExtendedLocale locale;
   501 		locale.LoadSystemSettings();
   502 		return locale.SaveSystemSettings();
   503 		}
   504 
   505 	case ETestProcessSetCurrencySymbol:
   506 		{
   507 		TExtendedLocale locale;
   508 		locale.LoadSystemSettings();
   509 		return locale.SetCurrencySymbol(TCurrencySymbol());
   510 		}
   511 
   512 	case ETestProcessAddEventESwitchOff:
   513 		{
   514 		TRawEvent event;
   515 		event.Set(TRawEvent::ESwitchOff);
   516 		return UserSvr::AddEvent(event);
   517 		}
   518 
   519 	case ETestProcessAddEventECaseOpen:
   520 		{
   521 		TRawEvent event;
   522 		event.Set(TRawEvent::ECaseOpen);
   523 		return UserSvr::AddEvent(event);
   524 		}
   525 
   526 	case ETestProcessAddEventECaseClose:
   527 		{
   528 		TRawEvent event;
   529 		event.Set(TRawEvent::ECaseClose);
   530 		return UserSvr::AddEvent(event);
   531 		}
   532 
   533 	default:
   534 		User::Panic(_L("T_SUSER"),1);
   535 		}
   536 
   537 	return KErrNone;
   538 	}
   539 
   540 
   541 
   542 void TestMachineConfiguration()
   543 	{
   544 	RTestProcess process;
   545 	TRequestStatus logonStatus;
   546 
   547 	test.Start(_L("Try getting machine-config without ECapabilityReadDeviceData"));
   548 	process.Create(~(1u<<ECapabilityReadDeviceData),ETestProcessMachineConfigGet);
   549 	process.Logon(logonStatus);
   550 	process.Resume();
   551 	User::WaitForRequest(logonStatus);
   552 	test(process.ExitType()==EExitPanic); // Process should have got a Platform Security panic
   553 	test(logonStatus==EPlatformSecurityTrap);
   554 	CLOSE_AND_WAIT(process);
   555 
   556 	test.Next(_L("Try setting machine-config without ECapabilityWriteDeviceData"));
   557 	process.Create(~(1u<<ECapabilityWriteDeviceData),ETestProcessMachineConfigSet);
   558 	process.Logon(logonStatus);
   559 	process.Resume();
   560 	User::WaitForRequest(logonStatus);
   561 	test(process.ExitType()==EExitPanic); // Process should have got a Platform Security panic
   562 	test(logonStatus==EPlatformSecurityTrap);
   563 	CLOSE_AND_WAIT(process);
   564 
   565 	test.Next(_L("Test getting machine-config with ECapabilityReadDeviceData"));
   566 	process.Create(1<<ECapabilityReadDeviceData,ETestProcessMachineConfigGet);
   567 	process.Logon(logonStatus);
   568 	process.Resume();
   569 	User::WaitForRequest(logonStatus);
   570 	test(process.ExitType()==EExitKill);
   571 	test(logonStatus==KErrNone);
   572 	CLOSE_AND_WAIT(process);
   573 
   574 	test.Next(_L("Test setting machine-conig with ECapabilityWriteDeviceData"));
   575 	process.Create((1<<ECapabilityWriteDeviceData)|(1<<ECapabilityReadDeviceData),ETestProcessMachineConfigSet);
   576 	process.Logon(logonStatus);
   577 	process.Resume();
   578 	User::WaitForRequest(logonStatus);
   579 	test(process.ExitType()==EExitKill);
   580 	test(logonStatus==KErrNone);
   581 	CLOSE_AND_WAIT(process);
   582 
   583 	test.End();
   584 	}
   585 
   586 
   587 	
   588 void TestSetCritical()
   589 	{
   590 	RTestProcess process;
   591 	TRequestStatus rendezvousStatus;
   592 	TRequestStatus logonStatus;
   593 
   594 	test.Start(_L("Test process critical thread exiting normally"));
   595 	process.Create(ETestProcessProcessCriticalNormalEnd);
   596 	process.Logon(logonStatus);
   597 	process.Rendezvous(rendezvousStatus);
   598 	process.Resume();
   599 	User::WaitForRequest(rendezvousStatus);
   600 	test(rendezvousStatus==KErrNone);
   601 	User::WaitForRequest(logonStatus);
   602 	test(process.ExitType()==EExitKill);
   603 	test(logonStatus==KErrNone);
   604 	CLOSE_AND_WAIT(process);
   605 
   606 	test.Next(_L("Test process critical thread being killed"));
   607 	process.Create(ETestProcessProcessCriticalKill);
   608 	process.Logon(logonStatus);
   609 	process.Rendezvous(rendezvousStatus);
   610 	process.Resume();
   611 	User::WaitForRequest(rendezvousStatus);
   612 	test(rendezvousStatus==KErrNone);
   613 	User::WaitForRequest(logonStatus);
   614 	test(process.ExitType()==EExitKill);
   615 	test(logonStatus==KErrNone); // Killed thread doesn't take down process
   616 	CLOSE_AND_WAIT(process);
   617 
   618 	test.Next(_L("Test process critical thread being terminated"));
   619 	process.Create(ETestProcessProcessCriticalTerminate);
   620 	process.Logon(logonStatus);
   621 	process.Rendezvous(rendezvousStatus);
   622 	process.Resume();
   623 	User::WaitForRequest(rendezvousStatus);
   624 	test(rendezvousStatus==KErrNone);
   625 	User::WaitForRequest(logonStatus);
   626 	test(process.ExitType()==EExitTerminate);
   627 	test(logonStatus==999);
   628 	CLOSE_AND_WAIT(process);
   629 
   630 	test.Next(_L("Test process critical thread being panicked"));
   631 	process.Create(ETestProcessProcessCriticalPanic);
   632 	process.Logon(logonStatus);
   633 	process.Rendezvous(rendezvousStatus);
   634 	process.Resume();
   635 	User::WaitForRequest(rendezvousStatus);
   636 	test(rendezvousStatus==KErrNone);
   637 	User::WaitForRequest(logonStatus);
   638 	test(process.ExitType()==EExitPanic);
   639 	test(logonStatus==999);
   640 	CLOSE_AND_WAIT(process);
   641 
   642 	test.Next(_L("Test all threads critical process with thread exiting normally"));
   643 	process.Create(ETestProcessAllThreadsCriticalNormalEnd);
   644 	process.Logon(logonStatus);
   645 	process.Rendezvous(rendezvousStatus);
   646 	process.Resume();
   647 	User::WaitForRequest(rendezvousStatus);
   648 	test(rendezvousStatus==KErrNone);
   649 	test(User::ProcessCritical(process) == User::EAllThreadsCritical);
   650 	User::WaitForRequest(logonStatus);
   651 	test(process.ExitType()==EExitKill);
   652 	test(logonStatus==KErrNone);
   653 	CLOSE_AND_WAIT(process);
   654 
   655 	test.Next(_L("Test all threads critical process with thread being killed"));
   656 	process.Create(ETestProcessAllThreadsCriticalKill);
   657 	process.Logon(logonStatus);
   658 	process.Rendezvous(rendezvousStatus);
   659 	process.Resume();
   660 	User::WaitForRequest(rendezvousStatus);
   661 	test(rendezvousStatus==KErrNone);
   662 	test(User::ProcessCritical(process) == User::EAllThreadsCritical);
   663 	User::WaitForRequest(logonStatus);
   664 	test(process.ExitType()==EExitKill);
   665 	test(logonStatus==KErrNone); // Killed thread doesn't take down process
   666 	CLOSE_AND_WAIT(process);
   667 
   668 	test.Next(_L("Test all threads critical process with thread being terminated"));
   669 	process.Create(ETestProcessAllThreadsCriticalTerminate);
   670 	process.Logon(logonStatus);
   671 	process.Rendezvous(rendezvousStatus);
   672 	process.Resume();
   673 	User::WaitForRequest(rendezvousStatus);
   674 	test(rendezvousStatus==KErrNone);
   675 	test(User::ProcessCritical(process) == User::EAllThreadsCritical);
   676 	User::WaitForRequest(logonStatus);
   677 	test(process.ExitType()==EExitTerminate);
   678 	test(logonStatus==999);
   679 	CLOSE_AND_WAIT(process);
   680 
   681 	test.Next(_L("Test all threads critical process with thread being panicked"));
   682 	process.Create(ETestProcessAllThreadsCriticalPanic);
   683 	process.Logon(logonStatus);
   684 	process.Rendezvous(rendezvousStatus);
   685 	process.Resume();
   686 	User::WaitForRequest(rendezvousStatus);
   687 	test(rendezvousStatus==KErrNone);
   688 	test(User::ProcessCritical(process) == User::EAllThreadsCritical);
   689 	User::WaitForRequest(logonStatus);
   690 	test.Printf(_L("Exit type == %d\n"), process.ExitType());
   691 	test(process.ExitType()==EExitPanic);
   692 	test(logonStatus==999);
   693 	CLOSE_AND_WAIT(process);
   694 
   695 	test.Next(_L("Try to setup a system critical thread without ECapabilityProtServ"));
   696 	process.Create(~(1u<<ECapabilityProtServ),ETestProcessSystemCritical);
   697 	process.Logon(logonStatus);
   698 	process.Rendezvous(rendezvousStatus);
   699 	process.Resume();
   700 	User::WaitForRequest(rendezvousStatus);
   701 	test(rendezvousStatus==EPlatformSecurityTrap);
   702 	User::WaitForRequest(logonStatus);
   703 	test(process.ExitType()==EExitPanic); // Process should have got a Platform Security panic
   704 	test(logonStatus==EPlatformSecurityTrap);
   705 	CLOSE_AND_WAIT(process);
   706 
   707 	test.Next(_L("Test setup of a system critical thread with ECapabilityProtServ"));
   708 	process.Create(1<<ECapabilityProtServ,ETestProcessSystemCritical);
   709 	process.Logon(logonStatus);
   710 	process.Rendezvous(rendezvousStatus);
   711 	process.Resume();
   712 	User::WaitForRequest(rendezvousStatus);
   713 	test(rendezvousStatus==KErrNone);
   714 	User::WaitForRequest(logonStatus);
   715 	test(logonStatus==KErrNone);
   716 	CLOSE_AND_WAIT(process);
   717 
   718 	test.Next(_L("Try to setup a system permanent thread without ECapabilityProtServ"));
   719 	process.Create(~(1u<<ECapabilityProtServ),ETestProcessSystemPermanent);
   720 	process.Logon(logonStatus);
   721 	process.Rendezvous(rendezvousStatus);
   722 	process.Resume();
   723 	User::WaitForRequest(rendezvousStatus);
   724 	test(rendezvousStatus==EPlatformSecurityTrap);
   725 	User::WaitForRequest(logonStatus);
   726 	test(process.ExitType()==EExitPanic); // Process should have got a Platform Security panic
   727 	test(logonStatus==EPlatformSecurityTrap);
   728 	CLOSE_AND_WAIT(process);
   729 
   730 	test.Next(_L("Test setup of a system permanent thread with ECapabilityProtServ"));
   731 	process.Create(1<<ECapabilityProtServ,ETestProcessSystemPermanent);
   732 	process.Logon(logonStatus);
   733 	process.Rendezvous(rendezvousStatus);
   734 	process.Resume();
   735 	User::WaitForRequest(rendezvousStatus);
   736 	test(rendezvousStatus==KErrNone);
   737 	User::WaitForRequest(logonStatus);
   738 	test(logonStatus==KErrNone);
   739 	CLOSE_AND_WAIT(process);
   740 
   741 	test.Next(_L("Try to setup a system critical process without ECapabilityProtServ"));
   742 	process.Create(~(1u<<ECapabilityProtServ),ETestProcessSystemProcessCritical);
   743 	process.Logon(logonStatus);
   744 	process.Rendezvous(rendezvousStatus);
   745 	process.Resume();
   746 	User::WaitForRequest(rendezvousStatus);
   747 	test(rendezvousStatus==EPlatformSecurityTrap);
   748 	test(User::ProcessCritical(process) == User::ENotCritical);
   749 	User::WaitForRequest(logonStatus);
   750 	test(process.ExitType()==EExitPanic); // Process should have got a Platform Security panic
   751 	test(logonStatus==EPlatformSecurityTrap);
   752 	CLOSE_AND_WAIT(process);
   753 
   754 	test.Next(_L("Test setup of a system critical process with ECapabilityProtServ"));
   755 	process.Create(1<<ECapabilityProtServ,ETestProcessSystemProcessCritical);
   756 	process.Logon(logonStatus);
   757 	process.Rendezvous(rendezvousStatus);
   758 	process.Resume();
   759 	User::WaitForRequest(rendezvousStatus);
   760 	test(rendezvousStatus==KErrNone);
   761 	test(User::ProcessCritical(process) == User::ESystemCritical);
   762 	SignalSlave();
   763 	User::WaitForRequest(logonStatus);
   764 	test(logonStatus==KErrNone);
   765 	CLOSE_AND_WAIT(process);
   766 
   767 	test.Next(_L("Try to setup a system permanent process without ECapabilityProtServ"));
   768 	process.Create(~(1u<<ECapabilityProtServ),ETestProcessSystemProcessPermanent);
   769 	process.Logon(logonStatus);
   770 	process.Rendezvous(rendezvousStatus);
   771 	process.Resume();
   772 	User::WaitForRequest(rendezvousStatus);
   773 	test(rendezvousStatus==EPlatformSecurityTrap);
   774 	test(User::ProcessCritical(process) == User::ENotCritical);
   775 	User::WaitForRequest(logonStatus);
   776 	test(process.ExitType()==EExitPanic); // Process should have got a Platform Security panic
   777 	test(logonStatus==EPlatformSecurityTrap);
   778 	CLOSE_AND_WAIT(process);
   779 
   780 	test.Next(_L("Test setup of a system permanent process with ECapabilityProtServ"));
   781 	process.Create(1<<ECapabilityProtServ,ETestProcessSystemProcessPermanent);
   782 	process.Logon(logonStatus);
   783 	process.Rendezvous(rendezvousStatus);
   784 	process.Resume();
   785 	User::WaitForRequest(rendezvousStatus);
   786 	test(rendezvousStatus==KErrNone);
   787 	test(User::ProcessCritical(process) == User::ESystemPermanent);
   788 	SignalSlave();
   789 	User::WaitForRequest(logonStatus);
   790 	test(logonStatus==KErrNone);
   791 	CLOSE_AND_WAIT(process);
   792 
   793 	test.Next(_L("Try to setup a trace bit KALLTHREADSSYSTEM process without ECapabilityProtServ"));
   794 	process.Create(~(1u<<ECapabilityProtServ),ETestProcessTraceKallthreadssystem);
   795 	process.Logon(logonStatus);
   796 	process.Rendezvous(rendezvousStatus);
   797 	process.Resume();
   798 	User::WaitForRequest(rendezvousStatus);
   799 	test(rendezvousStatus==EPlatformSecurityTrap);
   800 	User::WaitForRequest(logonStatus);
   801 	test(process.ExitType()==EExitPanic); // Process should have got a Platform Security panic
   802 	test(logonStatus==EPlatformSecurityTrap);
   803 	CLOSE_AND_WAIT(process);
   804 
   805 	test.Next(_L("Test setup of a trace bit KALLTHREADSSYSTEM process with ECapabilityProtServ"));
   806 	process.Create(1<<ECapabilityProtServ,ETestProcessTraceKallthreadssystem);
   807 	process.Logon(logonStatus);
   808 	process.Rendezvous(rendezvousStatus);
   809 	process.Resume();
   810 	User::WaitForRequest(rendezvousStatus);
   811 	test(rendezvousStatus==KErrNone);
   812 	User::WaitForRequest(logonStatus);
   813 	test(logonStatus==KErrNone);
   814 	CLOSE_AND_WAIT(process);
   815 
   816 	test.End();
   817 	}
   818 
   819 
   820 
   821 TUint KTestUid = 0x87654321;
   822 
   823 void SetAbsoluteTimeout(RTimer& aTimer, TUint aUs, TRequestStatus& aStatus)
   824 	{
   825 	TTime wakeup;
   826 	wakeup.HomeTime();
   827 	wakeup += TTimeIntervalMicroSeconds(aUs);
   828 	aTimer.At(aStatus, wakeup);
   829 	}
   830 
   831 void TestEvents()
   832 	{
   833 	RTestProcess process;
   834 	TRequestStatus logonStatus;
   835 
   836 	test.Start(_L("Try UserSvr::CaptureEventHook()"));
   837 	process.Create(~0u,ETestProcessCaptureEventHook);
   838 	process.Logon(logonStatus);
   839 	process.Resume();
   840 	User::WaitForRequest(logonStatus);
   841 	test(process.ExitType()==EExitPanic); // Process should have got a Platform Security panic
   842 	test(logonStatus==EPlatformSecurityTrap);
   843 	CLOSE_AND_WAIT(process);
   844 
   845 	test.Next(_L("Try UserSvr::ReleaseEventHook()"));
   846 	process.Create(~0u,ETestProcessReleaseEventHook);
   847 	process.Logon(logonStatus);
   848 	process.Resume();
   849 	User::WaitForRequest(logonStatus);
   850 	test(process.ExitType()==EExitPanic); // Process should have got a Platform Security panic
   851 	test(logonStatus==EEventNotCaptured);
   852 	CLOSE_AND_WAIT(process);
   853 
   854 	test.Next(_L("Try UserSvr::RequestEvent()"));
   855 	process.Create(~0u,ETestProcessRequestEvent);
   856 	process.Logon(logonStatus);
   857 	process.Resume();
   858 	User::WaitForRequest(logonStatus);
   859 	test(process.ExitType()==EExitPanic); // Process should have got a Platform Security panic
   860 	test(logonStatus==EEventNotCaptured);
   861 	CLOSE_AND_WAIT(process);
   862 
   863 	test.Next(_L("Try UserSvr::RequestEventCancel()"));
   864 	process.Create(~0u,ETestProcessRequestEventCancel);
   865 	process.Logon(logonStatus);
   866 	process.Resume();
   867 	User::WaitForRequest(logonStatus);
   868 	test(process.ExitType()==EExitPanic); // Process should have got a Platform Security panic
   869 	test(logonStatus==EEventNotCaptured);
   870 	CLOSE_AND_WAIT(process);
   871 
   872 	
   873 	
   874 	test.Next(_L("Try UserSvr::AddEvent(ECaseOpen) without ECapabilityPowerMgmt"));
   875 	process.Create(~(1u<<ECapabilityPowerMgmt),ETestProcessAddEventECaseOpen);
   876 	process.Logon(logonStatus);
   877 	process.Resume();
   878 	User::WaitForRequest(logonStatus);
   879 	test(process.ExitType()==EExitKill);
   880 	test(logonStatus==KErrPermissionDenied);
   881 	CLOSE_AND_WAIT(process);
   882 
   883 	test.Next(_L("Try UserSvr::AddEvent(ECaseOpen) without ECapabilitySwEvent"));
   884 	process.Create(~(1u<<ECapabilitySwEvent),ETestProcessAddEventECaseOpen);
   885 	process.Logon(logonStatus);
   886 	process.Resume();
   887 	User::WaitForRequest(logonStatus);
   888 	test(process.ExitType()==EExitKill);
   889 	test(logonStatus==KErrPermissionDenied);
   890 	CLOSE_AND_WAIT(process);
   891 
   892 	test.Next(_L("Calling UserSvr::AddEvent(ECaseOpen) with ECapabilityPowerMgmt & ECapabilitySwEvent"));
   893 	process.Create((1u<<ECapabilitySwEvent)|(1u<<ECapabilityPowerMgmt),ETestProcessAddEventECaseOpen);
   894 	process.Logon(logonStatus);
   895 	process.Resume();
   896 	User::WaitForRequest(logonStatus);
   897 	test(process.ExitType()==EExitKill);
   898 	test(logonStatus==KErrNone);
   899 	CLOSE_AND_WAIT(process);
   900 
   901 
   902 
   903 	test.Next(_L("Try UserSvr::AddEvent(ECaseClose) without ECapabilityPowerMgmt"));
   904 	process.Create(~(1u<<ECapabilityPowerMgmt),ETestProcessAddEventECaseClose);
   905 	process.Logon(logonStatus);
   906 	process.Resume();
   907 	User::WaitForRequest(logonStatus);
   908 	test(process.ExitType()==EExitKill);
   909 	test(logonStatus==KErrPermissionDenied);
   910 	CLOSE_AND_WAIT(process);
   911 
   912 	test.Next(_L("Try UserSvr::AddEvent(ECaseClose) without ECapabilitySwEvent"));
   913 	process.Create(~(1u<<ECapabilitySwEvent),ETestProcessAddEventECaseClose);
   914 	process.Logon(logonStatus);
   915 	process.Resume();
   916 	User::WaitForRequest(logonStatus);
   917 	test(process.ExitType()==EExitKill);
   918 	test(logonStatus==KErrPermissionDenied);
   919 	CLOSE_AND_WAIT(process);
   920 
   921 	test.Next(_L("Calling UserSvr::AddEvent(ECaseClose) with ECapabilityPowerMgmt & ECapabilitySwEvent"));
   922 	process.Create((1u<<ECapabilitySwEvent)|(1u<<ECapabilityPowerMgmt),ETestProcessAddEventECaseClose);
   923 	process.Logon(logonStatus);
   924 	process.Resume();
   925 	User::WaitForRequest(logonStatus);
   926 	test(process.ExitType()==EExitKill);
   927 	test(logonStatus==KErrNone);
   928 	CLOSE_AND_WAIT(process);
   929 
   930 
   931 	test.Next(_L("Try UserSvr::AddEvent(ESwitchOff) without ECapabilityPowerMgmt"));
   932 	process.Create(~(1u<<ECapabilityPowerMgmt),ETestProcessAddEventESwitchOff);
   933 	process.Logon(logonStatus);
   934 	process.Resume();
   935 	User::WaitForRequest(logonStatus);
   936 	test(process.ExitType()==EExitKill);
   937 	test(logonStatus==KErrPermissionDenied);
   938 	CLOSE_AND_WAIT(process);
   939 
   940 	test.Next(_L("Try UserSvr::AddEvent(ESwitchOff) without ECapabilitySwEvent"));
   941 	process.Create(~(1u<<ECapabilitySwEvent),ETestProcessAddEventESwitchOff);
   942 	process.Logon(logonStatus);
   943 	process.Resume();
   944 	User::WaitForRequest(logonStatus);
   945 	test(process.ExitType()==EExitKill);
   946 	test(logonStatus==KErrPermissionDenied);
   947 	CLOSE_AND_WAIT(process);
   948 
   949 	test.Next(_L("Calling UserSvr::AddEvent(ESwitchOff) with ECapabilityPowerMgmt & ECapabilitySwEvent"));
   950 	TRequestStatus absstatus;
   951 	RTimer abstimer;
   952 	TInt r = abstimer.CreateLocal();
   953 	test (r == KErrNone);
   954 	SetAbsoluteTimeout(abstimer, 5000000, absstatus); // 5 sec
   955 	process.Create((1u<<ECapabilitySwEvent)|(1u<<ECapabilityPowerMgmt),ETestProcessAddEventESwitchOff);
   956 	process.Logon(logonStatus);
   957 	process.Resume();
   958 	User::WaitForRequest(absstatus);
   959 	abstimer.Close();
   960 	User::WaitForRequest(logonStatus);
   961 	test(process.ExitType()==EExitKill);
   962 	test(logonStatus==KErrNone);
   963 	CLOSE_AND_WAIT(process);
   964 
   965 	test.End();
   966 	}
   967 
   968 
   969 const TInt KThreadCompleteOk = 0x80000002;
   970 TInt TestExceptionResult = KErrGeneral;
   971 
   972 void ExceptionHandler(TExcType /*aType*/)
   973 	{
   974 	TestExceptionResult = KErrNone;
   975 	}
   976 
   977 TInt TestExceptionThread(TAny* aArg)
   978 	{
   979 	TestExceptionResult = KErrGeneral;
   980 
   981 	User::SetExceptionHandler(ExceptionHandler,KExceptionAbort);
   982 
   983 	if(User::ExceptionHandler()!=ExceptionHandler)
   984 		return KErrGeneral;
   985 
   986 	if(User::IsExceptionHandled(EExcAbort))
   987 		User::ModifyExceptionMask(KExceptionAbort,0);
   988 
   989 	if(User::IsExceptionHandled(EExcAbort))
   990 		return KErrGeneral;
   991 
   992 	User::ModifyExceptionMask(0, KExceptionAbort);
   993 	if(!User::IsExceptionHandled((TExcType)EExcAbort))
   994 		return KErrGeneral;
   995 
   996 	if(User::RaiseException((TExcType)(TInt)aArg)!=KErrNone)
   997 		return KErrGeneral;
   998 
   999 	return KThreadCompleteOk;
  1000 	}
  1001 
  1002 void TestException()
  1003 	{
  1004 	RTestThread thread;
  1005 	TRequestStatus logonStatus;
  1006 
  1007 	test.Start(_L("Test handled exceptions"));
  1008 	thread.Create(TestExceptionThread,EExcAbort);
  1009 	thread.Logon(logonStatus);
  1010 	thread.Resume();
  1011 	User::WaitForRequest(logonStatus);
  1012 	test(logonStatus==KThreadCompleteOk);
  1013 	test(TestExceptionResult==KErrNone);
  1014 
  1015 	test.Next(_L("Test unhandled exceptions"));
  1016 	thread.Create(TestExceptionThread,EExcKill);
  1017 	thread.Logon(logonStatus);
  1018 	TInt jit = User::JustInTime();
  1019 	User::SetJustInTime(EFalse);
  1020 	thread.Resume();
  1021 	User::WaitForRequest(logonStatus);
  1022 	User::SetJustInTime(jit);
  1023 	test(logonStatus==ECausedException);
  1024 	test(TestExceptionResult==KErrGeneral);
  1025 
  1026 	test.End();
  1027 	}
  1028 
  1029 void TestSetHomeTime()
  1030 	{
  1031 	RTestProcess process;
  1032 	TRequestStatus logonStatus;
  1033 
  1034 	test.Start(_L("Try call without ECapabilityWriteDeviceData"));
  1035 	process.Create(~(1u<<ECapabilityWriteDeviceData),ETestProcessSetHomeTime,KTestUid);
  1036 	process.Logon(logonStatus);
  1037 	process.Resume();
  1038 	User::WaitForRequest(logonStatus);
  1039 	test(process.ExitType()==EExitPanic); // Process should have got a Platform Security panic
  1040 	test(logonStatus==EPlatformSecurityTrap);
  1041 	CLOSE_AND_WAIT(process);
  1042 
  1043 	test.Next(_L("Test call with ECapabilityWriteDeviceData"));
  1044 	process.Create(1<<ECapabilityWriteDeviceData,ETestProcessSetHomeTime,KTestUid);
  1045 	process.Logon(logonStatus);
  1046 	process.Resume();
  1047 	User::WaitForRequest(logonStatus);
  1048 	test(process.ExitType()==EExitKill);
  1049 	test(logonStatus==0);
  1050 	CLOSE_AND_WAIT(process);
  1051 
  1052 	test.End();
  1053 	}
  1054 
  1055 
  1056 
  1057 void TestSetUTCOffset()
  1058 	{
  1059 	RTestProcess process;
  1060 	TRequestStatus logonStatus;
  1061 
  1062 	test.Start(_L("Try call without ECapabilityWriteDeviceData"));
  1063 	process.Create(~(1u<<ECapabilityWriteDeviceData),ETestProcessSetUTCOffset,KTestUid);
  1064 	process.Logon(logonStatus);
  1065 	process.Resume();
  1066 	User::WaitForRequest(logonStatus);
  1067 	test(process.ExitType()==EExitPanic); // Process should have got a Platform Security panic
  1068 	test(logonStatus==EPlatformSecurityTrap);
  1069 	CLOSE_AND_WAIT(process);
  1070 
  1071 	test.Next(_L("Test call with ECapabilityWriteDeviceData"));
  1072 	process.Create(1<<ECapabilityWriteDeviceData,ETestProcessSetUTCOffset,KTestUid);
  1073 	process.Logon(logonStatus);
  1074 	process.Resume();
  1075 	User::WaitForRequest(logonStatus);
  1076 	test(process.ExitType()==EExitKill);
  1077 	test(logonStatus==0);
  1078 	CLOSE_AND_WAIT(process);
  1079 
  1080 	test.End();
  1081 	}
  1082 
  1083 
  1084 
  1085 void TestSetUTCTime()
  1086 	{
  1087 	RTestProcess process;
  1088 	TRequestStatus logonStatus;
  1089 
  1090 	test.Start(_L("Try call without ECapabilityWriteDeviceData"));
  1091 	process.Create(~(1u<<ECapabilityWriteDeviceData),ETestProcessSetUTCTime,KTestUid);
  1092 	process.Logon(logonStatus);
  1093 	process.Resume();
  1094 	User::WaitForRequest(logonStatus);
  1095 	test(process.ExitType()==EExitPanic); // Process should have got a Platform Security panic
  1096 	test(logonStatus==EPlatformSecurityTrap);
  1097 	CLOSE_AND_WAIT(process);
  1098 
  1099 	test.Next(_L("Test call with ECapabilityWriteDeviceData"));
  1100 	process.Create(1<<ECapabilityWriteDeviceData,ETestProcessSetUTCTime,KTestUid);
  1101 	process.Logon(logonStatus);
  1102 	process.Resume();
  1103 	User::WaitForRequest(logonStatus);
  1104 	test(process.ExitType()==EExitKill);
  1105 	test(logonStatus==0);
  1106 	CLOSE_AND_WAIT(process);
  1107 
  1108 	test.End();
  1109 	}
  1110 
  1111 
  1112 
  1113 void TestSetUTCTimeAndOffset()
  1114 	{
  1115 	RTestProcess process;
  1116 	TRequestStatus logonStatus;
  1117 
  1118 	test.Start(_L("Try call without ECapabilityWriteDeviceData"));
  1119 	process.Create(~(1u<<ECapabilityWriteDeviceData),ETestProcessSetUTCTimeAndOffset,KTestUid);
  1120 	process.Logon(logonStatus);
  1121 	process.Resume();
  1122 	User::WaitForRequest(logonStatus);
  1123 	test(process.ExitType()==EExitPanic); // Process should have got a Platform Security panic
  1124 	test(logonStatus==EPlatformSecurityTrap);
  1125 	CLOSE_AND_WAIT(process);
  1126 
  1127 	test.Next(_L("Test call with ECapabilityWriteDeviceData"));
  1128 	process.Create(1<<ECapabilityWriteDeviceData,ETestProcessSetUTCTimeAndOffset,KTestUid);
  1129 	process.Logon(logonStatus);
  1130 	process.Resume();
  1131 	User::WaitForRequest(logonStatus);
  1132 	test(process.ExitType()==EExitKill);
  1133 	test(logonStatus==0);
  1134 	CLOSE_AND_WAIT(process);
  1135 
  1136 	test.End();
  1137 	}
  1138 
  1139 
  1140 
  1141 void TestSetMemoryThresholds()
  1142 	{
  1143 	RTestProcess process;
  1144 	TRequestStatus logonStatus;
  1145 
  1146 	test.Start(_L("Try call without ECapabilityWriteDeviceData"));
  1147 	process.Create(~(1u<<ECapabilityWriteDeviceData),ETestProcessSetMemoryThresholds,KTestUid);
  1148 	process.Logon(logonStatus);
  1149 	process.Resume();
  1150 	User::WaitForRequest(logonStatus);
  1151 	test(process.ExitType()==EExitPanic); // Process should have got a Platform Security panic
  1152 	test(logonStatus==EPlatformSecurityTrap);
  1153 	CLOSE_AND_WAIT(process);
  1154 
  1155 	test.Next(_L("Test call with ECapabilityWriteDeviceData"));
  1156 	process.Create(1<<ECapabilityWriteDeviceData,ETestProcessSetMemoryThresholds,KTestUid);
  1157 	process.Logon(logonStatus);
  1158 	process.Resume();
  1159 	User::WaitForRequest(logonStatus);
  1160 	test(process.ExitType()==EExitKill);
  1161 	test(logonStatus==0);
  1162 	CLOSE_AND_WAIT(process);
  1163 
  1164 	test.End();
  1165 	}
  1166 
  1167 
  1168 
  1169 void TestWithWriteDeviceData(TTestProcessFunctions aFunction)
  1170 	{
  1171 	RTestProcess process;
  1172 	TRequestStatus logonStatus;
  1173 
  1174 	test.Start(_L("Try call without ECapabilityWriteDeviceData"));
  1175 	process.Create(~(1u<<ECapabilityWriteDeviceData),aFunction,KTestUid);
  1176 	process.Logon(logonStatus);
  1177 	process.Resume();
  1178 	User::WaitForRequest(logonStatus);
  1179 	test(process.ExitType()==EExitKill);
  1180 	test(logonStatus==KErrPermissionDenied);
  1181 	CLOSE_AND_WAIT(process);
  1182 
  1183 	test.Next(_L("Test call with ECapabilityWriteDeviceData"));
  1184 	process.Create(1<<ECapabilityWriteDeviceData,aFunction,KTestUid);
  1185 	process.Logon(logonStatus);
  1186 	process.Resume();
  1187 	User::WaitForRequest(logonStatus);
  1188 	test(process.ExitType()==EExitKill);
  1189 	test(logonStatus==0);
  1190 	CLOSE_AND_WAIT(process);
  1191 
  1192 	test.End();
  1193 	}
  1194 
  1195 
  1196 
  1197 GLDEF_C TInt E32Main()
  1198     {
  1199 	TBuf16<512> cmd;
  1200 	User::CommandLine(cmd);
  1201 	if(cmd.Length() && TChar(cmd[0]).IsDigit())
  1202 		{
  1203 		TInt function = -1;
  1204 		TInt arg1 = -1;
  1205 		TInt arg2 = -1;
  1206 		TLex lex(cmd);
  1207 
  1208 		lex.Val(function);
  1209 		lex.SkipSpace();
  1210 		lex.Val(arg1);
  1211 		lex.SkipSpace();
  1212 		lex.Val(arg2);
  1213 		return DoTestProcess(function,arg1,arg2);
  1214 		}
  1215 
  1216 	test.Title();
  1217 
  1218 	if(!PlatSec::ConfigSetting(PlatSec::EPlatSecEnforcement))
  1219 		{
  1220 		test.Start(_L("TESTS NOT RUN - EPlatSecEnforcement is OFF"));
  1221 		test.End();
  1222 		return 0;
  1223 		}
  1224 
  1225 	test_KErrNone(SyncSemaphore.CreateGlobal(KSyncSemaphoreName,0));
  1226 
  1227 	test.Start(_L("Test MachineConfiguration()"));
  1228 	TestMachineConfiguration();
  1229 
  1230 	test.Next(_L("Test SetCritical()"));
  1231 	TestSetCritical();
  1232 
  1233 	test.Next(_L("Test Set/PriorityControl()"));
  1234 	User::SetPriorityControl(ETrue);
  1235 	test(User::PriorityControl());
  1236 	User::SetPriorityControl(EFalse);
  1237 	test(!User::PriorityControl());
  1238 
  1239 	test.Next(_L("Test Event functions"));
  1240 	TestEvents();
  1241 
  1242 	test.Next(_L("Test Exception functions"));
  1243 	TestException();
  1244 
  1245 	test.Next(_L("Test SetHomeTime()"));
  1246 	TestSetHomeTime();
  1247 
  1248 	test.Next(_L("Test SetUTCOffset()"));
  1249 	TestSetUTCOffset();
  1250 
  1251 	test.Next(_L("Test SetUTCTime()"));
  1252 	TestSetUTCTime();
  1253 
  1254 	test.Next(_L("Test SetUTCTimeAndOffset()"));
  1255 	TestSetUTCTimeAndOffset();
  1256 
  1257 	test.Next(_L("Test SetMemoryThresholds"));
  1258 	TestSetMemoryThresholds();
  1259 
  1260 	test.Next(_L("Test Locale::Set"));
  1261 	TestWithWriteDeviceData(ETestProcessLocaleSet);
  1262 
  1263 	test.Next(_L("Test User::SetCurrencySymbol"));
  1264 	TestWithWriteDeviceData(ETestProcessUserSetCurrencySymbol);
  1265 
  1266 	test.Next(_L("Test UserSvr::ChangeLocale"));
  1267 	TestWithWriteDeviceData(ETestProcessChangeLocale);
  1268 
  1269 	test.Next(_L("Test TExtendedLocale::SaveSystemSettings"));
  1270 	TestWithWriteDeviceData(ETestProcessSaveSystemSettings);
  1271 
  1272 	test.Next(_L("Test TExtendedLocale::SetCurrencySymbol"));
  1273 	TestWithWriteDeviceData(ETestProcessSetCurrencySymbol);
  1274 
  1275 	SyncSemaphore.Close();
  1276 	test.End();
  1277 	return(0);
  1278     }
  1279