author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 25 May 2010 14:09:55 +0300 | |
branch | RCL_3 |
changeset 117 | 5b5d147c7838 |
parent 0 | a41df078684a |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 1995-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\prime\t_semutx2.cpp |
|
15 |
// Test RSemaphore and RMutex |
|
16 |
// Overview: |
|
17 |
// Tests the RSemaphore and RMutex |
|
18 |
// API Information: |
|
19 |
// RSemaphore, RMutex |
|
20 |
// Details: |
|
21 |
// - Test and verify that thread priorities work as expected. |
|
22 |
// - Test and verify that signalling an RMutex from the wrong |
|
23 |
// thread fails as expected. |
|
24 |
// - Test and verify that mutex priority inheritance works as |
|
25 |
// expected. |
|
26 |
// - Perform an exhaustive state transition test using mutexs |
|
27 |
// and up to ten threads. Verify priorities, order of execution, |
|
28 |
// mutex signalling, suspend, resume, kill and close. Verify |
|
29 |
// results are as expected. |
|
30 |
// - Test semaphore speed by counting how many Wait/Signal |
|
31 |
// operations can be completed in one second. |
|
32 |
// Platforms/Drives/Compatibility: |
|
33 |
// All. |
|
34 |
// Assumptions/Requirement/Pre-requisites: |
|
35 |
// Failures and causes: |
|
36 |
// Base Port information: |
|
37 |
// |
|
38 |
// |
|
39 |
||
117
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
40 |
#define __E32TEST_EXTENSION__ |
0 | 41 |
#include <e32test.h> |
117
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
42 |
#include <u32std.h> |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
43 |
#include <e32svr.h> |
0 | 44 |
|
45 |
RMutex M1; |
|
46 |
RMutex M2; |
|
47 |
RSemaphore S; |
|
48 |
||
49 |
const TInt KBufferSize=4096; |
|
50 |
TUint ThreadId[KBufferSize]; |
|
51 |
TInt PutIx; |
|
52 |
TInt GetIx; |
|
53 |
TInt Count; |
|
54 |
RThread Main; |
|
55 |
||
56 |
||
57 |
RTest test(_L("T_SEMUTX2")); |
|
58 |
||
59 |
/***************************************************************************** |
|
60 |
* Utility functions / macros |
|
61 |
*****************************************************************************/ |
|
62 |
#define TRACE_ON User::SetDebugMask(0xffdfffff); |
|
63 |
#define TRACE_OFF User::SetDebugMask(0x80000000); |
|
64 |
||
65 |
//#define MCOUNT(m,c) test((m).Count() ==(c)) |
|
66 |
// mutex count value is not visible for user any more |
|
67 |
#define MCOUNT(m,c) (void)(1) |
|
117
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
68 |
#define IDCHECK(x) test_Equal((x), GetNextId()) |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
69 |
#define NUMCHECK(x) test_Equal((x), NumIdsPending()) |
0 | 70 |
|
71 |
#define id0 id[0] |
|
72 |
#define id1 id[1] |
|
73 |
#define id2 id[2] |
|
74 |
#define id3 id[3] |
|
75 |
#define id4 id[4] |
|
76 |
#define id5 id[5] |
|
77 |
#define id6 id[6] |
|
78 |
#define id7 id[7] |
|
79 |
#define id8 id[8] |
|
80 |
#define id9 id[9] |
|
81 |
#define id10 id[10] |
|
82 |
||
83 |
TBool Exists(const TDesC& aName) |
|
84 |
{ |
|
85 |
TFullName n(RProcess().Name()); |
|
86 |
n+=_L("::"); |
|
87 |
n+=aName; |
|
88 |
TFindThread ft(n); |
|
89 |
TFullName fn; |
|
90 |
return ft.Next(fn)==KErrNone; |
|
91 |
} |
|
92 |
||
93 |
TBool Exists(TInt aNum) |
|
94 |
{ |
|
95 |
TBuf<4> b; |
|
96 |
b.Num(aNum); |
|
97 |
return Exists(b); |
|
98 |
} |
|
99 |
||
100 |
void BusyWait(TInt aMicroseconds) |
|
101 |
{ |
|
102 |
TTime begin; |
|
103 |
begin.HomeTime(); |
|
104 |
FOREVER |
|
105 |
{ |
|
106 |
TTime now; |
|
107 |
now.HomeTime(); |
|
108 |
TTimeIntervalMicroSeconds iv=now.MicroSecondsFrom(begin); |
|
109 |
if (iv.Int64()>=TInt64(aMicroseconds)) |
|
110 |
return; |
|
111 |
} |
|
112 |
} |
|
113 |
||
114 |
void Kick(RThread& t) |
|
115 |
{ |
|
116 |
TRequestStatus s; |
|
117 |
TRequestStatus* pS=&s; |
|
118 |
t.RequestComplete(pS,0); |
|
119 |
} |
|
120 |
||
121 |
TUint GetNextId() |
|
122 |
{ |
|
123 |
if (GetIx<PutIx) |
|
124 |
return ThreadId[GetIx++]; |
|
125 |
return 0; |
|
126 |
} |
|
127 |
||
128 |
TInt NumIdsPending() |
|
129 |
{ |
|
130 |
return PutIx-GetIx; |
|
131 |
} |
|
132 |
||
133 |
/***************************************************************************** |
|
134 |
* General tests |
|
135 |
*****************************************************************************/ |
|
136 |
TInt Test0Thread(TAny* aPtr) |
|
137 |
{ |
|
138 |
TInt& count=*(TInt*)aPtr; |
|
139 |
++count; |
|
140 |
Main.SetPriority(EPriorityMuchMore); |
|
141 |
++count; |
|
142 |
Main.SetPriority(EPriorityMuchMore); |
|
143 |
++count; |
|
144 |
RThread().SetPriority(EPriorityNormal); |
|
145 |
++count; |
|
146 |
return 0; |
|
147 |
} |
|
148 |
||
149 |
void Test0() |
|
150 |
{ |
|
151 |
User::After(100000); // Test fails intermittently on hardware unless we pause here |
|
152 |
||
153 |
test.Start(_L("Test thread priorities work")); |
|
154 |
test.Next(_L("Create thread")); |
|
155 |
RThread t; |
|
156 |
TInt count=0; |
|
157 |
TRequestStatus s; |
|
158 |
TInt r=t.Create(_L("Test0"),Test0Thread,0x1000,NULL,&count); |
|
117
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
159 |
test_KErrNone(r); |
0 | 160 |
t.Logon(s); |
117
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
161 |
test_KErrNone(r); |
0 | 162 |
User::After(10000); // make sure we have a full timeslice |
163 |
t.Resume(); |
|
164 |
||
117
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
165 |
test_Equal(0, count); // t shouldn't have run yet |
0 | 166 |
RThread().SetPriority(EPriorityMuchMore); // shouldn't reschedule (priority unchanged) |
117
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
167 |
test_Equal(0, count); |
0 | 168 |
RThread().SetPriority(EPriorityMore); // shouldn't reschedule (priority decreasing, but not enough) |
117
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
169 |
test_Equal(0, count); |
0 | 170 |
RThread().SetPriority(EPriorityMuchMore); // shouldn't reschedule (priority increasing) |
117
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
171 |
test_Equal(0, count); |
0 | 172 |
RThread().SetPriority(EPriorityNormal); // should reschedule (we go behind t) |
117
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
173 |
test_Equal(1, count); |
0 | 174 |
RThread().SetPriority(EPriorityLess); // should reschedule (priority decreasing to below t) |
117
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
175 |
test_Equal(2, count); |
0 | 176 |
t.SetPriority(EPriorityMuchMore); // shouldn't reschedule (round-robin, timeslice not expired) |
117
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
177 |
test_Equal(2, count); |
0 | 178 |
t.SetPriority(EPriorityNormal); // shouldn't reschedule (t's priority decreasing) |
117
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
179 |
test_Equal(2, count); |
0 | 180 |
t.SetPriority(EPriorityNormal); // shouldn't reschedule (t's priority unchanged) |
117
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
181 |
test_Equal(2, count); |
0 | 182 |
BusyWait(100000); // use up our timeslice |
183 |
t.SetPriority(EPriorityMuchMore); // should reschedule (round-robin, timeslice expired) |
|
117
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
184 |
test_Equal(3, count); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
185 |
test_Equal(KRequestPending, s.Int()); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
186 |
test_Equal(EExitPending, t.ExitType()); |
0 | 187 |
t.SetPriority(EPriorityRealTime); // should reschedule (t increases above current) |
117
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
188 |
test_Equal(4, count); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
189 |
test_KErrNone(s.Int()); // t should have exited |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
190 |
test_Equal(EExitKill, t.ExitType()); |
0 | 191 |
User::WaitForRequest(s); |
192 |
RThread().SetPriority(EPriorityMuchMore); |
|
193 |
t.Close(); |
|
194 |
test.End(); |
|
195 |
} |
|
196 |
||
197 |
TInt Test1Thread(TAny*) |
|
198 |
{ |
|
199 |
M1.Signal(); |
|
200 |
return 0; |
|
201 |
} |
|
202 |
||
203 |
void Test1() |
|
204 |
{ |
|
205 |
test.Start(_L("Test signalling from wrong thread")); |
|
206 |
TInt r=M1.CreateLocal(); |
|
117
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
207 |
test_KErrNone(r); |
0 | 208 |
M1.Wait(); |
209 |
RThread t; |
|
210 |
r=t.Create(_L("Test1"),Test1Thread,0x1000,NULL,NULL); |
|
117
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
211 |
test_KErrNone(r); |
0 | 212 |
TRequestStatus s; |
213 |
t.Logon(s); |
|
214 |
t.Resume(); |
|
215 |
TBool jit = User::JustInTime(); |
|
216 |
User::SetJustInTime(EFalse); |
|
217 |
User::WaitForRequest(s); |
|
218 |
User::SetJustInTime(jit); |
|
117
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
219 |
test_Equal(EAccessDenied, s.Int()); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
220 |
test_Equal(EExitPanic, t.ExitType()); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
221 |
test_Equal(EAccessDenied, t.ExitReason()); |
0 | 222 |
test(t.ExitCategory()==_L("KERN-EXEC")); |
223 |
t.Close(); |
|
224 |
M1.Close(); |
|
225 |
test.End(); |
|
226 |
} |
|
227 |
||
228 |
/***************************************************************************** |
|
229 |
* Mutex priority inheritance |
|
230 |
*****************************************************************************/ |
|
231 |
||
232 |
const TInt KTestDelay = 1000000; |
|
233 |
||
234 |
TInt LowThread(TAny* aPtr) |
|
235 |
{ |
|
236 |
TInt& count=*(TInt*)aPtr; |
|
237 |
FOREVER |
|
238 |
{ |
|
239 |
M1.Wait(); |
|
240 |
++count; |
|
241 |
BusyWait(KTestDelay); |
|
242 |
M1.Signal(); |
|
243 |
User::WaitForAnyRequest(); |
|
244 |
} |
|
245 |
} |
|
246 |
||
247 |
TInt MedThread(TAny* aPtr) |
|
248 |
{ |
|
249 |
TInt& count=*(TInt*)aPtr; |
|
250 |
FOREVER |
|
251 |
{ |
|
252 |
++count; |
|
253 |
User::WaitForAnyRequest(); |
|
254 |
} |
|
255 |
} |
|
256 |
||
257 |
TInt HighThread(TAny* aPtr) |
|
258 |
{ |
|
259 |
TInt& count=*(TInt*)aPtr; |
|
260 |
FOREVER |
|
261 |
{ |
|
262 |
M2.Wait(); |
|
263 |
++count; |
|
264 |
M1.Wait(); |
|
265 |
++count; |
|
266 |
BusyWait(KTestDelay); |
|
267 |
M1.Signal(); |
|
268 |
M2.Signal(); |
|
269 |
User::WaitForAnyRequest(); |
|
270 |
} |
|
271 |
} |
|
272 |
||
273 |
void TestMutex1() |
|
274 |
{ |
|
275 |
test.Start(_L("Test mutex priority inheritance")); |
|
276 |
||
277 |
test.Next(_L("Create mutex")); |
|
278 |
TInt r=M1.CreateLocal(); |
|
117
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
279 |
test_KErrNone(r); |
0 | 280 |
|
281 |
test.Next(_L("Create low priority thread")); |
|
282 |
TInt lowcount=0; |
|
283 |
RThread low; |
|
284 |
r=low.Create(_L("low"),LowThread,0x1000,NULL,&lowcount); |
|
117
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
285 |
test_KErrNone(r); |
0 | 286 |
low.SetPriority(EPriorityMuchLess); |
287 |
test(Exists(_L("low"))); |
|
288 |
||
289 |
test.Next(_L("Create medium priority thread")); |
|
290 |
TInt medcount=0; |
|
291 |
RThread med; |
|
292 |
r=med.Create(_L("med"),MedThread,0x1000,NULL,&medcount); |
|
117
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
293 |
test_KErrNone(r); |
0 | 294 |
med.SetPriority(EPriorityNormal); |
295 |
test(Exists(_L("med"))); |
|
296 |
||
297 |
test.Next(_L("Start low priority thread")); |
|
298 |
low.Resume(); |
|
299 |
User::AfterHighRes(KTestDelay/10); |
|
117
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
300 |
test_Equal(1, lowcount); |
0 | 301 |
// MCOUNT(M1,0); |
302 |
||
303 |
test.Next(_L("Start medium priority thread")); |
|
304 |
med.Resume(); |
|
305 |
User::AfterHighRes(KTestDelay/10); |
|
117
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
306 |
test_Equal(1, medcount); |
0 | 307 |
Kick(med); |
308 |
User::AfterHighRes(KTestDelay/10); |
|
117
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
309 |
test_Equal(2, medcount); |
0 | 310 |
Kick(med); |
311 |
||
312 |
M1.Wait(); |
|
117
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
313 |
test_Equal(1, lowcount); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
314 |
test_Equal(2, medcount); |
0 | 315 |
test.Next(_L("Wait, check medium runs")); |
316 |
User::AfterHighRes(KTestDelay/10); |
|
117
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
317 |
test_Equal(3, medcount); |
0 | 318 |
M1.Signal(); |
319 |
||
320 |
test.Next(_L("Create mutex 2")); |
|
321 |
r=M2.CreateLocal(); |
|
117
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
322 |
test_KErrNone(r); |
0 | 323 |
|
324 |
test.Next(_L("Create high priority thread")); |
|
325 |
TInt highcount=0; |
|
326 |
RThread high; |
|
327 |
r=high.Create(_L("high"),HighThread,0x1000,NULL,&highcount); |
|
117
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
328 |
test_KErrNone(r); |
0 | 329 |
high.SetPriority(EPriorityMore); |
330 |
test(Exists(_L("high"))); |
|
331 |
||
332 |
Kick(low); |
|
333 |
User::AfterHighRes(KTestDelay/10); |
|
334 |
// MCOUNT(M1,0); |
|
335 |
Kick(med); |
|
336 |
||
337 |
// MCOUNT(M2,1); |
|
338 |
high.Resume(); |
|
339 |
User::AfterHighRes(KTestDelay/10); |
|
340 |
// MCOUNT(M2,0); |
|
341 |
// MCOUNT(M1,-1); |
|
117
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
342 |
test_Equal(1, highcount); |
0 | 343 |
|
344 |
M2.Wait(); |
|
117
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
345 |
test_Equal(2, lowcount); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
346 |
test_Equal(3, medcount); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
347 |
test_Equal(2, highcount); |
0 | 348 |
test.Next(_L("Wait, check medium runs")); |
349 |
User::AfterHighRes(KTestDelay/10); |
|
117
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
350 |
test_Equal(4, medcount); |
0 | 351 |
M2.Signal(); |
352 |
||
353 |
test.Next(_L("Kill threads")); |
|
354 |
low.Kill(0); |
|
355 |
med.Kill(0); |
|
356 |
high.Kill(0); |
|
357 |
low.Close(); |
|
358 |
med.Close(); |
|
359 |
high.Close(); |
|
360 |
test(!Exists(_L("low"))); |
|
361 |
test(!Exists(_L("med"))); |
|
362 |
test(!Exists(_L("high"))); |
|
363 |
||
364 |
M1.Close(); |
|
365 |
test.End(); |
|
366 |
} |
|
367 |
||
368 |
/***************************************************************************** |
|
369 |
* Utilities for mutex exhaustive state transition test |
|
370 |
*****************************************************************************/ |
|
371 |
void MutexWait() |
|
372 |
{ |
|
373 |
M1.Wait(); |
|
374 |
++Count; |
|
375 |
ThreadId[PutIx++]=(TUint)RThread().Id(); |
|
376 |
} |
|
377 |
||
378 |
void MutexSignal() |
|
379 |
{ |
|
380 |
M1.Signal(); |
|
381 |
} |
|
382 |
||
383 |
typedef void (*PFV)(void); |
|
384 |
TInt ThreadFunction(TAny* aPtr) |
|
385 |
{ |
|
386 |
PFV& f=*(PFV*)aPtr; |
|
387 |
FOREVER |
|
388 |
{ |
|
389 |
MutexWait(); |
|
390 |
if (f) |
|
391 |
f(); |
|
392 |
MutexSignal(); |
|
393 |
User::WaitForAnyRequest(); |
|
394 |
} |
|
395 |
} |
|
396 |
||
397 |
void Exit() |
|
398 |
{ |
|
399 |
User::Exit(0); |
|
400 |
} |
|
401 |
||
402 |
TUint CreateThread(RThread& t, TInt n, TAny* aPtr) |
|
403 |
{ |
|
404 |
TBuf<4> b; |
|
405 |
b.Num(n); |
|
406 |
TInt r=t.Create(b,ThreadFunction,0x1000,NULL,aPtr); |
|
117
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
407 |
test_KErrNone(r); |
0 | 408 |
t.Resume(); |
409 |
TUint id=t.Id(); |
|
410 |
test.Printf(_L("id=%d\n"),id); |
|
411 |
return id; |
|
412 |
} |
|
413 |
||
414 |
/* |
|
415 |
Possible thread relationships with mutex: |
|
416 |
Holding |
|
417 |
Waiting |
|
418 |
Waiting + suspended |
|
419 |
Hold Pending |
|
420 |
||
421 |
Need to verify correct behaviour when the following actions occur for each of these states: |
|
422 |
Suspend thread |
|
423 |
Resume thread |
|
424 |
Change thread priority |
|
425 |
Thread exits |
|
426 |
Thread is killed |
|
427 |
Mutex deleted |
|
428 |
*/ |
|
429 |
||
430 |
PFV HoldExtra; |
|
431 |
void KickMain() |
|
432 |
{ |
|
433 |
RThread me; |
|
434 |
Kick(Main); |
|
435 |
User::WaitForAnyRequest(); |
|
436 |
me.SetPriority(EPriorityMuchMore); |
|
437 |
MutexSignal(); // this should wake up t8 |
|
438 |
MutexWait(); |
|
439 |
MutexSignal(); // this should wake up t9 |
|
440 |
MutexWait(); |
|
441 |
Kick(Main); |
|
442 |
User::WaitForAnyRequest(); |
|
443 |
if (HoldExtra) |
|
444 |
HoldExtra(); |
|
445 |
} |
|
446 |
||
447 |
void RackEmUp(RThread* t, PFV* f, TUint* id) |
|
448 |
{ |
|
449 |
// set up t4 holding |
|
450 |
// t1, t2, t5, t10 waiting |
|
451 |
// t3, t6, t7 waiting+suspended |
|
452 |
// t8, t9 pending |
|
453 |
MCOUNT(M1,1); // check mutex free |
|
454 |
Kick(t[4]); |
|
455 |
f[4]=&KickMain; |
|
456 |
User::WaitForAnyRequest(); |
|
457 |
MCOUNT(M1,0); // check mutex now held |
|
458 |
TInt i; |
|
459 |
for (i=1; i<=10; ++i) |
|
460 |
if (i!=4) |
|
461 |
Kick(t[i]); // wake up threads |
|
462 |
User::After(50000); // let threads wait |
|
463 |
MCOUNT(M1,-9); // check 9 threads waiting |
|
464 |
Kick(t[4]); |
|
465 |
User::WaitForAnyRequest(); |
|
466 |
MCOUNT(M1,-7); // check 7 threads waiting |
|
467 |
NUMCHECK(3); |
|
468 |
IDCHECK(id4); // from the initial wait |
|
469 |
IDCHECK(id4); // now have t8, t9 pending, t4 holding, rest waiting |
|
470 |
IDCHECK(id4); // now have t8, t9 pending, t4 holding, rest waiting |
|
471 |
t[4].SetPriority(EPriorityNormal); |
|
472 |
t[7].Resume(); // test resume when not suspended |
|
473 |
MCOUNT(M1,-7); // check 7 threads waiting |
|
474 |
t[3].Suspend(); |
|
475 |
t[6].Suspend(); |
|
476 |
t[7].Suspend(); // now have required state |
|
477 |
t[3].Suspend(); // suspend and resume t3 again for good measure |
|
478 |
t[3].Resume(); |
|
479 |
MCOUNT(M1,-7); // check 7 threads waiting |
|
480 |
HoldExtra=NULL; |
|
481 |
} |
|
482 |
||
483 |
void SimpleCheck(TInt n, const TUint* id, ...) |
|
484 |
{ |
|
485 |
VA_LIST list; |
|
486 |
VA_START(list,id); |
|
487 |
User::After(50000); // let stuff happen |
|
488 |
NUMCHECK(n); |
|
489 |
TInt i; |
|
490 |
for (i=0; i<n; ++i) |
|
491 |
{ |
|
492 |
TInt tn=VA_ARG(list,TInt); |
|
493 |
IDCHECK(id[tn]); |
|
494 |
} |
|
495 |
} |
|
496 |
||
497 |
void Resurrect(TInt n, TThreadPriority aPriority, RThread* t, PFV* f, TUint* id) |
|
498 |
{ |
|
499 |
f[n]=NULL; |
|
500 |
id[n]=CreateThread(t[n],n,f+n); |
|
501 |
t[n].SetPriority(EPriorityRealTime); |
|
502 |
t[n].SetPriority(aPriority); |
|
503 |
NUMCHECK(1); |
|
504 |
IDCHECK(id[n]); |
|
505 |
} |
|
506 |
||
507 |
/***************************************************************************** |
|
508 |
* Mutex exhaustive state transition test |
|
509 |
*****************************************************************************/ |
|
510 |
void TestMutex2() |
|
511 |
{ |
|
512 |
test.Start(_L("Test mutex state transitions")); |
|
513 |
RThread t[11]; |
|
514 |
TUint id[11]; |
|
515 |
PFV f[11]={NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}; |
|
516 |
id[0]=(TUint)RThread().Id(); |
|
517 |
PutIx=0; |
|
518 |
GetIx=0; |
|
519 |
Count=0; |
|
520 |
test.Next(_L("Create mutex")); |
|
521 |
TInt r=M1.CreateLocal(); |
|
117
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
522 |
test_KErrNone(r); |
0 | 523 |
MCOUNT(M1,1); |
524 |
MutexWait(); |
|
525 |
MCOUNT(M1,0); |
|
526 |
IDCHECK(id[0]); |
|
527 |
test.Next(_L("Create threads")); |
|
528 |
TInt i; |
|
529 |
for (i=1; i<=5; ++i) |
|
530 |
id[i]=CreateThread(t[i],i,f+i); |
|
531 |
User::After(50000); // let threads wait on mutex |
|
532 |
MCOUNT(M1,-5); // check 5 threads waiting |
|
533 |
for (i=-4; i<=0; ++i) |
|
534 |
{ |
|
535 |
MutexSignal(); // wake up next thread |
|
536 |
MutexWait(); |
|
537 |
MCOUNT(M1,i); // check right number of threads waiting |
|
538 |
IDCHECK(id0); // check we got mutex back straight away |
|
539 |
} |
|
540 |
MutexSignal(); |
|
541 |
User::After(50000); // let threads claim mutex |
|
542 |
MutexWait(); |
|
543 |
MCOUNT(M1,0); // check no threads waiting |
|
544 |
for (i=1; i<=5; ++i) |
|
545 |
{ |
|
546 |
IDCHECK(id[i]); // check they ran in order t1...t5 |
|
547 |
Kick(t[i]); // wake up thread |
|
548 |
} |
|
549 |
IDCHECK(id0); // check we got it back last |
|
550 |
t[4].SetPriority(EPriorityMore); // make t4 higher priority |
|
551 |
User::After(50000); // let threads wait on mutex |
|
552 |
MCOUNT(M1,-5); // check 5 threads waiting |
|
553 |
// temp = M1.Count(); |
|
554 |
MutexSignal(); |
|
555 |
// temp = M1.Count(); |
|
556 |
User::After(50000); // let threads claim mutex |
|
557 |
MutexWait(); |
|
558 |
// temp = M1.Count(); |
|
559 |
MCOUNT(M1,0); // check no threads waiting |
|
560 |
IDCHECK(id4); // check they ran in order t4,t1,t2,t3,t5 |
|
561 |
IDCHECK(id1); |
|
562 |
IDCHECK(id2); |
|
563 |
IDCHECK(id3); |
|
564 |
IDCHECK(id5); |
|
565 |
IDCHECK(id0); |
|
566 |
t[4].SetPriority(EPriorityNormal); // make t4 normal priority |
|
567 |
for (i=1; i<=5; ++i) |
|
568 |
Kick(t[i]); // wake up thread |
|
569 |
User::After(50000); // let threads wait on mutex |
|
570 |
MCOUNT(M1,-5); // check 5 threads waiting |
|
571 |
||
572 |
t[3].SetPriority(EPriorityMore); // make t3 higher priority |
|
573 |
// temp = M1.Count(); |
|
574 |
MutexSignal(); |
|
575 |
// temp = M1.Count(); |
|
576 |
User::After(50000); // let threads claim mutex |
|
577 |
MutexWait(); |
|
578 |
// temp = M1.Count(); |
|
579 |
MCOUNT(M1,0); // check no threads waiting |
|
580 |
IDCHECK(id3); // check they ran in order t3,t1,t2,t4,t5 |
|
581 |
IDCHECK(id1); |
|
582 |
IDCHECK(id2); |
|
583 |
IDCHECK(id4); |
|
584 |
IDCHECK(id5); |
|
585 |
IDCHECK(id0); |
|
586 |
t[3].SetPriority(EPriorityNormal); // make t4 normal priority |
|
587 |
for (i=1; i<=5; ++i) |
|
588 |
Kick(t[i]); // wake up threads |
|
589 |
User::After(50000); // let threads wait on mutex |
|
590 |
MCOUNT(M1,-5); // check 5 threads waiting |
|
591 |
||
592 |
t[2].SetPriority(EPriorityMore); // make t2 higher priority |
|
593 |
t[1].SetPriority(EPriorityLess); // make t1 lower priority |
|
594 |
MutexSignal(); |
|
595 |
User::After(50000); // let threads claim mutex |
|
596 |
MutexWait(); |
|
597 |
MCOUNT(M1,0); // check no threads waiting |
|
598 |
IDCHECK(id2); // check they ran in order t2,t3,t4,t5,t1 |
|
599 |
IDCHECK(id3); |
|
600 |
IDCHECK(id4); |
|
601 |
IDCHECK(id5); |
|
602 |
IDCHECK(id1); |
|
603 |
IDCHECK(id0); |
|
604 |
||
605 |
for (i=1; i<=5; ++i) |
|
606 |
Kick(t[i]); // wake up threads |
|
607 |
User::After(50000); // let threads wait on mutex |
|
608 |
MCOUNT(M1,-5); // check 5 threads waiting |
|
609 |
MutexSignal(); |
|
610 |
User::After(50000); // let threads claim mutex |
|
611 |
MutexWait(); |
|
612 |
MCOUNT(M1,0); // check no threads waiting |
|
613 |
IDCHECK(id2); // check they ran in order t2,t3,t4,t5,t1 |
|
614 |
IDCHECK(id3); |
|
615 |
IDCHECK(id4); |
|
616 |
IDCHECK(id5); |
|
617 |
IDCHECK(id1); |
|
618 |
IDCHECK(id0); |
|
619 |
||
620 |
test(Exists(2)); |
|
621 |
for (i=1; i<=5; ++i) |
|
622 |
Kick(t[i]); // wake up threads |
|
623 |
User::After(50000); // let threads wait on mutex |
|
624 |
MCOUNT(M1,-5); // check 5 threads waiting |
|
625 |
f[2]=&Exit; // make t2 exit while holding the mutex |
|
626 |
MutexSignal(); |
|
627 |
User::After(50000); // let threads claim mutex |
|
628 |
MutexWait(); |
|
629 |
MCOUNT(M1,0); // check no threads waiting |
|
117
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
630 |
test_Equal(EExitKill, t[2].ExitType()); // check t2 has exited |
0 | 631 |
t[2].Close(); |
632 |
test(!Exists(2)); |
|
633 |
IDCHECK(id2); // check they ran in order t2,t3,t4,t5,t1 |
|
634 |
IDCHECK(id3); |
|
635 |
IDCHECK(id4); |
|
636 |
IDCHECK(id5); |
|
637 |
IDCHECK(id1); |
|
638 |
IDCHECK(id0); |
|
639 |
f[2]=NULL; |
|
640 |
id[2]=CreateThread(t[2],2,f+2); // recreate t2 |
|
641 |
User::After(50000); // let new t2 wait on mutex |
|
642 |
MCOUNT(M1,-1); // check 1 thread waiting |
|
643 |
MutexSignal(); |
|
644 |
User::After(50000); // let t2 claim mutex |
|
645 |
MutexWait(); |
|
646 |
MCOUNT(M1,0); // check no threads waiting |
|
647 |
IDCHECK(id2); |
|
648 |
IDCHECK(id0); |
|
649 |
||
650 |
t[2].SetPriority(EPriorityLess); // make t2 lower priority |
|
651 |
for (i=1; i<=5; ++i) |
|
652 |
Kick(t[i]); // wake up threads |
|
653 |
User::After(50000); // let threads wait on mutex |
|
654 |
MCOUNT(M1,-5); // check 5 threads waiting |
|
655 |
MutexSignal(); // t3 now pending |
|
656 |
MCOUNT(M1,-3); // check 4 threads waiting, mutex free |
|
657 |
t[3].Suspend(); // this should wake up t4 |
|
658 |
MCOUNT(M1,-2); // check 3 threads waiting, mutex free |
|
659 |
User::After(50000); // let threads claim mutex |
|
660 |
MutexWait(); |
|
661 |
MCOUNT(M1,0); // check no threads still waiting |
|
662 |
IDCHECK(id4); // check they ran in order t4,t5,t1,t2 |
|
663 |
IDCHECK(id5); |
|
664 |
IDCHECK(id1); |
|
665 |
IDCHECK(id2); |
|
666 |
IDCHECK(id0); |
|
667 |
Kick(t[1]); // wake up t1 |
|
668 |
User::After(50000); // let thread wait on mutex |
|
669 |
MCOUNT(M1,-1); // check 1 thread waiting |
|
670 |
t[3].Resume(); // resume pending t3 |
|
671 |
MutexSignal(); |
|
672 |
User::After(50000); // let t2 claim mutex |
|
673 |
MutexWait(); |
|
674 |
MCOUNT(M1,0); // check no threads waiting |
|
675 |
IDCHECK(id3); // check order t3,t1 |
|
676 |
IDCHECK(id1); |
|
677 |
IDCHECK(id0); |
|
678 |
||
679 |
for (i=1; i<=5; ++i) |
|
680 |
Kick(t[i]); // wake up threads |
|
681 |
User::After(50000); // let threads wait on mutex |
|
682 |
MCOUNT(M1,-5); // check 5 threads waiting |
|
683 |
t[4].Suspend(); // suspend t4 |
|
684 |
MCOUNT(M1,-5); // check 5 threads waiting |
|
685 |
t[4].Suspend(); // suspend t4 again |
|
686 |
MCOUNT(M1,-5); // check 5 threads waiting |
|
687 |
MutexSignal(); |
|
688 |
User::After(50000); // let threads claim mutex |
|
689 |
MutexWait(); |
|
690 |
MCOUNT(M1,-1); // check 1 thread still waiting |
|
691 |
IDCHECK(id3); // check they ran in order t3,t5,t1,t2 |
|
692 |
IDCHECK(id5); |
|
693 |
IDCHECK(id1); |
|
694 |
IDCHECK(id2); |
|
695 |
IDCHECK(id0); |
|
696 |
MutexSignal(); |
|
697 |
t[4].Resume(); |
|
698 |
User::After(50000); // let threads claim mutex |
|
699 |
MutexWait(); |
|
700 |
IDCHECK(id0); // check thread didn't get mutex (still suspended) |
|
701 |
MutexSignal(); |
|
702 |
t[4].Resume(); |
|
703 |
User::After(50000); // let threads claim mutex |
|
704 |
MutexWait(); |
|
705 |
IDCHECK(id4); // check order t4 then this |
|
706 |
IDCHECK(id0); |
|
707 |
||
708 |
for (i=1; i<=5; ++i) |
|
709 |
Kick(t[i]); // wake up threads |
|
710 |
User::After(50000); // let threads wait on mutex |
|
711 |
MCOUNT(M1,-5); // check 5 threads waiting |
|
712 |
MutexWait(); // wait on mutex again |
|
713 |
IDCHECK(id0); |
|
714 |
MutexSignal(); // signal once |
|
715 |
MCOUNT(M1,-5); // check 5 threads still waiting |
|
716 |
MutexSignal(); // signal again |
|
717 |
MCOUNT(M1,-3); // check one thread has been woken up and mutex is now free |
|
718 |
User::After(50000); // let threads claim mutex |
|
719 |
MutexWait(); |
|
720 |
MCOUNT(M1,0); // check no threads still waiting |
|
721 |
IDCHECK(id3); // check they ran in order t3,t4,t5,t1,t2 |
|
722 |
IDCHECK(id4); |
|
723 |
IDCHECK(id5); |
|
724 |
IDCHECK(id1); |
|
725 |
IDCHECK(id2); |
|
726 |
IDCHECK(id0); |
|
727 |
||
728 |
test.Next(_L("Create more threads")); |
|
729 |
for (i=6; i<=10; ++i) |
|
730 |
id[i]=CreateThread(t[i],i,f+i); |
|
731 |
User::After(50000); // let threads wait on mutex |
|
732 |
MCOUNT(M1,-5); // check 5 threads waiting |
|
733 |
MutexSignal(); |
|
734 |
User::After(50000); // let threads claim mutex |
|
735 |
MCOUNT(M1,1); // check no threads still waiting and mutex free |
|
736 |
IDCHECK(id6); // check they ran in order t6,t7,t8,t9,t10 |
|
737 |
IDCHECK(id7); |
|
738 |
IDCHECK(id8); |
|
739 |
IDCHECK(id9); |
|
740 |
IDCHECK(id10); |
|
741 |
t[8].SetPriority(EPriorityMore); // t1-t3=less, t4-t7=normal, t8-t10 more, t0 much more |
|
742 |
t[9].SetPriority(EPriorityMore); |
|
743 |
t[10].SetPriority(EPriorityMore); |
|
744 |
t[2].SetPriority(EPriorityLess); |
|
745 |
t[3].SetPriority(EPriorityLess); |
|
746 |
||
747 |
RackEmUp(t,f,id); |
|
748 |
SimpleCheck(0,NULL,NULL); // holding thread still blocked |
|
749 |
Kick(t[4]); |
|
750 |
SimpleCheck(6,id,10,8,9,5,1,2); // 3,6,7 suspended |
|
751 |
t[3].Resume(); |
|
752 |
t[6].Resume(); |
|
753 |
t[7].Resume(); |
|
754 |
SimpleCheck(3,id,6,7,3); // 3,6,7 resumed |
|
755 |
||
756 |
RackEmUp(t,f,id); |
|
757 |
SimpleCheck(0,NULL,NULL); // holding thread still blocked |
|
758 |
Kick(t[4]); |
|
759 |
t[4].Suspend(); |
|
760 |
SimpleCheck(0,NULL,NULL); // holding thread suspended |
|
761 |
t[4].Resume(); |
|
762 |
SimpleCheck(6,id,10,8,9,5,1,2); // 3,6,7 suspended |
|
763 |
t[3].Resume(); |
|
764 |
t[6].Resume(); |
|
765 |
t[7].Resume(); |
|
766 |
SimpleCheck(3,id,6,7,3); // 3,6,7 resumed |
|
767 |
||
768 |
RackEmUp(t,f,id); |
|
769 |
Kick(t[4]); |
|
770 |
t[4].SetPriority(EPriorityRealTime); |
|
771 |
MCOUNT(M1,-5); // should be 6 waiting, mutex free |
|
772 |
t[4].SetPriority(EPriorityNormal); |
|
773 |
t[8].SetPriority(EPriorityRealTime); // change pending thread priority |
|
774 |
MCOUNT(M1,-4); // should be 5 waiting, mutex free |
|
775 |
t[8].SetPriority(EPriorityMore); |
|
776 |
NUMCHECK(1); |
|
777 |
IDCHECK(id8); |
|
778 |
t[3].SetPriority(EPriorityRealTime); // change suspended thread priority |
|
779 |
SimpleCheck(5,id,9,10,5,1,2); // 3,6,7 suspended |
|
780 |
t[6].Resume(); |
|
781 |
t[7].Resume(); |
|
782 |
t[3].Resume(); // this should run right away |
|
783 |
NUMCHECK(1); |
|
784 |
IDCHECK(id3); |
|
785 |
SimpleCheck(2,id,6,7); // 6,7 resumed |
|
786 |
t[3].SetPriority(EPriorityLess); |
|
787 |
||
788 |
RackEmUp(t,f,id); |
|
789 |
Kick(t[4]); |
|
790 |
t[1].SetPriority(EPriorityRealTime); // change waiting thread priority |
|
791 |
// this should run right away |
|
792 |
NUMCHECK(1); |
|
793 |
IDCHECK(id1); |
|
794 |
t[1].SetPriority(EPriorityLess); |
|
795 |
// t8,t9,t10 should now be pending |
|
796 |
MCOUNT(M1,1-5); |
|
797 |
t[8].Suspend(); // this should wake up t5 |
|
798 |
t[9].Suspend(); // this should wake up t2 |
|
799 |
MCOUNT(M1,1-3); |
|
800 |
t[8].Suspend(); // this should have no further effect |
|
801 |
t[8].Resume(); // this should have no further effect |
|
802 |
MCOUNT(M1,1-3); |
|
803 |
SimpleCheck(3,id,10,5,2); |
|
804 |
MCOUNT(M1,1-3); |
|
805 |
t[3].Resume(); |
|
806 |
t[6].Resume(); |
|
807 |
t[7].Resume(); |
|
808 |
t[8].Resume(); |
|
809 |
t[9].Resume(); |
|
810 |
SimpleCheck(5,id,8,9,6,7,3); |
|
811 |
||
812 |
RackEmUp(t,f,id); |
|
813 |
MCOUNT(M1,-7); |
|
814 |
t[8].Suspend(); // this shouldn't wake anything up |
|
815 |
t[9].Suspend(); // this shouldn't wake anything up |
|
816 |
MCOUNT(M1,-7); |
|
817 |
Kick(t[4]); |
|
818 |
t[4].SetPriority(EPriorityRealTime); |
|
819 |
MCOUNT(M1,1-6); // should be 6 waiting, mutex free, t10 pending |
|
820 |
t[4].SetPriority(EPriorityNormal); |
|
821 |
t[10].SetPriority(EPriorityLess); // this should wake up t5 |
|
822 |
MCOUNT(M1,1-5); // should be 5 waiting, mutex free, t10, t5 pending |
|
823 |
SimpleCheck(4,id,5,10,1,2); |
|
824 |
t[3].SetPriority(EPriorityRealTime); // boost suspended+waiting thread |
|
825 |
MCOUNT(M1,1-3); // should be 3 waiting+suspended, mutex free, t8, t9 pending+suspended |
|
826 |
t[6].Resume(); |
|
827 |
t[7].Resume(); |
|
828 |
t[8].Resume(); |
|
829 |
t[9].Resume(); |
|
830 |
t[3].Resume(); // this should run immediately |
|
831 |
MCOUNT(M1,1); // t8,t9,t6,t7 pending, mutex free |
|
832 |
NUMCHECK(1); |
|
833 |
IDCHECK(id3); // t3 should have run |
|
834 |
t[3].SetPriority(EPriorityLess); |
|
835 |
t[9].SetPriority(EPriorityMuchLess); // lower pending thread priority |
|
836 |
SimpleCheck(4,id,8,6,7,9); |
|
837 |
t[9].SetPriority(EPriorityMore); |
|
838 |
t[10].SetPriority(EPriorityMore); |
|
839 |
||
840 |
RackEmUp(t,f,id); |
|
841 |
MCOUNT(M1,-7); |
|
842 |
t[8].Suspend(); // this shouldn't wake anything up |
|
843 |
t[9].Suspend(); // this shouldn't wake anything up |
|
844 |
MCOUNT(M1,-7); |
|
845 |
Kick(t[4]); |
|
846 |
MCOUNT(M1,-7); |
|
847 |
t[4].SetPriority(EPriorityRealTime); |
|
848 |
MCOUNT(M1,1-6); // should be 6 waiting, mutex free, t10 pending, t8,t9 pending+suspended |
|
849 |
t[4].SetPriority(EPriorityNormal); |
|
850 |
t[10].SetPriority(EPriorityMuchLess); // lower pending thread priority |
|
851 |
MCOUNT(M1,1-5); // should now be 5 waiting, mutex free, t10,t5 pending, t8,t9 pending+suspended |
|
852 |
t[6].Resume(); |
|
853 |
t[7].Resume(); |
|
854 |
t[3].Resume(); // this gets made READY straight away |
|
855 |
SimpleCheck(7,id,5,6,7,3,1,2,10); |
|
856 |
t[8].Resume(); |
|
857 |
t[9].Resume(); |
|
858 |
SimpleCheck(2,id,8,9); |
|
859 |
t[10].SetPriority(EPriorityMore); |
|
860 |
||
861 |
RackEmUp(t,f,id); |
|
862 |
MCOUNT(M1,-7); |
|
863 |
Kick(t[4]); |
|
864 |
t[9].Kill(0); // kill pending thread |
|
865 |
t[9].Close(); |
|
866 |
test(!Exists(9)); |
|
867 |
t[1].Kill(0); // kill waiting thread |
|
868 |
t[1].Close(); |
|
869 |
test(!Exists(1)); |
|
870 |
t[6].Kill(0); // kill suspended+waiting thread |
|
871 |
t[6].Close(); |
|
872 |
t[7].Resume(); |
|
873 |
t[3].Resume(); |
|
874 |
test(!Exists(6)); |
|
875 |
SimpleCheck(6,id,10,8,5,7,2,3); // 8 runs first and gets blocked behind 10 |
|
876 |
Resurrect(9,EPriorityMore,t,f,id); |
|
877 |
Resurrect(1,EPriorityLess,t,f,id); |
|
878 |
Resurrect(6,EPriorityNormal,t,f,id); |
|
879 |
||
880 |
RackEmUp(t,f,id); |
|
881 |
MCOUNT(M1,-7); |
|
882 |
t[8].Suspend(); // this shouldn't wake anything up |
|
883 |
t[9].Suspend(); // this shouldn't wake anything up |
|
884 |
MCOUNT(M1,-7); |
|
885 |
Kick(t[4]); |
|
886 |
MCOUNT(M1,-7); |
|
887 |
t[4].SetPriority(EPriorityRealTime); |
|
888 |
MCOUNT(M1,1-6); // should be 6 waiting, mutex free, t10 pending, t8,t9 pending+suspended |
|
889 |
t[4].SetPriority(EPriorityNormal); |
|
890 |
t[10].Kill(0); // kill pending thread - this should wake up t5 |
|
891 |
t[10].Close(); |
|
892 |
test(!Exists(10)); |
|
893 |
MCOUNT(M1,1-5); // should be 5 waiting, mutex free, t5 pending, t8,t9 pending+suspended |
|
894 |
t[5].SetPriority(EPriorityRealTime); // this should make t5 run |
|
895 |
MCOUNT(M1,1-4); // should be 4 waiting, mutex free, t1 pending, t8,t9 pending+suspended |
|
896 |
t[5].SetPriority(EPriorityNormal); |
|
897 |
NUMCHECK(1); |
|
898 |
IDCHECK(id5); |
|
899 |
t[8].SetPriority(EPriorityRealTime); // this shouldn't make anything happen |
|
900 |
MCOUNT(M1,1-4); // mutex free, t1 pending, t8,t9 pending+suspended, t3,t6,t7 wait+susp, t2 waiting |
|
901 |
NUMCHECK(0); |
|
902 |
t[8].Resume(); |
|
903 |
MCOUNT(M1,1-3); // mutex free, t1,t2 pending, t9 pending+suspended, t3,t6,t7 wait+susp |
|
904 |
NUMCHECK(1); |
|
905 |
IDCHECK(id8); |
|
906 |
t[8].SetPriority(EPriorityMore); |
|
907 |
t[3].Resume(); |
|
908 |
t[6].Resume(); |
|
909 |
t[7].Resume(); |
|
910 |
t[9].Resume(); |
|
911 |
SimpleCheck(6,id,9,6,7,1,2,3); |
|
912 |
Resurrect(10,EPriorityMore,t,f,id); |
|
913 |
||
914 |
RackEmUp(t,f,id); |
|
915 |
MCOUNT(M1,-7); |
|
916 |
t[8].Suspend(); // this shouldn't wake anything up |
|
917 |
t[9].Suspend(); // this shouldn't wake anything up |
|
918 |
MCOUNT(M1,-7); |
|
919 |
Kick(t[4]); |
|
920 |
MCOUNT(M1,-7); |
|
921 |
t[4].SetPriority(EPriorityRealTime); |
|
922 |
MCOUNT(M1,1-6); // mutex free, t10 pending, t8,t9 pending+susp, t3,t6,t7 wait+susp, t1,t2,t5 wait |
|
923 |
t[4].SetPriority(EPriorityNormal); |
|
924 |
t[1].SetPriority(EPriorityRealTime); // this should be able to run and claim the mutex |
|
925 |
NUMCHECK(1); |
|
926 |
IDCHECK(id1); |
|
927 |
MCOUNT(M1,1-4); // mutex free, t10,t5 pending, t8,t9 pending+susp, t3,t6,t7 wait+susp, t2 wait |
|
928 |
t[1].SetPriority(EPriorityLess); |
|
929 |
t[3].Resume(); |
|
930 |
t[6].Resume(); |
|
931 |
t[7].Resume(); |
|
932 |
t[9].Resume(); |
|
933 |
t[8].Resume(); |
|
934 |
SimpleCheck(8,id,10,9,8,5,6,7,3,2); |
|
935 |
||
936 |
RackEmUp(t,f,id); |
|
937 |
MCOUNT(M1,-7); |
|
938 |
Kick(t[4]); |
|
939 |
M1.Close(); // close the mutex - non-suspended threads should all panic with KERN-EXEC 0 |
|
940 |
TBool jit = User::JustInTime(); |
|
941 |
User::SetJustInTime(EFalse); |
|
942 |
User::After(1000000); |
|
943 |
User::SetJustInTime(jit); |
|
944 |
for (i=1; i<=10; ++i) |
|
945 |
{ |
|
946 |
if (i==3 || i==6 || i==7) |
|
947 |
{ |
|
117
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
948 |
test_Equal(EExitPending, t[i].ExitType()); |
0 | 949 |
} |
950 |
else |
|
951 |
{ |
|
117
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
952 |
test_Equal(EExitPanic, t[i].ExitType()); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
953 |
test_Equal(EBadHandle, t[i].ExitReason()); |
0 | 954 |
test(t[i].ExitCategory()==_L("KERN-EXEC")); |
955 |
t[i].Close(); |
|
956 |
test(!Exists(i)); |
|
957 |
} |
|
958 |
} |
|
959 |
t[3].Resume(); |
|
960 |
t[6].Resume(); |
|
961 |
t[7].Resume(); |
|
962 |
User::SetJustInTime(EFalse); |
|
963 |
User::After(1000000); |
|
964 |
User::SetJustInTime(jit); |
|
965 |
for (i=1; i<=10; ++i) |
|
966 |
{ |
|
967 |
if (i==3 || i==6 || i==7) |
|
968 |
{ |
|
117
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
969 |
test_Equal(EExitPanic, t[i].ExitType()); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
970 |
test_Equal(EBadHandle, t[i].ExitReason()); |
0 | 971 |
test(t[i].ExitCategory()==_L("KERN-EXEC")); |
972 |
t[i].Close(); |
|
973 |
test(!Exists(i)); |
|
974 |
} |
|
975 |
} |
|
976 |
||
977 |
test.End(); |
|
978 |
} |
|
979 |
||
980 |
/***************************************************************************** |
|
981 |
* Mutex benchmarks |
|
982 |
*****************************************************************************/ |
|
983 |
TInt MutexSpeed(TAny* aPtr) |
|
984 |
{ |
|
985 |
TInt& count=*(TInt*)aPtr; |
|
986 |
RThread().SetPriority(EPriorityMore); |
|
987 |
FOREVER |
|
988 |
{ |
|
989 |
M1.Wait(); |
|
990 |
M1.Signal(); |
|
991 |
++count; |
|
992 |
} |
|
993 |
} |
|
994 |
||
995 |
TInt MutexSpeed2(TAny* aPtr) |
|
996 |
{ |
|
997 |
TInt& count=*(TInt*)aPtr; |
|
998 |
RThread().SetPriority(EPriorityMore); |
|
999 |
FOREVER |
|
1000 |
{ |
|
1001 |
M1.Wait(); |
|
1002 |
M1.Wait(); |
|
1003 |
M1.Signal(); |
|
1004 |
M1.Signal(); |
|
1005 |
++count; |
|
1006 |
} |
|
1007 |
} |
|
1008 |
||
1009 |
void TestMutexSpeed() |
|
1010 |
{ |
|
1011 |
test.Start(_L("Test mutex speed")); |
|
1012 |
TInt count=0; |
|
1013 |
TInt r=M1.CreateLocal(); |
|
117
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1014 |
test_KErrNone(r); |
0 | 1015 |
|
1016 |
RThread t; |
|
1017 |
r=t.Create(_L("Speed"),MutexSpeed,0x1000,NULL,&count); |
|
117
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1018 |
test_KErrNone(r); |
0 | 1019 |
t.SetPriority(EPriorityRealTime); |
1020 |
t.Resume(); |
|
1021 |
User::AfterHighRes(1000000); |
|
1022 |
t.Kill(0); |
|
1023 |
t.Close(); |
|
1024 |
test(!Exists(_L("Speed"))); |
|
1025 |
test.Printf(_L("%d wait/signal in 1 second\n"),count); |
|
1026 |
||
1027 |
TInt count2=0; |
|
1028 |
r=t.Create(_L("Speed2"),MutexSpeed2,0x1000,NULL,&count2); |
|
117
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1029 |
test_KErrNone(r); |
0 | 1030 |
t.SetPriority(EPriorityRealTime); |
1031 |
t.Resume(); |
|
1032 |
User::AfterHighRes(1000000); |
|
1033 |
t.Kill(0); |
|
1034 |
t.Close(); |
|
1035 |
test(!Exists(_L("Speed2"))); |
|
1036 |
test.Printf(_L("%d double wait/signal in 1 second\n"),count2); |
|
1037 |
||
1038 |
M1.Close(); |
|
1039 |
test.End(); |
|
1040 |
} |
|
1041 |
||
1042 |
/***************************************************************************** |
|
1043 |
* Utilities for semaphore test |
|
1044 |
*****************************************************************************/ |
|
1045 |
void SemWait() |
|
1046 |
{ |
|
1047 |
S.Wait(); |
|
1048 |
++Count; |
|
1049 |
ThreadId[PutIx++]=(TUint)RThread().Id(); |
|
1050 |
} |
|
1051 |
||
1052 |
void SemSignal() |
|
1053 |
{ |
|
1054 |
S.Signal(); |
|
1055 |
} |
|
1056 |
||
1057 |
TInt SemThreadFunction(TAny* aPtr) |
|
1058 |
{ |
|
1059 |
PFV& f=*(PFV*)aPtr; |
|
1060 |
FOREVER |
|
1061 |
{ |
|
1062 |
SemWait(); |
|
1063 |
if (f) |
|
1064 |
f(); |
|
1065 |
SemSignal(); |
|
1066 |
User::WaitForAnyRequest(); |
|
1067 |
} |
|
1068 |
} |
|
1069 |
||
1070 |
void Wait() |
|
1071 |
{ |
|
1072 |
User::WaitForAnyRequest(); |
|
1073 |
} |
|
1074 |
||
1075 |
TUint CreateSemThread(RThread& t, TInt n, TAny* aPtr) |
|
1076 |
{ |
|
1077 |
TBuf<4> b; |
|
1078 |
b.Num(n); |
|
1079 |
TInt r=t.Create(b,SemThreadFunction,0x1000,NULL,aPtr); |
|
117
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1080 |
test_KErrNone(r); |
0 | 1081 |
t.Resume(); |
1082 |
TUint id=t.Id(); |
|
1083 |
return id; |
|
1084 |
} |
|
1085 |
||
1086 |
/* |
|
1087 |
Possible thread relationships with semaphore: |
|
1088 |
Waiting |
|
1089 |
Waiting + suspended |
|
1090 |
||
1091 |
Need to verify correct behaviour when the following actions occur for each of these states: |
|
1092 |
Suspend thread |
|
1093 |
Resume thread |
|
1094 |
Change thread priority |
|
1095 |
Thread exits |
|
1096 |
Thread is killed |
|
1097 |
Semaphore deleted |
|
1098 |
*/ |
|
1099 |
||
1100 |
void RackEmUp2(RThread* t, PFV* f, TUint* id) |
|
1101 |
{ |
|
1102 |
// set up |
|
1103 |
// t1, t2, t4, t5, t6, t8, t9 waiting |
|
1104 |
// t3, t7, t10 waiting+suspended |
|
1105 |
(void)f; |
|
1106 |
MCOUNT(S,2); // check semaphore level = 2 |
|
1107 |
SemWait(); |
|
1108 |
SemWait(); |
|
1109 |
MCOUNT(S,0); // check semaphore level = 0 |
|
1110 |
NUMCHECK(2); |
|
1111 |
IDCHECK(id0); |
|
1112 |
IDCHECK(id0); |
|
1113 |
TInt i; |
|
1114 |
for (i=1; i<=10; ++i) |
|
1115 |
Kick(t[i]); // wake up threads |
|
1116 |
User::After(50000); // let threads wait |
|
1117 |
MCOUNT(S,-10); // check 10 threads waiting |
|
1118 |
t[7].Resume(); // test resume when not suspended |
|
1119 |
MCOUNT(S,-10); // check 7 threads waiting |
|
1120 |
t[3].Suspend(); |
|
1121 |
t[7].Suspend(); |
|
1122 |
t[10].Suspend(); // now have required state |
|
1123 |
t[3].Suspend(); // suspend and resume t3 again for good measure |
|
1124 |
t[3].Resume(); |
|
1125 |
MCOUNT(S,-7); // check 7 threads waiting |
|
1126 |
} |
|
1127 |
||
1128 |
void Resurrect2(TInt n, TThreadPriority aPriority, RThread* t, PFV* f, TUint* id) |
|
1129 |
{ |
|
1130 |
f[n]=NULL; |
|
1131 |
id[n]=CreateSemThread(t[n],n,f+n); |
|
1132 |
t[n].SetPriority(EPriorityRealTime); |
|
1133 |
t[n].SetPriority(aPriority); |
|
1134 |
NUMCHECK(1); |
|
1135 |
IDCHECK(id[n]); |
|
1136 |
} |
|
1137 |
||
1138 |
/***************************************************************************** |
|
1139 |
* Semaphore exhaustive state transition test |
|
1140 |
*****************************************************************************/ |
|
1141 |
void TestSemaphore() |
|
1142 |
{ |
|
1143 |
test.Start(_L("Test semaphore state transitions")); |
|
1144 |
RThread t[11]; |
|
1145 |
TUint id[11]; |
|
1146 |
PFV f[11]={NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}; |
|
1147 |
id[0]=(TUint)RThread().Id(); |
|
1148 |
PutIx=0; |
|
1149 |
GetIx=0; |
|
1150 |
Count=0; |
|
1151 |
test.Next(_L("Create semaphore")); |
|
1152 |
TInt r=S.CreateLocal(2); |
|
117
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1153 |
test_KErrNone(r); |
0 | 1154 |
MCOUNT(S,2); |
1155 |
SemWait(); |
|
1156 |
MCOUNT(S,1); |
|
1157 |
SemSignal(); |
|
1158 |
MCOUNT(S,2); |
|
1159 |
SemWait(); |
|
1160 |
SemWait(); |
|
1161 |
MCOUNT(S,0); |
|
1162 |
S.Signal(2); |
|
1163 |
MCOUNT(S,2); |
|
1164 |
NUMCHECK(3); |
|
1165 |
IDCHECK(id0); |
|
1166 |
IDCHECK(id0); |
|
1167 |
IDCHECK(id0); |
|
1168 |
test.Next(_L("Create threads")); |
|
1169 |
TInt i; |
|
1170 |
for (i=1; i<=10; ++i) |
|
1171 |
{ |
|
1172 |
id[i]=CreateSemThread(t[i],i,f+i); |
|
1173 |
f[i]=&Wait; |
|
1174 |
} |
|
1175 |
t[8].SetPriority(EPriorityMore); // t1-t3=less, t4-t7=normal, t8-t10 more, t0 much more |
|
1176 |
t[9].SetPriority(EPriorityMore); |
|
1177 |
t[10].SetPriority(EPriorityMore); |
|
1178 |
t[1].SetPriority(EPriorityLess); |
|
1179 |
t[2].SetPriority(EPriorityLess); |
|
1180 |
t[3].SetPriority(EPriorityLess); |
|
1181 |
User::After(50000); |
|
1182 |
MCOUNT(S,-8); // check 8 waiting |
|
1183 |
NUMCHECK(2); |
|
1184 |
IDCHECK(id8); |
|
1185 |
IDCHECK(id9); // check t8,t9 got through |
|
1186 |
t[8].SetPriority(EPriorityRealTime); |
|
1187 |
Kick(t[8]); // let t8 run and signal |
|
1188 |
t[8].SetPriority(EPriorityMore); |
|
1189 |
MCOUNT(S,-7); // check 7 waiting |
|
1190 |
User::After(50000); // let next thread obtain semaphore |
|
1191 |
MCOUNT(S,-7); // check 7 waiting |
|
1192 |
NUMCHECK(1); |
|
1193 |
IDCHECK(id10); // check t10 got it |
|
1194 |
Kick(t[10]); // let t10 run and signal |
|
1195 |
User::After(50000); // let next thread obtain semaphore |
|
1196 |
MCOUNT(S,-6); // check 6 waiting |
|
1197 |
NUMCHECK(1); |
|
1198 |
IDCHECK(id4); // check t4 got it |
|
1199 |
t[1].SetPriority(EPriorityRealTime); // boost t1 |
|
1200 |
MCOUNT(S,-6); // check 6 still waiting |
|
1201 |
User::After(50000); // let next thread obtain semaphore |
|
1202 |
MCOUNT(S,-6); // check 6 still waiting |
|
1203 |
NUMCHECK(0); |
|
1204 |
Kick(t[9]); // make t9 ready to run and signal |
|
1205 |
MCOUNT(S,-6); // check 6 still waiting |
|
1206 |
User::After(50000); // let next thread obtain semaphore |
|
1207 |
MCOUNT(S,-5); // check 5 waiting |
|
1208 |
NUMCHECK(1); |
|
1209 |
IDCHECK(id1); // check t1 got it |
|
1210 |
t[1].SetPriority(EPriorityLess); |
|
1211 |
Kick(t[1]); // kick all remaining threads |
|
1212 |
Kick(t[2]); |
|
1213 |
Kick(t[3]); |
|
1214 |
Kick(t[4]); |
|
1215 |
Kick(t[5]); |
|
1216 |
Kick(t[6]); |
|
1217 |
Kick(t[7]); |
|
1218 |
User::After(50000); // let them run and obtain/signal the semaphore |
|
1219 |
MCOUNT(S,2); // check semaphore now back to initial level |
|
1220 |
SimpleCheck(5,id,5,6,7,2,3); |
|
1221 |
||
1222 |
for (i=1; i<=10; ++i) |
|
1223 |
f[i]=NULL; |
|
1224 |
RackEmUp2(t,f,id); // set up threads waiting on semaphore again |
|
1225 |
S.Signal(); |
|
1226 |
SimpleCheck(7,id,8,9,4,5,6,1,2); // let them go |
|
1227 |
MCOUNT(S,1); |
|
1228 |
S.Wait(); |
|
1229 |
t[3].SetPriority(EPriorityRealTime); // change suspended thread priority |
|
1230 |
t[7].Resume(); |
|
1231 |
SimpleCheck(0,id); // t7 should wait for signal |
|
1232 |
S.Signal(); |
|
1233 |
SimpleCheck(1,id,7); |
|
1234 |
MCOUNT(S,1); |
|
1235 |
t[3].Resume(); |
|
1236 |
t[10].Resume(); |
|
1237 |
NUMCHECK(1); |
|
1238 |
IDCHECK(id3); // t3 should have grabbed semaphore as soon as we resumed it |
|
1239 |
SimpleCheck(1,id,10); |
|
1240 |
t[3].SetPriority(EPriorityLess); |
|
1241 |
S.Signal(); // put level back to 2 |
|
1242 |
||
1243 |
RackEmUp2(t,f,id); // set up threads waiting on semaphore again |
|
1244 |
S.Signal(); |
|
1245 |
SimpleCheck(7,id,8,9,4,5,6,1,2); // let them go |
|
1246 |
MCOUNT(S,1); |
|
1247 |
S.Wait(); |
|
1248 |
t[3].SetPriority(EPriorityRealTime); // change suspended thread priority |
|
1249 |
t[7].Resume(); |
|
1250 |
SimpleCheck(0,id); // t7 should wait for signal |
|
1251 |
S.Signal(); |
|
1252 |
SimpleCheck(1,id,7); |
|
1253 |
MCOUNT(S,1); |
|
1254 |
t[10].Resume(); |
|
1255 |
t[3].Resume(); // t3 not woken up here since t10 has already been given the semaphore |
|
1256 |
NUMCHECK(0); |
|
1257 |
SimpleCheck(2,id,10,3); |
|
1258 |
t[3].SetPriority(EPriorityLess); |
|
1259 |
S.Signal(); // put level back to 2 |
|
1260 |
||
1261 |
RackEmUp2(t,f,id); // set up threads waiting on semaphore again |
|
1262 |
S.Signal(); |
|
1263 |
SimpleCheck(7,id,8,9,4,5,6,1,2); // let them go |
|
1264 |
MCOUNT(S,1); |
|
1265 |
S.Wait(); |
|
1266 |
t[3].SetPriority(EPriorityRealTime); // change suspended thread priority |
|
1267 |
t[7].Resume(); |
|
1268 |
SimpleCheck(0,id); // t7 should wait for signal |
|
1269 |
S.Signal(); |
|
1270 |
S.Signal(); // put level back to 2 |
|
1271 |
SimpleCheck(1,id,7); |
|
1272 |
MCOUNT(S,2); |
|
1273 |
t[10].Resume(); |
|
1274 |
t[3].Resume(); // t3 and t10 both woken up here, t3 should run and signal |
|
1275 |
MCOUNT(S,1); |
|
1276 |
NUMCHECK(1); |
|
1277 |
IDCHECK(id3); |
|
1278 |
SimpleCheck(1,id,10); |
|
1279 |
t[3].SetPriority(EPriorityLess); |
|
1280 |
||
1281 |
RackEmUp2(t,f,id); // set up threads waiting on semaphore again |
|
1282 |
t[9].Kill(0); // kill waiting thread |
|
1283 |
t[9].Close(); |
|
1284 |
test(!Exists(9)); |
|
1285 |
t[10].Kill(0); // kill suspended thread |
|
1286 |
t[10].Close(); |
|
1287 |
test(!Exists(10)); |
|
1288 |
MCOUNT(S,-6); |
|
1289 |
f[5]=&Exit; // get t5 to exit after acquiring semaphore |
|
1290 |
S.Signal(); |
|
1291 |
SimpleCheck(3,id,8,4,5); // let them go |
|
1292 |
MCOUNT(S,-3); // check one signal has been lost due to t5 exiting |
|
1293 |
t[5].Close(); |
|
1294 |
test(!Exists(5)); |
|
1295 |
t[3].Resume(); |
|
1296 |
t[7].Resume(); |
|
1297 |
MCOUNT(S,-5); |
|
1298 |
S.Signal(); |
|
1299 |
SimpleCheck(5,id,6,7,1,2,3); // let them go |
|
1300 |
MCOUNT(S,1); |
|
1301 |
Resurrect2(9,EPriorityMore,t,f,id); |
|
1302 |
Resurrect2(10,EPriorityMore,t,f,id); |
|
1303 |
Resurrect2(5,EPriorityNormal,t,f,id); |
|
1304 |
S.Signal(); |
|
1305 |
||
1306 |
RackEmUp2(t,f,id); // set up threads waiting on semaphore again |
|
1307 |
f[5]=&Exit; // get t5 to exit after acquiring semaphore |
|
1308 |
S.Close(); // close semaphore - threads should panic except for 5 |
|
1309 |
||
1310 |
TBool jit = User::JustInTime(); |
|
1311 |
User::SetJustInTime(EFalse); |
|
1312 |
User::After(1000000); |
|
1313 |
User::SetJustInTime(jit); |
|
1314 |
for (i=1; i<=10; ++i) |
|
1315 |
{ |
|
1316 |
if (i==3 || i==7 || i==10) |
|
1317 |
{ |
|
117
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1318 |
test_Equal(EExitPending, t[i].ExitType()); |
0 | 1319 |
} |
1320 |
else if (i!=5) |
|
1321 |
{ |
|
117
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1322 |
test_Equal(EExitPanic, t[i].ExitType()); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1323 |
test_Equal(EBadHandle, t[i].ExitReason()); |
0 | 1324 |
test(t[i].ExitCategory()==_L("KERN-EXEC")); |
1325 |
t[i].Close(); |
|
1326 |
test(!Exists(i)); |
|
1327 |
} |
|
1328 |
else |
|
1329 |
{ |
|
117
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1330 |
test_Equal(EExitKill, t[i].ExitType()); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1331 |
test_Equal(0, t[i].ExitReason()); |
0 | 1332 |
t[i].Close(); |
1333 |
test(!Exists(i)); |
|
1334 |
} |
|
1335 |
} |
|
1336 |
t[3].Resume(); |
|
1337 |
t[7].Resume(); |
|
1338 |
t[10].Resume(); |
|
1339 |
User::SetJustInTime(EFalse); |
|
1340 |
User::After(1000000); |
|
1341 |
User::SetJustInTime(jit); |
|
1342 |
for (i=1; i<=10; ++i) |
|
1343 |
{ |
|
1344 |
if (i==3 || i==7 || i==10) |
|
1345 |
{ |
|
117
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1346 |
test_Equal(EExitPanic, t[i].ExitType()); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1347 |
test_Equal(EBadHandle, t[i].ExitReason()); |
0 | 1348 |
test(t[i].ExitCategory()==_L("KERN-EXEC")); |
1349 |
t[i].Close(); |
|
1350 |
test(!Exists(i)); |
|
1351 |
} |
|
1352 |
} |
|
1353 |
||
1354 |
test.End(); |
|
1355 |
} |
|
1356 |
||
1357 |
/***************************************************************************** |
|
1358 |
* Semaphore benchmarks |
|
1359 |
*****************************************************************************/ |
|
1360 |
TInt SemSpeed(TAny* aPtr) |
|
1361 |
{ |
|
1362 |
TInt& count=*(TInt*)aPtr; |
|
1363 |
RThread().SetPriority(EPriorityMore); |
|
1364 |
FOREVER |
|
1365 |
{ |
|
1366 |
S.Wait(); |
|
1367 |
S.Signal(); |
|
1368 |
++count; |
|
1369 |
} |
|
1370 |
} |
|
1371 |
||
1372 |
void TestSemSpeed() |
|
1373 |
{ |
|
1374 |
test.Start(_L("Test semaphore speed")); |
|
1375 |
TInt count=0; |
|
1376 |
TInt r=S.CreateLocal(1); |
|
117
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1377 |
test_KErrNone(r); |
0 | 1378 |
|
1379 |
RThread t; |
|
1380 |
r=t.Create(_L("SemSpeed"),SemSpeed,0x1000,NULL,&count); |
|
117
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1381 |
test_KErrNone(r); |
0 | 1382 |
t.SetPriority(EPriorityRealTime); |
1383 |
t.Resume(); |
|
1384 |
User::AfterHighRes(1000000); |
|
1385 |
t.Kill(0); |
|
1386 |
t.Close(); |
|
1387 |
test(!Exists(_L("SemSpeed"))); |
|
1388 |
test.Printf(_L("%d wait/signal in 1 second\n"),count); |
|
1389 |
||
1390 |
S.Close(); |
|
1391 |
test.End(); |
|
1392 |
} |
|
1393 |
||
1394 |
||
1395 |
GLDEF_C TInt E32Main() |
|
1396 |
{ |
|
117
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1397 |
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
|
1398 |
if (cpus != 1) |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1399 |
{ |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1400 |
test(cpus>1); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1401 |
// 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
|
1402 |
// 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
|
1403 |
test.Printf(_L("T_SEMUTX2 skipped, does not work on SMP\n")); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1404 |
return KErrNone; |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1405 |
} |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1406 |
|
0 | 1407 |
test.Title(); |
1408 |
||
1409 |
test.Start(_L("Test mutexes and semaphores")); |
|
1410 |
RThread().SetPriority(EPriorityMuchMore); |
|
1411 |
TInt r=Main.Duplicate(RThread()); |
|
117
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1412 |
test_KErrNone(r); |
0 | 1413 |
|
1414 |
Test0(); |
|
1415 |
Test1(); |
|
1416 |
TestMutex1(); |
|
1417 |
TestMutex2(); |
|
1418 |
TestSemaphore(); |
|
1419 |
||
1420 |
TestMutexSpeed(); |
|
1421 |
TestSemSpeed(); |
|
1422 |
||
1423 |
Main.Close(); |
|
1424 |
test.End(); |
|
1425 |
return KErrNone; |
|
1426 |
} |
|
1427 |