Update contrib.
1 // Copyright (c) 2006-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_fsrrepeat.cpp
21 #include "t_benchmain.h"
24 GLDEF_D RTest test(_L("FS Benchmarks, Open and read 4 KB"));
26 //----------------------------------------------------------------------------------------------
27 //! @SYMTestCaseID PBASE-T_FSRREPEAT-0276
30 //! @SYMTestCaseDesc This test case is measuring performance of the FAT implementation
31 //! @SYMTestActions 0. Expects the files to exist in order to successful execution
32 //! 1. Time the opening and read 3 times 4 Kb of last.txt file in each directory
33 //! 2. Time the opening and read 3 times 4 Kb of last.txt file in each directory
34 //! with two clients accessing the directory
35 //! 3. Time the opening and read 3 times of 4 Kb of last.txt file in each directory
36 //! with two clients accessing different directories
38 //! @SYMTestExpectedResults Finishes if the system behaves as expected, panics otherwise
39 //! @SYMTestPriority High
40 //! @SYMTestStatus Implemented
41 //----------------------------------------------------------------------------------------------
44 LOCAL_D RSemaphore client,write_screen;
45 LOCAL_D const TInt KHeapSize=0x4000;
47 LOCAL_D TDriveList gDriveList;
49 LOCAL_D TFileName gDelEntryDir;
50 LOCAL_D TFileName gDelEntryDir2;
57 TBool gKillMe = EFalse;
59 LOCAL_D TInt ThreadCount = 0;
60 LOCAL_D TBuf8<4096> buf;
62 _LIT(KDirMultipleName2, "dir%d_%d\\");
64 _LIT(KDeleteMe,"DELETE%d.ME");
65 _LIT(KDeleteMe2,"BLABLA%d.RHD");
68 /** Delete entry in directory
71 LOCAL_C TInt DeleteEntryAccess2(TAny* )
74 TInt r = fs.Connect();
79 fs.SetSessionPath(gSessionPath);
80 filename.Format(KDeleteMe2, gT2);
82 dirfile = gDelEntryDir2;
83 dirfile.Append(filename);
91 r = file.Create(fs, dirfile, EFileShareAny|EFileWrite);
92 if(r == KErrAlreadyExists)
93 r = file.Open(fs, dirfile, EFileShareAny|EFileWrite);
97 r = fs.Delete(dirfile);
98 if((r != KErrNone) && (r != KErrInUse))
100 test.Printf(_L("error = %d\n"), r);
102 test((r == KErrNone) || (r == KErrInUse));
107 /** Delete entry in directory
110 LOCAL_C TInt DeleteEntryAccess(TAny*)
113 TInt r = fs2.Connect();
117 RTest test(_L("test 2"));
119 fs2.SetSessionPath(gSessionPath);
120 filename.Format(KDeleteMe,gT1);
122 dirfile = gDelEntryDir;
123 dirfile.Append(filename);
131 r = file2.Create(fs2, dirfile, EFileShareAny|EFileWrite);
132 if(r == KErrAlreadyExists)
133 r = file2.Open(fs2, dirfile, EFileShareAny|EFileWrite);
137 r = fs2.Delete(dirfile);
138 if((r != KErrNone) && (r != KErrInUse))
140 test.Printf(_L("error = %d\n"), r);
142 test((r == KErrNone) || (r == KErrInUse));
147 /** Starts two concurrent client sessions in different directories
150 LOCAL_C void DoTest2(TThreadFunction aFunction)
154 TBuf<20> buf = _L("Speedy");
155 buf.AppendNum(ThreadCount++);
157 TInt r = gSpeedy.Create(buf, aFunction, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
161 buf.AppendNum(ThreadCount++);
163 r = gSpeedyII.Create(buf, DeleteEntryAccess2, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
166 gSpeedy.SetPriority(EPriorityLess);
167 gSpeedyII.SetPriority(EPriorityLess);
176 /** Kills the concurrent session
179 LOCAL_C void DoTestKill()
182 User::After(10000000);
184 gSpeedy.Kill(KErrNone);
187 gSpeedyII.Kill(KErrNone);
191 /** Open last.txt with RFs and without any other process
193 @param aN Number of files in the directory
194 @param aType Type of files
195 @param aStep Test step
197 LOCAL_C void OpenFile(TInt aN, TInt aType, TInt aStep)
205 TTimeIntervalMicroSeconds timeTaken(0);
206 TInt timeTakenArray[3] = {-1, -1, -1};
210 if(aN <= gFilesLimit)
216 dir.Format(KDirMultipleName2, aType, aN);
219 file.Append(KCommonFile);
224 startTime.HomeTime();
226 r = f.Open(TheFs, file, EFileShareAny|EFileRead);
235 timeTaken = endTime.MicroSecondsFrom(startTime);
236 timeTakenArray[i++] = I64LOW(timeTaken.Int64() / gTimeUnit);
241 dir.Format(KDirMultipleName,aType,aN);
243 PrintResultS(aStep, 1, dir);
244 PrintResultTime(aStep, 2, timeTakenArray[0]);
245 PrintResultTime(aStep, 3, timeTakenArray[1]);
246 PrintResultTime(aStep, 4, timeTakenArray[2]);
249 /** Times the opening of a file and read operation
250 Precondition: This test expects the drive already filled with the right files
252 @param aSelector Configuration in case of manual execution
254 LOCAL_C TInt TestOpen(TAny* aSelector)
261 test.Printf(_L("#~TS_Title_%d,%d: Open last.txt and read 4 K repeatedly, RFs::Open\n"), gTestHarness, gTestCase);
265 while(i <= KMaxFiles)
267 if(i == 100 || i == 1000 || i == 5000 || i == 10000)
270 while(j <= KMaxTypes)
272 OpenFile(i, j, testStep++);
283 /** Times the opening of a file and read operation with two threads accessing
284 different directories
286 @param aSelector Configuration in case of manual execution
288 LOCAL_C TInt TestOpenMultSame(TAny* aSelector)
291 TBuf16<50> directory;
297 test.Printf(_L("#~TS_Title_%d,%d: Open last.txt and read 4 K repeatedly with mult clients accessing, RFs::Open\n"), gTestHarness, gTestCase);
301 while(i <= KMaxFiles)
303 if(i == 100 || i == 1000 || i == 5000 || i == 10000)
306 while(j <= KMaxTypes)
308 directory = gSessionPath;
309 dirtemp.Format(KDirMultipleName2, j, i);
310 directory.Append(dirtemp);
311 gDelEntryDir = directory;
312 gDelEntryDir2 = directory;
314 DoTest2(DeleteEntryAccess);
316 OpenFile(i, j, testStep++);
330 /** Times the opening of a file and read operation with two threads accessing
331 different directories
333 @param aSelector Configuration in case of manual execution
335 LOCAL_C TInt TestOpenMultDif(TAny* aSelector)
338 TBuf16<50> directory;
344 CreateDirWithNFiles(300,3);
346 directory = gSessionPath;
347 dirtemp.Format(KDirMultipleName2, 3, 300);
348 directory.Append(dirtemp);
350 gDelEntryDir2 = directory;
352 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);
356 while(i <= KMaxFiles)
358 if(i == 100 || i == 1000 || i == 5000 || i == 10000)
361 while(j <= KMaxTypes)
363 directory = gSessionPath;
364 dirtemp.Format(KDirMultipleName2, j, i);
365 directory.Append(dirtemp);
366 gDelEntryDir = directory;
368 DoTest2(DeleteEntryAccess);
370 OpenFile(i, j, testStep++);
384 /** It goes automatically through all the options
386 @param aSelector Configuration in case of manual execution
388 LOCAL_C TInt TestAll(TAny* aSelector)
392 TestOpenMultSame(aSelector);
393 TestOpenMultDif(aSelector);
401 GLDEF_C void CallTestsL()
404 TInt r=client.CreateLocal(0);
409 // Each test case of the suite has an identifyer for parsing purposes of the results
413 PrintHeaders(2, _L("t_fsrrepeat. Repeat reading"));
415 CSelectionBox* TheSelector = CSelectionBox::NewL(test.Console());
420 gSessionPath = _L("?:\\");
421 TCallBack createFiles(TestFileCreate,TheSelector);
422 TCallBack openF(TestOpen,TheSelector);
423 TCallBack openMultSame(TestOpenMultSame,TheSelector);
424 TCallBack openMultDif(TestOpenMultDif,TheSelector);
425 TCallBack openAll(TestAll,TheSelector);
426 TheSelector->AddDriveSelectorL(TheFs);
427 TheSelector->AddLineL(_L("Create all files"),createFiles);
428 TheSelector->AddLineL(_L("Open and read repeatedly"),openF);
429 TheSelector->AddLineL(_L("Same mult clients same dir "),openMultSame);
430 TheSelector->AddLineL(_L("Same mult clients dif dir"),openMultDif);
431 TheSelector->AddLineL(_L("Execute all options"),openAll);
436 TestAll(TheSelector);
440 test.Printf(_L("#~TestEnd_%d\n"), gTestHarness);