author | Mike Kinghan <mikek@symbian.org> |
Mon, 19 Jul 2010 08:40:05 +0100 | |
branch | GCC_SURGE |
changeset 209 | 6035754ebf88 |
parent 109 | b3a1d9898418 |
child 220 | 14267bc009a6 |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 1998-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\server\t_dspace.cpp |
|
15 |
// |
|
16 |
// |
|
17 |
||
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
18 |
#define __E32TEST_EXTENSION__ |
0 | 19 |
#include <f32file.h> |
20 |
#include <e32test.h> |
|
21 |
#include "t_server.h" |
|
22 |
#include "t_chlffs.h" |
|
23 |
||
24 |
||
25 |
/* This tests disk space notification. Using RFs::NotifyDiskSpace a client can request |
|
26 |
to be notified if the free disk space crosses a specified threshold. This test requires |
|
27 |
a card to be present in d: */ |
|
28 |
||
29 |
GLDEF_D RTest test(_L("T_DSPACE")); |
|
30 |
||
31 |
const TInt KMaxBufSize=512; |
|
32 |
#if defined(__WINS__) |
|
33 |
TInt KFileSize1=2048; |
|
34 |
TInt KFileSize2=4096; |
|
35 |
TInt KFileSize3=8192; |
|
36 |
#else |
|
37 |
TInt KFileSize1=512; |
|
38 |
TInt KFileSize2=1024; |
|
39 |
TInt KFileSize3=4096; |
|
40 |
#endif |
|
41 |
||
42 |
const TInt KHeapSize=0x2000; |
|
43 |
const TInt KStackSize=0x4000; |
|
44 |
||
45 |
TInt gMinFileSize; |
|
46 |
||
47 |
TBool LffsDrive = EFalse; |
|
48 |
||
49 |
TBuf8<KMaxBufSize> TheBuffer; |
|
50 |
TInt64 TheDiskSize; |
|
51 |
TInt RemovableDrive; |
|
52 |
TBuf<4> RemovableDriveBuf=_L("?:\\"); |
|
53 |
||
54 |
_LIT(KTestFile1, "\\F32-TST\\testfile1"); |
|
55 |
_LIT(KTestFile2, "\\F32-TST\\testFile2"); |
|
56 |
_LIT(KTestDir1, "\\F32-TST\\testDir1\\"); |
|
57 |
_LIT(KTestDir2, "\\F32-TST\\testDir2\\"); |
|
58 |
_LIT(KFileFiller, "\\F32-TST\\fileFiller"); |
|
59 |
||
60 |
// functions that may cause change in free disk space |
|
61 |
// not all of them of tested since some require knowledge of file system |
|
62 |
// to ensure change in free disk space |
|
63 |
enum TThreadTask |
|
64 |
{ |
|
65 |
ETaskSetVolume, |
|
66 |
ETaskMkDir, |
|
67 |
ETaskRmDir, |
|
68 |
ETaskDelete, // test |
|
69 |
ETaskRename, |
|
70 |
ETaskReplace, // test |
|
71 |
ETaskFileCreate, |
|
72 |
ETaskFileReplace, // test |
|
73 |
ETaskFileTemp, |
|
74 |
ETaskFileWrite, // test |
|
75 |
ETaskFileWrite4KB, |
|
76 |
ETaskFileWrite64KB, |
|
77 |
ETaskFileSetSize, // test |
|
78 |
ETaskFileRename, |
|
79 |
ETaskNoChange1, |
|
80 |
ETaskNoChange2, |
|
81 |
ETaskFileCreateLffs,// test |
|
82 |
ETaskSpin |
|
83 |
}; |
|
84 |
||
85 |
||
86 |
LOCAL_C TBool IsWinsCDrive(TInt aDrive) |
|
87 |
// |
|
88 |
// |
|
89 |
// |
|
90 |
{ |
|
91 |
#if defined(__WINS__) |
|
92 |
if(aDrive==KDefaultDrive) |
|
93 |
return(gSessionPath[0]==(TText)'C'); |
|
94 |
else |
|
95 |
return(aDrive==EDriveC); |
|
96 |
#else |
|
97 |
return(EFalse); |
|
98 |
#endif |
|
99 |
} |
|
100 |
||
101 |
LOCAL_C TInt64 FreeDiskSpace(TInt aDrive) |
|
102 |
// |
|
103 |
// |
|
104 |
// |
|
105 |
{ |
|
106 |
TVolumeInfo v; |
|
107 |
TInt r=TheFs.Volume(v,aDrive); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
108 |
test_KErrNone(r); |
0 | 109 |
return(v.iFree); |
110 |
} |
|
111 |
||
112 |
LOCAL_C TInt64 DiskSize(TInt aDrive) |
|
113 |
// |
|
114 |
// |
|
115 |
// |
|
116 |
{ |
|
117 |
TVolumeInfo v; |
|
118 |
TInt r=TheFs.Volume(v,aDrive); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
119 |
test_KErrNone(r); |
0 | 120 |
return(v.iSize); |
121 |
} |
|
122 |
||
123 |
// MinimumFileSize() - |
|
124 |
// Deduces the minimum space occupied by a file by creating a file of one byte |
|
125 |
// in length. This should equal the cluster size on FAT volumes. |
|
126 |
// |
|
127 |
LOCAL_C TInt MinimumFileSize(TInt aDrive) |
|
128 |
{ |
|
129 |
TInt r = TheFs.Delete(KTestFile1); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
130 |
test_Value(r, r == KErrNone || r==KErrNotFound); |
0 | 131 |
|
132 |
TInt64 freeSpace = FreeDiskSpace(aDrive); |
|
133 |
||
134 |
RFile file; |
|
135 |
||
136 |
||
137 |
r=file.Create(TheFs,KTestFile1,EFileShareAny|EFileWrite); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
138 |
test_KErrNone(r); |
0 | 139 |
|
140 |
r = file.Write(TheBuffer,1); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
141 |
test_KErrNone(r); |
0 | 142 |
file.Close(); |
143 |
TInt64 newSpace = FreeDiskSpace(aDrive); |
|
144 |
||
145 |
r = TheFs.Delete(KTestFile1); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
146 |
test_KErrNone(r); |
0 | 147 |
|
148 |
||
149 |
TInt64 minFileSize = freeSpace - newSpace; |
|
150 |
test (minFileSize >= 0); |
|
151 |
minFileSize = Max(minFileSize, 512); |
|
152 |
test (minFileSize < KMaxTInt); |
|
153 |
||
154 |
TInt minFileSizeLow = I64LOW(minFileSize); |
|
155 |
||
156 |
RDebug::Print(_L("minFileSize %u"), minFileSizeLow); |
|
157 |
||
158 |
#if defined(__WINS__) |
|
159 |
KFileSize1 = minFileSizeLow << 2; // 512 * 2^2 = 512 * 4 = 2048; |
|
160 |
KFileSize2 = minFileSizeLow << 3; // 512 * 2^3 = 512 * 8 = 4096; |
|
161 |
KFileSize3 = minFileSizeLow << 4; // 512 * 2^4 = 512 * 16 = 8192; |
|
162 |
#else |
|
163 |
KFileSize1 = minFileSizeLow; // 512; |
|
164 |
KFileSize2 = minFileSizeLow << 1; // 512 * 2^1 = 512 * 2 = 1024; |
|
165 |
KFileSize3 = minFileSizeLow << 3; // 512 * 2^3 = 512 * 8 = 4096; |
|
166 |
#endif |
|
167 |
||
168 |
||
169 |
return (TInt) minFileSizeLow; |
|
170 |
} |
|
171 |
||
172 |
LOCAL_C void Initialise() |
|
173 |
// |
|
174 |
// do any initialisation before starting tests |
|
175 |
// |
|
176 |
{ |
|
177 |
if(TheBuffer.Length()!=KMaxBufSize) |
|
178 |
{ |
|
179 |
TheBuffer.SetLength(KMaxBufSize); |
|
180 |
Mem::Fill((void*)TheBuffer.Ptr(),KMaxBufSize,0xab); |
|
181 |
} |
|
182 |
#if defined(__WINS__) |
|
183 |
RemovableDrive=EDriveX; |
|
184 |
#else |
|
185 |
TDriveList drvList; |
|
186 |
if(KErrNone == TheFs.DriveList(drvList)) |
|
187 |
{ |
|
188 |
TInt i; |
|
189 |
//should be successful, otherwise it means a system w/o any drive!!! |
|
190 |
for(i=0;i<KMaxDrives;i++) |
|
191 |
{ |
|
192 |
TDriveInfo driveInfo; |
|
193 |
if((drvList[i] != 0) |
|
194 |
&& (KErrNone == TheFs.Drive(driveInfo, i)) |
|
195 |
&& (driveInfo.iType == EMediaHardDisk)) |
|
196 |
{ |
|
197 |
RemovableDrive = i; |
|
198 |
test.Printf(_L("RemovableDrive = %d\n"),RemovableDrive); |
|
199 |
break; |
|
200 |
} |
|
201 |
} |
|
202 |
if(i == KMaxDrives) |
|
203 |
{ |
|
204 |
test.Printf(_L("No Removable media found! Testing discontinued.\n")); |
|
205 |
User::Exit(KErrNone); |
|
206 |
} |
|
207 |
} |
|
208 |
else |
|
209 |
{ |
|
210 |
test.Printf(_L("No Drive found! Testing discontinued.\n")); |
|
211 |
User::Exit(KErrNone); |
|
212 |
} |
|
213 |
#endif |
|
214 |
||
215 |
test.Printf(_L("inside init++++++++++++++++++++++++++>\n\n\n")); |
|
216 |
test.Printf(_L("RemovableDrive = %d\n"),RemovableDrive); |
|
217 |
// initialise removable drive descriptor |
|
218 |
TChar c; |
|
219 |
TInt r=RFs::DriveToChar(RemovableDrive,c); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
220 |
test_KErrNone(r); |
0 | 221 |
RemovableDriveBuf[0]=(TText)c; |
222 |
||
223 |
if( !LffsDrive ) |
|
224 |
{ |
|
225 |
// and create the default directory |
|
226 |
TFileName d=gSessionPath; |
|
227 |
d[0]=RemovableDriveBuf[0]; |
|
228 |
MakeDir(d); |
|
229 |
} |
|
230 |
||
231 |
// better format the default drive as long as not WINS c drive |
|
232 |
TInt drive; |
|
233 |
r= RFs::CharToDrive(gSessionPath[0],drive); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
234 |
test_KErrNone(r); |
0 | 235 |
#if defined(__WINS__) |
236 |
if(drive!=EDriveC) |
|
237 |
Format(drive); |
|
238 |
#else |
|
239 |
Format(drive); |
|
240 |
// test not run on c: drive but does use it |
|
241 |
Format(EDriveC); |
|
242 |
#endif |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
243 |
TheDiskSize=DiskSize(KDefaultDrive); |
0 | 244 |
// and set the default directory |
245 |
r=TheFs.MkDirAll(gSessionPath); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
246 |
test_Value(r, r == KErrNone || r==KErrAlreadyExists); |
0 | 247 |
|
248 |
r=TheFs.Delete(KFileFiller); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
249 |
test_Value(r, r == KErrNone || r==KErrNotFound); |
0 | 250 |
r=TheFs.Delete(KTestFile1); |
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
251 |
test_Value(r, r == KErrNone || r==KErrNotFound); |
0 | 252 |
r=TheFs.Delete(KTestFile2); |
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
253 |
test_Value(r, r == KErrNone || r==KErrNotFound); |
0 | 254 |
r=TheFs.RmDir(KTestDir1); |
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
255 |
test_Value(r, r == KErrNone || r==KErrNotFound); |
0 | 256 |
r=TheFs.RmDir(KTestDir2); |
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
257 |
test_Value(r, r == KErrNone || r==KErrNotFound); |
0 | 258 |
|
259 |
gMinFileSize = MinimumFileSize(drive); |
|
260 |
} |
|
261 |
||
262 |
LOCAL_C TInt64 FillDisk(RFile& aFile,TInt64 aNewSpace,TInt aDrive) |
|
263 |
// |
|
264 |
// fill a file until free disk space equals aFreeSpace |
|
265 |
// |
|
266 |
{ |
|
267 |
TInt64 space=FreeDiskSpace(aDrive); |
|
268 |
test(space>aNewSpace); |
|
269 |
while(space>aNewSpace) |
|
270 |
{ |
|
271 |
TInt s=Min(KMaxBufSize, I64INT(space-aNewSpace)); |
|
272 |
TInt r=aFile.Write(TheBuffer,s); |
|
273 |
if( !LffsDrive ) |
|
274 |
{ |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
275 |
test_KErrNone(r); |
0 | 276 |
} |
277 |
else |
|
278 |
{ |
|
279 |
// |
|
280 |
// LFFS is less predictable than a normal drive because of the logging |
|
281 |
// and metadata arrangement |
|
282 |
// |
|
283 |
test( (KErrNone==r) || (KErrDiskFull==r) ); |
|
284 |
if( KErrDiskFull == r ) |
|
285 |
{ |
|
286 |
// shrink the file back down again to give the requested free space |
|
287 |
TInt fileSize; |
|
288 |
r=aFile.Size( fileSize ); |
|
289 |
test( KErrNone == r ); |
|
290 |
test( TInt64(fileSize) > aNewSpace ); |
|
291 |
fileSize -= I64LOW(aNewSpace); |
|
292 |
r=aFile.SetSize( fileSize ); |
|
293 |
test( KErrNone == r ); |
|
294 |
||
295 |
space=FreeDiskSpace(aDrive); |
|
296 |
while( space < aNewSpace ) |
|
297 |
{ |
|
298 |
fileSize -= I64LOW(aNewSpace - space); |
|
299 |
test( fileSize > 0 ); |
|
300 |
r=aFile.SetSize( fileSize ); |
|
301 |
test( KErrNone == r ); |
|
302 |
space=FreeDiskSpace(aDrive); |
|
303 |
} |
|
304 |
break; |
|
305 |
} |
|
306 |
} |
|
307 |
||
308 |
space=FreeDiskSpace(aDrive); |
|
309 |
} |
|
310 |
return(space); |
|
311 |
} |
|
312 |
||
313 |
LOCAL_C void WriteToFile(RFile& aFile,TInt aSize) |
|
314 |
// |
|
315 |
// |
|
316 |
// |
|
317 |
{ |
|
318 |
while(aSize>0) |
|
319 |
{ |
|
320 |
TInt s=Min(KMaxBufSize,aSize); |
|
321 |
TInt r=aFile.Write(TheBuffer,s); |
|
322 |
aSize-=s; |
|
323 |
||
324 |
// Flush if write caching enabled to ensure we get disk space notifications |
|
325 |
if ((gDriveCacheFlags & EFileCacheWriteOn) && (r == KErrNone)) |
|
326 |
r = aFile.Flush(); |
|
327 |
||
328 |
if( !LffsDrive ) |
|
329 |
{ |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
330 |
test_KErrNone(r); |
0 | 331 |
} |
332 |
else |
|
333 |
{ |
|
334 |
// we can't accurately predict the amount of data we can actually get |
|
335 |
// on an LFFS drive, so it's posible we could exceed the available |
|
336 |
// space even though we are writing less that the reported free space |
|
337 |
test( (KErrNone==r) || (KErrDiskFull==r) ); |
|
338 |
if( KErrDiskFull == r ) |
|
339 |
{ |
|
340 |
break; // just stop |
|
341 |
} |
|
342 |
} |
|
343 |
} |
|
344 |
} |
|
345 |
||
346 |
||
347 |
LOCAL_C void CleanupForThread(TInt aTask) |
|
348 |
// |
|
349 |
// |
|
350 |
// |
|
351 |
{ |
|
352 |
TInt r; |
|
353 |
switch(aTask) |
|
354 |
{ |
|
355 |
case ETaskMkDir: |
|
356 |
r=TheFs.RmDir(KTestDir1); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
357 |
test_KErrNone(r); |
0 | 358 |
break; |
359 |
case ETaskRmDir: break; |
|
360 |
case ETaskDelete: break; |
|
361 |
case ETaskReplace: |
|
362 |
r=TheFs.Delete(KTestFile2); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
363 |
test_KErrNone(r); |
0 | 364 |
break; |
365 |
case ETaskFileReplace: |
|
366 |
r=TheFs.Delete(KTestFile1); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
367 |
test_KErrNone(r); |
0 | 368 |
break; |
369 |
case ETaskFileWrite: |
|
370 |
case ETaskFileWrite4KB: |
|
371 |
case ETaskFileWrite64KB: |
|
372 |
case ETaskFileSetSize: |
|
373 |
case ETaskFileCreateLffs: |
|
374 |
case ETaskNoChange1: |
|
375 |
case ETaskNoChange2: |
|
376 |
r=TheFs.Delete(KTestFile1); |
|
377 |
if(r!=KErrNone) |
|
378 |
{ |
|
379 |
test.Printf(_L("r=%d"),r); |
|
380 |
test(EFalse); |
|
381 |
} |
|
382 |
break; |
|
383 |
case ETaskSpin: |
|
384 |
default:break; |
|
385 |
} |
|
386 |
} |
|
387 |
||
388 |
LOCAL_C void InitialiseForThread(TInt aTask) |
|
389 |
// |
|
390 |
// |
|
391 |
// |
|
392 |
{ |
|
393 |
TInt r; |
|
394 |
RFile file,file2; |
|
395 |
switch(aTask) |
|
396 |
{ |
|
397 |
case ETaskMkDir: break; |
|
398 |
case ETaskRmDir: |
|
399 |
r=TheFs.MkDir(KTestDir1); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
400 |
test_KErrNone(r); |
0 | 401 |
break; |
402 |
case ETaskDelete: |
|
403 |
r=file.Create(TheFs,KTestFile1,EFileShareAny|EFileWrite); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
404 |
test_KErrNone(r); |
0 | 405 |
if( !LffsDrive ) |
406 |
{ |
|
407 |
r=file.SetSize(KFileSize1); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
408 |
test_KErrNone(r); |
0 | 409 |
} |
410 |
else |
|
411 |
{ |
|
412 |
// LFFS supports sparse files, so we have to write real data |
|
413 |
// into the file to ensure that it uses up disk space |
|
414 |
WriteToFile( file, KFileSize1 ); |
|
415 |
} |
|
416 |
file.Close(); |
|
417 |
break; |
|
418 |
case ETaskReplace: |
|
419 |
r=file.Create(TheFs,KTestFile1,EFileShareAny|EFileWrite); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
420 |
test_KErrNone(r); |
0 | 421 |
if( !LffsDrive ) |
422 |
{ |
|
423 |
r=file.SetSize(KFileSize1); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
424 |
test_KErrNone(r); |
0 | 425 |
} |
426 |
else |
|
427 |
{ |
|
428 |
WriteToFile( file, KFileSize2 ); |
|
429 |
} |
|
430 |
file.Close(); |
|
431 |
r=file2.Create(TheFs,KTestFile2,EFileShareAny|EFileWrite); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
432 |
test_KErrNone(r); |
0 | 433 |
if( !LffsDrive ) |
434 |
{ |
|
435 |
r=file2.SetSize(KFileSize3); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
436 |
test_KErrNone(r); |
0 | 437 |
} |
438 |
else |
|
439 |
{ |
|
440 |
WriteToFile( file2, gMinFileSize << 4); // 512 * 16 = 8K |
|
441 |
} |
|
442 |
file2.Close(); |
|
443 |
break; |
|
444 |
case ETaskFileReplace: |
|
445 |
r=file.Create(TheFs,KTestFile1,EFileShareAny|EFileWrite); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
446 |
test_KErrNone(r); |
0 | 447 |
if( !LffsDrive ) |
448 |
{ |
|
449 |
r=file.SetSize(KFileSize3*2); |
|
450 |
} |
|
451 |
else |
|
452 |
{ |
|
453 |
WriteToFile( file, KFileSize3 ); |
|
454 |
} |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
455 |
test_KErrNone(r); |
0 | 456 |
file.Close(); |
457 |
break; |
|
458 |
case ETaskFileWrite: |
|
459 |
case ETaskFileWrite4KB: |
|
460 |
case ETaskFileWrite64KB: |
|
461 |
case ETaskFileSetSize: |
|
462 |
r=file.Create(TheFs,KTestFile1,EFileShareAny|EFileWrite); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
463 |
test_KErrNone(r); |
0 | 464 |
file.Close(); |
465 |
break; |
|
466 |
case ETaskNoChange1: |
|
467 |
r=file.Create(TheFs,KTestFile1,EFileShareAny|EFileWrite); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
468 |
test_KErrNone(r); |
0 | 469 |
if( !LffsDrive ) |
470 |
{ |
|
471 |
r=file.SetSize(KFileSize1); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
472 |
test_KErrNone(r); |
0 | 473 |
} |
474 |
else |
|
475 |
{ |
|
476 |
WriteToFile( file, KFileSize1 ); |
|
477 |
} |
|
478 |
file.Close(); |
|
479 |
break; |
|
480 |
case ETaskNoChange2: |
|
481 |
r=file.Create(TheFs,KTestFile1,EFileShareAny|EFileWrite); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
482 |
test_KErrNone(r); |
0 | 483 |
file.Close(); |
484 |
break; |
|
485 |
case ETaskFileCreateLffs: |
|
486 |
r = TheFs.Delete(KTestFile1); |
|
487 |
break; |
|
488 |
case ETaskSpin: |
|
489 |
default:break; |
|
490 |
} |
|
491 |
} |
|
492 |
||
493 |
LOCAL_C TInt ThreadFunction(TAny* aThreadTask) |
|
494 |
// |
|
495 |
// |
|
496 |
// |
|
497 |
{ |
|
498 |
RTest test(_L("T_DSPACE_ThreadFunction")); |
|
499 |
RFs fs; |
|
500 |
TInt r=fs.Connect(); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
501 |
test_KErrNone(r); |
0 | 502 |
r=fs.SetSessionPath(gSessionPath); |
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
503 |
test_KErrNone(r); |
0 | 504 |
TThreadTask task=*(TThreadTask*)&aThreadTask; |
505 |
RFile file; |
|
506 |
switch(task) |
|
507 |
{ |
|
508 |
case ETaskMkDir: |
|
509 |
r=fs.MkDir(KTestDir1); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
510 |
test_KErrNone(r); |
0 | 511 |
break; |
512 |
case ETaskRmDir: |
|
513 |
r=fs.RmDir(KTestDir1); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
514 |
test_KErrNone(r); |
0 | 515 |
break; |
516 |
case ETaskDelete: |
|
517 |
r=fs.Delete(KTestFile1); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
518 |
test_KErrNone(r); |
0 | 519 |
break; |
520 |
case ETaskReplace: |
|
521 |
r=fs.Replace(KTestFile1,KTestFile2); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
522 |
test_KErrNone(r); |
0 | 523 |
break; |
524 |
case ETaskFileReplace: |
|
525 |
r=file.Replace(fs,KTestFile1,EFileShareAny|EFileWrite); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
526 |
test_KErrNone(r); |
0 | 527 |
file.Close(); |
528 |
break; |
|
529 |
case ETaskFileWrite: |
|
530 |
r=file.Open(fs,KTestFile1,EFileShareAny|EFileWrite); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
531 |
test_KErrNone(r); |
0 | 532 |
#if defined(__WINS__) |
533 |
WriteToFile( file, gMinFileSize << 4); // 512 * 16 = 8K |
|
534 |
#else |
|
535 |
WriteToFile( file, gMinFileSize << 1); // 512 * 2 = 1K |
|
536 |
#endif |
|
537 |
file.Close(); |
|
538 |
break; |
|
539 |
case ETaskFileWrite4KB: |
|
540 |
r=file.Open(fs,KTestFile1,EFileShareAny|EFileWrite); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
541 |
test_KErrNone(r); |
0 | 542 |
WriteToFile(file,gMinFileSize << 3); // 512 * 2^3 = 512 * 8 = 4K |
543 |
file.Close(); |
|
544 |
break; |
|
545 |
case ETaskFileWrite64KB: |
|
546 |
r=file.Open(fs,KTestFile1,EFileShareAny|EFileWrite); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
547 |
test_KErrNone(r); |
0 | 548 |
WriteToFile(file,gMinFileSize<<7); // 512 * 2^7 = 512 * 128 = 64K |
549 |
file.Close(); |
|
550 |
break; |
|
551 |
case ETaskFileSetSize: |
|
552 |
r=file.Open(fs,KTestFile1,EFileShareAny|EFileWrite); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
553 |
test_KErrNone(r); |
0 | 554 |
r=file.SetSize(KFileSize3); |
555 |
file.Close(); |
|
556 |
break; |
|
557 |
case ETaskFileCreateLffs: |
|
558 |
r=file.Create(fs,KTestFile1,EFileShareAny|EFileWrite); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
559 |
test_KErrNone(r); |
0 | 560 |
file.Close(); |
561 |
break; |
|
562 |
case ETaskNoChange1: |
|
563 |
{ |
|
564 |
r=file.Open(fs,KTestFile1,EFileShareAny|EFileWrite); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
565 |
test_KErrNone(r); |
0 | 566 |
TTime time; |
567 |
time.HomeTime(); |
|
568 |
r=file.SetModified(time); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
569 |
test_KErrNone(r); |
0 | 570 |
file.Close(); |
571 |
break; |
|
572 |
} |
|
573 |
case ETaskNoChange2: |
|
574 |
{ |
|
575 |
TEntry e; |
|
576 |
r=fs.Entry(KTestFile1,e); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
577 |
test_KErrNone(r); |
0 | 578 |
break; |
579 |
} |
|
580 |
case ETaskSpin: |
|
581 |
for(;;) {}; |
|
582 |
||
583 |
default:break; |
|
584 |
} |
|
585 |
fs.Close(); |
|
586 |
return(KErrNone); |
|
587 |
} |
|
588 |
||
589 |
||
590 |
void TestCancellation() |
|
591 |
// |
|
592 |
// test error disk space notification requests can be cancelled |
|
593 |
// |
|
594 |
{ |
|
595 |
test.Next(_L("test disk space cancellation")); |
|
596 |
const TInt ThresholdSize=500; |
|
597 |
// test a cancellation |
|
598 |
// Up the priority of this thread so that we can cancel the request before the drive thread |
|
599 |
// runs, to test whether cancelling still works. |
|
600 |
RThread().SetPriority(EPriorityRealTime); |
|
601 |
TRequestStatus stat1; |
|
602 |
TheFs.NotifyDiskSpace(ThresholdSize,KDefaultDrive,stat1); |
|
603 |
test(stat1==KRequestPending); |
|
604 |
TheFs.NotifyDiskSpaceCancel(stat1); |
|
605 |
test(stat1==KErrCancel); |
|
606 |
RThread().SetPriority(EPriorityNormal); |
|
607 |
// test no affect if already cancelled |
|
608 |
stat1=KErrNone; |
|
609 |
TheFs.NotifyDiskSpaceCancel(stat1); |
|
610 |
test(stat1==KErrNone); |
|
611 |
// set up two requests, cancel 1 |
|
612 |
TRequestStatus stat2; |
|
613 |
TheFs.NotifyDiskSpace(ThresholdSize,KDefaultDrive,stat1); |
|
614 |
TheFs.NotifyDiskSpace(ThresholdSize,KDefaultDrive,stat2); |
|
615 |
test(stat1==KRequestPending && stat2==KRequestPending); |
|
616 |
TheFs.NotifyDiskSpaceCancel(stat2); |
|
617 |
test(stat1==KRequestPending && stat2==KErrCancel); |
|
618 |
TheFs.NotifyDiskSpaceCancel(stat1); |
|
619 |
test(stat1==KErrCancel); |
|
620 |
||
621 |
if( !LffsDrive) |
|
622 |
{ |
|
623 |
// now repeat with c: and removable drive |
|
624 |
TheFs.NotifyDiskSpace(ThresholdSize,EDriveC,stat1); |
|
625 |
TheFs.NotifyDiskSpace(ThresholdSize,RemovableDrive,stat2); |
|
626 |
test(stat1==KRequestPending && stat2==KRequestPending); |
|
627 |
TheFs.NotifyDiskSpaceCancel(stat1); |
|
628 |
test(stat2==KRequestPending && stat1==KErrCancel); |
|
629 |
TheFs.NotifyDiskSpaceCancel(stat2); |
|
630 |
test(stat2==KErrCancel); |
|
631 |
} |
|
632 |
} |
|
633 |
||
634 |
void TestErrorConditions() |
|
635 |
// |
|
636 |
// test disk space notification requests return correct error value |
|
637 |
// |
|
638 |
{ |
|
639 |
test.Next(_L("test error conditions")); |
|
640 |
// attempt to set up disk space notification with a threshold of zero |
|
641 |
TRequestStatus status; |
|
642 |
TheFs.NotifyDiskSpace(0,KDefaultDrive,status); |
|
643 |
test(status==KErrArgument); |
|
644 |
// test on an empty drive |
|
645 |
TheFs.NotifyDiskSpace(100,EDriveO,status); |
|
646 |
test(status==KErrNotReady); |
|
647 |
// test on a drive out of rance |
|
648 |
TheFs.NotifyDiskSpace(100,27,status); |
|
649 |
test(status==KErrBadName); |
|
650 |
// new setup with threshold of one |
|
651 |
TheFs.NotifyDiskSpace(1,KDefaultDrive,status); |
|
652 |
test(status==KRequestPending); |
|
653 |
TheFs.NotifyDiskSpaceCancel(status); |
|
654 |
test(status==KErrCancel); |
|
655 |
// and with a threshold > disk size |
|
656 |
TheFs.NotifyDiskSpace(TheDiskSize+10,KDefaultDrive,status); |
|
657 |
test(status==KErrArgument); |
|
658 |
// now with a size of max size -1 |
|
659 |
TheFs.NotifyDiskSpace(TheDiskSize-1,KDefaultDrive,status); |
|
660 |
test(status==KRequestPending); |
|
661 |
TheFs.NotifyDiskSpaceCancel(status); |
|
662 |
test(status==KErrCancel); |
|
663 |
// set up mutiple requests and cancel one |
|
664 |
TRequestStatus status2,status3; |
|
665 |
TheFs.NotifyDiskSpace(TheDiskSize-10,KDefaultDrive,status); |
|
666 |
TheFs.NotifyDiskSpace(TheDiskSize-10,KDefaultDrive,status2); |
|
667 |
TheFs.NotifyDiskSpace(TheDiskSize-10,KDefaultDrive,status3); |
|
668 |
test(status==KRequestPending&&status2==KRequestPending&&status3==KRequestPending); |
|
669 |
TheFs.NotifyDiskSpaceCancel(status3); |
|
670 |
test(status==KRequestPending&&status2==KRequestPending&&status3==KErrCancel); |
|
671 |
// cancel the remaining ones |
|
672 |
TheFs.NotifyDiskSpaceCancel(); |
|
673 |
test(status==KErrCancel&&status2==KErrCancel&&status3==KErrCancel); |
|
674 |
} |
|
675 |
||
676 |
TInt GenerateMediaChange() |
|
677 |
{ |
|
678 |
RLocalDrive d; |
|
679 |
TBool flag=EFalse; |
|
680 |
//Find the local drive number corresponding to removabledrive |
|
681 |
TMediaSerialNumber serialNum; |
|
682 |
TInt r = TheFs.GetMediaSerialNumber(serialNum, RemovableDrive); |
|
683 |
if(r!= KErrNone) |
|
684 |
return r; |
|
685 |
||
686 |
TInt len = serialNum.Length(); |
|
687 |
test.Printf(_L("Serial number (len %d) :"), len); |
|
688 |
||
689 |
TInt localDriveNum = -1; |
|
690 |
for (TInt n=0; n<KMaxLocalDrives; n++) |
|
691 |
{ |
|
692 |
r = d.Connect(n, flag); |
|
693 |
if(r != KErrNone) |
|
694 |
{ |
|
695 |
test.Printf(_L("drive %d: TBusLocalDrive::Connect() failed %d\n"), n, r); |
|
696 |
continue; |
|
697 |
} |
|
698 |
||
699 |
TLocalDriveCapsV5Buf capsBuf; |
|
700 |
TLocalDriveCapsV5& caps = capsBuf(); |
|
701 |
r = d.Caps(capsBuf); |
|
702 |
if(r != KErrNone) |
|
703 |
{ |
|
704 |
test.Printf(_L("drive %d: TBusLocalDrive::Caps() failed %d\n"), n, r); |
|
705 |
continue; |
|
706 |
} |
|
707 |
||
708 |
||
709 |
TPtrC8 localSerialNum(caps.iSerialNum, caps.iSerialNumLength); |
|
710 |
if (serialNum.Compare(localSerialNum) == 0) |
|
711 |
{ |
|
712 |
localDriveNum = n; |
|
713 |
d.Close(); |
|
714 |
break; |
|
715 |
} |
|
716 |
||
717 |
d.Close(); |
|
718 |
} |
|
719 |
r =d.Connect(localDriveNum,flag); |
|
720 |
if (r!=KErrNone) |
|
721 |
return r; |
|
722 |
d.ForceMediaChange(); |
|
723 |
d.Close(); |
|
724 |
return KErrNone; |
|
725 |
} |
|
726 |
||
727 |
void TestDiskNotify() |
|
728 |
// |
|
729 |
// test functions that can result in disk change notification |
|
730 |
// format,scandrive, media change |
|
731 |
// |
|
732 |
{ |
|
733 |
// make default directory |
|
734 |
_LIT(defaultDir,"C:\\F32-TST\\"); |
|
735 |
TInt r=TheFs.MkDirAll(defaultDir); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
736 |
test_Value(r, r == KErrNone||r==KErrAlreadyExists); |
0 | 737 |
// create the filler file |
738 |
RFile file; |
|
739 |
TFileName fileName=_L("C:"); |
|
740 |
fileName+=KFileFiller; |
|
741 |
r=file.Create(TheFs,fileName,EFileShareAny|EFileWrite); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
742 |
test_KErrNone(r); |
0 | 743 |
TInt64 free=FreeDiskSpace(EDriveC); |
744 |
// use up 16KB |
|
745 |
FillDisk(file,free-16384,EDriveC); |
|
746 |
||
747 |
// test formatting notifies clients on only specific drive |
|
748 |
test.Next(_L("test formatting")); |
|
749 |
TRequestStatus stat1, stat2; |
|
750 |
TInt64 freeC=FreeDiskSpace(EDriveC); |
|
751 |
TInt64 freeD=FreeDiskSpace(RemovableDrive); |
|
752 |
TheFs.NotifyDiskSpace(freeC+1024,EDriveC,stat1); |
|
753 |
TheFs.NotifyDiskSpace(freeD-1024,RemovableDrive,stat2); |
|
754 |
test(stat1==KRequestPending && stat2==KRequestPending); |
|
755 |
RFormat f; |
|
756 |
TInt count; |
|
757 |
r=f.Open(TheFs,RemovableDriveBuf,EQuickFormat,count); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
758 |
test_KErrNone(r); |
0 | 759 |
while(count) |
760 |
{ |
|
761 |
r=f.Next(count); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
762 |
test_KErrNone(r); |
0 | 763 |
} |
764 |
f.Close(); |
|
765 |
User::After(1000000); |
|
766 |
User::WaitForRequest(stat2); |
|
767 |
test(stat1==KRequestPending && stat2==KErrNone); |
|
768 |
TheFs.NotifyDiskSpaceCancel(stat1); |
|
769 |
test(stat1==KErrCancel); |
|
770 |
||
771 |
// and create the test directory for the removable drive |
|
772 |
TFileName fName=_L(""); |
|
773 |
fName+=RemovableDriveBuf; |
|
774 |
fName+=_L("F32-TST\\"); |
|
775 |
r=TheFs.MkDirAll(fName); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
776 |
test_KErrNone(r); |
0 | 777 |
|
778 |
// test that a media change notifies clients on all drives |
|
779 |
test.Next(_L("media change")); |
|
780 |
freeC=FreeDiskSpace(EDriveC); |
|
781 |
freeD=FreeDiskSpace(RemovableDrive); |
|
782 |
test.Printf(_L("free space on drive %d = 0x%x\n"),EDriveC,freeC); |
|
783 |
test.Printf(_L("free space on drive %d = 0x%x\n"),RemovableDrive,freeD); |
|
784 |
TheFs.NotifyDiskSpace(freeC+1024,EDriveC,stat1); |
|
785 |
TheFs.NotifyDiskSpace(freeD-1024,RemovableDrive,stat2); |
|
786 |
test(stat1==KRequestPending && stat2==KRequestPending); |
|
787 |
// UserSvr::ForceRemountMedia(ERemovableMedia0); |
|
788 |
r = GenerateMediaChange(); |
|
789 |
if(r == KErrNone) |
|
790 |
{ |
|
791 |
User::After(1000000); |
|
792 |
User::WaitForRequest(stat2); |
|
793 |
test(stat1==KRequestPending && stat2==KErrNone); |
|
794 |
TheFs.NotifyDiskSpaceCancel(stat1); |
|
795 |
test(stat1==KErrCancel); |
|
796 |
} |
|
797 |
else |
|
798 |
{ |
|
799 |
test.Printf(_L("media change not supported, skipping this step\n")); |
|
800 |
TheFs.NotifyDiskSpaceCancel(stat1); |
|
801 |
test(stat1 == KErrCancel); |
|
802 |
TheFs.NotifyDiskSpaceCancel(stat2); |
|
803 |
test(stat2 == KErrCancel); |
|
804 |
} |
|
805 |
||
806 |
// test that scandrive notifies clients on only specific drives |
|
807 |
test.Next(_L("scandrive")); |
|
808 |
// first test that scandrive does not find any problems on the removable media |
|
809 |
r=TheFs.ScanDrive(RemovableDriveBuf); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
810 |
test_KErrNone(r); |
0 | 811 |
// now set up disk space notification |
812 |
freeC=FreeDiskSpace(EDriveC); |
|
813 |
freeD=FreeDiskSpace(RemovableDrive); |
|
814 |
test.Printf(_L("free space on drive %d = 0x%x\n"),EDriveC,freeC); |
|
815 |
test.Printf(_L("free space on drive %d = 0x%x\n"),RemovableDrive,freeD); |
|
816 |
TheFs.NotifyDiskSpace(freeC+8192,EDriveC,stat1); |
|
817 |
TheFs.NotifyDiskSpace(freeD-8192,RemovableDrive,stat2); |
|
818 |
test(stat1==KRequestPending && stat2==KRequestPending); |
|
819 |
r=TheFs.ScanDrive(RemovableDriveBuf); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
820 |
test_KErrNone(r); |
0 | 821 |
User::After(1000000); |
822 |
User::WaitForRequest(stat2); |
|
823 |
test(stat1==KRequestPending && stat2==KErrNone); |
|
824 |
TheFs.NotifyDiskSpaceCancel(stat1); |
|
825 |
test(stat1==KErrCancel); |
|
826 |
||
827 |
file.Close(); |
|
828 |
r=TheFs.Delete(fileName); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
829 |
test_KErrNone(r); |
0 | 830 |
if(gSessionPath[0]!=(TText)'C') |
831 |
{ |
|
832 |
r=TheFs.RmDir(defaultDir); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
833 |
test_Value(r, r == KErrNone||r==KErrInUse); |
0 | 834 |
} |
835 |
||
836 |
} |
|
837 |
||
838 |
void TestFunctions() |
|
839 |
// |
|
840 |
// test some of the functions that may result in a change in free disk space |
|
841 |
// not testing all functions that may result in free disk space change since |
|
842 |
// change is dependent on the file system |
|
843 |
// |
|
844 |
{ |
|
845 |
test.Next(_L("test disk space functions")); |
|
846 |
// create the filler file |
|
847 |
RFile file; |
|
848 |
TInt r=file.Create(TheFs,KFileFiller,EFileShareAny|EFileWrite|EFileWriteDirectIO); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
849 |
test_KErrNone(r); |
0 | 850 |
TInt64 newSpace = FreeDiskSpace(KDefaultDrive)-8192; |
851 |
FillDisk(file,newSpace,KDefaultDrive); |
|
852 |
||
853 |
// check file write |
|
854 |
test.Next(_L("check RFile:Write")); |
|
855 |
TThreadTask task=ETaskFileWrite; |
|
856 |
InitialiseForThread(task); |
|
857 |
TInt64 free=FreeDiskSpace(KDefaultDrive); |
|
858 |
TRequestStatus stat1; |
|
859 |
TInt64 threshold=free-200; |
|
860 |
TheFs.NotifyDiskSpace(threshold,KDefaultDrive,stat1); |
|
861 |
test(stat1==KRequestPending); |
|
862 |
RThread thread; |
|
863 |
r=thread.Create(_L("thread1"),ThreadFunction,KStackSize,KHeapSize,KHeapSize,(TAny*)task); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
864 |
test_KErrNone(r); |
0 | 865 |
thread.Resume(); |
866 |
User::WaitForRequest(stat1); |
|
867 |
test(stat1==KErrNone); |
|
868 |
free=FreeDiskSpace(KDefaultDrive); |
|
869 |
test(free<threshold); |
|
870 |
TRequestStatus deathStat; |
|
871 |
thread.Logon( deathStat ); |
|
872 |
User::WaitForRequest( deathStat ); |
|
873 |
thread.Close(); |
|
874 |
CleanupForThread(task); |
|
875 |
||
876 |
// check file set size |
|
877 |
// setting file size on LFFS only uses a small amount of disk space for metadata |
|
878 |
// so we skip this test for an LFFS drive |
|
879 |
if( !LffsDrive ) |
|
880 |
{ |
|
881 |
test.Next(_L("check RFile:SetSize")); |
|
882 |
task=ETaskFileSetSize; |
|
883 |
InitialiseForThread(task); |
|
884 |
free=FreeDiskSpace(KDefaultDrive); |
|
885 |
threshold=free-100; |
|
886 |
TheFs.NotifyDiskSpace(threshold,KDefaultDrive,stat1); |
|
887 |
test(stat1==KRequestPending); |
|
888 |
r=thread.Create(_L("thread2"),ThreadFunction,KStackSize,KHeapSize,KHeapSize,(TAny*)task); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
889 |
test_KErrNone(r); |
0 | 890 |
TRequestStatus deathStat; |
891 |
thread.Logon( deathStat ); |
|
892 |
thread.Resume(); |
|
893 |
User::WaitForRequest(stat1); |
|
894 |
test(stat1==KErrNone); |
|
895 |
free=FreeDiskSpace(KDefaultDrive); |
|
896 |
test(free<threshold); |
|
897 |
User::WaitForRequest( deathStat ); |
|
898 |
thread.Close(); |
|
899 |
CleanupForThread(task); |
|
900 |
} |
|
901 |
||
902 |
// check disk space notification does not occur when threshold not crossed |
|
903 |
TInt64 newFree; |
|
904 |
test.Next(_L("check RFile:SetSize with wrong threshold")); |
|
905 |
||
906 |
User::After(1000000); //put in due to thread latency |
|
907 |
||
908 |
task=ETaskFileSetSize; |
|
909 |
InitialiseForThread(task); |
|
910 |
free=FreeDiskSpace(KDefaultDrive); |
|
911 |
threshold=free+100; |
|
912 |
TheFs.NotifyDiskSpace(threshold,KDefaultDrive,stat1); |
|
913 |
test(stat1==KRequestPending); |
|
914 |
r=thread.Create(_L("thread3"),ThreadFunction,KStackSize,KHeapSize,KHeapSize,(TAny*)task); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
915 |
test_KErrNone(r); |
0 | 916 |
thread.Logon( deathStat ); |
917 |
thread.Resume(); |
|
918 |
||
919 |
User::After(1000000); |
|
920 |
||
921 |
test(stat1==KRequestPending); |
|
922 |
newFree=FreeDiskSpace(KDefaultDrive); |
|
923 |
/* |
|
924 |
test.Printf(_L("threshold = %d and %d"),threshold.High(), threshold.Low()); |
|
925 |
test.Printf(_L("free = %d and %d"),free.High(), free.Low()); |
|
926 |
test.Printf(_L("newFree = %d and %d"),newFree.High(), newFree.Low()); |
|
927 |
*/ |
|
928 |
if(!LffsDrive) |
|
929 |
test(free<threshold && newFree<free); |
|
930 |
else |
|
931 |
test(free<threshold); //changing file size on lffs does not do anything |
|
932 |
||
933 |
User::WaitForRequest( deathStat ); |
|
934 |
thread.Close(); |
|
935 |
CleanupForThread(task); |
|
936 |
TheFs.NotifyDiskSpaceCancel(stat1); |
|
937 |
test(stat1==KErrCancel); |
|
938 |
||
939 |
// check for file delete |
|
940 |
test.Next(_L("check RFs::Delete")); |
|
941 |
task=ETaskDelete; |
|
942 |
InitialiseForThread(task); |
|
943 |
free=FreeDiskSpace(KDefaultDrive); |
|
944 |
threshold=free+300; |
|
945 |
TheFs.NotifyDiskSpace(threshold,KDefaultDrive,stat1); |
|
946 |
test(stat1==KRequestPending); |
|
947 |
r=thread.Create(_L("thread4"),ThreadFunction,KStackSize,KHeapSize,KHeapSize,(TAny*)task); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
948 |
test_KErrNone(r); |
0 | 949 |
thread.Logon( deathStat ); |
950 |
thread.Resume(); |
|
951 |
User::WaitForRequest(stat1); |
|
952 |
test(stat1==KErrNone); |
|
953 |
free=FreeDiskSpace(KDefaultDrive); |
|
954 |
test(free>threshold); |
|
955 |
User::WaitForRequest( deathStat ); |
|
956 |
thread.Close(); |
|
957 |
CleanupForThread(task); |
|
958 |
||
959 |
// check for replace with threshold too high |
|
960 |
test.Next(_L("check RFs::Replace with threshold too high")); |
|
961 |
||
962 |
if( LffsDrive ) |
|
963 |
{ |
|
964 |
test.Printf( _L("Skipped.... test isn't consistent on LFFS drive\n") ); |
|
965 |
} |
|
966 |
else |
|
967 |
{ |
|
968 |
task=ETaskReplace; |
|
969 |
InitialiseForThread(task); |
|
970 |
free=FreeDiskSpace(KDefaultDrive); |
|
971 |
#if defined(__WINS__) |
|
972 |
threshold=free + gMinFileSize * 16 + 2048; // 512 * 16 + 2K = 10K |
|
973 |
#else |
|
974 |
if(LffsDrive ) |
|
975 |
threshold=free + (gMinFileSize << 4) + 2048; // 512 * 16 + 2K = 10K |
|
976 |
else |
|
977 |
threshold=free + gMinFileSize * 9 + 392; // 512 * 9 + 392 = 5000; |
|
978 |
#endif |
|
979 |
||
980 |
TheFs.NotifyDiskSpace(threshold,KDefaultDrive,stat1); |
|
981 |
test(stat1==KRequestPending); |
|
982 |
||
983 |
r=thread.Create(_L("thread5"),ThreadFunction,KStackSize,KHeapSize,KHeapSize,(TAny*)task); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
984 |
test_KErrNone(r); |
0 | 985 |
thread.Logon( deathStat ); |
986 |
thread.Resume(); |
|
987 |
||
988 |
User::After(1000000); |
|
989 |
test(stat1==KRequestPending); |
|
990 |
newFree=FreeDiskSpace(KDefaultDrive); |
|
991 |
test(newFree<threshold && free<newFree); |
|
992 |
TheFs.NotifyDiskSpaceCancel(); |
|
993 |
test(stat1==KErrCancel); |
|
994 |
User::WaitForRequest( deathStat ); |
|
995 |
thread.Close(); |
|
996 |
CleanupForThread(task); |
|
997 |
||
998 |
||
999 |
// check for replace |
|
1000 |
test.Next(_L("check RFs:Replace")); |
|
1001 |
task=ETaskReplace; |
|
1002 |
InitialiseForThread(task); |
|
1003 |
free=FreeDiskSpace(KDefaultDrive); |
|
1004 |
threshold=free+200; |
|
1005 |
TheFs.NotifyDiskSpace(threshold,KDefaultDrive,stat1); |
|
1006 |
test(stat1==KRequestPending); |
|
1007 |
r=thread.Create(_L("thread6"),ThreadFunction,KStackSize,KHeapSize,KHeapSize,(TAny*)task); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1008 |
test_KErrNone(r); |
0 | 1009 |
thread.Logon( deathStat ); |
1010 |
thread.Resume(); |
|
1011 |
User::WaitForRequest(stat1); |
|
1012 |
//User::After(1000000); |
|
1013 |
test(stat1==KErrNone); |
|
1014 |
User::WaitForRequest( deathStat ); |
|
1015 |
test(deathStat==KErrNone); |
|
1016 |
thread.Close(); |
|
1017 |
CleanupForThread(task); |
|
1018 |
free=FreeDiskSpace(KDefaultDrive); |
|
1019 |
test(free>threshold); |
|
1020 |
} |
|
1021 |
||
1022 |
// check that CSessionFS::iTheDrive is set in subsession calls |
|
1023 |
test.Next(_L("Check iTheDrive and subsessions")); |
|
1024 |
if( LffsDrive ) |
|
1025 |
{ |
|
1026 |
test.Printf( _L("Skipped.... test not done on LFFS drive\n") ); |
|
1027 |
} |
|
1028 |
else |
|
1029 |
{ |
|
1030 |
RFile f2; |
|
1031 |
#if defined(__WINS__) |
|
1032 |
_LIT(someFile,"X:\\abcdef"); |
|
1033 |
#else |
|
1034 |
TBuf<10> someFile=_L("?:\\abcdef"); |
|
1035 |
TChar c; |
|
1036 |
TInt r=RFs::DriveToChar(RemovableDrive,c); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1037 |
test_KErrNone(r); |
0 | 1038 |
someFile[0]=(TText)c; |
1039 |
#endif |
|
1040 |
_LIT(someDir,"C:\\1234\\"); |
|
1041 |
||
1042 |
r=f2.Create(TheFs,someFile,EFileShareAny|EFileWrite); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1043 |
test_KErrNone(r); |
0 | 1044 |
r=TheFs.MkDir(someDir); |
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1045 |
test_KErrNone(r); |
0 | 1046 |
TRequestStatus stat2; |
1047 |
TInt64 freeC=FreeDiskSpace(EDriveC); |
|
1048 |
TInt64 freeD=FreeDiskSpace(RemovableDrive); |
|
1049 |
TheFs.NotifyDiskSpace(freeC-4097,EDriveC,stat1); |
|
1050 |
TheFs.NotifyDiskSpace(freeD-4097,RemovableDrive,stat2); |
|
1051 |
test(stat1==KRequestPending && stat2==KRequestPending); |
|
1052 |
// before fix this would result in iTheDrive not being updated in next subsession call |
|
1053 |
// therefore this could would not result in a disk space notification |
|
1054 |
r=f2.SetSize(8192); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1055 |
test_KErrNone(r); |
0 | 1056 |
User::After(1000000); |
1057 |
User::WaitForRequest(stat2); |
|
1058 |
||
1059 |
if (stat2!=KErrNone) |
|
1060 |
test.Printf(_L("stat2=%d\n"),stat2.Int()); |
|
1061 |
test(stat2==KErrNone); |
|
1062 |
if (stat1!=KRequestPending) |
|
1063 |
test.Printf(_L("stat1=%d\n"),stat1.Int()); |
|
1064 |
test(stat1==KRequestPending); |
|
1065 |
||
1066 |
f2.Close(); |
|
1067 |
TheFs.NotifyDiskSpaceCancel(); |
|
1068 |
test(stat1==KErrCancel); |
|
1069 |
r=TheFs.Delete(someFile); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1070 |
test_KErrNone(r); |
0 | 1071 |
r=TheFs.RmDir(someDir); |
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1072 |
test_KErrNone(r); |
0 | 1073 |
} |
1074 |
||
1075 |
file.Close(); |
|
1076 |
r=TheFs.Delete(KFileFiller); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1077 |
test_KErrNone(r); |
0 | 1078 |
} |
1079 |
||
1080 |
||
1081 |
||
1082 |
void TestLffsFunctions() |
|
1083 |
// |
|
1084 |
// LFFS-specific tests for some functions which may cause a disk |
|
1085 |
// space change |
|
1086 |
// |
|
1087 |
// |
|
1088 |
{ |
|
1089 |
test.Next(_L("test LFFS disk space functions")); |
|
1090 |
// create the filler file |
|
1091 |
RFile file; |
|
1092 |
TInt r=file.Create(TheFs,KFileFiller,EFileShareAny|EFileWrite|EFileWriteDirectIO); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1093 |
test_KErrNone(r); |
0 | 1094 |
TInt64 newSpace = FreeDiskSpace(KDefaultDrive)-8192; |
1095 |
FillDisk(file,newSpace,KDefaultDrive); |
|
1096 |
||
1097 |
||
1098 |
// check file create |
|
1099 |
// Creating a file will always allocate space for the inode |
|
1100 |
test.Next(_L("check RFile:Create")); |
|
1101 |
TThreadTask task=ETaskFileCreateLffs; |
|
1102 |
InitialiseForThread(task); |
|
1103 |
TInt64 free=FreeDiskSpace(KDefaultDrive); |
|
1104 |
TInt64 threshold1=free-64; |
|
1105 |
TInt64 threshold2=free-KFileSize3; |
|
1106 |
TRequestStatus stat1, stat2; |
|
1107 |
TheFs.NotifyDiskSpace(threshold1,KDefaultDrive,stat1); |
|
1108 |
TheFs.NotifyDiskSpace(threshold2,KDefaultDrive,stat2); |
|
1109 |
test(stat1==KRequestPending && stat2==KRequestPending); |
|
1110 |
RThread thread; |
|
1111 |
r=thread.Create(_L("thread7"),ThreadFunction,KStackSize,KHeapSize,KHeapSize,(TAny*)task); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1112 |
test_KErrNone(r); |
0 | 1113 |
TRequestStatus deathStat; |
1114 |
thread.Logon( deathStat ); |
|
1115 |
thread.Resume(); |
|
1116 |
User::WaitForRequest(stat1); |
|
1117 |
test(stat1==KErrNone); |
|
1118 |
free=FreeDiskSpace(KDefaultDrive); |
|
1119 |
test(free<threshold1); |
|
1120 |
test(stat2==KRequestPending); |
|
1121 |
test(free>threshold2); |
|
1122 |
TheFs.NotifyDiskSpaceCancel(stat2); |
|
1123 |
User::WaitForRequest(stat2); |
|
1124 |
test(stat2==KErrCancel); |
|
1125 |
User::WaitForRequest( deathStat ); |
|
1126 |
thread.Close(); |
|
1127 |
CleanupForThread(task); |
|
1128 |
||
1129 |
TInt64 threshold3; |
|
1130 |
TRequestStatus stat3; |
|
1131 |
RFile file2; |
|
1132 |
// don't test for wins urel since cant use RFs::ControlIo |
|
1133 |
#if defined(_DEBUG) |
|
1134 |
// check background thread notification |
|
1135 |
test.Next(_L("check Background thread notification")); |
|
1136 |
task=ETaskSpin; // create thread to block background thread |
|
1137 |
InitialiseForThread(task); |
|
1138 |
free=FreeDiskSpace(KDefaultDrive); |
|
1139 |
threshold1=free-64; // this should occur when we create test file |
|
1140 |
threshold2=free+9750; // some impossible value |
|
1141 |
threshold3=free+10000; // some other impossible value that will never happen |
|
1142 |
TheFs.NotifyDiskSpace(threshold1,KDefaultDrive,stat1); |
|
1143 |
TheFs.NotifyDiskSpace(threshold2,KDefaultDrive,stat2); |
|
1144 |
TheFs.NotifyDiskSpace(threshold3,KDefaultDrive,stat3); |
|
1145 |
test(stat1==KRequestPending && stat2==KRequestPending && stat3==KRequestPending); |
|
1146 |
r=thread.Create(_L("thread8"),ThreadFunction,KStackSize,KHeapSize,KHeapSize,(TAny*)task); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1147 |
test_KErrNone(r); |
0 | 1148 |
thread.Logon( deathStat ); |
1149 |
thread.SetPriority( EPriorityLess ); |
|
1150 |
thread.Resume(); // start spinning, blocks background thread |
|
1151 |
// request background thread to notify a daft value |
|
1152 |
TPckgBuf<TInt64> cBuf; |
|
1153 |
cBuf() = threshold2; |
|
1154 |
// Hard code the value of ECioBackgroundNotifyDiskSize. |
|
1155 |
// Although the value is enumerated in f32\slffs\lffs_controlio.h this header file is being |
|
1156 |
// removed from the release codeline but retained in the base team development codeline. |
|
1157 |
#define ECioBackgroundNotifyDiskSize 10016 |
|
1158 |
r = TheFs.ControlIo(GetDriveLFFS(), ECioBackgroundNotifyDiskSize, cBuf); |
|
1159 |
test( KErrNone==r ); |
|
1160 |
// create a file to force some roll-forward |
|
1161 |
r=file2.Create(TheFs,KTestFile1,EFileShareAny|EFileWrite); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1162 |
test_KErrNone(r); |
0 | 1163 |
User::WaitForRequest(stat1); |
1164 |
test(stat1==KErrNone); |
|
1165 |
test(stat2==KRequestPending); |
|
1166 |
test(stat3==KRequestPending); |
|
1167 |
// kill the spinner thread to allow the background thread to execute |
|
1168 |
thread.Kill(KErrNone); |
|
1169 |
User::WaitForRequest( deathStat ); |
|
1170 |
thread.Close(); |
|
1171 |
// wait for the notifier |
|
1172 |
User::WaitForRequest(stat2); |
|
1173 |
test( stat2==KErrNone ); |
|
1174 |
test( stat3==KRequestPending); |
|
1175 |
TheFs.NotifyDiskSpaceCancel(stat3); |
|
1176 |
User::WaitForRequest(stat3); |
|
1177 |
test(stat3==KErrCancel); |
|
1178 |
CleanupForThread(task); |
|
1179 |
file2.Close(); |
|
1180 |
TheFs.Delete( KTestFile1 ); |
|
1181 |
#endif |
|
1182 |
||
1183 |
// check background thread notification again, this time we won't request |
|
1184 |
// a special value - check that it notifies normally |
|
1185 |
test.Next(_L("check Background thread notification again")); |
|
1186 |
task=ETaskSpin; // create thread to block background thread |
|
1187 |
InitialiseForThread(task); |
|
1188 |
free=FreeDiskSpace(KDefaultDrive); |
|
1189 |
threshold1=free-64; // this should occur when we create test file |
|
1190 |
threshold2=free+9750; // some impossible value |
|
1191 |
threshold3=free+10000; // some other impossible value that will never happen |
|
1192 |
TheFs.NotifyDiskSpace(threshold1,KDefaultDrive,stat1); |
|
1193 |
TheFs.NotifyDiskSpace(threshold2,KDefaultDrive,stat2); |
|
1194 |
TheFs.NotifyDiskSpace(threshold3,KDefaultDrive,stat3); |
|
1195 |
test(stat1==KRequestPending && stat2==KRequestPending && stat3==KRequestPending); |
|
1196 |
r=thread.Create(_L("thread9"),ThreadFunction,KStackSize,KHeapSize,KHeapSize,(TAny*)task); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1197 |
test_KErrNone(r); |
0 | 1198 |
thread.Logon( deathStat ); |
1199 |
thread.SetPriority( EPriorityLess ); |
|
1200 |
thread.Resume(); // start spinning, blocks background thread |
|
1201 |
// create a file to force some roll-forward |
|
1202 |
r=file2.Create(TheFs,KTestFile1,EFileShareAny|EFileWrite); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1203 |
test_KErrNone(r); |
0 | 1204 |
User::WaitForRequest(stat1); |
1205 |
test(stat1==KErrNone); |
|
1206 |
test(stat2==KRequestPending); |
|
1207 |
test(stat3==KRequestPending); |
|
1208 |
// kill the spinner thread to allow the background thread to execute |
|
1209 |
thread.Kill(KErrNone); |
|
1210 |
User::WaitForRequest( deathStat ); |
|
1211 |
thread.Close(); |
|
1212 |
// wait for the notifier |
|
1213 |
test( stat2==KRequestPending ); |
|
1214 |
test( stat3==KRequestPending); |
|
1215 |
TheFs.NotifyDiskSpaceCancel(stat2); |
|
1216 |
User::WaitForRequest(stat2); |
|
1217 |
test(stat2==KErrCancel); |
|
1218 |
TheFs.NotifyDiskSpaceCancel(stat3); |
|
1219 |
User::WaitForRequest(stat3); |
|
1220 |
test(stat3==KErrCancel); |
|
1221 |
CleanupForThread(task); |
|
1222 |
file2.Close(); |
|
1223 |
TheFs.Delete( KTestFile1 ); |
|
1224 |
||
1225 |
||
1226 |
file.Close(); |
|
1227 |
r=TheFs.Delete(KFileFiller); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1228 |
test_KErrNone(r); |
0 | 1229 |
} |
1230 |
||
1231 |
||
1232 |
void TestMultiple() |
|
1233 |
// |
|
1234 |
// test muliple requests and multiple sessions |
|
1235 |
// |
|
1236 |
{ |
|
1237 |
// create the filler file |
|
1238 |
RFile file; |
|
1239 |
TInt r=file.Create(TheFs,KFileFiller,EFileShareAny|EFileWrite|EFileWriteDirectIO); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1240 |
test_KErrNone(r); |
0 | 1241 |
TInt64 free=FreeDiskSpace(KDefaultDrive); |
1242 |
TInt64 freeSpaceLeft = gMinFileSize << 4; // 512 * 2^4 = 512 * 16 = 8K |
|
1243 |
FillDisk(file,free-freeSpaceLeft,KDefaultDrive); |
|
1244 |
TInt size; |
|
1245 |
r=file.Size(size); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1246 |
test_KErrNone(r); |
0 | 1247 |
test(size>1024); |
1248 |
test.Printf(_L("filler file size=0x%x\n"),size); |
|
1249 |
||
1250 |
// test multiple requests |
|
1251 |
test.Next(_L("test multiple requests")); |
|
1252 |
TThreadTask task = ETaskFileWrite4KB; |
|
1253 |
InitialiseForThread(task); |
|
1254 |
free=FreeDiskSpace(KDefaultDrive); |
|
1255 |
TInt64 threshold1=free-gMinFileSize; // 512; |
|
1256 |
TInt64 threshold2=free - (gMinFileSize << 2); // 512 * 4 = 2048; |
|
1257 |
#if defined(__WINS__) |
|
1258 |
TInt64 threshold3=free-70000; //NTFS over-allocates then reduces when file closed |
|
1259 |
#else |
|
1260 |
TInt64 threshold3=free - (gMinFileSize << 5); // 512 * 2^5 = 512 * 32 = 16K |
|
1261 |
#endif |
|
1262 |
TRequestStatus stat1,stat2,stat3; |
|
1263 |
TheFs.NotifyDiskSpace(threshold1,KDefaultDrive,stat1); |
|
1264 |
TheFs.NotifyDiskSpace(threshold2,KDefaultDrive,stat2); |
|
1265 |
TheFs.NotifyDiskSpace(threshold3,KDefaultDrive,stat3); |
|
1266 |
test(stat1==KRequestPending&&stat2==KRequestPending&&stat3==KRequestPending); |
|
1267 |
RThread thread; |
|
1268 |
r=thread.Create(_L("thread1"),ThreadFunction,KStackSize,KHeapSize,KHeapSize,(TAny*)task); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1269 |
test_KErrNone(r); |
0 | 1270 |
TRequestStatus deathStat; |
1271 |
thread.Logon( deathStat ); |
|
1272 |
thread.Resume(); |
|
1273 |
User::After(1000000); |
|
1274 |
User::WaitForRequest(stat1); |
|
1275 |
User::WaitForRequest(stat2); |
|
1276 |
test(stat1==KErrNone && stat2==KErrNone); |
|
1277 |
test(stat3==KRequestPending); |
|
1278 |
free=FreeDiskSpace(KDefaultDrive); |
|
1279 |
test(free<threshold1 && free<threshold2 && free>threshold3); |
|
1280 |
TheFs.NotifyDiskSpaceCancel(stat3); |
|
1281 |
test(stat3==KErrCancel); |
|
1282 |
User::WaitForRequest( deathStat ); |
|
1283 |
thread.Close(); |
|
1284 |
CleanupForThread(task); |
|
1285 |
||
1286 |
// test multiple requests again |
|
1287 |
test.Next(_L("test multiple requests again")); |
|
1288 |
if( LffsDrive ) |
|
1289 |
{ |
|
1290 |
// SetSize doesn't use disk space on LFFS |
|
1291 |
test.Printf( _L("test skipped on LFFS drive\n") ); |
|
1292 |
} |
|
1293 |
else |
|
1294 |
{ |
|
1295 |
task=ETaskFileSetSize; |
|
1296 |
InitialiseForThread(task); // this also does initialisation for task2 |
|
1297 |
free=FreeDiskSpace(KDefaultDrive); |
|
1298 |
threshold1 = free + (gMinFileSize << 1); // 512 * 2 = 1024 |
|
1299 |
threshold2 = free + (gMinFileSize * 12); // 512 * 12 = 6144 |
|
1300 |
threshold3 = free - (gMinFileSize << 1); // 512 * 2 = 1024; |
|
1301 |
TheFs.NotifyDiskSpace(threshold1,KDefaultDrive,stat1); |
|
1302 |
TheFs.NotifyDiskSpace(threshold2,KDefaultDrive,stat2); |
|
1303 |
TheFs.NotifyDiskSpace(threshold3,KDefaultDrive,stat3); |
|
1304 |
test(stat1==KRequestPending&&stat2==KRequestPending&&stat3==KRequestPending); |
|
1305 |
r=thread.Create(_L("thread2"),ThreadFunction,KStackSize,KHeapSize,KHeapSize,(TAny*)task); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1306 |
test_KErrNone(r); |
0 | 1307 |
thread.Logon( deathStat ); |
1308 |
thread.Resume(); |
|
1309 |
User::After(10000); |
|
1310 |
User::WaitForRequest(stat3); |
|
1311 |
test(stat3==KErrNone && stat1==KRequestPending && stat2==KRequestPending); |
|
1312 |
free=FreeDiskSpace(KDefaultDrive); |
|
1313 |
test(free<threshold1); |
|
1314 |
User::WaitForRequest( deathStat ); |
|
1315 |
thread.Close(); |
|
1316 |
CleanupForThread(task); |
|
1317 |
if(!IsWinsCDrive(KDefaultDrive)) |
|
1318 |
{ |
|
1319 |
free=FreeDiskSpace(KDefaultDrive); |
|
1320 |
test(stat1==KRequestPending && stat2==KRequestPending); |
|
1321 |
file.SetSize(size - (gMinFileSize << 2)); // 512 * 4 = 2048 |
|
1322 |
free=FreeDiskSpace(KDefaultDrive); |
|
1323 |
User::After(1000000); |
|
1324 |
User::WaitForRequest(stat1); |
|
1325 |
//User::WaitForRequest(stat2); |
|
1326 |
test(stat1==KErrNone && stat2==KRequestPending); |
|
1327 |
free=FreeDiskSpace(KDefaultDrive); |
|
1328 |
test(free>threshold1 && free<threshold2); |
|
1329 |
TheFs.NotifyDiskSpaceCancel(); |
|
1330 |
test(stat2==KErrCancel); |
|
1331 |
} |
|
1332 |
else |
|
1333 |
{ |
|
1334 |
TheFs.NotifyDiskSpaceCancel(); |
|
1335 |
test(stat1==KErrCancel&&stat2==KErrCancel&&stat3==KErrNone); |
|
1336 |
} |
|
1337 |
} |
|
1338 |
||
1339 |
// test multiple sessions all notified on disk space change |
|
1340 |
test.Next(_L("test multiple sessions on same drive")); |
|
1341 |
RFs ses2,ses3; |
|
1342 |
r=ses2.Connect(); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1343 |
test_KErrNone(r); |
0 | 1344 |
r=ses3.Connect(); |
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1345 |
test_KErrNone(r); |
0 | 1346 |
r=ses2.SetSessionPath(gSessionPath); |
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1347 |
test_KErrNone(r); |
0 | 1348 |
r=ses3.SetSessionPath(gSessionPath); |
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1349 |
test_KErrNone(r); |
0 | 1350 |
task=ETaskFileReplace; |
1351 |
InitialiseForThread(task); |
|
1352 |
free=FreeDiskSpace(KDefaultDrive); |
|
1353 |
test.Printf(_L("free space on default drive = 0x%x\n"),free); |
|
1354 |
threshold1=free+gMinFileSize; // 512 |
|
1355 |
threshold2=free+(gMinFileSize << 1); // 1024; |
|
1356 |
threshold3=free+(gMinFileSize << 2); // 2048; |
|
1357 |
TheFs.NotifyDiskSpace(threshold1,KDefaultDrive,stat1); |
|
1358 |
ses2.NotifyDiskSpace(threshold2,KDefaultDrive,stat2); |
|
1359 |
ses3.NotifyDiskSpace(threshold3,KDefaultDrive,stat3); |
|
1360 |
test(stat1==KRequestPending&&stat2==KRequestPending&&stat3==KRequestPending); |
|
1361 |
r=thread.Create(_L("thread3"),ThreadFunction,KStackSize,KHeapSize,KHeapSize,(TAny*)task); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1362 |
test_KErrNone(r); |
0 | 1363 |
thread.Logon( deathStat ); |
1364 |
thread.Resume(); |
|
1365 |
User::After(1000000); |
|
1366 |
User::WaitForRequest(stat1); |
|
1367 |
User::WaitForRequest(stat2); |
|
1368 |
User::WaitForRequest(stat3); |
|
1369 |
test(stat1==KErrNone && stat2==KErrNone && stat3==KErrNone); |
|
1370 |
free=FreeDiskSpace(KDefaultDrive); |
|
1371 |
test(free>threshold1 && free>threshold2 && free>threshold3); |
|
1372 |
User::WaitForRequest( deathStat ); |
|
1373 |
thread.Close(); |
|
1374 |
CleanupForThread(task); |
|
1375 |
||
1376 |
// test NotifyDiskSpaceCancel() |
|
1377 |
test.Next(_L("test RFs:NotifyDiskSpaceCancel")); |
|
1378 |
free=FreeDiskSpace(KDefaultDrive); |
|
1379 |
TheFs.NotifyDiskSpace(free-100,KDefaultDrive,stat1); |
|
1380 |
ses2.NotifyDiskSpace(free-100,KDefaultDrive,stat2); |
|
1381 |
ses3.NotifyDiskSpace(free-100,KDefaultDrive,stat3); |
|
1382 |
test(stat1==KRequestPending&&stat2==KRequestPending&&stat3==KRequestPending); |
|
1383 |
TheFs.NotifyDiskSpaceCancel(); |
|
1384 |
test(stat1==KErrCancel&&stat2==KRequestPending&&stat3==KRequestPending); |
|
1385 |
ses2.NotifyDiskSpaceCancel(stat2); |
|
1386 |
test(stat2==KErrCancel&&stat3==KRequestPending); |
|
1387 |
ses3.NotifyDiskSpaceCancel(); |
|
1388 |
test(stat3==KErrCancel); |
|
1389 |
||
1390 |
if( !LffsDrive ) |
|
1391 |
{ |
|
1392 |
TInt sessionDrive; |
|
1393 |
r=RFs::CharToDrive(gSessionPath[0],sessionDrive); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1394 |
test_KErrNone(r); |
0 | 1395 |
if(sessionDrive!=RemovableDrive) |
1396 |
{ |
|
1397 |
// first create a file on the removable drive |
|
1398 |
RFile file2; |
|
1399 |
TFileName file2name=RemovableDriveBuf; |
|
1400 |
file2name+=_L("F32-TST\\testfile1"); |
|
1401 |
TheFs.Delete(file2name); |
|
1402 |
r=file2.Create(TheFs,file2name,EFileShareAny|EFileWrite); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1403 |
test_KErrNone(r); |
0 | 1404 |
r=file2.SetSize(KFileSize3); |
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1405 |
test_KErrNone(r); |
0 | 1406 |
// test multiple sessions not notified on disk space change on wrong drive |
1407 |
test.Next(_L("test multiple sessions on different drives")); |
|
1408 |
task=ETaskFileReplace; |
|
1409 |
InitialiseForThread(task); |
|
1410 |
TInt64 freeDef=FreeDiskSpace(KDefaultDrive); |
|
1411 |
TInt64 freeRem=FreeDiskSpace(RemovableDrive); |
|
1412 |
threshold1=freeDef + (gMinFileSize << 1); // 1024; |
|
1413 |
threshold2=freeRem + (gMinFileSize << 1); // 1024; |
|
1414 |
TheFs.NotifyDiskSpace(threshold1,KDefaultDrive,stat1); |
|
1415 |
ses2.NotifyDiskSpace(threshold2,RemovableDrive,stat2); |
|
1416 |
test(stat1==KRequestPending&&stat2==KRequestPending); |
|
1417 |
r=thread.Create(_L("thread4"),ThreadFunction,KStackSize,KHeapSize,KHeapSize,(TAny*)task); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1418 |
test_KErrNone(r); |
0 | 1419 |
thread.Logon( deathStat ); |
1420 |
thread.Resume(); |
|
1421 |
User::After(1000000); |
|
1422 |
User::WaitForRequest(stat1); |
|
1423 |
test(stat1==KErrNone && stat2==KRequestPending); |
|
1424 |
free=FreeDiskSpace(KDefaultDrive); |
|
1425 |
test(free>threshold1); |
|
1426 |
User::WaitForRequest( deathStat ); |
|
1427 |
thread.Close(); |
|
1428 |
CleanupForThread(task); |
|
1429 |
TheFs.NotifyDiskSpaceCancel(stat2); |
|
1430 |
test(stat2==KRequestPending); |
|
1431 |
ses2.NotifyDiskSpaceCancel(stat2); |
|
1432 |
test(stat2==KErrCancel); |
|
1433 |
file2.Close(); |
|
1434 |
r=TheFs.Delete(file2name); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1435 |
test_KErrNone(r); |
0 | 1436 |
} |
1437 |
} |
|
1438 |
||
1439 |
ses2.Close(); |
|
1440 |
ses3.Close(); |
|
1441 |
||
1442 |
||
1443 |
file.Close(); |
|
1444 |
r=TheFs.Delete(KFileFiller); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1445 |
test_KErrNone(r); |
0 | 1446 |
|
1447 |
} |
|
1448 |
||
1449 |
||
1450 |
void TestLffsMultiple() |
|
1451 |
// |
|
1452 |
// test muliple requests and multiple sessions speicifcally for LFFS drive |
|
1453 |
// |
|
1454 |
{ |
|
1455 |
// create the filler file |
|
1456 |
RFile file; |
|
1457 |
TInt r=file.Create(TheFs,KFileFiller,EFileShareAny|EFileWrite|EFileWriteDirectIO); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1458 |
test_KErrNone(r); |
0 | 1459 |
TInt64 free=FreeDiskSpace(KDefaultDrive); |
1460 |
FillDisk(file,free-8192,KDefaultDrive); |
|
1461 |
TInt size; |
|
1462 |
r=file.Size(size); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1463 |
test_KErrNone(r); |
0 | 1464 |
test.Printf(_L("filler file size=0x%x\n"),size); |
1465 |
||
1466 |
||
1467 |
// test multiple requests again |
|
1468 |
test.Next(_L("test multiple requests on LFFS") ); |
|
1469 |
||
1470 |
TThreadTask task=ETaskFileCreateLffs; |
|
1471 |
InitialiseForThread(task); // this also does initialisation for task2 |
|
1472 |
free=FreeDiskSpace(KDefaultDrive); |
|
1473 |
TInt64 threshold1=free+8192; |
|
1474 |
TInt64 threshold2=free+700; //increased threshold as LFFS, unpredicatably, can release drive space |
|
1475 |
TInt64 threshold3=free-64; |
|
1476 |
TRequestStatus stat1, stat2, stat3; |
|
1477 |
//test.Printf(_L("set up notifiers")); |
|
1478 |
TheFs.NotifyDiskSpace(threshold1,KDefaultDrive,stat1); |
|
1479 |
TheFs.NotifyDiskSpace(threshold2,KDefaultDrive,stat2); |
|
1480 |
TheFs.NotifyDiskSpace(threshold3,KDefaultDrive,stat3); |
|
1481 |
test(stat1==KRequestPending&&stat2==KRequestPending&&stat3==KRequestPending); |
|
1482 |
RThread thread; |
|
1483 |
r=thread.Create(_L("thread10"),ThreadFunction,KStackSize,KHeapSize,KHeapSize,(TAny*)task); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1484 |
test_KErrNone(r); |
0 | 1485 |
TRequestStatus deathStat; |
1486 |
thread.Logon( deathStat ); |
|
1487 |
// test.Printf(_L("Resuming other thread")); |
|
1488 |
thread.Resume(); |
|
1489 |
User::After(10000); |
|
1490 |
User::WaitForRequest(stat3); |
|
1491 |
test(stat3==KErrNone && stat1==KRequestPending && stat2==KRequestPending); |
|
1492 |
free=FreeDiskSpace(KDefaultDrive); |
|
1493 |
test(free<threshold1); |
|
1494 |
User::WaitForRequest( deathStat ); |
|
1495 |
thread.Close(); |
|
1496 |
CleanupForThread(task); |
|
1497 |
free=FreeDiskSpace(KDefaultDrive); |
|
1498 |
// test.Printf(_L("free =%d and %d"),free.Low(), free.High()); |
|
1499 |
// test.Printf(_L("stat1=%d, stat2=%d"),stat1,stat2); |
|
1500 |
test(stat1==KRequestPending && stat2==KRequestPending); |
|
1501 |
file.SetSize(6144); |
|
1502 |
User::After(1000000); |
|
1503 |
User::WaitForRequest(stat2); |
|
1504 |
test(stat1==KRequestPending && stat2==KErrNone); |
|
1505 |
free=FreeDiskSpace(KDefaultDrive); |
|
1506 |
test(free<threshold1 && free>threshold2); |
|
1507 |
TheFs.NotifyDiskSpaceCancel(); |
|
1508 |
User::WaitForRequest( stat1 ); |
|
1509 |
test(stat1==KErrCancel); |
|
1510 |
||
1511 |
||
1512 |
||
1513 |
TInt sessionDrive; |
|
1514 |
r=RFs::CharToDrive(gSessionPath[0],sessionDrive); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1515 |
test_KErrNone(r); |
0 | 1516 |
if(sessionDrive!=EDriveC) |
1517 |
{ |
|
1518 |
// test multiple sessions not notified on disk space change on wrong drive |
|
1519 |
test.Next(_L("test multiple sessions on different drives")); |
|
1520 |
||
1521 |
RFs ses2,ses3; |
|
1522 |
r=ses2.Connect(); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1523 |
test_KErrNone(r); |
0 | 1524 |
r=ses3.Connect(); |
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1525 |
test_KErrNone(r); |
0 | 1526 |
r=ses2.SetSessionPath(gSessionPath); |
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1527 |
test_KErrNone(r); |
0 | 1528 |
r=ses3.SetSessionPath(gSessionPath); |
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1529 |
test_KErrNone(r); |
0 | 1530 |
|
1531 |
// first create a file on the C:\ drive |
|
1532 |
RFile file2; |
|
1533 |
TFileName file2name=_L("C:\\"); |
|
1534 |
file2name+=_L("F32-TST\\"); |
|
1535 |
r=TheFs.MkDir(file2name); |
|
1536 |
test( KErrNone==r || KErrAlreadyExists==r ); |
|
1537 |
file2name+=_L("testfile1"); |
|
1538 |
TheFs.Delete(file2name); |
|
1539 |
r=file2.Create(TheFs,file2name,EFileShareAny|EFileWrite); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1540 |
test_KErrNone(r); |
0 | 1541 |
WriteToFile( file2, KFileSize3 ); |
1542 |
||
1543 |
task=ETaskFileReplace; |
|
1544 |
InitialiseForThread(task); |
|
1545 |
TInt64 freeLffs=FreeDiskSpace(KDefaultDrive); |
|
1546 |
TInt64 freeD=FreeDiskSpace(EDriveC); |
|
1547 |
threshold1=freeLffs+1024; |
|
1548 |
threshold2=freeD+1024; |
|
1549 |
TheFs.NotifyDiskSpace(threshold1,KDefaultDrive,stat1); |
|
1550 |
ses2.NotifyDiskSpace(threshold2,EDriveC,stat2); |
|
1551 |
test(stat1==KRequestPending&&stat2==KRequestPending); |
|
1552 |
r=thread.Create(_L("thread11"),ThreadFunction,KStackSize,KHeapSize,KHeapSize,(TAny*)task); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1553 |
test_KErrNone(r); |
0 | 1554 |
thread.Logon( deathStat ); |
1555 |
thread.Resume(); |
|
1556 |
User::After(1000000); |
|
1557 |
User::WaitForRequest(stat1); |
|
1558 |
test(stat1==KErrNone && stat2==KRequestPending); |
|
1559 |
free=FreeDiskSpace(KDefaultDrive); |
|
1560 |
test(free>threshold1); |
|
1561 |
User::WaitForRequest( deathStat ); |
|
1562 |
thread.Close(); |
|
1563 |
CleanupForThread(task); |
|
1564 |
TheFs.NotifyDiskSpaceCancel(stat2); |
|
1565 |
test(stat2==KRequestPending); |
|
1566 |
ses2.NotifyDiskSpaceCancel(stat2); |
|
1567 |
User::WaitForRequest( stat2 ); |
|
1568 |
test(stat2==KErrCancel); |
|
1569 |
file2.Close(); |
|
1570 |
r=TheFs.Delete(file2name); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1571 |
test_KErrNone(r); |
0 | 1572 |
ses2.Close(); |
1573 |
ses3.Close(); |
|
1574 |
} |
|
1575 |
||
1576 |
||
1577 |
||
1578 |
file.Close(); |
|
1579 |
r=TheFs.Delete(KFileFiller); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1580 |
test_KErrNone(r); |
0 | 1581 |
|
1582 |
} |
|
1583 |
||
1584 |
||
1585 |
void TestChangeNotification() |
|
1586 |
// |
|
1587 |
// test that disk space notification works with (extended) change notification |
|
1588 |
// |
|
1589 |
{ |
|
1590 |
// create a filler file |
|
1591 |
RFile file; |
|
1592 |
TInt r=file.Create(TheFs,KFileFiller,EFileShareAny|EFileWrite|EFileWriteDirectIO); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1593 |
test_KErrNone(r); |
0 | 1594 |
TInt64 free=FreeDiskSpace(KDefaultDrive); |
1595 |
// use 8KB in filler file |
|
1596 |
FillDisk(file,free-8192,KDefaultDrive); |
|
1597 |
||
1598 |
// test change notification when no disk space change |
|
1599 |
test.Next(_L("test change notification")); |
|
1600 |
TThreadTask task = ETaskNoChange1; |
|
1601 |
InitialiseForThread(task); |
|
1602 |
free=FreeDiskSpace(KDefaultDrive); |
|
1603 |
TInt64 threshold1=free+gMinFileSize; |
|
1604 |
TInt64 threshold2=free-gMinFileSize; |
|
1605 |
TRequestStatus stat1,stat2,stat3; |
|
1606 |
TheFs.NotifyDiskSpace(threshold1,KDefaultDrive,stat1); //more free space becoming available |
|
1607 |
TheFs.NotifyDiskSpace(threshold2,KDefaultDrive,stat2); |
|
1608 |
TheFs.NotifyChange(ENotifyAll,stat3); |
|
1609 |
test(stat1==KRequestPending&&stat2==KRequestPending&&stat3==KRequestPending); |
|
1610 |
RThread thread; |
|
1611 |
r=thread.Create(_L("thread1"),ThreadFunction,KStackSize,KHeapSize,KHeapSize,(TAny*)task); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1612 |
test_KErrNone(r); |
0 | 1613 |
TRequestStatus deathStat; |
1614 |
thread.Logon( deathStat ); |
|
1615 |
thread.Resume(); |
|
1616 |
User::After(1000000); |
|
1617 |
User::WaitForRequest(stat3); |
|
1618 |
if(!LffsDrive) |
|
1619 |
test(stat1==KRequestPending && stat2==KRequestPending && stat3==KErrNone); |
|
1620 |
else |
|
1621 |
test(stat2==KRequestPending && stat3==KErrNone); //As below |
|
1622 |
||
1623 |
TheFs.NotifyDiskSpaceCancel(); |
|
1624 |
if(!LffsDrive) |
|
1625 |
test(stat1==KErrCancel && stat2==KErrCancel); |
|
1626 |
else |
|
1627 |
test(stat2==KErrCancel); //is invalid for LFFS as can free up space un expectedly |
|
1628 |
||
1629 |
User::WaitForRequest( deathStat ); |
|
1630 |
thread.Close(); |
|
1631 |
CleanupForThread(task); |
|
1632 |
||
1633 |
// Have three different sessions |
|
1634 |
// do an operation that will cause the change notification |
|
1635 |
// and disk change notification to be signalled |
|
1636 |
test.Next(_L(" test change notification and disk space notification")); |
|
1637 |
RFs session2,session3; |
|
1638 |
r=session2.Connect(); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1639 |
test_KErrNone(r); |
0 | 1640 |
r=session3.Connect(); |
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1641 |
test_KErrNone(r); |
0 | 1642 |
r=session2.SetSessionPath(gSessionPath); |
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1643 |
test_KErrNone(r); |
0 | 1644 |
r=session3.SetSessionPath(gSessionPath); |
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1645 |
test_KErrNone(r); |
0 | 1646 |
task=ETaskFileWrite; |
1647 |
InitialiseForThread(task); |
|
1648 |
free=FreeDiskSpace(KDefaultDrive); |
|
1649 |
threshold1=free-400; |
|
1650 |
TheFs.NotifyDiskSpace(threshold1,KDefaultDrive,stat1); |
|
1651 |
session2.NotifyChange(ENotifyAll,stat2); |
|
1652 |
session3.NotifyChange(ENotifyAll,stat3,KTestFile1); |
|
1653 |
test(stat1==KRequestPending&&stat2==KRequestPending&&stat3==KRequestPending); |
|
1654 |
r=thread.Create(_L("thread2"),ThreadFunction,KStackSize,KHeapSize,KHeapSize,(TAny*)task); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1655 |
test_KErrNone(r); |
0 | 1656 |
thread.Logon( deathStat ); |
1657 |
thread.Resume(); |
|
1658 |
User::After(1000000); |
|
1659 |
User::WaitForRequest(stat1); |
|
1660 |
User::WaitForRequest(stat2); |
|
1661 |
User::WaitForRequest(stat3); |
|
1662 |
test(stat1==KErrNone && stat2==KErrNone && stat3==KErrNone); |
|
1663 |
free=FreeDiskSpace(KDefaultDrive); |
|
1664 |
test(free<threshold1); |
|
1665 |
User::WaitForRequest( deathStat ); |
|
1666 |
thread.Close(); |
|
1667 |
CleanupForThread(task); |
|
1668 |
||
1669 |
// check cancellation of change notification and disk space notification |
|
1670 |
// on same session |
|
1671 |
test.Next(_L("test cancellation of notifications")); |
|
1672 |
TheFs.NotifyDiskSpace(FreeDiskSpace(KDefaultDrive)-512,KDefaultDrive,stat1); |
|
1673 |
TheFs.NotifyChange(ENotifyAll,stat2); |
|
1674 |
TheFs.NotifyChange(ENotifyAll,stat3,KTestFile1); |
|
1675 |
test(stat1==KRequestPending&&stat2==KRequestPending&&stat3==KRequestPending); |
|
1676 |
TheFs.NotifyChangeCancel(); |
|
1677 |
test(stat1==KRequestPending&&stat2==KErrCancel&&stat3==KErrCancel); |
|
1678 |
TheFs.NotifyDiskSpaceCancel(); |
|
1679 |
test(stat1==KErrCancel); |
|
1680 |
// request change notification again |
|
1681 |
TheFs.NotifyDiskSpace(FreeDiskSpace(KDefaultDrive)-512,KDefaultDrive,stat1); |
|
1682 |
TheFs.NotifyChange(ENotifyAll,stat2); |
|
1683 |
TheFs.NotifyChange(ENotifyAll,stat3,KTestFile1); |
|
1684 |
test(stat1==KRequestPending&&stat2==KRequestPending&&stat3==KRequestPending); |
|
1685 |
TheFs.NotifyDiskSpaceCancel(); |
|
1686 |
test(stat1==KErrCancel&&stat2==KRequestPending&&stat3==KRequestPending); |
|
1687 |
TheFs.NotifyChangeCancel(); |
|
1688 |
test(stat1==KErrCancel&&stat2==KErrCancel&&stat3==KErrCancel); |
|
1689 |
||
1690 |
||
1691 |
session2.Close(); |
|
1692 |
session3.Close(); |
|
1693 |
||
1694 |
file.Close(); |
|
1695 |
r=TheFs.Delete(KFileFiller); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1696 |
test_KErrNone(r); |
0 | 1697 |
|
1698 |
} |
|
1699 |
||
1700 |
GLDEF_C void CallTestsL() |
|
1701 |
// |
|
1702 |
// Do all tests |
|
1703 |
// |
|
1704 |
{ |
|
1705 |
TInt r = KErrNone; |
|
1706 |
TInt driveNumber; |
|
1707 |
if(IsTestingLFFS()) |
|
1708 |
{ |
|
1709 |
LffsDrive = ETrue; |
|
1710 |
r = TheFs.CharToDrive( gSessionPath[0], driveNumber ); |
|
1711 |
test( KErrNone == r ); |
|
1712 |
} |
|
1713 |
||
1714 |
// at present internal ram drive not tested - the test should allow for fact |
|
1715 |
// that memory allocation will affect the free disk space on the internal ram drive |
|
1716 |
||
1717 |
// pc file system c drive is also not tested - the test should allow for the fact |
|
1718 |
// that other windows processes may affect the free disk space |
|
1719 |
#ifdef __WINS__ |
|
1720 |
if(gSessionPath[0]==(TText)'C') |
|
1721 |
#else |
|
1722 |
// check if gSessionPath drive is RAM drive |
|
1723 |
TDriveInfo driveInfo; |
|
1724 |
test(KErrNone == TheFs.CharToDrive(gSessionPath[0], driveNumber)); |
|
1725 |
test(KErrNone == TheFs.Drive(driveInfo, driveNumber)); |
|
1726 |
if(driveInfo.iType == EMediaRam) |
|
1727 |
#endif |
|
1728 |
{ |
|
1729 |
#ifdef __WINS__ |
|
1730 |
test.Printf( _L("C:\\ is not tested, test will exit") ); |
|
1731 |
#else |
|
1732 |
test.Printf( _L("%c:\\ is not tested (is RAM drive), test will exit"), gSessionPath[0]); |
|
1733 |
#endif |
|
1734 |
return; |
|
1735 |
} |
|
1736 |
//Test uses C drive as secondary drive so test can't be tested on that drive |
|
1737 |
r = TheFs.CharToDrive(gSessionPath[0], driveNumber); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1738 |
test_KErrNone(r); |
0 | 1739 |
if(driveNumber == EDriveC) |
1740 |
{ |
|
1741 |
test.Printf(_L("Test uses C drive as secondary drive so test can't be test on C drive, test will exit")); |
|
1742 |
return; |
|
1743 |
} |
|
1744 |
||
1745 |
Initialise(); |
|
1746 |
TestErrorConditions(); |
|
1747 |
TestCancellation(); |
|
1748 |
TestFunctions(); |
|
1749 |
TestMultiple(); |
|
1750 |
if( !LffsDrive ) |
|
1751 |
{ |
|
1752 |
TestDiskNotify(); |
|
1753 |
} |
|
1754 |
||
1755 |
TestChangeNotification(); |
|
1756 |
||
1757 |
if( LffsDrive ) |
|
1758 |
{ |
|
1759 |
||
1760 |
TestLffsFunctions(); |
|
1761 |
TestLffsMultiple(); |
|
1762 |
} |
|
1763 |
} |
|
1764 |