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_fsrvbm.cpp
21 #include "../server/t_server.h"
23 GLDEF_D RTest test(_L("File Server Benchmarks"));
25 LOCAL_D RSemaphore client;
26 LOCAL_D TInt speedCount;
27 LOCAL_D const TInt KHeapSize=0x2000;
28 LOCAL_D TBuf8<4096> buf;
30 LOCAL_D TDriveList gDriveList;
32 LOCAL_D TInt gLocalDrive;
33 LOCAL_D TInt gLocalDriveReadSize;
34 LOCAL_D TInt gLocalDriveWriteSize;
36 LOCAL_D TFileName gFindEntryDir;
37 LOCAL_D TInt gFindEntrySearchStart;
38 LOCAL_D TInt gFindEntrySearchFinish;
40 LOCAL_D TInt gSeekPos1;
41 LOCAL_D TInt gSeekPos2;
42 LOCAL_D TFileName gSeekFile;
44 LOCAL_D TInt ThreadCount=0;
46 #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
48 const TInt64 KGb = 1 << 30;
49 const TInt64 K2GB = 2 * KGb;
50 const TInt64 K3GB = 3 * KGb;
52 LOCAL_D TInt64 gLSeekPos1;
53 LOCAL_D TInt64 gLSeekPos2;
57 ELocalDriveTest, EFindEntryTest, EFileSeekTest, EFileSeekRFile64Test
62 ELocalDriveTest, EFindEntryTest, EFileSeekTest
64 #endif ////SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
67 // RFs::CheckDisk() will return an error if the directory depth exceeds this value :
68 const TInt KCheckDskMaxRecursionLevel = 50;
70 LOCAL_C void FormatFat(TDriveUnit aDrive)
72 // Call all RFormat methods
78 TInt r=format.Open(TheFs,aDrive.Name(),EHighDensity,count());
81 TRequestStatus status;
84 format.Next(count,status);
85 User::WaitForRequest(status);
86 test(status==KErrNone);
91 LOCAL_C void DoTest(TThreadFunction aFunction)
98 TBuf<8> buf=_L("Speedy");
99 buf.AppendNum(ThreadCount++);
100 TInt r=speedy.Create(buf,aFunction,KDefaultStackSize,KHeapSize,KHeapSize,NULL);
103 speedy.SetPriority(EPriorityLess);
107 r = TheFs.CheckDisk(gSessionPath);
108 test (r == KErrNone);
113 User::After(3000000);
115 test.Printf(_L(" Completed %d calls per second\n"),(n-b)/3);
117 test(TheFs.CheckDisk(gSessionPath) == KErrNone);
120 speedy.Kill(KErrNone);
125 LOCAL_C TInt rawReadData(TAny*)
127 // The entry point for the speed test thread.
132 TBusLocalDrive localDrive;
134 localDrive.Connect(gLocalDrive,changed);
138 localDrive.Read(512+32,gLocalDriveReadSize,buf);
144 LOCAL_C TInt rawWriteData(TAny*)
146 // The entry point for the speed test thread.
151 TBusLocalDrive localDrive;
153 localDrive.Connect(gLocalDrive,changed);
154 buf.SetLength(gLocalDriveWriteSize);
158 localDrive.Write(512+32,buf);
164 LOCAL_C void TestLocalDriveRead(TInt drive,TInt readsize)
166 // Test TBusLocalDrive read
170 test.Printf(_L("TBusLocalDrive %d Reading %d bytes"),drive,readsize);
171 #if defined(__WINS__)
174 else if (drive==EDriveY)
178 gLocalDriveReadSize=readsize;
182 LOCAL_C void TestLocalDriveWrite(TInt drive,TInt writesize)
184 // Test TBusLocalDrive write
188 test.Printf(_L("TBusLocalDrive %d Writing %d bytes"),drive,writesize);
189 #if defined(__WINS__)
192 else if (drive==EDriveY)
196 gLocalDriveWriteSize=writesize;
197 DoTest(rawWriteData);
200 LOCAL_C TInt FindEntryBounce(TAny*)
202 // Find entries in hierarchy
210 r=fs.SetSessionPath(gSessionPath);
216 r=fs.Entry(gFindEntryDir,entry);
218 r=fs.Entry(_L("\\F32-TST"),entry);
226 LOCAL_C void TestFindEntryBounce(TInt aDepth)
228 // Find entries at different depths
232 test.Printf(_L("Find entry 1 then find entry %d"),aDepth);
233 gFindEntryDir=_L("\\F32-TST\\");
235 for(i=0;i<aDepth;i++)
237 gFindEntryDir+=_L("X");
238 gFindEntryDir.AppendNum(i);
239 gFindEntryDir+=_L("\\");
241 gFindEntryDir+=_L("X");
242 gFindEntryDir.AppendNum(i);
243 DoTest(FindEntryBounce);
246 LOCAL_C TInt FindEntrySearch(TAny*)
248 // Find entries in hierarchy
256 r=fs.SetSessionPath(gSessionPath);
261 TFileName temp=gFindEntryDir;
262 for(TInt i=gFindEntrySearchStart;i<gFindEntrySearchFinish;i++)
267 r=fs.Entry(temp,entry);
277 LOCAL_C void TestFindEntrySearch(TInt aStart, TInt aFinish)
279 // Find entries at different depths
283 test.Printf(_L("Find entries %d to %d"),aStart,aFinish);
284 gFindEntrySearchStart=aStart;
285 gFindEntrySearchFinish=aFinish;
286 gFindEntryDir=_L("\\F32-TST\\");
287 for(TInt i=0;i<aStart;i++)
289 gFindEntryDir+=_L("X");
290 gFindEntryDir.AppendNum(i);
291 gFindEntryDir+=_L("\\");
293 DoTest(FindEntrySearch);
296 LOCAL_C TInt FileSeekTest(TAny*)
298 // Read 16bytes at different locations
306 r=fs.SetSessionPath(gSessionPath);
309 r=f.Open(fs,gSeekFile,EFileRead); // 3rd arg was EFileRandomAccess, but this no longer exists
314 r=f.Read(gSeekPos1,buf,16);
316 r=f.Read(gSeekPos2,buf,16);
325 #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
327 LOCAL_C TInt FileSeekRFile64Test(TAny*)
329 // Read 16bytes at different locations
337 r=fs.SetSessionPath(gSessionPath);
340 r=f.Open(fs,gSeekFile,EFileRead); // 3rd arg was EFileRandomAccess, but this no longer exists
345 r=f.Read(gLSeekPos1,buf,16);
347 r=f.Read(gLSeekPos2,buf,16);
353 LOCAL_C void TestSeek64(TInt64 aLoc1, TInt64 aLoc2)
355 // Read 16bytes at different locations
359 test.Printf(_L("Read 16bytes at positions %ld and %ld"),aLoc1,aLoc2);
363 DoTest(FileSeekRFile64Test);
366 #endif //SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
368 LOCAL_C void TestSeek(TInt aLoc1, TInt aLoc2)
370 // Read 16bytes at different locations
374 test.Printf(_L("Read 16bytes at positions %d and %d"),aLoc1,aLoc2);
377 DoTest(FileSeekTest);
380 LOCAL_C void InitializeDrive(CSelectionBox* aSelector)
382 // Get the drive into a good state
386 TDriveUnit drive=((CSelectionBox*)aSelector)->CurrentDrive();
387 gSessionPath[0]=TUint8('A'+drive);
388 TInt r=TheFs.SetSessionPath(gSessionPath);
390 TDriveInfo driveInfo;
391 r=TheFs.Drive(driveInfo);
393 if (driveInfo.iType==EMediaNotPresent)
395 test.Printf(_L("ERROR: MEDIA NOT PRESENT <Press return to continue>\n"));
399 r=TheFs.MkDirAll(gSessionPath);
400 test(r==KErrCorrupt || r==KErrAlreadyExists || r==KErrNone);
402 FormatFat(gSessionPath[0]-'A');
403 if (r!=KErrNone && r!=KErrAlreadyExists)
405 r=TheFs.MkDirAll(gSessionPath);
411 LOCAL_C TInt ValidateDriveSelection(TDriveUnit aDrive,TSelectedTest aTest)
413 if ((aDrive==EDriveZ)||((aDrive==EDriveC)&&(aTest==ELocalDriveTest)))
416 test.Printf(_L("Test not available for this drive\n"));
417 test.Printf(_L("Press any key to continue...\n"));
419 return (KErrNotSupported);
427 LOCAL_C TInt TestLocalDrive(TAny* aSelector)
429 // Test TBusLocalDrive
433 if (((CSelectionBox*)aSelector)->CurrentKeyPress()!=EKeyEnter)
435 TDriveUnit drive=((CSelectionBox*)aSelector)->CurrentDrive();
436 TInt r=ValidateDriveSelection(drive,ELocalDriveTest);
437 if (r==KErrNotSupported)
440 InitializeDrive((CSelectionBox*)aSelector);
443 TBuf<KMaxFileName> name=drive.Name();
444 testTitle.Format(_L("Test TBusLocalDrive %S"),&name);
445 test.Start(testTitle);
446 TestLocalDriveRead(drive,16);
447 TestLocalDriveRead(drive,1024);
448 TestLocalDriveRead(drive,4096);
450 TestLocalDriveWrite(drive,16);
451 TestLocalDriveWrite(drive,1024);
452 TestLocalDriveWrite(drive,4096);
454 test.Printf(_L("Test finished, reformatting drive %d\n"),gSessionPath[0]-'A');
455 FormatFat(gSessionPath[0]-'A');
460 LOCAL_C TInt TestFindEntries(TAny* aSelector)
466 if (((CSelectionBox*)aSelector)->CurrentKeyPress()!=EKeyEnter)
469 TInt r=ValidateDriveSelection(((CSelectionBox*)aSelector)->CurrentDrive(),EFindEntryTest);
470 if (r==KErrNotSupported)
473 InitializeDrive((CSelectionBox*)aSelector);
475 test.Start(_L("Test Entry"));
476 TFileName dirFiftyDeep=_L("\\F32-TST\\"); // root + first directory = 2 directory levels
477 for(TInt i=0;i<KCheckDskMaxRecursionLevel-2;i++) // 0 to 47 = 48 directory levels
479 dirFiftyDeep+=_L("X");
480 dirFiftyDeep.AppendNum(i);
481 dirFiftyDeep+=_L("\\");
483 r=TheFs.MkDirAll(dirFiftyDeep);
484 test(r==KErrNone || r==KErrAlreadyExists);
486 TestFindEntryBounce(2);
487 TestFindEntryBounce(10);
488 TestFindEntryBounce(20);
489 TestFindEntryBounce(KCheckDskMaxRecursionLevel-3);
491 TestFindEntrySearch(1,5);
492 TestFindEntrySearch(1,10);
493 TestFindEntrySearch(10,15);
494 TestFindEntrySearch(10,20);
496 test.Printf(_L("Test finished, removing directory\n"));
497 CFileMan* fMan=CFileMan::NewL(TheFs);
498 r=fMan->RmDir(_L("\\F32-TST\\X0\\"));
505 LOCAL_C TInt TestFileSeek(TAny* aSelector)
511 if (((CSelectionBox*)aSelector)->CurrentKeyPress()!=EKeyEnter)
514 TInt r=ValidateDriveSelection(((CSelectionBox*)aSelector)->CurrentDrive(),EFileSeekTest);
515 if (r==KErrNotSupported)
518 InitializeDrive((CSelectionBox*)aSelector);
520 test.Start(_L("Test Seek"));
522 gSeekFile=_L("\\F32-TST\\FILE512K.BIG");
523 r=f.Replace(TheFs,gSeekFile,EFileWrite);
532 TestSeek(5000,15000);
533 TestSeek(10000,100000);
534 TestSeek(200000,500000);
536 r=TheFs.Delete(gSeekFile);
542 #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
543 //Read the file at position beyond 2GB-1
544 //Minimum required disk space for this test is 3GB
546 LOCAL_C TInt TestLargeFileSeek(TAny* aSelector)
549 if (((CSelectionBox*)aSelector)->CurrentKeyPress()!=EKeyEnter)
552 TInt r=ValidateDriveSelection(((CSelectionBox*)aSelector)->CurrentDrive(),EFileSeekRFile64Test);
553 if (r==KErrNotSupported)
556 InitializeDrive((CSelectionBox*)aSelector);
558 test.Start(_L("Test large File Seek"));
561 gSeekFile=_L("\\F32-TST\\FILE4GBMINUS2.BIG");
562 r=BigFile.Replace(TheFs,gSeekFile,EFileWrite);
568 r = TheFs.Volume(volInfo);
571 //Get the free space available for test
572 if(volInfo.iFree < (K3GB-2))
576 r=TheFs.Delete(gSeekFile);
577 test.Printf(_L("Large File test is skipped: Free space %ld \n"),volInfo.iFree);
581 r=BigFile.SetSize(K3GB-2);
586 TestSeek64(5000,6000);
587 TestSeek64(200000,500000);
588 TestSeek64(K2GB,K2GB+1000);
589 TestSeek64(K3GB-1000,K3GB-2000);
590 TestSeek64(K3GB-50, K3GB-20);
591 r=TheFs.Delete(gSeekFile);
598 #endif //SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
600 GLDEF_C void CallTestsL()
606 TInt r=client.CreateLocal(0);
608 gSessionPath=_L("?:\\F32-TST\\");
609 CSelectionBox* TheSelector=CSelectionBox::NewL(test.Console());
610 TCallBack localDrivesCb(TestLocalDrive,TheSelector);
611 TCallBack findEntriesCb(TestFindEntries,TheSelector);
612 TCallBack fileSeekCb(TestFileSeek,TheSelector);
614 #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
615 TCallBack largefileSeekCb(TestLargeFileSeek,TheSelector);
616 #endif //SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
618 TheSelector->AddDriveSelectorL(TheFs);
619 TheSelector->AddLineL(_L("Test LocalDrive"),localDrivesCb);
620 TheSelector->AddLineL(_L("Test Find Entries"),findEntriesCb);
621 TheSelector->AddLineL(_L("Test File Seek"),fileSeekCb);
623 #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
624 TheSelector->AddLineL(_L("Test large File Seek"),largefileSeekCb);
625 #endif //SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API