1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/fbs/fontandbitmapserver/tfbs/tcompressed.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,770 @@
1.4 +// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#include <bitdev.h>
1.20 +#include <e32math.h>
1.21 +#include "tcompressed.h"
1.22 +
1.23 +CTCompressed::CTCompressed(CTestStep* aStep) :
1.24 + CTGraphicsBase(aStep)
1.25 + {
1.26 + }
1.27 +
1.28 +void CTCompressed::BlankBitmap(CFbsBitmapEx& aBitmap)
1.29 + {
1.30 + TSize size = aBitmap.SizeInPixels();
1.31 + TInt dataLength = CFbsBitmap::ScanLineLength(size.iWidth,aBitmap.DisplayMode()) * size.iHeight;
1.32 + aBitmap.LockHeap();
1.33 + Mem::FillZ((TUint8*)aBitmap.DataAddress(),dataLength);
1.34 + aBitmap.UnlockHeap();
1.35 + }
1.36 +
1.37 +void CTCompressed::RunTestCaseL(TInt aCurTestCase)
1.38 + {
1.39 + ((CTCompressedStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
1.40 + switch(aCurTestCase)
1.41 + {
1.42 + case 1:
1.43 + ((CTCompressedStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0571"));
1.44 + TRAPD(err, RunTestL());
1.45 + TEST(err == KErrNone);
1.46 + break;
1.47 + case 2:
1.48 + ((CTCompressedStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0572"));
1.49 + TRAP(err, DefectFix_EXT5DXGK6_L());
1.50 + TEST(err == KErrNone);
1.51 + break;
1.52 + case 3:
1.53 + {
1.54 + ((CTCompressedStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0500"));
1.55 + // Set size of bitmap large enough to warrant compression
1.56 + const TSize KBitmapSize(200,200);
1.57 + INFO_PRINTF1(_L("Test case for INC082713\r\n"));
1.58 + TRAP(err, DefectFix_INC082713_L(EColor16MU, KBitmapSize));
1.59 + TEST(err == KErrNone);
1.60 + TRAP(err, DefectFix_INC082713_L(EColor16MA, KBitmapSize));
1.61 + TEST(err == KErrNone);
1.62 + }
1.63 + break;
1.64 + case 4:
1.65 + ((CTCompressedStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0573"));
1.66 + TRAPD(err1, INC088856_TestL());
1.67 + TEST(err1 == KErrNone);
1.68 + break;
1.69 + case 5:
1.70 + ((CTCompressedStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0615"));
1.71 + TestDestroyBitmapWhileBeingBackgroundCompressedL();
1.72 + break;
1.73 + case 6:
1.74 + ((CTCompressedStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0616"));
1.75 + TestBackgroundCompressionThreadPriorityInheritanceL();
1.76 + break;
1.77 + case 7:
1.78 + ((CTCompressedStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
1.79 + ((CTCompressedStep*)iStep)->CloseTMSGraphicsStep();
1.80 + TestComplete();
1.81 + break;
1.82 + }
1.83 + ((CTCompressedStep*)iStep)->RecordTestResultL();
1.84 + }
1.85 +
1.86 +/**
1.87 + @SYMTestCaseID
1.88 + GRAPHICS-FBSERV-0571
1.89 +
1.90 + @SYMTestCaseDesc
1.91 + Tests compression of bitmaps in RAM and ROM.
1.92 +
1.93 + @SYMTestActions
1.94 + Four bitmaps are loaded. One compressed and one
1.95 + uncompressed from ROM and from RAM. The bitmap
1.96 + in RAM is tested if it can be compressed successfully.
1.97 + The bitmap in ROM should fail when tried to be compressed.
1.98 + All of the bitmaps are then tried to be BitBlt.
1.99 +
1.100 + @SYMTestExpectedResults
1.101 + Test should pass
1.102 +*/
1.103 +void CTCompressed::RunTestL()
1.104 + {
1.105 + TInt skipRomBitmapTests = EFalse;
1.106 + TUint32* romAddress = NULL;
1.107 + if(!CFbsBitmap::IsFileInRom(KRomNotCompressed, romAddress)) //any ROM bitmap
1.108 + {
1.109 + INFO_PRINTF2(_L("Skipping ROM bitmap tests since file \"%S\" is reported to not be a ROM bitmap."),
1.110 + &KRomNotCompressed);
1.111 + INFO_PRINTF1(_L("This should only occur on non-XIP ROMs, e.g. NAND ROMs, where ROM bitmaps aren't supported."));
1.112 + skipRomBitmapTests = ETrue;
1.113 + }
1.114 +
1.115 + TBuf<64> romNotCompressed(KRomNotCompressed);
1.116 + TBuf<64> romCompressed(KRomCompressed);
1.117 + TBuf<64> fileNotCompressed(KFileNotCompressed);
1.118 + TBuf<64> fileCompressed(KFileCompressed);
1.119 +
1.120 + TInt ret = KErrNone;
1.121 + CFbsBitmap rom;
1.122 + CFbsBitmap romcomp;
1.123 +
1.124 + if(!skipRomBitmapTests)
1.125 + {
1.126 + TEST(rom.Load(romNotCompressed, 0, EFalse)== KErrNone);
1.127 + TEST(romcomp.Load(romCompressed, 0, EFalse)== KErrNone);
1.128 +
1.129 + INFO_PRINTF1(_L("Check compressing of ROM bitmaps causes error.\r\n"));
1.130 + ret = rom.Compress();
1.131 + TEST(ret == KErrAccessDenied); //cannot compress bitmaps in ROM
1.132 + TEST(rom.IsCompressedInRAM());
1.133 + }
1.134 +
1.135 + CFbsBitmap file;
1.136 + CFbsBitmap filecomp;
1.137 + TEST(file.Load(fileNotCompressed, 0, EFalse)== KErrNone);
1.138 + TEST(filecomp.Load(fileCompressed, 0, EFalse)== KErrNone);
1.139 +
1.140 + INFO_PRINTF1(_L("Check compressing of RAM files is OK.\r\n"));
1.141 + CFbsBitmap ram;
1.142 + ret=ram.Load(fileNotCompressed,0,EFalse);
1.143 + TEST(ret == KErrNone);
1.144 + ret = ram.Compress();
1.145 + TEST(ret == KErrNone); //can compress bitmaps in RAM
1.146 + TEST(ram.IsCompressedInRAM());
1.147 +
1.148 + INFO_PRINTF1(_L("Check compressing a created EColor256 bitmap.\r\n"));
1.149 + CFbsBitmapEx created;
1.150 + ret=created.Create(TSize(200,200),EColor256);
1.151 + TEST(ret==KErrNone);
1.152 +
1.153 + // This makes sure we can compress it...
1.154 + BlankBitmap(created);
1.155 +
1.156 + ret = created.Compress();
1.157 + TEST(ret==KErrNone);
1.158 + TEST(created.IsCompressedInRAM());
1.159 +
1.160 + INFO_PRINTF1(_L("Check compressing a created EColor24MU bitmap.\r\n"));
1.161 + CFbsBitmapEx created24MU;
1.162 + ret=created24MU.Create(TSize(200,200),EColor16MU);
1.163 + TEST(ret==KErrNone);
1.164 +
1.165 + // This makes sure we can compress it...
1.166 + BlankBitmap(created24MU);
1.167 +
1.168 + ret = created24MU.Compress();
1.169 + TEST(ret==KErrNone);
1.170 + TEST(created24MU.IsCompressedInRAM());
1.171 +
1.172 + INFO_PRINTF1(_L("Try bitblt on all bitmaps"));
1.173 + for (TInt mode = EGray2; mode < EColorLast; mode++)
1.174 + {
1.175 + if(!skipRomBitmapTests)
1.176 + {
1.177 + INFO_PRINTF2(_L("BitBlt rom with %d display mode.\r\n"), mode);
1.178 + TestBitBltL(rom, TDisplayMode(mode));
1.179 + INFO_PRINTF2(_L("BitBlt romcomp with %d display mode.\r\n"), mode);
1.180 + TestBitBltL(romcomp, TDisplayMode(mode));
1.181 + }
1.182 + INFO_PRINTF2(_L("BitBlt file with %d display mode.\r\n"), mode);
1.183 + TestBitBltL(file, TDisplayMode(mode));
1.184 + INFO_PRINTF2(_L("BitBlt filecomp with %d display mode.\r\n"), mode);
1.185 + TestBitBltL(filecomp, TDisplayMode(mode));
1.186 + INFO_PRINTF2(_L("BitBlt ram with %d display mode.\r\n"), mode);
1.187 + TestBitBltL(ram, TDisplayMode(mode));
1.188 + INFO_PRINTF2(_L("BitBlt created with %d display mode.\r\n"), mode);
1.189 + TestBitBltL(created, TDisplayMode(mode));
1.190 + INFO_PRINTF2(_L("BitBlt 24MU created bitmap with %d display mode.\r\n"), mode);
1.191 + TestBitBltL(created24MU, TDisplayMode(mode));
1.192 + }
1.193 + }
1.194 +
1.195 +
1.196 +
1.197 +/**
1.198 + @SYMTestCaseID
1.199 + GRAPHICS-FBSERV-0572
1.200 +
1.201 + @SYMTestCaseDesc
1.202 + Testcode to check for fix to defect EXT-5DXGK6 Bitmap
1.203 + compression causes crash when loading skins.
1.204 + Its not a conclusive test as it depends on where the
1.205 + bitmap is loaded into memory and if there is
1.206 + memory allocated at the end of the bitmap.
1.207 +
1.208 + @SYMTestActions
1.209 +
1.210 + @SYMTestExpectedResults
1.211 + Test should pass
1.212 +*/
1.213 +void CTCompressed::DefectFix_EXT5DXGK6_L()
1.214 + {
1.215 + CFbsBitmapEx bmp1;
1.216 + TSize size(1000,1);
1.217 + TInt ret=bmp1.Create(size,EGray2);
1.218 + TEST(ret==KErrNone);
1.219 + BlankBitmap(bmp1);
1.220 +//
1.221 + // calculate the size of the destination scan line in bytes
1.222 + // + 31 to pad to 4 byte boundary; 8 bits in a byte
1.223 + TInt source_buffer_size = (size.iWidth + 31) / 8 ;
1.224 + TUint8* buffer = new(ELeave) TUint8[source_buffer_size];
1.225 + TPtr8 source_ptr(buffer,source_buffer_size,source_buffer_size);
1.226 +
1.227 + for(TInt ii = 0; ii<source_buffer_size; ++ii)
1.228 + {
1.229 + if(ii%2)
1.230 + source_ptr[ii] = 2;
1.231 + else
1.232 + source_ptr[ii] = 3;
1.233 + }
1.234 +
1.235 + source_ptr[source_buffer_size-1] = 5;
1.236 + source_ptr[source_buffer_size-2] = 5;
1.237 + source_ptr[source_buffer_size-3] = 5;
1.238 + source_ptr[source_buffer_size-4] = 4;
1.239 + bmp1.SetScanLine(source_ptr,0);
1.240 +
1.241 + delete [] buffer;
1.242 + bmp1.Compress();
1.243 + }
1.244 +
1.245 +/**
1.246 + * @SYMTestCaseID GRAPHICS-FBSERV-0500
1.247 + *
1.248 + * @SYMDEF INC082713
1.249 + *
1.250 + * @SYMTestCaseDesc Test RLE compression algorithm of EColor16MU and EColor16MA bitmaps.
1.251 + *
1.252 + * @SYMTestPriority Critical
1.253 + *
1.254 + * @SYMTestStatus Implemented
1.255 + *
1.256 + * @SYMTestActions The following test checks a corner-case of the algorithm triggered by a specific pixel pattern.
1.257 + *
1.258 + * The corner case is triggered when the input to the compression function ends in a run of equal pixels,
1.259 + * terminated by a single pixel that is different i.e. ...rrrrrrrrrrrrrrrg
1.260 + * where we have a run of equal (red) pixels followed by a green pixel, which is the last pixel in the
1.261 + * bitmap (or the scanline, depending on how the data is being compressed).
1.262 + *
1.263 + * This test case performs the following:
1.264 + * 1) Creates a bitmap in the display mode and of size specified in function args.
1.265 + * This size must be large enough to trigger the compression when requested.
1.266 + * 2) Creates a scanline the width of this bitmap, which is a run of equal pixels, and
1.267 + * then sets the last pixel to be different.
1.268 + * 3) Sets the last scanline of the bitmap to the scanline we have just created.
1.269 + * This means that the last scanline of the bitmap conforms to the corner-case pattern.
1.270 + * 4) Compresses the bitmap
1.271 + * 5) Checks the compression has been successful
1.272 + * 6) Retrieves the last scanline of the bitmap and compares it with the original one
1.273 + * to verify that the compression of data has been successful.
1.274 + *
1.275 + * @SYMTestExpectedResults
1.276 + * The compression should occur successfully without panicking.
1.277 + * The scanline retrieved from the compressed version of the bitmap should match
1.278 + * the original scanline created.
1.279 + */
1.280 +void CTCompressed::DefectFix_INC082713_L(const TDisplayMode aDispMode, const TSize aBitmapSize)
1.281 + {
1.282 + // *** This function assumes that pixels are stored as 32 bit words ***
1.283 + // *** for EColor16MU and EColor16MA bitmaps ***
1.284 + switch(aDispMode)
1.285 + {
1.286 + case EColor16MU:
1.287 + INFO_PRINTF1(_L("Check compression algorithm corner case for EColor16MU bitmap.\r\n"));
1.288 + break;
1.289 + case EColor16MA:
1.290 + INFO_PRINTF1(_L("Check compression algorithm corner case for EColor16MA bitmap.\r\n"));
1.291 + break;
1.292 + default:
1.293 + INFO_PRINTF1(_L("Unsupported display mode for test"));
1.294 + return;
1.295 + }
1.296 +
1.297 + CFbsBitmap bitmap;
1.298 + TInt ret=bitmap.Create(aBitmapSize,aDispMode);
1.299 + TEST(ret==KErrNone);
1.300 +
1.301 + TInt widthInPixels = bitmap.SizeInPixels().iWidth;
1.302 + TInt heightInPixels = bitmap.SizeInPixels().iHeight;
1.303 + TInt scanLineByteLength = bitmap.ScanLineLength(widthInPixels, aDispMode);
1.304 + TUint32* buffer = (TUint32*)User::AllocLC(scanLineByteLength);
1.305 +
1.306 + // Breaking from a run of equal pixels
1.307 + // i.e. rrrrrrr...rrrrrrrrg
1.308 + for (TInt ii = 0; ii < widthInPixels; ii++)
1.309 + {
1.310 + buffer[ii] = 0xc6ebff;
1.311 + }
1.312 + // Last pixel differs - must be able to re-enter loop when at last pixel
1.313 + buffer[widthInPixels - 1] = 0xcee7ff;
1.314 +
1.315 + TPtr8 scanline((TUint8*)buffer ,scanLineByteLength,scanLineByteLength);
1.316 +
1.317 + bitmap.SetScanLine(scanline, heightInPixels - 1);
1.318 +
1.319 + INFO_PRINTF1(_L("Compressing bitmap"));
1.320 + ret = bitmap.Compress();
1.321 + TEST(ret==KErrNone);
1.322 + TEST(bitmap.IsCompressedInRAM());
1.323 +
1.324 + // Retrieve the scanline from the compressed bitmap and compare with original
1.325 + // in order to test whether the scanline is correctly compressed
1.326 + INFO_PRINTF1(_L("Retrieving scanline from compressed bitmap"));
1.327 +
1.328 + TUint32* readbackbuffer = (TUint32*)User::AllocLC(scanLineByteLength);
1.329 + TPtr8 readbackscanline((TUint8*)readbackbuffer ,scanLineByteLength,scanLineByteLength);
1.330 + readbackscanline.Fill(0xff);
1.331 + bitmap.GetScanLine(readbackscanline,TPoint(0,heightInPixels - 1),widthInPixels, aDispMode);
1.332 +
1.333 + INFO_PRINTF1(_L("Comparing scanlines\r\n"));
1.334 + // Compare the original scanline with the one retrieved from the compressed version
1.335 + switch(aDispMode)
1.336 + {
1.337 + case EColor16MU:
1.338 + {
1.339 + TBool result = ETrue;
1.340 + for (TInt ii = 0; ii < widthInPixels; ii++)
1.341 + {
1.342 + // Must mask off top bits (as we can ignore them, since we have no alpha channel)
1.343 + TUint32 original = buffer[ii] & 0x00ffffff;
1.344 + TUint32 readback = readbackbuffer[ii] & 0x00ffffff;
1.345 + result = result && (original == readback);
1.346 + }
1.347 + TEST(result);
1.348 + }
1.349 + break;
1.350 + case EColor16MA:
1.351 + ret = Mem::Compare((TUint8*)buffer, scanLineByteLength, (TUint8*)readbackbuffer, scanLineByteLength);
1.352 + // Mem::Compare returns 0 if the two scanlines are equal
1.353 + TEST(ret == 0);
1.354 + break;
1.355 + default:
1.356 + INFO_PRINTF1(_L("Unsupported display mode for test"));
1.357 + break;
1.358 + }
1.359 +
1.360 + CleanupStack::PopAndDestroy(2, buffer);
1.361 + }
1.362 +
1.363 +void CTCompressed::TestBitBltL(CFbsBitmap& aBmp, TDisplayMode aDispMode)
1.364 + {
1.365 + CFbsScreenDevice* scd = 0;
1.366 + TRAPD(ret, scd = CFbsScreenDevice::NewL(_L("scdv"),aDispMode));
1.367 + if (!scd)
1.368 + {
1.369 + WARN_PRINTF3(_L("Could not create screen device in %d mode, reason=%d.\r\n"), aDispMode, ret);
1.370 + return;
1.371 + }
1.372 + CleanupStack::PushL(scd);
1.373 +
1.374 + scd->ChangeScreenDevice(NULL);
1.375 + CFbsBitGc* sgc;
1.376 + if (scd->CreateContext((CGraphicsContext*&)sgc)==KErrNone)
1.377 + {
1.378 + CleanupStack::PushL(sgc);
1.379 +
1.380 + TSize halfScreen = scd->SizeInPixels();
1.381 + halfScreen.iWidth /= 2;
1.382 +
1.383 + INFO_PRINTF1(_L("BitBlt..."));
1.384 + sgc->BitBlt(TPoint(halfScreen.iWidth,0),&aBmp);
1.385 + INFO_PRINTF1(_L("worked\r\n"));
1.386 +
1.387 + CleanupStack::PopAndDestroy(sgc);
1.388 + }
1.389 + else
1.390 + {
1.391 + INFO_PRINTF2(_L("Could not create context in %d mode.\r\n"), aDispMode);
1.392 + }
1.393 + CleanupStack::PopAndDestroy(scd);
1.394 + }
1.395 +
1.396 +/**
1.397 + @SYMTestCaseID
1.398 + GRAPHICS-FBSERV-0573
1.399 +
1.400 + @SYMDEF INC088856
1.401 +
1.402 + @SYMTestCaseDesc
1.403 + Verifies defect INC088856. Checks the
1.404 + updated padding value before compression for
1.405 + 256 gray scale and 64k colour.
1.406 +
1.407 + @SYMTestActions
1.408 + Creates a bitmap. Gets the bitmaps scanline length.
1.409 + Locks the heap. Retrieves the bitmaps data address.
1.410 + Unlocks the heap. Then for both 256 gray scale and 64k colour
1.411 + it checks the padding after compression matches before compression.
1.412 +
1.413 +
1.414 + @SYMTestExpectedResults
1.415 + Test should pass
1.416 +*/
1.417 +void CTCompressed::INC088856_TestL()
1.418 + {
1.419 + INFO_PRINTF1(_L("Check updated Padding value in before compression \r\n"));
1.420 +
1.421 + INFO_PRINTF1(_L("Check updated Padding value for EGray256 \r\n"));
1.422 + DoUpdateOnPadding(TSize(5,3),EGray256);
1.423 + DoUpdateOnPadding(TSize(25,43),EGray256);
1.424 +
1.425 + INFO_PRINTF1(_L("Check updated Padding value for EColor64K \r\n"));
1.426 + DoUpdateOnPadding(TSize(5,3),EColor64K);
1.427 + DoUpdateOnPadding(TSize(25,43),EColor64K);
1.428 + }
1.429 +
1.430 +void CTCompressed::DoUpdateOnPadding(const TSize aSize, const TDisplayMode aDispMode)
1.431 + {
1.432 + CFbsBitmapEx bmp1;
1.433 + TInt ret=bmp1.Create(aSize,aDispMode);
1.434 + TEST(ret==KErrNone);
1.435 +
1.436 + TInt dataLength = CFbsBitmap::ScanLineLength(aSize.iWidth, bmp1.DisplayMode()) * aSize.iHeight;
1.437 +
1.438 + bmp1.LockHeap();
1.439 + TUint8* srcBits = (TUint8*)bmp1.DataAddress();
1.440 + bmp1.UnlockHeap();
1.441 + TInt val=1,pos=0;
1.442 + switch (aDispMode)
1.443 + {
1.444 + case EGray256:
1.445 + {
1.446 + TUint8* bmpBits = srcBits;
1.447 + TUint8* bmpBitsLimit = srcBits + dataLength;
1.448 + while(bmpBits<bmpBitsLimit)
1.449 + {
1.450 + if(pos++ < aSize.iWidth)
1.451 + {
1.452 + *bmpBits++ = val;
1.453 + }
1.454 + else
1.455 + {
1.456 + bmpBits += 3;
1.457 + val++;
1.458 + pos=0;
1.459 + }
1.460 + }
1.461 + }
1.462 + break;
1.463 + case EColor64K:
1.464 + {
1.465 + TUint16* bmpBits = (TUint16*)srcBits;
1.466 + TUint16* bmpBitsLimit = (TUint16*)(srcBits + dataLength);
1.467 + while(bmpBits<bmpBitsLimit)
1.468 + {
1.469 + if(pos++ < aSize.iWidth)
1.470 + {
1.471 + *bmpBits++ = val;
1.472 + }
1.473 + else
1.474 + {
1.475 + bmpBits++;
1.476 + val++;
1.477 + pos=0;
1.478 + }
1.479 + }
1.480 + }
1.481 + break;
1.482 + default:
1.483 + break;
1.484 + }
1.485 +
1.486 + bmp1.Compress();
1.487 + TInt stride = bmp1.DataStride();
1.488 + TUint8* dataPtr = (TUint8*)bmp1.DataAddress();
1.489 + switch(aDispMode)
1.490 + {
1.491 + case EGray256:
1.492 + {
1.493 + for (TInt row = 0; row < aSize.iHeight - 1; ++row)
1.494 + {
1.495 + TEST(*dataPtr++ == stride - 1);
1.496 + TEST(*dataPtr++ == row + 1);
1.497 + }
1.498 + break;
1.499 + }
1.500 + case EColor64K:
1.501 + {
1.502 + for (TInt row = 0; row < aSize.iHeight - 1; ++row)
1.503 + {
1.504 + TEST(*dataPtr++ == stride / 2 - 1);
1.505 + TEST(*dataPtr++ == row + 1);
1.506 + TEST(*dataPtr++ == 0);
1.507 + }
1.508 + }
1.509 + break;
1.510 + default:
1.511 + break;
1.512 + }
1.513 + }
1.514 +
1.515 +/**
1.516 + * @SYMTestCaseID GRAPHICS-FBSERV-0615
1.517 + *
1.518 + * @SYMDEF PDEF115511
1.519 + *
1.520 + * @SYMTestCaseDesc
1.521 + * Test Fbserv robustness when bitmaps are destroyed while they are being background compressed
1.522 + *
1.523 + * @SYMTestPriority High
1.524 + *
1.525 + * @SYMTestStatus Implemented
1.526 + *
1.527 + * @SYMTestActions
1.528 + * Preform various scenarios to create bitmaps, compress them in background and then destroy the
1.529 + * bitmaps without waiting the compression to complete.
1.530 + *
1.531 + * @SYMTestExpectedResults
1.532 + * Fbserv does not crash because of misfirig its background compression active object
1.533 + */
1.534 +void CTCompressed::TestDestroyBitmapWhileBeingBackgroundCompressedL()
1.535 + {
1.536 + const TInt KNumOfBitmaps = 1000;
1.537 + const TSize KSize(1,1);
1.538 + const TDisplayMode KMode = EColor64K;
1.539 + CFbsBitmap* bitmaps[KNumOfBitmaps];
1.540 +
1.541 + // TestCase #1
1.542 + // Create N bitmap instances, compress them in background and destroy them in-reverse order
1.543 + // without waiting compression to complete
1.544 + INFO_PRINTF2(_L("Create %d bitmaps,compress them in background and destroy in reverse order"), KNumOfBitmaps);
1.545 +
1.546 + for (TInt idx=0; idx<KNumOfBitmaps; ++idx)
1.547 + {
1.548 + bitmaps[idx] = new(ELeave) CFbsBitmap;
1.549 + CleanupStack::PushL(bitmaps[idx]);
1.550 + User::LeaveIfError(bitmaps[idx]->Create(KSize, KMode));
1.551 + }
1.552 +
1.553 + for (TInt idx=0; idx<KNumOfBitmaps; ++idx)
1.554 + {
1.555 + User::LeaveIfError(bitmaps[idx]->CompressInBackground());
1.556 + }
1.557 +
1.558 + // Delete bitmaps in reverse order
1.559 + CleanupStack::PopAndDestroy(KNumOfBitmaps, bitmaps[0]);
1.560 +
1.561 + // TestCase #2
1.562 + // Create N bitmap instances, compress them in background and destroy them in the compression order
1.563 + // without waiting compression to complete
1.564 + INFO_PRINTF2(_L("Create %d bitmaps,compress them in background and destroy in forward order"), KNumOfBitmaps);
1.565 +
1.566 + for (TInt idx=0; idx<KNumOfBitmaps; ++idx)
1.567 + {
1.568 + bitmaps[idx] = new(ELeave) CFbsBitmap;
1.569 + CleanupStack::PushL(bitmaps[idx]);
1.570 + User::LeaveIfError(bitmaps[idx]->Create(KSize, KMode));
1.571 + }
1.572 +
1.573 + for (TInt idx=0; idx<KNumOfBitmaps; ++idx)
1.574 + {
1.575 + User::LeaveIfError(bitmaps[idx]->CompressInBackground());
1.576 + }
1.577 +
1.578 + // Delete bitmaps in compression order
1.579 + CleanupStack::Pop(KNumOfBitmaps, bitmaps[0]);
1.580 + for (TInt idx=0; idx<KNumOfBitmaps; ++idx)
1.581 + {
1.582 + delete bitmaps[idx];
1.583 + }
1.584 +
1.585 + // TestCase #3
1.586 + // Create N bitmap instances, compress them in background and destroy them in random order
1.587 + // without waiting compression to complete
1.588 + INFO_PRINTF2(_L("Create %d bitmaps,compress them in background and destroy in random order"), KNumOfBitmaps);
1.589 +
1.590 + TInt randomOrder[KNumOfBitmaps];
1.591 + for (TInt idx=0; idx<KNumOfBitmaps; ++idx)
1.592 + {
1.593 + bitmaps[idx] = new(ELeave) CFbsBitmap;
1.594 + CleanupStack::PushL(bitmaps[idx]);
1.595 + User::LeaveIfError(bitmaps[idx]->Create(KSize, KMode));
1.596 + randomOrder[idx] = idx;
1.597 + }
1.598 + // Randomise deletion order
1.599 + for (TInt idx=0; idx<KNumOfBitmaps; ++idx)
1.600 + {
1.601 + TInt swap = Math::Random()%KNumOfBitmaps;
1.602 + TInt tmp = randomOrder[idx];
1.603 + randomOrder[idx] = randomOrder[swap];
1.604 + randomOrder[swap] = tmp;
1.605 + }
1.606 +
1.607 + for (TInt idx=0; idx<KNumOfBitmaps; ++idx)
1.608 + {
1.609 + User::LeaveIfError(bitmaps[idx]->CompressInBackground());
1.610 + }
1.611 +
1.612 + // Delete bitmaps in random order
1.613 + CleanupStack::Pop(KNumOfBitmaps, bitmaps[0]);
1.614 + for (TInt idx=0; idx<KNumOfBitmaps; ++idx)
1.615 + {
1.616 + delete bitmaps[randomOrder[idx]];
1.617 + bitmaps[randomOrder[idx]] = NULL;
1.618 + }
1.619 + // Test all bitmaps has been destroyed
1.620 + for (TInt idx=0; idx<KNumOfBitmaps; ++idx)
1.621 + {
1.622 + TEST(bitmaps[idx]==NULL);
1.623 + }
1.624 +
1.625 + // TestCase #4
1.626 + // Create bitmap, compress it in background and immediately destroyed without waiting compression
1.627 + // to complete
1.628 + INFO_PRINTF2(_L("Create bitmap,compress in background and immediately destroyed. Repeat %d times"), KNumOfBitmaps);
1.629 +
1.630 + for (TInt idx=0; idx<KNumOfBitmaps; ++idx)
1.631 + {
1.632 + CFbsBitmap* bitmap = new(ELeave) CFbsBitmap;
1.633 + CleanupStack::PushL(bitmap);
1.634 + User::LeaveIfError(bitmap->Create(KSize, KMode));
1.635 + User::LeaveIfError(bitmap->CompressInBackground());
1.636 + CleanupStack::PopAndDestroy(bitmap);
1.637 + }
1.638 +
1.639 + // TestCase #5
1.640 + // Similar from #4 but executed from two different threads
1.641 + INFO_PRINTF2(_L("Create bitmap,compress in background and immediately destroyed from 2 different threads. Repeat %d times"), KNumOfBitmaps);
1.642 +
1.643 + const TInt KStackSize = 4096;
1.644 + const TInt KMinHeapSize = 4096;
1.645 + const TInt KMaxHeapSize = 1024*1024;
1.646 + RThread t1;
1.647 + User::LeaveIfError(t1.Create(_L("bgCompThreadFunc#1"), CTCompressed::BgCompThreadFunc, KStackSize, KMinHeapSize, KMaxHeapSize, NULL));
1.648 + RThread t2;
1.649 + User::LeaveIfError(t2.Create(_L("bgCompThreadFunc#2"), CTCompressed::BgCompThreadFunc, KStackSize, KMinHeapSize, KMaxHeapSize, NULL));
1.650 +
1.651 + TRequestStatus s1;
1.652 + TRequestStatus s2;
1.653 + t1.Logon(s1);
1.654 + t2.Logon(s2);
1.655 +
1.656 + t1.Resume();
1.657 + t2.Resume();
1.658 + User::WaitForRequest(s1);
1.659 + User::WaitForRequest(s2);
1.660 +
1.661 + t1.Close();
1.662 + t2.Close();
1.663 + }
1.664 +
1.665 +TInt CTCompressed::BgCompThreadFunc(TAny*)
1.666 + {
1.667 + const TInt KNumOfBitmaps = 1000;
1.668 + const TSize KSize(1,1);
1.669 + const TDisplayMode KMode = EColor64K;
1.670 +
1.671 + // No need to worries with cleanup stack and trap as resources will be freed if the thread
1.672 + // running this functions dies, panics or leaves.
1.673 +
1.674 + RFbsSession::Connect();
1.675 +
1.676 + for (TInt idx=0; idx<KNumOfBitmaps; ++idx)
1.677 + {
1.678 + CFbsBitmap* bitmap = new(ELeave) CFbsBitmap;
1.679 + User::LeaveIfError(bitmap->Create(KSize, KMode));
1.680 + User::LeaveIfError(bitmap->CompressInBackground());
1.681 + delete bitmap;
1.682 + }
1.683 +
1.684 + RFbsSession::Disconnect();
1.685 + return KErrNone;
1.686 + }
1.687 +
1.688 +
1.689 +/**
1.690 + * @SYMTestCaseID GRAPHICS-FBSERV-0616
1.691 + *
1.692 + * @SYMDEF INC123238
1.693 + *
1.694 + * @SYMTestCaseDesc
1.695 + * Test Fbserv bitmap's priority inversion when we use background compression against a long running thread
1.696 + *
1.697 + * @SYMTestPriority High
1.698 + *
1.699 + * @SYMTestStatus Implemented
1.700 + *
1.701 + * @SYMTestActions
1.702 + * Create a thread which creates a bitmap and makes a call to background compression. Once this thread resumed,
1.703 + * make the current thread as busy by doing some long running task and test the exit status of the bitmap compression thread.
1.704 + *
1.705 + * @SYMTestExpectedResults
1.706 + * Fbserv does priority inheritance and therefore protect against priority inversion, so the thread function will
1.707 + * do backgroud compression and the thread will exit successfully, which will pass the test. If it is not protect
1.708 + * against priority inversion with in 30 seconds(approximately) the test will fail without doing background compression.
1.709 + */
1.710 +void CTCompressed::TestBackgroundCompressionThreadPriorityInheritanceL()
1.711 + {
1.712 + const TInt KStackSize = 4096;
1.713 + const TInt KMinHeapSize = 4096;
1.714 + const TInt KMaxHeapSize = 1024*1024;
1.715 + const TInt KMaxViewChangeTime = 2000;
1.716 +
1.717 + INFO_PRINTF1(_L("Test case for Background Compression Thread Priority Inheritance\r\n"));
1.718 + //Create and start a thread which create a bitmap and calls CompressInBackground
1.719 + RThread thread1;
1.720 + User::LeaveIfError(thread1.Create(_L("CompressBgThreadFunc"), CTCompressed::CompressBgThreadFunc, KStackSize, KMinHeapSize, KMaxHeapSize, NULL));
1.721 + thread1.Resume();
1.722 + TUint startTime = User::TickCount();
1.723 +
1.724 + //Start a infinite running loop to make current thread as a busy and long running thread...
1.725 + for (;;)
1.726 + {
1.727 + TExitType exitType = thread1.ExitType();
1.728 + if(exitType != EExitPending)
1.729 + {
1.730 + TInt exitReason = thread1.ExitReason();
1.731 + TEST(exitType == EExitKill);
1.732 + TEST(exitReason == KErrNone);
1.733 + break;
1.734 + }
1.735 + TUint stopTime = User::TickCount();
1.736 + if((stopTime - startTime) > KMaxViewChangeTime) //Check for the busy task is running for more than 30 seconds...
1.737 + {
1.738 + TEST(EFalse);
1.739 + thread1.Terminate(KErrGeneral);
1.740 + break;
1.741 + }
1.742 + }
1.743 + thread1.Close();
1.744 + }
1.745 +
1.746 +/*
1.747 + Thread function used from the test case TestBackgroundCompressionThreadPriorityInheritanceL
1.748 + */
1.749 +TInt CTCompressed::CompressBgThreadFunc(TAny*)
1.750 + {
1.751 + const TSize KSize(100, 100);
1.752 + const TDisplayMode KMode = EColor64K;
1.753 +
1.754 + TInt err = RFbsSession::Connect();
1.755 + if (err != KErrNone)
1.756 + return err;
1.757 + CFbsBitmap* bitmap = new CFbsBitmap;
1.758 + if (!bitmap)
1.759 + return KErrNoMemory;
1.760 + err = bitmap->Create(KSize, KMode);
1.761 + if (err != KErrNone)
1.762 + return err;
1.763 + err = bitmap->CompressInBackground();
1.764 + if (err != KErrNone)
1.765 + return err;
1.766 + delete bitmap;
1.767 +
1.768 + RFbsSession::Disconnect();
1.769 + return KErrNone;
1.770 + }
1.771 +
1.772 +//--------------
1.773 +__CONSTRUCT_STEP__(Compressed)