sl@0
|
1 |
// Copyright (c) 1998-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_ipcbm.cpp
|
sl@0
|
15 |
// Overview:
|
sl@0
|
16 |
// Test and benchmark the data copy in inter-process communication.
|
sl@0
|
17 |
// API Information:
|
sl@0
|
18 |
// RServer2, RSessionBase
|
sl@0
|
19 |
// Details:
|
sl@0
|
20 |
// - Create a server thread and write data blocks of varying sizes from the
|
sl@0
|
21 |
// server to client, increment a count after each write.
|
sl@0
|
22 |
// - Create a client session, connect to server and send data block size
|
sl@0
|
23 |
// to the server.
|
sl@0
|
24 |
// - Print the block size, total number of bytes written along with usec
|
sl@0
|
25 |
// per block.
|
sl@0
|
26 |
// - Verify that the heap was not corrupted by any of the tests.
|
sl@0
|
27 |
// Platforms/Drives/Compatibility:
|
sl@0
|
28 |
// All.
|
sl@0
|
29 |
// Assumptions/Requirement/Pre-requisites:
|
sl@0
|
30 |
// Failures and causes:
|
sl@0
|
31 |
// Base Port information:
|
sl@0
|
32 |
//
|
sl@0
|
33 |
//
|
sl@0
|
34 |
|
sl@0
|
35 |
#include <e32test.h>
|
sl@0
|
36 |
#include <e32def.h>
|
sl@0
|
37 |
#include <e32def_private.h>
|
sl@0
|
38 |
|
sl@0
|
39 |
LOCAL_D RTest test(_L("T_IPCBM"));
|
sl@0
|
40 |
|
sl@0
|
41 |
const TInt KBufferSize = 65536;
|
sl@0
|
42 |
|
sl@0
|
43 |
LOCAL_D TUint32* Src;
|
sl@0
|
44 |
LOCAL_D TUint32* Dest;
|
sl@0
|
45 |
LOCAL_D TInt Count=0;
|
sl@0
|
46 |
LOCAL_D RServer2 Server;
|
sl@0
|
47 |
LOCAL_D RSemaphore ServerSem;
|
sl@0
|
48 |
|
sl@0
|
49 |
|
sl@0
|
50 |
class RMySession : public RSessionBase
|
sl@0
|
51 |
{
|
sl@0
|
52 |
public:
|
sl@0
|
53 |
TInt Connect(RServer2 aSrv,TRequestStatus& aStat)
|
sl@0
|
54 |
{return CreateSession(aSrv,TVersion(),1,EIpcSession_Unsharable,0,&aStat);}
|
sl@0
|
55 |
void Test(TDes8& aDes)
|
sl@0
|
56 |
{Send(0,TIpcArgs(&aDes));}
|
sl@0
|
57 |
};
|
sl@0
|
58 |
|
sl@0
|
59 |
LOCAL_C TInt TestThread(TAny* aSize)
|
sl@0
|
60 |
{
|
sl@0
|
61 |
TInt r = Server.CreateGlobal(KNullDesC);
|
sl@0
|
62 |
ServerSem.Signal();
|
sl@0
|
63 |
if (r != KErrNone)
|
sl@0
|
64 |
return r;
|
sl@0
|
65 |
|
sl@0
|
66 |
RMessage2 m;
|
sl@0
|
67 |
Server.Receive(m);
|
sl@0
|
68 |
m.Complete(KErrNone); // connect message
|
sl@0
|
69 |
|
sl@0
|
70 |
Server.Receive(m);
|
sl@0
|
71 |
TInt size=(TInt)aSize;
|
sl@0
|
72 |
TPtrC8 src((const TUint8*)Src,size);
|
sl@0
|
73 |
FOREVER
|
sl@0
|
74 |
{
|
sl@0
|
75 |
m.Write(0,src);
|
sl@0
|
76 |
Count++;
|
sl@0
|
77 |
}
|
sl@0
|
78 |
}
|
sl@0
|
79 |
|
sl@0
|
80 |
const TInt KTestRunSeconds = 10;
|
sl@0
|
81 |
|
sl@0
|
82 |
LOCAL_C void RunTest(TInt aSize)
|
sl@0
|
83 |
{
|
sl@0
|
84 |
const TInt KTestRunUs = KTestRunSeconds * 1000000;
|
sl@0
|
85 |
|
sl@0
|
86 |
RThread t;
|
sl@0
|
87 |
TInt r=t.Create(KNullDesC,TestThread,0x1000,NULL,(TAny*)aSize);
|
sl@0
|
88 |
test(r==KErrNone);
|
sl@0
|
89 |
t.SetPriority(EPriorityLess);
|
sl@0
|
90 |
TRequestStatus s;
|
sl@0
|
91 |
t.Logon(s);
|
sl@0
|
92 |
t.Resume();
|
sl@0
|
93 |
ServerSem.Wait();
|
sl@0
|
94 |
test(Server.Handle() != KNullHandle);
|
sl@0
|
95 |
|
sl@0
|
96 |
RMySession sess;
|
sl@0
|
97 |
TRequestStatus stat;
|
sl@0
|
98 |
test(sess.Connect(Server,stat) == KErrNone);
|
sl@0
|
99 |
User::WaitForRequest(stat); // connected
|
sl@0
|
100 |
|
sl@0
|
101 |
Count=0;
|
sl@0
|
102 |
TPtr8 des((TUint8*)Dest, 0, aSize);
|
sl@0
|
103 |
sess.Test(des);
|
sl@0
|
104 |
User::After(KTestRunUs);
|
sl@0
|
105 |
t.Kill(0);
|
sl@0
|
106 |
User::WaitForRequest(s);
|
sl@0
|
107 |
sess.Close();
|
sl@0
|
108 |
Server.Close();
|
sl@0
|
109 |
CLOSE_AND_WAIT(t);
|
sl@0
|
110 |
|
sl@0
|
111 |
TInt us=10*KTestRunUs/Count;
|
sl@0
|
112 |
test.Printf(_L("%5d byte writes: %8d/%ds %4d.%01dus\n"),aSize,Count,KTestRunSeconds,us/10,us%10);
|
sl@0
|
113 |
}
|
sl@0
|
114 |
|
sl@0
|
115 |
GLDEF_C TInt E32Main()
|
sl@0
|
116 |
{
|
sl@0
|
117 |
test.Title();
|
sl@0
|
118 |
test.Start(_L("Benchmark IPC copy"));
|
sl@0
|
119 |
|
sl@0
|
120 |
__KHEAP_MARK;
|
sl@0
|
121 |
|
sl@0
|
122 |
TAny* buffer = User::Alloc(2 * KBufferSize + 32);
|
sl@0
|
123 |
test(buffer != 0);
|
sl@0
|
124 |
|
sl@0
|
125 |
Src = (TUint32*)((((TInt)buffer) & ~0x1f) + 0x20);
|
sl@0
|
126 |
Dest = (TUint32*)(((TInt)Src) + KBufferSize);
|
sl@0
|
127 |
|
sl@0
|
128 |
test(ServerSem.CreateLocal(0) == KErrNone);
|
sl@0
|
129 |
|
sl@0
|
130 |
static TInt KMaxCounts[] = { 16, 256, 512, 2048, 2052, 4096, 32768, 65536 };
|
sl@0
|
131 |
for (TUint i=0; i<sizeof KMaxCounts/sizeof KMaxCounts[0]; ++i)
|
sl@0
|
132 |
{
|
sl@0
|
133 |
RunTest(KMaxCounts[i]);
|
sl@0
|
134 |
}
|
sl@0
|
135 |
|
sl@0
|
136 |
ServerSem.Close();
|
sl@0
|
137 |
User::Free(buffer);
|
sl@0
|
138 |
|
sl@0
|
139 |
__KHEAP_MARKEND;
|
sl@0
|
140 |
|
sl@0
|
141 |
test.End();
|
sl@0
|
142 |
return KErrNone;
|
sl@0
|
143 |
}
|