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