sl@0: // Copyright (c) 1996-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\bench\t_proc2.cpp sl@0: // The other half of the process relative type test stuff sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include "t_proc.h" sl@0: sl@0: RTest test(_L("T_PROC2")); sl@0: RTest testSvr(_L("Server")); sl@0: sl@0: void CMySession::DisplayName(const RMessage2& aMessage, const TDesC& aText) sl@0: // sl@0: // Display the client's name. sl@0: // sl@0: { sl@0: RThread client; sl@0: TInt r = aMessage.Client(client); sl@0: test(r == KErrNone); sl@0: TFullName name = client.FullName(); sl@0: client.Close(); sl@0: testSvr.Printf(_L("Session %S\n%S\n"), &name, &aText); sl@0: } sl@0: sl@0: void CMySession::ServiceL(const RMessage2& aMessage) sl@0: // sl@0: // Handle messages for this server. sl@0: // sl@0: { sl@0: sl@0: TInt r=KErrNone; sl@0: TBuf<0x100> b; sl@0: switch (aMessage.Function()) sl@0: { sl@0: case CMyServer::EDisplay: sl@0: TRAP(r,aMessage.ReadL(0,b)); sl@0: DisplayName(aMessage, b); sl@0: break; sl@0: case CMyServer::ERead: sl@0: TRAP(r,aMessage.ReadL(0,b)); sl@0: if (r==KErrNone && b!=_L("Testing read")) sl@0: r=KErrGeneral; sl@0: if (r==KErrNone) sl@0: { sl@0: TRAP(r,aMessage.ReadL(0,b,-1)); sl@0: if (r==KErrNone) sl@0: r=KErrGeneral; sl@0: if (r==KErrArgument) sl@0: r=KErrNone; sl@0: } sl@0: if (r==KErrNone) sl@0: { sl@0: TInt i = TInt(0xfefefefe); sl@0: TRAP(r,aMessage.ReadL(i,b)); sl@0: if (r==KErrNone) sl@0: r=KErrGeneral; sl@0: if (r==KErrBadDescriptor) sl@0: r=KErrNone; sl@0: } sl@0: break; sl@0: case CMyServer::EWrite: sl@0: TRAP(r,aMessage.WriteL(0,_L("It worked!"))); sl@0: if (r==KErrNone) sl@0: { sl@0: TRAP(r,aMessage.WriteL(0,b,-1)); sl@0: if (r==KErrNone) sl@0: r=KErrGeneral; sl@0: if (r==KErrArgument) sl@0: r=KErrNone; sl@0: } sl@0: if (r==KErrNone) sl@0: { sl@0: TRAP(r,aMessage.WriteL(1,b)); sl@0: if (r==KErrNone) sl@0: r=KErrGeneral; sl@0: if (r==KErrBadDescriptor) sl@0: r=KErrNone; sl@0: } sl@0: break; sl@0: case CMyServer::ETest: sl@0: break; sl@0: case CMyServer::EStop: sl@0: CActiveScheduler::Stop(); sl@0: break; sl@0: default: sl@0: r=KErrNotSupported; sl@0: } sl@0: aMessage.Complete(r); sl@0: } sl@0: sl@0: CMyServer* CMyServer::New(TInt aPriority) sl@0: // sl@0: // Create a new CMyServer. sl@0: // sl@0: { sl@0: sl@0: return new CMyServer(aPriority); sl@0: } sl@0: sl@0: CMyServer::CMyServer(TInt aPriority) sl@0: // sl@0: // Constructor. sl@0: // sl@0: : CServer2(aPriority) sl@0: {} sl@0: sl@0: CSession2* CMyServer::NewSessionL(const TVersion& aVersion, const RMessage2&) const sl@0: // sl@0: // Create a new client for this server. sl@0: // sl@0: { sl@0: sl@0: TVersion v(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber); sl@0: if (!User::QueryVersionSupported(v,aVersion)) sl@0: User::Leave(KErrNotSupported); sl@0: return(new(ELeave) CMySession()); sl@0: } sl@0: sl@0: void CMyActiveScheduler::Error(TInt anError) const sl@0: // sl@0: // Called if any Run() method leaves. sl@0: // sl@0: { sl@0: sl@0: testSvr.Panic(anError,_L("CMyActiveScheduler::Error")); sl@0: } sl@0: sl@0: LOCAL_C TInt serverThreadEntryPoint(TAny*) sl@0: // sl@0: // The entry point for the producer thread. sl@0: // sl@0: { sl@0: sl@0: // testSvr.Title(); sl@0: // testSvr.Start(_L("Create CActiveScheduler")); sl@0: CMyActiveScheduler* pR=new CMyActiveScheduler; sl@0: // testSvr(pR!=NULL); sl@0: CActiveScheduler::Install(pR); sl@0: // sl@0: // testSvr.Next(_L("Create CMyServer")); sl@0: CMyServer* pS=CMyServer::New(0); sl@0: // testSvr(pS!=NULL); sl@0: // sl@0: // testSvr.Next(_L("Start CMyServer")); sl@0: sl@0: pS->Start(KServerName); sl@0: sl@0: // TInt r=pS->Start(); sl@0: // testSvr(r==KErrNone); sl@0: // sl@0: // testSvr.Next(_L("Signal to client that we have started")); sl@0: // client.Signal(); sl@0: // sl@0: // testSvr.Next(_L("Start CActiveScheduler")); sl@0: CActiveScheduler::Start(); sl@0: // sl@0: // testSvr.Next(_L("Exit server")); sl@0: // testSvr.Close(); sl@0: sl@0: return(KErrNone); sl@0: } sl@0: sl@0: sl@0: void init() sl@0: { sl@0: // create server thread sl@0: RThread server; sl@0: TInt r=server.Create(_L("Server"),serverThreadEntryPoint,KDefaultStackSize,KHeapSize,KHeapSize,NULL); sl@0: test(r==KErrNone); sl@0: server.SetPriority(EPriorityMore); sl@0: server.Resume(); sl@0: sl@0: r=globSem1.OpenGlobal(_L("GlobSem1")); sl@0: test(r==KErrNone); sl@0: r=globSem2.OpenGlobal(_L("GlobSem2")); sl@0: test(r==KErrNone); sl@0: globSem1.Signal(); // finished init sl@0: } sl@0: sl@0: void sharedChunks() sl@0: { sl@0: sl@0: globSem2.Wait(); // wait for chunk test to be set up sl@0: sl@0: RChunk c; sl@0: TInt r=c.OpenGlobal(_L("Marmalade"),EFalse); sl@0: test(r==KErrNone); sl@0: test.Printf(_L("Chunk opened\r\n")); sl@0: TUint8* base=c.Base(); sl@0: test.Printf(_L("Chunk address %x\r\n"),base); sl@0: for (TInt8 i=0;i<10;i++) sl@0: test(*base++==i); // check the chunk has 0-9 sl@0: test.Printf(_L("Chunk contents tested\r\n")); sl@0: c.Close(); sl@0: globSem1.Signal(); // say we've done it sl@0: } sl@0: sl@0: TInt sharedChunks2(TAny* /*aDummy*/) sl@0: { sl@0: sl@0: RTest test(_L("Shared Chunks 2")); sl@0: sl@0: globSem2.Wait(); // wait for chunk test to be set up sl@0: sl@0: RChunk c; sl@0: TInt r=c.OpenGlobal(_L("Marmalade"),EFalse); sl@0: test(r==KErrNone); sl@0: test.Printf(_L("Chunk opened\r\n")); sl@0: TUint8* base=c.Base(); sl@0: test.Printf(_L("Chunk address %x\r\n"),base); sl@0: for (TInt8 i=0;i<10;i++) sl@0: test(*base++==i); // check the chunk has 0-9 sl@0: test.Printf(_L("Chunk contents tested\r\n")); sl@0: c.Close(); sl@0: globSem1.Signal(); // say we've done it sl@0: return(KErrNone); sl@0: } sl@0: sl@0: TInt E32Main() sl@0: { sl@0: sl@0: test.Title(); sl@0: sl@0: test.Start(_L("Testing process stuff 2")); sl@0: sl@0: test.Next(_L("Check that T_PROC1 is running")); sl@0: TFindProcess fProcess(_L("*T_PROC1*")); sl@0: TFullName n; sl@0: TInt r=fProcess.Next(n); sl@0: if (r!=KErrNone) sl@0: { sl@0: test.Printf(_L("This test should not be run from the command line.\n")); sl@0: test.Printf(_L("Run T_PROC1, which loads this test.\n")); sl@0: test.End(); sl@0: test.Close(); sl@0: return (KErrNone); sl@0: } sl@0: sl@0: test.Next(_L("Initialize")); sl@0: init(); sl@0: sl@0: test.Next(_L("Shared chunks from primary thread")); sl@0: sharedChunks(); sl@0: sl@0: test.Next(_L("Shared chunks from secondary thread")); sl@0: RThread t; sl@0: r=t.Create(_L("Shared chunks 2"),sharedChunks2,KDefaultStackSize,KHeapSize,KHeapSize,NULL); sl@0: test(r==KErrNone); sl@0: TRequestStatus s; sl@0: t.Logon(s); sl@0: t.Resume(); sl@0: User::WaitForRequest(s); sl@0: test(s==KErrNone); sl@0: CLOSE_AND_WAIT(t); sl@0: sl@0: test.Close(); sl@0: globSem1.Signal(); // tell proc1 I'm ready sl@0: sl@0: // test.Next(_L("Wait for first process to do speed tests")); sl@0: globSem2.Wait(); sl@0: sl@0: return(KErrNone); sl@0: } sl@0: