--- a/kerneltest/f32test/server/t_filecache.cpp Tue May 04 09:44:26 2010 +0100
+++ b/kerneltest/f32test/server/t_filecache.cpp Wed May 05 05:11:16 2010 +0100
@@ -22,6 +22,7 @@
#include "t_server.h"
#include <e32twin.h>
#include <e32rom.h>
+#include <u32hal.h> //*test*
//----------------------------------------------------------------------------------------------
@@ -114,7 +115,7 @@
void PrintFileCacheConfig(TFileCacheConfig& aFileCacheConfig, TBool aDisplay = ETrue)
{
TInt r = controlIo(TheFs,gDrive, KControlIoFileCacheConfig, aFileCacheConfig);
- test (r == KErrNone);
+ test_KErrNone(r);
if (!aDisplay)
return;
@@ -250,6 +251,18 @@
}
}
+//*test**************************************************************************
+TInt FreeRam()
+ {
+ // wait for any async cleanup in the supervisor to finish first...
+ UserSvr::HalFunction(EHalGroupKernel, EKernelHalSupervisorBarrier, 0, 0);
+
+ TMemoryInfoV1Buf meminfo;
+ UserHal::MemoryInfo(meminfo);
+ return meminfo().iFreeRamInBytes;
+ }
+//*test**************************************************************************
+
LOCAL_C void UnitTests()
//
@@ -271,7 +284,7 @@
TBool simulatelockFailureMode;
TFileCacheStats fileCacheStats;
r = controlIo(TheFs, gDrive, KControlIoFileCacheStats, fileCacheStats);
- test (r == KErrNone);
+ test_KErrNone(r);
test.Printf(_L("Number of files on closed queue=%d\n"),fileCacheStats.iFilesOnClosedQueue);
test(fileCacheStats.iFilesOnClosedQueue == 0);
#endif
@@ -280,7 +293,7 @@
// turn OFF lock failure mode
simulatelockFailureMode = EFalse;
r = controlIo(TheFs, gDrive, KControlIoSimulateLockFailureMode, simulatelockFailureMode);
- test (r == KErrNone);
+ test_KErrNone(r);
#endif
TFileName testFile = _L("TEST.BIN");
@@ -299,6 +312,68 @@
TInt uncachedPacketsRead;
#endif
+//*test**************************************************************************
+ {
+ TInt fileSize = 0;
+
+ const TInt KWriteLen = 128*1024;
+ test.Next(_L("Test appending to a file with low memory"));
+ gBufPtr.SetLength(KBufSize);
+
+ r = f.Replace(TheFs, testFile, EFileWrite | EFileWriteBuffered);
+ test_KErrNone(r);
+
+ pos = 0;
+
+ writePtr.Set(gBufPtr.MidTPtr(pos, KWriteLen));
+
+ r = f.Write(pos, writePtr);
+ test_KErrNone(r);
+ pos+= writePtr.Length();
+
+ r = f.Size(fileSize);
+ test_KErrNone(r);
+ test_Equal(fileSize,pos);
+
+
+
+ TInt freeRam = FreeRam();
+ test.Printf(_L("FreeRam = %d"), freeRam);
+ const TInt KPageSize=4096;
+
+ RChunk chunk;
+ TChunkCreateInfo chunkInfo;
+ chunkInfo.SetDisconnected(0, 0, freeRam);
+ chunkInfo.SetPaging(TChunkCreateInfo::EUnpaged);
+ test_KErrNone(chunk.Create(chunkInfo));
+
+ TUint commitEnd = 0;
+ TInt r;
+ while(KErrNone == (r = chunk.Commit(commitEnd,KPageSize)))
+ {
+ commitEnd += KPageSize;
+ }
+ test_Equal(KErrNoMemory, r);
+
+
+
+ pos-= KSegmentSize;
+ writePtr.Set(gBufPtr.MidTPtr(pos, KWriteLen));
+
+ r = f.Write(pos, writePtr);
+ test_KErrNone(r);
+ pos+= writePtr.Length();
+
+ r = f.Size(fileSize);
+ test_KErrNone(r);
+ test_Equal(fileSize,pos);
+
+ f.Close();
+
+ chunk.Close();
+ }
+//*test**************************************************************************
+
// create an empty file, so that any writes overlapping segemt boundaries
// need a read first
// create a test file using directIO and then re-open it in buffered mode,
@@ -618,7 +693,7 @@
TInt size;
r = f.Size(size);
- test (r == KErrNone);
+ test_KErrNone(r);
test (size = KBufSize);
readPtr.Set(gBuf->Des());
@@ -627,7 +702,7 @@
// Allocate full cachelines - so we can enable hole testing
TBool allocateAllSegmentsInCacheLine = ETrue;
r = controlIo(TheFs, gDrive, KControlIoAllocateMaxSegments, allocateAllSegmentsInCacheLine);
- test (r == KErrNone);
+ test_KErrNone(r);
PrintFileCacheStats(fileCacheStats, EFalse);
TInt holesDetected = fileCacheStats.iHoleCount;
TInt lockFailures = fileCacheStats.iCommitFailureCount + fileCacheStats.iLockFailureCount;
@@ -712,7 +787,7 @@
// Don't allocate full cachelines any more
allocateAllSegmentsInCacheLine = EFalse;
r = controlIo(TheFs, gDrive, KControlIoAllocateMaxSegments, allocateAllSegmentsInCacheLine);
- test (r == KErrNone);
+ test_KErrNone(r);
#endif
@@ -812,7 +887,7 @@
#if defined(_DEBUG) || defined(_DEBUG_RELEASE)
r = controlIo(TheFs, gDrive, KControlIoFileCacheStats, fileCacheStats);
- test (r == KErrNone);
+ test_KErrNone(r);
test.Printf(_L("Number of files on closed queue=%d\n"),fileCacheStats.iFilesOnClosedQueue);
test(fileCacheStats.iFilesOnClosedQueue == 1);
#endif
@@ -846,7 +921,7 @@
#if defined(_DEBUG) || defined(_DEBUG_RELEASE)
r = controlIo(TheFs, gDrive, KControlIoFileCacheStats, fileCacheStats);
- test (r == KErrNone);
+ test_KErrNone(r);
test.Printf(_L("Number of files on closed queue=%d\n"),fileCacheStats.iFilesOnClosedQueue);
test(fileCacheStats.iFilesOnClosedQueue == 0);
#endif
@@ -857,7 +932,7 @@
#if defined(_DEBUG) || defined(_DEBUG_RELEASE)
r = controlIo(TheFs, gDrive, KControlIoFileCacheStats, fileCacheStats);
- test (r == KErrNone);
+ test_KErrNone(r);
test.Printf(_L("Number of files on closed queue=%d\n"),fileCacheStats.iFilesOnClosedQueue);
test(fileCacheStats.iFilesOnClosedQueue == 1);
#endif
@@ -886,7 +961,7 @@
#if defined(_DEBUG) || defined(_DEBUG_RELEASE)
r = controlIo(TheFs, gDrive, KControlIoFileCacheStats, fileCacheStats);
- test (r == KErrNone);
+ test_KErrNone(r);
test.Printf(_L("Number of files on closed queue=%d\n"),fileCacheStats.iFilesOnClosedQueue);
test(fileCacheStats.iFilesOnClosedQueue == 0);
#endif
@@ -896,7 +971,7 @@
// turn lock failure mode back ON (if enabled)
simulatelockFailureMode = ETrue;
r = controlIo(TheFs, gDrive, KControlIoSimulateLockFailureMode, simulatelockFailureMode);
- test (r == KErrNone);
+ test_KErrNone(r);
#endif
//**************************************************************
@@ -922,7 +997,7 @@
#if defined(_DEBUG) || defined(_DEBUG_RELEASE)
r = controlIo(TheFs, gDrive, KControlIoFileCacheStats, fileCacheStats);
- test (r == KErrNone);
+ test_KErrNone(r);
test.Printf(_L("Number of Write-throughs with dirty data=%d\n"),fileCacheStats.iWriteThroughWithDirtyDataCount);
TInt writeThroughWithDirtyDataCountOld = fileCacheStats.iWriteThroughWithDirtyDataCount;
TInt writeThroughWithDirtyDataCountNew = writeThroughWithDirtyDataCountOld;
@@ -933,7 +1008,7 @@
{
fileSize = 0;
r = f.SetSize(fileSize);
- test (r == KErrNone);
+ test_KErrNone(r);
for (pos = 0; pos < KMaxFileSize; )
{
r = f.Write(pos, writePtr);
@@ -944,11 +1019,11 @@
test.Printf(_L("Flush returned %d"), r);
test(0);
}
- test(r == KErrNone);
+ test_KErrNone(r);
pos+= writePtr.Length();
r = f.Size(fileSize);
- test (r == KErrNone);
+ test_KErrNone(r);
if (fileSize != pos)
{
test.Printf(_L("Iter #%d, write pos %d != size %d"), i, pos, fileSize);
@@ -960,7 +1035,7 @@
#if defined(_DEBUG) || defined(_DEBUG_RELEASE)
r = controlIo(TheFs, gDrive, KControlIoFileCacheStats, fileCacheStats);
- test (r == KErrNone);
+ test_KErrNone(r);
writeThroughWithDirtyDataCountNew = fileCacheStats.iWriteThroughWithDirtyDataCount;
if (writeThroughWithDirtyDataCountNew > writeThroughWithDirtyDataCountOld)
{
@@ -998,9 +1073,9 @@
RFs fs;
TInt r = fs.Connect();
- test (r==KErrNone);
+ test_KErrNone(r);
r = fs.SetSessionPath(gSessionPath);
- test (r==KErrNone);
+ test_KErrNone(r);
RFile file;
@@ -1236,7 +1311,7 @@
RFile file;
TInt r = file.Replace(TheFs,_L("WRITETST"),EFileStream | aFileMode);
- test (r == KErrNone);
+ test_KErrNone(r);
TTime startTime;
TTime endTime;
@@ -1600,7 +1675,7 @@
TVolumeInfo volInfo;
TInt r = TheFs.Volume(volInfo, gDrive);
- test (r == KErrNone);
+ test_KErrNone(r);
TFullName extName;
r = TheFs.ExtensionName(extName,gDrive, 0);
@@ -1635,7 +1710,7 @@
// turn OFF lock failure mode
TBool simulatelockFailureMode = EFalse;
r = controlIo(TheFs, gDrive, KControlIoSimulateLockFailureMode, simulatelockFailureMode);
- test (r == KErrNone);
+ test_KErrNone(r);
#endif
TestFileRead(EFileReadDirectIO);
@@ -1655,7 +1730,7 @@
// turn lock failure mode back ON (if enabled)
simulatelockFailureMode = ETrue;
r = controlIo(TheFs, gDrive, KControlIoSimulateLockFailureMode, simulatelockFailureMode);
- test (r == KErrNone);
+ test_KErrNone(r);
#endif
} // if (gRunPerformanceTests)
@@ -1779,7 +1854,7 @@
{
test.Printf(_L("Writing DriveCacheFlags for drive %C = %08X\n"), (TInt) gDriveToTest, gDriveCacheFlags);
r = controlIo(TheFs,gDrive, KControlIoFileCacheFlagsWrite, gDriveCacheFlags);
- test (r == KErrNone);
+ test_KErrNone(r);
}
#endif