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