44
|
1 |
// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
|
0
|
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 |
// @internalComponent
|
|
15 |
//
|
|
16 |
//
|
|
17 |
|
|
18 |
#include <e32std.h>
|
|
19 |
#include <e32std_private.h>
|
|
20 |
#include <u32std.h> // unicode builds
|
|
21 |
#include <e32base.h>
|
|
22 |
#include <e32base_private.h>
|
|
23 |
#include <e32cons.h>
|
|
24 |
#include <e32Test.h> // RTest headder
|
|
25 |
#include <e32def.h>
|
|
26 |
#include <e32def_private.h>
|
|
27 |
#include "debugmacros.h"
|
|
28 |
#include "TestEngine.h"
|
|
29 |
#include "TestCaseController.h"
|
|
30 |
#include "TestCaseFactory.h"
|
|
31 |
#include "TestCaseRoot.h"
|
|
32 |
|
|
33 |
// Console application parameter options
|
|
34 |
_LIT(KArgAllTestCases,"/ALL"); // see default test-list below
|
|
35 |
_LIT(KArgGoTestCase, "/G:");
|
|
36 |
_LIT(KArgAutomatedTest, "/AUTO"); // removes "press any key to continue" prompts
|
|
37 |
_LIT(KArgVerboseOutput, "/VERBOSE"); // also turns on RDebug logging of all test output (to serial)
|
|
38 |
_LIT(KArgSetOpenIterations, "/LOOPO:"); // Open/Close test loop count
|
|
39 |
_LIT(KArgSetOOMIterations, "/LOOPM:"); // OOM test set #allocs
|
|
40 |
_LIT(KArgSetRoleMaster, "/MASTER"); // this is the default
|
|
41 |
_LIT(KArgSetRoleSlave, "/SLAVE"); // slave - Runs a dual-role test's Slave steps instead of Master
|
|
42 |
_LIT(KArgOverrideVidPid, "/PID:"); // vendor, product ID XXXX 4 hex digits /PID:0670
|
|
43 |
|
|
44 |
_LIT(KidFormatter,"PBASE-USB_OTGDI-%04d");
|
|
45 |
_LIT(KidFormatterS,"PBASE-USB_OTGDI-%S");
|
|
46 |
|
|
47 |
// '/ALL' tests grouping
|
|
48 |
const TInt KAllDefaultTestIDs[6] =
|
|
49 |
{
|
|
50 |
456, // (a) PBASE-USB_OTG-0456 open/close 'A'
|
|
51 |
457, // (a) PBASE-USB_OTG-0457 open/close disconnected
|
|
52 |
459, // (m) PBASE-USB_OTG-0459 detect 'A'
|
|
53 |
460, // (m) PBASE-USB_OTG-0460 detect 'A' removal
|
|
54 |
464, // (m) PBASE-USB_OTG-0464 raise
|
|
55 |
465 // (m) PBASE-USB_OTG-0465 lower
|
|
56 |
};
|
|
57 |
|
|
58 |
|
|
59 |
|
|
60 |
//
|
|
61 |
// CTestEngine implementation
|
|
62 |
//
|
|
63 |
CTestEngine* CTestEngine::NewL()
|
|
64 |
{
|
|
65 |
CTestEngine* self = new (ELeave) CTestEngine;
|
|
66 |
CleanupStack::PushL(self);
|
|
67 |
self->ConstructL();
|
|
68 |
CleanupStack::Pop(self);
|
|
69 |
return self;
|
|
70 |
}
|
|
71 |
|
|
72 |
|
|
73 |
CTestEngine::CTestEngine():
|
|
74 |
iTestCaseIndex(0),
|
|
75 |
iHelpRequested(EFalse)
|
|
76 |
{
|
|
77 |
|
|
78 |
}
|
|
79 |
|
|
80 |
|
|
81 |
CTestEngine::~CTestEngine()
|
|
82 |
{
|
44
|
83 |
LOG_FUNC
|
0
|
84 |
// Destroy the test case controller
|
|
85 |
if (iTestCaseController)
|
|
86 |
{
|
|
87 |
delete iTestCaseController;
|
|
88 |
}
|
|
89 |
// Destroy the test identity array and its contents
|
|
90 |
iTestCasesIdentities.ResetAndDestroy();
|
|
91 |
|
|
92 |
}
|
|
93 |
|
|
94 |
|
|
95 |
void CTestEngine::ConstructL()
|
|
96 |
{
|
44
|
97 |
LOG_FUNC
|
0
|
98 |
TInt menuSelection(0);
|
|
99 |
|
|
100 |
// Display information
|
|
101 |
test.Title();
|
|
102 |
test.Start(_L("Test Engine Initiation v2.00 "));
|
|
103 |
test.Printf(_L(">>\n"));
|
|
104 |
test.Printf(_L(">> T E S T R U N \n"));
|
|
105 |
test.Printf(_L(">>\n"));
|
|
106 |
|
|
107 |
|
|
108 |
// Process the command line parameters for batch/etc
|
|
109 |
TRAPD(err, ProcessCommandLineL());
|
|
110 |
if (err != KErrNone)
|
|
111 |
{
|
|
112 |
User::Panic(_L("Test F/W Err"), KErrNoMemory);
|
|
113 |
}
|
|
114 |
|
|
115 |
if (iHelpRequested)
|
|
116 |
{
|
|
117 |
PrintUsage();
|
|
118 |
User::Leave(-2); // nothing to do!
|
|
119 |
}
|
|
120 |
|
|
121 |
// if no command-line, we use a menu UI
|
|
122 |
if (!iTestCasesIdentities.Count())
|
|
123 |
{
|
|
124 |
RPointerArray<HBufC> testCaseNames;
|
|
125 |
// no tests added, select ONE to run from the menu
|
|
126 |
|
|
127 |
// list test cases (PRINT MENU) - in numeric order
|
|
128 |
RTestFactory::ListRegisteredTestCases(testCaseNames);
|
|
129 |
|
|
130 |
iTestCaseIndex = 0; // be sure we go back to beginning of the collection!
|
|
131 |
iTestCasesIdentities.ResetAndDestroy();
|
|
132 |
|
|
133 |
test.Printf(_L("Please select 0 to %d\n"), RTestFactory::TestCaseCount()-1);
|
|
134 |
test.Printf(_L("or 99<ENTER> to exit\n"));
|
|
135 |
GetNumericInput(menuSelection);
|
|
136 |
if ((menuSelection >=0) &&(menuSelection < RTestFactory::TestCaseCount()))
|
|
137 |
{
|
|
138 |
// add it to the list,and we can go
|
|
139 |
TBuf<KTestCaseIdLength> aSelectionID;
|
|
140 |
HBufC* tc = HBufC::NewLC(KTestCaseIdLength);
|
|
141 |
|
|
142 |
// get name from index
|
|
143 |
*tc = aSelectionID;
|
|
144 |
*tc = *testCaseNames[menuSelection];
|
|
145 |
|
|
146 |
iTestCasesIdentities.Append(tc);
|
|
147 |
CleanupStack::Pop(tc);
|
|
148 |
}
|
|
149 |
testCaseNames.ResetAndDestroy();
|
|
150 |
}
|
|
151 |
|
|
152 |
if ((menuSelection < RTestFactory::TestCaseCount()) && (menuSelection>=0))
|
|
153 |
{
|
|
154 |
// Create the test case controller
|
|
155 |
test.Printf(_L("Creating the test controller\n"));
|
|
156 |
iTestCaseController = CTestCaseController::NewL(*this, ETrue);
|
|
157 |
|
|
158 |
// Test-engine is non CActive class
|
|
159 |
}
|
|
160 |
else
|
|
161 |
{
|
|
162 |
// nothing to do, exit. USER aborted
|
|
163 |
test.Printf(_L("Test run stopped by user, nothing to do.\n"));
|
|
164 |
User::Leave(-2);
|
|
165 |
}
|
|
166 |
}
|
|
167 |
|
|
168 |
|
|
169 |
/* Displayed if used supplied no parameters, garbage, or a ? in the parameters
|
|
170 |
*/
|
|
171 |
void CTestEngine::PrintUsage()
|
|
172 |
{
|
|
173 |
test.Printf(_L("OTGDI Unit Test Suite.\n"));
|
|
174 |
test.Printf(_L("Usage : t_otgdi.exe [/option] /G:<TESTNUM1>\n"));
|
|
175 |
test.Printf(_L(" /ALL = add default test subset to List\n"));
|
|
176 |
test.Printf(_L(" /G:<TESTNUM> where <testname> is the test# to add \n"));
|
|
177 |
test.Printf(_L(" /AUTO = largely unattended operation\n"));
|
|
178 |
test.Printf(_L(" /VERBOSE = test debugging info\n"));
|
|
179 |
test.Printf(_L(" /LOOPO:<n> = Open/close repeat counter<n>\n"));
|
|
180 |
test.Printf(_L(" /LOOPM:<n> = OOM HEAP_ALLOCS counter<n>\n"));
|
|
181 |
test.Printf(_L(" /SLAVE = Test-peer server mode\n"));
|
|
182 |
test.Printf(_L(" /PID:<n> = USB VID/PID in hex eg 2670\n"));
|
|
183 |
test.Printf(_L("Valid test ID range 0456...0469\n"));
|
|
184 |
test.Printf(_L("and 0675...0684 .\n"));
|
|
185 |
test.Printf(_L("\n"));
|
|
186 |
}
|
|
187 |
|
|
188 |
/** process the command-line, ; arguments appear in any order
|
|
189 |
IN : User::CommandLine()
|
|
190 |
OUT : iTestCasesIdentities
|
|
191 |
iHelpRequested
|
|
192 |
gSemiAutomated
|
|
193 |
gVerboseOutput
|
|
194 |
gOpenIterations
|
|
195 |
gOOMIterations
|
|
196 |
gTestRoleMaster
|
|
197 |
gUSBVidPid
|
|
198 |
*/
|
|
199 |
void CTestEngine::ProcessCommandLineL()
|
|
200 |
{
|
|
201 |
// example t_otgdi.exe /ALL /G:0468 /VERBOSE
|
|
202 |
TInt cmdLineLength(User::CommandLineLength());
|
|
203 |
HBufC* cmdLine = HBufC::NewMaxLC(cmdLineLength);
|
|
204 |
TPtr cmdLinePtr = cmdLine->Des();
|
|
205 |
User::CommandLine(cmdLinePtr);
|
|
206 |
TBool tokenParsed(EFalse);
|
|
207 |
|
|
208 |
TLex args(*cmdLine);
|
|
209 |
args.SkipSpace(); // args are separated by spaces
|
|
210 |
|
|
211 |
// first arg is the exe name, skip it
|
|
212 |
TPtrC cmdToken = args.NextToken();
|
|
213 |
HBufC* tc = HBufC::NewLC(KParameterTextLenMax);
|
|
214 |
*tc = cmdToken;
|
|
215 |
while (tc->Length())
|
|
216 |
{
|
|
217 |
tokenParsed = EFalse;
|
|
218 |
|
|
219 |
// '/?' help wanted flag '?' or /? parameter
|
|
220 |
TInt pos(0);
|
|
221 |
if ((0== tc->FindF(_L("?"))) || (0==tc->FindF(_L("/?"))))
|
|
222 |
{
|
|
223 |
iHelpRequested = ETrue;
|
|
224 |
tokenParsed = ETrue;
|
|
225 |
}
|
|
226 |
|
|
227 |
// '/ALL' parameter
|
|
228 |
pos = tc->FindF(KArgAllTestCases);
|
|
229 |
if (pos != KErrNotFound)
|
|
230 |
{
|
|
231 |
AddAllDefaultTests();
|
|
232 |
tokenParsed = ETrue;
|
|
233 |
}
|
|
234 |
|
|
235 |
// '/AUTO'
|
|
236 |
pos = tc->FindF(KArgAutomatedTest);
|
|
237 |
if (pos != KErrNotFound)
|
|
238 |
{
|
|
239 |
// skip some of the press-any key things
|
|
240 |
test.Printf(_L("Test semi-automated mode.\n"));
|
|
241 |
gSemiAutomated = ETrue;
|
|
242 |
tokenParsed = ETrue;
|
|
243 |
}
|
|
244 |
|
|
245 |
// '/G:TESTNAME'
|
|
246 |
pos = tc->FindF(KArgGoTestCase);
|
|
247 |
if (pos != KErrNotFound)
|
|
248 |
{
|
|
249 |
HBufC* tcPart = HBufC::NewLC(KTestCaseIdLength);
|
|
250 |
TPtrC testID = tc->Right(tc->Length() - pos - KArgGoTestCase().Length());
|
|
251 |
|
|
252 |
LOG_VERBOSE2(_L("Parameter found:'%S'\n"), &testID);
|
|
253 |
|
|
254 |
// Check if it is a test we know of in our suite, users may provide the full
|
|
255 |
// name "PBASE-USB_OTGDI-0466", or just the last 4 digits "0466", in such cases, fetch the full name
|
|
256 |
if (!RTestFactory::TestCaseExists(testID))
|
|
257 |
{ // try use just the test#part
|
|
258 |
TPtr tcDes = tcPart->Des();
|
|
259 |
|
|
260 |
// build and add the full name
|
|
261 |
tcDes.Format(KidFormatterS, &testID);
|
|
262 |
if (!RTestFactory::TestCaseExists(tcDes))
|
|
263 |
{
|
|
264 |
|
|
265 |
test.Printf(_L("Test case does NOT Exist: '%lS'\n"), &testID);
|
|
266 |
}
|
|
267 |
else
|
|
268 |
{ // only the number was supplied, copy the full name
|
|
269 |
testID.Set(tcDes);
|
|
270 |
}
|
|
271 |
}
|
|
272 |
// check that it's valid before adding it to the run-list
|
|
273 |
if (RTestFactory::TestCaseExists(testID))
|
|
274 |
{
|
|
275 |
HBufC* testIdentity = HBufC::NewLC(KTestCaseIdLength);
|
|
276 |
*testIdentity = testID;
|
|
277 |
test.Printf(_L("Test case specified: %lS\n"), testIdentity);
|
|
278 |
|
|
279 |
iTestCasesIdentities.Append(testIdentity);
|
|
280 |
CleanupStack::Pop(testIdentity);
|
|
281 |
}
|
|
282 |
CleanupStack::PopAndDestroy(tcPart);
|
|
283 |
tokenParsed = ETrue;
|
|
284 |
}
|
|
285 |
|
|
286 |
// '/VERBOSE' option
|
|
287 |
pos = tc->FindF(KArgVerboseOutput);
|
|
288 |
if (pos != KErrNotFound)
|
|
289 |
{
|
|
290 |
gVerboseOutput = ETrue;
|
|
291 |
tokenParsed = ETrue;
|
|
292 |
|
|
293 |
// turn on logging of test Printf() output to serial debug/log at the same time
|
|
294 |
test.SetLogged(ETrue);
|
|
295 |
|
|
296 |
}
|
|
297 |
|
|
298 |
// '/LOOPO:n' option (Set #times to run open/close tests amongst others)
|
|
299 |
pos = tc->FindF(KArgSetOpenIterations);
|
|
300 |
if (pos != KErrNotFound)
|
|
301 |
{
|
|
302 |
TPtrC iterationStr = tc->Right(tc->Length() - pos - KArgSetOpenIterations().Length());
|
|
303 |
TLex lex(iterationStr);
|
|
304 |
lex.Val(gOpenIterations);
|
|
305 |
MINMAX_CLAMPVALUE(gOpenIterations, OPEN_MINREPEATS, OPEN_MAXREPEATS);
|
|
306 |
tokenParsed = ETrue;
|
|
307 |
}
|
|
308 |
|
|
309 |
// '/LOOPM:n' option (Set # of allocs to start at for OOM test)
|
|
310 |
pos = tc->FindF(KArgSetOOMIterations);
|
|
311 |
if (pos != KErrNotFound)
|
|
312 |
{
|
|
313 |
TPtrC iterationStr = tc->Right(tc->Length() - pos - KArgSetOOMIterations().Length());
|
|
314 |
TLex lex(iterationStr);
|
|
315 |
lex.Val(gOOMIterations);
|
|
316 |
MINMAX_CLAMPVALUE(gOOMIterations, OOM_MINREPEATS, OOM_MAXREPEATS);
|
|
317 |
tokenParsed = ETrue;
|
|
318 |
}
|
|
319 |
|
|
320 |
|
|
321 |
// '/VID:nnnn' option (Set Symbian or other VID-Pid example /VID:0670)
|
|
322 |
pos = tc->FindF(KArgOverrideVidPid);
|
|
323 |
if (pos != KErrNotFound)
|
|
324 |
{
|
|
325 |
TPtrC vidpidStr = tc->Right(tc->Length() - pos - KArgOverrideVidPid().Length());
|
|
326 |
TUint16 prodID;
|
|
327 |
TLex lex(vidpidStr);
|
|
328 |
|
|
329 |
if (KErrNone == lex.Val(prodID, EHex))
|
|
330 |
{
|
|
331 |
if (prodID> 0xFFFF)
|
|
332 |
prodID = 0xFFFF;
|
|
333 |
tokenParsed = ETrue;
|
|
334 |
LOG_VERBOSE2(_L(" accept param %04X \n\n"), prodID);
|
|
335 |
gUSBVidPid = prodID; // replace the vid-pid with the user-supplied one
|
|
336 |
}
|
|
337 |
else
|
|
338 |
{
|
|
339 |
// print error
|
|
340 |
test.Printf(_L("Warning: VID+PID '%lS' not parsed .\n"), tc);
|
|
341 |
}
|
|
342 |
}
|
|
343 |
|
|
344 |
// '/SLAVE' (peer)
|
|
345 |
pos = tc->FindF(KArgSetRoleSlave);
|
|
346 |
if (pos != KErrNotFound)
|
|
347 |
{
|
|
348 |
gTestRoleMaster = EFalse;
|
|
349 |
tokenParsed = ETrue;
|
|
350 |
}
|
|
351 |
// '/MASTER' - default role
|
|
352 |
pos = tc->FindF(KArgSetRoleMaster); // note that master is the default role, so this parameter is optional
|
|
353 |
if (pos != KErrNotFound)
|
|
354 |
{
|
|
355 |
gTestRoleMaster = ETrue;
|
|
356 |
tokenParsed = ETrue;
|
|
357 |
}
|
|
358 |
|
|
359 |
if (!tokenParsed)
|
|
360 |
{
|
|
361 |
// warn about unparsed parameter
|
|
362 |
test.Printf(_L("Warning: '%lS'??? not parsed\n"), tc);
|
|
363 |
iHelpRequested = ETrue;
|
|
364 |
}
|
|
365 |
|
|
366 |
// next parameter
|
|
367 |
*tc = args.NextToken();
|
|
368 |
}
|
|
369 |
CleanupStack::PopAndDestroy(tc);
|
|
370 |
CleanupStack::PopAndDestroy(cmdLine);
|
|
371 |
}
|
|
372 |
|
|
373 |
|
|
374 |
/** Add all default tests to the front of the test-list so we run them all in sequence
|
|
375 |
*/
|
|
376 |
void CTestEngine::AddAllDefaultTests()
|
|
377 |
{
|
|
378 |
test.Printf(_L("Adding default set test cases\n"));
|
|
379 |
//
|
|
380 |
TInt index(0);
|
|
381 |
while (index < sizeof(KAllDefaultTestIDs)/sizeof(KAllDefaultTestIDs[0]))
|
|
382 |
{
|
|
383 |
// allocate heap string
|
|
384 |
HBufC* tc(NULL);
|
|
385 |
TRAPD(err, tc = HBufC::NewL(KTestCaseIdLength))
|
|
386 |
if (err != KErrNone)
|
|
387 |
{
|
|
388 |
User::Panic(_L("Test F/W Err"), KErrNoMemory);
|
|
389 |
}
|
|
390 |
TPtr tcDes = tc->Des();
|
|
391 |
|
|
392 |
// build and add it
|
|
393 |
tcDes.Format(KidFormatter, KAllDefaultTestIDs[index]);
|
|
394 |
iTestCasesIdentities.Append(tc);
|
|
395 |
index++;
|
|
396 |
}
|
|
397 |
}
|
|
398 |
|
|
399 |
|
|
400 |
/* Return subsequent test case IDs from the test run-list KerrNotFound = end of list.
|
|
401 |
*/
|
|
402 |
TInt CTestEngine::NextTestCaseId(TDes& aTestCaseId)
|
|
403 |
{
|
|
404 |
if (iTestCaseIndex < iTestCasesIdentities.Count())
|
|
405 |
{
|
|
406 |
aTestCaseId = *iTestCasesIdentities[iTestCaseIndex++];
|
|
407 |
return KErrNone;
|
|
408 |
}
|
|
409 |
else
|
|
410 |
{
|
|
411 |
return KErrNotFound;
|
|
412 |
}
|
|
413 |
}
|
|
414 |
|
|
415 |
/////////////////////////////////////////////////////////////////////////////
|
|
416 |
// utility functions
|
|
417 |
|
|
418 |
|
|
419 |
void CTestEngine::GetNumericInput(TInt &aNumber)
|
|
420 |
{
|
|
421 |
TUint value(0);
|
|
422 |
TUint digits(0);
|
|
423 |
TKeyCode key = (TKeyCode) 0;
|
|
424 |
|
|
425 |
aNumber = -1;
|
|
426 |
while ( key != EKeyEnter )
|
|
427 |
{
|
|
428 |
key = test.Getch();
|
|
429 |
|
|
430 |
if ( ( key >= '0' ) && ( key <= '9' ) )
|
|
431 |
{
|
|
432 |
test.Printf(_L("%c"),key);
|
|
433 |
|
|
434 |
value = ( 10 * value ) + ( key - '0' );
|
|
435 |
digits++;
|
|
436 |
} else
|
|
437 |
{ // very basic keyboard processing, backspace
|
|
438 |
if (key == EKeyBackspace)
|
|
439 |
{
|
|
440 |
value = value/10;
|
|
441 |
digits--;
|
|
442 |
test.Printf(_L("\r \r%d"), value);
|
|
443 |
}
|
|
444 |
}
|
|
445 |
}
|
|
446 |
|
|
447 |
if (digits > 0)
|
|
448 |
{
|
|
449 |
aNumber = value;
|
|
450 |
}
|
|
451 |
test.Printf(_L("\n"));
|
|
452 |
}
|
|
453 |
|
|
454 |
|
|
455 |
/** Print a report at the end of a test run of all PASSED tests, Note: If a
|
|
456 |
test fails, the framework gets Panic'd */
|
|
457 |
void CTestEngine::Report()
|
|
458 |
{
|
|
459 |
TBuf<KTestCaseIdLength> aTestCaseId;
|
|
460 |
test.Printf(_L("============================\n"));
|
|
461 |
test.Printf(_L("PASSED TESTS:\n"));
|
|
462 |
// itterate our list of tests to perform
|
|
463 |
ResetTestCaseIndex();
|
|
464 |
while (KErrNone == NextTestCaseId(aTestCaseId))
|
|
465 |
{
|
|
466 |
test.Printf(_L("%S\n"), &aTestCaseId);
|
|
467 |
}
|
|
468 |
}
|
|
469 |
|
|
470 |
|
|
471 |
void CTestEngine::DoCancel()
|
|
472 |
{
|
44
|
473 |
LOG_FUNC
|
0
|
474 |
test.Console()->ReadCancel();
|
|
475 |
}
|
|
476 |
|
|
477 |
|
|
478 |
TInt CTestEngine::RunError(TInt aError)
|
|
479 |
{
|
|
480 |
return aError;
|
|
481 |
}
|
|
482 |
|