kerneltest/e32test/usbho/t_usbdi/src/TestEngine.cpp
branchRCL_3
changeset 257 3e88ff8f41d5
parent 256 c1f20ce4abcf
equal deleted inserted replaced
256:c1f20ce4abcf 257:3e88ff8f41d5
     1 // Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of the License "Eclipse Public License v1.0"
     4 // under the terms of the License "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
    18 
    18 
    19 #include "TestEngine.h"
    19 #include "TestEngine.h"
    20 #include "testdebug.h"
    20 #include "testdebug.h"
    21 #include "TestCaseController.h"
    21 #include "TestCaseController.h"
    22 #include "TestCaseFactory.h"
    22 #include "TestCaseFactory.h"
    23 #include "OstTraceDefinitions.h"
       
    24 #ifdef OST_TRACE_COMPILER_IN_USE
       
    25 #include "TestEngineTraces.h"
       
    26 #endif
       
    27 
    23 
    28 // Console application options
    24 // Console application options
    29 
    25 
    30 _LIT(KArgRole,"-role=");
    26 _LIT(KArgRole,"-role=");
    31 _LIT(KArgTestCases,"-cases=");
    27 _LIT(KArgTestCases,"-cases=");
    45 const TUint KTestIdSize = 4;
    41 const TUint KTestIdSize = 4;
    46 _LIT(KTestStringPreamble,"PBASE-T_USBDI-");
    42 _LIT(KTestStringPreamble,"PBASE-T_USBDI-");
    47 	
    43 	
    48 CTestEngine* CTestEngine::NewL()
    44 CTestEngine* CTestEngine::NewL()
    49 	{
    45 	{
    50 	OstTraceFunctionEntry0( CTESTENGINE_NEWL_ENTRY );
       
    51 	CTestEngine* self = new (ELeave) CTestEngine;
    46 	CTestEngine* self = new (ELeave) CTestEngine;
    52 	CleanupStack::PushL(self);
    47 	CleanupStack::PushL(self);
    53 	self->ConstructL();
    48 	self->ConstructL();
    54 	CleanupStack::Pop(self);
    49 	CleanupStack::Pop(self);
    55 	OstTraceFunctionExit1( CTESTENGINE_NEWL_EXIT, ( TUint )( self ) );
       
    56 	return self;
    50 	return self;
    57 	}
    51 	}
    58 
    52 
    59 
    53 
    60 
    54 
    61 CTestEngine::CTestEngine()
    55 CTestEngine::CTestEngine()
    62 :	CActive(EPriorityUserInput),
    56 :	CActive(EPriorityUserInput),
    63 	iTestCaseIndex(0), iRepeat(0), iNumRepeats(KDefaultNumRepeats)
    57 	iTestCaseIndex(0), iRepeat(0), iNumRepeats(KDefaultNumRepeats)
    64 	{
    58 	{
    65 	OstTraceFunctionEntry1( CTESTENGINE_CTESTENGINE_ENTRY, this );
       
    66 	OstTraceFunctionExit1( CTESTENGINE_CTESTENGINE_EXIT, this );
       
    67 	}
    59 	}
    68 
    60 
    69 
    61 
    70 
    62 
    71 CTestEngine::~CTestEngine()
    63 CTestEngine::~CTestEngine()
    72 	{
    64 	{
    73 	OstTraceFunctionEntry1( CTESTENGINE_CTESTENGINE_ENTRY_DUP01, this );
       
    74 	// Cancel reading user console input
    65 	// Cancel reading user console input
    75 	Cancel();
    66 	Cancel();
    76 	
    67 	
    77 	// Destroy the test case controller
    68 	// Destroy the test case controller
    78 	delete iTestCaseController;
    69 	delete iTestCaseController;
    81 	iTestCasesIdentities.ResetAndDestroy();
    72 	iTestCasesIdentities.ResetAndDestroy();
    82 	
    73 	
    83 	// Finish test and release resources
    74 	// Finish test and release resources
    84 	gtest.End();
    75 	gtest.End();
    85 	gtest.Close();
    76 	gtest.Close();
    86 	OstTraceFunctionExit1( CTESTENGINE_CTESTENGINE_EXIT_DUP01, this );
       
    87 	}
    77 	}
    88 	
    78 	
    89 	
    79 	
    90 	
    80 	
    91 void CTestEngine::ConstructL()
    81 void CTestEngine::ConstructL()
    92 	{
    82 	{
    93 	OstTraceFunctionEntry1( CTESTENGINE_CONSTRUCTL_ENTRY, this );
    83 	LOG_FUNC
    94 	CActiveScheduler::Add(this);
    84 	CActiveScheduler::Add(this);
    95 
    85 
    96 	// Display information (construction text and OS build version number
    86 	// Display information (construction text and OS build version number
    97 	gtest.Title();
    87 	gtest.Title();
    98 	gtest.Start(_L("Test Engine Initiation"));
    88 	gtest.Start(_L("Test Engine Initiation"));
    99 	gtest.Printf(_L(">>\n"));
    89 	gtest.Printf(_L(">>\n"));
   100 	OstTrace0(TRACE_NORMAL, CTESTENGINE_CONSTRUCTL, ">>\n");
       
   101 	gtest.Printf(_L(">>   T E S T   R U N \n"));
    90 	gtest.Printf(_L(">>   T E S T   R U N \n"));
   102 	OstTrace0(TRACE_NORMAL, CTESTENGINE_CONSTRUCTL_DUP01, ">>   T E S T   R U N \n");
       
   103 	gtest.Printf(_L(">>\n"));
    91 	gtest.Printf(_L(">>\n"));
   104 	OstTrace0(TRACE_NORMAL, CTESTENGINE_CONSTRUCTL_DUP02, ">>\n");
       
   105 
    92 
   106 	// Process the command line option for role
    93 	// Process the command line option for role
   107 	TInt cmdLineLength(User::CommandLineLength());
    94 	TInt cmdLineLength(User::CommandLineLength());
   108 	HBufC* cmdLine = HBufC::NewMax(cmdLineLength);
    95 	HBufC* cmdLine = HBufC::NewMax(cmdLineLength);
   109 	CleanupStack::PushL(cmdLine);
    96 	CleanupStack::PushL(cmdLine);
   110 	TPtr cmdLinePtr = cmdLine->Des();
    97 	TPtr cmdLinePtr = cmdLine->Des();
   111 	User::CommandLine(cmdLinePtr);
    98 	User::CommandLine(cmdLinePtr);
   112 	
    99 	
   113 	// be careful, command line length is limited(248 characters)	
   100 	// be careful, command line length is limited(248 characters)	
   114 	gtest.Printf(_L("***cmdLine = %lS\n"), cmdLine);
   101 	gtest.Printf(_L("***cmdLine = %lS\n"), cmdLine);
   115 	OstTraceExt1(TRACE_NORMAL, CTESTENGINE_CONSTRUCTL_DUP03, "***cmdLine = %lS\n", *cmdLine);
       
   116 		
   102 		
   117 	TLex args(*cmdLine);
   103 	TLex args(*cmdLine);
   118 	args.SkipSpace();
   104 	args.SkipSpace();
   119 	
   105 	
   120 	// Obtain the role of this test module
   106 	// Obtain the role of this test module
   135 			hostFlag = EFalse;
   121 			hostFlag = EFalse;
   136 			}
   122 			}
   137 		else
   123 		else
   138 			{
   124 			{
   139 			gtest.Printf(_L("Test configuration: could not find option -role\n"));
   125 			gtest.Printf(_L("Test configuration: could not find option -role\n"));
   140 			OstTrace0(TRACE_NORMAL, CTESTENGINE_CONSTRUCTL_DUP04, "Test configuration: could not find option -role\n");
       
   141 			gtest(EFalse);
   126 			gtest(EFalse);
   142 			}
   127 			}
   143 		}
   128 		}
   144 	else
   129 	else
   145 		{
   130 		{
   146 		gtest.Printf(_L("Test configuration option not found: %S\n"),&KArgRole);
   131 		gtest.Printf(_L("Test configuration option not found: %S\n"),&KArgRole);
   147 		OstTraceExt1(TRACE_NORMAL, CTESTENGINE_CONSTRUCTL_DUP05, "Test configuration option not found: %S\n",KArgRole);
       
   148 		gtest(EFalse);
   132 		gtest(EFalse);
   149 		}
   133 		}
   150 		
   134 		
   151 	// Obtain the test cases to be run
   135 	// Obtain the test cases to be run
   152 	TPtrC casesToken = args.NextToken();
   136 	TPtrC casesToken = args.NextToken();
   175 				{ 			
   159 				{ 			
   176 				tcPtr.Append(remCases.Left(KTestIdSize));
   160 				tcPtr.Append(remCases.Left(KTestIdSize));
   177 				}									
   161 				}									
   178 							
   162 							
   179 			gtest.Printf(_L("Test case specified: %S\n"),tc);
   163 			gtest.Printf(_L("Test case specified: %S\n"),tc);
   180 			OstTraceExt1(TRACE_NORMAL, CTESTENGINE_CONSTRUCTL_DUP06, "Test case specified: %S\n",*tc);
       
   181 			
   164 			
   182 						
   165 						
   183 			iTestCasesIdentities.Append(tc);
   166 			iTestCasesIdentities.Append(tc);
   184 			CleanupStack::Pop(tc);
   167 			CleanupStack::Pop(tc);
   185 			remCases.Set(testCases.Right(remCases.Length()-pos-1));
   168 			remCases.Set(testCases.Right(remCases.Length()-pos-1));
   186 			}
   169 			}
   187 		}
   170 		}
   188 	else
   171 	else
   189 		{
   172 		{
   190 		gtest.Printf(_L("Test configuration option not found: %S\n"),&KArgTestCases);
   173 		gtest.Printf(_L("Test configuration option not found: %S\n"),&KArgTestCases);
   191 		OstTraceExt1(TRACE_NORMAL, CTESTENGINE_CONSTRUCTL_DUP07, "Test configuration option not found: %S\n",KArgTestCases());
       
   192 		gtest(EFalse);		
   174 		gtest(EFalse);		
   193 		}
   175 		}
   194 				
   176 				
   195 	// Obtain the role of this test module
   177 	// Obtain the role of this test module
   196 	TPtrC repeatsToken = args.NextToken(); // e.g. -repeats=4
   178 	TPtrC repeatsToken = args.NextToken(); // e.g. -repeats=4
   203 		TLex lex(repeats);
   185 		TLex lex(repeats);
   204 		TInt ret = lex.Val(iNumRepeats, EDecimal);
   186 		TInt ret = lex.Val(iNumRepeats, EDecimal);
   205 		if(ret)
   187 		if(ret)
   206 			{
   188 			{
   207 			gtest.Printf(_L("Test configuration option not found: %S\n"),&KArgTestRepeats);
   189 			gtest.Printf(_L("Test configuration option not found: %S\n"),&KArgTestRepeats);
   208 			OstTraceExt1(TRACE_NORMAL, CTESTENGINE_CONSTRUCTL_DUP08, "Test configuration option not found: %S\n",KArgTestRepeats());
       
   209 			gtest.Printf(_L("DEFAULT to number of repeats = %d\n"),KDefaultNumRepeats);
   190 			gtest.Printf(_L("DEFAULT to number of repeats = %d\n"),KDefaultNumRepeats);
   210 			OstTrace1(TRACE_NORMAL, CTESTENGINE_CONSTRUCTL_DUP09, "DEFAULT to number of repeats = %d\n",KDefaultNumRepeats);
       
   211 			iNumRepeats = KDefaultNumRepeats;
   191 			iNumRepeats = KDefaultNumRepeats;
   212 			}
   192 			}
   213 		gtest.Printf(_L("Test repeats specified: %d cycles\n"),iNumRepeats);
   193 		gtest.Printf(_L("Test repeats specified: %d cycles\n"),iNumRepeats);
   214 		OstTrace1(TRACE_NORMAL, CTESTENGINE_CONSTRUCTL_DUP10, "Test repeats specified: %d cycles\n",iNumRepeats);
       
   215 		}
   194 		}
   216 	else
   195 	else
   217 		{
   196 		{
   218 		gtest.Printf(_L("Test configuration option not found: %S\n"),&KArgTestRepeats);
   197 		gtest.Printf(_L("Test configuration option not found: %S\n"),&KArgTestRepeats);
   219 		OstTraceExt1(TRACE_NORMAL, CTESTENGINE_CONSTRUCTL_DUP11, "Test configuration option not found: %S\n",KArgTestRepeats());
       
   220 		gtest.Printf(_L("DEFAULT to number of repeats = %d\n"),KDefaultNumRepeats);
   198 		gtest.Printf(_L("DEFAULT to number of repeats = %d\n"),KDefaultNumRepeats);
   221 		OstTrace1(TRACE_NORMAL, CTESTENGINE_CONSTRUCTL_DUP12, "DEFAULT to number of repeats = %d\n",KDefaultNumRepeats);
       
   222 		iNumRepeats = KDefaultNumRepeats;
   199 		iNumRepeats = KDefaultNumRepeats;
   223 		}
   200 		}
   224 		
   201 		
   225 	// Create the test case controller
   202 	// Create the test case controller
   226 	gtest.Printf(_L("Creating the test controller\n"));
   203 	gtest.Printf(_L("Creating the test controller\n"));
   227 	OstTrace0(TRACE_NORMAL, CTESTENGINE_CONSTRUCTL_DUP13, "Creating the test controller\n");
       
   228 	iTestCaseController = CTestCaseController::NewL(*this,hostFlag);
   204 	iTestCaseController = CTestCaseController::NewL(*this,hostFlag);
   229 
   205 
   230 	CleanupStack::PopAndDestroy(cmdLine);
   206 	CleanupStack::PopAndDestroy(cmdLine);
   231 
   207 
   232 	gtest.Console()->Read(iStatus);
   208 	gtest.Console()->Read(iStatus);
   233 	SetActive();	
   209 	SetActive();	
   234 	OstTraceFunctionExit1( CTESTENGINE_CONSTRUCTL_EXIT, this );
       
   235 	}
   210 	}
   236 	
   211 	
   237 
   212 
   238 TInt CTestEngine::NextTestCaseId(TDes& aTestCaseId)
   213 TInt CTestEngine::NextTestCaseId(TDes& aTestCaseId)
   239 	{
   214 	{
   240 	OstTraceFunctionEntryExt( CTESTENGINE_NEXTTESTCASEID_ENTRY, this );
   215 	LOG_FUNC
   241 	if(iTestCaseIndex < iTestCasesIdentities.Count())
   216 	if(iTestCaseIndex < iTestCasesIdentities.Count())
   242 		{
   217 		{
   243 		aTestCaseId = *iTestCasesIdentities[iTestCaseIndex++];
   218 		aTestCaseId = *iTestCasesIdentities[iTestCaseIndex++];
   244 		if(iTestCaseIndex==iTestCasesIdentities.Count())
   219 		if(iTestCaseIndex==iTestCasesIdentities.Count())
   245 			{
   220 			{
   247 			if(iRepeat < iNumRepeats)
   222 			if(iRepeat < iNumRepeats)
   248 				{
   223 				{
   249 				iTestCaseIndex = 0; //prepare to start again
   224 				iTestCaseIndex = 0; //prepare to start again
   250 				}
   225 				}
   251 			}
   226 			}
   252 		OstTraceFunctionExitExt( CTESTENGINE_NEXTTESTCASEID_EXIT, this, KErrNone );
       
   253 		return KErrNone;
   227 		return KErrNone;
   254 		}
   228 		}
   255 	else
   229 	else
   256 		{
   230 		{
   257 		OstTraceFunctionExitExt( CTESTENGINE_NEXTTESTCASEID_EXIT_DUP01, this, KErrNotFound );
       
   258 		return KErrNotFound;
   231 		return KErrNotFound;
   259 		}
   232 		}
   260 	}
   233 	}
   261 
   234 
   262 RPointerArray<HBufC>& CTestEngine::TestCasesIdentities()
   235 RPointerArray<HBufC>& CTestEngine::TestCasesIdentities()
   263 	{
   236 	{
   264 	OstTraceFunctionEntry1( CTESTENGINE_TESTCASESIDENTITIES_ENTRY, this );
       
   265 	OstTraceFunctionExitExt( CTESTENGINE_TESTCASESIDENTITIES_EXIT, this, ( TUint )&( iTestCasesIdentities ) );
       
   266 	return iTestCasesIdentities;
   237 	return iTestCasesIdentities;
   267 	}
   238 	}
   268 
   239 
   269 TUint CTestEngine::NumRepeats()
   240 TUint CTestEngine::NumRepeats()
   270 	{
   241 	{
   271 	OstTraceFunctionEntry1( CTESTENGINE_NUMREPEATS_ENTRY, this );
       
   272 	OstTraceFunctionExitExt( CTESTENGINE_NUMREPEATS_EXIT, this, iNumRepeats );
       
   273 	return iNumRepeats;
   242 	return iNumRepeats;
   274 	}
   243 	}
   275 
   244 
   276 void CTestEngine::DoCancel()
   245 void CTestEngine::DoCancel()
   277 	{
   246 	{
   278 	OstTraceFunctionEntry1( CTESTENGINE_DOCANCEL_ENTRY, this );
   247 	LOG_FUNC
   279 	gtest.Console()->ReadCancel();	
   248 	gtest.Console()->ReadCancel();	
   280 	OstTraceFunctionExit1( CTESTENGINE_DOCANCEL_EXIT, this );
       
   281 	}
   249 	}
   282 	
   250 	
   283 
   251 
   284 void CTestEngine::RunL()
   252 void CTestEngine::RunL()
   285 	{
   253 	{
   286 	OstTraceFunctionEntry1( CTESTENGINE_RUNL_ENTRY, this );
   254 	LOG_FUNC
   287 	TInt completionCode(iStatus.Int());
   255 	TInt completionCode(iStatus.Int());
   288 	
   256 	
   289 	if(completionCode == KErrNone)
   257 	if(completionCode == KErrNone)
   290 		{
   258 		{
   291 		// Possibility of displaying a range of key commands
   259 		// Possibility of displaying a range of key commands
   294 		TKeyCode keyCode(gtest.Console()->KeyCode());
   262 		TKeyCode keyCode(gtest.Console()->KeyCode());
   295 		if(keyCode == EKeySpace)
   263 		if(keyCode == EKeySpace)
   296 			{
   264 			{
   297 			iTestCaseController->Cancel();
   265 			iTestCaseController->Cancel();
   298 			gtest.Printf(_L("Test module terminating\n"));
   266 			gtest.Printf(_L("Test module terminating\n"));
   299 			OstTrace0(TRACE_NORMAL, CTESTENGINE_RUNL, "Test module terminating\n");
   267 			RDebug::Printf("CActiveScheduler::Stop CTestEngine::RunL");
   300 			OstTrace0(TRACE_NORMAL, CTESTENGINE_RUNL_DUP01, "CActiveScheduler::Stop CTestEngine::RunL");
       
   301 			CActiveScheduler::Stop();
   268 			CActiveScheduler::Stop();
   302 			}
   269 			}
   303 		else
   270 		else
   304 			{
   271 			{
   305 			gtest.Printf(_L("%d key pressed"),keyCode);
   272 			gtest.Printf(_L("%d key pressed"),keyCode);
   306 			OstTrace1(TRACE_NORMAL, CTESTENGINE_RUNL_DUP02, "%d key pressed",keyCode);
       
   307 			}
   273 			}
   308 		}
   274 		}
   309 	else
   275 	else
   310 		{
   276 		{
   311 		gtest.Printf(_L("Manual key error %d\n"),completionCode);
   277 		gtest.Printf(_L("Manual key error %d\n"),completionCode);
   312 		OstTrace1(TRACE_NORMAL, CTESTENGINE_RUNL_DUP03, "Manual key error %d\n",completionCode);
       
   313 		SetActive();
   278 		SetActive();
   314 		}
   279 		}
   315 	OstTraceFunctionExit1( CTESTENGINE_RUNL_EXIT, this );
       
   316 	}
   280 	}
   317 	
   281 	
   318 	
   282 	
   319 TInt CTestEngine::RunError(TInt aError)
   283 TInt CTestEngine::RunError(TInt aError)
   320 	{
   284 	{
   321 	OstTraceFunctionEntryExt( CTESTENGINE_RUNERROR_ENTRY, this );
       
   322 	OstTraceFunctionExitExt( CTESTENGINE_RUNERROR_EXIT, this, KErrNone );
       
   323 	return KErrNone;
   285 	return KErrNone;
   324 	}
   286 	}
   325 
   287 
   326 	}
   288 	}