Update contrib.
1 // Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32test\secure\t_sthread.cpp
16 // Test the platform security aspects of the RThread class
20 // - Test renaming the current thread and renaming a thread from
21 // another thread. Verify results are as expected.
22 // - Test resuming a thread from a different process and from the
23 // process that created the thread. Verify results are as expected.
24 // - Verify that other processes can not suspend a thread and that the
25 // creating process can.
26 // - Perform a variety of tests on killing, terminating and panicking
27 // a thread. Verify results are as expected.
28 // - Test setting thread priority in a variety of ways, verify results
29 // are as expected. Includes ensuring real-time priorities are
30 // unavailable to processes without capability ProtServ.
31 // - Test RequestComplete and RequestSignal on a thread in a variety
32 // of ways, verify results are as expected.
33 // - Test SetProcessPriority on a thread in a variety of ways, verify
34 // results are as expected.
35 // - Test the Heap, ExceptionHandler, SetExceptionHandler,
36 // ModifyExceptionMask, RaiseException, IsExceptionHandled,
37 // SetProtected and SetSystem methods. Verify results as expected.
38 // Platforms/Drives/Compatibility:
40 // Assumptions/Requirement/Pre-requisites:
41 // Failures and causes:
42 // Base Port information:
48 LOCAL_D RTest test(_L("T_STHREAD"));
50 _LIT(KSyncMutex,"T_STHREAD-sync-mutex");
56 if(syncMutex.OpenGlobal(KSyncMutex)!=KErrNone)
63 enum TTestProcessFunctions
68 ETestProcessTerminate,
70 ETestProcessRequestComplete,
71 ETestProcessRequestSignal,
72 ETestProcessPriorityControlOff,
73 ETestProcessPriorityControlOn,
74 ETestProcessSetPriority,
75 ETestProcessSetPrioritiesWithoutProtServ,
76 ETestProcessSetPrioritiesWithProtServ
79 #include "testprocess.h"
81 _LIT(KTestPanicCategory,"TEST PANIC");
82 _LIT(KTestThreadName,"TestName");
85 class RTestThread : public RThread
88 void Create(TThreadFunction aFunction,TAny* aArg=0);
91 volatile TInt TestThreadCount = 0;
93 TInt TestThreadNull(TAny*)
100 void RTestThread::Create(TThreadFunction aFunction,TAny* aArg)
102 TInt r=RThread::Create(_L("TestThread"),aFunction,KDefaultStackSize,KDefaultStackSize,KDefaultStackSize,aArg);
107 // these priorities are available to any process
108 void TestSetNormalApplicationPriorities(RThread& aThread)
110 TThreadPriority priority = aThread.Priority(); // save priority to restore before return
111 aThread.SetPriority(EPriorityAbsoluteVeryLow);
112 test(aThread.Priority()==EPriorityAbsoluteVeryLow);
113 aThread.SetPriority(EPriorityAbsoluteLowNormal);
114 test(aThread.Priority()==EPriorityAbsoluteLowNormal);
115 aThread.SetPriority(EPriorityAbsoluteLow);
116 test(aThread.Priority()==EPriorityAbsoluteLow);
117 aThread.SetPriority(EPriorityAbsoluteBackgroundNormal);
118 test(aThread.Priority()==EPriorityAbsoluteBackgroundNormal);
119 aThread.SetPriority(EPriorityAbsoluteBackground);
120 test(aThread.Priority()==EPriorityAbsoluteBackground);
121 aThread.SetPriority(EPriorityAbsoluteForegroundNormal);
122 test(aThread.Priority()==EPriorityAbsoluteForegroundNormal);
123 aThread.SetPriority(EPriorityAbsoluteForeground);
124 test(aThread.Priority()==EPriorityAbsoluteForeground);
125 aThread.SetPriority(EPriorityAbsoluteHighNormal);
126 test(aThread.Priority()==EPriorityAbsoluteHighNormal);
127 aThread.SetPriority(EPriorityAbsoluteHigh);
128 test(aThread.Priority()==EPriorityAbsoluteHigh);
129 aThread.SetPriority(priority);
132 TInt TestThreadSetPriority(TAny* aArg)
135 thisThread.SetPriority((TThreadPriority)(reinterpret_cast<TInt>(aArg)));
139 void TestSetPriorityPanic(TThreadPriority aPriority)
142 TRequestStatus status;
143 thread.Create(TestThreadSetPriority, reinterpret_cast<TAny*>(aPriority));
144 thread.Logon(status);
146 User::WaitForRequest(status);
147 test(thread.ExitType()==EExitPanic);
148 test(thread.ExitCategory()==_L("KERN-EXEC"));
149 test(thread.ExitReason()==46);
150 CLOSE_AND_WAIT(thread);
153 void TestSetPrioritySuccess(TThreadPriority aPriority)
156 TRequestStatus status;
157 thread.Create(TestThreadSetPriority, reinterpret_cast<TAny*>(aPriority));
158 thread.Logon(status);
160 User::WaitForRequest(status);
161 test(thread.Priority()==aPriority);
162 test(thread.ExitCategory()==_L("Kill"));
163 test(thread.ExitReason()==0);
164 CLOSE_AND_WAIT(thread);
167 TInt DoTestProcess(TInt aTestNum,TInt aArg1,TInt aArg2)
175 case ETestProcessResume:
177 r = thread.Open(aArg1);
179 thread.Resume(); // Should panic us
183 case ETestProcessSuspend:
185 r = thread.Open(aArg1);
187 thread.Suspend(); // Should panic us
191 case ETestProcessKill:
193 r = thread.Open(aArg1);
195 thread.Kill(999); // Should panic us
199 case ETestProcessTerminate:
201 r = thread.Open(aArg1);
203 thread.Terminate(999); // Should panic us
207 case ETestProcessPanic:
209 r = thread.Open(aArg1);
211 thread.Panic(KTestPanicCategory,999); // Should panic us
215 case ETestProcessSetPriority:
217 r = thread.Open(aArg1);
219 thread.SetPriority((TThreadPriority)aArg2);
223 case ETestProcessRequestComplete:
225 r = thread.Open(aArg1);
228 // use a local request status because Thread::RequestComplete is
229 // implemented to write to it in our context
230 TRequestStatus myStatus;
231 TRequestStatus* status = &myStatus;
232 thread.RequestComplete(status,KErrNone);
237 case ETestProcessRequestSignal:
239 r = thread.Open(aArg1);
241 thread.RequestSignal();
245 case ETestProcessPriorityControlOn:
246 User::SetPriorityControl(ETrue);
248 case ETestProcessPriorityControlOff:
249 RProcess::Rendezvous(RThread().Id());
253 case ETestProcessSetPrioritiesWithoutProtServ:
256 TestSetNormalApplicationPriorities(thread);
257 TestSetPriorityPanic(EPriorityAbsoluteRealTime1);
258 TestSetPriorityPanic(EPriorityAbsoluteRealTime2);
259 TestSetPriorityPanic(EPriorityAbsoluteRealTime3);
260 TestSetPriorityPanic(EPriorityAbsoluteRealTime4);
261 TestSetPriorityPanic(EPriorityAbsoluteRealTime5);
262 TestSetPriorityPanic(EPriorityAbsoluteRealTime6);
263 TestSetPriorityPanic(EPriorityAbsoluteRealTime7);
264 TestSetPriorityPanic(EPriorityAbsoluteRealTime8);
268 case ETestProcessSetPrioritiesWithProtServ:
271 TestSetNormalApplicationPriorities(thread);
272 TestSetPrioritySuccess(EPriorityAbsoluteRealTime1);
273 TestSetPrioritySuccess(EPriorityAbsoluteRealTime2);
274 TestSetPrioritySuccess(EPriorityAbsoluteRealTime3);
275 TestSetPrioritySuccess(EPriorityAbsoluteRealTime4);
276 TestSetPrioritySuccess(EPriorityAbsoluteRealTime5);
277 TestSetPrioritySuccess(EPriorityAbsoluteRealTime6);
278 TestSetPrioritySuccess(EPriorityAbsoluteRealTime7);
279 TestSetPrioritySuccess(EPriorityAbsoluteRealTime8);
284 User::Panic(_L("T_STHREAD"),1);
292 void TestThreadForPlatformSecurityTrap(TThreadFunction aFunction)
294 TBool jit = User::JustInTime();
295 TRequestStatus logonStatus;
297 thread.Create(aFunction,(TAny*)(TUint)RThread().Id());
298 thread.Logon(logonStatus);
299 User::SetJustInTime(EFalse);
301 User::WaitForRequest(logonStatus);
302 User::SetJustInTime(jit);
303 test(thread.ExitType()==EExitPanic);
304 test(logonStatus==EPlatformSecurityTrap);
305 CLOSE_AND_WAIT(thread);
309 void TestProcessForPlatformSecurityTrap(TTestProcessFunctions aFunction)
311 TRequestStatus logonStatus2;
312 RTestProcess process;
313 process.Create(~0u,aFunction,RThread().Id(),EPriorityAbsoluteLow);
314 process.Logon(logonStatus2);
316 User::WaitForRequest(logonStatus2);
317 test(process.ExitType()==EExitPanic); // Process should have got a Platform Security panic
318 test(logonStatus2==EPlatformSecurityTrap);
319 CLOSE_AND_WAIT(process);
327 test.Start(_L("Renaming the current thread"));
328 name = RThread().Name();
329 name.SetLength(KTestThreadName().Length());
330 test(name.CompareF(KTestThreadName)!=0);
331 User::RenameThread(KTestThreadName);
332 name = RThread().Name();
333 name.SetLength(KTestThreadName().Length());
334 test(name.CompareF(KTestThreadName)==0);
344 RTestProcess process;
346 TRequestStatus logonStatus;
347 TInt testCount = TestThreadCount;
349 test.Start(_L("Try to get another process to resume one we've created"));
350 thread.Create(TestThreadNull);
351 process.Create(~0u,ETestProcessResume,thread.Id());
352 process.Logon(logonStatus);
354 User::WaitForRequest(logonStatus);
355 test(process.ExitType()==EExitPanic); // Process should have got a Platform Security panic
356 test(logonStatus==EPlatformSecurityTrap);
357 User::After(1000000); // Give time for thread to run (if it had been resumed)...
358 test(TestThreadCount==testCount); // it shouldn't have, so count will be unchanged.
360 test.Next(_L("Test resuming a thread we've created"));
361 thread.Logon(logonStatus);
362 test(logonStatus==KRequestPending);
364 User::WaitForRequest(logonStatus);
365 test(logonStatus==KErrNone);
366 test(TestThreadCount==testCount+1); // Thread should have run and incremented the count
367 CLOSE_AND_WAIT(thread);
368 CLOSE_AND_WAIT(process);
375 TInt TestThreadCounting(TAny*)
377 RThread().SetPriority(EPriorityAbsoluteVeryLow);
382 TBool IsTestThreadRunning()
384 // Thread should have been busy incrementing the count if it is running
385 TInt testCount = TestThreadCount;
387 if(testCount!=TestThreadCount)
389 User::After(1000000);
390 return testCount!=TestThreadCount;
395 RTestProcess process;
397 TRequestStatus logonStatus;
399 test.Start(_L("Creating a never ending thread..."));
400 thread.Create(TestThreadCounting);
402 test(IsTestThreadRunning()); // Thread should still be running
404 test.Next(_L("Checking other process can't supspend it"));
405 process.Create(~0u,ETestProcessSuspend,thread.Id());
406 process.Logon(logonStatus);
408 User::WaitForRequest(logonStatus);
409 test(process.ExitType()==EExitPanic); // Process should have got a Platform Security panic
410 test(logonStatus==EPlatformSecurityTrap);
411 test(IsTestThreadRunning()); // Thread should still be running
413 test.Next(_L("Test suspending a thread in same process"));
414 thread.Logon(logonStatus);
416 test(!IsTestThreadRunning()); // Thread should have stopped...
417 test(logonStatus==KRequestPending); // but not have died
418 thread.LogonCancel(logonStatus);
419 User::WaitForRequest(logonStatus);
421 test.Next(_L("Kill thread"));
423 CLOSE_AND_WAIT(thread);
424 CLOSE_AND_WAIT(process);
431 TInt TestThreadKillSelf(TAny* )
437 TInt TestThreadTerminateSelf(TAny*)
439 RThread().Terminate(999);
443 TInt TestThreadPanicSelf(TAny*)
445 RThread().Panic(KTestPanicCategory,999);
451 RTestProcess process;
453 TRequestStatus logonStatus;
454 TRequestStatus logonStatus2;
455 TBool jit = User::JustInTime();
457 // Test RProcess::Kill()
459 test.Start(_L("Test killing an un-resumed thread created by us"));
460 thread.Create(TestThreadNull);
461 thread.Logon(logonStatus);
463 User::WaitForRequest(logonStatus);
464 test(thread.ExitType()==EExitKill);
465 test(logonStatus==999);
466 CLOSE_AND_WAIT(thread);
468 test.Next(_L("Test killing a resumed thread created by us"));
469 thread.Create(TestThreadNull);
470 thread.Logon(logonStatus);
475 User::WaitForRequest(logonStatus);
476 test(thread.ExitType()==EExitKill);
477 test(logonStatus==999);
478 CLOSE_AND_WAIT(thread);
480 test.Next(_L("Try killing un-resumed thread not created by self"));
481 thread.Create(TestThreadNull);
482 process.Create(~0u,ETestProcessKill,thread.Id());
483 thread.Logon(logonStatus2);
484 process.Logon(logonStatus);
486 User::WaitForRequest(logonStatus);
487 test(process.ExitType()==EExitPanic); // Process should have got a Platform Security panic
488 test(logonStatus==EPlatformSecurityTrap);
489 test(logonStatus2==KRequestPending); // the thread should still be alive
491 User::WaitForRequest(logonStatus2);
492 test(logonStatus2==KErrNone);
493 CLOSE_AND_WAIT(thread);
494 CLOSE_AND_WAIT(process);
496 test.Next(_L("Try killing resumed thread not created by self"));
497 thread.Create(TestThreadNull);
498 process.Create(~0u,ETestProcessKill,thread.Id());
499 thread.Logon(logonStatus2);
500 process.Logon(logonStatus);
504 User::WaitForRequest(logonStatus);
505 test(process.ExitType()==EExitPanic); // Process should have got a Platform Security panic
506 test(logonStatus==EPlatformSecurityTrap);
507 test(logonStatus2==KRequestPending); // the thread should still be alive
509 User::WaitForRequest(logonStatus2);
510 test(logonStatus2==KErrNone);
511 CLOSE_AND_WAIT(thread);
512 CLOSE_AND_WAIT(process);
514 test.Next(_L("Test a thread killing itself"));
515 thread.Create(TestThreadKillSelf);
516 thread.Logon(logonStatus);
518 User::WaitForRequest(logonStatus);
519 test(thread.ExitType()==EExitKill);
520 test(logonStatus==999);
521 CLOSE_AND_WAIT(thread);
523 // Test RProcess::Teminate()
525 test.Next(_L("Test terminating an un-resumed thread created by us"));
526 thread.Create(TestThreadNull);
527 thread.Logon(logonStatus);
528 thread.Terminate(999);
529 User::WaitForRequest(logonStatus);
530 test(thread.ExitType()==EExitTerminate);
531 test(logonStatus==999);
532 CLOSE_AND_WAIT(thread);
534 test.Next(_L("Test terminating a resumed thread created by us"));
535 thread.Create(TestThreadNull);
536 thread.Logon(logonStatus);
539 thread.Terminate(999);
541 User::WaitForRequest(logonStatus);
542 test(thread.ExitType()==EExitTerminate);
543 test(logonStatus==999);
544 CLOSE_AND_WAIT(thread);
546 test.Next(_L("Try terminating un-resumed thread not created by self"));
547 thread.Create(TestThreadNull);
548 process.Create(~0u,ETestProcessTerminate,thread.Id());
549 thread.Logon(logonStatus2);
550 process.Logon(logonStatus);
552 User::WaitForRequest(logonStatus);
553 test(process.ExitType()==EExitPanic); // Process should have got a Platform Security panic
554 test(logonStatus==EPlatformSecurityTrap);
555 test(logonStatus2==KRequestPending); // the thread should still be alive
557 User::WaitForRequest(logonStatus2);
558 test(logonStatus2==KErrNone);
559 CLOSE_AND_WAIT(thread);
560 CLOSE_AND_WAIT(process);
562 test.Next(_L("Try terminating resumed thread not created by self"));
563 thread.Create(TestThreadNull);
564 process.Create(~0u,ETestProcessTerminate,thread.Id());
565 thread.Logon(logonStatus2);
566 process.Logon(logonStatus);
570 User::WaitForRequest(logonStatus);
571 test(process.ExitType()==EExitPanic); // Process should have got a Platform Security panic
572 test(logonStatus==EPlatformSecurityTrap);
573 test(logonStatus2==KRequestPending); // the thread should still be alive
575 User::WaitForRequest(logonStatus2);
576 test(logonStatus2==KErrNone);
577 CLOSE_AND_WAIT(thread);
578 CLOSE_AND_WAIT(process);
580 test.Next(_L("Test a thread terminating itself"));
581 thread.Create(TestThreadTerminateSelf);
582 thread.Logon(logonStatus);
584 User::WaitForRequest(logonStatus);
585 test(thread.ExitType()==EExitTerminate);
586 test(logonStatus==999);
587 CLOSE_AND_WAIT(thread);
589 // Test RProcess::Panic()
591 test.Next(_L("Test panicking an un-resumed thread created by us"));
592 thread.Create(TestThreadNull);
593 thread.Logon(logonStatus);
594 User::SetJustInTime(EFalse);
595 thread.Panic(KTestPanicCategory,999);
596 User::WaitForRequest(logonStatus);
597 User::SetJustInTime(jit);
598 test(thread.ExitType()==EExitPanic);
599 test(logonStatus==999);
600 CLOSE_AND_WAIT(thread);
602 test.Next(_L("Test panicking a resumed thread created by us"));
603 thread.Create(TestThreadNull);
604 thread.Logon(logonStatus);
607 User::SetJustInTime(EFalse);
608 thread.Panic(KTestPanicCategory,999);
610 User::WaitForRequest(logonStatus);
611 User::SetJustInTime(jit);
612 test(thread.ExitType()==EExitPanic);
613 test(logonStatus==999);
614 CLOSE_AND_WAIT(thread);
616 test.Next(_L("Try panicking un-resumed thread not created by self"));
617 thread.Create(TestThreadNull);
618 process.Create(~0u,ETestProcessPanic,thread.Id());
619 thread.Logon(logonStatus2);
620 process.Logon(logonStatus);
622 User::WaitForRequest(logonStatus);
623 test(process.ExitType()==EExitPanic); // Process should have got a Platform Security panic
624 test(logonStatus==EPlatformSecurityTrap);
625 test(logonStatus2==KRequestPending); // the thread should still be alive
627 User::WaitForRequest(logonStatus2);
628 test(logonStatus2==KErrNone);
629 CLOSE_AND_WAIT(thread);
630 CLOSE_AND_WAIT(process);
632 test.Next(_L("Try panicking resumed thread not created by self"));
633 thread.Create(TestThreadNull);
634 process.Create(~0u,ETestProcessPanic,thread.Id());
635 thread.Logon(logonStatus2);
636 process.Logon(logonStatus);
640 User::WaitForRequest(logonStatus);
641 test(process.ExitType()==EExitPanic); // Process should have got a Platform Security panic
642 test(logonStatus==EPlatformSecurityTrap);
643 test(logonStatus2==KRequestPending); // the thread should still be alive
645 User::WaitForRequest(logonStatus2);
646 test(logonStatus2==KErrNone);
647 CLOSE_AND_WAIT(thread);
648 CLOSE_AND_WAIT(process);
650 test.Next(_L("Test a thread panicking itself"));
651 thread.Create(TestThreadPanicSelf);
652 thread.Logon(logonStatus);
653 User::SetJustInTime(EFalse);
655 User::WaitForRequest(logonStatus);
656 User::SetJustInTime(jit);
657 test(thread.ExitType()==EExitPanic);
658 test(logonStatus==999);
659 CLOSE_AND_WAIT(thread);
667 //---------------------------------------------
668 //! @SYMTestCaseID KBASE-T_STHREAD-0120
669 //! @SYMTestCaseDesc Set thread priority
671 //! @SYMREQ historical, enhanced under PREQ955
672 //! @SYMTestActions Test setting all thread priority values to threads in this process,
673 //! and in another process, resumed and not.
674 //! @SYMTestExpectedResults Confirm can set and get "normal application" thread priorities
675 //! for threads in this process, whether resumed or not. Confirm thread is panicked
676 //! if attempts to set priority of thread in another process. Confirm can set and get
677 //! "real-time" thread priorities if this process has ProtServ capability, and that
678 //! calling thread is panicked if not.
679 //! @SYMTestPriority Critical
680 //! @SYMTestStatus Implemented
681 //---------------------------------------------
682 void TestSetPriority()
685 RTestProcess process;
686 TRequestStatus logonStatus;
687 TRequestStatus logonStatus2;
689 test.Start(_L("Test changing our own threads priority"));
690 TestSetNormalApplicationPriorities(thread);
692 test.Next(_L("Test changing priority of un-resumed thread in our process"));
693 thread.Create(TestThreadNull);
694 thread.Logon(logonStatus);
695 TestSetNormalApplicationPriorities(thread);
697 test.Next(_L("Test changing priority of resumed thread in our process"));
700 TestSetNormalApplicationPriorities(thread);
702 User::WaitForRequest(logonStatus);
703 test(logonStatus==KErrNone);
704 CLOSE_AND_WAIT(thread);
706 test.Next(_L("Try changing priority of an un-resumed thread in other process"));
707 thread.Create(TestThreadNull);
708 thread.Logon(logonStatus);
709 thread.SetPriority(EPriorityAbsoluteHigh);
710 process.Create(~0u,ETestProcessSetPriority,thread.Id(),EPriorityAbsoluteLow);
711 process.Logon(logonStatus2);
713 User::WaitForRequest(logonStatus2);
714 test(process.ExitType()==EExitPanic); // Process should have got a Platform Security panic
715 test(logonStatus2==EPlatformSecurityTrap);
716 test(thread.Priority()==EPriorityAbsoluteHigh); // Priority should be unaltered
718 test.Next(_L("Try changing priority of a resumed thread in other process"));
719 process.Create(~0u,ETestProcessSetPriority,thread.Id(),EPriorityAbsoluteLow);
720 process.Logon(logonStatus2);
724 User::WaitForRequest(logonStatus2);
725 test(process.ExitType()==EExitPanic); // Process should have got a Platform Security panic
726 test(logonStatus2==EPlatformSecurityTrap);
727 test(thread.Priority()==EPriorityAbsoluteHigh); // Priority should be unaltered
729 User::WaitForRequest(logonStatus);
730 test(logonStatus==KErrNone);
731 CLOSE_AND_WAIT(thread);
733 test.Next(_L("Test setting thread priorities without ECapabilityProtServ"));
734 process.Create(~(1u<<ECapabilityProtServ), ETestProcessSetPrioritiesWithoutProtServ);
737 test.Next(_L("Test setting thread priorities with ECapabilityProtServ"));
738 process.Create(1<<ECapabilityProtServ, ETestProcessSetPrioritiesWithProtServ);
745 TRequestStatus TestRequest;
747 TInt TestThreadRequestComplete(TAny* aArg)
750 TInt r = thread.Open((TInt)aArg);
753 TRequestStatus* status = &TestRequest;
754 thread.RequestComplete(status,KErrNone);
759 void TestRequestComplete()
762 RTestProcess process;
763 TRequestStatus logonStatus;
765 test.Start(_L("Test RequestComplete on thread in current process"));
766 TestRequest = KRequestPending;
767 thread.Create(TestThreadRequestComplete,(TAny*)(TUint)RThread().Id());
768 thread.Logon(logonStatus);
770 User::WaitForRequest(TestRequest);
771 test(TestRequest==KErrNone);
772 User::WaitForRequest(logonStatus);
773 test(logonStatus==KErrNone);
774 CLOSE_AND_WAIT(thread);
776 test.Next(_L("Test RequestComplete on with NULL request pointer"));
777 test(RThread().RequestCount()==0); // No signals
778 TRequestStatus* nullReq = 0;
779 RThread().RequestComplete(nullReq,0);
780 test(RThread().RequestCount()==0); // No signals
782 test.Next(_L("Test RequestComplete on thread in different process"));
783 TestRequest = KRequestPending;
784 process.Create(~0u,ETestProcessRequestComplete,RThread().Id(),(TInt)&TestRequest);
785 process.Logon(logonStatus);
787 User::WaitForRequest(logonStatus);
788 test(process.ExitType()==EExitPanic); // Process should have got a Platform Security panic
789 test(logonStatus==EPlatformSecurityTrap);
790 test(TestRequest==KRequestPending);
791 CLOSE_AND_WAIT(process);
798 TInt TestThreadRequestSignal(TAny* aArg)
801 TInt r = thread.Open((TInt)aArg);
803 thread.RequestSignal();
807 void TestRequestSignal()
810 RTestProcess process;
811 TRequestStatus logonStatus;
814 test.Start(_L("Test RequestSignal on thread in current process"));
815 thread.Create(TestThreadRequestSignal,(TAny*)(TUint)RThread().Id());
816 thread.Logon(logonStatus);
817 count = RThread().RequestCount();
818 test(count==0); // No signals yet
820 User::WaitForRequest(logonStatus);
821 test(logonStatus==KErrNone);
822 count = RThread().RequestCount();
823 test(count==1); // We should have been signalled
824 User::WaitForAnyRequest(); // eat signal
825 CLOSE_AND_WAIT(thread);
827 test.Next(_L("Test RequestSignal on thread in different process"));
828 process.Create(~0u,ETestProcessRequestSignal,RThread().Id(),0);
829 process.Logon(logonStatus);
831 User::WaitForRequest(logonStatus);
832 test(process.ExitType()==EExitPanic); // Process should have got a Platform Security panic
833 test(logonStatus==EPlatformSecurityTrap);
834 count = RThread().RequestCount();
835 test(count==0); // We shouldn't have been signalled
836 CLOSE_AND_WAIT(process);
843 void TestSetProcessPriority()
846 RTestProcess process;
847 TProcessPriority priority;
848 TRequestStatus rendezvousStatus;
849 TRequestStatus logonStatus;
852 test.Start(_L("Test changing our own process priority"));
853 priority = process.Priority();
854 thread.SetProcessPriority(EPriorityLow);
855 test(process.Priority()==EPriorityLow);
856 thread.SetProcessPriority(EPriorityBackground);
857 test(process.Priority()==EPriorityBackground);
858 thread.SetProcessPriority(EPriorityForeground);
859 test(process.Priority()==EPriorityForeground);
860 thread.SetProcessPriority(priority);
862 test.Next(_L("Try changing other process's priority (no priority-control enabled)"));
863 process.Create(~0u,ETestProcessPriorityControlOff);
864 process.Rendezvous(rendezvousStatus);
865 process.Logon(logonStatus);
868 User::WaitForRequest(rendezvousStatus); // Process has started
869 r = thread.Open(rendezvousStatus.Int()); // Process returned Id of main thread as status value
871 priority = process.Priority();
872 thread.SetProcessPriority(EPriorityLow);
873 test(process.Priority()==priority); // priority shouldn't have changed
874 thread.SetProcessPriority(EPriorityBackground);
875 test(process.Priority()==priority); // priority shouldn't have changed
876 thread.SetProcessPriority(EPriorityForeground);
877 test(process.Priority()==priority); // priority shouldn't have changed
878 test(logonStatus==KRequestPending); // wait for process to end
880 User::WaitForRequest(logonStatus);
881 CLOSE_AND_WAIT(thread);
882 CLOSE_AND_WAIT(process);
884 test.Next(_L("Try changing other process's priority (priority-control enabled)"));
885 process.Create(~0u,ETestProcessPriorityControlOn);
886 process.Rendezvous(rendezvousStatus);
887 process.Logon(logonStatus);
890 User::WaitForRequest(rendezvousStatus); // Process has started
891 r = thread.Open(rendezvousStatus.Int()); // Process returned Id of main thread as status value
893 priority = process.Priority();
894 thread.SetProcessPriority(EPriorityForeground);
895 test(process.Priority()==EPriorityForeground);
896 thread.SetProcessPriority(EPriorityBackground);
897 test(process.Priority()==EPriorityBackground);
898 thread.SetProcessPriority(EPriorityForeground);
899 test(process.Priority()==EPriorityForeground);
900 thread.SetProcessPriority(EPriorityLow);
901 test(process.Priority()==EPriorityForeground); // should still be foreground priority
902 thread.SetProcessPriority(priority);
903 test(logonStatus==KRequestPending); // wait for process to end
905 User::WaitForRequest(logonStatus);
906 CLOSE_AND_WAIT(thread);
907 CLOSE_AND_WAIT(process);
914 GLDEF_C TInt E32Main()
917 User::CommandLine(cmd);
918 if(cmd.Length() && TChar(cmd[0]).IsDigit())
930 return DoTestProcess(function,arg1,arg2);
935 if((!PlatSec::ConfigSetting(PlatSec::EPlatSecProcessIsolation))||(!PlatSec::ConfigSetting(PlatSec::EPlatSecEnforcement)))
937 test.Start(_L("TESTS NOT RUN - PlatSecProcessIsolation is not enforced"));
942 test(SyncMutex.CreateGlobal(KSyncMutex)==KErrNone);
944 test.Start(_L("Test Rename"));
947 test.Next(_L("Test Resume"));
950 test.Next(_L("Test Suspend"));
953 test.Next(_L("Test Kill, Panic and Teminate"));
956 test.Next(_L("Test SetPriority"));
959 test.Next(_L("Test RequestComplete"));
960 TestRequestComplete();
962 test.Next(_L("Test RequestSignal"));
965 test.Next(_L("Test SetProcessPriority"));
966 TestSetProcessPriority();