112 } |
113 } |
113 |
114 |
114 void PrintFileCacheConfig(TFileCacheConfig& aFileCacheConfig, TBool aDisplay = ETrue) |
115 void PrintFileCacheConfig(TFileCacheConfig& aFileCacheConfig, TBool aDisplay = ETrue) |
115 { |
116 { |
116 TInt r = controlIo(TheFs,gDrive, KControlIoFileCacheConfig, aFileCacheConfig); |
117 TInt r = controlIo(TheFs,gDrive, KControlIoFileCacheConfig, aFileCacheConfig); |
117 test (r == KErrNone); |
118 test_KErrNone(r); |
118 if (!aDisplay) |
119 if (!aDisplay) |
119 return; |
120 return; |
120 |
121 |
121 test.Printf(_L("File cache:\nDrive %c\nFlags %08X\nFileCacheReadAsync %d\nFairSchedulingLen %d\nCacheSize %d\nMaxReadAheadLen %d\nClosedFileKeepAliveTime %d\nDirtyDataFlushTime %d"), |
122 test.Printf(_L("File cache:\nDrive %c\nFlags %08X\nFileCacheReadAsync %d\nFairSchedulingLen %d\nCacheSize %d\nMaxReadAheadLen %d\nClosedFileKeepAliveTime %d\nDirtyDataFlushTime %d"), |
122 aFileCacheConfig.iDrive + 'A', |
123 aFileCacheConfig.iDrive + 'A', |
248 TestBufferFail(aBuffer, pos, aLength); |
249 TestBufferFail(aBuffer, pos, aLength); |
249 } |
250 } |
250 } |
251 } |
251 } |
252 } |
252 |
253 |
|
254 //*test************************************************************************** |
|
255 TInt FreeRam() |
|
256 { |
|
257 // wait for any async cleanup in the supervisor to finish first... |
|
258 UserSvr::HalFunction(EHalGroupKernel, EKernelHalSupervisorBarrier, 0, 0); |
|
259 |
|
260 TMemoryInfoV1Buf meminfo; |
|
261 UserHal::MemoryInfo(meminfo); |
|
262 return meminfo().iFreeRamInBytes; |
|
263 } |
|
264 //*test************************************************************************** |
|
265 |
253 |
266 |
254 LOCAL_C void UnitTests() |
267 LOCAL_C void UnitTests() |
255 // |
268 // |
256 // Test read file handling. |
269 // Test read file handling. |
257 // |
270 // |
269 |
282 |
270 #if defined(_DEBUG) || defined(_DEBUG_RELEASE) |
283 #if defined(_DEBUG) || defined(_DEBUG_RELEASE) |
271 TBool simulatelockFailureMode; |
284 TBool simulatelockFailureMode; |
272 TFileCacheStats fileCacheStats; |
285 TFileCacheStats fileCacheStats; |
273 r = controlIo(TheFs, gDrive, KControlIoFileCacheStats, fileCacheStats); |
286 r = controlIo(TheFs, gDrive, KControlIoFileCacheStats, fileCacheStats); |
274 test (r == KErrNone); |
287 test_KErrNone(r); |
275 test.Printf(_L("Number of files on closed queue=%d\n"),fileCacheStats.iFilesOnClosedQueue); |
288 test.Printf(_L("Number of files on closed queue=%d\n"),fileCacheStats.iFilesOnClosedQueue); |
276 test(fileCacheStats.iFilesOnClosedQueue == 0); |
289 test(fileCacheStats.iFilesOnClosedQueue == 0); |
277 #endif |
290 #endif |
278 |
291 |
279 #if defined(_DEBUG) || defined(_DEBUG_RELEASE) |
292 #if defined(_DEBUG) || defined(_DEBUG_RELEASE) |
280 // turn OFF lock failure mode |
293 // turn OFF lock failure mode |
281 simulatelockFailureMode = EFalse; |
294 simulatelockFailureMode = EFalse; |
282 r = controlIo(TheFs, gDrive, KControlIoSimulateLockFailureMode, simulatelockFailureMode); |
295 r = controlIo(TheFs, gDrive, KControlIoSimulateLockFailureMode, simulatelockFailureMode); |
283 test (r == KErrNone); |
296 test_KErrNone(r); |
284 #endif |
297 #endif |
285 |
298 |
286 TFileName testFile = _L("TEST.BIN"); |
299 TFileName testFile = _L("TEST.BIN"); |
287 |
300 |
288 //********************************** |
301 //********************************** |
296 TPtr8 readPtr(gBuf->Des()); |
309 TPtr8 readPtr(gBuf->Des()); |
297 #if defined(_DEBUG) || defined(_DEBUG_RELEASE) |
310 #if defined(_DEBUG) || defined(_DEBUG_RELEASE) |
298 TInt uncachedBytesRead; |
311 TInt uncachedBytesRead; |
299 TInt uncachedPacketsRead; |
312 TInt uncachedPacketsRead; |
300 #endif |
313 #endif |
|
314 |
|
315 //*test************************************************************************** |
|
316 { |
|
317 TInt fileSize = 0; |
|
318 |
|
319 const TInt KWriteLen = 128*1024; |
|
320 test.Next(_L("Test appending to a file with low memory")); |
|
321 gBufPtr.SetLength(KBufSize); |
|
322 |
|
323 r = f.Replace(TheFs, testFile, EFileWrite | EFileWriteBuffered); |
|
324 test_KErrNone(r); |
|
325 |
|
326 pos = 0; |
|
327 |
|
328 writePtr.Set(gBufPtr.MidTPtr(pos, KWriteLen)); |
|
329 |
|
330 r = f.Write(pos, writePtr); |
|
331 test_KErrNone(r); |
|
332 pos+= writePtr.Length(); |
|
333 |
|
334 r = f.Size(fileSize); |
|
335 test_KErrNone(r); |
|
336 test_Equal(fileSize,pos); |
|
337 |
|
338 |
|
339 |
|
340 TInt freeRam = FreeRam(); |
|
341 test.Printf(_L("FreeRam = %d"), freeRam); |
|
342 const TInt KPageSize=4096; |
|
343 |
|
344 RChunk chunk; |
|
345 TChunkCreateInfo chunkInfo; |
|
346 chunkInfo.SetDisconnected(0, 0, freeRam); |
|
347 chunkInfo.SetPaging(TChunkCreateInfo::EUnpaged); |
|
348 test_KErrNone(chunk.Create(chunkInfo)); |
|
349 |
|
350 TUint commitEnd = 0; |
|
351 TInt r; |
|
352 while(KErrNone == (r = chunk.Commit(commitEnd,KPageSize))) |
|
353 { |
|
354 commitEnd += KPageSize; |
|
355 } |
|
356 test_Equal(KErrNoMemory, r); |
|
357 |
|
358 |
|
359 |
|
360 pos-= KSegmentSize; |
|
361 writePtr.Set(gBufPtr.MidTPtr(pos, KWriteLen)); |
|
362 |
|
363 r = f.Write(pos, writePtr); |
|
364 test_KErrNone(r); |
|
365 pos+= writePtr.Length(); |
|
366 |
|
367 r = f.Size(fileSize); |
|
368 test_KErrNone(r); |
|
369 test_Equal(fileSize,pos); |
|
370 |
|
371 f.Close(); |
|
372 |
|
373 chunk.Close(); |
|
374 } |
|
375 //*test************************************************************************** |
301 |
376 |
302 // create an empty file, so that any writes overlapping segemt boundaries |
377 // create an empty file, so that any writes overlapping segemt boundaries |
303 // need a read first |
378 // need a read first |
304 // create a test file using directIO and then re-open it in buffered mode, |
379 // create a test file using directIO and then re-open it in buffered mode, |
305 // so that any writes overlapping segemt boundaries need a read first |
380 // so that any writes overlapping segemt boundaries need a read first |
616 r = f.Open(TheFs, testFile, EFileRead | EFileReadBuffered | EFileWrite); |
691 r = f.Open(TheFs, testFile, EFileRead | EFileReadBuffered | EFileWrite); |
617 test_KErrNone(r); |
692 test_KErrNone(r); |
618 |
693 |
619 TInt size; |
694 TInt size; |
620 r = f.Size(size); |
695 r = f.Size(size); |
621 test (r == KErrNone); |
696 test_KErrNone(r); |
622 test (size = KBufSize); |
697 test (size = KBufSize); |
623 |
698 |
624 readPtr.Set(gBuf->Des()); |
699 readPtr.Set(gBuf->Des()); |
625 |
700 |
626 #if defined(_DEBUG) || defined(_DEBUG_RELEASE) |
701 #if defined(_DEBUG) || defined(_DEBUG_RELEASE) |
627 // Allocate full cachelines - so we can enable hole testing |
702 // Allocate full cachelines - so we can enable hole testing |
628 TBool allocateAllSegmentsInCacheLine = ETrue; |
703 TBool allocateAllSegmentsInCacheLine = ETrue; |
629 r = controlIo(TheFs, gDrive, KControlIoAllocateMaxSegments, allocateAllSegmentsInCacheLine); |
704 r = controlIo(TheFs, gDrive, KControlIoAllocateMaxSegments, allocateAllSegmentsInCacheLine); |
630 test (r == KErrNone); |
705 test_KErrNone(r); |
631 PrintFileCacheStats(fileCacheStats, EFalse); |
706 PrintFileCacheStats(fileCacheStats, EFalse); |
632 TInt holesDetected = fileCacheStats.iHoleCount; |
707 TInt holesDetected = fileCacheStats.iHoleCount; |
633 TInt lockFailures = fileCacheStats.iCommitFailureCount + fileCacheStats.iLockFailureCount; |
708 TInt lockFailures = fileCacheStats.iCommitFailureCount + fileCacheStats.iLockFailureCount; |
634 #endif |
709 #endif |
635 |
710 |
710 test(fileCacheStats.iHoleCount > holesDetected); |
785 test(fileCacheStats.iHoleCount > holesDetected); |
711 } |
786 } |
712 // Don't allocate full cachelines any more |
787 // Don't allocate full cachelines any more |
713 allocateAllSegmentsInCacheLine = EFalse; |
788 allocateAllSegmentsInCacheLine = EFalse; |
714 r = controlIo(TheFs, gDrive, KControlIoAllocateMaxSegments, allocateAllSegmentsInCacheLine); |
789 r = controlIo(TheFs, gDrive, KControlIoAllocateMaxSegments, allocateAllSegmentsInCacheLine); |
715 test (r == KErrNone); |
790 test_KErrNone(r); |
716 #endif |
791 #endif |
717 |
792 |
718 |
793 |
719 |
794 |
720 gBufPtr.FillZ(); |
795 gBufPtr.FillZ(); |
810 f.Close(); |
885 f.Close(); |
811 |
886 |
812 |
887 |
813 #if defined(_DEBUG) || defined(_DEBUG_RELEASE) |
888 #if defined(_DEBUG) || defined(_DEBUG_RELEASE) |
814 r = controlIo(TheFs, gDrive, KControlIoFileCacheStats, fileCacheStats); |
889 r = controlIo(TheFs, gDrive, KControlIoFileCacheStats, fileCacheStats); |
815 test (r == KErrNone); |
890 test_KErrNone(r); |
816 test.Printf(_L("Number of files on closed queue=%d\n"),fileCacheStats.iFilesOnClosedQueue); |
891 test.Printf(_L("Number of files on closed queue=%d\n"),fileCacheStats.iFilesOnClosedQueue); |
817 test(fileCacheStats.iFilesOnClosedQueue == 1); |
892 test(fileCacheStats.iFilesOnClosedQueue == 1); |
818 #endif |
893 #endif |
819 // |
894 // |
820 |
895 |
844 TestBuffer(gBufPtr, pos, len); |
919 TestBuffer(gBufPtr, pos, len); |
845 test_KErrNone(r); |
920 test_KErrNone(r); |
846 |
921 |
847 #if defined(_DEBUG) || defined(_DEBUG_RELEASE) |
922 #if defined(_DEBUG) || defined(_DEBUG_RELEASE) |
848 r = controlIo(TheFs, gDrive, KControlIoFileCacheStats, fileCacheStats); |
923 r = controlIo(TheFs, gDrive, KControlIoFileCacheStats, fileCacheStats); |
849 test (r == KErrNone); |
924 test_KErrNone(r); |
850 test.Printf(_L("Number of files on closed queue=%d\n"),fileCacheStats.iFilesOnClosedQueue); |
925 test.Printf(_L("Number of files on closed queue=%d\n"),fileCacheStats.iFilesOnClosedQueue); |
851 test(fileCacheStats.iFilesOnClosedQueue == 0); |
926 test(fileCacheStats.iFilesOnClosedQueue == 0); |
852 #endif |
927 #endif |
853 f.Close(); |
928 f.Close(); |
854 |
929 |
855 test.Next(_L("close & verify file is back on close queue")); |
930 test.Next(_L("close & verify file is back on close queue")); |
856 |
931 |
857 |
932 |
858 #if defined(_DEBUG) || defined(_DEBUG_RELEASE) |
933 #if defined(_DEBUG) || defined(_DEBUG_RELEASE) |
859 r = controlIo(TheFs, gDrive, KControlIoFileCacheStats, fileCacheStats); |
934 r = controlIo(TheFs, gDrive, KControlIoFileCacheStats, fileCacheStats); |
860 test (r == KErrNone); |
935 test_KErrNone(r); |
861 test.Printf(_L("Number of files on closed queue=%d\n"),fileCacheStats.iFilesOnClosedQueue); |
936 test.Printf(_L("Number of files on closed queue=%d\n"),fileCacheStats.iFilesOnClosedQueue); |
862 test(fileCacheStats.iFilesOnClosedQueue == 1); |
937 test(fileCacheStats.iFilesOnClosedQueue == 1); |
863 #endif |
938 #endif |
864 |
939 |
865 if (testNum == ETestCloseQueueEmptyAfterDelete) |
940 if (testNum == ETestCloseQueueEmptyAfterDelete) |
884 f.Close(); |
959 f.Close(); |
885 } |
960 } |
886 |
961 |
887 #if defined(_DEBUG) || defined(_DEBUG_RELEASE) |
962 #if defined(_DEBUG) || defined(_DEBUG_RELEASE) |
888 r = controlIo(TheFs, gDrive, KControlIoFileCacheStats, fileCacheStats); |
963 r = controlIo(TheFs, gDrive, KControlIoFileCacheStats, fileCacheStats); |
889 test (r == KErrNone); |
964 test_KErrNone(r); |
890 test.Printf(_L("Number of files on closed queue=%d\n"),fileCacheStats.iFilesOnClosedQueue); |
965 test.Printf(_L("Number of files on closed queue=%d\n"),fileCacheStats.iFilesOnClosedQueue); |
891 test(fileCacheStats.iFilesOnClosedQueue == 0); |
966 test(fileCacheStats.iFilesOnClosedQueue == 0); |
892 #endif |
967 #endif |
893 } |
968 } |
894 |
969 |
895 #if defined(_DEBUG) || defined(_DEBUG_RELEASE) |
970 #if defined(_DEBUG) || defined(_DEBUG_RELEASE) |
896 // turn lock failure mode back ON (if enabled) |
971 // turn lock failure mode back ON (if enabled) |
897 simulatelockFailureMode = ETrue; |
972 simulatelockFailureMode = ETrue; |
898 r = controlIo(TheFs, gDrive, KControlIoSimulateLockFailureMode, simulatelockFailureMode); |
973 r = controlIo(TheFs, gDrive, KControlIoSimulateLockFailureMode, simulatelockFailureMode); |
899 test (r == KErrNone); |
974 test_KErrNone(r); |
900 #endif |
975 #endif |
901 |
976 |
902 //************************************************************** |
977 //************************************************************** |
903 // Test opening a file with a silly open mode flags combinations |
978 // Test opening a file with a silly open mode flags combinations |
904 //************************************************************** |
979 //************************************************************** |
920 const TInt KWriteLen = KSegmentSize+1; |
995 const TInt KWriteLen = KSegmentSize+1; |
921 writePtr.Set(gBuf->Des().Ptr(), KWriteLen); |
996 writePtr.Set(gBuf->Des().Ptr(), KWriteLen); |
922 |
997 |
923 #if defined(_DEBUG) || defined(_DEBUG_RELEASE) |
998 #if defined(_DEBUG) || defined(_DEBUG_RELEASE) |
924 r = controlIo(TheFs, gDrive, KControlIoFileCacheStats, fileCacheStats); |
999 r = controlIo(TheFs, gDrive, KControlIoFileCacheStats, fileCacheStats); |
925 test (r == KErrNone); |
1000 test_KErrNone(r); |
926 test.Printf(_L("Number of Write-throughs with dirty data=%d\n"),fileCacheStats.iWriteThroughWithDirtyDataCount); |
1001 test.Printf(_L("Number of Write-throughs with dirty data=%d\n"),fileCacheStats.iWriteThroughWithDirtyDataCount); |
927 TInt writeThroughWithDirtyDataCountOld = fileCacheStats.iWriteThroughWithDirtyDataCount; |
1002 TInt writeThroughWithDirtyDataCountOld = fileCacheStats.iWriteThroughWithDirtyDataCount; |
928 TInt writeThroughWithDirtyDataCountNew = writeThroughWithDirtyDataCountOld; |
1003 TInt writeThroughWithDirtyDataCountNew = writeThroughWithDirtyDataCountOld; |
929 #endif |
1004 #endif |
930 |
1005 |
931 TInt fileSize = 0; |
1006 TInt fileSize = 0; |
932 for (TInt i=0; i<4; i++) |
1007 for (TInt i=0; i<4; i++) |
933 { |
1008 { |
934 fileSize = 0; |
1009 fileSize = 0; |
935 r = f.SetSize(fileSize); |
1010 r = f.SetSize(fileSize); |
936 test (r == KErrNone); |
1011 test_KErrNone(r); |
937 for (pos = 0; pos < KMaxFileSize; ) |
1012 for (pos = 0; pos < KMaxFileSize; ) |
938 { |
1013 { |
939 r = f.Write(pos, writePtr); |
1014 r = f.Write(pos, writePtr); |
940 if (r != KErrNone) |
1015 if (r != KErrNone) |
941 { |
1016 { |
942 test.Printf(_L("Iter #%d, write pos %d size %d, Write() returned %d"), i, pos, fileSize, r); |
1017 test.Printf(_L("Iter #%d, write pos %d size %d, Write() returned %d"), i, pos, fileSize, r); |
943 r = f.Flush(); |
1018 r = f.Flush(); |
944 test.Printf(_L("Flush returned %d"), r); |
1019 test.Printf(_L("Flush returned %d"), r); |
945 test(0); |
1020 test(0); |
946 } |
1021 } |
947 test(r == KErrNone); |
1022 test_KErrNone(r); |
948 pos+= writePtr.Length(); |
1023 pos+= writePtr.Length(); |
949 |
1024 |
950 r = f.Size(fileSize); |
1025 r = f.Size(fileSize); |
951 test (r == KErrNone); |
1026 test_KErrNone(r); |
952 if (fileSize != pos) |
1027 if (fileSize != pos) |
953 { |
1028 { |
954 test.Printf(_L("Iter #%d, write pos %d != size %d"), i, pos, fileSize); |
1029 test.Printf(_L("Iter #%d, write pos %d != size %d"), i, pos, fileSize); |
955 r = f.Flush(); |
1030 r = f.Flush(); |
956 test.Printf(_L("Flush returned %d"), r); |
1031 test.Printf(_L("Flush returned %d"), r); |
958 } |
1033 } |
959 test (fileSize == pos); |
1034 test (fileSize == pos); |
960 |
1035 |
961 #if defined(_DEBUG) || defined(_DEBUG_RELEASE) |
1036 #if defined(_DEBUG) || defined(_DEBUG_RELEASE) |
962 r = controlIo(TheFs, gDrive, KControlIoFileCacheStats, fileCacheStats); |
1037 r = controlIo(TheFs, gDrive, KControlIoFileCacheStats, fileCacheStats); |
963 test (r == KErrNone); |
1038 test_KErrNone(r); |
964 writeThroughWithDirtyDataCountNew = fileCacheStats.iWriteThroughWithDirtyDataCount; |
1039 writeThroughWithDirtyDataCountNew = fileCacheStats.iWriteThroughWithDirtyDataCount; |
965 if (writeThroughWithDirtyDataCountNew > writeThroughWithDirtyDataCountOld) |
1040 if (writeThroughWithDirtyDataCountNew > writeThroughWithDirtyDataCountOld) |
966 { |
1041 { |
967 test.Printf(_L("Iter #%d, write pos %d size %d"), i, pos, fileSize); |
1042 test.Printf(_L("Iter #%d, write pos %d size %d"), i, pos, fileSize); |
968 test.Printf(_L("Number of Write-throughs with dirty data=%d\n"),fileCacheStats.iWriteThroughWithDirtyDataCount); |
1043 test.Printf(_L("Number of Write-throughs with dirty data=%d\n"),fileCacheStats.iWriteThroughWithDirtyDataCount); |
1633 { |
1708 { |
1634 #if defined(_DEBUG) || defined(_DEBUG_RELEASE) |
1709 #if defined(_DEBUG) || defined(_DEBUG_RELEASE) |
1635 // turn OFF lock failure mode |
1710 // turn OFF lock failure mode |
1636 TBool simulatelockFailureMode = EFalse; |
1711 TBool simulatelockFailureMode = EFalse; |
1637 r = controlIo(TheFs, gDrive, KControlIoSimulateLockFailureMode, simulatelockFailureMode); |
1712 r = controlIo(TheFs, gDrive, KControlIoSimulateLockFailureMode, simulatelockFailureMode); |
1638 test (r == KErrNone); |
1713 test_KErrNone(r); |
1639 #endif |
1714 #endif |
1640 |
1715 |
1641 TestFileRead(EFileReadDirectIO); |
1716 TestFileRead(EFileReadDirectIO); |
1642 if (gDriveCacheFlags & (EFileCacheReadEnabled | EFileCacheReadOn)) |
1717 if (gDriveCacheFlags & (EFileCacheReadEnabled | EFileCacheReadOn)) |
1643 { |
1718 { |
1653 |
1728 |
1654 #if defined(_DEBUG) || defined(_DEBUG_RELEASE) |
1729 #if defined(_DEBUG) || defined(_DEBUG_RELEASE) |
1655 // turn lock failure mode back ON (if enabled) |
1730 // turn lock failure mode back ON (if enabled) |
1656 simulatelockFailureMode = ETrue; |
1731 simulatelockFailureMode = ETrue; |
1657 r = controlIo(TheFs, gDrive, KControlIoSimulateLockFailureMode, simulatelockFailureMode); |
1732 r = controlIo(TheFs, gDrive, KControlIoSimulateLockFailureMode, simulatelockFailureMode); |
1658 test (r == KErrNone); |
1733 test_KErrNone(r); |
1659 #endif |
1734 #endif |
1660 } // if (gRunPerformanceTests) |
1735 } // if (gRunPerformanceTests) |
1661 |
1736 |
1662 TestsEnd(); |
1737 TestsEnd(); |
1663 } |
1738 } |
1777 |
1852 |
1778 if (gWriteCacheFlags) |
1853 if (gWriteCacheFlags) |
1779 { |
1854 { |
1780 test.Printf(_L("Writing DriveCacheFlags for drive %C = %08X\n"), (TInt) gDriveToTest, gDriveCacheFlags); |
1855 test.Printf(_L("Writing DriveCacheFlags for drive %C = %08X\n"), (TInt) gDriveToTest, gDriveCacheFlags); |
1781 r = controlIo(TheFs,gDrive, KControlIoFileCacheFlagsWrite, gDriveCacheFlags); |
1856 r = controlIo(TheFs,gDrive, KControlIoFileCacheFlagsWrite, gDriveCacheFlags); |
1782 test (r == KErrNone); |
1857 test_KErrNone(r); |
1783 } |
1858 } |
1784 #endif |
1859 #endif |
1785 |
1860 |
1786 if (gRunTests) |
1861 if (gRunTests) |
1787 { |
1862 { |