|
1 // Copyright (c) 2006-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 // Notifier step / thread, locks a contact / database, sends message to |
|
15 // concurrent running listener thread / step informing it what has been locked |
|
16 // waits for message from listner to start countdown to release of lock |
|
17 // listener will send message and wait for specified lock to be released |
|
18 // or for timeout to be invoked by cntmodel. |
|
19 // Sending Messages: |
|
20 // Set shared string to contain length of time resource will be locked for in seconds. KSharedEvents. (6) |
|
21 // Set shared string to contain id of contact that is locked. KSharedContact. (1) |
|
22 // Set shared string to contain a value, specify that new test case can start. KSharedNextTest. (aa) |
|
23 // Receiving messages: |
|
24 // Read shared string length signifying that thread should start countdown |
|
25 // until realease of resource. KSharedClients. (AA) |
|
26 // |
|
27 // |
|
28 |
|
29 /** |
|
30 @file |
|
31 @publishedAll |
|
32 @released |
|
33 */ |
|
34 |
|
35 #include "ConcurrentTimeOutNotifierStep.h" |
|
36 #include "PerformanceFunctionalityDefs.h" |
|
37 |
|
38 _LIT(KRun1,"NonTrans"); |
|
39 _LIT(KRun2,"Transaction"); |
|
40 |
|
41 _LIT(KTest1, "Contacts timeout test"); |
|
42 _LIT(KTest2, "Transaction timeout test"); |
|
43 |
|
44 const static TInt KTimeout = 50000000;//50 seconds timeout |
|
45 const static TInt KOneSecond = 1000000; |
|
46 |
|
47 _LIT(KDoubleChar,"AA"); |
|
48 |
|
49 CConcurrentTimeOutNotifierStep::CConcurrentTimeOutNotifierStep() : |
|
50 CPerformanceFunctionalityBase(KConcurrentTimeoutContacts), |
|
51 iSeconds( 10 ) |
|
52 { |
|
53 iConcurrent = ETrue; |
|
54 SetTestStepName(KConcurrentTimeoutNotifierStep); |
|
55 } |
|
56 /** |
|
57 runs the next test that will lock a particular resource |
|
58 */ |
|
59 void CConcurrentTimeOutNotifierStep::CConcurrentTimeOutNotifierMyActive::RunL() |
|
60 { |
|
61 const static TInt KTestCount = iStep->iTests->Count(); |
|
62 if( iStep->iNextTest >= KTestCount ) |
|
63 { |
|
64 CActiveScheduler::Stop(); |
|
65 iStep->iNextTest = 0; |
|
66 } |
|
67 else |
|
68 { |
|
69 RArray< void (CConcurrentTimeOutNotifierStep::*)() > &Tests = *( iStep->iTests ); |
|
70 //select test to run |
|
71 void (CConcurrentTimeOutNotifierStep::*TestFunction)() = Tests[ iStep->iNextTest ]; |
|
72 //execute test |
|
73 ( iStep->*TestFunction )(); |
|
74 Activate(); |
|
75 } |
|
76 } |
|
77 |
|
78 void CConcurrentTimeOutNotifierStep::CConcurrentTimeOutNotifierMyActive::DoCancel() |
|
79 { |
|
80 //nothing to cleanup, does nothing. |
|
81 } |
|
82 |
|
83 TInt CConcurrentTimeOutNotifierStep::CConcurrentTimeOutNotifierMyActive::RunError(TInt aError) |
|
84 { |
|
85 _LIT(KActiveError,"CConcurrentTimeOutNotifierStep:: Error in doTest runL: %d"); |
|
86 iStep->ERR_PRINTF2(KActiveError, aError ); |
|
87 return aError; |
|
88 } |
|
89 |
|
90 void CConcurrentTimeOutNotifierStep::CConcurrentTimeOutNotifierMyActive::Activate() |
|
91 { |
|
92 if(!IsActive()) |
|
93 { |
|
94 TRequestStatus *pS=&iStatus; |
|
95 User::RequestComplete(pS,KErrNone); |
|
96 SetActive(); |
|
97 } |
|
98 } |
|
99 |
|
100 CConcurrentTimeOutNotifierStep::~CConcurrentTimeOutNotifierStep() |
|
101 { |
|
102 if( iTests ) |
|
103 { |
|
104 iTests->Close(); |
|
105 CLEAR(iTests); |
|
106 } |
|
107 CLEAR(iMyActive); |
|
108 } |
|
109 |
|
110 /** |
|
111 create active object and test array |
|
112 append contact lock or transaction lock test as necessary |
|
113 */ |
|
114 void CConcurrentTimeOutNotifierStep::PreTestL() |
|
115 { |
|
116 iMyActive = new (ELeave) CConcurrentTimeOutNotifierStep::CConcurrentTimeOutNotifierMyActive( this ); |
|
117 iTests = new(ELeave) RArray< void (CConcurrentTimeOutNotifierStep::*)() >(); |
|
118 |
|
119 const TDesC &run = ConfigSection(); |
|
120 |
|
121 if( run == KRun1 ) |
|
122 { |
|
123 iTests->AppendL( &CConcurrentTimeOutNotifierStep::LockContactTestL ); |
|
124 } |
|
125 else if( run == KRun2 ) |
|
126 { |
|
127 iTests->AppendL( &CConcurrentTimeOutNotifierStep::LockDatabaseTestL ); |
|
128 } |
|
129 else |
|
130 { |
|
131 MissingTestPanic(); |
|
132 } |
|
133 } |
|
134 |
|
135 TVerdict CConcurrentTimeOutNotifierStep::doTestStepL() |
|
136 { |
|
137 __UHEAP_MARK; |
|
138 InitializeL(); |
|
139 _LIT(KDoStepPrint,"CConcurrentTimeOutNotifierStep::doTestStepL()"); |
|
140 INFO_PRINTF1(KDoStepPrint); //Block start |
|
141 iIterate->Reset(); |
|
142 SetTimerL(-1); |
|
143 SetContactL( -1 ); |
|
144 SetSharedTextL(KSharedNextTest, KDoubleChar, EFalse); |
|
145 CActiveScheduler::Add(iMyActive); |
|
146 iMyActive->Activate(); |
|
147 CActiveScheduler::Start(); |
|
148 |
|
149 Cleanup(); |
|
150 __UHEAP_MARKEND; |
|
151 |
|
152 return TestStepResult(); |
|
153 } |
|
154 |
|
155 /** |
|
156 sends message to listener specifying the length of time resource will be locked for |
|
157 */ |
|
158 void CConcurrentTimeOutNotifierStep::SetTimerL(const TInt aTime) |
|
159 { |
|
160 |
|
161 ShareIntL(KSharedEvents, aTime); |
|
162 |
|
163 } |
|
164 |
|
165 /** |
|
166 sends message to listener specifying the contact that will be locked |
|
167 */ |
|
168 void CConcurrentTimeOutNotifierStep::SetContactL(const TInt aCid) |
|
169 { |
|
170 |
|
171 ShareIntL(KSharedContact, aCid); |
|
172 |
|
173 } |
|
174 |
|
175 /** |
|
176 wait for message from listener specifying that countdown to release of resource should commence |
|
177 */ |
|
178 void CConcurrentTimeOutNotifierStep::StartCountdownL() |
|
179 { |
|
180 if ( iCountdown ) |
|
181 { |
|
182 return; |
|
183 } |
|
184 iCountdown = SharedCountL(KSharedClients) > 0; |
|
185 if (iCountdown) |
|
186 { |
|
187 iStart.UniversalTime(); |
|
188 SetSharedTextL(KSharedClients, KNullDesC, EFalse); |
|
189 } |
|
190 } |
|
191 |
|
192 /** |
|
193 either release resource after countdown has reached the necessary value |
|
194 or timeout test if countdown is not started after the timeout period has passed |
|
195 */ |
|
196 void CConcurrentTimeOutNotifierStep::ProcessWaitL(const TBool aTransaction) |
|
197 { |
|
198 StartCountdownL(); |
|
199 iEnd.UniversalTime(); |
|
200 const TInt64 KLockTime = iEnd.MicroSecondsFrom( iStart ).Int64(); |
|
201 const TInt64 KTestTime = iEnd.MicroSecondsFrom( iTestStart ).Int64(); |
|
202 if( iCountdown && ( KLockTime >= ((iSeconds - KTimeDiff) * KOneSecond) ) ) |
|
203 { |
|
204 iWaiting = EFalse; |
|
205 iCountdown = EFalse; |
|
206 if(aTransaction) |
|
207 { |
|
208 iContactsDatabase->DatabaseCommitL( EFalse );//unlock database |
|
209 } |
|
210 else |
|
211 { |
|
212 CloseL( ETrue );//unlock contact |
|
213 } |
|
214 ++iNextTest; |
|
215 SetSharedTextL(KSharedNextTest, KDoubleChar, EFalse); |
|
216 } |
|
217 else if( KTestTime > KTimeout ) //test has timed out |
|
218 { |
|
219 _LIT(KTimedOut,"Notifier test %d has timed out"); |
|
220 ERR_PRINTF2(KTimedOut, ++iNextTest); |
|
221 iWaiting = EFalse; |
|
222 iCountdown = EFalse; |
|
223 TESTPRINT( EFalse ); |
|
224 SetSharedTextL(KSharedNextTest, KDoubleChar, EFalse); |
|
225 iNextTest = iTests->Count(); |
|
226 } |
|
227 //else test is not complete and has not timed out... continue waiting |
|
228 } |
|
229 |
|
230 /* |
|
231 open a contact, this causes that contact to be locked |
|
232 */ |
|
233 void CConcurrentTimeOutNotifierStep::LockContactTestL() |
|
234 { |
|
235 if(iWaiting) |
|
236 { |
|
237 ProcessWaitL( EFalse ); |
|
238 } |
|
239 else |
|
240 { |
|
241 INFO_PRINTF1(KTest1); |
|
242 iWaiting = ETrue; |
|
243 TContactItemId cid = iIterate->NextL(); |
|
244 OpenL( cid ); |
|
245 //notify listener that database will be unlocked after x amount of time |
|
246 SetTimerL( iSeconds - KTimeDiff ); |
|
247 SetContactL( cid ); |
|
248 iTestStart.UniversalTime(); |
|
249 } |
|
250 } |
|
251 |
|
252 /* |
|
253 starts a transactions |
|
254 this causes the database to be locked |
|
255 */ |
|
256 void CConcurrentTimeOutNotifierStep::LockDatabaseTestL() |
|
257 { |
|
258 if(iWaiting) |
|
259 { |
|
260 ProcessWaitL( ETrue ); |
|
261 } |
|
262 else |
|
263 { |
|
264 INFO_PRINTF1(KTest2); |
|
265 iWaiting = ETrue; |
|
266 TContactItemId cid = iIterate->NextL(); |
|
267 iContactsDatabase->DatabaseBeginLC(EFalse); |
|
268 //notify listener that contact will be unlocked after x amount of time |
|
269 SetTimerL( iSeconds - KTimeDiff ); |
|
270 SetContactL( cid ); |
|
271 CleanupStack::Pop(); // cleanup item from the CContactDatabase::DatabaseBeginLC() |
|
272 iTestStart.UniversalTime(); |
|
273 } |
|
274 } |
|
275 |
|
276 |
|
277 |
|
278 |