Update contrib.
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of the License "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
21 Test DLL Writeable Static Data support
27 - Each process has independent DLL WSD
28 - Whether DLL linked directly or indirectly
29 - Whether DLL loaded dynamically or statically
30 - DLL WSD is consistent under heavy usage by multiple processes
31 - IPC works to/from DLL WSD descriptors & TRequestStatus
32 This source file builds in 4 configurations, with each of
33 direct and indirect linking either used or not used.
34 These configurations are set by 4 MM files, t_dllwsd[d][i].mmp
35 Any of the exe created from the MMP files can be started
36 to run the tests, it does not matter which is used.
37 All exe configurations will be used during the tests.
39 Platforms/Drives/Compatibility:
42 Assumptions/Requirement/Pre-requisites:
48 Base Port information:
52 #define __E32TEST_EXTENSION__
58 #include "t_dllwsd_dll.h"
59 #include "t_dllwsd_dlli.h"
62 LOCAL_D RTest test(_L("T_DLLWSD"));
75 // Test session for IPC use of WSD, talks to the same server as RDllWsd
76 class RIpcTestSession : public RSessionBase
81 return CreateSession(_L("IpcTestServer"), TVersion());
83 void Get(TBuf<60000>& buf, TRequestStatus& req)
85 SendReceive(ETestFuncIpcGet, TIpcArgs(&buf), req);
87 void Reverse(TRequestStatus& req)
89 SendReceive(ETestFuncIpcReverse, req);
91 void Set(const TBuf<60000>& buf, TRequestStatus& req)
93 SendReceive(ETestFuncIpcSet, TIpcArgs(&buf), req);
97 #ifdef T_DLLWSD_DIRECT
98 void FillBuf(TInt start, TInt inc)
100 for (int ii=0; ii<WsdBuf().Length(); ii++)
102 WsdBuf()[ii] = (unsigned short)start;
107 TInt CheckBuf(TInt start, TInt inc)
109 for (int ii=0; ii<WsdBuf().Length(); ii++)
111 if (WsdBuf()[ii] != start)
119 class CDllWsdServer : public CServer2
122 CDllWsdServer() : CServer2(EPriorityStandard)
125 CSession2* NewSessionL(const TVersion& /*aVersion*/,const RMessage2& /*aMessage*/) const;
129 class CDllWsdSession : public CSession2
134 ResetConsistencyCheck();
139 // transient server immediate shutdown when last client disconnects
140 if (--((CDllWsdServer*)Server())->iCount == 0)
141 CActiveScheduler::Stop();
144 void ResetConsistencyCheck()
150 void OptResetConsistencyCheck()
152 #if !defined(T_DLLWSD_DIRECT) && !defined(T_DLLWSD_INDIRECT)
153 // if DLL has been unloaded (dynamic library closed, no static link)
155 ResetConsistencyCheck();
159 TInt TestConsistency()
161 #ifdef T_DLLWSD_DIRECT
163 if (WsdFuncX() != iX++)
165 if (WsdFuncY() != iY++)
169 #ifdef T_DLLWSD_INDIRECT
171 if (IndWsdFuncX() != iX++)
173 if (IndWsdFuncY() != iY++)
178 OptResetConsistencyCheck();
180 TInt err = lib.Load(_L("t_dllwsd_dll"));
182 if ((*lib.Lookup(1))/*WsdFuncX*/() != iX++)
184 if ((*lib.Lookup(2))/*WsdFuncX*/() != iY++)
189 OptResetConsistencyCheck();
190 err = lib.Load(_L("t_dllwsd_dlli"));
192 if ((*lib.Lookup(1))/*IndWsdFuncX*/() != iX++)
194 if ((*lib.Lookup(2))/*IndWsdFuncX*/() != iY++)
206 const TTimeIntervalMicroSeconds limit(10000000); // 10 seconds
209 TInt err = TestConsistency();
213 if (now.MicroSecondsFrom(start) > limit)
216 return count > 0 ? count : -count;
221 #ifdef T_DLLWSD_DIRECT
223 TInt err = s.Connect();
224 if (!err) return err;
225 WsdBuf().SetLength(WsdBuf().MaxLength());
226 for (int i=0; i<10; i++)
231 if (!err) return err;
234 s.Set(WsdBuf(), WsdReq());
236 if (!err) return err;
238 // use TReqestStatus in WSD
239 User::WaitForRequest(WsdReq());
240 if (!WsdReq().Int()) return WsdReq().Int();
245 if (!err) return err;
246 WsdReq() = KRequestPending;
248 // reverse buf on server
251 // local buf is still 0..0
253 if (!err) return err;
255 // use TReqestStatus in WSD
256 User::WaitForRequest(WsdReq());
257 if (!WsdReq().Int()) return WsdReq().Int();
259 // local buf is still 0..0
261 if (!err) return err;
263 // get buf from server
264 s.Get(WsdBuf(), WsdReq());
265 User::WaitForRequest(WsdReq());
268 err = CheckBuf(59999,-1);
269 if (!err) return err;
274 return KErrNotSupported;
278 void ServiceL(const RMessage2& aMessage)
280 #ifdef T_DLLWSD_DIRECT
283 switch (aMessage.Function())
285 case ETestFuncTestCons:
286 aMessage.Complete(TestConsistency());
288 case ETestFuncThrash1:
289 aMessage.Complete(Thrash1());
291 case ETestFuncIpcTest:
292 aMessage.Complete(IpcTest());
294 case ETestFuncIpcGet:
295 #ifdef T_DLLWSD_DIRECT
296 aMessage.WriteL(0, WsdBuf());
297 aMessage.Complete(KErrNone);
299 aMessage.Complete(KErrNotSupported);
302 case ETestFuncIpcReverse:
303 #ifdef T_DLLWSD_DIRECT
304 for (ii=0; ii<WsdBuf().Length()/2; ii++)
306 TInt o = WsdBuf().Length() - 1 - ii;
307 TInt t = WsdBuf()[ii];
308 WsdBuf()[ii] = WsdBuf()[o];
309 WsdBuf()[o] = (unsigned short)t;
311 aMessage.Complete(KErrNone);
313 aMessage.Complete(KErrNotSupported);
316 case ETestFuncIpcSet:
317 #ifdef T_DLLWSD_DIRECT
318 aMessage.ReadL(0, WsdBuf());
319 aMessage.Complete(KErrNone);
321 aMessage.Complete(KErrNotSupported);
325 User::Panic(_L("As requested..."), 0);
328 aMessage.Panic(_L("Unrecognised"), aMessage.Function());
337 CSession2* CDllWsdServer::NewSessionL(const TVersion& /*aVersion*/,const RMessage2& /*aMessage*/) const
340 return new(ELeave) CDllWsdSession;
346 User::CommandLine(name);
348 CTrapCleanup* cleanup = CTrapCleanup::New();
354 CActiveScheduler* sched=new(ELeave) CActiveScheduler;
355 CActiveScheduler::Install(sched);
357 CDllWsdServer* server = new(ELeave) CDllWsdServer;
358 server->StartL(name);
360 RProcess::Rendezvous(KErrNone);
361 CActiveScheduler::Start();
372 // Master test controller
375 class RDllWsd : public RSessionBase
378 RDllWsd(const TDesC& aServerName, const TDesC& aExeName = _L("t_dllwsddi"))
380 test.Start(_L("RDllWsd create"));
382 test_KErrNone(proc.Create(aExeName, aServerName));
384 proc.Rendezvous(req);
386 User::WaitForRequest(req);
387 test_KErrNone(req.Int());
388 test_KErrNone(CreateSession(aServerName, TVersion()));
392 TInt ConsistencyTest()
394 return SendReceive(ETestFuncTestCons);
396 void ThrashTest1(TRequestStatus& aStatus)
398 SendReceive(ETestFuncThrash1, aStatus);
402 return SendReceive(ETestFuncIpcTest);
406 return SendReceive(ETestFuncPanic);
412 test.Start(_L("BasicConsistency"));
414 // create a test server/process for each link variant
417 RDllWsd(_L("slave1"), _L("t_dllwsd")),
418 RDllWsd(_L("slave2"), _L("t_dllwsdd")),
419 RDllWsd(_L("slave3"), _L("t_dllwsdi")),
420 RDllWsd(_L("slave4"), _L("t_dllwsddi")),
421 RDllWsd(_L("slave5"), _L("t_dllwsd")),
422 RDllWsd(_L("slave6"), _L("t_dllwsdd")),
423 RDllWsd(_L("slave7"), _L("t_dllwsdi")),
424 RDllWsd(_L("slave8"), _L("t_dllwsddi"))
426 TInt nSlaves = sizeof(slaves)/sizeof(slaves[0]);
428 // do this a few times
429 for (TInt jj=0; jj<10; jj++)
431 // all four test variants
432 for (ii=0; ii<nSlaves; ii++)
434 // repeat the test different numbers of times, to ensure WSD values diverge
435 for (TInt kk=0; kk<ii+2; kk++)
437 // change order in which processes run the tests
438 int idx = (ii + jj) % nSlaves;
439 test_KErrNone(slaves[idx].ConsistencyTest());
442 // start and stop an extra process
443 RDllWsd extra(_L("slave9"), _L("t_dllwsddi"));
444 test_KErrNone(extra.ConsistencyTest());
448 for (ii=nSlaves-1; ii>=0; ii--)
456 test.Start(_L("ThrashTest1"));
458 // create a test server/process for each link variant
461 RDllWsd(_L("slaveA"), _L("t_dllwsd")),
462 RDllWsd(_L("slaveB"), _L("t_dllwsdd")),
463 RDllWsd(_L("slaveC"), _L("t_dllwsdi")),
464 RDllWsd(_L("slaveD"), _L("t_dllwsddi"))
467 TRequestStatus req[4];
469 // start the thrash tests
470 for (ii=0; ii<4; ii++)
472 slaves[ii].ThrashTest1(req[ii]);
473 test.Printf(_L("slave %d thrash started\n"), ii);
476 // show some progress to indicate that things are running
477 for (ii=0; ii<8; ii++)
479 test.Printf(_L("Waiting %d\n"), ii);
480 User::After(1000000);
482 // demonstrate that test processes are still doing their stuff
483 test.Printf(_L("Still a couple of seconds to wait...\n"));
485 // wait till the test process are done
486 for (ii=0; ii<4; ii++)
488 User::WaitForRequest(req[ii]);
489 // show how much each process did
490 test.Printf(_L("Slave %d count = %d\n"), ii, req[ii].Int());
491 test_NotNegative(req[ii].Int());
494 for (ii=3; ii>=0; ii--)
502 test.Start(_L("PanicTest1"));
504 // create a test server/process for each link variant
507 RDllWsd(_L("slaveP1"), _L("t_dllwsd")),
508 RDllWsd(_L("slaveP2"), _L("t_dllwsdd")),
509 RDllWsd(_L("slaveP3"), _L("t_dllwsdi")),
510 RDllWsd(_L("slaveP4"), _L("t_dllwsddi"))
513 for (ii=0; ii<4; ii++)
516 for (ii=0; ii<4; ii++)
522 test.Start(_L("IPC test"));
523 // these two processes will use t_dllwsddi, static link variant
524 RDllWsd server(_L("IpcTestServer"));
525 RDllWsd client(_L("IpcTestClient"));
526 // client will talk to IpcTestServer, ie the server
527 test_KErrNone(client.IpcTest());
536 test.Start(_L("Test"));
549 if (User::CommandLineLength() > 0) // command line contains server name