os/graphics/egl/egltest/endpointtestsuite/automated/tsrc/egltest_endpoint_stressload.cpp
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
23 #include <e32atomics.h>
24 #include "egltest_endpoint_stressload.h"
25 #include "egltest_endpoint_engine.h"
28 // This would run in conjunction with
29 static TStressTestSection test603[] =
31 1, EOnErrorPolicyFail,
34 { EInitializeCase, 0, EGL_SUCCESS },
35 { EStartLoadThreadCase, EThreadController, EGL_SUCCESS, EThreadLoadGpuProcessor },
38 1000, EOnErrorPolicyContinue,
39 { PARAM_DECL_ITER(0, 4, 1) },
41 { ECreateSurfaceCase, 0, EGL_SUCCESS, 0, EStandardSurface },
42 { ECreateEndpointCase, 0, EGL_SUCCESS, 0 },
43 { EDrawContentCase, 0, EGL_SUCCESS, 0, PARAM0(0) },
44 { EContentUpdateCase, 0, EGL_SUCCESS, 0 },
45 { EBeginStreamingCase, 0, EGL_SUCCESS, 0 },
46 { EAcquireImageCase, 0, EGL_SUCCESS, 0 },
47 { ECompareImageCase, 0, EGL_SUCCESS, 0, PARAM0(0) },
48 { EReleaseImageCase, 0, EGL_SUCCESS, 0, 0 },
49 { EDestroyEndpointCase, 0, EGL_SUCCESS, 0 },
50 { EDestroySurfaceCase, 0, EGL_SUCCESS, 0 },
53 1, EOnErrorPolicyFail,
56 { EEndLoadThreadCase, EThreadController, EGL_SUCCESS, EThreadLoadGpuProcessor },
57 { ETerminateCase, 0, EGL_SUCCESS },
63 static TStressTestSection test625[] =
65 1, EOnErrorPolicyFail,
68 { EInitializeCase, 0, EGL_SUCCESS },
69 { EStartLoadThreadCase, EThreadController, EGL_SUCCESS, EThreadLoadGpuMemory },
72 200, EOnErrorPolicyContinue,
73 { PARAM_DECL_ITER(0, 4, 1) },
75 { ECreateSurfaceCase, 0, EGL_SUCCESS, 0, EStandardSurface },
76 { ECreateEndpointCase, 0, EGL_SUCCESS, 0 },
77 { EDrawContentCase, 0, EGL_SUCCESS, 0, PARAM0(0) },
78 { EContentUpdateCase, 0, EGL_SUCCESS, 0 },
79 { EBeginStreamingCase, 0, EGL_SUCCESS, 0 },
80 { EAcquireImageCase, 0, EGL_SUCCESS, 0 },
81 { ECompareImageCase, 0, EGL_SUCCESS, 0, PARAM0(0) },
82 { EReleaseImageCase, 0, EGL_SUCCESS, 0, 0 },
83 { EDestroyEndpointCase, 0, EGL_SUCCESS, 0 },
84 { EDestroySurfaceCase, 0, EGL_SUCCESS, 0 },
87 1, EOnErrorPolicyFail,
90 { EEndLoadThreadCase, EThreadController, EGL_SUCCESS, EThreadLoadGpuMemory },
91 { ECheckForMemoryLeaks, 0, EGL_SUCCESS },
92 { EStartLoadThreadCase, EThreadController, EGL_SUCCESS, EThreadLoadGpuMemory },
95 200, EOnErrorPolicyContinue,
96 { PARAM_DECL_ITER(0, 4, 1) },
98 { ECreateSurfaceCase, 0, EGL_SUCCESS, 0, EStandardSurface },
99 { ECreateEndpointCase, 0, EGL_SUCCESS, 0 },
100 { EDrawContentCase, 0, EGL_SUCCESS, 0, PARAM0(0) },
101 { EContentUpdateCase, 0, EGL_SUCCESS, 0 },
102 { EBeginStreamingCase, 0, EGL_SUCCESS, 0 },
103 { EAcquireImageCase, 0, EGL_SUCCESS, 0 },
104 { ECompareImageCase, 0, EGL_SUCCESS, 0, PARAM0(0) },
105 { EReleaseImageCase, 0, EGL_SUCCESS, 0, 0 },
106 { EDestroyEndpointCase, 0, EGL_SUCCESS, 0 },
107 { EDestroySurfaceCase, 0, EGL_SUCCESS, 0 },
110 1, EOnErrorPolicyFail,
113 { EEndLoadThreadCase, EThreadController, EGL_SUCCESS, EThreadLoadGpuMemory },
114 { ECheckForMemoryLeaks, 0, EGL_SUCCESS },
115 { EStartLoadThreadCase, EThreadController, EGL_SUCCESS, EThreadLoadGpuMemory },
118 200, EOnErrorPolicyContinue,
119 { PARAM_DECL_ITER(0, 4, 1) },
121 { ECreateSurfaceCase, 0, EGL_SUCCESS, 0, EStandardSurface },
122 { ECreateEndpointCase, 0, EGL_SUCCESS, 0 },
123 { EDrawContentCase, 0, EGL_SUCCESS, 0, PARAM0(0) },
124 { EContentUpdateCase, 0, EGL_SUCCESS, 0 },
125 { EBeginStreamingCase, 0, EGL_SUCCESS, 0 },
126 { EAcquireImageCase, 0, EGL_SUCCESS, 0 },
127 { ECompareImageCase, 0, EGL_SUCCESS, 0, PARAM0(0) },
128 { EReleaseImageCase, 0, EGL_SUCCESS, 0, 0 },
129 { EDestroyEndpointCase, 0, EGL_SUCCESS, 0 },
130 { EDestroySurfaceCase, 0, EGL_SUCCESS, 0 },
133 1, EOnErrorPolicyFail,
136 { EEndLoadThreadCase, EThreadController, EGL_SUCCESS, EThreadLoadGpuMemory },
137 { ECheckForMemoryLeaks, 0, EGL_SUCCESS },
138 { EStartLoadThreadCase, EThreadController, EGL_SUCCESS, EThreadLoadGpuMemory },
141 200, EOnErrorPolicyContinue,
142 { PARAM_DECL_ITER(0, 4, 1) },
144 { ECreateSurfaceCase, 0, EGL_SUCCESS, 0, EStandardSurface },
145 { ECreateEndpointCase, 0, EGL_SUCCESS, 0 },
146 { EDrawContentCase, 0, EGL_SUCCESS, 0, PARAM0(0) },
147 { EContentUpdateCase, 0, EGL_SUCCESS, 0 },
148 { EBeginStreamingCase, 0, EGL_SUCCESS, 0 },
149 { EAcquireImageCase, 0, EGL_SUCCESS, 0 },
150 { ECompareImageCase, 0, EGL_SUCCESS, 0, PARAM0(0) },
151 { EReleaseImageCase, 0, EGL_SUCCESS, 0, 0 },
152 { EDestroyEndpointCase, 0, EGL_SUCCESS, 0 },
153 { EDestroySurfaceCase, 0, EGL_SUCCESS, 0 },
156 1, EOnErrorPolicyFail,
159 { EEndLoadThreadCase, EThreadController, EGL_SUCCESS, EThreadLoadGpuMemory },
160 { ECheckForMemoryLeaks, 0, EGL_SUCCESS },
161 { EStartLoadThreadCase, EThreadController, EGL_SUCCESS, EThreadLoadGpuMemory },
164 200, EOnErrorPolicyContinue,
165 { PARAM_DECL_ITER(0, 4, 1) },
167 { ECreateSurfaceCase, 0, EGL_SUCCESS, 0, EStandardSurface },
168 { ECreateEndpointCase, 0, EGL_SUCCESS, 0 },
169 { EDrawContentCase, 0, EGL_SUCCESS, 0, PARAM0(0) },
170 { EContentUpdateCase, 0, EGL_SUCCESS, 0 },
171 { EBeginStreamingCase, 0, EGL_SUCCESS, 0 },
172 { EAcquireImageCase, 0, EGL_SUCCESS, 0 },
173 { ECompareImageCase, 0, EGL_SUCCESS, 0, PARAM0(0) },
174 { EReleaseImageCase, 0, EGL_SUCCESS, 0, 0 },
175 { EDestroyEndpointCase, 0, EGL_SUCCESS, 0 },
176 { EDestroySurfaceCase, 0, EGL_SUCCESS, 0 },
179 1, EOnErrorPolicyFail,
182 { EEndLoadThreadCase, EThreadController, EGL_SUCCESS, EThreadLoadGpuMemory },
183 { ECheckForMemoryLeaks, 0, EGL_SUCCESS },
184 { ECheckForMemoryLeaksFinish,0, EGL_SUCCESS },
185 { ETerminateCase, 0, EGL_SUCCESS },
191 static const TStressTestTable testTable[] =
196 CASETITLE("Stress: Test with GPU memory low."),
197 SurfaceTypes3(ESurfTypeEglWindow, ESurfTypeRawSingleBuffered, ESurfTypeRaw),
204 CASETITLE("Stress: Test with high GPU load."),
205 SurfaceTypes3(ESurfTypeRaw, ESurfTypeEglWindow, ESurfTypeRawSingleBuffered),
212 CEglTest_TestStep_StressLoad::CEglTest_TestStep_StressLoad()
216 CEglTest_TestStep_StressLoad* CEglTest_TestStep_StressLoad::New()
218 CEglTest_TestStep_StressLoad *self = new CEglTest_TestStep_StressLoad;
222 self->ConstructL(testTable, sizeof(testTable)/sizeof(testTable[0]));
228 TInt CEglTest_TestStep_StressLoad::LoadGpuProcessor(TAny* aSelf )
230 CEglTest_TestStep_StressLoad* self = reinterpret_cast<CEglTest_TestStep_StressLoad*>(aSelf);
231 CTrapCleanup *cleanUpStack = CTrapCleanup::New();
234 // Can't use INFO_PRINTF here, as we have not yet
235 // created the logger object - nor can we until we have
236 // a working cleanupstack, so we just do our best at a
237 // reason able error message.
238 RDebug::Printf("Could not allocate memory for cleanupStack!");
239 User::Panic(_L("LoadThread"), __LINE__);
243 TRAPD(err, self->LoadGpuProcessorL());
247 RDebug::Printf("LoadGpuProcessorL left with %d", err);
248 User::Panic(_L("LoadGpuProc"), __LINE__);
254 void CEglTest_TestStep_StressLoad::LoadGpuProcessorL()
256 CSurface *surface = CSurface::SurfaceFactoryL(ESurfTypeEglWindow);
257 CleanupStack::PushL(surface);
258 surface->CreateL(EStandard128sqSurface, TPoint(128, 128));
259 TRgb bg = TRgb(0x55, 0x88, 0xff); // Cyan/turqoise-ish.
260 TRgb fg = TRgb(0xff, 0x11, 0x22); // Red (sort of)
261 while(!__e32_atomic_load_acq32(&iStopThreadFlag[EThreadLoadGpuProcessor]))
263 surface->DrawContentL(bg);
264 surface->DrawComplexL(fg);
265 surface->SubmitContent(ETrue);
267 CleanupStack::PopAndDestroy(surface);
272 TInt CEglTest_TestStep_StressLoad::LoadGpuMemory(TAny* aSelf)
274 CEglTest_TestStep_StressLoad* self = reinterpret_cast<CEglTest_TestStep_StressLoad*>(aSelf);
275 CTrapCleanup *cleanUpStack = CTrapCleanup::New();
278 // Can't use INFO_PRINTF here, as we have not yet
279 // created the logger object - nor can we until we have
280 // a working cleanupstack, so we just do our best at a
281 // reasonable error message.
282 RDebug::Printf("Could not allocate memory for cleanupStack!");
283 User::Panic(_L("LoadThread"), __LINE__);
287 TRAPD(err, self->LoadGpuMemoryL());
291 RDebug::Printf("LoadThreadL left with %d", err);
292 User::Panic(_L("LoadThread"), __LINE__);
298 void CEglTest_TestStep_StressLoad::LoadGpuMemoryL()
300 const TInt KMaxSurfaceAllocs = 1000;
301 CSurface **surfaces = new CSurface*[KMaxSurfaceAllocs];
302 ENGINE_ASSERT(surfaces);
305 while(!__e32_atomic_load_acq32(&iStopThreadFlag[EThreadLoadGpuMemory]))
307 ENGINE_ASSERT(nSurfaces < KMaxSurfaceAllocs);
308 CSurface* s = CSurface::SurfaceFactoryL(ESurfTypePBuffer);
311 TRAP(err, s->CreateL(ELargeSurface));
314 surfaces[nSurfaces++] = s;
315 TRAP(err, s->DrawContentL(TRgb(0x10, 0x20, 0xB0)));
325 User::After(100 * 1000);
326 TInt nRelease = nSurfaces / 4;
327 for(TInt i = 0; i < nRelease; i++)
329 delete surfaces[--nSurfaces];
330 surfaces[nSurfaces] = NULL;
332 User::After(100 * 1000); // 100 ms.
337 delete surfaces[--nSurfaces];
345 TThreadFunction CEglTest_TestStep_StressLoad::GetThreadFunction(TInt aThreadNumber)
347 switch(aThreadNumber)
349 case EThreadLoadGpuProcessor:
350 return LoadGpuProcessor;
352 case EThreadLoadGpuMemory:
353 return LoadGpuMemory;
355 RDebug::Printf("%s:%d: Unknown thread number %d", __FILE__, __LINE__, aThreadNumber);