os/graphics/egl/egltest/endpointtestsuite/automated/tinc/egltest_endpoint_stress_engine.h
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
19 @internalComponent - Internal Symbian test code
22 #ifndef __EGLTEST_ENDPOINT_STRESS_ENGINE_H__
23 #define __EGLTEST_ENDPOINT_STRESS_ENGINE_H__
25 #include "egltest_endpoint_engine_types.h"
26 #include "egltest_endpoint_engine.h"
27 #include "localtestbase.h"
29 #define TESTTABLE(x) sizeof(x) / sizeof(x[0]), x
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;
38 // Max parameters must be a 2^n number so that we can use binary and magig...
39 const TInt KMaxParams = 4;
41 const TInt KMaxParamsLog2 = 2;
44 // Parameter types. Used to build tables at compile time and passed to factory
45 // function to request the implementation object for that iterator.
54 // Parameter declaration. Used to build tables at compile time.
55 struct TParamDeclaration
63 // These enums define what should be done when there's
64 // a failure in a stress test section.
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
73 // Continue - ignore errors, and continue.
74 EOnErrorPolicyContinue,
75 // Fail - errors lead to failing the test.
79 // The basic component for producing many table entries from a short table.
80 struct TStressTestSection
82 // Number of iterations to run.
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];
93 // Used to create a list of TStessTestSections.
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
107 TTestCaseBase iTestCaseBase;
109 const TStressTestSection* iSections;
113 // A collection of constant values for the purpose of marking/extracting the
115 enum TExpandEntryFlags
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,
126 NONSHARABLE_CLASS(CStressParam) : CBase
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);
137 NONSHARABLE_CLASS(CStressParamIterator) : public CStressParam
140 CStressParamIterator();
141 ~CStressParamIterator();
142 virtual void Initialize(TInt aInit, TInt aEnd, TInt aStep);
144 virtual TInt Value();
152 NONSHARABLE_CLASS(CStressParamTable) : public CStressParam
156 ~CStressParamTable();
157 virtual void Initialize(TInt aTable, TInt aCount, TInt /* aUnused */);
159 virtual TInt Value();
166 NONSHARABLE_CLASS(CStressParamRandomizer) : public CStressParam
169 CStressParamRandomizer();
170 ~CStressParamRandomizer();
171 virtual void Initialize(TInt aMin, TInt aMax, TInt aMul);
173 virtual TInt Value();
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
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)
194 #define NO_PARAMS { EParamTypeNone, 0, 0, 0 }
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)
203 class CTestExecuteLogger;
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.
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
216 static CStressTestEngine *NewL(const TStressTestTable aStressTable[], TUint aNumTables);
217 ~CStressTestEngine();
218 TVerdict doTestStepL();
220 virtual void DoPreambleL();
221 virtual void DoPostambleL();
224 void ConstructL(const TStressTestTable aStressTable[], TUint aNumTables);
225 void StartThreadL(TInt aThreadNumber);
226 void EndThread(TInt aThreadNumber);
227 virtual TThreadFunction GetThreadFunction(TInt aThreadNumber);
230 void ModifyL(TEngineTestCase &aTestCase);
231 void DoModifyL(TInt &aItem);
233 void CreateParams(const TStressTestSection &aSection);
234 void DestroyParams();
236 TBool HandleError(const TStressTestSection §ion, TInt aCopy,
237 TInt aCopies, TInt aCurSection, TInt &aPreviousCopiesRun);
238 void UpdateVerdict(TVerdict aVerdict);
241 const TStressTestTable *iStressTable;
242 CStressParam *iParams[KMaxParams];
244 RThread iLoadThread[KMaxLoadThreads];
245 TBool iStopThreadFlag[KMaxLoadThreads];
248 #endif // __EGLTEST_ENDPOINT_STRESS_ENGINE_H__