|
1 // Copyright (c) 2002-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 // Contains MBufMgr Test Step 13 that measures the time spent for alloc/free methods |
|
15 // |
|
16 // |
|
17 |
|
18 // EPOC includes |
|
19 #include <e32base.h> |
|
20 |
|
21 // Test system includes |
|
22 //#ifdef SYMBIAN_OLD_EXPORT_LOCATION |
|
23 //#include "networking/log.h" |
|
24 //#include "networking/teststep.h" |
|
25 //#else |
|
26 //#include <networking/log.h> |
|
27 //#include <networking/teststep.h> |
|
28 //#endif |
|
29 #include "TestStepCTMbufmgr.h" |
|
30 |
|
31 #include "Test13Performance.h" |
|
32 |
|
33 #include <comms-infras/commsbufpond.h> |
|
34 // constructor |
|
35 CTest13Performance::CTest13Performance() |
|
36 { |
|
37 SetTestStepName(_L("MBufMgrTest13"));// Store the name of this test case |
|
38 } |
|
39 |
|
40 // destructor |
|
41 CTest13Performance::~CTest13Performance() |
|
42 { |
|
43 } |
|
44 |
|
45 |
|
46 // |
|
47 enum TVerdict CTest13Performance::doTestStepL(void) |
|
48 { |
|
49 SetTestStepResult(EFail); |
|
50 TInt aMBufNo; //Taken from the script; |
|
51 TInt aLoopNo; //Taken from the script; |
|
52 TTime aTimeStart, aTimeStop; |
|
53 //-------------- substep 0 -------------------- |
|
54 INFO_PRINTF1(_L(" 00 Read parameters from the script:")); |
|
55 TInt bRet = GetIntFromConfig(_L("MBufMgrTest13"), _L("MBufNo"), aMBufNo); |
|
56 |
|
57 if (!bRet) |
|
58 return TestStepResult(); |
|
59 |
|
60 bRet = GetIntFromConfig(_L("MBufMgrTest13"), _L("LoopNo"), aLoopNo); |
|
61 |
|
62 if (!bRet) |
|
63 return TestStepResult(); |
|
64 |
|
65 |
|
66 INFO_PRINTF3(_L(" Info: MBUFNO = %d, LOOPNO= %d"),aMBufNo, aLoopNo); |
|
67 |
|
68 //-------------- substep 1 -------------------- |
|
69 INFO_PRINTF1(_L(" 01 Create CMBufManager and install active scheduler:")); |
|
70 CleanupStack::PushL( iActSch = new(ELeave) CActiveScheduler ); |
|
71 CActiveScheduler::Install(iActSch); |
|
72 |
|
73 CreateInstanceMBufMgrL((TUint)(3*KMBufSmallSize*aMBufNo)); |
|
74 CleanupClosePushL(iBufPond); |
|
75 |
|
76 TInt i,j,k; //Counters |
|
77 TInt64 us; |
|
78 RMBufQ aBufList1, aBufList2; //Will contain all small buffers; |
|
79 RMBuf* aBuf=0; |
|
80 |
|
81 for (i = 0; i<aLoopNo; i++) |
|
82 { |
|
83 INFO_PRINTF2(_L(" Loop #%d"), i + 1); |
|
84 |
|
85 //-------------- substep 2 -------------------- |
|
86 INFO_PRINTF1(_L(" 02 Allocate Chain that contains RMBUFNO buffers. Free Chain.")); |
|
87 INFO_PRINTF1(_L(" ...Repeat the same 1000 times.Display the time spent:")); |
|
88 RMBufChain aChain; |
|
89 aTimeStart.UniversalTime(); |
|
90 for (j = 0;j < 1000; j++) |
|
91 { |
|
92 TRAPD(ret,aChain.AllocL(KMBufSmallSize*aMBufNo)); |
|
93 if (ret != KErrNone) |
|
94 { |
|
95 INFO_PRINTF1(_L("Error: Couldn't allocate RMBuf:")); |
|
96 return TestStepResult(); |
|
97 } |
|
98 |
|
99 aChain.Free(); |
|
100 } |
|
101 aTimeStop.UniversalTime(); |
|
102 us = aTimeStop.MicroSecondsFrom(aTimeStart).Int64()/1000; |
|
103 INFO_PRINTF2(_L(" ...Info: The time spent on 1000 alloc and free is %d mS"),us); |
|
104 |
|
105 //-------------- substep 3 -------------------- |
|
106 INFO_PRINTF2(_L(" 03 Create %d chains, each containing one RMBuf."), 2 * aMBufNo); |
|
107 INFO_PRINTF1(_L(" ...Then, free all even chains:")); |
|
108 |
|
109 aTimeStart.UniversalTime(); |
|
110 TInt attemptCount = 0; |
|
111 for (j = 0;j<2*aMBufNo;j++) |
|
112 { |
|
113 aBuf = static_cast<RMBuf*>(iBufPond.Alloc(KMBufSmallSize, 0, KMaxTInt)); |
|
114 if (aBuf == NULL) |
|
115 { |
|
116 ++attemptCount; |
|
117 if(attemptCount == 3) |
|
118 { |
|
119 INFO_PRINTF2(_L("Error: Couldn't allocate RMBuf number %d:"),j); |
|
120 User::Leave(EFail); |
|
121 } |
|
122 else |
|
123 { |
|
124 User::After(100000); |
|
125 } |
|
126 } |
|
127 if(aBuf) |
|
128 { |
|
129 aBufList1.Append(aBuf); |
|
130 } |
|
131 } |
|
132 |
|
133 k=0; |
|
134 while (!aBufList1.IsEmpty()) |
|
135 { |
|
136 k++; |
|
137 aBuf = aBufList1.Remove(); |
|
138 if (k%2) |
|
139 { |
|
140 aBuf->Free(); |
|
141 } |
|
142 else |
|
143 { |
|
144 aBufList2.Append(aBuf); |
|
145 } |
|
146 } |
|
147 aTimeStop.UniversalTime(); |
|
148 us = aTimeStop.MicroSecondsFrom(aTimeStart).Int64()/1000; |
|
149 INFO_PRINTF2(_L(" ...Info: The time spent is %d mS"), us); |
|
150 |
|
151 |
|
152 //-------------- substep 4 -------------------- |
|
153 INFO_PRINTF1(_L(" 04 Allocate Chain that contains RMBUFNO buffers. Free Chain.")); |
|
154 INFO_PRINTF1(_L(" ...Repeat the same 1000 times.Display the time spent:")); |
|
155 aTimeStart.UniversalTime(); |
|
156 for (j = 0;j < 1000; j++) |
|
157 { |
|
158 TRAPD(ret,aChain.AllocL(KMBufSmallSize*aMBufNo)); |
|
159 if (ret != KErrNone) |
|
160 { |
|
161 INFO_PRINTF2(_L("Error: Couldn't allocate RMBuf number %d:"),j); |
|
162 User::Leave(EFail); |
|
163 } |
|
164 |
|
165 aChain.Free(); |
|
166 } |
|
167 aTimeStop.UniversalTime(); |
|
168 us = aTimeStop.MicroSecondsFrom(aTimeStart).Int64()/1000; |
|
169 INFO_PRINTF2(_L(" ...Info: The time spent on 1000 alloc and free is %d mS"),us); |
|
170 |
|
171 //-------------- substep 5 -------------------- |
|
172 INFO_PRINTF1(_L(" 05 Free all remainig chains:")); |
|
173 while (!aBufList2.IsEmpty()) |
|
174 { |
|
175 aBuf = aBufList2.Remove(); |
|
176 aBuf->Free(); |
|
177 } |
|
178 } |
|
179 |
|
180 |
|
181 //-------------- substep 9 -------------------- |
|
182 INFO_PRINTF1(_L(" 09 Clean up stack:")); |
|
183 CleanupStack::PopAndDestroy(); |
|
184 CActiveScheduler::Install(NULL); |
|
185 CleanupStack::PopAndDestroy(iActSch); |
|
186 |
|
187 SetTestStepResult(EPass); |
|
188 return TestStepResult(); |
|
189 } |