26 #include <e32test.h> |
26 #include <e32test.h> |
27 #include <e32svr.h> |
27 #include <e32svr.h> |
28 #include <f32dbg.h> |
28 #include <f32dbg.h> |
29 #include "t_server.h" |
29 #include "t_server.h" |
30 #include <e32twin.h> |
30 #include <e32twin.h> |
|
31 #include <hal.h> |
|
32 #include "tf32testtimer.h" |
31 |
33 |
32 const TInt KTotalCacheSize = 32 * 1024 * 1024; |
34 const TInt KTotalCacheSize = 32 * 1024 * 1024; |
33 const TInt KDefaultCacheSize = (128 + 12) * 1024; // This size is the default configuration size |
35 const TInt KDefaultCacheSize = (128 + 12) * 1024; // This size is the default configuration size |
34 const TInt KFilesNeededToFillCache = (KTotalCacheSize / KDefaultCacheSize) + 2; |
36 const TInt KFilesNeededToFillCache = (KTotalCacheSize / KDefaultCacheSize) + 2; |
35 const TInt KMinSize = 254; // Boundary minim limit |
37 const TInt KMinSize = 254; // Boundary minim limit |
87 |
89 |
88 const TInt KOneK = 1024; |
90 const TInt KOneK = 1024; |
89 const TInt KOneMeg = KOneK * 1024; |
91 const TInt KOneMeg = KOneK * 1024; |
90 const TInt KBlockSize = KOneK; |
92 const TInt KBlockSize = KOneK; |
91 const TInt KWaitRequestsTableSize = 256; |
93 const TInt KWaitRequestsTableSize = 256; |
92 const TInt KMs = 1000; |
|
93 |
94 |
94 TInt gSecondFileSize = 0; |
95 TInt gSecondFileSize = 0; |
95 TInt gFirstFileSize = 0; |
96 TInt gFirstFileSize = 0; |
96 |
97 |
97 TInt64 gMediaSize = 0; |
98 TInt64 gMediaSize = 0; |
511 @param aBlockSize Size of the block |
509 @param aBlockSize Size of the block |
512 @param aMode Mode in which the file is going to be opened |
510 @param aMode Mode in which the file is going to be opened |
513 |
511 |
514 @return time taken to perform the operation in uS |
512 @return time taken to perform the operation in uS |
515 */ |
513 */ |
516 TInt WriteTestFile(RFile& aFile, TDes16& aFileName, TInt aSize, TInt aBlockSize, TInt aMode) |
514 TTimeIntervalMicroSeconds WriteTestFile(RFile& aFile, TDes16& aFileName, TInt aSize, TInt aBlockSize, TInt aMode) |
517 { |
515 { |
518 RTest test(_L("T_WCACHE")); |
516 RTest test(_L("T_WCACHE")); |
519 |
517 |
520 TTime startTime; |
|
521 TTime endTime; |
|
522 TInt r = 0; |
518 TInt r = 0; |
523 |
519 |
524 startTime.HomeTime(); |
520 TF32TestTimer timer; |
|
521 timer.Start(); |
525 |
522 |
526 r = WriteFile(gTheFs,aFile, aFileName , aSize * KOneK, aBlockSize, gBufWritePtr, aMode); |
523 r = WriteFile(gTheFs,aFile, aFileName , aSize * KOneK, aBlockSize, gBufWritePtr, aMode); |
527 test_KErrNone(r); |
524 test_KErrNone(r); |
528 |
525 |
529 endTime.HomeTime(); |
526 timer.Stop(); |
530 |
527 gTimeTakenBigFile = timer.Time(); |
531 gTimeTakenBigFile = I64LOW(endTime.MicroSecondsFrom(startTime).Int64()); |
|
532 |
|
533 test.Close(); |
528 test.Close(); |
534 return I64LOW(gTimeTakenBigFile.Int64()); |
529 return timer.Time(); |
535 } |
530 } |
536 |
531 |
537 /** Measure the time taken for this file to be read synchronously |
532 /** Measure the time taken for this file to be read synchronously |
538 |
533 |
539 @param aFile File object |
534 @param aFile File object |
543 @param aMode Mode in which the file is going to be opened |
538 @param aMode Mode in which the file is going to be opened |
544 |
539 |
545 @return time taken to perform the operation in uS |
540 @return time taken to perform the operation in uS |
546 |
541 |
547 */ |
542 */ |
548 TInt ReadTestFile(RFile& aFile, TDes16& aFileName, TInt aSize, TInt aBlockSize, TInt aMode) |
543 TTimeIntervalMicroSeconds ReadTestFile(RFile& aFile, TDes16& aFileName, TInt aSize, TInt aBlockSize, TInt aMode) |
549 { |
544 { |
550 TTime startTime; |
545 TF32TestTimer timer; |
551 TTime endTime; |
546 timer.Start(); |
552 |
|
553 startTime.HomeTime(); |
|
554 ReadFile(gTheFs,aFile, aFileName, aSize * KOneK, aBlockSize, aMode); |
547 ReadFile(gTheFs,aFile, aFileName, aSize * KOneK, aBlockSize, aMode); |
555 endTime.HomeTime(); |
548 timer.Stop(); |
556 |
549 |
557 gTimeTakenBigFile = I64LOW(endTime.MicroSecondsFrom(startTime).Int64()); |
550 gTimeTakenBigFile = timer.Time(); |
558 |
551 |
559 return I64LOW(gTimeTakenBigFile.Int64()) ; |
552 return timer.Time(); |
560 } |
553 } |
561 |
554 |
562 /** Read asynchronously the test file from the disc |
555 /** Read asynchronously the test file from the disc |
563 |
556 |
564 @param aFile File object |
557 @param aFile File object |
567 @param aBlockSize Size of the block |
560 @param aBlockSize Size of the block |
568 @param aMode Mode in which the file is going to be opened |
561 @param aMode Mode in which the file is going to be opened |
569 |
562 |
570 @return time taken to perform the operation in uS |
563 @return time taken to perform the operation in uS |
571 */ |
564 */ |
572 TInt ReadAsyncTestFile(RFile& file, TDes16& aFile, TInt aSize, TInt aBlockSize, TInt aMode) |
565 TTimeIntervalMicroSeconds ReadAsyncTestFile(RFile& file, TDes16& aFile, TInt aSize, TInt aBlockSize, TInt aMode) |
573 { |
566 { |
574 TTime startTime; |
|
575 TTime endTime; |
|
576 TRequestStatus status[KWaitRequestsTableSize]; |
567 TRequestStatus status[KWaitRequestsTableSize]; |
577 |
568 TF32TestTimer timer; |
578 startTime.HomeTime(); |
569 timer.Start(); |
579 |
570 |
580 ReadFileAsync(gTheFs, file, aFile, aSize * KOneK, aBlockSize, status, aMode); |
571 ReadFileAsync(gTheFs, file, aFile, aSize * KOneK, aBlockSize, status, aMode); |
581 WaitForAll(status, (aSize * KOneK)/KBlockSize); |
572 WaitForAll(status, (aSize * KOneK)/KBlockSize); |
582 |
573 timer.Stop(); |
583 endTime.HomeTime(); |
574 |
584 |
575 gTimeTakenBigFile = timer.Time(); |
585 gTimeTakenBigFile = I64LOW(endTime.MicroSecondsFrom(startTime).Int64()); |
576 |
586 |
577 return timer.Time(); |
587 return I64LOW(gTimeTakenBigFile.Int64()); |
|
588 } |
578 } |
589 |
579 |
590 /** Read asynchronously the test file from the disc |
580 /** Read asynchronously the test file from the disc |
591 |
581 |
592 @param aFile File object |
582 @param aFile File object |
594 @param aSize Size in kilobytes |
584 @param aSize Size in kilobytes |
595 @param aMode Mode in which the file is going to be opened |
585 @param aMode Mode in which the file is going to be opened |
596 |
586 |
597 @return time taken to perform the operation in uS |
587 @return time taken to perform the operation in uS |
598 */ |
588 */ |
599 TInt WriteAsyncTestFile(RFile& aFile, TDes16& aFileName, TInt aSize, TInt aMode) |
589 TTimeIntervalMicroSeconds WriteAsyncTestFile(RFile& aFile, TDes16& aFileName, TInt aSize, TInt aMode) |
600 { |
590 { |
601 TTime startTime; |
|
602 TTime endTime; |
|
603 TRequestStatus status[KWaitRequestsTableSize]; |
591 TRequestStatus status[KWaitRequestsTableSize]; |
604 |
592 TF32TestTimer timer; |
605 startTime.HomeTime(); |
593 timer.Start(); |
606 |
594 |
607 WriteFileAsync(gTheFs, aFile, aFileName, aSize * KOneK, aMode, status ); |
595 WriteFileAsync(gTheFs, aFile, aFileName, aSize * KOneK, aMode, status ); |
608 WaitForAll(status, (aSize * KOneK)/KBlockSize); |
596 WaitForAll(status, (aSize * KOneK)/KBlockSize); |
609 |
597 timer.Stop(); |
610 endTime.HomeTime(); |
598 |
611 |
599 gTimeTakenBigFile = timer.Time(); |
612 gTimeTakenBigFile = I64LOW(endTime.MicroSecondsFrom(startTime).Int64()); |
600 |
613 |
601 return timer.Time(); |
614 return I64LOW(gTimeTakenBigFile.Int64()); |
|
615 } |
602 } |
616 |
603 |
617 /** Test Boundaries |
604 /** Test Boundaries |
618 |
605 |
619 This function is testing the behaviour on the boundaries of the write cache size |
606 This function is testing the behaviour on the boundaries of the write cache size |
620 */ |
607 */ |
621 void TestBoundaries() |
608 void TestBoundaries() |
622 { |
609 { |
623 TInt r = 0; |
610 TInt r = 0; |
624 TInt time = 0; |
611 TTimeIntervalMicroSeconds time = 0; |
625 TInt rtime = 0; |
612 TTimeIntervalMicroSeconds rtime = 0; |
626 TInt tcreate = 0; |
613 TTimeIntervalMicroSeconds tcreate = 0; |
627 RFile fileWriter; |
614 RFile fileWriter; |
628 RFile fileWriter2; |
615 RFile fileWriter2; |
629 RFile fileReader; |
616 RFile fileReader; |
630 |
617 |
631 test.Start(_L("Test Boundaries")); |
618 test.Start(_L("Test Boundaries")); |
639 while(i < KMaxSize) |
626 while(i < KMaxSize) |
640 { |
627 { |
641 test.Printf(_L("\nSync: Write from 1 K to %d K \n"), i); |
628 test.Printf(_L("\nSync: Write from 1 K to %d K \n"), i); |
642 |
629 |
643 tcreate = WriteTestFile(fileWriter, gSecondFile, i, KBlockSize, EFileShareAny|EFileWrite|EFileWriteDirectIO); |
630 tcreate = WriteTestFile(fileWriter, gSecondFile, i, KBlockSize, EFileShareAny|EFileWrite|EFileWriteDirectIO); |
644 test.Printf(_L("Time to write %d K without caching: %d mS\n"), i, tcreate/KMs); |
631 test.Printf(_L("Time to write %d K without caching: %d mS\n"), i, TF32TestTimer::TimeInMilliSeconds(tcreate)); |
645 fileWriter.Close(); |
632 fileWriter.Close(); |
646 |
633 |
647 time = WriteTestFile(fileWriter2, gFirstFile, i, KBlockSize, EFileShareAny|EFileWrite|EFileWriteBuffered); |
634 time = WriteTestFile(fileWriter2, gFirstFile, i, KBlockSize, EFileShareAny|EFileWrite|EFileWriteBuffered); |
648 test.Printf(_L("Time to write %d K WITH caching: %d mS\n"), i, time/KMs); |
635 test.Printf(_L("Time to write %d K WITH caching: %d mS\n"), i, TF32TestTimer::TimeInMilliSeconds(time)); |
649 |
636 |
650 rtime = ReadTestFile(fileReader, gFirstFile, i, KBlockSize, EFileShareAny|EFileRead|EFileReadBuffered); |
637 rtime = ReadTestFile(fileReader, gFirstFile, i, KBlockSize, EFileShareAny|EFileRead|EFileReadBuffered); |
651 test.Printf(_L("Time to read %d K from the cache: %d mS\n"), i, rtime/KMs); |
638 test.Printf(_L("Time to read %d K from the cache: %d mS\n"), i, TF32TestTimer::TimeInMilliSeconds(rtime)); |
652 |
|
653 |
639 |
654 fileReader.Close(); |
640 fileReader.Close(); |
655 fileWriter2.Close(); |
641 fileWriter2.Close(); |
656 |
642 |
657 #if !defined(__WINS__) |
643 #if !defined(__WINS__) |
658 test((tcreate > time) || (tcreate > rtime)); |
644 test(tcreate > TTimeIntervalMicroSeconds(0)); // test measured time is correct |
|
645 test(tcreate > time); |
|
646 test(tcreate > rtime); |
659 #endif |
647 #endif |
660 |
648 |
661 r = gTheFs.Delete(gFirstFile); |
649 r = gTheFs.Delete(gFirstFile); |
662 test_KErrNone(r); |
650 test_KErrNone(r); |
663 r = gTheFs.Delete(gSecondFile); |
651 r = gTheFs.Delete(gSecondFile); |
674 while(i < KMaxSize) |
662 while(i < KMaxSize) |
675 { |
663 { |
676 test.Printf(_L("\nAsync: Write from 1 K to %d K \n"), i); |
664 test.Printf(_L("\nAsync: Write from 1 K to %d K \n"), i); |
677 |
665 |
678 tcreate = WriteAsyncTestFile(fileWriter, gSecondFile, i, EFileShareAny|EFileWrite|EFileWriteDirectIO); |
666 tcreate = WriteAsyncTestFile(fileWriter, gSecondFile, i, EFileShareAny|EFileWrite|EFileWriteDirectIO); |
679 test.Printf(_L("Time to write %d K without caching: %d mS\n"), i, tcreate/KMs); |
667 test.Printf(_L("Time to write %d K without caching: %d mS\n"), i, TF32TestTimer::TimeInMilliSeconds(tcreate)); |
680 fileWriter.Close(); |
668 fileWriter.Close(); |
681 |
669 |
682 time = WriteAsyncTestFile(fileWriter2, gFirstFile, i,EFileShareAny|EFileWrite|EFileWriteBuffered); |
670 time = WriteAsyncTestFile(fileWriter2, gFirstFile, i,EFileShareAny|EFileWrite|EFileWriteBuffered); |
683 test.Printf(_L("Time to write %d K WITH caching: %d mS\n"), i, time/KMs); |
671 test.Printf(_L("Time to write %d K WITH caching: %d mS\n"), i, TF32TestTimer::TimeInMilliSeconds(time)); |
684 |
672 |
685 |
673 |
686 rtime = ReadAsyncTestFile(fileReader, gFirstFile, i, KBlockSize, EFileShareAny|EFileRead|EFileReadBuffered); |
674 rtime = ReadAsyncTestFile(fileReader, gFirstFile, i, KBlockSize, EFileShareAny|EFileRead|EFileReadBuffered); |
687 test.Printf(_L("Time to read %d K from the cache: %d mS\n"), i, rtime/KMs); |
675 test.Printf(_L("Time to read %d K from the cache: %d mS\n"), i, TF32TestTimer::TimeInMilliSeconds(rtime)); |
688 |
676 |
689 fileReader.Close(); |
677 fileReader.Close(); |
690 fileWriter2.Close(); |
678 fileWriter2.Close(); |
691 |
679 |
692 #if !defined(__WINS__) |
680 #if !defined(__WINS__) |
693 test((tcreate > time) || (tcreate > rtime)); |
681 test(tcreate > TTimeIntervalMicroSeconds(0)); // test measured time is correct |
|
682 test(tcreate > time); |
|
683 test(tcreate > rtime); |
694 #endif |
684 #endif |
695 |
685 |
696 r = gTheFs.Delete(gFirstFile); |
686 r = gTheFs.Delete(gFirstFile); |
697 test_KErrNone(r); |
687 test_KErrNone(r); |
698 r = gTheFs.Delete(gSecondFile); |
688 r = gTheFs.Delete(gSecondFile); |
747 |
737 |
748 @param aFile file name to verify |
738 @param aFile file name to verify |
749 |
739 |
750 @return returns the time that took to do the verification in mS, fails if the file is not corrupted/modified |
740 @return returns the time that took to do the verification in mS, fails if the file is not corrupted/modified |
751 */ |
741 */ |
752 TInt ReadTestFileVerif(TDes16& aFile) |
742 TTimeIntervalMicroSeconds ReadTestFileVerif(TDes16& aFile) |
753 { |
743 { |
754 TTime startTime; |
|
755 TTime endTime; |
|
756 TInt r = 0; |
744 TInt r = 0; |
757 TInt size = 0; |
745 TInt size = 0; |
758 RFile fileRead; |
746 RFile fileRead; |
759 TInt corrupt = 0; |
747 TInt corrupt = 0; |
760 TBool isFat=IsFSFAT(gTheFs,gDrive); |
748 TBool isFat=IsFSFAT(gTheFs,gDrive); |
761 |
749 |
762 startTime.HomeTime(); |
750 TF32TestTimer timer; |
|
751 timer.Start(); |
763 |
752 |
764 r = fileRead.Open(gTheFs,aFile,EFileShareAny|EFileRead|EFileReadBuffered|EFileReadAheadOff); |
753 r = fileRead.Open(gTheFs,aFile,EFileShareAny|EFileRead|EFileReadBuffered|EFileReadAheadOff); |
765 test_KErrNone(r); |
754 test_KErrNone(r); |
766 |
755 |
767 r = fileRead.Size(size); |
756 r = fileRead.Size(size); |
838 |
826 |
839 */ |
827 */ |
840 LOCAL_C void TestIntegrity() |
828 LOCAL_C void TestIntegrity() |
841 { |
829 { |
842 TInt r = 0; |
830 TInt r = 0; |
843 TInt time; |
831 TTimeIntervalMicroSeconds time; |
844 TInt tcreate = 0; |
832 TTimeIntervalMicroSeconds tcreate = 0; |
845 RFile file; |
833 RFile file; |
846 |
834 |
847 // Modify file in some position |
835 // Modify file in some position |
848 test.Printf(_L("Overwrite partially a file\n")); |
836 test.Printf(_L("Overwrite partially a file\n")); |
849 |
837 |
850 test.Printf(_L("\nSync: Write from 1 K to %d K \n"), 255); |
838 test.Printf(_L("\nSync: Write from 1 K to %d K \n"), 255); |
851 |
839 |
852 tcreate = WriteTestFile(file, gSecondFile, 255, KBlockSize, EFileShareAny|EFileWrite|EFileWriteBuffered); |
840 tcreate = WriteTestFile(file, gSecondFile, 255, KBlockSize, EFileShareAny|EFileWrite|EFileWriteBuffered); |
853 test.Printf(_L("Time to write %d K with caching: %d mS\n"), 255, tcreate/KMs); |
841 test.Printf(_L("Time to write %d K with caching: %d mS\n"), 255, TF32TestTimer::TimeInMilliSeconds(tcreate)); |
854 file.Close(); |
842 file.Close(); |
855 |
843 |
856 test.Printf(_L("Mess the content that is still in the cache\n")); |
844 test.Printf(_L("Mess the content that is still in the cache\n")); |
857 CorruptSecondFile(); |
845 CorruptSecondFile(); |
858 |
846 |
859 time = ReadTestFileVerif(gSecondFile); |
847 time = ReadTestFileVerif(gSecondFile); |
860 test.Printf(_L("Time taken to verify: %d\n"),time); |
848 test.Printf(_L("Time taken to verify: %ld\n"),time.Int64()); |
861 |
849 |
862 test.Printf(_L("Integrity verified\n")); |
850 test.Printf(_L("Integrity verified\n")); |
863 |
851 |
864 r = DeleteAllL(gSessionPath); |
852 r = DeleteAllL(gSessionPath); |
865 test_KErrNone(r); |
853 test_KErrNone(r); |
1225 |
1213 |
1226 |
1214 |
1227 test.Printf(_L("\nSync: Write from 1 K to 254 K \n")); |
1215 test.Printf(_L("\nSync: Write from 1 K to 254 K \n")); |
1228 |
1216 |
1229 time = WriteTestFile(file1, gSecondFile, KMinSize, KBlockSize, EFileShareAny|EFileWrite|EFileWriteBuffered); |
1217 time = WriteTestFile(file1, gSecondFile, KMinSize, KBlockSize, EFileShareAny|EFileWrite|EFileWriteBuffered); |
1230 test.Printf(_L("Time to write %d K WITH caching: %d mS\n"), KMinSize, time/KMs); |
1218 test.Printf(_L("Time to write %d K WITH caching: %d mS\n"), KMinSize, TF32TestTimer::TimeInMilliSeconds(time)); |
1231 test.Printf(_L("Remove MMC card,! and then press a key\n")); |
1219 test.Printf(_L("Remove MMC card,! and then press a key\n")); |
1232 test.Getch(); |
1220 test.Getch(); |
1233 |
1221 |
1234 test.Printf(_L("Wait 3 seconds and insert MMC card! and then press a key\n")); |
1222 test.Printf(_L("Wait 3 seconds and insert MMC card! and then press a key\n")); |
1235 test.Getch(); |
1223 test.Getch(); |
1236 |
1224 |
1237 rtime = ReadTestFile(file2, gSecondFile, KMinSize, KBlockSize, EFileShareAny|EFileRead|EFileReadBuffered); |
1225 rtime = ReadTestFile(file2, gSecondFile, KMinSize, KBlockSize, EFileShareAny|EFileRead|EFileReadBuffered); |
1238 test.Printf(_L("Time to read %d K from the cache: %d mS\n"), KMinSize, rtime/KMs); |
1226 test.Printf(_L("Time to read %d K from the cache: %d mS\n"), KMinSize, TF32TestTimer::TimeInMilliSeconds(rtime)); |
1239 |
1227 |
1240 test.Printf(_L("Remove MMC card! and then press a key\n")); |
1228 test.Printf(_L("Remove MMC card! and then press a key\n")); |
1241 test.Getch(); |
1229 test.Getch(); |
1242 |
1230 |
1243 test.Printf(_L("Wait 3 seconds and insert MMC card! and then press a key\n")); |
1231 test.Printf(_L("Wait 3 seconds and insert MMC card! and then press a key\n")); |
1245 |
1233 |
1246 |
1234 |
1247 test.Printf(_L("\nSync: Write from 1 K to 255 K \n")); |
1235 test.Printf(_L("\nSync: Write from 1 K to 255 K \n")); |
1248 |
1236 |
1249 time = WriteTestFile(file1, gFirstFile, KMinSize + 1 , KBlockSize, EFileShareAny|EFileWrite|EFileWriteBuffered); |
1237 time = WriteTestFile(file1, gFirstFile, KMinSize + 1 , KBlockSize, EFileShareAny|EFileWrite|EFileWriteBuffered); |
1250 test.Printf(_L("Time to write %d K WITH caching: %d mS\n"), KMinSize + 1, time/KMs); |
1238 test.Printf(_L("Time to write %d K WITH caching: %d mS\n"), KMinSize + 1, TF32TestTimer::TimeInMilliSeconds(time)); |
1251 test.Printf(_L("Remove MMC card and delete the file //F32-TST//FFFFFFF0.TXT and then press a key\n")); |
1239 test.Printf(_L("Remove MMC card and delete the file //F32-TST//FFFFFFF0.TXT and then press a key\n")); |
1252 test.Getch(); |
1240 test.Getch(); |
1253 |
1241 |
1254 test.Printf(_L("Wait 3 seconds and insert MMC card! and then press a key\n")); |
1242 test.Printf(_L("Wait 3 seconds and insert MMC card! and then press a key\n")); |
1255 test.Getch(); |
1243 test.Getch(); |
1256 |
1244 |
1257 rtime = ReadTestFile(file2, gFirstFile, KMinSize + 1, KBlockSize, EFileShareAny|EFileRead|EFileReadBuffered); |
1245 rtime = ReadTestFile(file2, gFirstFile, KMinSize + 1, KBlockSize, EFileShareAny|EFileRead|EFileReadBuffered); |
1258 test.Printf(_L("Time to read %d K from the cache: %d mS\n"), KMinSize + 1, rtime/KMs); |
1246 test.Printf(_L("Time to read %d K from the cache: %d mS\n"), KMinSize + 1, TF32TestTimer::TimeInMilliSeconds(rtime)); |
1259 |
1247 |
1260 test.Printf(_L("Remove MMC card! and then press a key\n")); |
1248 test.Printf(_L("Remove MMC card! and then press a key\n")); |
1261 test.Getch(); |
1249 test.Getch(); |
1262 |
1250 |
1263 test.Printf(_L("Wait 3 seconds and insert MMC card! and then press a key\n")); |
1251 test.Printf(_L("Wait 3 seconds and insert MMC card! and then press a key\n")); |