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