|
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 */ |
|
20 |
|
21 #include <e32math.h> |
|
22 #include <e32debug.h> |
|
23 #include <cinidata.h> |
|
24 #include "t_simload.h" |
|
25 #include "t_simloadutils.h" |
|
26 |
|
27 EXPORT_C TBool CTSimLoadAppUtils::IsStaticLoadL() |
|
28 { |
|
29 CIniData * iniData = CIniData::NewL(KSimLoadConfigFile); |
|
30 CleanupStack::PushL(iniData); |
|
31 |
|
32 TPtrC value; |
|
33 User::LeaveIfError(iniData->FindVar(KDefaultSectionName, KConfigSimLoadType(), value)); |
|
34 HBufC* simLoadType = value.Alloc(); |
|
35 |
|
36 CleanupStack::PopAndDestroy(iniData); |
|
37 |
|
38 TBool ret = EFalse; |
|
39 |
|
40 if (simLoadType!=NULL && simLoadType->Des().Compare(_L("KSimLoadStatic")) == KErrNone) |
|
41 { |
|
42 ret = ETrue; |
|
43 } |
|
44 else |
|
45 { |
|
46 if (simLoadType!=NULL && simLoadType->Des().Compare(_L("KSimLoadSpiked")) != KErrNone) |
|
47 { |
|
48 User::Leave(KErrAbort); |
|
49 } |
|
50 } |
|
51 |
|
52 return ret; |
|
53 } |
|
54 |
|
55 EXPORT_C TInt CTSimLoadAppUtils::SimLoadL() |
|
56 { |
|
57 CIniData * iniData = CIniData::NewL(KSimLoadConfigFile); |
|
58 CleanupStack::PushL(iniData); |
|
59 |
|
60 TInt ret; |
|
61 User::LeaveIfError(iniData->FindVar(KDefaultSectionName, KConfigSimLoadValue(), ret)); |
|
62 CleanupStack::PopAndDestroy(iniData); |
|
63 return ret; |
|
64 } |
|
65 |
|
66 EXPORT_C void CTSimLoadAppUtils::SimulateStaticLoadL(TInt aLoadPercentage, TInt aDelay) |
|
67 { |
|
68 if (aLoadPercentage>=0) |
|
69 { |
|
70 // assuming the figure read in was '%' calculate the loop count |
|
71 // required to achieve the simulated load required |
|
72 const TInt mySimLoad = CalculateSimLoadL(aLoadPercentage); |
|
73 |
|
74 TInt internalDelay = aDelay; |
|
75 |
|
76 if (aLoadPercentage==0) |
|
77 { |
|
78 // set delay to large number, so that simload process is still |
|
79 // running at end of test, and therefore not cause issue with |
|
80 // TEF execution determining the test has failed because |
|
81 // the sim load app is not running at end of test. |
|
82 internalDelay = 30000000; // 30s |
|
83 } |
|
84 |
|
85 SimulateTestLoad(mySimLoad, internalDelay); |
|
86 } |
|
87 } |
|
88 |
|
89 EXPORT_C void CTSimLoadAppUtils::SimulateSpikedLoad() |
|
90 { |
|
91 SimulateTestLoad(1500000, 100000); |
|
92 } |
|
93 |
|
94 void CTSimLoadAppUtils::SimulateTestLoad(TInt aSimLoad, TInt aDelay) |
|
95 { |
|
96 FOREVER |
|
97 { |
|
98 for (TInt i = 0; i <= aSimLoad; i++) |
|
99 { |
|
100 //Load the CPU by forcing it to execute the NOP The load value |
|
101 //is dependant upon the value of aSimLoad and the load type (either |
|
102 //static or spiked) by the ratio of aSimload to aDelay |
|
103 //Tuned to work with the H4 only |
|
104 #if !defined(__WINS__) && !defined(__X86GCC__) |
|
105 asm{nop;}; |
|
106 #endif |
|
107 } |
|
108 |
|
109 User::After(aDelay); |
|
110 } |
|
111 } |
|
112 |
|
113 TInt CTSimLoadAppUtils::CalculateSimLoadL(TInt aPercentage) |
|
114 { |
|
115 TInt32 calculatedLoad = 0; |
|
116 |
|
117 if (aPercentage>0) |
|
118 { |
|
119 // based on measurements performed using Symbian Sample Profiler |
|
120 // .../base/e32utils/analyse/profiler.rtf |
|
121 // and then utilising curve fit (http://www.ebicom.net/~dhyams/cftp.htm) |
|
122 // the following formula was determined to best calculate the load |
|
123 // based on a required percentage |
|
124 // simload = a + b*aPercentage + c*aPercentage^2 + d*aPercentage^3 + e*aPercentage^4 |
|
125 const TReal a = 92600; |
|
126 const TReal b = -32000; |
|
127 const TReal c = 4700; |
|
128 const TReal d = -114; |
|
129 const TReal e = 0.91; |
|
130 TReal tempValue = a + (b*aPercentage) + (c*aPercentage*aPercentage) |
|
131 + (d*aPercentage*aPercentage*aPercentage) |
|
132 + (e*aPercentage*aPercentage*aPercentage*aPercentage); |
|
133 User::LeaveIfError(Math::Int(calculatedLoad, tempValue)); |
|
134 } |
|
135 |
|
136 return calculatedLoad; |
|
137 } |