kerneltest/e32test/prime/t_semutx2.cpp
branchRCL_3
changeset 28 5b5d147c7838
parent 0 a41df078684a
equal deleted inserted replaced
26:c734af59ce98 28:5b5d147c7838
    35 // Failures and causes:
    35 // Failures and causes:
    36 // Base Port information:
    36 // Base Port information:
    37 // 
    37 // 
    38 //
    38 //
    39 
    39 
       
    40 #define __E32TEST_EXTENSION__
    40 #include <e32test.h>
    41 #include <e32test.h>
       
    42 #include <u32std.h>
       
    43 #include <e32svr.h>
    41 
    44 
    42 RMutex M1;
    45 RMutex M1;
    43 RMutex M2;
    46 RMutex M2;
    44 RSemaphore S;
    47 RSemaphore S;
    45 
    48 
    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);
   399 TUint CreateThread(RThread& t, TInt n, TAny* aPtr)
   402 TUint CreateThread(RThread& t, TInt n, TAny* aPtr)
   400 	{
   403 	{
   401 	TBuf<4> b;
   404 	TBuf<4> b;
   402 	b.Num(n);
   405 	b.Num(n);
   403 	TInt r=t.Create(b,ThreadFunction,0x1000,NULL,aPtr);
   406 	TInt r=t.Create(b,ThreadFunction,0x1000,NULL,aPtr);
   404 	test(r==KErrNone);
   407 	test_KErrNone(r);
   405 	t.Resume();
   408 	t.Resume();
   406 	TUint id=t.Id();
   409 	TUint id=t.Id();
   407 	test.Printf(_L("id=%d\n"),id);
   410 	test.Printf(_L("id=%d\n"),id);
   408 	return id;
   411 	return id;
   409 	}
   412 	}
   514 	PutIx=0;
   517 	PutIx=0;
   515 	GetIx=0;
   518 	GetIx=0;
   516 	Count=0;
   519 	Count=0;
   517 	test.Next(_L("Create mutex"));
   520 	test.Next(_L("Create mutex"));
   518 	TInt r=M1.CreateLocal();
   521 	TInt r=M1.CreateLocal();
   519 	test(r==KErrNone);
   522 	test_KErrNone(r);
   520 	MCOUNT(M1,1);
   523 	MCOUNT(M1,1);
   521 	MutexWait();
   524 	MutexWait();
   522 	MCOUNT(M1,0);
   525 	MCOUNT(M1,0);
   523 	IDCHECK(id[0]);
   526 	IDCHECK(id[0]);
   524 	test.Next(_L("Create threads"));
   527 	test.Next(_L("Create threads"));
   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 		}
   961 	User::SetJustInTime(jit);
   964 	User::SetJustInTime(jit);
   962 	for (i=1; i<=10; ++i)
   965 	for (i=1; i<=10; ++i)
   963 		{
   966 		{
   964 		if (i==3 || i==6 || i==7)
   967 		if (i==3 || i==6 || i==7)
   965 			{
   968 			{
   966 			test(t[i].ExitType()==EExitPanic);
   969 			test_Equal(EExitPanic, t[i].ExitType());
   967 			test(t[i].ExitReason()==EBadHandle);
   970 			test_Equal(EBadHandle, t[i].ExitReason());
   968 			test(t[i].ExitCategory()==_L("KERN-EXEC"));
   971 			test(t[i].ExitCategory()==_L("KERN-EXEC"));
   969 			t[i].Close();
   972 			t[i].Close();
   970 			test(!Exists(i));
   973 			test(!Exists(i));
   971 			}
   974 			}
   972 		}
   975 		}
  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();
  1072 TUint CreateSemThread(RThread& t, TInt n, TAny* aPtr)
  1075 TUint CreateSemThread(RThread& t, TInt n, TAny* aPtr)
  1073 	{
  1076 	{
  1074 	TBuf<4> b;
  1077 	TBuf<4> b;
  1075 	b.Num(n);
  1078 	b.Num(n);
  1076 	TInt r=t.Create(b,SemThreadFunction,0x1000,NULL,aPtr);
  1079 	TInt r=t.Create(b,SemThreadFunction,0x1000,NULL,aPtr);
  1077 	test(r==KErrNone);
  1080 	test_KErrNone(r);
  1078 	t.Resume();
  1081 	t.Resume();
  1079 	TUint id=t.Id();
  1082 	TUint id=t.Id();
  1080 	return id;
  1083 	return id;
  1081 	}
  1084 	}
  1082 
  1085 
  1145 	PutIx=0;
  1148 	PutIx=0;
  1146 	GetIx=0;
  1149 	GetIx=0;
  1147 	Count=0;
  1150 	Count=0;
  1148 	test.Next(_L("Create semaphore"));
  1151 	test.Next(_L("Create semaphore"));
  1149 	TInt r=S.CreateLocal(2);
  1152 	TInt r=S.CreateLocal(2);
  1150 	test(r==KErrNone);
  1153 	test_KErrNone(r);
  1151 	MCOUNT(S,2);
  1154 	MCOUNT(S,2);
  1152 	SemWait();
  1155 	SemWait();
  1153 	MCOUNT(S,1);
  1156 	MCOUNT(S,1);
  1154 	SemSignal();
  1157 	SemSignal();
  1155 	MCOUNT(S,2);
  1158 	MCOUNT(S,2);
  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();
  1338 	User::SetJustInTime(jit);
  1341 	User::SetJustInTime(jit);
  1339 	for (i=1; i<=10; ++i)
  1342 	for (i=1; i<=10; ++i)
  1340 		{
  1343 		{
  1341 		if (i==3 || i==7 || i==10)
  1344 		if (i==3 || i==7 || i==10)
  1342 			{
  1345 			{
  1343 			test(t[i].ExitType()==EExitPanic);
  1346 			test_Equal(EExitPanic, t[i].ExitType());
  1344 			test(t[i].ExitReason()==EBadHandle);
  1347 			test_Equal(EBadHandle, t[i].ExitReason());
  1345 			test(t[i].ExitCategory()==_L("KERN-EXEC"));
  1348 			test(t[i].ExitCategory()==_L("KERN-EXEC"));
  1346 			t[i].Close();
  1349 			t[i].Close();
  1347 			test(!Exists(i));
  1350 			test(!Exists(i));
  1348 			}
  1351 			}
  1349 		}
  1352 		}
  1369 void TestSemSpeed()
  1372 void TestSemSpeed()
  1370 	{
  1373 	{
  1371 	test.Start(_L("Test semaphore speed"));
  1374 	test.Start(_L("Test semaphore speed"));
  1372 	TInt count=0;
  1375 	TInt count=0;
  1373 	TInt r=S.CreateLocal(1);
  1376 	TInt r=S.CreateLocal(1);
  1374 	test(r==KErrNone);
  1377 	test_KErrNone(r);
  1375 
  1378 
  1376 	RThread t;
  1379 	RThread t;
  1377 	r=t.Create(_L("SemSpeed"),SemSpeed,0x1000,NULL,&count);
  1380 	r=t.Create(_L("SemSpeed"),SemSpeed,0x1000,NULL,&count);
  1378 	test(r==KErrNone);
  1381 	test_KErrNone(r);
  1379 	t.SetPriority(EPriorityRealTime);
  1382 	t.SetPriority(EPriorityRealTime);
  1380 	t.Resume();
  1383 	t.Resume();
  1381 	User::AfterHighRes(1000000);
  1384 	User::AfterHighRes(1000000);
  1382 	t.Kill(0);
  1385 	t.Kill(0);
  1383 	t.Close();
  1386 	t.Close();
  1389 	}
  1392 	}
  1390 
  1393 
  1391 
  1394 
  1392 GLDEF_C TInt E32Main()
  1395 GLDEF_C TInt E32Main()
  1393 	{
  1396 	{
       
  1397 	TInt cpus = UserSvr::HalFunction(EHalGroupKernel, EKernelHalNumLogicalCpus, 0, 0);
       
  1398 	if (cpus != 1)
       
  1399 		{
       
  1400 		test(cpus>1);
       
  1401 		// This test will require compatibility mode (and probably other changes)
       
  1402 		// to work on SMP - it depends on explicit scheduling order.
       
  1403 		test.Printf(_L("T_SEMUTX2 skipped, does not work on SMP\n"));
       
  1404 		return KErrNone;
       
  1405 		}	
       
  1406 	
  1394 	test.Title();
  1407 	test.Title();
  1395 
  1408 
  1396 	test.Start(_L("Test mutexes and semaphores"));
  1409 	test.Start(_L("Test mutexes and semaphores"));
  1397 	RThread().SetPriority(EPriorityMuchMore);
  1410 	RThread().SetPriority(EPriorityMuchMore);
  1398 	TInt r=Main.Duplicate(RThread());
  1411 	TInt r=Main.Duplicate(RThread());
  1399 	test(r==KErrNone);
  1412 	test_KErrNone(r);
  1400 
  1413 
  1401 	Test0();
  1414 	Test0();
  1402 	Test1();
  1415 	Test1();
  1403 	TestMutex1();
  1416 	TestMutex1();
  1404 	TestMutex2();
  1417 	TestMutex2();