|
1 /* |
|
2 * Copyright (c) 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 "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 * |
|
16 */ |
|
17 |
|
18 #include <ss_std.h> |
|
19 |
|
20 // Test system includes |
|
21 //#ifdef SYMBIAN_OLD_EXPORT_LOCATION |
|
22 //#include "networking/log.h" |
|
23 //#include "networking/teststep.h" |
|
24 //#else |
|
25 //#include <networking/log.h> |
|
26 //#include <networking/teststep.h> |
|
27 //#endif |
|
28 |
|
29 #include "TestStepCTMbufmgr.h" |
|
30 |
|
31 #include "test20poolceilingfull.h" |
|
32 |
|
33 |
|
34 CTest20PoolCeilingFull::CTest20PoolCeilingFull() |
|
35 { |
|
36 SetTestStepName( _L("MBufMgrTest20") ); // Store the name of this test case |
|
37 } |
|
38 |
|
39 CTest20PoolCeilingFull::~CTest20PoolCeilingFull() |
|
40 { |
|
41 iChain.Free(); |
|
42 } |
|
43 |
|
44 TVerdict CTest20PoolCeilingFull::doTestStepL() |
|
45 { |
|
46 __UHEAP_MARK; |
|
47 //-------------- substep 1 -------------------- |
|
48 INFO_PRINTF1(_L(" 01 Create CMBufManager and install active scheduler:")); |
|
49 |
|
50 CleanupStack::PushL( iActSch = new(ELeave) CActiveScheduler ); |
|
51 CActiveScheduler::Install(iActSch); |
|
52 |
|
53 RArray<TCommsBufPoolCreateInfo> createInfoArray; |
|
54 |
|
55 TCommsBufPoolCreateInfo createInfo; |
|
56 createInfo.iBufSize = 256; |
|
57 createInfo.iInitialBufs = 50; |
|
58 createInfo.iGrowByBufs = 20; |
|
59 createInfo.iMinFreeBufs = 4; |
|
60 createInfo.iCeiling = 100; |
|
61 createInfoArray.Append(createInfo); |
|
62 |
|
63 CreateInstanceMBufMgrL(createInfoArray); |
|
64 CleanupClosePushL(iBufPond); |
|
65 createInfoArray.Close (); |
|
66 |
|
67 INFO_PRINTF1(_L(" 02 Create and install active object that will do the test:")); |
|
68 |
|
69 CMBufAsyncPoolCeilingFull* poolCeilingFull; |
|
70 CleanupStack::PushL(poolCeilingFull = new(ELeave) CMBufAsyncPoolCeilingFull(*this)); |
|
71 |
|
72 INFO_PRINTF1(_L(" 03 Start the test:")); |
|
73 if(poolCeilingFull->DoStartTest() != KErrNone) |
|
74 { |
|
75 INFO_PRINTF1(_L("Error: Async Alloc's failing in test run:")); |
|
76 SetTestStepResult(EFail); |
|
77 return TestStepResult(); |
|
78 } |
|
79 //Clean up stack |
|
80 CleanupStack::PopAndDestroy(); // poolCeilingFull |
|
81 CleanupStack::PopAndDestroy(); // bufpond |
|
82 CActiveScheduler::Install(NULL); |
|
83 CleanupStack::PopAndDestroy(iActSch); |
|
84 |
|
85 __UHEAP_MARKEND; |
|
86 |
|
87 SetTestStepResult(EPass); |
|
88 return TestStepResult(); |
|
89 } |
|
90 |
|
91 RCommsBufPond& CTest20PoolCeilingFull::BufPond() |
|
92 { |
|
93 return iBufPond; |
|
94 } |
|
95 |
|
96 CMBufAsyncPoolCeilingFull::CMBufAsyncPoolCeilingFull(CTest20PoolCeilingFull& aTestObject) |
|
97 : CActive(EPriorityStandard), |
|
98 iTestObject(aTestObject) |
|
99 { |
|
100 CActiveScheduler::Add(this); |
|
101 } |
|
102 |
|
103 |
|
104 CMBufAsyncPoolCeilingFull::~CMBufAsyncPoolCeilingFull() |
|
105 { |
|
106 Cancel(); |
|
107 iAsyncChain.Free(); |
|
108 } |
|
109 |
|
110 void CMBufAsyncPoolCeilingFull::CompleteSelf() |
|
111 { |
|
112 TRequestStatus* pStat = &iStatus; |
|
113 User::RequestComplete(pStat, KErrNone); |
|
114 SetActive(); |
|
115 } |
|
116 |
|
117 void CMBufAsyncPoolCeilingFull::RunL() |
|
118 { |
|
119 User::LeaveIfError(iStatus.Int()); |
|
120 |
|
121 if((iThread1.ExitType() != EExitPending)) |
|
122 { |
|
123 CActiveScheduler::Stop(); |
|
124 return; |
|
125 } |
|
126 if(iAsyncChain.IsEmpty()) |
|
127 { |
|
128 iAsyncRequest.Alloc(iAsyncChain, 256 * 8, iStatus); |
|
129 SetActive(); |
|
130 } |
|
131 else |
|
132 { |
|
133 iAsyncChain.Free(); |
|
134 CompleteSelf(); |
|
135 } |
|
136 } |
|
137 |
|
138 void CMBufAsyncPoolCeilingFull::DoCancel() |
|
139 { |
|
140 iAsyncRequest.Cancel(); |
|
141 } |
|
142 |
|
143 |
|
144 TInt CMBufAsyncPoolCeilingFull::DoStartTest() |
|
145 { |
|
146 |
|
147 TInt err=iThread1.Create(_L("testThread1Rec"), |
|
148 fThread1, |
|
149 KDefaultStackSize, |
|
150 KDefaultHeapSize, |
|
151 KMaxHeapSize, |
|
152 (TAny*)&iTestObject, |
|
153 EOwnerProcess); |
|
154 if (err!=KErrNone) |
|
155 { |
|
156 User::Leave(EFail); |
|
157 } |
|
158 //iThread1.SetPriority(EPriorityAbsoluteHigh); |
|
159 iThread1.Resume(); |
|
160 iAsyncRequest.Alloc(iAsyncChain, 256, iStatus); |
|
161 SetActive(); |
|
162 CActiveScheduler::Start(); |
|
163 |
|
164 iThread1.Close(); |
|
165 iThread2.Close(); |
|
166 iThread3.Close(); |
|
167 |
|
168 return iError; |
|
169 } |
|
170 |
|
171 |
|
172 TInt CMBufAsyncPoolCeilingFull::fThread1(TAny* aInput) |
|
173 { |
|
174 TInt totalAllocation = 90; |
|
175 CTest20PoolCeilingFull* pTestObject = (CTest20PoolCeilingFull*)aInput; |
|
176 // We need to introduce this new client thread to the MBufMgr |
|
177 TCommsBufPondTLSOp tls(pTestObject->BufPond()); |
|
178 tls.Set(); |
|
179 |
|
180 CTrapCleanup* aCleanup = CTrapCleanup::New(); |
|
181 |
|
182 TBool freeMem = EFalse; |
|
183 for(TInt i=0; i < 1000; ++i) |
|
184 { |
|
185 //INFO_PRINTF2(_L("Inside the for loop: %d"),i); |
|
186 RDebug::Printf("inside the for loop: %d", i); |
|
187 |
|
188 RMBufChain chain; |
|
189 chain.Alloc(512, 256, 256); |
|
190 if(freeMem) |
|
191 { |
|
192 chain.Free(); |
|
193 freeMem = EFalse; |
|
194 } |
|
195 else |
|
196 { |
|
197 pTestObject->iChain.Append(chain); |
|
198 freeMem = ETrue; |
|
199 } |
|
200 if(pTestObject->iChain.NumBufs() == totalAllocation) |
|
201 { |
|
202 // Free all. Will trigger the AO. |
|
203 pTestObject->iChain.Free(); |
|
204 break; |
|
205 } |
|
206 //Sleep for 5ms |
|
207 User::After(5000); |
|
208 } |
|
209 |
|
210 delete aCleanup; |
|
211 return KErrNone; |
|
212 } |
|
213 |
|
214 |
|
215 |