1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/egl/egltest/endpointtestsuite/automated/src/remotetestbase.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,700 @@
1.4 +// Copyright (c) 2009-2010 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 +
1.17 +/**
1.18 + @file
1.19 + @test
1.20 + @internalComponent - Internal Symbian test code
1.21 +*/
1.22 +
1.23 +
1.24 +/*
1.25 + * This file contains the parts of CRemoteTestEnv and CRemoteTestStepBase
1.26 + * that do not need editting when adding new tests.
1.27 + *
1.28 + * CRemoteTestEnv acts as the controller. It provides the means of communicating
1.29 + * with the local side and it instantiates remote test steps and executes them in
1.30 + * their own thread. It monitors this thread for panic / timeout. If this
1.31 + * happens, it informs the local side.
1.32 + */
1.33 +
1.34 +
1.35 +#include "remotetestbase.h"
1.36 +#include <e32debug.h>
1.37 +#include <e32math.h>
1.38 +
1.39 +
1.40 +// Default timout for remote test steps. This MUST be smaller
1.41 +// than any timeout passed to TEF for the local test step
1.42 +// in the script file. Remote test steps can override this
1.43 +// value by implementing the Timeout() function in their
1.44 +// derrived class.
1.45 +const TInt KRemoteTestStepTimeout = 10 * 1000000;
1.46 +
1.47 +
1.48 +//Active object used to generate a timeout if worker thread takes too long. ------
1.49 +
1.50 +CTimeoutTimer* CTimeoutTimer::NewL(CRemoteTestEnv& aEnv, TInt aPriority)
1.51 + {
1.52 + CTimeoutTimer* obj = new (ELeave) CTimeoutTimer(aEnv, aPriority);
1.53 + CleanupStack::PushL(obj);
1.54 + obj->ConstructL();
1.55 + CleanupStack::Pop(obj);
1.56 + return obj;
1.57 + }
1.58 +
1.59 +
1.60 +CTimeoutTimer::CTimeoutTimer(CRemoteTestEnv& aEnv, TInt aPriority) :
1.61 + CTimer(aPriority),
1.62 + iEnv(aEnv)
1.63 + {
1.64 + }
1.65 +
1.66 +
1.67 +void CTimeoutTimer::ConstructL()
1.68 + {
1.69 + CTimer::ConstructL();
1.70 + CActiveScheduler::Add(this);
1.71 + }
1.72 +
1.73 +
1.74 +CTimeoutTimer::~CTimeoutTimer()
1.75 + {
1.76 + Cancel();
1.77 + }
1.78 +
1.79 +
1.80 +void CTimeoutTimer::RunL()
1.81 + {
1.82 + ENDPOINT_ASSERT_DEBUG(iStatus.Int() == KErrNone, User::Invariant());
1.83 + iEnv.TestCaseTimedOut();
1.84 + }
1.85 +
1.86 +//--------------------------------------------------------------------------------
1.87 +
1.88 +
1.89 +//Active object used to listen to the worker thread to see if it panics. ---------
1.90 +
1.91 +CWorkerListener* CWorkerListener::NewL(CRemoteTestEnv& aEnv, TInt aPriority)
1.92 + {
1.93 + CWorkerListener* obj = new (ELeave) CWorkerListener(aEnv, aPriority);
1.94 + CleanupStack::PushL(obj);
1.95 + obj->ConstructL();
1.96 + CleanupStack::Pop(obj);
1.97 + return obj;
1.98 + }
1.99 +
1.100 +
1.101 +CWorkerListener::CWorkerListener(CRemoteTestEnv& aEnv, TInt aPriority) :
1.102 + CActive(aPriority),
1.103 + iEnv(aEnv)
1.104 + {
1.105 + }
1.106 +
1.107 +
1.108 +CWorkerListener::~CWorkerListener()
1.109 + {
1.110 + Cancel();
1.111 + }
1.112 +
1.113 +
1.114 +void CWorkerListener::ConstructL()
1.115 + {
1.116 + CActiveScheduler::Add(this);
1.117 + }
1.118 +
1.119 +
1.120 +void CWorkerListener::Listen(RThread& aThread)
1.121 + {
1.122 + ENDPOINT_ASSERT_DEBUG(!IsActive(), User::Invariant());
1.123 + iThread = &aThread;
1.124 + iThread->Logon(iStatus);
1.125 + SetActive();
1.126 + }
1.127 +
1.128 +
1.129 +void CWorkerListener::RunL()
1.130 + {
1.131 + iEnv.WorkerExitted();
1.132 + }
1.133 +
1.134 +
1.135 +void CWorkerListener::DoCancel()
1.136 + {
1.137 + iThread->LogonCancel(iStatus);
1.138 + }
1.139 +
1.140 +//--------------------------------------------------------------------------------
1.141 +
1.142 +
1.143 +//Active object used to listen for test case completion from the worker thread. --
1.144 +
1.145 +CTestCaseListener* CTestCaseListener::NewL(CRemoteTestEnv& aEnv, TInt aPriority)
1.146 + {
1.147 + CTestCaseListener* obj = new (ELeave) CTestCaseListener(aEnv, aPriority);
1.148 + CleanupStack::PushL(obj);
1.149 + obj->ConstructL();
1.150 + CleanupStack::Pop(obj);
1.151 + return obj;
1.152 + }
1.153 +
1.154 +
1.155 +CTestCaseListener::CTestCaseListener(CRemoteTestEnv& aEnv, TInt aPriority) :
1.156 + CActive(aPriority),
1.157 + iEnv(aEnv)
1.158 + {
1.159 + }
1.160 +
1.161 +
1.162 +CTestCaseListener::~CTestCaseListener()
1.163 + {
1.164 + Cancel();
1.165 + }
1.166 +
1.167 +
1.168 +void CTestCaseListener::ConstructL()
1.169 + {
1.170 + CActiveScheduler::Add(this);
1.171 + }
1.172 +
1.173 +
1.174 +void CTestCaseListener::Listen()
1.175 + {
1.176 + ENDPOINT_ASSERT_DEBUG(!IsActive(), User::Invariant());
1.177 + iStatus = KRequestPending;
1.178 + SetActive();
1.179 + }
1.180 +
1.181 +
1.182 +void CTestCaseListener::RunL()
1.183 + {
1.184 + ENDPOINT_ASSERT_DEBUG(iStatus.Int() == KErrNone, User::Invariant());
1.185 + iEnv.TestCaseCompleted();
1.186 + }
1.187 +
1.188 +
1.189 +void CTestCaseListener::DoCancel()
1.190 + {
1.191 + //There is no way to actually cancel a test case,
1.192 + //But this AO will only be cancelled when the thread
1.193 + //has panicked or timed out - which is as good as a
1.194 + //cancel. We still need to call canel on the AO though
1.195 + //to set it as inactive.
1.196 +
1.197 + //Also need to do a request complete if the worker has not already
1.198 + //done it. There is no danger of the worker completing between our
1.199 + //check (the if) and actually completing because the worker is dead.
1.200 + if(iStatus.Int() == KRequestPending)
1.201 + {
1.202 + TRequestStatus* myStatus = &iStatus;
1.203 + User::RequestComplete(myStatus, KErrCancel);
1.204 + }
1.205 + }
1.206 +
1.207 +//--------------------------------------------------------------------------------
1.208 +
1.209 +
1.210 +//CRemoteTestEnv -----------------------------------------------------------------
1.211 +
1.212 +CRemoteTestEnv* CRemoteTestEnv::NewL()
1.213 + {
1.214 + CRemoteTestEnv* obj = new (ELeave) CRemoteTestEnv();
1.215 + CleanupStack::PushL(obj);
1.216 + obj->ConstructL();
1.217 + CleanupStack::Pop(obj);
1.218 + return obj;
1.219 + }
1.220 +
1.221 +
1.222 +CRemoteTestEnv::CRemoteTestEnv() :
1.223 + CActive(CActive::EPriorityStandard)
1.224 + {
1.225 + }
1.226 +
1.227 +
1.228 +void CRemoteTestEnv::ConstructL()
1.229 + {
1.230 + //Create the message queues.
1.231 + User::LeaveIfError(iResultOutQueue.CreateGlobal(KResultQueueName, 5));
1.232 + User::LeaveIfError(iParamsInQueue.CreateGlobal(KParamsQueueName, 1));
1.233 +
1.234 + iSupervisorId = RThread().Id();
1.235 +
1.236 + //Create AOs that monitor for events.
1.237 + //These priorities are important, since if, for example, the worker
1.238 + //thread exits by returning from the thread entrypoint after
1.239 + //successfully completing the EndTestStep() case, but before the
1.240 + //supervisor runs, the supervisor's AS will find that both iWorkerListener
1.241 + //and iTestCaseListener have completed. We use the priorities to determine
1.242 + //which signal to run first. (The one we run will cancel the others).
1.243 + iTimeoutTimer = CTimeoutTimer::NewL(*this, CActive::EPriorityLow);
1.244 + iWorkerListener = CWorkerListener::NewL(*this, CActive::EPriorityStandard);
1.245 + iTestCaseListener = CTestCaseListener::NewL(*this, CActive::EPriorityHigh);
1.246 +
1.247 + //Add self to active scheduler.
1.248 + CActiveScheduler::Add(this);
1.249 + }
1.250 +
1.251 +
1.252 +CRemoteTestEnv::~CRemoteTestEnv()
1.253 + {
1.254 + Cancel();
1.255 + delete iTimeoutTimer;
1.256 + delete iWorkerListener;
1.257 + delete iTestCaseListener;
1.258 + iParamsInQueue.Close();
1.259 + iResultOutQueue.Close();
1.260 + }
1.261 +
1.262 +
1.263 +void CRemoteTestEnv::StartReceivingCmds()
1.264 + {
1.265 + ReceiveCmd();
1.266 + CActiveScheduler::Start();
1.267 + }
1.268 +
1.269 +
1.270 +void CRemoteTestEnv::ReceiveCmd()
1.271 + {
1.272 + ENDPOINT_ASSERT_DEBUG(!IsActive(), User::Invariant());
1.273 + iParamsInQueue.NotifyDataAvailable(iStatus);
1.274 + SetActive();
1.275 + }
1.276 +
1.277 +
1.278 +//This is run when an packet arrives in the queue from the local side.
1.279 +//It is not rearmed until the test step has run to completion.
1.280 +void CRemoteTestEnv::RunL()
1.281 + {
1.282 + //Retrieve the packet from the queue.
1.283 + TInt err = iParamsInQueue.Receive(iCurTestCaseParamsPacket);
1.284 + ENDPOINT_ASSERT_DEBUG(err == KErrNone, User::Invariant());
1.285 +
1.286 + //Create the appropriate TestStep and launch thread if this is a "StartTestStep".
1.287 + if(iCurTestCaseParamsPacket.iTestCase == KStartTestStepCaseNumber)
1.288 + {
1.289 + //At this point in a well behaved system, iCurTestStep must be NULL.
1.290 + //If it is not, comms has gone wrong (most likely the local side has
1.291 + //panicked midway through the test step). If iCurTestStep is not NULL
1.292 + //we can also guarantee that the thread is still running. Recover
1.293 + //from this by getting the thread to do some special teardown,
1.294 + //followed by tidying up in this thread.
1.295 + if(iCurTestStep)
1.296 + {
1.297 + //Logon to worker then signal to abort the test case
1.298 + //and wait for completion.
1.299 + TRequestStatus threadStat;
1.300 + iCurWorker.Logon(threadStat);
1.301 + TRequestStatus* notifyRunTestCase = &iNotifyRunTestCase;
1.302 + iCurWorker.RequestComplete(notifyRunTestCase, KErrAbort);
1.303 + User::WaitForRequest(threadStat);
1.304 +
1.305 + //Tidy up.
1.306 + iCurWorker.Close();
1.307 + delete iCurTestStep;
1.308 + iCurTestStep = NULL;
1.309 + }
1.310 +
1.311 + TBool result = SetupTestStep();
1.312 +
1.313 + //If we failed to setup the test step (invalid uid),
1.314 + //just register for another command and return.
1.315 + if(!result)
1.316 + {
1.317 + //Register to receive another packet from the message queue.
1.318 + ReceiveCmd();
1.319 + return;
1.320 + }
1.321 + }
1.322 +
1.323 + //Activate the TimoutTimer, TestCaseListener and WorkerListener.
1.324 + iTimeoutTimer->After(iCurTestStep->Timeout());
1.325 + iTestCaseListener->Listen();
1.326 + iWorkerListener->Listen(iCurWorker);
1.327 +
1.328 + //Signal the worker thread to start a test case.
1.329 + TRequestStatus* notifyRunTestCase = &iNotifyRunTestCase;
1.330 + iCurWorker.RequestComplete(notifyRunTestCase, KErrNone);
1.331 + }
1.332 +
1.333 +
1.334 +void CRemoteTestEnv::DoCancel()
1.335 + {
1.336 + iParamsInQueue.CancelDataAvailable();
1.337 + }
1.338 +
1.339 +
1.340 +//The test case can end in three ways:
1.341 +// 1. Test Case compeletes normally (this includes failing).
1.342 +// 2. The Test Case times out (in which case the thread is panicked).
1.343 +// 3. The Test Case panics the worker thread.
1.344 +//Three AOs listen for each of these possibilities and one of the functions below.
1.345 +
1.346 +
1.347 +//This is called for case 1.
1.348 +void CRemoteTestEnv::TestCaseCompleted()
1.349 + {
1.350 + //Cancel the TimeoutTimer and WorkerListener.
1.351 + iTimeoutTimer->Cancel();
1.352 + iWorkerListener->Cancel();
1.353 +
1.354 + //Test case completed correctly, so send test result.
1.355 + SendResult(iCurTestCaseVerdict);
1.356 +
1.357 + //Tidy up if this is the end of the test step.
1.358 + if(iCurTestCaseParamsPacket.iTestCase == KEndTestStepCaseNumber)
1.359 + {
1.360 + iCurWorker.Close();
1.361 + delete iCurTestStep;
1.362 + iCurTestStep = NULL;
1.363 + }
1.364 +
1.365 + //Register to receive another packet from the message queue.
1.366 + ReceiveCmd();
1.367 + }
1.368 +
1.369 +
1.370 +//This is called for case 2.
1.371 +void CRemoteTestEnv::TestCaseTimedOut()
1.372 + {
1.373 + //Cancel the TestCaseListener and WorkerListener.
1.374 + iTestCaseListener->Cancel();
1.375 + iWorkerListener->Cancel();
1.376 +
1.377 + //Thread timed out so log that it timed out and send the ERtvTimeout result.
1.378 + iCurTestStep->REMOTE_ERR_PRINTF1(_L("Remote test step timed out."));
1.379 + SendResult(ERtvTimeout);
1.380 +
1.381 + //Tidy up. Because we timed out, we abandon the test step, so
1.382 + //kill the thread and release even if this was not an EndTestStep
1.383 + iCurWorker.Kill(KErrTimedOut);
1.384 + iCurWorker.Close();
1.385 + delete iCurTestStep;
1.386 + iCurTestStep = NULL;
1.387 +
1.388 + //Register to receive another packet from the message queue.
1.389 + ReceiveCmd();
1.390 + }
1.391 +
1.392 +
1.393 +//This is called for case 3.
1.394 +void CRemoteTestEnv::WorkerExitted()
1.395 + {
1.396 + //Cancel the TimeoutTimer and TestCaseListener.
1.397 + iTimeoutTimer->Cancel();
1.398 + iTestCaseListener->Cancel();
1.399 +
1.400 + //Even if we were running a EndTestStep (ie the thread will exit normally), TestCaseListener should still
1.401 + //fire first, and it will cancel the WorkerListener - so we know that if we get here, it is because the
1.402 + //thread exitted abnormally.
1.403 +
1.404 + //Thread was panicked, so log the panic category before sending the ERtvPanic result.
1.405 + TExitCategoryName exitCategory = iCurWorker.ExitCategory();
1.406 + iCurTestStep->REMOTE_ERR_PRINTF3(_L("Remote test step panicked with: %S, code = %d."), &exitCategory, iCurWorker.ExitReason());
1.407 + SendResult(ERtvPanic);
1.408 +
1.409 + //Tidy up. Because we panicked, we abandon the test step, so
1.410 + //release resources even if this was not an EndTestStep
1.411 + iCurWorker.Close();
1.412 + delete iCurTestStep;
1.413 + iCurTestStep = NULL;
1.414 +
1.415 + //Register to receive another packet from the message queue.
1.416 + ReceiveCmd();
1.417 + }
1.418 +
1.419 +
1.420 +TBool CRemoteTestEnv::SetupTestStep()
1.421 + {
1.422 + //Set the TRequestStatus that the worker thread triggers off for the first time.
1.423 + //After this, the worker thread will set it back to KRequestPending itself.
1.424 + iNotifyRunTestCase = KRequestPending;
1.425 +
1.426 + //Create TestStep
1.427 + TRAPD(err, iCurTestStep = CreateRemoteTestStepL(iCurTestCaseParamsPacket.iUid));
1.428 + if(err == KErrUnknown)
1.429 + {
1.430 + //Unknown test step. Tell the driver app.
1.431 + SendResult(ERtvUnknownTestUid);
1.432 + return EFalse;
1.433 + }
1.434 + else if(err != KErrNone || !iCurTestStep)
1.435 + {
1.436 + User::Invariant();
1.437 + }
1.438 +
1.439 + //Construct the test step base class.
1.440 + TRAP(err, iCurTestStep->ConstructL(*this));
1.441 + __ASSERT_ALWAYS(err == KErrNone, User::Invariant());
1.442 +
1.443 + //Create Test Thread.
1.444 + static const TInt KStackSize = 0x2000; // 8KB
1.445 + static const TInt KHeapMinSize = 0x1000; // 4KB
1.446 + static const TInt KHeapMaxSize = 0x1000000; // 16MB
1.447 + TUint32 random = Math::Random();
1.448 + TName threadName;
1.449 + _LIT(KThreadNameFormat, "%S-%u");
1.450 + _LIT(KExecName, "EpTestRemoteExec");
1.451 + threadName.Format(KThreadNameFormat, &KExecName, random);
1.452 + err = iCurWorker.Create(threadName, TestThreadEntryPoint, KStackSize, KHeapMinSize, KHeapMaxSize, this);
1.453 + __ASSERT_ALWAYS(err == KErrNone, User::Invariant());
1.454 +
1.455 + //Start the test thread.
1.456 + iCurWorker.Resume();
1.457 +
1.458 + return ETrue;
1.459 + }
1.460 +
1.461 +
1.462 +// The DoEglHeapMark and DoEglHeapCheck are intended to make sure memory
1.463 +// allocations are freed when the testing is complete. The current
1.464 +// implementation only supports the Symbian/Nokia reference implementation.
1.465 +// An implementor of another EGL implementation is free to add their own
1.466 +// variant of heapchecking here, with suitable #if around it.
1.467 +// The function in egl should call __DbgMarkStart() and __DbgMarkEnd()
1.468 +// on the heap for the egl implementation - or the equivalent if the
1.469 +// heap is not a typical Symbian heap.
1.470 +void CRemoteTestEnv::DoEglHeapMark()
1.471 + {
1.472 +#if USE_EGLHEAP_CHECKING
1.473 + typedef void (*TEglDebugHeapMarkStartPtr)();
1.474 +
1.475 + TEglDebugHeapMarkStartPtr heapMarkStart = reinterpret_cast<TEglDebugHeapMarkStartPtr>(eglGetProcAddress("egliDebugHeapMarkStart"));
1.476 + if (heapMarkStart)
1.477 + {
1.478 + heapMarkStart();
1.479 + }
1.480 +#endif
1.481 + }
1.482 +
1.483 +void CRemoteTestEnv::DoEglHeapCheck()
1.484 + {
1.485 +#if USE_EGLHEAP_CHECKING
1.486 + typedef EGLint (*TEglDebugHeapMarkEndPtr)(EGLint count);
1.487 +
1.488 + TEglDebugHeapMarkEndPtr heapMarkEnd = reinterpret_cast<TEglDebugHeapMarkEndPtr>(eglGetProcAddress("egliDebugHeapMarkEnd"));
1.489 + if (heapMarkEnd)
1.490 + {
1.491 + (void)heapMarkEnd(0);
1.492 + }
1.493 +#endif
1.494 + }
1.495 +
1.496 +#define __EGLHEAP_MARK DoEglHeapMark()
1.497 +#define __EGLHEAP_MARKEND DoEglHeapCheck()
1.498 +
1.499 +
1.500 +void CRemoteTestEnv::RunCurrentTestStepL()
1.501 + {
1.502 + TInt processHandleMarkDummy;
1.503 + TInt threadHandleMarkStart;
1.504 + TInt threadHandleMarkEnd;
1.505 + TBool finished = EFalse;
1.506 +
1.507 + while(!finished)
1.508 + {
1.509 + //Wait to be signalled to run a test case.
1.510 + User::WaitForRequest(iNotifyRunTestCase);
1.511 +
1.512 + //We are aborting the test step. Tidy up EGL and exit.
1.513 + if(iNotifyRunTestCase.Int() == KErrAbort)
1.514 + {
1.515 + iCurTestStep->EglEndL();
1.516 + iNotifyRunTestCase = KRequestPending;
1.517 + return;
1.518 + }
1.519 +
1.520 + //Rearm the TRequestStatus (The first arming is done in the supervisor thread).
1.521 + iNotifyRunTestCase = KRequestPending;
1.522 +
1.523 + //Run the test case and panic if it leaves. Start/End are just special test cases.
1.524 + if(iCurTestCaseParamsPacket.iTestCase == KStartTestStepCaseNumber)
1.525 + {
1.526 + //Mark the user heap & thread handle count (we don't care about the process handle count).
1.527 + RThread().HandleCount(processHandleMarkDummy, threadHandleMarkStart);
1.528 + __UHEAP_MARK;
1.529 + __EGLHEAP_MARK;
1.530 +
1.531 + //StartRemoteTest.
1.532 + TRAPD(err, iCurTestCaseVerdict = iCurTestStep->DoStartRemoteTestStepL(iCurTestCaseParamsPacket.iParams));
1.533 + __ASSERT_ALWAYS(err == KErrNone, User::Panic(_L("tried to leave."), __LINE__));
1.534 + }
1.535 + else if(iCurTestCaseParamsPacket.iTestCase == KEndTestStepCaseNumber)
1.536 + {
1.537 + //EndRemoteTest.
1.538 + TRAPD(err, iCurTestCaseVerdict = iCurTestStep->DoEndRemoteTestStepL(iCurTestCaseParamsPacket.iParams));
1.539 + __ASSERT_ALWAYS(err == KErrNone, User::Panic(_L("tried to leave."), __LINE__));
1.540 +
1.541 + //This will cause a panic if the test step leaked memory or thread handles.
1.542 + __UHEAP_MARKEND;
1.543 + __EGLHEAP_MARKEND;
1.544 + RThread().HandleCount(processHandleMarkDummy, threadHandleMarkEnd);
1.545 + __ASSERT_ALWAYS(threadHandleMarkStart == threadHandleMarkEnd, User::Panic(_L("leaked handles."), KErrBadHandle));
1.546 +
1.547 + //Exit the loop (and eventually the thread).
1.548 + finished = ETrue;
1.549 + }
1.550 + else
1.551 + {
1.552 + //Run a regular Test Case.
1.553 + TRAPD(err, iCurTestCaseVerdict = iCurTestStep->DoRunRemoteTestCaseL(iCurTestCaseParamsPacket.iTestCase, iCurTestCaseParamsPacket.iParams));
1.554 + __ASSERT_ALWAYS(err == KErrNone, User::Panic(_L("tried to leave."), __LINE__));
1.555 + }
1.556 +
1.557 + //Notify the supervisor that we have completed the test case.
1.558 + RThread supervisor;
1.559 + TInt err = supervisor.Open(iSupervisorId);
1.560 + __ASSERT_ALWAYS(err == KErrNone, User::Panic(_L("framework error."), __LINE__));
1.561 + TRequestStatus* notifyFinishTestCase = &iTestCaseListener->iStatus;
1.562 + supervisor.RequestComplete(notifyFinishTestCase, KErrNone);
1.563 + supervisor.Close();
1.564 + }
1.565 + }
1.566 +
1.567 +
1.568 +TInt CRemoteTestEnv::TestThreadEntryPoint(TAny* aSelf)
1.569 + {
1.570 + CRemoteTestEnv* self = static_cast<CRemoteTestEnv*>(aSelf);
1.571 +
1.572 + //Create cleanup stack.
1.573 + CTrapCleanup* cleanup = CTrapCleanup::New();
1.574 + ASSERT(cleanup);
1.575 +
1.576 + //Create active scheduler.
1.577 + CActiveScheduler* scheduler = new CActiveScheduler();
1.578 + ASSERT(scheduler);
1.579 + CActiveScheduler::Install(scheduler);
1.580 +
1.581 + TRAPD(err, self->RunCurrentTestStepL());
1.582 + __ASSERT_ALWAYS(err == KErrNone, User::Invariant());
1.583 +
1.584 + //Clean up.
1.585 + delete scheduler;
1.586 + delete cleanup;
1.587 + return KErrNone;
1.588 + }
1.589 +
1.590 +
1.591 +void CRemoteTestEnv::SendResult(TRemoteTestVerdict aVerdict)
1.592 + {
1.593 + iResultOutQueue.SendBlocking(TRemoteTestResult(iCurTestCaseParamsPacket.iUid, iCurTestCaseParamsPacket.iTestCase, aVerdict));
1.594 + }
1.595 +
1.596 +
1.597 +void CRemoteTestEnv::SendLog(const TDesC8& aFile, TInt aLine, TInt aSeverity, const TDesC& aMessage)
1.598 + {
1.599 + iResultOutQueue.SendBlocking(TRemoteTestResult(iCurTestCaseParamsPacket.iUid, iCurTestCaseParamsPacket.iTestCase, aFile, aLine, aSeverity, aMessage));
1.600 + }
1.601 +
1.602 +//--------------------------------------------------------------------------------
1.603 +
1.604 +
1.605 +//CRemoteTestStepBase ------------------------------------------------------------
1.606 +
1.607 +CRemoteTestStepBase::CRemoteTestStepBase(TTestUid aUid) :
1.608 + iUid(aUid)
1.609 + {
1.610 + }
1.611 +
1.612 +
1.613 +void CRemoteTestStepBase::ConstructL(CRemoteTestEnv& aTestEnv)
1.614 + {
1.615 + iTestEnv = &aTestEnv;
1.616 + if (iEndpoint.Error() != KErrNone)
1.617 + {
1.618 + RDebug::Printf("Could not construct CRemoteTestStepBase"
1.619 + " - is EglEndpointNOK enabled?? -- Error: %d", iEndpoint.Error());
1.620 + User::Leave(iEndpoint.Error());
1.621 + }
1.622 + }
1.623 +
1.624 +
1.625 +CRemoteTestStepBase::~CRemoteTestStepBase()
1.626 + {
1.627 + }
1.628 +
1.629 +
1.630 +TRemoteTestVerdict CRemoteTestStepBase::DoStartRemoteTestStepL(const TRemoteTestParams& /*aMessageIn*/)
1.631 + {
1.632 + //Default implementation does nothing.
1.633 + return ERtvPass;
1.634 + }
1.635 +
1.636 +
1.637 +TRemoteTestVerdict CRemoteTestStepBase::DoEndRemoteTestStepL(const TRemoteTestParams& /*aMessageIn*/)
1.638 + {
1.639 + //Default implementation does nothing.
1.640 + return ERtvPass;
1.641 + }
1.642 +
1.643 +
1.644 +TInt CRemoteTestStepBase::Timeout() const
1.645 + {
1.646 + return KRemoteTestStepTimeout;
1.647 + }
1.648 +
1.649 +
1.650 +class TOverflowTruncate : public TDesOverflow
1.651 + {
1.652 +public:
1.653 + virtual void Overflow(TDes& /*aDes*/)
1.654 + {
1.655 + //Do nothing - just let it truncate.
1.656 + }
1.657 + };
1.658 +
1.659 +
1.660 +void CRemoteTestStepBase::Log(const TText8* aFile, TInt aLine, TInt aSeverity, TRefByValue<const TDesC> aFmt, ...)
1.661 + {
1.662 + if(iTestEnv)
1.663 + {
1.664 + TOverflowTruncate overflow;
1.665 + VA_LIST list;
1.666 + VA_START(list, aFmt);
1.667 + TBuf<0x100> buf;
1.668 + buf.AppendFormatList(aFmt, list, &overflow);
1.669 + TPtrC8 file(aFile);
1.670 + iTestEnv->SendLog(file, aLine, aSeverity, buf);
1.671 + }
1.672 + }
1.673 +
1.674 +
1.675 +void CRemoteTestStepBase::EglStartL()
1.676 + {
1.677 + eglInitialize(eglGetDisplay(EGL_DEFAULT_DISPLAY), NULL, NULL);
1.678 + if (eglGetError()!=EGL_SUCCESS)
1.679 + {
1.680 + REMOTE_INFO_PRINTF1(_L("could not initialise egl"));
1.681 + User::Leave(KErrGeneral);
1.682 + }
1.683 + }
1.684 +
1.685 +
1.686 +void CRemoteTestStepBase::EglEndL()
1.687 + {
1.688 + eglTerminate(eglGetDisplay(EGL_DEFAULT_DISPLAY));
1.689 + if (eglGetError()!=EGL_SUCCESS)
1.690 + {
1.691 + REMOTE_INFO_PRINTF1(_L("could not terminate egl"));
1.692 + User::Leave(KErrGeneral);
1.693 + }
1.694 + eglReleaseThread();
1.695 + }
1.696 +
1.697 +
1.698 +const TEglEndpointWrap& CRemoteTestStepBase::EglEndpoint() const
1.699 + {
1.700 + return iEndpoint;
1.701 + }
1.702 +
1.703 +//--------------------------------------------------------------------------------