os/graphics/egl/egltest/src/egltest_stress_sgimage.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
*/
sl@0
    20
sl@0
    21
#include <s32file.h>
sl@0
    22
#include <test/t_simload.h>
sl@0
    23
#include <test/tefunit.h>    //ASSERT_TRUE
sl@0
    24
#include "egltest_stress_sgimage.h"
sl@0
    25
sl@0
    26
TVerdict CEglTest_Stress::doTestStepL()
sl@0
    27
    {
sl@0
    28
    INFO_PRINTF1(_L("CEglTest_Stress:doTestStepL()"));
sl@0
    29
    
sl@0
    30
    TBuf<100> testCaseId;
sl@0
    31
    TestCaseName(testCaseId);
sl@0
    32
    SetTestStepID(testCaseId);
sl@0
    33
sl@0
    34
#ifdef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
sl@0
    35
    __UHEAP_MARK;
sl@0
    36
    
sl@0
    37
    //File server is used to generate simload ini file
sl@0
    38
    User::LeaveIfError(iFs.Connect());
sl@0
    39
  
sl@0
    40
    TBool ret = CheckForExtensionL(KEGL_RSgimage | KEGL_KHR_image_base | KVG_KHR_EGL_image | KEGL_KHR_image_pixmap);
sl@0
    41
    if(!ret)
sl@0
    42
        {
sl@0
    43
        // The extension is not supported
sl@0
    44
        RecordTestResultL();
sl@0
    45
        CloseTMSGraphicsStep();
sl@0
    46
        return TestStepResult();
sl@0
    47
        }
sl@0
    48
sl@0
    49
    //Create a config file and launch the simulated load app
sl@0
    50
    ReadIniValuesL();
sl@0
    51
    PrintConfigDataL();
sl@0
    52
    CreateSimLoadAppL();
sl@0
    53
sl@0
    54
    INFO_PRINTF1(_L("Creating a Semaphore to signal all child processes at once"));
sl@0
    55
    RSemaphore sem;
sl@0
    56
    User::LeaveIfError(sem.CreateGlobal(KEglStressTest(), iNumberChildProcesses));
sl@0
    57
    CleanupClosePushL(sem);
sl@0
    58
sl@0
    59
    //Information to be passed to the child process
sl@0
    60
    TSgImageInfo info;
sl@0
    61
    TSize size(iRSgImageWidth, iRSgImageHeight);
sl@0
    62
    info.iUsage = ESgUsageBitOpenVgImage | ESgUsageBitOpenVgSurface;
sl@0
    63
    info.iPixelFormat = iFormat;
sl@0
    64
    info.iSizeInPixels = size;
sl@0
    65
sl@0
    66
    //Utilise egl helper functions
sl@0
    67
    CreateEglSessionL();
sl@0
    68
    
sl@0
    69
    //Create a display and initialise it
sl@0
    70
    GetDisplayL();
sl@0
    71
    iEglSess->InitializeL();
sl@0
    72
    
sl@0
    73
    //Open RSGImage driver    
sl@0
    74
    iEglSess->OpenSgDriverL();
sl@0
    75
    
sl@0
    76
    EGL_LEAVE_ERROR(eglBindAPI(EGL_OPENVG_API));
sl@0
    77
 
sl@0
    78
    EGLContext context;
sl@0
    79
    for(TInt i=0; i<iNumberRSgImages; i++)
sl@0
    80
        {
sl@0
    81
        RSgImage image;
sl@0
    82
        iSgImageArray.InsertL(image, i);
sl@0
    83
        User::LeaveIfError(iSgImageArray[i].Create(info, NULL, NULL));
sl@0
    84
sl@0
    85
        EGLConfig config;
sl@0
    86
        if(i == 0)
sl@0
    87
            {
sl@0
    88
            //Only need to determine a matching configuration once
sl@0
    89
            ChooseConfigAndCreateContextL(iDisplay, context, config, iSgImageArray[i], KStressTestMainAppPanic, iAlphaPre);
sl@0
    90
            }
sl@0
    91
 
sl@0
    92
        EGLSurface surface = EGL_NO_SURFACE; //remove arm warning
sl@0
    93
        EGL_LEAVE_NULL(surface, CreatePixmapSurfaceL(iDisplay, config, iSgImageArray[i], iAlphaPre));
sl@0
    94
sl@0
    95
        EGL_LEAVE_ERROR(eglMakeCurrent(iDisplay, surface, surface, context));
sl@0
    96
         
sl@0
    97
        PaintSurfaceL(iDisplay, surface, context);
sl@0
    98
        EGL_LEAVE_ERROR(eglSwapBuffers(iDisplay, surface));
sl@0
    99
sl@0
   100
        if(iTestType == EStressVGImage)
sl@0
   101
            {
sl@0
   102
            EGL_LEAVE_ERROR(eglMakeCurrent(iDisplay, surface, surface, context));
sl@0
   103
            
sl@0
   104
            EGLImageKHR eglImage = 0; //removes arm compiler warning
sl@0
   105
            VGImage vgImage;
sl@0
   106
sl@0
   107
            EGL_LEAVE_NULL(eglImage, iEglSess->eglCreateImageKhrL(iDisplay, EGL_NO_CONTEXT, EGL_NATIVE_PIXMAP_KHR, &iSgImageArray[i], (int*)KEglImageAttribsPreservedTrue));
sl@0
   108
            EGL_LEAVE_NULL(vgImage, iEglSess->vgCreateImageTargetKHR(eglImage));
sl@0
   109
sl@0
   110
            //Close the EGLImage
sl@0
   111
            EGL_LEAVE_ERROR(iEglSess->DestroyEGLImage(iDisplay, eglImage));
sl@0
   112
                        
sl@0
   113
            User::LeaveIfError(iVGImageArray.Insert(vgImage, i));
sl@0
   114
            }
sl@0
   115
sl@0
   116
        User::LeaveIfError(iSurfaceArray.Insert(surface, i));
sl@0
   117
        }
sl@0
   118
sl@0
   119
    /* Create and install the active scheduler */
sl@0
   120
    CActiveScheduler* sched = new(ELeave) CActiveScheduler;
sl@0
   121
    CActiveScheduler::Install(sched);
sl@0
   122
    CleanupStack::PushL(sched);
sl@0
   123
sl@0
   124
    TInt exitCounter = iNumberMainImages;
sl@0
   125
    TBool testResult = ETrue;
sl@0
   126
sl@0
   127
    //Create an active object for each RSgImage accessed in the main process
sl@0
   128
    CTReadWriteMain* painter = 0;
sl@0
   129
    for(TInt i=0; i<iNumberMainImages; i++)
sl@0
   130
        {
sl@0
   131
        if(iTestType == EStressVGImage)
sl@0
   132
            {
sl@0
   133
            painter = CTReadWriteMain::NewL(iDisplay, iSurfaceArray[i], context, iRSgImageWidth, iRSgImageHeight, iByteSize, iVgFormat, testResult, exitCounter, iTestType, iVGImageArray[i]);
sl@0
   134
            }
sl@0
   135
        else
sl@0
   136
            {
sl@0
   137
            painter = CTReadWriteMain::NewL(iDisplay, iSurfaceArray[i], context, iRSgImageWidth, iRSgImageHeight, iByteSize, iVgFormat, testResult, exitCounter, iTestType);            
sl@0
   138
            }
sl@0
   139
            
sl@0
   140
        CleanupStack::PushL(painter);
sl@0
   141
        painter->After(TTimeIntervalMicroSeconds32(0));
sl@0
   142
        }
sl@0
   143
sl@0
   144
    CreateChildProcessesL();
sl@0
   145
sl@0
   146
    INFO_PRINTF1(_L("Signaling all child processes at once - starts data access in the child processes"));
sl@0
   147
    sem.Signal(iNumberChildProcesses);
sl@0
   148
sl@0
   149
    //Start the active scheduler - starts data access in the main process
sl@0
   150
    sched->Start();
sl@0
   151
sl@0
   152
    if(testResult == EFalse)
sl@0
   153
        {
sl@0
   154
		if (iTestType == EStressReadWriteSingleImage || iTestType == EStressReadWriteMultiImage)
sl@0
   155
			{
sl@0
   156
			// For GRAPHICS-EGL-0428 and GRAPHICS-EGL-0437 data integrity cannot be guaranteed on 
sl@0
   157
			// all implementations, so the pixel value checking aspects of these tests are regarded as optional   
sl@0
   158
			WARN_PRINTF1(_L("Unexpected pixel colour"));
sl@0
   159
			}
sl@0
   160
		else
sl@0
   161
			{
sl@0
   162
			ERR_PRINTF1(_L("Unexpected pixel colour"));
sl@0
   163
			SetTestStepResult(EFail);
sl@0
   164
			}
sl@0
   165
        }
sl@0
   166
sl@0
   167
    //Check that each child process has completed without error
sl@0
   168
    for(TInt i=0; i<iNumberChildProcesses; i++)
sl@0
   169
       {
sl@0
   170
       TRequestStatus status;
sl@0
   171
       iProcessArray[i].Logon(status);
sl@0
   172
       User::WaitForRequest(status);
sl@0
   173
sl@0
   174
       if(status != KErrNone)
sl@0
   175
           {
sl@0
   176
		   if (status == KTestStressUnexpectedPixelError && (iTestType == EStressReadWriteSingleImage || iTestType == EStressReadWriteMultiImage))
sl@0
   177
			   {
sl@0
   178
			   // For GRAPHICS-EGL-0428 and GRAPHICS-EGL-0437 data integrity cannot be guaranteed on 
sl@0
   179
			   // all implementations, so the pixel value checking aspects of these tests are regarded as optional
sl@0
   180
			   // So check that if it fails, it fails for the expected reason of no matching pixel.
sl@0
   181
			   WARN_PRINTF2(_L("Child Process completed with code %d, expected KErrNone"), status.Int());
sl@0
   182
			   }
sl@0
   183
		   else
sl@0
   184
			   {
sl@0
   185
			   ERR_PRINTF2(_L("Child Process completed with code %d, expected KErrNone"), status.Int());
sl@0
   186
			   SetTestStepResult(EFail);
sl@0
   187
			   }
sl@0
   188
           }
sl@0
   189
       }
sl@0
   190
sl@0
   191
    DestroySimLoadProcess();
sl@0
   192
    DeleteConfigData();
sl@0
   193
    ClearDownArraysL(iDisplay);
sl@0
   194
    EGL_LEAVE_ERROR(eglDestroyContext(iDisplay, context));
sl@0
   195
sl@0
   196
    CleanupStack::PopAndDestroy(iNumberMainImages + 2, &sem); //(iNumberMainImages + 1) active objects, sched, sem
sl@0
   197
    iEglSess->CloseSgDriver();
sl@0
   198
    
sl@0
   199
    CleanAll();
sl@0
   200
    iFs.Close();
sl@0
   201
sl@0
   202
    __UHEAP_MARKEND;
sl@0
   203
sl@0
   204
#else
sl@0
   205
    INFO_PRINTF2(_L("%S can only be run with SgImage-Lite"), &testCaseId);
sl@0
   206
#endif //SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
sl@0
   207
    
sl@0
   208
    //Comply with the terrific TMS
sl@0
   209
    RecordTestResultL();
sl@0
   210
    CloseTMSGraphicsStep();
sl@0
   211
sl@0
   212
    return TestStepResult();
sl@0
   213
    }
sl@0
   214
sl@0
   215
CEglTest_Stress::~CEglTest_Stress()
sl@0
   216
    {
sl@0
   217
    //Free memory and close handles in case of panic in the doTestStepL()
sl@0
   218
    delete iEglSess;
sl@0
   219
    
sl@0
   220
    iFs.Close();
sl@0
   221
    iSurfaceArray.Close();
sl@0
   222
    iProcessArray.Close();
sl@0
   223
    iSgImageArray.Close();
sl@0
   224
    iVGImageArray.Close();
sl@0
   225
    }
sl@0
   226
sl@0
   227
void CEglTest_Stress::PaintSurfaceL(EGLDisplay aDisplay, EGLSurface aSurface, EGLContext aContext)
sl@0
   228
    {
sl@0
   229
    //Clear surface background, format of the constant is ARGB
sl@0
   230
    //Match the colour to that of the defined constant
sl@0
   231
    VGfloat red = 0.0;
sl@0
   232
    VGfloat green = 0.0;
sl@0
   233
    VGfloat blue = 0.0;
sl@0
   234
    VGfloat alpha = 0.0;
sl@0
   235
    
sl@0
   236
    //Care taken to avoid fixed width -> floating point -> fixed width rounding errors
sl@0
   237
    if(iByteSize == 4)
sl@0
   238
        {
sl@0
   239
        red = 1.0 * ((KColourInitial32 & 0x00FF0000) >> 16)/255;
sl@0
   240
        green = 1.0 * ((KColourInitial32 & 0x0000FF00) >> 8)/255;
sl@0
   241
        blue = 1.0 * (KColourInitial32 & 0x000000FF)/255;
sl@0
   242
        alpha = 1.0 * ((KColourInitial32 & 0xFF000000) >> 24)/255;        
sl@0
   243
        }
sl@0
   244
    else //iByteSize == 2
sl@0
   245
        {
sl@0
   246
        red = 1.0 * ((KColourInitial16 & 0x7C00) >> 11)/31;
sl@0
   247
        green = 1.0 * ((KColourInitial16 & 0x0480) >> 5)/63;
sl@0
   248
        blue = 1.0 * (KColourInitial16 & 0x001F)/31;
sl@0
   249
        }
sl@0
   250
sl@0
   251
    //Format of the constant is RGBA (32 bit) 
sl@0
   252
    VGfloat bgColor[] = {red, green, blue, alpha};
sl@0
   253
sl@0
   254
    EGL_LEAVE_ERROR(eglMakeCurrent(aDisplay, aSurface, aSurface, aContext));
sl@0
   255
 
sl@0
   256
    vgSetfv(VG_CLEAR_COLOR, 4, bgColor);
sl@0
   257
    ASSERT_VG_TRUE(vgGetError() == VG_NO_ERROR);
sl@0
   258
    vgClear(0, 0, iRSgImageWidth, iRSgImageHeight);
sl@0
   259
    ASSERT_VG_TRUE(vgGetError() == VG_NO_ERROR);
sl@0
   260
    }
sl@0
   261
sl@0
   262
void CEglTest_Stress::CreateChildProcessL(TInt aProcessNumber, TTestType aTestType, TSgDrawableId aDrawableId)
sl@0
   263
    {
sl@0
   264
    TRequestStatus status;
sl@0
   265
    RProcess client;
sl@0
   266
    User::LeaveIfError(client.Create(KStressTestClientApp, KNullDesC));
sl@0
   267
sl@0
   268
    //Pass image and test information to the child process
sl@0
   269
    TStressProcessInfo info;
sl@0
   270
    info.iTestType = aTestType;
sl@0
   271
    info.iSgId = aDrawableId;
sl@0
   272
    info.iByteSize = iByteSize;
sl@0
   273
    info.iAlphaPre = iAlphaPre;
sl@0
   274
sl@0
   275
    TPckg<TStressProcessInfo> pckgInfo(info);
sl@0
   276
    User::LeaveIfError((client.SetParameter(KMultiProcessSlot, pckgInfo)));
sl@0
   277
sl@0
   278
    client.Rendezvous(status);
sl@0
   279
    client.Resume();
sl@0
   280
    User::WaitForRequest(status);
sl@0
   281
    TEST(status == KErrNone);
sl@0
   282
sl@0
   283
    //Store image handle for cleanup
sl@0
   284
    iProcessArray.InsertL(client, aProcessNumber);
sl@0
   285
    }
sl@0
   286
sl@0
   287
void CEglTest_Stress::CreateChildProcessesL()
sl@0
   288
    {
sl@0
   289
    for(TInt i=0; i<iNumberChildProcesses; i++)
sl@0
   290
        {
sl@0
   291
        switch(iTestType)
sl@0
   292
            {
sl@0
   293
            case EStressReadWriteMultiImage:
sl@0
   294
            case EStressPixmapSurface:
sl@0
   295
                {
sl@0
   296
                //Each child process accesses one SgImage
sl@0
   297
                CreateChildProcessL(i, iTestType, iSgImageArray[i].Id());
sl@0
   298
                break;
sl@0
   299
                }
sl@0
   300
            case EStressRead:
sl@0
   301
            case EStressReadWriteSingleImage:
sl@0
   302
            case EStressVGImage:
sl@0
   303
                {
sl@0
   304
                //All child processes access the same SgImage
sl@0
   305
                CreateChildProcessL(i, iTestType, iSgImageArray[0].Id());
sl@0
   306
                break;
sl@0
   307
                }
sl@0
   308
            default:
sl@0
   309
                User::Panic(KStressTestMainAppPanic, KErrNotFound);
sl@0
   310
                break;
sl@0
   311
            }
sl@0
   312
        }
sl@0
   313
    }
sl@0
   314
sl@0
   315
void CEglTest_Stress::ClearDownArraysL(EGLDisplay aDisplay)
sl@0
   316
    {
sl@0
   317
    for(TInt i=0; i<iSurfaceArray.Count(); i++)
sl@0
   318
        {
sl@0
   319
        ASSERT_EGL_TRUE(eglDestroySurface(aDisplay, iSurfaceArray[i]));
sl@0
   320
        }
sl@0
   321
    
sl@0
   322
    for(TInt i=0; i<iVGImageArray.Count(); i++)
sl@0
   323
        {
sl@0
   324
        vgDestroyImage(iVGImageArray[i]);
sl@0
   325
        ASSERT_VG_TRUE(vgGetError() == VG_NO_ERROR);
sl@0
   326
        }
sl@0
   327
    
sl@0
   328
    for(TInt i=0; i<iProcessArray.Count(); i++)
sl@0
   329
        {
sl@0
   330
        iProcessArray[i].Close();
sl@0
   331
        }
sl@0
   332
sl@0
   333
    for(TInt i=0; i<iSgImageArray.Count(); i++)
sl@0
   334
        {
sl@0
   335
        iSgImageArray[i].Close();
sl@0
   336
        }
sl@0
   337
    
sl@0
   338
    iSurfaceArray.Close();
sl@0
   339
    iProcessArray.Close();
sl@0
   340
    iSgImageArray.Close();
sl@0
   341
    iVGImageArray.Close();
sl@0
   342
    }
sl@0
   343
sl@0
   344
void CEglTest_Stress::CreateSimLoadAppL()
sl@0
   345
    {
sl@0
   346
    TInt index = 1;
sl@0
   347
    TBuf<100> tempStore;
sl@0
   348
sl@0
   349
    //Three simload processes need to be launched t_simloadapp1.exe - t_simloadapp3.exe
sl@0
   350
    while(index <= KNumSimLoadApps)
sl@0
   351
        {
sl@0
   352
        tempStore.Format(KSimLoadApp, index++);
sl@0
   353
        CreateSimLoadProcessL(tempStore);
sl@0
   354
        }
sl@0
   355
    }
sl@0
   356
sl@0
   357
void CEglTest_Stress::CreateSimLoadProcessL(const TDesC& aApp)
sl@0
   358
    {
sl@0
   359
    INFO_PRINTF2(_L("Starting App: %S"), &aApp);
sl@0
   360
sl@0
   361
    RProcess process;
sl@0
   362
    User::LeaveIfError(process.Create(aApp, KNullDesC));
sl@0
   363
sl@0
   364
    //Give the simulated load high priority to be sure it does its job
sl@0
   365
    process.SetPriority(EPriorityHigh);
sl@0
   366
    TEST(process.Priority() == EPriorityHigh);
sl@0
   367
    INFO_PRINTF3(_L("Process Priority: Actual: %d, Expected: %d"), process.Priority(), EPriorityHigh);
sl@0
   368
    process.Resume();
sl@0
   369
    
sl@0
   370
    iProcessList.AppendL(process);
sl@0
   371
    }
sl@0
   372
sl@0
   373
void CEglTest_Stress::DestroySimLoadProcess()
sl@0
   374
    {
sl@0
   375
    for (TInt index = 0; index < iProcessList.Count(); index++)
sl@0
   376
        {
sl@0
   377
        // check process
sl@0
   378
        INFO_PRINTF3(_L("Process Check: Actual: %d, Expected: %d"), iProcessList[index].ExitReason(), KErrNone);
sl@0
   379
        TEST(iProcessList[index].ExitReason( )== KErrNone);
sl@0
   380
sl@0
   381
        // kill process
sl@0
   382
        iProcessList[index].Kill(KErrGeneral);
sl@0
   383
        INFO_PRINTF3(_L("Process Exit Reason: Actual: %d, Expected: %d"), iProcessList[index].ExitReason(), KErrGeneral);
sl@0
   384
        TEST(iProcessList[index].ExitReason() == KErrGeneral);
sl@0
   385
sl@0
   386
        iProcessList[index].Close();
sl@0
   387
        }
sl@0
   388
sl@0
   389
    iProcessList.Close();
sl@0
   390
    }
sl@0
   391
sl@0
   392
void CEglTest_Stress::ReadIniValueL(const TDesC& aSectName, const TDesC& aKeyName, TInt& aResult)
sl@0
   393
    {
sl@0
   394
    if(!GetIntFromConfig(aSectName, aKeyName, aResult))
sl@0
   395
        {
sl@0
   396
        ERR_PRINTF2(_L("Error reading %S value from ini file"), &aKeyName);
sl@0
   397
        User::Leave(KErrNotFound);
sl@0
   398
        }
sl@0
   399
sl@0
   400
    INFO_PRINTF3(_L("Ini file value %S = %d"), &aKeyName, aResult);
sl@0
   401
    }
sl@0
   402
sl@0
   403
void CEglTest_Stress::ReadIniValuesL()
sl@0
   404
    {
sl@0
   405
    ReadIniValueL(ConfigSection(), KNumberRSgImages, iNumberRSgImages);
sl@0
   406
    ReadIniValueL(ConfigSection(), KNumberMainImages, iNumberMainImages);
sl@0
   407
    ReadIniValueL(ConfigSection(), KNumberChildProcesses, iNumberChildProcesses);
sl@0
   408
    ReadIniValueL(ConfigSection(), KRSgImageWidth, iRSgImageWidth);
sl@0
   409
    ReadIniValueL(ConfigSection(), KRSgImageHeight, iRSgImageHeight);
sl@0
   410
    ReadIniValueL(ConfigSection(), KConfigSimLoadValue, iSimLoadValue);
sl@0
   411
    
sl@0
   412
    //Check for erroneous ini values
sl@0
   413
    ASSERT_TRUE(iNumberChildProcesses <= iNumberRSgImages);
sl@0
   414
    ASSERT_TRUE(iNumberMainImages <= iNumberRSgImages);
sl@0
   415
    ASSERT_TRUE(iRSgImageWidth >= 0);
sl@0
   416
    ASSERT_TRUE(iRSgImageHeight >= 0);
sl@0
   417
    ASSERT_TRUE(iSimLoadValue >= 0);
sl@0
   418
    ASSERT_TRUE(iSimLoadValue <= 100);
sl@0
   419
    
sl@0
   420
    TBuf16<100> buffer;
sl@0
   421
    TPtrC16 ptrBuffer(buffer);
sl@0
   422
    if(!GetStringFromConfig(ConfigSection(), KPixelFormat, ptrBuffer))
sl@0
   423
        {
sl@0
   424
        ERR_PRINTF2(_L("Error reading %S value from ini file"), &KPixelFormat);
sl@0
   425
        User::Leave(KErrNotFound);
sl@0
   426
        }
sl@0
   427
sl@0
   428
    INFO_PRINTF3(_L("Ini file value %S = %S"), &KPixelFormat, &ptrBuffer);
sl@0
   429
sl@0
   430
    //Derive information from the pixel format
sl@0
   431
    if(ptrBuffer == KUidPixelFormatARGB_8888)
sl@0
   432
        {
sl@0
   433
        iFormat = EUidPixelFormatARGB_8888;
sl@0
   434
        iVgFormat = VG_sARGB_8888;
sl@0
   435
        iAlphaPre = EFalse;
sl@0
   436
        iByteSize = 4;
sl@0
   437
        }
sl@0
   438
    else if(ptrBuffer == KUidPixelFormatARGB_8888_PRE)
sl@0
   439
        {
sl@0
   440
        iFormat = EUidPixelFormatARGB_8888_PRE;
sl@0
   441
        iVgFormat = VG_sARGB_8888_PRE;
sl@0
   442
        iAlphaPre = ETrue;
sl@0
   443
        iByteSize = 4;
sl@0
   444
        }
sl@0
   445
    else if(ptrBuffer == KUidPixelFormatRGB_565)
sl@0
   446
        {
sl@0
   447
        iFormat = EUidPixelFormatRGB_565;
sl@0
   448
        iVgFormat = VG_sRGB_565;
sl@0
   449
        iAlphaPre = EFalse;
sl@0
   450
        iByteSize = 2;
sl@0
   451
        }
sl@0
   452
    else
sl@0
   453
        {
sl@0
   454
        ERR_PRINTF2(_L("Unsupported pixel format %S"), &ptrBuffer);
sl@0
   455
        User::Leave(KErrNotFound);
sl@0
   456
        }
sl@0
   457
sl@0
   458
     //Determine the test type from the ini file section name
sl@0
   459
     if(ConfigSection().Find(KStressReadOnly) != KErrNotFound)
sl@0
   460
         {
sl@0
   461
         iTestType = EStressRead;
sl@0
   462
         }
sl@0
   463
     else if(ConfigSection().Find(KEStressReadWriteSingleImage) != KErrNotFound)
sl@0
   464
         {
sl@0
   465
         iTestType = EStressReadWriteSingleImage;
sl@0
   466
         }
sl@0
   467
     else if(ConfigSection().Find(KStressReadWriteMultiImage) != KErrNotFound)
sl@0
   468
         {
sl@0
   469
         iTestType = EStressReadWriteMultiImage;
sl@0
   470
         }
sl@0
   471
     else if(ConfigSection().Find(KStressVGImage) != KErrNotFound)
sl@0
   472
         {
sl@0
   473
         iTestType = EStressVGImage;
sl@0
   474
         }
sl@0
   475
     else if(ConfigSection().Find(KStressPixmapSurface) != KErrNotFound)
sl@0
   476
         {
sl@0
   477
         iTestType = EStressPixmapSurface;
sl@0
   478
         }
sl@0
   479
     else
sl@0
   480
         {
sl@0
   481
         ERR_PRINTF2(_L("Unknown test case %S"), &ptrBuffer);
sl@0
   482
         User::Leave(KErrNotFound);
sl@0
   483
         }
sl@0
   484
    }
sl@0
   485
sl@0
   486
/** 
sl@0
   487
 *   This function generates an ini file for the simulated load application
sl@0
   488
 *   containing two lines to determine
sl@0
   489
 *   1. The type of load (static or spiked, in this case always static)
sl@0
   490
 *   2. The simulated load level
sl@0
   491
 */
sl@0
   492
void CEglTest_Stress::PrintConfigDataL()
sl@0
   493
    {
sl@0
   494
    RFileWriteStream writer;
sl@0
   495
    writer.PushL();
sl@0
   496
sl@0
   497
    TInt err = iFs.MkDirAll(KSimLoadConfigFile);
sl@0
   498
    TEST(err == KErrNone || err == KErrAlreadyExists);
sl@0
   499
    INFO_PRINTF2(_L("Create Config File: %S"), &KSimLoadConfigFile);
sl@0
   500
    User::LeaveIfError(writer.Replace(iFs, KSimLoadConfigFile, EFileStreamText|EFileWrite));
sl@0
   501
    writer.CommitL();
sl@0
   502
sl@0
   503
    CleanupStack::PopAndDestroy(&writer);
sl@0
   504
sl@0
   505
    CIniData* data=CIniData::NewL(KSimLoadConfigFile);
sl@0
   506
    CleanupStack::PushL(data);
sl@0
   507
sl@0
   508
    INFO_PRINTF3(_L("Config Name: %S, \t\tConfig Data: %S"), &KConfigSimLoadType, &KConfigSimLoadStatic);
sl@0
   509
    err = data->AddValue(KDefaultSectionName, KConfigSimLoadType, KConfigSimLoadStatic);
sl@0
   510
    INFO_PRINTF3(_L("AddValue - Expected: %d, Actual: %d"), KErrNone, err);
sl@0
   511
    TEST(err == KErrNone);
sl@0
   512
sl@0
   513
    TBuf16<100> buffer;
sl@0
   514
    TPtrC16 ptrBuffer(buffer);
sl@0
   515
    User::LeaveIfError(GetStringFromConfig(ConfigSection(), KConfigSimLoadValue, ptrBuffer));
sl@0
   516
sl@0
   517
    INFO_PRINTF3(_L("Config Name: %S, \t\tConfig Data: %S"), &KConfigSimLoadValue, &ptrBuffer);
sl@0
   518
    err = data->AddValue(KDefaultSectionName, KConfigSimLoadValue, ptrBuffer);
sl@0
   519
sl@0
   520
    INFO_PRINTF3(_L("AddValue - Expected: %d, Actual: %d"), KErrNone, err);
sl@0
   521
    TEST(err == KErrNone);
sl@0
   522
sl@0
   523
    data->WriteToFileL();
sl@0
   524
    CleanupStack::PopAndDestroy(data);
sl@0
   525
    }
sl@0
   526
sl@0
   527
void CEglTest_Stress::DeleteConfigData()
sl@0
   528
    {
sl@0
   529
    INFO_PRINTF2(_L("Deleting Config File Name: %S"), &KSimLoadConfigFile);
sl@0
   530
    TInt err = iFs.Delete(KSimLoadConfigFile);
sl@0
   531
    TEST(err==KErrNone);
sl@0
   532
    }
sl@0
   533
sl@0
   534
/**
sl@0
   535
 *    class CTReadWriteMain
sl@0
   536
 *    A Child of CTReadWrite which contains member data not included in the base class and 
sl@0
   537
 *    implementations of pure virtual functions.
sl@0
   538
 *    a) One for each particular test case
sl@0
   539
 *    b) Support functions MakeCurrentL() and IsFinished()
sl@0
   540
 *    
sl@0
   541
 *    The base class is an active object and the implemented virtual functions are invoked
sl@0
   542
 *    indirectly from the RunL() function
sl@0
   543
 */
sl@0
   544
CTReadWriteMain::CTReadWriteMain(EGLDisplay aDisplay, EGLSurface aSurface, EGLContext aContext, TInt aWidth, TInt aHeight, TInt aByteSize, VGImageFormat aFormat, TBool& aTestPass, TInt& aFinishedCounter, const TTestType& aTestType)
sl@0
   545
: CTReadWrite(aWidth, aHeight, aByteSize, aFormat, aTestType, aTestPass),
sl@0
   546
    iDisplay(aDisplay),
sl@0
   547
    iSurface(aSurface),
sl@0
   548
    iContext(aContext),
sl@0
   549
    iFinishedCounter(aFinishedCounter)
sl@0
   550
    {
sl@0
   551
    }
sl@0
   552
sl@0
   553
CTReadWriteMain* CTReadWriteMain::NewL(EGLDisplay aDisplay, EGLSurface aSurface, EGLContext aContext, TInt aWidth, TInt aHeight, TInt aByteSize, VGImageFormat aFormat, TBool& aTestPass, TInt& aFinishedCounter, const TTestType& aTestType, VGImage aVGImage)
sl@0
   554
    {
sl@0
   555
    CTReadWriteMain* self = new (ELeave) CTReadWriteMain(aDisplay, aSurface, aContext, aWidth, aHeight, aByteSize, aFormat, aTestPass, aFinishedCounter, aTestType);
sl@0
   556
    CleanupStack::PushL(self);
sl@0
   557
    self->ConstructL(aVGImage);
sl@0
   558
    CleanupStack::Pop(self);
sl@0
   559
    return self;
sl@0
   560
    }
sl@0
   561
sl@0
   562
void CTReadWriteMain::ConstructL(VGImage aVGImage)
sl@0
   563
    {
sl@0
   564
    //NULL values indicate a programming error
sl@0
   565
    if( (iDisplay == EGL_NO_DISPLAY) || (iSurface == EGL_NO_SURFACE) || (iContext == EGL_NO_CONTEXT) || (iFinishedCounter == 0) || ((iTestType == EStressVGImage) && (aVGImage == NULL)) )
sl@0
   566
        {
sl@0
   567
        User::Leave(KErrArgument);
sl@0
   568
        }
sl@0
   569
    
sl@0
   570
    iVGImage = aVGImage;
sl@0
   571
    
sl@0
   572
    //Call base class function to complete construction
sl@0
   573
     CTReadWrite::ConstructL();
sl@0
   574
    }
sl@0
   575
sl@0
   576
void CTReadWriteMain::MakeCurrentL() const
sl@0
   577
    {
sl@0
   578
    EGL_LEAVE_ERROR(eglMakeCurrent(iDisplay, iSurface, iSurface, iContext));
sl@0
   579
    }
sl@0
   580
sl@0
   581
void CTReadWriteMain::ReadImageFuncL()
sl@0
   582
    {
sl@0
   583
    vgReadPixels(iData, iWidth*iByteSize, iFormat, 0, 0, iWidth, iHeight);
sl@0
   584
    VgLeaveIfErrorL();
sl@0
   585
    }
sl@0
   586
sl@0
   587
void CTReadWriteMain::ReadFuncL()
sl@0
   588
    {
sl@0
   589
    ReadImageFuncL();
sl@0
   590
    }
sl@0
   591
sl@0
   592
void CTReadWriteMain::WriteImageFuncL()
sl@0
   593
    {
sl@0
   594
    vgWritePixels(iData, iWidth*iByteSize, iFormat, 0, 0, iWidth, iHeight);
sl@0
   595
    VgLeaveIfErrorL();
sl@0
   596
    }
sl@0
   597
sl@0
   598
TBool CTReadWriteMain::IsFinished()
sl@0
   599
    {
sl@0
   600
    iFinishedCounter--;
sl@0
   601
sl@0
   602
    if(iFinishedCounter <= 0)
sl@0
   603
        {
sl@0
   604
        return ETrue;
sl@0
   605
        }
sl@0
   606
sl@0
   607
    return EFalse;
sl@0
   608
    }
sl@0
   609
sl@0
   610
void CTReadWriteMain::VgImageFuncL()
sl@0
   611
    {
sl@0
   612
    //Alter the image data, actual pixel values are not important
sl@0
   613
    for(TInt i=0; i<iBufferSize; i++)
sl@0
   614
        {
sl@0
   615
        const TUint32 temp = iBufferSize % iFrameNumber;
sl@0
   616
        iData[i] = temp + (temp << 8) + (temp << 16) + (temp << 24);
sl@0
   617
        }
sl@0
   618
    
sl@0
   619
    //Currently panics as context->scanlinebuffer is NULL
sl@0
   620
    vgImageSubData(iVGImage, iData, iWidth*iByteSize, iFormat, 0, 0, iWidth, iHeight);
sl@0
   621
    VgLeaveIfErrorL();
sl@0
   622
    
sl@0
   623
    EGL_LEAVE_ERROR(eglSwapBuffers(iDisplay, iSurface));
sl@0
   624
    }
sl@0
   625
sl@0
   626
void CTReadWriteMain::PixmapSurfaceFuncL()
sl@0
   627
    {
sl@0
   628
    // clear surface background to an arbitrary colour
sl@0
   629
    VGfloat arbitraryColour = (1.0*iFrameNumber)/KNumberOfFrames;
sl@0
   630
    VGfloat backgroundColour[] = {1.0 - arbitraryColour/2, arbitraryColour/2, 1.0 - arbitraryColour, arbitraryColour};
sl@0
   631
    vgSetfv(VG_CLEAR_COLOR, 4, backgroundColour);
sl@0
   632
    VgLeaveIfErrorL();
sl@0
   633
    vgClear(0, 0, iWidth, iHeight);
sl@0
   634
    VgLeaveIfErrorL();
sl@0
   635
sl@0
   636
    EGL_LEAVE_ERROR(eglSwapBuffers(iDisplay, iSurface));
sl@0
   637
    }