1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/usbho/t_otgdi/src/testengine.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,482 @@
1.4 +// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// @internalComponent
1.18 +//
1.19 +//
1.20 +
1.21 +#include <e32std.h>
1.22 +#include <e32std_private.h>
1.23 +#include <u32std.h> // unicode builds
1.24 +#include <e32base.h>
1.25 +#include <e32base_private.h>
1.26 +#include <e32cons.h>
1.27 +#include <e32Test.h> // RTest headder
1.28 +#include <e32def.h>
1.29 +#include <e32def_private.h>
1.30 +#include "debugmacros.h"
1.31 +#include "TestEngine.h"
1.32 +#include "TestCaseController.h"
1.33 +#include "TestCaseFactory.h"
1.34 +#include "TestCaseRoot.h"
1.35 +
1.36 +// Console application parameter options
1.37 +_LIT(KArgAllTestCases,"/ALL"); // see default test-list below
1.38 +_LIT(KArgGoTestCase, "/G:");
1.39 +_LIT(KArgAutomatedTest, "/AUTO"); // removes "press any key to continue" prompts
1.40 +_LIT(KArgVerboseOutput, "/VERBOSE"); // also turns on RDebug logging of all test output (to serial)
1.41 +_LIT(KArgSetOpenIterations, "/LOOPO:"); // Open/Close test loop count
1.42 +_LIT(KArgSetOOMIterations, "/LOOPM:"); // OOM test set #allocs
1.43 +_LIT(KArgSetRoleMaster, "/MASTER"); // this is the default
1.44 +_LIT(KArgSetRoleSlave, "/SLAVE"); // slave - Runs a dual-role test's Slave steps instead of Master
1.45 +_LIT(KArgOverrideVidPid, "/PID:"); // vendor, product ID XXXX 4 hex digits /PID:0670
1.46 +
1.47 +_LIT(KidFormatter,"PBASE-USB_OTGDI-%04d");
1.48 +_LIT(KidFormatterS,"PBASE-USB_OTGDI-%S");
1.49 +
1.50 +// '/ALL' tests grouping
1.51 +const TInt KAllDefaultTestIDs[6] =
1.52 + {
1.53 + 456, // (a) PBASE-USB_OTG-0456 open/close 'A'
1.54 + 457, // (a) PBASE-USB_OTG-0457 open/close disconnected
1.55 + 459, // (m) PBASE-USB_OTG-0459 detect 'A'
1.56 + 460, // (m) PBASE-USB_OTG-0460 detect 'A' removal
1.57 + 464, // (m) PBASE-USB_OTG-0464 raise
1.58 + 465 // (m) PBASE-USB_OTG-0465 lower
1.59 + };
1.60 +
1.61 +
1.62 +
1.63 +//
1.64 +// CTestEngine implementation
1.65 +//
1.66 +CTestEngine* CTestEngine::NewL()
1.67 + {
1.68 + CTestEngine* self = new (ELeave) CTestEngine;
1.69 + CleanupStack::PushL(self);
1.70 + self->ConstructL();
1.71 + CleanupStack::Pop(self);
1.72 + return self;
1.73 + }
1.74 +
1.75 +
1.76 +CTestEngine::CTestEngine():
1.77 + iTestCaseIndex(0),
1.78 + iHelpRequested(EFalse)
1.79 + {
1.80 +
1.81 + }
1.82 +
1.83 +
1.84 +CTestEngine::~CTestEngine()
1.85 + {
1.86 + LOG_FUNC
1.87 + // Destroy the test case controller
1.88 + if (iTestCaseController)
1.89 + {
1.90 + delete iTestCaseController;
1.91 + }
1.92 + // Destroy the test identity array and its contents
1.93 + iTestCasesIdentities.ResetAndDestroy();
1.94 +
1.95 + }
1.96 +
1.97 +
1.98 +void CTestEngine::ConstructL()
1.99 + {
1.100 + LOG_FUNC
1.101 + TInt menuSelection(0);
1.102 +
1.103 + // Display information
1.104 + test.Title();
1.105 + test.Start(_L("Test Engine Initiation v2.00 "));
1.106 + test.Printf(_L(">>\n"));
1.107 + test.Printf(_L(">> T E S T R U N \n"));
1.108 + test.Printf(_L(">>\n"));
1.109 +
1.110 +
1.111 + // Process the command line parameters for batch/etc
1.112 + TRAPD(err, ProcessCommandLineL());
1.113 + if (err != KErrNone)
1.114 + {
1.115 + User::Panic(_L("Test F/W Err"), KErrNoMemory);
1.116 + }
1.117 +
1.118 + if (iHelpRequested)
1.119 + {
1.120 + PrintUsage();
1.121 + User::Leave(-2); // nothing to do!
1.122 + }
1.123 +
1.124 + // if no command-line, we use a menu UI
1.125 + if (!iTestCasesIdentities.Count())
1.126 + {
1.127 + RPointerArray<HBufC> testCaseNames;
1.128 + // no tests added, select ONE to run from the menu
1.129 +
1.130 + // list test cases (PRINT MENU) - in numeric order
1.131 + RTestFactory::ListRegisteredTestCases(testCaseNames);
1.132 +
1.133 + iTestCaseIndex = 0; // be sure we go back to beginning of the collection!
1.134 + iTestCasesIdentities.ResetAndDestroy();
1.135 +
1.136 + test.Printf(_L("Please select 0 to %d\n"), RTestFactory::TestCaseCount()-1);
1.137 + test.Printf(_L("or 99<ENTER> to exit\n"));
1.138 + GetNumericInput(menuSelection);
1.139 + if ((menuSelection >=0) &&(menuSelection < RTestFactory::TestCaseCount()))
1.140 + {
1.141 + // add it to the list,and we can go
1.142 + TBuf<KTestCaseIdLength> aSelectionID;
1.143 + HBufC* tc = HBufC::NewLC(KTestCaseIdLength);
1.144 +
1.145 + // get name from index
1.146 + *tc = aSelectionID;
1.147 + *tc = *testCaseNames[menuSelection];
1.148 +
1.149 + iTestCasesIdentities.Append(tc);
1.150 + CleanupStack::Pop(tc);
1.151 + }
1.152 + testCaseNames.ResetAndDestroy();
1.153 + }
1.154 +
1.155 + if ((menuSelection < RTestFactory::TestCaseCount()) && (menuSelection>=0))
1.156 + {
1.157 + // Create the test case controller
1.158 + test.Printf(_L("Creating the test controller\n"));
1.159 + iTestCaseController = CTestCaseController::NewL(*this, ETrue);
1.160 +
1.161 + // Test-engine is non CActive class
1.162 + }
1.163 + else
1.164 + {
1.165 + // nothing to do, exit. USER aborted
1.166 + test.Printf(_L("Test run stopped by user, nothing to do.\n"));
1.167 + User::Leave(-2);
1.168 + }
1.169 + }
1.170 +
1.171 +
1.172 +/* Displayed if used supplied no parameters, garbage, or a ? in the parameters
1.173 + */
1.174 +void CTestEngine::PrintUsage()
1.175 + {
1.176 + test.Printf(_L("OTGDI Unit Test Suite.\n"));
1.177 + test.Printf(_L("Usage : t_otgdi.exe [/option] /G:<TESTNUM1>\n"));
1.178 + test.Printf(_L(" /ALL = add default test subset to List\n"));
1.179 + test.Printf(_L(" /G:<TESTNUM> where <testname> is the test# to add \n"));
1.180 + test.Printf(_L(" /AUTO = largely unattended operation\n"));
1.181 + test.Printf(_L(" /VERBOSE = test debugging info\n"));
1.182 + test.Printf(_L(" /LOOPO:<n> = Open/close repeat counter<n>\n"));
1.183 + test.Printf(_L(" /LOOPM:<n> = OOM HEAP_ALLOCS counter<n>\n"));
1.184 + test.Printf(_L(" /SLAVE = Test-peer server mode\n"));
1.185 + test.Printf(_L(" /PID:<n> = USB VID/PID in hex eg 2670\n"));
1.186 + test.Printf(_L("Valid test ID range 0456...0469\n"));
1.187 + test.Printf(_L("and 0675...0684 .\n"));
1.188 + test.Printf(_L("\n"));
1.189 + }
1.190 +
1.191 +/** process the command-line, ; arguments appear in any order
1.192 + IN : User::CommandLine()
1.193 + OUT : iTestCasesIdentities
1.194 + iHelpRequested
1.195 + gSemiAutomated
1.196 + gVerboseOutput
1.197 + gOpenIterations
1.198 + gOOMIterations
1.199 + gTestRoleMaster
1.200 + gUSBVidPid
1.201 +*/
1.202 +void CTestEngine::ProcessCommandLineL()
1.203 + {
1.204 + // example t_otgdi.exe /ALL /G:0468 /VERBOSE
1.205 + TInt cmdLineLength(User::CommandLineLength());
1.206 + HBufC* cmdLine = HBufC::NewMaxLC(cmdLineLength);
1.207 + TPtr cmdLinePtr = cmdLine->Des();
1.208 + User::CommandLine(cmdLinePtr);
1.209 + TBool tokenParsed(EFalse);
1.210 +
1.211 + TLex args(*cmdLine);
1.212 + args.SkipSpace(); // args are separated by spaces
1.213 +
1.214 + // first arg is the exe name, skip it
1.215 + TPtrC cmdToken = args.NextToken();
1.216 + HBufC* tc = HBufC::NewLC(KParameterTextLenMax);
1.217 + *tc = cmdToken;
1.218 + while (tc->Length())
1.219 + {
1.220 + tokenParsed = EFalse;
1.221 +
1.222 + // '/?' help wanted flag '?' or /? parameter
1.223 + TInt pos(0);
1.224 + if ((0== tc->FindF(_L("?"))) || (0==tc->FindF(_L("/?"))))
1.225 + {
1.226 + iHelpRequested = ETrue;
1.227 + tokenParsed = ETrue;
1.228 + }
1.229 +
1.230 + // '/ALL' parameter
1.231 + pos = tc->FindF(KArgAllTestCases);
1.232 + if (pos != KErrNotFound)
1.233 + {
1.234 + AddAllDefaultTests();
1.235 + tokenParsed = ETrue;
1.236 + }
1.237 +
1.238 + // '/AUTO'
1.239 + pos = tc->FindF(KArgAutomatedTest);
1.240 + if (pos != KErrNotFound)
1.241 + {
1.242 + // skip some of the press-any key things
1.243 + test.Printf(_L("Test semi-automated mode.\n"));
1.244 + gSemiAutomated = ETrue;
1.245 + tokenParsed = ETrue;
1.246 + }
1.247 +
1.248 + // '/G:TESTNAME'
1.249 + pos = tc->FindF(KArgGoTestCase);
1.250 + if (pos != KErrNotFound)
1.251 + {
1.252 + HBufC* tcPart = HBufC::NewLC(KTestCaseIdLength);
1.253 + TPtrC testID = tc->Right(tc->Length() - pos - KArgGoTestCase().Length());
1.254 +
1.255 + LOG_VERBOSE2(_L("Parameter found:'%S'\n"), &testID);
1.256 +
1.257 + // Check if it is a test we know of in our suite, users may provide the full
1.258 + // name "PBASE-USB_OTGDI-0466", or just the last 4 digits "0466", in such cases, fetch the full name
1.259 + if (!RTestFactory::TestCaseExists(testID))
1.260 + { // try use just the test#part
1.261 + TPtr tcDes = tcPart->Des();
1.262 +
1.263 + // build and add the full name
1.264 + tcDes.Format(KidFormatterS, &testID);
1.265 + if (!RTestFactory::TestCaseExists(tcDes))
1.266 + {
1.267 +
1.268 + test.Printf(_L("Test case does NOT Exist: '%lS'\n"), &testID);
1.269 + }
1.270 + else
1.271 + { // only the number was supplied, copy the full name
1.272 + testID.Set(tcDes);
1.273 + }
1.274 + }
1.275 + // check that it's valid before adding it to the run-list
1.276 + if (RTestFactory::TestCaseExists(testID))
1.277 + {
1.278 + HBufC* testIdentity = HBufC::NewLC(KTestCaseIdLength);
1.279 + *testIdentity = testID;
1.280 + test.Printf(_L("Test case specified: %lS\n"), testIdentity);
1.281 +
1.282 + iTestCasesIdentities.Append(testIdentity);
1.283 + CleanupStack::Pop(testIdentity);
1.284 + }
1.285 + CleanupStack::PopAndDestroy(tcPart);
1.286 + tokenParsed = ETrue;
1.287 + }
1.288 +
1.289 + // '/VERBOSE' option
1.290 + pos = tc->FindF(KArgVerboseOutput);
1.291 + if (pos != KErrNotFound)
1.292 + {
1.293 + gVerboseOutput = ETrue;
1.294 + tokenParsed = ETrue;
1.295 +
1.296 + // turn on logging of test Printf() output to serial debug/log at the same time
1.297 + test.SetLogged(ETrue);
1.298 +
1.299 + }
1.300 +
1.301 + // '/LOOPO:n' option (Set #times to run open/close tests amongst others)
1.302 + pos = tc->FindF(KArgSetOpenIterations);
1.303 + if (pos != KErrNotFound)
1.304 + {
1.305 + TPtrC iterationStr = tc->Right(tc->Length() - pos - KArgSetOpenIterations().Length());
1.306 + TLex lex(iterationStr);
1.307 + lex.Val(gOpenIterations);
1.308 + MINMAX_CLAMPVALUE(gOpenIterations, OPEN_MINREPEATS, OPEN_MAXREPEATS);
1.309 + tokenParsed = ETrue;
1.310 + }
1.311 +
1.312 + // '/LOOPM:n' option (Set # of allocs to start at for OOM test)
1.313 + pos = tc->FindF(KArgSetOOMIterations);
1.314 + if (pos != KErrNotFound)
1.315 + {
1.316 + TPtrC iterationStr = tc->Right(tc->Length() - pos - KArgSetOOMIterations().Length());
1.317 + TLex lex(iterationStr);
1.318 + lex.Val(gOOMIterations);
1.319 + MINMAX_CLAMPVALUE(gOOMIterations, OOM_MINREPEATS, OOM_MAXREPEATS);
1.320 + tokenParsed = ETrue;
1.321 + }
1.322 +
1.323 +
1.324 + // '/VID:nnnn' option (Set Symbian or other VID-Pid example /VID:0670)
1.325 + pos = tc->FindF(KArgOverrideVidPid);
1.326 + if (pos != KErrNotFound)
1.327 + {
1.328 + TPtrC vidpidStr = tc->Right(tc->Length() - pos - KArgOverrideVidPid().Length());
1.329 + TUint16 prodID;
1.330 + TLex lex(vidpidStr);
1.331 +
1.332 + if (KErrNone == lex.Val(prodID, EHex))
1.333 + {
1.334 + if (prodID> 0xFFFF)
1.335 + prodID = 0xFFFF;
1.336 + tokenParsed = ETrue;
1.337 + LOG_VERBOSE2(_L(" accept param %04X \n\n"), prodID);
1.338 + gUSBVidPid = prodID; // replace the vid-pid with the user-supplied one
1.339 + }
1.340 + else
1.341 + {
1.342 + // print error
1.343 + test.Printf(_L("Warning: VID+PID '%lS' not parsed .\n"), tc);
1.344 + }
1.345 + }
1.346 +
1.347 + // '/SLAVE' (peer)
1.348 + pos = tc->FindF(KArgSetRoleSlave);
1.349 + if (pos != KErrNotFound)
1.350 + {
1.351 + gTestRoleMaster = EFalse;
1.352 + tokenParsed = ETrue;
1.353 + }
1.354 + // '/MASTER' - default role
1.355 + pos = tc->FindF(KArgSetRoleMaster); // note that master is the default role, so this parameter is optional
1.356 + if (pos != KErrNotFound)
1.357 + {
1.358 + gTestRoleMaster = ETrue;
1.359 + tokenParsed = ETrue;
1.360 + }
1.361 +
1.362 + if (!tokenParsed)
1.363 + {
1.364 + // warn about unparsed parameter
1.365 + test.Printf(_L("Warning: '%lS'??? not parsed\n"), tc);
1.366 + iHelpRequested = ETrue;
1.367 + }
1.368 +
1.369 + // next parameter
1.370 + *tc = args.NextToken();
1.371 + }
1.372 + CleanupStack::PopAndDestroy(tc);
1.373 + CleanupStack::PopAndDestroy(cmdLine);
1.374 + }
1.375 +
1.376 +
1.377 +/** Add all default tests to the front of the test-list so we run them all in sequence
1.378 +*/
1.379 +void CTestEngine::AddAllDefaultTests()
1.380 + {
1.381 + test.Printf(_L("Adding default set test cases\n"));
1.382 + //
1.383 + TInt index(0);
1.384 + while (index < sizeof(KAllDefaultTestIDs)/sizeof(KAllDefaultTestIDs[0]))
1.385 + {
1.386 + // allocate heap string
1.387 + HBufC* tc(NULL);
1.388 + TRAPD(err, tc = HBufC::NewL(KTestCaseIdLength))
1.389 + if (err != KErrNone)
1.390 + {
1.391 + User::Panic(_L("Test F/W Err"), KErrNoMemory);
1.392 + }
1.393 + TPtr tcDes = tc->Des();
1.394 +
1.395 + // build and add it
1.396 + tcDes.Format(KidFormatter, KAllDefaultTestIDs[index]);
1.397 + iTestCasesIdentities.Append(tc);
1.398 + index++;
1.399 + }
1.400 + }
1.401 +
1.402 +
1.403 +/* Return subsequent test case IDs from the test run-list KerrNotFound = end of list.
1.404 + */
1.405 +TInt CTestEngine::NextTestCaseId(TDes& aTestCaseId)
1.406 + {
1.407 + if (iTestCaseIndex < iTestCasesIdentities.Count())
1.408 + {
1.409 + aTestCaseId = *iTestCasesIdentities[iTestCaseIndex++];
1.410 + return KErrNone;
1.411 + }
1.412 + else
1.413 + {
1.414 + return KErrNotFound;
1.415 + }
1.416 + }
1.417 +
1.418 +/////////////////////////////////////////////////////////////////////////////
1.419 +// utility functions
1.420 +
1.421 +
1.422 +void CTestEngine::GetNumericInput(TInt &aNumber)
1.423 + {
1.424 + TUint value(0);
1.425 + TUint digits(0);
1.426 + TKeyCode key = (TKeyCode) 0;
1.427 +
1.428 + aNumber = -1;
1.429 + while ( key != EKeyEnter )
1.430 + {
1.431 + key = test.Getch();
1.432 +
1.433 + if ( ( key >= '0' ) && ( key <= '9' ) )
1.434 + {
1.435 + test.Printf(_L("%c"),key);
1.436 +
1.437 + value = ( 10 * value ) + ( key - '0' );
1.438 + digits++;
1.439 + } else
1.440 + { // very basic keyboard processing, backspace
1.441 + if (key == EKeyBackspace)
1.442 + {
1.443 + value = value/10;
1.444 + digits--;
1.445 + test.Printf(_L("\r \r%d"), value);
1.446 + }
1.447 + }
1.448 + }
1.449 +
1.450 + if (digits > 0)
1.451 + {
1.452 + aNumber = value;
1.453 + }
1.454 + test.Printf(_L("\n"));
1.455 + }
1.456 +
1.457 +
1.458 +/** Print a report at the end of a test run of all PASSED tests, Note: If a
1.459 + test fails, the framework gets Panic'd */
1.460 +void CTestEngine::Report()
1.461 + {
1.462 + TBuf<KTestCaseIdLength> aTestCaseId;
1.463 + test.Printf(_L("============================\n"));
1.464 + test.Printf(_L("PASSED TESTS:\n"));
1.465 + // itterate our list of tests to perform
1.466 + ResetTestCaseIndex();
1.467 + while (KErrNone == NextTestCaseId(aTestCaseId))
1.468 + {
1.469 + test.Printf(_L("%S\n"), &aTestCaseId);
1.470 + }
1.471 + }
1.472 +
1.473 +
1.474 +void CTestEngine::DoCancel()
1.475 + {
1.476 + LOG_FUNC
1.477 + test.Console()->ReadCancel();
1.478 + }
1.479 +
1.480 +
1.481 +TInt CTestEngine::RunError(TInt aError)
1.482 + {
1.483 + return aError;
1.484 + }
1.485 +