author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Mon, 21 Jun 2010 17:12:14 +0300 | |
branch | RCL_3 |
changeset 198 | 2bb754abd467 |
parent 117 | 5b5d147c7838 |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 1994-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 the License "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 |
// e32test\system\t_condvar.cpp |
|
15 |
// Overview: |
|
16 |
// Test the use of the RCondVar & RMutex classes. |
|
17 |
// API Information: |
|
18 |
// RCondVar, RMutex |
|
19 |
// Details: |
|
20 |
// - Create some local conditional variables and mutexes and verify results |
|
21 |
// are as expected. |
|
22 |
// - Create a test thread that waits on conditional variables and mutexes, |
|
23 |
// append some items on an array, signal the conditional variable and mutex, |
|
24 |
// the thread then counts the number of items on the array and passes the |
|
25 |
// result back to the main process. Verify results are as expected. Repeat |
|
26 |
// with different array data. |
|
27 |
// - Verify that a RCondVar::Wait() panics when the thread does not hold the |
|
28 |
// specified mutex (mutex not locked). |
|
29 |
// - Test using two mutexes with 1 conditional variable, append some items to |
|
30 |
// an array, verify results from the thread are as expected. |
|
31 |
// - Create a second thread with higher priority, perform tests similar to |
|
32 |
// above, verify results are as expected. |
|
33 |
// - Verify the thread timeout values are as expected. |
|
34 |
// - Create global conditional variables and global mutexes, using two threads |
|
35 |
// test the RCondVar::Signal() and RMutex::Wait() results are as expected. |
|
36 |
// - Test various combinations of creating a thread, suspending and killing it |
|
37 |
// and signalling a conditional variable and mutex. Verify results are as |
|
38 |
// expected. |
|
39 |
// - Create a secondary process along with a global chunk, conditional variable |
|
40 |
// and mutex. Signal the conditional variable and verify the results are as |
|
41 |
// expected. |
|
42 |
// - Using two threads, benchmark the number of conditional variable/mutex Signal |
|
43 |
// and Wait iterations that can be completed per second. |
|
44 |
// Platforms/Drives/Compatibility: |
|
45 |
// All. |
|
46 |
// Assumptions/Requirement/Pre-requisites: |
|
47 |
// Failures and causes: |
|
48 |
// Base Port information: |
|
49 |
// |
|
50 |
// |
|
51 |
||
52 |
#include <e32std.h> |
|
53 |
#include <e32std_private.h> |
|
54 |
#include <e32svr.h> |
|
55 |
#include <e32test.h> |
|
56 |
#include <e32ldr.h> |
|
57 |
#include <e32def.h> |
|
58 |
#include <e32def_private.h> |
|
117
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
59 |
#include <u32std.h> |
0 | 60 |
|
61 |
RTest test(_L("T_CONDVAR")); |
|
62 |
RMutex M1; |
|
63 |
RMutex M2; |
|
64 |
RCondVar CV1; |
|
65 |
RCondVar CV2; |
|
66 |
||
67 |
#define __TRACE_LINE__ test.Printf(_L("Line %d\n"),__LINE__) |
|
68 |
||
69 |
struct SThreadData |
|
70 |
{ |
|
71 |
SThreadData(); |
|
72 |
RMutex iM; |
|
73 |
RCondVar iV; |
|
74 |
RArray<TInt>* iA; |
|
75 |
TInt iTotal; |
|
76 |
TInt iInnerLoops; |
|
77 |
TInt iOuterLoops; |
|
78 |
TInt iTimeoutMs; |
|
79 |
TInt iTimeouts; |
|
80 |
TInt iBadCount; |
|
81 |
}; |
|
82 |
||
83 |
struct SThreadData2 |
|
84 |
{ |
|
85 |
SThreadData2(); |
|
86 |
const TText* iMutexName; |
|
87 |
const TText* iCondVarName; |
|
88 |
TInt iInnerLoops; |
|
89 |
}; |
|
90 |
||
91 |
SThreadData::SThreadData() |
|
92 |
{ |
|
93 |
memset(this, 0, sizeof(*this)); |
|
94 |
} |
|
95 |
||
96 |
SThreadData2::SThreadData2() |
|
97 |
{ |
|
98 |
memset(this, 0, sizeof(*this)); |
|
99 |
} |
|
100 |
||
101 |
TInt Thread0(TAny*) |
|
102 |
{ |
|
103 |
return CV1.Wait(M1); |
|
104 |
} |
|
105 |
||
106 |
TInt Thread1(TAny* a) |
|
107 |
{ |
|
108 |
TUint32 t1, t2; |
|
109 |
SThreadData& d = *(SThreadData*)a; |
|
110 |
TInt r = KErrNone; |
|
111 |
TInt i = 0; |
|
112 |
d.iM.Wait(); |
|
113 |
FOREVER |
|
114 |
{ |
|
115 |
while (d.iA->Count()<=i && r==KErrNone) |
|
116 |
{ |
|
117 |
t1 = User::NTickCount(); |
|
118 |
if (d.iTimeoutMs) |
|
119 |
r = d.iV.TimedWait(d.iM, d.iTimeoutMs*1000); |
|
120 |
else |
|
121 |
r = d.iV.Wait(d.iM); |
|
122 |
t2 = User::NTickCount(); |
|
123 |
++d.iInnerLoops; |
|
124 |
if (r == KErrTimedOut) |
|
125 |
{ |
|
126 |
++d.iTimeouts; |
|
127 |
TInt iv = (TInt)(t2-t1); |
|
128 |
if (iv<d.iTimeoutMs) |
|
129 |
++d.iBadCount; |
|
130 |
r = KErrNone; |
|
131 |
} |
|
132 |
} |
|
133 |
if (r != KErrNone) |
|
134 |
break; |
|
135 |
++d.iOuterLoops; |
|
136 |
TInt c = d.iA->Count(); |
|
137 |
for (; i<c; ++i) |
|
138 |
d.iTotal += (*d.iA)[i]; |
|
139 |
} |
|
140 |
return r; |
|
141 |
} |
|
142 |
||
143 |
TInt Thread2(TAny* a) |
|
144 |
{ |
|
145 |
TUint32 t1, t2; |
|
146 |
SThreadData& d = *(SThreadData*)a; |
|
147 |
TInt r = KErrNone; |
|
148 |
d.iM.Wait(); |
|
149 |
RThread::Rendezvous(KErrNone); |
|
150 |
while (r==KErrNone) |
|
151 |
{ |
|
152 |
t1 = User::NTickCount(); |
|
153 |
if (d.iTimeoutMs) |
|
154 |
r = d.iV.TimedWait(d.iM, d.iTimeoutMs*1000); |
|
155 |
else |
|
156 |
r = d.iV.Wait(d.iM); |
|
157 |
t2 = User::NTickCount(); |
|
158 |
++d.iInnerLoops; |
|
159 |
if (r == KErrTimedOut) |
|
160 |
{ |
|
161 |
++d.iTimeouts; |
|
162 |
TInt iv = (TInt)(t2-t1); |
|
163 |
if (iv<d.iTimeoutMs) |
|
164 |
++d.iBadCount; |
|
165 |
r = KErrNone; |
|
166 |
} |
|
167 |
} |
|
168 |
return r; |
|
169 |
} |
|
170 |
||
171 |
TInt Thread3(TAny* a) |
|
172 |
{ |
|
173 |
SThreadData2& d = *(SThreadData2*)a; |
|
174 |
RMutex m; |
|
175 |
RCondVar cv; |
|
176 |
TInt r = m.OpenGlobal(TPtrC(d.iMutexName), EOwnerThread); |
|
177 |
if (r!=KErrNone) |
|
178 |
return r; |
|
179 |
r = cv.OpenGlobal(TPtrC(d.iCondVarName), EOwnerThread); |
|
180 |
if (r!=KErrNone) |
|
181 |
return r; |
|
182 |
m.Wait(); |
|
183 |
while (r==KErrNone) |
|
184 |
{ |
|
185 |
r = cv.Wait(m); |
|
186 |
++d.iInnerLoops; |
|
187 |
} |
|
188 |
return r; |
|
189 |
} |
|
190 |
||
191 |
TInt Thread4(TAny* a) |
|
192 |
{ |
|
193 |
volatile TInt& count = *(volatile TInt*)a; |
|
194 |
TInt r = KErrNone; |
|
195 |
M2.Wait(); |
|
196 |
while (r==KErrNone) |
|
197 |
{ |
|
198 |
r = CV2.Wait(M2); |
|
199 |
++count; |
|
200 |
} |
|
201 |
return r; |
|
202 |
} |
|
203 |
||
204 |
TInt Thread5(TAny*) |
|
205 |
{ |
|
206 |
FOREVER |
|
207 |
{ |
|
208 |
M2.Wait(); |
|
209 |
CV2.Signal(); |
|
210 |
M2.Signal(); |
|
211 |
} |
|
212 |
} |
|
213 |
||
214 |
void RunBench() |
|
215 |
{ |
|
216 |
test.Next(_L("Benchmark")); |
|
217 |
RThread t4, t5; |
|
218 |
TInt count = 0; |
|
219 |
TInt r = t4.Create(KNullDesC, &Thread4, 0x1000, 0x1000, 0x1000, &count); |
|
220 |
test(r==KErrNone); |
|
221 |
t4.SetPriority(EPriorityLess); |
|
222 |
r = t5.Create(KNullDesC, &Thread5, 0x1000, 0x1000, 0x1000, NULL); |
|
223 |
test(r==KErrNone); |
|
224 |
t5.SetPriority(EPriorityMuchLess); |
|
225 |
t4.Resume(); |
|
226 |
t5.Resume(); |
|
227 |
User::After(500000); |
|
228 |
TInt initc = count; |
|
229 |
User::After(5000000); |
|
230 |
TInt finalc = count; |
|
231 |
test.Printf(_L("%d iterations per second\n"), (finalc-initc)/5); |
|
232 |
t4.Kill(0); |
|
233 |
t5.Kill(0); |
|
234 |
CLOSE_AND_WAIT(t4); |
|
235 |
CLOSE_AND_WAIT(t5); |
|
236 |
} |
|
237 |
||
238 |
void CreateThread2(RThread& aThread, SThreadData& aData, TThreadPriority aPri) |
|
239 |
{ |
|
240 |
TInt r = aThread.Create(KNullDesC, &Thread2, 0x1000, 0x1000, 0x1000, &aData); |
|
241 |
test(r==KErrNone); |
|
242 |
aThread.SetPriority(aPri); |
|
243 |
TRequestStatus s; |
|
244 |
aThread.Rendezvous(s); |
|
245 |
test(s==KRequestPending); |
|
246 |
aThread.Resume(); |
|
247 |
User::WaitForRequest(s); |
|
248 |
test(s==KErrNone); |
|
249 |
test(aThread.ExitType()==EExitPending); |
|
250 |
aData.iM.Wait(); |
|
251 |
} |
|
252 |
||
253 |
void KillThread2(RThread& aThread) |
|
254 |
{ |
|
255 |
TRequestStatus s; |
|
256 |
aThread.Logon(s); |
|
257 |
test(s==KRequestPending); |
|
258 |
aThread.Terminate(0); |
|
259 |
User::WaitForRequest(s); |
|
260 |
test(aThread.ExitType()==EExitTerminate); |
|
261 |
test(aThread.ExitReason()==0); |
|
262 |
test(s==0); |
|
263 |
CLOSE_AND_WAIT(aThread); |
|
264 |
} |
|
265 |
||
266 |
void AppendToArray(SThreadData& aD, TInt aCount, ...) |
|
267 |
{ |
|
268 |
VA_LIST list; |
|
269 |
VA_START(list,aCount); |
|
270 |
aD.iM.Wait(); |
|
271 |
while(--aCount>=0) |
|
272 |
{ |
|
273 |
test(aD.iA->Append(VA_ARG(list,TInt))==KErrNone); |
|
274 |
} |
|
275 |
aD.iV.Signal(); |
|
276 |
aD.iM.Signal(); |
|
277 |
} |
|
278 |
||
279 |
void AppendToArrayB(SThreadData& aD, TInt aCount, ...) |
|
280 |
{ |
|
281 |
VA_LIST list; |
|
282 |
VA_START(list,aCount); |
|
283 |
aD.iM.Wait(); |
|
284 |
while(--aCount>=0) |
|
285 |
{ |
|
286 |
test(aD.iA->Append(VA_ARG(list,TInt))==KErrNone); |
|
287 |
} |
|
288 |
aD.iV.Broadcast(); |
|
289 |
aD.iM.Signal(); |
|
290 |
} |
|
291 |
||
292 |
void AppendToArrayB2(SThreadData& aD, TInt aCount, ...) |
|
293 |
{ |
|
294 |
VA_LIST list; |
|
295 |
VA_START(list,aCount); |
|
296 |
aD.iM.Wait(); |
|
297 |
while(--aCount>=0) |
|
298 |
{ |
|
299 |
test(aD.iA->Append(VA_ARG(list,TInt))==KErrNone); |
|
300 |
} |
|
301 |
aD.iM.Signal(); |
|
302 |
aD.iV.Broadcast(); |
|
303 |
} |
|
304 |
||
305 |
void Thread2Test() |
|
306 |
{ |
|
307 |
test.Next(_L("Thread2Test")); |
|
308 |
RCondVar cv2; |
|
309 |
RMutex m3; |
|
310 |
TInt r = cv2.CreateLocal(); |
|
311 |
test(r==KErrNone); |
|
312 |
r = m3.CreateLocal(); |
|
313 |
test(r==KErrNone); |
|
314 |
SThreadData d1; |
|
315 |
d1.iM = m3; |
|
316 |
d1.iV = cv2; |
|
317 |
RThread t1; |
|
318 |
||
319 |
CreateThread2(t1, d1, EPriorityLess); |
|
320 |
cv2.Signal(); |
|
321 |
m3.Signal(); |
|
322 |
User::After(100000); |
|
323 |
test(d1.iInnerLoops == 1); |
|
324 |
KillThread2(t1); |
|
325 |
||
326 |
CreateThread2(t1, d1, EPriorityLess); |
|
327 |
KillThread2(t1); |
|
328 |
m3.Signal(); |
|
329 |
test(d1.iInnerLoops == 1); |
|
330 |
||
331 |
CreateThread2(t1, d1, EPriorityLess); |
|
332 |
m3.Signal(); |
|
333 |
User::After(10000); |
|
334 |
KillThread2(t1); |
|
335 |
test(d1.iInnerLoops == 1); |
|
336 |
||
337 |
CreateThread2(t1, d1, EPriorityLess); |
|
338 |
cv2.Signal(); |
|
339 |
User::After(10000); |
|
340 |
KillThread2(t1); |
|
341 |
m3.Signal(); |
|
342 |
test(d1.iInnerLoops == 1); |
|
343 |
||
344 |
CreateThread2(t1, d1, EPriorityLess); |
|
345 |
t1.Suspend(); |
|
346 |
KillThread2(t1); |
|
347 |
m3.Signal(); |
|
348 |
test(d1.iInnerLoops == 1); |
|
349 |
||
350 |
CreateThread2(t1, d1, EPriorityLess); |
|
351 |
User::After(10000); |
|
352 |
t1.Suspend(); |
|
353 |
KillThread2(t1); |
|
354 |
m3.Signal(); |
|
355 |
test(d1.iInnerLoops == 1); |
|
356 |
||
357 |
CreateThread2(t1, d1, EPriorityLess); |
|
358 |
cv2.Signal(); |
|
359 |
t1.Suspend(); |
|
360 |
KillThread2(t1); |
|
361 |
m3.Signal(); |
|
362 |
test(d1.iInnerLoops == 1); |
|
363 |
||
364 |
CreateThread2(t1, d1, EPriorityLess); |
|
365 |
cv2.Signal(); |
|
366 |
User::After(10000); |
|
367 |
t1.Suspend(); |
|
368 |
KillThread2(t1); |
|
369 |
m3.Signal(); |
|
370 |
test(d1.iInnerLoops == 1); |
|
371 |
||
372 |
cv2.Close(); |
|
373 |
m3.Close(); |
|
374 |
} |
|
375 |
||
376 |
const TText* KMutex1Name = _S("mtx1"); |
|
377 |
const TText* KMutex2Name = _S("mtx2"); |
|
378 |
const TText* KCondVar1Name = _S("cv1"); |
|
379 |
const TText* KCondVar2Name = _S("cv2"); |
|
380 |
||
381 |
void TestGlobal() |
|
382 |
{ |
|
383 |
test.Next(_L("Test Global")); |
|
384 |
RMutex mg1, mg2; |
|
385 |
RCondVar cvg1, cvg2; |
|
386 |
TInt r = mg1.CreateGlobal(TPtrC(KMutex1Name)); |
|
387 |
test(r==KErrNone); |
|
388 |
r = mg2.CreateGlobal(TPtrC(KMutex2Name)); |
|
389 |
test(r==KErrNone); |
|
390 |
r = cvg1.CreateGlobal(TPtrC(KCondVar1Name)); |
|
391 |
test(r==KErrNone); |
|
392 |
r = cvg2.CreateGlobal(TPtrC(KCondVar2Name)); |
|
393 |
test(r==KErrNone); |
|
394 |
SThreadData2 d1, d2; |
|
395 |
d1.iMutexName = KMutex1Name; |
|
396 |
d1.iCondVarName = KCondVar1Name; |
|
397 |
d2.iMutexName = KMutex2Name; |
|
398 |
d2.iCondVarName = KCondVar2Name; |
|
399 |
||
400 |
RThread t1, t2; |
|
401 |
r = t1.Create(KNullDesC, &Thread3, 0x1000, 0x1000, 0x1000, &d1); |
|
402 |
test(r==KErrNone); |
|
403 |
t1.SetPriority(EPriorityMore); |
|
404 |
TRequestStatus s1; |
|
405 |
t1.Logon(s1); |
|
406 |
t1.Resume(); |
|
407 |
r = t2.Create(KNullDesC, &Thread3, 0x1000, 0x1000, 0x1000, &d2); |
|
408 |
test(r==KErrNone); |
|
409 |
t2.SetPriority(EPriorityMore); |
|
410 |
TRequestStatus s2; |
|
411 |
t2.Logon(s2); |
|
412 |
t2.Resume(); |
|
413 |
||
414 |
test(s1==KRequestPending); |
|
415 |
test(s2==KRequestPending); |
|
416 |
test(d1.iInnerLoops == 0); |
|
417 |
test(d2.iInnerLoops == 0); |
|
418 |
cvg1.Signal(); |
|
419 |
test(d1.iInnerLoops == 1); |
|
420 |
test(d2.iInnerLoops == 0); |
|
421 |
cvg2.Signal(); |
|
422 |
test(d1.iInnerLoops == 1); |
|
423 |
test(d2.iInnerLoops == 1); |
|
424 |
||
425 |
cvg1.Close(); |
|
426 |
cvg2.Close(); |
|
427 |
test(s1==KRequestPending); |
|
428 |
test(s2==KRequestPending); |
|
429 |
test(d1.iInnerLoops == 1); |
|
430 |
test(d2.iInnerLoops == 1); |
|
431 |
||
432 |
t1.Kill(0); |
|
433 |
t2.Kill(0); |
|
434 |
User::WaitForRequest(s1); |
|
435 |
User::WaitForRequest(s2); |
|
436 |
test(t1.ExitType()==EExitKill); |
|
437 |
test(t1.ExitReason()==0); |
|
438 |
test(t2.ExitType()==EExitKill); |
|
439 |
test(t2.ExitReason()==0); |
|
440 |
CLOSE_AND_WAIT(t1); |
|
441 |
CLOSE_AND_WAIT(t2); |
|
442 |
r = cvg1.OpenGlobal(TPtrC(KCondVar1Name)); |
|
443 |
test(r==KErrNotFound); |
|
444 |
test(cvg1.Handle()==0); |
|
445 |
mg1.Close(); |
|
446 |
mg2.Close(); |
|
447 |
} |
|
448 |
||
449 |
void TestSecondaryProcess() |
|
450 |
{ |
|
451 |
test.Next(_L("Test Secondary Process")); |
|
452 |
||
453 |
RProcess p; |
|
454 |
RChunk c; |
|
455 |
RMutex m; |
|
456 |
RCondVar cv; |
|
457 |
||
458 |
//cancel lazy dll unloading |
|
459 |
RLoader loader; |
|
460 |
TInt r = loader.Connect(); |
|
461 |
test(r==KErrNone); |
|
462 |
r = loader.CancelLazyDllUnload(); |
|
463 |
test(r==KErrNone); |
|
464 |
loader.Close(); |
|
465 |
||
466 |
r = c.CreateGlobal(KNullDesC, 0x1000, 0x1000); |
|
467 |
test(r==KErrNone); |
|
468 |
volatile TInt& x = *(volatile TInt*)c.Base(); |
|
469 |
x = 0; |
|
470 |
r = m.CreateGlobal(KNullDesC); |
|
471 |
test(r==KErrNone); |
|
472 |
r = cv.CreateGlobal(KNullDesC); |
|
473 |
test(r==KErrNone); |
|
474 |
r = p.Create(RProcess().FileName(), KNullDesC); |
|
475 |
test(r==KErrNone); |
|
476 |
p.SetPriority(EPriorityHigh); |
|
477 |
r = p.SetParameter(1, cv); |
|
478 |
test(r==KErrNone); |
|
479 |
r = p.SetParameter(2, m); |
|
480 |
test(r==KErrNone); |
|
481 |
r = p.SetParameter(3, c); |
|
482 |
test(r==KErrNone); |
|
483 |
TRequestStatus s; |
|
484 |
p.Logon(s); |
|
485 |
p.Resume(); |
|
486 |
test(s==KRequestPending); |
|
487 |
test(x==0); |
|
488 |
TInt i; |
|
489 |
for (i=0; i<10; ++i) |
|
490 |
{ |
|
491 |
cv.Signal(); |
|
492 |
test(x == i+1); |
|
493 |
} |
|
494 |
cv.Close(); |
|
495 |
test(s==KRequestPending); |
|
496 |
test(x==10); |
|
497 |
p.Terminate(0); |
|
498 |
User::WaitForRequest(s); |
|
499 |
test(p.ExitType()==EExitTerminate); |
|
500 |
test(p.ExitReason()==0); |
|
501 |
CLOSE_AND_WAIT(p); |
|
502 |
m.Close(); |
|
503 |
c.Close(); |
|
504 |
} |
|
505 |
||
506 |
TInt SecondaryProcess(RCondVar aCV) |
|
507 |
{ |
|
508 |
RDebug::Print(_L("SecProc")); |
|
509 |
RMutex mp; |
|
510 |
RChunk cp; |
|
511 |
TInt r = mp.Open(2); |
|
512 |
if (r!=KErrNone) |
|
513 |
return r; |
|
514 |
r = cp.Open(3); |
|
515 |
if (r!=KErrNone) |
|
516 |
return r; |
|
517 |
volatile TInt& x = *(volatile TInt*)cp.Base(); |
|
518 |
mp.Wait(); |
|
519 |
r = KErrNone; |
|
520 |
while (r==KErrNone) |
|
521 |
{ |
|
522 |
r = aCV.Wait(mp); |
|
523 |
++x; |
|
524 |
RDebug::Print(_L("SecProc r=%d x=%d"), r, x); |
|
525 |
} |
|
526 |
return r; |
|
527 |
} |
|
528 |
||
529 |
TInt E32Main() |
|
530 |
{ |
|
117
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
531 |
TInt cpus = UserSvr::HalFunction(EHalGroupKernel, EKernelHalNumLogicalCpus, 0, 0); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
532 |
if (cpus != 1) |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
533 |
{ |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
534 |
test(cpus>1); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
535 |
// This test will require compatibility mode (and probably other changes) |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
536 |
// to work on SMP - it depends on explicit scheduling order. |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
537 |
test.Printf(_L("T_CONDVAR skipped, does not work on SMP\n")); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
538 |
return KErrNone; |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
539 |
} |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
540 |
|
0 | 541 |
__KHEAP_MARK; |
542 |
__UHEAP_MARK; |
|
543 |
||
544 |
TInt r; |
|
545 |
RCondVar cvp; |
|
546 |
r = cvp.Open(1); |
|
547 |
if (r==KErrNone) |
|
548 |
return SecondaryProcess(cvp); |
|
549 |
test.Title(); |
|
550 |
test.Start(_L("Create condition variable")); |
|
551 |
r = CV1.CreateLocal(); |
|
552 |
test(r==KErrNone); |
|
553 |
r = CV2.CreateLocal(); |
|
554 |
test(r==KErrNone); |
|
555 |
||
556 |
test.Next(_L("Signal with no-one waiting")); |
|
557 |
CV1.Signal(); |
|
558 |
||
559 |
test.Next(_L("Broadcast with no-one waiting")); |
|
560 |
CV1.Broadcast(); |
|
561 |
||
562 |
test.Next(_L("Create mutexes")); |
|
563 |
r = M1.CreateLocal(); |
|
564 |
test(r==KErrNone); |
|
565 |
r = M2.CreateLocal(); |
|
566 |
test(r==KErrNone); |
|
567 |
||
568 |
RArray<TInt> array; |
|
569 |
SThreadData d0; |
|
570 |
d0.iM = M2; |
|
571 |
d0.iV = CV1; |
|
572 |
d0.iA = &array; |
|
573 |
test.Next(_L("Create thread to use mutex 2")); |
|
574 |
RThread t0; |
|
575 |
r = t0.Create(KNullDesC, &Thread1, 0x1000, 0x1000, 0x1000, &d0); |
|
576 |
test(r==KErrNone); |
|
577 |
t0.SetPriority(EPriorityMore); |
|
578 |
TRequestStatus s0; |
|
579 |
t0.Logon(s0); |
|
580 |
t0.Resume(); |
|
581 |
__TRACE_LINE__; |
|
582 |
AppendToArray(d0, 1, 4); |
|
583 |
test(d0.iTotal==4); |
|
584 |
__TRACE_LINE__; |
|
585 |
AppendToArray(d0, 2, -3, 17); |
|
586 |
test(d0.iTotal==18); |
|
587 |
t0.Terminate(11); |
|
588 |
User::WaitForRequest(s0); |
|
589 |
test(t0.ExitType()==EExitTerminate); |
|
590 |
test(t0.ExitReason()==11); |
|
591 |
CLOSE_AND_WAIT(t0); |
|
592 |
array.Reset(); |
|
593 |
||
594 |
SThreadData d; |
|
595 |
d.iM = M1; |
|
596 |
d.iV = CV1; |
|
597 |
d.iA = &array; |
|
598 |
test.Next(_L("Create thread to use mutex 1")); |
|
599 |
RThread t; |
|
600 |
r = t.Create(KNullDesC, &Thread1, 0x1000, 0x1000, 0x1000, &d); |
|
601 |
test(r==KErrNone); |
|
602 |
t.SetPriority(EPriorityMore); |
|
603 |
TRequestStatus s; |
|
604 |
t.Logon(s); |
|
605 |
t.Resume(); |
|
606 |
||
607 |
test.Next(_L("Test wait with mutex unlocked")); |
|
608 |
r = t0.Create(KNullDesC, &Thread0, 0x1000, 0x1000, 0x1000, NULL); |
|
609 |
test(r==KErrNone); |
|
610 |
t0.SetPriority(EPriorityMore); |
|
611 |
t0.Logon(s0); |
|
612 |
TBool jit = User::JustInTime(); |
|
613 |
User::SetJustInTime(EFalse); |
|
614 |
t0.Resume(); |
|
615 |
User::WaitForRequest(s0); |
|
616 |
User::SetJustInTime(jit); |
|
617 |
test(t0.ExitType()==EExitPanic); |
|
618 |
test(t0.ExitCategory()==_L("KERN-EXEC")); |
|
619 |
test(t0.ExitReason()==ECondVarWaitMutexNotLocked); |
|
620 |
CLOSE_AND_WAIT(t0); |
|
621 |
||
622 |
test.Next(_L("Test trying to use two mutexes with 1 condition variable")); |
|
623 |
M2.Wait(); |
|
624 |
r = CV1.Wait(M2); |
|
625 |
M2.Signal(); |
|
626 |
test(r==KErrInUse); |
|
627 |
||
628 |
test(d.iTotal==0); |
|
629 |
__TRACE_LINE__; |
|
630 |
AppendToArray(d, 1, 3); |
|
631 |
test(d.iTotal==3); |
|
632 |
__TRACE_LINE__; |
|
633 |
AppendToArray(d, 2, 3, 19); |
|
634 |
test(d.iTotal==25); |
|
635 |
__TRACE_LINE__; |
|
636 |
AppendToArray(d, 4, 15, -1, -2, -30); |
|
637 |
test(d.iTotal==7); |
|
638 |
test(d.iInnerLoops==3); |
|
639 |
test(d.iOuterLoops==3); |
|
640 |
__TRACE_LINE__; |
|
641 |
t.Suspend(); |
|
642 |
__TRACE_LINE__; |
|
643 |
t.Resume(); |
|
644 |
test(d.iTotal==7); |
|
645 |
test(d.iInnerLoops==4); |
|
646 |
test(d.iOuterLoops==3); |
|
647 |
__TRACE_LINE__; |
|
648 |
t.SetPriority(EPriorityLess); |
|
649 |
test(d.iTotal==7); |
|
650 |
test(d.iInnerLoops==4); |
|
651 |
test(d.iOuterLoops==3); |
|
652 |
__TRACE_LINE__; |
|
653 |
t.SetPriority(EPriorityMore); |
|
654 |
test(d.iTotal==7); |
|
655 |
test(d.iInnerLoops==5); |
|
656 |
test(d.iOuterLoops==3); |
|
657 |
__TRACE_LINE__; |
|
658 |
t.Suspend(); |
|
659 |
__TRACE_LINE__; |
|
660 |
AppendToArray(d, 1, 4); |
|
661 |
test(d.iTotal==7); |
|
662 |
test(d.iInnerLoops==5); |
|
663 |
test(d.iOuterLoops==3); |
|
664 |
__TRACE_LINE__; |
|
665 |
t.Resume(); |
|
666 |
test(d.iTotal==11); |
|
667 |
test(d.iInnerLoops==6); |
|
668 |
test(d.iOuterLoops==4); |
|
669 |
||
670 |
SThreadData d2; |
|
671 |
d2.iM = M1; |
|
672 |
d2.iV = CV1; |
|
673 |
d2.iA = &array; |
|
674 |
||
675 |
test.Next(_L("Create 2nd thread")); |
|
676 |
RThread t2; |
|
677 |
r = t2.Create(KNullDesC, &Thread1, 0x1000, NULL, &d2); |
|
678 |
test(r==KErrNone); |
|
679 |
t2.SetPriority(EPriorityMuchMore); |
|
680 |
TRequestStatus s2; |
|
681 |
t2.Logon(s2); |
|
682 |
__TRACE_LINE__; |
|
683 |
t2.Resume(); |
|
684 |
||
685 |
test(d2.iTotal == 11); |
|
686 |
test(d2.iInnerLoops == 0); |
|
687 |
test(d2.iOuterLoops == 1); |
|
688 |
__TRACE_LINE__; |
|
689 |
AppendToArray(d, 2, 9, 10); |
|
690 |
test(d2.iTotal == 30); |
|
691 |
test(d2.iInnerLoops == 1); |
|
692 |
test(d2.iOuterLoops == 2); |
|
693 |
test(d.iTotal==11); |
|
694 |
test(d.iInnerLoops==6); |
|
695 |
test(d.iOuterLoops==4); |
|
696 |
__TRACE_LINE__; |
|
697 |
AppendToArrayB(d, 2, 20, 30); |
|
698 |
test(d2.iTotal == 80); |
|
699 |
test(d2.iInnerLoops == 2); |
|
700 |
test(d2.iOuterLoops == 3); |
|
701 |
test(d.iTotal == 80); |
|
702 |
test(d.iInnerLoops == 7); |
|
703 |
test(d.iOuterLoops == 5); |
|
704 |
__TRACE_LINE__; |
|
705 |
AppendToArrayB2(d, 2, -10, -6); |
|
706 |
test(d2.iTotal == 64); |
|
707 |
test(d2.iInnerLoops == 3); |
|
708 |
test(d2.iOuterLoops == 4); |
|
709 |
test(d.iTotal == 64); |
|
710 |
test(d.iInnerLoops == 8); |
|
711 |
test(d.iOuterLoops == 6); |
|
712 |
__TRACE_LINE__; |
|
713 |
t2.Suspend(); |
|
714 |
__TRACE_LINE__; |
|
715 |
AppendToArray(d, 2, -8, -8); |
|
716 |
test(d2.iTotal == 64); |
|
717 |
test(d2.iInnerLoops == 3); |
|
718 |
test(d2.iOuterLoops == 4); |
|
719 |
test(d.iTotal == 48); |
|
720 |
test(d.iInnerLoops == 9); |
|
721 |
test(d.iOuterLoops == 7); |
|
722 |
__TRACE_LINE__; |
|
723 |
t2.Resume(); |
|
724 |
test(d2.iTotal == 48); |
|
725 |
test(d2.iInnerLoops == 4); |
|
726 |
test(d2.iOuterLoops == 5); |
|
727 |
test(d.iTotal == 48); |
|
728 |
test(d.iInnerLoops == 9); |
|
729 |
test(d.iOuterLoops == 7); |
|
730 |
||
731 |
// test timeouts |
|
732 |
d.iTimeoutMs = 1000; |
|
733 |
__TRACE_LINE__; |
|
734 |
t.Suspend(); |
|
735 |
__TRACE_LINE__; |
|
736 |
t.Resume(); |
|
737 |
test(d2.iTotal == 48); |
|
738 |
test(d2.iInnerLoops == 4); |
|
739 |
test(d2.iOuterLoops == 5); |
|
740 |
test(d2.iTimeouts == 0); |
|
741 |
test(d.iTotal == 48); |
|
742 |
test(d.iInnerLoops == 10); |
|
743 |
test(d.iOuterLoops == 7); |
|
744 |
test(d.iTimeouts == 0); |
|
745 |
test(array.Append(1)==0); |
|
746 |
TInt nt = 0; |
|
747 |
do { |
|
748 |
if (d.iTimeouts > nt) |
|
749 |
{ |
|
750 |
test(d.iTimeouts-nt == 1); |
|
751 |
nt = d.iTimeouts; |
|
752 |
test.Printf(_L("Timeout %d\n"), nt); |
|
753 |
test(d2.iTotal == 48); |
|
754 |
test(d2.iInnerLoops == 4); |
|
755 |
test(d2.iOuterLoops == 5); |
|
756 |
test(d2.iTimeouts == 0); |
|
757 |
test(d.iTotal == 48+nt); |
|
758 |
test(d.iInnerLoops == 10+nt); |
|
759 |
test(d.iOuterLoops == 7+nt); |
|
760 |
test(array.Append(1)==0); |
|
761 |
} |
|
762 |
} while (nt<10); |
|
763 |
||
764 |
d.iTimeoutMs = 0; |
|
765 |
AppendToArrayB(d, 0); |
|
766 |
test(d2.iTotal == 59); |
|
767 |
test(d2.iInnerLoops == 5); |
|
768 |
test(d2.iOuterLoops == 6); |
|
769 |
test(d2.iTimeouts == 0); |
|
770 |
test(d.iTotal == 59); |
|
771 |
test(d.iInnerLoops == 21); |
|
772 |
test(d.iOuterLoops == 18); |
|
773 |
test(d.iTimeouts == 10); |
|
774 |
||
775 |
__TRACE_LINE__; |
|
776 |
t.SetPriority(EPriorityLess); |
|
777 |
__TRACE_LINE__; |
|
778 |
AppendToArrayB(d, 1, 11); |
|
779 |
test(d2.iTotal == 70); |
|
780 |
test(d2.iInnerLoops == 6); |
|
781 |
test(d2.iOuterLoops == 7); |
|
782 |
test(d2.iTimeouts == 0); |
|
783 |
test(d.iTotal == 59); |
|
784 |
test(d.iInnerLoops == 21); |
|
785 |
test(d.iOuterLoops == 18); |
|
786 |
test(d.iTimeouts == 10); |
|
787 |
User::After(50000); |
|
788 |
test(d2.iTotal == 70); |
|
789 |
test(d2.iInnerLoops == 6); |
|
790 |
test(d2.iOuterLoops == 7); |
|
791 |
test(d2.iTimeouts == 0); |
|
792 |
test(d.iTotal == 70); |
|
793 |
test(d.iInnerLoops == 22); |
|
794 |
test(d.iOuterLoops == 19); |
|
795 |
test(d.iTimeouts == 10); |
|
796 |
||
797 |
||
798 |
||
799 |
__TRACE_LINE__; |
|
800 |
CV1.Close(); |
|
801 |
User::WaitForRequest(s); |
|
802 |
test(t.ExitType()==EExitKill); |
|
803 |
test(t.ExitReason()==KErrGeneral); |
|
804 |
User::WaitForRequest(s2); |
|
805 |
test(t2.ExitType()==EExitKill); |
|
806 |
test(t2.ExitReason()==KErrGeneral); |
|
807 |
CLOSE_AND_WAIT(t); |
|
808 |
CLOSE_AND_WAIT(t2); |
|
809 |
||
810 |
||
811 |
M1.Close(); |
|
812 |
||
813 |
TestGlobal(); |
|
814 |
||
815 |
Thread2Test(); |
|
816 |
||
817 |
TestSecondaryProcess(); |
|
818 |
||
819 |
RunBench(); |
|
820 |
M2.Close(); |
|
821 |
CV2.Close(); |
|
822 |
array.Close(); |
|
823 |
||
824 |
test.End(); |
|
825 |
test.Close(); |
|
826 |
||
827 |
__UHEAP_MARKEND; |
|
828 |
__KHEAP_MARKEND; |
|
829 |
return KErrNone; |
|
830 |
} |
|
831 |