telephonyprotocols/csdagt/TS_CsdAgt/CsdAgtTestOOM.cpp
changeset 0 3553901f7fa8
child 24 6638e7f4bd8f
equal deleted inserted replaced
-1:000000000000 0:3553901f7fa8
       
     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 // CsdAgtTestClosure.cpp
       
    15 // This contains CsdAgt TestCase Test 4.1
       
    16 // 
       
    17 //
       
    18 
       
    19 // EPOC includes
       
    20 #include <e32base.h>
       
    21 #include <in_sock.h>
       
    22 
       
    23 // Test system includes
       
    24 #include "log.h"
       
    25 #include "teststep.h"
       
    26 #include "TestStepCsdAgt.h"
       
    27 #include "TestSuiteCsdAgt.h"
       
    28 
       
    29 // COMMDB Database Undo
       
    30 #include "DbUndo.h"
       
    31 
       
    32 // EConnectionOpen
       
    33 #include <csdprog.h>
       
    34 
       
    35 // Class definitions
       
    36 #include "CsdAgtTestOOM.h"
       
    37 
       
    38 #define MaxAllocationFailures 1500
       
    39 #define MaxConsecutiveSuccess 5		//maximum number of consecutive successful operations
       
    40 									//indicating that from now on the __HEAP_FAILNEXT()
       
    41 									//cannot cause a failure anymore
       
    42 
       
    43 /**
       
    44  * Test case 4.1
       
    45  *
       
    46  */
       
    47 enum TVerdict CCsdAgtTest4_1::doCsdAgtTestStepL( void )
       
    48 	{
       
    49 	TInt failCount=500;
       
    50 	TInt successCount=0;
       
    51 	TInt ret=-1;
       
    52 
       
    53 	TRealAgtNotify AgtNotify; 
       
    54 
       
    55 	AgtNotify.SetTestCase(10401);
       
    56 	SetGSMModeL(AgtNotify);
       
    57 
       
    58 	while(failCount < MaxAllocationFailures && successCount < MaxConsecutiveSuccess)
       
    59 		{
       
    60 		// Mark heap and set allocation to fail
       
    61 		__UHEAP_MARK;
       
    62 		__UHEAP_FAILNEXT(failCount);
       
    63 
       
    64 	    Log(_L("Incrementing __HEAP_FAILNEXT(%d) of %d"), failCount, MaxAllocationFailures);
       
    65 
       
    66 		// Connect, most likely fail at some point
       
    67 		TRAP(ret,NormalConnectL());
       
    68 	
       
    69 		User::After(200000); // Allow async libraries to unload
       
    70 
       
    71 		// Check all heap is free'd
       
    72 		__UHEAP_MARKEND;
       
    73 
       
    74 		if(ret == KErrNone)
       
    75 			{
       
    76 			// Allocation failure has been moved all the way through the test
       
    77 			// Succeeded after failCount allocations
       
    78 			//return iTestStepResult;
       
    79 
       
    80 			// Clear __UHEAP_FAILNEXT
       
    81 			__UHEAP_RESET;
       
    82 			
       
    83 			//Operation may succeed even in OOM test due to interuption 
       
    84 			//in propagating the exception, so let it to continue to the 
       
    85 			//maximum number of iterations. (the next iteration might fail)
       
    86 			Log(_L("Operation completed @ iteration %d"), failCount);
       
    87 
       
    88 			//Mark the success
       
    89 			//At this stage we don't know if it's a real success
       
    90 			successCount++;
       
    91 			}
       
    92 		else if(ret == KErrNoMemory)
       
    93 			{
       
    94 			// Reset test result to pass since the allocation failure most
       
    95 			// likely caused it to fail
       
    96 			iTestStepResult = EPass;
       
    97 
       
    98 			//Start counting the consecutive successful operations again
       
    99 			successCount=0;
       
   100 			}
       
   101 		else 
       
   102 			{
       
   103 			// Failure other than Memory failure this would be the result of a bug
       
   104 			iTestStepResult = EFail;
       
   105 			return iTestStepResult;
       
   106 			}
       
   107 		Log(_L("Run completed with %d after failcount of %d and successcount of %d"), ret, failCount, successCount);
       
   108 
       
   109 		// Try failing a little further into the process
       
   110 		failCount++;
       
   111 		}
       
   112 
       
   113 	if (failCount == MaxAllocationFailures)
       
   114 		{
       
   115 		// We have reached our maximum number of allocation failures
       
   116 		// There must be some other problem within the NormalConnect() function
       
   117 		iTestStepResult=EFail;
       
   118 		}
       
   119 
       
   120 	return iTestStepResult;
       
   121 	}