windowing/windowserver/test/t_integ/src/t_simloadutils.cpp
changeset 36 01a6848ebfd7
parent 0 5d03bc08d59c
child 43 7579f232bae7
child 45 36b2e23a8629
equal deleted inserted replaced
0:5d03bc08d59c 36:01a6848ebfd7
     1 // Copyright (c) 2007-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 //
       
    15 
       
    16 /**
       
    17  @file
       
    18  @test
       
    19  @internalComponent
       
    20 */
       
    21 
       
    22 #include <e32math.h>
       
    23 #include <e32debug.h>
       
    24 #include <cinidata.h>
       
    25 #include "t_inidata.h"
       
    26 #include "t_simloadutils.h"
       
    27 #include "t_wservconsts.h"
       
    28 
       
    29 EXPORT_C TBool CTSimLoadAppUtils::SpikedLoadL()
       
    30 	{
       
    31 	TBool ret = EFalse;
       
    32 	
       
    33 	HBufC* simLoadType = NULL;
       
    34 	simLoadType = CTIniData::ReadStrL(KConfigSimLoadType(), KWServSimLoadConfigFile);
       
    35 	
       
    36 	if (simLoadType!=NULL && simLoadType->Des().Compare(_L("KSimLoadSpiked")) == KErrNone)
       
    37 		{
       
    38 		ret = ETrue;
       
    39 		}
       
    40 	
       
    41 	return ret;
       
    42 	}
       
    43 
       
    44 EXPORT_C TBool CTSimLoadAppUtils::StaticLoadL()
       
    45 	{
       
    46 	TBool ret = EFalse;
       
    47 	
       
    48 	HBufC* simLoadType = NULL;
       
    49 	simLoadType = CTIniData::ReadStrL(KConfigSimLoadType(), KWServSimLoadConfigFile);
       
    50 	
       
    51 	if (simLoadType!=NULL && simLoadType->Des().Compare(_L("KSimLoadStatic")) == KErrNone)
       
    52 		{
       
    53 		ret = ETrue;
       
    54 		}
       
    55 	
       
    56 	return ret;
       
    57 	}
       
    58 
       
    59 EXPORT_C TInt CTSimLoadAppUtils::SimLoadL()
       
    60 	{
       
    61 	return CTIniData::ReadIntL(KConfigSimLoadValue(), KWServSimLoadConfigFile);
       
    62 	}
       
    63 	
       
    64 EXPORT_C void CTSimLoadAppUtils::SimulateStaticLoadL(const TInt& aLoadPercentage, const TInt& aDelay)
       
    65 	{
       
    66 	if (aLoadPercentage>=0)
       
    67 		{
       
    68 		// assuming the figure read in was '%' calculate the loop count
       
    69 		// required to achieve the simulated load required
       
    70 		TInt mySimLoad = CalculateSimLoadL(aLoadPercentage);
       
    71 		
       
    72 		TInt internalDelay = aDelay;
       
    73 		
       
    74 		if (aLoadPercentage==0)
       
    75 			{
       
    76 			// set delay to large number, so that simload process is still
       
    77 			// running at end of test, and therefore not cause issue with
       
    78 			// TEF execution determining the test has failed because
       
    79 			// the sim load app is not running at end of test.
       
    80 			internalDelay = 30000000; // 30s
       
    81 			}
       
    82 			
       
    83 		SimulateTestLoad(mySimLoad, internalDelay);
       
    84 		}	
       
    85 	}
       
    86 	
       
    87 EXPORT_C void CTSimLoadAppUtils::SimulateSpikedLoad()
       
    88 	{
       
    89 	SimulateTestLoad(1500000, 100000);
       
    90 	}
       
    91 
       
    92 void CTSimLoadAppUtils::SimulateTestLoad(const TInt& aSimLoad, const TInt& aDelay)
       
    93 	{
       
    94 	FOREVER
       
    95 		{
       
    96 		for (TInt i = 0; i <= aSimLoad; i++)
       
    97 			{
       
    98 			#if !defined(__WINS__) && !defined(__X86GCC__)
       
    99 			asm{nop;};
       
   100 			#endif
       
   101 			}
       
   102 
       
   103 		User::After(aDelay);
       
   104 		}
       
   105 	}
       
   106 
       
   107 TInt CTSimLoadAppUtils::CalculateSimLoadL(const TInt& aPercentage)
       
   108 	{
       
   109 	TInt32 calculatedLoad = 0;
       
   110 	
       
   111 	if (aPercentage>0)
       
   112 		{
       
   113 		// based on measurements performed using Symbian Sample Profiler
       
   114 		// .../base/e32utils/analyse/profiler.rtf
       
   115 		// and then utilising curve fit (http://www.ebicom.net/~dhyams/cftp.htm)
       
   116 		// the following formula was determined to best calculate the load
       
   117 		// based on a required percentage
       
   118 		// simload = a + b*aPercentage + c*aPercentage^2 + d*aPercentage^3 + e*aPercentage^4
       
   119 		const TReal a = 92600;
       
   120 		const TReal b = -32000;
       
   121 		const TReal c = 4700;
       
   122 		const TReal d = -114;
       
   123 		const TReal e = 0.91;
       
   124 		TReal tempValue = a + (b*aPercentage) + (c*aPercentage*aPercentage) 
       
   125 		                    + (d*aPercentage*aPercentage*aPercentage) 
       
   126 		                    + (e*aPercentage*aPercentage*aPercentage*aPercentage);
       
   127 		User::LeaveIfError(Math::Int(calculatedLoad, tempValue));
       
   128 		}
       
   129 		
       
   130 	return calculatedLoad;
       
   131 	}
       
   132