sl@0: // Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // f32test\bench\t_fsrvbm.cpp sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include "t_select.h" sl@0: #include "../server/t_server.h" sl@0: sl@0: GLDEF_D RTest test(_L("File Server Benchmarks")); sl@0: sl@0: LOCAL_D RSemaphore client; sl@0: LOCAL_D TInt speedCount; sl@0: LOCAL_D const TInt KHeapSize=0x2000; sl@0: LOCAL_D TBuf8<4096> buf; sl@0: // sl@0: LOCAL_D TDriveList gDriveList; sl@0: // sl@0: LOCAL_D TInt gLocalDrive; sl@0: LOCAL_D TInt gLocalDriveReadSize; sl@0: LOCAL_D TInt gLocalDriveWriteSize; sl@0: // sl@0: LOCAL_D TFileName gFindEntryDir; sl@0: LOCAL_D TInt gFindEntrySearchStart; sl@0: LOCAL_D TInt gFindEntrySearchFinish; sl@0: // sl@0: LOCAL_D TInt gSeekPos1; sl@0: LOCAL_D TInt gSeekPos2; sl@0: LOCAL_D TFileName gSeekFile; sl@0: sl@0: LOCAL_D TInt ThreadCount=0; sl@0: sl@0: #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API sl@0: sl@0: const TInt64 KGb = 1 << 30; sl@0: const TInt64 K2GB = 2 * KGb; sl@0: const TInt64 K3GB = 3 * KGb; sl@0: sl@0: LOCAL_D TInt64 gLSeekPos1; sl@0: LOCAL_D TInt64 gLSeekPos2; sl@0: sl@0: enum TSelectedTest sl@0: { sl@0: ELocalDriveTest, EFindEntryTest, EFileSeekTest, EFileSeekRFile64Test sl@0: }; sl@0: #else sl@0: enum TSelectedTest sl@0: { sl@0: ELocalDriveTest, EFindEntryTest, EFileSeekTest sl@0: }; sl@0: #endif ////SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API sl@0: sl@0: sl@0: // RFs::CheckDisk() will return an error if the directory depth exceeds this value : sl@0: const TInt KCheckDskMaxRecursionLevel = 50; sl@0: sl@0: LOCAL_C void FormatFat(TDriveUnit aDrive) sl@0: // sl@0: // Call all RFormat methods sl@0: // sl@0: { sl@0: sl@0: RFormat format; sl@0: TPckgBuf count; sl@0: TInt r=format.Open(TheFs,aDrive.Name(),EHighDensity,count()); sl@0: test(r==KErrNone); sl@0: test(count()==100); sl@0: TRequestStatus status; sl@0: while (count()) sl@0: { sl@0: format.Next(count,status); sl@0: User::WaitForRequest(status); sl@0: test(status==KErrNone); sl@0: } sl@0: format.Close(); sl@0: } sl@0: sl@0: LOCAL_C void DoTest(TThreadFunction aFunction) sl@0: // sl@0: // Do a speed test sl@0: // sl@0: { sl@0: sl@0: RThread speedy; sl@0: TBuf<8> buf=_L("Speedy"); sl@0: buf.AppendNum(ThreadCount++); sl@0: TInt r=speedy.Create(buf,aFunction,KDefaultStackSize,KHeapSize,KHeapSize,NULL); sl@0: test(r==KErrNone); sl@0: // sl@0: speedy.SetPriority(EPriorityLess); sl@0: speedy.Resume(); sl@0: client.Wait(); sl@0: sl@0: r = TheFs.CheckDisk(gSessionPath); sl@0: test (r == KErrNone); sl@0: sl@0: // sl@0: User::After(300000); sl@0: TInt b=speedCount; sl@0: User::After(3000000); sl@0: TInt n=speedCount; sl@0: test.Printf(_L(" Completed %d calls per second\n"),(n-b)/3); sl@0: sl@0: test(TheFs.CheckDisk(gSessionPath) == KErrNone); sl@0: sl@0: // sl@0: speedy.Kill(KErrNone); sl@0: test(r==KErrNone); sl@0: speedy.Close(); sl@0: } sl@0: sl@0: LOCAL_C TInt rawReadData(TAny*) sl@0: // sl@0: // The entry point for the speed test thread. sl@0: // sl@0: { sl@0: sl@0: speedCount=0; sl@0: TBusLocalDrive localDrive; sl@0: TBool changed; sl@0: localDrive.Connect(gLocalDrive,changed); sl@0: client.Signal(); sl@0: FOREVER sl@0: { sl@0: localDrive.Read(512+32,gLocalDriveReadSize,buf); sl@0: speedCount++; sl@0: } sl@0: // return(KErrNone); sl@0: } sl@0: sl@0: LOCAL_C TInt rawWriteData(TAny*) sl@0: // sl@0: // The entry point for the speed test thread. sl@0: // sl@0: { sl@0: sl@0: speedCount=0; sl@0: TBusLocalDrive localDrive; sl@0: TBool changed; sl@0: localDrive.Connect(gLocalDrive,changed); sl@0: buf.SetLength(gLocalDriveWriteSize); sl@0: client.Signal(); sl@0: FOREVER sl@0: { sl@0: localDrive.Write(512+32,buf); sl@0: speedCount++; sl@0: } sl@0: // return(KErrNone); sl@0: } sl@0: sl@0: LOCAL_C void TestLocalDriveRead(TInt drive,TInt readsize) sl@0: // sl@0: // Test TBusLocalDrive read sl@0: // sl@0: { sl@0: sl@0: test.Printf(_L("TBusLocalDrive %d Reading %d bytes"),drive,readsize); sl@0: #if defined(__WINS__) sl@0: if (drive==EDriveX) sl@0: drive=1; sl@0: else if (drive==EDriveY) sl@0: drive=0; sl@0: #endif sl@0: gLocalDrive=drive; sl@0: gLocalDriveReadSize=readsize; sl@0: DoTest(rawReadData); sl@0: } sl@0: sl@0: LOCAL_C void TestLocalDriveWrite(TInt drive,TInt writesize) sl@0: // sl@0: // Test TBusLocalDrive write sl@0: // sl@0: { sl@0: sl@0: test.Printf(_L("TBusLocalDrive %d Writing %d bytes"),drive,writesize); sl@0: #if defined(__WINS__) sl@0: if (drive==EDriveX) sl@0: drive=1; sl@0: else if (drive==EDriveY) sl@0: drive=0; sl@0: #endif sl@0: gLocalDrive=drive; sl@0: gLocalDriveWriteSize=writesize; sl@0: DoTest(rawWriteData); sl@0: } sl@0: sl@0: LOCAL_C TInt FindEntryBounce(TAny*) sl@0: // sl@0: // Find entries in hierarchy sl@0: // sl@0: { sl@0: sl@0: speedCount=0; sl@0: RFs fs; sl@0: TInt r=fs.Connect(); sl@0: test(r==KErrNone); sl@0: r=fs.SetSessionPath(gSessionPath); sl@0: test(r==KErrNone); sl@0: client.Signal(); sl@0: FOREVER sl@0: { sl@0: TEntry entry; sl@0: r=fs.Entry(gFindEntryDir,entry); sl@0: test(r==KErrNone); sl@0: r=fs.Entry(_L("\\F32-TST"),entry); sl@0: test(r==KErrNone); sl@0: speedCount++; sl@0: } sl@0: // fs.Close(); sl@0: // return(KErrNone); sl@0: } sl@0: sl@0: LOCAL_C void TestFindEntryBounce(TInt aDepth) sl@0: // sl@0: // Find entries at different depths sl@0: // sl@0: { sl@0: sl@0: test.Printf(_L("Find entry 1 then find entry %d"),aDepth); sl@0: gFindEntryDir=_L("\\F32-TST\\"); sl@0: TInt i; sl@0: for(i=0;iCurrentDrive(); sl@0: gSessionPath[0]=TUint8('A'+drive); sl@0: TInt r=TheFs.SetSessionPath(gSessionPath); sl@0: test(r==KErrNone); sl@0: TDriveInfo driveInfo; sl@0: r=TheFs.Drive(driveInfo); sl@0: test(r==KErrNone); sl@0: if (driveInfo.iType==EMediaNotPresent) sl@0: { sl@0: test.Printf(_L("ERROR: MEDIA NOT PRESENT \n")); sl@0: test.Getch(); sl@0: return; sl@0: } sl@0: r=TheFs.MkDirAll(gSessionPath); sl@0: test(r==KErrCorrupt || r==KErrAlreadyExists || r==KErrNone); sl@0: if (r==KErrCorrupt) sl@0: FormatFat(gSessionPath[0]-'A'); sl@0: if (r!=KErrNone && r!=KErrAlreadyExists) sl@0: { sl@0: r=TheFs.MkDirAll(gSessionPath); sl@0: test(r==KErrNone); sl@0: } sl@0: } sl@0: sl@0: sl@0: LOCAL_C TInt ValidateDriveSelection(TDriveUnit aDrive,TSelectedTest aTest) sl@0: { sl@0: if ((aDrive==EDriveZ)||((aDrive==EDriveC)&&(aTest==ELocalDriveTest))) sl@0: { sl@0: sl@0: test.Printf(_L("Test not available for this drive\n")); sl@0: test.Printf(_L("Press any key to continue...\n")); sl@0: test.Getch(); sl@0: return (KErrNotSupported); sl@0: } sl@0: else sl@0: return (KErrNone); sl@0: } sl@0: sl@0: sl@0: sl@0: LOCAL_C TInt TestLocalDrive(TAny* aSelector) sl@0: // sl@0: // Test TBusLocalDrive sl@0: // sl@0: { sl@0: sl@0: if (((CSelectionBox*)aSelector)->CurrentKeyPress()!=EKeyEnter) sl@0: return(KErrNone); sl@0: TDriveUnit drive=((CSelectionBox*)aSelector)->CurrentDrive(); sl@0: TInt r=ValidateDriveSelection(drive,ELocalDriveTest); sl@0: if (r==KErrNotSupported) sl@0: return (r); sl@0: sl@0: InitializeDrive((CSelectionBox*)aSelector); sl@0: // sl@0: TBuf<128> testTitle; sl@0: TBuf name=drive.Name(); sl@0: testTitle.Format(_L("Test TBusLocalDrive %S"),&name); sl@0: test.Start(testTitle); sl@0: TestLocalDriveRead(drive,16); sl@0: TestLocalDriveRead(drive,1024); sl@0: TestLocalDriveRead(drive,4096); sl@0: // sl@0: TestLocalDriveWrite(drive,16); sl@0: TestLocalDriveWrite(drive,1024); sl@0: TestLocalDriveWrite(drive,4096); sl@0: // sl@0: test.Printf(_L("Test finished, reformatting drive %d\n"),gSessionPath[0]-'A'); sl@0: FormatFat(gSessionPath[0]-'A'); sl@0: test.End(); sl@0: return(KErrNone); sl@0: } sl@0: sl@0: LOCAL_C TInt TestFindEntries(TAny* aSelector) sl@0: // sl@0: // Test Entry sl@0: // sl@0: { sl@0: sl@0: if (((CSelectionBox*)aSelector)->CurrentKeyPress()!=EKeyEnter) sl@0: return(KErrNone); sl@0: sl@0: TInt r=ValidateDriveSelection(((CSelectionBox*)aSelector)->CurrentDrive(),EFindEntryTest); sl@0: if (r==KErrNotSupported) sl@0: return(r); sl@0: sl@0: InitializeDrive((CSelectionBox*)aSelector); sl@0: // sl@0: test.Start(_L("Test Entry")); sl@0: TFileName dirFiftyDeep=_L("\\F32-TST\\"); // root + first directory = 2 directory levels sl@0: for(TInt i=0;iRmDir(_L("\\F32-TST\\X0\\")); sl@0: test(r==KErrNone); sl@0: delete fMan; sl@0: test.End(); sl@0: return(KErrNone); sl@0: } sl@0: sl@0: LOCAL_C TInt TestFileSeek(TAny* aSelector) sl@0: // sl@0: // Test Seek sl@0: // sl@0: { sl@0: sl@0: if (((CSelectionBox*)aSelector)->CurrentKeyPress()!=EKeyEnter) sl@0: return(KErrNone); sl@0: sl@0: TInt r=ValidateDriveSelection(((CSelectionBox*)aSelector)->CurrentDrive(),EFileSeekTest); sl@0: if (r==KErrNotSupported) sl@0: return (r); sl@0: sl@0: InitializeDrive((CSelectionBox*)aSelector); sl@0: // sl@0: test.Start(_L("Test Seek")); sl@0: RFile f; sl@0: gSeekFile=_L("\\F32-TST\\FILE512K.BIG"); sl@0: r=f.Replace(TheFs,gSeekFile,EFileWrite); sl@0: test(r==KErrNone); sl@0: r=f.SetSize(524268); sl@0: test(r==KErrNone); sl@0: f.Close(); sl@0: // sl@0: TestSeek(0,1000); sl@0: TestSeek(0,10000); sl@0: TestSeek(5000,6000); sl@0: TestSeek(5000,15000); sl@0: TestSeek(10000,100000); sl@0: TestSeek(200000,500000); sl@0: // sl@0: r=TheFs.Delete(gSeekFile); sl@0: test(r==KErrNone); sl@0: test.End(); sl@0: return(KErrNone); sl@0: } sl@0: sl@0: #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API sl@0: //Read the file at position beyond 2GB-1 sl@0: //Minimum required disk space for this test is 3GB sl@0: // sl@0: LOCAL_C TInt TestLargeFileSeek(TAny* aSelector) sl@0: { sl@0: sl@0: if (((CSelectionBox*)aSelector)->CurrentKeyPress()!=EKeyEnter) sl@0: return(KErrNone); sl@0: sl@0: TInt r=ValidateDriveSelection(((CSelectionBox*)aSelector)->CurrentDrive(),EFileSeekRFile64Test); sl@0: if (r==KErrNotSupported) sl@0: return (r); sl@0: sl@0: InitializeDrive((CSelectionBox*)aSelector); sl@0: // sl@0: test.Start(_L("Test large File Seek")); sl@0: sl@0: RFile64 BigFile; sl@0: gSeekFile=_L("\\F32-TST\\FILE4GBMINUS2.BIG"); sl@0: r=BigFile.Replace(TheFs,gSeekFile,EFileWrite); sl@0: test(r==KErrNone); sl@0: sl@0: //check Disk space sl@0: TVolumeInfo volInfo; sl@0: sl@0: r = TheFs.Volume(volInfo); sl@0: test(r==KErrNone); sl@0: sl@0: //Get the free space available for test sl@0: if(volInfo.iFree < (K3GB-2)) sl@0: { sl@0: BigFile.Close(); sl@0: test(r==KErrNone); sl@0: r=TheFs.Delete(gSeekFile); sl@0: test.Printf(_L("Large File test is skipped: Free space %ld \n"),volInfo.iFree); sl@0: return r; sl@0: } sl@0: sl@0: r=BigFile.SetSize(K3GB-2); sl@0: test(r==KErrNone); sl@0: BigFile.Close(); sl@0: sl@0: TestSeek64(0,1000); sl@0: TestSeek64(5000,6000); sl@0: TestSeek64(200000,500000); sl@0: TestSeek64(K2GB,K2GB+1000); sl@0: TestSeek64(K3GB-1000,K3GB-2000); sl@0: TestSeek64(K3GB-50, K3GB-20); sl@0: r=TheFs.Delete(gSeekFile); sl@0: test(r==KErrNone); sl@0: sl@0: test.End(); sl@0: return(KErrNone); sl@0: sl@0: } sl@0: #endif //SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API sl@0: sl@0: GLDEF_C void CallTestsL() sl@0: // sl@0: // Call all tests sl@0: // sl@0: { sl@0: sl@0: TInt r=client.CreateLocal(0); sl@0: test(r==KErrNone); sl@0: gSessionPath=_L("?:\\F32-TST\\"); sl@0: CSelectionBox* TheSelector=CSelectionBox::NewL(test.Console()); sl@0: TCallBack localDrivesCb(TestLocalDrive,TheSelector); sl@0: TCallBack findEntriesCb(TestFindEntries,TheSelector); sl@0: TCallBack fileSeekCb(TestFileSeek,TheSelector); sl@0: sl@0: #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API sl@0: TCallBack largefileSeekCb(TestLargeFileSeek,TheSelector); sl@0: #endif //SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API sl@0: sl@0: TheSelector->AddDriveSelectorL(TheFs); sl@0: TheSelector->AddLineL(_L("Test LocalDrive"),localDrivesCb); sl@0: TheSelector->AddLineL(_L("Test Find Entries"),findEntriesCb); sl@0: TheSelector->AddLineL(_L("Test File Seek"),fileSeekCb); sl@0: sl@0: #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API sl@0: TheSelector->AddLineL(_L("Test large File Seek"),largefileSeekCb); sl@0: #endif //SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API sl@0: TheSelector->Run(); sl@0: client.Close(); sl@0: delete TheSelector; sl@0: }