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