1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/bench/t_proc2.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,277 @@
1.4 +// Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// e32test\bench\t_proc2.cpp
1.18 +// The other half of the process relative type test stuff
1.19 +//
1.20 +//
1.21 +
1.22 +#include <e32test.h>
1.23 +#include "t_proc.h"
1.24 +
1.25 +RTest test(_L("T_PROC2"));
1.26 +RTest testSvr(_L("Server"));
1.27 +
1.28 +void CMySession::DisplayName(const RMessage2& aMessage, const TDesC& aText)
1.29 +//
1.30 +// Display the client's name.
1.31 +//
1.32 + {
1.33 + RThread client;
1.34 + TInt r = aMessage.Client(client);
1.35 + test(r == KErrNone);
1.36 + TFullName name = client.FullName();
1.37 + client.Close();
1.38 + testSvr.Printf(_L("Session %S\n%S\n"), &name, &aText);
1.39 + }
1.40 +
1.41 +void CMySession::ServiceL(const RMessage2& aMessage)
1.42 +//
1.43 +// Handle messages for this server.
1.44 +//
1.45 + {
1.46 +
1.47 + TInt r=KErrNone;
1.48 + TBuf<0x100> b;
1.49 + switch (aMessage.Function())
1.50 + {
1.51 + case CMyServer::EDisplay:
1.52 + TRAP(r,aMessage.ReadL(0,b));
1.53 + DisplayName(aMessage, b);
1.54 + break;
1.55 + case CMyServer::ERead:
1.56 + TRAP(r,aMessage.ReadL(0,b));
1.57 + if (r==KErrNone && b!=_L("Testing read"))
1.58 + r=KErrGeneral;
1.59 + if (r==KErrNone)
1.60 + {
1.61 + TRAP(r,aMessage.ReadL(0,b,-1));
1.62 + if (r==KErrNone)
1.63 + r=KErrGeneral;
1.64 + if (r==KErrArgument)
1.65 + r=KErrNone;
1.66 + }
1.67 + if (r==KErrNone)
1.68 + {
1.69 + TInt i = TInt(0xfefefefe);
1.70 + TRAP(r,aMessage.ReadL(i,b));
1.71 + if (r==KErrNone)
1.72 + r=KErrGeneral;
1.73 + if (r==KErrBadDescriptor)
1.74 + r=KErrNone;
1.75 + }
1.76 + break;
1.77 + case CMyServer::EWrite:
1.78 + TRAP(r,aMessage.WriteL(0,_L("It worked!")));
1.79 + if (r==KErrNone)
1.80 + {
1.81 + TRAP(r,aMessage.WriteL(0,b,-1));
1.82 + if (r==KErrNone)
1.83 + r=KErrGeneral;
1.84 + if (r==KErrArgument)
1.85 + r=KErrNone;
1.86 + }
1.87 + if (r==KErrNone)
1.88 + {
1.89 + TRAP(r,aMessage.WriteL(1,b));
1.90 + if (r==KErrNone)
1.91 + r=KErrGeneral;
1.92 + if (r==KErrBadDescriptor)
1.93 + r=KErrNone;
1.94 + }
1.95 + break;
1.96 + case CMyServer::ETest:
1.97 + break;
1.98 + case CMyServer::EStop:
1.99 + CActiveScheduler::Stop();
1.100 + break;
1.101 + default:
1.102 + r=KErrNotSupported;
1.103 + }
1.104 + aMessage.Complete(r);
1.105 + }
1.106 +
1.107 +CMyServer* CMyServer::New(TInt aPriority)
1.108 +//
1.109 +// Create a new CMyServer.
1.110 +//
1.111 + {
1.112 +
1.113 + return new CMyServer(aPriority);
1.114 + }
1.115 +
1.116 +CMyServer::CMyServer(TInt aPriority)
1.117 +//
1.118 +// Constructor.
1.119 +//
1.120 + : CServer2(aPriority)
1.121 + {}
1.122 +
1.123 +CSession2* CMyServer::NewSessionL(const TVersion& aVersion, const RMessage2&) const
1.124 +//
1.125 +// Create a new client for this server.
1.126 +//
1.127 + {
1.128 +
1.129 + TVersion v(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber);
1.130 + if (!User::QueryVersionSupported(v,aVersion))
1.131 + User::Leave(KErrNotSupported);
1.132 + return(new(ELeave) CMySession());
1.133 + }
1.134 +
1.135 +void CMyActiveScheduler::Error(TInt anError) const
1.136 +//
1.137 +// Called if any Run() method leaves.
1.138 +//
1.139 + {
1.140 +
1.141 + testSvr.Panic(anError,_L("CMyActiveScheduler::Error"));
1.142 + }
1.143 +
1.144 +LOCAL_C TInt serverThreadEntryPoint(TAny*)
1.145 +//
1.146 +// The entry point for the producer thread.
1.147 +//
1.148 + {
1.149 +
1.150 +// testSvr.Title();
1.151 +// testSvr.Start(_L("Create CActiveScheduler"));
1.152 + CMyActiveScheduler* pR=new CMyActiveScheduler;
1.153 +// testSvr(pR!=NULL);
1.154 + CActiveScheduler::Install(pR);
1.155 +//
1.156 +// testSvr.Next(_L("Create CMyServer"));
1.157 + CMyServer* pS=CMyServer::New(0);
1.158 +// testSvr(pS!=NULL);
1.159 +//
1.160 +// testSvr.Next(_L("Start CMyServer"));
1.161 +
1.162 + pS->Start(KServerName);
1.163 +
1.164 +// TInt r=pS->Start();
1.165 +// testSvr(r==KErrNone);
1.166 +//
1.167 +// testSvr.Next(_L("Signal to client that we have started"));
1.168 +// client.Signal();
1.169 +//
1.170 +// testSvr.Next(_L("Start CActiveScheduler"));
1.171 + CActiveScheduler::Start();
1.172 +//
1.173 +// testSvr.Next(_L("Exit server"));
1.174 +// testSvr.Close();
1.175 +
1.176 + return(KErrNone);
1.177 + }
1.178 +
1.179 +
1.180 +void init()
1.181 + {
1.182 + // create server thread
1.183 + RThread server;
1.184 + TInt r=server.Create(_L("Server"),serverThreadEntryPoint,KDefaultStackSize,KHeapSize,KHeapSize,NULL);
1.185 + test(r==KErrNone);
1.186 + server.SetPriority(EPriorityMore);
1.187 + server.Resume();
1.188 +
1.189 + r=globSem1.OpenGlobal(_L("GlobSem1"));
1.190 + test(r==KErrNone);
1.191 + r=globSem2.OpenGlobal(_L("GlobSem2"));
1.192 + test(r==KErrNone);
1.193 + globSem1.Signal(); // finished init
1.194 + }
1.195 +
1.196 +void sharedChunks()
1.197 + {
1.198 +
1.199 + globSem2.Wait(); // wait for chunk test to be set up
1.200 +
1.201 + RChunk c;
1.202 + TInt r=c.OpenGlobal(_L("Marmalade"),EFalse);
1.203 + test(r==KErrNone);
1.204 + test.Printf(_L("Chunk opened\r\n"));
1.205 + TUint8* base=c.Base();
1.206 + test.Printf(_L("Chunk address %x\r\n"),base);
1.207 + for (TInt8 i=0;i<10;i++)
1.208 + test(*base++==i); // check the chunk has 0-9
1.209 + test.Printf(_L("Chunk contents tested\r\n"));
1.210 + c.Close();
1.211 + globSem1.Signal(); // say we've done it
1.212 + }
1.213 +
1.214 +TInt sharedChunks2(TAny* /*aDummy*/)
1.215 + {
1.216 +
1.217 + RTest test(_L("Shared Chunks 2"));
1.218 +
1.219 + globSem2.Wait(); // wait for chunk test to be set up
1.220 +
1.221 + RChunk c;
1.222 + TInt r=c.OpenGlobal(_L("Marmalade"),EFalse);
1.223 + test(r==KErrNone);
1.224 + test.Printf(_L("Chunk opened\r\n"));
1.225 + TUint8* base=c.Base();
1.226 + test.Printf(_L("Chunk address %x\r\n"),base);
1.227 + for (TInt8 i=0;i<10;i++)
1.228 + test(*base++==i); // check the chunk has 0-9
1.229 + test.Printf(_L("Chunk contents tested\r\n"));
1.230 + c.Close();
1.231 + globSem1.Signal(); // say we've done it
1.232 + return(KErrNone);
1.233 + }
1.234 +
1.235 +TInt E32Main()
1.236 + {
1.237 +
1.238 + test.Title();
1.239 +
1.240 + test.Start(_L("Testing process stuff 2"));
1.241 +
1.242 + test.Next(_L("Check that T_PROC1 is running"));
1.243 + TFindProcess fProcess(_L("*T_PROC1*"));
1.244 + TFullName n;
1.245 + TInt r=fProcess.Next(n);
1.246 + if (r!=KErrNone)
1.247 + {
1.248 + test.Printf(_L("This test should not be run from the command line.\n"));
1.249 + test.Printf(_L("Run T_PROC1, which loads this test.\n"));
1.250 + test.End();
1.251 + test.Close();
1.252 + return (KErrNone);
1.253 + }
1.254 +
1.255 + test.Next(_L("Initialize"));
1.256 + init();
1.257 +
1.258 + test.Next(_L("Shared chunks from primary thread"));
1.259 + sharedChunks();
1.260 +
1.261 + test.Next(_L("Shared chunks from secondary thread"));
1.262 + RThread t;
1.263 + r=t.Create(_L("Shared chunks 2"),sharedChunks2,KDefaultStackSize,KHeapSize,KHeapSize,NULL);
1.264 + test(r==KErrNone);
1.265 + TRequestStatus s;
1.266 + t.Logon(s);
1.267 + t.Resume();
1.268 + User::WaitForRequest(s);
1.269 + test(s==KErrNone);
1.270 + CLOSE_AND_WAIT(t);
1.271 +
1.272 + test.Close();
1.273 + globSem1.Signal(); // tell proc1 I'm ready
1.274 +
1.275 +// test.Next(_L("Wait for first process to do speed tests"));
1.276 + globSem2.Wait();
1.277 +
1.278 + return(KErrNone);
1.279 + }
1.280 +