kerneltest/f32test/server/t_filecache.cpp
changeset 134 95847726fe57
parent 131 e880629062dd
child 176 af6ec97d9189
equal deleted inserted replaced
133:2a0ada0a1bf8 134:95847726fe57
    20 #include <e32svr.h> 
    20 #include <e32svr.h> 
    21 #include <f32dbg.h>
    21 #include <f32dbg.h>
    22 #include "t_server.h"
    22 #include "t_server.h"
    23 #include <e32twin.h>
    23 #include <e32twin.h>
    24 #include <e32rom.h>
    24 #include <e32rom.h>
    25 #include <u32hal.h>	//*test*
    25 #include <u32hal.h>
    26 
    26 
    27 
    27 
    28 //----------------------------------------------------------------------------------------------
    28 //----------------------------------------------------------------------------------------------
    29 //! @SYMTestCaseID      PBASE-T_FILECACHE-0189
    29 //! @SYMTestCaseID      PBASE-T_FILECACHE-0189
    30 //! @SYMTestType        UT
    30 //! @SYMTestType        UT
   249 				TestBufferFail(aBuffer, pos, aLength);
   249 				TestBufferFail(aBuffer, pos, aLength);
   250 			}
   250 			}
   251 		}
   251 		}
   252 	}
   252 	}
   253 
   253 
   254 //*test**************************************************************************
       
   255 TInt FreeRam()
   254 TInt FreeRam()
   256 	{
   255 	{
   257 	// wait for any async cleanup in the supervisor to finish first...
   256 	// wait for any async cleanup in the supervisor to finish first...
   258 	UserSvr::HalFunction(EHalGroupKernel, EKernelHalSupervisorBarrier, 0, 0);
   257 	UserSvr::HalFunction(EHalGroupKernel, EKernelHalSupervisorBarrier, 0, 0);
   259 
   258 
   260 	TMemoryInfoV1Buf meminfo;
   259 	TMemoryInfoV1Buf meminfo;
   261 	UserHal::MemoryInfo(meminfo);
   260 	UserHal::MemoryInfo(meminfo);
   262 	return meminfo().iFreeRamInBytes;
   261 	return meminfo().iFreeRamInBytes;
   263 	}
   262 	}
   264 //*test**************************************************************************
   263 
       
   264 void LowMemoryTest()
       
   265 	{
       
   266 	TInt fileSize = 0;
       
   267 	
       
   268 	const TInt KWriteLen = 128*1024;
       
   269 	test.Next(_L("Test appending to a file with low memory"));
       
   270 	gBufPtr.SetLength(KBufSize);
       
   271 
       
   272 	RFile f;
       
   273 	TFileName testFile   = _L("TEST.BIN");
       
   274 
       
   275 	TInt r = f.Replace(TheFs, testFile, EFileWrite | EFileWriteBuffered);
       
   276 	test_KErrNone(r);
       
   277 
       
   278 	TInt pos = 0;
       
   279 
       
   280 	TPtrC8 writePtr;
       
   281 	writePtr.Set(gBufPtr.MidTPtr(pos, KWriteLen));
       
   282 
       
   283 	r = f.Write(pos, writePtr);
       
   284 	test_KErrNone(r);
       
   285 	pos+= writePtr.Length();
       
   286 
       
   287 	r = f.Size(fileSize);
       
   288 	test_KErrNone(r);
       
   289 	test_Equal(fileSize,pos);
       
   290 
       
   291 
       
   292 
       
   293 	TUint freeRam = FreeRam();
       
   294 	const TInt KPageSize=4096;
       
   295 	freeRam = (freeRam + KPageSize -1) & ~(KPageSize-1);
       
   296 	test.Printf(_L("FreeRam = %d"), freeRam);
       
   297 
       
   298 	RChunk chunk;
       
   299 	TChunkCreateInfo chunkInfo;
       
   300 	chunkInfo.SetDisconnected(0, 0, freeRam);
       
   301 	chunkInfo.SetPaging(TChunkCreateInfo::EUnpaged);
       
   302 	test_KErrNone(chunk.Create(chunkInfo));
       
   303 
       
   304 	test.Printf(_L("Gobbling all of memory..."));
       
   305 	
       
   306 	TUint commitEnd;
       
   307 	for (commitEnd = 0; commitEnd < freeRam; commitEnd += KPageSize) 
       
   308 		{
       
   309 		r = chunk.Commit(commitEnd,KPageSize);
       
   310 		if (r != KErrNone)
       
   311 			break;
       
   312 		
       
   313 		}
       
   314 	test.Printf(_L("commitEnd %d, r %d"), commitEnd, r);
       
   315 	test_Value(r, r == KErrNoMemory || r == KErrNone);
       
   316 
       
   317 	test.Printf(_L("FreeRam = %d"), FreeRam());
       
   318 
       
   319 	pos-= KSegmentSize;
       
   320 	writePtr.Set(gBufPtr.MidTPtr(pos, KWriteLen));
       
   321 
       
   322 	test.Printf(_L("Writing to file..."));
       
   323 
       
   324 	r = f.Write(pos, writePtr);
       
   325 	test_KErrNone(r);
       
   326 	pos+= writePtr.Length();
       
   327 
       
   328 	test.Printf(_L("Setting size of file ..."));
       
   329 	r = f.Size(fileSize);
       
   330 	test_KErrNone(r);
       
   331 	test_Equal(fileSize,pos);
       
   332 
       
   333 	test.Printf(_L("Closing file ..."));
       
   334 	f.Close();
       
   335 
       
   336 	test.Printf(_L("Closing chunk ..."));
       
   337 	chunk.Close();
       
   338 
       
   339 	test.Printf(_L("FreeRam = %d"), FreeRam());
       
   340 	}
       
   341 
   265 
   342 
   266 
   343 
   267 LOCAL_C void UnitTests()
   344 LOCAL_C void UnitTests()
   268 //
   345 //
   269 // Test read file handling.
   346 // Test read file handling.
   310 #if defined(_DEBUG) || defined(_DEBUG_RELEASE)
   387 #if defined(_DEBUG) || defined(_DEBUG_RELEASE)
   311 	TInt uncachedBytesRead;
   388 	TInt uncachedBytesRead;
   312 	TInt uncachedPacketsRead;
   389 	TInt uncachedPacketsRead;
   313 #endif
   390 #endif
   314 
   391 
   315 //*test**************************************************************************
   392 	LowMemoryTest();
   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**************************************************************************
       
   376 
   393 
   377 	// create an empty file, so that any writes overlapping segemt boundaries
   394 	// create an empty file, so that any writes overlapping segemt boundaries
   378 	// need a read first
   395 	// need a read first
   379 	// create a test file using directIO and then re-open it in buffered mode, 
   396 	// create a test file using directIO and then re-open it in buffered mode, 
   380 	// so that any writes overlapping segemt boundaries need a read first
   397 	// so that any writes overlapping segemt boundaries need a read first