1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/mm/mmtestenv/mmtestfw/Source/TestFramework/TestFrameworkMain.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,385 @@
1.4 +// Copyright (c) 2002-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 "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 +//
1.18 +
1.19 +#include "TestFrameworkMain.h"
1.20 +#include "../../recog/TestFrameworkRecog.h"
1.21 +#include "script.h"
1.22 +#include "parseline.h"
1.23 +#include "Filename.h"
1.24 +#include "config.h"
1.25 +
1.26 +// Hurricane emulator only - start all services which we require to run tests.
1.27 +// Future enhancement :- add these startups to TestUtils
1.28 +#if defined(__WINS__)
1.29 +IMPORT_C TInt FbsStartup();
1.30 +#endif
1.31 +
1.32 +/**
1.33 + *
1.34 + * Literals : program information and usage
1.35 + *
1.36 + * @xxxx
1.37 + *
1.38 + */
1.39 +_LIT(KTxtFrameworkStarting, "%S %S %S starting....");
1.40 +//_LIT(KTxtUseExample,"Usage:\nTESTFRAMEWORK [-C] [-F] <file.script> [file.ini]"); // EABI warning removal
1.41 +
1.42 +/**
1.43 + *
1.44 + * Compiler switches
1.45 + *
1.46 + * @xxxx
1.47 + *
1.48 + */
1.49 +#ifdef _WIN32
1.50 +_LIT(KTxtTarget,"WINS");
1.51 +#else
1.52 +#ifdef __MARM_THUMB__
1.53 +_LIT(KTxtTarget,"THUMB");
1.54 +#else
1.55 +_LIT(KTxtTarget,"ARM4");
1.56 +#endif
1.57 +#endif
1.58 +
1.59 +#ifdef _DEBUG
1.60 +_LIT(KTxtBuild,"udeb");
1.61 +#else
1.62 +_LIT(KTxtBuild,"urel");
1.63 +#endif
1.64 +
1.65 +
1.66 +/**
1.67 + *
1.68 + * max length of command line
1.69 + *
1.70 + * @xxxx
1.71 + *
1.72 + */
1.73 +const TInt KMaxLenCmdLine = 256;
1.74 +
1.75 +/**
1.76 + *
1.77 + * Test Framework startup function.
1.78 + * Creates an active scheduler for input if required, reads
1.79 + * the command line, starts the main test loop.
1.80 + *
1.81 + * @xxxx
1.82 + *
1.83 + */
1.84 +void StartupL()
1.85 + {
1.86 + CActiveScheduler* pA=new(ELeave) CActiveScheduler;
1.87 + CleanupStack::PushL(pA);
1.88 + CActiveScheduler::Install(pA);
1.89 +
1.90 +// Hurricane emulator only - start all services which we require to run tests.
1.91 +// Future enhancement :- add these startups to TestUtils
1.92 +#if defined(__WINS__)
1.93 + #ifndef EXCLUDE_FOR_UNITTEST
1.94 + FbsStartup();
1.95 + #endif // EXCLUDE_FOR_UNITTEST
1.96 +#endif
1.97 +
1.98 + // read the command line into cmd
1.99 + TPtr16 cmd(REINTERPRET_CAST(TUint16*,User::AllocLC(KMaxLenCmdLine*2)), 0, KMaxLenCmdLine);
1.100 + cmd.Fill('\0', KMaxLenCmdLine);
1.101 +
1.102 + User::CommandLine(cmd);
1.103 + cmd.UpperCase();
1.104 +
1.105 + CTestFrameworkMain* tester = CTestFrameworkMain::NewLC();
1.106 + tester->StartTestingL(cmd);
1.107 +
1.108 + // NOTE. Currently there is no need to start the active scheduler, as the input console is
1.109 + // now at the server. This will however change when AOs are implemented to replace
1.110 + // the main client loop.
1.111 +
1.112 + // CActiveScheduler::Start();
1.113 +
1.114 + CleanupStack::PopAndDestroy(3); //tester, pA, cmd
1.115 + }
1.116 +
1.117 +
1.118 +GLDEF_C TInt E32Main()
1.119 + {
1.120 +
1.121 + __UHEAP_MARK;
1.122 + CTrapCleanup* cleanup = CTrapCleanup::New(); // get clean-up stack
1.123 +
1.124 + // start scheduler
1.125 + TRAPD(error, StartupL());
1.126 + __ASSERT_ALWAYS(!error, User::Panic(_L("TestFramework"), error));
1.127 +
1.128 + delete cleanup; // destroy clean-up stack
1.129 + __UHEAP_MARKEND;
1.130 + return KErrNone;
1.131 + }
1.132 +
1.133 +// Instructions for Console Display
1.134 +// Please add new entries to the right hand column,
1.135 +// Precede number and text with "\t "
1.136 +// Leave \n\ at end of each line except the last line
1.137 +//_LIT(KTxtMainInstructions, "Welcome to TestFramework. Press Q to quit "); // EABI warning removal
1.138 +
1.139 +
1.140 +/**
1.141 + *
1.142 + * CTestFrameworkMain static constructor.
1.143 + *
1.144 + * @xxxx
1.145 + *
1.146 + */
1.147 +CTestFrameworkMain* CTestFrameworkMain::NewLC()
1.148 + {
1.149 + CTestFrameworkMain* s = new(ELeave) CTestFrameworkMain;
1.150 + CleanupStack::PushL(s);
1.151 + s->ConstructL();
1.152 + return s;
1.153 + }
1.154 +
1.155 +/**
1.156 + *
1.157 + * CTestFrameworkMain first-phase constructor.
1.158 + *
1.159 + * @xxxx
1.160 + *
1.161 + */
1.162 +CTestFrameworkMain::CTestFrameworkMain()
1.163 + {
1.164 + }
1.165 +
1.166 +/**
1.167 + *
1.168 + * CTestFrameworkMain second-phase constructor.
1.169 + * Loads log client and test utils.
1.170 + *
1.171 + * @xxxx
1.172 + *
1.173 + */
1.174 +void CTestFrameworkMain::ConstructL()
1.175 + {
1.176 + iLogClient = CLog::NewL();
1.177 + iLogMode = ELogToConsole | ELogToFile;
1.178 + iTestUtils = CTestUtils::NewL(iLogClient);
1.179 + iGuardTimer = KNoGuardTimer; // default value
1.180 + }
1.181 +
1.182 +/**
1.183 + *
1.184 + * CTestFrameworkMain destructor.
1.185 + *
1.186 + * @xxxx
1.187 + *
1.188 + */
1.189 +CTestFrameworkMain::~CTestFrameworkMain()
1.190 + {
1.191 + delete iTestUtils;
1.192 + delete iLogClient;
1.193 + }
1.194 +
1.195 +/**
1.196 + *
1.197 + * CTestFrameworkMain - start testing.
1.198 + * Calls main test loop.
1.199 + *
1.200 + * @param "const TDesC& aCmdLine"
1.201 + * The command line
1.202 + *
1.203 + * @xxxx
1.204 + *
1.205 + */
1.206 +void CTestFrameworkMain::StartTestingL(const TDesC& aCmdLine)
1.207 + {
1.208 + RunTestScriptL(aCmdLine);
1.209 +
1.210 + RSemaphore sem;
1.211 + TInt err = sem.OpenGlobal(KRecogSemaphoreName);
1.212 + if (err==KErrNone)
1.213 + {
1.214 + // Tell the recognizer thread that we're finished
1.215 + sem.Signal();
1.216 + sem.Close();
1.217 + }
1.218 + }
1.219 +
1.220 +/**
1.221 + *
1.222 + * Accessor : log client
1.223 + *
1.224 + * @return "CLog*"
1.225 + * The log client
1.226 + *
1.227 + * @xxxx
1.228 + *
1.229 + */
1.230 +CLog* CTestFrameworkMain::LogClient() const
1.231 + {
1.232 + return iLogClient;
1.233 + }
1.234 +
1.235 +/**
1.236 + *
1.237 + * Main testing loop.
1.238 + * Read a script file, parse it and execute each test step in turn.
1.239 + *
1.240 + * @param "const TDesC& aCmdLine"
1.241 + * The command line
1.242 + *
1.243 + * @xxxx
1.244 + *
1.245 + */
1.246 +void CTestFrameworkMain::RunTestScriptL(const TDesC& aCmdLine)
1.247 + {
1.248 + // use TLex to decode the cmd line
1.249 + TLex lex(aCmdLine);
1.250 + TPtrC token=lex.NextToken();
1.251 +
1.252 + // if there is no input filename on the cmd line, panic
1.253 + if (token.Length() == 0)
1.254 + UsageL();
1.255 + else
1.256 + {
1.257 + // Process any options
1.258 + while(token.Length() > 1 && token[0] == '-')
1.259 + {
1.260 + switch(token[1])
1.261 + {
1.262 + case 'C':
1.263 + case 'c':
1.264 + // log to console ONLY
1.265 + iLogMode = ELogToConsole;
1.266 + break;
1.267 + case 'A':
1.268 + case 'a':
1.269 + iLogMode |= ELogConsoleFull;
1.270 + break;
1.271 + case 'F':
1.272 + case 'f':
1.273 + // log to file ONLY
1.274 + iLogMode = ELogToFile;
1.275 + break;
1.276 + case 'P':
1.277 + case 'p':
1.278 + // log to port AS WELL AS to console / file
1.279 + iLogMode |= ELogToPort;
1.280 + break;
1.281 + //This stops the emulator from thowing int 3 if a panic occurs in debug builds
1.282 + case 'T':
1.283 + case 't':
1.284 + User::SetJustInTime(EFalse);
1.285 + // -S flag removed - was for old Unit Test mode only
1.286 + // -A 'automated mode' removed - it's always automated
1.287 + break;
1.288 + case 'G':
1.289 + case 'g':
1.290 + {
1.291 + // ** guard timer override - get numeric value that follows
1.292 + TPtrC val = &token[2];
1.293 + TLex lexTimeOut(val);
1.294 + if (lexTimeOut.Val(iGuardTimer) != KErrNone)
1.295 + UsageL();
1.296 + }
1.297 + break;
1.298 + case 'm':
1.299 + case 'M':
1.300 + {
1.301 + if (token.Length()<=2)
1.302 + {
1.303 + // only -m found. must be -m<arg> with no space
1.304 + UsageL();
1.305 + }
1.306 + TPtrC restOfLine = &token[2]; // this will be rest of command line
1.307 + TLex argument(restOfLine);
1.308 + TPtrC matchString = argument.NextToken(); // will be the argument itself
1.309 + ASSERT(matchString.Length()>1);
1.310 + iTestMatchString = matchString;
1.311 + }
1.312 + break;
1.313 + case 'Q':
1.314 + case 'q':
1.315 + {
1.316 + // This flag has been removed. This block is just to ensure that if used it wont panic
1.317 + }
1.318 + break;
1.319 +
1.320 + default:
1.321 + UsageL();
1.322 + return;
1.323 + }
1.324 +
1.325 + token.Set(lex.NextToken());
1.326 + }
1.327 +
1.328 + // save the input filename
1.329 + CFileName* scriptFileName = CFileName::NewLC();
1.330 + *scriptFileName = token;
1.331 +
1.332 + // make the log file name from the script file name
1.333 + CFileName* logFileName = CFileName::NewLC();
1.334 + *logFileName = token;
1.335 + RDebug::Print(_L("TestFrameWorkMain.cpp: RunTestScriptL 1"));
1.336 + // open the log file
1.337 + iLogClient->OpenLogFileL(logFileName->FileName(), iLogMode);
1.338 + RDebug::Print(_L("TestFrameWorkMain.cpp: RunTestScriptL 2"));
1.339 + iLogClient->LogExtra(__FILE8__, __LINE__, ESevrInfo,
1.340 + KTxtFrameworkStarting, &KTxtVersion(), &KTxtTarget(), &KTxtBuild());
1.341 + RDebug::Print(_L("TestFrameWorkMain.cpp: RunTestScriptL 3"));
1.342 + // create a ParseScript object
1.343 + CScript* parseScript = CScript::NewLC(iTestUtils,
1.344 + iLogClient,
1.345 + iGuardTimer,
1.346 + iTestMatchString);
1.347 + RDebug::Print(_L("TestFrameWorkMain.cpp: RunTestScriptL 4"));
1.348 + // parse all scripts
1.349 + do
1.350 + {
1.351 + // get the next file
1.352 + *scriptFileName = token;
1.353 +
1.354 + // read in the script file
1.355 + if ( parseScript->OpenScriptFile(scriptFileName))
1.356 + {
1.357 + // process it
1.358 + parseScript->ExecuteScriptL();
1.359 + // display results summary
1.360 + parseScript->DisplayResults();
1.361 + }
1.362 + // get the next
1.363 + token.Set(lex.NextToken());
1.364 + } while ( token.Length()!=0 );
1.365 + RDebug::Print(_L("TestFrameWorkMain.cpp: RunTestScriptL 5"));
1.366 + CleanupStack::PopAndDestroy(parseScript);
1.367 +
1.368 + // close the logging system
1.369 + iLogClient->CloseLogFile();
1.370 +
1.371 + CleanupStack::PopAndDestroy(logFileName);
1.372 + CleanupStack::PopAndDestroy(scriptFileName);
1.373 + }
1.374 + }
1.375 +
1.376 +/**
1.377 + *
1.378 + * Display command line format.
1.379 + *
1.380 + * @xxxx
1.381 + *
1.382 + */
1.383 +void CTestFrameworkMain::UsageL()
1.384 + {
1.385 + // If command line is erroneous, raise a panic.
1.386 + // At this point, there may be no log outputs at all.
1.387 + User::Panic(_L("TestFramework"), 2);
1.388 + }