sl@0
|
1 |
// Copyright (c) 1996-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\b_open.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 <f32dbg.h>
|
sl@0
|
24 |
#include "t_server.h"
|
sl@0
|
25 |
#include "t_chlffs.h"
|
sl@0
|
26 |
|
sl@0
|
27 |
#ifdef __WINS__
|
sl@0
|
28 |
#define WIN32_LEAN_AND_MEAN
|
sl@0
|
29 |
#pragma warning( disable : 4201 ) // nonstandard extension used : nameless struct/union
|
sl@0
|
30 |
#include <windows.h>
|
sl@0
|
31 |
#pragma warning( default : 4201 ) // nonstandard extension used : nameless struct/union
|
sl@0
|
32 |
#endif
|
sl@0
|
33 |
|
sl@0
|
34 |
GLDEF_D RTest test(_L("B_OPEN"));
|
sl@0
|
35 |
|
sl@0
|
36 |
LOCAL_D const TInt KMaxFiles=200;
|
sl@0
|
37 |
LOCAL_D TBuf<32> nameBuf[KMaxFiles];
|
sl@0
|
38 |
LOCAL_D TBuf<0x100> nameBuf1;
|
sl@0
|
39 |
LOCAL_D RFile chan[KMaxFiles];
|
sl@0
|
40 |
LOCAL_D RFile chan1;
|
sl@0
|
41 |
LOCAL_D TFileName fBuf;
|
sl@0
|
42 |
LOCAL_D TVolumeInfo vInfo;
|
sl@0
|
43 |
LOCAL_D TInt LeaveMemFree;
|
sl@0
|
44 |
|
sl@0
|
45 |
LOCAL_C void testOpenFiles()
|
sl@0
|
46 |
//
|
sl@0
|
47 |
// Open files till memory is full
|
sl@0
|
48 |
// Write, seek, read, seteof, close, check and delete all files.
|
sl@0
|
49 |
//
|
sl@0
|
50 |
{
|
sl@0
|
51 |
|
sl@0
|
52 |
TChar currentDrive=gSessionPath[0];
|
sl@0
|
53 |
TInt driveNum;
|
sl@0
|
54 |
TInt r=TheFs.CharToDrive(currentDrive,driveNum);
|
sl@0
|
55 |
test_KErrNone(r);
|
sl@0
|
56 |
|
sl@0
|
57 |
TInt i=0;
|
sl@0
|
58 |
TInt totalRam;
|
sl@0
|
59 |
FOREVER
|
sl@0
|
60 |
{
|
sl@0
|
61 |
|
sl@0
|
62 |
#if defined(__WINS__)
|
sl@0
|
63 |
DWORD sectorsPerCluster;
|
sl@0
|
64 |
DWORD bytesPerSector;
|
sl@0
|
65 |
DWORD freeClusters;
|
sl@0
|
66 |
DWORD sizeClusters;
|
sl@0
|
67 |
BOOL b=GetDiskFreeSpaceA("C:\\",§orsPerCluster,&bytesPerSector,&freeClusters,&sizeClusters);
|
sl@0
|
68 |
test(b==TRUE);
|
sl@0
|
69 |
totalRam=sizeClusters*sectorsPerCluster*bytesPerSector;
|
sl@0
|
70 |
#else
|
sl@0
|
71 |
TMemoryInfoV1Buf memInfoBuf;
|
sl@0
|
72 |
UserHal::MemoryInfo(memInfoBuf);
|
sl@0
|
73 |
totalRam=memInfoBuf().iTotalRamInBytes;
|
sl@0
|
74 |
#endif
|
sl@0
|
75 |
test.Printf(_L("Open %u\n"),i);
|
sl@0
|
76 |
nameBuf[i].Format(_L("B_OPEN test file %d"),i);
|
sl@0
|
77 |
r=chan[i].Replace(TheFs,nameBuf[i],EFileStream|EFileWrite);
|
sl@0
|
78 |
if (r==KErrNone)
|
sl@0
|
79 |
{
|
sl@0
|
80 |
r=chan[i].Write(_L8("SomeText"));
|
sl@0
|
81 |
if ((gDriveCacheFlags & EFileCacheWriteOn) && (r == KErrNone))
|
sl@0
|
82 |
r = chan[i].Flush();
|
sl@0
|
83 |
if (r==KErrDiskFull)
|
sl@0
|
84 |
{
|
sl@0
|
85 |
chan[i].Close();
|
sl@0
|
86 |
test(TheFs.Delete(nameBuf[i])==KErrNone);
|
sl@0
|
87 |
}
|
sl@0
|
88 |
}
|
sl@0
|
89 |
if (r==KErrDiskFull)
|
sl@0
|
90 |
break;
|
sl@0
|
91 |
if (r==KErrNoMemory)
|
sl@0
|
92 |
break;
|
sl@0
|
93 |
if (r!=KErrNone)
|
sl@0
|
94 |
{
|
sl@0
|
95 |
test.Printf(_L("ERROR: RFile::Replace returned %d\n"),r);
|
sl@0
|
96 |
test(EFalse);
|
sl@0
|
97 |
}
|
sl@0
|
98 |
|
sl@0
|
99 |
r=TheFs.Volume(vInfo);
|
sl@0
|
100 |
test_KErrNone(r);
|
sl@0
|
101 |
if (driveNum==EDriveC)
|
sl@0
|
102 |
test.Printf(_L("VInfo size=0x%x free=0x%x TotalRam = 0x%x\n"),vInfo.iSize,vInfo.iFree,totalRam);
|
sl@0
|
103 |
test(vInfo.iFree<=vInfo.iSize);
|
sl@0
|
104 |
|
sl@0
|
105 |
// r=TheFs.Volume(vInfo,(driveNum==EDriveC) ? EDriveD : EDriveC);
|
sl@0
|
106 |
// if (r==KErrNone);
|
sl@0
|
107 |
// test(vInfo.iFree<=vInfo.iSize);
|
sl@0
|
108 |
i++;
|
sl@0
|
109 |
if (i==KMaxFiles)
|
sl@0
|
110 |
{
|
sl@0
|
111 |
if (IsTestingLFFS())
|
sl@0
|
112 |
break;
|
sl@0
|
113 |
else
|
sl@0
|
114 |
test.Panic(_L("Too many files opened"));
|
sl@0
|
115 |
}
|
sl@0
|
116 |
}
|
sl@0
|
117 |
|
sl@0
|
118 |
test.Printf(_L("Created %d extra files\n"),i);
|
sl@0
|
119 |
const TInt n_files=i;
|
sl@0
|
120 |
r=TheFs.Volume(vInfo);
|
sl@0
|
121 |
test_KErrNone(r);
|
sl@0
|
122 |
if (driveNum==EDriveC && (vInfo.iDrive.iMediaAtt & KMediaAttVariableSize))
|
sl@0
|
123 |
{
|
sl@0
|
124 |
test(vInfo.iSize<=totalRam);
|
sl@0
|
125 |
test(vInfo.iFree<=totalRam);
|
sl@0
|
126 |
}
|
sl@0
|
127 |
test(vInfo.iFree<=vInfo.iSize);
|
sl@0
|
128 |
|
sl@0
|
129 |
test.Next(_L("SetSize to each file"));
|
sl@0
|
130 |
for (i=0;i<n_files;i++)
|
sl@0
|
131 |
{
|
sl@0
|
132 |
r=chan[i].SetSize(0);
|
sl@0
|
133 |
test_KErrNone(r);
|
sl@0
|
134 |
}
|
sl@0
|
135 |
|
sl@0
|
136 |
test.Next(_L("Write to each file"));
|
sl@0
|
137 |
TBuf8<3> numBuf;
|
sl@0
|
138 |
for (i=0;i<n_files;i++)
|
sl@0
|
139 |
{
|
sl@0
|
140 |
test.Printf(_L("Write %u\n"),i);
|
sl@0
|
141 |
numBuf.Format(_L8("%d"),i);
|
sl@0
|
142 |
r=chan[i].Write(0,numBuf);
|
sl@0
|
143 |
test_KErrNone(r);
|
sl@0
|
144 |
}
|
sl@0
|
145 |
|
sl@0
|
146 |
test.Next(_L("Seek on each file"));
|
sl@0
|
147 |
for (i=0;i<n_files;i++)
|
sl@0
|
148 |
{
|
sl@0
|
149 |
test.Printf(_L("Seeking %u\n"),i);
|
sl@0
|
150 |
TInt pos=0;
|
sl@0
|
151 |
r=chan[i].Seek(ESeekStart,pos);
|
sl@0
|
152 |
test_KErrNone(r);
|
sl@0
|
153 |
}
|
sl@0
|
154 |
|
sl@0
|
155 |
test.Next(_L("Read from each file"));
|
sl@0
|
156 |
TBuf8<3> checkBuf;
|
sl@0
|
157 |
for (i=0;i<n_files;i++)
|
sl@0
|
158 |
{
|
sl@0
|
159 |
test.Printf(_L("Read %u\n"),i);
|
sl@0
|
160 |
r=chan[i].Read(checkBuf,3);
|
sl@0
|
161 |
test_KErrNone(r);
|
sl@0
|
162 |
numBuf.Format(_L8("%d"),i);
|
sl@0
|
163 |
test(numBuf==checkBuf);
|
sl@0
|
164 |
}
|
sl@0
|
165 |
|
sl@0
|
166 |
test.Next(_L("Set size of each file"));
|
sl@0
|
167 |
for (i=0;i<n_files;i++)
|
sl@0
|
168 |
{
|
sl@0
|
169 |
test.Printf(_L("Set size %u\n"),i);
|
sl@0
|
170 |
r=chan[i].SetSize(i);
|
sl@0
|
171 |
test_KErrNone(r);
|
sl@0
|
172 |
}
|
sl@0
|
173 |
|
sl@0
|
174 |
r=TheFs.Volume(vInfo);
|
sl@0
|
175 |
test_KErrNone(r);
|
sl@0
|
176 |
if (driveNum==EDriveC && (vInfo.iDrive.iMediaAtt & KMediaAttVariableSize))
|
sl@0
|
177 |
{
|
sl@0
|
178 |
test(vInfo.iSize<=totalRam);
|
sl@0
|
179 |
test(vInfo.iFree<=totalRam);
|
sl@0
|
180 |
}
|
sl@0
|
181 |
test(vInfo.iFree<=vInfo.iSize);
|
sl@0
|
182 |
|
sl@0
|
183 |
test.Next(_L("Close each file"));
|
sl@0
|
184 |
for (i=0;i<n_files;i++)
|
sl@0
|
185 |
{
|
sl@0
|
186 |
test.Printf(_L("Close %u\n"),i);
|
sl@0
|
187 |
chan[i].Close();
|
sl@0
|
188 |
}
|
sl@0
|
189 |
|
sl@0
|
190 |
test.Next(_L("Open each file"));
|
sl@0
|
191 |
|
sl@0
|
192 |
TInt n_files_open;
|
sl@0
|
193 |
for (n_files_open=0; n_files_open < n_files; n_files_open++)
|
sl@0
|
194 |
{
|
sl@0
|
195 |
r = chan[n_files_open].Open(TheFs,nameBuf[n_files_open],EFileRead|EFileStream);
|
sl@0
|
196 |
test.Printf(_L("Open(%d) ret %d\n"), n_files_open, r);
|
sl@0
|
197 |
if (r != KErrNone)
|
sl@0
|
198 |
{
|
sl@0
|
199 |
if (driveNum==EDriveC && (vInfo.iDrive.iMediaAtt & KMediaAttVariableSize))
|
sl@0
|
200 |
break;
|
sl@0
|
201 |
else
|
sl@0
|
202 |
test(0);
|
sl@0
|
203 |
}
|
sl@0
|
204 |
}
|
sl@0
|
205 |
|
sl@0
|
206 |
test.Next(_L("Check size of each file"));
|
sl@0
|
207 |
for (i=0;i<n_files_open;i++)
|
sl@0
|
208 |
{
|
sl@0
|
209 |
test.Printf(_L("Check %u\n"),i);
|
sl@0
|
210 |
TInt size;
|
sl@0
|
211 |
TInt r=chan[i].Size(size);
|
sl@0
|
212 |
test.Printf(_L("size of file %u is %d ret %d\n"),i,size, r);
|
sl@0
|
213 |
test_KErrNone(r);
|
sl@0
|
214 |
test_Equal(i,size);
|
sl@0
|
215 |
}
|
sl@0
|
216 |
|
sl@0
|
217 |
test.Next(_L("Close each file"));
|
sl@0
|
218 |
for (i=0;i<n_files_open;i++)
|
sl@0
|
219 |
{
|
sl@0
|
220 |
test.Printf(_L("Close %u\n"),i);
|
sl@0
|
221 |
chan[i].Close();
|
sl@0
|
222 |
}
|
sl@0
|
223 |
|
sl@0
|
224 |
test.Next(_L("Delete files"));
|
sl@0
|
225 |
for (i=0;i<n_files;i++)
|
sl@0
|
226 |
{
|
sl@0
|
227 |
test.Printf(_L("Delete %u\n"),i);
|
sl@0
|
228 |
r=TheFs.Delete(nameBuf[i]);
|
sl@0
|
229 |
test_KErrNone(r);
|
sl@0
|
230 |
}
|
sl@0
|
231 |
}
|
sl@0
|
232 |
|
sl@0
|
233 |
|
sl@0
|
234 |
|
sl@0
|
235 |
LOCAL_C void InitTest()
|
sl@0
|
236 |
//
|
sl@0
|
237 |
// Create a large file
|
sl@0
|
238 |
//
|
sl@0
|
239 |
{
|
sl@0
|
240 |
TInt fileNumber = 0;
|
sl@0
|
241 |
TBool fileSizeTruncated;
|
sl@0
|
242 |
|
sl@0
|
243 |
do
|
sl@0
|
244 |
{
|
sl@0
|
245 |
fileSizeTruncated = EFalse;
|
sl@0
|
246 |
nameBuf1.Format(_L("\\Hooge Test File for B_OPEN %d"), fileNumber++);
|
sl@0
|
247 |
|
sl@0
|
248 |
TInt r=chan1.Replace(TheFs,nameBuf1,EFileStream|EFileWrite);
|
sl@0
|
249 |
test_KErrNone(r);
|
sl@0
|
250 |
r=TheFs.Volume(vInfo);
|
sl@0
|
251 |
test_KErrNone(r);
|
sl@0
|
252 |
TInt64 size;
|
sl@0
|
253 |
LeaveMemFree = 0x400; // ???
|
sl@0
|
254 |
if (vInfo.iFree>LeaveMemFree)
|
sl@0
|
255 |
size=vInfo.iFree-LeaveMemFree;
|
sl@0
|
256 |
else
|
sl@0
|
257 |
size=0;
|
sl@0
|
258 |
|
sl@0
|
259 |
const TInt KMaxFileSize = 0x40000000;
|
sl@0
|
260 |
|
sl@0
|
261 |
// test as 64 bit numbers in case size is very large (eg. enough that TInt is
|
sl@0
|
262 |
// not large enough to hold it)
|
sl@0
|
263 |
TInt64 KMaxFileSize64 = MAKE_TINT64(0, KMaxFileSize);
|
sl@0
|
264 |
|
sl@0
|
265 |
test.Printf(_L("Free space available = %08x:%08x\n"), I64HIGH(size), I64LOW(size));
|
sl@0
|
266 |
if (size > KMaxFileSize64)
|
sl@0
|
267 |
{
|
sl@0
|
268 |
size = KMaxFileSize;
|
sl@0
|
269 |
test.Printf(_L("Truncated to %d to avoid current FAT FSY file size limit !!!\n"), size);
|
sl@0
|
270 |
fileSizeTruncated = ETrue;
|
sl@0
|
271 |
}
|
sl@0
|
272 |
|
sl@0
|
273 |
TFileName sessionPath;
|
sl@0
|
274 |
TheFs.SessionPath(sessionPath);
|
sl@0
|
275 |
TBuf<32> message=_L("?: has %ld bytes free\n");
|
sl@0
|
276 |
message[0]=sessionPath[0];
|
sl@0
|
277 |
test.Printf(message,vInfo.iFree);
|
sl@0
|
278 |
if (((vInfo.iDrive.iMediaAtt)&KMediaAttVariableSize)==0)
|
sl@0
|
279 |
{
|
sl@0
|
280 |
// Not a variable sized drive, so should be safe to to just create big file
|
sl@0
|
281 |
test.Printf(_L("Creating %S, 0x%08lx\n"),&nameBuf1,size);
|
sl@0
|
282 |
r=chan1.SetSize((TUint)size);
|
sl@0
|
283 |
}
|
sl@0
|
284 |
else
|
sl@0
|
285 |
{
|
sl@0
|
286 |
// Variable sized drive (proabably RAM drive) needs a bit of special treatment
|
sl@0
|
287 |
// Use a binary search to allocate largest sized file possible...
|
sl@0
|
288 |
test.Printf(_L("Creating %S, 0x%08x\n"),&nameBuf1,size);
|
sl@0
|
289 |
TInt lo = 0;
|
sl@0
|
290 |
TInt hi = (TInt)size;
|
sl@0
|
291 |
const TInt KSizeGranularity = 0x200; // must be power-of-2
|
sl@0
|
292 |
while(hi-lo>KSizeGranularity && r==KErrNone)
|
sl@0
|
293 |
{
|
sl@0
|
294 |
TInt trySize = (lo+hi)/2;
|
sl@0
|
295 |
trySize &= ~(KSizeGranularity-1);
|
sl@0
|
296 |
r = chan1.SetSize((TUint)trySize);
|
sl@0
|
297 |
if(r==KErrNone)
|
sl@0
|
298 |
{
|
sl@0
|
299 |
size = trySize;
|
sl@0
|
300 |
lo = trySize;
|
sl@0
|
301 |
}
|
sl@0
|
302 |
else if(r==KErrDiskFull)
|
sl@0
|
303 |
{
|
sl@0
|
304 |
hi = trySize;
|
sl@0
|
305 |
r = KErrNone;
|
sl@0
|
306 |
}
|
sl@0
|
307 |
}
|
sl@0
|
308 |
if(r==KErrNone)
|
sl@0
|
309 |
{
|
sl@0
|
310 |
// reduce size to leave some free for tests...
|
sl@0
|
311 |
LeaveMemFree = 4096*4; // best leave several RAM pages worth of space so rest of test has some memory
|
sl@0
|
312 |
size -= LeaveMemFree;
|
sl@0
|
313 |
r = chan1.SetSize((TUint)size);
|
sl@0
|
314 |
}
|
sl@0
|
315 |
}
|
sl@0
|
316 |
|
sl@0
|
317 |
if (r!=KErrNone)
|
sl@0
|
318 |
{
|
sl@0
|
319 |
test.Printf(_L("ERROR: Creating large file failed %d\n"),r);
|
sl@0
|
320 |
test(EFalse);
|
sl@0
|
321 |
}
|
sl@0
|
322 |
test.Printf(_L("Created %S, 0x%08x\n"),&nameBuf1,size);
|
sl@0
|
323 |
chan1.Close();
|
sl@0
|
324 |
}
|
sl@0
|
325 |
while (fileSizeTruncated);
|
sl@0
|
326 |
|
sl@0
|
327 |
}
|
sl@0
|
328 |
|
sl@0
|
329 |
LOCAL_C void Cleanup()
|
sl@0
|
330 |
//
|
sl@0
|
331 |
// Cleanup test files
|
sl@0
|
332 |
//
|
sl@0
|
333 |
{
|
sl@0
|
334 |
|
sl@0
|
335 |
TInt r=TheFs.Delete(nameBuf1);
|
sl@0
|
336 |
test_KErrNone(r);
|
sl@0
|
337 |
r=TheFs.RmDir(gSessionPath);
|
sl@0
|
338 |
test_KErrNone(r);
|
sl@0
|
339 |
}
|
sl@0
|
340 |
|
sl@0
|
341 |
|
sl@0
|
342 |
GLDEF_C void CallTestsL()
|
sl@0
|
343 |
//
|
sl@0
|
344 |
// Call tests that may leave
|
sl@0
|
345 |
//
|
sl@0
|
346 |
{
|
sl@0
|
347 |
|
sl@0
|
348 |
#ifdef __WINS__
|
sl@0
|
349 |
// These tests try to create a huge file to fill up the drive.
|
sl@0
|
350 |
// This fails on WINS with drives with > 1/2G free because
|
sl@0
|
351 |
// RFile::SetSize() (among other things) only takes a TInt.
|
sl@0
|
352 |
//
|
sl@0
|
353 |
if (gSessionPath.Left(1).CompareF(_L("C")) == 0)
|
sl@0
|
354 |
return;
|
sl@0
|
355 |
#endif
|
sl@0
|
356 |
CreateTestDirectory(_L("\\B_OPEN\\"));
|
sl@0
|
357 |
InitTest();
|
sl@0
|
358 |
testOpenFiles();
|
sl@0
|
359 |
Cleanup();
|
sl@0
|
360 |
}
|
sl@0
|
361 |
|