60 #define TRACE_OFF User::SetDebugMask(0x80000000); |
63 #define TRACE_OFF User::SetDebugMask(0x80000000); |
61 |
64 |
62 //#define MCOUNT(m,c) test((m).Count() ==(c)) |
65 //#define MCOUNT(m,c) test((m).Count() ==(c)) |
63 // mutex count value is not visible for user any more |
66 // mutex count value is not visible for user any more |
64 #define MCOUNT(m,c) (void)(1) |
67 #define MCOUNT(m,c) (void)(1) |
65 #define IDCHECK(x) test(GetNextId()==(x)) |
68 #define IDCHECK(x) test_Equal((x), GetNextId()) |
66 #define NUMCHECK(x) test(NumIdsPending()==(x)) |
69 #define NUMCHECK(x) test_Equal((x), NumIdsPending()) |
67 |
70 |
68 #define id0 id[0] |
71 #define id0 id[0] |
69 #define id1 id[1] |
72 #define id1 id[1] |
70 #define id2 id[2] |
73 #define id2 id[2] |
71 #define id3 id[3] |
74 #define id3 id[3] |
151 test.Next(_L("Create thread")); |
154 test.Next(_L("Create thread")); |
152 RThread t; |
155 RThread t; |
153 TInt count=0; |
156 TInt count=0; |
154 TRequestStatus s; |
157 TRequestStatus s; |
155 TInt r=t.Create(_L("Test0"),Test0Thread,0x1000,NULL,&count); |
158 TInt r=t.Create(_L("Test0"),Test0Thread,0x1000,NULL,&count); |
156 test(r==KErrNone); |
159 test_KErrNone(r); |
157 t.Logon(s); |
160 t.Logon(s); |
158 test(r==KErrNone); |
161 test_KErrNone(r); |
159 User::After(10000); // make sure we have a full timeslice |
162 User::After(10000); // make sure we have a full timeslice |
160 t.Resume(); |
163 t.Resume(); |
161 |
164 |
162 test(count==0); // t shouldn't have run yet |
165 test_Equal(0, count); // t shouldn't have run yet |
163 RThread().SetPriority(EPriorityMuchMore); // shouldn't reschedule (priority unchanged) |
166 RThread().SetPriority(EPriorityMuchMore); // shouldn't reschedule (priority unchanged) |
164 test(count==0); |
167 test_Equal(0, count); |
165 RThread().SetPriority(EPriorityMore); // shouldn't reschedule (priority decreasing, but not enough) |
168 RThread().SetPriority(EPriorityMore); // shouldn't reschedule (priority decreasing, but not enough) |
166 test(count==0); |
169 test_Equal(0, count); |
167 RThread().SetPriority(EPriorityMuchMore); // shouldn't reschedule (priority increasing) |
170 RThread().SetPriority(EPriorityMuchMore); // shouldn't reschedule (priority increasing) |
168 test(count==0); |
171 test_Equal(0, count); |
169 RThread().SetPriority(EPriorityNormal); // should reschedule (we go behind t) |
172 RThread().SetPriority(EPriorityNormal); // should reschedule (we go behind t) |
170 test(count==1); |
173 test_Equal(1, count); |
171 RThread().SetPriority(EPriorityLess); // should reschedule (priority decreasing to below t) |
174 RThread().SetPriority(EPriorityLess); // should reschedule (priority decreasing to below t) |
172 test(count==2); |
175 test_Equal(2, count); |
173 t.SetPriority(EPriorityMuchMore); // shouldn't reschedule (round-robin, timeslice not expired) |
176 t.SetPriority(EPriorityMuchMore); // shouldn't reschedule (round-robin, timeslice not expired) |
174 test(count==2); |
177 test_Equal(2, count); |
175 t.SetPriority(EPriorityNormal); // shouldn't reschedule (t's priority decreasing) |
178 t.SetPriority(EPriorityNormal); // shouldn't reschedule (t's priority decreasing) |
176 test(count==2); |
179 test_Equal(2, count); |
177 t.SetPriority(EPriorityNormal); // shouldn't reschedule (t's priority unchanged) |
180 t.SetPriority(EPriorityNormal); // shouldn't reschedule (t's priority unchanged) |
178 test(count==2); |
181 test_Equal(2, count); |
179 BusyWait(100000); // use up our timeslice |
182 BusyWait(100000); // use up our timeslice |
180 t.SetPriority(EPriorityMuchMore); // should reschedule (round-robin, timeslice expired) |
183 t.SetPriority(EPriorityMuchMore); // should reschedule (round-robin, timeslice expired) |
181 test(count==3); |
184 test_Equal(3, count); |
182 test(s==KRequestPending); |
185 test_Equal(KRequestPending, s.Int()); |
183 test(t.ExitType()==EExitPending); |
186 test_Equal(EExitPending, t.ExitType()); |
184 t.SetPriority(EPriorityRealTime); // should reschedule (t increases above current) |
187 t.SetPriority(EPriorityRealTime); // should reschedule (t increases above current) |
185 test(count==4); |
188 test_Equal(4, count); |
186 test(s==KErrNone); // t should have exited |
189 test_KErrNone(s.Int()); // t should have exited |
187 test(t.ExitType()==EExitKill); |
190 test_Equal(EExitKill, t.ExitType()); |
188 User::WaitForRequest(s); |
191 User::WaitForRequest(s); |
189 RThread().SetPriority(EPriorityMuchMore); |
192 RThread().SetPriority(EPriorityMuchMore); |
190 t.Close(); |
193 t.Close(); |
191 test.End(); |
194 test.End(); |
192 } |
195 } |
199 |
202 |
200 void Test1() |
203 void Test1() |
201 { |
204 { |
202 test.Start(_L("Test signalling from wrong thread")); |
205 test.Start(_L("Test signalling from wrong thread")); |
203 TInt r=M1.CreateLocal(); |
206 TInt r=M1.CreateLocal(); |
204 test(r==KErrNone); |
207 test_KErrNone(r); |
205 M1.Wait(); |
208 M1.Wait(); |
206 RThread t; |
209 RThread t; |
207 r=t.Create(_L("Test1"),Test1Thread,0x1000,NULL,NULL); |
210 r=t.Create(_L("Test1"),Test1Thread,0x1000,NULL,NULL); |
208 test(r==KErrNone); |
211 test_KErrNone(r); |
209 TRequestStatus s; |
212 TRequestStatus s; |
210 t.Logon(s); |
213 t.Logon(s); |
211 t.Resume(); |
214 t.Resume(); |
212 TBool jit = User::JustInTime(); |
215 TBool jit = User::JustInTime(); |
213 User::SetJustInTime(EFalse); |
216 User::SetJustInTime(EFalse); |
214 User::WaitForRequest(s); |
217 User::WaitForRequest(s); |
215 User::SetJustInTime(jit); |
218 User::SetJustInTime(jit); |
216 test(s==EAccessDenied); |
219 test_Equal(EAccessDenied, s.Int()); |
217 test(t.ExitType()==EExitPanic); |
220 test_Equal(EExitPanic, t.ExitType()); |
218 test(t.ExitReason()==EAccessDenied); |
221 test_Equal(EAccessDenied, t.ExitReason()); |
219 test(t.ExitCategory()==_L("KERN-EXEC")); |
222 test(t.ExitCategory()==_L("KERN-EXEC")); |
220 t.Close(); |
223 t.Close(); |
221 M1.Close(); |
224 M1.Close(); |
222 test.End(); |
225 test.End(); |
223 } |
226 } |
271 { |
274 { |
272 test.Start(_L("Test mutex priority inheritance")); |
275 test.Start(_L("Test mutex priority inheritance")); |
273 |
276 |
274 test.Next(_L("Create mutex")); |
277 test.Next(_L("Create mutex")); |
275 TInt r=M1.CreateLocal(); |
278 TInt r=M1.CreateLocal(); |
276 test(r==KErrNone); |
279 test_KErrNone(r); |
277 |
280 |
278 test.Next(_L("Create low priority thread")); |
281 test.Next(_L("Create low priority thread")); |
279 TInt lowcount=0; |
282 TInt lowcount=0; |
280 RThread low; |
283 RThread low; |
281 r=low.Create(_L("low"),LowThread,0x1000,NULL,&lowcount); |
284 r=low.Create(_L("low"),LowThread,0x1000,NULL,&lowcount); |
282 test(r==KErrNone); |
285 test_KErrNone(r); |
283 low.SetPriority(EPriorityMuchLess); |
286 low.SetPriority(EPriorityMuchLess); |
284 test(Exists(_L("low"))); |
287 test(Exists(_L("low"))); |
285 |
288 |
286 test.Next(_L("Create medium priority thread")); |
289 test.Next(_L("Create medium priority thread")); |
287 TInt medcount=0; |
290 TInt medcount=0; |
288 RThread med; |
291 RThread med; |
289 r=med.Create(_L("med"),MedThread,0x1000,NULL,&medcount); |
292 r=med.Create(_L("med"),MedThread,0x1000,NULL,&medcount); |
290 test(r==KErrNone); |
293 test_KErrNone(r); |
291 med.SetPriority(EPriorityNormal); |
294 med.SetPriority(EPriorityNormal); |
292 test(Exists(_L("med"))); |
295 test(Exists(_L("med"))); |
293 |
296 |
294 test.Next(_L("Start low priority thread")); |
297 test.Next(_L("Start low priority thread")); |
295 low.Resume(); |
298 low.Resume(); |
296 User::AfterHighRes(KTestDelay/10); |
299 User::AfterHighRes(KTestDelay/10); |
297 test(lowcount==1); |
300 test_Equal(1, lowcount); |
298 // MCOUNT(M1,0); |
301 // MCOUNT(M1,0); |
299 |
302 |
300 test.Next(_L("Start medium priority thread")); |
303 test.Next(_L("Start medium priority thread")); |
301 med.Resume(); |
304 med.Resume(); |
302 User::AfterHighRes(KTestDelay/10); |
305 User::AfterHighRes(KTestDelay/10); |
303 test(medcount==1); |
306 test_Equal(1, medcount); |
304 Kick(med); |
307 Kick(med); |
305 User::AfterHighRes(KTestDelay/10); |
308 User::AfterHighRes(KTestDelay/10); |
306 test(medcount==2); |
309 test_Equal(2, medcount); |
307 Kick(med); |
310 Kick(med); |
308 |
311 |
309 M1.Wait(); |
312 M1.Wait(); |
310 test(lowcount==1); |
313 test_Equal(1, lowcount); |
311 test(medcount==2); |
314 test_Equal(2, medcount); |
312 test.Next(_L("Wait, check medium runs")); |
315 test.Next(_L("Wait, check medium runs")); |
313 User::AfterHighRes(KTestDelay/10); |
316 User::AfterHighRes(KTestDelay/10); |
314 test(medcount==3); |
317 test_Equal(3, medcount); |
315 M1.Signal(); |
318 M1.Signal(); |
316 |
319 |
317 test.Next(_L("Create mutex 2")); |
320 test.Next(_L("Create mutex 2")); |
318 r=M2.CreateLocal(); |
321 r=M2.CreateLocal(); |
319 test(r==KErrNone); |
322 test_KErrNone(r); |
320 |
323 |
321 test.Next(_L("Create high priority thread")); |
324 test.Next(_L("Create high priority thread")); |
322 TInt highcount=0; |
325 TInt highcount=0; |
323 RThread high; |
326 RThread high; |
324 r=high.Create(_L("high"),HighThread,0x1000,NULL,&highcount); |
327 r=high.Create(_L("high"),HighThread,0x1000,NULL,&highcount); |
325 test(r==KErrNone); |
328 test_KErrNone(r); |
326 high.SetPriority(EPriorityMore); |
329 high.SetPriority(EPriorityMore); |
327 test(Exists(_L("high"))); |
330 test(Exists(_L("high"))); |
328 |
331 |
329 Kick(low); |
332 Kick(low); |
330 User::AfterHighRes(KTestDelay/10); |
333 User::AfterHighRes(KTestDelay/10); |
334 // MCOUNT(M2,1); |
337 // MCOUNT(M2,1); |
335 high.Resume(); |
338 high.Resume(); |
336 User::AfterHighRes(KTestDelay/10); |
339 User::AfterHighRes(KTestDelay/10); |
337 // MCOUNT(M2,0); |
340 // MCOUNT(M2,0); |
338 // MCOUNT(M1,-1); |
341 // MCOUNT(M1,-1); |
339 test(highcount==1); |
342 test_Equal(1, highcount); |
340 |
343 |
341 M2.Wait(); |
344 M2.Wait(); |
342 test(lowcount==2); |
345 test_Equal(2, lowcount); |
343 test(medcount==3); |
346 test_Equal(3, medcount); |
344 test(highcount==2); |
347 test_Equal(2, highcount); |
345 test.Next(_L("Wait, check medium runs")); |
348 test.Next(_L("Wait, check medium runs")); |
346 User::AfterHighRes(KTestDelay/10); |
349 User::AfterHighRes(KTestDelay/10); |
347 test(medcount==4); |
350 test_Equal(4, medcount); |
348 M2.Signal(); |
351 M2.Signal(); |
349 |
352 |
350 test.Next(_L("Kill threads")); |
353 test.Next(_L("Kill threads")); |
351 low.Kill(0); |
354 low.Kill(0); |
352 med.Kill(0); |
355 med.Kill(0); |
622 f[2]=&Exit; // make t2 exit while holding the mutex |
625 f[2]=&Exit; // make t2 exit while holding the mutex |
623 MutexSignal(); |
626 MutexSignal(); |
624 User::After(50000); // let threads claim mutex |
627 User::After(50000); // let threads claim mutex |
625 MutexWait(); |
628 MutexWait(); |
626 MCOUNT(M1,0); // check no threads waiting |
629 MCOUNT(M1,0); // check no threads waiting |
627 test(t[2].ExitType()==EExitKill); // check t2 has exited |
630 test_Equal(EExitKill, t[2].ExitType()); // check t2 has exited |
628 t[2].Close(); |
631 t[2].Close(); |
629 test(!Exists(2)); |
632 test(!Exists(2)); |
630 IDCHECK(id2); // check they ran in order t2,t3,t4,t5,t1 |
633 IDCHECK(id2); // check they ran in order t2,t3,t4,t5,t1 |
631 IDCHECK(id3); |
634 IDCHECK(id3); |
632 IDCHECK(id4); |
635 IDCHECK(id4); |
940 User::SetJustInTime(jit); |
943 User::SetJustInTime(jit); |
941 for (i=1; i<=10; ++i) |
944 for (i=1; i<=10; ++i) |
942 { |
945 { |
943 if (i==3 || i==6 || i==7) |
946 if (i==3 || i==6 || i==7) |
944 { |
947 { |
945 test(t[i].ExitType()==EExitPending); |
948 test_Equal(EExitPending, t[i].ExitType()); |
946 } |
949 } |
947 else |
950 else |
948 { |
951 { |
949 test(t[i].ExitType()==EExitPanic); |
952 test_Equal(EExitPanic, t[i].ExitType()); |
950 test(t[i].ExitReason()==EBadHandle); |
953 test_Equal(EBadHandle, t[i].ExitReason()); |
951 test(t[i].ExitCategory()==_L("KERN-EXEC")); |
954 test(t[i].ExitCategory()==_L("KERN-EXEC")); |
952 t[i].Close(); |
955 t[i].Close(); |
953 test(!Exists(i)); |
956 test(!Exists(i)); |
954 } |
957 } |
955 } |
958 } |
1006 void TestMutexSpeed() |
1009 void TestMutexSpeed() |
1007 { |
1010 { |
1008 test.Start(_L("Test mutex speed")); |
1011 test.Start(_L("Test mutex speed")); |
1009 TInt count=0; |
1012 TInt count=0; |
1010 TInt r=M1.CreateLocal(); |
1013 TInt r=M1.CreateLocal(); |
1011 test(r==KErrNone); |
1014 test_KErrNone(r); |
1012 |
1015 |
1013 RThread t; |
1016 RThread t; |
1014 r=t.Create(_L("Speed"),MutexSpeed,0x1000,NULL,&count); |
1017 r=t.Create(_L("Speed"),MutexSpeed,0x1000,NULL,&count); |
1015 test(r==KErrNone); |
1018 test_KErrNone(r); |
1016 t.SetPriority(EPriorityRealTime); |
1019 t.SetPriority(EPriorityRealTime); |
1017 t.Resume(); |
1020 t.Resume(); |
1018 User::AfterHighRes(1000000); |
1021 User::AfterHighRes(1000000); |
1019 t.Kill(0); |
1022 t.Kill(0); |
1020 t.Close(); |
1023 t.Close(); |
1021 test(!Exists(_L("Speed"))); |
1024 test(!Exists(_L("Speed"))); |
1022 test.Printf(_L("%d wait/signal in 1 second\n"),count); |
1025 test.Printf(_L("%d wait/signal in 1 second\n"),count); |
1023 |
1026 |
1024 TInt count2=0; |
1027 TInt count2=0; |
1025 r=t.Create(_L("Speed2"),MutexSpeed2,0x1000,NULL,&count2); |
1028 r=t.Create(_L("Speed2"),MutexSpeed2,0x1000,NULL,&count2); |
1026 test(r==KErrNone); |
1029 test_KErrNone(r); |
1027 t.SetPriority(EPriorityRealTime); |
1030 t.SetPriority(EPriorityRealTime); |
1028 t.Resume(); |
1031 t.Resume(); |
1029 User::AfterHighRes(1000000); |
1032 User::AfterHighRes(1000000); |
1030 t.Kill(0); |
1033 t.Kill(0); |
1031 t.Close(); |
1034 t.Close(); |
1310 User::SetJustInTime(jit); |
1313 User::SetJustInTime(jit); |
1311 for (i=1; i<=10; ++i) |
1314 for (i=1; i<=10; ++i) |
1312 { |
1315 { |
1313 if (i==3 || i==7 || i==10) |
1316 if (i==3 || i==7 || i==10) |
1314 { |
1317 { |
1315 test(t[i].ExitType()==EExitPending); |
1318 test_Equal(EExitPending, t[i].ExitType()); |
1316 } |
1319 } |
1317 else if (i!=5) |
1320 else if (i!=5) |
1318 { |
1321 { |
1319 test(t[i].ExitType()==EExitPanic); |
1322 test_Equal(EExitPanic, t[i].ExitType()); |
1320 test(t[i].ExitReason()==EBadHandle); |
1323 test_Equal(EBadHandle, t[i].ExitReason()); |
1321 test(t[i].ExitCategory()==_L("KERN-EXEC")); |
1324 test(t[i].ExitCategory()==_L("KERN-EXEC")); |
1322 t[i].Close(); |
1325 t[i].Close(); |
1323 test(!Exists(i)); |
1326 test(!Exists(i)); |
1324 } |
1327 } |
1325 else |
1328 else |
1326 { |
1329 { |
1327 test(t[i].ExitType()==EExitKill); |
1330 test_Equal(EExitKill, t[i].ExitType()); |
1328 test(t[i].ExitReason()==0); |
1331 test_Equal(0, t[i].ExitReason()); |
1329 t[i].Close(); |
1332 t[i].Close(); |
1330 test(!Exists(i)); |
1333 test(!Exists(i)); |
1331 } |
1334 } |
1332 } |
1335 } |
1333 t[3].Resume(); |
1336 t[3].Resume(); |