kerneltest/f32test/server/t_notifydismount.cpp
changeset 0 a41df078684a
child 109 b3a1d9898418
equal deleted inserted replaced
-1:000000000000 0:a41df078684a
       
     1 // Copyright (c) 1997-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".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // f32test\manager\t_notifydismount.cpp
       
    15 // 
       
    16 //
       
    17 
       
    18 #include <f32file.h>
       
    19 #include <e32test.h>
       
    20 #include <e32hal.h>
       
    21 #include <e32math.h>
       
    22 #include <f32dbg.h>
       
    23 #include <hal.h>
       
    24 #include "t_server.h"
       
    25 
       
    26 LOCAL_D TFullName fsname;
       
    27 LOCAL_D	RFile file; 
       
    28 LOCAL_D TRequestStatus stat;
       
    29 LOCAL_D	TBuf8<0x10> buf; 
       
    30 LOCAL_D	TFileName fn;
       
    31 GLDEF_D	RTest test(_L("t_notifydismount"));
       
    32 
       
    33 #if defined(_DEBUG)
       
    34 const TInt KControlIoRuggedOn=2;
       
    35 const TInt KControlIoRuggedOff=3;
       
    36 const TInt KControlIoIsRugged=4;
       
    37 #endif
       
    38 
       
    39 #if defined(_DEBUG)
       
    40 LOCAL_C void TestFileHandleClosure(TInt aDrvNum)
       
    41 //
       
    42 // check that open file handles may be closed following a NotifyDismount in
       
    43 // forced dismount mode
       
    44 //	
       
    45 {
       
    46 	test.Next( _L("Test File Handle Closure"));
       
    47 
       
    48 	TInt r = file.Replace(TheFs, fn, EFileWrite); 
       
    49 	test(r == KErrNone); 
       
    50 	r = TheFs.FileSystemName(fsname,aDrvNum);
       
    51 	test(r == KErrNone); 
       
    52 	buf = _L8("handle test23456");
       
    53 	r = file.Write(buf); 
       
    54 	test(r == KErrNone); 
       
    55 	TheFs.NotifyDismount(aDrvNum, stat, EFsDismountForceDismount); 
       
    56 	User::WaitForRequest(stat);         
       
    57 	test(stat.Int() == KErrNone);
       
    58 
       
    59 	// PDEF137626 Connectivity: Phone reboots automatically when connecting to PC via USB after pl 
       
    60 	// Check that writing data to a file when the drive is dismounted doesn't upset the file server
       
    61 	r = file.Write(buf); 
       
    62 	test(r == KErrNotReady || r == KErrDisMounted); 
       
    63 
       
    64 	// PDEF091956 was a file server fault EFsDriveThreadError when the file 
       
    65 	// handle was closed
       
    66 	file.Close(); 
       
    67 	r = TheFs.MountFileSystem(fsname,aDrvNum);
       
    68 	test(r == KErrNone); 
       
    69 }
       
    70 
       
    71 
       
    72 LOCAL_C void TestRequestCancelling(TInt aDrvNum)
       
    73 //
       
    74 // check that Cancelling all drive thread requests allows File server object to be closed down gracefully
       
    75 // PDEF101895- Device crash in efile.exe when plugging/unplugging USB cable using fast file ... 
       
    76 //
       
    77 	{
       
    78 	test.Next( _L("Test Request Cancelling") );
       
    79 
       
    80 	TInt r = TheFs.FileSystemName(fsname,aDrvNum);
       
    81 	test(r == KErrNone); 
       
    82 	
       
    83 	//***************************************
       
    84 	// first test with an open file handle
       
    85 	//***************************************
       
    86 	r = file.Replace(TheFs, fn, EFileWrite); 
       
    87 	test(r == KErrNone); 
       
    88 
       
    89 	// up the priority of this thread so that we can queue 2 requests onto the drive thread - 
       
    90 	// i.e. a TFsNotifyDismount and a TFsCloseObject
       
    91 	RThread				thisThread;
       
    92 	thisThread.SetPriority(EPriorityRealTime);
       
    93 
       
    94 	// Post a TFsNotifyDismount do drive thread - this will cancel all requests when it runs
       
    95 	// including the subsequent TFsCloseObject...
       
    96 	TheFs.NotifyDismount(aDrvNum, stat, EFsDismountForceDismount); 
       
    97 
       
    98 	
       
    99 	// Post a TFsCloseObject do drive thread - this should be cancelled before it is processed
       
   100 	// by the earlier TFsNotifyDismount
       
   101 	file.Close();
       
   102 
       
   103 	User::WaitForRequest(stat);         
       
   104 	test(stat.Int() == KErrNone);
       
   105 	
       
   106 	thisThread.SetPriority(EPriorityNormal);
       
   107 
       
   108 	r = TheFs.MountFileSystem(fsname,aDrvNum);
       
   109 	test(r == KErrNone); 
       
   110 
       
   111 
       
   112 	//***************************************
       
   113 	// now test with an open directory handle
       
   114 	//***************************************
       
   115 
       
   116 	RDir dir;
       
   117 	TFileName sessionPath;
       
   118 	r=TheFs.SessionPath(sessionPath);
       
   119 	test(r==KErrNone);
       
   120 	TFileName path=_L("?:\\*");
       
   121 	path[0]=sessionPath[0];
       
   122 	r=dir.Open(TheFs,path,KEntryAttMaskSupported);
       
   123 	test(r==KErrNone);
       
   124 
       
   125 	thisThread.SetPriority(EPriorityRealTime);
       
   126 	TheFs.NotifyDismount(aDrvNum, stat, EFsDismountForceDismount); 
       
   127 	dir.Close();
       
   128 
       
   129 	User::WaitForRequest(stat);         
       
   130 	test(stat.Int() == KErrNone);
       
   131 	
       
   132 	thisThread.SetPriority(EPriorityNormal);
       
   133 
       
   134 	r = TheFs.MountFileSystem(fsname,aDrvNum);
       
   135 	test(r == KErrNone); 
       
   136 	}
       
   137 
       
   138 
       
   139 LOCAL_C void TestFileSizeFlushing(TInt aDrvNum)
       
   140 //
       
   141 // check that new file sizes are flushed during a NotifyDismount in forced
       
   142 // dismount mode
       
   143 //	 
       
   144 	{	
       
   145 	test.Next( _L("Test File Size Flushing with EFsDismountForceDismount") );
       
   146 
       
   147 	TInt size = 0;
       
   148 	TInt r = file.Replace(TheFs, fn, EFileWrite); 
       
   149 	test(r == KErrNone); 
       
   150 	r = TheFs.FileSystemName(fsname,aDrvNum);
       
   151 	test(r == KErrNone); 
       
   152 	buf = _L8("size test9123456"); 
       
   153 	r = file.Write(buf); 
       
   154 	test(r == KErrNone); 
       
   155 	r = file.Flush(); 
       
   156 	test(r == KErrNone); 
       
   157 	r = file.Write(buf); 
       
   158 	test(r == KErrNone); 
       
   159 	TheFs.NotifyDismount(aDrvNum, stat, EFsDismountForceDismount); 
       
   160 	User::WaitForRequest(stat);         
       
   161 	test(stat.Int() == KErrNone);
       
   162 	file.Close();
       
   163 	r = TheFs.MountFileSystem(fsname,aDrvNum);
       
   164 	test(r == KErrNone); 
       
   165 	file.Open(TheFs, fn, EFileWrite);
       
   166 	r = file.Size(size); 
       
   167 	test(r == KErrNone); 
       
   168 	// PDEF091956 was, for example, a file size of 16 rather than 32. new file sizes were
       
   169 	// not flushed for the forced dismount. this was only a problem with rugged fat off.
       
   170 	test(size == 32);
       
   171 	file.Close();
       
   172 
       
   173 	test.Next( _L("Test File Size Flushing with EFsDismountNotifyClients") );
       
   174 	size = 0;
       
   175 	r = file.Replace(TheFs, fn, EFileWrite); 
       
   176 	test(r == KErrNone); 
       
   177 
       
   178 	r = file.Write(buf); 
       
   179 	test(r == KErrNone); 
       
   180 
       
   181 	r = file.Write(buf); 
       
   182 	test(r == KErrNone); 
       
   183 
       
   184 	TheFs.NotifyDismount(aDrvNum, stat, EFsDismountNotifyClients); 
       
   185 	User::WaitForRequest(stat);
       
   186 
       
   187 	test(stat.Int() == KErrNone);
       
   188 	file.Close();
       
   189 
       
   190 	r = TheFs.MountFileSystem(fsname,aDrvNum);
       
   191 	test(r == KErrNone); 
       
   192 	file.Open(TheFs, fn, EFileWrite);
       
   193 	r = file.Size(size); 
       
   194 	test(r == KErrNone); 
       
   195 	test(size == 32);
       
   196 	file.Close();
       
   197 	}
       
   198 #endif
       
   199 
       
   200 LOCAL_C void TestNotifyCancel(TInt aDrvNum)
       
   201 //
       
   202 //	
       
   203 	{
       
   204 	test.Next( _L("Test Cancelling a notifier"));
       
   205 
       
   206 	TRequestStatus status;
       
   207 	TheFs.NotifyDismount( aDrvNum, status, EFsDismountRegisterClient );
       
   208 	TheFs.NotifyDismountCancel(status);
       
   209 	User::WaitForRequest( status );
       
   210 	test(status.Int() == KErrCancel);
       
   211 
       
   212 	// up the priority of this thread so that we can queue 2 requests onto the drive thread - 
       
   213 	// to test CNotifyInfo objects are cleaned up correctly even if the drive thread doesn't run
       
   214 	RThread	thisThread;
       
   215 	thisThread.SetPriority(EPriorityRealTime);
       
   216 	TheFs.NotifyDismount( aDrvNum, status, EFsDismountRegisterClient );
       
   217 	TheFs.NotifyDismountCancel(status);
       
   218 	User::WaitForRequest( status );
       
   219 	test(status.Int() == KErrCancel);
       
   220 	}
       
   221 
       
   222 GLDEF_C void CallTestsL()
       
   223 //
       
   224 // Call tests that may leave
       
   225 //
       
   226 	{
       
   227 	test.Title();
       
   228 	TInt drvNum, r;
       
   229 
       
   230 	r=TheFs.CharToDrive(gDriveToTest,drvNum);
       
   231 	test(r==KErrNone);
       
   232 
       
   233 
       
   234 	// dismounting with file system extension present doesn't seem to work
       
   235 	// so skip the test for now.
       
   236 	TFullName extName;
       
   237 	r = TheFs.ExtensionName(extName,drvNum, 0);
       
   238 	if (r == KErrNone)
       
   239 		{
       
   240 		test.Printf(_L("File system extension present (%S). Skipping test.\n"), &extName);
       
   241 		return;
       
   242 		}
       
   243 
       
   244 	
       
   245 	fn.Format(_L("%c:\\notifydismount.tst"), TUint(gDriveToTest));
       
   246 
       
   247 	test.Start( _L("Test Notify Dismount") );
       
   248 
       
   249 #if defined(_DEBUG)
       
   250 	// the EFsDriveThreadError file server fault (PDEF091956) was only detected 
       
   251 	// in debug mode
       
   252  	TestFileHandleClosure(drvNum);
       
   253 	TestRequestCancelling(drvNum);
       
   254 #else
       
   255 	test.Printf(_L("CallTestsL: Skip TestFileHandleClosure - urel mode.\n"));
       
   256 #endif
       
   257 	
       
   258 	TestNotifyCancel(drvNum);
       
   259 
       
   260 #if defined(_DEBUG)
       
   261 	// failure to observe flushing of file size (PDEF091956) only observed 
       
   262 	// in debug mode
       
   263 	// debug mode required to determine rugged or non rugged FAT and to switch between these 
       
   264 	// modes 
       
   265 	if (IsFileSystemFAT(TheFs,drvNum) || IsFileSystemFAT32(TheFs,drvNum))
       
   266 		{
       
   267 		// next test requires rugged fat off
       
   268 		TUint8 isRugged;
       
   269 		TPtr8 pRugged(&isRugged,1,1);
       
   270 		r=TheFs.ControlIo(drvNum,KControlIoIsRugged,pRugged);
       
   271 		test(r==KErrNone);
       
   272 		if(isRugged)
       
   273 			{
       
   274 			r=TheFs.ControlIo(drvNum,KControlIoRuggedOff);
       
   275 			test(r==KErrNone);
       
   276 			}
       
   277 
       
   278 		TestFileSizeFlushing(drvNum);
       
   279 	
       
   280 		// if originally rugged set system back to rugged
       
   281 		if(isRugged)
       
   282 			{
       
   283 			r=TheFs.ControlIo(drvNum,KControlIoRuggedOn);
       
   284 			test(r==KErrNone);
       
   285 			}	
       
   286 		}
       
   287 	else
       
   288 		{
       
   289 		test.Printf(_L("CallTestsL: Skip TestFileSizeFlushing - not a FAT filesystem.\n"));
       
   290 		}
       
   291 #else 
       
   292 		test.Printf(_L("CallTestsL: Skip TestFileSizeFlushing - urel mode.\n"));
       
   293 #endif
       
   294 
       
   295 	test.End();
       
   296  
       
   297 	}