os/kernelhwsrv/kerneltest/e32test/pccd/t_pccdbm.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/pccd/t_pccdbm.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,477 @@
     1.4 +// Copyright (c) 1996-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 the License "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 +// e32test\pccd\t_pccdbm.cpp
    1.18 +// 
    1.19 +//
    1.20 +#include "../mmu/d_sharedchunk.h"
    1.21 +#include <hal.h>
    1.22 +#include <e32test.h>
    1.23 +#include <e32svr.h>
    1.24 +#include <e32hal.h>
    1.25 +#include <e32uid.h>
    1.26 +
    1.27 +const TInt K1K = 1024;
    1.28 +const TInt K4K = 4096;
    1.29 +const TInt K1MB = K1K*K1K;
    1.30 +const TInt KMaxTestSize = K1MB;     // Redefine to increase test length
    1.31 +const TInt KVeryLongRdWrBufLen=((KMaxTestSize*2)+K4K);	// Double Max Test size + 4K
    1.32 +
    1.33 +LOCAL_D TPtr8 DataBuf(NULL, KVeryLongRdWrBufLen,KVeryLongRdWrBufLen);
    1.34 +LOCAL_D HBufC8* wrBufH = NULL;
    1.35 +
    1.36 +LOCAL_D TInt DriveNumber;
    1.37 +LOCAL_D TBusLocalDrive TheDrive;
    1.38 +LOCAL_D TBool IsReadOnly;
    1.39 +
    1.40 +LOCAL_D RSharedChunkLdd Ldd;
    1.41 +LOCAL_D RChunk TheChunk;
    1.42 +const TUint ChunkSize = KVeryLongRdWrBufLen;
    1.43 +
    1.44 +const TTimeIntervalMicroSeconds32 KFloatingPointTestTime = 10000000;	// 10 seconds
    1.45 +LOCAL_D TInt gFastCounterFreq;
    1.46 +LOCAL_D TBool ChangeFlag;
    1.47 +
    1.48 +RTest test(_L("Local Drive BenchMark Test"));
    1.49 +
    1.50 +///// Buffer Allocation
    1.51 +void AllocateBuffers()
    1.52 +	{
    1.53 +	test.Next(_L("Allocate Buffers"));
    1.54 +
    1.55 +	wrBufH = HBufC8::New(KVeryLongRdWrBufLen);
    1.56 +	test(wrBufH != NULL);
    1.57 +	}
    1.58 +	
    1.59 +void AllocateSharedBuffers(TBool Fragmented, TBool Caching)
    1.60 +	{
    1.61 +	// Setup SharedMemory Buffers
    1.62 +	test.Next(_L("Allocate Shared Memory\n"));
    1.63 +	
    1.64 +	RLoader l;
    1.65 +	test(l.Connect()==KErrNone);
    1.66 +	test(l.CancelLazyDllUnload()==KErrNone);
    1.67 +	l.Close();
    1.68 +
    1.69 +	test.Printf(_L("Initialise\n"));
    1.70 +	TInt PageSize = 0;
    1.71 +	TInt r = UserHal::PageSizeInBytes(PageSize);
    1.72 +	test(r==KErrNone);
    1.73 +
    1.74 +	test.Printf(_L("Loading test driver\n"));
    1.75 +	r = User::LoadLogicalDevice(KSharedChunkLddName);
    1.76 +	test(r==KErrNone || r==KErrAlreadyExists);
    1.77 +
    1.78 +	test.Printf(_L("Opening channel\n"));
    1.79 +	r = Ldd.Open();
    1.80 +	test(r==KErrNone);
    1.81 +
    1.82 +	test.Printf(_L("Create chunk\n"));
    1.83 +	
    1.84 +	TUint aCreateFlags = EMultiple|EOwnsMemory;
    1.85 +	
    1.86 +	if (Caching)
    1.87 +		{
    1.88 +		test.Printf(_L("Chunk Type:Caching\n"));
    1.89 +		aCreateFlags |= ECached;
    1.90 +		}
    1.91 +	else
    1.92 +		test.Printf(_L("Chunk Type:Fully Blocking\n"));
    1.93 +	
    1.94 +    TCommitType aCommitType = EContiguous;
    1.95 +      
    1.96 +    TUint TotalChunkSize = ChunkSize;  // rounded to nearest Page Size
    1.97 +    
    1.98 +	TUint ChunkAttribs = TotalChunkSize|aCreateFlags;	
    1.99 +	r = Ldd.CreateChunk(ChunkAttribs);
   1.100 +	test(r==KErrNone);
   1.101 +
   1.102 +	if(Fragmented)
   1.103 +		{
   1.104 +		test.Printf(_L("Commit Fragmented Memory\n"));
   1.105 +			
   1.106 +		// Allocate Pages in reverse order to maximise memory fragmentation
   1.107 +		TUint i = ChunkSize;
   1.108 +		do
   1.109 +			{
   1.110 +			i-=PageSize;
   1.111 +			test.Printf(_L("Commit %d\n"), i);
   1.112 +			r = Ldd.CommitMemory(aCommitType|i,PageSize);
   1.113 +			test(r==KErrNone);
   1.114 +			}while (i>0);
   1.115 +		}
   1.116 +	else
   1.117 +		{
   1.118 +		test.Printf(_L("Commit Contigouos Memory\n"));
   1.119 +		r = Ldd.CommitMemory(aCommitType,TotalChunkSize);
   1.120 +		test(r==KErrNone);
   1.121 +		}
   1.122 +
   1.123 +	test.Printf(_L("Open user handle\n"));
   1.124 +	r = Ldd.GetChunkHandle(TheChunk);
   1.125 +	test(r==KErrNone);
   1.126 +	
   1.127 +	}
   1.128 +
   1.129 +void DeAllocateBuffers()
   1.130 +	{
   1.131 +	delete wrBufH;
   1.132 +	}
   1.133 +
   1.134 +void DeAllocareSharedMemory()
   1.135 +	{
   1.136 +// destory chunk
   1.137 +	test.Printf(_L("Shared Memory\n"));
   1.138 +	test.Printf(_L("Close user chunk handle\n"));
   1.139 +	TheChunk.Close();
   1.140 +
   1.141 +	test.Printf(_L("Close kernel chunk handle\n"));
   1.142 +	TInt r = Ldd.CloseChunk();  // 1==DObject::EObjectDeleted
   1.143 +	test(r==1);
   1.144 +
   1.145 +	test.Printf(_L("Check chunk is destroyed\n"));
   1.146 +	r = Ldd.IsDestroyed();
   1.147 +	test(r==1);
   1.148 +        
   1.149 +	test.Printf(_L("Close test driver\n"));
   1.150 +	Ldd.Close();
   1.151 +	}
   1.152 +
   1.153 +// end Buffer allocation
   1.154 +
   1.155 +
   1.156 +LOCAL_C void FillRegion(TInt aBlockSize)
   1.157 +/**
   1.158 + * Fill media starting at pos 0, 
   1.159 + * with a pattern of 2*aBlockSize in length
   1.160 + */
   1.161 +	{
   1.162 +	test.Printf(_L("Fill Region with Data!\n"));
   1.163 +	DataBuf.SetLength(aBlockSize);
   1.164 +		
   1.165 +	//fill up buffer
   1.166 +	for (TInt i=0;i<(aBlockSize);i++)
   1.167 +		{
   1.168 +		DataBuf[i]=(TUint8)(0xFF-i);
   1.169 +		}
   1.170 +	
   1.171 +	TInt r = TheDrive.Write(0, DataBuf);
   1.172 +	test (r == KErrNone);
   1.173 +	}
   1.174 +
   1.175 +LOCAL_C void DoTestRead(TInt aBlockSize)
   1.176 +// 
   1.177 +// Multiple Read operations of aBlockSize are performed for 10 seconds.
   1.178 +// Average is then displayed.
   1.179 +//
   1.180 +	{
   1.181 +	DataBuf.SetLength(aBlockSize);
   1.182 +	
   1.183 +	TUint functionCalls = 0;
   1.184 +	TUint initTicks = 0;
   1.185 +	TUint finalTicks = 0;
   1.186 +
   1.187 +	RTimer timer;
   1.188 +	timer.CreateLocal();
   1.189 +	TRequestStatus reqStat;
   1.190 +
   1.191 +	TInt pos = 0;
   1.192 +
   1.193 +	timer.After(reqStat, KFloatingPointTestTime);
   1.194 +	initTicks = User::FastCounter();
   1.195 +	
   1.196 +	for (TInt i = 0; reqStat==KRequestPending; i++)
   1.197 +		{
   1.198 +		TInt r = TheDrive.Read(pos, aBlockSize, DataBuf);
   1.199 +		
   1.200 +		test (r == KErrNone);
   1.201 +		
   1.202 +		pos += aBlockSize;
   1.203 +		if (pos > KVeryLongRdWrBufLen-aBlockSize)
   1.204 +			pos = 0;
   1.205 +
   1.206 +		functionCalls++;
   1.207 +		}
   1.208 +
   1.209 +	finalTicks = User::FastCounter();
   1.210 +	timer.Close();
   1.211 +	
   1.212 +	TTimeIntervalMicroSeconds duration = TInt64(finalTicks - initTicks) * TInt64(1000000) / TInt64(gFastCounterFreq) ;
   1.213 +
   1.214 +	TInt dataTransferred = functionCalls * aBlockSize;
   1.215 +	TReal transferRate =  TReal32(dataTransferred) / 
   1.216 +						 TReal(duration.Int64()) * TReal(1000000) / TReal(K1K); // KB/s
   1.217 +		
   1.218 +	test.Printf(_L("Read  %7d bytes in %7d byte blocks:\t%11.3f KBytes/s\n"), 
   1.219 +				    dataTransferred, aBlockSize, transferRate);
   1.220 +
   1.221 +	return;
   1.222 +	}	
   1.223 +
   1.224 +
   1.225 +LOCAL_C void TestRead()
   1.226 +/**
   1.227 + * Repeat read test for values between 1Byte and KMaxTestSize, in steps of power of 2
   1.228 + */
   1.229 +	{
   1.230 +	FillRegion(KVeryLongRdWrBufLen);
   1.231 +	
   1.232 +	for (TInt i = 1; i<=KMaxTestSize; i*=2)
   1.233 +		{
   1.234 +		DoTestRead(i);
   1.235 +		}
   1.236 +	}
   1.237 +
   1.238 +LOCAL_C void DoTestWrite(TInt aBlockSize)
   1.239 +// 
   1.240 +// Multiple Write operations of aBlockSize are performed for 10 seconds.
   1.241 +// Average is then displayed.
   1.242 +//
   1.243 +	{
   1.244 +	DataBuf.SetLength(aBlockSize);
   1.245 +	
   1.246 +	//fill up buffer
   1.247 +	for (TInt i=0;i<aBlockSize;i++)
   1.248 +		{
   1.249 +		DataBuf[i]=(TUint8)(0xFF-i);
   1.250 +		}
   1.251 +	
   1.252 +	TUint functionCalls = 0;
   1.253 +	TUint initTicks = 0;
   1.254 +	TUint finalTicks = 0;
   1.255 +
   1.256 +	RTimer timer;
   1.257 +	timer.CreateLocal();
   1.258 +	TRequestStatus reqStat;
   1.259 +
   1.260 +	TInt pos = 0;
   1.261 +
   1.262 +	timer.After(reqStat, KFloatingPointTestTime);
   1.263 +	initTicks = User::FastCounter();
   1.264 +	
   1.265 +	for (TInt j = 0; reqStat==KRequestPending; j++)
   1.266 +		{
   1.267 +		TInt r = TheDrive.Write(pos, DataBuf);
   1.268 +		
   1.269 +		test (r == KErrNone);
   1.270 +		
   1.271 +		pos += aBlockSize;
   1.272 +		if (pos > KVeryLongRdWrBufLen-aBlockSize)
   1.273 +			pos = 0;
   1.274 +
   1.275 +		functionCalls++;
   1.276 +		}
   1.277 +
   1.278 +	finalTicks = User::FastCounter();
   1.279 +	timer.Close();
   1.280 +	
   1.281 +	TTimeIntervalMicroSeconds duration = TInt64(finalTicks - initTicks) * TInt64(1000000) / TInt64(gFastCounterFreq) ;
   1.282 +
   1.283 +	TInt dataTransferred = functionCalls * aBlockSize;
   1.284 +	TReal transferRate =  TReal32(dataTransferred) / 
   1.285 +						 TReal(duration.Int64()) * TReal(1000000) / TReal(K1K); // KB/s
   1.286 +		
   1.287 +	test.Printf(_L("Write %7d bytes in %7d byte blocks:\t%11.3f KBytes/s\n"), 
   1.288 +				    dataTransferred, aBlockSize, transferRate);
   1.289 +
   1.290 +	return;
   1.291 +	}	
   1.292 +
   1.293 +LOCAL_C void TestWrite()
   1.294 +/**
   1.295 + * Repeat write test for values between 1Byte and KMaxTestSize, in steps of power of 2
   1.296 + */
   1.297 +	{
   1.298 +	for (TInt i = 1; i<=KMaxTestSize; i*=2)
   1.299 +		{
   1.300 +		DoTestWrite(i);
   1.301 +		}
   1.302 +	}
   1.303 +
   1.304 +TBool TestDriveInfo()
   1.305 +	{
   1.306 +	test.Next( _L("Test drive info") );
   1.307 +	
   1.308 +	TLocalDriveCapsV6Buf DriveCaps;
   1.309 +	TheDrive.Caps( DriveCaps );
   1.310 +
   1.311 +	test.Printf( _L("Caps V1:\n\tiSize=0x%lx\n\tiType=%d\n\tiConnectionBusType=%d\n\tiDriveAtt=0x%x\n\tiMediaAtt=0x%x\n\tiBaseAddress=0x%x\n\tiFileSystemId=0x%x\n\tiPartitionType=0x%x\n"),
   1.312 +			DriveCaps().iSize,
   1.313 +			DriveCaps().iType,
   1.314 +			DriveCaps().iConnectionBusType,
   1.315 +			DriveCaps().iDriveAtt,
   1.316 +			DriveCaps().iMediaAtt,
   1.317 +			DriveCaps().iBaseAddress,
   1.318 +			DriveCaps().iFileSystemId,
   1.319 +			DriveCaps().iPartitionType );
   1.320 +
   1.321 +	test.Printf( _L("Caps V2:\n\tiHiddenSectors=0x%x\n\tiEraseBlockSize=0x%x\nCaps V3:\n\tiExtraInfo=%x\n\tiMaxBytesPerFormat=0x%x\n"),
   1.322 +			DriveCaps().iHiddenSectors,
   1.323 +			DriveCaps().iEraseBlockSize, 
   1.324 +			DriveCaps().iExtraInfo,
   1.325 +			DriveCaps().iMaxBytesPerFormat );
   1.326 +
   1.327 +	test.Printf( _L("Format info:\n\tiCapacity=0x%lx\n\tiSectorsPerCluster=0x%x\n\tiSectorsPerTrack=0x%x\n\tiNumberOfSides=0x%x\n\tiFatBits=%d\n"),
   1.328 +			DriveCaps().iFormatInfo.iCapacity,
   1.329 +			DriveCaps().iFormatInfo.iSectorsPerCluster,
   1.330 +			DriveCaps().iFormatInfo.iSectorsPerTrack,
   1.331 +			DriveCaps().iFormatInfo.iNumberOfSides,
   1.332 +			DriveCaps().iFormatInfo.iFATBits );
   1.333 +
   1.334 +	test.Printf( _L("Caps V4:\n"));
   1.335 +	test.Printf(_L("\tiNumberOfSectors: %d\r\n"),DriveCaps().iNumberOfSectors);
   1.336 +	test.Printf(_L("\tiNumPagesPerBlock: %d\r\n"),DriveCaps().iNumPagesPerBlock);
   1.337 +	test.Printf(_L("\tiSectorSizeInBytes: %d\r\n"),DriveCaps().iSectorSizeInBytes);
   1.338 +	test.Printf(_L("\tiNumBytesSpare: %d\r\n"),DriveCaps().iNumBytesSpare);
   1.339 +	test.Printf(_L("\tiEffectiveBlks: %d\r\n"),DriveCaps().iEffectiveBlks);
   1.340 +	test.Printf(_L("\tiStartPage: %d\r\n"),DriveCaps().iStartPage);
   1.341 +	test.Printf(_L("\tMediaSizeInBytes: %ld\r\n"),DriveCaps().MediaSizeInBytes());
   1.342 +	
   1.343 +	test.Printf( _L("Caps V5:\n"));
   1.344 +	if(DriveCaps().iSerialNumLength > 0)
   1.345 +		{
   1.346 +        test.Printf( _L("\tiSerialNum : ") );
   1.347 +        TBuf8<2*KMaxSerialNumLength> snBuf;
   1.348 +        TUint i;
   1.349 +		for (i=0; i<DriveCaps().iSerialNumLength; i++)
   1.350 +			{
   1.351 +            snBuf.AppendNumFixedWidth( DriveCaps().iSerialNum[i], EHex, 2 );
   1.352 +			test.Printf( _L("%02x"), DriveCaps().iSerialNum[i]);
   1.353 +			}
   1.354 +		test.Printf( _L("\n") );
   1.355 +		}
   1.356 +	else
   1.357 +		{
   1.358 +		test.Printf( _L("\tiSerialNum : Not Supported") );
   1.359 +		}
   1.360 +	
   1.361 +	test.Printf(_L("Caps V6:\n"));
   1.362 +	test.Printf(_L("\tiBlockSize: %d\r\n"),DriveCaps().iBlockSize);
   1.363 +	
   1.364 +	TBool isReadOnly = DriveCaps().iMediaAtt & KMediaAttWriteProtected;
   1.365 +	return(isReadOnly);
   1.366 +	}
   1.367 +
   1.368 +
   1.369 +
   1.370 +void ParseCommandLineArgs()
   1.371 +	{
   1.372 +	TBuf<0x100> buf;
   1.373 +	
   1.374 +	TChar driveToTest;
   1.375 +
   1.376 +	// Get the list of drives
   1.377 +	TDriveInfoV1Buf diBuf;
   1.378 +	UserHal::DriveInfo(diBuf);
   1.379 +	TDriveInfoV1 &di=diBuf();
   1.380 +	TInt driveCount = di.iTotalSupportedDrives;
   1.381 +
   1.382 +	// Parse command line arguments for the drive to test
   1.383 +	User::CommandLine(buf);
   1.384 +	TLex lex(buf);
   1.385 +	TPtrC token=lex.NextToken();
   1.386 +	TFileName thisfile=RProcess().FileName();
   1.387 +	if (token.MatchF(thisfile)==0)
   1.388 +		{
   1.389 +		token.Set(lex.NextToken());
   1.390 +		}
   1.391 +
   1.392 +	if(token.Length()!=0)
   1.393 +		{
   1.394 +		driveToTest=token[0];
   1.395 +		}
   1.396 +	else
   1.397 +		{		
   1.398 +		//Print the list of usable drives
   1.399 +		test.Printf(_L("\nDRIVES USED AT PRESENT :\r\n"));
   1.400 +
   1.401 +		for (TInt i=0; i < driveCount; i++)
   1.402 +			{
   1.403 +			TBool flag=EFalse;
   1.404 +			RLocalDrive d;
   1.405 +			TInt r=d.Connect(i,flag);
   1.406 +			//Not all the drives are used at present
   1.407 +			if (r == KErrNotSupported)
   1.408 +				continue;
   1.409 +
   1.410 +			test.Printf(_L("%d : DRIVE NAME  :%- 16S\r\n"), i, &di.iDriveName[i]);
   1.411 +			}	
   1.412 +		
   1.413 +		test.Printf(_L("\r\nWarning - all data on drive will be lost.\r\n"));
   1.414 +		test.Printf(_L("<<<Hit drive number to continue>>>\r\n"));
   1.415 +
   1.416 +		driveToTest=(TUint)test.Getch();
   1.417 +		}
   1.418 +
   1.419 +	DriveNumber=((TUint)driveToTest) - '0';
   1.420 +	test(DriveNumber >= 1 && DriveNumber < di.iTotalSupportedDrives);
   1.421 +	}
   1.422 +
   1.423 +GLDEF_C TInt E32Main()
   1.424 +    {
   1.425 +	test.Title();
   1.426 +	test.Start(_L("Benchmark Testing for Local Media Drivers"));
   1.427 +	
   1.428 +	ParseCommandLineArgs();
   1.429 +	
   1.430 +	AllocateBuffers();
   1.431 +	
   1.432 +	test.Printf(_L("Connect to local drive (%d)\n"),DriveNumber);
   1.433 +
   1.434 +	ChangeFlag=EFalse;
   1.435 +	test(TheDrive.Connect(DriveNumber,ChangeFlag)==KErrNone);
   1.436 +	
   1.437 +	TInt r = HAL::Get(HAL::EFastCounterFrequency, gFastCounterFreq);	
   1.438 +	test(r == KErrNone);
   1.439 +
   1.440 +	IsReadOnly = TestDriveInfo();
   1.441 +	
   1.442 +	if (IsReadOnly)
   1.443 +		{
   1.444 +		test.Printf(_L("Drive is read only - can't run test!!\n"));
   1.445 +		DeAllocateBuffers();
   1.446 +	    test.End();
   1.447 +		return(0);
   1.448 +		}
   1.449 +	
   1.450 +// Heap Memory 	
   1.451 +	DataBuf.Set(wrBufH->Des());
   1.452 +	test.Next(_L("Read Benchmark - Heap Memory"));
   1.453 +	TestRead();
   1.454 +	test.Next(_L("Write Benchmark - Heap Memory"));
   1.455 +	TestWrite();
   1.456 +	DeAllocateBuffers();
   1.457 +	
   1.458 +// Contiguous Shared Chunk	
   1.459 +	AllocateSharedBuffers(EFalse, EFalse);
   1.460 +	DataBuf.Set(TheChunk.Base(),KVeryLongRdWrBufLen, KVeryLongRdWrBufLen);
   1.461 +	test.Next(_L("Read Benchmark - Shared Contiguous Memory"));
   1.462 +	TestRead();
   1.463 +	test.Next(_L("Write Benchmark - Shared Contiguous Memory"));
   1.464 +	TestWrite();
   1.465 +	DeAllocareSharedMemory();
   1.466 +
   1.467 +// Fragmented Shared Chunk	
   1.468 +	AllocateSharedBuffers(ETrue, EFalse);
   1.469 +	DataBuf.Set(TheChunk.Base(),KVeryLongRdWrBufLen, KVeryLongRdWrBufLen);
   1.470 +	test.Next(_L("Read Benchmark - Shared Fragmented Memory"));
   1.471 +	TestRead();
   1.472 +	test.Next(_L("Write Benchmark - Shared Fragmented Memory"));
   1.473 +	TestWrite();
   1.474 +	DeAllocareSharedMemory();	
   1.475 +	
   1.476 +    test.End();
   1.477 +
   1.478 +	return(0);
   1.479 +	}
   1.480 +