os/security/cryptoservices/filebasedcertificateandkeystores/source/generic/server/tokenserverdebug.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/security/cryptoservices/filebasedcertificateandkeystores/source/generic/server/tokenserverdebug.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,116 @@
     1.4 +/*
     1.5 +* Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of the License "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description: 
    1.18 +* tokenserverdebug.h
    1.19 +*
    1.20 +*/
    1.21 +
    1.22 + 
    1.23 +#ifdef _DEBUG
    1.24 +
    1.25 +#include "tokenserverdebug.h"
    1.26 +#include <f32file.h>
    1.27 +
    1.28 +TInt TokenServerDebug::iCounter = 0;
    1.29 +TInt TokenServerDebug::iStartCount = 0;
    1.30 +TInt TokenServerDebug::iPauseCount = 0;
    1.31 +TInt TokenServerDebug::iInitialAllocCount = 0;
    1.32 +
    1.33 +_LIT(KHeapErrorFile, "\\fsserver_heap_error");
    1.34 +
    1.35 +void TokenServerDebug::StartOOMTest()
    1.36 +	{
    1.37 +	iStartCount = User::CountAllocCells();
    1.38 +	iCounter = 0;
    1.39 +	}
    1.40 +
    1.41 +void TokenServerDebug::IncHeapFailPoint()
    1.42 +	{
    1.43 +	__UHEAP_FAILNEXT(iCounter);	
    1.44 +	++iCounter;
    1.45 +	}
    1.46 +
    1.47 +void TokenServerDebug::ResetHeapFail()
    1.48 +	{
    1.49 +	__UHEAP_RESET;
    1.50 +	}
    1.51 +
    1.52 +void TokenServerDebug::PauseOOMTest()
    1.53 +	{
    1.54 +	ASSERT(iPauseCount == 0); // Don't nest
    1.55 +	if (iCounter)
    1.56 +		{
    1.57 +		__UHEAP_RESET;
    1.58 +		iPauseCount = User::CountAllocCells();
    1.59 +		}
    1.60 +	}
    1.61 +
    1.62 +void TokenServerDebug::ResumeOOMTest()
    1.63 +	{
    1.64 +	if (iCounter)
    1.65 +		{
    1.66 +		ASSERT(iPauseCount > 0);
    1.67 +		__UHEAP_FAILNEXT(iCounter - (iPauseCount - iStartCount));
    1.68 +		iPauseCount = 0;
    1.69 +		}
    1.70 +	}
    1.71 +
    1.72 +void TokenServerDebug::HeapCheckStart()
    1.73 +	{
    1.74 +	iInitialAllocCount = User::CountAllocCells();
    1.75 +	}
    1.76 +
    1.77 +void TokenServerDebug::HeapCheckEnd()
    1.78 +	{
    1.79 +	TInt finalAllocCount = User::CountAllocCells();
    1.80 +	TRAP_IGNORE(HeapErrorL(finalAllocCount != iInitialAllocCount));
    1.81 +	// ignore errors
    1.82 +	}
    1.83 +
    1.84 +/**
    1.85 + * Write or delete a file to signify to the test code that there's a memory leak
    1.86 + * in the server.  This is unfortunately the best way of doing it since we can't
    1.87 + * trap a panic when the server's shutting down.
    1.88 + */
    1.89 +void TokenServerDebug::HeapErrorL(TBool aError)
    1.90 +	{
    1.91 +	RFs fs;
    1.92 +	User::LeaveIfError(fs.Connect());
    1.93 +	
    1.94 +	TDriveUnit sysDrive (fs.GetSystemDrive());
    1.95 +	TDriveName driveName(sysDrive.Name());
    1.96 +	TFileName heapErrFile (driveName);
    1.97 +	heapErrFile.Append(KHeapErrorFile);
    1.98 +	
    1.99 +	if (aError)
   1.100 +		{
   1.101 +		RFile file;
   1.102 +		TInt err = file.Create(fs, heapErrFile, EFileWrite | EFileShareExclusive);
   1.103 +		if (err != KErrNone || err != KErrAlreadyExists)
   1.104 +			{
   1.105 +			User::Leave(err);
   1.106 +			}
   1.107 +		file.Close();
   1.108 +		}
   1.109 +	else
   1.110 +		{
   1.111 +		TInt err = fs.Delete(heapErrFile);
   1.112 +		if (err != KErrNone && err != KErrNotFound)
   1.113 +			{
   1.114 +			User::Leave(err);
   1.115 +			}
   1.116 +		}
   1.117 +	}
   1.118 +
   1.119 +#endif