author | hgs |
Wed, 12 May 2010 10:34:10 +0100 | |
changeset 133 | 2a0ada0a1bf8 |
parent 132 | e4a7b1cbe40c |
child 175 | 5af6c74cd793 |
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 |
// |
|
15 |
||
131 | 16 |
#define __E32TEST_EXTENSION__ |
0 | 17 |
#include <f32file.h> |
18 |
#include <e32test.h> |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
19 |
#include <e32svr.h> |
0 | 20 |
#include <e32math.h> |
21 |
||
22 |
#include "fat_utils.h" |
|
23 |
#include "t_server.h" |
|
24 |
#include "t_chlffs.h" |
|
25 |
||
26 |
using namespace Fat_Test_Utils; |
|
27 |
||
28 |
RTest test(_L("t_falsespace")); |
|
29 |
||
30 |
const TInt KNumberThreads=2; |
|
31 |
const TInt KHeapSize=0x2000; |
|
32 |
||
33 |
static TInt RsrvSpaceThread(TAny* aArg); |
|
34 |
static TInt SessCloseThread(TAny* aArg); |
|
35 |
static void GetFreeDiskSpace(TInt64 &aFree); |
|
36 |
||
37 |
||
38 |
TInt gCount; //count of files used to fill up the disk |
|
39 |
TInt gTestDrive; //drive number of the drive currently being tested |
|
40 |
||
41 |
TChar gCh; |
|
42 |
||
43 |
_LIT(KBasePath,"\\F32-TST\\FILLDIR\\"); |
|
44 |
_LIT(KBaseName,"\\F32-TST\\FILLDIR\\FILE"); |
|
45 |
||
46 |
_LIT(KTestFile,"?:\\test.txt"); |
|
47 |
_LIT8(KTestData, "12345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678"); |
|
48 |
_LIT(KDir, "?:\\adodgydir\\"); |
|
49 |
_LIT(KDrv,"?:\\"); |
|
50 |
_LIT(KNewName,"?:\\newname.txt"); |
|
51 |
||
52 |
||
53 |
void FormatDrive() |
|
54 |
{ |
|
55 |
TInt nRes; |
|
56 |
||
57 |
||
58 |
#if 0 |
|
59 |
//-- FAT32 SPC:1; for the FAT32 testing on the emulator |
|
60 |
TFatFormatParam fp; |
|
61 |
fp.iFatType = EFat32; |
|
62 |
fp.iSecPerCluster = 1; |
|
63 |
||
64 |
nRes = FormatFatDrive(TheFs, gTestDrive, ETrue, &fp); |
|
65 |
#else |
|
66 |
||
67 |
nRes = FormatFatDrive(TheFs, gTestDrive, ETrue); |
|
68 |
||
69 |
#endif |
|
70 |
||
131 | 71 |
test_KErrNone(nRes); |
0 | 72 |
} |
73 |
||
74 |
void SynchronousClose(RFs &aSession) |
|
75 |
{ |
|
76 |
TRequestStatus s; |
|
77 |
aSession.NotifyDestruction(s); |
|
78 |
test(s.Int()==KRequestPending); |
|
79 |
aSession.Close(); |
|
80 |
User::WaitForRequest(s); |
|
81 |
} |
|
82 |
||
83 |
||
84 |
static TInt CreateFileX(const TDesC& aBaseName,TInt aX, TInt aFileSize) |
|
85 |
// |
|
86 |
// Create a large file. Return KErrEof or KErrNone |
|
87 |
// |
|
88 |
{ |
|
89 |
||
90 |
TBuf<128> fileName=aBaseName; |
|
91 |
fileName.AppendNum(aX); |
|
92 |
RFile file; |
|
93 |
||
94 |
TInt r=file.Replace(TheFs,fileName,EFileWrite); |
|
95 |
if (r==KErrDiskFull) |
|
96 |
return(r); |
|
97 |
if (r!=KErrNone) |
|
98 |
{ |
|
99 |
test.Printf(_L("ERROR:: Replace returned %d\n"),r); |
|
100 |
test(0); |
|
101 |
return(KErrDiskFull); |
|
102 |
} |
|
103 |
||
104 |
if (!IsTestingLFFS()) |
|
105 |
r=file.SetSize(aFileSize); |
|
106 |
else |
|
107 |
{ |
|
108 |
TBuf8<1024> testdata(1024); |
|
109 |
TInt count=(aFileSize/testdata.Length()); |
|
110 |
r=KErrNone; |
|
111 |
while (count-- && r==KErrNone) |
|
112 |
r=file.Write(testdata); |
|
113 |
} |
|
114 |
if (r==KErrDiskFull) |
|
115 |
{ |
|
116 |
file.Close(); |
|
117 |
return(r); |
|
118 |
} |
|
119 |
if (r!=KErrNone) |
|
120 |
{ |
|
121 |
test.Printf(_L("ERROR:: SetSize/Write returned %d\n"),r); |
|
122 |
test(0); |
|
123 |
//test.Getch(); |
|
124 |
file.Close(); |
|
125 |
return(KErrDiskFull); |
|
126 |
} |
|
127 |
||
128 |
file.Close(); |
|
129 |
||
130 |
test.Printf(_L("Created file %d size %d\n"),aX,aFileSize); |
|
131 |
return(KErrNone); |
|
132 |
} |
|
133 |
||
134 |
LOCAL_C TInt DeleteFileX(const TDesC& aBaseName,TInt aX) |
|
135 |
// |
|
136 |
// Delete a large file |
|
137 |
// |
|
138 |
{ |
|
139 |
TBuf<128> fileName=aBaseName; |
|
140 |
fileName.AppendNum(aX); |
|
141 |
return TheFs.Delete(fileName); |
|
142 |
} |
|
143 |
||
144 |
||
145 |
static void FillUpDisk() |
|
146 |
// |
|
147 |
// Test that a full disk is ok |
|
148 |
// |
|
149 |
{ |
|
150 |
||
151 |
test.Start(_L("Fill disk to capacity")); |
|
152 |
TInt r=TheFs.MkDirAll(KBasePath); |
|
131 | 153 |
test_Value(r, r == KErrNone || r==KErrAlreadyExists); |
0 | 154 |
gCount=0; |
155 |
TFileName sessionPath; |
|
156 |
r=TheFs.SessionPath(sessionPath); |
|
131 | 157 |
test_KErrNone(r); |
0 | 158 |
TBuf<128> fileName=KBaseName(); |
159 |
||
160 |
TInt64 freespace=0; |
|
161 |
TInt64 freespaceBeforeScanDrive = 0; |
|
162 |
TInt64 freespaceAfterScanDrive = 0; |
|
163 |
||
164 |
do |
|
165 |
{ |
|
166 |
GetFreeDiskSpace(freespace); |
|
167 |
TInt fillfilesize=0; |
|
168 |
if (I64HIGH(freespace)) |
|
169 |
fillfilesize=KMaxTInt; |
|
170 |
else |
|
171 |
fillfilesize=I64LOW(freespace)* 7/8; |
|
172 |
||
173 |
FOREVER |
|
174 |
{ |
|
175 |
TInt r=CreateFileX(fileName,gCount,fillfilesize); |
|
176 |
if (r==KErrDiskFull) |
|
177 |
{ |
|
178 |
if(fillfilesize <= 2) |
|
179 |
break; |
|
180 |
else |
|
181 |
fillfilesize=fillfilesize/2; |
|
182 |
} |
|
131 | 183 |
test_Value(r, r == KErrNone || r==KErrDiskFull); |
0 | 184 |
if(r==KErrNone) |
185 |
gCount++; |
|
186 |
} |
|
187 |
||
188 |
r=TheFs.CheckDisk(fileName); |
|
189 |
if (r!=KErrNone && r!=KErrNotSupported) |
|
190 |
{ |
|
191 |
test.Printf(_L("ERROR:: CheckDisk returned %d\n"),r); |
|
192 |
test(0); |
|
193 |
||
194 |
} |
|
195 |
||
196 |
// Test that scan drive passes on a full disk |
|
197 |
// DEF071696 - KErrCorrupt on Scan Drive |
|
198 |
GetFreeDiskSpace(freespaceBeforeScanDrive); |
|
199 |
test.Printf(_L("Before ScanDrive freeSpace = %08X:%08X\n"), |
|
200 |
I64HIGH(freespaceBeforeScanDrive), I64LOW(freespaceBeforeScanDrive)); |
|
201 |
r = TheFs.ScanDrive(fileName); |
|
202 |
if (r!=KErrNone && r!=KErrNotSupported) |
|
203 |
{ |
|
204 |
test.Printf(_L("ScanDrive returned %d\n"), r); |
|
205 |
test(0); |
|
206 |
} |
|
207 |
GetFreeDiskSpace(freespaceAfterScanDrive); |
|
208 |
test.Printf(_L("After ScanDrive freeSpace = %08X:%08X\n"), |
|
209 |
I64HIGH(freespaceAfterScanDrive), I64LOW(freespaceAfterScanDrive)); |
|
210 |
} |
|
211 |
while (freespaceBeforeScanDrive != freespaceAfterScanDrive ); |
|
212 |
||
213 |
gCount--; |
|
214 |
||
215 |
test.End(); |
|
216 |
} |
|
217 |
||
218 |
static void GetFreeDiskSpace(TInt64 &aFree) |
|
219 |
// |
|
220 |
// Get free disk space |
|
221 |
// |
|
222 |
{ |
|
223 |
TVolumeInfo v; |
|
224 |
||
225 |
TInt r=TheFs.Volume(v,gTestDrive); |
|
131 | 226 |
test_KErrNone(r); |
0 | 227 |
aFree=v.iFree; |
228 |
} |
|
229 |
||
230 |
||
231 |
static void Test1() |
|
232 |
// |
|
233 |
// Test the API fundamentaly works for one session |
|
234 |
// |
|
235 |
{ |
|
236 |
test.Next(_L("Test Disk Space reserve APIs")); |
|
237 |
TInt r=0; |
|
238 |
||
239 |
FormatDrive(); |
|
240 |
||
241 |
TInt64 free2; |
|
242 |
TInt64 free1; |
|
243 |
TInt64 diff; |
|
244 |
||
245 |
r=TheFs.GetReserveAccess(gTestDrive); |
|
131 | 246 |
test_Value(r, r == KErrPermissionDenied); |
0 | 247 |
|
248 |
//make sure nothing odd happens if we didnt already have access |
|
249 |
r=TheFs.ReleaseReserveAccess(gTestDrive); |
|
131 | 250 |
test_KErrNone(r); |
0 | 251 |
|
252 |
||
253 |
GetFreeDiskSpace(free2); |
|
254 |
||
255 |
r=TheFs.ReserveDriveSpace(gTestDrive,0x1000); |
|
131 | 256 |
test_KErrNone(r); |
0 | 257 |
|
258 |
GetFreeDiskSpace(free1); |
|
259 |
diff = free2 - free1; |
|
260 |
test(I64INT(diff) > 0xfe0 && I64INT(diff) < 0x1100); |
|
261 |
||
262 |
r=TheFs.GetReserveAccess(gTestDrive); |
|
131 | 263 |
test_KErrNone(r); |
0 | 264 |
|
265 |
GetFreeDiskSpace(free1); |
|
266 |
TInt64 temp = free2-free1; |
|
267 |
test(I64INT(temp)>(-0x90) && I64INT(temp)<0x90); |
|
268 |
||
269 |
r=TheFs.ReleaseReserveAccess(gTestDrive); |
|
131 | 270 |
test_KErrNone(r); |
0 | 271 |
GetFreeDiskSpace(free1); |
272 |
||
273 |
diff = free2 - free1; |
|
274 |
test(I64INT(diff) > 0xfe0 && I64INT(diff) < 0x1100); |
|
275 |
||
276 |
||
277 |
//test reallocation of reserved space is possible |
|
278 |
r=TheFs.ReserveDriveSpace(gTestDrive,0x2000); |
|
131 | 279 |
test_KErrNone(r); |
0 | 280 |
|
281 |
//test upper limit of reserved space |
|
282 |
r=TheFs.ReserveDriveSpace(gTestDrive,0x2000000); |
|
131 | 283 |
test_Value(r, r == KErrArgument); |
0 | 284 |
|
285 |
r=TheFs.ReserveDriveSpace(gTestDrive,0); |
|
131 | 286 |
test_KErrNone(r); |
0 | 287 |
|
288 |
r=TheFs.GetReserveAccess(gTestDrive); |
|
131 | 289 |
test_Value(r, r == KErrPermissionDenied); |
0 | 290 |
|
291 |
//make sure nothing odd happens if we didnt already have access |
|
292 |
r=TheFs.ReleaseReserveAccess(gTestDrive); |
|
131 | 293 |
test_KErrNone(r); |
0 | 294 |
|
295 |
r=TheFs.ReserveDriveSpace(gTestDrive,-45); |
|
131 | 296 |
test_Value(r, r == KErrArgument); |
0 | 297 |
} |
298 |
||
299 |
||
300 |
static void Test2() |
|
301 |
// |
|
302 |
// Test multiple sessions, ensure the drive limit is not exceeded |
|
303 |
// |
|
304 |
{ |
|
305 |
||
306 |
test.Next(_L("Test Session and total reserve limits")); |
|
307 |
||
308 |
FormatDrive(); |
|
309 |
||
310 |
TInt i=0; |
|
311 |
TInt r=0; |
|
312 |
RFs sessions[17]; |
|
313 |
TVolumeInfo v; |
|
314 |
||
315 |
//Connect Sessions |
|
316 |
for(i=0; i<17; i++) |
|
317 |
{ |
|
318 |
r = sessions[i].Connect(); |
|
131 | 319 |
test_KErrNone(r); |
0 | 320 |
} |
321 |
||
322 |
test.Next(_L("Test breaching sesson reserve limit")); |
|
323 |
r=sessions[0].ReserveDriveSpace(gTestDrive,0x10001); |
|
131 | 324 |
test_Value(r, r == KErrArgument); |
0 | 325 |
|
326 |
//Get Volume Free Space |
|
327 |
r = sessions[0].Volume(v, gTestDrive); |
|
328 |
||
329 |
if(v.iFree > 0x100000) |
|
330 |
{ |
|
331 |
test.Next(_L("Test breaching drive reserve limit")); |
|
332 |
||
333 |
for (i=0; i<16; i++) |
|
334 |
{ |
|
335 |
r=sessions[i].ReserveDriveSpace(gTestDrive,0x10000); |
|
131 | 336 |
test_KErrNone(r); |
0 | 337 |
} |
338 |
||
339 |
//The straw |
|
340 |
r=sessions[16].ReserveDriveSpace(gTestDrive,0x10); |
|
131 | 341 |
test_Value(r, r == KErrTooBig); |
0 | 342 |
} |
343 |
else |
|
344 |
{ |
|
345 |
test.Printf(_L("Drive too small: breaching drive reserve limit test skipped\n")); |
|
346 |
test.Next(_L("Testing exhausting available drive free space instead")); |
|
347 |
||
348 |
for(i=0; (v.iFree -= 0x10000) >= 0; i++) |
|
349 |
{ |
|
350 |
r=sessions[i].ReserveDriveSpace(gTestDrive,0x10000); |
|
131 | 351 |
test_KErrNone(r); |
0 | 352 |
} |
353 |
||
354 |
//The straw |
|
355 |
r=sessions[i].ReserveDriveSpace(gTestDrive,0x10000); |
|
131 | 356 |
test_Value(r, r == KErrDiskFull); |
0 | 357 |
} |
358 |
||
359 |
//Close Sessions |
|
360 |
for(i=0; i<17; i++) |
|
361 |
{ |
|
362 |
SynchronousClose(sessions[i]); |
|
363 |
} |
|
364 |
} |
|
365 |
||
366 |
static void Test3() |
|
367 |
// |
|
368 |
// Test session cleanup |
|
369 |
// |
|
370 |
{ |
|
371 |
test.Next(_L("Test session close and clean up of resrved space")); |
|
372 |
||
373 |
FormatDrive(); |
|
374 |
||
375 |
RFs fs1; |
|
376 |
RFs fs2; |
|
377 |
TInt64 free2(0); |
|
378 |
TInt64 free1(0); |
|
379 |
TInt64 diff(0); |
|
380 |
||
381 |
TInt r=0; |
|
382 |
r = fs1.Connect(); |
|
131 | 383 |
test_KErrNone(r); |
0 | 384 |
r = fs2.Connect(); |
131 | 385 |
test_KErrNone(r); |
0 | 386 |
|
387 |
GetFreeDiskSpace(free1); |
|
388 |
||
389 |
r=fs1.ReserveDriveSpace(gTestDrive,0x10000); |
|
131 | 390 |
test_KErrNone(r); |
0 | 391 |
r=fs2.ReserveDriveSpace(gTestDrive,0x10000); |
131 | 392 |
test_KErrNone(r); |
0 | 393 |
|
394 |
GetFreeDiskSpace(free2); |
|
395 |
diff = free1 - free2; |
|
396 |
test(I64INT(diff)>0x1FBD0 && I64INT(diff)<0x21000); |
|
397 |
||
398 |
SynchronousClose(fs1); |
|
399 |
||
400 |
GetFreeDiskSpace(free2); |
|
401 |
diff = free1-free2; |
|
402 |
test(I64INT(diff)>0xFA00 && I64INT(diff)<0x103C4); |
|
403 |
||
404 |
r = fs1.Connect(); |
|
131 | 405 |
test_KErrNone(r); |
0 | 406 |
|
407 |
GetFreeDiskSpace(free1); |
|
408 |
diff= free1-free2; |
|
409 |
test(I64INT(diff)== 0 || I64INT(diff)<0xFA0 ); |
|
410 |
||
411 |
r=fs1.ReserveDriveSpace(gTestDrive,0x10000); |
|
131 | 412 |
test_KErrNone(r); |
0 | 413 |
|
414 |
GetFreeDiskSpace(free2); |
|
415 |
diff = free1 - free2; |
|
416 |
test(I64INT(diff)>0xFA00 && I64INT(diff)<0x103C4); |
|
417 |
||
418 |
// Make sure no reserve space is allocated |
|
419 |
r=fs1.ReserveDriveSpace(gTestDrive,0); |
|
131 | 420 |
test_KErrNone(r); |
0 | 421 |
r=fs2.ReserveDriveSpace(gTestDrive,0); |
131 | 422 |
test_KErrNone(r); |
0 | 423 |
|
424 |
// Now fill up the disk |
|
425 |
FillUpDisk(); |
|
426 |
||
427 |
// Should fail as there is no space |
|
428 |
r=fs1.ReserveDriveSpace(gTestDrive,0x10000); |
|
131 | 429 |
test_Value(r, r == KErrDiskFull); |
0 | 430 |
|
431 |
SynchronousClose(fs1); |
|
432 |
SynchronousClose(fs2); |
|
433 |
} |
|
434 |
||
435 |
||
436 |
static void Test4() |
|
437 |
// |
|
438 |
// Test real out of disk space conditions i.e. properly run out of disk space and try to |
|
439 |
// reserve an area etc |
|
440 |
// |
|
441 |
{ |
|
442 |
test.Next(_L("Test Filling disk and using APIs")); |
|
443 |
||
444 |
if(IsTestingLFFS()) |
|
445 |
{ |
|
446 |
//-- This test is not valid for LFFS, because free space on this FS can change itself because of some |
|
447 |
//-- internal FS activities |
|
448 |
test.Printf(_L("This test is inconsistent on LFFS\n")); |
|
449 |
return; |
|
450 |
} |
|
451 |
||
452 |
FormatDrive(); |
|
453 |
||
454 |
RFs fs; |
|
455 |
TInt r=fs.Connect(); |
|
131 | 456 |
test_KErrNone(r); |
0 | 457 |
TInt64 freeA(0); |
458 |
TInt64 freeB(0); |
|
459 |
RFile file; |
|
460 |
||
461 |
//start with known amount of space |
|
462 |
||
463 |
//create a single file to use for futher tests |
|
464 |
TBuf<20> buf; |
|
465 |
buf=KTestFile; |
|
466 |
buf[0]=(TUint16)gCh; |
|
467 |
||
468 |
r=file.Replace(fs, buf, EFileWrite); |
|
131 | 469 |
test_KErrNone(r); |
0 | 470 |
|
471 |
r=file.Write(KTestData()); |
|
131 | 472 |
test_KErrNone(r); |
0 | 473 |
|
474 |
file.Close(); |
|
475 |
||
476 |
r=fs.ReserveDriveSpace(gTestDrive,0x10000); //reserve some disk space |
|
131 | 477 |
test_KErrNone(r); |
0 | 478 |
|
479 |
FillUpDisk(); //fill up the disk |
|
480 |
||
481 |
TVolumeInfo v; //get disk space |
|
482 |
r=fs.Volume(v,gTestDrive); |
|
131 | 483 |
test_KErrNone(r); |
0 | 484 |
freeA=v.iFree; |
485 |
||
486 |
r=fs.GetReserveAccess(gTestDrive); //get access to reserve space |
|
131 | 487 |
test_KErrNone(r); |
0 | 488 |
|
489 |
r=fs.Volume(v,gTestDrive); //get disk space |
|
131 | 490 |
test_KErrNone(r); |
0 | 491 |
freeB=v.iFree; |
492 |
||
493 |
r=fs.ReleaseReserveAccess(gTestDrive); //release reserve space |
|
131 | 494 |
test_KErrNone(r); |
0 | 495 |
|
496 |
test(freeA == (freeB - 0x10000)); //test difference in space is equal to the amount reserved |
|
497 |
||
498 |
r=fs.Volume(v,gTestDrive); //get disk space |
|
131 | 499 |
test_KErrNone(r); |
0 | 500 |
freeB=v.iFree; |
501 |
test(freeA == freeB); //check reading is still correct |
|
502 |
||
503 |
TBuf <20> dir = KDir(); |
|
504 |
dir[0]=(TUint16)gCh; |
|
505 |
r=fs.MkDir(dir); |
|
131 | 506 |
test_Value(r, r == KErrDiskFull); |
0 | 507 |
|
508 |
r=fs.MkDirAll(dir); |
|
131 | 509 |
test_Value(r, r == KErrDiskFull); |
0 | 510 |
|
511 |
TFileName temp; |
|
512 |
TBuf<5> drv = KDrv(); |
|
513 |
drv[0]=(TUint16)gCh; |
|
514 |
r=file.Temp(fs, drv, temp, EFileWrite); |
|
131 | 515 |
test_Value(r, r == KErrDiskFull); |
0 | 516 |
|
517 |
r=file.Replace(fs, buf, EFileWrite); |
|
131 | 518 |
test_Value(r, r == KErrDiskFull); |
0 | 519 |
|
520 |
r=file.Create(fs, buf, EFileWrite); |
|
131 | 521 |
test_Value(r, r == KErrDiskFull); |
0 | 522 |
|
523 |
r=file.Open(fs, buf, EFileWrite); |
|
131 | 524 |
test_KErrNone(r); |
0 | 525 |
|
526 |
r=file.Write(128, KTestData()); |
|
527 |
||
528 |
if ((gDriveCacheFlags & EFileCacheWriteOn) && (r == KErrNone)) |
|
529 |
r = file.Flush(); |
|
530 |
||
131 | 531 |
test_Value(r, r == KErrDiskFull); |
0 | 532 |
|
533 |
r=file.SetSize(0x1000); |
|
131 | 534 |
test_Value(r, r == KErrDiskFull); |
0 | 535 |
|
536 |
r=file.SetAtt(KEntryAttHidden,0); |
|
131 | 537 |
test_Value(r, r == KErrDiskFull); |
0 | 538 |
|
539 |
TTime dtime; |
|
540 |
r=file.SetModified(dtime); |
|
131 | 541 |
test_Value(r, r == KErrDiskFull); |
0 | 542 |
|
543 |
r=file.Set(dtime,KEntryAttHidden,0); |
|
131 | 544 |
test_Value(r, r == KErrDiskFull); |
0 | 545 |
|
546 |
r=file.Rename(buf); |
|
131 | 547 |
test_Value(r, r == KErrDiskFull); |
0 | 548 |
|
549 |
file.Close(); |
|
550 |
||
551 |
||
552 |
// Test that we can create a temporary file & write to it after acquiring reserved access, |
|
553 |
r=fs.GetReserveAccess(gTestDrive); //get access to reserve space |
|
131 | 554 |
test_KErrNone(r); |
0 | 555 |
|
556 |
r=fs.Volume(v,gTestDrive); //get disk space |
|
131 | 557 |
test_KErrNone(r); |
0 | 558 |
freeA = v.iFree; |
559 |
||
560 |
r=file.Temp(fs, drv, temp, EFileWrite); |
|
131 | 561 |
test_KErrNone(r); |
0 | 562 |
|
563 |
r = file.Write(KTestData()); |
|
131 | 564 |
test_KErrNone(r); |
0 | 565 |
|
566 |
// If write caching is enabled, call RFs::Entry() to flush the file "anonymously" |
|
567 |
if ((gDriveCacheFlags & EFileCacheWriteOn) && (r == KErrNone)) |
|
568 |
{ |
|
569 |
r = file.Flush(); |
|
131 | 570 |
test_KErrNone(r); |
0 | 571 |
} |
572 |
||
573 |
r=fs.Volume(v,gTestDrive); //get disk space |
|
131 | 574 |
test_KErrNone(r); |
0 | 575 |
freeB = v.iFree; |
576 |
test (freeB < freeA); |
|
577 |
||
578 |
file.Close(); |
|
579 |
||
580 |
r=fs.ReleaseReserveAccess(gTestDrive); //release reserve space |
|
131 | 581 |
test_KErrNone(r); |
0 | 582 |
|
583 |
||
584 |
TBuf<20> newname =KNewName(); |
|
585 |
newname[0]=(TUint16)gCh; |
|
586 |
r=fs.Rename(buf, newname); |
|
131 | 587 |
test_Value(r, r == KErrDiskFull); |
0 | 588 |
|
589 |
r=fs.Replace(buf, newname); |
|
131 | 590 |
test_Value(r, r == KErrDiskFull); |
0 | 591 |
|
592 |
r=fs.SetEntry(buf, dtime, KEntryAttHidden, 0); |
|
131 | 593 |
test_Value(r, r == KErrDiskFull); |
0 | 594 |
|
595 |
r=fs.CreatePrivatePath(gTestDrive); |
|
131 | 596 |
test_Value(r, r == KErrDiskFull); |
0 | 597 |
|
598 |
r=fs.SetVolumeLabel(_L("Moooo"), gTestDrive); |
|
131 | 599 |
test_Value(r, r == KErrDiskFull); |
0 | 600 |
|
601 |
r=fs.SetModified(buf, dtime); |
|
131 | 602 |
test_Value(r, r == KErrDiskFull); |
0 | 603 |
|
604 |
SynchronousClose(fs); |
|
605 |
} |
|
606 |
||
607 |
||
608 |
||
609 |
static void Test5() |
|
610 |
// |
|
611 |
// |
|
612 |
// |
|
613 |
{ |
|
614 |
test.Next(_L("Test Session limits")); |
|
615 |
||
616 |
if(IsTestingLFFS()) |
|
617 |
{ |
|
618 |
//-- This test is not valid for LFFS, because free space on this FS can change itself because of some |
|
619 |
//-- internal FS activities |
|
620 |
test.Printf(_L("This test is inconsistent on LFFS\n")); |
|
621 |
return; |
|
622 |
} |
|
623 |
||
624 |
||
625 |
RFs fs1; |
|
626 |
RFs fs2; |
|
627 |
TInt r=KErrNone; |
|
628 |
||
629 |
r=fs1.Connect(); |
|
131 | 630 |
test_KErrNone(r); |
0 | 631 |
r=fs2.Connect(); |
131 | 632 |
test_KErrNone(r); |
0 | 633 |
|
634 |
FormatDrive(); |
|
635 |
||
636 |
r=fs1.ReserveDriveSpace(gTestDrive,0x10000); |
|
131 | 637 |
test_KErrNone(r); |
0 | 638 |
|
639 |
r=fs2.ReserveDriveSpace(gTestDrive,0x10000); |
|
131 | 640 |
test_KErrNone(r); |
0 | 641 |
|
642 |
FillUpDisk(); |
|
643 |
||
644 |
r=fs1.GetReserveAccess(gTestDrive); |
|
131 | 645 |
test_KErrNone(r); |
0 | 646 |
|
647 |
TBuf<20> dir = KDir(); |
|
648 |
dir[0]=(TUint16)gCh; |
|
649 |
||
650 |
||
651 |
r=fs2.MkDir(dir); |
|
131 | 652 |
test_Value(r, r == KErrDiskFull); |
0 | 653 |
|
654 |
r=fs1.ReserveDriveSpace(gTestDrive,0); //can not release reserve space while you have reserve access |
|
131 | 655 |
test_Value(r, r == KErrInUse); |
0 | 656 |
|
657 |
r=fs1.ReleaseReserveAccess(gTestDrive); |
|
131 | 658 |
test_KErrNone(r); |
0 | 659 |
|
660 |
r=fs1.ReserveDriveSpace(gTestDrive,0); |
|
131 | 661 |
test_KErrNone(r); |
0 | 662 |
|
663 |
r=fs2.MkDir(dir); |
|
131 | 664 |
test_KErrNone(r); |
0 | 665 |
|
666 |
SynchronousClose(fs1); |
|
667 |
SynchronousClose(fs2); |
|
668 |
} |
|
669 |
||
670 |
static TInt RsrvSpaceThread(TAny* aArg) |
|
671 |
{ |
|
672 |
TInt r=KErrNone; |
|
673 |
TInt64 fr1; |
|
674 |
TInt64 fr2; |
|
675 |
TInt64 diff; |
|
676 |
||
677 |
TVolumeInfo v; |
|
678 |
r=((RFs*)aArg)->Volume(v,gTestDrive); |
|
679 |
if(r!=KErrNone) |
|
680 |
return(r); |
|
681 |
||
682 |
fr1=v.iFree; |
|
683 |
||
684 |
r=((RFs*)aArg)->ReserveDriveSpace(gTestDrive,0x10000); |
|
685 |
if(r!=KErrNone) |
|
686 |
return(r); |
|
687 |
||
688 |
r=((RFs*)aArg)->Volume(v,gTestDrive); |
|
689 |
if(r!=KErrNone) |
|
690 |
return(r); |
|
691 |
fr2=v.iFree; |
|
692 |
||
693 |
diff=fr1-fr2; |
|
694 |
if(!(I64INT(diff)> 0xef38 && I64INT(diff)<0xf100)) |
|
695 |
return(KErrGeneral); |
|
696 |
return r; |
|
697 |
} |
|
698 |
||
699 |
static TInt SessCloseThread(TAny* aArg) |
|
700 |
{ |
|
701 |
TInt r=KErrNone; |
|
702 |
TInt64 fr1; |
|
703 |
TInt64 fr2; |
|
704 |
TInt64 diff; |
|
705 |
||
706 |
TVolumeInfo v; |
|
707 |
r=((RFs*)aArg)->Volume(v,gTestDrive); |
|
708 |
if(r!=KErrNone) |
|
709 |
return(r); |
|
710 |
fr1=v.iFree; |
|
711 |
||
712 |
((RFs*)aArg)->ReserveDriveSpace(gTestDrive,0x1000); |
|
713 |
||
714 |
r=((RFs*)aArg)->Volume(v,gTestDrive); |
|
715 |
if(r!=KErrNone) |
|
716 |
return(r); |
|
717 |
fr2=v.iFree; |
|
718 |
||
719 |
diff=fr2-fr1; |
|
720 |
if(!(I64INT(diff)> 0xef38 && I64INT(diff)<0xf100)) |
|
721 |
return(KErrGeneral); |
|
722 |
||
723 |
SynchronousClose(*((RFs*)aArg)); |
|
724 |
||
725 |
return r; |
|
726 |
} |
|
727 |
||
728 |
static void Test6() |
|
729 |
// |
|
730 |
// Test sharabale session |
|
731 |
// |
|
732 |
{ |
|
733 |
||
734 |
test.Next(_L("Test sharable session")); |
|
735 |
||
736 |
RFs fsess; |
|
737 |
TInt r=KErrNone; |
|
738 |
TInt64 free1(0); |
|
739 |
TInt64 free2(0); |
|
740 |
TInt64 diff(0); |
|
741 |
RThread t[KNumberThreads]; |
|
742 |
TRequestStatus tStat[KNumberThreads]; |
|
743 |
||
744 |
r=fsess.Connect(); |
|
131 | 745 |
test_KErrNone(r); |
0 | 746 |
|
747 |
FormatDrive(); |
|
748 |
||
749 |
r= fsess.ShareAuto(); |
|
131 | 750 |
test_KErrNone(r); |
0 | 751 |
|
752 |
GetFreeDiskSpace(free1); |
|
753 |
||
754 |
fsess.ReserveDriveSpace(gTestDrive,0x1000); |
|
755 |
||
756 |
r = t[0].Create(_L("Sub_Thread1"),RsrvSpaceThread,KDefaultStackSize,KHeapSize,KHeapSize,&fsess); |
|
131 | 757 |
test_KErrNone(r); |
0 | 758 |
|
759 |
t[0].Rendezvous(tStat[0]); |
|
760 |
t[0].Resume(); |
|
761 |
||
762 |
User::WaitForRequest(tStat[0]); |
|
763 |
||
764 |
t[0].Close(); |
|
765 |
test(tStat[0]==KErrNone); |
|
766 |
||
767 |
r = t[1].Create(_L("Sub_Thread2"),SessCloseThread,KDefaultStackSize,KHeapSize,KHeapSize,&fsess); |
|
131 | 768 |
test_KErrNone(r); |
0 | 769 |
|
770 |
t[1].Rendezvous(tStat[1]); |
|
771 |
t[1].Resume(); |
|
772 |
||
773 |
User::WaitForRequest(tStat[1]); |
|
774 |
||
775 |
t[1].Close(); |
|
776 |
test(tStat[1]==KErrNone); |
|
777 |
||
778 |
GetFreeDiskSpace(free2); |
|
779 |
||
780 |
diff = free1-free2; |
|
781 |
test(I64INT(diff)== 0 || I64INT(diff)<0xFA0 ); |
|
782 |
} |
|
783 |
||
784 |
||
785 |
static void Test7() |
|
786 |
// |
|
787 |
// Tests notifier events for sessions with and without reserved access |
|
788 |
// |
|
789 |
{ |
|
790 |
if(IsTestingLFFS()) |
|
791 |
{ |
|
792 |
// This test is not valid for LFFS... |
|
793 |
test.Printf(_L("Test reserved access notification not run for LFFS\n")); |
|
794 |
return; |
|
795 |
} |
|
796 |
||
797 |
||
798 |
test.Next(_L("Test reserved access notification")); |
|
799 |
||
800 |
FormatDrive(); |
|
801 |
||
802 |
RFs theNrm; |
|
803 |
RFs theRes; |
|
804 |
||
805 |
TInt err = theNrm.Connect(); |
|
806 |
test(KErrNone == err); |
|
807 |
||
808 |
err = theRes.Connect(); |
|
809 |
test(KErrNone == err); |
|
810 |
||
811 |
||
812 |
TInt64 freeSpace(0); |
|
813 |
GetFreeDiskSpace(freeSpace); |
|
814 |
||
815 |
RFs theTestSession; |
|
816 |
theTestSession.Connect(); |
|
817 |
||
818 |
_LIT(KFileFiller, "?:\\t_falseSpaceFiller"); |
|
819 |
TBuf<25> fileName; |
|
820 |
fileName = KFileFiller; |
|
821 |
fileName[0] = (TUint16)gCh; |
|
822 |
||
823 |
err = theTestSession.Connect(); |
|
131 | 824 |
test_KErrNone(err); |
0 | 825 |
|
826 |
// determine the cluster size |
|
827 |
RFile theFile; |
|
828 |
err=theFile.Replace(theTestSession, fileName, EFileShareAny | EFileWrite); |
|
131 | 829 |
test_KErrNone(err); |
0 | 830 |
|
831 |
// Neither notifier should be triggered here |
|
832 |
err = theFile.SetSize(1); |
|
833 |
test(KErrNone == err); |
|
834 |
theFile.Close(); |
|
835 |
||
836 |
TInt64 newFreeSpace; |
|
837 |
GetFreeDiskSpace(newFreeSpace); |
|
838 |
TInt clusterSize = TInt(freeSpace - newFreeSpace); |
|
839 |
theTestSession.Delete(fileName); |
|
840 |
GetFreeDiskSpace(newFreeSpace); |
|
841 |
test (newFreeSpace == freeSpace); |
|
842 |
||
843 |
TInt resSpace = Max(0x1000, clusterSize); |
|
844 |
||
845 |
TVolumeInfo volInfo; |
|
846 |
theNrm.Volume(volInfo, gTestDrive); |
|
847 |
test(volInfo.iFree == freeSpace); |
|
848 |
||
849 |
err = theRes.ReserveDriveSpace(gTestDrive, resSpace); |
|
850 |
test(KErrNone == err); |
|
851 |
err = theRes.GetReserveAccess(gTestDrive); |
|
852 |
test(KErrNone == err); |
|
853 |
||
854 |
theRes.Volume(volInfo, gTestDrive); |
|
855 |
test(volInfo.iFree == freeSpace); |
|
856 |
||
857 |
theNrm.Volume(volInfo, gTestDrive); |
|
858 |
test(volInfo.iFree == freeSpace - resSpace); |
|
859 |
||
860 |
||
861 |
// |
|
862 |
// Register the notifiers and verify that the only the "Normal" |
|
863 |
// and not the "Reserved" session is triggered. |
|
864 |
// |
|
865 |
TRequestStatus statNrm; |
|
866 |
TRequestStatus statRes; |
|
867 |
||
868 |
TInt64 threshold(freeSpace - resSpace*2); |
|
869 |
theNrm.NotifyDiskSpace(threshold, gTestDrive, statNrm); |
|
870 |
theRes.NotifyDiskSpace(threshold, gTestDrive, statRes); |
|
871 |
test((statNrm == KRequestPending) && (statRes == KRequestPending)); |
|
872 |
||
873 |
||
874 |
// |
|
875 |
// Main part of the test starts here. |
|
876 |
// First we create a new file, then we increase its size to cause the |
|
877 |
// "Normal" notifier to trigger but not the "Reserved" notifier |
|
878 |
// |
|
879 |
err=theFile.Replace(theTestSession, fileName, EFileShareAny | EFileWrite); |
|
131 | 880 |
test_KErrNone(err); |
0 | 881 |
test((statNrm == KRequestPending) && (statRes == KRequestPending)); |
882 |
||
883 |
// Neither notifier should be triggered here |
|
884 |
err = theFile.SetSize(resSpace); |
|
885 |
test(KErrNone == err); |
|
886 |
test((statNrm == KRequestPending) && (statRes == KRequestPending)); |
|
887 |
||
888 |
// This should trigger the "Normal" notifier, but not the "Reserved" one |
|
889 |
err = theFile.SetSize(2*resSpace); |
|
890 |
test(KErrNone == err); |
|
891 |
test((statNrm == KErrNone) && (statRes == KRequestPending)); |
|
892 |
||
893 |
||
894 |
// |
|
895 |
// Reset the "Normal" notifier then increase the amount of reserved space |
|
896 |
// on the drive. This should re-trigger the "Normal" notifier but leave |
|
897 |
// the "Reserved" notifier untouched. |
|
898 |
// |
|
899 |
theNrm.NotifyDiskSpace(threshold - resSpace, gTestDrive, statNrm); |
|
900 |
test((statNrm == KRequestPending) && (statRes == KRequestPending)); |
|
901 |
||
902 |
err = theTestSession.ReserveDriveSpace(gTestDrive, resSpace * 3); |
|
903 |
if (err != KErrArgument) // will have exceeded limit if resSpace = 32K |
|
904 |
{ |
|
131 | 905 |
test_KErrNone(err); |
0 | 906 |
test((statNrm == KErrNone) && (statRes == KRequestPending)); |
907 |
} |
|
908 |
||
909 |
// |
|
910 |
// All done - tidy up. |
|
911 |
// |
|
912 |
theFile.Close(); |
|
913 |
theTestSession.Delete(fileName); |
|
914 |
theTestSession.Close(); |
|
915 |
theNrm.Close(); |
|
916 |
theRes.Close(); |
|
917 |
} |
|
918 |
||
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
919 |
LOCAL_C void TestForDEF142554() |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
920 |
{ |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
921 |
test.Next(_L("Test for DEF142554: test RFile::Modified and RFile::Att when disk full")); |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
922 |
|
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
923 |
Format(gTestDrive); |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
924 |
|
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
925 |
TUint att; |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
926 |
TTime time; |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
927 |
|
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
928 |
RFs fs; |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
929 |
TInt err = fs.Connect(); |
131 | 930 |
test_KErrNone(err); |
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
931 |
|
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
932 |
RFile file; |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
933 |
TBuf<20> fileName; |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
934 |
fileName = KTestFile; |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
935 |
fileName[0] = (TUint16)gCh; |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
936 |
|
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
937 |
err = fs.ReserveDriveSpace(gTestDrive,0x10000); |
131 | 938 |
test_KErrNone(err); |
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
939 |
|
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
940 |
err = file.Replace(fs, fileName, EFileWrite); |
131 | 941 |
test_KErrNone(err); |
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
942 |
|
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
943 |
err = file.Write(KTestData); |
131 | 944 |
test_KErrNone(err); |
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
945 |
|
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
946 |
err = file.Flush(); |
131 | 947 |
test_KErrNone(err); |
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
948 |
|
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
949 |
file.Close(); |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
950 |
|
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
951 |
err = file.Open(fs, fileName, EFileRead); |
131 | 952 |
test_KErrNone(err); |
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
953 |
|
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
954 |
err = file.Att(att); |
131 | 955 |
test_KErrNone(err); |
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
956 |
|
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
957 |
err = file.Modified(time); |
131 | 958 |
test_KErrNone(err); |
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
959 |
|
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
960 |
file.Close(); |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
961 |
|
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
962 |
FillUpDisk(); |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
963 |
|
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
964 |
err = file.Open(fs, fileName, EFileRead); |
131 | 965 |
test_KErrNone(err); |
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
966 |
|
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
967 |
TUint att1; |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
968 |
err = file.Att(att1); |
131 | 969 |
test_KErrNone(err); |
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
970 |
test(att1 == att); |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
971 |
|
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
972 |
TTime time1; |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
973 |
err = file.Modified(time1); |
131 | 974 |
test_KErrNone(err); |
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
975 |
test(time1 == time); |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
976 |
|
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
977 |
file.Close(); |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
978 |
fs.Close(); |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
979 |
|
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
980 |
} |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
981 |
|
0 | 982 |
|
983 |
//----------------------------------------------------------------------------- |
|
984 |
||
985 |
/** |
|
986 |
test creation of the the file that crosses 4G boundary on the FAT media |
|
987 |
||
988 |
*/ |
|
989 |
static void TestFAT4G_Boundary() |
|
990 |
{ |
|
991 |
const TInt64 K4Gig = 4*(TInt64)K1GigaByte; |
|
992 |
||
993 |
test.Next(_L("Test files crossing 4G boundary on FAT")); |
|
994 |
||
995 |
if(!Is_Fat32(TheFs, gTestDrive)) |
|
996 |
{ |
|
997 |
test.Printf(_L("This test requires FAT32. Skipping.\n")); |
|
998 |
return; |
|
999 |
} |
|
1000 |
||
1001 |
TVolumeInfo volInfo; |
|
1002 |
||
1003 |
TInt nRes = TheFs.Volume(volInfo,gTestDrive); |
|
131 | 1004 |
test_KErrNone(nRes); |
0 | 1005 |
|
1006 |
if(volInfo.iSize < K4Gig+K1MegaByte) |
|
1007 |
{ |
|
1008 |
test.Printf(_L("This test requires volume > 4G. Skipping.\n")); |
|
1009 |
return; |
|
1010 |
} |
|
1011 |
||
1012 |
//-- 1. format the volume |
|
1013 |
FormatDrive(); |
|
1014 |
||
1015 |
//-- find out media position of the data region start |
|
1016 |
TFatBootSector bootSector; |
|
1017 |
nRes = ReadBootSector(TheFs, gTestDrive, 0, bootSector); |
|
131 | 1018 |
test_KErrNone(nRes); |
0 | 1019 |
test(bootSector.IsValid()); |
1020 |
||
1021 |
const TInt64 dataStartPos = bootSector.FirstDataSector() << KDefaultSectorLog2; |
|
1022 |
const TInt64 lowRegion = K4Gig - dataStartPos - K1MegaByte; |
|
1023 |
||
1024 |
||
1025 |
//-- 2. create several empty files that take a bit less that 4gig |
|
1026 |
//-- the drive is freshly formatted and the files will expand linearry |
|
1027 |
_LIT(KBaseFN, "\\LargeFile"); |
|
1028 |
||
1029 |
const TInt MaxDummyFiles = 5; |
|
1030 |
const TUint32 DummyFileLen = (TUint32)(lowRegion / MaxDummyFiles); |
|
1031 |
TInt i; |
|
1032 |
for(i=0; i<MaxDummyFiles; ++i) |
|
1033 |
{ |
|
1034 |
nRes = CreateFileX(KBaseFN, i, DummyFileLen); |
|
131 | 1035 |
test_KErrNone(nRes); |
0 | 1036 |
} |
1037 |
||
1038 |
//-- 3. create a real file that crosses 4G boundary |
|
1039 |
nRes = CreateCheckableStuffedFile(TheFs, KBaseFN, 5*K1MegaByte); |
|
131 | 1040 |
test_KErrNone(nRes); |
0 | 1041 |
|
1042 |
test.Printf(_L("Verifying the file that crosses 4G boundary.\n")); |
|
1043 |
||
1044 |
nRes = VerifyCheckableFile(TheFs, KBaseFN); |
|
131 | 1045 |
test_KErrNone(nRes); |
0 | 1046 |
|
1047 |
||
1048 |
nRes = TheFs.Delete(KBaseFN); |
|
131 | 1049 |
test_KErrNone(nRes); |
0 | 1050 |
for(i=0; i<MaxDummyFiles; ++i) |
1051 |
{ |
|
132 | 1052 |
nRes = DeleteFileX(KBaseFN, i); |
131 | 1053 |
test_KErrNone(nRes); |
0 | 1054 |
} |
1055 |
} |
|
1056 |
||
131 | 1057 |
void TestRAMDriveNotification() |
1058 |
{ |
|
1059 |
test.Next(_L("Verifying RFs::ReserveDriveSpace() triggers RFs::NotifyDiskSpace() events")); |
|
1060 |
||
1061 |
TInt64 freeSpace; |
|
1062 |
GetFreeDiskSpace(freeSpace); |
|
1063 |
test.Printf(_L("free space: 0x%Lx bytes\n"), freeSpace); |
|
1064 |
||
1065 |
// set a notification on half the amount we plan to reserve |
|
1066 |
TInt reserve = 4096; |
|
1067 |
TInt64 trigger = freeSpace - 2048; |
|
1068 |
test.Printf(_L("setting notification for space to fall below: 0x%Lx bytes ... "), trigger); |
|
1069 |
TRequestStatus stat; |
|
1070 |
TheFs.NotifyDiskSpace(trigger, gTestDrive, stat); |
|
1071 |
test_Value(stat.Int(), stat == KRequestPending); |
|
1072 |
test.Printf(_L("ok\n")); |
|
1073 |
||
1074 |
// reserve the space and validate that this triggers the notification |
|
1075 |
test.Printf(_L("reserving 0x%x bytes ..."), reserve); |
|
1076 |
TInt r = TheFs.ReserveDriveSpace(gTestDrive, reserve); |
|
1077 |
test_KErrNone(r); |
|
1078 |
test.Printf(_L("ok\n")); |
|
1079 |
||
1080 |
test.Printf(_L("validating that the disk space notification triggered ... ")); |
|
1081 |
User::After(2000000); // 2 seconds should be enough to cause the trigger |
|
1082 |
test_Value(stat.Int(), stat == KErrNone); |
|
1083 |
test.Printf(_L("ok\n")); |
|
1084 |
} |
|
1085 |
||
1086 |
||
132 | 1087 |
//----------------------------------------------------------------------------- |
1088 |
/** |
|
1089 |
Test that the reserving some drive space does not takes more space than required. |
|
1090 |
*/ |
|
1091 |
void Test0() |
|
1092 |
{ |
|
1093 |
test.Next(_L("test ReserveDriveSpace threshold")); |
|
1094 |
||
1095 |
TInt nRes; |
|
1096 |
TVolumeIOParamInfo volIop; |
|
1097 |
TInt64 freespace=0; |
|
1098 |
||
1099 |
//-- 1. format the volume |
|
1100 |
FormatDrive(); |
|
1101 |
||
1102 |
GetFreeDiskSpace(freespace); |
|
1103 |
const TInt64 freeSpace1 = freespace; //-- initial amount of free space on the volume |
|
1104 |
||
1105 |
nRes = TheFs.VolumeIOParam(gTestDrive, volIop); |
|
1106 |
test_KErrNone(nRes); |
|
1107 |
const TInt KClusterSz = volIop.iClusterSize; |
|
1108 |
if(!IsPowerOf2(KClusterSz)) |
|
1109 |
{ |
|
1110 |
test.Next(_L("The FS hasn't reported a cluster size. The test is inconsistent, skipping")); |
|
1111 |
return; |
|
1112 |
} |
|
1113 |
||
1114 |
//-- reserve exactly 1 cluster worth drive space. |
|
1115 |
nRes = TheFs.ReserveDriveSpace(gTestDrive, KClusterSz); |
|
1116 |
test_KErrNone(nRes); |
|
1117 |
||
1118 |
GetFreeDiskSpace(freespace); |
|
1119 |
const TInt64 freeSpace2 = freespace; |
|
1120 |
test((freeSpace1 - freeSpace2) == KClusterSz); |
|
1121 |
||
1122 |
//-- fill up a drive (it has a reserved space) |
|
1123 |
FillUpDisk(); |
|
1124 |
||
1125 |
//-- delete 1 file; |
|
1126 |
nRes = DeleteFileX(KBaseName, 0); |
|
1127 |
test_KErrNone(nRes); |
|
1128 |
||
1129 |
//-- try to create a file with the size that is exacly the same as free space; it should succeed |
|
1130 |
GetFreeDiskSpace(freespace); |
|
1131 |
||
1132 |
nRes = CreateEmptyFile(TheFs, _L("\\aaa1"), freespace); |
|
1133 |
test_KErrNone(nRes); |
|
1134 |
||
1135 |
GetFreeDiskSpace(freespace); |
|
1136 |
test(freespace == 0); |
|
1137 |
||
1138 |
//-- return the drive space to the system |
|
1139 |
nRes = TheFs.ReserveDriveSpace(gTestDrive,0); |
|
1140 |
test_KErrNone(nRes); |
|
1141 |
||
1142 |
//-- release drive space |
|
1143 |
nRes = TheFs.ReleaseReserveAccess(gTestDrive); |
|
1144 |
test_KErrNone(nRes); |
|
1145 |
||
1146 |
GetFreeDiskSpace(freespace); |
|
1147 |
test(freespace == KClusterSz); |
|
1148 |
||
1149 |
FormatDrive(); |
|
1150 |
} |
|
131 | 1151 |
|
0 | 1152 |
//----------------------------------------------------------------------------- |
1153 |
||
1154 |
GLDEF_C void CallTestsL() |
|
1155 |
// |
|
1156 |
// Do tests relative to session path |
|
1157 |
// |
|
1158 |
{ |
|
132 | 1159 |
//-- set up console output |
1160 |
Fat_Test_Utils::SetConsole(test.Console()); |
|
1161 |
||
131 | 1162 |
// If TESTFAST mode (for automated test builds) is set, don't run LFFS tests. |
1163 |
if ((UserSvr::DebugMask(2) & 0x00000002) && IsTestingLFFS()) |
|
1164 |
{ |
|
1165 |
test.Printf(_L("TEST NOT RUN FOR LFFS DRIVE")); |
|
1166 |
return; |
|
1167 |
} |
|
0 | 1168 |
|
1169 |
//get the number of the drive we are currently testing |
|
1170 |
TInt r=0; |
|
1171 |
r=RFs::CharToDrive(gSessionPath[0],gTestDrive); |
|
131 | 1172 |
test_KErrNone(r); |
0 | 1173 |
|
1174 |
r=RFs::DriveToChar(gTestDrive,gCh); |
|
131 | 1175 |
test_KErrNone(r); |
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1176 |
|
131 | 1177 |
TDriveInfo drv; |
1178 |
r = TheFs.Drive(drv, gTestDrive); |
|
1179 |
test_KErrNone(r); |
|
1180 |
||
1181 |
||
1182 |
//-- print drive information |
|
1183 |
PrintDrvInfo(TheFs, gTestDrive); |
|
1184 |
||
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1185 |
|
131 | 1186 |
// do not run the remainder of this test on RAM drive |
1187 |
if (drv.iType == EMediaRam) |
|
1188 |
{ |
|
1189 |
TestRAMDriveNotification(); // Test drive space reservations trigger disk space notifications |
|
1190 |
test.Printf(_L("Main tests can't run on RAM drive %C:\n"), gSessionPath[0]); |
|
1191 |
return; |
|
1192 |
} |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1193 |
|
131 | 1194 |
if (Is_Win32(TheFs, gTestDrive)) |
1195 |
{ |
|
1196 |
test.Printf(_L("Skipping on emulator %C: drive\n"), gSessionPath[0]); |
|
1197 |
return; |
|
1198 |
} |
|
0 | 1199 |
|
132 | 1200 |
Test0(); |
131 | 1201 |
Test1(); // General test for new APIs |
1202 |
Test2(); // Test to ensure drive and session reserve limits are not exceeded |
|
0 | 1203 |
Test3(); |
131 | 1204 |
Test4(); // test filling the drive and that each checked API fails |
0 | 1205 |
Test5(); |
1206 |
Test6(); |
|
1207 |
Test7(); |
|
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1208 |
TestForDEF142554(); |
131 | 1209 |
Test2(); // run this test to check reserves are being cleared correctly |
0 | 1210 |
|
1211 |
TestFAT4G_Boundary(); |
|
132 | 1212 |
|
131 | 1213 |
TurnAllocFailureOff(); |
0 | 1214 |
} |