72
|
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 IPC Test 15
|
|
15 |
//
|
|
16 |
//
|
|
17 |
|
|
18 |
// EPOC includes
|
|
19 |
#include <e32base.h>
|
|
20 |
#include <ss_std.h>
|
|
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 "Test15Concurrency.h"
|
|
32 |
#include <comms-infras/commsbufpond.h>
|
|
33 |
|
|
34 |
// constructor
|
|
35 |
CTest15Concurrency::CTest15Concurrency()
|
|
36 |
{
|
|
37 |
SetTestStepName(_L("MBufMgrTest15"));// Store the name of this test case
|
|
38 |
iMainThreadTries = 0;
|
|
39 |
iMainThreadFails = 0;
|
|
40 |
iHighThreadTries = 0;
|
|
41 |
iHighThreadFails = 0;
|
|
42 |
}
|
|
43 |
|
|
44 |
// destructor
|
|
45 |
CTest15Concurrency::~CTest15Concurrency()
|
|
46 |
{
|
|
47 |
}
|
|
48 |
|
|
49 |
//
|
|
50 |
TInt CTest15Concurrency::fHighPriorityThread(TAny* aInput)
|
|
51 |
{
|
|
52 |
CTest15Concurrency* pTestObject = (CTest15Concurrency*)aInput;
|
|
53 |
// We need to introduce this new client thread to the MBufMgr
|
|
54 |
TCommsBufPondTLSOp tls(pTestObject->iBufPond);
|
|
55 |
tls.Set();
|
|
56 |
|
|
57 |
CTrapCleanup* aCleanup = CTrapCleanup::New();
|
|
58 |
|
|
59 |
//Install active scheduler
|
|
60 |
CActiveScheduler* aActSch = new CActiveScheduler;
|
|
61 |
if(aActSch==NULL)
|
|
62 |
{
|
|
63 |
return KErrNoMemory;
|
|
64 |
}
|
|
65 |
CActiveScheduler::Install(aActSch);
|
|
66 |
|
|
67 |
RTimer aTimer;
|
|
68 |
TRequestStatus aTimerStatus; // Request status associated with timer
|
|
69 |
aTimer.CreateLocal(); // Create timer for this thread
|
|
70 |
//-------------- substep 1 --------------------
|
|
71 |
|
|
72 |
// Allocate two 500-bytes long descriptors (Des1 & Des2):"));
|
|
73 |
TBuf8<500> *aDes1 = NULL;
|
|
74 |
TBuf8<500> *aDes2 = NULL;
|
|
75 |
|
|
76 |
TRAPD(ret, aDes1 = new(ELeave) TBuf8<500>);
|
|
77 |
if(ret!=KErrNone)
|
|
78 |
{
|
|
79 |
return ret;
|
|
80 |
}
|
|
81 |
|
|
82 |
TRAP(ret, aDes2 = new(ELeave) TBuf8<500>);
|
|
83 |
if(ret!=KErrNone)
|
|
84 |
{
|
|
85 |
delete aDes1;
|
|
86 |
return ret;
|
|
87 |
}
|
|
88 |
|
|
89 |
aDes1->SetLength(500);
|
|
90 |
aDes2->SetLength(500);
|
|
91 |
|
|
92 |
//Fill in the Des1 with a pattern
|
|
93 |
pTestObject->StripeDes(*aDes1, 0, 500, 'a', 'z');
|
|
94 |
|
|
95 |
for (TInt i = 0 ; i<1000;i++)
|
|
96 |
{
|
|
97 |
//Allocate 500-bytes long RMBufChain
|
|
98 |
RMBufChain aChain;
|
|
99 |
TRAP(ret,aChain.AllocL(500));
|
|
100 |
if (ret != KErrNone)
|
|
101 |
{
|
|
102 |
break;
|
|
103 |
}
|
|
104 |
//Copy in Des1 into Chain
|
|
105 |
aChain.CopyIn(*aDes1);
|
|
106 |
//Fill in Des2 with zeros
|
|
107 |
pTestObject->StripeDes(*aDes2, 0, 500, 0, 0);
|
|
108 |
//Copy out Chain into Des2;
|
|
109 |
aChain.CopyOut(*aDes2);
|
|
110 |
//Compare the contents of Des1 & Des2
|
|
111 |
if(aDes1->Compare(*aDes2))
|
|
112 |
pTestObject->iHighThreadFails++;
|
|
113 |
pTestObject->iHighThreadTries++;
|
|
114 |
//Free chain
|
|
115 |
aChain.Free();
|
|
116 |
//Sleep for 5ms
|
|
117 |
aTimer.After(aTimerStatus,5000);
|
|
118 |
User::WaitForRequest(aTimerStatus);
|
|
119 |
}
|
|
120 |
delete aDes1;
|
|
121 |
delete aDes2;
|
|
122 |
CActiveScheduler::Install(NULL);
|
|
123 |
delete aActSch;
|
|
124 |
delete aCleanup;
|
|
125 |
return ret;
|
|
126 |
}
|
|
127 |
|
|
128 |
|
|
129 |
|
|
130 |
enum TVerdict CTest15Concurrency::doTestStepL(void)
|
|
131 |
{
|
|
132 |
SetTestStepResult(EFail);
|
|
133 |
volatile TExitType aExit;
|
|
134 |
|
|
135 |
//-------------- substep 1 --------------------
|
|
136 |
INFO_PRINTF1(_L(" 01 Create CMBufManager and install active scheduler:"));
|
|
137 |
CleanupStack::PushL( iActSch = new(ELeave) CActiveScheduler );
|
|
138 |
CActiveScheduler::Install(iActSch);
|
|
139 |
CreateInstanceMBufMgrL(KMBufDefaultHeapSize);
|
|
140 |
CleanupClosePushL(iBufPond);
|
|
141 |
|
|
142 |
//-------------------substep 01-----------------------------
|
|
143 |
INFO_PRINTF1(_L(" 02 Create high priority thread and resume it:"));
|
|
144 |
RThread aThread;
|
|
145 |
|
|
146 |
TInt err=aThread.Create(_L("testThreadRec"),
|
|
147 |
fHighPriorityThread,
|
|
148 |
KDefaultStackSize,
|
|
149 |
KDefaultHeapSize,
|
|
150 |
KDefaultHeapSize,
|
|
151 |
(TAny*)this,
|
|
152 |
EOwnerProcess);
|
|
153 |
if (err!=KErrNone)
|
|
154 |
{
|
|
155 |
_LIT(aLog,"Error:Could not create the thread. err = %d"); INFO_PRINTF2(aLog,err);
|
|
156 |
User::Leave(EFail);
|
|
157 |
}
|
|
158 |
aThread.SetPriority(EPriorityAbsoluteHigh);
|
|
159 |
aThread.Resume();
|
|
160 |
|
|
161 |
//-------------------substep 03-----------------------------
|
|
162 |
INFO_PRINTF1(_L(" 02 Do tests in loop end stop when the other finishes"));
|
|
163 |
INFO_PRINTF1(_L(" ...It will take a while (about 10 sec.):"));
|
|
164 |
|
|
165 |
// Allocate two 5000-bytes long descriptors (Des1 & Des2):"));
|
|
166 |
TBuf8<5000> *aDes1, *aDes2;
|
|
167 |
CleanupStack::PushL( aDes1 = new(ELeave) TBuf8<5000> );
|
|
168 |
CleanupStack::PushL( aDes2 = new(ELeave) TBuf8<5000> );
|
|
169 |
aDes1->SetLength(5000);
|
|
170 |
aDes2->SetLength(5000);
|
|
171 |
//Fill in the Des1 with a pattern:"));
|
|
172 |
StripeDes(*aDes1, 0, 5000, '@', 'Z');
|
|
173 |
|
|
174 |
do {
|
|
175 |
//Allocate 5000-bytes long RMBufChain
|
|
176 |
RMBufChain aChain;
|
|
177 |
TRAPD(ret,aChain.AllocL(5000));
|
|
178 |
if (ret != KErrNone)
|
|
179 |
{
|
|
180 |
INFO_PRINTF1(_L("Error: Couldn't allocate RMBuf:"));
|
|
181 |
User::Leave(EFail);
|
|
182 |
}
|
|
183 |
//Copy in Des1 into Chain
|
|
184 |
aChain.CopyIn(*aDes1);
|
|
185 |
//Fill in Des2 with zeros:"));
|
|
186 |
StripeDes(*aDes2, 0, 5000, 0, 0);
|
|
187 |
//Copy out Chain into Des2:"));
|
|
188 |
aChain.CopyOut(*aDes2);
|
|
189 |
//Compare the contents of Des1 & Des2:
|
|
190 |
if(aDes1->Compare(*aDes2)) iMainThreadFails++;
|
|
191 |
iMainThreadTries++;
|
|
192 |
//Free chain
|
|
193 |
aChain.Free();
|
|
194 |
|
|
195 |
//Check whether the other task has finished
|
|
196 |
aExit = aThread.ExitType();
|
|
197 |
}
|
|
198 |
while (aExit == EExitPending);
|
|
199 |
|
|
200 |
//Clean up stack
|
|
201 |
CleanupStack::PopAndDestroy(aDes2);
|
|
202 |
CleanupStack::PopAndDestroy(aDes1);
|
|
203 |
CleanupStack::PopAndDestroy();
|
|
204 |
CActiveScheduler::Install(NULL);
|
|
205 |
CleanupStack::PopAndDestroy(iActSch);
|
|
206 |
|
|
207 |
//-------------------substep 02-----------------------------
|
|
208 |
INFO_PRINTF3(_L(" Info: Number of main thread checkings: %d with %d fails"),iMainThreadTries,iMainThreadFails);
|
|
209 |
INFO_PRINTF3(_L(" Info: Number of high priority thread checkings: %d with %d fails"),iHighThreadTries,iHighThreadFails);
|
|
210 |
aThread.Close();
|
|
211 |
if (iHighThreadTries <1000)
|
|
212 |
{
|
|
213 |
INFO_PRINTF1(_L(" Error: High priority thread ended before 1000 loops are finished"));
|
|
214 |
SetTestStepResult(EFail);
|
|
215 |
|
|
216 |
return TestStepResult();
|
|
217 |
}
|
|
218 |
if ( iHighThreadFails || iMainThreadFails)
|
|
219 |
{
|
|
220 |
SetTestStepResult(EFail);
|
|
221 |
|
|
222 |
return TestStepResult();
|
|
223 |
}
|
|
224 |
SetTestStepResult(EPass);
|
|
225 |
|
|
226 |
return TestStepResult();
|
|
227 |
}
|