sl@0: // Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // e32test\secure\t_sthread.cpp sl@0: // Overview: sl@0: // Test the platform security aspects of the RThread class sl@0: // API Information: sl@0: // RThread sl@0: // Details: sl@0: // - Test renaming the current thread and renaming a thread from sl@0: // another thread. Verify results are as expected. sl@0: // - Test resuming a thread from a different process and from the sl@0: // process that created the thread. Verify results are as expected. sl@0: // - Verify that other processes can not suspend a thread and that the sl@0: // creating process can. sl@0: // - Perform a variety of tests on killing, terminating and panicking sl@0: // a thread. Verify results are as expected. sl@0: // - Test setting thread priority in a variety of ways, verify results sl@0: // are as expected. Includes ensuring real-time priorities are sl@0: // unavailable to processes without capability ProtServ. sl@0: // - Test RequestComplete and RequestSignal on a thread in a variety sl@0: // of ways, verify results are as expected. sl@0: // - Test SetProcessPriority on a thread in a variety of ways, verify sl@0: // results are as expected. sl@0: // - Test the Heap, ExceptionHandler, SetExceptionHandler, sl@0: // ModifyExceptionMask, RaiseException, IsExceptionHandled, sl@0: // SetProtected and SetSystem methods. Verify results as expected. sl@0: // Platforms/Drives/Compatibility: sl@0: // All. sl@0: // Assumptions/Requirement/Pre-requisites: sl@0: // Failures and causes: sl@0: // Base Port information: sl@0: // sl@0: // sl@0: sl@0: #include sl@0: sl@0: LOCAL_D RTest test(_L("T_STHREAD")); sl@0: sl@0: _LIT(KSyncMutex,"T_STHREAD-sync-mutex"); sl@0: RMutex SyncMutex; sl@0: sl@0: void Wait() sl@0: { sl@0: RMutex syncMutex; sl@0: if(syncMutex.OpenGlobal(KSyncMutex)!=KErrNone) sl@0: User::Invariant(); sl@0: syncMutex.Wait(); sl@0: syncMutex.Signal(); sl@0: syncMutex.Close(); sl@0: } sl@0: sl@0: enum TTestProcessFunctions sl@0: { sl@0: ETestProcessResume, sl@0: ETestProcessSuspend, sl@0: ETestProcessKill, sl@0: ETestProcessTerminate, sl@0: ETestProcessPanic, sl@0: ETestProcessRequestComplete, sl@0: ETestProcessRequestSignal, sl@0: ETestProcessPriorityControlOff, sl@0: ETestProcessPriorityControlOn, sl@0: ETestProcessSetPriority, sl@0: ETestProcessSetPrioritiesWithoutProtServ, sl@0: ETestProcessSetPrioritiesWithProtServ sl@0: }; sl@0: sl@0: #include "testprocess.h" sl@0: sl@0: _LIT(KTestPanicCategory,"TEST PANIC"); sl@0: _LIT(KTestThreadName,"TestName"); sl@0: sl@0: sl@0: class RTestThread : public RThread sl@0: { sl@0: public: sl@0: void Create(TThreadFunction aFunction,TAny* aArg=0); sl@0: }; sl@0: sl@0: volatile TInt TestThreadCount = 0; sl@0: sl@0: TInt TestThreadNull(TAny*) sl@0: { sl@0: ++TestThreadCount; sl@0: Wait(); sl@0: return KErrNone; sl@0: } sl@0: sl@0: void RTestThread::Create(TThreadFunction aFunction,TAny* aArg) sl@0: { sl@0: TInt r=RThread::Create(_L("TestThread"),aFunction,KDefaultStackSize,KDefaultStackSize,KDefaultStackSize,aArg); sl@0: test(r==KErrNone); sl@0: } sl@0: sl@0: sl@0: // these priorities are available to any process sl@0: void TestSetNormalApplicationPriorities(RThread& aThread) sl@0: { sl@0: TThreadPriority priority = aThread.Priority(); // save priority to restore before return sl@0: aThread.SetPriority(EPriorityAbsoluteVeryLow); sl@0: test(aThread.Priority()==EPriorityAbsoluteVeryLow); sl@0: aThread.SetPriority(EPriorityAbsoluteLowNormal); sl@0: test(aThread.Priority()==EPriorityAbsoluteLowNormal); sl@0: aThread.SetPriority(EPriorityAbsoluteLow); sl@0: test(aThread.Priority()==EPriorityAbsoluteLow); sl@0: aThread.SetPriority(EPriorityAbsoluteBackgroundNormal); sl@0: test(aThread.Priority()==EPriorityAbsoluteBackgroundNormal); sl@0: aThread.SetPriority(EPriorityAbsoluteBackground); sl@0: test(aThread.Priority()==EPriorityAbsoluteBackground); sl@0: aThread.SetPriority(EPriorityAbsoluteForegroundNormal); sl@0: test(aThread.Priority()==EPriorityAbsoluteForegroundNormal); sl@0: aThread.SetPriority(EPriorityAbsoluteForeground); sl@0: test(aThread.Priority()==EPriorityAbsoluteForeground); sl@0: aThread.SetPriority(EPriorityAbsoluteHighNormal); sl@0: test(aThread.Priority()==EPriorityAbsoluteHighNormal); sl@0: aThread.SetPriority(EPriorityAbsoluteHigh); sl@0: test(aThread.Priority()==EPriorityAbsoluteHigh); sl@0: aThread.SetPriority(priority); sl@0: } sl@0: sl@0: TInt TestThreadSetPriority(TAny* aArg) sl@0: { sl@0: RThread thisThread; sl@0: thisThread.SetPriority((TThreadPriority)(reinterpret_cast(aArg))); sl@0: return KErrNone; sl@0: } sl@0: sl@0: void TestSetPriorityPanic(TThreadPriority aPriority) sl@0: { sl@0: RTestThread thread; sl@0: TRequestStatus status; sl@0: thread.Create(TestThreadSetPriority, reinterpret_cast(aPriority)); sl@0: thread.Logon(status); sl@0: thread.Resume(); sl@0: User::WaitForRequest(status); sl@0: test(thread.ExitType()==EExitPanic); sl@0: test(thread.ExitCategory()==_L("KERN-EXEC")); sl@0: test(thread.ExitReason()==46); sl@0: CLOSE_AND_WAIT(thread); sl@0: } sl@0: sl@0: void TestSetPrioritySuccess(TThreadPriority aPriority) sl@0: { sl@0: RTestThread thread; sl@0: TRequestStatus status; sl@0: thread.Create(TestThreadSetPriority, reinterpret_cast(aPriority)); sl@0: thread.Logon(status); sl@0: thread.Resume(); sl@0: User::WaitForRequest(status); sl@0: test(thread.Priority()==aPriority); sl@0: test(thread.ExitCategory()==_L("Kill")); sl@0: test(thread.ExitReason()==0); sl@0: CLOSE_AND_WAIT(thread); sl@0: } sl@0: sl@0: TInt DoTestProcess(TInt aTestNum,TInt aArg1,TInt aArg2) sl@0: { sl@0: RThread thread; sl@0: TInt r; sl@0: sl@0: switch(aTestNum) sl@0: { sl@0: sl@0: case ETestProcessResume: sl@0: { sl@0: r = thread.Open(aArg1); sl@0: if(r==KErrNone) sl@0: thread.Resume(); // Should panic us sl@0: return r; sl@0: } sl@0: sl@0: case ETestProcessSuspend: sl@0: { sl@0: r = thread.Open(aArg1); sl@0: if(r==KErrNone) sl@0: thread.Suspend(); // Should panic us sl@0: return r; sl@0: } sl@0: sl@0: case ETestProcessKill: sl@0: { sl@0: r = thread.Open(aArg1); sl@0: if(r==KErrNone) sl@0: thread.Kill(999); // Should panic us sl@0: return r; sl@0: } sl@0: sl@0: case ETestProcessTerminate: sl@0: { sl@0: r = thread.Open(aArg1); sl@0: if(r==KErrNone) sl@0: thread.Terminate(999); // Should panic us sl@0: return r; sl@0: } sl@0: sl@0: case ETestProcessPanic: sl@0: { sl@0: r = thread.Open(aArg1); sl@0: if(r==KErrNone) sl@0: thread.Panic(KTestPanicCategory,999); // Should panic us sl@0: return r; sl@0: } sl@0: sl@0: case ETestProcessSetPriority: sl@0: { sl@0: r = thread.Open(aArg1); sl@0: if(r==KErrNone) sl@0: thread.SetPriority((TThreadPriority)aArg2); sl@0: return r; sl@0: } sl@0: sl@0: case ETestProcessRequestComplete: sl@0: { sl@0: r = thread.Open(aArg1); sl@0: if(r==KErrNone) sl@0: { sl@0: // use a local request status because Thread::RequestComplete is sl@0: // implemented to write to it in our context sl@0: TRequestStatus myStatus; sl@0: TRequestStatus* status = &myStatus; sl@0: thread.RequestComplete(status,KErrNone); sl@0: } sl@0: return r; sl@0: } sl@0: sl@0: case ETestProcessRequestSignal: sl@0: { sl@0: r = thread.Open(aArg1); sl@0: if(r==KErrNone) sl@0: thread.RequestSignal(); sl@0: return r; sl@0: } sl@0: sl@0: case ETestProcessPriorityControlOn: sl@0: User::SetPriorityControl(ETrue); sl@0: // fall through... sl@0: case ETestProcessPriorityControlOff: sl@0: RProcess::Rendezvous(RThread().Id()); sl@0: Wait(); sl@0: return KErrNone; sl@0: sl@0: case ETestProcessSetPrioritiesWithoutProtServ: sl@0: { sl@0: RThread thread; sl@0: TestSetNormalApplicationPriorities(thread); sl@0: TestSetPriorityPanic(EPriorityAbsoluteRealTime1); sl@0: TestSetPriorityPanic(EPriorityAbsoluteRealTime2); sl@0: TestSetPriorityPanic(EPriorityAbsoluteRealTime3); sl@0: TestSetPriorityPanic(EPriorityAbsoluteRealTime4); sl@0: TestSetPriorityPanic(EPriorityAbsoluteRealTime5); sl@0: TestSetPriorityPanic(EPriorityAbsoluteRealTime6); sl@0: TestSetPriorityPanic(EPriorityAbsoluteRealTime7); sl@0: TestSetPriorityPanic(EPriorityAbsoluteRealTime8); sl@0: return KErrNone; sl@0: } sl@0: sl@0: case ETestProcessSetPrioritiesWithProtServ: sl@0: { sl@0: RThread thread; sl@0: TestSetNormalApplicationPriorities(thread); sl@0: TestSetPrioritySuccess(EPriorityAbsoluteRealTime1); sl@0: TestSetPrioritySuccess(EPriorityAbsoluteRealTime2); sl@0: TestSetPrioritySuccess(EPriorityAbsoluteRealTime3); sl@0: TestSetPrioritySuccess(EPriorityAbsoluteRealTime4); sl@0: TestSetPrioritySuccess(EPriorityAbsoluteRealTime5); sl@0: TestSetPrioritySuccess(EPriorityAbsoluteRealTime6); sl@0: TestSetPrioritySuccess(EPriorityAbsoluteRealTime7); sl@0: TestSetPrioritySuccess(EPriorityAbsoluteRealTime8); sl@0: return KErrNone; sl@0: } sl@0: sl@0: default: sl@0: User::Panic(_L("T_STHREAD"),1); sl@0: } sl@0: sl@0: return KErrNone; sl@0: } sl@0: sl@0: sl@0: sl@0: void TestThreadForPlatformSecurityTrap(TThreadFunction aFunction) sl@0: { sl@0: TBool jit = User::JustInTime(); sl@0: TRequestStatus logonStatus; sl@0: RTestThread thread; sl@0: thread.Create(aFunction,(TAny*)(TUint)RThread().Id()); sl@0: thread.Logon(logonStatus); sl@0: User::SetJustInTime(EFalse); sl@0: thread.Resume(); sl@0: User::WaitForRequest(logonStatus); sl@0: User::SetJustInTime(jit); sl@0: test(thread.ExitType()==EExitPanic); sl@0: test(logonStatus==EPlatformSecurityTrap); sl@0: CLOSE_AND_WAIT(thread); sl@0: } sl@0: sl@0: sl@0: void TestProcessForPlatformSecurityTrap(TTestProcessFunctions aFunction) sl@0: { sl@0: TRequestStatus logonStatus2; sl@0: RTestProcess process; sl@0: process.Create(~0u,aFunction,RThread().Id(),EPriorityAbsoluteLow); sl@0: process.Logon(logonStatus2); sl@0: process.Resume(); sl@0: User::WaitForRequest(logonStatus2); sl@0: test(process.ExitType()==EExitPanic); // Process should have got a Platform Security panic sl@0: test(logonStatus2==EPlatformSecurityTrap); sl@0: CLOSE_AND_WAIT(process); sl@0: } sl@0: sl@0: sl@0: void TestRename() sl@0: { sl@0: TName name; sl@0: sl@0: test.Start(_L("Renaming the current thread")); sl@0: name = RThread().Name(); sl@0: name.SetLength(KTestThreadName().Length()); sl@0: test(name.CompareF(KTestThreadName)!=0); sl@0: User::RenameThread(KTestThreadName); sl@0: name = RThread().Name(); sl@0: name.SetLength(KTestThreadName().Length()); sl@0: test(name.CompareF(KTestThreadName)==0); sl@0: sl@0: sl@0: test.End(); sl@0: } sl@0: sl@0: sl@0: sl@0: void TestResume() sl@0: { sl@0: RTestProcess process; sl@0: RTestThread thread; sl@0: TRequestStatus logonStatus; sl@0: TInt testCount = TestThreadCount; sl@0: sl@0: test.Start(_L("Try to get another process to resume one we've created")); sl@0: thread.Create(TestThreadNull); sl@0: process.Create(~0u,ETestProcessResume,thread.Id()); sl@0: process.Logon(logonStatus); sl@0: process.Resume(); sl@0: User::WaitForRequest(logonStatus); sl@0: test(process.ExitType()==EExitPanic); // Process should have got a Platform Security panic sl@0: test(logonStatus==EPlatformSecurityTrap); sl@0: User::After(1000000); // Give time for thread to run (if it had been resumed)... sl@0: test(TestThreadCount==testCount); // it shouldn't have, so count will be unchanged. sl@0: sl@0: test.Next(_L("Test resuming a thread we've created")); sl@0: thread.Logon(logonStatus); sl@0: test(logonStatus==KRequestPending); sl@0: thread.Resume(); sl@0: User::WaitForRequest(logonStatus); sl@0: test(logonStatus==KErrNone); sl@0: test(TestThreadCount==testCount+1); // Thread should have run and incremented the count sl@0: CLOSE_AND_WAIT(thread); sl@0: CLOSE_AND_WAIT(process); sl@0: sl@0: test.End(); sl@0: } sl@0: sl@0: sl@0: sl@0: TInt TestThreadCounting(TAny*) sl@0: { sl@0: RThread().SetPriority(EPriorityAbsoluteVeryLow); sl@0: for(;;) sl@0: ++TestThreadCount; sl@0: } sl@0: sl@0: TBool IsTestThreadRunning() sl@0: { sl@0: // Thread should have been busy incrementing the count if it is running sl@0: TInt testCount = TestThreadCount; sl@0: User::After(100000); sl@0: if(testCount!=TestThreadCount) sl@0: return ETrue; sl@0: User::After(1000000); sl@0: return testCount!=TestThreadCount; sl@0: } sl@0: sl@0: void TestSuspend() sl@0: { sl@0: RTestProcess process; sl@0: RTestThread thread; sl@0: TRequestStatus logonStatus; sl@0: sl@0: test.Start(_L("Creating a never ending thread...")); sl@0: thread.Create(TestThreadCounting); sl@0: thread.Resume(); sl@0: test(IsTestThreadRunning()); // Thread should still be running sl@0: sl@0: test.Next(_L("Checking other process can't supspend it")); sl@0: process.Create(~0u,ETestProcessSuspend,thread.Id()); sl@0: process.Logon(logonStatus); sl@0: process.Resume(); sl@0: User::WaitForRequest(logonStatus); sl@0: test(process.ExitType()==EExitPanic); // Process should have got a Platform Security panic sl@0: test(logonStatus==EPlatformSecurityTrap); sl@0: test(IsTestThreadRunning()); // Thread should still be running sl@0: sl@0: test.Next(_L("Test suspending a thread in same process")); sl@0: thread.Logon(logonStatus); sl@0: thread.Suspend(); sl@0: test(!IsTestThreadRunning()); // Thread should have stopped... sl@0: test(logonStatus==KRequestPending); // but not have died sl@0: thread.LogonCancel(logonStatus); sl@0: User::WaitForRequest(logonStatus); sl@0: sl@0: test.Next(_L("Kill thread")); sl@0: thread.Kill(0); sl@0: CLOSE_AND_WAIT(thread); sl@0: CLOSE_AND_WAIT(process); sl@0: sl@0: test.End(); sl@0: } sl@0: sl@0: sl@0: sl@0: TInt TestThreadKillSelf(TAny* ) sl@0: { sl@0: RThread().Kill(999); sl@0: return KErrGeneral; sl@0: } sl@0: sl@0: TInt TestThreadTerminateSelf(TAny*) sl@0: { sl@0: RThread().Terminate(999); sl@0: return KErrGeneral; sl@0: } sl@0: sl@0: TInt TestThreadPanicSelf(TAny*) sl@0: { sl@0: RThread().Panic(KTestPanicCategory,999); sl@0: return KErrGeneral; sl@0: } sl@0: sl@0: void TestKill() sl@0: { sl@0: RTestProcess process; sl@0: RTestThread thread; sl@0: TRequestStatus logonStatus; sl@0: TRequestStatus logonStatus2; sl@0: TBool jit = User::JustInTime(); sl@0: sl@0: // Test RProcess::Kill() sl@0: sl@0: test.Start(_L("Test killing an un-resumed thread created by us")); sl@0: thread.Create(TestThreadNull); sl@0: thread.Logon(logonStatus); sl@0: thread.Kill(999); sl@0: User::WaitForRequest(logonStatus); sl@0: test(thread.ExitType()==EExitKill); sl@0: test(logonStatus==999); sl@0: CLOSE_AND_WAIT(thread); sl@0: sl@0: test.Next(_L("Test killing a resumed thread created by us")); sl@0: thread.Create(TestThreadNull); sl@0: thread.Logon(logonStatus); sl@0: SyncMutex.Wait(); sl@0: thread.Resume(); sl@0: thread.Kill(999); sl@0: SyncMutex.Signal(); sl@0: User::WaitForRequest(logonStatus); sl@0: test(thread.ExitType()==EExitKill); sl@0: test(logonStatus==999); sl@0: CLOSE_AND_WAIT(thread); sl@0: sl@0: test.Next(_L("Try killing un-resumed thread not created by self")); sl@0: thread.Create(TestThreadNull); sl@0: process.Create(~0u,ETestProcessKill,thread.Id()); sl@0: thread.Logon(logonStatus2); sl@0: process.Logon(logonStatus); sl@0: process.Resume(); sl@0: User::WaitForRequest(logonStatus); sl@0: test(process.ExitType()==EExitPanic); // Process should have got a Platform Security panic sl@0: test(logonStatus==EPlatformSecurityTrap); sl@0: test(logonStatus2==KRequestPending); // the thread should still be alive sl@0: thread.Resume(); sl@0: User::WaitForRequest(logonStatus2); sl@0: test(logonStatus2==KErrNone); sl@0: CLOSE_AND_WAIT(thread); sl@0: CLOSE_AND_WAIT(process); sl@0: sl@0: test.Next(_L("Try killing resumed thread not created by self")); sl@0: thread.Create(TestThreadNull); sl@0: process.Create(~0u,ETestProcessKill,thread.Id()); sl@0: thread.Logon(logonStatus2); sl@0: process.Logon(logonStatus); sl@0: SyncMutex.Wait(); sl@0: thread.Resume(); sl@0: process.Resume(); sl@0: User::WaitForRequest(logonStatus); sl@0: test(process.ExitType()==EExitPanic); // Process should have got a Platform Security panic sl@0: test(logonStatus==EPlatformSecurityTrap); sl@0: test(logonStatus2==KRequestPending); // the thread should still be alive sl@0: SyncMutex.Signal(); sl@0: User::WaitForRequest(logonStatus2); sl@0: test(logonStatus2==KErrNone); sl@0: CLOSE_AND_WAIT(thread); sl@0: CLOSE_AND_WAIT(process); sl@0: sl@0: test.Next(_L("Test a thread killing itself")); sl@0: thread.Create(TestThreadKillSelf); sl@0: thread.Logon(logonStatus); sl@0: thread.Resume(); sl@0: User::WaitForRequest(logonStatus); sl@0: test(thread.ExitType()==EExitKill); sl@0: test(logonStatus==999); sl@0: CLOSE_AND_WAIT(thread); sl@0: sl@0: // Test RProcess::Teminate() sl@0: sl@0: test.Next(_L("Test terminating an un-resumed thread created by us")); sl@0: thread.Create(TestThreadNull); sl@0: thread.Logon(logonStatus); sl@0: thread.Terminate(999); sl@0: User::WaitForRequest(logonStatus); sl@0: test(thread.ExitType()==EExitTerminate); sl@0: test(logonStatus==999); sl@0: CLOSE_AND_WAIT(thread); sl@0: sl@0: test.Next(_L("Test terminating a resumed thread created by us")); sl@0: thread.Create(TestThreadNull); sl@0: thread.Logon(logonStatus); sl@0: SyncMutex.Wait(); sl@0: thread.Resume(); sl@0: thread.Terminate(999); sl@0: SyncMutex.Signal(); sl@0: User::WaitForRequest(logonStatus); sl@0: test(thread.ExitType()==EExitTerminate); sl@0: test(logonStatus==999); sl@0: CLOSE_AND_WAIT(thread); sl@0: sl@0: test.Next(_L("Try terminating un-resumed thread not created by self")); sl@0: thread.Create(TestThreadNull); sl@0: process.Create(~0u,ETestProcessTerminate,thread.Id()); sl@0: thread.Logon(logonStatus2); sl@0: process.Logon(logonStatus); sl@0: process.Resume(); sl@0: User::WaitForRequest(logonStatus); sl@0: test(process.ExitType()==EExitPanic); // Process should have got a Platform Security panic sl@0: test(logonStatus==EPlatformSecurityTrap); sl@0: test(logonStatus2==KRequestPending); // the thread should still be alive sl@0: thread.Resume(); sl@0: User::WaitForRequest(logonStatus2); sl@0: test(logonStatus2==KErrNone); sl@0: CLOSE_AND_WAIT(thread); sl@0: CLOSE_AND_WAIT(process); sl@0: sl@0: test.Next(_L("Try terminating resumed thread not created by self")); sl@0: thread.Create(TestThreadNull); sl@0: process.Create(~0u,ETestProcessTerminate,thread.Id()); sl@0: thread.Logon(logonStatus2); sl@0: process.Logon(logonStatus); sl@0: SyncMutex.Wait(); sl@0: thread.Resume(); sl@0: process.Resume(); sl@0: User::WaitForRequest(logonStatus); sl@0: test(process.ExitType()==EExitPanic); // Process should have got a Platform Security panic sl@0: test(logonStatus==EPlatformSecurityTrap); sl@0: test(logonStatus2==KRequestPending); // the thread should still be alive sl@0: SyncMutex.Signal(); sl@0: User::WaitForRequest(logonStatus2); sl@0: test(logonStatus2==KErrNone); sl@0: CLOSE_AND_WAIT(thread); sl@0: CLOSE_AND_WAIT(process); sl@0: sl@0: test.Next(_L("Test a thread terminating itself")); sl@0: thread.Create(TestThreadTerminateSelf); sl@0: thread.Logon(logonStatus); sl@0: thread.Resume(); sl@0: User::WaitForRequest(logonStatus); sl@0: test(thread.ExitType()==EExitTerminate); sl@0: test(logonStatus==999); sl@0: CLOSE_AND_WAIT(thread); sl@0: sl@0: // Test RProcess::Panic() sl@0: sl@0: test.Next(_L("Test panicking an un-resumed thread created by us")); sl@0: thread.Create(TestThreadNull); sl@0: thread.Logon(logonStatus); sl@0: User::SetJustInTime(EFalse); sl@0: thread.Panic(KTestPanicCategory,999); sl@0: User::WaitForRequest(logonStatus); sl@0: User::SetJustInTime(jit); sl@0: test(thread.ExitType()==EExitPanic); sl@0: test(logonStatus==999); sl@0: CLOSE_AND_WAIT(thread); sl@0: sl@0: test.Next(_L("Test panicking a resumed thread created by us")); sl@0: thread.Create(TestThreadNull); sl@0: thread.Logon(logonStatus); sl@0: SyncMutex.Wait(); sl@0: thread.Resume(); sl@0: User::SetJustInTime(EFalse); sl@0: thread.Panic(KTestPanicCategory,999); sl@0: SyncMutex.Signal(); sl@0: User::WaitForRequest(logonStatus); sl@0: User::SetJustInTime(jit); sl@0: test(thread.ExitType()==EExitPanic); sl@0: test(logonStatus==999); sl@0: CLOSE_AND_WAIT(thread); sl@0: sl@0: test.Next(_L("Try panicking un-resumed thread not created by self")); sl@0: thread.Create(TestThreadNull); sl@0: process.Create(~0u,ETestProcessPanic,thread.Id()); sl@0: thread.Logon(logonStatus2); sl@0: process.Logon(logonStatus); sl@0: process.Resume(); sl@0: User::WaitForRequest(logonStatus); sl@0: test(process.ExitType()==EExitPanic); // Process should have got a Platform Security panic sl@0: test(logonStatus==EPlatformSecurityTrap); sl@0: test(logonStatus2==KRequestPending); // the thread should still be alive sl@0: thread.Resume(); sl@0: User::WaitForRequest(logonStatus2); sl@0: test(logonStatus2==KErrNone); sl@0: CLOSE_AND_WAIT(thread); sl@0: CLOSE_AND_WAIT(process); sl@0: sl@0: test.Next(_L("Try panicking resumed thread not created by self")); sl@0: thread.Create(TestThreadNull); sl@0: process.Create(~0u,ETestProcessPanic,thread.Id()); sl@0: thread.Logon(logonStatus2); sl@0: process.Logon(logonStatus); sl@0: SyncMutex.Wait(); sl@0: thread.Resume(); sl@0: process.Resume(); sl@0: User::WaitForRequest(logonStatus); sl@0: test(process.ExitType()==EExitPanic); // Process should have got a Platform Security panic sl@0: test(logonStatus==EPlatformSecurityTrap); sl@0: test(logonStatus2==KRequestPending); // the thread should still be alive sl@0: SyncMutex.Signal(); sl@0: User::WaitForRequest(logonStatus2); sl@0: test(logonStatus2==KErrNone); sl@0: CLOSE_AND_WAIT(thread); sl@0: CLOSE_AND_WAIT(process); sl@0: sl@0: test.Next(_L("Test a thread panicking itself")); sl@0: thread.Create(TestThreadPanicSelf); sl@0: thread.Logon(logonStatus); sl@0: User::SetJustInTime(EFalse); sl@0: thread.Resume(); sl@0: User::WaitForRequest(logonStatus); sl@0: User::SetJustInTime(jit); sl@0: test(thread.ExitType()==EExitPanic); sl@0: test(logonStatus==999); sl@0: CLOSE_AND_WAIT(thread); sl@0: sl@0: // sl@0: sl@0: test.End(); sl@0: } sl@0: sl@0: sl@0: //--------------------------------------------- sl@0: //! @SYMTestCaseID KBASE-T_STHREAD-0120 sl@0: //! @SYMTestCaseDesc Set thread priority sl@0: //! @SYMTestType UT sl@0: //! @SYMREQ historical, enhanced under PREQ955 sl@0: //! @SYMTestActions Test setting all thread priority values to threads in this process, sl@0: //! and in another process, resumed and not. sl@0: //! @SYMTestExpectedResults Confirm can set and get "normal application" thread priorities sl@0: //! for threads in this process, whether resumed or not. Confirm thread is panicked sl@0: //! if attempts to set priority of thread in another process. Confirm can set and get sl@0: //! "real-time" thread priorities if this process has ProtServ capability, and that sl@0: //! calling thread is panicked if not. sl@0: //! @SYMTestPriority Critical sl@0: //! @SYMTestStatus Implemented sl@0: //--------------------------------------------- sl@0: void TestSetPriority() sl@0: { sl@0: RTestThread thread; sl@0: RTestProcess process; sl@0: TRequestStatus logonStatus; sl@0: TRequestStatus logonStatus2; sl@0: sl@0: test.Start(_L("Test changing our own threads priority")); sl@0: TestSetNormalApplicationPriorities(thread); sl@0: sl@0: test.Next(_L("Test changing priority of un-resumed thread in our process")); sl@0: thread.Create(TestThreadNull); sl@0: thread.Logon(logonStatus); sl@0: TestSetNormalApplicationPriorities(thread); sl@0: sl@0: test.Next(_L("Test changing priority of resumed thread in our process")); sl@0: SyncMutex.Wait(); sl@0: thread.Resume(); sl@0: TestSetNormalApplicationPriorities(thread); sl@0: SyncMutex.Signal(); sl@0: User::WaitForRequest(logonStatus); sl@0: test(logonStatus==KErrNone); sl@0: CLOSE_AND_WAIT(thread); sl@0: sl@0: test.Next(_L("Try changing priority of an un-resumed thread in other process")); sl@0: thread.Create(TestThreadNull); sl@0: thread.Logon(logonStatus); sl@0: thread.SetPriority(EPriorityAbsoluteHigh); sl@0: process.Create(~0u,ETestProcessSetPriority,thread.Id(),EPriorityAbsoluteLow); sl@0: process.Logon(logonStatus2); sl@0: process.Resume(); sl@0: User::WaitForRequest(logonStatus2); sl@0: test(process.ExitType()==EExitPanic); // Process should have got a Platform Security panic sl@0: test(logonStatus2==EPlatformSecurityTrap); sl@0: test(thread.Priority()==EPriorityAbsoluteHigh); // Priority should be unaltered sl@0: sl@0: test.Next(_L("Try changing priority of a resumed thread in other process")); sl@0: process.Create(~0u,ETestProcessSetPriority,thread.Id(),EPriorityAbsoluteLow); sl@0: process.Logon(logonStatus2); sl@0: SyncMutex.Wait(); sl@0: thread.Resume(); sl@0: process.Resume(); sl@0: User::WaitForRequest(logonStatus2); sl@0: test(process.ExitType()==EExitPanic); // Process should have got a Platform Security panic sl@0: test(logonStatus2==EPlatformSecurityTrap); sl@0: test(thread.Priority()==EPriorityAbsoluteHigh); // Priority should be unaltered sl@0: SyncMutex.Signal(); sl@0: User::WaitForRequest(logonStatus); sl@0: test(logonStatus==KErrNone); sl@0: CLOSE_AND_WAIT(thread); sl@0: sl@0: test.Next(_L("Test setting thread priorities without ECapabilityProtServ")); sl@0: process.Create(~(1u< cmd; sl@0: User::CommandLine(cmd); sl@0: if(cmd.Length() && TChar(cmd[0]).IsDigit()) sl@0: { sl@0: TInt function = -1; sl@0: TInt arg1 = -1; sl@0: TInt arg2 = -1; sl@0: TLex lex(cmd); sl@0: sl@0: lex.Val(function); sl@0: lex.SkipSpace(); sl@0: lex.Val(arg1); sl@0: lex.SkipSpace(); sl@0: lex.Val(arg2); sl@0: return DoTestProcess(function,arg1,arg2); sl@0: } sl@0: sl@0: test.Title(); sl@0: sl@0: if((!PlatSec::ConfigSetting(PlatSec::EPlatSecProcessIsolation))||(!PlatSec::ConfigSetting(PlatSec::EPlatSecEnforcement))) sl@0: { sl@0: test.Start(_L("TESTS NOT RUN - PlatSecProcessIsolation is not enforced")); sl@0: test.End(); sl@0: return 0; sl@0: } sl@0: sl@0: test(SyncMutex.CreateGlobal(KSyncMutex)==KErrNone); sl@0: sl@0: test.Start(_L("Test Rename")); sl@0: TestRename(); sl@0: sl@0: test.Next(_L("Test Resume")); sl@0: TestResume(); sl@0: sl@0: test.Next(_L("Test Suspend")); sl@0: TestSuspend(); sl@0: sl@0: test.Next(_L("Test Kill, Panic and Teminate")); sl@0: TestKill(); sl@0: sl@0: test.Next(_L("Test SetPriority")); sl@0: TestSetPriority(); sl@0: sl@0: test.Next(_L("Test RequestComplete")); sl@0: TestRequestComplete(); sl@0: sl@0: test.Next(_L("Test RequestSignal")); sl@0: TestRequestSignal(); sl@0: sl@0: test.Next(_L("Test SetProcessPriority")); sl@0: TestSetProcessPriority(); sl@0: sl@0: sl@0: SyncMutex.Close(); sl@0: test.End(); sl@0: sl@0: return(0); sl@0: } sl@0: