kerneltest/f32test/server/t_fsys.cpp
changeset 270 ea2cef07f9fe
parent 254 1560c419b176
child 271 dc268b18d709
--- a/kerneltest/f32test/server/t_fsys.cpp	Tue Aug 31 11:40:45 2010 +0100
+++ b/kerneltest/f32test/server/t_fsys.cpp	Tue Sep 14 15:52:42 2010 +0100
@@ -30,6 +30,16 @@
 RTest test(_L("T_FSYS"));
 static TInt64   gRndSeed;
 
+_LIT(KTestFsy,  "T_TFSYS");
+_LIT(KTestFsy2, "T_TFSYS2");
+_LIT(KTestFsy3, "T_TFSYS3");
+
+_LIT(KTestFsName,  "Test");
+_LIT(KTestFsName2, "Test2");
+_LIT(KTestFsName3, "Test3");
+
+
+
 //---------------------------------------------------
 
 
@@ -53,10 +63,10 @@
 */
 void TestFileSystemNameLength()
 {
-    test.Next(_L("Test file system name lenght limits"));
+    test.Next(_L("Test file system name length limits\n"));
     if(Is_SimulatedSystemDrive(TheFs, CurrentDrive()))
     {
-        test.Printf(_L("Can't test on a simulated drive, skipping!"));
+        test.Printf(_L("Can't test on a simulated drive, skipping!\n"));
         return;
     }
 
@@ -176,26 +186,41 @@
     test_KErrNone(nRes);
 }
 
-
+//---------------------------------------------------
 static void TestFileSystemNames()
     {
-    test.Next(_L("Read file system names for all drives"));
+    test.Next(_L("TestFileSystemNames(). Read file system names for all drives\n"));
     TFullName name;
-    TInt r;
-    for(TInt i=EDriveA;i<KMaxDrives;++i)
+    TBuf<60>  buf;
+    TInt nRes;
+
+    TDriveList drvList;
+    nRes = TheFs.DriveList(drvList);
+    test_KErrNone(nRes);
+
+    for(TInt i=0; i<KMaxDrives; ++i)
         {
-        r=TheFs.FileSystemName(name,i);
-        test_Value(r, r == KErrNone || r==KErrNotFound);
-        TChar c;
-        r=RFs::DriveToChar(i,c);
-        test_KErrNone(r);
-        if(name.Length())       
-            test.Printf(_L("File System Name on drive %c is %S\n"),(char)c,&name);
+        buf.Format(_L("drv %C: att:0x%02x"), 'A'+i, drvList[i]);
+        
+        nRes = TheFs.FileSystemName(name, i);
+        test_Value(nRes, nRes == KErrNone || nRes==KErrNotFound);
+        
+        if(nRes == KErrNone)
+            {
+            buf.AppendFormat(_L(" Mounted FS:%S"), &name);
+            }
         else
-            test.Printf(_L("No file system on drive %c\n"),(char)c);
+            {
+            buf.Append(_L(" Mounted FS:"));
+            }
+
+        buf.Append(_L("\n"));
+        test.Printf(buf);
         }
+    
     }
 
+//---------------------------------------------------
 static void CheckDismount(TDesC& aFs,TInt aDrive)
     {
 
@@ -216,32 +241,32 @@
     TDriveInfo di;
     r=TheFs.Drive(di,aDrive);
     test_KErrNone(r);
-    b.Format(_L("Test dismounting of test file system on %c: (DrvAtt:%x MedAtt:%x)"),(TUint)c,di.iDriveAtt,di.iMediaAtt);
+    b.Format(_L("Test dismounting of test file system on %c: (DrvAtt:%x MedAtt:%x)\n"),(TUint)c,di.iDriveAtt,di.iMediaAtt);
     test.Next(b);
     
     // Test cannot dismount on rom drive
-    test.Next(_L("Test cannot dismount on Rom drive"));
+    test.Next(_L("Test cannot dismount on Rom drive\n"));
     TFullName zName;
     r=TheFs.FileSystemName(zName,EDriveZ);
     test_KErrNone(r);
     r=TheFs.DismountFileSystem(zName,EDriveZ);
-    test.Printf(_L("r=%d"),r);
+    test.Printf(_L("r=%d\n"),r);
     // NB if paging is enabled on a ROFS partition which is part of the composite file system then the 
     // likelihood is that there will be a at least one file clamped: in this case there error will be KErrInUse
     test_Value(r, r == KErrAccessDenied || r==KErrInUse);
 
     // Test cannot dismount on wrong drive
-    test.Next(_L("Test cannot dismount on wrong drive"));
+    test.Next(_L("Test cannot dismount on wrong drive\n"));
     r=TheFs.DismountFileSystem(aFs,EDriveA);
     test_Value(r, r == KErrNotReady);
 
     // Test cannot dismount with wrong name
-    test.Next(_L("Test cannot dismount with wrong file system name"));
+    test.Next(_L("Test cannot dismount with wrong file system name\n"));
     r=TheFs.DismountFileSystem(_L("abc"),aDrive);
     test_Value(r, r == KErrNotFound);
  
     // Test cannot dismount with a file open
-    test.Next(_L("Test cannot dismount with a file open"));
+    test.Next(_L("Test cannot dismount with a file open\n"));
     r=TheFs.SetSessionPath(newSess);
     RFile file;
     r=file.Replace(TheFs,_L("abc"),EFileShareAny);
@@ -256,11 +281,11 @@
     file.Close();
 
     // Now test dismount works
-    test.Next(_L("Test dismounts OK"));
+    test.Next(_L("Test dismounts OK\n"));
     r=TheFs.DismountFileSystem(aFs,aDrive);
     if(r!=KErrNone)
         {
-        test.Printf(_L("Error = %d"),r);    
+        test.Printf(_L("Error = %d\n"),r);    
         test(EFalse);
         }
     TFullName n;
@@ -289,7 +314,7 @@
 
 static void TestDismountFileSystem(TInt aDrive)
     {
-
+    test.Next(_L("TestDismountFileSystem()\n"));
     TInt r;
     TFullName name;
     r=TheFs.FileSystemName(name,aDrive);
@@ -298,12 +323,20 @@
         CheckDismount(name,aDrive);
     }
 
-#if defined(__EPOC32__)
-static void TestFileSystem(TInt aDrive)
+//---------------------------------------------------
 //
 // Mount a new CTestFileSystem on the drive under test
 //
+static void TestFileSystem(TInt aDrive)
     {
+    test.Next(_L("TestFileSystem()\n"));
+
+    if(Is_SimulatedSystemDrive(TheFs, aDrive))
+        {
+        test.Printf(_L("Can't test on a simulated drive, skipping!\n"));
+        return;
+        }
+
     TBuf<64> b;
     TChar c;
     TInt r=TheFs.DriveToChar(aDrive,c);
@@ -311,14 +344,14 @@
     TDriveInfo di;
     r=TheFs.Drive(di,aDrive);
     test_KErrNone(r);
-    b.Format(_L("Test mounting of test file system on %c: (DrvAtt:%x MedAtt:%x)"),(TUint)c,di.iDriveAtt,di.iMediaAtt);
+    b.Format(_L("Test mounting of test file system on %c: (DrvAtt:%x MedAtt:%x)\n"),(TUint)c,di.iDriveAtt,di.iMediaAtt);
     test.Next(b);
 
-    test.Next(_L("Test mounting of test file system"));
-    r=TheFs.AddFileSystem(_L("T_TFSYS"));
+    test.Next(_L("Test mounting of test file system\n"));
+    r=TheFs.AddFileSystem(KTestFsy);
     if(r!=KErrNone && r!=KErrAlreadyExists)
         {
-        test.Printf(_L("error=%d"),r);
+        test.Printf(_L("error=%d\n"),r);
         test(EFalse);
         }
 
@@ -330,35 +363,34 @@
     r=TheFs.DismountFileSystem(oldFs,aDrive);
     if(r!=KErrNone)
         {
-        test.Printf(_L("Error = %d"),r);    
+        test.Printf(_L("Error = %d\n"),r);    
         test(EFalse);
         }
-    r=TheFs.MountFileSystem(_L("Test"),aDrive);
+    r=TheFs.MountFileSystem(KTestFsName,aDrive);
     test_KErrNone(r);
 
     TFileName newFs;
     r=TheFs.FileSystemName(newFs,aDrive);
     test_KErrNone(r);
-    test(newFs.Compare(_L("Test"))==0);
+    test(newFs.Compare(KTestFsName)==0);
 
     // Check attributes
     TDriveInfo info;
     r=TheFs.Drive(info,aDrive);
     test_KErrNone(r);
  
-    test.Printf(_L("iType=%d,iConnectionBusType=%d,iDriveAtt=%x,iMediaAtt=%x\n"),(TUint)info.iType,\
-        (TUint)info.iConnectionBusType,info.iDriveAtt,info.iMediaAtt);
+    test.Printf(_L("iType=%d,iConnectionBusType=%d,iDriveAtt=%x,iMediaAtt=%x\n"),(TUint)info.iType, (TUint)info.iConnectionBusType,info.iDriveAtt,info.iMediaAtt);
 
     //Try to remove filesystem without dismounting.
-    r=TheFs.RemoveFileSystem(_L("Test"));
+    r=TheFs.RemoveFileSystem(KTestFsName);
     if(r!=KErrInUse)
         {
-        test.Printf(_L("error=%d"),r);
+        test.Printf(_L("error=%d\n"),r);
         test(EFalse);
         }
     r=TheFs.FileSystemName(newFs,aDrive);
     test_KErrNone(r);
-    test(newFs.Compare(_L("Test"))==0);
+    test(newFs.Compare(KTestFsName)==0);
 
     r=TheFs.DismountFileSystem(newFs,aDrive);
     test_KErrNone(r);
@@ -366,31 +398,33 @@
     r=TheFs.MountFileSystem(oldFs,aDrive);
     test_KErrNone(r);
     }
-#endif
 
+//---------------------------------------------------
 static void TestMountInvalidDrive()
-//
-// Attempt to mount FAT on non-local drive
     {
-    test.Start(_L("TestMountInvalidDrive"));
+    test.Next(_L("TestMountInvalidDrive(). Try mounting FS on an invalid drive\n"));
 
-    TInt r;
+    //-- 1. find an invalid drive
+    TInt drv = 0;
+    TDriveList drvList;
+    
+    TInt nRes = TheFs.DriveList(drvList);
+    test_KErrNone(nRes);
 
-    test.Next(_L("Adding EFAT"));
-#ifdef __WINS__
-    _LIT(KFsNm, "EFAT32");
-#else
-    _LIT(KFsNm, "ELOCAL");
-#endif
+    for(drv =0; drv<KMaxDrives; ++drv)
+        {
+        if(!drvList[drv])
+            break;
+        }
 
-    r = TheFs.AddFileSystem(KFsNm);
-    test.Printf(_L("afs: r = %d\n"), r);
-    test_Value(r, r == KErrNone || r == KErrAlreadyExists);
-    test.Next(_L("mounting FAT on drive R"));
-    r = TheFs.MountFileSystem(KFileSystemName_FAT, EDriveR);
-    test_Value(r, r == KErrArgument);
+    test.Printf(_L("Try mounting a test FS onto drive:%C:\n"), 'A'+drv);
+
+    nRes = TheFs.AddFileSystem(KTestFsy);
+    test_Value(nRes, nRes == KErrNone || nRes == KErrAlreadyExists);
+
+    nRes = TheFs.MountFileSystem(KTestFsName, drv);
+    test_Value(nRes, nRes == KErrArgument);
     
-    test.End();
     }
 
 // Additional step for INC083446: Corrupted miniSD not detected as corrupted by phone 
@@ -409,14 +443,14 @@
     TDriveInfo di;
     r=TheFs.Drive(di,aDrive);
     test_KErrNone(r);
-    b.Format(_L("Test mounting of test file system on %c: (DrvAtt:%x MedAtt:%x)"),(TUint)c,di.iDriveAtt,di.iMediaAtt);
+    b.Format(_L("Test mounting of test file system on %c: (DrvAtt:%x MedAtt:%x)\n"),(TUint)c,di.iDriveAtt,di.iMediaAtt);
     test.Next(b);
 
-    test.Next(_L("Test mounting of test file system"));
-    r=TheFs.AddFileSystem(_L("T_TFSYS2"));
+    test.Next(_L("Test mounting of test file system\n"));
+    r=TheFs.AddFileSystem(KTestFsy2);
     if(r!=KErrNone && r!=KErrAlreadyExists)
         {
-        test.Printf(_L("error=%d"),r);
+        test.Printf(_L("error=%d\n"),r);
         test(EFalse);
         }
 
@@ -426,16 +460,16 @@
     r=TheFs.DismountFileSystem(oldFs,aDrive);
     if(r!=KErrNone)
         {
-        test.Printf(_L("Error = %d"),r);    
+        test.Printf(_L("Error = %d\n"),r);    
         test(EFalse);
         }
-    r=TheFs.MountFileSystem(_L("Test2"),aDrive);
+    r=TheFs.MountFileSystem(KTestFsName2 ,aDrive);
     test_Value(r, r == KErrCorrupt);
 
     TFileName newFs;
     r=TheFs.FileSystemName(newFs,aDrive);
     test_KErrNone(r);
-    test(newFs.Compare(_L("Test2"))==0);
+    test(newFs.Compare(KTestFsName2)==0);
 
     // Get the number of remounts by checking the volume attributes -
     // T_TFSYS2 hijacks the iBattery member to report back the number of times MountL() has been called
@@ -446,7 +480,7 @@
     test.Printf(_L("iType=%d,iBattery=%d,iDriveAtt=%x,iMediaAtt=%x\n"),(TUint)info.iType,\
         (TUint)info.iBattery,info.iDriveAtt,info.iMediaAtt);
     remounts = (TInt) info.iBattery;
-    test.Printf(_L("Initial remounts = %d"), remounts);
+    test.Printf(_L("Initial remounts = %d\n"), remounts);
 
     // Make the file server attempt to remount the drive by looking for a non-existant DLL
     // The file server should setop trying to remount the driver after KMaxMountFailures attempts
@@ -465,7 +499,7 @@
     test.Printf(_L("iType=%d,iBattery=%d,iDriveAtt=%x,iMediaAtt=%x\n"),(TUint)info.iType,\
         (TUint)info.iBattery,info.iDriveAtt,info.iMediaAtt);
     remounts = (TInt) info.iBattery;
-    test.Printf(_L("Remounts = %d"), remounts);
+    test.Printf(_L("Remounts = %d\n"), remounts);
     test(remounts ==  KMaxMountFailures);
     
     // simulate a media change to reset failure count
@@ -484,7 +518,7 @@
     test.Printf(_L("iType=%d,iBattery=%d,iDriveAtt=%x,iMediaAtt=%x\n"),(TUint)info.iType,\
         (TUint)info.iBattery,info.iDriveAtt,info.iMediaAtt);
     remounts = (TInt) info.iBattery;
-    test.Printf(_L("Remounts = %d"), remounts);
+    test.Printf(_L("Remounts = %d\n"), remounts);
     test(remounts ==  KMaxMountFailures * 2);
     
 
@@ -494,10 +528,10 @@
     r=TheFs.MountFileSystem(oldFs,aDrive);
     test_KErrNone(r);
     
-    r=TheFs.RemoveFileSystem(_L("Test2"));
+    r=TheFs.RemoveFileSystem(KTestFsName2);
     if(r!=KErrNone)
         {
-        test.Printf(_L("error=%d"),r);
+        test.Printf(_L("error=%d\n"),r);
         test(EFalse);
         }
     }
@@ -508,7 +542,7 @@
 */
 static void TestSubstDriveMediaSerialNumber()
 {
-    test.Next(_L("Test obtaining media serial number for the substituted drives"));
+    test.Next(_L("Test obtaining media serial number for the substituted drives\n"));
 
     TInt  nRes;
     const TInt currDrvNum=CurrentDrive();
@@ -587,7 +621,7 @@
 //----------------------------------------------------------------------------------------------
 static void TestFileSystemSubTypeQuery()
     {
-    test.Next(_L("Test querying sub type of the mounted file system"));
+    test.Next(_L("Test querying sub type of the mounted file system\n"));
     TFSName fsName;
     TPckgBuf<TFSName> subName;
     TInt i, r;
@@ -690,7 +724,7 @@
 //----------------------------------------------------------------------------------------------
 static void TestFileSystemClusterSizeQuery()
     {
-    test.Next(_L("Test querying cluster size information of the mounted file system"));
+    test.Next(_L("Test querying cluster size information of the mounted file system\n"));
     TFullName fsName;
     TPckgBuf<TVolumeIOParamInfo> ioInfo;
     TInt i, r;
@@ -795,12 +829,12 @@
 //----------------------------------------------------------------------------------------------
 static void TestMediaBlockSizeQuery()
     {
-    test.Next(_L("Test querying block size information of the underlying media"));
+    test.Next(_L("Test querying block size information of the underlying media\n"));
     #if defined(__WINS__)
-        test.Printf(_L("This test case runs on hardware only"));
+        test.Printf(_L("This test case runs on hardware only\n"));
         return;
-    
     #else   // test runs on hardware only.
+ 
     TFSName fsName;
     TPckgBuf<TVolumeIOParamInfo> ioInfo;
     TInt i, r;
@@ -914,7 +948,7 @@
 //----------------------------------------------------------------------------------------------
 static void TestFileSystemSubType()
     {
-    test.Next(_L("Test wrapper API RFs::FileSystemSubType()'s behaviour"));
+    test.Next(_L("Test wrapper API RFs::FileSystemSubType()'s behaviour\n"));
     TFSName fsName;
     TPckgBuf<TFSName> subName;
     TInt r;
@@ -956,7 +990,7 @@
 //----------------------------------------------------------------------------------------------
 static void TestVolumeIOParam()
     {
-    test.Next(_L("Test wrapper API RFs::VolumeIOParam()'s behaviour"));
+    test.Next(_L("Test wrapper API RFs::VolumeIOParam()'s behaviour\n"));
     TFSName fsName;
     TPckgBuf<TVolumeIOParamInfo> ioInfo;
     TInt r;
@@ -1005,11 +1039,11 @@
     test.Printf(_L("Tested on drive: %c.\n"), (char)(aDrive+'A'));
 
     // Mount a new CTestFileSystem on the drive under test
-    test.Next(_L("Test RFs::QueryVolumeInfoExt() on Testing File System"));
-    r = TheFs.AddFileSystem(_L("T_TFSYS3"));
+    test.Next(_L("Test RFs::QueryVolumeInfoExt() on Testing File System\n"));
+    r = TheFs.AddFileSystem(KTestFsy3);
     if (r != KErrNone && r != KErrAlreadyExists)
         {
-        test.Printf(_L("error=%d"),r);
+        test.Printf(_L("error=%d\n"),r);
         test(EFalse);
         }
     TFSName oldFs;
@@ -1018,15 +1052,15 @@
     r = TheFs.DismountFileSystem(oldFs,aDrive);
     if (r != KErrNone)
         {
-        test.Printf(_L("Error = %d"),r);    
+        test.Printf(_L("Error = %d\n"),r);    
         test(EFalse);
         }
-    r = TheFs.MountFileSystem(_L("Test3"),aDrive);
+    r = TheFs.MountFileSystem(KTestFsName3, aDrive);
     test_KErrNone(r);
     TFSName newFs;
     r = TheFs.FileSystemName(newFs,aDrive);
     test_KErrNone(r);
-    test(newFs.Compare(_L("Test3"))==0);
+    test(newFs.Compare(KTestFsName3)==0);
 
     // Sub type name query: 
     TPckgBuf<TFSName> subNameP;
@@ -1046,10 +1080,10 @@
     r=TheFs.MountFileSystem(oldFs,aDrive);
     test_KErrNone(r);
     
-    r=TheFs.RemoveFileSystem(_L("Test3"));
+    r=TheFs.RemoveFileSystem(KTestFsName3);
     if(r!=KErrNone)
         {
-        test.Printf(_L("error=%d"),r);
+        test.Printf(_L("error=%d\n"),r);
         test(EFalse);
         }
     }
@@ -1068,7 +1102,21 @@
 {
     test.Next(_L("Testing forcedly remounting FS with objects opened.\n"));
     
+    //-- don't perform this test on a non-removable drive, generating media change on such drive
+    //-- doesn't always work
     TInt nRes;
+    const TInt drvNumber = CurrentDrive();
+    TDriveInfo driveInfo;
+
+    nRes = TheFs.Drive(driveInfo, drvNumber);
+    test_KErrNone(nRes);
+
+    if(! (driveInfo.iDriveAtt & KDriveAttRemovable))
+    {
+        test.Printf(_L("Can't perform this test on a non-removable drive. Skippping!\n"));
+        return;
+    }
+
     
     //-- 1. create a file
     _LIT(KFile, "\\test_file.file");
@@ -1083,7 +1131,7 @@
     nRes = file.Open(TheFs, KFile, EFileRead);
     test_KErrNone(nRes);
     
-    const TInt drvNumber = CurrentDrive();
+    
 
     //-- 2.1 try to dismount the FS, it must fail because of the opened object.
     TBuf<40> fsName;
@@ -1097,14 +1145,14 @@
     const TUint KMediaRemountForceMediaChange = 0x00000001;
     TRequestStatus changeStatus;
     TheFs.NotifyChange(ENotifyAll, changeStatus);
-    TDriveInfo driveInfo;
+    
     
     //-- 3. forcedly remount the drive
     nRes = TheFs.RemountDrive(drvNumber, NULL, KMediaRemountForceMediaChange);
     
     if(nRes == KErrNotSupported)
     	{//-- this feature is not supported and the test is inconsistent.
-        test.Printf(_L("RemountDrive() is not supported, the test is inconsistent!"));
+        test.Printf(_L("RemountDrive() is not supported, the test is inconsistent!\n"));
         
         //-- remounting must work at least on MMC drives
         const TBool isFAT = Is_Fat(TheFs, drvNumber);
@@ -1117,6 +1165,7 @@
     else
     	{
 		test_Value(nRes, nRes == KErrNotReady || nRes == KErrNone);
+		test.Printf(_L("Waiting for the simulated media change...\n"));
 		
 		//-- 3.1 wait for media change to complete
 		do
@@ -1152,7 +1201,7 @@
 //----------------------------------------------------------------------------------------------
 static void TestFileSystem_MaxSupportedFileSizeQuery()
 {
-    test.Next(_L("Test querying max. supported file size on this file system"));
+    test.Next(_L("Test querying max. supported file size on this file system\n"));
     TFullName fsName;
     TPckgBuf<TVolumeIOParamInfo> ioInfo;
     TVolumeIOParamInfo& volInfo = ioInfo();
@@ -1183,33 +1232,28 @@
 }
 
 //----------------------------------------------------------------------------------------------
-GLDEF_C void CallTestsL()
-//
-// Do all tests
-//
+void CallTestsL()
     {
 
     //-- set up console output 
     Fat_Test_Utils::SetConsole(test.Console()); 
 
-    TInt drive=CurrentDrive();
-
+    const TInt drive=CurrentDrive();
     PrintDrvInfo(TheFs, drive);
 
-    //Do not run this test on the NAND drive, as
-    //this has the FTL mounted as a primary extension
+    //Do not run this test on the NAND drive, as this has the FTL mounted as a primary extension
     //which causes the test to fail
-    #if defined(__WINS__)
-        if (drive==EDriveU)
-            return;
-    #else
-        TDriveInfo driveInfo;
-        TheFs.Drive(driveInfo,drive);
-        if (driveInfo.iType == EMediaNANDFlash)
-            {
-            return;
-            }
-    #endif
+    
+    TFSName pExtName;
+    pExtName.Zero();
+   
+    TInt nRes = TheFs.ExtensionName(pExtName, drive, 0);
+   
+    if(nRes == KErrNone && pExtName.Length())
+        {
+        test.Printf(_L("This test can't be run on a drive that has a primary extension:%S\n"), &pExtName);   
+        return;
+        }
 
     //---------------------------------------
 
@@ -1219,12 +1263,8 @@
     TestFileSystemNames();
     TestFileSystemNameLength();
     TestDismountFileSystem(CurrentDrive());
-#if defined(__EPOC32__)
     TestFileSystem(CurrentDrive());
-#endif
-
     TestMountInvalidDrive();
-    
     TestMountingBrokenMedia(CurrentDrive());
     TestSubstDriveMediaSerialNumber();
 
@@ -1234,9 +1274,7 @@
     TestFileSystemSubType();
     TestVolumeIOParam();
     TestQueryVolumeInfoExtOnTestFS(CurrentDrive());
-
     TestFileSystem_MaxSupportedFileSizeQuery();
-
     TestRemountFSWithOpenedObjects();
 
     //---------------------------------------