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