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