|
1 // Copyright (c) 2004-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 6 |
|
15 // |
|
16 // |
|
17 |
|
18 // EPOC includes |
|
19 #include <e32base.h> |
|
20 #include <dns_qry.h> |
|
21 #include <es_sock.h> |
|
22 |
|
23 // Test system includes |
|
24 #include "SocketTestSection6.h" |
|
25 |
|
26 |
|
27 // Test step 6.1 |
|
28 const TDesC& CSocketTest6_1::GetTestName() |
|
29 { |
|
30 _LIT(ret,"Test6.1"); |
|
31 return ret; |
|
32 } |
|
33 |
|
34 enum TVerdict CSocketTest6_1::InternalDoTestStepL( void ) |
|
35 { |
|
36 TVerdict verdict = EPass; |
|
37 |
|
38 Logger().WriteFormat(_L("Test Purpose: Out of Memory During Connect")); |
|
39 |
|
40 #if defined (_DEBUG_SOCKET_FUNCTIONS) |
|
41 |
|
42 // connect to esock |
|
43 Logger().WriteFormat(_L("Attempting to connect to socket server")); |
|
44 RSocketServ ss; |
|
45 TInt ret = OptimalConnect(ss); |
|
46 CleanupClosePushL(ss); |
|
47 Logger().WriteFormat(_L("Connect returned %S"), &EpocErrorToText(ret)); |
|
48 TESTL(KErrNone == ret); |
|
49 |
|
50 Logger().WriteFormat(_L("Starting OOM Connect loop")); |
|
51 TInt failure = 0; |
|
52 RSocketServ ss2; |
|
53 ret = -1; |
|
54 // ss.__DbgMarkHeap(); // in ESOCKMT leak checking is best done by shutting down the server |
|
55 |
|
56 while (ret != KErrNone) |
|
57 { |
|
58 Logger().WriteFormat(_L("Failing after %d allocs"), failure); |
|
59 ss.__DbgFailNext(failure); |
|
60 ret = OptimalConnect(ss2); |
|
61 // if (ret != KErrNone) |
|
62 // ss.__DbgCheckHeap(0); |
|
63 failure++; |
|
64 } |
|
65 Logger().WriteFormat(_L("Connected OK")); |
|
66 |
|
67 ss2.Close(); |
|
68 |
|
69 // ss.__DbgMarkEnd(0); |
|
70 ss.__DbgFailNext(-1); |
|
71 CleanupStack::Pop(&ss); |
|
72 ss.Close(); |
|
73 #else |
|
74 Logger().WriteFormat(_L("TestDisabled on release build.")); |
|
75 verdict = EInconclusive; |
|
76 #endif |
|
77 |
|
78 SetTestStepResult(verdict); |
|
79 return verdict; |
|
80 } |
|
81 |
|
82 // Test step 6.2 |
|
83 const TDesC& CSocketTest6_2::GetTestName() |
|
84 { |
|
85 _LIT(ret,"Test6.2"); |
|
86 return ret; |
|
87 } |
|
88 |
|
89 enum TVerdict CSocketTest6_2::InternalDoTestStepL( void ) |
|
90 { |
|
91 TVerdict verdict = EPass; |
|
92 |
|
93 Logger().WriteFormat(_L("Test Purpose: Out of Memory Conditions for Socket Open")); |
|
94 |
|
95 #if defined (_DEBUG_SOCKET_FUNCTIONS) |
|
96 |
|
97 // connect to esock |
|
98 Logger().WriteFormat(_L("Attempting to connect to socket server")); |
|
99 RSocketServ ss; |
|
100 TInt ret = OptimalConnect(ss); |
|
101 CleanupClosePushL(ss); |
|
102 Logger().WriteFormat(_L("Connect returned %S"), &EpocErrorToText(ret)); |
|
103 TESTL(KErrNone == ret); |
|
104 |
|
105 Logger().WriteFormat(_L("Trying FindProtocol")); |
|
106 TProtocolDesc protoInfo; |
|
107 ret = ss.FindProtocol(_L("Dummy Protocol 1"), protoInfo); |
|
108 Logger().WriteFormat(_L("FindProtocol returned %S"), &EpocErrorToText(ret)); |
|
109 TESTL(KErrNone == ret); |
|
110 |
|
111 // Flush any FailNext there might be hanging around. |
|
112 ss.__DbgFailNext(-1); |
|
113 |
|
114 // test OOM during socket open |
|
115 // ss.__DbgMarkHeap(); // in ESOCKMT leak checking is best done by shutting down the server |
|
116 TInt failure = 0; |
|
117 RSocket sock; |
|
118 ret = -1; |
|
119 Logger().WriteFormat(_L("Starting OOM Socket Open Loop")); |
|
120 while (ret != KErrNone) |
|
121 { |
|
122 Logger().WriteFormat(_L("Failing after %d allocs"), failure); |
|
123 ss.__DbgFailNext(failure); |
|
124 ret = sock.Open(ss, protoInfo.iAddrFamily, protoInfo.iSockType, protoInfo.iProtocol); |
|
125 failure++; |
|
126 } |
|
127 Logger().WriteFormat(_L("Opened socket OK")); |
|
128 sock.Close(); |
|
129 // ss.__DbgMarkEnd(0); |
|
130 |
|
131 // Flush any FailNext there might be hanging around. |
|
132 ss.__DbgFailNext(-1); |
|
133 CleanupStack::Pop(&ss); |
|
134 ss.Close(); |
|
135 |
|
136 #else |
|
137 Logger().WriteFormat(_L("TestDisabled on release build.")); |
|
138 verdict = EInconclusive; |
|
139 #endif |
|
140 |
|
141 SetTestStepResult(verdict); |
|
142 return verdict; |
|
143 } |
|
144 |
|
145 // Test step 6.3 |
|
146 const TDesC& CSocketTest6_3::GetTestName() |
|
147 { |
|
148 _LIT(ret,"Test6.3"); |
|
149 return ret; |
|
150 } |
|
151 |
|
152 enum TVerdict CSocketTest6_3::InternalDoTestStepL( void ) |
|
153 { |
|
154 TVerdict verdict = EPass; |
|
155 |
|
156 Logger().WriteFormat(_L("Test Purpose: Out of Memory Conditions for Host Resolver")); |
|
157 |
|
158 #if defined (_DEBUG_SOCKET_FUNCTIONS) |
|
159 |
|
160 // connect to esock |
|
161 Logger().WriteFormat(_L("Attempting to connect to socket server")); |
|
162 RSocketServ ss; |
|
163 TInt ret = OptimalConnect(ss); |
|
164 CleanupClosePushL(ss); |
|
165 Logger().WriteFormat(_L("Connect returned %S"), &EpocErrorToText(ret)); |
|
166 TESTL(KErrNone == ret); |
|
167 |
|
168 Logger().WriteFormat(_L("Trying FindProtocol")); |
|
169 TProtocolDesc protoInfo; |
|
170 ret = ss.FindProtocol(_L("Dummy Protocol 1"), protoInfo); |
|
171 Logger().WriteFormat(_L("FindProtocol returned %S"), &EpocErrorToText(ret)); |
|
172 TESTL(KErrNone == ret); |
|
173 |
|
174 // Host resolvers |
|
175 // ss.__DbgMarkHeap(); // in ESOCKMT leak checking is best done by shutting down the server |
|
176 TInt failure = 0; |
|
177 RHostResolver hResolv; |
|
178 ret = -1; |
|
179 Logger().WriteFormat(_L("Starting OOM Host Resolver Open Loop")); |
|
180 while (ret != KErrNone) |
|
181 { |
|
182 Logger().WriteFormat(_L("Failing after %d allocs"), failure); |
|
183 ss.__DbgFailNext(failure); |
|
184 ret = hResolv.Open(ss, protoInfo.iAddrFamily, protoInfo.iProtocol); |
|
185 failure++; |
|
186 } |
|
187 Logger().WriteFormat(_L("Opened host resolver OK")); |
|
188 hResolv.Close(); |
|
189 // ss.__DbgMarkEnd(0); |
|
190 |
|
191 // Flush any FailNext there might be hanging around. |
|
192 ss.__DbgFailNext(-1); |
|
193 |
|
194 // Test OOM on Query() |
|
195 Logger().WriteFormat(_L("Testing OOM handling of RHostResolver::Query()")); |
|
196 |
|
197 ret = hResolv.Open(ss, protoInfo.iAddrFamily, protoInfo.iProtocol); |
|
198 TESTL(KErrNone == ret); |
|
199 |
|
200 TDnsQueryBuf dnsQryBuf; |
|
201 TDnsRespABuf dnsRespABuf; |
|
202 dnsQryBuf().SetType(KDnsRRTypeA); |
|
203 dnsQryBuf().SetData(_L8("http://www.sample.net/")); |
|
204 |
|
205 // create a timer to catch esock hanging |
|
206 RTimer timer; |
|
207 timer.CreateLocal(); |
|
208 CleanupClosePushL(timer); |
|
209 const TUint oneSec(1000000); |
|
210 TRequestStatus timerStatus; |
|
211 TRequestStatus status(KErrNoMemory); |
|
212 TUint failCount(0); |
|
213 |
|
214 // slowly increase the fail count until success |
|
215 while(KErrNoMemory == status.Int() && failCount < 20) |
|
216 { |
|
217 Logger().WriteFormat(_L("Checking Query with %d allocs before failure"), failCount); |
|
218 ss.__DbgFailNext(failCount++); |
|
219 hResolv.Query(dnsQryBuf, dnsRespABuf, status); |
|
220 timer.After(timerStatus, oneSec); |
|
221 User::WaitForRequest(status, timerStatus); |
|
222 timer.Cancel(); |
|
223 User::WaitForAnyRequest(); |
|
224 } |
|
225 |
|
226 // check query eventually finished ok |
|
227 ss.__DbgFailNext(-1); |
|
228 TESTL(KErrNone == status.Int()); |
|
229 |
|
230 CleanupStack::PopAndDestroy(&timer); |
|
231 |
|
232 CleanupStack::Pop(&ss); |
|
233 ss.Close(); |
|
234 #else |
|
235 Logger().WriteFormat(_L("TestDisabled on release build.")); |
|
236 verdict = EInconclusive; |
|
237 #endif |
|
238 |
|
239 SetTestStepResult(verdict); |
|
240 return verdict; |
|
241 } |
|
242 |
|
243 // Test step 6.4 |
|
244 const TDesC& CSocketTest6_4::GetTestName() |
|
245 { |
|
246 _LIT(ret,"Test6.4"); |
|
247 return ret; |
|
248 } |
|
249 |
|
250 enum TVerdict CSocketTest6_4::InternalDoTestStepL( void ) |
|
251 { |
|
252 TVerdict verdict = EPass; |
|
253 |
|
254 Logger().WriteFormat(_L("Test Purpose: Out of Memory Conditions for Service Resolver")); |
|
255 |
|
256 #if defined (_DEBUG_SOCKET_FUNCTIONS) |
|
257 |
|
258 // connect to esock |
|
259 Logger().WriteFormat(_L("Attempting to connect to socket server")); |
|
260 RSocketServ ss; |
|
261 TInt ret = OptimalConnect(ss); |
|
262 CleanupClosePushL(ss); |
|
263 Logger().WriteFormat(_L("Connect returned %S"), &EpocErrorToText(ret)); |
|
264 TESTL(KErrNone == ret); |
|
265 |
|
266 Logger().WriteFormat(_L("Trying FindProtocol")); |
|
267 TProtocolDesc protoInfo; |
|
268 ret = ss.FindProtocol(_L("Dummy Protocol 1"), protoInfo); |
|
269 Logger().WriteFormat(_L("FindProtocol returned %S"), &EpocErrorToText(ret)); |
|
270 TESTL(KErrNone == ret); |
|
271 |
|
272 // Flush any FailNext there might be hanging around. |
|
273 ss.__DbgFailNext(-1); |
|
274 |
|
275 // service resolvers |
|
276 // ss.__DbgMarkHeap(); // in ESOCKMT leak checking is best done by shutting down the server |
|
277 TInt failure = 0; |
|
278 RServiceResolver sResolv; |
|
279 ret = -1; |
|
280 Logger().WriteFormat(_L("Starting OOM Service Resolver Open Loop")); |
|
281 while (ret != KErrNone) |
|
282 { |
|
283 Logger().WriteFormat(_L("Failing after %d allocs"), failure); |
|
284 ss.__DbgFailNext(failure); |
|
285 ret = sResolv.Open(ss, protoInfo.iAddrFamily, protoInfo.iSockType, protoInfo.iProtocol); |
|
286 failure++; |
|
287 } |
|
288 Logger().WriteFormat(_L("Created service resolver OK")); |
|
289 sResolv.Close(); |
|
290 // ss.__DbgMarkEnd(0); |
|
291 |
|
292 // Flush any FailNext there might be hanging around. |
|
293 ss.__DbgFailNext(-1); |
|
294 |
|
295 CleanupStack::Pop(&ss); |
|
296 ss.Close(); |
|
297 #else |
|
298 Logger().WriteFormat(_L("TestDisabled on release build.")); |
|
299 verdict = EInconclusive; |
|
300 #endif |
|
301 |
|
302 SetTestStepResult(verdict); |
|
303 return verdict; |
|
304 } |
|
305 |
|
306 // Test step 6.5 |
|
307 const TDesC& CSocketTest6_5::GetTestName() |
|
308 { |
|
309 _LIT(ret,"Test6.5"); |
|
310 return ret; |
|
311 } |
|
312 |
|
313 enum TVerdict CSocketTest6_5::InternalDoTestStepL( void ) |
|
314 { |
|
315 TVerdict verdict = EPass; |
|
316 |
|
317 Logger().WriteFormat(_L("Test Purpose: Out of Memory Conditions for Net Database")); |
|
318 |
|
319 #if defined (_DEBUG_SOCKET_FUNCTIONS) |
|
320 |
|
321 // connect to esock |
|
322 Logger().WriteFormat(_L("Attempting to connect to socket server")); |
|
323 RSocketServ ss; |
|
324 TInt ret = OptimalConnect(ss); |
|
325 CleanupClosePushL(ss); |
|
326 Logger().WriteFormat(_L("Connect returned %S"), &EpocErrorToText(ret)); |
|
327 TESTL(KErrNone == ret); |
|
328 |
|
329 Logger().WriteFormat(_L("Trying FindProtocol")); |
|
330 TProtocolDesc protoInfo; |
|
331 ret = ss.FindProtocol(_L("Dummy Protocol 1"), protoInfo); |
|
332 Logger().WriteFormat(_L("FindProtocol returned %S"), &EpocErrorToText(ret)); |
|
333 TESTL(KErrNone == ret); |
|
334 |
|
335 // Flush any FailNext there might be hanging around. |
|
336 ss.__DbgFailNext(-1); |
|
337 |
|
338 // net database |
|
339 // ss.__DbgMarkHeap(); // in ESOCKMT leak checking is best done by shutting down the server |
|
340 TInt failure = 0; |
|
341 RNetDatabase netDb; |
|
342 ret = -1; |
|
343 Logger().WriteFormat(_L("Starting OOM Net Database Open Loop")); |
|
344 while (ret != KErrNone) |
|
345 { |
|
346 Logger().WriteFormat(_L("Failing after %d allocs"), failure); |
|
347 ss.__DbgFailNext(failure); |
|
348 ret = netDb.Open(ss, protoInfo.iAddrFamily, protoInfo.iProtocol); |
|
349 failure++; |
|
350 } |
|
351 Logger().WriteFormat(_L("Created net database OK")); |
|
352 netDb.Close(); |
|
353 // ss.__DbgMarkEnd(0); |
|
354 |
|
355 // Flush any FailNext there might be hanging around. |
|
356 ss.__DbgFailNext(-1); |
|
357 |
|
358 CleanupStack::Pop(&ss); |
|
359 ss.Close(); |
|
360 #else |
|
361 Logger().WriteFormat(_L("TestDisabled on release build.")); |
|
362 verdict = EInconclusive; |
|
363 #endif |
|
364 |
|
365 SetTestStepResult(verdict); |
|
366 return verdict; |
|
367 } |
|
368 |