|
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". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // f32test\bench\t_fsrmkdir.cpp |
|
15 // |
|
16 // |
|
17 |
|
18 #include <f32file.h> |
|
19 #include <e32test.h> |
|
20 #include "t_select.h" |
|
21 #include "t_benchmain.h" |
|
22 |
|
23 |
|
24 GLDEF_D RTest test(_L("FS Benchmarks, mkdir")); |
|
25 |
|
26 //---------------------------------------------------------------------------------------------- |
|
27 //! @SYMTestCaseID PBASE-T_FSRMKDIR-0277 |
|
28 //! @SYMTestType CIT |
|
29 //! @SYMPREQ PREQ000 |
|
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 |
|
37 //! |
|
38 //! @SYMTestExpectedResults Finishes if the system behaves as expected, panics otherwise |
|
39 //! @SYMTestPriority High |
|
40 //! @SYMTestStatus Implemented |
|
41 //---------------------------------------------------------------------------------------------- |
|
42 |
|
43 LOCAL_D RSemaphore client,write_screen; |
|
44 LOCAL_D const TInt KHeapSize = 0x4000; |
|
45 LOCAL_D TBuf8<4096> buf; |
|
46 |
|
47 LOCAL_D TDriveList gDriveList; |
|
48 |
|
49 LOCAL_D TFileName gDelEntryDir; |
|
50 LOCAL_D TFileName gDelEntryDir2; |
|
51 |
|
52 // Concurrent thread |
|
53 RThread gSpeedy; |
|
54 RThread gSpeedyII; |
|
55 TInt gT1; |
|
56 TInt gT2; |
|
57 TBool gKillMe=EFalse; |
|
58 |
|
59 LOCAL_D TInt ThreadCount=0; |
|
60 |
|
61 _LIT(KDirMultipleName2, "dir%d_%d\\"); |
|
62 _LIT(KNewDir, "new_dir\\"); |
|
63 |
|
64 _LIT(KDeleteMe,"delete%d.me"); |
|
65 _LIT(KDeleteMe2,"blabla%d.rhd"); |
|
66 |
|
67 /** Delete entry in directory |
|
68 |
|
69 */ |
|
70 LOCAL_C TInt DeleteEntryAccess2(TAny* ) |
|
71 { |
|
72 RFs fs; |
|
73 TInt r = fs.Connect(); |
|
74 TBuf<100> dirfile; |
|
75 TBuf<50> filename; |
|
76 RFile file; |
|
77 RTest test(_L("test 2")); |
|
78 |
|
79 fs.SetSessionPath(gSessionPath); |
|
80 filename.Format(KDeleteMe2, gT2); |
|
81 |
|
82 dirfile = gDelEntryDir2; |
|
83 dirfile.Append(filename); |
|
84 |
|
85 client.Signal(); |
|
86 |
|
87 FOREVER |
|
88 { |
|
89 if(!gKillMe) |
|
90 { |
|
91 r = file.Create(fs, dirfile, EFileShareAny|EFileWrite); |
|
92 if(r == KErrAlreadyExists) |
|
93 r=file.Open(fs, dirfile, EFileShareAny|EFileWrite); |
|
94 file.Close(); |
|
95 FailIfError(r); |
|
96 |
|
97 r = fs.Delete(dirfile); |
|
98 if((r != KErrNone) && (r != KErrInUse)) |
|
99 { |
|
100 test.Printf(_L("error = %d\n"), r); |
|
101 } |
|
102 test(r == KErrNone || r == KErrInUse); |
|
103 } |
|
104 } |
|
105 } |
|
106 |
|
107 /** Delete entry in directory |
|
108 |
|
109 */ |
|
110 LOCAL_C TInt DeleteEntryAccess(TAny*) |
|
111 { |
|
112 RFs fs2; |
|
113 TInt r = fs2.Connect(); |
|
114 TBuf<100> dirfile; |
|
115 TBuf<50> filename; |
|
116 RFile file2; |
|
117 RTest test(_L("test 2")); |
|
118 |
|
119 r = fs2.SetSessionPath(gSessionPath); |
|
120 filename.Format(KDeleteMe, gT1); |
|
121 |
|
122 dirfile = gDelEntryDir; |
|
123 dirfile.Append(filename); |
|
124 |
|
125 client.Signal(); |
|
126 |
|
127 FOREVER |
|
128 { |
|
129 if(!gKillMe) |
|
130 { |
|
131 r = file2.Create(fs2, dirfile, EFileShareAny|EFileWrite); |
|
132 if(r == KErrAlreadyExists) |
|
133 r = file2.Open(fs2, dirfile, EFileShareAny|EFileWrite); |
|
134 file2.Close(); |
|
135 FailIfError(r); |
|
136 r = fs2.Delete(dirfile); |
|
137 |
|
138 if((r != KErrNone) && (r != KErrInUse)) |
|
139 { |
|
140 test.Printf(_L("error = %d\n"), r); |
|
141 } |
|
142 |
|
143 test(r == KErrNone || r == KErrInUse); |
|
144 } |
|
145 } |
|
146 } |
|
147 |
|
148 |
|
149 /** Starts two concurrent client sessions in different directories |
|
150 |
|
151 */ |
|
152 LOCAL_C void DoTest2(TThreadFunction aFunction) |
|
153 { |
|
154 gKillMe = EFalse; |
|
155 |
|
156 TBuf<20> buf = _L("Speedy"); |
|
157 buf.AppendNum(ThreadCount++); |
|
158 gT1 = ThreadCount; |
|
159 TInt r = gSpeedy.Create(buf, aFunction, KDefaultStackSize, KHeapSize, KHeapSize, NULL); |
|
160 FailIfError(r); |
|
161 |
|
162 buf = _L("Speedy"); |
|
163 buf.AppendNum(ThreadCount++); |
|
164 gT2 = ThreadCount; |
|
165 r = gSpeedyII.Create(buf, DeleteEntryAccess2, KDefaultStackSize, KHeapSize, KHeapSize, NULL); |
|
166 FailIfError(r); |
|
167 |
|
168 gSpeedy.SetPriority(EPriorityLess); |
|
169 gSpeedyII.SetPriority(EPriorityLess); |
|
170 |
|
171 gSpeedy.Resume(); |
|
172 gSpeedyII.Resume(); |
|
173 |
|
174 client.Wait(); |
|
175 client.Wait(); |
|
176 } |
|
177 |
|
178 |
|
179 /** Kills the concurrent session |
|
180 |
|
181 */ |
|
182 LOCAL_C void DoTestKill() |
|
183 { |
|
184 gKillMe = ETrue; |
|
185 User::After(10000000); |
|
186 |
|
187 gSpeedy.Kill(KErrNone); |
|
188 gSpeedy.Close(); |
|
189 |
|
190 gSpeedyII.Kill(KErrNone); |
|
191 gSpeedyII.Close(); |
|
192 } |
|
193 |
|
194 /** Time the creation of a directory inside each type of directory |
|
195 |
|
196 @param aN Number of files in the directory |
|
197 @param aStep Test step |
|
198 */ |
|
199 LOCAL_C void MakeDir(TInt aN, TInt aStep) |
|
200 { |
|
201 TBuf16<100> dir1; |
|
202 TBuf16<100> dir2; |
|
203 TBuf16<100> dir3; |
|
204 TBuf16<100> dir4; |
|
205 |
|
206 TInt r=0; |
|
207 TTime startTime; |
|
208 TTime endTime; |
|
209 TTimeIntervalMicroSeconds timeTaken(0); |
|
210 TInt timeTaken1 = -1, timeTaken2 = -1, timeTaken3 = -1; |
|
211 |
|
212 if(aN <= gFilesLimit) |
|
213 { |
|
214 dir1 = gSessionPath; |
|
215 dir2 = gSessionPath; |
|
216 dir3 = gSessionPath; |
|
217 |
|
218 dir4.Format(KDirMultipleName2, 1, aN); |
|
219 dir1.Append(dir4); |
|
220 dir4.Format(KDirMultipleName2, 2, aN); |
|
221 dir2.Append(dir4); |
|
222 dir4.Format(KDirMultipleName2, 3, aN); |
|
223 dir3.Append(dir4); |
|
224 |
|
225 dir1.Append(KNewDir); |
|
226 dir2.Append(KNewDir); |
|
227 dir3.Append(KNewDir); |
|
228 |
|
229 if(gTypes >= 1) |
|
230 { |
|
231 dir4.Format(KDirMultipleName, 1, aN); |
|
232 startTime.HomeTime(); |
|
233 |
|
234 r = TheFs.MkDir(dir1); |
|
235 FailIfError(r); |
|
236 |
|
237 endTime.HomeTime(); |
|
238 |
|
239 timeTaken = endTime.MicroSecondsFrom(startTime); |
|
240 timeTaken1 = I64LOW(timeTaken.Int64() / gTimeUnit); |
|
241 TheFs.RmDir(dir1); |
|
242 } |
|
243 |
|
244 if(gTypes >= 2) |
|
245 { |
|
246 startTime.HomeTime(); |
|
247 |
|
248 r = TheFs.MkDir(dir2); |
|
249 FailIfError(r); |
|
250 |
|
251 endTime.HomeTime(); |
|
252 |
|
253 timeTaken = endTime.MicroSecondsFrom(startTime); |
|
254 timeTaken2 = I64LOW(timeTaken.Int64() / gTimeUnit); |
|
255 TheFs.RmDir(dir2); |
|
256 } |
|
257 |
|
258 if(gTypes>=3) |
|
259 { |
|
260 startTime.HomeTime(); |
|
261 |
|
262 r = TheFs.MkDir(dir3); |
|
263 FailIfError(r); |
|
264 |
|
265 endTime.HomeTime(); |
|
266 timeTaken = endTime.MicroSecondsFrom(startTime); |
|
267 timeTaken3 = I64LOW(timeTaken.Int64() / gTimeUnit); |
|
268 |
|
269 TheFs.RmDir(dir3); |
|
270 } |
|
271 } |
|
272 |
|
273 PrintResult(aStep, 1, aN); |
|
274 PrintResultTime(aStep, 2, timeTaken1); |
|
275 PrintResultTime(aStep, 3, timeTaken2); |
|
276 PrintResultTime(aStep, 4, timeTaken3); |
|
277 } |
|
278 |
|
279 /** Time the creation of a directory inside each type of directory with multiple threads ongoing |
|
280 |
|
281 @param aN Number of files in the directory |
|
282 @param aStep Test step |
|
283 */ |
|
284 LOCAL_C void MakeDirM(TInt aN, TInt aStep) |
|
285 { |
|
286 TBuf16<100> dir1; |
|
287 TBuf16<100> dir2; |
|
288 TBuf16<100> dir3; |
|
289 TBuf16<100> dir4; |
|
290 |
|
291 TInt r = 0; |
|
292 TTime startTime; |
|
293 TTime endTime; |
|
294 TTimeIntervalMicroSeconds timeTaken(0); |
|
295 TInt timeTaken1 = -1, timeTaken2 = -1, timeTaken3 = -1; |
|
296 |
|
297 if(aN <= gFilesLimit) |
|
298 { |
|
299 dir1 = gSessionPath; |
|
300 dir2 = gSessionPath; |
|
301 dir3 = gSessionPath; |
|
302 |
|
303 dir4.Format(KDirMultipleName2, 1, aN); |
|
304 dir1.Append(dir4); |
|
305 dir4.Format(KDirMultipleName2, 2, aN); |
|
306 dir2.Append(dir4); |
|
307 dir4.Format(KDirMultipleName2, 3, aN); |
|
308 dir3.Append(dir4); |
|
309 |
|
310 if(gTypes >= 1) |
|
311 { |
|
312 gDelEntryDir = dir1; |
|
313 gDelEntryDir2 = dir1; |
|
314 |
|
315 dir1.Append(KNewDir); |
|
316 DoTest2(DeleteEntryAccess); |
|
317 |
|
318 startTime.HomeTime(); |
|
319 |
|
320 r = TheFs.MkDir(dir1); |
|
321 FailIfError(r); |
|
322 |
|
323 endTime.HomeTime(); |
|
324 |
|
325 DoTestKill(); |
|
326 |
|
327 timeTaken = endTime.MicroSecondsFrom(startTime); |
|
328 timeTaken1 = I64LOW(timeTaken.Int64() / gTimeUnit); |
|
329 |
|
330 TheFs.RmDir(dir1); |
|
331 } |
|
332 |
|
333 if(gTypes >= 2) |
|
334 { |
|
335 gDelEntryDir = dir2; |
|
336 gDelEntryDir2 = dir2; |
|
337 dir2.Append(KNewDir); |
|
338 |
|
339 DoTest2(DeleteEntryAccess); |
|
340 |
|
341 startTime.HomeTime(); |
|
342 |
|
343 r = TheFs.MkDir(dir2); |
|
344 FailIfError(r); |
|
345 |
|
346 endTime.HomeTime(); |
|
347 DoTestKill(); |
|
348 |
|
349 timeTaken = endTime.MicroSecondsFrom(startTime); |
|
350 timeTaken2 = I64LOW(timeTaken.Int64() / gTimeUnit); |
|
351 |
|
352 TheFs.RmDir(dir2); |
|
353 } |
|
354 |
|
355 if(gTypes >= 3) |
|
356 { |
|
357 gDelEntryDir = dir3; |
|
358 gDelEntryDir2 = dir3; |
|
359 dir3.Append(KNewDir); |
|
360 DoTest2(DeleteEntryAccess); |
|
361 |
|
362 startTime.HomeTime(); |
|
363 |
|
364 r = TheFs.MkDir(dir3); |
|
365 FailIfError(r); |
|
366 |
|
367 endTime.HomeTime(); |
|
368 DoTestKill(); |
|
369 |
|
370 timeTaken = endTime.MicroSecondsFrom(startTime); |
|
371 timeTaken3 = I64LOW(timeTaken.Int64() / gTimeUnit); |
|
372 |
|
373 TheFs.RmDir(dir3); |
|
374 } |
|
375 } |
|
376 |
|
377 PrintResult(aStep, 1, aN); |
|
378 PrintResultTime(aStep, 2, timeTaken1); |
|
379 PrintResultTime(aStep, 3, timeTaken2); |
|
380 PrintResultTime(aStep, 4, timeTaken3); |
|
381 |
|
382 } |
|
383 |
|
384 /** Times the creation of a directory |
|
385 Precondition: This test expectsthe drive already filled with the right files |
|
386 |
|
387 @param aSelector Configuration in case of manual execution |
|
388 */ |
|
389 LOCAL_C TInt TestMake(TAny* aSelector) |
|
390 { |
|
391 TInt i = 100; |
|
392 TInt testStep; |
|
393 |
|
394 Validate(aSelector); |
|
395 |
|
396 test.Printf(_L("#~TS_Title_%d,%d: MkDir, RFs::MkDir\n"), gTestHarness, gTestCase); |
|
397 |
|
398 i = 100; |
|
399 testStep = 1; |
|
400 while(i <= KMaxFiles) |
|
401 { |
|
402 if(i == 100 || i == 1000 || i == 5000 || i == 10000) |
|
403 { |
|
404 MakeDir(i, testStep++); |
|
405 } |
|
406 i += 100; |
|
407 } |
|
408 |
|
409 gTestCase++; |
|
410 return(KErrNone); |
|
411 } |
|
412 |
|
413 /** Tests the creation of a directory with 2 threads accessing the directory |
|
414 |
|
415 @param aSelector Configuration in case of manual execution |
|
416 */ |
|
417 LOCAL_C TInt TestMakeMultSame(TAny* aSelector) |
|
418 { |
|
419 TInt i; |
|
420 TInt testStep; |
|
421 |
|
422 Validate(aSelector); |
|
423 |
|
424 test.Printf(_L("#~TS_Title_%d,%d: MkDir with mult clients accessing same dir, RFs::MkDir\n"), gTestHarness, gTestCase); |
|
425 |
|
426 i = 100; |
|
427 testStep = 1; |
|
428 while(i <= KMaxFiles) |
|
429 { |
|
430 if(i == 100 || i == 1000 || i == 5000 || i == 10000) |
|
431 { |
|
432 MakeDirM(i, testStep++); |
|
433 } |
|
434 i += 100; |
|
435 } |
|
436 |
|
437 gTestCase++; |
|
438 return(KErrNone); |
|
439 } |
|
440 |
|
441 /** Tests the creation of a directory with 2 threads accessing different directories |
|
442 (the current and one with 300 files) |
|
443 |
|
444 @param aSelector Configuration in case of manual execution |
|
445 */ |
|
446 LOCAL_C TInt TestMakeMultDif(TAny* aSelector) |
|
447 { |
|
448 TInt i = 100; |
|
449 TBuf16<50> directory; |
|
450 TBuf16<50> dirtemp; |
|
451 TInt testStep; |
|
452 |
|
453 Validate(aSelector); |
|
454 |
|
455 CreateDirWithNFiles(300,3); |
|
456 |
|
457 directory = gSessionPath; |
|
458 dirtemp.Format(KDirMultipleName2, 3, 300); |
|
459 directory.Append(dirtemp); |
|
460 gDelEntryDir2 = directory; |
|
461 |
|
462 test.Printf(_L("#~TS_Title_%d,%d: MkDir with mult clients accessing dif dirs, RFs::MkDir\n"), gTestHarness, gTestCase); |
|
463 |
|
464 i = 100; |
|
465 testStep = 1; |
|
466 while(i <= KMaxFiles) |
|
467 { |
|
468 if(i == 100 || i == 1000 || i == 5000 || i == 10000) |
|
469 { |
|
470 directory = gSessionPath; |
|
471 dirtemp.Format(KDirMultipleName2, 2, i); |
|
472 directory.Append(dirtemp); |
|
473 gDelEntryDir = directory; |
|
474 |
|
475 DoTest2(DeleteEntryAccess); |
|
476 |
|
477 MakeDir(i, testStep++); |
|
478 |
|
479 DoTestKill(); |
|
480 } |
|
481 i += 100; |
|
482 } |
|
483 |
|
484 gTestCase++; |
|
485 return(KErrNone); |
|
486 } |
|
487 |
|
488 /** Goes automatically through all the options |
|
489 |
|
490 @param aSelector Configuration in case of manual execution |
|
491 */ |
|
492 LOCAL_C TInt TestAll(TAny* aSelector) |
|
493 { |
|
494 Validate(aSelector); |
|
495 |
|
496 TestMake(aSelector); |
|
497 TestMakeMultSame(aSelector); |
|
498 TestMakeMultDif(aSelector); |
|
499 |
|
500 return(KErrNone); |
|
501 } |
|
502 |
|
503 /** Call all tests |
|
504 |
|
505 */ |
|
506 GLDEF_C void CallTestsL() |
|
507 { |
|
508 TInt r = client.CreateLocal(0); |
|
509 FailIfError(r); |
|
510 |
|
511 gFileSize = 8; |
|
512 |
|
513 CSelectionBox* TheSelector = CSelectionBox::NewL(test.Console()); |
|
514 |
|
515 // Each test case of the suite has an identifyer for parsing purposes of the results |
|
516 gTestHarness = 6; |
|
517 gTestCase = 1; |
|
518 |
|
519 PrintHeaders(1, _L("t_fsrmkdir. Mkdir")); |
|
520 |
|
521 if(gMode == 0) |
|
522 { // Manual |
|
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); |
|
535 TheSelector->Run(); |
|
536 } |
|
537 else |
|
538 { // Automatic |
|
539 TestAll(TheSelector); |
|
540 } |
|
541 |
|
542 client.Close(); |
|
543 test.Printf(_L("#~TestEnd_%d\n"), gTestHarness); |
|
544 delete TheSelector; |
|
545 } |