egl/egltest/src/egltest_oom_sgimage.cpp
changeset 116 171fae344dd4
parent 85 cdf2f6e5c390
equal deleted inserted replaced
103:2717213c588a 116:171fae344dd4
     1 // Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
    32 
    32 
    33 //Since we want to exhaust the memory it probably makes sense to use any 32bpp mode  
    33 //Since we want to exhaust the memory it probably makes sense to use any 32bpp mode  
    34 //There is no need to put it into INI file
    34 //There is no need to put it into INI file
    35 const TUidPixelFormat KOOMPixelFormat = EUidPixelFormatARGB_8888; 
    35 const TUidPixelFormat KOOMPixelFormat = EUidPixelFormatARGB_8888; 
    36 
    36 
       
    37 // Deviation in per cent for test 0442 and 0443
       
    38 const TInt KOOMSgImageDeviation = 5; 
       
    39 
    37 
    40 
    38 CEglTest_OOM_Base::~CEglTest_OOM_Base()
    41 CEglTest_OOM_Base::~CEglTest_OOM_Base()
    39     {
    42     {
    40     CleanGraphicsResources();
    43     CleanGraphicsResources();
    41     CleanAll();
    44     CleanAll();
   190     TInt res = KErrNone;
   193     TInt res = KErrNone;
   191     
   194     
   192     if(iGPUUsedMemory.Count() > 0)
   195     if(iGPUUsedMemory.Count() > 0)
   193         {
   196         {
   194         res = Deviation(iGPUUsedMemory);
   197         res = Deviation(iGPUUsedMemory);
   195         TEST(iThresholdGPUUsedMemory >= res);
   198         ASSERT_TRUE(iThresholdGPUUsedMemory >= res);
   196         INFO_PRINTF3(_L("GPU used memory deviation %d %%, threshold %d %%"), res, iThresholdGPUUsedMemory);
   199         INFO_PRINTF3(_L("GPU used memory deviation %d %%, threshold %d %%"), res, iThresholdGPUUsedMemory);
   197         }
   200         }
   198     
   201     
   199     if(iLastIterations.Count() > 0)
   202     if(iLastIterations.Count() > 0)
   200         {
   203         {
   201         res = Deviation(iLastIterations);
   204         res = Deviation(iLastIterations);
   202         TEST(iThresholdLastIteration >= res);
   205         ASSERT_TRUE(iThresholdLastIteration >= res);
   203         INFO_PRINTF3(_L("Last iteration deviation %d %%, threshold %d %%"), res, iThresholdLastIteration);
   206         INFO_PRINTF3(_L("Last iteration deviation %d %%, threshold %d %%"), res, iThresholdLastIteration);
   204         }
   207         }
   205     }
   208     }
   206 
   209 
   207 void CEglTest_OOM_Base::RetrieveExtensionDataL()
   210 void CEglTest_OOM_Base::RetrieveExtensionDataL()
   443             RSgImage sgImage;
   446             RSgImage sgImage;
   444             TInt res = sgImage.Create(imageInfo, NULL);
   447             TInt res = sgImage.Create(imageInfo, NULL);
   445             if(res != KErrNone || sgImage.IsNull())
   448             if(res != KErrNone || sgImage.IsNull())
   446                 {
   449                 {
   447                 INFO_PRINTF5(_L("***Fail to create RSgImage after %d attempts, error: %d, expected %d or %d"), index, res, KErrNoMemory, KErrNoGraphicsMemory);
   450                 INFO_PRINTF5(_L("***Fail to create RSgImage after %d attempts, error: %d, expected %d or %d"), index, res, KErrNoMemory, KErrNoGraphicsMemory);
   448                 TEST((res == KErrNoMemory) || (res == KErrNoGraphicsMemory));
   451                 ASSERT_TRUE((res == KErrNoMemory) || (res == KErrNoGraphicsMemory));
   449                 break;
   452                 break;
   450                 }
   453                 }
   451             EGLImageKHR eglImages = iEglSess->eglCreateImageKhrL(iDisplay,EGL_NO_CONTEXT,EGL_NATIVE_PIXMAP_KHR,&sgImage,const_cast<EGLint *> (KEglImageAttribsPreservedTrue));
   454             EGLImageKHR eglImages = iEglSess->eglCreateImageKhrL(iDisplay,EGL_NO_CONTEXT,EGL_NATIVE_PIXMAP_KHR,&sgImage,const_cast<EGLint *> (KEglImageAttribsPreservedTrue));
   452             EGLint eglError = eglGetError();
   455             EGLint eglError = eglGetError();
   453             if((eglImages == EGL_NO_IMAGE_KHR) || (eglError != EGL_SUCCESS))
   456             if((eglImages == EGL_NO_IMAGE_KHR) || (eglError != EGL_SUCCESS))
   454                 {
   457                 {
   455                 INFO_PRINTF4(_L("***Fail to create EGLImage after %d attempts, error: %d, expected: %d"), index, eglError, EGL_BAD_ALLOC);
   458                 INFO_PRINTF4(_L("***Fail to create EGLImage after %d attempts, error: %d, expected: %d"), index, eglError, EGL_BAD_ALLOC);
   456                 TEST(eglError == EGL_BAD_ALLOC);
   459                 ASSERT_TRUE(eglError == EGL_BAD_ALLOC);
   457                 break;
   460                 break;
   458                 }
   461                 }
   459 
   462 
   460             VGImage vgImage = iEglSess->vgCreateImageTargetKHR((VGeglImageKHR)eglImages);
   463             VGImage vgImage = iEglSess->vgCreateImageTargetKHR((VGeglImageKHR)eglImages);
   461             VGErrorCode vgError = vgGetError();
   464             VGErrorCode vgError = vgGetError();
   462             if(vgImage == VG_INVALID_HANDLE || (vgError != VG_NO_ERROR))
   465             if(vgImage == VG_INVALID_HANDLE || (vgError != VG_NO_ERROR))
   463                 {
   466                 {
   464                 INFO_PRINTF4(_L("***Fail to create VGImage after %d attempts, error: %d, expected: %d"), index, vgError, VG_OUT_OF_MEMORY_ERROR);
   467                 INFO_PRINTF4(_L("***Fail to create VGImage after %d attempts, error: %d, expected: %d"), index, vgError, VG_OUT_OF_MEMORY_ERROR);
   465                 TEST(vgError == VG_OUT_OF_MEMORY_ERROR);
   468                 ASSERT_TRUE(vgError == VG_OUT_OF_MEMORY_ERROR);
   466                 break;
   469                 break;
   467                 }
   470                 }
   468             } //for
   471             } //for
   469         SendIndexToMainProcessL(index);
   472         SendIndexToMainProcessL(index);
   470         }
   473         }
   489         TProcessId procId;
   492         TProcessId procId;
   490         messageQueueProcId.ReceiveBlocking(procId);
   493         messageQueueProcId.ReceiveBlocking(procId);
   491         CleanupStack::PopAndDestroy(&messageQueueProcId);
   494         CleanupStack::PopAndDestroy(&messageQueueProcId);
   492 
   495 
   493         RProcess process;
   496         RProcess process;
   494         TESTL(process.Open(procId) == KErrNone);
   497         ASSERT_TRUE(process.Open(procId) == KErrNone);
   495         process.Kill(KErrNone);
   498         process.Kill(KErrNone);
   496         process.Close();
   499         process.Close();
   497         
   500         
   498         // small delay to ensure the kernel finishes the clean-up
   501         // small delay to ensure the kernel finishes the clean-up
   499         User::After(1*1000*1000); // 1 second
   502         User::After(1*1000*1000); // 1 second
   596     return TestStepResult();
   599     return TestStepResult();
   597     }
   600     }
   598 
   601 
   599 void CEglTest_OOM_CloseVGImage::doProcessFunctionL(TInt aIdx)
   602 void CEglTest_OOM_CloseVGImage::doProcessFunctionL(TInt aIdx)
   600     {
   603     {
   601     INFO_PRINTF2(_L("CEglTest_OOM_CloseVGImageWithTermination::doProcessFunctionL, Process %d"),aIdx);
   604     INFO_PRINTF2(_L("CEglTest_OOM_CloseVGImage::doProcessFunctionL, Process %d"),aIdx);
   602 #ifdef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
   605 #ifdef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
   603     GetDisplayL();
   606     GetDisplayL();
   604     CreateEglSessionL(aIdx);
   607     CreateEglSessionL(aIdx);
   605     iEglSess->InitializeL();    
   608     iEglSess->InitializeL();    
   606     iEglSess->OpenSgDriverL();
   609     iEglSess->OpenSgDriverL();
   623         RSgImage sgImage;
   626         RSgImage sgImage;
   624         TInt res = sgImage.Create(imageInfo, NULL);
   627         TInt res = sgImage.Create(imageInfo, NULL);
   625         if(res != KErrNone || sgImage.IsNull())
   628         if(res != KErrNone || sgImage.IsNull())
   626             {
   629             {
   627             INFO_PRINTF5(_L("***Fail to create RSgImage after %d attempts, error: %d, expected: %d or %d"), index, res, KErrNoMemory, KErrNoGraphicsMemory);
   630             INFO_PRINTF5(_L("***Fail to create RSgImage after %d attempts, error: %d, expected: %d or %d"), index, res, KErrNoMemory, KErrNoGraphicsMemory);
   628             TEST((res == KErrNoMemory) || (res == KErrNoGraphicsMemory));
   631             ASSERT_TRUE((res == KErrNoMemory) || (res == KErrNoGraphicsMemory));
   629             break;
   632             break;
   630             }
   633             }
   631         iSgImages.AppendL(sgImage);
   634         iSgImages.AppendL(sgImage);
   632         
   635         
   633         EGLImageKHR eglImage = iEglSess->eglCreateImageKhrL(iDisplay,EGL_NO_CONTEXT,EGL_NATIVE_PIXMAP_KHR,&sgImage,const_cast<EGLint *> (KEglImageAttribsPreservedTrue));
   636         EGLImageKHR eglImage = iEglSess->eglCreateImageKhrL(iDisplay,EGL_NO_CONTEXT,EGL_NATIVE_PIXMAP_KHR,&sgImage,const_cast<EGLint *> (KEglImageAttribsPreservedTrue));
   634         EGLint eglError = eglGetError();
   637         EGLint eglError = eglGetError();
   635         if((eglImage == EGL_NO_IMAGE_KHR) || (eglError != EGL_SUCCESS))
   638         if((eglImage == EGL_NO_IMAGE_KHR) || (eglError != EGL_SUCCESS))
   636             {
   639             {
   637             INFO_PRINTF4(_L("***Fail to create EGLImage after %d attempts, error: %d, expected: %d"), index, eglError, EGL_BAD_ALLOC);
   640             INFO_PRINTF4(_L("***Fail to create EGLImage after %d attempts, error: %d, expected: %d"), index, eglError, EGL_BAD_ALLOC);
   638             TEST(eglError == EGL_BAD_ALLOC);
   641             ASSERT_TRUE(eglError == EGL_BAD_ALLOC);
   639             break;
   642             break;
   640             }
   643             }
   641         iEglImages.AppendL(eglImage);
   644         iEglImages.AppendL(eglImage);
   642         
   645         
   643         VGImage vgImage = iEglSess->vgCreateImageTargetKHR((VGeglImageKHR)eglImage);
   646         VGImage vgImage = iEglSess->vgCreateImageTargetKHR((VGeglImageKHR)eglImage);
   644         VGErrorCode vgError = vgGetError();
   647         VGErrorCode vgError = vgGetError();
   645         if(vgImage == VG_INVALID_HANDLE || (vgError != VG_NO_ERROR))
   648         if(vgImage == VG_INVALID_HANDLE || (vgError != VG_NO_ERROR))
   646             {
   649             {
   647             INFO_PRINTF4(_L("***Fail to create VGImage after %d attempts, error: %d, expected: %d"), index, vgError, VG_OUT_OF_MEMORY_ERROR);
   650             INFO_PRINTF4(_L("***Fail to create VGImage after %d attempts, error: %d, expected: %d"), index, vgError, VG_OUT_OF_MEMORY_ERROR);
   648             TEST(vgError == VG_OUT_OF_MEMORY_ERROR);
   651             ASSERT_TRUE(vgError == VG_OUT_OF_MEMORY_ERROR);
   649             break;
   652             break;
   650             }
   653             }
   651         iVgImages.AppendL(vgImage);
   654         iVgImages.AppendL(vgImage);
   652         }
   655         }
   653 
   656 
   775             RSgImage sgImage;
   778             RSgImage sgImage;
   776             TInt res = sgImage.Create(imageInfo, NULL);
   779             TInt res = sgImage.Create(imageInfo, NULL);
   777             if(res != KErrNone || sgImage.IsNull())
   780             if(res != KErrNone || sgImage.IsNull())
   778                 {
   781                 {
   779                 INFO_PRINTF5(_L("***Fail to create RSgImage after %d attempts, error: %d, expected: %d or %d"), index, res, KErrNoMemory, KErrNoGraphicsMemory);
   782                 INFO_PRINTF5(_L("***Fail to create RSgImage after %d attempts, error: %d, expected: %d or %d"), index, res, KErrNoMemory, KErrNoGraphicsMemory);
   780                 TEST((res == KErrNoMemory) || (res == KErrNoGraphicsMemory));
   783                 ASSERT_TRUE((res == KErrNoMemory) || (res == KErrNoGraphicsMemory));
   781                 break;
   784                 break;
   782                 }
   785                 }
   783             
   786             
   784             EGLConfig currentConfig = 0;
   787             EGLConfig currentConfig = 0;
   785             const EGLint KAttrib[] = { EGL_MATCH_NATIVE_PIXMAP,   (TInt)&sgImage,
   788             const EGLint KAttrib[] = { EGL_MATCH_NATIVE_PIXMAP,   (TInt)&sgImage,
   795             EGLSurface surface = eglCreatePixmapSurface(iDisplay, currentConfig, &sgImage, NULL);
   798             EGLSurface surface = eglCreatePixmapSurface(iDisplay, currentConfig, &sgImage, NULL);
   796             EGLint eglError = eglGetError();
   799             EGLint eglError = eglGetError();
   797             if((surface == EGL_NO_SURFACE) || (eglError != EGL_SUCCESS))
   800             if((surface == EGL_NO_SURFACE) || (eglError != EGL_SUCCESS))
   798                 {
   801                 {
   799                 INFO_PRINTF4(_L("***Fail to create Pixmap surface after %d attempts, error: %d, expected: %d"), index, eglError, EGL_BAD_ALLOC);
   802                 INFO_PRINTF4(_L("***Fail to create Pixmap surface after %d attempts, error: %d, expected: %d"), index, eglError, EGL_BAD_ALLOC);
   800                 TEST(eglError == EGL_BAD_ALLOC);
   803                 ASSERT_TRUE(eglError == EGL_BAD_ALLOC);
   801                 break;
   804                 break;
   802                 }            
   805                 }            
   803             } //for
   806             } //for
   804         SendIndexToMainProcessL(index);
   807         SendIndexToMainProcessL(index);
   805         }
   808         }
   824         TProcessId procId;
   827         TProcessId procId;
   825         messageQueueProcId.ReceiveBlocking(procId);
   828         messageQueueProcId.ReceiveBlocking(procId);
   826         CleanupStack::PopAndDestroy(&messageQueueProcId);
   829         CleanupStack::PopAndDestroy(&messageQueueProcId);
   827 
   830 
   828         RProcess process;
   831         RProcess process;
   829         TESTL(process.Open(procId) == KErrNone);
   832         ASSERT_TRUE(process.Open(procId) == KErrNone);
   830         process.Kill(KErrNone);
   833         process.Kill(KErrNone);
   831 		process.Close();
   834 		process.Close();
   832 
   835 
   833         // small delay to ensure the kernel finishes the clean-up
   836         // small delay to ensure the kernel finishes the clean-up
   834         User::After(1*1000*1000); // 1 second
   837         User::After(1*1000*1000); // 1 second
   944         RSgImage sgImage;
   947         RSgImage sgImage;
   945         TInt res = sgImage.Create(imageInfo, NULL);
   948         TInt res = sgImage.Create(imageInfo, NULL);
   946         if(res != KErrNone || sgImage.IsNull())
   949         if(res != KErrNone || sgImage.IsNull())
   947             {
   950             {
   948             INFO_PRINTF5(_L("***Fail to create RSgImage after %d attempts, error: %d, expected: %d or %d"), index, res, KErrNoMemory, KErrNoGraphicsMemory);
   951             INFO_PRINTF5(_L("***Fail to create RSgImage after %d attempts, error: %d, expected: %d or %d"), index, res, KErrNoMemory, KErrNoGraphicsMemory);
   949             TEST((res == KErrNoMemory) || (res == KErrNoGraphicsMemory));
   952             ASSERT_TRUE((res == KErrNoMemory) || (res == KErrNoGraphicsMemory));
   950             break;
   953             break;
   951             }
   954             }
   952         iSgImages.AppendL(sgImage);
   955         iSgImages.AppendL(sgImage);
   953         
   956         
   954         EGLConfig currentConfig = 0;
   957         EGLConfig currentConfig = 0;
   965         EGLSurface surface = eglCreatePixmapSurface(iDisplay, currentConfig, &sgImage, NULL);
   968         EGLSurface surface = eglCreatePixmapSurface(iDisplay, currentConfig, &sgImage, NULL);
   966         EGLint eglError = eglGetError();
   969         EGLint eglError = eglGetError();
   967         if((surface == EGL_NO_SURFACE) || (eglError != EGL_SUCCESS))
   970         if((surface == EGL_NO_SURFACE) || (eglError != EGL_SUCCESS))
   968             {
   971             {
   969             INFO_PRINTF4(_L("***Fail to create Pixmap surface after %d attempts, error: %d, expected: %d "), index, eglError, EGL_BAD_ALLOC);
   972             INFO_PRINTF4(_L("***Fail to create Pixmap surface after %d attempts, error: %d, expected: %d "), index, eglError, EGL_BAD_ALLOC);
   970             TEST(eglError == EGL_BAD_ALLOC);
   973             ASSERT_TRUE(eglError == EGL_BAD_ALLOC);
   971             break;
   974             break;
   972             }       
   975             }       
   973         iSurfaces.AppendL(surface);
   976         iSurfaces.AppendL(surface);
   974         } //for
   977         } //for
   975     SendIndexToMainProcessL(index);
   978     SendIndexToMainProcessL(index);
   978     iEglSess->CloseSgDriver();
   981     iEglSess->CloseSgDriver();
   979     CleanAll();
   982     CleanAll();
   980 #endif    
   983 #endif    
   981     }    
   984     }    
   982 
   985 
       
   986 /**
       
   987 @SYMTestCaseID GRAPHICS-EGL-0442
       
   988 
       
   989 @SYMTestPriority 1
       
   990 
       
   991 @SYMPREQ 2637
       
   992 
       
   993 @SYMTestCaseDesc
       
   994     OOM test – Check SgImages are removed when SgImage handles in multiple processes are closed
       
   995 
       
   996 @SYMTestActions
       
   997 Environmental settings:
       
   998 •   Image Size: as per ini file
       
   999 •   List of simulated load: 0%
       
  1000 •   List of pixel formats
       
  1001 ESgPixelFormatARGB_8888
       
  1002 •   Client process priorities - all the same
       
  1003 •   Client process random parameters:
       
  1004 -   None
       
  1005 
       
  1006 The creation of RSgImages and launching of processes is along the lines of the method outlined in GRAPHICS-EGL-RSGIMAGE_LITE-0406
       
  1007 
       
  1008     From the main process:
       
  1009         Spawn 2 client processes A and B.
       
  1010         Wait until client processes exit
       
  1011     If the test fails not due to the memory allocation record an error code to the log file then set a test result as a failure and skip further actions.
       
  1012     End loop
       
  1013     Exit
       
  1014 
       
  1015     From client process A:
       
  1016     Get EGL display
       
  1017     Initialize EGL
       
  1018     Open RSgDriver
       
  1019     Loop until exit condition met
       
  1020     Start loop:
       
  1021         Create SgImage
       
  1022         Exit condition – SgImage surface creation has failed.
       
  1023     End loop:
       
  1024     Make the process busy by putting it into the indefinite loop.
       
  1025     
       
  1026     From client process B:
       
  1027     Start loop:
       
  1028         Open SgImage
       
  1029         Close SgImage
       
  1030     End loop:
       
  1031 
       
  1032     From client process A:
       
  1033     Start loop:
       
  1034         Close SgImage
       
  1035     End loop:
       
  1036     Check all memory has been deallocated by starting a second loop
       
  1037         Start loop 2:
       
  1038             Create SgImage
       
  1039             Exit condition – SgImage surface creation has failed.
       
  1040         End loop:
       
  1041     Check that the amount of images created within this loop 2 is similar to loop 1,
       
  1042     meaning that all images were correctly freed.
       
  1043     Cleanup everything
       
  1044     
       
  1045     Terminate process A
       
  1046     Terminate process B
       
  1047     
       
  1048 @SYMTestExpectedResults
       
  1049 For each step from 0 to N in the main process, 
       
  1050 -   Image or surface allocation failure must happen at approximately the same iteration 
       
  1051     in process A.  
       
  1052 */
       
  1053 TVerdict CEglTest_OOM_CloseSgImageDifferentProcess::doTestStepL()
       
  1054     {
       
  1055     SetTestStepID(_L("GRAPHICS-EGL-0442"));
       
  1056     SetTestStepName(KOOM_CloseSgImageDifferentProcess);
       
  1057     INFO_PRINTF1(_L("CEglTest_OOM_CloseSgImageDifferentProcess::doTestStepL"));
       
  1058 
       
  1059 #ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
       
  1060     INFO_PRINTF1(_L("CEglTest_OOM_CloseSgImageDifferentProcess can only be run with SgImage-Lite"));
       
  1061 #else
       
  1062     TBool ret = CheckForExtensionL(KEGL_RSgimage | KEGL_KHR_image_base | KVG_KHR_EGL_image | KEGL_KHR_image_pixmap);
       
  1063     if(ret)
       
  1064         {
       
  1065         // launch 2 processes
       
  1066         Test_MultiProcessL(KEglTestStepDllName, 2, TestStepName());
       
  1067         }
       
  1068     INFO_PRINTF1(_L("Exit: CEglTest_OOM_CloseSgImageDifferentProcess::doTestStepL"));
       
  1069 #endif //SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
       
  1070     RecordTestResultL();
       
  1071     CloseTMSGraphicsStep();
       
  1072     return TestStepResult();
       
  1073     }
       
  1074 
       
  1075 void CEglTest_OOM_CloseSgImageDifferentProcess::doProcessFunctionL(TInt aIdx)
       
  1076     {
       
  1077     INFO_PRINTF2(_L("CEglTest_OOM_CloseSgImageDifferentProcess::doProcessFunctionL, Process %d"),aIdx);
       
  1078 #ifdef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
       
  1079 
       
  1080     GetDisplayL();
       
  1081     CreateEglSessionL(aIdx);
       
  1082     iEglSess->InitializeL();
       
  1083     iEglSess->OpenSgDriverL();
       
  1084 
       
  1085     //create the queue to send/receive SgImage ID between processes
       
  1086     RMsgQueue<TSgDrawableId> messageQueueSgId;
       
  1087     User::LeaveIfError(messageQueueSgId.Open(EProcSlotMsgQueueSgId, EOwnerProcess));
       
  1088     CleanupClosePushL(messageQueueSgId);
       
  1089 
       
  1090     // create as many sgimages until it reaches out of memory
       
  1091     TInt numImages = 0;
       
  1092     if(aIdx == 0)
       
  1093         {
       
  1094         for(;;++numImages)
       
  1095             {
       
  1096             RSgImage sgImage;
       
  1097             TInt res = sgImage.Create(TSgImageInfo(iImageSize, KOOMPixelFormat, ESgUsageBitOpenVgImage));
       
  1098             if(res != KErrNone || sgImage.IsNull())
       
  1099                 {
       
  1100                 INFO_PRINTF5(_L("***Fail to create RSgImage after %d attempts, error: %d, expected: %d or %d"), numImages, res, KErrNoMemory, KErrNoGraphicsMemory);
       
  1101                 ASSERT_TRUE((res == KErrNoMemory) || (res == KErrNoGraphicsMemory));
       
  1102                 break;
       
  1103                 }
       
  1104             iSgImages.AppendL(sgImage);
       
  1105             }
       
  1106         }
       
  1107     
       
  1108     // Send to process B how many images it needs to wait for
       
  1109     if(aIdx == 0)
       
  1110         {
       
  1111        // send a TInt as a  fake SgImage Id
       
  1112         messageQueueSgId.SendBlocking(reinterpret_cast<TSgDrawableId&>(numImages));
       
  1113         }
       
  1114     else if (aIdx == 1)
       
  1115         {
       
  1116         // receive the fake SgImage Id and convert it to a TInt
       
  1117         TSgDrawableId fakeId;
       
  1118         messageQueueSgId.ReceiveBlocking(fakeId);
       
  1119         numImages = reinterpret_cast<TInt&>(fakeId);
       
  1120         }
       
  1121     
       
  1122     // Wait for both processes to reach this point
       
  1123     Rendezvous(aIdx);
       
  1124     
       
  1125     // Now process B knows how many images needs to wait for
       
  1126     if(aIdx == 0)
       
  1127         {
       
  1128         for(TInt index = 0; index<numImages; ++index)
       
  1129             {
       
  1130             // send Id to other process
       
  1131             messageQueueSgId.SendBlocking(iSgImages[index].Id());
       
  1132             }
       
  1133         }
       
  1134     else if(aIdx == 1)
       
  1135         {
       
  1136         for(TInt index = 0; index<numImages; ++index)
       
  1137             {
       
  1138             // receive Id from other process
       
  1139             TSgDrawableId sgImageId;
       
  1140             messageQueueSgId.ReceiveBlocking(sgImageId);
       
  1141             
       
  1142             // open sgImage with received Id
       
  1143             RSgImage sgImage;
       
  1144             ASSERT_EQUALS(sgImage.Open(sgImageId), KErrNone);
       
  1145 
       
  1146             // close SgImage just created
       
  1147             sgImage.Close();
       
  1148             }
       
  1149         }
       
  1150 
       
  1151     // Wait for both processes to reach this point
       
  1152     Rendezvous(aIdx);
       
  1153 
       
  1154     // delete all sgImages created in first process
       
  1155     if(aIdx == 0)
       
  1156         {
       
  1157         CleanGraphicsResources();
       
  1158         }
       
  1159 
       
  1160     // create (again) as many sgimages until it reaches out of memory
       
  1161     // note that process B needs to be alive (hence the Rendezvous further down)
       
  1162     if(aIdx == 0)
       
  1163         {
       
  1164         TInt numImages2 = 0;
       
  1165         for(;;++numImages2)
       
  1166             {
       
  1167             RSgImage sgImage;
       
  1168             TInt res = sgImage.Create(TSgImageInfo(iImageSize, KOOMPixelFormat, ESgUsageBitOpenVgImage));
       
  1169             if(res != KErrNone || sgImage.IsNull())
       
  1170                 {
       
  1171                 INFO_PRINTF5(_L("***Fail to create RSgImage after %d attempts, error: %d, expected: %d or %d"), numImages2, res, KErrNoMemory, KErrNoGraphicsMemory);
       
  1172                 ASSERT_TRUE((res == KErrNoMemory) || (res == KErrNoGraphicsMemory));
       
  1173                 break;
       
  1174                 }
       
  1175             iSgImages.AppendL(sgImage);
       
  1176             }
       
  1177         // clean up these images, we don't really need them
       
  1178         CleanGraphicsResources();
       
  1179         
       
  1180         // check numbers...
       
  1181         INFO_PRINTF2(_L("***Num sgImages created first time: %d."), numImages);
       
  1182         INFO_PRINTF2(_L("***Num sgImages created second time: %d."), numImages2);
       
  1183         TInt deviation = Abs(((numImages2*100) / numImages) - 100);
       
  1184         ASSERT_TRUE(deviation < KOOMSgImageDeviation);
       
  1185         INFO_PRINTF3(_L("***Deviation: %d%% (must be less than %d%%)"), deviation, KOOMSgImageDeviation);
       
  1186 
       
  1187         // This test does not need to send anything, but since OOM test framework expects something
       
  1188         // we can send a fake index so that the test is not waiting for it forever.
       
  1189         const TInt KTestNotUsedData = 0;
       
  1190         SendIndexToMainProcessL(KTestNotUsedData); 
       
  1191         }
       
  1192 
       
  1193     // Wait for both processes to reach this point
       
  1194     Rendezvous(aIdx);
       
  1195 
       
  1196     //now clean everything
       
  1197     CleanupStack::PopAndDestroy(&messageQueueSgId);
       
  1198     CleanGraphicsResources();
       
  1199     iEglSess->CloseSgDriver();
       
  1200     CleanAll();
       
  1201 #endif //SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
       
  1202     }
       
  1203 
       
  1204 /**
       
  1205 @SYMTestCaseID GRAPHICS-EGL-0443
       
  1206 
       
  1207 @SYMTestPriority 1
       
  1208 
       
  1209 @SYMPREQ 2637
       
  1210 
       
  1211 @SYMTestCaseDesc
       
  1212     OOM test – Check SgImages are removed when SgImage handles in multiple processes are closed
       
  1213 
       
  1214 @SYMTestActions
       
  1215 Environmental settings:
       
  1216 •   Image Size: as per ini file
       
  1217 •   List of simulated load: 0%
       
  1218 •   List of pixel formats
       
  1219 ESgPixelFormatARGB_8888
       
  1220 •   Client process priorities - all the same
       
  1221 •   Client process random parameters:
       
  1222 -   None
       
  1223 
       
  1224 The creation of RSgImages and launching of processes is along the lines of the method outlined in GRAPHICS-EGL-RSGIMAGE_LITE-0406
       
  1225 
       
  1226     From the main process:
       
  1227     From client process A:
       
  1228     Get EGL display
       
  1229     Initialize EGL
       
  1230     Open RSgDriver
       
  1231     Loop until exit condition met
       
  1232     Start loop:
       
  1233         Create SgImage
       
  1234         Exit condition – SgImage surface creation has failed.
       
  1235     End loop:
       
  1236     Start loop:
       
  1237         Open SgImage
       
  1238         Close SgImage
       
  1239     End loop:
       
  1240     Start loop:
       
  1241         Close SgImage
       
  1242     End loop:
       
  1243     Check all memory has been deallocated by starting a second loop
       
  1244         Start loop 2:
       
  1245             Create SgImage
       
  1246             Exit condition – SgImage surface creation has failed.
       
  1247         End loop:
       
  1248     Check that the amount of images created within this loop 2 is similar to loop 1,
       
  1249     meaning that all images were correctly freed.
       
  1250     Cleanup everything
       
  1251     
       
  1252 @SYMTestExpectedResults
       
  1253 For each step from 0 to N in the main process, 
       
  1254 -   Image or surface allocation failure must happen at approximately the same iteration 
       
  1255     in process A.  
       
  1256 */
       
  1257 TVerdict CEglTest_OOM_CloseSgImageSameThread::doTestStepL()
       
  1258     {
       
  1259     SetTestStepID(_L("GRAPHICS-EGL-0443"));
       
  1260     SetTestStepName(KOOM_CloseSgImageSameThread);
       
  1261     INFO_PRINTF1(_L("CEglTest_OOM_CloseSgImageSameThread::doTestStepL"));
       
  1262 
       
  1263 #ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
       
  1264     INFO_PRINTF1(_L("CEglTest_OOM_CloseSgImageSameThread can only be run with SgImage-Lite"));
       
  1265 #else
       
  1266     TBool ret = CheckForExtensionL(KEGL_RSgimage | KEGL_KHR_image_base | KVG_KHR_EGL_image | KEGL_KHR_image_pixmap);
       
  1267     if(ret)
       
  1268         {
       
  1269         GetDisplayL();
       
  1270         CreateEglSessionL(0);
       
  1271         iEglSess->InitializeL();
       
  1272         iEglSess->OpenSgDriverL();
       
  1273     
       
  1274         // create as many sgimages until it reaches out of memory
       
  1275         TInt numImages = 0;
       
  1276         for(;;++numImages)
       
  1277             {
       
  1278             RSgImage sgImage;
       
  1279             TInt res = sgImage.Create(TSgImageInfo(iImageSize, KOOMPixelFormat, ESgUsageBitOpenVgImage));
       
  1280             if(res != KErrNone || sgImage.IsNull())
       
  1281                 {
       
  1282                 INFO_PRINTF5(_L("***Fail to create RSgImage after %d attempts, error: %d, expected: %d or %d"), numImages, res, KErrNoMemory, KErrNoGraphicsMemory);
       
  1283                 ASSERT_TRUE((res == KErrNoMemory) || (res == KErrNoGraphicsMemory));
       
  1284                 break;
       
  1285                 }
       
  1286             iSgImages.AppendL(sgImage);
       
  1287             }
       
  1288 
       
  1289         //open a duplicate handle for the created images (can close straightaway)
       
  1290         for(TInt index = 0; index<numImages; ++index)
       
  1291             {
       
  1292             RSgImage sgImage;
       
  1293             ASSERT_EQUALS(sgImage.Open(iSgImages[index].Id()), KErrNone);
       
  1294             // close SgImage just created
       
  1295             sgImage.Close();
       
  1296             }
       
  1297 
       
  1298         // clean up all (original) images
       
  1299         CleanGraphicsResources();
       
  1300 
       
  1301         // create (again) as many sgimages until it reaches out of memory
       
  1302         TInt numImages2 = 0;
       
  1303         for(;;++numImages2)
       
  1304             {
       
  1305             RSgImage sgImage;
       
  1306             TInt res = sgImage.Create(TSgImageInfo(iImageSize, KOOMPixelFormat, ESgUsageBitOpenVgImage));
       
  1307             if(res != KErrNone || sgImage.IsNull())
       
  1308                 {
       
  1309                 INFO_PRINTF5(_L("***Fail to create RSgImage after %d attempts, error: %d, expected: %d or %d"), numImages2, res, KErrNoMemory, KErrNoGraphicsMemory);
       
  1310                 ASSERT_TRUE((res == KErrNoMemory) || (res == KErrNoGraphicsMemory));
       
  1311                 break;
       
  1312                 }
       
  1313             iSgImages.AppendL(sgImage);
       
  1314             }
       
  1315             
       
  1316         // clean up everything now
       
  1317         CleanGraphicsResources();
       
  1318         iEglSess->CloseSgDriver();
       
  1319         CleanAll();
       
  1320 
       
  1321         // check numbers...
       
  1322         INFO_PRINTF2(_L("***Num sgImages created first time: %d."), numImages);
       
  1323         INFO_PRINTF2(_L("***Num sgImages created second time: %d."), numImages2);
       
  1324         TInt deviation = Abs(((numImages2*100) / numImages) - 100);
       
  1325         ASSERT_TRUE(deviation < KOOMSgImageDeviation);
       
  1326         INFO_PRINTF3(_L("***Deviation: %d%% (must be less than %d%%)"), deviation, KOOMSgImageDeviation);
       
  1327         }
       
  1328     INFO_PRINTF1(_L("Exit: CEglTest_OOM_CloseSgImageSameThread::doTestStepL"));
       
  1329 #endif //SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
       
  1330 
       
  1331     RecordTestResultL();
       
  1332     CloseTMSGraphicsStep();
       
  1333     return TestStepResult();
       
  1334     }
       
  1335