Update contrib.
1 // Copyright (c) 1997-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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32test\nkern\d_implicit.cpp
15 // LDD for testing nanokernel implicit system lock
19 #define __INCLUDE_NTHREADBASE_DEFINES__
23 #include "d_implicit.h"
26 #include "../misc/prbs.h"
28 const TInt KMajorVersionNumber=0;
29 const TInt KMinorVersionNumber=1;
30 const TInt KBuildVersionNumber=1;
32 const TInt KStackSize=1024;
34 inline NThreadBase::NThreadBase()
38 class DImpSysTestFactory : public DLogicalDevice
40 // Implicit system lock test LDD factory
45 virtual TInt Install(); //overriding pure virtual
46 virtual void GetCaps(TDes8& aDes) const; //overriding pure virtual
47 virtual TInt Create(DLogicalChannelBase*& aChannel); //overriding pure virtual
50 class DImpSysTest : public DLogicalChannelBase
52 // Implicit system lock test LDD channel
58 virtual TInt Request(TInt aReqNo, TAny* a1, TAny* a2);
59 virtual TInt DoCreate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer);
61 TInt CreateThread(TInt);
62 TInt Start(TInt aTest);
63 TInt Stop(SStats& aStats);
64 static void Thread1(TAny*);
65 static void Thread2(TAny*);
66 static void Thread3(TAny*);
74 NThread iThread1; // holds fast mutex, imp sys
75 NThread iThread2; // holds system lock, not imp sys
76 NThread iThread3; // random stuff
77 TUint32 iStack1[KStackSize/sizeof(TUint32)];
78 TUint32 iStack2[KStackSize/sizeof(TUint32)];
79 TUint32 iStack3[KStackSize/sizeof(TUint32)];
82 TInt DImpSysTest::CreateThread(TInt a)
84 SNThreadCreateInfo info;
85 info.iStackSize=KStackSize;
86 info.iPriority=(a==3)?16:12;
88 info.iAttributes=(TUint8)((a==1)?KThreadAttImplicitSystemLock:0);
90 info.iFastExecTable=NULL;
91 info.iSlowExecTable=NULL;
92 info.iParameterBlock=(const TUint32*)this;
93 info.iParameterBlockSize=0;
100 info.iFunction=&Thread1;
101 info.iStackBase=iStack1;
105 info.iFunction=&Thread2;
106 info.iStackBase=iStack2;
110 info.iFunction=&Thread3;
111 info.iStackBase=iStack3;
117 return NKern::ThreadCreate(pT,info);
120 void DImpSysTest::Thread1(TAny* aPtr)
122 DImpSysTest& d=*(DImpSysTest*)aPtr;
123 TScheduler* pS=TScheduler::Ptr();
124 NFastMutex& m=pS->iLock;
130 NKern::FMWait(&d.iMutex);
131 Kern::NanoWait(1300000); // spin for 1.3ms
132 TInt c = NKern::CurrentContext();
133 __NK_ASSERT_ALWAYS(c == NKern::EThread);
134 NKern::FMSignal(&d.iMutex);
135 if (m.iHoldingThread)
137 TInt x=Random(seed)&3;
144 void DImpSysTest::Thread2(TAny* aPtr)
146 DImpSysTest& d=*(DImpSysTest*)aPtr;
152 TInt c = NKern::CurrentContext();
153 __NK_ASSERT_ALWAYS(c == NKern::EThread);
155 Kern::NanoWait(1100000); // spin for 1.1ms
156 NKern::UnlockSystem();
157 TInt x=Random(seed)&3;
164 void DImpSysTest::Thread3(TAny* aPtr)
166 DImpSysTest& d=*(DImpSysTest*)aPtr;
170 if (d.iTestNum==RImpSysTest::ETestPriority)
174 TInt c = NKern::CurrentContext();
175 __NK_ASSERT_ALWAYS(c == NKern::EThread);
176 TInt x=Random(seed)&15;
179 TInt p=10+Random(seed)&3;
181 NKern::ThreadSetPriority(&d.iThread1,p);
183 NKern::ThreadSetPriority(&d.iThread2,p);
187 else if (d.iTestNum==RImpSysTest::ETestRoundRobin)
191 TInt c = NKern::CurrentContext();
192 __NK_ASSERT_ALWAYS(c == NKern::EThread);
193 TInt x=Random(seed)&15;
195 NKern::RotateReadyList(12);
199 else if (d.iTestNum==RImpSysTest::ETestDummy)
203 TInt c = NKern::CurrentContext();
204 __NK_ASSERT_ALWAYS(c == NKern::EThread);
205 TInt x=Random(seed)&15;
208 TInt p=10+Random(seed)&3;
212 NKern::ThreadSetPriority(&d.iThread1,p);
213 NKern::UnlockSystem();
218 NKern::ThreadSetPriority(&d.iThread2,p);
219 NKern::UnlockSystem();
223 NKern::FMWait(&d.iMutex);
224 NKern::FMSignal(&d.iMutex);
231 TInt DImpSysTest::Start(TInt aTest)
240 new (&iMutex) NFastMutex;
241 TInt r=CreateThread(1);
248 NKern::ThreadResume(&iThread3);
249 NKern::ThreadResume(&iThread1);
250 NKern::ThreadResume(&iThread2);
258 TInt DImpSysTest::Stop(SStats& a)
260 NKern::ThreadKill(&iThread1);
261 NKern::ThreadKill(&iThread2);
262 NKern::ThreadKill(&iThread3);
263 NKern::ThreadSetPriority(&iThread1,16);
264 NKern::ThreadSetPriority(&iThread2,16);
265 NKern::ThreadSetPriority(&iThread3,16);
266 while (iThread1.iNState!=NThread::EDead || iThread2.iNState!=NThread::EDead || iThread3.iNState!=NThread::EDead)
268 TInt size=3*(sizeof(NThread)+KStackSize)+sizeof(NFastMutex);
269 memset(&iMutex,0xbb,size);
270 a.iFailCount=iFailCount;
278 DImpSysTestFactory::DImpSysTestFactory()
283 iVersion=TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber);
284 //iParseMask=0;//No units, no info, no PDD
285 //iUnitsMask=0;//Only one thing
288 TInt DImpSysTestFactory::Create(DLogicalChannelBase*& aChannel)
290 // Create a new DImpSysTest on this logical device
293 aChannel=new DImpSysTest;
294 return aChannel?KErrNone:KErrNoMemory;
297 TInt DImpSysTestFactory::Install()
299 // Install the LDD - overriding pure virtual
302 return SetName(&KLddName);
305 void DImpSysTestFactory::GetCaps(TDes8& aDes) const
307 // Get capabilities - overriding pure virtual
310 TCapsImpSysTestV01 b;
311 b.iVersion=TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber);
312 Kern::InfoCopy(aDes,(TUint8*)&b,sizeof(b));
315 DImpSysTest::DImpSysTest()
323 TInt DImpSysTest::DoCreate(TInt /*aUnit*/, const TDesC8* /*anInfo*/, const TVersion& aVer)
329 if (!Kern::QueryVersionSupported(TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber),aVer))
330 return KErrNotSupported;
334 TInt DImpSysTest::Request(TInt aReqNo, TAny* a1, TAny*)
337 TInt r=KErrNotSupported;
340 case RImpSysTest::EControlStart:
343 case RImpSysTest::EControlStop:
346 kumemput32(a1,&s,sizeof(s));
358 DECLARE_STANDARD_LDD()
361 return 0; // not used on SMP
363 return new DImpSysTestFactory;