sl@0
|
1 |
// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
// f32test\server\t_main.cpp
|
sl@0
|
15 |
//
|
sl@0
|
16 |
//
|
sl@0
|
17 |
|
sl@0
|
18 |
#define __E32TEST_EXTENSION__
|
sl@0
|
19 |
|
sl@0
|
20 |
#include <f32file.h>
|
sl@0
|
21 |
#include <e32test.h>
|
sl@0
|
22 |
#include <e32hal.h>
|
sl@0
|
23 |
#include <e32math.h>
|
sl@0
|
24 |
#include <f32dbg.h>
|
sl@0
|
25 |
#include "t_server.h"
|
sl@0
|
26 |
#include "t_chlffs.h"
|
sl@0
|
27 |
|
sl@0
|
28 |
GLDEF_D RFs TheFs;
|
sl@0
|
29 |
GLDEF_D TFileName gSessionPath;
|
sl@0
|
30 |
GLDEF_D TFileName gExeFileName(RProcess().FileName());
|
sl@0
|
31 |
GLDEF_D TInt gAllocFailOff=KAllocFailureOff;
|
sl@0
|
32 |
GLDEF_D TInt gAllocFailOn=KAllocFailureOff;
|
sl@0
|
33 |
GLDEF_D TInt64 gSeed=51703;
|
sl@0
|
34 |
|
sl@0
|
35 |
GLDEF_D TChar gDriveToTest;
|
sl@0
|
36 |
GLDEF_D TVolumeInfo gVolInfo; // volume info for current drive
|
sl@0
|
37 |
GLDEF_D TFileCacheFlags gDriveCacheFlags;
|
sl@0
|
38 |
|
sl@0
|
39 |
_LIT(KPrivate, "\\Private\\");
|
sl@0
|
40 |
|
sl@0
|
41 |
|
sl@0
|
42 |
////////////////////////////////////////////////////////////
|
sl@0
|
43 |
// Template functions encapsulating ControlIo magic
|
sl@0
|
44 |
//
|
sl@0
|
45 |
GLDEF_D template <class C>
|
sl@0
|
46 |
GLDEF_C TInt controlIo(RFs &fs, TInt drv, TInt fkn, C &c)
|
sl@0
|
47 |
{
|
sl@0
|
48 |
TPtr8 ptrC((TUint8 *)&c, sizeof(C), sizeof(C));
|
sl@0
|
49 |
|
sl@0
|
50 |
TInt r = fs.ControlIo(drv, fkn, ptrC);
|
sl@0
|
51 |
|
sl@0
|
52 |
return r;
|
sl@0
|
53 |
}
|
sl@0
|
54 |
|
sl@0
|
55 |
GLDEF_C void CreateShortName(TDes& aFileName,TInt64& aSeed)
|
sl@0
|
56 |
//
|
sl@0
|
57 |
// Create a random, dos legal 8.3 char name
|
sl@0
|
58 |
//
|
sl@0
|
59 |
{
|
sl@0
|
60 |
|
sl@0
|
61 |
TInt length=Math::Rand(aSeed)%11;
|
sl@0
|
62 |
if (length==0)
|
sl@0
|
63 |
length=1;
|
sl@0
|
64 |
else if (length==3) // don't create three letter names like 'AUX' or 'PRN'
|
sl@0
|
65 |
length++;
|
sl@0
|
66 |
else if (length>8) // end in '.' if no extension
|
sl@0
|
67 |
length++;
|
sl@0
|
68 |
|
sl@0
|
69 |
aFileName.SetLength(length);
|
sl@0
|
70 |
for(TInt i=0;i<length;i++)
|
sl@0
|
71 |
{
|
sl@0
|
72 |
if (i==9)
|
sl@0
|
73 |
{
|
sl@0
|
74 |
aFileName[i]='.';
|
sl@0
|
75 |
continue;
|
sl@0
|
76 |
}
|
sl@0
|
77 |
TInt letter=Math::Rand(aSeed)%26;
|
sl@0
|
78 |
aFileName[i]=(TText)('A'+letter);
|
sl@0
|
79 |
}
|
sl@0
|
80 |
}
|
sl@0
|
81 |
|
sl@0
|
82 |
_LIT(KFatName, "Fat");
|
sl@0
|
83 |
_LIT(KFat32Name, "Fat32");
|
sl@0
|
84 |
|
sl@0
|
85 |
static
|
sl@0
|
86 |
TBool isFAT(RFs &aFsSession, TInt aDrive)
|
sl@0
|
87 |
{
|
sl@0
|
88 |
TFileName f;
|
sl@0
|
89 |
TInt r = aFsSession.FileSystemName(f, aDrive);
|
sl@0
|
90 |
test_Value(r, r == KErrNone || r == KErrNotFound);
|
sl@0
|
91 |
return (f.CompareF(KFatName) == 0 || f.CompareF(KFat32Name) == 0);
|
sl@0
|
92 |
}
|
sl@0
|
93 |
|
sl@0
|
94 |
static
|
sl@0
|
95 |
TUint16 getRootEntCnt(RFs &aFsSession, TInt aDrive)
|
sl@0
|
96 |
{
|
sl@0
|
97 |
RRawDisk rdisk;
|
sl@0
|
98 |
TUint16 rootEntCnt;
|
sl@0
|
99 |
TPtr8 reader((TUint8*)&rootEntCnt, sizeof(rootEntCnt));
|
sl@0
|
100 |
|
sl@0
|
101 |
test_KErrNone(rdisk.Open(aFsSession, aDrive));
|
sl@0
|
102 |
test_KErrNone(rdisk.Read(17, reader)); // "BPB_RootEntCnt" field at offset 17
|
sl@0
|
103 |
rdisk.Close();
|
sl@0
|
104 |
|
sl@0
|
105 |
return rootEntCnt;
|
sl@0
|
106 |
}
|
sl@0
|
107 |
|
sl@0
|
108 |
GLDEF_C TBool IsFileSystemFAT(RFs &aFsSession,TInt aDrive)
|
sl@0
|
109 |
//
|
sl@0
|
110 |
// return true if FAT on aDrive
|
sl@0
|
111 |
//
|
sl@0
|
112 |
{
|
sl@0
|
113 |
return (isFAT(aFsSession, aDrive) && getRootEntCnt(aFsSession, aDrive) != 0);
|
sl@0
|
114 |
}
|
sl@0
|
115 |
|
sl@0
|
116 |
GLDEF_C TBool IsFileSystemFAT32(RFs &aFsSession,TInt aDrive)
|
sl@0
|
117 |
//
|
sl@0
|
118 |
// return true if FAT32 on aDrive
|
sl@0
|
119 |
//
|
sl@0
|
120 |
{
|
sl@0
|
121 |
return (isFAT(aFsSession, aDrive) && getRootEntCnt(aFsSession, aDrive) == 0);
|
sl@0
|
122 |
}
|
sl@0
|
123 |
|
sl@0
|
124 |
GLDEF_C void CreateLongName(TDes& aFileName,TInt64& aSeed,TInt aLength)
|
sl@0
|
125 |
//
|
sl@0
|
126 |
// Create a random, dos legal 8.3 char name
|
sl@0
|
127 |
//
|
sl@0
|
128 |
{
|
sl@0
|
129 |
|
sl@0
|
130 |
TInt length;
|
sl@0
|
131 |
if (aLength>0)
|
sl@0
|
132 |
length=aLength;
|
sl@0
|
133 |
else
|
sl@0
|
134 |
{
|
sl@0
|
135 |
length=Math::Rand(aSeed)%128;
|
sl@0
|
136 |
length+=Math::Rand(aSeed)%128;
|
sl@0
|
137 |
length+=Math::Rand(aSeed)%128;
|
sl@0
|
138 |
length+=Math::Rand(aSeed)%128;
|
sl@0
|
139 |
length-=256;
|
sl@0
|
140 |
length=Abs(length);
|
sl@0
|
141 |
if (length==0)
|
sl@0
|
142 |
length=1;
|
sl@0
|
143 |
if (length>220)
|
sl@0
|
144 |
length=31;
|
sl@0
|
145 |
}
|
sl@0
|
146 |
if (length==3) // don't create three letter names like 'AUX' or 'PRN'
|
sl@0
|
147 |
length++;
|
sl@0
|
148 |
|
sl@0
|
149 |
aFileName.SetLength(length);
|
sl@0
|
150 |
TInt spaceChar=-1;
|
sl@0
|
151 |
TInt i;
|
sl@0
|
152 |
for(i=0;i<length;i++)
|
sl@0
|
153 |
{
|
sl@0
|
154 |
StartAgain:
|
sl@0
|
155 |
TChar letter=0;
|
sl@0
|
156 |
TBool illegalChar=ETrue;
|
sl@0
|
157 |
|
sl@0
|
158 |
while(illegalChar)
|
sl@0
|
159 |
{
|
sl@0
|
160 |
#if defined(__WINS__)
|
sl@0
|
161 |
if (gSessionPath[0]=='C')
|
sl@0
|
162 |
letter=(TChar)('A'+Math::Rand(aSeed)%26);
|
sl@0
|
163 |
else
|
sl@0
|
164 |
letter=(TChar)Math::Rand(aSeed)%256;
|
sl@0
|
165 |
#else
|
sl@0
|
166 |
letter=(TChar)Math::Rand(aSeed)%256;
|
sl@0
|
167 |
#endif
|
sl@0
|
168 |
TBool space=letter.IsSpace();
|
sl@0
|
169 |
if (space && spaceChar==-1)
|
sl@0
|
170 |
spaceChar=i;
|
sl@0
|
171 |
else if (!space && spaceChar!=-1)
|
sl@0
|
172 |
spaceChar=-1;
|
sl@0
|
173 |
|
sl@0
|
174 |
switch(letter)
|
sl@0
|
175 |
{
|
sl@0
|
176 |
case '<':
|
sl@0
|
177 |
case '>':
|
sl@0
|
178 |
case ':':
|
sl@0
|
179 |
case '"':
|
sl@0
|
180 |
case '/':
|
sl@0
|
181 |
case '|':
|
sl@0
|
182 |
case '*':
|
sl@0
|
183 |
case '?':
|
sl@0
|
184 |
case '\\':
|
sl@0
|
185 |
case '\0':
|
sl@0
|
186 |
break;
|
sl@0
|
187 |
default:
|
sl@0
|
188 |
illegalChar=EFalse;
|
sl@0
|
189 |
};
|
sl@0
|
190 |
}
|
sl@0
|
191 |
aFileName[i]=(TText)letter;
|
sl@0
|
192 |
}
|
sl@0
|
193 |
|
sl@0
|
194 |
if (spaceChar!=-1)
|
sl@0
|
195 |
{
|
sl@0
|
196 |
i=spaceChar;
|
sl@0
|
197 |
goto StartAgain;
|
sl@0
|
198 |
}
|
sl@0
|
199 |
}
|
sl@0
|
200 |
|
sl@0
|
201 |
GLDEF_C void CheckEntry(const TDesC& aName,TUint anAttributes,const TTime& aModified)
|
sl@0
|
202 |
//
|
sl@0
|
203 |
// Checks the values associated with an entry
|
sl@0
|
204 |
//
|
sl@0
|
205 |
{
|
sl@0
|
206 |
|
sl@0
|
207 |
TEntry entry;
|
sl@0
|
208 |
TInt r=TheFs.Entry(aName,entry);
|
sl@0
|
209 |
test_KErrNone(r);
|
sl@0
|
210 |
test(entry.iAtt==anAttributes);
|
sl@0
|
211 |
if (aModified!=TTime(0))
|
sl@0
|
212 |
test(entry.iModified==aModified);
|
sl@0
|
213 |
}
|
sl@0
|
214 |
|
sl@0
|
215 |
GLDEF_C void CheckDisk()
|
sl@0
|
216 |
//
|
sl@0
|
217 |
// Do a checkdisk and report failure
|
sl@0
|
218 |
//
|
sl@0
|
219 |
{
|
sl@0
|
220 |
test.Next(_L("Check Disk"));
|
sl@0
|
221 |
TInt r=TheFs.CheckDisk(gSessionPath);
|
sl@0
|
222 |
if (r!=KErrNone && r!=KErrNotSupported && r!=KErrPermissionDenied)
|
sl@0
|
223 |
ReportCheckDiskFailure(r);
|
sl@0
|
224 |
}
|
sl@0
|
225 |
|
sl@0
|
226 |
GLDEF_C void ReportCheckDiskFailure(TInt aRet)
|
sl@0
|
227 |
//
|
sl@0
|
228 |
// Report the failure of checkdisk
|
sl@0
|
229 |
//
|
sl@0
|
230 |
{
|
sl@0
|
231 |
|
sl@0
|
232 |
test.Printf(_L("CHECKDISK FAILED: "));
|
sl@0
|
233 |
switch(aRet)
|
sl@0
|
234 |
{
|
sl@0
|
235 |
case 1: test.Printf(_L("File cluster chain contains a bad value (<2 or >maxCluster)\n")); break;
|
sl@0
|
236 |
case 2: test.Printf(_L("Two files are linked to the same cluster\n")); break;
|
sl@0
|
237 |
case 3: test.Printf(_L("Unallocated cluster contains a value != 0\n")); break;
|
sl@0
|
238 |
case 4: test.Printf(_L("Size of file != number of clusters in chain\n")); break;
|
sl@0
|
239 |
default: test.Printf(_L("Undefined Error value %d\n"),aRet);
|
sl@0
|
240 |
}
|
sl@0
|
241 |
test(EFalse);
|
sl@0
|
242 |
}
|
sl@0
|
243 |
|
sl@0
|
244 |
GLDEF_C void TurnAllocFailureOff()
|
sl@0
|
245 |
//
|
sl@0
|
246 |
// Switch off all allocFailure
|
sl@0
|
247 |
//
|
sl@0
|
248 |
{
|
sl@0
|
249 |
|
sl@0
|
250 |
test.Printf(_L("Disable Alloc Failure\n"));
|
sl@0
|
251 |
TheFs.SetAllocFailure(gAllocFailOff);
|
sl@0
|
252 |
gAllocFailOn=KAllocFailureOff; // Disable gAllocFailOn
|
sl@0
|
253 |
}
|
sl@0
|
254 |
|
sl@0
|
255 |
GLDEF_C void TurnAllocFailureOn()
|
sl@0
|
256 |
//
|
sl@0
|
257 |
// Switch off all allocFailure
|
sl@0
|
258 |
//
|
sl@0
|
259 |
{
|
sl@0
|
260 |
|
sl@0
|
261 |
test.Printf(_L("Enable Alloc Failure\n"));
|
sl@0
|
262 |
gAllocFailOn=KAllocFailureOn; // Enable gAllocFailOn
|
sl@0
|
263 |
TheFs.SetAllocFailure(gAllocFailOn);
|
sl@0
|
264 |
}
|
sl@0
|
265 |
|
sl@0
|
266 |
GLDEF_C void MakeFile(const TDesC& aFileName,const TUidType& aUidType,const TDesC8& aFileContents)
|
sl@0
|
267 |
//
|
sl@0
|
268 |
// Make a file and write uid and data
|
sl@0
|
269 |
//
|
sl@0
|
270 |
{
|
sl@0
|
271 |
|
sl@0
|
272 |
RFile file;
|
sl@0
|
273 |
TInt r=file.Replace(TheFs,aFileName,0);
|
sl@0
|
274 |
if (r==KErrPathNotFound)
|
sl@0
|
275 |
{
|
sl@0
|
276 |
r=TheFs.MkDirAll(aFileName);
|
sl@0
|
277 |
test_KErrNone(r);
|
sl@0
|
278 |
r=file.Replace(TheFs,aFileName,0);
|
sl@0
|
279 |
}
|
sl@0
|
280 |
test_KErrNone(r);
|
sl@0
|
281 |
TCheckedUid checkedUid(aUidType);
|
sl@0
|
282 |
TPtrC8 uidData((TUint8*)&checkedUid,sizeof(TCheckedUid));
|
sl@0
|
283 |
r=file.Write(uidData);
|
sl@0
|
284 |
test_KErrNone(r);
|
sl@0
|
285 |
r=file.Write(aFileContents);
|
sl@0
|
286 |
test_KErrNone(r);
|
sl@0
|
287 |
file.Close();
|
sl@0
|
288 |
}
|
sl@0
|
289 |
|
sl@0
|
290 |
GLDEF_C void MakeFile(const TDesC& aFileName,const TDesC8& aFileContents)
|
sl@0
|
291 |
//
|
sl@0
|
292 |
// Make a file and write something in it
|
sl@0
|
293 |
//
|
sl@0
|
294 |
{
|
sl@0
|
295 |
|
sl@0
|
296 |
RFile file;
|
sl@0
|
297 |
TInt r=file.Replace(TheFs,aFileName,0);
|
sl@0
|
298 |
if (r==KErrPathNotFound)
|
sl@0
|
299 |
{
|
sl@0
|
300 |
r=TheFs.MkDirAll(aFileName);
|
sl@0
|
301 |
test_KErrNone(r);
|
sl@0
|
302 |
r=file.Replace(TheFs,aFileName,0);
|
sl@0
|
303 |
}
|
sl@0
|
304 |
test_KErrNone(r);
|
sl@0
|
305 |
r=file.Write(aFileContents);
|
sl@0
|
306 |
test_KErrNone(r);
|
sl@0
|
307 |
file.Close();
|
sl@0
|
308 |
}
|
sl@0
|
309 |
|
sl@0
|
310 |
GLDEF_C void MakeFile(const TDesC& aFileName,TInt anAttributes)
|
sl@0
|
311 |
//
|
sl@0
|
312 |
// Make a file and write something in it
|
sl@0
|
313 |
//
|
sl@0
|
314 |
{
|
sl@0
|
315 |
|
sl@0
|
316 |
RFile file;
|
sl@0
|
317 |
TInt r=file.Replace(TheFs,aFileName,0);
|
sl@0
|
318 |
if (r==KErrPathNotFound)
|
sl@0
|
319 |
{
|
sl@0
|
320 |
r=TheFs.MkDirAll(aFileName);
|
sl@0
|
321 |
test_KErrNone(r);
|
sl@0
|
322 |
r=file.Replace(TheFs,aFileName,0);
|
sl@0
|
323 |
}
|
sl@0
|
324 |
test_KErrNone(r);
|
sl@0
|
325 |
file.Close();
|
sl@0
|
326 |
r=TheFs.SetAtt(aFileName,anAttributes,0);
|
sl@0
|
327 |
test_KErrNone(r);
|
sl@0
|
328 |
}
|
sl@0
|
329 |
|
sl@0
|
330 |
GLDEF_C void SetSessionPath(const TDesC& aPathName)
|
sl@0
|
331 |
//
|
sl@0
|
332 |
// Set the session path and update gSessionPath
|
sl@0
|
333 |
//
|
sl@0
|
334 |
{
|
sl@0
|
335 |
|
sl@0
|
336 |
TInt r=TheFs.SetSessionPath(aPathName);
|
sl@0
|
337 |
test_KErrNone(r);
|
sl@0
|
338 |
r=TheFs.SessionPath(gSessionPath);
|
sl@0
|
339 |
test_KErrNone(r);
|
sl@0
|
340 |
}
|
sl@0
|
341 |
|
sl@0
|
342 |
GLDEF_C void MakeFile(const TDesC& aFileName)
|
sl@0
|
343 |
//
|
sl@0
|
344 |
// Make a file
|
sl@0
|
345 |
//
|
sl@0
|
346 |
{
|
sl@0
|
347 |
|
sl@0
|
348 |
MakeFile(aFileName,_L8(""));
|
sl@0
|
349 |
}
|
sl@0
|
350 |
|
sl@0
|
351 |
GLDEF_C void MakeDir(const TDesC& aDirName)
|
sl@0
|
352 |
//
|
sl@0
|
353 |
// Make a directory
|
sl@0
|
354 |
//
|
sl@0
|
355 |
{
|
sl@0
|
356 |
|
sl@0
|
357 |
TInt r=TheFs.MkDirAll(aDirName);
|
sl@0
|
358 |
if (r!=KErrNone && r!=KErrAlreadyExists)
|
sl@0
|
359 |
{
|
sl@0
|
360 |
test.Printf(_L("%c: MakeDir Error %d\n"),aDirName[0],r);
|
sl@0
|
361 |
test(0);
|
sl@0
|
362 |
}
|
sl@0
|
363 |
}
|
sl@0
|
364 |
|
sl@0
|
365 |
GLDEF_C TInt CheckFileExists(const TDesC& aName,TInt aResult,TBool aCompRes/*=ETrue*/)
|
sl@0
|
366 |
//
|
sl@0
|
367 |
// Check aName exists
|
sl@0
|
368 |
//
|
sl@0
|
369 |
{
|
sl@0
|
370 |
|
sl@0
|
371 |
TEntry entry;
|
sl@0
|
372 |
TInt r=TheFs.Entry(aName,entry);
|
sl@0
|
373 |
test_Value(r, r == KErrNone || r == aResult);
|
sl@0
|
374 |
if (aResult!=KErrNone)
|
sl@0
|
375 |
return(0);
|
sl@0
|
376 |
TParsePtrC nameParse(aName);
|
sl@0
|
377 |
TParsePtrC entryParse(entry.iName);
|
sl@0
|
378 |
TBool nameMatch=(entryParse.Name()==nameParse.Name());
|
sl@0
|
379 |
TBool extMatch=(entryParse.Ext()==nameParse.Ext()) || (entryParse.Ext().Length()<=1 && nameParse.Ext().Length()<=1);
|
sl@0
|
380 |
test((nameMatch && extMatch)==aCompRes);
|
sl@0
|
381 |
return(entry.iSize);
|
sl@0
|
382 |
}
|
sl@0
|
383 |
|
sl@0
|
384 |
GLDEF_C void CheckFileContents(const TDesC& aName,const TDesC8& aContents)
|
sl@0
|
385 |
//
|
sl@0
|
386 |
// Check contents of file
|
sl@0
|
387 |
//
|
sl@0
|
388 |
{
|
sl@0
|
389 |
|
sl@0
|
390 |
RFile f;
|
sl@0
|
391 |
TInt r=f.Open(TheFs,aName,EFileRead);
|
sl@0
|
392 |
test_KErrNone(r);
|
sl@0
|
393 |
HBufC8* testBuf=HBufC8::NewL(aContents.Length());
|
sl@0
|
394 |
test(testBuf!=NULL);
|
sl@0
|
395 |
TPtr8 bufPtr(testBuf->Des());
|
sl@0
|
396 |
r=f.Read(bufPtr);
|
sl@0
|
397 |
test_KErrNone(r);
|
sl@0
|
398 |
test(bufPtr==aContents);
|
sl@0
|
399 |
r=f.Read(bufPtr);
|
sl@0
|
400 |
test_KErrNone(r);
|
sl@0
|
401 |
test(bufPtr.Length()==0);
|
sl@0
|
402 |
f.Close();
|
sl@0
|
403 |
User::Free(testBuf);
|
sl@0
|
404 |
}
|
sl@0
|
405 |
|
sl@0
|
406 |
GLDEF_C void DeleteTestDirectory()
|
sl@0
|
407 |
//
|
sl@0
|
408 |
// Delete the leaf session path directory
|
sl@0
|
409 |
//
|
sl@0
|
410 |
{
|
sl@0
|
411 |
|
sl@0
|
412 |
TheFs.SetAtt(_L("\\F32-TST\\SCANTEST\\Left\\Dir3\\Dir4\\Hidden"), 0, KEntryAttHidden);
|
sl@0
|
413 |
TheFs.SetAtt(_L("\\F32-TST\\SCANTEST\\Left\\Dir3\\Dir4\\Hidden\\HiddenFile"), 0, KEntryAttHidden);
|
sl@0
|
414 |
TheFs.SetAtt(_L("\\F32-TST\\SCANTEST\\Left\\Dir3\\Dir4\\Hidden\\System"), 0, KEntryAttSystem);
|
sl@0
|
415 |
test.Next(_L("Delete test directory"));
|
sl@0
|
416 |
CFileMan* fMan=CFileMan::NewL(TheFs);
|
sl@0
|
417 |
test(fMan!=NULL);
|
sl@0
|
418 |
TInt r=TheFs.SessionPath(gSessionPath);
|
sl@0
|
419 |
test_KErrNone(r);
|
sl@0
|
420 |
r=TheFs.CheckDisk(gSessionPath);
|
sl@0
|
421 |
if (r!=KErrNone && r!=KErrNotSupported)
|
sl@0
|
422 |
ReportCheckDiskFailure(r);
|
sl@0
|
423 |
r=fMan->RmDir(gSessionPath);
|
sl@0
|
424 |
test_KErrNone(r);
|
sl@0
|
425 |
delete fMan;
|
sl@0
|
426 |
}
|
sl@0
|
427 |
|
sl@0
|
428 |
GLDEF_C void CreateTestDirectory(const TDesC& aSessionPath)
|
sl@0
|
429 |
//
|
sl@0
|
430 |
// Create directory for test
|
sl@0
|
431 |
//
|
sl@0
|
432 |
{
|
sl@0
|
433 |
TParsePtrC path(aSessionPath);
|
sl@0
|
434 |
test(path.DrivePresent()==EFalse);
|
sl@0
|
435 |
|
sl@0
|
436 |
TInt r=TheFs.SetSessionPath(aSessionPath);
|
sl@0
|
437 |
test_KErrNone(r);
|
sl@0
|
438 |
r=TheFs.SessionPath(gSessionPath);
|
sl@0
|
439 |
test_KErrNone(r);
|
sl@0
|
440 |
r=TheFs.MkDirAll(gSessionPath);
|
sl@0
|
441 |
test_Value(r, r == KErrNone || r == KErrAlreadyExists);
|
sl@0
|
442 |
}
|
sl@0
|
443 |
|
sl@0
|
444 |
GLDEF_C TInt CurrentDrive()
|
sl@0
|
445 |
//
|
sl@0
|
446 |
// Return the current drive number
|
sl@0
|
447 |
//
|
sl@0
|
448 |
{
|
sl@0
|
449 |
|
sl@0
|
450 |
TInt driveNum;
|
sl@0
|
451 |
TInt r=TheFs.CharToDrive(gSessionPath[0],driveNum);
|
sl@0
|
452 |
test_KErrNone(r);
|
sl@0
|
453 |
return(driveNum);
|
sl@0
|
454 |
}
|
sl@0
|
455 |
|
sl@0
|
456 |
GLDEF_C void Format(TInt aDrive)
|
sl@0
|
457 |
//
|
sl@0
|
458 |
// Format current drive
|
sl@0
|
459 |
//
|
sl@0
|
460 |
{
|
sl@0
|
461 |
|
sl@0
|
462 |
test.Next(_L("Format"));
|
sl@0
|
463 |
TBuf<4> driveBuf=_L("?:\\");
|
sl@0
|
464 |
driveBuf[0]=(TText)(aDrive+'A');
|
sl@0
|
465 |
RFormat format;
|
sl@0
|
466 |
TInt count;
|
sl@0
|
467 |
TInt r=format.Open(TheFs,driveBuf,EQuickFormat,count);
|
sl@0
|
468 |
test_KErrNone(r);
|
sl@0
|
469 |
while(count)
|
sl@0
|
470 |
{
|
sl@0
|
471 |
TInt r=format.Next(count);
|
sl@0
|
472 |
test_KErrNone(r);
|
sl@0
|
473 |
}
|
sl@0
|
474 |
format.Close();
|
sl@0
|
475 |
}
|
sl@0
|
476 |
|
sl@0
|
477 |
LOCAL_C void PushLotsL()
|
sl@0
|
478 |
//
|
sl@0
|
479 |
// Expand the cleanup stack
|
sl@0
|
480 |
//
|
sl@0
|
481 |
{
|
sl@0
|
482 |
TInt i;
|
sl@0
|
483 |
for(i=0;i<1000;i++)
|
sl@0
|
484 |
CleanupStack::PushL((CBase*)NULL);
|
sl@0
|
485 |
CleanupStack::Pop(1000);
|
sl@0
|
486 |
}
|
sl@0
|
487 |
|
sl@0
|
488 |
|
sl@0
|
489 |
LOCAL_C void DoTests(TInt aDrive)
|
sl@0
|
490 |
//
|
sl@0
|
491 |
// Do testing on aDrive
|
sl@0
|
492 |
//
|
sl@0
|
493 |
{
|
sl@0
|
494 |
|
sl@0
|
495 |
gSessionPath=_L("?:\\F32-TST\\");
|
sl@0
|
496 |
TChar driveLetter;
|
sl@0
|
497 |
TInt r=TheFs.DriveToChar(aDrive,driveLetter);
|
sl@0
|
498 |
test_KErrNone(r);
|
sl@0
|
499 |
gSessionPath[0]=(TText)driveLetter;
|
sl@0
|
500 |
r=TheFs.SetSessionPath(gSessionPath);
|
sl@0
|
501 |
test_KErrNone(r);
|
sl@0
|
502 |
|
sl@0
|
503 |
// !!! Disable platform security tests until we get the new APIs
|
sl@0
|
504 |
// if(User::Capability() & KCapabilityRoot)
|
sl@0
|
505 |
CheckMountLFFS(TheFs,driveLetter);
|
sl@0
|
506 |
|
sl@0
|
507 |
User::After(1000000);
|
sl@0
|
508 |
|
sl@0
|
509 |
// Format(CurrentDrive());
|
sl@0
|
510 |
|
sl@0
|
511 |
test.Printf(_L("Creating session path"));
|
sl@0
|
512 |
r=TheFs.MkDirAll(gSessionPath);
|
sl@0
|
513 |
if(r == KErrCorrupt)
|
sl@0
|
514 |
{
|
sl@0
|
515 |
test.Printf(_L("Attempting to create directory \'%S\' failed, KErrCorrupt\n"), &gSessionPath);
|
sl@0
|
516 |
test.Printf(_L("This could be caused by a previous failing test, or a test media defect\n"));
|
sl@0
|
517 |
test.Printf(_L("Formatting drive, retrying MkDirall\nShould subsequent tests fail with KErrCorrupt (%d) as well, replace test medium !\n"),
|
sl@0
|
518 |
r);
|
sl@0
|
519 |
Format(aDrive);
|
sl@0
|
520 |
r=TheFs.MkDirAll(gSessionPath);
|
sl@0
|
521 |
test_KErrNone(r);
|
sl@0
|
522 |
}
|
sl@0
|
523 |
else if (r == KErrNotReady)
|
sl@0
|
524 |
{
|
sl@0
|
525 |
TDriveInfo d;
|
sl@0
|
526 |
r=TheFs.Drive(d, aDrive);
|
sl@0
|
527 |
test_KErrNone(r);
|
sl@0
|
528 |
if (d.iType == EMediaNotPresent)
|
sl@0
|
529 |
test.Printf(_L("%c: Medium not present - cannot perform test.\n"), (TUint)driveLetter);
|
sl@0
|
530 |
else
|
sl@0
|
531 |
test.Printf(_L("medium found (type %d) but drive %c: not ready\nPrevious test may have hung; else, check hardware.\n"), (TInt)d.iType, (TUint)driveLetter);
|
sl@0
|
532 |
}
|
sl@0
|
533 |
test_Value(r, r == KErrNone || r == KErrAlreadyExists);
|
sl@0
|
534 |
TheFs.ResourceCountMarkStart();
|
sl@0
|
535 |
test.Printf(_L("Calling main test sequence ...\n"));
|
sl@0
|
536 |
TRAP(r,CallTestsL());
|
sl@0
|
537 |
test_KErrNone(r);
|
sl@0
|
538 |
test.Printf(_L("test sequence completed without error\n"));
|
sl@0
|
539 |
TheFs.ResourceCountMarkEnd();
|
sl@0
|
540 |
|
sl@0
|
541 |
CheckDisk();
|
sl@0
|
542 |
TestingLFFS(EFalse);
|
sl@0
|
543 |
}
|
sl@0
|
544 |
|
sl@0
|
545 |
|
sl@0
|
546 |
void ParseCommandArguments()
|
sl@0
|
547 |
//
|
sl@0
|
548 |
//
|
sl@0
|
549 |
//
|
sl@0
|
550 |
{
|
sl@0
|
551 |
TBuf<0x100> cmd;
|
sl@0
|
552 |
User::CommandLine(cmd);
|
sl@0
|
553 |
TLex lex(cmd);
|
sl@0
|
554 |
TPtrC token=lex.NextToken();
|
sl@0
|
555 |
TFileName thisfile=RProcess().FileName();
|
sl@0
|
556 |
if (token.MatchF(thisfile)==0)
|
sl@0
|
557 |
{
|
sl@0
|
558 |
token.Set(lex.NextToken());
|
sl@0
|
559 |
}
|
sl@0
|
560 |
test.Printf(_L("CLP=%S\n"),&token);
|
sl@0
|
561 |
|
sl@0
|
562 |
if(token.Length()!=0)
|
sl@0
|
563 |
{
|
sl@0
|
564 |
gDriveToTest=token[0];
|
sl@0
|
565 |
gDriveToTest.UpperCase();
|
sl@0
|
566 |
}
|
sl@0
|
567 |
else
|
sl@0
|
568 |
gDriveToTest='C';
|
sl@0
|
569 |
}
|
sl@0
|
570 |
|
sl@0
|
571 |
TFullName gExtName;
|
sl@0
|
572 |
TBool gPrimaryExtensionExists = EFalse;
|
sl@0
|
573 |
|
sl@0
|
574 |
GLDEF_C TInt DismountFileSystem(RFs& aFs, const TDesC& aFileSystemName,TInt aDrive)
|
sl@0
|
575 |
{
|
sl@0
|
576 |
//Make note of the first extension if it exists, so that we remount
|
sl@0
|
577 |
//it when the file system is remounted.
|
sl@0
|
578 |
TInt r = aFs.ExtensionName(gExtName, aDrive, 0);
|
sl@0
|
579 |
|
sl@0
|
580 |
if (r == KErrNone)
|
sl@0
|
581 |
{
|
sl@0
|
582 |
gPrimaryExtensionExists = ETrue;
|
sl@0
|
583 |
}
|
sl@0
|
584 |
return aFs.DismountFileSystem(aFileSystemName, aDrive);
|
sl@0
|
585 |
}
|
sl@0
|
586 |
|
sl@0
|
587 |
GLDEF_C TInt MountFileSystem(RFs& aFs, const TDesC& aFileSystemName,TInt aDrive, TBool aIsSync)
|
sl@0
|
588 |
{
|
sl@0
|
589 |
TInt r;
|
sl@0
|
590 |
if (gPrimaryExtensionExists)
|
sl@0
|
591 |
{
|
sl@0
|
592 |
r = aFs.MountFileSystem(aFileSystemName, gExtName, aDrive, aIsSync);
|
sl@0
|
593 |
}
|
sl@0
|
594 |
else
|
sl@0
|
595 |
{
|
sl@0
|
596 |
r = aFs. MountFileSystem(aFileSystemName, aDrive, aIsSync);
|
sl@0
|
597 |
}
|
sl@0
|
598 |
return r;
|
sl@0
|
599 |
}
|
sl@0
|
600 |
|
sl@0
|
601 |
GLDEF_C TInt E32Main()
|
sl@0
|
602 |
//
|
sl@0
|
603 |
// Test with drive nearly full
|
sl@0
|
604 |
//
|
sl@0
|
605 |
{
|
sl@0
|
606 |
|
sl@0
|
607 |
CTrapCleanup* cleanup;
|
sl@0
|
608 |
cleanup=CTrapCleanup::New();
|
sl@0
|
609 |
TRAPD(r,PushLotsL());
|
sl@0
|
610 |
__UHEAP_MARK;
|
sl@0
|
611 |
|
sl@0
|
612 |
test.Title();
|
sl@0
|
613 |
test.Start(_L("Starting tests..."));
|
sl@0
|
614 |
|
sl@0
|
615 |
|
sl@0
|
616 |
ParseCommandArguments(); //need this for drive letter to test
|
sl@0
|
617 |
|
sl@0
|
618 |
|
sl@0
|
619 |
r=TheFs.Connect();
|
sl@0
|
620 |
test_KErrNone(r);
|
sl@0
|
621 |
TheFs.SetAllocFailure(gAllocFailOn);
|
sl@0
|
622 |
TTime timerC;
|
sl@0
|
623 |
timerC.HomeTime();
|
sl@0
|
624 |
TFileName sessionp;
|
sl@0
|
625 |
TheFs.SessionPath(sessionp);
|
sl@0
|
626 |
|
sl@0
|
627 |
TBuf<30> privatedir;
|
sl@0
|
628 |
privatedir = KPrivate;
|
sl@0
|
629 |
|
sl@0
|
630 |
TUid thisUID = RProcess().Identity();
|
sl@0
|
631 |
privatedir.AppendFormat(_L("%08x"),thisUID.iUid);
|
sl@0
|
632 |
privatedir.Append(_L("\\"));
|
sl@0
|
633 |
|
sl@0
|
634 |
test(privatedir == sessionp.Mid(2,sessionp.Length()-2));
|
sl@0
|
635 |
|
sl@0
|
636 |
test.Printf(_L("sp=%S\n"),&sessionp);
|
sl@0
|
637 |
sessionp[0]=(TText)gDriveToTest;
|
sl@0
|
638 |
test.Printf(_L("sp1=%S\n"),&sessionp);
|
sl@0
|
639 |
|
sl@0
|
640 |
TInt theDrive;
|
sl@0
|
641 |
r=TheFs.CharToDrive(gDriveToTest,theDrive);
|
sl@0
|
642 |
test_KErrNone(r);
|
sl@0
|
643 |
|
sl@0
|
644 |
// Get the TFileCacheFlags for this drive
|
sl@0
|
645 |
r = TheFs.Volume(gVolInfo, theDrive);
|
sl@0
|
646 |
if (r == KErrNotReady)
|
sl@0
|
647 |
{
|
sl@0
|
648 |
TDriveInfo info;
|
sl@0
|
649 |
TInt err = TheFs.Drive(info,theDrive);
|
sl@0
|
650 |
test_KErrNone(err);
|
sl@0
|
651 |
if (info.iType == EMediaNotPresent)
|
sl@0
|
652 |
test.Printf(_L("%c: Medium not present - cannot perform test.\n"), (TUint)gDriveToTest);
|
sl@0
|
653 |
else
|
sl@0
|
654 |
test.Printf(_L("%c: medium found (type %d) but drive not ready\nPrevious test may have hung; else, check hardware.\n"), (TUint)gDriveToTest, (TInt)info.iType);
|
sl@0
|
655 |
}
|
sl@0
|
656 |
else if (r == KErrCorrupt)
|
sl@0
|
657 |
{
|
sl@0
|
658 |
test.Printf(_L("%c: Media corruption; previous test may have aborted; else, check hardware\n"), (TUint)gDriveToTest);
|
sl@0
|
659 |
}
|
sl@0
|
660 |
test_KErrNone(r);
|
sl@0
|
661 |
gDriveCacheFlags = gVolInfo.iFileCacheFlags;
|
sl@0
|
662 |
test.Printf(_L("DriveCacheFlags = %08X\n"), gDriveCacheFlags);
|
sl@0
|
663 |
|
sl@0
|
664 |
#if defined(_DEBUG) || defined(_DEBUG_RELEASE)
|
sl@0
|
665 |
TPckgBuf<TIOCacheValues> pkgOrgValues;
|
sl@0
|
666 |
TIOCacheValues& orgValues=pkgOrgValues();
|
sl@0
|
667 |
r = controlIo(TheFs,theDrive, KControlIoCacheCount, orgValues);
|
sl@0
|
668 |
test_KErrNone(r);
|
sl@0
|
669 |
|
sl@0
|
670 |
test.Printf(_L("\n"));
|
sl@0
|
671 |
test.Printf(_L("Requests on close queue at start=%d\n"),orgValues.iCloseCount);
|
sl@0
|
672 |
test.Printf(_L("Requests on free queue at start=%d\n"),orgValues.iFreeCount);
|
sl@0
|
673 |
test.Printf(_L("Requests dynamically allocated at start=%d\n"),orgValues.iAllocated);
|
sl@0
|
674 |
test.Printf(_L("Requests in total at start=%d\n"),orgValues.iTotalCount);
|
sl@0
|
675 |
|
sl@0
|
676 |
// File cache
|
sl@0
|
677 |
|
sl@0
|
678 |
// flush closed files queue
|
sl@0
|
679 |
r = TheFs.ControlIo(theDrive, KControlIoFlushClosedFiles);
|
sl@0
|
680 |
test_KErrNone(r);
|
sl@0
|
681 |
|
sl@0
|
682 |
// get number of items on File Cache
|
sl@0
|
683 |
TFileCacheStats startFileCacheStats;
|
sl@0
|
684 |
r = controlIo(TheFs,theDrive, KControlIoFileCacheStats, startFileCacheStats);
|
sl@0
|
685 |
test_Value(r, r == KErrNone || r == KErrNotSupported);
|
sl@0
|
686 |
test.Printf(_L("File cache: Cachelines (free %d, used %d), Segments(allocated %d locked %d). Closed files(%d)\n"),
|
sl@0
|
687 |
startFileCacheStats.iFreeCount,
|
sl@0
|
688 |
startFileCacheStats.iUsedCount,
|
sl@0
|
689 |
startFileCacheStats.iAllocatedSegmentCount,
|
sl@0
|
690 |
startFileCacheStats.iLockedSegmentCount,
|
sl@0
|
691 |
startFileCacheStats.iFilesOnClosedQueue);
|
sl@0
|
692 |
#endif
|
sl@0
|
693 |
|
sl@0
|
694 |
DoTests(theDrive);
|
sl@0
|
695 |
|
sl@0
|
696 |
TTime endTimeC;
|
sl@0
|
697 |
endTimeC.HomeTime();
|
sl@0
|
698 |
TTimeIntervalSeconds timeTakenC;
|
sl@0
|
699 |
r=endTimeC.SecondsFrom(timerC,timeTakenC);
|
sl@0
|
700 |
test_KErrNone(r);
|
sl@0
|
701 |
test.Printf(_L("Time taken for test = %d seconds\n"),timeTakenC.Int());
|
sl@0
|
702 |
TheFs.SetAllocFailure(gAllocFailOff);
|
sl@0
|
703 |
|
sl@0
|
704 |
#if defined(_DEBUG) || defined(_DEBUG_RELEASE)
|
sl@0
|
705 |
TPckgBuf<TIOCacheValues> pkgValues;
|
sl@0
|
706 |
TIOCacheValues& values=pkgValues();
|
sl@0
|
707 |
r = controlIo(TheFs,theDrive, KControlIoCacheCount, values);
|
sl@0
|
708 |
test_KErrNone(r);
|
sl@0
|
709 |
|
sl@0
|
710 |
test.Printf(_L("Requests on close queue at end=%d\n"),values.iCloseCount);
|
sl@0
|
711 |
test.Printf(_L("Requests on free queue at end=%d\n"),values.iFreeCount);
|
sl@0
|
712 |
test.Printf(_L("Requests dynamically allocated at end=%d\n"),values.iAllocated);
|
sl@0
|
713 |
test.Printf(_L("Requests in total at end=%d\n"),values.iTotalCount);
|
sl@0
|
714 |
|
sl@0
|
715 |
test(orgValues.iCloseCount==values.iCloseCount);
|
sl@0
|
716 |
test(orgValues.iAllocated == values.iAllocated);
|
sl@0
|
717 |
// The free count can increase if the file server runs out of requests in the RequestAllocator
|
sl@0
|
718 |
// free pool but this should never decrease - this implies a request leak
|
sl@0
|
719 |
test(orgValues.iFreeCount <= values.iFreeCount);
|
sl@0
|
720 |
|
sl@0
|
721 |
// The total number of allocated requests should be equal to :
|
sl@0
|
722 |
// requests on the close queue + requests on free queue
|
sl@0
|
723 |
// + 1 (because we used one request to issue KControlIoCacheCount)
|
sl@0
|
724 |
// If this doesn't equate then this implies a request leak
|
sl@0
|
725 |
test(values.iTotalCount == values.iCloseCount + values.iFreeCount + 1);
|
sl@0
|
726 |
|
sl@0
|
727 |
// File cache
|
sl@0
|
728 |
TFileCacheStats endFileCacheStats;
|
sl@0
|
729 |
r = controlIo(TheFs,theDrive, KControlIoFileCacheStats, endFileCacheStats);
|
sl@0
|
730 |
test_Value(r, r == KErrNone || r == KErrNotSupported);
|
sl@0
|
731 |
|
sl@0
|
732 |
test.Printf(_L("File cache: Cachelines (free %d, used %d), Segments(allocated %d locked %d). Closed files(%d)\n"),
|
sl@0
|
733 |
endFileCacheStats.iFreeCount,
|
sl@0
|
734 |
endFileCacheStats.iUsedCount,
|
sl@0
|
735 |
endFileCacheStats.iAllocatedSegmentCount,
|
sl@0
|
736 |
endFileCacheStats.iLockedSegmentCount,
|
sl@0
|
737 |
endFileCacheStats.iFilesOnClosedQueue);
|
sl@0
|
738 |
|
sl@0
|
739 |
// flush closed files queue
|
sl@0
|
740 |
test.Printf(_L("Flushing close queue..."));
|
sl@0
|
741 |
r = TheFs.ControlIo(theDrive, KControlIoFlushClosedFiles);
|
sl@0
|
742 |
test_KErrNone(r);
|
sl@0
|
743 |
|
sl@0
|
744 |
r = controlIo(TheFs,theDrive, KControlIoFileCacheStats, endFileCacheStats);
|
sl@0
|
745 |
test_Value(r, r == KErrNone || r == KErrNotSupported);
|
sl@0
|
746 |
test.Printf(_L("File cache: Cachelines (free %d, used %d), Segments(allocated %d locked %d). Closed files(%d)\n"),
|
sl@0
|
747 |
endFileCacheStats.iFreeCount,
|
sl@0
|
748 |
endFileCacheStats.iUsedCount,
|
sl@0
|
749 |
endFileCacheStats.iAllocatedSegmentCount,
|
sl@0
|
750 |
endFileCacheStats.iLockedSegmentCount,
|
sl@0
|
751 |
endFileCacheStats.iFilesOnClosedQueue);
|
sl@0
|
752 |
|
sl@0
|
753 |
|
sl@0
|
754 |
if (r == KErrNone)
|
sl@0
|
755 |
{
|
sl@0
|
756 |
test(startFileCacheStats.iFreeCount == endFileCacheStats.iFreeCount);
|
sl@0
|
757 |
test(startFileCacheStats.iUsedCount == endFileCacheStats.iUsedCount);
|
sl@0
|
758 |
test(startFileCacheStats.iAllocatedSegmentCount == endFileCacheStats.iAllocatedSegmentCount);
|
sl@0
|
759 |
test(startFileCacheStats.iLockedSegmentCount == endFileCacheStats.iLockedSegmentCount);
|
sl@0
|
760 |
test(startFileCacheStats.iFileCount == endFileCacheStats.iFileCount);
|
sl@0
|
761 |
}
|
sl@0
|
762 |
#endif
|
sl@0
|
763 |
|
sl@0
|
764 |
TheFs.Close();
|
sl@0
|
765 |
test.End();
|
sl@0
|
766 |
test.Close();
|
sl@0
|
767 |
__UHEAP_MARKEND;
|
sl@0
|
768 |
delete cleanup;
|
sl@0
|
769 |
return(KErrNone);
|
sl@0
|
770 |
}
|
sl@0
|
771 |
|
sl@0
|
772 |
|