sl@0: // Copyright (c) 2006-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_fsrmkdir.cpp sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include "t_select.h" sl@0: #include "t_benchmain.h" sl@0: sl@0: sl@0: GLDEF_D RTest test(_L("FS Benchmarks, mkdir")); sl@0: sl@0: //---------------------------------------------------------------------------------------------- sl@0: //! @SYMTestCaseID PBASE-T_FSRMKDIR-0277 sl@0: //! @SYMTestType CIT sl@0: //! @SYMPREQ PREQ000 sl@0: //! @SYMTestCaseDesc This test case is measuring performance of the FAT implementation sl@0: //! @SYMTestActions 0. Expects the files to exist in order to successful execution sl@0: //! 1. Time the creation of a directory in each directory with RFs::MkDir sl@0: //! 2. Time the creation of a directory (with RFs::MkDir) in each directory sl@0: //! with different clients accessing the directory sl@0: //! 3. Time the creation of a directory (with RFs::MkDir) in each directory sl@0: //! with different clients accessing different directories sl@0: //! sl@0: //! @SYMTestExpectedResults Finishes if the system behaves as expected, panics otherwise sl@0: //! @SYMTestPriority High sl@0: //! @SYMTestStatus Implemented sl@0: //---------------------------------------------------------------------------------------------- sl@0: sl@0: LOCAL_D RSemaphore client,write_screen; sl@0: LOCAL_D const TInt KHeapSize = 0x4000; sl@0: LOCAL_D TBuf8<4096> buf; sl@0: sl@0: LOCAL_D TDriveList gDriveList; sl@0: sl@0: LOCAL_D TFileName gDelEntryDir; sl@0: LOCAL_D TFileName gDelEntryDir2; sl@0: sl@0: // Concurrent thread sl@0: RThread gSpeedy; sl@0: RThread gSpeedyII; sl@0: TInt gT1; sl@0: TInt gT2; sl@0: TBool gKillMe=EFalse; sl@0: sl@0: LOCAL_D TInt ThreadCount=0; sl@0: sl@0: _LIT(KDirMultipleName2, "dir%d_%d\\"); sl@0: _LIT(KNewDir, "new_dir\\"); sl@0: sl@0: _LIT(KDeleteMe,"delete%d.me"); sl@0: _LIT(KDeleteMe2,"blabla%d.rhd"); sl@0: sl@0: /** Delete entry in directory sl@0: sl@0: */ sl@0: LOCAL_C TInt DeleteEntryAccess2(TAny* ) sl@0: { sl@0: RFs fs; sl@0: TInt r = fs.Connect(); sl@0: TBuf<100> dirfile; sl@0: TBuf<50> filename; sl@0: RFile file; sl@0: RTest test(_L("test 2")); sl@0: sl@0: fs.SetSessionPath(gSessionPath); sl@0: filename.Format(KDeleteMe2, gT2); sl@0: sl@0: dirfile = gDelEntryDir2; sl@0: dirfile.Append(filename); sl@0: sl@0: client.Signal(); sl@0: sl@0: FOREVER sl@0: { sl@0: if(!gKillMe) sl@0: { sl@0: r = file.Create(fs, dirfile, EFileShareAny|EFileWrite); sl@0: if(r == KErrAlreadyExists) sl@0: r=file.Open(fs, dirfile, EFileShareAny|EFileWrite); sl@0: file.Close(); sl@0: FailIfError(r); sl@0: sl@0: r = fs.Delete(dirfile); sl@0: if((r != KErrNone) && (r != KErrInUse)) sl@0: { sl@0: test.Printf(_L("error = %d\n"), r); sl@0: } sl@0: test(r == KErrNone || r == KErrInUse); sl@0: } sl@0: } sl@0: } sl@0: sl@0: /** Delete entry in directory sl@0: sl@0: */ sl@0: LOCAL_C TInt DeleteEntryAccess(TAny*) sl@0: { sl@0: RFs fs2; sl@0: TInt r = fs2.Connect(); sl@0: TBuf<100> dirfile; sl@0: TBuf<50> filename; sl@0: RFile file2; sl@0: RTest test(_L("test 2")); sl@0: sl@0: r = fs2.SetSessionPath(gSessionPath); sl@0: filename.Format(KDeleteMe, gT1); sl@0: sl@0: dirfile = gDelEntryDir; sl@0: dirfile.Append(filename); sl@0: sl@0: client.Signal(); sl@0: sl@0: FOREVER sl@0: { sl@0: if(!gKillMe) sl@0: { sl@0: r = file2.Create(fs2, dirfile, EFileShareAny|EFileWrite); sl@0: if(r == KErrAlreadyExists) sl@0: r = file2.Open(fs2, dirfile, EFileShareAny|EFileWrite); sl@0: file2.Close(); sl@0: FailIfError(r); sl@0: r = fs2.Delete(dirfile); sl@0: sl@0: if((r != KErrNone) && (r != KErrInUse)) sl@0: { sl@0: test.Printf(_L("error = %d\n"), r); sl@0: } sl@0: sl@0: test(r == KErrNone || r == KErrInUse); sl@0: } sl@0: } sl@0: } sl@0: sl@0: sl@0: /** Starts two concurrent client sessions in different directories sl@0: sl@0: */ sl@0: LOCAL_C void DoTest2(TThreadFunction aFunction) sl@0: { sl@0: gKillMe = EFalse; sl@0: sl@0: TBuf<20> buf = _L("Speedy"); sl@0: buf.AppendNum(ThreadCount++); sl@0: gT1 = ThreadCount; sl@0: TInt r = gSpeedy.Create(buf, aFunction, KDefaultStackSize, KHeapSize, KHeapSize, NULL); sl@0: FailIfError(r); sl@0: sl@0: buf = _L("Speedy"); sl@0: buf.AppendNum(ThreadCount++); sl@0: gT2 = ThreadCount; sl@0: r = gSpeedyII.Create(buf, DeleteEntryAccess2, KDefaultStackSize, KHeapSize, KHeapSize, NULL); sl@0: FailIfError(r); sl@0: sl@0: gSpeedy.SetPriority(EPriorityLess); sl@0: gSpeedyII.SetPriority(EPriorityLess); sl@0: sl@0: gSpeedy.Resume(); sl@0: gSpeedyII.Resume(); sl@0: sl@0: client.Wait(); sl@0: client.Wait(); sl@0: } sl@0: sl@0: sl@0: /** Kills the concurrent session sl@0: sl@0: */ sl@0: LOCAL_C void DoTestKill() sl@0: { sl@0: gKillMe = ETrue; sl@0: User::After(10000000); sl@0: sl@0: gSpeedy.Kill(KErrNone); sl@0: gSpeedy.Close(); sl@0: sl@0: gSpeedyII.Kill(KErrNone); sl@0: gSpeedyII.Close(); sl@0: } sl@0: sl@0: /** Time the creation of a directory inside each type of directory sl@0: sl@0: @param aN Number of files in the directory sl@0: @param aStep Test step sl@0: */ sl@0: LOCAL_C void MakeDir(TInt aN, TInt aStep) sl@0: { sl@0: TBuf16<100> dir1; sl@0: TBuf16<100> dir2; sl@0: TBuf16<100> dir3; sl@0: TBuf16<100> dir4; sl@0: sl@0: TInt r=0; sl@0: TTime startTime; sl@0: TTime endTime; sl@0: TTimeIntervalMicroSeconds timeTaken(0); sl@0: TInt timeTaken1 = -1, timeTaken2 = -1, timeTaken3 = -1; sl@0: sl@0: if(aN <= gFilesLimit) sl@0: { sl@0: dir1 = gSessionPath; sl@0: dir2 = gSessionPath; sl@0: dir3 = gSessionPath; sl@0: sl@0: dir4.Format(KDirMultipleName2, 1, aN); sl@0: dir1.Append(dir4); sl@0: dir4.Format(KDirMultipleName2, 2, aN); sl@0: dir2.Append(dir4); sl@0: dir4.Format(KDirMultipleName2, 3, aN); sl@0: dir3.Append(dir4); sl@0: sl@0: dir1.Append(KNewDir); sl@0: dir2.Append(KNewDir); sl@0: dir3.Append(KNewDir); sl@0: sl@0: if(gTypes >= 1) sl@0: { sl@0: dir4.Format(KDirMultipleName, 1, aN); sl@0: startTime.HomeTime(); sl@0: sl@0: r = TheFs.MkDir(dir1); sl@0: FailIfError(r); sl@0: sl@0: endTime.HomeTime(); sl@0: sl@0: timeTaken = endTime.MicroSecondsFrom(startTime); sl@0: timeTaken1 = I64LOW(timeTaken.Int64() / gTimeUnit); sl@0: TheFs.RmDir(dir1); sl@0: } sl@0: sl@0: if(gTypes >= 2) sl@0: { sl@0: startTime.HomeTime(); sl@0: sl@0: r = TheFs.MkDir(dir2); sl@0: FailIfError(r); sl@0: sl@0: endTime.HomeTime(); sl@0: sl@0: timeTaken = endTime.MicroSecondsFrom(startTime); sl@0: timeTaken2 = I64LOW(timeTaken.Int64() / gTimeUnit); sl@0: TheFs.RmDir(dir2); sl@0: } sl@0: sl@0: if(gTypes>=3) sl@0: { sl@0: startTime.HomeTime(); sl@0: sl@0: r = TheFs.MkDir(dir3); sl@0: FailIfError(r); sl@0: sl@0: endTime.HomeTime(); sl@0: timeTaken = endTime.MicroSecondsFrom(startTime); sl@0: timeTaken3 = I64LOW(timeTaken.Int64() / gTimeUnit); sl@0: sl@0: TheFs.RmDir(dir3); sl@0: } sl@0: } sl@0: sl@0: PrintResult(aStep, 1, aN); sl@0: PrintResultTime(aStep, 2, timeTaken1); sl@0: PrintResultTime(aStep, 3, timeTaken2); sl@0: PrintResultTime(aStep, 4, timeTaken3); sl@0: } sl@0: sl@0: /** Time the creation of a directory inside each type of directory with multiple threads ongoing sl@0: sl@0: @param aN Number of files in the directory sl@0: @param aStep Test step sl@0: */ sl@0: LOCAL_C void MakeDirM(TInt aN, TInt aStep) sl@0: { sl@0: TBuf16<100> dir1; sl@0: TBuf16<100> dir2; sl@0: TBuf16<100> dir3; sl@0: TBuf16<100> dir4; sl@0: sl@0: TInt r = 0; sl@0: TTime startTime; sl@0: TTime endTime; sl@0: TTimeIntervalMicroSeconds timeTaken(0); sl@0: TInt timeTaken1 = -1, timeTaken2 = -1, timeTaken3 = -1; sl@0: sl@0: if(aN <= gFilesLimit) sl@0: { sl@0: dir1 = gSessionPath; sl@0: dir2 = gSessionPath; sl@0: dir3 = gSessionPath; sl@0: sl@0: dir4.Format(KDirMultipleName2, 1, aN); sl@0: dir1.Append(dir4); sl@0: dir4.Format(KDirMultipleName2, 2, aN); sl@0: dir2.Append(dir4); sl@0: dir4.Format(KDirMultipleName2, 3, aN); sl@0: dir3.Append(dir4); sl@0: sl@0: if(gTypes >= 1) sl@0: { sl@0: gDelEntryDir = dir1; sl@0: gDelEntryDir2 = dir1; sl@0: sl@0: dir1.Append(KNewDir); sl@0: DoTest2(DeleteEntryAccess); sl@0: sl@0: startTime.HomeTime(); sl@0: sl@0: r = TheFs.MkDir(dir1); sl@0: FailIfError(r); sl@0: sl@0: endTime.HomeTime(); sl@0: sl@0: DoTestKill(); sl@0: sl@0: timeTaken = endTime.MicroSecondsFrom(startTime); sl@0: timeTaken1 = I64LOW(timeTaken.Int64() / gTimeUnit); sl@0: sl@0: TheFs.RmDir(dir1); sl@0: } sl@0: sl@0: if(gTypes >= 2) sl@0: { sl@0: gDelEntryDir = dir2; sl@0: gDelEntryDir2 = dir2; sl@0: dir2.Append(KNewDir); sl@0: sl@0: DoTest2(DeleteEntryAccess); sl@0: sl@0: startTime.HomeTime(); sl@0: sl@0: r = TheFs.MkDir(dir2); sl@0: FailIfError(r); sl@0: sl@0: endTime.HomeTime(); sl@0: DoTestKill(); sl@0: sl@0: timeTaken = endTime.MicroSecondsFrom(startTime); sl@0: timeTaken2 = I64LOW(timeTaken.Int64() / gTimeUnit); sl@0: sl@0: TheFs.RmDir(dir2); sl@0: } sl@0: sl@0: if(gTypes >= 3) sl@0: { sl@0: gDelEntryDir = dir3; sl@0: gDelEntryDir2 = dir3; sl@0: dir3.Append(KNewDir); sl@0: DoTest2(DeleteEntryAccess); sl@0: sl@0: startTime.HomeTime(); sl@0: sl@0: r = TheFs.MkDir(dir3); sl@0: FailIfError(r); sl@0: sl@0: endTime.HomeTime(); sl@0: DoTestKill(); sl@0: sl@0: timeTaken = endTime.MicroSecondsFrom(startTime); sl@0: timeTaken3 = I64LOW(timeTaken.Int64() / gTimeUnit); sl@0: sl@0: TheFs.RmDir(dir3); sl@0: } sl@0: } sl@0: sl@0: PrintResult(aStep, 1, aN); sl@0: PrintResultTime(aStep, 2, timeTaken1); sl@0: PrintResultTime(aStep, 3, timeTaken2); sl@0: PrintResultTime(aStep, 4, timeTaken3); sl@0: sl@0: } sl@0: sl@0: /** Times the creation of a directory sl@0: Precondition: This test expectsthe drive already filled with the right files sl@0: sl@0: @param aSelector Configuration in case of manual execution sl@0: */ sl@0: LOCAL_C TInt TestMake(TAny* aSelector) sl@0: { sl@0: TInt i = 100; sl@0: TInt testStep; sl@0: sl@0: Validate(aSelector); sl@0: sl@0: test.Printf(_L("#~TS_Title_%d,%d: MkDir, RFs::MkDir\n"), gTestHarness, gTestCase); sl@0: sl@0: i = 100; sl@0: testStep = 1; sl@0: while(i <= KMaxFiles) sl@0: { sl@0: if(i == 100 || i == 1000 || i == 5000 || i == 10000) sl@0: { sl@0: MakeDir(i, testStep++); sl@0: } sl@0: i += 100; sl@0: } sl@0: sl@0: gTestCase++; sl@0: return(KErrNone); sl@0: } sl@0: sl@0: /** Tests the creation of a directory with 2 threads accessing the directory sl@0: sl@0: @param aSelector Configuration in case of manual execution sl@0: */ sl@0: LOCAL_C TInt TestMakeMultSame(TAny* aSelector) sl@0: { sl@0: TInt i; sl@0: TInt testStep; sl@0: sl@0: Validate(aSelector); sl@0: sl@0: test.Printf(_L("#~TS_Title_%d,%d: MkDir with mult clients accessing same dir, RFs::MkDir\n"), gTestHarness, gTestCase); sl@0: sl@0: i = 100; sl@0: testStep = 1; sl@0: while(i <= KMaxFiles) sl@0: { sl@0: if(i == 100 || i == 1000 || i == 5000 || i == 10000) sl@0: { sl@0: MakeDirM(i, testStep++); sl@0: } sl@0: i += 100; sl@0: } sl@0: sl@0: gTestCase++; sl@0: return(KErrNone); sl@0: } sl@0: sl@0: /** Tests the creation of a directory with 2 threads accessing different directories sl@0: (the current and one with 300 files) sl@0: sl@0: @param aSelector Configuration in case of manual execution sl@0: */ sl@0: LOCAL_C TInt TestMakeMultDif(TAny* aSelector) sl@0: { sl@0: TInt i = 100; sl@0: TBuf16<50> directory; sl@0: TBuf16<50> dirtemp; sl@0: TInt testStep; sl@0: sl@0: Validate(aSelector); sl@0: sl@0: CreateDirWithNFiles(300,3); sl@0: sl@0: directory = gSessionPath; sl@0: dirtemp.Format(KDirMultipleName2, 3, 300); sl@0: directory.Append(dirtemp); sl@0: gDelEntryDir2 = directory; sl@0: sl@0: test.Printf(_L("#~TS_Title_%d,%d: MkDir with mult clients accessing dif dirs, RFs::MkDir\n"), gTestHarness, gTestCase); sl@0: sl@0: i = 100; sl@0: testStep = 1; sl@0: while(i <= KMaxFiles) sl@0: { sl@0: if(i == 100 || i == 1000 || i == 5000 || i == 10000) sl@0: { sl@0: directory = gSessionPath; sl@0: dirtemp.Format(KDirMultipleName2, 2, i); sl@0: directory.Append(dirtemp); sl@0: gDelEntryDir = directory; sl@0: sl@0: DoTest2(DeleteEntryAccess); sl@0: sl@0: MakeDir(i, testStep++); sl@0: sl@0: DoTestKill(); sl@0: } sl@0: i += 100; sl@0: } sl@0: sl@0: gTestCase++; sl@0: return(KErrNone); sl@0: } sl@0: sl@0: /** Goes automatically through all the options sl@0: sl@0: @param aSelector Configuration in case of manual execution sl@0: */ sl@0: LOCAL_C TInt TestAll(TAny* aSelector) sl@0: { sl@0: Validate(aSelector); sl@0: sl@0: TestMake(aSelector); sl@0: TestMakeMultSame(aSelector); sl@0: TestMakeMultDif(aSelector); sl@0: sl@0: return(KErrNone); sl@0: } sl@0: sl@0: /** Call all tests sl@0: sl@0: */ sl@0: GLDEF_C void CallTestsL() sl@0: { sl@0: TInt r = client.CreateLocal(0); sl@0: FailIfError(r); sl@0: sl@0: gFileSize = 8; sl@0: sl@0: CSelectionBox* TheSelector = CSelectionBox::NewL(test.Console()); sl@0: sl@0: // Each test case of the suite has an identifyer for parsing purposes of the results sl@0: gTestHarness = 6; sl@0: gTestCase = 1; sl@0: sl@0: PrintHeaders(1, _L("t_fsrmkdir. Mkdir")); sl@0: sl@0: if(gMode == 0) sl@0: { // Manual sl@0: gSessionPath=_L("?:\\"); sl@0: TCallBack createFiles(TestFileCreate, TheSelector); sl@0: TCallBack MkDir(TestMake, TheSelector); sl@0: TCallBack makeMultSame(TestMakeMultSame, TheSelector); sl@0: TCallBack makeMultDif(TestMakeMultDif, TheSelector); sl@0: TCallBack makeAll(TestAll, TheSelector); sl@0: TheSelector->AddDriveSelectorL(TheFs); sl@0: TheSelector->AddLineL(_L("Create all files"), createFiles); sl@0: TheSelector->AddLineL(_L("Mkdir "), MkDir); sl@0: TheSelector->AddLineL(_L("Mkdir mult clients same dir "), makeMultSame); sl@0: TheSelector->AddLineL(_L("Mkdir mult clients dif dir"), makeMultDif); sl@0: TheSelector->AddLineL(_L("Execute all options"), makeAll); sl@0: TheSelector->Run(); sl@0: } sl@0: else sl@0: { // Automatic sl@0: TestAll(TheSelector); sl@0: } sl@0: sl@0: client.Close(); sl@0: test.Printf(_L("#~TestEnd_%d\n"), gTestHarness); sl@0: delete TheSelector; sl@0: }