Update contrib.
1 // Copyright (c) 1996-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 the License "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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32test\pccd\t_pccdbm.cpp
17 #include "../mmu/d_sharedchunk.h"
24 const TInt K1K = 1024;
25 const TInt K4K = 4096;
26 const TInt K1MB = K1K*K1K;
27 const TInt KMaxTestSize = K1MB; // Redefine to increase test length
28 const TInt KVeryLongRdWrBufLen=((KMaxTestSize*2)+K4K); // Double Max Test size + 4K
30 LOCAL_D TPtr8 DataBuf(NULL, KVeryLongRdWrBufLen,KVeryLongRdWrBufLen);
31 LOCAL_D HBufC8* wrBufH = NULL;
33 LOCAL_D TInt DriveNumber;
34 LOCAL_D TBusLocalDrive TheDrive;
35 LOCAL_D TBool IsReadOnly;
37 LOCAL_D RSharedChunkLdd Ldd;
38 LOCAL_D RChunk TheChunk;
39 const TUint ChunkSize = KVeryLongRdWrBufLen;
41 const TTimeIntervalMicroSeconds32 KFloatingPointTestTime = 10000000; // 10 seconds
42 LOCAL_D TInt gFastCounterFreq;
43 LOCAL_D TBool ChangeFlag;
45 RTest test(_L("Local Drive BenchMark Test"));
47 ///// Buffer Allocation
48 void AllocateBuffers()
50 test.Next(_L("Allocate Buffers"));
52 wrBufH = HBufC8::New(KVeryLongRdWrBufLen);
56 void AllocateSharedBuffers(TBool Fragmented, TBool Caching)
58 // Setup SharedMemory Buffers
59 test.Next(_L("Allocate Shared Memory\n"));
62 test(l.Connect()==KErrNone);
63 test(l.CancelLazyDllUnload()==KErrNone);
66 test.Printf(_L("Initialise\n"));
68 TInt r = UserHal::PageSizeInBytes(PageSize);
71 test.Printf(_L("Loading test driver\n"));
72 r = User::LoadLogicalDevice(KSharedChunkLddName);
73 test(r==KErrNone || r==KErrAlreadyExists);
75 test.Printf(_L("Opening channel\n"));
79 test.Printf(_L("Create chunk\n"));
81 TUint aCreateFlags = EMultiple|EOwnsMemory;
85 test.Printf(_L("Chunk Type:Caching\n"));
86 aCreateFlags |= ECached;
89 test.Printf(_L("Chunk Type:Fully Blocking\n"));
91 TCommitType aCommitType = EContiguous;
93 TUint TotalChunkSize = ChunkSize; // rounded to nearest Page Size
95 TUint ChunkAttribs = TotalChunkSize|aCreateFlags;
96 r = Ldd.CreateChunk(ChunkAttribs);
101 test.Printf(_L("Commit Fragmented Memory\n"));
103 // Allocate Pages in reverse order to maximise memory fragmentation
108 test.Printf(_L("Commit %d\n"), i);
109 r = Ldd.CommitMemory(aCommitType|i,PageSize);
115 test.Printf(_L("Commit Contigouos Memory\n"));
116 r = Ldd.CommitMemory(aCommitType,TotalChunkSize);
120 test.Printf(_L("Open user handle\n"));
121 r = Ldd.GetChunkHandle(TheChunk);
126 void DeAllocateBuffers()
131 void DeAllocareSharedMemory()
134 test.Printf(_L("Shared Memory\n"));
135 test.Printf(_L("Close user chunk handle\n"));
138 test.Printf(_L("Close kernel chunk handle\n"));
139 TInt r = Ldd.CloseChunk(); // 1==DObject::EObjectDeleted
142 test.Printf(_L("Check chunk is destroyed\n"));
143 r = Ldd.IsDestroyed();
146 test.Printf(_L("Close test driver\n"));
150 // end Buffer allocation
153 LOCAL_C void FillRegion(TInt aBlockSize)
155 * Fill media starting at pos 0,
156 * with a pattern of 2*aBlockSize in length
159 test.Printf(_L("Fill Region with Data!\n"));
160 DataBuf.SetLength(aBlockSize);
163 for (TInt i=0;i<(aBlockSize);i++)
165 DataBuf[i]=(TUint8)(0xFF-i);
168 TInt r = TheDrive.Write(0, DataBuf);
169 test (r == KErrNone);
172 LOCAL_C void DoTestRead(TInt aBlockSize)
174 // Multiple Read operations of aBlockSize are performed for 10 seconds.
175 // Average is then displayed.
178 DataBuf.SetLength(aBlockSize);
180 TUint functionCalls = 0;
182 TUint finalTicks = 0;
186 TRequestStatus reqStat;
190 timer.After(reqStat, KFloatingPointTestTime);
191 initTicks = User::FastCounter();
193 for (TInt i = 0; reqStat==KRequestPending; i++)
195 TInt r = TheDrive.Read(pos, aBlockSize, DataBuf);
197 test (r == KErrNone);
200 if (pos > KVeryLongRdWrBufLen-aBlockSize)
206 finalTicks = User::FastCounter();
209 TTimeIntervalMicroSeconds duration = TInt64(finalTicks - initTicks) * TInt64(1000000) / TInt64(gFastCounterFreq) ;
211 TInt dataTransferred = functionCalls * aBlockSize;
212 TReal transferRate = TReal32(dataTransferred) /
213 TReal(duration.Int64()) * TReal(1000000) / TReal(K1K); // KB/s
215 test.Printf(_L("Read %7d bytes in %7d byte blocks:\t%11.3f KBytes/s\n"),
216 dataTransferred, aBlockSize, transferRate);
222 LOCAL_C void TestRead()
224 * Repeat read test for values between 1Byte and KMaxTestSize, in steps of power of 2
227 FillRegion(KVeryLongRdWrBufLen);
229 for (TInt i = 1; i<=KMaxTestSize; i*=2)
235 LOCAL_C void DoTestWrite(TInt aBlockSize)
237 // Multiple Write operations of aBlockSize are performed for 10 seconds.
238 // Average is then displayed.
241 DataBuf.SetLength(aBlockSize);
244 for (TInt i=0;i<aBlockSize;i++)
246 DataBuf[i]=(TUint8)(0xFF-i);
249 TUint functionCalls = 0;
251 TUint finalTicks = 0;
255 TRequestStatus reqStat;
259 timer.After(reqStat, KFloatingPointTestTime);
260 initTicks = User::FastCounter();
262 for (TInt j = 0; reqStat==KRequestPending; j++)
264 TInt r = TheDrive.Write(pos, DataBuf);
266 test (r == KErrNone);
269 if (pos > KVeryLongRdWrBufLen-aBlockSize)
275 finalTicks = User::FastCounter();
278 TTimeIntervalMicroSeconds duration = TInt64(finalTicks - initTicks) * TInt64(1000000) / TInt64(gFastCounterFreq) ;
280 TInt dataTransferred = functionCalls * aBlockSize;
281 TReal transferRate = TReal32(dataTransferred) /
282 TReal(duration.Int64()) * TReal(1000000) / TReal(K1K); // KB/s
284 test.Printf(_L("Write %7d bytes in %7d byte blocks:\t%11.3f KBytes/s\n"),
285 dataTransferred, aBlockSize, transferRate);
290 LOCAL_C void TestWrite()
292 * Repeat write test for values between 1Byte and KMaxTestSize, in steps of power of 2
295 for (TInt i = 1; i<=KMaxTestSize; i*=2)
301 TBool TestDriveInfo()
303 test.Next( _L("Test drive info") );
305 TLocalDriveCapsV6Buf DriveCaps;
306 TheDrive.Caps( DriveCaps );
308 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"),
311 DriveCaps().iConnectionBusType,
312 DriveCaps().iDriveAtt,
313 DriveCaps().iMediaAtt,
314 DriveCaps().iBaseAddress,
315 DriveCaps().iFileSystemId,
316 DriveCaps().iPartitionType );
318 test.Printf( _L("Caps V2:\n\tiHiddenSectors=0x%x\n\tiEraseBlockSize=0x%x\nCaps V3:\n\tiExtraInfo=%x\n\tiMaxBytesPerFormat=0x%x\n"),
319 DriveCaps().iHiddenSectors,
320 DriveCaps().iEraseBlockSize,
321 DriveCaps().iExtraInfo,
322 DriveCaps().iMaxBytesPerFormat );
324 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"),
325 DriveCaps().iFormatInfo.iCapacity,
326 DriveCaps().iFormatInfo.iSectorsPerCluster,
327 DriveCaps().iFormatInfo.iSectorsPerTrack,
328 DriveCaps().iFormatInfo.iNumberOfSides,
329 DriveCaps().iFormatInfo.iFATBits );
331 test.Printf( _L("Caps V4:\n"));
332 test.Printf(_L("\tiNumberOfSectors: %d\r\n"),DriveCaps().iNumberOfSectors);
333 test.Printf(_L("\tiNumPagesPerBlock: %d\r\n"),DriveCaps().iNumPagesPerBlock);
334 test.Printf(_L("\tiSectorSizeInBytes: %d\r\n"),DriveCaps().iSectorSizeInBytes);
335 test.Printf(_L("\tiNumBytesSpare: %d\r\n"),DriveCaps().iNumBytesSpare);
336 test.Printf(_L("\tiEffectiveBlks: %d\r\n"),DriveCaps().iEffectiveBlks);
337 test.Printf(_L("\tiStartPage: %d\r\n"),DriveCaps().iStartPage);
338 test.Printf(_L("\tMediaSizeInBytes: %ld\r\n"),DriveCaps().MediaSizeInBytes());
340 test.Printf( _L("Caps V5:\n"));
341 if(DriveCaps().iSerialNumLength > 0)
343 test.Printf( _L("\tiSerialNum : ") );
344 TBuf8<2*KMaxSerialNumLength> snBuf;
346 for (i=0; i<DriveCaps().iSerialNumLength; i++)
348 snBuf.AppendNumFixedWidth( DriveCaps().iSerialNum[i], EHex, 2 );
349 test.Printf( _L("%02x"), DriveCaps().iSerialNum[i]);
351 test.Printf( _L("\n") );
355 test.Printf( _L("\tiSerialNum : Not Supported") );
358 test.Printf(_L("Caps V6:\n"));
359 test.Printf(_L("\tiBlockSize: %d\r\n"),DriveCaps().iBlockSize);
361 TBool isReadOnly = DriveCaps().iMediaAtt & KMediaAttWriteProtected;
367 void ParseCommandLineArgs()
373 // Get the list of drives
374 TDriveInfoV1Buf diBuf;
375 UserHal::DriveInfo(diBuf);
376 TDriveInfoV1 &di=diBuf();
377 TInt driveCount = di.iTotalSupportedDrives;
379 // Parse command line arguments for the drive to test
380 User::CommandLine(buf);
382 TPtrC token=lex.NextToken();
383 TFileName thisfile=RProcess().FileName();
384 if (token.MatchF(thisfile)==0)
386 token.Set(lex.NextToken());
389 if(token.Length()!=0)
391 driveToTest=token[0];
395 //Print the list of usable drives
396 test.Printf(_L("\nDRIVES USED AT PRESENT :\r\n"));
398 for (TInt i=0; i < driveCount; i++)
402 TInt r=d.Connect(i,flag);
403 //Not all the drives are used at present
404 if (r == KErrNotSupported)
407 test.Printf(_L("%d : DRIVE NAME :%- 16S\r\n"), i, &di.iDriveName[i]);
410 test.Printf(_L("\r\nWarning - all data on drive will be lost.\r\n"));
411 test.Printf(_L("<<<Hit drive number to continue>>>\r\n"));
413 driveToTest=(TUint)test.Getch();
416 DriveNumber=((TUint)driveToTest) - '0';
417 test(DriveNumber >= 1 && DriveNumber < di.iTotalSupportedDrives);
420 GLDEF_C TInt E32Main()
423 test.Start(_L("Benchmark Testing for Local Media Drivers"));
425 ParseCommandLineArgs();
429 test.Printf(_L("Connect to local drive (%d)\n"),DriveNumber);
432 test(TheDrive.Connect(DriveNumber,ChangeFlag)==KErrNone);
434 TInt r = HAL::Get(HAL::EFastCounterFrequency, gFastCounterFreq);
437 IsReadOnly = TestDriveInfo();
441 test.Printf(_L("Drive is read only - can't run test!!\n"));
448 DataBuf.Set(wrBufH->Des());
449 test.Next(_L("Read Benchmark - Heap Memory"));
451 test.Next(_L("Write Benchmark - Heap Memory"));
455 // Contiguous Shared Chunk
456 AllocateSharedBuffers(EFalse, EFalse);
457 DataBuf.Set(TheChunk.Base(),KVeryLongRdWrBufLen, KVeryLongRdWrBufLen);
458 test.Next(_L("Read Benchmark - Shared Contiguous Memory"));
460 test.Next(_L("Write Benchmark - Shared Contiguous Memory"));
462 DeAllocareSharedMemory();
464 // Fragmented Shared Chunk
465 AllocateSharedBuffers(ETrue, EFalse);
466 DataBuf.Set(TheChunk.Base(),KVeryLongRdWrBufLen, KVeryLongRdWrBufLen);
467 test.Next(_L("Read Benchmark - Shared Fragmented Memory"));
469 test.Next(_L("Write Benchmark - Shared Fragmented Memory"));
471 DeAllocareSharedMemory();