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