author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 14 May 2010 17:13:29 +0300 | |
changeset 109 | b3a1d9898418 |
parent 0 | a41df078684a |
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\fsstress\t_ramstr.cpp |
|
15 |
// |
|
16 |
// |
|
17 |
||
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
18 |
#define __E32TEST_EXTENSION__ |
0 | 19 |
#include <f32file.h> |
20 |
#include <e32test.h> |
|
21 |
#include <e32math.h> |
|
22 |
#include <e32hal.h> |
|
23 |
#include "t_stress.h" |
|
24 |
||
25 |
GLDEF_D RTest test(_L("T_RAMSTR")); |
|
26 |
||
27 |
LOCAL_D TBuf8<512> testBuf(512); |
|
28 |
LOCAL_D TInt64 TheSeed=917824; |
|
29 |
LOCAL_D TInt KMaxIteration; |
|
30 |
LOCAL_D const TInt KMaxFiles=4; |
|
31 |
LOCAL_D const TInt KMaxLengthIncrement=7770; |
|
32 |
LOCAL_D const TInt mult[] = { 1, 5, 13, 37}; |
|
33 |
LOCAL_D const TInt KReduceSizeFrequency=20; // 1 reduce in ?? iterations |
|
34 |
LOCAL_D const TInt KCheckFileFrequency=20000; // 1 check in ?? iterations |
|
35 |
LOCAL_D const TInt KMaxBufferLength=0x8000; |
|
36 |
||
37 |
LOCAL_C TInt CreateFileEx(const TDesC& aBaseName,TInt aX, TInt anInitialSize) |
|
38 |
// |
|
39 |
// Create a single cluster file |
|
40 |
// |
|
41 |
{ |
|
42 |
TBuf<128> fileName=aBaseName; |
|
43 |
fileName.AppendNum(aX); |
|
44 |
RFile file; |
|
45 |
TInt r=file.Replace(TheFs,fileName,EFileWrite); |
|
46 |
if (r==KErrDiskFull) |
|
47 |
return(r); |
|
48 |
if (r!=KErrNone) |
|
49 |
{ |
|
50 |
test.Printf(_L("ERROR:: Replace returned %d\n"),r); |
|
51 |
test.Getch(); |
|
52 |
return(r); |
|
53 |
} |
|
54 |
||
55 |
r=file.SetSize(anInitialSize); |
|
56 |
file.Close(); |
|
57 |
if (r==KErrDiskFull) |
|
58 |
return(r); |
|
59 |
||
60 |
if (r!=KErrNone) |
|
61 |
{ |
|
62 |
test.Printf(_L("ERROR:: SetSize returned %d\n"),r); |
|
63 |
test.Getch(); |
|
64 |
return(r); |
|
65 |
} |
|
66 |
||
67 |
// r=TheFs.CheckDisk(fileName); |
|
68 |
// if (r!=KErrNone && r!=KErrNotSupported) |
|
69 |
// { |
|
70 |
// test.Printf(_L("ERROR:: CheckDisk returned %d\n"),r); |
|
71 |
// test.Getch(); |
|
72 |
// return(KErrDiskFull); |
|
73 |
// } |
|
74 |
test.Printf(_L("Created file %d size %d\n"),aX, anInitialSize); |
|
75 |
return(KErrNone); |
|
76 |
} |
|
77 |
||
78 |
LOCAL_C TInt DeleteFileEx(TBuf<128>& aBaseName,TInt aX) |
|
79 |
// |
|
80 |
// Delete a file. |
|
81 |
// |
|
82 |
{ |
|
83 |
||
84 |
TBuf<128> fileName=aBaseName; |
|
85 |
fileName.AppendNum(aX); |
|
86 |
TInt r=TheFs.Delete(fileName); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
87 |
test_KErrNone(r); |
0 | 88 |
// r=TheFs.CheckDisk(fileName); |
89 |
// if (r!=KErrNone && r!=KErrNotSupported) |
|
90 |
// { |
|
91 |
// test.Printf(_L("ERROR:: CheckDisk returned %d\n"),r); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
92 |
// test_KErrNone(r); |
0 | 93 |
// } |
94 |
test.Printf(_L("Deleted File %d\n"),aX); |
|
95 |
return(KErrNone); |
|
96 |
} |
|
97 |
||
98 |
LOCAL_C void WriteCluster(RFile& aFile,TInt aCluster) |
|
99 |
// |
|
100 |
// Extend aFile by 1 cluster |
|
101 |
// |
|
102 |
{ |
|
103 |
TUint8* bufPtr=(TUint8*)testBuf.Ptr(); |
|
104 |
testBuf.SetLength(testBuf.MaxSize()); |
|
105 |
Mem::Fill(bufPtr,testBuf.MaxSize(),aCluster); |
|
106 |
TInt r=aFile.Write(testBuf); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
107 |
test_KErrNone(r); |
0 | 108 |
} |
109 |
||
110 |
LOCAL_C void SeekToCluster(RFile& aFile,TInt aCluster) |
|
111 |
// |
|
112 |
// Seek to aCluster and check it is found correctly |
|
113 |
// |
|
114 |
{ |
|
115 |
TBuf8<508> seekBuf(508); |
|
116 |
TInt r=aFile.Read(aCluster*testBuf.MaxSize(),seekBuf); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
117 |
test_KErrNone(r); |
0 | 118 |
test(seekBuf[0]==(TUint8)aCluster && seekBuf[507]==(TUint8)aCluster); |
119 |
} |
|
120 |
||
121 |
LOCAL_C void SeekToCluster(RFile& aFile,TInt aCluster1,TInt aCluster2) |
|
122 |
// |
|
123 |
// Seek to aCluster and check it is found correctly |
|
124 |
// |
|
125 |
{ |
|
126 |
TBuf8<508> seekBuf(508); |
|
127 |
TInt r=aFile.Read(aCluster1*testBuf.MaxSize(),seekBuf); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
128 |
test_KErrNone(r); |
0 | 129 |
test(seekBuf[0]==(TUint8)aCluster1 && seekBuf[507]==(TUint8)aCluster1); |
130 |
r=aFile.Read(aCluster2*testBuf.MaxSize(),seekBuf); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
131 |
test_KErrNone(r); |
0 | 132 |
test(seekBuf[0]==(TUint8)aCluster2 && seekBuf[507]==(TUint8)aCluster2); |
133 |
} |
|
134 |
||
135 |
LOCAL_C void ExhaustiveTest(RFile& aFile,TInt aCount1) |
|
136 |
// |
|
137 |
// Test every possible seeking combination |
|
138 |
// |
|
139 |
{ |
|
140 |
TInt i=0,k=0; |
|
141 |
for(k=0;k<aCount1;k++) |
|
142 |
{ |
|
143 |
for(i=aCount1-1;i>0;i--) |
|
144 |
{ |
|
145 |
SeekToCluster(aFile,i); |
|
146 |
SeekToCluster(aFile,k); |
|
147 |
} |
|
148 |
test.Printf(_L("Seek from %d \r"),k); |
|
149 |
} |
|
150 |
test.Printf(_L("\n")); |
|
151 |
} |
|
152 |
||
153 |
LOCAL_C void Test1() |
|
154 |
// |
|
155 |
// Test opening a large file |
|
156 |
// |
|
157 |
{ |
|
158 |
test.Next(_L("Create interleaved files")); |
|
159 |
RFile f1,f2; |
|
160 |
||
161 |
TInt r=f1.Replace(TheFs,_L("BIGFILE1.TST"),EFileWrite); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
162 |
test_KErrNone(r); |
0 | 163 |
r=f2.Replace(TheFs,_L("BIGFILE2.TST"),EFileWrite); |
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
164 |
test_KErrNone(r); |
0 | 165 |
|
166 |
TInt maxListLength=4; |
|
167 |
TInt i=0,k=0; |
|
168 |
TInt countf1=0; |
|
169 |
TInt countf2=0; |
|
170 |
for (k=0;k<maxListLength;k++) |
|
171 |
{ |
|
172 |
for (i=0;i<maxListLength;i++) |
|
173 |
{ |
|
174 |
TInt j; |
|
175 |
for (j=0;j<=i;j++) |
|
176 |
WriteCluster(f1,countf1++); |
|
177 |
for (j=0;j<=k;j++) |
|
178 |
WriteCluster(f2,countf2++); |
|
179 |
test.Printf(_L("Written %d to file1 %d to file2\n"),i+1,k+1); |
|
180 |
} |
|
181 |
} |
|
182 |
||
183 |
ExhaustiveTest(f1,countf1); |
|
184 |
ExhaustiveTest(f2,countf2); |
|
185 |
||
186 |
SeekToCluster(f1,1,10); |
|
187 |
SeekToCluster(f1,6,3); |
|
188 |
SeekToCluster(f1,8,4); |
|
189 |
SeekToCluster(f1,12,3); |
|
190 |
SeekToCluster(f1,23,32); |
|
191 |
SeekToCluster(f1,5,8); |
|
192 |
SeekToCluster(f1,7,9); |
|
193 |
SeekToCluster(f1,12,1); |
|
194 |
SeekToCluster(f1,2,32); |
|
195 |
SeekToCluster(f1,16,8); |
|
196 |
SeekToCluster(f1,9,5); |
|
197 |
SeekToCluster(f1,33,6); |
|
198 |
SeekToCluster(f1,13,7); |
|
199 |
SeekToCluster(f1,9,17); |
|
200 |
SeekToCluster(f1,4,5); |
|
201 |
SeekToCluster(f1,5,31); |
|
202 |
SeekToCluster(f1,11,10); |
|
203 |
SeekToCluster(f1,1,2); |
|
204 |
SeekToCluster(f1,5,5); |
|
205 |
||
206 |
f1.Close(); |
|
207 |
f2.Close(); |
|
208 |
r=TheFs.Delete(_L("BIGFile1.tst")); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
209 |
test_KErrNone(r); |
0 | 210 |
r=TheFs.Delete(_L("BIGFile2.tst")); |
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
211 |
test_KErrNone(r); |
0 | 212 |
CheckDisk(); |
213 |
} |
|
214 |
||
215 |
LOCAL_C void Test2() |
|
216 |
// |
|
217 |
// Reproduce old bugs |
|
218 |
// |
|
219 |
{ |
|
220 |
test.Next(_L("Regression Protection")); |
|
221 |
RFile f1,f2; |
|
222 |
||
223 |
TInt r=f1.Replace(TheFs,_L("BIGFILE1.TST"),EFileWrite); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
224 |
test_KErrNone(r); |
0 | 225 |
r=f2.Replace(TheFs,_L("BIGFILE2.TST"),EFileWrite); |
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
226 |
test_KErrNone(r); |
0 | 227 |
|
228 |
WriteCluster(f1,0); |
|
229 |
WriteCluster(f1,1); |
|
230 |
WriteCluster(f1,2); |
|
231 |
WriteCluster(f1,3); |
|
232 |
WriteCluster(f1,4); |
|
233 |
WriteCluster(f1,5); |
|
234 |
WriteCluster(f2,0); |
|
235 |
WriteCluster(f1,6); |
|
236 |
||
237 |
SeekToCluster(f1,6); |
|
238 |
SeekToCluster(f1,4); |
|
239 |
||
240 |
f1.Close(); |
|
241 |
f2.Close(); |
|
242 |
r=TheFs.Delete(_L("BIGFile1.tst")); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
243 |
test_KErrNone(r); |
0 | 244 |
r=TheFs.Delete(_L("BIGFile2.tst")); |
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
245 |
test_KErrNone(r); |
0 | 246 |
CheckDisk(); |
247 |
} |
|
248 |
||
249 |
LOCAL_C void Test3() |
|
250 |
// |
|
251 |
// Change file size while seeking |
|
252 |
// |
|
253 |
{ |
|
254 |
||
255 |
test.Next(_L("Alter filesize")); |
|
256 |
RFile f1; |
|
257 |
TheSeed=917824; |
|
258 |
TInt i=0,j=0; |
|
259 |
TInt r=f1.Replace(TheFs,_L("BIGFILE1.TST"),EFileWrite); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
260 |
test_KErrNone(r); |
0 | 261 |
|
262 |
r=f1.SetSize(65534); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
263 |
test_KErrNone(r); |
0 | 264 |
|
265 |
for(i=0;i<=15;i++) |
|
266 |
WriteCluster(f1,i); |
|
267 |
||
268 |
for (j=0;j<100;j++) |
|
269 |
{ |
|
270 |
TInt cluster1=Math::Rand(TheSeed)%15; |
|
271 |
TInt cluster2=Math::Rand(TheSeed)%15; |
|
272 |
SeekToCluster(f1,cluster2,cluster1); |
|
273 |
} |
|
274 |
||
275 |
test.Next(_L("Increase Size")); |
|
276 |
r=f1.SetSize(1048577); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
277 |
test_Value(r, r == KErrNone || r==KErrDiskFull); |
0 | 278 |
if (r==KErrDiskFull) |
279 |
{ |
|
280 |
test.Printf(_L("File too big\n")); |
|
281 |
f1.Close(); |
|
282 |
return; |
|
283 |
} |
|
284 |
||
285 |
test.Next(_L("Test data still present")); |
|
286 |
for (j=0;j<200;j++) |
|
287 |
{ |
|
288 |
TInt cluster1=Math::Rand(TheSeed)%15; |
|
289 |
TInt cluster2=Math::Rand(TheSeed)%15; |
|
290 |
SeekToCluster(f1,cluster2,cluster1); |
|
291 |
} |
|
292 |
||
293 |
TInt newPos=8192; |
|
294 |
r=f1.Seek(ESeekStart,newPos); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
295 |
test_KErrNone(r); |
0 | 296 |
|
297 |
test.Next(_L("Write more data")); |
|
298 |
for(i=16;i<83;i++) |
|
299 |
WriteCluster(f1,i); |
|
300 |
||
301 |
test.Next(_L("Seek to new data")); |
|
302 |
for (j=0;j<200;j++) |
|
303 |
{ |
|
304 |
TInt cluster1=Math::Rand(TheSeed)%83; |
|
305 |
TInt cluster2=Math::Rand(TheSeed)%83; |
|
306 |
SeekToCluster(f1,cluster2,cluster1); |
|
307 |
} |
|
308 |
||
309 |
test.Next(_L("Reduce file size")); |
|
310 |
r=f1.SetSize(135000); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
311 |
test_KErrNone(r); |
0 | 312 |
|
313 |
test.Next(_L("Test data still present")); |
|
314 |
for (j=0;j<200;j++) |
|
315 |
{ |
|
316 |
TInt cluster1=Math::Rand(TheSeed)%31; |
|
317 |
TInt cluster2=Math::Rand(TheSeed)%31; |
|
318 |
SeekToCluster(f1,cluster2,cluster1); |
|
319 |
} |
|
320 |
||
321 |
f1.Close(); |
|
322 |
} |
|
323 |
||
324 |
class TFileReader |
|
325 |
{ |
|
326 |
public: |
|
327 |
TFileReader(RFile* aFile); |
|
328 |
void Next(TUint8& aVal,TInt& aLength); |
|
329 |
TBool Compare(TUint8 aVal,TInt aLength); |
|
330 |
private: |
|
331 |
RFile iFile; |
|
332 |
TBuf8<512> iData; |
|
333 |
TInt iPos; |
|
334 |
}; |
|
335 |
||
336 |
TFileReader::TFileReader(RFile* aFile) |
|
337 |
// |
|
338 |
// Constructor |
|
339 |
// |
|
340 |
: iFile(*aFile), iPos(0) |
|
341 |
{ |
|
342 |
||
343 |
TInt r=iFile.Read(0,iData); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
344 |
test_KErrNone(r); |
0 | 345 |
} |
346 |
||
347 |
void TFileReader::Next(TUint8& aVal,TInt& aLength) |
|
348 |
// |
|
349 |
// Read aLength contiguous bytes with aVal |
|
350 |
// |
|
351 |
{ |
|
352 |
||
353 |
if (iPos==iData.Length()) |
|
354 |
{ |
|
355 |
TInt r=iFile.Read(iData); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
356 |
test_KErrNone(r); |
0 | 357 |
iPos=0; |
358 |
if (iData.Length()==0) |
|
359 |
{ |
|
360 |
aLength=0; |
|
361 |
return; |
|
362 |
} |
|
363 |
} |
|
364 |
||
365 |
aVal=iData[iPos]; |
|
366 |
aLength=0; |
|
367 |
while(iPos<iData.Length()) |
|
368 |
{ |
|
369 |
if (iData[iPos]!=aVal) |
|
370 |
break; |
|
371 |
iPos++; |
|
372 |
aLength++; |
|
373 |
} |
|
374 |
} |
|
375 |
||
376 |
TBool TFileReader::Compare(TUint8 aVal, TInt aLength) |
|
377 |
// |
|
378 |
// Compare file contents == aVal for aLength bytes |
|
379 |
// |
|
380 |
{ |
|
381 |
||
382 |
FOREVER |
|
383 |
{ |
|
384 |
if(iPos==iData.Length()) |
|
385 |
{ |
|
386 |
TInt r=iFile.Read(iData); |
|
387 |
if (r!=KErrNone) |
|
388 |
{ |
|
389 |
test.Printf(_L("READ error %d\n"),r); |
|
390 |
test.Getch(); |
|
391 |
RFs fs; |
|
392 |
r=fs.Connect(); |
|
393 |
test.Printf(_L("connect returned %d\n"),r); |
|
394 |
test.Getch(); |
|
395 |
fs.Close(); |
|
396 |
return(EFalse); |
|
397 |
} |
|
398 |
iPos=0; |
|
399 |
if (iData.Length()==0) |
|
400 |
{ |
|
401 |
test.Printf(_L("\nFound Error\n")); |
|
402 |
test.Getch(); |
|
403 |
return(EFalse); |
|
404 |
} |
|
405 |
} |
|
406 |
while(iPos<iData.Length()) |
|
407 |
{ |
|
408 |
if (iData[iPos]!=aVal) |
|
409 |
{ |
|
410 |
test.Printf(_L("\nFound Error\n")); |
|
411 |
test.Getch(); |
|
412 |
return(EFalse); |
|
413 |
} |
|
414 |
iPos++; |
|
415 |
aLength--; |
|
416 |
if (aLength==0) |
|
417 |
return(ETrue); |
|
418 |
} |
|
419 |
} |
|
420 |
} |
|
421 |
||
422 |
LOCAL_C void CheckFileContents(RFile* aFile) |
|
423 |
// |
|
424 |
// Check all files have consistent contents |
|
425 |
// |
|
426 |
{ |
|
427 |
||
428 |
TFileReader f0(aFile); |
|
429 |
TFileReader f1(aFile+1); |
|
430 |
TFileReader f2(aFile+2); |
|
431 |
TFileReader f3(aFile+3); |
|
432 |
||
433 |
FOREVER |
|
434 |
{ |
|
435 |
TUint8 val; |
|
436 |
TInt length; |
|
437 |
f0.Next(val,length); |
|
438 |
if (length==0) |
|
439 |
break; |
|
440 |
test(f1.Compare(val,length*mult[1])); |
|
441 |
test(f2.Compare(val,length*mult[2])); |
|
442 |
test(f3.Compare(val,length*mult[3])); |
|
443 |
} |
|
444 |
||
445 |
TUint8 val; |
|
446 |
TInt length; |
|
447 |
f1.Next(val,length); |
|
448 |
if (length!=0) |
|
449 |
{ |
|
450 |
test.Printf(_L("\nFound Error\n")); |
|
451 |
test.Getch(); |
|
452 |
} |
|
453 |
test(length==0); |
|
454 |
f2.Next(val,length); |
|
455 |
if (length!=0) |
|
456 |
{ |
|
457 |
test.Printf(_L("\nFound Error\n")); |
|
458 |
test.Getch(); |
|
459 |
} |
|
460 |
test(length==0); |
|
461 |
f3.Next(val,length); |
|
462 |
if (length!=0) |
|
463 |
{ |
|
464 |
test.Printf(_L("\nFound Error\n")); |
|
465 |
test.Getch(); |
|
466 |
} |
|
467 |
test(length==0); |
|
468 |
} |
|
469 |
||
470 |
LOCAL_C void Test4() |
|
471 |
// |
|
472 |
// Read, write and resize 4 interleaved files |
|
473 |
// |
|
474 |
{ |
|
475 |
||
476 |
RFile f[KMaxFiles]; |
|
477 |
HBufC8* dataBuf=HBufC8::NewL(KMaxBufferLength); |
|
478 |
||
479 |
TInt r=f[0].Replace(TheFs,_L("TEST1.DAT"),EFileWrite); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
480 |
test_KErrNone(r); |
0 | 481 |
r=f[1].Replace(TheFs,_L("TEST2.DAT"),EFileWrite); |
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
482 |
test_KErrNone(r); |
0 | 483 |
r=f[2].Replace(TheFs,_L("TEST3.DAT"),EFileWrite); |
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
484 |
test_KErrNone(r); |
0 | 485 |
r=f[3].Replace(TheFs,_L("TEST4.DAT"),EFileWrite); |
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
486 |
test_KErrNone(r); |
0 | 487 |
|
488 |
TInt size=0; |
|
489 |
TInt iteration=0; |
|
490 |
||
491 |
FOREVER |
|
492 |
{ |
|
493 |
iteration++; |
|
494 |
TInt pos=(size) ? Math::Rand(TheSeed)%size : 0; |
|
495 |
TInt len=Math::Rand(TheSeed)%KMaxLengthIncrement; |
|
496 |
TInt order=Math::Rand(TheSeed)%KMaxFiles; |
|
497 |
TInt value=Math::Rand(TheSeed)%KMaxTUint8; |
|
498 |
||
499 |
TUint8* data=(TUint8*)dataBuf->Ptr(); |
|
500 |
Mem::Fill(data,KMaxBufferLength,value); |
|
501 |
||
502 |
if (pos+len>size) |
|
503 |
size=pos+len; |
|
504 |
||
505 |
for (TInt i=0;i<KMaxFiles;i++) |
|
506 |
{ |
|
507 |
TInt fileNum=(order+i)%KMaxFiles; |
|
508 |
TInt s=len*mult[fileNum]; |
|
509 |
TInt filePos=pos*mult[fileNum]; |
|
510 |
r=f[fileNum].Seek(ESeekStart,filePos); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
511 |
test_KErrNone(r); |
0 | 512 |
|
513 |
while(s>0) |
|
514 |
{ |
|
515 |
TInt l=(s>KMaxBufferLength) ? KMaxBufferLength : s; |
|
516 |
dataBuf->Des().SetLength(l); |
|
517 |
r=f[fileNum].Write(*dataBuf); |
|
518 |
if (r==KErrDiskFull) |
|
519 |
goto End; |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
520 |
test_KErrNone(r); |
0 | 521 |
s-=l; |
522 |
} |
|
523 |
||
524 |
} |
|
525 |
||
526 |
if ((iteration%KCheckFileFrequency)==0) |
|
527 |
CheckFileContents(&f[0]); |
|
528 |
||
529 |
test.Printf(_L("Iteration %d, size %d \r"),iteration,size); |
|
530 |
if (iteration==KMaxIteration) |
|
531 |
break; |
|
532 |
||
533 |
if ((iteration%KReduceSizeFrequency)==0) |
|
534 |
{ |
|
535 |
size=(size) ? Math::Rand(TheSeed)%size : 0; |
|
536 |
test.Printf(_L("\nReduceSize newsize=%d\n"),size); |
|
537 |
for (TInt i=0;i<KMaxFiles;i++) |
|
538 |
{ |
|
539 |
TInt fileNum=(order+i)%KMaxFiles; |
|
540 |
r=f[fileNum].SetSize(size*mult[fileNum]); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
541 |
test_KErrNone(r); |
0 | 542 |
} |
543 |
CheckFileContents(&f[0]); |
|
544 |
} |
|
545 |
} |
|
546 |
End: |
|
547 |
delete dataBuf; |
|
548 |
for (TInt i=0;i<KMaxFiles;i++) |
|
549 |
f[i].Close(); |
|
550 |
test.Printf(_L("\n")); |
|
551 |
} |
|
552 |
||
553 |
LOCAL_C void MultipleFiles(TInt numberOfFiles,TInt anInitialSize) |
|
554 |
// |
|
555 |
// Test filling the disk with files, and various manipulations thereof |
|
556 |
// |
|
557 |
{ |
|
558 |
test.Start(_L("Test multiple file creation, deletion and resize operations")); |
|
559 |
TInt r=TheFs.MkDirAll(_L("\\F32-TST\\BIGDIRECTORY\\")); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
560 |
test_Value(r, r == KErrNone || r==KErrAlreadyExists); |
0 | 561 |
TFileName sessionPath; |
562 |
r=TheFs.SessionPath(sessionPath); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
563 |
test_KErrNone(r); |
0 | 564 |
|
565 |
TInt index=0; |
|
566 |
TBuf<128> fileName=_L("\\F32-TST\\BIGDIRECTORY\\FILE"); |
|
567 |
||
568 |
for (;index<numberOfFiles;index++) |
|
569 |
{ |
|
570 |
r=CreateFileEx(fileName,index,anInitialSize); |
|
571 |
if (r!=KErrNone) |
|
572 |
break; |
|
573 |
||
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
574 |
test_KErrNone(r); |
0 | 575 |
|
576 |
#if defined(__WINS__) |
|
577 |
if (index==32 && sessionPath[0]=='C') |
|
578 |
break; |
|
579 |
#endif |
|
580 |
} |
|
581 |
||
582 |
if ((r==KErrNone)||(r==KErrDiskFull)) |
|
583 |
r=TheFs.CheckDisk(fileName); |
|
584 |
||
585 |
if (r!=KErrNone && r!=KErrNotSupported) |
|
586 |
{ |
|
587 |
test.Printf(_L("ERROR:: CheckDisk returned %d\n"),r); |
|
588 |
// test.Getch(); |
|
589 |
} |
|
590 |
||
591 |
// Delete half of the files |
|
592 |
TInt halfCount=index/2; |
|
593 |
index--; |
|
594 |
for (; index>halfCount; index--) |
|
595 |
DeleteFileEx(fileName,index); |
|
596 |
||
597 |
TBuf<128> baseName; |
|
598 |
RFile file; |
|
599 |
// Double the size of those files remaining |
|
600 |
for (index=0; index<halfCount; index++) |
|
601 |
{ |
|
602 |
baseName=fileName; |
|
603 |
baseName.AppendNum(index); |
|
604 |
r=file.Open(TheFs,baseName,EFileRead|EFileWrite); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
605 |
test_KErrNone(r); |
0 | 606 |
test.Printf(_L("Resized %S from %d to %d\n"),&baseName,anInitialSize,anInitialSize*2); |
607 |
r=file.SetSize(2*anInitialSize); |
|
608 |
test((r==KErrNone)||(r==KErrDiskFull)); |
|
609 |
file.Close(); |
|
610 |
} |
|
611 |
||
612 |
r=TheFs.CheckDisk(fileName); |
|
613 |
||
614 |
if (r!=KErrNone && r!=KErrNotSupported) |
|
615 |
{ |
|
616 |
test.Printf(_L("ERROR:: CheckDisk returned %d\n"),r); |
|
617 |
// test.Getch(); |
|
618 |
} |
|
619 |
||
620 |
// Delete the files |
|
621 |
for (index=0; index<halfCount; index++) |
|
622 |
{ |
|
623 |
baseName=fileName; |
|
624 |
baseName.AppendNum(index); |
|
625 |
test.Printf(_L("Deleted %S\n"),&baseName); |
|
626 |
r=TheFs.Delete(baseName); |
|
627 |
test((r==KErrNone)||(r==KErrNotFound)); |
|
628 |
} |
|
629 |
||
630 |
r=TheFs.CheckDisk(fileName); |
|
631 |
||
632 |
if (r!=KErrNone && r!=KErrNotSupported) |
|
633 |
{ |
|
634 |
test.Printf(_L("ERROR:: CheckDisk returned %d\n"),r); |
|
635 |
// test.Getch(); |
|
636 |
} |
|
637 |
||
638 |
test.End(); |
|
639 |
} |
|
640 |
||
641 |
||
642 |
GLDEF_C void CallTestsL() |
|
643 |
// |
|
644 |
// Call all tests |
|
645 |
// |
|
646 |
{ |
|
647 |
||
648 |
#if defined(__WINS__) |
|
649 |
if (gSessionPath[0]=='C') |
|
650 |
return; |
|
651 |
#endif |
|
652 |
if (gSessionPath[0]=='C' || gSessionPath[0]=='Y') |
|
653 |
KMaxIteration=100; |
|
654 |
else |
|
655 |
KMaxIteration=100; |
|
656 |
CreateTestDirectory(_L("\\TRAND\\")); |
|
657 |
test.Printf(_L("\nThis test never stops. It is designed to create, delete and resize \n")); |
|
658 |
test.Printf(_L("multiple small files on the EPOC machine whilst testing that soft reset\n")); |
|
659 |
test.Printf(_L("events are not catastrophic to the filesystem. Once the test is running, \n")); |
|
660 |
test.Printf(_L("push the grey button to reset the machine at random intervals and then\n")); |
|
661 |
test.Printf(_L("restart the test. \n")); |
|
662 |
test.Printf(_L("\nPress any key to continue... \n")); |
|
663 |
test.Getch(); |
|
664 |
FOREVER |
|
665 |
{ |
|
666 |
MultipleFiles(50,0x200); |
|
667 |
MultipleFiles(50,0x400); |
|
668 |
MultipleFiles(50,0x1FF); |
|
669 |
MultipleFiles(50,0x201); |
|
670 |
Test1(); |
|
671 |
Test2(); |
|
672 |
Test3(); |
|
673 |
Test4(); |
|
674 |
} |
|
675 |
//DeleteTestDirectory(); |
|
676 |
} |