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_fsrrepeat.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, Open and read 4 KB")); sl@0: sl@0: //---------------------------------------------------------------------------------------------- sl@0: //! @SYMTestCaseID PBASE-T_FSRREPEAT-0276 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 opening and read 3 times 4 Kb of last.txt file in each directory sl@0: //! 2. Time the opening and read 3 times 4 Kb of last.txt file in each directory sl@0: //! with two clients accessing the directory sl@0: //! 3. Time the opening and read 3 times of 4 Kb of last.txt file in each directory sl@0: //! with two 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: sl@0: LOCAL_D RSemaphore client,write_screen; sl@0: LOCAL_D const TInt KHeapSize=0x4000; 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 threads 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: LOCAL_D TBuf8<4096> buf; sl@0: sl@0: _LIT(KDirMultipleName2, "dir%d_%d\\"); sl@0: sl@0: _LIT(KDeleteMe,"DELETE%d.ME"); sl@0: _LIT(KDeleteMe2,"BLABLA%d.RHD"); sl@0: 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: 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: 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: sl@0: r = fs2.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: /** 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: /** 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: /** Open last.txt with RFs and without any other process sl@0: sl@0: @param aN Number of files in the directory sl@0: @param aType Type of files sl@0: @param aStep Test step sl@0: */ sl@0: LOCAL_C void OpenFile(TInt aN, TInt aType, TInt aStep) sl@0: { sl@0: TBuf16<100> file; sl@0: TBuf16<100> dir; sl@0: sl@0: TInt r = 0; sl@0: TTime startTime; sl@0: TTime endTime; sl@0: TTimeIntervalMicroSeconds timeTaken(0); sl@0: TInt timeTakenArray[3] = {-1, -1, -1}; sl@0: TInt i; sl@0: RFile f; sl@0: sl@0: if(aN <= gFilesLimit) sl@0: { sl@0: if(aType <= gTypes) sl@0: { sl@0: file = gSessionPath; sl@0: sl@0: dir.Format(KDirMultipleName2, aType, aN); sl@0: file.Append(dir); sl@0: sl@0: file.Append(KCommonFile); sl@0: sl@0: i = 0; sl@0: while(i < 3) sl@0: { sl@0: startTime.HomeTime(); sl@0: sl@0: r = f.Open(TheFs, file, EFileShareAny|EFileRead); sl@0: FailIfError(r); sl@0: r = f.Read(buf); sl@0: FailIfError(r); sl@0: sl@0: f.Close(); sl@0: sl@0: endTime.HomeTime(); sl@0: sl@0: timeTaken = endTime.MicroSecondsFrom(startTime); sl@0: timeTakenArray[i++] = I64LOW(timeTaken.Int64() / gTimeUnit); sl@0: } sl@0: } sl@0: } sl@0: sl@0: dir.Format(KDirMultipleName,aType,aN); sl@0: sl@0: PrintResultS(aStep, 1, dir); sl@0: PrintResultTime(aStep, 2, timeTakenArray[0]); sl@0: PrintResultTime(aStep, 3, timeTakenArray[1]); sl@0: PrintResultTime(aStep, 4, timeTakenArray[2]); sl@0: } sl@0: sl@0: /** Times the opening of a file and read operation sl@0: Precondition: This test expects the 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 TestOpen(TAny* aSelector) sl@0: { sl@0: TInt i = 100, j; sl@0: TInt testStep; sl@0: sl@0: Validate(aSelector); sl@0: sl@0: test.Printf(_L("#~TS_Title_%d,%d: Open last.txt and read 4 K repeatedly, RFs::Open\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: j = 1; sl@0: while(j <= KMaxTypes) sl@0: { sl@0: OpenFile(i, j, testStep++); sl@0: j++; sl@0: } sl@0: } sl@0: i += 100; sl@0: } sl@0: sl@0: gTestCase++; sl@0: return(KErrNone); sl@0: } sl@0: sl@0: /** Times the opening of a file and read operation with two threads accessing sl@0: different directories sl@0: sl@0: @param aSelector Configuration in case of manual execution sl@0: */ sl@0: LOCAL_C TInt TestOpenMultSame(TAny* aSelector) sl@0: { sl@0: TInt i = 100,j; sl@0: TBuf16<50> directory; sl@0: TBuf16<50> dirtemp; sl@0: TInt testStep; sl@0: sl@0: Validate(aSelector); sl@0: sl@0: test.Printf(_L("#~TS_Title_%d,%d: Open last.txt and read 4 K repeatedly with mult clients accessing, RFs::Open\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: j = 1; sl@0: while(j <= KMaxTypes) sl@0: { sl@0: directory = gSessionPath; sl@0: dirtemp.Format(KDirMultipleName2, j, i); sl@0: directory.Append(dirtemp); sl@0: gDelEntryDir = directory; sl@0: gDelEntryDir2 = directory; sl@0: sl@0: DoTest2(DeleteEntryAccess); sl@0: sl@0: OpenFile(i, j, testStep++); sl@0: sl@0: DoTestKill(); sl@0: sl@0: j++; sl@0: } sl@0: } sl@0: i += 100; sl@0: } sl@0: sl@0: gTestCase++; sl@0: return(KErrNone); sl@0: } sl@0: sl@0: /** Times the opening of a file and read operation with two threads accessing sl@0: different directories sl@0: sl@0: @param aSelector Configuration in case of manual execution sl@0: */ sl@0: LOCAL_C TInt TestOpenMultDif(TAny* aSelector) sl@0: { sl@0: TInt i = 100,j; 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: sl@0: gDelEntryDir2 = directory; sl@0: sl@0: test.Printf(_L("#~TS_Title_%d,%d: Open last.txt and read 4 K repeatedly mult clients accessing dif dirs, RFs::Open\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: j = 1; sl@0: while(j <= KMaxTypes) sl@0: { sl@0: directory = gSessionPath; sl@0: dirtemp.Format(KDirMultipleName2, j, i); sl@0: directory.Append(dirtemp); sl@0: gDelEntryDir = directory; sl@0: sl@0: DoTest2(DeleteEntryAccess); sl@0: sl@0: OpenFile(i, j, testStep++); sl@0: sl@0: DoTestKill(); sl@0: sl@0: j++; sl@0: } sl@0: } sl@0: i += 100; sl@0: } sl@0: sl@0: gTestCase++; sl@0: return(KErrNone); sl@0: } sl@0: sl@0: /** It 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: sl@0: TestOpen(aSelector); sl@0: TestOpenMultSame(aSelector); sl@0: TestOpenMultDif(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: sl@0: TInt r=client.CreateLocal(0); sl@0: FailIfError(r); sl@0: sl@0: gFileSize = 8; sl@0: sl@0: // Each test case of the suite has an identifyer for parsing purposes of the results sl@0: gTestHarness = 5; sl@0: gTestCase = 1; sl@0: sl@0: PrintHeaders(2, _L("t_fsrrepeat. Repeat reading")); sl@0: sl@0: CSelectionBox* TheSelector = CSelectionBox::NewL(test.Console()); sl@0: sl@0: sl@0: if(gMode == 0) sl@0: { // Manual sl@0: gSessionPath = _L("?:\\"); sl@0: TCallBack createFiles(TestFileCreate,TheSelector); sl@0: TCallBack openF(TestOpen,TheSelector); sl@0: TCallBack openMultSame(TestOpenMultSame,TheSelector); sl@0: TCallBack openMultDif(TestOpenMultDif,TheSelector); sl@0: TCallBack openAll(TestAll,TheSelector); sl@0: TheSelector->AddDriveSelectorL(TheFs); sl@0: TheSelector->AddLineL(_L("Create all files"),createFiles); sl@0: TheSelector->AddLineL(_L("Open and read repeatedly"),openF); sl@0: TheSelector->AddLineL(_L("Same mult clients same dir "),openMultSame); sl@0: TheSelector->AddLineL(_L("Same mult clients dif dir"),openMultDif); sl@0: TheSelector->AddLineL(_L("Execute all options"),openAll); 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: }