Update contrib.
1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // f32test\server\t_wcache.cpp
15 // This file contains a test for the Write Caching functionality of the File Server
24 #define __E32TEST_EXTENSION__
32 const TInt KTotalCacheSize = 32 * 1024 * 1024;
33 const TInt KDefaultCacheSize = (128 + 12) * 1024; // This size is the default configuration size
34 const TInt KFilesNeededToFillCache = (KTotalCacheSize / KDefaultCacheSize) + 2;
35 const TInt KMinSize = 254; // Boundary minim limit
36 const TInt KMaxSize = 257; // Boundary max limit
40 //----------------------------------------------------------------------------------------------
41 //! @SYMTestCaseID PBASE-T_WCACHE-0271
44 //! @SYMTestCaseDesc This test case is exercising the Write Caching functionality added to
45 //! the File Server. There are negative and positive tests.
46 //! @SYMTestActions 0 setup the environment to execute the tests
47 //! 1 TestBoundaries writes/reads around the write cache boundaries to
48 //! the behaviour of the cache in some common cases.
49 //! 2 TestNegative ensures the integrity of data in the cache gets
50 //! preserved under error conditions
51 //! 3 TestIntegrity is trying to make sure integrity of the data is preserved
52 //! 4 TestFillCache fills the cache and then executes TestBoundaries.
53 //! 5 TestFillCacheNegative fills the cache with uncommitted data
55 //! @SYMTestExpectedResults finishes if the read cache behaves as expected, panics otherwise
56 //! @SYMTestPriority High
57 //! @SYMTestStatus Implemented
58 //----------------------------------------------------------------------------------------------
61 ////////////////////////////////////////////////////////////
62 // Template functions encapsulating ControlIo magic
65 TInt controlIo(RFs &fs, TInt drv, TInt fkn, C &c)
67 TPtr8 ptrC((TUint8 *)&c, sizeof(C), sizeof(C));
69 TInt r = fs.ControlIo(drv, fkn, ptrC);
74 RTest test(_L("T_WCACHE"));
78 TFileName gSessionPath;
80 TThreadId gMainThreadId;
84 TPtr8 gBufReadPtr(NULL, 0);
85 HBufC8* gBufSec = NULL;
86 TPtr8 gBufWritePtr(NULL, 0);
88 const TInt KOneK = 1024;
89 const TInt KOneMeg = KOneK * 1024;
90 const TInt KBlockSize = KOneK;
91 const TInt KWaitRequestsTableSize = 256;
92 const TInt KMs = 1000;
94 TInt gSecondFileSize = 0;
95 TInt gFirstFileSize = 0;
97 TInt64 gMediaSize = 0;
99 TTimeIntervalMicroSeconds gTimeTakenBigFile(0);
100 TBuf16<25> gFirstFile;
101 TBuf16<25> gSecondFile;
102 TBuf16<25> gCurrentFile;
109 // Concurrent Threads
112 const TInt KHeapSize = 0x4000;
113 const TInt KMaxHeapSize = 0x100000;
116 /** Formats the drive
118 @param aDrive Drive to be formatted
119 @param aFormatMode Mode for the format operation
121 void Formatting(TInt aDrive, TUint aFormatMode )
124 test.Next(_L("Format"));
125 TBuf<4> driveBuf = _L("?:\\");
126 driveBuf[0]=(TText)(aDrive+'A');
129 TInt r = format.Open(gTheFs,driveBuf,aFormatMode,count);
133 TInt r = format.Next(count);
140 /** Verifies the content of a buffer
141 This function returns KErrNone when all the letters are consecutive in the aBuffer, KErrCorrupt otherwise
143 @param aBuffer Buffer to be verified
145 @return KErrNone if all the letters are the same, KErrCorrupt otherwise
147 TInt VerifyBuffer(TDes8& aBuffer)
149 TChar c = aBuffer[0];
151 for(TInt i = 1; i < aBuffer.Length(); i++)
155 if(c != (TChar)(aBuffer[i] - 1))
160 if(aBuffer[i] != aBuffer[0])
169 /** Fills a buffer with character aC, aC+1, aC+2, ..., aC+0x20, aC, etc
171 @param aBuffer Buffer to be filled, output
172 @param aLength Length to be filled
173 @param aC Character to be used to fill the buffer
175 void FillBuffer(TDes8& aBuffer, TInt aLength, TChar aC)
177 test (aBuffer.MaxLength() >= aLength);
178 for(TInt i = 0; i < aLength; i++)
180 aBuffer.Append((i%32) + aC);
184 /** Returns true if fat filesystem present on aDrive
186 @param aFsSession Session on the File Server
187 @param aDrive Drive to be looked at
189 @return ETrue if FAT, EFalse otherwise
191 TBool IsFSFAT(RFs &aFsSession,TInt aDrive)
194 TInt r = aFsSession.FileSystemName(f,aDrive);
198 test.Printf(_L("Unable to get file system name\n"));
202 return (f.CompareF(_L("Fat")) == 0);
205 /** Generates a file name of the form FFFFF*<aPos>.TXT (aLong.3)
207 @param aBuffer The filename will be returned here
208 @param aLong Defines the longitude of the file name
209 @param aPos Defines the number that will be attached to the filename
211 void FileNameGen(TDes16& aBuffer, TInt aLong, TInt aPos)
218 tempbuf.Format(KNumber,aPos);
219 padding = aLong-tempbuf.Size()/2;
226 aBuffer.Append(tempbuf);
228 _LIT(KExtension1, ".TXT");
229 aBuffer.Append(KExtension1);
232 /** Delete content of directory
234 @param aDir Target directory
236 @return Error returned if any, otherwise KErrNone
238 TInt DeleteAllL(TDes16& aDir)
241 CFileMan* fMan = CFileMan::NewL(gTheFs);
245 dir.Append(_L("F*.*"));
246 r = fMan->Delete(dir);
252 /** Waits for all the TRequestStatus in status[] to complete
254 @param status Array of TRequestStatus
255 @param aSize Length to be filled
257 void WaitForAll(TRequestStatus* status, TInt aSize)
261 RTest test(_L("T_WCACHE"));
265 User::WaitForRequest(status[i]);
266 if (status[i] != KErrNone)
268 test.Printf(_L("status[%d] == %d\n"), i, status[i].Int());
277 /** Reads the parameters from the comand line
278 and updates the appropriate variables
280 void parseCommandLine()
283 User::CommandLine(cmd);
285 TPtrC token = lex.NextToken();
288 if(token.Length() != 0)
290 gDriveToTest = token[0];
291 gDriveToTest.UpperCase();
298 r = gTheFs.CharToDrive(gDriveToTest,gDrive);
303 token.Set(lex.NextToken());
304 if(token.Length() != 0)
309 gManual = (c == 'M');
313 gSessionPath = _L("?:\\F32-TST\\");
314 gSessionPath[0] = (TUint16) gDriveToTest;
315 test.Printf(_L("\nCLP=%C\n"),(TInt)gDriveToTest);
320 /** Writes a file synchronously in blocks of aBlockSize size
322 @param aFs RFs object
324 @param aFileName File name
325 @param aSize Size of the file in bytes
326 @param aBlockSize Size of the blocks to be used in bytes
327 @param aBuf Buffer to be used to write
328 @param aMode Mode in which the file is meant to be opened
330 @return Returns KErrNone if everything ok, otherwise it panics
332 TInt WriteFile(RFs& aFs, RFile& aFile, TDes16& aFileName, TInt aSize, TInt aBlockSize, TDes8& aBuf, TInt aMode)
334 RTest test(_L("T_WCACHE"));
338 test(aBlockSize > 0);
341 r = aFile.Replace(aFs,aFileName,aMode);
347 r = aFile.Write(aBuf, aBlockSize);
356 /** Write a file that fits in the cache, and dies without proper cleaning
359 LOCAL_C TInt WriteFileT(TAny* )
361 RTest test(_L("T_WCACHE"));
364 TInt r = fs.Connect();
367 r = fs.SetSessionPath(gSessionPath);
370 r = WriteFile(fs, file, gFirstFile, KMinSize * KOneK, KBlockSize, gBufWritePtr, EFileShareAny|EFileWrite|EFileWriteBuffered);
378 // waiting for the kill
382 /** Read File in blocks of size aBlockSize
384 @param aFs RFs object
386 @param aFileName File name
387 @param aSize Expected file size
388 @param aBlockSize Size of the blocks to be used in bytes
389 @param aMode Mode in which the file is meant to be opened
391 @return Returns KErrNone if everything ok, otherwise it panics
393 TInt ReadFile(RFs& aFs, RFile& aFile, TDes16& aFileName, TInt aSize, TInt aBlockSize, TInt aMode)
395 RTest test(_L("T_WCACHE"));
397 TInt r = 0, size = 0;
399 test(aBlockSize>0); // Block size must be greater than 0
401 r = aFile.Open(aFs,aFileName,aMode);
404 // Make sure the size of the file is the right one at this stage
405 r = aFile.Size(size);
406 test.Printf(_L("size of the file: %d \n"), size/KOneK);
412 r = aFile.Read(gBufReadPtr, aBlockSize);
421 /** Write a file asynchronously in blocks of aBlockSize size
423 @param aFs RFs object
424 @param aFileWrite RFile object, needs to exist beyond the scope of this function
425 @param aFile File name
426 @param aSize Size of the file in bytes
427 @param aMode Specifies the mode in which the file should be openned
428 @param aStatus TRequestStatus array for all the requests
430 void WriteFileAsync(RFs& aFs, RFile& aFileWrite, TDes16& aFile, TInt aSize, TInt aMode, TRequestStatus aStatus[])
432 RTest test(_L("T_WCACHE"));
436 r = aFileWrite.Replace(aFs,aFile,aMode);
442 aFileWrite.Write(gBufWritePtr, KBlockSize, aStatus[i]);
443 r = aStatus[i].Int();
444 if (r != KErrNone && r != KRequestPending)
446 test.Printf(_L("Write %d returned %d\n"), i, r);
456 /** Read a file asynchronously in blocks of aBlockSize size
458 @param aFs RFs object
459 @param aFileRead RFile object, needs to exist beyond the scope of this function
460 @param aFile File name
461 @param aFileSize Size of the file in bytes
462 @param aBlockSize Size of the blocks to be used in bytes
463 @param aStatus TRequestStatus array for all the requests
464 @param aMode Specifies the mode in which the file should be openned
468 TInt ReadFileAsync(RFs& aFs,RFile& aFileRead, TDes16& aFile, TInt aFileSize, TInt aBlockSize,TRequestStatus aStatus[], TInt aMode)
470 RTest test(_L("T_WCACHE"));
475 test(aBlockSize > 0);
478 r = aFileRead.Open(aFs,aFile, aMode);
481 r = aFileRead.Size(size);
484 test.Printf(_L("size of the file %d\n"), size/KOneK);
485 test(size == aFileSize);
490 aFileRead.Read(gBufReadPtr, aBlockSize, aStatus[i]);
491 r = aStatus[i].Int();
492 if (r != KErrNone && r != KRequestPending)
494 test.Printf(_L("Read %d returned %d\n"), i, r);
506 /** Measure the time taken for this file to be written synchronously
508 @param aFile File object
509 @param aFileName File Name
510 @param aSize Size in kilobytes
511 @param aBlockSize Size of the block
512 @param aMode Mode in which the file is going to be opened
514 @return time taken to perform the operation in uS
516 TInt WriteTestFile(RFile& aFile, TDes16& aFileName, TInt aSize, TInt aBlockSize, TInt aMode)
518 RTest test(_L("T_WCACHE"));
524 startTime.HomeTime();
526 r = WriteFile(gTheFs,aFile, aFileName , aSize * KOneK, aBlockSize, gBufWritePtr, aMode);
531 gTimeTakenBigFile = I64LOW(endTime.MicroSecondsFrom(startTime).Int64());
534 return I64LOW(gTimeTakenBigFile.Int64());
537 /** Measure the time taken for this file to be read synchronously
539 @param aFile File object
540 @param aFileName File Name
541 @param aSize Size in kilobytes
542 @param aBlockSize Size of the block
543 @param aMode Mode in which the file is going to be opened
545 @return time taken to perform the operation in uS
548 TInt ReadTestFile(RFile& aFile, TDes16& aFileName, TInt aSize, TInt aBlockSize, TInt aMode)
553 startTime.HomeTime();
554 ReadFile(gTheFs,aFile, aFileName, aSize * KOneK, aBlockSize, aMode);
557 gTimeTakenBigFile = I64LOW(endTime.MicroSecondsFrom(startTime).Int64());
559 return I64LOW(gTimeTakenBigFile.Int64()) ;
562 /** Read asynchronously the test file from the disc
564 @param aFile File object
565 @param aFileName File Name
566 @param aSize Size in kilobytes
567 @param aBlockSize Size of the block
568 @param aMode Mode in which the file is going to be opened
570 @return time taken to perform the operation in uS
572 TInt ReadAsyncTestFile(RFile& file, TDes16& aFile, TInt aSize, TInt aBlockSize, TInt aMode)
576 TRequestStatus status[KWaitRequestsTableSize];
578 startTime.HomeTime();
580 ReadFileAsync(gTheFs, file, aFile, aSize * KOneK, aBlockSize, status, aMode);
581 WaitForAll(status, (aSize * KOneK)/KBlockSize);
585 gTimeTakenBigFile = I64LOW(endTime.MicroSecondsFrom(startTime).Int64());
587 return I64LOW(gTimeTakenBigFile.Int64());
590 /** Read asynchronously the test file from the disc
592 @param aFile File object
593 @param aFileName File Name
594 @param aSize Size in kilobytes
595 @param aMode Mode in which the file is going to be opened
597 @return time taken to perform the operation in uS
599 TInt WriteAsyncTestFile(RFile& aFile, TDes16& aFileName, TInt aSize, TInt aMode)
603 TRequestStatus status[KWaitRequestsTableSize];
605 startTime.HomeTime();
607 WriteFileAsync(gTheFs, aFile, aFileName, aSize * KOneK, aMode, status );
608 WaitForAll(status, (aSize * KOneK)/KBlockSize);
612 gTimeTakenBigFile = I64LOW(endTime.MicroSecondsFrom(startTime).Int64());
614 return I64LOW(gTimeTakenBigFile.Int64());
619 This function is testing the behaviour on the boundaries of the write cache size
621 void TestBoundaries()
631 test.Start(_L("Test Boundaries"));
633 // Test boundaries from 254K to 256K, synchronous operations
637 test.Printf(_L("\n\n\n"));
641 test.Printf(_L("\nSync: Write from 1 K to %d K \n"), i);
643 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);
647 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);
650 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);
657 #if !defined(__WINS__)
658 test((tcreate > time) || (tcreate > rtime));
661 r = gTheFs.Delete(gFirstFile);
663 r = gTheFs.Delete(gSecondFile);
669 test.Printf(_L("\n\n\n"));
671 // Test boundaries from 254K to 256K, asynchronous operations
676 test.Printf(_L("\nAsync: Write from 1 K to %d K \n"), i);
678 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);
682 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);
686 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);
692 #if !defined(__WINS__)
693 test((tcreate > time) || (tcreate > rtime));
696 r = gTheFs.Delete(gFirstFile);
698 r = gTheFs.Delete(gSecondFile);
707 /** Test negative cases
716 TBuf<20> buf = _L("Write File");
719 test.Start(_L("Test Negative"));
721 test.Next(_L("Kill a simple operation"));
723 r = gThread1.Create(buf,WriteFileT,KDefaultStackSize,KHeapSize,KMaxHeapSize,NULL);
729 gThread1.Kill(KErrGeneral);
731 r = file.Open(gTheFs,gFirstFile,EFileShareAny|EFileRead|EFileReadBuffered|EFileReadAheadOff);
737 test.Printf(_L("The size of the file is %d KB\n\n"), size/KOneK);
738 test(size == (KMinSize * KOneK));
746 /** Read the file verifying content
748 @param aFile file name to verify
750 @return returns the time that took to do the verification in mS, fails if the file is not corrupted/modified
752 TInt ReadTestFileVerif(TDes16& aFile)
760 TBool isFat=IsFSFAT(gTheFs,gDrive);
762 startTime.HomeTime();
764 r = fileRead.Open(gTheFs,aFile,EFileShareAny|EFileRead|EFileReadBuffered|EFileReadAheadOff);
767 r = fileRead.Size(size);
774 r = fileRead.Read(gBufReadPtr, KBlockSize);
786 r = VerifyBuffer(gBufReadPtr);
793 test(corrupt>0); // Ensure the cache returns the changed content
797 gTimeTakenBigFile = I64LOW(endTime.MicroSecondsFrom(startTime).Int64());
799 return I64LOW(gTimeTakenBigFile.Int64()) / KMs;
802 /** Modifies the second file
805 LOCAL_C TInt CorruptSecondFile()
809 HBufC8* dummy = NULL;
810 TPtr8 dummyPtr(NULL, 0);
812 TRAPD(res,dummy = HBufC8::NewL(4));
813 test(res == KErrNone && dummy != NULL);
815 dummyPtr.Set(dummy->Des());
816 FillBuffer(dummyPtr, 4, '1');
818 r = fileWrite.Open(gTheFs,gSecondFile,EFileShareAny|EFileWrite|EFileWriteBuffered);
822 r = fileWrite.Seek(ESeekStart,pos);
825 r = fileWrite.Write(dummyPtr);
837 /** Integrity testing
840 LOCAL_C void TestIntegrity()
847 // Modify file in some position
848 test.Printf(_L("Overwrite partially a file\n"));
850 test.Printf(_L("\nSync: Write from 1 K to %d K \n"), 255);
852 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);
856 test.Printf(_L("Mess the content that is still in the cache\n"));
859 time = ReadTestFileVerif(gSecondFile);
860 test.Printf(_L("Time taken to verify: %d\n"),time);
862 test.Printf(_L("Integrity verified\n"));
864 r = DeleteAllL(gSessionPath);
868 /** Creates the files to fill the cache with dirty data
872 TInt CreateFilesThread(TAny *)
876 TBuf16<50> directory;
879 TBuf16<50> buffer(50);
880 RFile file[KFilesNeededToFillCache];
882 RTest test(_L("T_WCACHE2"));
887 directory = gSessionPath;
889 test.Printf(_L("Creating %d files for filling the cache (size %d)\n"), KFilesNeededToFillCache, KDefaultCacheSize);
891 // create a big buffer to speed things up
892 HBufC8* bigBuf = NULL;
893 TInt KBigBifferSize = 32 * KOneK;
895 TRAPD(res,bigBuf = HBufC8::NewL(KBigBifferSize));
896 test(res == KErrNone && bigBuf != NULL);
898 TPtr8 bigBufWritePtr(NULL, 0);
899 bigBufWritePtr.Set(bigBuf->Des());
900 FillBuffer(bigBufWritePtr, KBigBifferSize, 'A');
903 while(i < KFilesNeededToFillCache)
906 test.Printf(_L("Creating file %d of %d...\r"), i, KFilesNeededToFillCache);
907 FileNameGen(buffer, 8, i+3) ;
911 r = file[i].Create(fs,path,EFileShareAny|EFileWrite|EFileWriteBuffered);
912 if(r == KErrAlreadyExists)
913 r = file[i].Open(fs,path,EFileShareAny|EFileWrite|EFileWriteBuffered);
917 while(j < KDefaultCacheSize)
919 bigBufWritePtr.SetLength(Min(KBigBifferSize, KDefaultCacheSize - j));
921 r = file[i].Write(bigBufWritePtr);
923 j += bigBufWritePtr.Length();
926 // Not closing the files is done on purpose, as part of the test
930 test.Printf(_L("\nFiles created\n"));
939 /** Creates the files to fill the read cache
941 @param aFiles Number of files needed to fill the cache
942 @param aFileSize The file size
944 void CreateFiles(TInt aFiles, TInt aFileSize)
949 TBuf16<50> directory;
952 TBuf16<50> buffer(50);
954 directory = gSessionPath;
956 test.Printf(_L("Creating %d files for filling the cache (size %d)\n"), aFiles, aFileSize);
958 // create a big buffer to speed things up
959 HBufC8* bigBuf = NULL;
960 const TInt KBigBifferSize = 32 * 1024;
961 TRAPD(res,bigBuf = HBufC8::NewL(KBigBifferSize));
962 test(res == KErrNone && bigBuf != NULL);
964 TPtr8 bigBufWritePtr(NULL, 0);
965 bigBufWritePtr.Set(bigBuf->Des());
966 FillBuffer(bigBufWritePtr, KBigBifferSize, 'A');
972 test.Printf(_L("Creating file %d of %d...\r"), i, aFiles);
973 FileNameGen(buffer, 8, i+3) ;
977 // delete file first to ensure it's contents are not in the cache (file may be be on the closed file queue)
978 r = gTheFs.Delete(path);
979 test_Value(r, r == KErrNone || r == KErrNotFound);
981 r = file.Create(gTheFs,path,EFileShareAny|EFileWrite|EFileWriteDirectIO);
982 if(r == KErrAlreadyExists)
983 r = file.Open(gTheFs,path,EFileShareAny|EFileWrite|EFileWriteDirectIO);
988 bigBufWritePtr.SetLength(Min(KBigBifferSize, aFileSize - j));
989 r = file.Write(bigBufWritePtr);
991 j += bigBufWritePtr.Length();
997 test.Printf(_L("\nFiles created\n"));
1001 /** Fills the read cache
1003 @param aFile Array of files needed to fill the cache
1004 @param aFiles Number of files needed to fill the cache
1005 @param aFileSize The file size
1007 void FillCache(RFile aFile[KFilesNeededToFillCache], TInt aFiles, TInt aFileSize)
1011 TBuf16<50> directory;
1014 TBuf16<50> buffer(50);
1016 TPtr8 bufPtr(NULL, 0);
1018 TRAPD(res,buf = HBufC8::NewL(2));
1019 test(res == KErrNone && buf != NULL);
1020 bufPtr.Set(buf->Des());
1022 directory = gSessionPath;
1027 FileNameGen(buffer, 8, i+3) ;
1029 path.Append(buffer);
1030 r = aFile[i].Open(gTheFs,path,EFileShareAny|EFileRead|EFileReadBuffered|EFileReadAheadOff);
1034 while(j < aFileSize)
1036 r = aFile[i].Read(j,bufPtr);
1045 test.Printf(_L("Cache filled\n"));
1048 /** Fills the default cache
1051 void TestFillCache()
1053 TInt nFiles = KFilesNeededToFillCache;
1054 TInt fSize = KDefaultCacheSize;
1055 RFile file[KFilesNeededToFillCache];
1058 if(gMediaSize> ((fSize * nFiles)+gSecondFileSize+gFirstFileSize))
1060 test.Start(_L("Creating files for filling the cache\n"));
1061 CreateFiles(nFiles,fSize);
1062 #if defined(_DEBUG) || defined(_DEBUG_RELEASE)
1063 // get number of items on Page Cache
1064 TFileCacheStats startPageCacheStats;
1065 r = controlIo(gTheFs,gDrive, KControlIoFileCacheStats, startPageCacheStats);
1066 test_Value(r, r == KErrNone || r == KErrNotSupported);
1067 test.Printf(_L("Number of page cache lines on free list at beginning=%d\n"),startPageCacheStats.iFreeCount);
1068 test.Printf(_L("Number of page cache lines on used list at beginning=%d\n"),startPageCacheStats.iUsedCount);
1069 test.Printf(_L("Number of files on closed queue=%d\n"),startPageCacheStats.iFilesOnClosedQueue);
1071 FillCache(file,nFiles,fSize);
1073 #if defined(_DEBUG) || defined(_DEBUG_RELEASE)
1074 // get number of items on Page Cache
1075 r = controlIo(gTheFs,gDrive, KControlIoFileCacheStats, startPageCacheStats);
1076 test_Value(r, r == KErrNone || r == KErrNotSupported);
1077 test.Printf(_L("Number of page cache lines on free list at end=%d\n"),startPageCacheStats.iFreeCount);
1078 test.Printf(_L("Number of page cache lines on used list at end=%d\n"),startPageCacheStats.iUsedCount);
1079 test.Printf(_L("Number of files on closed queue=%d\n"),startPageCacheStats.iFilesOnClosedQueue);
1084 #if defined(_DEBUG) || defined(_DEBUG_RELEASE)
1085 // get number of items on Page Cache
1086 r = controlIo(gTheFs,gDrive, KControlIoFileCacheStats, startPageCacheStats);
1087 test_Value(r, r == KErrNone || r == KErrNotSupported);
1088 test.Printf(_L("Number of page cache lines on free list after the boundary testing=%d\n"),startPageCacheStats.iFreeCount);
1089 test.Printf(_L("Number of page cache lines on used list after the boundary testing=%d\n"),startPageCacheStats.iUsedCount);
1090 test.Printf(_L("Number of files on closed queue=%d\n"),startPageCacheStats.iFilesOnClosedQueue);
1094 while( i < KFilesNeededToFillCache )
1099 r = DeleteAllL(gSessionPath);
1105 test.Printf(_L("Skipping the fill of the cache due to lack of space in the current drive\n"));
1108 /** Fills the cache and generate error situations
1111 void TestFillCacheNegative()
1113 TInt nFiles = KFilesNeededToFillCache;
1116 if(gMediaSize> ((KDefaultCacheSize * nFiles)+gSecondFileSize+gFirstFileSize))
1118 #if defined(_DEBUG) || defined(_DEBUG_RELEASE)
1119 // get number of items on Page Cache
1120 TFileCacheStats startPageCacheStats;
1121 r = controlIo(gTheFs,gDrive, KControlIoFileCacheStats, startPageCacheStats);
1122 test_Value(r, r == KErrNone || r == KErrNotSupported);
1123 test.Printf(_L("Number of page cache lines on free list at beginning=%d\n"),startPageCacheStats.iFreeCount);
1124 test.Printf(_L("Number of page cache lines on used list at beginning=%d\n"),startPageCacheStats.iUsedCount);
1125 test.Printf(_L("Number of files on closed queue=%d\n"),startPageCacheStats.iFilesOnClosedQueue);
1127 test.Start(_L("Creating files for filling the cache, with uncommitted data\n"));
1129 TBuf<20> buf = _L("FillCache");
1131 r = gThread1.Create(buf,CreateFilesThread,KDefaultStackSize,KHeapSize,KMaxHeapSize,NULL);
1137 #if defined(_DEBUG) || defined(_DEBUG_RELEASE)
1138 // get number of items on Page Cache
1139 r = controlIo(gTheFs,gDrive, KControlIoFileCacheStats, startPageCacheStats);
1140 test_Value(r, r == KErrNone || r == KErrNotSupported);
1141 test.Printf(_L("Number of page cache lines on free list at end=%d\n"),startPageCacheStats.iFreeCount);
1142 test.Printf(_L("Number of page cache lines on used list at end=%d\n"),startPageCacheStats.iUsedCount);
1143 test.Printf(_L("Number of files on closed queue=%d\n"),startPageCacheStats.iFilesOnClosedQueue);
1148 #if defined(_DEBUG) || defined(_DEBUG_RELEASE)
1149 // get number of items on Page Cache
1150 r = controlIo(gTheFs,gDrive, KControlIoFileCacheStats, startPageCacheStats);
1151 test_Value(r, r == KErrNone || r == KErrNotSupported);
1152 test.Printf(_L("Number of page cache lines on free list after the boundary testing=%d\n"),startPageCacheStats.iFreeCount);
1153 test.Printf(_L("Number of page cache lines on used list after the boundary testing=%d\n"),startPageCacheStats.iUsedCount);
1154 test.Printf(_L("Number of files on closed queue=%d\n"),startPageCacheStats.iFilesOnClosedQueue);
1156 User::After(180000);
1158 r = controlIo(gTheFs,gDrive, KControlIoFileCacheStats, startPageCacheStats);
1159 test_Value(r, r == KErrNone || r == KErrNotSupported);
1160 test.Printf(_L("Number of page cache lines on free list after the boundary testing=%d\n"),startPageCacheStats.iFreeCount);
1161 test.Printf(_L("Number of page cache lines on used list after the boundary testing=%d\n"),startPageCacheStats.iUsedCount);
1162 test.Printf(_L("Number of files on closed queue=%d\n"),startPageCacheStats.iFilesOnClosedQueue);
1167 r = DeleteAllL(gSessionPath);
1172 test.Printf(_L("Skipping the fill of the cache due to lack of space in the current drive\n"));
1176 /** Manual test for card removal
1181 TInt time = 0, rtime = 0;
1185 TInt r = gClient.CreateLocal(0);
1188 r = gTheFs.SetSessionPath(gSessionPath);
1191 r = gTheFs.MkDirAll(gSessionPath);
1192 test_Value(r, r == KErrNone || r == KErrAlreadyExists);
1194 #if defined(_DEBUG) || defined(_DEBUG_RELEASE)
1195 test.Printf(_L("Disabling Lock Fail simulation ...\n"));
1196 // turn OFF lock failure mode
1197 TBool simulatelockFailureMode = EFalse;
1198 r = controlIo(gTheFs, gDrive, KControlIoSimulateLockFailureMode, simulatelockFailureMode);
1204 // FileNames/File generation
1205 test.Start(_L("Preparing the environmnet\n"));
1206 FileNameGen(gFirstFile, 8, gNextFile++);
1207 FileNameGen(gSecondFile, 8, gNextFile++);
1209 dir.Append(gFirstFile);
1212 dir.Append(gSecondFile);
1216 TRAPD(res,gBuf = HBufC8::NewL(KBlockSize+1));
1217 test(res == KErrNone && gBuf != NULL);
1219 gBufWritePtr.Set(gBuf->Des());
1220 FillBuffer(gBufWritePtr, KBlockSize, 'A');
1222 TRAPD(res2,gBufSec = HBufC8::NewL(KBlockSize+1));
1223 test(res2 == KErrNone && gBufSec != NULL);
1224 gBufReadPtr.Set(gBufSec->Des());
1227 test.Printf(_L("\nSync: Write from 1 K to 254 K \n"));
1229 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);
1231 test.Printf(_L("Remove MMC card,! and then press a key\n"));
1234 test.Printf(_L("Wait 3 seconds and insert MMC card! and then press a key\n"));
1237 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);
1240 test.Printf(_L("Remove MMC card! and then press a key\n"));
1243 test.Printf(_L("Wait 3 seconds and insert MMC card! and then press a key\n"));
1247 test.Printf(_L("\nSync: Write from 1 K to 255 K \n"));
1249 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);
1251 test.Printf(_L("Remove MMC card and delete the file //F32-TST//FFFFFFF0.TXT and then press a key\n"));
1254 test.Printf(_L("Wait 3 seconds and insert MMC card! and then press a key\n"));
1257 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);
1260 test.Printf(_L("Remove MMC card! and then press a key\n"));
1263 test.Printf(_L("Wait 3 seconds and insert MMC card! and then press a key\n"));
1274 /** Main tests function
1279 #if defined(_DEBUG) || defined(_DEBUG_RELEASE)
1280 test.Printf(_L("Disabling Lock Fail simulation ...\n"));
1281 // turn OFF lock failure mode
1282 TBool simulatelockFailureMode = EFalse;
1283 TInt r = controlIo(gTheFs, gDrive, KControlIoSimulateLockFailureMode, simulatelockFailureMode);
1289 // FileNames/File generation
1290 test.Start(_L("Preparing the environmnet\n"));
1291 FileNameGen(gFirstFile, 8, gNextFile++);
1292 FileNameGen(gSecondFile, 8, gNextFile++);
1294 dir.Append(gFirstFile);
1297 dir.Append(gSecondFile);
1301 TRAPD(res,gBuf = HBufC8::NewL(KBlockSize+1));
1302 test(res == KErrNone && gBuf != NULL);
1304 gBufWritePtr.Set(gBuf->Des());
1305 FillBuffer(gBufWritePtr, KBlockSize, 'A');
1307 TRAPD(res2,gBufSec = HBufC8::NewL(KBlockSize+1));
1308 test(res2 == KErrNone && gBufSec != NULL);
1309 gBufReadPtr.Set(gBufSec->Des());
1311 test.Next(_L("Boundary test"));
1314 test.Next(_L("Negative test\n"));
1317 test.Next(_L("Integrity test\n"));
1321 test.Next(_L("Fill the cache, boundary testing\n"));
1324 test.Next(_L("Fill the cache negative, boundary testing\n"));
1325 TestFillCacheNegative();
1331 #if defined(_DEBUG) || defined(_DEBUG_RELEASE)
1332 // turn lock failure mode back ON (if enabled)
1333 simulatelockFailureMode = ETrue;
1334 r = controlIo(gTheFs, gDrive, KControlIoSimulateLockFailureMode, simulatelockFailureMode);
1340 /** Initialises semaphores and call the tests
1346 r = gClient.CreateLocal(0);
1349 r = gTheFs.SetSessionPath(gSessionPath);
1352 r = gTheFs.MkDirAll(gSessionPath);
1353 test_Value(r, r == KErrNone || r == KErrAlreadyExists);
1354 gTheFs.ResourceCountMarkStart();
1356 TRAP(r,CallTestsL());
1359 gTheFs.ResourceCountMarkEnd();
1362 /** Determines the space that can be used for the files
1365 TBool CheckForDiskSize()
1367 TVolumeInfo volInfo;
1368 TInt r = gTheFs.Volume(volInfo, gDrive);
1370 gMediaSize = volInfo.iSize;
1372 test.Printf(_L("\nMedia size: %d MB\n"), gMediaSize/KOneMeg );
1379 @return KErrNone if everything was ok, panics otherwise
1384 gMainThreadId = t.Id();
1386 CTrapCleanup* cleanup;
1387 cleanup = CTrapCleanup::New();
1390 test.Start(_L("Starting tests... T_WCACHE"));
1393 TInt r = gTheFs.Connect();
1397 TVolumeInfo volInfo;
1398 r = gTheFs.Drive(info,gDrive);
1401 if(info.iMediaAtt&KMediaAttVariableSize)
1403 test.Printf(_L("Tests skipped in RAM drive\n"));
1407 r = gTheFs.Volume(volInfo, gDrive);
1408 if (r == KErrNotReady)
1410 if (info.iType == EMediaNotPresent)
1411 test.Printf(_L("%c: Medium not present - cannot perform test.\n"), (TUint)gDriveToTest);
1413 test.Printf(_L("%c: medium found (type %d) but drive not ready\nPrevious test may have hung; else, check hardware.\n"), (TUint)gDriveToTest, (TInt)info.iType);
1415 else if (r == KErrCorrupt)
1417 test.Printf(_L("%c: Media corruption; previous test may have aborted; else, check hardware\n"), (TUint)gDriveToTest);
1421 if(!(volInfo.iFileCacheFlags & (EFileCacheReadEnabled | EFileCacheReadAheadEnabled)))
1423 test.Printf(_L("Skipping tests, Read caching not enabled in this drive\n"));
1427 if (((volInfo.iDrive.iMediaAtt & KMediaAttFormattable)))
1428 Formatting(gDrive,ESpecialFormat);
1430 if(!CheckForDiskSize())
1432 test.Printf(_L("Skipping tests due to lack of space to perform them in this drive\n"));