os/graphics/egl/egltest/endpointtestsuite/automated/tsrc/egltest_endpoint_stressload.cpp
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 #include <e32math.h>
    23 #include <e32atomics.h>
    24 #include "egltest_endpoint_stressload.h"
    25 #include "egltest_endpoint_engine.h"
    26 
    27 
    28 // This would run in conjunction with 
    29 static TStressTestSection test603[] =
    30 {
    31     1, EOnErrorPolicyFail, 
    32     { NO_PARAMS },
    33     {
    34         { EInitializeCase,           0,                 EGL_SUCCESS },
    35         { EStartLoadThreadCase,      EThreadController, EGL_SUCCESS, EThreadLoadGpuProcessor },
    36         { EFinishedCase }
    37     },
    38     1000, EOnErrorPolicyContinue, 
    39     { PARAM_DECL_ITER(0, 4, 1) },
    40     {
    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 },
    51         { EFinishedCase }
    52     },
    53     1, EOnErrorPolicyFail,
    54     { NO_PARAMS },
    55     {
    56         { EEndLoadThreadCase,        EThreadController, EGL_SUCCESS, EThreadLoadGpuProcessor },
    57         { ETerminateCase,            0,                 EGL_SUCCESS },
    58         { EFinishedCase }
    59     },
    60 };
    61 
    62 
    63 static TStressTestSection test625[] =
    64 {
    65     1, EOnErrorPolicyFail,
    66     { NO_PARAMS },
    67     {
    68         { EInitializeCase,           0,                 EGL_SUCCESS },
    69         { EStartLoadThreadCase,      EThreadController, EGL_SUCCESS, EThreadLoadGpuMemory },
    70         { EFinishedCase }
    71     },
    72     200, EOnErrorPolicyContinue, 
    73     { PARAM_DECL_ITER(0, 4, 1) },
    74     {
    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 },
    85         { EFinishedCase }
    86     },
    87     1, EOnErrorPolicyFail,
    88     { NO_PARAMS },
    89     {
    90         { EEndLoadThreadCase,        EThreadController, EGL_SUCCESS, EThreadLoadGpuMemory },
    91         { ECheckForMemoryLeaks,      0,              EGL_SUCCESS }, 
    92         { EStartLoadThreadCase,      EThreadController, EGL_SUCCESS, EThreadLoadGpuMemory },
    93         { EFinishedCase }
    94     },
    95     200, EOnErrorPolicyContinue, 
    96     { PARAM_DECL_ITER(0, 4, 1) },
    97     {
    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 },
   108         { EFinishedCase }
   109     },
   110     1, EOnErrorPolicyFail,
   111     { NO_PARAMS },
   112     {
   113         { EEndLoadThreadCase,        EThreadController, EGL_SUCCESS, EThreadLoadGpuMemory },
   114         { ECheckForMemoryLeaks,      0,              EGL_SUCCESS }, 
   115         { EStartLoadThreadCase,      EThreadController, EGL_SUCCESS, EThreadLoadGpuMemory },
   116         { EFinishedCase }
   117     },
   118     200, EOnErrorPolicyContinue,
   119     { PARAM_DECL_ITER(0, 4, 1) },
   120     {
   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 },
   131         { EFinishedCase }
   132     },
   133     1, EOnErrorPolicyFail,
   134     { NO_PARAMS },
   135     {
   136         { EEndLoadThreadCase,        EThreadController, EGL_SUCCESS, EThreadLoadGpuMemory },
   137         { ECheckForMemoryLeaks,      0,              EGL_SUCCESS }, 
   138         { EStartLoadThreadCase,      EThreadController, EGL_SUCCESS, EThreadLoadGpuMemory },
   139         { EFinishedCase }
   140     },
   141     200, EOnErrorPolicyContinue,
   142     { PARAM_DECL_ITER(0, 4, 1) },
   143     {
   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 },
   154         { EFinishedCase }
   155     },
   156     1, EOnErrorPolicyFail,
   157     { NO_PARAMS },
   158     {
   159         { EEndLoadThreadCase,        EThreadController, EGL_SUCCESS, EThreadLoadGpuMemory },
   160         { ECheckForMemoryLeaks,      0,              EGL_SUCCESS }, 
   161         { EStartLoadThreadCase,      EThreadController, EGL_SUCCESS, EThreadLoadGpuMemory },
   162         { EFinishedCase }
   163     },
   164     200, EOnErrorPolicyContinue,
   165     { PARAM_DECL_ITER(0, 4, 1) },
   166     {
   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 },
   177         { EFinishedCase }
   178     },
   179     1, EOnErrorPolicyFail, 
   180     { NO_PARAMS },
   181     {
   182         { EEndLoadThreadCase,        EThreadController, EGL_SUCCESS, EThreadLoadGpuMemory },
   183         { ECheckForMemoryLeaks,      0,                 EGL_SUCCESS }, 
   184         { ECheckForMemoryLeaksFinish,0,                 EGL_SUCCESS },
   185         { ETerminateCase,            0,                 EGL_SUCCESS },
   186         { EFinishedCase }
   187     },
   188 };
   189 
   190 
   191 static const TStressTestTable testTable[] =
   192 {
   193     {
   194         {
   195         TESTIDS("625"),
   196         CASETITLE("Stress: Test with GPU memory low."),
   197         SurfaceTypes3(ESurfTypeEglWindow, ESurfTypeRawSingleBuffered, ESurfTypeRaw),
   198         },
   199         TESTTABLE(test625)
   200     },
   201     {
   202         {
   203         TESTIDS("603"),
   204         CASETITLE("Stress: Test with high GPU load."),
   205         SurfaceTypes3(ESurfTypeRaw, ESurfTypeEglWindow, ESurfTypeRawSingleBuffered),
   206         },
   207         TESTTABLE(test603)
   208     },
   209 };
   210 
   211 
   212 CEglTest_TestStep_StressLoad::CEglTest_TestStep_StressLoad()
   213     {
   214     }
   215 
   216 CEglTest_TestStep_StressLoad* CEglTest_TestStep_StressLoad::New()
   217     {
   218     CEglTest_TestStep_StressLoad *self = new CEglTest_TestStep_StressLoad;
   219     
   220     if (self)
   221         {
   222         self->ConstructL(testTable, sizeof(testTable)/sizeof(testTable[0]));
   223         }
   224     return self;
   225     }
   226 
   227 
   228 TInt CEglTest_TestStep_StressLoad::LoadGpuProcessor(TAny* aSelf )
   229     {
   230     CEglTest_TestStep_StressLoad* self = reinterpret_cast<CEglTest_TestStep_StressLoad*>(aSelf);
   231     CTrapCleanup *cleanUpStack = CTrapCleanup::New();
   232     if (!cleanUpStack)
   233        {
   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__);
   240        return KErrNoMemory;
   241        }
   242 
   243     TRAPD(err, self->LoadGpuProcessorL());
   244     delete cleanUpStack;
   245     if (err != KErrNone)
   246         {
   247         RDebug::Printf("LoadGpuProcessorL left with %d", err);
   248         User::Panic(_L("LoadGpuProc"), __LINE__);
   249         }
   250     return err;
   251     }
   252 
   253 
   254 void CEglTest_TestStep_StressLoad::LoadGpuProcessorL()
   255     {
   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])) 
   262         {
   263             surface->DrawContentL(bg);
   264             surface->DrawComplexL(fg);
   265             surface->SubmitContent(ETrue);
   266         }
   267     CleanupStack::PopAndDestroy(surface);
   268     eglReleaseThread();
   269     }
   270 
   271 
   272 TInt CEglTest_TestStep_StressLoad::LoadGpuMemory(TAny* aSelf)
   273     { 
   274     CEglTest_TestStep_StressLoad* self = reinterpret_cast<CEglTest_TestStep_StressLoad*>(aSelf);
   275     CTrapCleanup *cleanUpStack = CTrapCleanup::New();
   276     if (!cleanUpStack)
   277        {
   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__);
   284        return KErrNoMemory;
   285        }
   286 
   287     TRAPD(err, self->LoadGpuMemoryL());
   288     delete cleanUpStack;
   289     if (err != KErrNone)
   290         {
   291         RDebug::Printf("LoadThreadL left with %d", err);
   292         User::Panic(_L("LoadThread"), __LINE__);
   293         }
   294     return err;
   295     }
   296 
   297 
   298 void CEglTest_TestStep_StressLoad::LoadGpuMemoryL()
   299     {
   300     const TInt KMaxSurfaceAllocs = 1000;
   301     CSurface **surfaces = new CSurface*[KMaxSurfaceAllocs];
   302     ENGINE_ASSERT(surfaces);
   303     TInt nSurfaces = 0;
   304     TInt err;
   305     while(!__e32_atomic_load_acq32(&iStopThreadFlag[EThreadLoadGpuMemory]))     
   306         {
   307         ENGINE_ASSERT(nSurfaces < KMaxSurfaceAllocs);
   308         CSurface* s = CSurface::SurfaceFactoryL(ESurfTypePBuffer);
   309         if (s)
   310             {
   311             TRAP(err, s->CreateL(ELargeSurface));
   312             if (err == KErrNone)
   313                 {
   314                 surfaces[nSurfaces++] = s;
   315                 TRAP(err, s->DrawContentL(TRgb(0x10, 0x20, 0xB0)));
   316                 }
   317             else
   318                 {
   319                 delete s;
   320                 s = NULL;
   321                 }
   322             }
   323         if (!s)
   324             {
   325             User::After(100 * 1000);
   326             TInt nRelease = nSurfaces / 4;
   327             for(TInt i = 0; i < nRelease; i++)
   328                 {
   329                 delete surfaces[--nSurfaces];
   330                 surfaces[nSurfaces] = NULL;
   331                 }
   332             User::After(100 * 1000); // 100 ms. 
   333             }
   334         }
   335     while(nSurfaces)
   336         {
   337         delete surfaces[--nSurfaces];
   338         }
   339     delete [] surfaces;
   340     eglReleaseThread();
   341     }
   342 
   343 
   344 
   345 TThreadFunction CEglTest_TestStep_StressLoad::GetThreadFunction(TInt aThreadNumber)
   346     {
   347     switch(aThreadNumber)
   348         {
   349         case EThreadLoadGpuProcessor:
   350             return LoadGpuProcessor; 
   351 
   352         case EThreadLoadGpuMemory:
   353             return LoadGpuMemory;
   354         }
   355     RDebug::Printf("%s:%d: Unknown thread number %d", __FILE__, __LINE__, aThreadNumber);
   356     return NULL;
   357     }