sl@0: // Copyright (c) 1994-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\system\t_env.cpp sl@0: // Overview: sl@0: // Test RProcess parameters sl@0: // API Information: sl@0: // RProcess sl@0: // Details: sl@0: // - Create a thread that causes a variety of panics. Verify that the exit sl@0: // reason is as expected. sl@0: // - Create a process that causes a variety of panics. Verify that the results sl@0: // are as expected. sl@0: // - Test passing 16 bit and 8 bit descriptors to another process. Verify the sl@0: // text and other results are as expected. sl@0: // - Verify that an invalid read of a descriptor by a process causes a panic. sl@0: // - Test passing zero length data to a separate process works as expected. sl@0: // - Test that passing each of a mutex, semaphore, file handle and chunk to a sl@0: // separate process works 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: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: #if defined (__WINS__) sl@0: #define PDD_NAME _L("ECDRV.PDD") sl@0: #define LDD_NAME _L("ECOMM.LDD") sl@0: #else sl@0: #define PDD_NAME _L("EUART") sl@0: #define LDD_NAME _L("ECOMM") sl@0: #endif sl@0: sl@0: sl@0: LOCAL_D RTest test(_L("T_ENV")); sl@0: sl@0: sl@0: _LIT(KProcName, "t_env_child.exe"); sl@0: _LIT(KThreadName, "t_env_panic_thread"); sl@0: _LIT(KQueueName, "testqueue"); sl@0: _LIT(KMutexName, "testmutex"); sl@0: _LIT(KSemName, "testsemaphore"); sl@0: _LIT(KChunkName, "testchunk"); sl@0: _LIT(KFileName, "c:\\testfile"); sl@0: sl@0: const TInt KHeapSize=0x2000; sl@0: sl@0: sl@0: sl@0: class TData sl@0: { sl@0: public: sl@0: TData(TInt aTest, RProcess& aProcess); sl@0: TInt iTest; sl@0: RProcess& iProcess; sl@0: }; sl@0: sl@0: TData::TData(TInt aTest, RProcess& aProcess) : iTest(aTest), iProcess(aProcess) sl@0: { sl@0: //empty sl@0: }; sl@0: sl@0: sl@0: class Handles sl@0: { sl@0: public: sl@0: void SetupParameters(RProcess& aNewProcess); sl@0: Handles(); sl@0: ~Handles(); sl@0: void Command(TInt aCommand); sl@0: sl@0: public: sl@0: RMsgQueue iCommandQueue; sl@0: RMsgQueue iIntQueue; sl@0: RMutex iMutex; sl@0: RSemaphore iSem; sl@0: RChunk iChunk; sl@0: RFile iFile; sl@0: RFs iSession; sl@0: }; sl@0: sl@0: void Handles::Command(TInt aC) sl@0: { sl@0: iCommandQueue.SendBlocking(aC); sl@0: } sl@0: sl@0: void Handles::SetupParameters(RProcess& aNewProcess) sl@0: { sl@0: aNewProcess.SetParameter(1, iCommandQueue); sl@0: aNewProcess.SetParameter(2, iIntQueue); sl@0: aNewProcess.SetParameter(3, iMutex); sl@0: aNewProcess.SetParameter(4, iSem); sl@0: aNewProcess.SetParameter(5, iChunk); sl@0: aNewProcess.SetParameter(7, iSession); sl@0: aNewProcess.SetParameter(8, iFile); sl@0: } sl@0: sl@0: sl@0: sl@0: _LIT8(KTestData,"test data"); sl@0: sl@0: Handles::Handles() sl@0: { sl@0: TInt ret = iCommandQueue.CreateGlobal(KNullDesC, 10, EOwnerProcess); sl@0: test(ret == KErrNone); sl@0: sl@0: ret = iIntQueue.CreateGlobal(KQueueName,1); sl@0: test(ret == KErrNone); sl@0: sl@0: ret = iMutex.CreateGlobal(KMutexName); sl@0: test(ret == KErrNone); sl@0: sl@0: ret = iSem.CreateGlobal(KSemName,0); sl@0: test(ret == KErrNone); sl@0: sl@0: ret = iChunk.CreateGlobal(KChunkName, 1024, 2048); sl@0: test(ret == KErrNone); sl@0: sl@0: ret = iSession.Connect(); sl@0: test(ret == KErrNone); sl@0: sl@0: ret = iSession.ShareProtected(); sl@0: test(ret == KErrNone); sl@0: sl@0: ret = iFile.Open(iSession, KFileName, EFileStreamText|EFileWrite|EFileShareAny); sl@0: if (ret == KErrNotFound) // file does not exist - create it sl@0: ret = iFile.Create(iSession, KFileName, EFileStreamText|EFileWrite|EFileShareAny); sl@0: test(ret == KErrNone); sl@0: ret = iFile.Write(0, KTestData); sl@0: test(ret == KErrNone); sl@0: } sl@0: sl@0: Handles::~Handles() sl@0: { sl@0: iCommandQueue.Close(); sl@0: iIntQueue.Close(); sl@0: iMutex.Close(); sl@0: iSem.Close(); sl@0: iChunk.Close(); sl@0: iSession.Close(); sl@0: } sl@0: sl@0: sl@0: LOCAL_C TInt testSetParameterPanics(TAny* aData) sl@0: { sl@0: const TData* data = (const TData*)aData; sl@0: switch (data->iTest) sl@0: { sl@0: case 0: //try and pass a non local handle sl@0: { sl@0: RMsgQueue localMsgQueue; sl@0: localMsgQueue.CreateLocal(1); sl@0: data->iProcess.SetParameter(1, localMsgQueue); //should panic with plat security panic sl@0: break; sl@0: } sl@0: sl@0: case 1: //out of range slot sl@0: { sl@0: RMsgQueue globalMsgQueue; sl@0: globalMsgQueue.CreateGlobal(KNullDesC, 1); sl@0: data->iProcess.SetParameter(-1, globalMsgQueue); //should panic with range error sl@0: break; sl@0: } sl@0: sl@0: case 2: sl@0: { sl@0: RMsgQueue globalMsgQueue; sl@0: globalMsgQueue.CreateGlobal(KNullDesC, 1); sl@0: data->iProcess.SetParameter(1234, globalMsgQueue); //should panic with range error sl@0: break; sl@0: } sl@0: sl@0: case 3: //in use sl@0: { sl@0: RMsgQueue globalMsgQueue; sl@0: globalMsgQueue.CreateGlobal(KNullDesC, 1); sl@0: data->iProcess.SetParameter(1, globalMsgQueue); sl@0: data->iProcess.SetParameter(1, globalMsgQueue); //panic, in use sl@0: break; sl@0: } sl@0: sl@0: case 4: sl@0: { sl@0: TPtrC8 bad((const TUint8*)0xfeed,4); sl@0: data->iProcess.SetParameter(1, bad); sl@0: break; sl@0: } sl@0: sl@0: case 5: //slot 0 is for the command line sl@0: { sl@0: RMsgQueue globalMsgQueue; sl@0: globalMsgQueue.CreateGlobal(KNullDesC, 1); sl@0: data->iProcess.SetParameter(0, globalMsgQueue); //panic, in use sl@0: break; sl@0: } sl@0: sl@0: } sl@0: return KErrNone; sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: GLDEF_C TInt E32Main() sl@0: { sl@0: sl@0: test.Title(); sl@0: test.Start(_L("Process Parameters")); sl@0: sl@0: test.Next(_L("Test Panics on a set")); sl@0: sl@0: TBool jit = User::JustInTime(); sl@0: User::SetJustInTime(EFalse); sl@0: TInt i; sl@0: RProcess p; sl@0: TInt ret = p.Create(KProcName, KProcName); sl@0: test(ret == KErrNone); sl@0: for (i = 0; i < 6; i++) sl@0: { sl@0: test.Printf(_L("panic test number %d\n"), i); sl@0: TData data(i, p); sl@0: RThread thread; sl@0: ret = thread.Create(KThreadName, testSetParameterPanics, KDefaultStackSize, KHeapSize, KHeapSize, &data); sl@0: test(KErrNone == ret); sl@0: TRequestStatus stat; sl@0: thread.Logon(stat); sl@0: thread.Resume(); sl@0: User::WaitForRequest(stat); sl@0: test.Printf(_L("exit type is %d, stat is %d"), thread.ExitType(), stat.Int()); sl@0: test (thread.ExitType() == EExitPanic); sl@0: switch (i) sl@0: { sl@0: case 0: sl@0: test (thread.ExitReason() == EPlatformSecurityTrap); sl@0: break; sl@0: sl@0: case 1: sl@0: case 2: sl@0: test (thread.ExitReason() == EParameterSlotRange); sl@0: break; sl@0: sl@0: case 3: sl@0: case 5: sl@0: test (thread.ExitReason() == EParameterSlotInUse); sl@0: break; sl@0: sl@0: case 4: sl@0: test (thread.ExitReason() == ECausedException); sl@0: break; sl@0: } sl@0: CLOSE_AND_WAIT(thread); sl@0: } sl@0: p.Kill(0); sl@0: CLOSE_AND_WAIT(p); sl@0: sl@0: test.Next(_L("launch panicing process")); sl@0: sl@0: sl@0: Handles h; sl@0: sl@0: TRequestStatus stat; sl@0: for (i = 0; i < 1; i++) sl@0: { sl@0: h.Command(i); sl@0: ret = p.Create(KProcName, KNullDesC); sl@0: test(ret == KErrNone); sl@0: p.Logon(stat); sl@0: h.SetupParameters(p); sl@0: p.Resume(); sl@0: User::WaitForRequest(stat); sl@0: test(p.ExitType()==EExitPanic); sl@0: test(p.ExitReason()==EParameterSlotRange); sl@0: CLOSE_AND_WAIT(p); sl@0: } sl@0: User::SetJustInTime(jit); sl@0: sl@0: test.Next(_L("test 16 bit descriptor")); sl@0: h.Command(8); sl@0: ret = p.Create(KProcName, KNullDesC); sl@0: test(ret == KErrNone); sl@0: p.Logon(stat); sl@0: h.SetupParameters(p); sl@0: p.SetParameter(15, _L("16 bit text")); sl@0: p.Resume(); sl@0: User::WaitForRequest(stat); sl@0: test(p.ExitType()==EExitKill); sl@0: test(p.ExitReason()==KErrNone); sl@0: CLOSE_AND_WAIT(p); sl@0: sl@0: test.Next(_L("test 8 bit descriptor")); sl@0: h.Command(9); sl@0: ret = p.Create(KProcName, KNullDesC); sl@0: test(ret == KErrNone); sl@0: p.Logon(stat); sl@0: h.SetupParameters(p); sl@0: p.SetParameter(15, _L8("8 bit text")); sl@0: p.Resume(); sl@0: User::WaitForRequest(stat); sl@0: test(p.ExitType()==EExitKill); sl@0: test(p.ExitReason()==KErrNone); sl@0: CLOSE_AND_WAIT(p); sl@0: sl@0: sl@0: test.Next(_L("test bad read of descriptor")); sl@0: h.Command(10); sl@0: ret = p.Create(KProcName, KNullDesC); sl@0: test(ret == KErrNone); sl@0: p.Logon(stat); sl@0: h.SetupParameters(p); sl@0: p.SetParameter(15, _L8("aa")); sl@0: p.Resume(); sl@0: User::WaitForRequest(stat); sl@0: test(p.ExitType()==EExitPanic); sl@0: test(p.ExitReason()==ECausedException); sl@0: CLOSE_AND_WAIT(p); sl@0: sl@0: test.Next(_L("test zero length data")); sl@0: h.Command(11); sl@0: ret = p.Create(KProcName, KNullDesC); sl@0: test(ret == KErrNone); sl@0: p.Logon(stat); sl@0: h.SetupParameters(p); sl@0: p.SetParameter(15, KNullDesC); sl@0: p.Resume(); sl@0: User::WaitForRequest(stat); sl@0: test(p.ExitType()==EExitKill); sl@0: test(p.ExitReason()==KErrNone); sl@0: CLOSE_AND_WAIT(p); sl@0: sl@0: test.Next(_L("test reserved command line")); sl@0: h.Command(12); sl@0: ret = p.Create(KProcName, KNullDesC); sl@0: test(ret == KErrNone); sl@0: p.Logon(stat); sl@0: h.SetupParameters(p); sl@0: p.Resume(); sl@0: User::WaitForRequest(stat); sl@0: test(p.ExitType()==EExitKill); sl@0: test(p.ExitReason()==KErrNone); sl@0: CLOSE_AND_WAIT(p); sl@0: sl@0: sl@0: test.Next(_L("test mutex")); sl@0: h.Command(4); sl@0: ret = p.Create(KProcName, KNullDesC); sl@0: test(ret == KErrNone); sl@0: p.Logon(stat); sl@0: h.SetupParameters(p); sl@0: p.Resume(); sl@0: User::WaitForRequest(stat); sl@0: test(p.ExitType()==EExitKill); sl@0: test(p.ExitReason()==KErrNone); sl@0: CLOSE_AND_WAIT(p); sl@0: sl@0: sl@0: test.Next(_L("test semaphore")); sl@0: h.Command(5); sl@0: ret = p.Create(KProcName, KNullDesC); sl@0: test(ret == KErrNone); sl@0: p.Logon(stat); sl@0: h.SetupParameters(p); sl@0: p.Resume(); sl@0: User::WaitForRequest(stat); sl@0: test(p.ExitType()==EExitKill); sl@0: test(p.ExitReason()==KErrNone); sl@0: CLOSE_AND_WAIT(p); sl@0: sl@0: test.Next(_L("test file handle")); sl@0: h.Command(6); sl@0: ret = p.Create(KProcName, KNullDesC); sl@0: test(ret == KErrNone); sl@0: p.Logon(stat); sl@0: h.SetupParameters(p); sl@0: p.Resume(); sl@0: User::WaitForRequest(stat); sl@0: test(p.ExitType()==EExitKill); sl@0: test(p.ExitReason()==KErrNone); sl@0: CLOSE_AND_WAIT(p); sl@0: sl@0: test.Next(_L("test chunk")); sl@0: h.Command(7); sl@0: ret = p.Create(KProcName, KNullDesC); sl@0: test(ret == KErrNone); sl@0: p.Logon(stat); sl@0: h.SetupParameters(p); sl@0: p.Resume(); sl@0: User::WaitForRequest(stat); sl@0: test(p.ExitType()==EExitKill); sl@0: test(p.ExitReason()==KErrNone); sl@0: CLOSE_AND_WAIT(p); sl@0: sl@0: test.End(); sl@0: return 0; sl@0: }