kerneltest/f32test/server/t_filecache.cpp
changeset 109 b3a1d9898418
parent 0 a41df078684a
child 139 95f71bcdcdb7
equal deleted inserted replaced
102:ef2a444a7410 109:b3a1d9898418
   112 	}
   112 	}
   113 
   113 
   114 void PrintFileCacheConfig(TFileCacheConfig& aFileCacheConfig, TBool aDisplay = ETrue)
   114 void PrintFileCacheConfig(TFileCacheConfig& aFileCacheConfig, TBool aDisplay = ETrue)
   115 	{
   115 	{
   116 	TInt r = controlIo(TheFs,gDrive, KControlIoFileCacheConfig, aFileCacheConfig);
   116 	TInt r = controlIo(TheFs,gDrive, KControlIoFileCacheConfig, aFileCacheConfig);
   117 	test (r == KErrNone);
   117 	test_KErrNone(r);
   118 	if (!aDisplay)
   118 	if (!aDisplay)
   119 		return;
   119 		return;
   120 	
   120 	
   121 	test.Printf(_L("File cache:\nDrive %c\nFlags %08X\nFileCacheReadAsync %d\nFairSchedulingLen %d\nCacheSize %d\nMaxReadAheadLen %d\nClosedFileKeepAliveTime %d\nDirtyDataFlushTime %d"), 
   121 	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',
   122 		aFileCacheConfig.iDrive + 'A',
   269 
   269 
   270 #if defined(_DEBUG) || defined(_DEBUG_RELEASE)
   270 #if defined(_DEBUG) || defined(_DEBUG_RELEASE)
   271 	TBool simulatelockFailureMode;
   271 	TBool simulatelockFailureMode;
   272 	TFileCacheStats fileCacheStats;
   272 	TFileCacheStats fileCacheStats;
   273 	r = controlIo(TheFs, gDrive, KControlIoFileCacheStats, fileCacheStats);
   273 	r = controlIo(TheFs, gDrive, KControlIoFileCacheStats, fileCacheStats);
   274 	test (r == KErrNone);
   274 	test_KErrNone(r);
   275 	test.Printf(_L("Number of files on closed queue=%d\n"),fileCacheStats.iFilesOnClosedQueue);
   275 	test.Printf(_L("Number of files on closed queue=%d\n"),fileCacheStats.iFilesOnClosedQueue);
   276 	test(fileCacheStats.iFilesOnClosedQueue == 0);
   276 	test(fileCacheStats.iFilesOnClosedQueue == 0);
   277 #endif
   277 #endif
   278 
   278 
   279 #if defined(_DEBUG) || defined(_DEBUG_RELEASE)
   279 #if defined(_DEBUG) || defined(_DEBUG_RELEASE)
   280 	// turn OFF lock failure mode 
   280 	// turn OFF lock failure mode 
   281 	simulatelockFailureMode = EFalse;
   281 	simulatelockFailureMode = EFalse;
   282 	r = controlIo(TheFs, gDrive, KControlIoSimulateLockFailureMode, simulatelockFailureMode);
   282 	r = controlIo(TheFs, gDrive, KControlIoSimulateLockFailureMode, simulatelockFailureMode);
   283 	test (r == KErrNone);
   283 	test_KErrNone(r);
   284 #endif
   284 #endif
   285 
   285 
   286 	TFileName testFile   = _L("TEST.BIN");
   286 	TFileName testFile   = _L("TEST.BIN");
   287 
   287 
   288 	//**********************************
   288 	//**********************************
   616 	r = f.Open(TheFs, testFile, EFileRead | EFileReadBuffered | EFileWrite);
   616 	r = f.Open(TheFs, testFile, EFileRead | EFileReadBuffered | EFileWrite);
   617 	test_KErrNone(r);
   617 	test_KErrNone(r);
   618 
   618 
   619 	TInt size;
   619 	TInt size;
   620 	r = f.Size(size);
   620 	r = f.Size(size);
   621 	test (r == KErrNone);
   621 	test_KErrNone(r);
   622 	test (size = KBufSize);
   622 	test (size = KBufSize);
   623 
   623 
   624 	readPtr.Set(gBuf->Des());
   624 	readPtr.Set(gBuf->Des());
   625 
   625 
   626 #if defined(_DEBUG) || defined(_DEBUG_RELEASE)
   626 #if defined(_DEBUG) || defined(_DEBUG_RELEASE)
   627 	// Allocate full cachelines - so we can enable hole testing
   627 	// Allocate full cachelines - so we can enable hole testing
   628 	TBool allocateAllSegmentsInCacheLine = ETrue;
   628 	TBool allocateAllSegmentsInCacheLine = ETrue;
   629 	r = controlIo(TheFs, gDrive, KControlIoAllocateMaxSegments, allocateAllSegmentsInCacheLine);
   629 	r = controlIo(TheFs, gDrive, KControlIoAllocateMaxSegments, allocateAllSegmentsInCacheLine);
   630 	test (r == KErrNone);
   630 	test_KErrNone(r);
   631 	PrintFileCacheStats(fileCacheStats, EFalse);
   631 	PrintFileCacheStats(fileCacheStats, EFalse);
   632 	TInt holesDetected = fileCacheStats.iHoleCount;
   632 	TInt holesDetected = fileCacheStats.iHoleCount;
   633 	TInt lockFailures = fileCacheStats.iCommitFailureCount + fileCacheStats.iLockFailureCount;
   633 	TInt lockFailures = fileCacheStats.iCommitFailureCount + fileCacheStats.iLockFailureCount;
   634 #endif
   634 #endif
   635 
   635 
   710 		test(fileCacheStats.iHoleCount > holesDetected);
   710 		test(fileCacheStats.iHoleCount > holesDetected);
   711 		}
   711 		}
   712 	// Don't allocate full cachelines any more
   712 	// Don't allocate full cachelines any more
   713 	allocateAllSegmentsInCacheLine = EFalse;
   713 	allocateAllSegmentsInCacheLine = EFalse;
   714 	r = controlIo(TheFs, gDrive, KControlIoAllocateMaxSegments, allocateAllSegmentsInCacheLine);
   714 	r = controlIo(TheFs, gDrive, KControlIoAllocateMaxSegments, allocateAllSegmentsInCacheLine);
   715 	test (r == KErrNone);
   715 	test_KErrNone(r);
   716 #endif
   716 #endif
   717 
   717 
   718 
   718 
   719 
   719 
   720 	gBufPtr.FillZ();
   720 	gBufPtr.FillZ();
   810 	f.Close();
   810 	f.Close();
   811 
   811 
   812 
   812 
   813 #if defined(_DEBUG) || defined(_DEBUG_RELEASE)
   813 #if defined(_DEBUG) || defined(_DEBUG_RELEASE)
   814 	r = controlIo(TheFs, gDrive, KControlIoFileCacheStats, fileCacheStats);
   814 	r = controlIo(TheFs, gDrive, KControlIoFileCacheStats, fileCacheStats);
   815 	test (r == KErrNone);
   815 	test_KErrNone(r);
   816 	test.Printf(_L("Number of files on closed queue=%d\n"),fileCacheStats.iFilesOnClosedQueue);
   816 	test.Printf(_L("Number of files on closed queue=%d\n"),fileCacheStats.iFilesOnClosedQueue);
   817 	test(fileCacheStats.iFilesOnClosedQueue == 1);
   817 	test(fileCacheStats.iFilesOnClosedQueue == 1);
   818 #endif
   818 #endif
   819 	//
   819 	//
   820 
   820 
   844 		TestBuffer(gBufPtr, pos, len);
   844 		TestBuffer(gBufPtr, pos, len);
   845 		test_KErrNone(r);
   845 		test_KErrNone(r);
   846 
   846 
   847 #if defined(_DEBUG) || defined(_DEBUG_RELEASE)
   847 #if defined(_DEBUG) || defined(_DEBUG_RELEASE)
   848 		r = controlIo(TheFs, gDrive, KControlIoFileCacheStats, fileCacheStats);
   848 		r = controlIo(TheFs, gDrive, KControlIoFileCacheStats, fileCacheStats);
   849 		test (r == KErrNone);
   849 		test_KErrNone(r);
   850 		test.Printf(_L("Number of files on closed queue=%d\n"),fileCacheStats.iFilesOnClosedQueue);
   850 		test.Printf(_L("Number of files on closed queue=%d\n"),fileCacheStats.iFilesOnClosedQueue);
   851 		test(fileCacheStats.iFilesOnClosedQueue == 0);
   851 		test(fileCacheStats.iFilesOnClosedQueue == 0);
   852 #endif
   852 #endif
   853 		f.Close();
   853 		f.Close();
   854 
   854 
   855 		test.Next(_L("close & verify file is back on close queue"));
   855 		test.Next(_L("close & verify file is back on close queue"));
   856 
   856 
   857 
   857 
   858 #if defined(_DEBUG) || defined(_DEBUG_RELEASE)
   858 #if defined(_DEBUG) || defined(_DEBUG_RELEASE)
   859 		r = controlIo(TheFs, gDrive, KControlIoFileCacheStats, fileCacheStats);
   859 		r = controlIo(TheFs, gDrive, KControlIoFileCacheStats, fileCacheStats);
   860 		test (r == KErrNone);
   860 		test_KErrNone(r);
   861 		test.Printf(_L("Number of files on closed queue=%d\n"),fileCacheStats.iFilesOnClosedQueue);
   861 		test.Printf(_L("Number of files on closed queue=%d\n"),fileCacheStats.iFilesOnClosedQueue);
   862 		test(fileCacheStats.iFilesOnClosedQueue == 1);
   862 		test(fileCacheStats.iFilesOnClosedQueue == 1);
   863 #endif
   863 #endif
   864 
   864 
   865 		if (testNum == ETestCloseQueueEmptyAfterDelete)
   865 		if (testNum == ETestCloseQueueEmptyAfterDelete)
   884 			f.Close();
   884 			f.Close();
   885 			}
   885 			}
   886 
   886 
   887 	#if defined(_DEBUG) || defined(_DEBUG_RELEASE)
   887 	#if defined(_DEBUG) || defined(_DEBUG_RELEASE)
   888 		r = controlIo(TheFs, gDrive, KControlIoFileCacheStats, fileCacheStats);
   888 		r = controlIo(TheFs, gDrive, KControlIoFileCacheStats, fileCacheStats);
   889 		test (r == KErrNone);
   889 		test_KErrNone(r);
   890 		test.Printf(_L("Number of files on closed queue=%d\n"),fileCacheStats.iFilesOnClosedQueue);
   890 		test.Printf(_L("Number of files on closed queue=%d\n"),fileCacheStats.iFilesOnClosedQueue);
   891 		test(fileCacheStats.iFilesOnClosedQueue == 0);
   891 		test(fileCacheStats.iFilesOnClosedQueue == 0);
   892 	#endif
   892 	#endif
   893 		}
   893 		}
   894 
   894 
   895 #if defined(_DEBUG) || defined(_DEBUG_RELEASE)
   895 #if defined(_DEBUG) || defined(_DEBUG_RELEASE)
   896 	// turn lock failure mode back ON (if enabled)
   896 	// turn lock failure mode back ON (if enabled)
   897 	simulatelockFailureMode = ETrue;
   897 	simulatelockFailureMode = ETrue;
   898 	r = controlIo(TheFs, gDrive, KControlIoSimulateLockFailureMode, simulatelockFailureMode);
   898 	r = controlIo(TheFs, gDrive, KControlIoSimulateLockFailureMode, simulatelockFailureMode);
   899 	test (r == KErrNone);
   899 	test_KErrNone(r);
   900 #endif
   900 #endif
   901 
   901 
   902 	//**************************************************************
   902 	//**************************************************************
   903 	// Test opening a file with a silly open mode flags combinations 
   903 	// Test opening a file with a silly open mode flags combinations 
   904 	//**************************************************************
   904 	//**************************************************************
   920 	const TInt KWriteLen = KSegmentSize+1;
   920 	const TInt KWriteLen = KSegmentSize+1;
   921 	writePtr.Set(gBuf->Des().Ptr(), KWriteLen);
   921 	writePtr.Set(gBuf->Des().Ptr(), KWriteLen);
   922 
   922 
   923 #if defined(_DEBUG) || defined(_DEBUG_RELEASE)
   923 #if defined(_DEBUG) || defined(_DEBUG_RELEASE)
   924 	r = controlIo(TheFs, gDrive, KControlIoFileCacheStats, fileCacheStats);
   924 	r = controlIo(TheFs, gDrive, KControlIoFileCacheStats, fileCacheStats);
   925 	test (r == KErrNone);
   925 	test_KErrNone(r);
   926 	test.Printf(_L("Number of Write-throughs with dirty data=%d\n"),fileCacheStats.iWriteThroughWithDirtyDataCount);
   926 	test.Printf(_L("Number of Write-throughs with dirty data=%d\n"),fileCacheStats.iWriteThroughWithDirtyDataCount);
   927 	TInt writeThroughWithDirtyDataCountOld = fileCacheStats.iWriteThroughWithDirtyDataCount;
   927 	TInt writeThroughWithDirtyDataCountOld = fileCacheStats.iWriteThroughWithDirtyDataCount;
   928 	TInt writeThroughWithDirtyDataCountNew = writeThroughWithDirtyDataCountOld;
   928 	TInt writeThroughWithDirtyDataCountNew = writeThroughWithDirtyDataCountOld;
   929 #endif
   929 #endif
   930 
   930 
   931 	TInt fileSize = 0;
   931 	TInt fileSize = 0;
   932 	for (TInt i=0; i<4; i++)
   932 	for (TInt i=0; i<4; i++)
   933 		{
   933 		{
   934 		fileSize = 0;
   934 		fileSize = 0;
   935 		r = f.SetSize(fileSize);
   935 		r = f.SetSize(fileSize);
   936 		test (r == KErrNone);
   936 		test_KErrNone(r);
   937 		for (pos = 0; pos < KMaxFileSize; )
   937 		for (pos = 0; pos < KMaxFileSize; )
   938 			{
   938 			{
   939 			r = f.Write(pos, writePtr);
   939 			r = f.Write(pos, writePtr);
   940 			if (r != KErrNone)
   940 			if (r != KErrNone)
   941 				{
   941 				{
   942 				test.Printf(_L("Iter #%d, write pos %d size %d, Write() returned %d"), i, pos, fileSize, r);
   942 				test.Printf(_L("Iter #%d, write pos %d size %d, Write() returned %d"), i, pos, fileSize, r);
   943 				r = f.Flush();
   943 				r = f.Flush();
   944 				test.Printf(_L("Flush returned %d"), r);
   944 				test.Printf(_L("Flush returned %d"), r);
   945 				test(0);
   945 				test(0);
   946 				}
   946 				}
   947 			test(r == KErrNone);
   947 			test_KErrNone(r);
   948 			pos+= writePtr.Length();
   948 			pos+= writePtr.Length();
   949 
   949 
   950 			r = f.Size(fileSize);
   950 			r = f.Size(fileSize);
   951 			test (r == KErrNone);
   951 			test_KErrNone(r);
   952 			if (fileSize != pos)
   952 			if (fileSize != pos)
   953 				{
   953 				{
   954 				test.Printf(_L("Iter #%d, write pos %d != size %d"), i, pos, fileSize);
   954 				test.Printf(_L("Iter #%d, write pos %d != size %d"), i, pos, fileSize);
   955 				r = f.Flush();
   955 				r = f.Flush();
   956 				test.Printf(_L("Flush returned %d"), r);
   956 				test.Printf(_L("Flush returned %d"), r);
   958 				}
   958 				}
   959 			test (fileSize == pos);
   959 			test (fileSize == pos);
   960 
   960 
   961 #if defined(_DEBUG) || defined(_DEBUG_RELEASE)
   961 #if defined(_DEBUG) || defined(_DEBUG_RELEASE)
   962 			r = controlIo(TheFs, gDrive, KControlIoFileCacheStats, fileCacheStats);
   962 			r = controlIo(TheFs, gDrive, KControlIoFileCacheStats, fileCacheStats);
   963 			test (r == KErrNone);
   963 			test_KErrNone(r);
   964 			writeThroughWithDirtyDataCountNew = fileCacheStats.iWriteThroughWithDirtyDataCount;
   964 			writeThroughWithDirtyDataCountNew = fileCacheStats.iWriteThroughWithDirtyDataCount;
   965 			if (writeThroughWithDirtyDataCountNew > writeThroughWithDirtyDataCountOld)
   965 			if (writeThroughWithDirtyDataCountNew > writeThroughWithDirtyDataCountOld)
   966 				{
   966 				{
   967 				test.Printf(_L("Iter #%d, write pos %d size %d"), i, pos, fileSize);
   967 				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);
   968 				test.Printf(_L("Number of Write-throughs with dirty data=%d\n"),fileCacheStats.iWriteThroughWithDirtyDataCount);
   996 	
   996 	
   997 	TDesC& fileName = *(TDesC*) aFileName;
   997 	TDesC& fileName = *(TDesC*) aFileName;
   998 
   998 
   999 	RFs fs;
   999 	RFs fs;
  1000 	TInt r = fs.Connect();
  1000 	TInt r = fs.Connect();
  1001 	test (r==KErrNone);
  1001 	test_KErrNone(r);
  1002 	r = fs.SetSessionPath(gSessionPath);
  1002 	r = fs.SetSessionPath(gSessionPath);
  1003 	test (r==KErrNone);
  1003 	test_KErrNone(r);
  1004 
  1004 
  1005 
  1005 
  1006 	RFile file;
  1006 	RFile file;
  1007 	r = file.Open(fs, fileName, EFileRead | EFileReadBuffered | EFileShareReadersOrWriters);
  1007 	r = file.Open(fs, fileName, EFileRead | EFileReadBuffered | EFileShareReadersOrWriters);
  1008 	test_KErrNone(r);
  1008 	test_KErrNone(r);
  1234 	TInt maxWriteCount=KMaxFileSize/aWriteBlockSize;
  1234 	TInt maxWriteCount=KMaxFileSize/aWriteBlockSize;
  1235 	TInt loopCount=0;
  1235 	TInt loopCount=0;
  1236 
  1236 
  1237 	RFile file;
  1237 	RFile file;
  1238 	TInt r = file.Replace(TheFs,_L("WRITETST"),EFileStream | aFileMode);
  1238 	TInt r = file.Replace(TheFs,_L("WRITETST"),EFileStream | aFileMode);
  1239 	test (r == KErrNone);
  1239 	test_KErrNone(r);
  1240 
  1240 
  1241 	TTime startTime;
  1241 	TTime startTime;
  1242 	TTime endTime;
  1242 	TTime endTime;
  1243 
  1243 
  1244 	RTimer timer;
  1244 	RTimer timer;
  1598 	{
  1598 	{
  1599 	TestsInit();
  1599 	TestsInit();
  1600 
  1600 
  1601 	TVolumeInfo volInfo;
  1601 	TVolumeInfo volInfo;
  1602 	TInt r = TheFs.Volume(volInfo, gDrive);
  1602 	TInt r = TheFs.Volume(volInfo, gDrive);
  1603 	test (r == KErrNone);
  1603 	test_KErrNone(r);
  1604 
  1604 
  1605 	TFullName extName;
  1605 	TFullName extName;
  1606 	r = TheFs.ExtensionName(extName,gDrive, 0);
  1606 	r = TheFs.ExtensionName(extName,gDrive, 0);
  1607 	if (r == KErrNone)
  1607 	if (r == KErrNone)
  1608 		{
  1608 		{
  1633 		{
  1633 		{
  1634 #if defined(_DEBUG) || defined(_DEBUG_RELEASE)
  1634 #if defined(_DEBUG) || defined(_DEBUG_RELEASE)
  1635 		// turn OFF lock failure mode
  1635 		// turn OFF lock failure mode
  1636 		TBool simulatelockFailureMode = EFalse;
  1636 		TBool simulatelockFailureMode = EFalse;
  1637 		r = controlIo(TheFs, gDrive, KControlIoSimulateLockFailureMode, simulatelockFailureMode);
  1637 		r = controlIo(TheFs, gDrive, KControlIoSimulateLockFailureMode, simulatelockFailureMode);
  1638 		test (r == KErrNone);
  1638 		test_KErrNone(r);
  1639 #endif
  1639 #endif
  1640 
  1640 
  1641 		TestFileRead(EFileReadDirectIO);
  1641 		TestFileRead(EFileReadDirectIO);
  1642 		if (gDriveCacheFlags & (EFileCacheReadEnabled | EFileCacheReadOn))
  1642 		if (gDriveCacheFlags & (EFileCacheReadEnabled | EFileCacheReadOn))
  1643 			{
  1643 			{
  1653 
  1653 
  1654 #if defined(_DEBUG) || defined(_DEBUG_RELEASE)
  1654 #if defined(_DEBUG) || defined(_DEBUG_RELEASE)
  1655 		// turn lock failure mode back ON (if enabled)
  1655 		// turn lock failure mode back ON (if enabled)
  1656 		simulatelockFailureMode = ETrue;
  1656 		simulatelockFailureMode = ETrue;
  1657 		r = controlIo(TheFs, gDrive, KControlIoSimulateLockFailureMode, simulatelockFailureMode);
  1657 		r = controlIo(TheFs, gDrive, KControlIoSimulateLockFailureMode, simulatelockFailureMode);
  1658 		test (r == KErrNone);
  1658 		test_KErrNone(r);
  1659 #endif
  1659 #endif
  1660 		}	// if (gRunPerformanceTests)
  1660 		}	// if (gRunPerformanceTests)
  1661 
  1661 
  1662 	TestsEnd();
  1662 	TestsEnd();
  1663 	}
  1663 	}
  1777 
  1777 
  1778 	if (gWriteCacheFlags)
  1778 	if (gWriteCacheFlags)
  1779 		{
  1779 		{
  1780 		test.Printf(_L("Writing DriveCacheFlags for drive %C = %08X\n"), (TInt) gDriveToTest, gDriveCacheFlags);
  1780 		test.Printf(_L("Writing DriveCacheFlags for drive %C = %08X\n"), (TInt) gDriveToTest, gDriveCacheFlags);
  1781 		r = controlIo(TheFs,gDrive, KControlIoFileCacheFlagsWrite, gDriveCacheFlags);
  1781 		r = controlIo(TheFs,gDrive, KControlIoFileCacheFlagsWrite, gDriveCacheFlags);
  1782 		test (r == KErrNone);
  1782 		test_KErrNone(r);
  1783 		}
  1783 		}
  1784 #endif
  1784 #endif
  1785 
  1785 
  1786 	if (gRunTests)
  1786 	if (gRunTests)
  1787 		{
  1787 		{