First public contribution.
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 // f32test/bench/t_fsysbm.cpp
18 #define __E32TEST_EXTENSION__
26 #include <e32ldr_private.h>
28 #include "../../e32test/mmu/d_sharedchunk.h"
30 #define SYMBIAN_TEST_EXTENDED_BUFFER_SIZES // test using a greater number of buffer sizes
31 //#define SYMBIAN_TEST_COPY // read from one drive and write to another
34 GLDEF_D RTest test(_L("File System Benchmarks"));
36 static const TUint K1K = 1024; // 1K
37 static const TUint K1M = 1024 * 1024; // 1M
38 static const TUint K2M = 2 * K1M; // 2M
40 #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
41 const TInt64 KGb = 1 << 30;
42 const TInt64 K3GB = 3 * KGb;
43 const TInt64 K4GB = 4 * KGb;
44 #endif //SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
47 LOCAL_D TInt KMaxFileSize = 256 * K1K; // 256K
48 //LOCAL_D TInt KMaxFileSize = K1M; // 1M
50 //LOCAL_D TInt KMaxFileSize = 256 * K1K; // 256K
51 //LOCAL_D TInt KMaxFileSize = K1M; // 1M
52 LOCAL_D TInt KMaxFileSize = K2M; // 2M
55 const TTimeIntervalMicroSeconds32 KFloatingPointTestTime = 10000000; // 10 seconds
56 LOCAL_D const TInt KHeapSize = 0x4000;
58 LOCAL_D TPtr8 DataBuf(NULL, KMaxFileSize,KMaxFileSize);
59 LOCAL_D HBufC8* DataBufH = NULL;
61 LOCAL_D RSharedChunkLdd Ldd;
62 LOCAL_D RChunk TheChunk;
63 LOCAL_D TInt PageSize;
64 const TUint ChunkSize = KMaxFileSize;
67 LOCAL_D RFile File, File2;
68 LOCAL_D TChar gDriveToTest2;
70 // if enabled, Read and Write operations are not boundary aligned.
71 LOCAL_D TBool gMisalignedReadWrites = EFalse;
73 // read & write caching enabled flags - may be overriden by +/-r +/-w command line switches
74 LOCAL_D TBool gReadCachingOn = EFalse;
75 LOCAL_D TBool gWriteCachingOn = EFalse;
77 // if enabled, timings are for write AND flush
78 LOCAL_D TBool gFlushAfterWrite = ETrue;
80 // if enabled, contiguous shared memory is used for Data buffer
81 LOCAL_D TBool gSharedMemory = EFalse;
83 // if enabled, fragmented shared memory is used for Data buffer
84 LOCAL_D TBool gFragSharedMemory = EFalse;
86 LOCAL_D TInt gFastCounterFreq;
90 LOCAL_C void RecursiveRmDir(const TDesC& aDes)
92 // Delete directory contents recursively
98 TInt r=TheFs.GetDir(n,KEntryAttMaskSupported,EDirsLast,pD);
99 if (r==KErrNotFound || r==KErrPathNotFound)
102 TInt count=pD->Count();
106 const TEntry& e=(*pD)[i++];
110 dirName.Format(_L("%S%S\\"),&aDes,&e.iName);
111 RecursiveRmDir(dirName);
116 fileName.Format(_L("%S%S"),&aDes,&e.iName);
117 r=TheFs.Delete(fileName);
127 void LOCAL_C ClearSessionDirectory()
129 // Delete the contents of F32-TST
133 TInt r=TheFs.Parse(_L("\\F32-TST\\"),_L(""),sessionPath);
135 RecursiveRmDir(sessionPath.FullName());
136 r=TheFs.MkDir(sessionPath.FullName());
141 LOCAL_C void DoTestFileRead(TInt aBlockSize, TInt aFileSize = KMaxFileSize, TBool aReRead = EFalse)
147 // test.Printf(_L("Creating test file..."));
148 TInt writeBlockLen = aFileSize > DataBuf.MaxSize() ? DataBuf.MaxSize() : aFileSize;
149 DataBuf.SetLength(writeBlockLen);
151 for (TInt m = 0; m < DataBuf.Length(); m++)
152 DataBuf[m] = TText8(m % 256);
154 // To allow this test to run on a non-preq914 branch :
155 enum {EFileWriteDirectIO = 0x00001000};
156 TInt r = File.Create(TheFs, _L("READTEST"), EFileStream | EFileWriteDirectIO);
158 TInt count = aFileSize / DataBuf.Length();
161 // test.Printf(_L("done\n"));
164 enum {EFileReadBuffered = 0x00002000, EFileReadDirectIO = 0x00004000};
165 r = File.Open(TheFs, _L("READTEST"), EFileStream | (gReadCachingOn ? EFileReadBuffered : EFileReadDirectIO));
168 // const TInt maxReadCount = aFileSize / aBlockSize;
169 TUint functionCalls = 0;
171 #if defined SYMBIAN_TEST_COPY
172 // To allow this test to run on a non-preq914 branch :
173 enum {EFileWriteDirectIO = 0x00001000};
174 TInt r = File2.Replace(TheFs, _L("WRITETEST"), EFileStream | EFileWriteDirectIO);
181 // we stop after the entire file has been read or after 10 seconds, whichever happens sooner
184 TRequestStatus reqStat;
188 TUint finalTicks = 0;
190 // if aReRead file is set, then read file twice
191 for (TInt n=0; n<(aReRead?2:1); n++)
195 const TInt readLen = (aReRead && n == 0) ? writeBlockLen : aBlockSize;
196 const TInt maxReadCount = aFileSize / readLen;
199 File.Seek(ESeekStart, pos);
201 timer.After(reqStat, 10000000); // After 10 secs
202 startTime.HomeTime();
203 initTicks = User::FastCounter();
205 for (TInt i = 0; i<maxReadCount && reqStat==KRequestPending; i++)
207 // test.Printf(_L("Read %d\n"),i);
208 // for (TInt a = 0; a < 512; a++)
209 // test.Printf(_L("%d"),DataBuf[a]);
211 TInt r = File.Read(DataBuf, readLen);
212 test (r == KErrNone);
214 if (DataBuf.Length() == 0)
217 #if defined SYMBIAN_TEST_COPY
218 r = File2.Write(DataBuf, readLen);
219 test (r == KErrNone);
224 // for (TInt a = 0; a < 512; a++)
225 // test.Printf(_L("%d"),DataBuf[a]);
227 for (TInt j = 0; j < DataBuf.Size(); j++)
228 test(DataBuf[j] == (j + i * readLen) % 256);
233 finalTicks = User::FastCounter();
238 TInt dataTransferred = functionCalls * aBlockSize;
240 // TTimeIntervalMicroSeconds duration = endTime.MicroSecondsFrom(startTime);
241 TTimeIntervalMicroSeconds duration = TInt64(finalTicks - initTicks) * TInt64(1000000) / TInt64(gFastCounterFreq) ;
244 TReal32(dataTransferred) /
245 TReal(duration.Int64()) * TReal(1000000) / TReal(K1K); // KB/s
246 test.Printf(_L("Read %7d bytes in %7d byte blocks:\t%11.3f KBytes/s (%d microsecs)\n"),
247 dataTransferred, aBlockSize, transferRate, endTime.MicroSecondsFrom(startTime).Int64());
251 #if defined SYMBIAN_TEST_COPY
256 r = TheFs.Delete(_L("READTEST"));
262 LOCAL_C void TestFileRead(TInt aFileSize = KMaxFileSize, TBool aMisalignedReadWrites = EFalse, TBool aReRead = EFalse)
264 // Benchmark read method
267 ClearSessionDirectory();
268 test.Next(_L("Benchmark read method"));
270 _LIT(KLitReadOnce,"Read-once");
271 _LIT(KLitReRead,"Re-read");
272 test.Printf(_L("FileSize %d, MisalignedReadWrites %d %S\n"), aFileSize, aMisalignedReadWrites, aReRead ? &KLitReRead : &KLitReadOnce);
273 TInt misalignedOffset = aMisalignedReadWrites ? 1 : 0;
275 #if defined (SYMBIAN_TEST_EXTENDED_BUFFER_SIZES)
276 DoTestFileRead(1+misalignedOffset, aFileSize, aReRead);
277 DoTestFileRead(2+misalignedOffset, aFileSize, aReRead);
278 DoTestFileRead(4+misalignedOffset, aFileSize, aReRead);
279 DoTestFileRead(8+misalignedOffset, aFileSize, aReRead);
280 DoTestFileRead(16+misalignedOffset, aFileSize, aReRead);
281 DoTestFileRead(32+misalignedOffset, aFileSize, aReRead);
282 DoTestFileRead(64+misalignedOffset, aFileSize, aReRead);
283 DoTestFileRead(128+misalignedOffset, aFileSize, aReRead);
284 DoTestFileRead(256+misalignedOffset, aFileSize, aReRead);
285 DoTestFileRead(512+misalignedOffset, aFileSize, aReRead);
286 DoTestFileRead(1024+misalignedOffset, aFileSize, aReRead);
287 DoTestFileRead(2 * 1024+misalignedOffset, aFileSize, aReRead);
288 DoTestFileRead(4 * 1024+misalignedOffset, aFileSize, aReRead);
289 DoTestFileRead(8 * 1024+misalignedOffset, aFileSize, aReRead);
290 DoTestFileRead(16 * 1024+misalignedOffset, aFileSize, aReRead);
291 DoTestFileRead(32 * 1024+misalignedOffset, aFileSize, aReRead);
292 DoTestFileRead(64 * 1024+misalignedOffset, aFileSize, aReRead);
293 DoTestFileRead(128 * 1024+misalignedOffset, aFileSize, aReRead);
294 DoTestFileRead(256 * 1024+misalignedOffset, aFileSize, aReRead);
295 DoTestFileRead(512 * 1024+misalignedOffset, aFileSize, aReRead);
296 DoTestFileRead(1024 * 1024+misalignedOffset, aFileSize, aReRead);
298 DoTestFileRead(16+misalignedOffset, aFileSize, aReRead);
299 DoTestFileRead(512+misalignedOffset, aFileSize, aReRead);
300 DoTestFileRead(4096+misalignedOffset, aFileSize, aReRead);
301 DoTestFileRead(32768+misalignedOffset, aFileSize, aReRead);
302 DoTestFileRead(64 * 1024+misalignedOffset, aFileSize, aReRead);
303 DoTestFileRead(K1M+misalignedOffset, aFileSize, aReRead);
309 LOCAL_C TInt FloatingPointLoop(TAny* funcCount)
311 TUint& count = *(TUint*) funcCount;
323 LOCAL_C void DoTestFileReadCPU(TInt aBlockSize)
325 // Benchmark CPU utilisation for Read method
327 // Read operations are performed for 10 seconds whilst a second thread executes floating point calculations
328 // The higher the number of calculations the less amount of CPU time has been used by the Read method.
331 enum {EFileReadBuffered = 0x00002000, EFileReadDirectIO = 0x00004000};
332 TInt r = File.Open(TheFs, _L("READCPUTEST"), EFileStream | (gReadCachingOn ? EFileReadBuffered : EFileReadDirectIO));
337 TUint functionCalls = 0;
338 TUint fltPntCalls = 0;
341 TBuf<6> buf = _L("Floaty");
342 fltPntThrd.Create(buf, FloatingPointLoop, KDefaultStackSize, KHeapSize, KHeapSize, (TAny*) &fltPntCalls);
346 TRequestStatus reqStat;
349 TUint finalTicks = 0;
351 timer.After(reqStat, KFloatingPointTestTime); // After 10 secs
352 initTicks = User::FastCounter();
354 // up the priority of this thread so that we only run the floating point thread when this thread is idle
356 thisThread.SetPriority(EPriorityMuchMore);
359 fltPntThrd.Logon(req);
363 for (TInt i = 0; reqStat==KRequestPending; i++)
365 TInt r = File.Read(pos, DataBuf, aBlockSize);
366 test (r == KErrNone);
369 if (pos > KMaxFileSize-aBlockSize)
375 TUint fltPntCallsFinal = fltPntCalls;
376 fltPntThrd.Kill(KErrNone);
378 finalTicks = User::FastCounter();
381 User::WaitForRequest(req);
383 TInt dataTransferred = functionCalls * aBlockSize;
385 TTimeIntervalMicroSeconds duration = TInt64(finalTicks - initTicks) * TInt64(1000000) / TInt64(gFastCounterFreq) ;
387 TReal transferRate = TReal32(dataTransferred) /
388 TReal(duration.Int64()) * TReal(1000000) / TReal(K1K); // KB/s
390 test.Printf(_L("Read %7d bytes in %7d byte blocks:\t%11.3f KBytes/s; %d Flt Calcs\n"),
391 dataTransferred, aBlockSize, transferRate, fltPntCallsFinal);
401 LOCAL_C void TestFileReadCPU(TBool aMisalignedReadWrites = EFalse)
403 // Benchmark CPU utilisation for Read method
406 ClearSessionDirectory();
407 test.Next(_L("Benchmark Read method CPU Utilisation"));
409 test.Printf(_L("MisalignedReadWrites %d\n"), aMisalignedReadWrites);
410 TInt misalignedOffset = aMisalignedReadWrites ? 1 : 0;
413 test.Printf(_L("Creating test file..."));
414 DataBuf.SetLength(KMaxFileSize);
416 TInt r = File.Create(TheFs, _L("READCPUTEST"), EFileStream | EFileWriteDirectIO);
421 test.Printf(_L("done\n"));
424 DoTestFileReadCPU(1+misalignedOffset);
425 DoTestFileReadCPU(2+misalignedOffset);
426 DoTestFileReadCPU(4+misalignedOffset);
427 DoTestFileReadCPU(8+misalignedOffset);
428 DoTestFileReadCPU(16+misalignedOffset);
429 DoTestFileReadCPU(32+misalignedOffset);
430 DoTestFileReadCPU(64+misalignedOffset);
431 DoTestFileReadCPU(128+misalignedOffset);
432 DoTestFileReadCPU(256+misalignedOffset);
433 DoTestFileReadCPU(512+misalignedOffset);
434 DoTestFileReadCPU(1024+misalignedOffset);
435 DoTestFileReadCPU(2 * 1024+misalignedOffset);
436 DoTestFileReadCPU(4 * 1024+misalignedOffset);
437 DoTestFileReadCPU(8 * 1024+misalignedOffset);
438 DoTestFileReadCPU(16 * 1024+misalignedOffset);
439 DoTestFileReadCPU(32 * 1024+misalignedOffset);
440 DoTestFileReadCPU(64 * 1024+misalignedOffset);
441 DoTestFileReadCPU(128 * 1024+misalignedOffset);
442 DoTestFileReadCPU(256 * 1024+misalignedOffset);
443 DoTestFileReadCPU(512 * 1024+misalignedOffset);
444 DoTestFileReadCPU(K1M+misalignedOffset);
447 r = TheFs.Delete(_L("READCPUTEST"));
452 LOCAL_C void DoTestFileWrite(TInt aBlockSize, TInt aFileSize = KMaxFileSize, TBool aUpdate = EFalse)
454 // Do Write benchmark
457 DataBuf.SetLength(aBlockSize);
458 const TInt maxWriteCount = aFileSize / aBlockSize;
460 TFileName testDir(_L("?:\\F32-TST\\"));
461 testDir[0] = (TText) gDriveToTest;
462 TInt r = TheFs.MkDir(testDir);
463 test(r == KErrNone || r == KErrAlreadyExists);
466 enum {EFileWriteDirectIO = 0x00001000, EFileWriteBuffered = 0x00000800};
467 r = File.Temp(TheFs, testDir, fileName, EFileWrite | (gWriteCachingOn ? EFileWriteBuffered : EFileWriteDirectIO));
472 TInt r = File.SetSize(aFileSize);
476 TUint functionCalls = 0;
481 TUint finalTicks = 0;
484 // we stop after the entire file has been written or after 10 seconds, whichever happens sooner
487 TRequestStatus reqStat;
490 File.Seek(ESeekStart, pos);
492 timer.After(reqStat, 10000000); // After 10 secs
494 startTime.HomeTime();
495 initTicks = User::FastCounter();
497 for (TInt i = 0 ; i<maxWriteCount && reqStat==KRequestPending; i++)
499 File.Write(pos, DataBuf, aBlockSize);
502 if (pos > KMaxFileSize-aBlockSize)
508 if (gFlushAfterWrite)
514 // write file once only
515 finalTicks = User::FastCounter();
517 // TTimeIntervalMicroSeconds duration = endTime.MicroSecondsFrom(startTime);
518 TTimeIntervalMicroSeconds duration = TInt64(finalTicks - initTicks) * TInt64(1000000) / TInt64(gFastCounterFreq) ;
520 TInt dataTransferred = functionCalls * aBlockSize;
522 TReal32(dataTransferred) /
523 TReal(duration.Int64()) * TReal(1000000) / TReal(K1K); // KB/s
524 test.Printf(_L("Write %7d bytes in %7d byte blocks:\t%11.3f KBytes/s (%d microsecs)\n"),
525 dataTransferred, aBlockSize, transferRate, endTime.MicroSecondsFrom(startTime).Int64());
530 r = TheFs.Delete(fileName);
537 LOCAL_C void TestFileWrite(TInt aFileSize = KMaxFileSize, TBool aMisalignedReadWrites = EFalse, TBool aUpdate = EFalse)
539 // Benchmark write method
542 ClearSessionDirectory();
543 test.Next(_L("Benchmark write method"));
545 _LIT(KLitUpdate,"update");
546 _LIT(KLitAppend,"append");
547 test.Printf(_L("FileSize %d %S MisalignedReadWrites %d\n"), aFileSize, aUpdate? &KLitUpdate : &KLitAppend, aMisalignedReadWrites);
549 TInt misalignedOffset = aMisalignedReadWrites ? 1 : 0;
551 #if defined (SYMBIAN_TEST_EXTENDED_BUFFER_SIZES)
552 DoTestFileWrite(1+misalignedOffset, aFileSize, aUpdate);
553 DoTestFileWrite(2+misalignedOffset, aFileSize, aUpdate);
554 DoTestFileWrite(4+misalignedOffset, aFileSize, aUpdate);
555 DoTestFileWrite(8+misalignedOffset, aFileSize, aUpdate);
556 DoTestFileWrite(16+misalignedOffset, aFileSize, aUpdate);
557 DoTestFileWrite(32+misalignedOffset, aFileSize, aUpdate);
558 DoTestFileWrite(64+misalignedOffset, aFileSize, aUpdate);
559 DoTestFileWrite(128+misalignedOffset, aFileSize, aUpdate);
560 DoTestFileWrite(256+misalignedOffset, aFileSize, aUpdate);
561 DoTestFileWrite(512+misalignedOffset, aFileSize, aUpdate);
562 DoTestFileWrite(1024+misalignedOffset, aFileSize, aUpdate);
563 DoTestFileWrite(2 * 1024+misalignedOffset, aFileSize, aUpdate);
564 DoTestFileWrite(4 * 1024+misalignedOffset, aFileSize, aUpdate);
565 DoTestFileWrite(8 * 1024+misalignedOffset, aFileSize, aUpdate);
566 DoTestFileWrite(16 * 1024+misalignedOffset, aFileSize, aUpdate);
567 DoTestFileWrite(32 * 1024+misalignedOffset, aFileSize, aUpdate);
568 DoTestFileWrite(64 * 1024+misalignedOffset, aFileSize, aUpdate);
569 DoTestFileWrite(128 * 1024+misalignedOffset, aFileSize, aUpdate);
570 DoTestFileWrite(256 * 1024+misalignedOffset, aFileSize, aUpdate);
571 DoTestFileWrite(512 * 1024+misalignedOffset, aFileSize, aUpdate);
572 DoTestFileWrite(1024 * 1024+misalignedOffset, aFileSize, aUpdate);
574 DoTestFileWrite(16+misalignedOffset, aFileSize, aUpdate);
575 DoTestFileWrite(512+misalignedOffset, aFileSize, aUpdate);
576 DoTestFileWrite(4096+misalignedOffset, aFileSize, aUpdate);
577 DoTestFileWrite(32768+misalignedOffset, aFileSize, aUpdate);
578 DoTestFileWrite(64 * 1024+misalignedOffset, aFileSize, aUpdate);
579 DoTestFileWrite(K1M+misalignedOffset, aFileSize, aUpdate);
585 LOCAL_C void DoTestFileWriteCPU(TInt aBlockSize)
587 // Benchmark CPU utilisation for Write method
589 // Write operations are performed for 10 seconds whilst a second thread executes floating point calculations
590 // The higher the number of calculations the less amount of CPU time has been used by the Write method.
593 DataBuf.SetLength(aBlockSize);
595 TFileName testDir(_L("?:\\F32-TST\\"));
596 testDir[0] = (TText) gDriveToTest;
597 TInt r = TheFs.MkDir(testDir);
598 test(r == KErrNone || r == KErrAlreadyExists);
601 enum {EFileWriteDirectIO = 0x00001000, EFileWriteBuffered = 0x00000800};
602 r = File.Temp(TheFs, testDir, fileName, EFileWrite | (gWriteCachingOn ? EFileWriteBuffered : EFileWriteDirectIO));
605 TUint functionCalls = 0;
606 TUint fltPntCalls = 0;
609 TBuf<6> buf = _L("Floaty");
610 fltPntThrd.Create(buf, FloatingPointLoop, KDefaultStackSize, KHeapSize, KHeapSize, (TAny*) &fltPntCalls);
613 TUint finalTicks = 0;
615 // up the priority of this thread so that we only run the floating point thread when this thread is idle
617 thisThread.SetPriority(EPriorityMuchMore);
620 fltPntThrd.Logon(req);
624 TRequestStatus reqStat;
627 File.Seek(ESeekStart, pos);
629 timer.After(reqStat, KFloatingPointTestTime);
630 initTicks = User::FastCounter();
634 for (TInt i = 0 ; reqStat==KRequestPending; i++)
636 File.Write(DataBuf, aBlockSize);
639 TUint fltPntCallsFinal = fltPntCalls;
641 fltPntThrd.Kill(KErrNone);
643 finalTicks = User::FastCounter();
646 User::WaitForRequest(req);
648 TTimeIntervalMicroSeconds duration = TInt64(finalTicks - initTicks) * TInt64(1000000) / TInt64(gFastCounterFreq) ;
650 TInt dataTransferred = functionCalls * aBlockSize;
651 TReal transferRate = TReal32(dataTransferred) /
652 TReal(duration.Int64()) * TReal(1000000) / TReal(K1K); // KB/s
654 test.Printf(_L("Write %7d bytes in %7d byte blocks:\t%11.3f KBytes/s; %d Flt Calcs\n"),
655 dataTransferred, aBlockSize, transferRate, fltPntCallsFinal);
660 r = TheFs.Delete(fileName);
667 LOCAL_C void TestFileWriteCPU(TBool aMisalignedReadWrites = EFalse)
669 // Benchmark CPU utilisation for Write method
672 ClearSessionDirectory();
673 test.Next(_L("Benchmark Write method CPU Utilisation"));
675 test.Printf(_L("MisalignedReadWrites %d\n"), aMisalignedReadWrites);
676 TInt misalignedOffset = aMisalignedReadWrites ? 1 : 0;
678 DoTestFileWriteCPU(1+misalignedOffset);
679 DoTestFileWriteCPU(2+misalignedOffset);
680 DoTestFileWriteCPU(4+misalignedOffset);
681 DoTestFileWriteCPU(8+misalignedOffset);
682 DoTestFileWriteCPU(16+misalignedOffset);
683 DoTestFileWriteCPU(32+misalignedOffset);
684 DoTestFileWriteCPU(64+misalignedOffset);
685 DoTestFileWriteCPU(128+misalignedOffset);
686 DoTestFileWriteCPU(256+misalignedOffset);
687 DoTestFileWriteCPU(512+misalignedOffset);
688 DoTestFileWriteCPU(1024+misalignedOffset);
689 DoTestFileWriteCPU(2 * 1024+misalignedOffset);
690 DoTestFileWriteCPU(4 * 1024+misalignedOffset);
691 DoTestFileWriteCPU(8 * 1024+misalignedOffset);
692 DoTestFileWriteCPU(16 * 1024+misalignedOffset);
693 DoTestFileWriteCPU(32 * 1024+misalignedOffset);
694 DoTestFileWriteCPU(64 * 1024+misalignedOffset);
695 DoTestFileWriteCPU(128 * 1024+misalignedOffset);
696 DoTestFileWriteCPU(256 * 1024+misalignedOffset);
697 DoTestFileWriteCPU(512 * 1024+misalignedOffset);
698 DoTestFileWriteCPU(K1M+misalignedOffset);
702 LOCAL_C void TestFileSeek()
704 // Benchmark file seek method
707 ClearSessionDirectory();
708 test.Next(_L("RFile::Seek method"));
709 TInt increment=1789; // random number > cluster size
714 TBuf8<1024> testdata(1024);
716 TInt r=f.Create(TheFs,_L("SEEKTEST"),EFileStream);
721 TInt fileSize=count*testdata.MaxLength();
727 TRequestStatus reqStat;
728 timer.After(reqStat,10000000); // After 10 secs
729 while(reqStat==KRequestPending)
731 TInt dum=(pos+=increment)%fileSize;
732 f.Seek(ESeekStart,dum);
735 test.Printf(_L("RFile::Seek operations in 10 secs == %d\n"),count);
739 TheFs.Delete(_L("SEEKTEST"));
742 #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
744 LOCAL_C void CreateManyLargFiles(TInt aNumber)
746 // Make a directory with aNumber entries
750 TInt maxEntry=aNumber;
752 test.Printf(_L("Create a directory with %d entries\n"),aNumber);
754 TFileName sessionPath;
755 TInt r=TheFs.SessionPath(sessionPath);
757 r=TheFs.MkDir(_L("\\F32-TST\\"));
758 test((r==KErrNone)||(r==KErrAlreadyExists));
759 r=TheFs.MkDir(_L("\\F32-TST\\BENCH_DELETE\\"));
760 test((r==KErrNone)||(r==KErrAlreadyExists));
761 TBuf8<8> WriteData =_L8("Wibbleuy");
762 for (TInt i=0;i<maxEntry;i++)
764 TFileName baseName=_L("\\F32-TST\\BENCH_DELETE\\FILE");
765 baseName.AppendNum(i);
766 r=f.Replace(TheFs,baseName,EFileWrite);
770 r=f.Write((K3GB-30),WriteData);
776 test.Printf(_L("Test all entries have been created successfully\n"));
779 for (TInt j=0;j<=maxEntry;j++)
781 TFileName baseName=_L("\\F32-TST\\BENCH_DELETE\\FILE");
782 baseName.AppendNum(j);
784 TInt r=f.Open(TheFs,baseName,EFileRead);
787 test(r==KErrNotFound && j==maxEntry);
791 r=f.Read((K3GB-30),ReadData);
793 test(f.Size(Size)==KErrNone);
795 test(ReadData==WriteData);
801 LOCAL_C void TestLargeFileDelete()
803 // This test require MMC/SD card size >=4GB-2 in size
806 ClearSessionDirectory();
807 test.Next(_L("Benchmark delete large file"));
815 //check Disk space and decide how many files to create
819 r = TheFs.Volume(volInfo);
822 TInt numberOfFiles = (TUint)(volInfo.iFree/(K4GB -2));
823 test.Printf(_L("Number of large files =%d \n"),numberOfFiles);
827 test.Printf(_L("Large File delete is skipped \n"));
831 for (; i<cycles; i++)
834 CreateManyLargFiles(numberOfFiles);
836 test.Next(_L("Time the delete"));
837 // Now delete them and time it
839 startTime.HomeTime();
841 for (TInt index=0;index<numberOfFiles;index++)
843 TFileName baseName=_L("\\F32-TST\\BENCH_DELETE\\FILE");
844 baseName.AppendNum(index);
846 TInt r=TheFs.Delete(baseName);
852 TTimeIntervalMicroSeconds timeTaken;
853 timeTaken=endTime.MicroSecondsFrom(startTime);
854 TInt64 time=timeTaken.Int64();
857 // We deleted cycles*numberOfFiles files in total microseconds
858 TInt64 fileDeleteTime=total/(numberOfFiles*cycles);
859 test.Next(_L("Benchmarked RFs::Delete()"));
860 test.Printf(_L("Delete time per file = %d microseconds\n"),fileDeleteTime);
862 CFileMan* fMan=CFileMan::NewL(TheFs);
867 for (; i<cycles; i++)
870 CreateManyLargFiles(numberOfFiles);
872 test.Next(_L("Time the delete"));
873 // Now delete them and time it
875 startTime.HomeTime();
877 for (TInt index=0;index<numberOfFiles;index++)
879 TInt r=fMan->Delete(_L("\\F32-TST\\BENCH_DELETE\\FILE*"));
880 test(r==KErrNone || r==KErrNotFound);
885 TTimeIntervalMicroSeconds timeTaken;
886 timeTaken=endTime.MicroSecondsFrom(startTime);
887 TInt64 time=timeTaken.Int64();
890 // We deleted cycles*numberOfFiles files in total microseconds
891 fileDeleteTime=total/(numberOfFiles*cycles);
892 test.Next(_L("Benchmarked CFileMan::Delete()"));
893 test.Printf(_L("Delete time per file = %d microseconds\n"),fileDeleteTime);
898 #endif //SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
901 LOCAL_C void CreateManyFiles(TInt aNumber)
903 // Make a directory with aNumber entries
907 TInt maxEntry=aNumber;
909 test.Printf(_L("Create a directory with %d entries\n"),aNumber);
911 TFileName sessionPath;
912 TInt r=TheFs.SessionPath(sessionPath);
914 r=TheFs.MkDir(_L("\\F32-TST\\"));
915 test((r==KErrNone)||(r==KErrAlreadyExists));
916 r=TheFs.MkDir(_L("\\F32-TST\\BENCH_DELETE\\"));
917 test((r==KErrNone)||(r==KErrAlreadyExists));
919 for (TInt i=0;i<maxEntry;i++)
921 TFileName baseName=_L("\\F32-TST\\BENCH_DELETE\\FILE");
922 baseName.AppendNum(i);
923 r=f.Replace(TheFs,baseName,EFileRead);
925 r=f.Write(_L8("Wibble"));
930 test.Printf(_L("Test all entries have been created successfully\n"));
931 for (TInt j=0;j<=maxEntry;j++)
933 TFileName baseName=_L("\\F32-TST\\BENCH_DELETE\\FILE");
934 baseName.AppendNum(j);
935 TInt r=f.Open(TheFs,baseName,EFileRead);
938 test(r==KErrNotFound && j==maxEntry);
944 test(data==_L8("Wibble"));
950 LOCAL_C void TestFileDelete()
955 ClearSessionDirectory();
956 test.Next(_L("Benchmark delete"));
959 TInt numberOfFiles=100;
963 for (; i<cycles; i++)
966 CreateManyFiles(numberOfFiles);
968 test.Next(_L("Time the delete"));
969 // Now delete them and time it
971 startTime.HomeTime();
973 for (TInt index=0;index<numberOfFiles;index++)
975 TFileName baseName=_L("\\F32-TST\\BENCH_DELETE\\FILE");
976 baseName.AppendNum(index);
978 TInt r=TheFs.Delete(baseName);
984 TTimeIntervalMicroSeconds timeTaken;
985 timeTaken=endTime.MicroSecondsFrom(startTime);
986 TInt64 time=timeTaken.Int64();
989 // We deleted cycles*numberOfFiles files in total microseconds
990 TInt64 fileDeleteTime=total/(numberOfFiles*cycles);
991 test.Next(_L("Benchmarked RFs::Delete()"));
992 test.Printf(_L("Delete time per file = %d microseconds\n"),fileDeleteTime);
994 CFileMan* fMan=CFileMan::NewL(TheFs);
999 for (; i<cycles; i++)
1001 // Create many files
1002 CreateManyFiles(numberOfFiles);
1004 test.Next(_L("Time the delete"));
1005 // Now delete them and time it
1007 startTime.HomeTime();
1009 for (TInt index=0;index<numberOfFiles;index++)
1011 TInt r=fMan->Delete(_L("\\F32-TST\\BENCH_DELETE\\FILE*"));
1012 test(r==KErrNone || r==KErrNotFound);
1017 TTimeIntervalMicroSeconds timeTaken;
1018 timeTaken=endTime.MicroSecondsFrom(startTime);
1019 TInt64 time=timeTaken.Int64();
1022 // We deleted cycles*numberOfFiles files in total microseconds
1023 fileDeleteTime=total/(numberOfFiles*cycles);
1024 test.Next(_L("Benchmarked CFileMan::Delete()"));
1025 test.Printf(_L("Delete time per file = %d microseconds\n"),fileDeleteTime);
1032 TInt maxDirEntry=200;
1033 LOCAL_C void TestDirRead()
1035 // Benchmark directory read method
1039 ClearSessionDirectory();
1040 test.Next(_L("Benchmark directory read method"));
1041 // Create one test entry
1043 f.Create(TheFs,_L("ONE.XXX"),EFileStream);
1048 for (i=0;i<maxDirEntry;i++)
1051 TheFs.GetDir(_L("*"),KEntryAttMaskSupported,ESortByName,dirPtr);
1056 DirReadOne=end.MicroSecondsFrom(start);
1057 // Create lost of test entries
1058 for (i=0;i<maxDirEntry;i++)
1060 TBuf<12> baseName(_L("MANY"));
1061 baseName.AppendNum(i,EHex);
1062 baseName.Append(_L(".TXT"));
1064 f.Create(TheFs,baseName,EFileStream);
1069 TheFs.GetDir(_L("*"),KEntryAttMaskSupported,ESortByName,dirPtr);
1072 DirReadMany=end.MicroSecondsFrom(start);
1073 // Select one entry from lots
1075 TheFs.GetDir(_L("*.XXX"),KEntryAttMaskSupported,ESortByName,dirPtr);
1077 test(dirPtr->Count()==1);
1079 DirMatchOne=end.MicroSecondsFrom(start);
1083 void LOCAL_C PrintDirResults()
1085 // Print results of Directory Benchmark
1088 test.Printf(_L("\nBenchmark: Dir Results\n"));
1089 test.Printf(_L("Read one entry %d times = %d ms\n"),maxDirEntry,DirReadOne.Int64().GetTInt()/1000);
1090 test.Printf(_L("Read %d entries = %d ms\n"),maxDirEntry,DirReadMany.Int64().GetTInt()/1000);
1091 test.Printf(_L("Match 1 entry from %d entries = %d ms\n"),maxDirEntry,DirMatchOne.Int64().GetTInt()/1000);
1092 test.Printf(_L("Press Enter to continue\n\n"));
1098 LOCAL_C void TestMkDir()
1100 test.Next(_L("Benchmark MkDir"));
1101 ClearSessionDirectory();
1105 TTimeIntervalMicroSeconds timeTaken(0);
1106 startTime.HomeTime();
1108 const TInt KNumDirEntries = 100;
1109 for (TInt n=0; n<KNumDirEntries; n++)
1111 TFileName dirName = _L("\\F32-TST\\DIR_");
1112 dirName.AppendNum(n);
1113 dirName.Append(_L("\\"));
1114 TInt r = TheFs.MkDir(dirName);
1115 test(r == KErrNone);
1119 timeTaken=endTime.MicroSecondsFrom(startTime);
1120 TInt timeTakenInMs = I64LOW(timeTaken.Int64() / 1000);
1121 test.Printf(_L("Time taken to create %d entries = %d ms\n"), KNumDirEntries, timeTakenInMs);
1125 // Allocate Data Buffers for Read/Write Tests
1126 void AllocateBuffers()
1128 test.Printf(_L("Allocate Buffers -"));
1130 if (gFragSharedMemory || gSharedMemory)
1132 test.Printf(_L("Shared Memory\n"));
1135 test(l.Connect()==KErrNone);
1136 test(l.CancelLazyDllUnload()==KErrNone);
1139 test.Printf(_L("Initialise\n"));
1140 TInt r = UserHal::PageSizeInBytes(PageSize);
1143 test.Printf(_L("Loading test driver\n"));
1144 r = User::LoadLogicalDevice(KSharedChunkLddName);
1145 test(r==KErrNone || r==KErrAlreadyExists);
1147 test.Printf(_L("Opening channel\n"));
1151 test.Printf(_L("Create chunk\n"));
1153 TUint aCreateFlags = EMultiple|EOwnsMemory;
1154 TCommitType aCommitType = EContiguous;
1156 TUint TotalChunkSize = ChunkSize; // rounded to nearest Page Size
1158 TUint ChunkAttribs = TotalChunkSize|aCreateFlags;
1159 r = Ldd.CreateChunk(ChunkAttribs);
1164 test.Printf(_L("Commit Contigouos Memory\n"));
1165 r = Ldd.CommitMemory(aCommitType,TotalChunkSize);
1170 test.Printf(_L("Commit Fragmented Memory\n"));
1172 // Allocate Pages in reverse order to maximise memory fragmentation
1173 TUint i = ChunkSize;
1177 test.Printf(_L("Commit %d\n"), i);
1178 r = Ldd.CommitMemory(aCommitType|i,PageSize);
1182 for (TInt i = (ChunkSize-PageSize); i>=0; )
1184 test.Printf(_L("Commit %d\n"), i);
1185 r = Ldd.CommitMemory(aCommitType|i,PageSize);
1192 test.Printf(_L("\nOpen user handle\n"));
1193 r = Ldd.GetChunkHandle(TheChunk);
1196 DataBuf.Set(TheChunk.Base(),KMaxFileSize, KMaxFileSize);
1200 test.Printf(_L("Heap Memory\n"));
1201 DataBufH = HBufC8::New(KMaxFileSize);
1202 test(DataBufH != NULL);
1204 DataBuf.Set(DataBufH->Des());
1209 void DeAllocateBuffers()
1211 test.Printf(_L("DeAllocate Buffers -"));
1213 if (gFragSharedMemory || gSharedMemory)
1215 test.Printf(_L("Shared Memory\n"));
1216 test.Printf(_L("Close user chunk handle\n"));
1219 test.Printf(_L("Close kernel chunk handle\n"));
1220 TInt r = Ldd.CloseChunk();
1223 test.Printf(_L("Check chunk is destroyed\n"));
1224 r = Ldd.IsDestroyed();
1227 test.Printf(_L("Close test driver\n"));
1232 test.Printf(_L("Heap Memory\n"));
1233 test.Printf(_L("Delete Heap Buffer\n"));
1238 void ParseCommandLine()
1241 User::CommandLine(cmd);
1244 for (TPtrC token=lex.NextToken(); token.Length() != 0;token.Set(lex.NextToken()))
1246 if (token.MatchF(RProcess().FileName())==0)
1251 if (token.CompareF(_L("-m"))== 0)
1253 gMisalignedReadWrites = ETrue;
1256 if (token.CompareF(_L("-r"))== 0)
1258 gReadCachingOn = EFalse;
1261 if (token.CompareF(_L("+r"))== 0)
1263 gReadCachingOn = ETrue;
1266 if (token.CompareF(_L("-w"))== 0)
1268 gWriteCachingOn = EFalse;
1271 if (token.CompareF(_L("+w"))== 0)
1273 gWriteCachingOn = ETrue;
1277 if (token.CompareF(_L("-f"))== 0)
1279 gFlushAfterWrite = EFalse;
1282 if (token.CompareF(_L("+f"))== 0)
1284 gFlushAfterWrite = ETrue;
1287 if (token.CompareF(_L("+s"))== 0)
1289 gSharedMemory = ETrue;
1292 if (token.CompareF(_L("+x"))== 0)
1294 gFragSharedMemory = ETrue;
1298 test.Printf(_L("CLP=%S\n"),&token);
1300 if(token.Length()!=0)
1302 gDriveToTest=token[0];
1303 gDriveToTest.UpperCase();
1308 #if defined SYMBIAN_TEST_COPY
1309 token.Set(lex.NextToken());
1310 if(token.Length()!=0)
1312 gDriveToTest2=token[0];
1313 gDriveToTest2.UpperCase();
1317 test.Printf(_L("CLP2=%S\n"),&token);
1324 GLDEF_C void CallTestsL(void)
1330 test.Start(_L("Start Benchmarking ..."));
1332 test.Next(gSessionPath);
1337 RProcess().SetPriority(EPriorityBackground);
1339 TInt r = HAL::Get(HAL::EFastCounterFrequency, gFastCounterFreq);
1340 test(r == KErrNone);
1341 test.Printf(_L("HAL::EFastCounterFrequency %d\n"), gFastCounterFreq);
1343 test.Printf(_L("gReadCachingOn %d gWriteCachingOn %d gFlushAfterWrite %d\n"), gReadCachingOn, gWriteCachingOn, gFlushAfterWrite);
1348 TestFileRead(KMaxFileSize, gMisalignedReadWrites, EFalse);
1351 TestFileRead(KMaxFileSize, gMisalignedReadWrites, ETrue);
1353 TestFileReadCPU(gMisalignedReadWrites);
1356 TestFileWrite(KMaxFileSize, gMisalignedReadWrites, EFalse);
1358 // update (overwrite) file
1359 TestFileWrite(KMaxFileSize, gMisalignedReadWrites, ETrue);
1361 TestFileWriteCPU(gMisalignedReadWrites);
1366 // PrintDirResults();
1367 #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
1368 TestLargeFileDelete();
1369 #endif //SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
1373 RecursiveRmDir(gSessionPath);
1375 DeAllocateBuffers();