os/graphics/egl/egltest/endpointtestsuite/automated/tinc/egltest_endpoint_engine.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of "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 //
    15 
    16 /**
    17  @file
    18  @test
    19  @internalComponent - Internal Symbian test code
    20 */
    21 
    22 
    23 #ifndef __EGLTEST_ENDPOINT_ENGINE_H__
    24 #define __EGLTEST_ENDPOINT_ENGINE_H__
    25 
    26 #include "localtestbase.h"
    27 #include "remotetestbase.h"
    28 #include "egltest_surface.h"
    29 #include "egltest_endpoint_engine_types.h"
    30 #include "egltest_endpoint_images.h"
    31 
    32 #define ENGINE_ASSERT(x) DoEngineAssert((x) != 0, #x, __FILE__, __LINE__)
    33 
    34 static inline void DoEngineAssert(TInt aX, const char *aXStr, 
    35         const char *aFile, TInt aLine)
    36     {
    37     if (!aX)
    38         {
    39         RDebug::Printf("EGL_ENDPOINT_TEST_ENGINE ASSERT(%s) failed (value %d) at %s:%d\n",
    40                 aXStr, aX, aFile, aLine);
    41         User::Panic(_L("ENGINE_ASSERT"), aLine);
    42         }
    43     }
    44 
    45 
    46 // This could be wrapped in #if/#else to allow us to generate non-unicode text content.
    47 #define TESTIDS(x)  _S(x)
    48 #define CASETITLE(x)  _S(x)
    49 
    50 
    51 // SurfaceType lists.
    52 // We use macros so that we get an automatic comment as to what the fields are,
    53 // rather than just listing enums in an array.
    54 #define SurfaceTypes1(type1) 1, { type1 }
    55 #define SurfaceTypes2(type1, type2) 2, { type1, type2 }
    56 #define SurfaceTypes3(type1, type2, type3) 3, { type1, type2, type3 }
    57 #define SurfaceTypes4(type1, type2, type3, type4) 4, { type1, type2, type3, type4 }
    58 
    59 // Macro used for building a TTestCases entry.
    60 #define TestCase(x) { x, sizeof(x) / sizeof(x[0]) }
    61 
    62 // Forward declare this class.
    63 class CEgltest_Local_Engine_Exec;
    64 
    65 // The object passed back from the exec thread to the
    66 // controller thread.
    67 class TExecResult
    68     {
    69 public:
    70     TExecResult();
    71 
    72     //Constructor for sending result info.
    73     TExecResult(TVerdict aVerdict, TEngineCases aCase);
    74     
    75     // Constructor for sending result of buffer count paramters.
    76     TExecResult(TVerdict aBufferCountVerdict, TVerdict aVerdict, TEngineCases aCase);
    77     
    78 public:
    79     //Result message.
    80     TVerdict             iVerdict;
    81     // Checking buffer count. 
    82     TVerdict             iBufferCountVerdict;
    83     // Get Surface parameter reply.
    84     TSurfaceParamsRemote iSurfaceParams;
    85     // To check that we are in sync - it should match the request.
    86     TEngineCases         iCase;
    87     };
    88 
    89 const TInt KMaxLoadThreads = 4;
    90 
    91 NONSHARABLE_CLASS(CEgltest_Local_Engine): public CLocalTestStepBase
    92     {
    93 private:
    94     enum TExecState
    95         {
    96         EExecStateNone  = 0,
    97         EExecStateRemote, 
    98         EExecStateLocal
    99         };
   100 public:
   101     CEgltest_Local_Engine(const TTestCases *aTestCases, TInt aNumCases);
   102     virtual ~CEgltest_Local_Engine();
   103     virtual TVerdict doTestStepL();
   104     virtual void DoPreambleL();
   105     virtual void DoPostambleL();
   106     void SetTestCasesL(const TTestCases * const aTestCases, TInt aNumCases);
   107     
   108 private:
   109     void RunTestCase(const TTestCases &aTestCase);
   110     void RunOneTestCase(const TTestCase& aTestCase, TSurfaceType aSurfType);
   111     void SendLocalTestCase(const TRemoteTestParams &aParams);
   112     void RunLocalTestCase(TEngineCases aCase);
   113     void DoSyncToLocal();
   114     void GetLocalResult(TExecResult& aResult, TEngineCases aCase);
   115     void DoMonitorThreadEntry();
   116     void ForwardPanic(RThread& aThread, RThread& aOtherThread, TRequestStatus &aStatus);
   117     static TInt MonitorThreadEntry(TAny *aParam);
   118     void RunControllerLocalAndRemoteL(const TEngineTestCase&, const TRemoteTestParams& params);
   119     
   120 protected:
   121     void RunLocalTestCase(const TRemoteTestParams& aMessageIn, TExecResult& aResult);
   122     TVerdict RunRemoteTestCase(TInt aTestCase, const TRemoteTestParams& aMessageIn);
   123     void RunSingleCaseL(const TTestCase& aTestCase, TSurfaceType aSurfType);
   124     void CommonPreambleL();
   125     CEgltest_Local_Engine();
   126     // The StartThread and EndThread needs to be overridden in the 
   127     // implementation to provide a good functionality. 
   128     virtual void StartThreadL(TInt aThreadNumber);
   129     virtual void EndThread(TInt aThreadNumber);
   130     
   131 protected:
   132     const TTestCases*                  iTestCases;
   133     TInt                               iNumCases;
   134     RThread                            iExecThread;
   135     RThread                            iMonitorThread;
   136     RThread                            iControllerThread;  // Controller thread
   137     RMsgQueue<TExecResult>             iExecResultOutQueue;
   138     RMsgQueue<TRemoteTestParamsPacket> iExecParamsInQueue;
   139     TExecState                         iExecState;
   140     TBool                              iLogging;
   141     };
   142 
   143 
   144 struct TRemoteTestArgs
   145     {
   146     EGLDisplay     iDisplay;
   147     EGLEndpointNOK iEndpoint;
   148     EGLImageKHR    iImage;
   149     };
   150 
   151 
   152 struct TAvailableMemory
   153     {
   154     TInt iHeapMemAvailable;
   155     TInt iGpuMemAvailable;
   156     };
   157 
   158 // Base class that allows "script" style exectution of testcases.
   159 NONSHARABLE_CLASS(CEgltest_Remote_Engine): public CRemoteTestStepBase
   160     {
   161 public:
   162     CEgltest_Remote_Engine();
   163     virtual ~CEgltest_Remote_Engine();
   164     virtual TRemoteTestVerdict DoStartRemoteTestStepL(const TRemoteTestParams& aParams);
   165     virtual TRemoteTestVerdict DoEndRemoteTestStepL(const TRemoteTestParams& aParams);
   166     virtual TRemoteTestVerdict DoRunRemoteTestCaseL(TInt aTestCase, const TRemoteTestParams& aParams);
   167 private:
   168     void LogDump(const TEngineTestCase& aCase);
   169     EGLDisplay GetDisplay(TInt aFlags);
   170     EGLEndpointNOK GetEndpoint(TInt aIndex, TInt aFlags);
   171     EGLImageKHR GetImage(TInt aIndex, TInt aFlags);
   172     EGLenum GetEndpointType(TInt aFlags);
   173     EGLenum GetSourceType(TInt aFlags);
   174     const TSurfaceId GetSurfaceId(TInt aFlags, const TSurfaceId& aSurfaceId);
   175     void CheckReturn(TInt aRetval, const TEngineTestCase& aStreamItem, TInt aFailValue,
   176                       const TText* aFailSymbol, const TText* aFunction);
   177     void RunCaseL(TInt aTestCase, const TRemoteTestParams &aParams, const TRemoteTestArgs& aArgs);
   178     void CreateEndpointCaseL(const TRemoteTestParams& aParams, const TRemoteTestArgs& aArgs);
   179     void ReleaseImageCaseL(const TRemoteTestParams& aParams, const TRemoteTestArgs& aArgs);
   180     void ActivateVgContextL();
   181     void RequestNotificationL(const TRemoteTestParams& aParams, const TRemoteTestArgs& aArgs);
   182     void GetEndpointDirtyAreaL(const TRemoteTestParams& aParams, const TRemoteTestArgs& aArgs);
   183     void DoCheckRectsL(EGLint *aActualRects, EGLint aRectCount, EGLint aMaxRects,
   184                        TInt aRectsIndex, const TRect aSurfacRect);
   185     void CheckForMemoryLeaks();
   186     void CheckForMemoryLeaksFinish();
   187     
   188     TInt FillGpuMemory();
   189     TInt CalculateAvailableGPUMemory();
   190     TInt CalculateAvailableHeapMemory();
   191     
   192     // Thread entry points for "load" threads.
   193     static TInt LoadHeapMemory(TAny *);
   194     void LoadHeapMemoryL();
   195     static TInt LoadGpuMemory(TAny *);
   196     void LoadGpuMemoryL();
   197 
   198     void StartThreadL(TInt aThreadNumber);
   199     void EndThread(TInt aThreadNumber);
   200     TThreadFunction GetThreadFunction(TInt aThreadNumber);
   201 
   202 private:
   203     EGLEndpointNOK iEndpoints[KMaxEndpoints];
   204     EGLImageKHR iEglImage[KMaxEndpoints];
   205     CTestVgEglImage* iVgImage[KMaxEndpoints];
   206     TRequestStatus iRequestStatus[KMaxEndpoints];
   207     TRemoteTestVerdict iTestVerdict;
   208     TBool iLogging;
   209     CEglWindowSurface *iSurface;
   210     // when this flag is set, errors discovered during a test-step is logged.
   211     // This is normally true, but for stress tests [etc], it can be turned
   212     // off so that when a test is set up to run 1000 times, but only succeeds
   213     // X times, we don't get "error, something failed", when we really didn't
   214     // get an error.
   215     TBool iLogErrors;
   216     
   217     // Tracking memory available. 
   218     RArray<TAvailableMemory> iMemoryStats;
   219     
   220     // Variables to keep track of load-threads.
   221     RThread iLoadThread[KMaxLoadThreads];
   222     TBool   iStopThreadFlag[KMaxLoadThreads]; 
   223     
   224     RHeap* iMainThreadHeap;
   225     PFNEGLQUERYPROFILINGDATANOKPROC ipfnEglQueryProfilingDataNOK;
   226     };
   227 
   228 
   229 #define CASE(x)   case x: caseName=_S(#x); break
   230 
   231 static inline const TText* EngineCaseName(TEngineCases aCase)
   232     {
   233     const TText* caseName = _S("Unknown Engine Case");
   234     switch (aCase)
   235         {
   236 	  CASE(ECreateEndpointCase);
   237 	  CASE(EBeginStreamingCase);
   238 	  CASE(EAcquireImageCase);
   239 	  CASE(EReleaseImageCase);
   240 	  CASE(EEndStreamingCase);
   241 	  CASE(EContentUpdateCase);
   242 	  CASE(EDestroyEndpointCase);
   243 	  CASE(EInitializeCase);
   244 	  CASE(ETerminateCase);
   245 	  CASE(EGetAttribCase);
   246 	  CASE(ESetAttribCase);
   247 	  CASE(ECreateSurfaceCase);
   248 	  CASE(EDrawContentCase);
   249 	  CASE(ECompareImageCase);
   250 	  CASE(EWaitForCase);
   251 	  CASE(ENotifyWhenCase);
   252 	  CASE(ETestVgImageValidCase);
   253 	  CASE(EDestroyVgImageCase);
   254 	  CASE(EDestroyEglImageCase);
   255 	  CASE(ETimeStampCase);
   256 	  CASE(ERequestNotificationCase);
   257 	  CASE(EWaitForNotificationCase);
   258 	  CASE(ECancelNotificationCase);
   259 	  CASE(EBreakPointCase);
   260 	  CASE(ELogEnableCase);
   261 	  CASE(EIllegalCase);
   262 	  CASE(EPanicCase);
   263 	  CASE(EGetEndpointDirtyAreaCase);
   264 	  CASE(ESyncLocalCase);
   265 	  CASE(EGetSurfaceParamsCase);
   266 	  CASE(EFinishedCase);
   267 	  CASE(ECreateVgImageCase);
   268       CASE(EDestroySurfaceCase);
   269       CASE(EStartLoadThreadCase);
   270       CASE(EEndLoadThreadCase);
   271       CASE(ECheckForMemoryLeaks);
   272       CASE(ECheckForMemoryLeaksFinish);
   273         }
   274     return caseName;
   275     }
   276 
   277 #undef CASE
   278 
   279 
   280 inline void LogDump(CTestExecuteLogger &aLogger, const TEngineTestCase& aCase)
   281 {
   282     const TText *caseName = EngineCaseName(aCase.iCase);
   283     aLogger.LogExtra(((TText8*)__FILE__), __LINE__, ESevrInfo,
   284                     _L("Performing subcase %d (%s), with flags=%d, err=%04x endpointidx=%d, image=%d, args=(%d, %d)"),
   285                     aCase.iCase,
   286                     caseName,
   287                     aCase.iFlags,
   288                     aCase.iErrorExpected,
   289                     aCase.iEndpointIndex,
   290                     aCase.iImageIndex,
   291                     aCase.iArg1, aCase.iArg2);
   292 }
   293 
   294 
   295 #endif // __EGLTEST_ENDPOINT_ENGINE_H__