os/security/crypto/weakcryptospi/test/kms/driver/test/kmslddtest/oom.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 2007-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 the License "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 * Framework function for running hardware key store OOM tests.
    16 *
    17 */
    18 
    19 
    20 /**
    21  @file
    22 */
    23 
    24 #include "kmslddtest.h"
    25 
    26 
    27 void RunOomTest(void (*aAllocFunc)(TRequestStatus&), void (*aFreeFunc)())
    28 /**
    29 	Test harness calls an allocating function in OOM, ensuring that no resources are leaked.
    30 
    31 	@param	aAllocFunc		This allocating function is called in OOM.  It is expected
    32 							to fail with KErrNoMemory, in which case no memory is leaked,
    33 							or to succeed with KErrNone.
    34 	@param	aFreeFunc		Cleans up resources allocated with aAllocFunc after aAllocFunc
    35 							succeeds.
    36  */
    37 	{
    38 	TInt r = KErrNoMemory;
    39 	for (TInt i = 1; r == KErrNoMemory; ++i)
    40 		{
    41 		__UHEAP_MARK;
    42 		__KHEAP_MARK;
    43 		
    44 		__KHEAP_SETFAIL(RAllocator::EDeterministic, i);
    45 		TRequestStatus rs;
    46 		aAllocFunc(rs);
    47 		User::WaitForRequest(rs);
    48 		r = rs.Int();
    49 		
    50 		test(r == KErrNone || r == KErrNoMemory);
    51 		if (r == KErrNone)
    52 			aFreeFunc();
    53 		
    54 		__KHEAP_MARKEND;
    55 		__UHEAP_MARKEND;
    56 		
    57 		__KHEAP_RESET;
    58 		__UHEAP_RESET;
    59 		}
    60 	}
    61