First public contribution.
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_fsrmkdir.cpp
21 #include "t_benchmain.h"
24 GLDEF_D RTest test(_L("FS Benchmarks, mkdir"));
26 //----------------------------------------------------------------------------------------------
27 //! @SYMTestCaseID PBASE-T_FSRMKDIR-0277
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 creation of a directory in each directory with RFs::MkDir
33 //! 2. Time the creation of a directory (with RFs::MkDir) in each directory
34 //! with different clients accessing the directory
35 //! 3. Time the creation of a directory (with RFs::MkDir) in each directory
36 //! with different clients accessing different directories
38 //! @SYMTestExpectedResults Finishes if the system behaves as expected, panics otherwise
39 //! @SYMTestPriority High
40 //! @SYMTestStatus Implemented
41 //----------------------------------------------------------------------------------------------
43 LOCAL_D RSemaphore client,write_screen;
44 LOCAL_D const TInt KHeapSize = 0x4000;
45 LOCAL_D TBuf8<4096> buf;
47 LOCAL_D TDriveList gDriveList;
49 LOCAL_D TFileName gDelEntryDir;
50 LOCAL_D TFileName gDelEntryDir2;
59 LOCAL_D TInt ThreadCount=0;
61 _LIT(KDirMultipleName2, "dir%d_%d\\");
62 _LIT(KNewDir, "new_dir\\");
64 _LIT(KDeleteMe,"delete%d.me");
65 _LIT(KDeleteMe2,"blabla%d.rhd");
67 /** Delete entry in directory
70 LOCAL_C TInt DeleteEntryAccess2(TAny* )
73 TInt r = fs.Connect();
77 RTest test(_L("test 2"));
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 r = 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);
136 r = fs2.Delete(dirfile);
138 if((r != KErrNone) && (r != KErrInUse))
140 test.Printf(_L("error = %d\n"), r);
143 test(r == KErrNone || r == KErrInUse);
149 /** Starts two concurrent client sessions in different directories
152 LOCAL_C void DoTest2(TThreadFunction aFunction)
156 TBuf<20> buf = _L("Speedy");
157 buf.AppendNum(ThreadCount++);
159 TInt r = gSpeedy.Create(buf, aFunction, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
163 buf.AppendNum(ThreadCount++);
165 r = gSpeedyII.Create(buf, DeleteEntryAccess2, KDefaultStackSize, KHeapSize, KHeapSize, NULL);
168 gSpeedy.SetPriority(EPriorityLess);
169 gSpeedyII.SetPriority(EPriorityLess);
179 /** Kills the concurrent session
182 LOCAL_C void DoTestKill()
185 User::After(10000000);
187 gSpeedy.Kill(KErrNone);
190 gSpeedyII.Kill(KErrNone);
194 /** Time the creation of a directory inside each type of directory
196 @param aN Number of files in the directory
197 @param aStep Test step
199 LOCAL_C void MakeDir(TInt aN, TInt aStep)
209 TTimeIntervalMicroSeconds timeTaken(0);
210 TInt timeTaken1 = -1, timeTaken2 = -1, timeTaken3 = -1;
212 if(aN <= gFilesLimit)
218 dir4.Format(KDirMultipleName2, 1, aN);
220 dir4.Format(KDirMultipleName2, 2, aN);
222 dir4.Format(KDirMultipleName2, 3, aN);
225 dir1.Append(KNewDir);
226 dir2.Append(KNewDir);
227 dir3.Append(KNewDir);
231 dir4.Format(KDirMultipleName, 1, aN);
232 startTime.HomeTime();
234 r = TheFs.MkDir(dir1);
239 timeTaken = endTime.MicroSecondsFrom(startTime);
240 timeTaken1 = I64LOW(timeTaken.Int64() / gTimeUnit);
246 startTime.HomeTime();
248 r = TheFs.MkDir(dir2);
253 timeTaken = endTime.MicroSecondsFrom(startTime);
254 timeTaken2 = I64LOW(timeTaken.Int64() / gTimeUnit);
260 startTime.HomeTime();
262 r = TheFs.MkDir(dir3);
266 timeTaken = endTime.MicroSecondsFrom(startTime);
267 timeTaken3 = I64LOW(timeTaken.Int64() / gTimeUnit);
273 PrintResult(aStep, 1, aN);
274 PrintResultTime(aStep, 2, timeTaken1);
275 PrintResultTime(aStep, 3, timeTaken2);
276 PrintResultTime(aStep, 4, timeTaken3);
279 /** Time the creation of a directory inside each type of directory with multiple threads ongoing
281 @param aN Number of files in the directory
282 @param aStep Test step
284 LOCAL_C void MakeDirM(TInt aN, TInt aStep)
294 TTimeIntervalMicroSeconds timeTaken(0);
295 TInt timeTaken1 = -1, timeTaken2 = -1, timeTaken3 = -1;
297 if(aN <= gFilesLimit)
303 dir4.Format(KDirMultipleName2, 1, aN);
305 dir4.Format(KDirMultipleName2, 2, aN);
307 dir4.Format(KDirMultipleName2, 3, aN);
313 gDelEntryDir2 = dir1;
315 dir1.Append(KNewDir);
316 DoTest2(DeleteEntryAccess);
318 startTime.HomeTime();
320 r = TheFs.MkDir(dir1);
327 timeTaken = endTime.MicroSecondsFrom(startTime);
328 timeTaken1 = I64LOW(timeTaken.Int64() / gTimeUnit);
336 gDelEntryDir2 = dir2;
337 dir2.Append(KNewDir);
339 DoTest2(DeleteEntryAccess);
341 startTime.HomeTime();
343 r = TheFs.MkDir(dir2);
349 timeTaken = endTime.MicroSecondsFrom(startTime);
350 timeTaken2 = I64LOW(timeTaken.Int64() / gTimeUnit);
358 gDelEntryDir2 = dir3;
359 dir3.Append(KNewDir);
360 DoTest2(DeleteEntryAccess);
362 startTime.HomeTime();
364 r = TheFs.MkDir(dir3);
370 timeTaken = endTime.MicroSecondsFrom(startTime);
371 timeTaken3 = I64LOW(timeTaken.Int64() / gTimeUnit);
377 PrintResult(aStep, 1, aN);
378 PrintResultTime(aStep, 2, timeTaken1);
379 PrintResultTime(aStep, 3, timeTaken2);
380 PrintResultTime(aStep, 4, timeTaken3);
384 /** Times the creation of a directory
385 Precondition: This test expectsthe drive already filled with the right files
387 @param aSelector Configuration in case of manual execution
389 LOCAL_C TInt TestMake(TAny* aSelector)
396 test.Printf(_L("#~TS_Title_%d,%d: MkDir, RFs::MkDir\n"), gTestHarness, gTestCase);
400 while(i <= KMaxFiles)
402 if(i == 100 || i == 1000 || i == 5000 || i == 10000)
404 MakeDir(i, testStep++);
413 /** Tests the creation of a directory with 2 threads accessing the directory
415 @param aSelector Configuration in case of manual execution
417 LOCAL_C TInt TestMakeMultSame(TAny* aSelector)
424 test.Printf(_L("#~TS_Title_%d,%d: MkDir with mult clients accessing same dir, RFs::MkDir\n"), gTestHarness, gTestCase);
428 while(i <= KMaxFiles)
430 if(i == 100 || i == 1000 || i == 5000 || i == 10000)
432 MakeDirM(i, testStep++);
441 /** Tests the creation of a directory with 2 threads accessing different directories
442 (the current and one with 300 files)
444 @param aSelector Configuration in case of manual execution
446 LOCAL_C TInt TestMakeMultDif(TAny* aSelector)
449 TBuf16<50> directory;
455 CreateDirWithNFiles(300,3);
457 directory = gSessionPath;
458 dirtemp.Format(KDirMultipleName2, 3, 300);
459 directory.Append(dirtemp);
460 gDelEntryDir2 = directory;
462 test.Printf(_L("#~TS_Title_%d,%d: MkDir with mult clients accessing dif dirs, RFs::MkDir\n"), gTestHarness, gTestCase);
466 while(i <= KMaxFiles)
468 if(i == 100 || i == 1000 || i == 5000 || i == 10000)
470 directory = gSessionPath;
471 dirtemp.Format(KDirMultipleName2, 2, i);
472 directory.Append(dirtemp);
473 gDelEntryDir = directory;
475 DoTest2(DeleteEntryAccess);
477 MakeDir(i, testStep++);
488 /** Goes automatically through all the options
490 @param aSelector Configuration in case of manual execution
492 LOCAL_C TInt TestAll(TAny* aSelector)
497 TestMakeMultSame(aSelector);
498 TestMakeMultDif(aSelector);
506 GLDEF_C void CallTestsL()
508 TInt r = client.CreateLocal(0);
513 CSelectionBox* TheSelector = CSelectionBox::NewL(test.Console());
515 // Each test case of the suite has an identifyer for parsing purposes of the results
519 PrintHeaders(1, _L("t_fsrmkdir. Mkdir"));
523 gSessionPath=_L("?:\\");
524 TCallBack createFiles(TestFileCreate, TheSelector);
525 TCallBack MkDir(TestMake, TheSelector);
526 TCallBack makeMultSame(TestMakeMultSame, TheSelector);
527 TCallBack makeMultDif(TestMakeMultDif, TheSelector);
528 TCallBack makeAll(TestAll, TheSelector);
529 TheSelector->AddDriveSelectorL(TheFs);
530 TheSelector->AddLineL(_L("Create all files"), createFiles);
531 TheSelector->AddLineL(_L("Mkdir "), MkDir);
532 TheSelector->AddLineL(_L("Mkdir mult clients same dir "), makeMultSame);
533 TheSelector->AddLineL(_L("Mkdir mult clients dif dir"), makeMultDif);
534 TheSelector->AddLineL(_L("Execute all options"), makeAll);
539 TestAll(TheSelector);
543 test.Printf(_L("#~TestEnd_%d\n"), gTestHarness);