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