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