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