os/graphics/egl/egltest/endpointtestsuite/automated/tsrc/egltest_endpoint_stressload.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/egl/egltest/endpointtestsuite/automated/tsrc/egltest_endpoint_stressload.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,357 @@
     1.4 +// Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +/**
    1.20 + @file
    1.21 + @test
    1.22 + @internalComponent - Internal Symbian test code
    1.23 +*/
    1.24 +
    1.25 +#include <e32math.h>
    1.26 +#include <e32atomics.h>
    1.27 +#include "egltest_endpoint_stressload.h"
    1.28 +#include "egltest_endpoint_engine.h"
    1.29 +
    1.30 +
    1.31 +// This would run in conjunction with 
    1.32 +static TStressTestSection test603[] =
    1.33 +{
    1.34 +    1, EOnErrorPolicyFail, 
    1.35 +    { NO_PARAMS },
    1.36 +    {
    1.37 +        { EInitializeCase,           0,                 EGL_SUCCESS },
    1.38 +        { EStartLoadThreadCase,      EThreadController, EGL_SUCCESS, EThreadLoadGpuProcessor },
    1.39 +        { EFinishedCase }
    1.40 +    },
    1.41 +    1000, EOnErrorPolicyContinue, 
    1.42 +    { PARAM_DECL_ITER(0, 4, 1) },
    1.43 +    {
    1.44 +        { ECreateSurfaceCase,        0,              EGL_SUCCESS, 0, EStandardSurface },
    1.45 +        { ECreateEndpointCase,       0,              EGL_SUCCESS, 0 },
    1.46 +        { EDrawContentCase,          0,              EGL_SUCCESS, 0, PARAM0(0) },
    1.47 +        { EContentUpdateCase,        0,              EGL_SUCCESS, 0 },
    1.48 +        { EBeginStreamingCase,       0,              EGL_SUCCESS, 0 },
    1.49 +        { EAcquireImageCase,         0,              EGL_SUCCESS, 0 },
    1.50 +        { ECompareImageCase,         0,              EGL_SUCCESS, 0, PARAM0(0) },
    1.51 +        { EReleaseImageCase,         0,              EGL_SUCCESS, 0, 0 },
    1.52 +        { EDestroyEndpointCase,      0,              EGL_SUCCESS, 0 },
    1.53 +        { EDestroySurfaceCase,       0,              EGL_SUCCESS, 0 },
    1.54 +        { EFinishedCase }
    1.55 +    },
    1.56 +    1, EOnErrorPolicyFail,
    1.57 +    { NO_PARAMS },
    1.58 +    {
    1.59 +        { EEndLoadThreadCase,        EThreadController, EGL_SUCCESS, EThreadLoadGpuProcessor },
    1.60 +        { ETerminateCase,            0,                 EGL_SUCCESS },
    1.61 +        { EFinishedCase }
    1.62 +    },
    1.63 +};
    1.64 +
    1.65 +
    1.66 +static TStressTestSection test625[] =
    1.67 +{
    1.68 +    1, EOnErrorPolicyFail,
    1.69 +    { NO_PARAMS },
    1.70 +    {
    1.71 +        { EInitializeCase,           0,                 EGL_SUCCESS },
    1.72 +        { EStartLoadThreadCase,      EThreadController, EGL_SUCCESS, EThreadLoadGpuMemory },
    1.73 +        { EFinishedCase }
    1.74 +    },
    1.75 +    200, EOnErrorPolicyContinue, 
    1.76 +    { PARAM_DECL_ITER(0, 4, 1) },
    1.77 +    {
    1.78 +        { ECreateSurfaceCase,        0,              EGL_SUCCESS, 0, EStandardSurface },
    1.79 +        { ECreateEndpointCase,       0,              EGL_SUCCESS, 0 },
    1.80 +        { EDrawContentCase,          0,              EGL_SUCCESS, 0, PARAM0(0) },
    1.81 +        { EContentUpdateCase,        0,              EGL_SUCCESS, 0 },
    1.82 +        { EBeginStreamingCase,       0,              EGL_SUCCESS, 0 },
    1.83 +        { EAcquireImageCase,         0,              EGL_SUCCESS, 0 },
    1.84 +        { ECompareImageCase,         0,              EGL_SUCCESS, 0, PARAM0(0) },
    1.85 +        { EReleaseImageCase,         0,              EGL_SUCCESS, 0, 0 },
    1.86 +        { EDestroyEndpointCase,      0,              EGL_SUCCESS, 0 },
    1.87 +        { EDestroySurfaceCase,       0,              EGL_SUCCESS, 0 },
    1.88 +        { EFinishedCase }
    1.89 +    },
    1.90 +    1, EOnErrorPolicyFail,
    1.91 +    { NO_PARAMS },
    1.92 +    {
    1.93 +        { EEndLoadThreadCase,        EThreadController, EGL_SUCCESS, EThreadLoadGpuMemory },
    1.94 +        { ECheckForMemoryLeaks,      0,              EGL_SUCCESS }, 
    1.95 +        { EStartLoadThreadCase,      EThreadController, EGL_SUCCESS, EThreadLoadGpuMemory },
    1.96 +        { EFinishedCase }
    1.97 +    },
    1.98 +    200, EOnErrorPolicyContinue, 
    1.99 +    { PARAM_DECL_ITER(0, 4, 1) },
   1.100 +    {
   1.101 +        { ECreateSurfaceCase,        0,              EGL_SUCCESS, 0, EStandardSurface },
   1.102 +        { ECreateEndpointCase,       0,              EGL_SUCCESS, 0 },
   1.103 +        { EDrawContentCase,          0,              EGL_SUCCESS, 0, PARAM0(0) },
   1.104 +        { EContentUpdateCase,        0,              EGL_SUCCESS, 0 },
   1.105 +        { EBeginStreamingCase,       0,              EGL_SUCCESS, 0 },
   1.106 +        { EAcquireImageCase,         0,              EGL_SUCCESS, 0 },
   1.107 +        { ECompareImageCase,         0,              EGL_SUCCESS, 0, PARAM0(0) },
   1.108 +        { EReleaseImageCase,         0,              EGL_SUCCESS, 0, 0 },
   1.109 +        { EDestroyEndpointCase,      0,              EGL_SUCCESS, 0 },
   1.110 +        { EDestroySurfaceCase,       0,              EGL_SUCCESS, 0 },
   1.111 +        { EFinishedCase }
   1.112 +    },
   1.113 +    1, EOnErrorPolicyFail,
   1.114 +    { NO_PARAMS },
   1.115 +    {
   1.116 +        { EEndLoadThreadCase,        EThreadController, EGL_SUCCESS, EThreadLoadGpuMemory },
   1.117 +        { ECheckForMemoryLeaks,      0,              EGL_SUCCESS }, 
   1.118 +        { EStartLoadThreadCase,      EThreadController, EGL_SUCCESS, EThreadLoadGpuMemory },
   1.119 +        { EFinishedCase }
   1.120 +    },
   1.121 +    200, EOnErrorPolicyContinue,
   1.122 +    { PARAM_DECL_ITER(0, 4, 1) },
   1.123 +    {
   1.124 +        { ECreateSurfaceCase,        0,              EGL_SUCCESS, 0, EStandardSurface },
   1.125 +        { ECreateEndpointCase,       0,              EGL_SUCCESS, 0 },
   1.126 +        { EDrawContentCase,          0,              EGL_SUCCESS, 0, PARAM0(0) },
   1.127 +        { EContentUpdateCase,        0,              EGL_SUCCESS, 0 },
   1.128 +        { EBeginStreamingCase,       0,              EGL_SUCCESS, 0 },
   1.129 +        { EAcquireImageCase,         0,              EGL_SUCCESS, 0 },
   1.130 +        { ECompareImageCase,         0,              EGL_SUCCESS, 0, PARAM0(0) },
   1.131 +        { EReleaseImageCase,         0,              EGL_SUCCESS, 0, 0 },
   1.132 +        { EDestroyEndpointCase,      0,              EGL_SUCCESS, 0 },
   1.133 +        { EDestroySurfaceCase,       0,              EGL_SUCCESS, 0 },
   1.134 +        { EFinishedCase }
   1.135 +    },
   1.136 +    1, EOnErrorPolicyFail,
   1.137 +    { NO_PARAMS },
   1.138 +    {
   1.139 +        { EEndLoadThreadCase,        EThreadController, EGL_SUCCESS, EThreadLoadGpuMemory },
   1.140 +        { ECheckForMemoryLeaks,      0,              EGL_SUCCESS }, 
   1.141 +        { EStartLoadThreadCase,      EThreadController, EGL_SUCCESS, EThreadLoadGpuMemory },
   1.142 +        { EFinishedCase }
   1.143 +    },
   1.144 +    200, EOnErrorPolicyContinue,
   1.145 +    { PARAM_DECL_ITER(0, 4, 1) },
   1.146 +    {
   1.147 +        { ECreateSurfaceCase,        0,              EGL_SUCCESS, 0, EStandardSurface },
   1.148 +        { ECreateEndpointCase,       0,              EGL_SUCCESS, 0 },
   1.149 +        { EDrawContentCase,          0,              EGL_SUCCESS, 0, PARAM0(0) },
   1.150 +        { EContentUpdateCase,        0,              EGL_SUCCESS, 0 },
   1.151 +        { EBeginStreamingCase,       0,              EGL_SUCCESS, 0 },
   1.152 +        { EAcquireImageCase,         0,              EGL_SUCCESS, 0 },
   1.153 +        { ECompareImageCase,         0,              EGL_SUCCESS, 0, PARAM0(0) },
   1.154 +        { EReleaseImageCase,         0,              EGL_SUCCESS, 0, 0 },
   1.155 +        { EDestroyEndpointCase,      0,              EGL_SUCCESS, 0 },
   1.156 +        { EDestroySurfaceCase,       0,              EGL_SUCCESS, 0 },
   1.157 +        { EFinishedCase }
   1.158 +    },
   1.159 +    1, EOnErrorPolicyFail,
   1.160 +    { NO_PARAMS },
   1.161 +    {
   1.162 +        { EEndLoadThreadCase,        EThreadController, EGL_SUCCESS, EThreadLoadGpuMemory },
   1.163 +        { ECheckForMemoryLeaks,      0,              EGL_SUCCESS }, 
   1.164 +        { EStartLoadThreadCase,      EThreadController, EGL_SUCCESS, EThreadLoadGpuMemory },
   1.165 +        { EFinishedCase }
   1.166 +    },
   1.167 +    200, EOnErrorPolicyContinue,
   1.168 +    { PARAM_DECL_ITER(0, 4, 1) },
   1.169 +    {
   1.170 +        { ECreateSurfaceCase,        0,              EGL_SUCCESS, 0, EStandardSurface },
   1.171 +        { ECreateEndpointCase,       0,              EGL_SUCCESS, 0 },
   1.172 +        { EDrawContentCase,          0,              EGL_SUCCESS, 0, PARAM0(0) },
   1.173 +        { EContentUpdateCase,        0,              EGL_SUCCESS, 0 },
   1.174 +        { EBeginStreamingCase,       0,              EGL_SUCCESS, 0 },
   1.175 +        { EAcquireImageCase,         0,              EGL_SUCCESS, 0 },
   1.176 +        { ECompareImageCase,         0,              EGL_SUCCESS, 0, PARAM0(0) },
   1.177 +        { EReleaseImageCase,         0,              EGL_SUCCESS, 0, 0 },
   1.178 +        { EDestroyEndpointCase,      0,              EGL_SUCCESS, 0 },
   1.179 +        { EDestroySurfaceCase,       0,              EGL_SUCCESS, 0 },
   1.180 +        { EFinishedCase }
   1.181 +    },
   1.182 +    1, EOnErrorPolicyFail, 
   1.183 +    { NO_PARAMS },
   1.184 +    {
   1.185 +        { EEndLoadThreadCase,        EThreadController, EGL_SUCCESS, EThreadLoadGpuMemory },
   1.186 +        { ECheckForMemoryLeaks,      0,                 EGL_SUCCESS }, 
   1.187 +        { ECheckForMemoryLeaksFinish,0,                 EGL_SUCCESS },
   1.188 +        { ETerminateCase,            0,                 EGL_SUCCESS },
   1.189 +        { EFinishedCase }
   1.190 +    },
   1.191 +};
   1.192 +
   1.193 +
   1.194 +static const TStressTestTable testTable[] =
   1.195 +{
   1.196 +    {
   1.197 +        {
   1.198 +        TESTIDS("625"),
   1.199 +        CASETITLE("Stress: Test with GPU memory low."),
   1.200 +        SurfaceTypes3(ESurfTypeEglWindow, ESurfTypeRawSingleBuffered, ESurfTypeRaw),
   1.201 +        },
   1.202 +        TESTTABLE(test625)
   1.203 +    },
   1.204 +    {
   1.205 +        {
   1.206 +        TESTIDS("603"),
   1.207 +        CASETITLE("Stress: Test with high GPU load."),
   1.208 +        SurfaceTypes3(ESurfTypeRaw, ESurfTypeEglWindow, ESurfTypeRawSingleBuffered),
   1.209 +        },
   1.210 +        TESTTABLE(test603)
   1.211 +    },
   1.212 +};
   1.213 +
   1.214 +
   1.215 +CEglTest_TestStep_StressLoad::CEglTest_TestStep_StressLoad()
   1.216 +    {
   1.217 +    }
   1.218 +
   1.219 +CEglTest_TestStep_StressLoad* CEglTest_TestStep_StressLoad::New()
   1.220 +    {
   1.221 +    CEglTest_TestStep_StressLoad *self = new CEglTest_TestStep_StressLoad;
   1.222 +    
   1.223 +    if (self)
   1.224 +        {
   1.225 +        self->ConstructL(testTable, sizeof(testTable)/sizeof(testTable[0]));
   1.226 +        }
   1.227 +    return self;
   1.228 +    }
   1.229 +
   1.230 +
   1.231 +TInt CEglTest_TestStep_StressLoad::LoadGpuProcessor(TAny* aSelf )
   1.232 +    {
   1.233 +    CEglTest_TestStep_StressLoad* self = reinterpret_cast<CEglTest_TestStep_StressLoad*>(aSelf);
   1.234 +    CTrapCleanup *cleanUpStack = CTrapCleanup::New();
   1.235 +    if (!cleanUpStack)
   1.236 +       {
   1.237 +       // Can't use INFO_PRINTF here, as we have not yet
   1.238 +       // created the logger object - nor can we until we have
   1.239 +       // a working cleanupstack, so we just do our best at a 
   1.240 +       // reason able error message.
   1.241 +       RDebug::Printf("Could not allocate memory for cleanupStack!");
   1.242 +       User::Panic(_L("LoadThread"), __LINE__);
   1.243 +       return KErrNoMemory;
   1.244 +       }
   1.245 +
   1.246 +    TRAPD(err, self->LoadGpuProcessorL());
   1.247 +    delete cleanUpStack;
   1.248 +    if (err != KErrNone)
   1.249 +        {
   1.250 +        RDebug::Printf("LoadGpuProcessorL left with %d", err);
   1.251 +        User::Panic(_L("LoadGpuProc"), __LINE__);
   1.252 +        }
   1.253 +    return err;
   1.254 +    }
   1.255 +
   1.256 +
   1.257 +void CEglTest_TestStep_StressLoad::LoadGpuProcessorL()
   1.258 +    {
   1.259 +    CSurface  *surface = CSurface::SurfaceFactoryL(ESurfTypeEglWindow);
   1.260 +    CleanupStack::PushL(surface);
   1.261 +    surface->CreateL(EStandard128sqSurface, TPoint(128, 128));
   1.262 +    TRgb bg = TRgb(0x55, 0x88, 0xff);   // Cyan/turqoise-ish.  
   1.263 +    TRgb fg = TRgb(0xff, 0x11, 0x22);   // Red (sort of)
   1.264 +    while(!__e32_atomic_load_acq32(&iStopThreadFlag[EThreadLoadGpuProcessor])) 
   1.265 +        {
   1.266 +            surface->DrawContentL(bg);
   1.267 +            surface->DrawComplexL(fg);
   1.268 +            surface->SubmitContent(ETrue);
   1.269 +        }
   1.270 +    CleanupStack::PopAndDestroy(surface);
   1.271 +    eglReleaseThread();
   1.272 +    }
   1.273 +
   1.274 +
   1.275 +TInt CEglTest_TestStep_StressLoad::LoadGpuMemory(TAny* aSelf)
   1.276 +    { 
   1.277 +    CEglTest_TestStep_StressLoad* self = reinterpret_cast<CEglTest_TestStep_StressLoad*>(aSelf);
   1.278 +    CTrapCleanup *cleanUpStack = CTrapCleanup::New();
   1.279 +    if (!cleanUpStack)
   1.280 +       {
   1.281 +       // Can't use INFO_PRINTF here, as we have not yet
   1.282 +       // created the logger object - nor can we until we have
   1.283 +       // a working cleanupstack, so we just do our best at a 
   1.284 +       // reasonable error message.
   1.285 +       RDebug::Printf("Could not allocate memory for cleanupStack!");
   1.286 +       User::Panic(_L("LoadThread"), __LINE__);
   1.287 +       return KErrNoMemory;
   1.288 +       }
   1.289 +
   1.290 +    TRAPD(err, self->LoadGpuMemoryL());
   1.291 +    delete cleanUpStack;
   1.292 +    if (err != KErrNone)
   1.293 +        {
   1.294 +        RDebug::Printf("LoadThreadL left with %d", err);
   1.295 +        User::Panic(_L("LoadThread"), __LINE__);
   1.296 +        }
   1.297 +    return err;
   1.298 +    }
   1.299 +
   1.300 +
   1.301 +void CEglTest_TestStep_StressLoad::LoadGpuMemoryL()
   1.302 +    {
   1.303 +    const TInt KMaxSurfaceAllocs = 1000;
   1.304 +    CSurface **surfaces = new CSurface*[KMaxSurfaceAllocs];
   1.305 +    ENGINE_ASSERT(surfaces);
   1.306 +    TInt nSurfaces = 0;
   1.307 +    TInt err;
   1.308 +    while(!__e32_atomic_load_acq32(&iStopThreadFlag[EThreadLoadGpuMemory]))     
   1.309 +        {
   1.310 +        ENGINE_ASSERT(nSurfaces < KMaxSurfaceAllocs);
   1.311 +        CSurface* s = CSurface::SurfaceFactoryL(ESurfTypePBuffer);
   1.312 +        if (s)
   1.313 +            {
   1.314 +            TRAP(err, s->CreateL(ELargeSurface));
   1.315 +            if (err == KErrNone)
   1.316 +                {
   1.317 +                surfaces[nSurfaces++] = s;
   1.318 +                TRAP(err, s->DrawContentL(TRgb(0x10, 0x20, 0xB0)));
   1.319 +                }
   1.320 +            else
   1.321 +                {
   1.322 +                delete s;
   1.323 +                s = NULL;
   1.324 +                }
   1.325 +            }
   1.326 +        if (!s)
   1.327 +            {
   1.328 +            User::After(100 * 1000);
   1.329 +            TInt nRelease = nSurfaces / 4;
   1.330 +            for(TInt i = 0; i < nRelease; i++)
   1.331 +                {
   1.332 +                delete surfaces[--nSurfaces];
   1.333 +                surfaces[nSurfaces] = NULL;
   1.334 +                }
   1.335 +            User::After(100 * 1000); // 100 ms. 
   1.336 +            }
   1.337 +        }
   1.338 +    while(nSurfaces)
   1.339 +        {
   1.340 +        delete surfaces[--nSurfaces];
   1.341 +        }
   1.342 +    delete [] surfaces;
   1.343 +    eglReleaseThread();
   1.344 +    }
   1.345 +
   1.346 +
   1.347 +
   1.348 +TThreadFunction CEglTest_TestStep_StressLoad::GetThreadFunction(TInt aThreadNumber)
   1.349 +    {
   1.350 +    switch(aThreadNumber)
   1.351 +        {
   1.352 +        case EThreadLoadGpuProcessor:
   1.353 +            return LoadGpuProcessor; 
   1.354 +
   1.355 +        case EThreadLoadGpuMemory:
   1.356 +            return LoadGpuMemory;
   1.357 +        }
   1.358 +    RDebug::Printf("%s:%d: Unknown thread number %d", __FILE__, __LINE__, aThreadNumber);
   1.359 +    return NULL;
   1.360 +    }