Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // f32test\manager\t_notifydismount.cpp
26 LOCAL_D TFullName fsname;
28 LOCAL_D TRequestStatus stat;
29 LOCAL_D TBuf8<0x10> buf;
31 GLDEF_D RTest test(_L("t_notifydismount"));
34 const TInt KControlIoRuggedOn=2;
35 const TInt KControlIoRuggedOff=3;
36 const TInt KControlIoIsRugged=4;
40 LOCAL_C void TestFileHandleClosure(TInt aDrvNum)
42 // check that open file handles may be closed following a NotifyDismount in
43 // forced dismount mode
46 test.Next( _L("Test File Handle Closure"));
48 TInt r = file.Replace(TheFs, fn, EFileWrite);
50 r = TheFs.FileSystemName(fsname,aDrvNum);
52 buf = _L8("handle test23456");
55 TheFs.NotifyDismount(aDrvNum, stat, EFsDismountForceDismount);
56 User::WaitForRequest(stat);
57 test(stat.Int() == KErrNone);
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
62 test(r == KErrNotReady || r == KErrDisMounted);
64 // PDEF091956 was a file server fault EFsDriveThreadError when the file
67 r = TheFs.MountFileSystem(fsname,aDrvNum);
72 LOCAL_C void TestRequestCancelling(TInt aDrvNum)
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 ...
78 test.Next( _L("Test Request Cancelling") );
80 TInt r = TheFs.FileSystemName(fsname,aDrvNum);
83 //***************************************
84 // first test with an open file handle
85 //***************************************
86 r = file.Replace(TheFs, fn, EFileWrite);
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
92 thisThread.SetPriority(EPriorityRealTime);
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);
99 // Post a TFsCloseObject do drive thread - this should be cancelled before it is processed
100 // by the earlier TFsNotifyDismount
103 User::WaitForRequest(stat);
104 test(stat.Int() == KErrNone);
106 thisThread.SetPriority(EPriorityNormal);
108 r = TheFs.MountFileSystem(fsname,aDrvNum);
112 //***************************************
113 // now test with an open directory handle
114 //***************************************
117 TFileName sessionPath;
118 r=TheFs.SessionPath(sessionPath);
120 TFileName path=_L("?:\\*");
121 path[0]=sessionPath[0];
122 r=dir.Open(TheFs,path,KEntryAttMaskSupported);
125 thisThread.SetPriority(EPriorityRealTime);
126 TheFs.NotifyDismount(aDrvNum, stat, EFsDismountForceDismount);
129 User::WaitForRequest(stat);
130 test(stat.Int() == KErrNone);
132 thisThread.SetPriority(EPriorityNormal);
134 r = TheFs.MountFileSystem(fsname,aDrvNum);
139 LOCAL_C void TestFileSizeFlushing(TInt aDrvNum)
141 // check that new file sizes are flushed during a NotifyDismount in forced
145 test.Next( _L("Test File Size Flushing with EFsDismountForceDismount") );
148 TInt r = file.Replace(TheFs, fn, EFileWrite);
150 r = TheFs.FileSystemName(fsname,aDrvNum);
152 buf = _L8("size test9123456");
159 TheFs.NotifyDismount(aDrvNum, stat, EFsDismountForceDismount);
160 User::WaitForRequest(stat);
161 test(stat.Int() == KErrNone);
163 r = TheFs.MountFileSystem(fsname,aDrvNum);
165 file.Open(TheFs, fn, EFileWrite);
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.
173 test.Next( _L("Test File Size Flushing with EFsDismountNotifyClients") );
175 r = file.Replace(TheFs, fn, EFileWrite);
184 TheFs.NotifyDismount(aDrvNum, stat, EFsDismountNotifyClients);
185 User::WaitForRequest(stat);
187 test(stat.Int() == KErrNone);
190 r = TheFs.MountFileSystem(fsname,aDrvNum);
192 file.Open(TheFs, fn, EFileWrite);
200 LOCAL_C void TestNotifyCancel(TInt aDrvNum)
204 test.Next( _L("Test Cancelling a notifier"));
206 TRequestStatus status;
207 TheFs.NotifyDismount( aDrvNum, status, EFsDismountRegisterClient );
208 TheFs.NotifyDismountCancel(status);
209 User::WaitForRequest( status );
210 test(status.Int() == KErrCancel);
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
215 thisThread.SetPriority(EPriorityRealTime);
216 TheFs.NotifyDismount( aDrvNum, status, EFsDismountRegisterClient );
217 TheFs.NotifyDismountCancel(status);
218 User::WaitForRequest( status );
219 test(status.Int() == KErrCancel);
222 GLDEF_C void CallTestsL()
224 // Call tests that may leave
230 r=TheFs.CharToDrive(gDriveToTest,drvNum);
234 // dismounting with file system extension present doesn't seem to work
235 // so skip the test for now.
237 r = TheFs.ExtensionName(extName,drvNum, 0);
240 test.Printf(_L("File system extension present (%S). Skipping test.\n"), &extName);
245 fn.Format(_L("%c:\\notifydismount.tst"), TUint(gDriveToTest));
247 test.Start( _L("Test Notify Dismount") );
250 // the EFsDriveThreadError file server fault (PDEF091956) was only detected
252 TestFileHandleClosure(drvNum);
253 TestRequestCancelling(drvNum);
255 test.Printf(_L("CallTestsL: Skip TestFileHandleClosure - urel mode.\n"));
258 TestNotifyCancel(drvNum);
261 // failure to observe flushing of file size (PDEF091956) only observed
263 // debug mode required to determine rugged or non rugged FAT and to switch between these
265 if (IsFileSystemFAT(TheFs,drvNum) || IsFileSystemFAT32(TheFs,drvNum))
267 // next test requires rugged fat off
269 TPtr8 pRugged(&isRugged,1,1);
270 r=TheFs.ControlIo(drvNum,KControlIoIsRugged,pRugged);
274 r=TheFs.ControlIo(drvNum,KControlIoRuggedOff);
278 TestFileSizeFlushing(drvNum);
280 // if originally rugged set system back to rugged
283 r=TheFs.ControlIo(drvNum,KControlIoRuggedOn);
289 test.Printf(_L("CallTestsL: Skip TestFileSizeFlushing - not a FAT filesystem.\n"));
292 test.Printf(_L("CallTestsL: Skip TestFileSizeFlushing - urel mode.\n"));