os/graphics/egl/egltest/endpointtestsuite/automated/tsrc/egltest_endpoint_engine_remote.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) 2009 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 <e32std.h>
sl@0
    23
#include <e32math.h>
sl@0
    24
#include <e32atomics.h> 
sl@0
    25
#include "egltest_endpoint_engine.h"
sl@0
    26
#include "egltest_endpoint_images.h"
sl@0
    27
#include "egltest_surface.h"
sl@0
    28
#include "egltest_parameters.h"
sl@0
    29
sl@0
    30
sl@0
    31
const TInt KMemStatsReserve = 3;
sl@0
    32
sl@0
    33
CEgltest_Remote_Engine::CEgltest_Remote_Engine()
sl@0
    34
    : CRemoteTestStepBase(ETestUidEndpointEngine), iTestVerdict(ERtvPass), iLogging(EFalse), iSurface(0)
sl@0
    35
    {
sl@0
    36
    iMainThreadHeap = &User::Heap();   // ?? Is this the right heap ??
sl@0
    37
    for (TInt i = 0; i < KMaxEndpoints; i++)
sl@0
    38
        {
sl@0
    39
        iEndpoints[i] = EGL_NO_ENDPOINT_NOK;
sl@0
    40
        iEglImage[i] = EGL_NO_IMAGE_KHR;
sl@0
    41
        iVgImage[i] = NULL;
sl@0
    42
        iRequestStatus[i] = KRequestPending;
sl@0
    43
        }
sl@0
    44
    ipfnEglQueryProfilingDataNOK = reinterpret_cast<PFNEGLQUERYPROFILINGDATANOKPROC>(eglGetProcAddress("eglQueryProfilingDataNOK"));
sl@0
    45
    if (ipfnEglQueryProfilingDataNOK)
sl@0
    46
        {
sl@0
    47
        RDebug::Printf("%s:%d: found eglQueryProfilingDataNOK function");
sl@0
    48
        }
sl@0
    49
    }
sl@0
    50
sl@0
    51
CEgltest_Remote_Engine::~CEgltest_Remote_Engine()
sl@0
    52
    {
sl@0
    53
    // Note: This is run from a different thread an on a different heap than the one
sl@0
    54
    // used during the execution of DoRunRemoteTestCaseL(). So any allocation done
sl@0
    55
    // during DoRunRemoteTestCaseL must be de-allocated in DoEndRemoteTestStepL()
sl@0
    56
    }
sl@0
    57
sl@0
    58
TRemoteTestVerdict CEgltest_Remote_Engine::DoStartRemoteTestStepL(
sl@0
    59
        const TRemoteTestParams& aParams)
sl@0
    60
    {
sl@0
    61
    iMainThreadHeap = &User::Heap();   
sl@0
    62
    
sl@0
    63
    iMemoryStats.ReserveL(KMemStatsReserve);
sl@0
    64
    iLogging = EFalse;
sl@0
    65
    iLogErrors = aParams.iEndpointEngineConfig.iLogErrors;
sl@0
    66
    return ERtvPass;
sl@0
    67
    }
sl@0
    68
sl@0
    69
TRemoteTestVerdict CEgltest_Remote_Engine::DoEndRemoteTestStepL(
sl@0
    70
        const TRemoteTestParams& /* aParams */)
sl@0
    71
    {
sl@0
    72
    iMemoryStats.Close();
sl@0
    73
    delete iSurface;
sl@0
    74
    return ERtvPass;
sl@0
    75
    }
sl@0
    76
sl@0
    77
void CEgltest_Remote_Engine::CheckReturn(TInt aRetval,
sl@0
    78
        const TEngineTestCase& aEngineTestCase, TInt aFailValue,
sl@0
    79
        const TText* aFailSymbol, const TText* aFunction)
sl@0
    80
    {
sl@0
    81
    TBool isEqual = (aRetval == aFailValue);
sl@0
    82
    TBool expectFail = (aEngineTestCase.iFlags & EExpectFailureMask) != 0;
sl@0
    83
sl@0
    84
    EGLint err = eglGetError();
sl@0
    85
    if (err != aEngineTestCase.iErrorExpected)
sl@0
    86
        {
sl@0
    87
        if (iLogErrors)
sl@0
    88
            {
sl@0
    89
            REMOTE_ERR_PRINTF3(_L("testcase failed: expected %04x, got %04x"), aEngineTestCase.iErrorExpected, err);
sl@0
    90
            }
sl@0
    91
        iTestVerdict = ERtvFail;
sl@0
    92
        }
sl@0
    93
sl@0
    94
    if (!isEqual && expectFail)
sl@0
    95
        {
sl@0
    96
        if (iLogErrors)
sl@0
    97
            {
sl@0
    98
            REMOTE_ERR_PRINTF5(
sl@0
    99
                    _L("return value when failing from %s is not expected fail value %s (%d). Value returned is %d"),
sl@0
   100
                    aFunction, aFailSymbol, aFailValue, aRetval);
sl@0
   101
            }
sl@0
   102
        iTestVerdict = ERtvFail;
sl@0
   103
        }
sl@0
   104
    else if (isEqual && !expectFail)
sl@0
   105
        {
sl@0
   106
        if (iLogErrors)
sl@0
   107
            {
sl@0
   108
            REMOTE_ERR_PRINTF5(
sl@0
   109
                    _L("return value when succeeding from %s is equal to expected fail value %s (%d). Value returned is %d"),
sl@0
   110
                    aFunction, aFailSymbol, aFailValue, aRetval);
sl@0
   111
            }
sl@0
   112
        iTestVerdict = ERtvFail;
sl@0
   113
        }
sl@0
   114
    if (isEqual != expectFail)
sl@0
   115
        {
sl@0
   116
        if (iLogErrors)
sl@0
   117
            {
sl@0
   118
            REMOTE_ERR_PRINTF4(_L("Unexpected result for %s, failvalue is %s, flags = %d"),
sl@0
   119
                    aFunction, aFailSymbol,
sl@0
   120
                    aEngineTestCase.iFlags);
sl@0
   121
            }
sl@0
   122
        iTestVerdict = ERtvFail;
sl@0
   123
        }
sl@0
   124
    // Now check
sl@0
   125
    if (expectFail && err == EGL_SUCCESS)
sl@0
   126
        {
sl@0
   127
        if (iLogErrors)
sl@0
   128
            {
sl@0
   129
            REMOTE_ERR_PRINTF2(_L("Got EGL_SUCCESS in error when calling %s, when we expected an error"),
sl@0
   130
                    aFunction);
sl@0
   131
            }
sl@0
   132
        iTestVerdict = ERtvFail;
sl@0
   133
        }
sl@0
   134
    // Didn't expect to fail, so we
sl@0
   135
    else if (!expectFail && err != EGL_SUCCESS)
sl@0
   136
        {
sl@0
   137
        if (iLogErrors)
sl@0
   138
            {
sl@0
   139
            REMOTE_ERR_PRINTF3(_L("Got an error (%x) on successful call to %s, when expecting EGL_SUCCESS"),
sl@0
   140
                    err, aFunction);
sl@0
   141
            }
sl@0
   142
        iTestVerdict = ERtvFail;
sl@0
   143
        }
sl@0
   144
    }
sl@0
   145
sl@0
   146
#define CHECK_RETURN(retval, failval, func) \
sl@0
   147
    CheckReturn((retval), si, (failval), _S(#failval), func)
sl@0
   148
sl@0
   149
#define CHECK_RETURN_CAST(retval, failval, func) \
sl@0
   150
    CheckReturn(reinterpret_cast<int>(retval), si, reinterpret_cast<int>(failval), _S(#failval), func)
sl@0
   151
sl@0
   152
#define CHECK_BOOL_RET(func, funcName) \
sl@0
   153
{  \
sl@0
   154
    EGLBoolean ret = EglEndpoint().func(dpy, endpoint);     \
sl@0
   155
    CheckReturn(ret, si, EGL_FALSE, _S("EGL_FALSE"), _S(funcName));  \
sl@0
   156
}
sl@0
   157
sl@0
   158
void CEgltest_Remote_Engine::LogDump(const TEngineTestCase& aCase)
sl@0
   159
    {
sl@0
   160
    const TText *caseName = EngineCaseName(aCase.iCase);
sl@0
   161
sl@0
   162
    Log(((TText8*)__FILE__), __LINE__, ESevrInfo,
sl@0
   163
                    _L("Performing subcase %d (%s), with flags=%d, err=%04x endpointidx=%d, image=%d, args=(%d, %d)"),
sl@0
   164
                    aCase.iCase,
sl@0
   165
                    caseName,
sl@0
   166
                    aCase.iFlags,
sl@0
   167
                    aCase.iErrorExpected,
sl@0
   168
                    aCase.iEndpointIndex,
sl@0
   169
                    aCase.iImageIndex,
sl@0
   170
                    aCase.iArg1, aCase.iArg2);
sl@0
   171
    }
sl@0
   172
sl@0
   173
TRemoteTestVerdict CEgltest_Remote_Engine::DoRunRemoteTestCaseL(
sl@0
   174
        TInt aTestCase, const TRemoteTestParams &aParams)
sl@0
   175
    {
sl@0
   176
    TRemoteTestArgs args;
sl@0
   177
    iTestVerdict = ERtvPass;
sl@0
   178
    const TEngineTestCase &si = aParams.iEndpointEngine.iEngineTestCase;
sl@0
   179
sl@0
   180
    CDisplayParams* displayParams = CDisplayParams::NewLC(!!(si.iFlags & EUseBadDisplay), eglGetDisplay(EGL_DEFAULT_DISPLAY));
sl@0
   181
    TInt dpyParamsCount = displayParams->Count();
sl@0
   182
    CEndpointParams* endpointParams = CEndpointParams::NewLC(!!(si.iFlags & EUseBadEndpoint), iEndpoints, KMaxEndpoints, si.iEndpointIndex);
sl@0
   183
    TInt endpointCount  = endpointParams->Count();
sl@0
   184
    CImageParams* imageParams = CImageParams::NewLC(!!(si.iFlags & EUseBadEglImage), iEglImage, KMaxEndpoints, si.iImageIndex);
sl@0
   185
    TInt imageCount = imageParams->Count();
sl@0
   186
sl@0
   187
    for(TInt dpyIter = 0; dpyIter < dpyParamsCount; dpyIter++)
sl@0
   188
        {
sl@0
   189
        args.iDisplay = (*displayParams)[dpyIter];
sl@0
   190
        for(TInt epIter = 0; epIter < endpointCount; epIter++)
sl@0
   191
            {
sl@0
   192
            args.iEndpoint = (*endpointParams)[epIter];
sl@0
   193
sl@0
   194
            for(TInt imageIter = 0; imageIter < imageCount; imageIter++)
sl@0
   195
                {
sl@0
   196
                args.iImage = (*imageParams)[imageIter];
sl@0
   197
sl@0
   198
                RunCaseL(aTestCase, aParams, args);
sl@0
   199
                if (iLogErrors && iTestVerdict != ERtvPass || iLogging)
sl@0
   200
                    {
sl@0
   201
                    if (iTestVerdict != ERtvPass)
sl@0
   202
                        {
sl@0
   203
                        REMOTE_INFO_PRINTF1(_L("Test failed:"));
sl@0
   204
                        }
sl@0
   205
                    LogDump(si);
sl@0
   206
                    REMOTE_INFO_PRINTF4(_L("Using values: display: %d, endpoint: %d, image: %d"),
sl@0
   207
                            args.iDisplay, args.iEndpoint, args.iImage);
sl@0
   208
                    }
sl@0
   209
                }
sl@0
   210
            }
sl@0
   211
        }
sl@0
   212
    CleanupStack::PopAndDestroy(3);
sl@0
   213
    return iTestVerdict;
sl@0
   214
    }
sl@0
   215
sl@0
   216
sl@0
   217
void CEgltest_Remote_Engine::ActivateVgContextL()
sl@0
   218
    {
sl@0
   219
    if (!iSurface)
sl@0
   220
        {
sl@0
   221
        iSurface = CEglWindowSurface::NewL();
sl@0
   222
        iSurface->CreateL(EStandardSurface, TPoint(0, 110));
sl@0
   223
        }
sl@0
   224
    iSurface->ActivateL();
sl@0
   225
    }
sl@0
   226
sl@0
   227
sl@0
   228
TInt CEgltest_Remote_Engine::FillGpuMemory()
sl@0
   229
    {
sl@0
   230
    TSurfaceIndex table[] = 
sl@0
   231
            {
sl@0
   232
            ELargeSurface,
sl@0
   233
            EStandard128sqSurface,
sl@0
   234
            ESmallSurface,
sl@0
   235
            ETinySurface
sl@0
   236
            };
sl@0
   237
    const TInt KNumSurfaceTypes = sizeof(table) / sizeof(table[0]);
sl@0
   238
    
sl@0
   239
    TInt nSurfaces = 0;
sl@0
   240
    const TInt KMaxSurfaceAllocs = 1000;
sl@0
   241
    CSurface **surfaces = new CSurface*[KMaxSurfaceAllocs];
sl@0
   242
    TInt size = 0;
sl@0
   243
    ENGINE_ASSERT(surfaces);
sl@0
   244
    for(TInt i = 0; i < KNumSurfaceTypes; i++)
sl@0
   245
        {
sl@0
   246
        TInt err = KErrNone;
sl@0
   247
        while(err == KErrNone)     
sl@0
   248
            {
sl@0
   249
            ENGINE_ASSERT(nSurfaces < KMaxSurfaceAllocs);
sl@0
   250
            CSurface* s = CSurface::SurfaceFactoryL(ESurfTypePBuffer);
sl@0
   251
            if (s)
sl@0
   252
                {
sl@0
   253
                TRAP(err, s->CreateL(table[i]));
sl@0
   254
                if (err == KErrNone)
sl@0
   255
                    {
sl@0
   256
                    surfaces[nSurfaces++] = s;
sl@0
   257
//                    s->DrawContentL(TRgb(0x10, 0x20, 0xB0));
sl@0
   258
                    size += s->SizeInBytes();
sl@0
   259
                    }
sl@0
   260
                }
sl@0
   261
            }
sl@0
   262
        }
sl@0
   263
    RDebug::Printf("nSurfaces=%d", nSurfaces);
sl@0
   264
    while(nSurfaces)
sl@0
   265
        {
sl@0
   266
        delete surfaces[--nSurfaces];
sl@0
   267
        }
sl@0
   268
    delete [] surfaces;
sl@0
   269
    return size;
sl@0
   270
    }
sl@0
   271
sl@0
   272
TInt CEgltest_Remote_Engine::CalculateAvailableGPUMemory()
sl@0
   273
    {
sl@0
   274
    TInt result = 0;
sl@0
   275
    if (ipfnEglQueryProfilingDataNOK)
sl@0
   276
        {
sl@0
   277
        EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
sl@0
   278
        ENGINE_ASSERT(display != EGL_NO_DISPLAY);
sl@0
   279
        TInt count;
sl@0
   280
        ipfnEglQueryProfilingDataNOK(
sl@0
   281
                display, EGL_PROF_QUERY_MEMORY_USAGE_BIT_NOK, 
sl@0
   282
                NULL, 0, &count);
sl@0
   283
        ENGINE_ASSERT(count);
sl@0
   284
        TInt *mem = new TInt[count * 2];
sl@0
   285
        ENGINE_ASSERT(mem);
sl@0
   286
        TInt newCount;
sl@0
   287
        ipfnEglQueryProfilingDataNOK(
sl@0
   288
                display, EGL_PROF_QUERY_MEMORY_USAGE_BIT_NOK, 
sl@0
   289
                mem, count, &newCount);
sl@0
   290
        ENGINE_ASSERT(newCount == count);
sl@0
   291
        for(TInt i = 0; i < count; i ++)
sl@0
   292
            {
sl@0
   293
            switch(mem[i*2])
sl@0
   294
                {
sl@0
   295
            case EGL_PROF_USED_MEMORY_NOK:
sl@0
   296
                // Assert that we only have one entry - if there are
sl@0
   297
                // more than one, we can't really know what is the "right" one.
sl@0
   298
                ENGINE_ASSERT(!result);
sl@0
   299
                result = mem[i*2+1];
sl@0
   300
                break;
sl@0
   301
                }
sl@0
   302
            }
sl@0
   303
        delete [] mem;
sl@0
   304
        }
sl@0
   305
    else
sl@0
   306
        {
sl@0
   307
#if 1
sl@0
   308
        result = 1000;
sl@0
   309
#else
sl@0
   310
        // This code currently causes a memory leak to be detected when the
sl@0
   311
        // remote thread is destroyed. This causes further tests to be skipped.
sl@0
   312
        // We disable this function at the moment, to allow other tests to run.
sl@0
   313
        result = FillGpuMemory();
sl@0
   314
#endif
sl@0
   315
        }
sl@0
   316
    return result;
sl@0
   317
    }
sl@0
   318
sl@0
   319
sl@0
   320
TInt CEgltest_Remote_Engine::CalculateAvailableHeapMemory()
sl@0
   321
    {
sl@0
   322
    TInt biggest = 0;
sl@0
   323
    return User::Heap().Available(biggest);
sl@0
   324
    }
sl@0
   325
sl@0
   326
sl@0
   327
void CEgltest_Remote_Engine::CheckForMemoryLeaks()
sl@0
   328
    {
sl@0
   329
    TAvailableMemory mem;
sl@0
   330
    mem.iGpuMemAvailable = CalculateAvailableGPUMemory();
sl@0
   331
    mem.iHeapMemAvailable = CalculateAvailableHeapMemory();
sl@0
   332
    
sl@0
   333
    REMOTE_INFO_PRINTF3(_L("GPU memory available: %d, heapmemory available: %d"), 
sl@0
   334
            mem.iGpuMemAvailable, mem.iHeapMemAvailable);
sl@0
   335
    if (iMemoryStats.Count() ==  KMemStatsReserve)
sl@0
   336
        {
sl@0
   337
        REMOTE_INFO_PRINTF2(_L("false positive HEAP leak possible, as reserved memory is exhausted... (%d)"), KMemStatsReserve);
sl@0
   338
        }
sl@0
   339
    TInt err = iMemoryStats.Append(mem); 
sl@0
   340
    if (err)
sl@0
   341
        {
sl@0
   342
        REMOTE_ERR_PRINTF2(_L("CheckForMemoryLeaks could not append to iMemoryStats. err=%d"), err);
sl@0
   343
        }
sl@0
   344
    }
sl@0
   345
sl@0
   346
void CEgltest_Remote_Engine::CheckForMemoryLeaksFinish()
sl@0
   347
    {
sl@0
   348
    TInt count = iMemoryStats.Count();
sl@0
   349
    if (count)
sl@0
   350
        {
sl@0
   351
        TReal sumGpu = 0.0;
sl@0
   352
        TReal sumHeap = 0.0;
sl@0
   353
        
sl@0
   354
        for(TInt i = 0; i < count; i++)
sl@0
   355
            {
sl@0
   356
            sumGpu += iMemoryStats[i].iGpuMemAvailable;
sl@0
   357
            sumHeap += iMemoryStats[i].iHeapMemAvailable;
sl@0
   358
            }
sl@0
   359
        REMOTE_INFO_PRINTF2(_L("CheckMemoryLeaksFinish - average = %6.2f"), sumGpu / count);
sl@0
   360
        REMOTE_INFO_PRINTF2(_L("CheckMemoryLeaksFinish - average = %6.2f"), sumHeap / count);
sl@0
   361
        }
sl@0
   362
    else
sl@0
   363
        {
sl@0
   364
        REMOTE_INFO_PRINTF1(_L("CheckMemoryLeaksFinish - no data collected"));
sl@0
   365
        }
sl@0
   366
    iMemoryStats.Close();
sl@0
   367
    }
sl@0
   368
sl@0
   369
TRemoteTestVerdict ConvertToLocalVerdict(TInt aVerdict)
sl@0
   370
    {
sl@0
   371
    switch(aVerdict)
sl@0
   372
        {
sl@0
   373
        case EPass:
sl@0
   374
            return ERtvPass;
sl@0
   375
        case EFail:
sl@0
   376
            return ERtvFail;
sl@0
   377
        }
sl@0
   378
        return ERtvInconclusive;
sl@0
   379
    }
sl@0
   380
sl@0
   381
void CEgltest_Remote_Engine::RunCaseL(TInt aTestCase, const TRemoteTestParams &aParams, const TRemoteTestArgs& aArgs)
sl@0
   382
    {
sl@0
   383
    const TEngineTestCase &si = aParams.iEndpointEngine.iEngineTestCase;
sl@0
   384
    EGLDisplay dpy = aArgs.iDisplay;
sl@0
   385
    EGLImageKHR image = aArgs.iImage;
sl@0
   386
    EGLEndpointNOK endpoint = aArgs.iEndpoint;
sl@0
   387
sl@0
   388
    switch (aTestCase)
sl@0
   389
        {
sl@0
   390
        case EInitializeCase:
sl@0
   391
            REMOTE_INFO_PRINTF1(_L("calling EglStartL()"));
sl@0
   392
            EglStartL();
sl@0
   393
            break;
sl@0
   394
sl@0
   395
        case ECreateEndpointCase:
sl@0
   396
            CreateEndpointCaseL(aParams, aArgs);
sl@0
   397
            break;
sl@0
   398
sl@0
   399
        case EAcquireImageCase:
sl@0
   400
            image = EglEndpoint().AcquireImage(dpy, endpoint);
sl@0
   401
            CHECK_RETURN(image, EGL_NO_IMAGE_KHR, _S("eglAcquireImage"));
sl@0
   402
            if (image != EGL_NO_IMAGE_KHR)
sl@0
   403
                {
sl@0
   404
                iEglImage[si.iEndpointIndex] = image;
sl@0
   405
                }
sl@0
   406
            break;
sl@0
   407
sl@0
   408
        case ECompareImageCase:
sl@0
   409
            if (iEglImage[si.iEndpointIndex] == EGL_NO_IMAGE_KHR)
sl@0
   410
                {
sl@0
   411
                REMOTE_ERR_PRINTF2(_L("Image at index %d is not a valid eglImage"), si.iEndpointIndex);
sl@0
   412
                iTestVerdict = ERtvFail;
sl@0
   413
                }
sl@0
   414
            else
sl@0
   415
                {
sl@0
   416
                ActivateVgContextL();
sl@0
   417
sl@0
   418
                CTestCFbsImage *image = CTestCFbsImage::NewL(si.iImageIndex);
sl@0
   419
                CleanupStack::PushL(image);
sl@0
   420
                CTestVgEglImage *vgImage = CTestVgEglImage::New(iEglImage[si.iEndpointIndex]);
sl@0
   421
                if (!vgImage)
sl@0
   422
                    {
sl@0
   423
                    REMOTE_INFO_PRINTF2(_L("Could not create vgimage from eglimage: endpointindex=%d"), 
sl@0
   424
                            si.iEndpointIndex);
sl@0
   425
                    }
sl@0
   426
                else
sl@0
   427
                    {
sl@0
   428
                    CleanupStack::PushL(vgImage);
sl@0
   429
                    TBool res = vgImage->CompareImageL(image, !!(si.iFlags & EExpectError));
sl@0
   430
                    if (res != !(si.iFlags & EExpectError))
sl@0
   431
                        {
sl@0
   432
                        if (iLogErrors)
sl@0
   433
                            {
sl@0
   434
                        REMOTE_ERR_PRINTF1(_L("Pixel comparison failed...."));
sl@0
   435
                            }
sl@0
   436
                        iTestVerdict = ERtvFail;
sl@0
   437
                        }
sl@0
   438
                    else if (!(si.iFlags & EExpectError))
sl@0
   439
                        {
sl@0
   440
                        // Extra check that ANOTHER image doesn't match the image
sl@0
   441
                        // we compared with.
sl@0
   442
                        // This would detect when images have incorrect content or
sl@0
   443
                        // the code for comparing images have been broken. 
sl@0
   444
                        TInt imageIndex2 = (si.iImageIndex + 1) % CTestImage::KImageCount;
sl@0
   445
                        CTestCFbsImage *image2 = CTestCFbsImage::NewL(imageIndex2);
sl@0
   446
                        CleanupStack::PushL(image2);
sl@0
   447
                        res = vgImage->CompareImageL(image2, ETrue);
sl@0
   448
                        if (res)
sl@0
   449
                            {
sl@0
   450
                            REMOTE_ERR_PRINTF1(_L("Pixel comparison didn't fail - two images the same?...."));
sl@0
   451
                            iTestVerdict = ERtvFail;
sl@0
   452
                            }
sl@0
   453
                        CleanupStack::PopAndDestroy(image2);
sl@0
   454
                        }
sl@0
   455
                    CleanupStack::PopAndDestroy(vgImage);
sl@0
   456
                    }
sl@0
   457
                CleanupStack::PopAndDestroy(image);
sl@0
   458
                }
sl@0
   459
            break;
sl@0
   460
sl@0
   461
        case EReleaseImageCase:
sl@0
   462
            ReleaseImageCaseL(aParams, aArgs);
sl@0
   463
            break;
sl@0
   464
sl@0
   465
        case EBeginStreamingCase:
sl@0
   466
            CHECK_BOOL_RET(EndpointBeginStreaming, "eglEndpointBeginStreaming");
sl@0
   467
            break;
sl@0
   468
sl@0
   469
        case EEndStreamingCase:
sl@0
   470
            CHECK_BOOL_RET(EndpointEndStreaming, "eglEndpointEndStreaming");
sl@0
   471
            break;
sl@0
   472
sl@0
   473
        case EDestroyEndpointCase:
sl@0
   474
            CHECK_BOOL_RET(DestroyEndpoint, "eglDestroyEndpoint");
sl@0
   475
            break;
sl@0
   476
sl@0
   477
        case EGetAttribCase:
sl@0
   478
            {
sl@0
   479
            TInt value = EglEndpoint().GetEndpointAttrib(dpy, endpoint, si.iArg1);
sl@0
   480
            // We can't use the macro CHECK_RETURN here, as the return value for
sl@0
   481
            // "success" can be any integer value, including "EGL_FALSE". So we can
sl@0
   482
            // only check when we expect failure.
sl@0
   483
            if (si.iFlags & EExpectFailureMask)
sl@0
   484
                {
sl@0
   485
                CheckReturn(value, si, EGL_FALSE,_S("EGL_FALSE") ,_S("eglGetEndpointAttrib"));
sl@0
   486
                }
sl@0
   487
            else
sl@0
   488
                {
sl@0
   489
                EGLint err = eglGetError();
sl@0
   490
                if (err != EGL_SUCCESS)
sl@0
   491
                    {
sl@0
   492
                    REMOTE_ERR_PRINTF2(_L("Got an error (%x) on successful call to eglGetEndpointAttrib, when expecting EGL_SUCCESS in error"),
sl@0
   493
                            err);
sl@0
   494
                    iTestVerdict = ERtvFail;
sl@0
   495
                    }
sl@0
   496
                }
sl@0
   497
            if (value != si.iArg2)
sl@0
   498
                {
sl@0
   499
                REMOTE_ERR_PRINTF4(_L("GetEndpointAttrib(%04x), got %d, expected %d"), si.iArg1, value, si.iArg2);
sl@0
   500
                iTestVerdict = ERtvFail;
sl@0
   501
                }
sl@0
   502
            }
sl@0
   503
            break;
sl@0
   504
sl@0
   505
        case ESetAttribCase:
sl@0
   506
            {
sl@0
   507
            EGLBoolean ret = EglEndpoint().SetEndpointAttrib(dpy, endpoint, si.iArg1, si.iArg2);
sl@0
   508
            CHECK_RETURN(ret, EGL_FALSE, _S("eglSetEndpointAttrib"));
sl@0
   509
            }
sl@0
   510
            break;
sl@0
   511
sl@0
   512
        case EDestroyEglImageCase:
sl@0
   513
            {
sl@0
   514
            EGLBoolean ret = EglEndpoint().DestroyImage(dpy, image);
sl@0
   515
            CHECK_RETURN(ret, EGL_FALSE, _S("eglDestroyImageKHR"));
sl@0
   516
            }
sl@0
   517
			break;
sl@0
   518
sl@0
   519
        case ECreateVgImageCase:
sl@0
   520
            {
sl@0
   521
            // For a VgImage to be possible to create, we need to have a EglSurface.
sl@0
   522
            ActivateVgContextL();
sl@0
   523
sl@0
   524
            TRAPD(err, iVgImage[si.iImageIndex] = CTestVgEglImage::NewL(iEglImage[si.iEndpointIndex]));
sl@0
   525
            if ((si.iFlags & EExpectFailureMask) && err == KErrNone)
sl@0
   526
                {
sl@0
   527
                REMOTE_ERR_PRINTF1(_L("Successfully created VGImage when we expected an error"));
sl@0
   528
                iTestVerdict = ERtvFail;
sl@0
   529
                delete iVgImage[si.iImageIndex];
sl@0
   530
                iVgImage[si.iImageIndex] = NULL;
sl@0
   531
                }
sl@0
   532
            else if (!(si.iFlags & EExpectFailureMask) && err != KErrNone)
sl@0
   533
                {
sl@0
   534
                REMOTE_ERR_PRINTF1(_L("Failed to create VGImage when we expected to succeed"));
sl@0
   535
                iTestVerdict = ERtvFail;
sl@0
   536
                }
sl@0
   537
            }
sl@0
   538
            break;
sl@0
   539
sl@0
   540
        // Test that a vgImage can be used. We do NOT test the content for anything in particular, since
sl@0
   541
        // the current usage of this is to do checking on a vgImage after endpoint is destroyed, and the
sl@0
   542
        // specification is that the vgImage is undefined under this condition.
sl@0
   543
        case ETestVgImageValidCase:
sl@0
   544
            {
sl@0
   545
            ActivateVgContextL();
sl@0
   546
            CTestVgEglImage *vgImage = iVgImage[si.iImageIndex];
sl@0
   547
            if (!vgImage)
sl@0
   548
                {
sl@0
   549
                // Image not usable!
sl@0
   550
                REMOTE_ERR_PRINTF1(_L("VGImage is not present"));
sl@0
   551
                iTestVerdict = ERtvFail;
sl@0
   552
                }
sl@0
   553
            else
sl@0
   554
                {
sl@0
   555
                vgDrawImage(vgImage->VGImage());
sl@0
   556
                VGint err = vgGetError();
sl@0
   557
                if (err != VG_NO_ERROR)
sl@0
   558
                    {
sl@0
   559
                    iTestVerdict = ERtvFail;
sl@0
   560
                    }
sl@0
   561
#if 0
sl@0
   562
                TSize size = vgImage->Size();
sl@0
   563
                // Now read the pixels in four corners and the middle to check if the image is still "working".
sl@0
   564
                vgImage->Pixel(0, 0);
sl@0
   565
                vgImage->Pixel(size.iWidth-1, size.iHeight-1);
sl@0
   566
                vgImage->Pixel(0, size.iHeight-1);
sl@0
   567
                vgImage->Pixel(size.iWidth-1, 0);
sl@0
   568
                vgImage->Pixel(size.iWidth >> 1, size.iHeight >> 1);
sl@0
   569
#endif
sl@0
   570
                }
sl@0
   571
            // If we get here, the image is "working" - we expect to panic or crash if it's not...
sl@0
   572
            }
sl@0
   573
            break;
sl@0
   574
sl@0
   575
        case EDestroyVgImageCase:
sl@0
   576
            delete iVgImage[si.iImageIndex];
sl@0
   577
            iVgImage[si.iImageIndex] = NULL;
sl@0
   578
            break;
sl@0
   579
sl@0
   580
        case ERequestNotificationCase:
sl@0
   581
            RequestNotificationL(aParams, aArgs);
sl@0
   582
            break;
sl@0
   583
sl@0
   584
        case ECancelNotificationCase:
sl@0
   585
            CHECK_BOOL_RET(EndpointCancelNotification, "eglEndpointCancelNotification");
sl@0
   586
            break;
sl@0
   587
sl@0
   588
        case EWaitForNotificationCase:
sl@0
   589
            {
sl@0
   590
            RTimer timer;
sl@0
   591
            TInt err = timer.CreateLocal();
sl@0
   592
            if (err != KErrNone)
sl@0
   593
                {
sl@0
   594
                REMOTE_INFO_PRINTF2(_L("Could not create timer. Error=%d"), err);
sl@0
   595
                iTestVerdict = ERtvFail;
sl@0
   596
                }
sl@0
   597
            else
sl@0
   598
                {
sl@0
   599
                TRequestStatus timerStatus = KRequestPending;
sl@0
   600
                timer.HighRes(timerStatus, si.iArg1);
sl@0
   601
                // Note that the requeststatus is set to KRequestPending by
sl@0
   602
                // eglEndpointRequestNotificationNOK(), so we don't do that
sl@0
   603
                // before waiting. See below for more comments.
sl@0
   604
                TRequestStatus *requestStatus = &iRequestStatus[si.iEndpointIndex];
sl@0
   605
                User::WaitForRequest(timerStatus, *requestStatus);
sl@0
   606
                TInt result = KErrNotReady;  // Give it some ERROR value that is unlikely to happen later.
sl@0
   607
                timer.Cancel();
sl@0
   608
                timer.Close();
sl@0
   609
                if (timerStatus == KErrNone && *requestStatus == KRequestPending)
sl@0
   610
                    {
sl@0
   611
                    result = KErrTimedOut;
sl@0
   612
                    }
sl@0
   613
                else
sl@0
   614
                    {
sl@0
   615
                    result = requestStatus->Int();
sl@0
   616
                    }
sl@0
   617
                // Reset the request - this allows us to (ab-)use this request to
sl@0
   618
                // wait for things that aren't completing, etc.
sl@0
   619
                *requestStatus = KRequestPending;
sl@0
   620
                if ((si.iFlags & EExpectError) && result >= KErrNone)
sl@0
   621
                    {
sl@0
   622
                    iTestVerdict = ERtvFail;
sl@0
   623
                    REMOTE_INFO_PRINTF1(_L("Expected failure, but result was a success"));
sl@0
   624
                    }
sl@0
   625
                else if (!(si.iFlags & EExpectError) && result < KErrNone)
sl@0
   626
                    {
sl@0
   627
                    iTestVerdict = ERtvFail;
sl@0
   628
                    REMOTE_INFO_PRINTF1(_L("Expected success, but result was a failure"));
sl@0
   629
                    }
sl@0
   630
                if (result != si.iErrorExpected)
sl@0
   631
                    {
sl@0
   632
                    iTestVerdict = ERtvFail;
sl@0
   633
                    REMOTE_INFO_PRINTF3(_L("EWaitForNotificationCase: Expected error %d, got %d"), si.iErrorExpected, result);
sl@0
   634
                    }
sl@0
   635
                }
sl@0
   636
            }
sl@0
   637
            break;
sl@0
   638
sl@0
   639
        case EGetEndpointDirtyAreaCase:
sl@0
   640
            GetEndpointDirtyAreaL(aParams, aArgs);
sl@0
   641
            break;
sl@0
   642
sl@0
   643
        case ETerminateCase:
sl@0
   644
            REMOTE_INFO_PRINTF1(_L("calling EglEndL()"));
sl@0
   645
            EglEndL();
sl@0
   646
            break;
sl@0
   647
            
sl@0
   648
        // Memory leak checking functions.
sl@0
   649
        case ECheckForMemoryLeaks:
sl@0
   650
            CheckForMemoryLeaks();
sl@0
   651
            break;
sl@0
   652
            
sl@0
   653
        case ECheckForMemoryLeaksFinish:
sl@0
   654
            CheckForMemoryLeaksFinish();
sl@0
   655
            break;
sl@0
   656
            
sl@0
   657
            
sl@0
   658
        case EStartLoadThreadCase:
sl@0
   659
            StartThreadL(si.iEndpointIndex);
sl@0
   660
            break;
sl@0
   661
            
sl@0
   662
        case EEndLoadThreadCase:
sl@0
   663
            EndThread(si.iEndpointIndex);
sl@0
   664
            break;
sl@0
   665
            
sl@0
   666
        case ESetVerdictCase:
sl@0
   667
            iTestVerdict = ConvertToLocalVerdict(si.iEndpointIndex);
sl@0
   668
            break;
sl@0
   669
            
sl@0
   670
sl@0
   671
        /*
sl@0
   672
         * Debug cases
sl@0
   673
         */
sl@0
   674
sl@0
   675
        case EBreakPointCase:
sl@0
   676
            __BREAKPOINT();
sl@0
   677
            break;
sl@0
   678
sl@0
   679
        case ELogEnableCase:
sl@0
   680
            iLogging = ETrue;
sl@0
   681
            break;
sl@0
   682
            
sl@0
   683
        case EPanicCase:
sl@0
   684
            User::Panic(_L("EPanicCase"), -1);
sl@0
   685
            break;
sl@0
   686
sl@0
   687
        default:
sl@0
   688
            REMOTE_ERR_PRINTF2(_L("Invalid testcase %d"), aTestCase);
sl@0
   689
            User::Invariant();
sl@0
   690
            break;
sl@0
   691
        }
sl@0
   692
    }
sl@0
   693
sl@0
   694
sl@0
   695
// Create thread that consumes some sort of resource (e.g. Heap or GPU memory)
sl@0
   696
// @param aThreadNumber indicates "which" 
sl@0
   697
void CEgltest_Remote_Engine::StartThreadL(TInt aThreadNumber)
sl@0
   698
    {
sl@0
   699
    const TInt KStackSize = 12000;
sl@0
   700
    const TInt KHeapMinSize = 16000;
sl@0
   701
    const TInt KHeapMaxSize = 1000000;
sl@0
   702
sl@0
   703
    if (aThreadNumber >= KMaxLoadThreads)
sl@0
   704
        {
sl@0
   705
        User::Panic(_L("StartThreadL"), __LINE__);
sl@0
   706
        }
sl@0
   707
    
sl@0
   708
    __e32_atomic_store_rel32(&iStopThreadFlag[aThreadNumber], EFalse);
sl@0
   709
    
sl@0
   710
    TUint32 random = Math::Random();
sl@0
   711
    TName threadName;
sl@0
   712
    _LIT(KThreadNameFormat, "%S-%u");
sl@0
   713
sl@0
   714
    // Create a load-thread.
sl@0
   715
    _LIT(KThreadName, "EpTestLoadThread");
sl@0
   716
    threadName.Format(KThreadNameFormat, &KThreadName, random);
sl@0
   717
    TThreadFunction threadFunc = GetThreadFunction(aThreadNumber);
sl@0
   718
    if (threadFunc == NULL)
sl@0
   719
        {
sl@0
   720
        REMOTE_ERR_PRINTF2(_L("Requested thread function %d, got NULL pointer back!"), aThreadNumber);
sl@0
   721
        User::Leave(KErrArgument);
sl@0
   722
        }
sl@0
   723
    TInt err = iLoadThread[aThreadNumber].Create(threadName, threadFunc, 
sl@0
   724
                    KStackSize, KHeapMinSize, KHeapMaxSize, this, EOwnerThread);
sl@0
   725
    if(err != KErrNone)
sl@0
   726
        {
sl@0
   727
        REMOTE_ERR_PRINTF2(_L("Could not create load thread - err=%d"), err);
sl@0
   728
        User::Leave(err);
sl@0
   729
        }
sl@0
   730
    iLoadThread[aThreadNumber].Resume();
sl@0
   731
    }
sl@0
   732
sl@0
   733
sl@0
   734
void CEgltest_Remote_Engine::EndThread(TInt aThreadNumber)
sl@0
   735
    {
sl@0
   736
    if (aThreadNumber >= KMaxLoadThreads)
sl@0
   737
        {
sl@0
   738
        User::Panic(_L("StartThreadL"), __LINE__);
sl@0
   739
        }
sl@0
   740
sl@0
   741
    TRequestStatus status;
sl@0
   742
    iLoadThread[aThreadNumber].Logon(status);
sl@0
   743
    // Tell thread to go away. 
sl@0
   744
    __e32_atomic_store_rel32(&iStopThreadFlag[aThreadNumber], ETrue);
sl@0
   745
    User::WaitForRequest(status);
sl@0
   746
    iLoadThread[aThreadNumber].Close();
sl@0
   747
    }
sl@0
   748
sl@0
   749
sl@0
   750
void CEgltest_Remote_Engine::CreateEndpointCaseL(const TRemoteTestParams &aParams, const TRemoteTestArgs& aArgs)
sl@0
   751
    {
sl@0
   752
    const TEngineTestCase &si = aParams.iEndpointEngine.iEngineTestCase;
sl@0
   753
    EGLDisplay dpy = aArgs.iDisplay;
sl@0
   754
    EGLEndpointNOK endpoint = aArgs.iEndpoint;
sl@0
   755
    const TSurfaceParamsRemote& cp = aParams.iEndpointEngine.iSurfaceParams;
sl@0
   756
sl@0
   757
    CEnumParams* endpointTypeParams = CEnumParams::NewLC(!!(si.iFlags & EUseBadEndpointType),
sl@0
   758
                                                            EGL_ENDPOINT_TYPE_CONSUMER_NOK);
sl@0
   759
    CEnumParams* sourceParams = CEnumParams::NewLC(!!(si.iFlags & EUseBadSourceType),
sl@0
   760
                                                   EGL_TSURFACEID_NOK);
sl@0
   761
    CSurfaceIdParams *surfParams = CSurfaceIdParams::NewLC(!!(si.iFlags & EUseBadSurfaceId),
sl@0
   762
                                                           cp.iSurfaceId);
sl@0
   763
sl@0
   764
    TInt endpointTypeCount = endpointTypeParams->Count();
sl@0
   765
    TInt sourceCount = sourceParams->Count();
sl@0
   766
    TInt surfCount = surfParams->Count();
sl@0
   767
sl@0
   768
    for(TInt typeIter = 0; typeIter < endpointTypeCount; typeIter++)
sl@0
   769
        {
sl@0
   770
        EGLenum type = (*endpointTypeParams)[typeIter];
sl@0
   771
        for(TInt sourceIter = 0; sourceIter < sourceCount; sourceIter++)
sl@0
   772
            {
sl@0
   773
            EGLenum source_type = (*sourceParams)[sourceIter];
sl@0
   774
sl@0
   775
            for(TInt surfIter = 0; surfIter < surfCount; surfIter++)
sl@0
   776
                {
sl@0
   777
                EGLEndpointSourceNOK source = (EGLEndpointSourceNOK)(&(*surfParams)[surfIter]);
sl@0
   778
                EGLint *attrib_list = cp.iCommonParams.iUseAttribList?
sl@0
   779
                    const_cast<EGLint *>(cp.iCommonParams.iAttribs):NULL;
sl@0
   780
sl@0
   781
                endpoint = EglEndpoint().CreateEndpoint(dpy, type, source_type, source, attrib_list);
sl@0
   782
                CHECK_RETURN_CAST(endpoint, EGL_NO_ENDPOINT_NOK, _S("eglCreateEndpoint"));
sl@0
   783
                if (endpoint != EGL_NO_ENDPOINT_NOK)
sl@0
   784
                    {
sl@0
   785
                    iEndpoints[si.iEndpointIndex] = endpoint;
sl@0
   786
                    }
sl@0
   787
                }
sl@0
   788
            }
sl@0
   789
        }
sl@0
   790
    CleanupStack::PopAndDestroy(3);
sl@0
   791
    }
sl@0
   792
sl@0
   793
sl@0
   794
void CEgltest_Remote_Engine::ReleaseImageCaseL(const TRemoteTestParams& aParams, const TRemoteTestArgs& aArgs)
sl@0
   795
    {
sl@0
   796
    const TEngineTestCase &si = aParams.iEndpointEngine.iEngineTestCase;
sl@0
   797
    EGLDisplay dpy = aArgs.iDisplay;
sl@0
   798
    EGLImageKHR image = aArgs.iImage;
sl@0
   799
    EGLEndpointNOK endpoint = aArgs.iEndpoint;
sl@0
   800
sl@0
   801
    static const EGLenum validAPIs[] = { EGL_OPENVG_API, EGL_OPENGL_API, EGL_OPENGL_ES_API };
sl@0
   802
    const TInt validAPIcount = sizeof(validAPIs) / sizeof(validAPIs[0]);
sl@0
   803
sl@0
   804
    CEnumParams* enumParams = CEnumParams::NewLC(!!(si.iFlags & EUseBadApi),
sl@0
   805
            validAPIs, validAPIcount, 0);
sl@0
   806
    for(TInt enumIter = 0; enumIter < enumParams->Count(); enumIter++)
sl@0
   807
        {
sl@0
   808
        EGLenum api = (*enumParams)[enumIter];
sl@0
   809
        EGLBoolean ret = EglEndpoint().ReleaseImage(dpy, endpoint, image, api);
sl@0
   810
        CHECK_RETURN(ret, EGL_FALSE, _S("eglReleaseImage"));
sl@0
   811
        }
sl@0
   812
    CleanupStack::PopAndDestroy(enumParams);
sl@0
   813
    }
sl@0
   814
sl@0
   815
void CEgltest_Remote_Engine::RequestNotificationL(const TRemoteTestParams& aParams, const TRemoteTestArgs &aArgs)
sl@0
   816
    {
sl@0
   817
    const TEngineTestCase &si = aParams.iEndpointEngine.iEngineTestCase;
sl@0
   818
    EGLDisplay dpy = aArgs.iDisplay;
sl@0
   819
    EGLEndpointNOK endpoint = aArgs.iEndpoint;
sl@0
   820
sl@0
   821
    CSyncParams* enumParams = CSyncParams::NewLC(!!(si.iFlags & EUseBadSync), &iRequestStatus[si.iEndpointIndex]);
sl@0
   822
    for(TInt enumIter = 0; enumIter < enumParams->Count(); enumIter++)
sl@0
   823
        {
sl@0
   824
        TRequestStatus* sync = (*enumParams)[enumIter];
sl@0
   825
        EGLBoolean ret = EglEndpoint().EndpointRequestNotification(dpy, endpoint, sync);
sl@0
   826
        CHECK_RETURN(ret, EGL_FALSE, _S("eglEndpointRequestNotification"));
sl@0
   827
        }
sl@0
   828
    CleanupStack::PopAndDestroy(enumParams);
sl@0
   829
    }
sl@0
   830
sl@0
   831
// Mark either side of "rects" with something that we can detect.
sl@0
   832
// Must not be a valid rect coordinate - which is unlikely for this
sl@0
   833
// number (regardless of endianness), since it's roughly 0x40000000.
sl@0
   834
static const EGLint KMarker = 'NTCH';
sl@0
   835
// Allow space for this number of rectangles either side of the actual buffer.
sl@0
   836
static const TInt KBufferArea = 2;
sl@0
   837
sl@0
   838
void CEgltest_Remote_Engine::DoCheckRectsL(EGLint *aRectsBuffer, EGLint aRectCount, EGLint aMaxRects,
sl@0
   839
                                           TInt aRectsIndex, const TRect aSurfaceRect)
sl@0
   840
    {
sl@0
   841
    // Right now, this testing only supports "full surface" rectangles.
sl@0
   842
    ASSERT(aRectsIndex == 0);
sl@0
   843
    EGLint *rects = aRectsBuffer+KBufferArea * 4;
sl@0
   844
sl@0
   845
    // First, check the rects returned by the call. Should not be equal to KMarker.
sl@0
   846
    // For example, if we ask for 4 rects, and only two rects are filled in, index
sl@0
   847
    // 0 and 1 are checked that they are properly filled in.
sl@0
   848
    for (TInt i = 0; i < aRectCount * 4; i++)
sl@0
   849
        {
sl@0
   850
        if (rects[i] == KMarker)
sl@0
   851
            {
sl@0
   852
            iTestVerdict = ERtvFail;
sl@0
   853
            REMOTE_INFO_PRINTF3(_L("Seems the dirty area wasn't filled in properly! Got 0x%08x at %d"), rects[i], i);
sl@0
   854
            }
sl@0
   855
        }
sl@0
   856
    // Check the area not supposed to be filled in! All this should contain KMArker!
sl@0
   857
    // Check that the dirty area get call didn't fill in any memory
sl@0
   858
    // beyond the rectangles returned. Say we asked for 4 rectangles,
sl@0
   859
    // and two were returned, this will check that index 2 & 3 were
sl@0
   860
    // not modified. If we ask for 4 rects and get 4 rects back, nothing
sl@0
   861
    // is done here.
sl@0
   862
    for(TInt i = aRectCount * 4; i < aMaxRects * 4; i++)
sl@0
   863
        {
sl@0
   864
        if (rects[i] != KMarker)
sl@0
   865
            {
sl@0
   866
            iTestVerdict = ERtvFail;
sl@0
   867
            REMOTE_INFO_PRINTF3(_L("Seems the dirty area filled beyond the number of rects that it returned! Got 0x%08x at %d"), rects[i], i);
sl@0
   868
            }
sl@0
   869
        }
sl@0
   870
    // Check the "bufferaea" before the actual rects - MUST not be touched.
sl@0
   871
    for(TInt i = 0; i < KBufferArea * 4; i++)
sl@0
   872
        {
sl@0
   873
        if (aRectsBuffer[i] != KMarker)
sl@0
   874
            {
sl@0
   875
            iTestVerdict = ERtvFail;
sl@0
   876
            REMOTE_INFO_PRINTF3(_L("Seems the dirty area walked outside it's allowed memory! Got 0x%08x at %d"), rects[i], i);
sl@0
   877
            }
sl@0
   878
        }
sl@0
   879
    // Check the buffer area AFTER the buffer we gave - again, the
sl@0
   880
    // production code should ABSOLUTELY not write here.
sl@0
   881
    for(TInt i = (aMaxRects + KBufferArea) * 4; i < (aMaxRects + KBufferArea * 2) * 4; i++)
sl@0
   882
        {
sl@0
   883
        if (aRectsBuffer[i] != KMarker)
sl@0
   884
            {
sl@0
   885
            iTestVerdict = ERtvFail;
sl@0
   886
            REMOTE_INFO_PRINTF3(_L("Seems the dirty area walked outside it's allowed memory! Got 0x%08x at %d"), rects[i], i);
sl@0
   887
            }
sl@0
   888
        }
sl@0
   889
    if (aRectsIndex == 0)
sl@0
   890
        {
sl@0
   891
        // Check that rectangle matches the full surface extent.
sl@0
   892
        // We should only have ONE rectangle in this case!
sl@0
   893
        if (aRectCount != 1)
sl@0
   894
            {
sl@0
   895
            REMOTE_INFO_PRINTF2(_L("Expected 1 rectangle returned - got %d"), aRectCount);
sl@0
   896
            iTestVerdict = ERtvFail;
sl@0
   897
            }
sl@0
   898
        else
sl@0
   899
            {
sl@0
   900
            TRect returnedRect = TRect(rects[0], rects[1], rects[2], rects[3]);
sl@0
   901
            if (returnedRect != aSurfaceRect)
sl@0
   902
                {
sl@0
   903
                REMOTE_INFO_PRINTF1(_L("rectangles do not match!"));
sl@0
   904
                }
sl@0
   905
            }
sl@0
   906
        }
sl@0
   907
    // TODO: To support flexible sets of dirty area we need an else on the
sl@0
   908
    // above if-statement. However, with the current reference and the planned
sl@0
   909
    // third party known at this point, only "full surface" will ever be
sl@0
   910
    // returned.
sl@0
   911
    }
sl@0
   912
sl@0
   913
void CEgltest_Remote_Engine::GetEndpointDirtyAreaL(const TRemoteTestParams& aParams, const TRemoteTestArgs& aArgs)
sl@0
   914
    {
sl@0
   915
    const TEngineTestCase &si = aParams.iEndpointEngine.iEngineTestCase;
sl@0
   916
    EGLDisplay dpy = aArgs.iDisplay;
sl@0
   917
    EGLEndpointNOK endpoint = aArgs.iEndpoint;
sl@0
   918
sl@0
   919
    EGLint *rects;
sl@0
   920
    EGLint *rectsBuffer = NULL;
sl@0
   921
    const TInt actualRectsSize = (si.iArg2 + KBufferArea * 2) * 4;
sl@0
   922
    // We don't use the "parameter expansion" for bad rects value.
sl@0
   923
    // This is because it's so easy to just add it here, and there is only one bad
sl@0
   924
    // value that is recognisable.
sl@0
   925
    if (si.iFlags & (EUseNullRects | EUseBadRects))
sl@0
   926
        {
sl@0
   927
        rects = NULL;
sl@0
   928
        }
sl@0
   929
    else
sl@0
   930
        {
sl@0
   931
        rectsBuffer = new EGLint[actualRectsSize];
sl@0
   932
        CleanupStack::PushL(rectsBuffer);
sl@0
   933
        rects = rectsBuffer + (KBufferArea * 4);
sl@0
   934
        for(TInt i = 0; i < actualRectsSize; i++)
sl@0
   935
            {
sl@0
   936
            rectsBuffer[i] = KMarker;
sl@0
   937
            }
sl@0
   938
        }
sl@0
   939
    EGLBoolean collapse = (si.iFlags & EUseCollapseArea)?EGL_TRUE:EGL_FALSE;
sl@0
   940
    EGLint ret = EglEndpoint().GetEndpointDirtyArea(dpy, endpoint, rects, si.iArg1, si.iArg2, collapse);
sl@0
   941
    if (!(si.iFlags & EExpectFailureMask))
sl@0
   942
        {
sl@0
   943
        if (rectsBuffer)
sl@0
   944
            {
sl@0
   945
            TInt rectsIndex = si.iImageIndex;  // ImageIndex is used for rects!
sl@0
   946
            const TSurfaceParamsRemote &surfParams = aParams.iEndpointEngine.iSurfaceParams;
sl@0
   947
            // TODO: If the surface has been downscaled, we need to modify this rectangle.
sl@0
   948
            // We can only know if it's downsampled by getting the image, converting to a VGImage,
sl@0
   949
            // and getting the size of the VGImage. It can be done, but we would need to make
sl@0
   950
            // sure the imageindex matches the endpointindex, as imageindex is used by the
sl@0
   951
            // rectsindex (above).
sl@0
   952
            TRect surfaceRect = TRect(0, 0, surfParams.iCommonParams.iXSize-1, surfParams.iCommonParams.iYSize-1);
sl@0
   953
            DoCheckRectsL(rectsBuffer, ret, si.iArg2, rectsIndex, surfaceRect);
sl@0
   954
            }
sl@0
   955
        }
sl@0
   956
    if (rectsBuffer)
sl@0
   957
        {
sl@0
   958
        CleanupStack::PopAndDestroy(rectsBuffer);
sl@0
   959
        }
sl@0
   960
    if (ret != 0 || (si.iFlags & EExpectFailureMask))
sl@0
   961
        {
sl@0
   962
        CHECK_RETURN(ret, EGL_FALSE, _S("eglGetEndpointDirtyArea"));
sl@0
   963
        }
sl@0
   964
    }
sl@0
   965
sl@0
   966
sl@0
   967
TInt CEgltest_Remote_Engine::LoadHeapMemory(TAny *aSelf)
sl@0
   968
    {
sl@0
   969
    CEgltest_Remote_Engine* self = reinterpret_cast<CEgltest_Remote_Engine*>(aSelf);
sl@0
   970
    User::SwitchHeap(self->iMainThreadHeap);
sl@0
   971
    CTrapCleanup *cleanUpStack = CTrapCleanup::New();
sl@0
   972
    if (!cleanUpStack)
sl@0
   973
       {
sl@0
   974
       // Can't use INFO_PRINTF here, as we have not yet
sl@0
   975
       // created the logger object - nor can we until we have
sl@0
   976
       // a working cleanupstack, so we just do our best at a 
sl@0
   977
       // reasonable error message.
sl@0
   978
       RDebug::Printf("Could not allocate memory for cleanupStack!");
sl@0
   979
       User::Panic(_L("LoadThread"), __LINE__);
sl@0
   980
       return KErrNoMemory;
sl@0
   981
       }
sl@0
   982
sl@0
   983
    TRAPD(err, self->LoadHeapMemoryL());
sl@0
   984
    delete cleanUpStack;
sl@0
   985
    if (err != KErrNone)
sl@0
   986
        {
sl@0
   987
        RDebug::Printf("LoadThreadL left with %d", err);
sl@0
   988
        User::Panic(_L("LoadThread"), __LINE__);
sl@0
   989
        }
sl@0
   990
    return err;    
sl@0
   991
    }
sl@0
   992
sl@0
   993
sl@0
   994
void CEgltest_Remote_Engine::LoadHeapMemoryL()
sl@0
   995
    {
sl@0
   996
    const TInt KMaxAllocs = 40000;
sl@0
   997
    char **ptr = new char*[KMaxAllocs];
sl@0
   998
    TInt nAllocs = 0;
sl@0
   999
    while(!__e32_atomic_load_acq32(&iStopThreadFlag[EThreadLoadHeapMemory]))
sl@0
  1000
        {
sl@0
  1001
        char *p = new char[1000];
sl@0
  1002
        if (p)
sl@0
  1003
            {
sl@0
  1004
            if (nAllocs >= KMaxAllocs)
sl@0
  1005
                {
sl@0
  1006
                User::Panic(_L("KMaxAllocs"), -3);
sl@0
  1007
                }
sl@0
  1008
            ptr[nAllocs++] = p;
sl@0
  1009
            }
sl@0
  1010
        else
sl@0
  1011
            {
sl@0
  1012
            RDebug::Printf("Memory full after %d allocations - freeing some", nAllocs);
sl@0
  1013
            // Now release 1/4 of the allocations...
sl@0
  1014
            TInt nRelease = nAllocs / 4;
sl@0
  1015
            for(int i = 0; i < nRelease; i++)
sl@0
  1016
                {
sl@0
  1017
                // Decrement first, then use as index.
sl@0
  1018
                delete [] ptr[--nAllocs];
sl@0
  1019
                }
sl@0
  1020
            User::After(10 * 1000);   // Let others run for a bit
sl@0
  1021
            }
sl@0
  1022
        }
sl@0
  1023
    // Done - let's deallocate.
sl@0
  1024
    while(nAllocs)
sl@0
  1025
        {
sl@0
  1026
        delete [] ptr[--nAllocs];
sl@0
  1027
        }
sl@0
  1028
    delete [] ptr;
sl@0
  1029
    eglReleaseThread();
sl@0
  1030
    }
sl@0
  1031
sl@0
  1032
sl@0
  1033
TInt CEgltest_Remote_Engine::LoadGpuMemory(TAny* aSelf)
sl@0
  1034
    { 
sl@0
  1035
    CEgltest_Remote_Engine* self = reinterpret_cast<CEgltest_Remote_Engine*>(aSelf);
sl@0
  1036
    CTrapCleanup *cleanUpStack = CTrapCleanup::New();
sl@0
  1037
    if (!cleanUpStack)
sl@0
  1038
       {
sl@0
  1039
       // Can't use INFO_PRINTF here, as we have not yet
sl@0
  1040
       // created the logger object - nor can we until we have
sl@0
  1041
       // a working cleanupstack, so we just do our best at a 
sl@0
  1042
       // reasonable error message.
sl@0
  1043
       RDebug::Printf("Could not allocate memory for cleanupStack!");
sl@0
  1044
       User::Panic(_L("LoadThread"), __LINE__);
sl@0
  1045
       return KErrNoMemory;
sl@0
  1046
       }
sl@0
  1047
sl@0
  1048
    TRAPD(err, self->LoadGpuMemoryL());
sl@0
  1049
    delete cleanUpStack;
sl@0
  1050
    if (err != KErrNone)
sl@0
  1051
        {
sl@0
  1052
        RDebug::Printf("LoadThreadL left with %d", err);
sl@0
  1053
        User::Panic(_L("LoadThread"), __LINE__);
sl@0
  1054
        }
sl@0
  1055
    return err;
sl@0
  1056
    }
sl@0
  1057
sl@0
  1058
sl@0
  1059
void CEgltest_Remote_Engine::LoadGpuMemoryL()
sl@0
  1060
    {
sl@0
  1061
    const TInt KMaxSurfaceAllocs = 1000;
sl@0
  1062
    CSurface **surfaces = new CSurface*[KMaxSurfaceAllocs];
sl@0
  1063
    ENGINE_ASSERT(surfaces);
sl@0
  1064
    TInt nSurfaces = 0;
sl@0
  1065
    while(!__e32_atomic_load_acq32(&iStopThreadFlag[EThreadLoadGpuMemory]))     
sl@0
  1066
        {
sl@0
  1067
        ENGINE_ASSERT(nSurfaces < KMaxSurfaceAllocs);
sl@0
  1068
        CSurface* s = CSurface::SurfaceFactoryL(ESurfTypePBuffer);
sl@0
  1069
        if (s)
sl@0
  1070
            {
sl@0
  1071
            TRAPD(err, s->CreateL(ELargeSurface));
sl@0
  1072
            if (err == KErrNone)
sl@0
  1073
                {
sl@0
  1074
                if (nSurfaces >= KMaxSurfaceAllocs)
sl@0
  1075
                    {
sl@0
  1076
                    User::Panic(_L("KMaxAllocs"), -3);
sl@0
  1077
                    }
sl@0
  1078
                surfaces[nSurfaces++] = s;
sl@0
  1079
                s->DrawContentL(TRgb(0x10, 0x20, 0xB0));
sl@0
  1080
                }
sl@0
  1081
            else
sl@0
  1082
                {
sl@0
  1083
                delete s;
sl@0
  1084
                s = NULL;
sl@0
  1085
                }
sl@0
  1086
            }
sl@0
  1087
        if (!s)
sl@0
  1088
            {
sl@0
  1089
            User::After(100 * 1000);
sl@0
  1090
            TInt nRelease = nSurfaces / 4;
sl@0
  1091
            for(TInt i = 0; i < nRelease; i++)
sl@0
  1092
                {
sl@0
  1093
                delete surfaces[--nSurfaces];
sl@0
  1094
                surfaces[nSurfaces] = NULL;
sl@0
  1095
                }
sl@0
  1096
            User::After(100 * 1000); // 100 ms. 
sl@0
  1097
            }
sl@0
  1098
        }
sl@0
  1099
    while(nSurfaces)
sl@0
  1100
        {
sl@0
  1101
        delete surfaces[--nSurfaces];
sl@0
  1102
        }
sl@0
  1103
    delete [] surfaces;
sl@0
  1104
    eglReleaseThread();
sl@0
  1105
    }
sl@0
  1106
sl@0
  1107
sl@0
  1108
sl@0
  1109
TThreadFunction CEgltest_Remote_Engine::GetThreadFunction(TInt aThreadNumber)
sl@0
  1110
    {
sl@0
  1111
    switch(aThreadNumber)
sl@0
  1112
        {
sl@0
  1113
        case EThreadLoadHeapMemory:
sl@0
  1114
            return LoadHeapMemory;
sl@0
  1115
        case EThreadLoadGpuMemory:
sl@0
  1116
            return LoadGpuMemory;
sl@0
  1117
        }
sl@0
  1118
    RDebug::Printf("%s:%d: Unknown thread function %d", __FILE__, __LINE__, aThreadNumber);
sl@0
  1119
    return NULL;
sl@0
  1120
    }