sl@0: // Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: sl@0: sl@0: /** sl@0: @file sl@0: @test sl@0: @internalComponent - Internal Symbian test code sl@0: */ sl@0: sl@0: sl@0: #ifndef __REMOTETESTBASE_H__ sl@0: #define __REMOTETESTBASE_H__ sl@0: sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include "eglendpointwrap.h" sl@0: #include "egltest_commscommon.h" sl@0: sl@0: sl@0: class CRemoteTestStepBase; sl@0: class CRemoteTestEnv; sl@0: sl@0: sl@0: //Active object used to generate a timeout if worker thread takes too long. sl@0: class CTimeoutTimer : public CTimer sl@0: { sl@0: public: sl@0: static CTimeoutTimer* NewL(CRemoteTestEnv& aEnv, TInt aPriority); sl@0: ~CTimeoutTimer(); sl@0: sl@0: private: sl@0: CTimeoutTimer(CRemoteTestEnv& aEnv, TInt aPriority); sl@0: void ConstructL(); sl@0: void RunL(); sl@0: sl@0: private: sl@0: CRemoteTestEnv& iEnv; sl@0: }; sl@0: sl@0: sl@0: //Active object used to listen to the worker thread to see if it panics. sl@0: class CWorkerListener : public CActive sl@0: { sl@0: public: sl@0: static CWorkerListener* NewL(CRemoteTestEnv& aEnv, TInt aPriority); sl@0: ~CWorkerListener(); sl@0: void Listen(RThread& aThread); sl@0: sl@0: private: sl@0: CWorkerListener(CRemoteTestEnv& aEnv, TInt aPriority); sl@0: void ConstructL(); sl@0: void RunL(); sl@0: void DoCancel(); sl@0: sl@0: private: sl@0: CRemoteTestEnv& iEnv; sl@0: RThread* iThread; sl@0: }; sl@0: sl@0: sl@0: //Active object used to listen for test case completion from the worker thread. sl@0: class CTestCaseListener : public CActive sl@0: { sl@0: public: sl@0: static CTestCaseListener* NewL(CRemoteTestEnv& aEnv, TInt aPriority); sl@0: ~CTestCaseListener(); sl@0: void Listen(); sl@0: sl@0: private: sl@0: CTestCaseListener(CRemoteTestEnv& aEnv, TInt aPriority); sl@0: void ConstructL(); sl@0: void RunL(); sl@0: void DoCancel(); sl@0: sl@0: private: sl@0: CRemoteTestEnv& iEnv; sl@0: }; sl@0: sl@0: sl@0: //This class provides the remote test environment. CreateRemoteTestStepL() sl@0: //Should be edited to return an instance of a derived CRemoteTestStepBase sl@0: //class that corresponds with the passed in aTestUid. sl@0: class CRemoteTestEnv : public CActive sl@0: { sl@0: public: sl@0: static CRemoteTestEnv* NewL(); sl@0: virtual ~CRemoteTestEnv(); sl@0: sl@0: void StartReceivingCmds(); sl@0: CRemoteTestStepBase* CreateRemoteTestStepL(TTestUid aTestUid); sl@0: sl@0: void SendResult(TRemoteTestVerdict aVerdict); sl@0: void SendLog(const TDesC8& aFile, TInt aLine, TInt aSeverity, const TDesC& aMessage); sl@0: sl@0: void TestCaseCompleted(); sl@0: void TestCaseTimedOut(); sl@0: void WorkerExitted(); sl@0: sl@0: protected: sl@0: CRemoteTestEnv(); sl@0: void ConstructL(); sl@0: sl@0: private: sl@0: void RunL(); sl@0: void DoCancel(); sl@0: sl@0: void ReceiveCmd(); sl@0: TBool SetupTestStep(); sl@0: sl@0: //These functions run in the context of the worker thread. sl@0: void RunCurrentTestStepL(); sl@0: static TInt TestThreadEntryPoint(TAny* aSelf); sl@0: sl@0: void DoEglHeapMark(); sl@0: void DoEglHeapCheck(); sl@0: sl@0: private: sl@0: RMsgQueue iResultOutQueue; sl@0: RMsgQueue iParamsInQueue; sl@0: sl@0: CRemoteTestStepBase* iCurTestStep; sl@0: TRemoteTestParamsPacket iCurTestCaseParamsPacket; sl@0: TRemoteTestVerdict iCurTestCaseVerdict; sl@0: RThread iCurWorker; sl@0: sl@0: TThreadId iSupervisorId; sl@0: TRequestStatus iNotifyRunTestCase; sl@0: sl@0: CTimeoutTimer* iTimeoutTimer; sl@0: CWorkerListener* iWorkerListener; sl@0: CTestCaseListener* iTestCaseListener; sl@0: }; sl@0: sl@0: sl@0: //This is the base class for all remote test steps. Derived classes should implement sl@0: //DoRemoteTestStepL(), and return the result of the test as a TVerdict. sl@0: class CRemoteTestStepBase : public CBase, public MLog sl@0: { sl@0: public: sl@0: virtual ~CRemoteTestStepBase(); sl@0: sl@0: virtual TRemoteTestVerdict DoStartRemoteTestStepL(const TRemoteTestParams& aMessageIn); sl@0: virtual TRemoteTestVerdict DoRunRemoteTestCaseL(TInt aTestCase, const TRemoteTestParams& aMessageIn) = 0; sl@0: virtual TRemoteTestVerdict DoEndRemoteTestStepL(const TRemoteTestParams& aMessageIn); sl@0: sl@0: virtual TInt Timeout() const; sl@0: sl@0: void Log(const TText8* aFile, TInt aLine, TInt aSeverity, TRefByValue aFmt, ...); sl@0: const TEglEndpointWrap& EglEndpoint() const; sl@0: sl@0: void EglStartL(); sl@0: void EglEndL(); sl@0: sl@0: protected: sl@0: CRemoteTestStepBase(TTestUid aUid); sl@0: sl@0: private: sl@0: friend class CRemoteTestEnv; sl@0: //Function called by CRemoteTestEnv. sl@0: //It should NOT be called by a derived class during construction. sl@0: void ConstructL(CRemoteTestEnv& aTestEnv); sl@0: sl@0: private: sl@0: const TTestUid iUid; sl@0: TInt iCurrentTestCase; sl@0: CRemoteTestEnv* iTestEnv; sl@0: TEglEndpointWrap iEndpoint; sl@0: }; sl@0: sl@0: sl@0: // Logger Macros - based on TEF but for use with CRemoteTestStepBase. sl@0: //The severity enumeration is from TEF. sl@0: #define REMOTE_INFO_PRINTF1(p1) Log(((TText8*)__FILE__), __LINE__, ESevrInfo, (p1)) sl@0: #define REMOTE_INFO_PRINTF2(p1, p2) Log(((TText8*)__FILE__), __LINE__, ESevrInfo, (p1), (p2)) sl@0: #define REMOTE_INFO_PRINTF3(p1, p2, p3) Log(((TText8*)__FILE__), __LINE__, ESevrInfo, (p1), (p2), (p3)) sl@0: #define REMOTE_INFO_PRINTF4(p1, p2, p3, p4) Log(((TText8*)__FILE__), __LINE__, ESevrInfo, (p1), (p2), (p3), (p4)) sl@0: #define REMOTE_INFO_PRINTF5(p1, p2, p3, p4, p5) Log(((TText8*)__FILE__), __LINE__, ESevrInfo, (p1), (p2), (p3), (p4), (p5)) sl@0: #define REMOTE_INFO_PRINTF6(p1, p2, p3, p4, p5, p6) Log(((TText8*)__FILE__), __LINE__, ESevrInfo, (p1), (p2), (p3), (p4), (p5), (p6)) sl@0: #define REMOTE_INFO_PRINTF7(p1, p2, p3, p4, p5, p6, p7) Log(((TText8*)__FILE__), __LINE__, ESevrInfo, (p1), (p2), (p3), (p4), (p5), (p6), (p7)) sl@0: sl@0: #define REMOTE_WARN_PRINTF1(p1) Log(((TText8*)__FILE__), __LINE__, ESevrWarn, (p1)) sl@0: #define REMOTE_WARN_PRINTF2(p1, p2) Log(((TText8*)__FILE__), __LINE__, ESevrWarn, (p1), (p2)) sl@0: #define REMOTE_WARN_PRINTF3(p1, p2, p3) Log(((TText8*)__FILE__), __LINE__, ESevrWarn, (p1), (p2), (p3)) sl@0: #define REMOTE_WARN_PRINTF4(p1, p2, p3, p4) Log(((TText8*)__FILE__), __LINE__, ESevrWarn, (p1), (p2), (p3), (p4)) sl@0: #define REMOTE_WARN_PRINTF5(p1, p2, p3, p4, p5) Log(((TText8*)__FILE__), __LINE__, ESevrWarn, (p1), (p2), (p3), (p4), (p5)) sl@0: #define REMOTE_WARN_PRINTF6(p1, p2, p3, p4, p5, p6) Log(((TText8*)__FILE__), __LINE__, ESevrWarn, (p1), (p2), (p3), (p4), (p5), (p6)) sl@0: #define REMOTE_WARN_PRINTF7(p1, p2, p3, p4, p5, p6, p7) Log(((TText8*)__FILE__), __LINE__, ESevrWarn, (p1), (p2), (p3), (p4), (p5), (p6), (p7)) sl@0: sl@0: #define REMOTE_ERR_PRINTF1(p1) Log(((TText8*)__FILE__), __LINE__, ESevrErr, (p1)) sl@0: #define REMOTE_ERR_PRINTF2(p1, p2) Log(((TText8*)__FILE__), __LINE__, ESevrErr, (p1), (p2)) sl@0: #define REMOTE_ERR_PRINTF3(p1, p2, p3) Log(((TText8*)__FILE__), __LINE__, ESevrErr, (p1), (p2), (p3)) sl@0: #define REMOTE_ERR_PRINTF4(p1, p2, p3, p4) Log(((TText8*)__FILE__), __LINE__, ESevrErr, (p1), (p2), (p3), (p4)) sl@0: #define REMOTE_ERR_PRINTF5(p1, p2, p3, p4, p5) Log(((TText8*)__FILE__), __LINE__, ESevrErr, (p1), (p2), (p3), (p4), (p5)) sl@0: #define REMOTE_ERR_PRINTF6(p1, p2, p3, p4, p5, p6) Log(((TText8*)__FILE__), __LINE__, ESevrErr, (p1), (p2), (p3), (p4), (p5), (p6)) sl@0: #define REMOTE_ERR_PRINTF7(p1, p2, p3, p4, p5, p6, p7) Log(((TText8*)__FILE__), __LINE__, ESevrErr, (p1), (p2), (p3), (p4), (p5), (p6), (p7)) sl@0: sl@0: sl@0: #endif