kerneltest/e32test/bench/t_proc2.cpp
changeset 0 a41df078684a
equal deleted inserted replaced
-1:000000000000 0:a41df078684a
       
     1 // Copyright (c) 1996-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".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // e32test\bench\t_proc2.cpp
       
    15 // The other half of the process relative type test stuff
       
    16 // 
       
    17 //
       
    18 										
       
    19 #include <e32test.h>
       
    20 #include "t_proc.h"
       
    21 
       
    22 RTest test(_L("T_PROC2"));
       
    23 RTest testSvr(_L("Server"));
       
    24 
       
    25 void CMySession::DisplayName(const RMessage2& aMessage, const TDesC& aText)
       
    26 //
       
    27 // Display the client's name.
       
    28 //
       
    29 	{
       
    30 	RThread client;
       
    31 	TInt r = aMessage.Client(client);
       
    32 	test(r == KErrNone);
       
    33 	TFullName name = client.FullName();
       
    34 	client.Close();
       
    35 	testSvr.Printf(_L("Session %S\n%S\n"), &name, &aText);
       
    36 	}
       
    37 
       
    38 void CMySession::ServiceL(const RMessage2& aMessage)
       
    39 //
       
    40 // Handle messages for this server.
       
    41 //
       
    42 	{
       
    43 
       
    44 	TInt r=KErrNone;
       
    45 	TBuf<0x100> b;
       
    46 	switch (aMessage.Function())
       
    47 		{
       
    48 	case CMyServer::EDisplay:
       
    49 		TRAP(r,aMessage.ReadL(0,b));
       
    50 		DisplayName(aMessage, b);
       
    51 		break;
       
    52 	case CMyServer::ERead:
       
    53 		TRAP(r,aMessage.ReadL(0,b));
       
    54 		if (r==KErrNone && b!=_L("Testing read"))
       
    55 			r=KErrGeneral;
       
    56 		if (r==KErrNone)
       
    57 			{
       
    58 			TRAP(r,aMessage.ReadL(0,b,-1));
       
    59 			if (r==KErrNone)
       
    60 				r=KErrGeneral;
       
    61 			if (r==KErrArgument)
       
    62 				r=KErrNone;
       
    63 			}
       
    64 		if (r==KErrNone)
       
    65 			{
       
    66 			TInt i = TInt(0xfefefefe);
       
    67 			TRAP(r,aMessage.ReadL(i,b));
       
    68 			if (r==KErrNone)
       
    69 				r=KErrGeneral;
       
    70 			if (r==KErrBadDescriptor)
       
    71 				r=KErrNone;
       
    72 			}
       
    73 		break;
       
    74 	case CMyServer::EWrite:
       
    75 		TRAP(r,aMessage.WriteL(0,_L("It worked!")));
       
    76 		if (r==KErrNone)
       
    77 			{
       
    78 			TRAP(r,aMessage.WriteL(0,b,-1));
       
    79 			if (r==KErrNone)
       
    80 				r=KErrGeneral;
       
    81 			if (r==KErrArgument)
       
    82 				r=KErrNone;
       
    83 			}
       
    84 		if (r==KErrNone)
       
    85 			{
       
    86 			TRAP(r,aMessage.WriteL(1,b));
       
    87 			if (r==KErrNone)
       
    88 				r=KErrGeneral;
       
    89 			if (r==KErrBadDescriptor)
       
    90 				r=KErrNone;
       
    91 			}
       
    92 		break;
       
    93 	case CMyServer::ETest:
       
    94 		break;
       
    95 	case CMyServer::EStop:
       
    96 		CActiveScheduler::Stop();
       
    97 		break;
       
    98 	default:
       
    99 		r=KErrNotSupported;
       
   100 		}
       
   101 	aMessage.Complete(r);
       
   102 	}
       
   103 
       
   104 CMyServer* CMyServer::New(TInt aPriority)
       
   105 //
       
   106 // Create a new CMyServer.
       
   107 //
       
   108 	{
       
   109 
       
   110 	return new CMyServer(aPriority);
       
   111 	}
       
   112 
       
   113 CMyServer::CMyServer(TInt aPriority)
       
   114 //
       
   115 // Constructor.
       
   116 //
       
   117 	: CServer2(aPriority)
       
   118 	{}
       
   119 
       
   120 CSession2* CMyServer::NewSessionL(const TVersion& aVersion, const RMessage2&) const
       
   121 //
       
   122 // Create a new client for this server.
       
   123 //
       
   124 	{
       
   125 
       
   126 	TVersion v(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber);
       
   127 	if (!User::QueryVersionSupported(v,aVersion))
       
   128 		User::Leave(KErrNotSupported);
       
   129 	return(new(ELeave) CMySession());
       
   130 	}
       
   131 
       
   132 void CMyActiveScheduler::Error(TInt anError) const
       
   133 //
       
   134 // Called if any Run() method leaves.
       
   135 //
       
   136 	{
       
   137 
       
   138 	testSvr.Panic(anError,_L("CMyActiveScheduler::Error"));
       
   139 	}
       
   140 
       
   141 LOCAL_C TInt serverThreadEntryPoint(TAny*)
       
   142 //
       
   143 // The entry point for the producer thread.
       
   144 //
       
   145 	{
       
   146 
       
   147 //	testSvr.Title();
       
   148 //	testSvr.Start(_L("Create CActiveScheduler"));
       
   149 	CMyActiveScheduler* pR=new CMyActiveScheduler;
       
   150 //	testSvr(pR!=NULL);
       
   151 	CActiveScheduler::Install(pR);
       
   152 //
       
   153 //	testSvr.Next(_L("Create CMyServer"));
       
   154 	CMyServer* pS=CMyServer::New(0);
       
   155 //	testSvr(pS!=NULL);
       
   156 //
       
   157 //	testSvr.Next(_L("Start CMyServer"));
       
   158 
       
   159 	pS->Start(KServerName);
       
   160 
       
   161 //	TInt r=pS->Start();
       
   162 //	testSvr(r==KErrNone);
       
   163 //
       
   164 //	testSvr.Next(_L("Signal to client that we have started"));
       
   165 //	client.Signal();
       
   166 //
       
   167 //	testSvr.Next(_L("Start CActiveScheduler"));
       
   168 	CActiveScheduler::Start();
       
   169 //
       
   170 //	testSvr.Next(_L("Exit server"));
       
   171 //	testSvr.Close();
       
   172 
       
   173 	return(KErrNone);
       
   174 	}
       
   175 
       
   176 
       
   177 void init()
       
   178 	{
       
   179 	// create server thread
       
   180 	RThread server;
       
   181 	TInt r=server.Create(_L("Server"),serverThreadEntryPoint,KDefaultStackSize,KHeapSize,KHeapSize,NULL);
       
   182 	test(r==KErrNone);
       
   183 	server.SetPriority(EPriorityMore);
       
   184 	server.Resume();
       
   185 
       
   186 	r=globSem1.OpenGlobal(_L("GlobSem1"));
       
   187 	test(r==KErrNone);
       
   188 	r=globSem2.OpenGlobal(_L("GlobSem2"));
       
   189 	test(r==KErrNone);
       
   190 	globSem1.Signal(); // finished init
       
   191 	}
       
   192 
       
   193 void sharedChunks()
       
   194 	{
       
   195 
       
   196 	globSem2.Wait(); // wait for chunk test to be set up
       
   197 
       
   198 	RChunk c;
       
   199 	TInt r=c.OpenGlobal(_L("Marmalade"),EFalse);
       
   200 	test(r==KErrNone);
       
   201     test.Printf(_L("Chunk opened\r\n"));
       
   202 	TUint8* base=c.Base();
       
   203     test.Printf(_L("Chunk address %x\r\n"),base);
       
   204 	for (TInt8 i=0;i<10;i++)
       
   205 		test(*base++==i); // check the chunk has 0-9
       
   206     test.Printf(_L("Chunk contents tested\r\n"));
       
   207   	c.Close();
       
   208 	globSem1.Signal(); // say we've done it
       
   209 	}
       
   210 
       
   211 TInt sharedChunks2(TAny* /*aDummy*/)
       
   212 	{
       
   213 
       
   214     RTest test(_L("Shared Chunks 2"));
       
   215 
       
   216 	globSem2.Wait(); // wait for chunk test to be set up
       
   217 
       
   218 	RChunk c;
       
   219 	TInt r=c.OpenGlobal(_L("Marmalade"),EFalse);
       
   220 	test(r==KErrNone);
       
   221     test.Printf(_L("Chunk opened\r\n"));
       
   222 	TUint8* base=c.Base();
       
   223     test.Printf(_L("Chunk address %x\r\n"),base);
       
   224 	for (TInt8 i=0;i<10;i++)
       
   225 		test(*base++==i); // check the chunk has 0-9
       
   226     test.Printf(_L("Chunk contents tested\r\n"));
       
   227   	c.Close();
       
   228 	globSem1.Signal(); // say we've done it
       
   229     return(KErrNone);
       
   230 	}
       
   231 
       
   232 TInt E32Main()
       
   233 	{	
       
   234  
       
   235 	test.Title();
       
   236 
       
   237 	test.Start(_L("Testing process stuff 2"));
       
   238 
       
   239 	test.Next(_L("Check that T_PROC1 is running"));
       
   240 	TFindProcess fProcess(_L("*T_PROC1*"));
       
   241 	TFullName n;
       
   242 	TInt r=fProcess.Next(n);
       
   243 	if (r!=KErrNone)
       
   244 		{
       
   245 		test.Printf(_L("This test should not be run from the command line.\n"));
       
   246 		test.Printf(_L("Run T_PROC1, which loads this test.\n"));
       
   247 		test.End();
       
   248 		test.Close();
       
   249 		return (KErrNone);
       
   250 		}
       
   251 
       
   252 	test.Next(_L("Initialize"));
       
   253 	init();
       
   254 
       
   255 	test.Next(_L("Shared chunks from primary thread"));
       
   256 	sharedChunks();
       
   257 	
       
   258 	test.Next(_L("Shared chunks from secondary thread"));
       
   259 	RThread t;
       
   260 	r=t.Create(_L("Shared chunks 2"),sharedChunks2,KDefaultStackSize,KHeapSize,KHeapSize,NULL);
       
   261     test(r==KErrNone);
       
   262 	TRequestStatus s;
       
   263 	t.Logon(s);
       
   264 	t.Resume();
       
   265 	User::WaitForRequest(s);
       
   266 	test(s==KErrNone);
       
   267 	CLOSE_AND_WAIT(t);
       
   268 
       
   269 	test.Close();
       
   270 	globSem1.Signal(); // tell proc1 I'm ready
       
   271 
       
   272 //	test.Next(_L("Wait for first process to do speed tests"));
       
   273 	globSem2.Wait();
       
   274 	
       
   275 	return(KErrNone);
       
   276 	}
       
   277