os/graphics/fbs/fontandbitmapserver/tfbs/TFBSDefect.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 //
    15 
    16 #include "../sfbs/UTILS.H"
    17 #include "TFBSDefect.h"
    18 #include "fbsmessage.h"
    19 
    20 CTFbsDefect::CTFbsDefect(CTestStep* aStep) :
    21 	CTGraphicsBase(aStep)
    22 	{
    23 	
    24 	}
    25 
    26 /**
    27 	@SYMTestCaseID
    28 	GRAPHICS-FBSERV-0574
    29 
    30 	@SYMTestCaseDesc
    31 	Checks for leaking thread handles during 
    32 	creation of bitmaps
    33 	
    34 	@SYMDEF INC041784
    35 	
    36 	@SYMTestActions
    37 	Retrieves the process handle count and the
    38 	thread handle count. Creates a bitmap with 
    39 	the specified size and display mode. The bitmap 
    40 	is created on the font and bitmap server's shared 
    41 	heap. The thread handle count is retrieved again 
    42 	and compared against the first thread handle count
    43 	and they should match.
    44 	
    45 	@SYMTestExpectedResults
    46 	Test should pass
    47 */
    48 void CTFbsDefect::CreateBitmapTestL()
    49     {
    50 	INFO_PRINTF1(_L("CreateBitmapTestL (INC041784)"));
    51 
    52 	// and leaking thread handles
    53 	TInt startProcessHandleCount;
    54 	TInt startThreadHandleCount;
    55 	TInt endProcessHandleCount;
    56 	TInt endThreadHandleCount;
    57 
    58 	RThread thisThread;
    59 	thisThread.HandleCount(startProcessHandleCount, startThreadHandleCount);
    60 
    61 	// Test Starts...
    62 	//
    63 
    64     const TSize size(100, 100);
    65 
    66 	CFbsBitmap* bitmap = new (ELeave) CFbsBitmap;
    67 	CleanupStack::PushL(bitmap);
    68 
    69 	TEST (bitmap->Create(size, ERgb)     == KErrArgument);
    70 	TEST (bitmap->Create(size, ENone)    == KErrArgument);
    71 	TEST (bitmap->Create(size, EColor16) == KErrNone);
    72 
    73 	CleanupStack::PopAndDestroy(bitmap);
    74 
    75 	//
    76 	// Test Ends...
    77 
    78 	// Check for open handles
    79 	thisThread.HandleCount(endProcessHandleCount, endThreadHandleCount);
    80 
    81 	TEST(startThreadHandleCount == endThreadHandleCount);
    82     }
    83     
    84 /**
    85 	@SYMTestCaseID
    86 	GRAPHICS-FBSERV-0575
    87 	
    88 	@SYMDEF	DEF042528
    89 
    90 	@SYMTestCaseDesc
    91 	Tests replacing initial display with all the 
    92 	possible higher display mode and tests replacing 
    93 	initial display with all the possible lower display mode.
    94 	
    95 	@SYMTestActions
    96 	Creates a bitmap. Creates an array containing display modes. 
    97 	For each display mode it sets the display mode to a higher
    98 	display mode and checks for errors. Then for each display mode
    99 	it sets the display mode to a lower display mode and checks
   100 	for errors.
   101 	
   102 	@SYMTestExpectedResults
   103 	Test should pass
   104 */
   105 void CTFbsDefect::TestDisplayModeL()
   106 	{
   107 	INFO_PRINTF1(_L("TestDisplayModeL (DEF042528)"));
   108 
   109     const TSize size(10,10);
   110 	CFbsBitmap* bitmap = new (ELeave) CFbsBitmap;
   111 	//TDisplayMode value= {   1  ,  2   ,  3    ,  4     ,   5         6        10       7         8          11          12		13
   112 	TDisplayMode mode[] = {EGray2,EGray4,EGray16,EGray256,EColor16,EColor256,EColor4K,EColor64K,EColor16M,EColor16MU,EColor16MA,EColor16MAP};
   113 
   114 	TInt arraysize=sizeof(mode)/sizeof(mode[0]);
   115 	INFO_PRINTF2(_L("Array size=%d\n"),arraysize);
   116 	TInt ret;
   117 	
   118 	//Test for replacing initial display with all the possible higher display mode
   119 	//This should not work and all the values returned by SetDisplayMode()==KErrArgument
   120 	for (TInt i=0;i<arraysize;i++)
   121 		{
   122 		ret=bitmap->Create(size,mode[i]);
   123 		INFO_PRINTF2(_L("Initial mode: %d\n"),mode[i]);
   124 		TEST(ret==KErrNone);
   125 		for (TInt j=i+1;j<arraysize;j++)
   126 			{
   127 			if ((mode[i]==EColor16MU && (mode[j]==EColor16MA || mode[j]==EColor16MAP)) || (mode[i]==EColor16MA && mode[j]==EColor16MAP))
   128 				{
   129 				//special cases where we can change from EColor16MU to either EColor16MA or EColor16MAP and from EColor16MA to EColor16MAP.
   130 				ret=bitmap->SetDisplayMode(mode[j]);
   131 				INFO_PRINTF3(_L("Changing to display mode=%d with ret value=%d\n "),mode[j],ret);
   132 				TEST(ret==KErrNone);
   133 				}
   134 			else
   135 				{
   136 				ret=bitmap->SetDisplayMode(mode[j]);
   137 				INFO_PRINTF3(_L("Changing to display mode %d with ret value %d \n"),mode[j],ret);				
   138 				TEST(ret==KErrArgument);	
   139 				}
   140 			}
   141 		INFO_PRINTF1(_L("End of mode \n"));
   142 		}
   143 	
   144 	//Test for replacing initial display with all the possible lower display mode
   145 	//This should work fine and all the values returned by SetDisplayMode()==KErrNone
   146 	INFO_PRINTF1(_L("\n\n"));
   147 	for (TInt k=arraysize-1;k>=0;k--)
   148 		{
   149 		ret=bitmap->Create(size,mode[k]);
   150 		INFO_PRINTF2(_L("Initial mode=%d\n"),mode[k]);
   151 		TEST(ret==KErrNone);
   152 		for (TInt l=k-1;l>=0;l--)
   153 			{
   154 			
   155 			if (mode[k]==EColor16 && mode[l]==EGray256)
   156 				{
   157 				//special case where we cannot change from EColor16 to EGray256
   158 				ret=bitmap->SetDisplayMode(mode[l]);
   159 				INFO_PRINTF3(_L("Changing to display mode=%d with ret value=%d\n "),mode[l],ret);
   160 				TEST(ret==KErrArgument);
   161 				}
   162 			
   163 			else
   164 				{
   165 				ret=bitmap->SetDisplayMode(mode[l]);
   166 				INFO_PRINTF3(_L("Changing to display mode=%d with ret value=%d\n "),mode[l],ret);
   167 				TEST(ret==KErrNone);
   168 				}
   169 			}
   170 		
   171 		}
   172 	
   173 	bitmap->Reset();
   174 	delete bitmap;
   175 	}
   176     
   177 /* Creates and destroys large bitmaps */
   178 TInt BitmapCreate(TAny* /* aAny */)
   179 	{
   180 	RFbsSession fbs;
   181 	TInt err = fbs.Connect();
   182 	User::LeaveIfError(err);
   183 	RFbsSession* fbs2 = RFbsSession::GetSession();
   184 	
   185 	FOREVER
   186 		{
   187 		CFbsBitmap bitmap;
   188 		bitmap.Create(TSize(300,200), EColor16MU);
   189 		bitmap.Reset();
   190 		fbs2->SendCommand(EFbsCompress, 0);
   191 		User::After(1);
   192 		}
   193 	}
   194 
   195 void CleanupFbsConnection(TAny* aPtr)
   196 	{
   197 	RFbsSession* fbs = static_cast<RFbsSession*>(aPtr);
   198 	fbs->Disconnect();
   199 	}
   200 
   201 void CleanupLoadedBitmap(TAny* aPtr)
   202 	{
   203 	RPointerArray<CFbsBitmap>* ptrArray = (static_cast<RPointerArray<CFbsBitmap>*>(aPtr));	
   204 	ptrArray->ResetAndDestroy();
   205 	ptrArray->Close();
   206 	}
   207 
   208 void FillBitmapArray(RPointerArray<CFbsBitmap>& aArray)
   209 	{
   210 	for(TInt count=100; count>=0; --count)
   211 		{
   212 		CFbsBitmap* bitmap = new CFbsBitmap;
   213 		if (!bitmap)
   214 			return;
   215 
   216 		TInt err = bitmap->Create(TSize(100,100), EColor16MU);
   217 
   218 		if (err == KErrNone)
   219 			{
   220 			err = aArray.Append(bitmap);
   221 			}
   222 
   223 		if (err != KErrNone)
   224 			{
   225 			delete bitmap;
   226 			return;
   227 			}
   228 		}
   229 	}
   230 
   231 void DoBitmapUseL()
   232 	{
   233 	RFbsSession fbs;
   234 	TInt err = fbs.Connect();
   235 	User::LeaveIfError(err);
   236 	TCleanupItem fbsConnectionCleanup(CleanupFbsConnection, &fbs);
   237 	CleanupStack::PushL(fbsConnectionCleanup);
   238 
   239 	RPointerArray<CFbsBitmap> stressBitmaps;
   240 	TCleanupItem loadedBitmapCleanup(CleanupLoadedBitmap, &stressBitmaps);
   241 	CleanupStack::PushL(loadedBitmapCleanup);
   242 	FillBitmapArray(stressBitmaps);
   243 
   244 	CFbsBitmap* outputBitmap=new(ELeave) CFbsBitmap;
   245 	CleanupStack::PushL(outputBitmap);
   246 	User::LeaveIfError(outputBitmap->Create(TSize(200,200),EColor16MU));
   247 	CFbsBitmapDevice *bgDevice=CFbsBitmapDevice::NewL(outputBitmap);
   248 	CleanupStack::PushL(bgDevice);
   249 	CFbsBitGc* bgGc=NULL;
   250 	User::LeaveIfError(bgDevice->CreateContext(bgGc));
   251 	CleanupStack::PushL(bgGc);
   252 
   253 	CFbsBitmap* bitmap=new(ELeave) CFbsBitmap;
   254 	CleanupStack::PushL(bitmap);
   255 	User::LeaveIfError(bitmap->Create(TSize(100,100),EColor16MU));
   256 	for (TInt count = 1000; count > 0; count--)
   257 		{
   258 		if ((count % 31)==1)
   259 			{
   260 			bitmap->Reset();
   261 			User::After(1);
   262 			User::LeaveIfError(bitmap->Create(TSize(100,100),EColor16MU));
   263 			}
   264 		if ((count % 11)==1)
   265 			{
   266 			stressBitmaps.ResetAndDestroy();
   267 			}
   268 		if ((count % 11)==5)
   269 			{
   270 			stressBitmaps.ResetAndDestroy();
   271 			FillBitmapArray(stressBitmaps);
   272 			}
   273 		bgGc->DrawBitmap(TPoint(10,10),bitmap);
   274 		User::After(1);
   275 		}
   276 
   277 	CleanupStack::PopAndDestroy(bitmap);
   278 	CleanupStack::PopAndDestroy(bgGc);
   279 	CleanupStack::PopAndDestroy(bgDevice);
   280 	CleanupStack::PopAndDestroy(outputBitmap);
   281 	CleanupStack::PopAndDestroy(/*&loadedBitmapCleanup*/);
   282 	CleanupStack::PopAndDestroy(/*&fbsConnectionCleanup*/);
   283 	}
   284 
   285 void TestBitmapUseL(CTFbsDefect* aFbsDefect)
   286 	{
   287 	TRAPD(err,DoBitmapUseL());
   288 	aFbsDefect->TEST(err==KErrNone || err==KErrNoMemory); // Out-of-memory doesn't constitute a test failure
   289 	}
   290 
   291 /* Draws bitmaps */
   292 TInt BitmapUse(TAny* aAny)
   293 	{
   294 	CTrapCleanup* CleanUpStack=CTrapCleanup::New();
   295 	CTFbsDefect* theTest = static_cast <CTFbsDefect*> (aAny);
   296 	__UHEAP_MARK;
   297 	
   298 	TRAP_IGNORE(TestBitmapUseL(theTest));
   299 
   300 	__UHEAP_MARKEND;
   301 	delete CleanUpStack;
   302 	return KErrNone;
   303 	}
   304 
   305 /** 
   306 	@SYMTestCaseID
   307 	GRAPHICS-FBSERV-0576
   308 
   309 	@SYMTestCaseDesc
   310 	Verifies defect DEF079124.
   311 	
   312 	@SYMDEF DEF079124
   313 
   314 	@SYMTestActions
   315 	Creates two threads. One threads keeps creating
   316 	and destroying large bitmaps. The second thread 
   317 	draws bitmaps. The exit reason of the threads
   318 	are checked. The thread handles are closed.
   319 	
   320 	@SYMTestExpectedResults
   321 	Test should pass
   322 */
   323 void CTFbsDefect::TestFbservChunkLockingL()
   324 	{
   325 	INFO_PRINTF1(_L("TestDisplayModeL (DEF079124)"));
   326 	
   327 	__UHEAP_MARK;
   328 	TRequestStatus stat;
   329 	RThread bitmapCreate;
   330 	RThread bitmapUse;
   331 	bitmapCreate.Create(_L("BitmapCreate"),BitmapCreate,KDefaultStackSize,0x2200,0x2200,this);
   332 	bitmapUse.Create(_L("BitmapUse"),BitmapUse,KDefaultStackSize,0x2200,0x2200,this);
   333 
   334 	bitmapUse.Logon(stat);
   335 	bitmapCreate.Resume();
   336 	bitmapUse.Resume();
   337 	User::WaitForRequest(stat);
   338 	
   339 	INFO_PRINTF2(_L("bitmapCreate ExitReason: %d"),bitmapCreate.ExitReason());
   340 	INFO_PRINTF2(_L("bitmapUse ExitReason: %d"),bitmapUse.ExitReason());
   341 	TEST(bitmapCreate.ExitReason() == KErrNone);
   342 	TEST(bitmapUse.ExitReason() == KErrNone);
   343 	bitmapCreate.Close();
   344 	bitmapUse.Close();
   345 	__UHEAP_MARKEND;
   346 	}
   347 	
   348 /**
   349  * @SYMTestCaseID GRAPHICS-FBSERV-0621
   350  *
   351  * @SYMDEF INC112542, PDEF113158
   352  *
   353  * @SYMTestCaseDesc A test to check KErrEof is returned when a bitmap index greater than the 
   354  * 					number of bitmaps present in the .mbm is requested from a ROM bitamp
   355  *
   356  * @SYMTestPriority Normal
   357  *
   358  * @SYMTestStatus Implemented
   359  *
   360  * @SYMTestActions Loads a bitmap from rom where the index is greater than the numer of bitmaps actually in the mbm
   361  * 					Checks that KErrEof is returned when this happens.	
   362  *
   363 */	
   364 void CTFbsDefect::TestKErrEof()
   365 	{
   366 	INFO_PRINTF1(_L("TestKErrEof - testing error code returned from CFbsBitmap::Load()"));
   367 	_LIT(KTestBitmapOnZZ,"z:\\system\\data\\tfbs.rbm"); // this contains 2 bitmaps
   368 
   369 
   370 	TUint32* romAddress = NULL;
   371 	if(!CFbsBitmap::IsFileInRom(KTestBitmapOnZZ, romAddress))
   372 		{
   373 		INFO_PRINTF2(_L("Skipping test of ROM bitmaps since file \"%S\" is reported to not be a ROM bitmap."),
   374 				&KTestBitmapOnZZ);
   375 		INFO_PRINTF1(_L("This should only occur on non-XIP ROMs, e.g. NAND ROMs, where ROM bitmaps aren't supported."));
   376 		return;
   377 		}
   378 
   379 	CFbsBitmap rom;
   380 	TInt bitmapIndex = 2;	// this bmp index is one greater than the bitmap contains
   381 	TInt errCode = rom.Load(KTestBitmapOnZZ,bitmapIndex,EFalse);
   382 	
   383 	if(errCode!=KErrEof)
   384 		{
   385 		TEST(EFalse);
   386 		INFO_PRINTF2(_L("TestKErrEof - Accessing ROM bitmap index greater than # contained returned %d instead of KErrEof"),errCode);			
   387 		}
   388 	}
   389 
   390 /* Creates  bitmaps under OOM conditions (PDEF129780)*/
   391 void CTFbsDefect::CreateBitmapOOMTestL()
   392 	{
   393 	INFO_PRINTF1(_L("CreateBitmapOOMTestL (PDEF129780) - Creating Bitmap under OOM conditions"));
   394 	
   395 	RFbsSession* fbs = RFbsSession::GetSession();
   396 		
   397 	RPointerArray<CFbsBitmap> bitmaps;
   398 	TCleanupItem bitmapsCleanupItem (CleanupLoadedBitmap, &bitmaps);
   399 	CleanupStack::PushL(bitmapsCleanupItem);
   400 		
   401 	// Loop here is to fill CFbTop::iBitmapObjectIndex and force it reallocate memory inside CBitmapObject::ConstructL
   402 	// The upper bound of the loop depends on how CFbTop::iBitmapObjectIndex is expended and how many pointers are in it by the start of this subtest
   403 	// The upper bound may require to be increased if previous subtests are changed
   404 	for(TInt i=0; i<500; i++)
   405 		{
   406 		TSize size(2,2); 
   407 		
   408 		// Rate starts from 2 to allow allocate memory at least for new CBitmapObject and leave during next attempt to allocate memory
   409 		// The Loop is to make sure that the situation won't be missed if something in code is changed 
   410 		// and it is more memory allocations before ConstructL. Currently it is enough 2.
   411 		for(TInt leaveRate = 2; leaveRate<10; leaveRate++)
   412 			{
   413 			CFbsBitmap* testBitmap = new(ELeave) CFbsBitmap;
   414 			
   415 			fbs->SendCommand(EFbsMessSetHeapFail, RFbsSession::EHeapFailTypeServerMemory, leaveRate); 
   416 			
   417 			//Try to create bitmap 
   418 			testBitmap->Create(size, EColor16MAP);
   419 			delete testBitmap;
   420 			}
   421 		
   422 		fbs->SendCommand(EFbsMessSetHeapReset, RFbsSession::EHeapFailTypeServerMemory, 0);
   423 		
   424 		// Create bitmap to fill FbTop::iBitmapObjectIndex
   425 		CFbsBitmap* bitmap = new(ELeave) CFbsBitmap;
   426 		CleanupStack::PushL(bitmap);
   427 		User::LeaveIfError(bitmaps.Append(bitmap));
   428 		CleanupStack::Pop(bitmap);
   429 		User::LeaveIfError(bitmap->Create(size, EColor16MAP));
   430 		}
   431 	INFO_PRINTF2(_L("Created %d bitmaps."), bitmaps.Count());
   432 	CleanupStack::PopAndDestroy(&bitmaps);
   433 	// If it was no Panic in fbserv and we have got here test pass
   434 	}
   435 
   436 
   437 void CTFbsDefect::RunTestCaseL(TInt aCurTestCase)
   438 	{
   439 	((CTFbsDefectStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
   440 	switch(aCurTestCase)
   441 		{
   442 	case 1:
   443 		((CTFbsDefectStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0574"));
   444 		CreateBitmapTestL();
   445 		break;
   446 	case 2:
   447 		((CTFbsDefectStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0575"));
   448 		TestDisplayModeL();
   449 		break;
   450 	case 3:
   451 		((CTFbsDefectStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0576"));
   452 		TestFbservChunkLockingL();
   453 		break;
   454 	case 4:
   455 		((CTFbsDefectStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0621"));
   456 		TestKErrEof();
   457 		break;
   458 	case 5:
   459 /**
   460     @SYMTestCaseID GRAPHICS-FBSERV-0620
   461 */
   462 		((CTFbsDefectStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0620"));
   463 		CreateBitmapOOMTestL();
   464 		break;	
   465 	case 6:
   466 		((CTFbsDefectStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
   467 		((CTFbsDefectStep*)iStep)->CloseTMSGraphicsStep();
   468 		TestComplete();
   469 		break;
   470 		}
   471 	((CTFbsDefectStep*)iStep)->RecordTestResultL();
   472 	}
   473 
   474 //--------------
   475 __CONSTRUCT_STEP__(FbsDefect)