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.
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
#include <e32math.h>
sl@0
    23
#include <e32atomics.h>
sl@0
    24
#include "egltest_endpoint_stressload.h"
sl@0
    25
#include "egltest_endpoint_engine.h"
sl@0
    26
sl@0
    27
sl@0
    28
// This would run in conjunction with 
sl@0
    29
static TStressTestSection test603[] =
sl@0
    30
{
sl@0
    31
    1, EOnErrorPolicyFail, 
sl@0
    32
    { NO_PARAMS },
sl@0
    33
    {
sl@0
    34
        { EInitializeCase,           0,                 EGL_SUCCESS },
sl@0
    35
        { EStartLoadThreadCase,      EThreadController, EGL_SUCCESS, EThreadLoadGpuProcessor },
sl@0
    36
        { EFinishedCase }
sl@0
    37
    },
sl@0
    38
    1000, EOnErrorPolicyContinue, 
sl@0
    39
    { PARAM_DECL_ITER(0, 4, 1) },
sl@0
    40
    {
sl@0
    41
        { ECreateSurfaceCase,        0,              EGL_SUCCESS, 0, EStandardSurface },
sl@0
    42
        { ECreateEndpointCase,       0,              EGL_SUCCESS, 0 },
sl@0
    43
        { EDrawContentCase,          0,              EGL_SUCCESS, 0, PARAM0(0) },
sl@0
    44
        { EContentUpdateCase,        0,              EGL_SUCCESS, 0 },
sl@0
    45
        { EBeginStreamingCase,       0,              EGL_SUCCESS, 0 },
sl@0
    46
        { EAcquireImageCase,         0,              EGL_SUCCESS, 0 },
sl@0
    47
        { ECompareImageCase,         0,              EGL_SUCCESS, 0, PARAM0(0) },
sl@0
    48
        { EReleaseImageCase,         0,              EGL_SUCCESS, 0, 0 },
sl@0
    49
        { EDestroyEndpointCase,      0,              EGL_SUCCESS, 0 },
sl@0
    50
        { EDestroySurfaceCase,       0,              EGL_SUCCESS, 0 },
sl@0
    51
        { EFinishedCase }
sl@0
    52
    },
sl@0
    53
    1, EOnErrorPolicyFail,
sl@0
    54
    { NO_PARAMS },
sl@0
    55
    {
sl@0
    56
        { EEndLoadThreadCase,        EThreadController, EGL_SUCCESS, EThreadLoadGpuProcessor },
sl@0
    57
        { ETerminateCase,            0,                 EGL_SUCCESS },
sl@0
    58
        { EFinishedCase }
sl@0
    59
    },
sl@0
    60
};
sl@0
    61
sl@0
    62
sl@0
    63
static TStressTestSection test625[] =
sl@0
    64
{
sl@0
    65
    1, EOnErrorPolicyFail,
sl@0
    66
    { NO_PARAMS },
sl@0
    67
    {
sl@0
    68
        { EInitializeCase,           0,                 EGL_SUCCESS },
sl@0
    69
        { EStartLoadThreadCase,      EThreadController, EGL_SUCCESS, EThreadLoadGpuMemory },
sl@0
    70
        { EFinishedCase }
sl@0
    71
    },
sl@0
    72
    200, EOnErrorPolicyContinue, 
sl@0
    73
    { PARAM_DECL_ITER(0, 4, 1) },
sl@0
    74
    {
sl@0
    75
        { ECreateSurfaceCase,        0,              EGL_SUCCESS, 0, EStandardSurface },
sl@0
    76
        { ECreateEndpointCase,       0,              EGL_SUCCESS, 0 },
sl@0
    77
        { EDrawContentCase,          0,              EGL_SUCCESS, 0, PARAM0(0) },
sl@0
    78
        { EContentUpdateCase,        0,              EGL_SUCCESS, 0 },
sl@0
    79
        { EBeginStreamingCase,       0,              EGL_SUCCESS, 0 },
sl@0
    80
        { EAcquireImageCase,         0,              EGL_SUCCESS, 0 },
sl@0
    81
        { ECompareImageCase,         0,              EGL_SUCCESS, 0, PARAM0(0) },
sl@0
    82
        { EReleaseImageCase,         0,              EGL_SUCCESS, 0, 0 },
sl@0
    83
        { EDestroyEndpointCase,      0,              EGL_SUCCESS, 0 },
sl@0
    84
        { EDestroySurfaceCase,       0,              EGL_SUCCESS, 0 },
sl@0
    85
        { EFinishedCase }
sl@0
    86
    },
sl@0
    87
    1, EOnErrorPolicyFail,
sl@0
    88
    { NO_PARAMS },
sl@0
    89
    {
sl@0
    90
        { EEndLoadThreadCase,        EThreadController, EGL_SUCCESS, EThreadLoadGpuMemory },
sl@0
    91
        { ECheckForMemoryLeaks,      0,              EGL_SUCCESS }, 
sl@0
    92
        { EStartLoadThreadCase,      EThreadController, EGL_SUCCESS, EThreadLoadGpuMemory },
sl@0
    93
        { EFinishedCase }
sl@0
    94
    },
sl@0
    95
    200, EOnErrorPolicyContinue, 
sl@0
    96
    { PARAM_DECL_ITER(0, 4, 1) },
sl@0
    97
    {
sl@0
    98
        { ECreateSurfaceCase,        0,              EGL_SUCCESS, 0, EStandardSurface },
sl@0
    99
        { ECreateEndpointCase,       0,              EGL_SUCCESS, 0 },
sl@0
   100
        { EDrawContentCase,          0,              EGL_SUCCESS, 0, PARAM0(0) },
sl@0
   101
        { EContentUpdateCase,        0,              EGL_SUCCESS, 0 },
sl@0
   102
        { EBeginStreamingCase,       0,              EGL_SUCCESS, 0 },
sl@0
   103
        { EAcquireImageCase,         0,              EGL_SUCCESS, 0 },
sl@0
   104
        { ECompareImageCase,         0,              EGL_SUCCESS, 0, PARAM0(0) },
sl@0
   105
        { EReleaseImageCase,         0,              EGL_SUCCESS, 0, 0 },
sl@0
   106
        { EDestroyEndpointCase,      0,              EGL_SUCCESS, 0 },
sl@0
   107
        { EDestroySurfaceCase,       0,              EGL_SUCCESS, 0 },
sl@0
   108
        { EFinishedCase }
sl@0
   109
    },
sl@0
   110
    1, EOnErrorPolicyFail,
sl@0
   111
    { NO_PARAMS },
sl@0
   112
    {
sl@0
   113
        { EEndLoadThreadCase,        EThreadController, EGL_SUCCESS, EThreadLoadGpuMemory },
sl@0
   114
        { ECheckForMemoryLeaks,      0,              EGL_SUCCESS }, 
sl@0
   115
        { EStartLoadThreadCase,      EThreadController, EGL_SUCCESS, EThreadLoadGpuMemory },
sl@0
   116
        { EFinishedCase }
sl@0
   117
    },
sl@0
   118
    200, EOnErrorPolicyContinue,
sl@0
   119
    { PARAM_DECL_ITER(0, 4, 1) },
sl@0
   120
    {
sl@0
   121
        { ECreateSurfaceCase,        0,              EGL_SUCCESS, 0, EStandardSurface },
sl@0
   122
        { ECreateEndpointCase,       0,              EGL_SUCCESS, 0 },
sl@0
   123
        { EDrawContentCase,          0,              EGL_SUCCESS, 0, PARAM0(0) },
sl@0
   124
        { EContentUpdateCase,        0,              EGL_SUCCESS, 0 },
sl@0
   125
        { EBeginStreamingCase,       0,              EGL_SUCCESS, 0 },
sl@0
   126
        { EAcquireImageCase,         0,              EGL_SUCCESS, 0 },
sl@0
   127
        { ECompareImageCase,         0,              EGL_SUCCESS, 0, PARAM0(0) },
sl@0
   128
        { EReleaseImageCase,         0,              EGL_SUCCESS, 0, 0 },
sl@0
   129
        { EDestroyEndpointCase,      0,              EGL_SUCCESS, 0 },
sl@0
   130
        { EDestroySurfaceCase,       0,              EGL_SUCCESS, 0 },
sl@0
   131
        { EFinishedCase }
sl@0
   132
    },
sl@0
   133
    1, EOnErrorPolicyFail,
sl@0
   134
    { NO_PARAMS },
sl@0
   135
    {
sl@0
   136
        { EEndLoadThreadCase,        EThreadController, EGL_SUCCESS, EThreadLoadGpuMemory },
sl@0
   137
        { ECheckForMemoryLeaks,      0,              EGL_SUCCESS }, 
sl@0
   138
        { EStartLoadThreadCase,      EThreadController, EGL_SUCCESS, EThreadLoadGpuMemory },
sl@0
   139
        { EFinishedCase }
sl@0
   140
    },
sl@0
   141
    200, EOnErrorPolicyContinue,
sl@0
   142
    { PARAM_DECL_ITER(0, 4, 1) },
sl@0
   143
    {
sl@0
   144
        { ECreateSurfaceCase,        0,              EGL_SUCCESS, 0, EStandardSurface },
sl@0
   145
        { ECreateEndpointCase,       0,              EGL_SUCCESS, 0 },
sl@0
   146
        { EDrawContentCase,          0,              EGL_SUCCESS, 0, PARAM0(0) },
sl@0
   147
        { EContentUpdateCase,        0,              EGL_SUCCESS, 0 },
sl@0
   148
        { EBeginStreamingCase,       0,              EGL_SUCCESS, 0 },
sl@0
   149
        { EAcquireImageCase,         0,              EGL_SUCCESS, 0 },
sl@0
   150
        { ECompareImageCase,         0,              EGL_SUCCESS, 0, PARAM0(0) },
sl@0
   151
        { EReleaseImageCase,         0,              EGL_SUCCESS, 0, 0 },
sl@0
   152
        { EDestroyEndpointCase,      0,              EGL_SUCCESS, 0 },
sl@0
   153
        { EDestroySurfaceCase,       0,              EGL_SUCCESS, 0 },
sl@0
   154
        { EFinishedCase }
sl@0
   155
    },
sl@0
   156
    1, EOnErrorPolicyFail,
sl@0
   157
    { NO_PARAMS },
sl@0
   158
    {
sl@0
   159
        { EEndLoadThreadCase,        EThreadController, EGL_SUCCESS, EThreadLoadGpuMemory },
sl@0
   160
        { ECheckForMemoryLeaks,      0,              EGL_SUCCESS }, 
sl@0
   161
        { EStartLoadThreadCase,      EThreadController, EGL_SUCCESS, EThreadLoadGpuMemory },
sl@0
   162
        { EFinishedCase }
sl@0
   163
    },
sl@0
   164
    200, EOnErrorPolicyContinue,
sl@0
   165
    { PARAM_DECL_ITER(0, 4, 1) },
sl@0
   166
    {
sl@0
   167
        { ECreateSurfaceCase,        0,              EGL_SUCCESS, 0, EStandardSurface },
sl@0
   168
        { ECreateEndpointCase,       0,              EGL_SUCCESS, 0 },
sl@0
   169
        { EDrawContentCase,          0,              EGL_SUCCESS, 0, PARAM0(0) },
sl@0
   170
        { EContentUpdateCase,        0,              EGL_SUCCESS, 0 },
sl@0
   171
        { EBeginStreamingCase,       0,              EGL_SUCCESS, 0 },
sl@0
   172
        { EAcquireImageCase,         0,              EGL_SUCCESS, 0 },
sl@0
   173
        { ECompareImageCase,         0,              EGL_SUCCESS, 0, PARAM0(0) },
sl@0
   174
        { EReleaseImageCase,         0,              EGL_SUCCESS, 0, 0 },
sl@0
   175
        { EDestroyEndpointCase,      0,              EGL_SUCCESS, 0 },
sl@0
   176
        { EDestroySurfaceCase,       0,              EGL_SUCCESS, 0 },
sl@0
   177
        { EFinishedCase }
sl@0
   178
    },
sl@0
   179
    1, EOnErrorPolicyFail, 
sl@0
   180
    { NO_PARAMS },
sl@0
   181
    {
sl@0
   182
        { EEndLoadThreadCase,        EThreadController, EGL_SUCCESS, EThreadLoadGpuMemory },
sl@0
   183
        { ECheckForMemoryLeaks,      0,                 EGL_SUCCESS }, 
sl@0
   184
        { ECheckForMemoryLeaksFinish,0,                 EGL_SUCCESS },
sl@0
   185
        { ETerminateCase,            0,                 EGL_SUCCESS },
sl@0
   186
        { EFinishedCase }
sl@0
   187
    },
sl@0
   188
};
sl@0
   189
sl@0
   190
sl@0
   191
static const TStressTestTable testTable[] =
sl@0
   192
{
sl@0
   193
    {
sl@0
   194
        {
sl@0
   195
        TESTIDS("625"),
sl@0
   196
        CASETITLE("Stress: Test with GPU memory low."),
sl@0
   197
        SurfaceTypes3(ESurfTypeEglWindow, ESurfTypeRawSingleBuffered, ESurfTypeRaw),
sl@0
   198
        },
sl@0
   199
        TESTTABLE(test625)
sl@0
   200
    },
sl@0
   201
    {
sl@0
   202
        {
sl@0
   203
        TESTIDS("603"),
sl@0
   204
        CASETITLE("Stress: Test with high GPU load."),
sl@0
   205
        SurfaceTypes3(ESurfTypeRaw, ESurfTypeEglWindow, ESurfTypeRawSingleBuffered),
sl@0
   206
        },
sl@0
   207
        TESTTABLE(test603)
sl@0
   208
    },
sl@0
   209
};
sl@0
   210
sl@0
   211
sl@0
   212
CEglTest_TestStep_StressLoad::CEglTest_TestStep_StressLoad()
sl@0
   213
    {
sl@0
   214
    }
sl@0
   215
sl@0
   216
CEglTest_TestStep_StressLoad* CEglTest_TestStep_StressLoad::New()
sl@0
   217
    {
sl@0
   218
    CEglTest_TestStep_StressLoad *self = new CEglTest_TestStep_StressLoad;
sl@0
   219
    
sl@0
   220
    if (self)
sl@0
   221
        {
sl@0
   222
        self->ConstructL(testTable, sizeof(testTable)/sizeof(testTable[0]));
sl@0
   223
        }
sl@0
   224
    return self;
sl@0
   225
    }
sl@0
   226
sl@0
   227
sl@0
   228
TInt CEglTest_TestStep_StressLoad::LoadGpuProcessor(TAny* aSelf )
sl@0
   229
    {
sl@0
   230
    CEglTest_TestStep_StressLoad* self = reinterpret_cast<CEglTest_TestStep_StressLoad*>(aSelf);
sl@0
   231
    CTrapCleanup *cleanUpStack = CTrapCleanup::New();
sl@0
   232
    if (!cleanUpStack)
sl@0
   233
       {
sl@0
   234
       // Can't use INFO_PRINTF here, as we have not yet
sl@0
   235
       // created the logger object - nor can we until we have
sl@0
   236
       // a working cleanupstack, so we just do our best at a 
sl@0
   237
       // reason able error message.
sl@0
   238
       RDebug::Printf("Could not allocate memory for cleanupStack!");
sl@0
   239
       User::Panic(_L("LoadThread"), __LINE__);
sl@0
   240
       return KErrNoMemory;
sl@0
   241
       }
sl@0
   242
sl@0
   243
    TRAPD(err, self->LoadGpuProcessorL());
sl@0
   244
    delete cleanUpStack;
sl@0
   245
    if (err != KErrNone)
sl@0
   246
        {
sl@0
   247
        RDebug::Printf("LoadGpuProcessorL left with %d", err);
sl@0
   248
        User::Panic(_L("LoadGpuProc"), __LINE__);
sl@0
   249
        }
sl@0
   250
    return err;
sl@0
   251
    }
sl@0
   252
sl@0
   253
sl@0
   254
void CEglTest_TestStep_StressLoad::LoadGpuProcessorL()
sl@0
   255
    {
sl@0
   256
    CSurface  *surface = CSurface::SurfaceFactoryL(ESurfTypeEglWindow);
sl@0
   257
    CleanupStack::PushL(surface);
sl@0
   258
    surface->CreateL(EStandard128sqSurface, TPoint(128, 128));
sl@0
   259
    TRgb bg = TRgb(0x55, 0x88, 0xff);   // Cyan/turqoise-ish.  
sl@0
   260
    TRgb fg = TRgb(0xff, 0x11, 0x22);   // Red (sort of)
sl@0
   261
    while(!__e32_atomic_load_acq32(&iStopThreadFlag[EThreadLoadGpuProcessor])) 
sl@0
   262
        {
sl@0
   263
            surface->DrawContentL(bg);
sl@0
   264
            surface->DrawComplexL(fg);
sl@0
   265
            surface->SubmitContent(ETrue);
sl@0
   266
        }
sl@0
   267
    CleanupStack::PopAndDestroy(surface);
sl@0
   268
    eglReleaseThread();
sl@0
   269
    }
sl@0
   270
sl@0
   271
sl@0
   272
TInt CEglTest_TestStep_StressLoad::LoadGpuMemory(TAny* aSelf)
sl@0
   273
    { 
sl@0
   274
    CEglTest_TestStep_StressLoad* self = reinterpret_cast<CEglTest_TestStep_StressLoad*>(aSelf);
sl@0
   275
    CTrapCleanup *cleanUpStack = CTrapCleanup::New();
sl@0
   276
    if (!cleanUpStack)
sl@0
   277
       {
sl@0
   278
       // Can't use INFO_PRINTF here, as we have not yet
sl@0
   279
       // created the logger object - nor can we until we have
sl@0
   280
       // a working cleanupstack, so we just do our best at a 
sl@0
   281
       // reasonable error message.
sl@0
   282
       RDebug::Printf("Could not allocate memory for cleanupStack!");
sl@0
   283
       User::Panic(_L("LoadThread"), __LINE__);
sl@0
   284
       return KErrNoMemory;
sl@0
   285
       }
sl@0
   286
sl@0
   287
    TRAPD(err, self->LoadGpuMemoryL());
sl@0
   288
    delete cleanUpStack;
sl@0
   289
    if (err != KErrNone)
sl@0
   290
        {
sl@0
   291
        RDebug::Printf("LoadThreadL left with %d", err);
sl@0
   292
        User::Panic(_L("LoadThread"), __LINE__);
sl@0
   293
        }
sl@0
   294
    return err;
sl@0
   295
    }
sl@0
   296
sl@0
   297
sl@0
   298
void CEglTest_TestStep_StressLoad::LoadGpuMemoryL()
sl@0
   299
    {
sl@0
   300
    const TInt KMaxSurfaceAllocs = 1000;
sl@0
   301
    CSurface **surfaces = new CSurface*[KMaxSurfaceAllocs];
sl@0
   302
    ENGINE_ASSERT(surfaces);
sl@0
   303
    TInt nSurfaces = 0;
sl@0
   304
    TInt err;
sl@0
   305
    while(!__e32_atomic_load_acq32(&iStopThreadFlag[EThreadLoadGpuMemory]))     
sl@0
   306
        {
sl@0
   307
        ENGINE_ASSERT(nSurfaces < KMaxSurfaceAllocs);
sl@0
   308
        CSurface* s = CSurface::SurfaceFactoryL(ESurfTypePBuffer);
sl@0
   309
        if (s)
sl@0
   310
            {
sl@0
   311
            TRAP(err, s->CreateL(ELargeSurface));
sl@0
   312
            if (err == KErrNone)
sl@0
   313
                {
sl@0
   314
                surfaces[nSurfaces++] = s;
sl@0
   315
                TRAP(err, s->DrawContentL(TRgb(0x10, 0x20, 0xB0)));
sl@0
   316
                }
sl@0
   317
            else
sl@0
   318
                {
sl@0
   319
                delete s;
sl@0
   320
                s = NULL;
sl@0
   321
                }
sl@0
   322
            }
sl@0
   323
        if (!s)
sl@0
   324
            {
sl@0
   325
            User::After(100 * 1000);
sl@0
   326
            TInt nRelease = nSurfaces / 4;
sl@0
   327
            for(TInt i = 0; i < nRelease; i++)
sl@0
   328
                {
sl@0
   329
                delete surfaces[--nSurfaces];
sl@0
   330
                surfaces[nSurfaces] = NULL;
sl@0
   331
                }
sl@0
   332
            User::After(100 * 1000); // 100 ms. 
sl@0
   333
            }
sl@0
   334
        }
sl@0
   335
    while(nSurfaces)
sl@0
   336
        {
sl@0
   337
        delete surfaces[--nSurfaces];
sl@0
   338
        }
sl@0
   339
    delete [] surfaces;
sl@0
   340
    eglReleaseThread();
sl@0
   341
    }
sl@0
   342
sl@0
   343
sl@0
   344
sl@0
   345
TThreadFunction CEglTest_TestStep_StressLoad::GetThreadFunction(TInt aThreadNumber)
sl@0
   346
    {
sl@0
   347
    switch(aThreadNumber)
sl@0
   348
        {
sl@0
   349
        case EThreadLoadGpuProcessor:
sl@0
   350
            return LoadGpuProcessor; 
sl@0
   351
sl@0
   352
        case EThreadLoadGpuMemory:
sl@0
   353
            return LoadGpuMemory;
sl@0
   354
        }
sl@0
   355
    RDebug::Printf("%s:%d: Unknown thread number %d", __FILE__, __LINE__, aThreadNumber);
sl@0
   356
    return NULL;
sl@0
   357
    }