|
1 // Copyright (c) 2001-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 "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 // This contains ESock Test cases from section 11 |
|
15 // |
|
16 // |
|
17 |
|
18 // EPOC includes |
|
19 #include <e32base.h> |
|
20 #include <in_sock.h> |
|
21 |
|
22 // Test system includes |
|
23 #include "EsockTestSection11.h" |
|
24 #include "esockopenserver.h" |
|
25 |
|
26 |
|
27 // Test step 11.1 |
|
28 const TDesC& CEsockTest11_1::GetTestName() |
|
29 { |
|
30 // store the name of this test case |
|
31 _LIT(ret,"Test11.1"); |
|
32 return ret; |
|
33 } |
|
34 |
|
35 CEsockTest11_1::~CEsockTest11_1() |
|
36 { |
|
37 } |
|
38 |
|
39 enum TVerdict CEsockTest11_1::easyTestStepL() |
|
40 { |
|
41 // get ip address to connect to |
|
42 TInetAddr addr; |
|
43 TESTL(GetIpAddressFromConfig(_L("Test_Common"), _L("ipAddress"), addr)); |
|
44 |
|
45 // get port number to connect to |
|
46 TInt port; |
|
47 TESTL(GetIntFromConfig(_L("Test_11.1"), _L("port"), port)); |
|
48 |
|
49 // set remote address port |
|
50 addr.SetPort(port); |
|
51 |
|
52 // open a TCP socket |
|
53 RSocket sock; |
|
54 CleanupClosePushL(sock); |
|
55 TInt nRet = sock.Open(iEsockSuite->iSocketServer, KAfInet, KSockStream, KProtocolInetTcp); |
|
56 TESTEL(KErrNone == nRet, nRet); |
|
57 |
|
58 // connect to the remote address |
|
59 TRequestStatus stat; |
|
60 sock.Connect(addr, stat); |
|
61 User::WaitForRequest(stat); |
|
62 TESTEL(stat==KErrNone, stat.Int()); |
|
63 |
|
64 // get the remote name of the connected socket |
|
65 TInetAddr addr1; |
|
66 sock.RemoteName(addr1); |
|
67 |
|
68 // check this matches the address we connected to |
|
69 TESTL(addr.CmpAddr(addr1)); |
|
70 |
|
71 CleanupStack::PopAndDestroy(1, &sock); |
|
72 return EPass; |
|
73 } |
|
74 |
|
75 |
|
76 // Test step 11.2 |
|
77 const TDesC& CEsockTest11_2::GetTestName() |
|
78 { |
|
79 // store the name of this test case |
|
80 _LIT(ret,"Test11.2"); |
|
81 |
|
82 return ret; |
|
83 } |
|
84 |
|
85 CEsockTest11_2::~CEsockTest11_2() |
|
86 { |
|
87 } |
|
88 |
|
89 enum TVerdict CEsockTest11_2::easyTestStepL() |
|
90 { |
|
91 TInt nRet; |
|
92 TProtocolDesc protocolInfo; |
|
93 |
|
94 // Get protocol information |
|
95 |
|
96 // open a TCP socket, retrieve the protocol info |
|
97 // and check the protocol ID |
|
98 RSocket sock1; |
|
99 CleanupClosePushL(sock1); |
|
100 nRet = sock1.Open(iEsockSuite->iSocketServer, KAfInet, KSockStream, KProtocolInetTcp); |
|
101 TESTEL(KErrNone == nRet, nRet); |
|
102 TESTL(sock1.Info(protocolInfo)==KErrNone); |
|
103 TESTL(protocolInfo.iProtocol==KProtocolInetTcp); |
|
104 CleanupStack::PopAndDestroy(1, &sock1); |
|
105 |
|
106 // open a UDP socket, retrieve the protocol info |
|
107 // and check the protocol ID |
|
108 RSocket sock2; |
|
109 CleanupClosePushL(sock2); |
|
110 nRet = sock2.Open(iEsockSuite->iSocketServer, KAfInet, KSockDatagram, KProtocolInetUdp); |
|
111 TESTEL(KErrNone == nRet, nRet); |
|
112 TESTL(sock2.Info(protocolInfo)==KErrNone); |
|
113 TESTL(protocolInfo.iProtocol==KProtocolInetUdp); |
|
114 CleanupStack::PopAndDestroy(1, &sock2); |
|
115 |
|
116 // open an ICMP socket, retrieve the protocol info |
|
117 // and check the protocol ID |
|
118 RSocket sock3; |
|
119 CleanupClosePushL(sock3); |
|
120 nRet = sock3.Open(iEsockSuite->iSocketServer, KAfInet, KSockDatagram, KProtocolInetIcmp); |
|
121 TESTEL(KErrNone == nRet, nRet); |
|
122 TESTL(sock3.Info(protocolInfo)==KErrNone); |
|
123 TESTL(protocolInfo.iProtocol==KProtocolInetIcmp); |
|
124 CleanupStack::PopAndDestroy(1, &sock3); |
|
125 |
|
126 // open an IP socket, retrieve the protocol info |
|
127 // and check the protocol ID |
|
128 RSocket sock4; |
|
129 CleanupClosePushL(sock4); |
|
130 nRet = sock4.Open(iEsockSuite->iSocketServer, KAfInet, KSockDatagram, KProtocolInetIp); |
|
131 TESTEL(KErrNone == nRet, nRet); |
|
132 TESTL(sock4.Info(protocolInfo)==KErrNone); |
|
133 TESTL(protocolInfo.iProtocol==KProtocolInetIp); |
|
134 CleanupStack::PopAndDestroy(1, &sock4); |
|
135 |
|
136 return EPass; |
|
137 } |
|
138 |
|
139 |
|
140 // Test step 11.3 |
|
141 const TDesC& CEsockTest11_3::GetTestName() |
|
142 { |
|
143 // store the name of this test case |
|
144 _LIT(ret,"Test11.3"); |
|
145 |
|
146 return ret; |
|
147 } |
|
148 |
|
149 CEsockTest11_3::~CEsockTest11_3() |
|
150 { |
|
151 } |
|
152 |
|
153 enum TVerdict CEsockTest11_3::easyTestStepL() |
|
154 { |
|
155 TInetAddr addrLocal, addrRemote; |
|
156 TRequestStatus wstat, wstat2, wstat3, rstat; |
|
157 TInt sockIndex1, sockIndex2, sockIndex3; |
|
158 |
|
159 const TInt KBufSize = 4024; |
|
160 // Constructs an empty 8 bit modifiable buffer descriptor. It contains no data. |
|
161 typedef TBuf8<KBufSize> TBuffer; |
|
162 |
|
163 // get local ip address |
|
164 TESTL(GetIpAddressFromConfig(_L("Test_11.3"), _L("ipAddressLocal"), addrLocal)); |
|
165 |
|
166 // get ip address to connect to (usually loopback) |
|
167 TESTL(GetIpAddressFromConfig(_L("Test_11.3"), _L("ipAddressRemote"), addrRemote)); |
|
168 |
|
169 // open socket and listen for connect requests |
|
170 TESTL(KErrNone == OpenListeningSocketL(addrLocal, sockIndex1)); |
|
171 |
|
172 // open active socket and make connect request |
|
173 TESTL(KErrNone == OpenActiveSocketL(addrRemote, sockIndex2)); |
|
174 |
|
175 // accept connect request |
|
176 TESTL(KErrNone == AcceptConnectionL(sockIndex3, sockIndex1)); |
|
177 |
|
178 TBuffer* wtemp=new (ELeave) TBuffer; |
|
179 CleanupStack::PushL(wtemp); |
|
180 TBuffer& wbuf=*wtemp; |
|
181 |
|
182 TBuffer* rtemp=new (ELeave) TBuffer; |
|
183 CleanupStack::PushL(rtemp); |
|
184 TBuffer& rbuf=*rtemp; |
|
185 |
|
186 wbuf.SetMax(); |
|
187 StripeDes(wbuf, 0, wbuf.Length(), '@', 'Z'); |
|
188 |
|
189 iEsockSuite->GetSocketHandle(sockIndex2).Send(wbuf, 0, wstat); |
|
190 iEsockSuite->GetSocketHandle(sockIndex2).Send(wbuf, 0, wstat2); |
|
191 iEsockSuite->GetSocketHandle(sockIndex2).Send(wbuf, 0, wstat3); |
|
192 iEsockSuite->GetSocketHandle(sockIndex2).CancelAll(); |
|
193 User::WaitForRequest(wstat); |
|
194 User::WaitForRequest(wstat2); |
|
195 User::WaitForRequest(wstat3); |
|
196 TESTEL(wstat==KErrNone || wstat==KErrCancel, wstat.Int()); |
|
197 TESTEL(wstat2==KErrNone || wstat2==KErrCancel, wstat2.Int()); |
|
198 TESTEL(wstat3==KErrNone || wstat3==KErrCancel, wstat3.Int()); |
|
199 |
|
200 Logger().WriteFormat(_L("stat1 %d stat2 %d stat3 %d"),wstat.Int(), wstat2.Int(), wstat3.Int()); |
|
201 |
|
202 iEsockSuite->GetSocketHandle(sockIndex3).Recv(rbuf, 0, rstat); |
|
203 iEsockSuite->GetSocketHandle(sockIndex3).CancelAll(); |
|
204 User::WaitForRequest(rstat); |
|
205 TESTEL(rstat==KErrNone || rstat==KErrCancel, rstat.Int()); |
|
206 |
|
207 iEsockSuite->GetSocketHandle(sockIndex2).Shutdown(RSocket::ENormal, wstat); |
|
208 iEsockSuite->GetSocketHandle(sockIndex3).Shutdown(RSocket::ENormal, rstat); |
|
209 iEsockSuite->GetSocketHandle(sockIndex2).CancelAll(); |
|
210 iEsockSuite->GetSocketHandle(sockIndex3).CancelAll(); |
|
211 User::WaitForRequest(wstat); |
|
212 User::WaitForRequest(rstat); |
|
213 TESTEL(wstat == KErrNone, wstat.Int()); |
|
214 TESTEL(rstat == KErrNone, rstat.Int()); |
|
215 |
|
216 CleanupStack::PopAndDestroy(2, wtemp); |
|
217 |
|
218 // shutdown the client socket - do not wait for completion |
|
219 CloseSockets(2); |
|
220 return EPass; |
|
221 } |
|
222 |
|
223 |
|
224 // Test step 11.4 |
|
225 const TDesC& CEsockTest11_4::GetTestName() |
|
226 { |
|
227 // store the name of this test case |
|
228 _LIT(ret,"Test11.4"); |
|
229 |
|
230 return ret; |
|
231 } |
|
232 |
|
233 CEsockTest11_4::~CEsockTest11_4() |
|
234 { |
|
235 } |
|
236 |
|
237 enum TVerdict CEsockTest11_4::easyTestStepL() |
|
238 { |
|
239 // |
|
240 // Out Of Memory Test on open() RSocket // |
|
241 // |
|
242 |
|
243 TVerdict verdict = EPass; |
|
244 |
|
245 Logger().WriteFormat(_L("TE_ESock: test 11.4")); |
|
246 Logger().WriteFormat(_L("RSocket Open")); |
|
247 |
|
248 #if defined (_DEBUG_SOCKET_FUNCTIONS) |
|
249 |
|
250 RSocketServ socketHelper; |
|
251 CleanupClosePushL(socketHelper); |
|
252 TInt ret = socketHelper.Connect(); |
|
253 TESTEL(KErrNone == ret, ret); |
|
254 |
|
255 // Create a socket on the helper to get the DND up & running |
|
256 RSocket sockHelper; |
|
257 CleanupClosePushL(sockHelper); |
|
258 ret = sockHelper.Open(socketHelper, KAfInet, KSockStream, KProtocolInetTcp); |
|
259 TESTEL(KErrNone == ret, ret); |
|
260 // Short wait for DND settle down |
|
261 User::After(5000000); |
|
262 socketHelper.__DbgMarkHeap(); |
|
263 |
|
264 RSocketServ socketServer; |
|
265 CleanupClosePushL(socketServer); |
|
266 ret = socketServer.Connect(); |
|
267 TESTEL(KErrNone == ret, ret); |
|
268 |
|
269 // See if we can crash the server: |
|
270 RSocket sock; |
|
271 CleanupClosePushL(sock); |
|
272 TInt failure = 0; |
|
273 |
|
274 verdict = EInconclusive; |
|
275 TInt prevResult = KErrNoMemory; |
|
276 TInt prevOccurs = 0; |
|
277 while (EInconclusive == verdict) |
|
278 { |
|
279 socketServer.__DbgFailNext(failure++); |
|
280 ret = sock.Open(socketServer, KAfInet, KSockStream, KProtocolInetTcp); |
|
281 |
|
282 if ((prevResult != ret) || (++prevOccurs >= 1000)) |
|
283 { |
|
284 Logger().WriteFormat(_L("%d loop(s), open socket returned %d"), prevOccurs, prevResult); |
|
285 if (KErrNone == ret) |
|
286 { |
|
287 verdict = EPass; |
|
288 } |
|
289 else if (KErrServerTerminated == ret) |
|
290 { |
|
291 verdict = EFail; |
|
292 } |
|
293 else if (prevResult != ret) |
|
294 { |
|
295 prevResult = ret; |
|
296 prevOccurs = 1; |
|
297 } |
|
298 else |
|
299 { |
|
300 prevOccurs = 0; |
|
301 } |
|
302 } |
|
303 }; |
|
304 |
|
305 socketServer.__DbgFailNext(-1); |
|
306 // wait for protocol families to unload - it's via an async callback and dependent upon the IP stack, which |
|
307 // may also be killing off DND. So a big delay is needed. If it proves unreliable in future then the really |
|
308 // strong approach would be shutting down ESOCK - it'll panic if it has allocations outstanding |
|
309 User::After(5000000); |
|
310 socketHelper.__DbgMarkEnd(0); |
|
311 CleanupStack::PopAndDestroy(4, &socketHelper); |
|
312 |
|
313 #else |
|
314 Logger().WriteFormat(_L("Test disabled on release build.")); |
|
315 #endif |
|
316 |
|
317 return verdict; |
|
318 } |
|
319 |