|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "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". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 #include <e32base.h> |
|
18 #include <e32property.h> |
|
19 #include <es_sock.h> |
|
20 #include <test/es_dummy.h> |
|
21 #include <in_sock.h> |
|
22 #include <test/testexecutestepbase.h> |
|
23 #include <test/testexecuteserverbase.h> |
|
24 |
|
25 |
|
26 class CLoopbackDrvTestServer : public CTestServer |
|
27 { |
|
28 public: |
|
29 CLoopbackDrvTestServer(); |
|
30 ~CLoopbackDrvTestServer(); |
|
31 static CTestServer* NewL(); |
|
32 virtual CTestStep* CreateTestStep(const TDesC& aStepName); |
|
33 |
|
34 private: |
|
35 }; |
|
36 |
|
37 class CTestStepLoopback : public CTestStep |
|
38 { |
|
39 public: |
|
40 CTestStepLoopback(); |
|
41 ~CTestStepLoopback(); |
|
42 enum TVerdict doTestStepL(); |
|
43 static const TDesC& GetTestName() |
|
44 { |
|
45 _LIT(KTestName, "tcploop"); |
|
46 return KTestName(); |
|
47 } |
|
48 // CTestSuiteIPC * iEsockSuite;// Pointer to the suite which owns this test |
|
49 }; |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 CTestServer* CLoopbackDrvTestServer::NewL() |
|
55 /** |
|
56 * @return - Instance of the test server |
|
57 * Called inside the MainL() function to create and start the |
|
58 * CTestServer derived server. |
|
59 */ |
|
60 { |
|
61 CTestServer * server = new (ELeave) CLoopbackDrvTestServer(); |
|
62 CleanupStack::PushL(server); |
|
63 |
|
64 // Either use a StartL or ConstructL, the latter will permit |
|
65 // Server Logging. |
|
66 |
|
67 //server->StartL(KServerName); |
|
68 _LIT(KServerName, "te_loopback"); |
|
69 server-> ConstructL(KServerName); |
|
70 CleanupStack::Pop(server); |
|
71 return server; |
|
72 } |
|
73 |
|
74 // EKA2 much simpler |
|
75 // Just an E32Main and a MainL() |
|
76 LOCAL_C void MainL() |
|
77 /** |
|
78 * Much simpler, uses the new Rendezvous() call to sync with the client |
|
79 */ |
|
80 { |
|
81 // Leave the hooks in for platform security |
|
82 #if (defined __DATA_CAGING__) |
|
83 RProcess().DataCaging(RProcess::EDataCagingOn); |
|
84 RProcess().SecureApi(RProcess::ESecureApiOn); |
|
85 #endif |
|
86 CActiveScheduler* sched=NULL; |
|
87 sched=new(ELeave) CActiveScheduler; |
|
88 CActiveScheduler::Install(sched); |
|
89 |
|
90 CTestServer* server = NULL; |
|
91 // Create the CTestServer derived server |
|
92 |
|
93 TRAPD(err,server = CLoopbackDrvTestServer::NewL()); |
|
94 if(!err) |
|
95 { |
|
96 // Sync with the client and enter the active scheduler |
|
97 RProcess::Rendezvous(KErrNone); |
|
98 sched->Start(); |
|
99 } |
|
100 delete server; |
|
101 delete sched; |
|
102 } |
|
103 |
|
104 // Only a DLL on emulator for typhoon and earlier |
|
105 |
|
106 GLDEF_C TInt E32Main() |
|
107 /** |
|
108 * @return - Standard Epoc error code on exit |
|
109 */ |
|
110 { |
|
111 CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
112 if(cleanup == NULL) |
|
113 { |
|
114 return KErrNoMemory; |
|
115 } |
|
116 TRAP_IGNORE(MainL()); |
|
117 delete cleanup; |
|
118 return KErrNone; |
|
119 } |
|
120 |
|
121 // Create a thread in the calling process |
|
122 // Emulator typhoon and earlier |
|
123 |
|
124 CLoopbackDrvTestServer::CLoopbackDrvTestServer() |
|
125 { |
|
126 } |
|
127 |
|
128 CLoopbackDrvTestServer::~CLoopbackDrvTestServer() |
|
129 { |
|
130 } |
|
131 |
|
132 |
|
133 CTestStep* CLoopbackDrvTestServer::CreateTestStep(const TDesC& aStepName) |
|
134 /** |
|
135 * @return - A CTestStep derived instance |
|
136 * Implementation of CTestServer pure virtual |
|
137 */ |
|
138 { |
|
139 if(aStepName.CompareF(CTestStepLoopback::GetTestName()) == 0) |
|
140 { |
|
141 CTestStepLoopback* ret = new(ELeave) CTestStepLoopback; |
|
142 ret->SetTestStepName(CTestStepLoopback::GetTestName()); |
|
143 return ret; |
|
144 } |
|
145 return NULL; |
|
146 } |
|
147 |
|
148 |
|
149 |
|
150 |
|
151 // constructor |
|
152 CTestStepLoopback::CTestStepLoopback() |
|
153 { |
|
154 } |
|
155 |
|
156 // destructor |
|
157 CTestStepLoopback::~CTestStepLoopback() |
|
158 { |
|
159 } |
|
160 |
|
161 enum TVerdict CTestStepLoopback::doTestStepL() |
|
162 { |
|
163 SetTestStepResult(EFail); |
|
164 |
|
165 // const TUid KPktTxKey = {0x104045dd}; |
|
166 // const TUid KPktRxKey = {0x104045de}; |
|
167 // const TUid KMeUid = {0x101F529F}; |
|
168 // TSecurityPolicy readPolicy(ECapability_None); |
|
169 // TSecurityPolicy writePolicy(ECapability_None); |
|
170 // TInt result = RProperty::Define(KMeUid, KPktTxKey .iUid, RProperty::EInt, readPolicy, writePolicy); |
|
171 // result = RProperty::Define(KMeUid, KPktRxKey .iUid, RProperty::EInt, readPolicy, writePolicy); |
|
172 |
|
173 |
|
174 RSocketServ ss; |
|
175 CleanupClosePushL(ss); |
|
176 Logger().WriteFormat(_L("Start: creating + starting connection")); |
|
177 User::LeaveIfError(ss.Connect()); |
|
178 RConnection conn; |
|
179 CleanupClosePushL(conn); |
|
180 User::LeaveIfError(conn.Open(ss)); |
|
181 User::LeaveIfError(conn.Start()); |
|
182 |
|
183 TInt srvPort; |
|
184 if(!GetIntFromConfig(_L("TcpLoop"), _L("Port"), srvPort)) |
|
185 { |
|
186 srvPort = 5002; |
|
187 } |
|
188 Logger().WriteFormat(_L("Start: creating server socket listening on %d"), srvPort); |
|
189 RSocket srv; |
|
190 CleanupClosePushL(srv); |
|
191 User::LeaveIfError(srv.Open(ss, KAfInet, KSockStream, KProtocolInetTcp, conn)); |
|
192 TInetAddr srvAddr(KAfInet); |
|
193 srvAddr.SetPort(srvPort); |
|
194 User::LeaveIfError(srv.Bind(srvAddr)); |
|
195 User::LeaveIfError(srv.Listen(5)); |
|
196 RSocket acc; |
|
197 CleanupClosePushL(acc); |
|
198 User::LeaveIfError(acc.Open(ss)); |
|
199 TRequestStatus accStat; |
|
200 srv.Accept(acc, accStat); |
|
201 |
|
202 Logger().WriteFormat(_L("Start: connecting client socket")); |
|
203 RSocket cli; |
|
204 CleanupClosePushL(cli); |
|
205 User::LeaveIfError(cli.Open(ss, KAfInet, KSockStream, KProtocolInetTcp, conn)); |
|
206 srvAddr.SetAddress(0xC0A80707); |
|
207 TRequestStatus cliStat; |
|
208 cli.Connect(srvAddr, cliStat); |
|
209 User::WaitForRequest(cliStat, accStat); |
|
210 User::WaitForRequest(cliStat, accStat); |
|
211 User::LeaveIfError(cliStat.Int()); |
|
212 User::LeaveIfError(accStat.Int()); |
|
213 |
|
214 //_LIT8(KTest, "jackdaws love my big sphinx of quartz"); |
|
215 |
|
216 TInt xferSize = 0; |
|
217 if(!GetIntFromConfig(_L("TcpLoop"), _L("xferSize"), xferSize)) |
|
218 { |
|
219 xferSize = 1 * 1000 * 1000; |
|
220 } |
|
221 TInt fc = User::FastCounter(); |
|
222 TInt txSize = 0; |
|
223 TInt txCnt = 0; |
|
224 TRequestStatus txStat(KErrNone); |
|
225 TBuf8<4096> txBuf; |
|
226 txBuf.SetMax(); |
|
227 TInt rxSize = 0; |
|
228 TInt rxCnt = -1; |
|
229 TRequestStatus rxStat(KErrNone); |
|
230 TBuf8<4096> rxBuf; |
|
231 |
|
232 Logger().WriteFormat(_L("Transferring %d bytes"), xferSize); |
|
233 while(rxSize < xferSize) |
|
234 { |
|
235 fc = User::FastCounter(); |
|
236 if(txStat.Int() != KRequestPending) |
|
237 { |
|
238 RDebug::Printf("tx status:%d, ", txStat.Int()); |
|
239 cli.Send(txBuf, 0, txStat); |
|
240 ++txCnt; |
|
241 txSize += txBuf.Length(); |
|
242 RDebug::Printf("tx #%d, %d, +%d\n", txCnt, fc, txBuf.Length()); |
|
243 } |
|
244 if(rxStat.Int() != KRequestPending) |
|
245 { |
|
246 RDebug::Printf("rx status:%d, ", rxStat.Int()); |
|
247 ++rxCnt; |
|
248 rxSize += rxBuf.Length(); |
|
249 RDebug::Printf("rx #%d, %d, +%d\n", rxCnt, fc, rxBuf.Length()); |
|
250 TSockXfrLength dummy; |
|
251 acc.RecvOneOrMore(rxBuf, 0, rxStat, dummy); |
|
252 } |
|
253 User::WaitForRequest(rxStat, txStat); |
|
254 } |
|
255 |
|
256 Logger().WriteFormat(_L("Transferred; %d writes, %d reads"), txCnt, rxCnt); |
|
257 |
|
258 // RProperty::Get(KUidSystemCategory, KPktTxKey .iUid, txCnt); |
|
259 // RProperty::Define(KUidSystemCategory, KPktRxKey .iUid, rxCnt); |
|
260 // Logger().WriteFormat(_L("Packet counts; %d sends, %d processes"), txCnt, rxCnt); |
|
261 |
|
262 |
|
263 CleanupStack::PopAndDestroy(5, &ss); |
|
264 |
|
265 SetTestStepResult(EPass); |
|
266 return TestStepResult(); |
|
267 }; |
|
268 |