os/kernelhwsrv/kerneltest/e32test/smpsoak/t_smpsoakspin.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2002-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\t_smpsoakspin.cpp
    15 //
    16 
    17 #define __E32TEST_EXTENSION__
    18 #include <e32svr.h>
    19 #include <e32test.h>
    20 #include <u32hal.h>
    21 #include <f32file.h>
    22 
    23 
    24 #include "d_smpsoak.h"
    25 
    26 #define PRINT(string) if (!gQuiet) test.Printf(string)
    27 #define PRINT1(string,param) if (!gQuiet) test.Printf(string,param)
    28 #define TESTNEXT(string) if (!gQuiet) test.Next(string)
    29 
    30 #define DEBUG_PRINT(__args)		test.Printf __args
    31 
    32 //------------globals---------------------
    33 LOCAL_D RTest test(_L("T_SMPSOAKSPIN"));
    34 LOCAL_D TBool gQuiet = EFalse;
    35 LOCAL_D TBool gAbort = EFalse;
    36 
    37 TInt		TestCpuCount = 0;
    38 
    39 const TInt KTimerPeriod = 10000;
    40 
    41 const TInt KHeapMinSize=0x1000;
    42 const TInt KHeapMaxSize=0x1000;
    43 
    44 // Create a new thread
    45 RThread *spinthread = new RThread;
    46 
    47 //Periadic Bip
    48 CPeriodic*	Timer;
    49 
    50 TInt SMPSpinThread(TAny*);
    51 
    52 
    53 struct TThread
    54 	{
    55 	RThread thread;
    56 	TDesC threadName;
    57 	TInt threadPriority;
    58 	TInt cpuAffinity;
    59 	TInt loopCount;
    60 	TInt endLoopDelay;
    61 	TBool fixedCPU;
    62 	TBool endFlag;
    63 	};
    64 
    65 TThread ThreadTable[] =
    66 	{
    67 		{ RThread(), _L("Thread1"),  EPriorityAbsoluteHigh,     0, 1000, 100, EFalse,    EFalse}, 	
    68 		{ RThread(), _L("Thread2"),  EPriorityAbsoluteHigh,     0, 1000, 100, EFalse,    EFalse}, 	 
    69 	};
    70 
    71 enum 
    72 	{
    73 	KThreads = (TInt)(sizeof(ThreadTable) / sizeof(TThread))
    74 };
    75 
    76 void ShowHelp()
    77 	{
    78 	PRINT(_L("***************************************\n"));
    79 	PRINT(_L("The following are available commands\n"));
    80 	PRINT(_L("Esc     to exit\n"));
    81 	PRINT(_L("***************************************\n"));
    82 	}
    83 
    84 TInt NumberOfCpus()
    85 	{
    86 	TInt r = UserSvr::HalFunction(EHalGroupKernel, EKernelHalNumLogicalCpus, 0, 0);
    87 	test(r>0);
    88 	return r;
    89 	}
    90 
    91 
    92 void ParseCommandLine ()
    93 	{
    94 	TBuf<64> c;
    95 	
    96 	User::CommandLine(c);
    97 	c.LowerCase();
    98 
    99 	if (c != KNullDesC)
   100 		{
   101 		TLex lex(c);
   102 		TPtrC token;
   103 
   104 		while (token.Set(lex.NextToken()), token != KNullDesC)
   105 			{
   106 			if (token.Mid(0) == _L("quiet"))
   107 				{
   108 				gQuiet = ETrue;
   109 				continue;
   110 				}
   111 
   112 			if (token.Mid(0) == _L("verbose"))
   113 				{
   114 				gQuiet = EFalse;
   115 				continue;
   116 				}
   117 			}
   118 		}
   119 	}
   120 
   121 // CActive class to monitor KeyStrokes from User
   122 class CActiveConsole : public CActive
   123 	{
   124 public:
   125 	CActiveConsole();
   126 	~CActiveConsole();
   127 	void GetCharacter();
   128 	static TInt Callback(TAny* aCtrl);
   129 	static CPeriodic* TimerL();
   130 private:
   131 
   132 	
   133 	// Defined as pure virtual by CActive;
   134 	// implementation provided by this class.
   135 	virtual void DoCancel();
   136 	// Defined as pure virtual by CActive;
   137 	// implementation provided by this class,
   138 	virtual void RunL();
   139 	void ProcessKeyPressL(TChar aChar);
   140 	};
   141 
   142 // Class CActiveConsole
   143 CActiveConsole::CActiveConsole()
   144 	: CActive(EPriorityHigh)
   145 	{
   146 	CActiveScheduler::Add(this);
   147 	}
   148 
   149 CActiveConsole::~CActiveConsole()
   150 	{
   151     Cancel();
   152 	}
   153 
   154 CPeriodic* CActiveConsole::TimerL()
   155     {
   156     return(CPeriodic::NewL(EPriorityNormal));
   157     }
   158 
   159 // Callback function for timer expiry
   160 TInt CActiveConsole::Callback(TAny* aControl)
   161 	{
   162 	return KErrNone;
   163 	}
   164 
   165 void CActiveConsole::GetCharacter()
   166 	{
   167 	test.Console()->Read(iStatus);
   168 	SetActive();
   169 	}
   170 
   171 void CActiveConsole::DoCancel()
   172 	{
   173 	PRINT(_L("CActiveConsole::DoCancel\n"));
   174 	test.Console()->ReadCancel();
   175 	}
   176 
   177 void CActiveConsole::ProcessKeyPressL(TChar aChar)
   178 	{
   179 	if (aChar == EKeyEscape)
   180 		{
   181 		PRINT(_L("CActiveConsole: ESC key pressed -> stopping active scheduler...\n"));
   182 		CActiveScheduler::Stop();
   183 		return;
   184 		}
   185 	aChar.UpperCase();
   186 	GetCharacter();
   187 	}
   188 
   189 void CActiveConsole::RunL()
   190 	{
   191 	ProcessKeyPressL(static_cast<TChar>(test.Console()->KeyCode()));
   192 	}
   193 
   194 TInt E32Main()
   195 	{
   196 	test.Title();
   197 	__UHEAP_MARK;
   198 	test.Start(_L("SMP Soak Test"));
   199 
   200 	test.Next(_L("Load device driver"));
   201 	TInt r = User::LoadLogicalDevice(_L("d_smpsoak.ldd"));
   202 	if (r == KErrNotFound)
   203 		{
   204 		test.Printf(_L("Test not supported on this platform because the D_SMPSOAK.LDD Driver is Not Present\n"));
   205 		test.End();
   206 		return 0;
   207 		}
   208 
   209 	test.Next(_L("Calling rt.Open"));
   210 	RSMPSoak rt;
   211 	r = rt.Open();
   212 	if (r!=KErrNone)
   213 		{
   214 		test.Printf(_L("Error- Couldn't able to open soak driver:%d"),r);
   215 		return r;
   216 		}
   217 	test.Next(_L("rt.Open called"));
   218 
   219     spinthread->Create(_L("SMPSpinThread"), SMPSpinThread, KDefaultStackSize, KHeapMinSize, KHeapMaxSize, &rt);
   220 	DEBUG_PRINT((_L("SMPSoak Thread is %x\n"), spinthread));
   221 
   222 	spinthread->SetPriority(EPriorityAbsoluteLow);
   223 
   224 	spinthread->Resume();
   225 	
   226 	ParseCommandLine();
   227 	
   228 	CActiveScheduler* myScheduler = new (ELeave) CActiveScheduler();
   229 	test(myScheduler !=NULL);
   230 	CActiveScheduler::Install(myScheduler);
   231 
   232 	CPeriodic* theTimer=NULL;
   233 	TRAPD(ret,theTimer=CActiveConsole::TimerL())
   234 	test_KErrNone(ret);
   235 	theTimer->Start(0,KTimerPeriod,TCallBack(CActiveConsole::Callback));
   236 
   237 	CActiveConsole* myActiveConsole = new CActiveConsole();
   238 	test(myActiveConsole !=NULL);
   239 	myActiveConsole->GetCharacter();
   240 
   241 	CActiveScheduler::Start();
   242 
   243 	delete theTimer;
   244 
   245 	 __UHEAP_MARKEND;
   246 
   247 	test.End();
   248 
   249 	return 0;
   250 	}
   251 
   252 TInt SMPSpinThread(TAny* rt)
   253 {
   254 	TInt startCpu = 0x00;
   255 	TInt endCpu = 0x00;
   256 	RTimer timer;
   257 	test(timer.CreateLocal()==KErrNone);
   258 	TRequestStatus s;
   259 
   260 	RSMPSoak* pMyDriver = (RSMPSoak*)rt;
   261 	RTest test(_L("SMPSpinThread"));
   262 	test.Title();
   263 
   264 	FOREVER
   265 	{
   266 		startCpu = pMyDriver->TryControl(RSMPSoak::KGETCURRENTCPU, 0);
   267 		
   268 		timer.After(s, 250000);			
   269 		User::WaitForRequest(s);
   270 		test(s==KErrNone);
   271 		DEBUG_PRINT((_L("+")));
   272 
   273 		endCpu = pMyDriver->TryControl(RSMPSoak::KGETCURRENTCPU, 0);
   274 		
   275 		if(startCpu != endCpu)
   276 		{
   277 			DEBUG_PRINT((_L("\r\nSMPSoakSpin app:- Thread moved from cpu %d to cpu %d ************\n"), startCpu, endCpu));
   278 		}
   279 		if (gAbort)
   280 			break;
   281 	}
   282 	
   283 	timer.Cancel();
   284 	DEBUG_PRINT((_L("MyTimer.Cancel() called\n")));
   285 	return 0x00;	
   286 }
   287 
   288