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