os/graphics/egl/egltest/endpointtestsuite/automated/tinc/egltest_endpoint_stress_engine.h
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 // Copyright (c) 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 #ifndef __EGLTEST_ENDPOINT_STRESS_ENGINE_H__
    23 #define __EGLTEST_ENDPOINT_STRESS_ENGINE_H__
    24 
    25 #include "egltest_endpoint_engine_types.h"
    26 #include "egltest_endpoint_engine.h"
    27 #include "localtestbase.h"
    28 
    29 #define TESTTABLE(x) sizeof(x) / sizeof(x[0]), x
    30 
    31 // This file provides extensions to the egltest engine functionality to 
    32 // support stress tests that aren't practical to do as small tables. The main
    33 // point is to support copying a set of table entries many times.
    34 // Number of sections we expect is needed. This is just an arbitrary value, and a 
    35 // larger value can be used. 
    36 const TInt KMaxSections = 10;
    37 
    38 // Max parameters must be a 2^n number so that we can use binary and magig...
    39 const TInt KMaxParams = 4;
    40 // Log2 of KMaxParams
    41 const TInt KMaxParamsLog2 = 2;
    42 
    43 
    44 // Parameter types. Used to build tables at compile time and passed to factory
    45 // function to request the implementation object for that iterator.
    46 enum TParamType
    47     {
    48     EParamTypeNone = 0,
    49     EParamTypeIterator,
    50     EParamTypeTable,
    51     EParamTypeRandomizer
    52     };
    53 
    54 // Parameter declaration. Used to build tables at compile time. 
    55 struct TParamDeclaration
    56     {
    57     TParamType iType;
    58     TInt       iInit;       
    59     TInt       iEnd;
    60     TInt       iStep;
    61     };
    62 
    63 // These enums define what should be done when there's
    64 // a failure in a stress test section.
    65 enum TOnErrorPolicy
    66     {
    67     // Unknown - this is not a policy, but a placeholder for "uninitialized"
    68     EOnErrorPolicyUnknown,
    69     // Break - this policy is where a failure causes a section to be broken,
    70     // that is, we skip to the next section and remember the number of times this
    71     // section was run. 
    72     EOnErrorPolicyBreak,
    73     // Continue - ignore errors, and continue.
    74     EOnErrorPolicyContinue,
    75     // Fail - errors lead to failing the test.
    76     EOnErrorPolicyFail
    77     };
    78 
    79 // The basic component for producing many table entries from a short table.
    80 struct TStressTestSection
    81     {
    82     // Number of iterations to run.
    83     TInt iIterations;
    84     // What to do when we have a "fail" during the stress test...
    85     TOnErrorPolicy iErrorPolicy;
    86     // Parameter declarations
    87     TParamDeclaration iParams[KMaxParams];
    88     // The actual test cases.
    89     TEngineTestCase iEngineTestCase[KMaxCases];
    90     };
    91 
    92 
    93 // Used to create a list of TStessTestSections.
    94 // 
    95 // A typical stress test table would have a epilog, body and prolog, where
    96 // the epilog and prolog are copied once to the table, and the body copied
    97 // many times over. Sometimes, there may be a test that for example creates
    98 // a large number of endpoints, then does something and then cleans up the
    99 // endpoints. This would have 5 sections: 
   100 // prolog to start things off copied once. 
   101 // creation of endpoints (body part 1), copied n times.
   102 // do some work with endpoints (body part 2), copied n times.
   103 // cleanup of endpoints (body part 3), copied n times. 
   104 // epilog to clean up final items, copied once.
   105 struct TStressTestTable
   106     {
   107     TTestCaseBase             iTestCaseBase;
   108     TUint                     iNumSections;
   109     const TStressTestSection* iSections;
   110     };
   111 
   112 
   113 // A collection of constant values for the purpose of marking/extracting the
   114 // parameter index.
   115 enum TExpandEntryFlags 
   116     {
   117     EParamBitsInInt  = 32,
   118     EExpandParamBit = EParamBitsInInt-1,
   119     EExpandParamFlag = 1 << 31,
   120     EParamShift      = (30-KMaxParamsLog2),
   121     EParamMask       = ((KMaxParams-1) << EParamShift),
   122     EAllFlags = EExpandParamFlag | EParamMask,
   123     ERemoveFlagsMask = ~EAllFlags,
   124     };
   125 
   126 NONSHARABLE_CLASS(CStressParam) : CBase
   127     {
   128 public:
   129     virtual void Initialize(TInt aInit, TInt aEnd, TInt aStep) = 0;
   130     virtual void Next() = 0;
   131     virtual TInt Value() = 0;
   132     virtual ~CStressParam();
   133     static CStressParam *Factory(const TParamDeclaration &aParamDecl);
   134     
   135     };
   136 
   137 NONSHARABLE_CLASS(CStressParamIterator) : public CStressParam 
   138     {
   139 public:
   140     CStressParamIterator();
   141     ~CStressParamIterator();
   142     virtual void Initialize(TInt aInit, TInt aEnd, TInt aStep);
   143     virtual void Next();
   144     virtual TInt Value();
   145 private:
   146     TInt iIterator;
   147     TInt iInit;
   148     TInt iEnd;
   149     TInt iStep;
   150     };
   151 
   152 NONSHARABLE_CLASS(CStressParamTable) : public CStressParam 
   153     {
   154 public:
   155     CStressParamTable();
   156     ~CStressParamTable();
   157     virtual void Initialize(TInt aTable, TInt aCount, TInt /* aUnused */);
   158     virtual void Next();
   159     virtual TInt Value();
   160 private:
   161     TInt  iIndex;
   162     TInt* iTable;
   163     TInt  iCount;
   164     };
   165 
   166 NONSHARABLE_CLASS(CStressParamRandomizer) : public CStressParam
   167     {
   168 public:
   169     CStressParamRandomizer();
   170     ~CStressParamRandomizer();
   171     virtual void Initialize(TInt aMin, TInt aMax, TInt aMul);
   172     virtual void Next();
   173     virtual TInt Value();
   174 private:
   175     TInt  iMin;
   176     TInt  iMax;
   177     TInt  iMul;
   178     TInt  iCurrent;
   179     };
   180 
   181 #define PARAM_DECL(type, init, end, step) { type, init, end, step }
   182 // Iterator parameter: Goes from init to end in step increments. If the total
   183 // loop is bigger than (end - init), it restarts on init. 
   184 #define PARAM_DECL_ITER(init, end, step) PARAM_DECL(EParamTypeIterator, init, end, step)
   185 // Table iterator. Steps over table. Rstarts at index 0 when going past the end. 
   186 #define PARAM_DECL_TABLE(table) \
   187     PARAM_DECL(EParamTypeTable, (TInt)table, sizeof(table)/sizeof(table[0]), 0)
   188 // Random generator. generates an integer in the range [min..max[ then 
   189 // multiples by mul. 
   190 // Example: PARAM_DECL_RANDOM(2, 6, 3) will generate numbers that are multiples 
   191 // of three in the range 6..15. 
   192 #define PARAM_DECL_RANDOM(min, max, mul) PARAM_DECL(EParamTypeRandom, min, max, mul)
   193 
   194 #define NO_PARAMS  { EParamTypeNone, 0, 0, 0 }
   195 
   196 // Make Parameter entry
   197 #define PARAM(n, offset) (EExpandParamFlag | (n << EParamShift) | offset)
   198 #define PARAM0(offset)   PARAM(0, offset)
   199 #define PARAM1(offset)   PARAM(1, offset)
   200 #define PARAM2(offset)   PARAM(2, offset)
   201 #define PARAM3(offset)   PARAM(3, offset)
   202 
   203 class CTestExecuteLogger;
   204 
   205 // A class to allow tests that run many operations to be written as tables
   206 // without having very long tables. Instead the table structure is (as 
   207 // described for the TStressTestTable), consists of a generic header and
   208 // multiple sections of table that have a "number of times to run" counter. 
   209 
   210 // To allow for these changes to the table structure, we derive the 
   211 // CEgttest_Local_Engine class, but provide alternative solutions for a few of
   212 // A class to build stress tests. 
   213 NONSHARABLE_CLASS(CStressTestEngine): public CEgltest_Local_Engine
   214     {
   215 public:
   216     static CStressTestEngine *NewL(const TStressTestTable aStressTable[], TUint aNumTables);
   217     ~CStressTestEngine();
   218     TVerdict doTestStepL();
   219     CStressTestEngine();
   220     virtual void DoPreambleL();
   221     virtual void DoPostambleL();
   222     
   223 protected:
   224     void ConstructL(const TStressTestTable aStressTable[], TUint aNumTables);
   225     void StartThreadL(TInt aThreadNumber);
   226     void EndThread(TInt aThreadNumber);
   227     virtual TThreadFunction GetThreadFunction(TInt aThreadNumber);
   228     
   229 private:
   230     void ModifyL(TEngineTestCase &aTestCase);
   231     void DoModifyL(TInt &aItem);
   232     
   233     void CreateParams(const TStressTestSection &aSection);
   234     void DestroyParams();
   235     void NextParams();
   236     TBool HandleError(const TStressTestSection &section, TInt aCopy, 
   237             TInt aCopies, TInt aCurSection, TInt &aPreviousCopiesRun);
   238     void UpdateVerdict(TVerdict aVerdict);
   239     
   240 private:
   241     const TStressTestTable *iStressTable;
   242     CStressParam *iParams[KMaxParams];
   243 protected:
   244     RThread iLoadThread[KMaxLoadThreads];
   245     TBool   iStopThreadFlag[KMaxLoadThreads];
   246     };
   247 
   248 #endif // __EGLTEST_ENDPOINT_STRESS_ENGINE_H__