datacommsserver/esockserver/test/TE_Socket/SocketTestSection7.cpp
changeset 0 dfb7c4ff071f
equal deleted inserted replaced
-1:000000000000 0:dfb7c4ff071f
       
     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 7
       
    15 // 
       
    16 //
       
    17 
       
    18 // EPOC includes
       
    19 #include <e32base.h>
       
    20 
       
    21 // Test system includes
       
    22 #include "SocketTestSection7.h"
       
    23 
       
    24 
       
    25 // Test step 7.1
       
    26 const TDesC& CSocketTest7_1::GetTestName()
       
    27 	{
       
    28 	_LIT(ret,"Test7.1");
       
    29 	return ret;
       
    30 	}
       
    31 
       
    32 enum TVerdict CSocketTest7_1::InternalDoTestStepL( void )
       
    33 	{
       
    34 	TVerdict verdict = EPass;
       
    35 	
       
    36 	Logger().WriteFormat(_L("Test Purpose: Alloc Heaven during socket open"));
       
    37 	
       
    38 #if defined (_DEBUG_SOCKET_FUNCTIONS)
       
    39 	
       
    40 	// connect to esock
       
    41 	Logger().WriteFormat(_L("Attempting to connect to socket server"));
       
    42     RSocketServ ss;
       
    43 	TInt ret = OptimalConnect(ss);
       
    44 	CleanupClosePushL(ss);
       
    45 	Logger().WriteFormat(_L("Connect returned %S"), &EpocErrorToText(ret));
       
    46 	TESTL(KErrNone == ret);
       
    47 	
       
    48 	// get a protocol
       
    49 	Logger().WriteFormat(_L("Attempting to FindProtocol dummy protocol 1"));
       
    50 	TProtocolDesc protoInfo;
       
    51 	ret = ss.FindProtocol(_L("Dummy Protocol 1"), protoInfo);
       
    52 	Logger().WriteFormat(_L("FindProtocol returned %S"), &EpocErrorToText(ret));
       
    53 	TESTL(KErrNone == ret);
       
    54 	
       
    55 	// Stretch socket arrays in the  server.
       
    56 	RSocket *sockets = new (ELeave) RSocket[KNumStretchOpens];
       
    57 	CleanupArrayDeletePushL(sockets);
       
    58 	TInt i;
       
    59 	Logger().WriteFormat(_L("Attempting to Open %d sockets"), KNumStretchOpens);
       
    60 	for (i=0; i<KNumStretchOpens; i++)
       
    61 		{
       
    62 		ret = sockets[i].Open(ss, protoInfo.iAddrFamily, protoInfo.iSockType, protoInfo.iProtocol);
       
    63 		if (KErrNone != ret)
       
    64 			{
       
    65 			Logger().WriteFormat(_L("Open returned %S for socket %d"), &EpocErrorToText(ret), i);
       
    66 			TESTL(EFalse);
       
    67 			}
       
    68 		}
       
    69 	
       
    70 	Logger().WriteFormat(_L("Closing the first %d sockets"), KNumStretchOpens-1);
       
    71 	for (i=0; i<KNumStretchOpens-1; i++)
       
    72 		{
       
    73 		sockets[i].Close();
       
    74 		}
       
    75 	
       
    76 	RSocket sock;
       
    77 	TInt failure = 0;
       
    78 	ret = -1;
       
    79 	Logger().WriteFormat(_L("Starting OOM Socket Open Loop"));
       
    80 	//	ss.__DbgMarkHeap();		// in ESOCKMT leak checking is best done by shutting down the server
       
    81 	while (ret != KErrNone)
       
    82 		{
       
    83 		Logger().WriteFormat(_L("Failing after %d allocs"), failure);
       
    84 		ss.__DbgFailNext(failure);
       
    85 		ret = sock.Open(ss, protoInfo.iAddrFamily, protoInfo.iSockType, protoInfo.iProtocol);
       
    86 		//		if (ret != KErrNone)
       
    87 		//			{
       
    88 		//			ss.__DbgCheckHeap(0);
       
    89 		//			}
       
    90 		failure++;
       
    91 		}
       
    92 	Logger().WriteFormat(_L("Created socket OK"));
       
    93 	
       
    94 	sockets[KNumStretchOpens-1].Close();
       
    95 	CleanupStack::PopAndDestroy(sockets);
       
    96 	sock.Close();
       
    97 	//	ss.__DbgMarkEnd(0);
       
    98 	
       
    99 	// Flush any FailNext there might be hanging around.
       
   100 	ss.__DbgFailNext(-1);
       
   101 	
       
   102 	CleanupStack::Pop(&ss);
       
   103 	ss.Close();
       
   104 #else
       
   105 	Logger().WriteFormat(_L("TestDisabled on release build."));
       
   106 	verdict = EInconclusive;
       
   107 #endif
       
   108 	
       
   109 	SetTestStepResult(verdict);
       
   110 	return verdict;
       
   111 	}
       
   112 
       
   113 
       
   114 // Test step 7.2
       
   115 const TDesC& CSocketTest7_2::GetTestName()
       
   116 	{
       
   117 	_LIT(ret,"Test7.2");
       
   118 	return ret;
       
   119 	}
       
   120 
       
   121 enum TVerdict CSocketTest7_2::InternalDoTestStepL( void )
       
   122 	{
       
   123 	TVerdict verdict = EPass;
       
   124 	
       
   125 	Logger().WriteFormat(_L("Test Purpose: Alloc Heaven during host resolver open"));
       
   126 	
       
   127 #if defined (_DEBUG_SOCKET_FUNCTIONS)
       
   128 	
       
   129 	// connect to esock
       
   130 	Logger().WriteFormat(_L("Attempting to connect to socket server"));
       
   131     RSocketServ ss;
       
   132 	TInt ret = OptimalConnect(ss);
       
   133 	CleanupClosePushL(ss);
       
   134 	Logger().WriteFormat(_L("Connect returned %S"), &EpocErrorToText(ret));
       
   135 	TESTL(KErrNone == ret);
       
   136 	
       
   137 	// get a protocol
       
   138 	Logger().WriteFormat(_L("Attempting to FindProtocol dummy protocol 1"));
       
   139 	TProtocolDesc protoInfo;
       
   140 	ret = ss.FindProtocol(_L("Dummy Protocol 1"), protoInfo);
       
   141 	Logger().WriteFormat(_L("FindProtocol returned %S"), &EpocErrorToText(ret));
       
   142 	TESTL(KErrNone == ret);
       
   143 	
       
   144 	// Stretch host resolver arrays in the  server.
       
   145 	RHostResolver *hrs = new (ELeave) RHostResolver[KNumStretchOpens];
       
   146 	CleanupArrayDeletePushL(hrs);
       
   147 	
       
   148 	Logger().WriteFormat(_L("Attempting to Open %d host resolvers"), KNumStretchOpens);
       
   149 	TInt i;
       
   150 	for (i=0; i<KNumStretchOpens; i++)
       
   151 		{
       
   152 		ret = hrs[i].Open(ss, protoInfo.iAddrFamily, protoInfo.iProtocol);
       
   153 		if (KErrNone != ret)
       
   154 			{
       
   155 			Logger().WriteFormat(_L("Open returned %S for host resolver %d"), &EpocErrorToText(ret), i);
       
   156 			TESTL(EFalse);
       
   157 			}
       
   158 		}
       
   159 	
       
   160 	Logger().WriteFormat(_L("Closing the first %d host resolvers"), KNumStretchOpens-1);
       
   161 	for (i=0; i<KNumStretchOpens-1; i++)
       
   162 		{
       
   163 		hrs[i].Close();
       
   164 		}
       
   165 	
       
   166 	RHostResolver hr;
       
   167 	TInt failure = 0;
       
   168 	ret = -1;
       
   169 	Logger().WriteFormat(_L("Starting OOM Host Resolver Open Loop"));
       
   170 	//	ss.__DbgMarkHeap();		// in ESOCKMT leak checking is best done by shutting down the server
       
   171 	while (ret != KErrNone)
       
   172 		{
       
   173 		Logger().WriteFormat(_L("Failing after %d allocs"), failure);
       
   174 		ss.__DbgFailNext(failure);
       
   175 		ret = hr.Open(ss, protoInfo.iAddrFamily, protoInfo.iProtocol);
       
   176 		//		if (ret != KErrNone)
       
   177 		//			{
       
   178 		//			ss.__DbgCheckHeap(0);
       
   179 		//			}
       
   180 		failure++;
       
   181 		}
       
   182 	Logger().WriteFormat(_L("Created Host Resolver OK"));
       
   183 	
       
   184 	hrs[KNumStretchOpens-1].Close();
       
   185 	CleanupStack::PopAndDestroy(hrs);
       
   186 	hr.Close();
       
   187 	//	ss.__DbgMarkEnd(0);
       
   188 	
       
   189 	// Flush any FailNext there might be hanging around.
       
   190 	ss.__DbgFailNext(-1);
       
   191 	
       
   192 	CleanupStack::Pop(&ss);
       
   193 	ss.Close();
       
   194 #else
       
   195 	Logger().WriteFormat(_L("TestDisabled on release build."));
       
   196 	verdict = EInconclusive;
       
   197 #endif
       
   198 	
       
   199 	SetTestStepResult(verdict);
       
   200 	return verdict;
       
   201 	}
       
   202 
       
   203 // Test step 7.3
       
   204 const TDesC& CSocketTest7_3::GetTestName()
       
   205 	{
       
   206 	_LIT(ret,"Test7.3");
       
   207 	return ret;
       
   208 	}	
       
   209 
       
   210 enum TVerdict CSocketTest7_3::InternalDoTestStepL( void )
       
   211 	{
       
   212 	TVerdict verdict = EPass;
       
   213 	
       
   214 	Logger().WriteFormat(_L("Test Purpose: Alloc Heaven for service resolver open"));
       
   215 	
       
   216 #if defined (_DEBUG_SOCKET_FUNCTIONS)
       
   217 	
       
   218 	// connect to esock
       
   219 	Logger().WriteFormat(_L("Attempting to connect to socket server"));
       
   220     RSocketServ ss;
       
   221 	TInt ret = OptimalConnect(ss);
       
   222 	CleanupClosePushL(ss);
       
   223 	Logger().WriteFormat(_L("Connect returned %S"), &EpocErrorToText(ret));
       
   224 	TESTL(KErrNone == ret);
       
   225 	
       
   226 	// get a protocol
       
   227 	Logger().WriteFormat(_L("Attempting to FindProtocol dummy protocol 1"));
       
   228 	TProtocolDesc protoInfo;
       
   229 	ret = ss.FindProtocol(_L("Dummy Protocol 1"), protoInfo);
       
   230 	Logger().WriteFormat(_L("FindProtocol returned %S"), &EpocErrorToText(ret));
       
   231 	TESTL(KErrNone == ret);
       
   232 	
       
   233 	// Stretch service resolver arrays in the server.
       
   234 	RServiceResolver *srs = new (ELeave) RServiceResolver[KNumStretchOpens];
       
   235 	CleanupArrayDeletePushL(srs);
       
   236 	TInt i;
       
   237 	Logger().WriteFormat(_L("Attempting to Open %d service resolvers"), KNumStretchOpens);
       
   238 	for (i=0; i<KNumStretchOpens; i++)
       
   239 		{
       
   240 		ret = srs[i].Open(ss, protoInfo.iAddrFamily, protoInfo.iSockType, protoInfo.iProtocol);
       
   241 		if (KErrNone != ret)
       
   242 			{
       
   243 			Logger().WriteFormat(_L("Open returned %S for service resolver %d"), &EpocErrorToText(ret), i);
       
   244 			TESTL(EFalse);
       
   245 			}
       
   246 		}
       
   247 	
       
   248 	Logger().WriteFormat(_L("Closing the first %d service resolvers"), KNumStretchOpens-1);
       
   249 	for (i=0; i<KNumStretchOpens-1; i++)
       
   250 		{
       
   251 		srs[i].Close();
       
   252 		}
       
   253 	
       
   254 	RServiceResolver sr;
       
   255 	TInt failure = 0;
       
   256 	ret = -1;
       
   257 	Logger().WriteFormat(_L("Starting OOM Service Resolver Open Loop"));
       
   258 	//	ss.__DbgMarkHeap();		// in ESOCKMT leak checking is best done by shutting down the server
       
   259 	while (ret != KErrNone)
       
   260 		{
       
   261 		Logger().WriteFormat(_L("Failing after %d allocs"), failure);
       
   262 		ss.__DbgFailNext(failure);
       
   263 		ret = sr.Open(ss, protoInfo.iAddrFamily, protoInfo.iSockType, protoInfo.iProtocol);
       
   264 		//		if (ret != KErrNone)
       
   265 		//			{
       
   266 		//			ss.__DbgCheckHeap(0);
       
   267 		//			}
       
   268 		failure++;
       
   269 		}
       
   270 	Logger().WriteFormat(_L("Created service resolver OK"));
       
   271 	
       
   272 	srs[KNumStretchOpens-1].Close();
       
   273 	CleanupStack::PopAndDestroy(srs);
       
   274 	sr.Close();
       
   275 	//	ss.__DbgMarkEnd(0);
       
   276 	
       
   277 	// Flush any FailNext there might be hanging around.
       
   278 	ss.__DbgFailNext(-1);
       
   279 	
       
   280 	CleanupStack::Pop(&ss);
       
   281 	ss.Close();
       
   282 #else
       
   283 	Logger().WriteFormat(_L("TestDisabled on release build."));
       
   284 	verdict = EInconclusive;
       
   285 #endif
       
   286 	
       
   287 	SetTestStepResult(verdict);
       
   288 	return verdict;
       
   289 	}
       
   290 
       
   291 // Test step 7.4
       
   292 const TDesC& CSocketTest7_4::GetTestName()
       
   293 	{
       
   294 	_LIT(ret,"Test7.4");
       
   295 	return ret;
       
   296 	}
       
   297 
       
   298 enum TVerdict CSocketTest7_4::InternalDoTestStepL( void )
       
   299 	{
       
   300 	TVerdict verdict = EPass;
       
   301 	
       
   302 	Logger().WriteFormat(_L("Test Purpose: Alloc Heaven for net database open"));
       
   303 	
       
   304 #if defined (_DEBUG_SOCKET_FUNCTIONS)
       
   305 	
       
   306 	// connect to esock
       
   307 	Logger().WriteFormat(_L("Attempting to connect to socket server"));
       
   308     RSocketServ ss;
       
   309 	TInt ret = OptimalConnect(ss);
       
   310 	CleanupClosePushL(ss);
       
   311 	Logger().WriteFormat(_L("Connect returned %S"), &EpocErrorToText(ret));
       
   312 	TESTL(KErrNone == ret);
       
   313 	
       
   314 	// get a protocol
       
   315 	Logger().WriteFormat(_L("Attempting to FindProtocol dummy protocol 1"));
       
   316 	TProtocolDesc protoInfo;
       
   317 	ret = ss.FindProtocol(_L("Dummy Protocol 1"), protoInfo);
       
   318 	Logger().WriteFormat(_L("FindProtocol returned %S"), &EpocErrorToText(ret));
       
   319 	TESTL(KErrNone == ret);
       
   320 	
       
   321 	// Stretch net database arrays in the server.
       
   322 	RNetDatabase *ndbs = new (ELeave) RNetDatabase[KNumStretchOpens];
       
   323 	CleanupArrayDeletePushL(ndbs);
       
   324 	
       
   325 	Logger().WriteFormat(_L("Attempting to Open %d net databases"), KNumStretchOpens);
       
   326 	TInt i;
       
   327 	for (i=0; i<KNumStretchOpens; i++)
       
   328 		{
       
   329 		ret = ndbs[i].Open(ss, protoInfo.iAddrFamily, protoInfo.iProtocol);
       
   330 		if (KErrNone != ret)
       
   331 			{
       
   332 			Logger().WriteFormat(_L("Open returned %S for net database %d"), &EpocErrorToText(ret), i);
       
   333 			TESTL(EFalse);
       
   334 			}
       
   335 		}
       
   336 	
       
   337 	Logger().WriteFormat(_L("Closing the first %d net databases"), KNumStretchOpens-1);
       
   338 	for (i=0; i<KNumStretchOpens-1; i++)
       
   339 		{
       
   340 		ndbs[i].Close();
       
   341 		}
       
   342 	
       
   343 	RNetDatabase ndb;
       
   344 	TInt failure = 0;
       
   345 	ret = -1;
       
   346 	Logger().WriteFormat(_L("Starting OOM Net Database Open Loop"));
       
   347 	//	ss.__DbgMarkHeap();		// in ESOCKMT leak checking is best done by shutting down the server
       
   348 	while (ret != KErrNone)
       
   349 		{
       
   350 		Logger().WriteFormat(_L("Failing after %d allocs"), failure);
       
   351 		ss.__DbgFailNext(failure);
       
   352 		ret = ndb.Open(ss, protoInfo.iAddrFamily, protoInfo.iProtocol);
       
   353 		//		if (ret != KErrNone)
       
   354 		//			{
       
   355 		//			ss.__DbgCheckHeap(0);
       
   356 		//			}
       
   357 		failure++;
       
   358 		}
       
   359 	Logger().WriteFormat(_L("Created net database OK"));
       
   360 	
       
   361 	ndbs[KNumStretchOpens-1].Close();
       
   362 	CleanupStack::PopAndDestroy(ndbs);
       
   363 	ndb.Close();
       
   364 	//	ss.__DbgMarkEnd(0);
       
   365 	
       
   366 	// Flush any FailNext there might be hanging around.
       
   367 	ss.__DbgFailNext(-1);
       
   368 	
       
   369 	CleanupStack::Pop(&ss);
       
   370 	ss.Close();
       
   371 #else
       
   372 	Logger().WriteFormat(_L("TestDisabled on release build."));
       
   373 	verdict = EInconclusive;
       
   374 #endif
       
   375 	SetTestStepResult(verdict);
       
   376 	return verdict;
       
   377 	}
       
   378