author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Thu, 02 Sep 2010 21:54:16 +0300 | |
changeset 259 | 57b9594f5772 |
parent 247 | d8d70de2bd36 |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 2007-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\t_wcache.cpp |
|
15 |
// This file contains a test for the Write Caching functionality of the File Server |
|
16 |
// |
|
17 |
// |
|
18 |
||
19 |
/** |
|
20 |
@file |
|
21 |
@internalTechnology |
|
22 |
*/ |
|
23 |
||
24 |
#define __E32TEST_EXTENSION__ |
|
25 |
#include <f32file.h> |
|
26 |
#include <e32test.h> |
|
27 |
#include <e32svr.h> |
|
28 |
#include <f32dbg.h> |
|
29 |
#include "t_server.h" |
|
30 |
#include <e32twin.h> |
|
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
31 |
#include <hal.h> |
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
32 |
#include "tf32testtimer.h" |
0 | 33 |
|
34 |
const TInt KTotalCacheSize = 32 * 1024 * 1024; |
|
35 |
const TInt KDefaultCacheSize = (128 + 12) * 1024; // This size is the default configuration size |
|
36 |
const TInt KFilesNeededToFillCache = (KTotalCacheSize / KDefaultCacheSize) + 2; |
|
37 |
const TInt KMinSize = 254; // Boundary minim limit |
|
38 |
const TInt KMaxSize = 257; // Boundary max limit |
|
39 |
||
40 |
||
41 |
||
42 |
//---------------------------------------------------------------------------------------------- |
|
43 |
//! @SYMTestCaseID PBASE-T_WCACHE-0271 |
|
44 |
//! @SYMTestType CIT |
|
45 |
//! @SYMPREQ PREQ914 |
|
46 |
//! @SYMTestCaseDesc This test case is exercising the Write Caching functionality added to |
|
47 |
//! the File Server. There are negative and positive tests. |
|
48 |
//! @SYMTestActions 0 setup the environment to execute the tests |
|
49 |
//! 1 TestBoundaries writes/reads around the write cache boundaries to |
|
50 |
//! the behaviour of the cache in some common cases. |
|
51 |
//! 2 TestNegative ensures the integrity of data in the cache gets |
|
52 |
//! preserved under error conditions |
|
53 |
//! 3 TestIntegrity is trying to make sure integrity of the data is preserved |
|
54 |
//! 4 TestFillCache fills the cache and then executes TestBoundaries. |
|
55 |
//! 5 TestFillCacheNegative fills the cache with uncommitted data |
|
56 |
//! |
|
57 |
//! @SYMTestExpectedResults finishes if the read cache behaves as expected, panics otherwise |
|
58 |
//! @SYMTestPriority High |
|
59 |
//! @SYMTestStatus Implemented |
|
60 |
//---------------------------------------------------------------------------------------------- |
|
61 |
||
62 |
||
63 |
//////////////////////////////////////////////////////////// |
|
64 |
// Template functions encapsulating ControlIo magic |
|
65 |
// |
|
66 |
template <class C> |
|
67 |
TInt controlIo(RFs &fs, TInt drv, TInt fkn, C &c) |
|
68 |
{ |
|
69 |
TPtr8 ptrC((TUint8 *)&c, sizeof(C), sizeof(C)); |
|
70 |
||
71 |
TInt r = fs.ControlIo(drv, fkn, ptrC); |
|
72 |
||
73 |
return r; |
|
74 |
} |
|
75 |
||
76 |
RTest test(_L("T_WCACHE")); |
|
77 |
||
78 |
RFs gTheFs; |
|
79 |
TInt gDrive; |
|
80 |
TFileName gSessionPath; |
|
81 |
TChar gDriveToTest; |
|
82 |
TThreadId gMainThreadId; |
|
83 |
TInt gManual = 0; |
|
84 |
||
85 |
HBufC8* gBuf = NULL; |
|
86 |
TPtr8 gBufReadPtr(NULL, 0); |
|
87 |
HBufC8* gBufSec = NULL; |
|
88 |
TPtr8 gBufWritePtr(NULL, 0); |
|
89 |
||
90 |
const TInt KOneK = 1024; |
|
91 |
const TInt KOneMeg = KOneK * 1024; |
|
92 |
const TInt KBlockSize = KOneK; |
|
93 |
const TInt KWaitRequestsTableSize = 256; |
|
94 |
||
95 |
TInt gSecondFileSize = 0; |
|
96 |
TInt gFirstFileSize = 0; |
|
97 |
||
98 |
TInt64 gMediaSize = 0; |
|
99 |
||
100 |
TTimeIntervalMicroSeconds gTimeTakenBigFile(0); |
|
101 |
TBuf16<25> gFirstFile; |
|
102 |
TBuf16<25> gSecondFile; |
|
103 |
TBuf16<25> gCurrentFile; |
|
104 |
||
105 |
TInt gNextFile = 0; |
|
106 |
||
107 |
// Concurrent Threads |
|
108 |
RThread gThread1; |
|
109 |
RSemaphore gClient; |
|
110 |
const TInt KHeapSize = 0x4000; |
|
111 |
const TInt KMaxHeapSize = 0x100000; |
|
112 |
||
113 |
||
114 |
/** Formats the drive |
|
115 |
||
116 |
@param aDrive Drive to be formatted |
|
117 |
@param aFormatMode Mode for the format operation |
|
118 |
*/ |
|
119 |
void Formatting(TInt aDrive, TUint aFormatMode ) |
|
120 |
{ |
|
121 |
||
122 |
test.Next(_L("Format")); |
|
123 |
TBuf<4> driveBuf = _L("?:\\"); |
|
124 |
driveBuf[0]=(TText)(aDrive+'A'); |
|
125 |
RFormat format; |
|
126 |
TInt count; |
|
127 |
TInt r = format.Open(gTheFs,driveBuf,aFormatMode,count); |
|
128 |
test_KErrNone(r); |
|
129 |
while(count) |
|
130 |
{ |
|
131 |
TInt r = format.Next(count); |
|
132 |
test_KErrNone(r); |
|
133 |
} |
|
134 |
format.Close(); |
|
135 |
||
136 |
} |
|
137 |
||
138 |
/** Verifies the content of a buffer |
|
139 |
This function returns KErrNone when all the letters are consecutive in the aBuffer, KErrCorrupt otherwise |
|
140 |
||
141 |
@param aBuffer Buffer to be verified |
|
142 |
||
143 |
@return KErrNone if all the letters are the same, KErrCorrupt otherwise |
|
144 |
*/ |
|
145 |
TInt VerifyBuffer(TDes8& aBuffer) |
|
146 |
{ |
|
147 |
TChar c = aBuffer[0]; |
|
148 |
||
149 |
for(TInt i = 1; i < aBuffer.Length(); i++) |
|
150 |
{ |
|
151 |
if(i%32 != 0) |
|
152 |
{ |
|
153 |
if(c != (TChar)(aBuffer[i] - 1)) |
|
154 |
return KErrCorrupt; |
|
155 |
} |
|
156 |
else |
|
157 |
{ |
|
158 |
if(aBuffer[i] != aBuffer[0]) |
|
159 |
return KErrCorrupt; |
|
160 |
} |
|
161 |
c = aBuffer[i]; |
|
162 |
} |
|
163 |
||
164 |
return KErrNone; |
|
165 |
} |
|
166 |
||
167 |
/** Fills a buffer with character aC, aC+1, aC+2, ..., aC+0x20, aC, etc |
|
168 |
||
169 |
@param aBuffer Buffer to be filled, output |
|
170 |
@param aLength Length to be filled |
|
171 |
@param aC Character to be used to fill the buffer |
|
172 |
*/ |
|
173 |
void FillBuffer(TDes8& aBuffer, TInt aLength, TChar aC) |
|
174 |
{ |
|
175 |
test (aBuffer.MaxLength() >= aLength); |
|
176 |
for(TInt i = 0; i < aLength; i++) |
|
177 |
{ |
|
178 |
aBuffer.Append((i%32) + aC); |
|
179 |
} |
|
180 |
} |
|
181 |
||
182 |
/** Returns true if fat filesystem present on aDrive |
|
183 |
||
184 |
@param aFsSession Session on the File Server |
|
185 |
@param aDrive Drive to be looked at |
|
186 |
||
187 |
@return ETrue if FAT, EFalse otherwise |
|
188 |
*/ |
|
189 |
TBool IsFSFAT(RFs &aFsSession,TInt aDrive) |
|
190 |
{ |
|
191 |
TFileName f; |
|
192 |
TInt r = aFsSession.FileSystemName(f,aDrive); |
|
193 |
||
194 |
if (r != KErrNone) |
|
195 |
{ |
|
196 |
test.Printf(_L("Unable to get file system name\n")); |
|
197 |
return EFalse; |
|
198 |
} |
|
199 |
||
200 |
return (f.CompareF(_L("Fat")) == 0); |
|
201 |
} |
|
202 |
||
203 |
/** Generates a file name of the form FFFFF*<aPos>.TXT (aLong.3) |
|
204 |
||
205 |
@param aBuffer The filename will be returned here |
|
206 |
@param aLong Defines the longitude of the file name |
|
207 |
@param aPos Defines the number that will be attached to the filename |
|
208 |
*/ |
|
209 |
void FileNameGen(TDes16& aBuffer, TInt aLong, TInt aPos) |
|
210 |
{ |
|
211 |
TInt padding; |
|
212 |
TInt i = 0; |
|
213 |
TBuf16<10> tempbuf; |
|
214 |
||
215 |
_LIT(KNumber,"%d"); |
|
216 |
tempbuf.Format(KNumber,aPos); |
|
217 |
padding = aLong-tempbuf.Size()/2; |
|
218 |
aBuffer = _L(""); |
|
219 |
while(i < padding) |
|
220 |
{ |
|
221 |
aBuffer.Append('F'); |
|
222 |
i++; |
|
223 |
} |
|
224 |
aBuffer.Append(tempbuf); |
|
225 |
||
226 |
_LIT(KExtension1, ".TXT"); |
|
227 |
aBuffer.Append(KExtension1); |
|
228 |
} |
|
229 |
||
230 |
/** Delete content of directory |
|
231 |
||
232 |
@param aDir Target directory |
|
233 |
||
234 |
@return Error returned if any, otherwise KErrNone |
|
235 |
*/ |
|
236 |
TInt DeleteAllL(TDes16& aDir) |
|
237 |
{ |
|
238 |
TBuf16<100> dir; |
|
239 |
CFileMan* fMan = CFileMan::NewL(gTheFs); |
|
240 |
TInt r=0; |
|
241 |
||
242 |
dir = aDir; |
|
243 |
dir.Append(_L("F*.*")); |
|
244 |
r = fMan->Delete(dir); |
|
245 |
||
246 |
delete fMan; |
|
247 |
return r; |
|
248 |
} |
|
249 |
||
250 |
/** Waits for all the TRequestStatus in status[] to complete |
|
251 |
||
252 |
@param status Array of TRequestStatus |
|
253 |
@param aSize Length to be filled |
|
254 |
*/ |
|
255 |
void WaitForAll(TRequestStatus* status, TInt aSize) |
|
256 |
{ |
|
257 |
TInt i = 0; |
|
258 |
||
259 |
RTest test(_L("T_WCACHE")); |
|
260 |
||
261 |
while(i < aSize) |
|
262 |
{ |
|
263 |
User::WaitForRequest(status[i]); |
|
264 |
if (status[i] != KErrNone) |
|
265 |
{ |
|
266 |
test.Printf(_L("status[%d] == %d\n"), i, status[i].Int()); |
|
267 |
test(EFalse); |
|
268 |
} |
|
269 |
i++; |
|
270 |
} |
|
271 |
||
272 |
test.Close(); |
|
273 |
} |
|
274 |
||
275 |
/** Reads the parameters from the comand line |
|
276 |
and updates the appropriate variables |
|
277 |
*/ |
|
278 |
void parseCommandLine() |
|
279 |
{ |
|
280 |
TBuf<0x100> cmd; |
|
281 |
User::CommandLine(cmd); |
|
282 |
TLex lex(cmd); |
|
283 |
TPtrC token = lex.NextToken(); |
|
284 |
TInt r=0; |
|
285 |
||
286 |
if(token.Length() != 0) |
|
287 |
{ |
|
288 |
gDriveToTest = token[0]; |
|
289 |
gDriveToTest.UpperCase(); |
|
290 |
} |
|
291 |
else |
|
292 |
{ |
|
293 |
gDriveToTest = 'C'; |
|
294 |
} |
|
295 |
||
296 |
r = gTheFs.CharToDrive(gDriveToTest,gDrive); |
|
297 |
test_KErrNone(r); |
|
298 |
||
299 |
if(!lex.Eos()) |
|
300 |
{ |
|
301 |
token.Set(lex.NextToken()); |
|
302 |
if(token.Length() != 0) |
|
303 |
{ |
|
304 |
TChar c = token[0]; |
|
305 |
c.UpperCase(); |
|
306 |
||
307 |
gManual = (c == 'M'); |
|
308 |
} |
|
309 |
} |
|
310 |
||
311 |
gSessionPath = _L("?:\\F32-TST\\"); |
|
312 |
gSessionPath[0] = (TUint16) gDriveToTest; |
|
313 |
test.Printf(_L("\nCLP=%C\n"),(TInt)gDriveToTest); |
|
314 |
} |
|
315 |
||
316 |
||
317 |
||
318 |
/** Writes a file synchronously in blocks of aBlockSize size |
|
319 |
||
320 |
@param aFs RFs object |
|
321 |
@param aFile File |
|
322 |
@param aFileName File name |
|
323 |
@param aSize Size of the file in bytes |
|
324 |
@param aBlockSize Size of the blocks to be used in bytes |
|
325 |
@param aBuf Buffer to be used to write |
|
326 |
@param aMode Mode in which the file is meant to be opened |
|
327 |
||
328 |
@return Returns KErrNone if everything ok, otherwise it panics |
|
329 |
*/ |
|
330 |
TInt WriteFile(RFs& aFs, RFile& aFile, TDes16& aFileName, TInt aSize, TInt aBlockSize, TDes8& aBuf, TInt aMode) |
|
331 |
{ |
|
332 |
RTest test(_L("T_WCACHE")); |
|
333 |
||
334 |
TInt r = 0; |
|
335 |
||
336 |
test(aBlockSize > 0); |
|
337 |
||
338 |
||
339 |
r = aFile.Replace(aFs,aFileName,aMode); |
|
340 |
test_KErrNone(r); |
|
341 |
||
342 |
TInt j = 0; |
|
343 |
while(j < aSize) |
|
344 |
{ |
|
345 |
r = aFile.Write(aBuf, aBlockSize); |
|
346 |
test_KErrNone(r); |
|
347 |
j += aBlockSize; |
|
348 |
} |
|
349 |
||
350 |
test.Close(); |
|
351 |
return KErrNone; |
|
352 |
} |
|
353 |
||
354 |
/** Write a file that fits in the cache, and dies without proper cleaning |
|
355 |
||
356 |
*/ |
|
357 |
LOCAL_C TInt WriteFileT(TAny* ) |
|
358 |
{ |
|
359 |
RTest test(_L("T_WCACHE")); |
|
360 |
RFs fs; |
|
361 |
RFile file; |
|
362 |
TInt r = fs.Connect(); |
|
363 |
test_KErrNone(r); |
|
364 |
||
365 |
r = fs.SetSessionPath(gSessionPath); |
|
366 |
test_KErrNone(r); |
|
367 |
||
368 |
r = WriteFile(fs, file, gFirstFile, KMinSize * KOneK, KBlockSize, gBufWritePtr, EFileShareAny|EFileWrite|EFileWriteBuffered); |
|
369 |
test_KErrNone(r); |
|
370 |
||
371 |
gClient.Signal(); |
|
372 |
||
373 |
||
374 |
FOREVER |
|
375 |
{ |
|
376 |
// waiting for the kill |
|
377 |
} |
|
378 |
} |
|
379 |
||
380 |
/** Read File in blocks of size aBlockSize |
|
381 |
||
382 |
@param aFs RFs object |
|
383 |
@param aFile File |
|
384 |
@param aFileName File name |
|
385 |
@param aSize Expected file size |
|
386 |
@param aBlockSize Size of the blocks to be used in bytes |
|
387 |
@param aMode Mode in which the file is meant to be opened |
|
388 |
||
389 |
@return Returns KErrNone if everything ok, otherwise it panics |
|
390 |
*/ |
|
391 |
TInt ReadFile(RFs& aFs, RFile& aFile, TDes16& aFileName, TInt aSize, TInt aBlockSize, TInt aMode) |
|
392 |
{ |
|
393 |
RTest test(_L("T_WCACHE")); |
|
394 |
||
395 |
TInt r = 0, size = 0; |
|
396 |
||
397 |
test(aBlockSize>0); // Block size must be greater than 0 |
|
398 |
||
399 |
r = aFile.Open(aFs,aFileName,aMode); |
|
400 |
test_KErrNone(r); |
|
401 |
||
402 |
// Make sure the size of the file is the right one at this stage |
|
403 |
r = aFile.Size(size); |
|
404 |
test.Printf(_L("size of the file: %d \n"), size/KOneK); |
|
405 |
test(size == aSize); |
|
406 |
||
407 |
TInt j = 0; |
|
408 |
while(j < size) |
|
409 |
{ |
|
410 |
r = aFile.Read(gBufReadPtr, aBlockSize); |
|
411 |
test_KErrNone(r); |
|
412 |
j += aBlockSize; |
|
413 |
} |
|
414 |
||
415 |
test.Close(); |
|
416 |
return KErrNone; |
|
417 |
} |
|
418 |
||
419 |
/** Write a file asynchronously in blocks of aBlockSize size |
|
420 |
||
421 |
@param aFs RFs object |
|
422 |
@param aFileWrite RFile object, needs to exist beyond the scope of this function |
|
423 |
@param aFile File name |
|
424 |
@param aSize Size of the file in bytes |
|
425 |
@param aMode Specifies the mode in which the file should be openned |
|
426 |
@param aStatus TRequestStatus array for all the requests |
|
427 |
*/ |
|
428 |
void WriteFileAsync(RFs& aFs, RFile& aFileWrite, TDes16& aFile, TInt aSize, TInt aMode, TRequestStatus aStatus[]) |
|
429 |
{ |
|
430 |
RTest test(_L("T_WCACHE")); |
|
431 |
||
432 |
TInt r = 0; |
|
433 |
||
434 |
r = aFileWrite.Replace(aFs,aFile,aMode); |
|
435 |
test_KErrNone(r); |
|
436 |
||
437 |
TInt j = 0, i = 0; |
|
438 |
while(j < aSize) |
|
439 |
{ |
|
440 |
aFileWrite.Write(gBufWritePtr, KBlockSize, aStatus[i]); |
|
441 |
r = aStatus[i].Int(); |
|
442 |
if (r != KErrNone && r != KRequestPending) |
|
443 |
{ |
|
444 |
test.Printf(_L("Write %d returned %d\n"), i, r); |
|
445 |
test(0); |
|
446 |
} |
|
447 |
i++; |
|
448 |
||
449 |
j += KBlockSize; |
|
450 |
} |
|
451 |
test.Close(); |
|
452 |
} |
|
453 |
||
454 |
/** Read a file asynchronously in blocks of aBlockSize size |
|
455 |
||
456 |
@param aFs RFs object |
|
457 |
@param aFileRead RFile object, needs to exist beyond the scope of this function |
|
458 |
@param aFile File name |
|
459 |
@param aFileSize Size of the file in bytes |
|
460 |
@param aBlockSize Size of the blocks to be used in bytes |
|
461 |
@param aStatus TRequestStatus array for all the requests |
|
462 |
@param aMode Specifies the mode in which the file should be openned |
|
463 |
||
464 |
@return KErrNone |
|
465 |
*/ |
|
466 |
TInt ReadFileAsync(RFs& aFs,RFile& aFileRead, TDes16& aFile, TInt aFileSize, TInt aBlockSize,TRequestStatus aStatus[], TInt aMode) |
|
467 |
{ |
|
468 |
RTest test(_L("T_WCACHE")); |
|
469 |
||
470 |
TInt r = 0; |
|
471 |
TInt size = 0; |
|
472 |
||
473 |
test(aBlockSize > 0); |
|
474 |
||
475 |
||
476 |
r = aFileRead.Open(aFs,aFile, aMode); |
|
477 |
test_KErrNone(r); |
|
478 |
||
479 |
r = aFileRead.Size(size); |
|
480 |
test_KErrNone(r); |
|
481 |
||
482 |
test.Printf(_L("size of the file %d\n"), size/KOneK); |
|
483 |
test(size == aFileSize); |
|
484 |
||
485 |
TInt j = 0, i = 0; |
|
486 |
while(j < size) |
|
487 |
{ |
|
488 |
aFileRead.Read(gBufReadPtr, aBlockSize, aStatus[i]); |
|
489 |
r = aStatus[i].Int(); |
|
490 |
if (r != KErrNone && r != KRequestPending) |
|
491 |
{ |
|
492 |
test.Printf(_L("Read %d returned %d\n"), i, r); |
|
493 |
test(0); |
|
494 |
} |
|
495 |
i++; |
|
496 |
||
497 |
j += aBlockSize; |
|
498 |
} |
|
499 |
||
500 |
test.Close(); |
|
501 |
return KErrNone; |
|
502 |
} |
|
503 |
||
504 |
/** Measure the time taken for this file to be written synchronously |
|
505 |
||
506 |
@param aFile File object |
|
507 |
@param aFileName File Name |
|
508 |
@param aSize Size in kilobytes |
|
509 |
@param aBlockSize Size of the block |
|
510 |
@param aMode Mode in which the file is going to be opened |
|
511 |
||
512 |
@return time taken to perform the operation in uS |
|
513 |
*/ |
|
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
514 |
TTimeIntervalMicroSeconds WriteTestFile(RFile& aFile, TDes16& aFileName, TInt aSize, TInt aBlockSize, TInt aMode) |
0 | 515 |
{ |
516 |
RTest test(_L("T_WCACHE")); |
|
517 |
||
518 |
TInt r = 0; |
|
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
519 |
|
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
520 |
TF32TestTimer timer; |
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
521 |
timer.Start(); |
0 | 522 |
|
523 |
r = WriteFile(gTheFs,aFile, aFileName , aSize * KOneK, aBlockSize, gBufWritePtr, aMode); |
|
524 |
test_KErrNone(r); |
|
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
525 |
|
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
526 |
timer.Stop(); |
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
527 |
gTimeTakenBigFile = timer.Time(); |
0 | 528 |
test.Close(); |
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
529 |
return timer.Time(); |
0 | 530 |
} |
531 |
||
532 |
/** Measure the time taken for this file to be read synchronously |
|
533 |
||
534 |
@param aFile File object |
|
535 |
@param aFileName File Name |
|
536 |
@param aSize Size in kilobytes |
|
537 |
@param aBlockSize Size of the block |
|
538 |
@param aMode Mode in which the file is going to be opened |
|
539 |
||
540 |
@return time taken to perform the operation in uS |
|
541 |
||
542 |
*/ |
|
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
543 |
TTimeIntervalMicroSeconds ReadTestFile(RFile& aFile, TDes16& aFileName, TInt aSize, TInt aBlockSize, TInt aMode) |
0 | 544 |
{ |
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
545 |
TF32TestTimer timer; |
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
546 |
timer.Start(); |
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
547 |
ReadFile(gTheFs,aFile, aFileName, aSize * KOneK, aBlockSize, aMode); |
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
548 |
timer.Stop(); |
0 | 549 |
|
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
550 |
gTimeTakenBigFile = timer.Time(); |
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
551 |
|
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
552 |
return timer.Time(); |
0 | 553 |
} |
554 |
||
555 |
/** Read asynchronously the test file from the disc |
|
556 |
||
557 |
@param aFile File object |
|
558 |
@param aFileName File Name |
|
559 |
@param aSize Size in kilobytes |
|
560 |
@param aBlockSize Size of the block |
|
561 |
@param aMode Mode in which the file is going to be opened |
|
562 |
||
563 |
@return time taken to perform the operation in uS |
|
564 |
*/ |
|
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
565 |
TTimeIntervalMicroSeconds ReadAsyncTestFile(RFile& file, TDes16& aFile, TInt aSize, TInt aBlockSize, TInt aMode) |
0 | 566 |
{ |
567 |
TRequestStatus status[KWaitRequestsTableSize]; |
|
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
568 |
TF32TestTimer timer; |
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
569 |
timer.Start(); |
0 | 570 |
|
571 |
ReadFileAsync(gTheFs, file, aFile, aSize * KOneK, aBlockSize, status, aMode); |
|
572 |
WaitForAll(status, (aSize * KOneK)/KBlockSize); |
|
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
573 |
timer.Stop(); |
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
574 |
|
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
575 |
gTimeTakenBigFile = timer.Time(); |
0 | 576 |
|
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
577 |
return timer.Time(); |
0 | 578 |
} |
579 |
||
580 |
/** Read asynchronously the test file from the disc |
|
581 |
||
582 |
@param aFile File object |
|
583 |
@param aFileName File Name |
|
584 |
@param aSize Size in kilobytes |
|
585 |
@param aMode Mode in which the file is going to be opened |
|
586 |
||
587 |
@return time taken to perform the operation in uS |
|
588 |
*/ |
|
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
589 |
TTimeIntervalMicroSeconds WriteAsyncTestFile(RFile& aFile, TDes16& aFileName, TInt aSize, TInt aMode) |
0 | 590 |
{ |
591 |
TRequestStatus status[KWaitRequestsTableSize]; |
|
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
592 |
TF32TestTimer timer; |
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
593 |
timer.Start(); |
0 | 594 |
|
595 |
WriteFileAsync(gTheFs, aFile, aFileName, aSize * KOneK, aMode, status ); |
|
596 |
WaitForAll(status, (aSize * KOneK)/KBlockSize); |
|
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
597 |
timer.Stop(); |
0 | 598 |
|
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
599 |
gTimeTakenBigFile = timer.Time(); |
0 | 600 |
|
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
601 |
return timer.Time(); |
0 | 602 |
} |
603 |
||
604 |
/** Test Boundaries |
|
605 |
||
606 |
This function is testing the behaviour on the boundaries of the write cache size |
|
607 |
*/ |
|
608 |
void TestBoundaries() |
|
609 |
{ |
|
610 |
TInt r = 0; |
|
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
611 |
TTimeIntervalMicroSeconds time = 0; |
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
612 |
TTimeIntervalMicroSeconds rtime = 0; |
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
613 |
TTimeIntervalMicroSeconds tcreate = 0; |
0 | 614 |
RFile fileWriter; |
615 |
RFile fileWriter2; |
|
616 |
RFile fileReader; |
|
617 |
||
618 |
test.Start(_L("Test Boundaries")); |
|
619 |
||
620 |
// Test boundaries from 254K to 256K, synchronous operations |
|
621 |
TInt i = KMinSize; |
|
622 |
||
623 |
||
624 |
test.Printf(_L("\n\n\n")); |
|
625 |
||
626 |
while(i < KMaxSize) |
|
627 |
{ |
|
628 |
test.Printf(_L("\nSync: Write from 1 K to %d K \n"), i); |
|
629 |
||
630 |
tcreate = WriteTestFile(fileWriter, gSecondFile, i, KBlockSize, EFileShareAny|EFileWrite|EFileWriteDirectIO); |
|
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
631 |
test.Printf(_L("Time to write %d K without caching: %d mS\n"), i, TF32TestTimer::TimeInMilliSeconds(tcreate)); |
0 | 632 |
fileWriter.Close(); |
633 |
||
634 |
time = WriteTestFile(fileWriter2, gFirstFile, i, KBlockSize, EFileShareAny|EFileWrite|EFileWriteBuffered); |
|
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
635 |
test.Printf(_L("Time to write %d K WITH caching: %d mS\n"), i, TF32TestTimer::TimeInMilliSeconds(time)); |
0 | 636 |
|
637 |
rtime = ReadTestFile(fileReader, gFirstFile, i, KBlockSize, EFileShareAny|EFileRead|EFileReadBuffered); |
|
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
638 |
test.Printf(_L("Time to read %d K from the cache: %d mS\n"), i, TF32TestTimer::TimeInMilliSeconds(rtime)); |
0 | 639 |
|
640 |
fileReader.Close(); |
|
641 |
fileWriter2.Close(); |
|
642 |
||
643 |
#if !defined(__WINS__) |
|
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
644 |
test(tcreate > TTimeIntervalMicroSeconds(0)); // test measured time is correct |
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
645 |
test(tcreate > time); |
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
646 |
test(tcreate > rtime); |
0 | 647 |
#endif |
648 |
||
649 |
r = gTheFs.Delete(gFirstFile); |
|
650 |
test_KErrNone(r); |
|
651 |
r = gTheFs.Delete(gSecondFile); |
|
652 |
test_KErrNone(r); |
|
653 |
||
654 |
i++; |
|
655 |
} |
|
656 |
||
657 |
test.Printf(_L("\n\n\n")); |
|
658 |
||
659 |
// Test boundaries from 254K to 256K, asynchronous operations |
|
660 |
i = KMinSize; |
|
661 |
||
662 |
while(i < KMaxSize) |
|
663 |
{ |
|
664 |
test.Printf(_L("\nAsync: Write from 1 K to %d K \n"), i); |
|
665 |
||
666 |
tcreate = WriteAsyncTestFile(fileWriter, gSecondFile, i, EFileShareAny|EFileWrite|EFileWriteDirectIO); |
|
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
667 |
test.Printf(_L("Time to write %d K without caching: %d mS\n"), i, TF32TestTimer::TimeInMilliSeconds(tcreate)); |
0 | 668 |
fileWriter.Close(); |
669 |
||
670 |
time = WriteAsyncTestFile(fileWriter2, gFirstFile, i,EFileShareAny|EFileWrite|EFileWriteBuffered); |
|
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
671 |
test.Printf(_L("Time to write %d K WITH caching: %d mS\n"), i, TF32TestTimer::TimeInMilliSeconds(time)); |
0 | 672 |
|
673 |
||
674 |
rtime = ReadAsyncTestFile(fileReader, gFirstFile, i, KBlockSize, EFileShareAny|EFileRead|EFileReadBuffered); |
|
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
675 |
test.Printf(_L("Time to read %d K from the cache: %d mS\n"), i, TF32TestTimer::TimeInMilliSeconds(rtime)); |
0 | 676 |
|
677 |
fileReader.Close(); |
|
678 |
fileWriter2.Close(); |
|
679 |
||
680 |
#if !defined(__WINS__) |
|
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
681 |
test(tcreate > TTimeIntervalMicroSeconds(0)); // test measured time is correct |
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
682 |
test(tcreate > time); |
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
683 |
test(tcreate > rtime); |
0 | 684 |
#endif |
685 |
||
686 |
r = gTheFs.Delete(gFirstFile); |
|
687 |
test_KErrNone(r); |
|
688 |
r = gTheFs.Delete(gSecondFile); |
|
689 |
test_KErrNone(r); |
|
690 |
||
691 |
i++; |
|
692 |
} |
|
693 |
||
694 |
test.End(); |
|
695 |
} |
|
696 |
||
697 |
/** Test negative cases |
|
698 |
||
699 |
*/ |
|
700 |
void TestNegative() |
|
701 |
{ |
|
702 |
TInt r = 0; |
|
703 |
RFile file; |
|
704 |
TInt size =0; |
|
705 |
||
706 |
TBuf<20> buf = _L("Write File"); |
|
707 |
||
708 |
||
709 |
test.Start(_L("Test Negative")); |
|
710 |
||
711 |
test.Next(_L("Kill a simple operation")); |
|
712 |
||
713 |
r = gThread1.Create(buf,WriteFileT,KDefaultStackSize,KHeapSize,KMaxHeapSize,NULL); |
|
714 |
test_KErrNone(r); |
|
715 |
||
716 |
gThread1.Resume(); |
|
717 |
gClient.Wait(); |
|
718 |
||
719 |
gThread1.Kill(KErrGeneral); |
|
720 |
||
721 |
r = file.Open(gTheFs,gFirstFile,EFileShareAny|EFileRead|EFileReadBuffered|EFileReadAheadOff); |
|
722 |
test_KErrNone(r); |
|
723 |
||
724 |
r = file.Size(size); |
|
725 |
test_KErrNone(r); |
|
726 |
||
727 |
test.Printf(_L("The size of the file is %d KB\n\n"), size/KOneK); |
|
728 |
test(size == (KMinSize * KOneK)); |
|
729 |
||
730 |
file.Close(); |
|
731 |
||
732 |
test.End(); |
|
733 |
} |
|
734 |
||
735 |
||
736 |
/** Read the file verifying content |
|
737 |
||
738 |
@param aFile file name to verify |
|
739 |
||
740 |
@return returns the time that took to do the verification in mS, fails if the file is not corrupted/modified |
|
741 |
*/ |
|
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
742 |
TTimeIntervalMicroSeconds ReadTestFileVerif(TDes16& aFile) |
0 | 743 |
{ |
744 |
TInt r = 0; |
|
745 |
TInt size = 0; |
|
746 |
RFile fileRead; |
|
747 |
TInt corrupt = 0; |
|
748 |
TBool isFat=IsFSFAT(gTheFs,gDrive); |
|
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
749 |
|
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
750 |
TF32TestTimer timer; |
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
751 |
timer.Start(); |
0 | 752 |
|
753 |
r = fileRead.Open(gTheFs,aFile,EFileShareAny|EFileRead|EFileReadBuffered|EFileReadAheadOff); |
|
754 |
test_KErrNone(r); |
|
755 |
||
756 |
r = fileRead.Size(size); |
|
757 |
test_KErrNone(r); |
|
758 |
||
759 |
TInt j = 0; |
|
760 |
||
761 |
while(j < size) |
|
762 |
{ |
|
763 |
r = fileRead.Read(gBufReadPtr, KBlockSize); |
|
764 |
if(isFat) |
|
765 |
{ |
|
766 |
test_KErrNone(r); |
|
767 |
} |
|
768 |
else |
|
769 |
{ |
|
770 |
if(r == KErrCorrupt) |
|
771 |
corrupt++; |
|
772 |
} |
|
773 |
||
774 |
j += KBlockSize; |
|
775 |
r = VerifyBuffer(gBufReadPtr); |
|
776 |
if(r == KErrCorrupt) |
|
777 |
corrupt++; |
|
778 |
} |
|
779 |
||
780 |
fileRead.Close(); |
|
781 |
||
782 |
test(corrupt>0); // Ensure the cache returns the changed content |
|
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
783 |
timer.Stop(); |
0 | 784 |
|
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
785 |
gTimeTakenBigFile = timer.Time(); |
0 | 786 |
|
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
787 |
return timer.Time(); |
0 | 788 |
} |
789 |
||
790 |
/** Modifies the second file |
|
791 |
||
792 |
*/ |
|
793 |
LOCAL_C TInt CorruptSecondFile() |
|
794 |
{ |
|
795 |
TInt r = 0; |
|
796 |
RFile fileWrite; |
|
797 |
HBufC8* dummy = NULL; |
|
798 |
TPtr8 dummyPtr(NULL, 0); |
|
799 |
||
800 |
TRAPD(res,dummy = HBufC8::NewL(4)); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
801 |
test_Value(res, res == KErrNone && dummy != NULL); |
0 | 802 |
|
803 |
dummyPtr.Set(dummy->Des()); |
|
804 |
FillBuffer(dummyPtr, 4, '1'); |
|
805 |
||
806 |
r = fileWrite.Open(gTheFs,gSecondFile,EFileShareAny|EFileWrite|EFileWriteBuffered); |
|
807 |
if(r != KErrNone) |
|
808 |
return r; |
|
809 |
TInt pos = 30; |
|
810 |
r = fileWrite.Seek(ESeekStart,pos); |
|
811 |
test_KErrNone(r); |
|
812 |
||
813 |
r = fileWrite.Write(dummyPtr); |
|
814 |
if(r != KErrNone) |
|
815 |
return r; |
|
816 |
||
817 |
fileWrite.Close(); |
|
818 |
||
819 |
delete dummy; |
|
820 |
||
821 |
return KErrNone; |
|
822 |
} |
|
823 |
||
824 |
||
825 |
/** Integrity testing |
|
826 |
||
827 |
*/ |
|
828 |
LOCAL_C void TestIntegrity() |
|
829 |
{ |
|
830 |
TInt r = 0; |
|
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
831 |
TTimeIntervalMicroSeconds time; |
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
832 |
TTimeIntervalMicroSeconds tcreate = 0; |
0 | 833 |
RFile file; |
834 |
||
835 |
// Modify file in some position |
|
836 |
test.Printf(_L("Overwrite partially a file\n")); |
|
837 |
||
838 |
test.Printf(_L("\nSync: Write from 1 K to %d K \n"), 255); |
|
839 |
||
840 |
tcreate = WriteTestFile(file, gSecondFile, 255, KBlockSize, EFileShareAny|EFileWrite|EFileWriteBuffered); |
|
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
841 |
test.Printf(_L("Time to write %d K with caching: %d mS\n"), 255, TF32TestTimer::TimeInMilliSeconds(tcreate)); |
0 | 842 |
file.Close(); |
843 |
||
844 |
test.Printf(_L("Mess the content that is still in the cache\n")); |
|
845 |
CorruptSecondFile(); |
|
846 |
||
847 |
time = ReadTestFileVerif(gSecondFile); |
|
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
848 |
test.Printf(_L("Time taken to verify: %ld\n"),time.Int64()); |
0 | 849 |
|
850 |
test.Printf(_L("Integrity verified\n")); |
|
851 |
||
852 |
r = DeleteAllL(gSessionPath); |
|
853 |
test_KErrNone(r); |
|
854 |
} |
|
855 |
||
856 |
/** Creates the files to fill the cache with dirty data |
|
857 |
||
858 |
@return KErrNone |
|
859 |
*/ |
|
860 |
TInt CreateFilesThread(TAny *) |
|
861 |
{ |
|
862 |
TInt i = 0; |
|
863 |
TInt r = 0; |
|
864 |
TBuf16<50> directory; |
|
865 |
||
866 |
TBuf16<50> path; |
|
867 |
TBuf16<50> buffer(50); |
|
868 |
RFile file[KFilesNeededToFillCache]; |
|
869 |
||
870 |
RTest test(_L("T_WCACHE2")); |
|
871 |
RFs fs; |
|
872 |
||
873 |
fs.Connect(); |
|
874 |
||
875 |
directory = gSessionPath; |
|
876 |
||
877 |
test.Printf(_L("Creating %d files for filling the cache (size %d)\n"), KFilesNeededToFillCache, KDefaultCacheSize); |
|
878 |
||
879 |
// create a big buffer to speed things up |
|
880 |
HBufC8* bigBuf = NULL; |
|
881 |
TInt KBigBifferSize = 32 * KOneK; |
|
882 |
||
883 |
TRAPD(res,bigBuf = HBufC8::NewL(KBigBifferSize)); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
884 |
test_Value(res, res == KErrNone && bigBuf != NULL); |
0 | 885 |
|
886 |
TPtr8 bigBufWritePtr(NULL, 0); |
|
887 |
bigBufWritePtr.Set(bigBuf->Des()); |
|
888 |
FillBuffer(bigBufWritePtr, KBigBifferSize, 'A'); |
|
889 |
||
890 |
i = 0; |
|
891 |
while(i < KFilesNeededToFillCache) |
|
892 |
{ |
|
893 |
if (i % 10 == 0) |
|
894 |
test.Printf(_L("Creating file %d of %d...\r"), i, KFilesNeededToFillCache); |
|
895 |
FileNameGen(buffer, 8, i+3) ; |
|
896 |
path = directory; |
|
897 |
path.Append(buffer); |
|
898 |
||
899 |
r = file[i].Create(fs,path,EFileShareAny|EFileWrite|EFileWriteBuffered); |
|
900 |
if(r == KErrAlreadyExists) |
|
901 |
r = file[i].Open(fs,path,EFileShareAny|EFileWrite|EFileWriteBuffered); |
|
902 |
test_KErrNone(r); |
|
903 |
TInt j = 0; |
|
904 |
||
905 |
while(j < KDefaultCacheSize) |
|
906 |
{ |
|
907 |
bigBufWritePtr.SetLength(Min(KBigBifferSize, KDefaultCacheSize - j)); |
|
908 |
||
909 |
r = file[i].Write(bigBufWritePtr); |
|
910 |
test_KErrNone(r); |
|
911 |
j += bigBufWritePtr.Length(); |
|
912 |
} |
|
913 |
||
914 |
// Not closing the files is done on purpose, as part of the test |
|
915 |
||
916 |
i++; |
|
917 |
} |
|
918 |
test.Printf(_L("\nFiles created\n")); |
|
919 |
delete bigBuf; |
|
920 |
||
921 |
gClient.Signal(); |
|
922 |
||
923 |
return KErrNone; |
|
924 |
} |
|
925 |
||
926 |
||
927 |
/** Creates the files to fill the read cache |
|
928 |
||
929 |
@param aFiles Number of files needed to fill the cache |
|
930 |
@param aFileSize The file size |
|
931 |
*/ |
|
932 |
void CreateFiles(TInt aFiles, TInt aFileSize) |
|
933 |
{ |
|
934 |
TInt i = 0; |
|
935 |
TInt r = 0; |
|
936 |
RFile file; |
|
937 |
TBuf16<50> directory; |
|
938 |
||
939 |
TBuf16<50> path; |
|
940 |
TBuf16<50> buffer(50); |
|
941 |
||
942 |
directory = gSessionPath; |
|
943 |
||
944 |
test.Printf(_L("Creating %d files for filling the cache (size %d)\n"), aFiles, aFileSize); |
|
945 |
||
946 |
// create a big buffer to speed things up |
|
947 |
HBufC8* bigBuf = NULL; |
|
948 |
const TInt KBigBifferSize = 32 * 1024; |
|
949 |
TRAPD(res,bigBuf = HBufC8::NewL(KBigBifferSize)); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
950 |
test_Value(res, res == KErrNone && bigBuf != NULL); |
0 | 951 |
|
952 |
TPtr8 bigBufWritePtr(NULL, 0); |
|
953 |
bigBufWritePtr.Set(bigBuf->Des()); |
|
954 |
FillBuffer(bigBufWritePtr, KBigBifferSize, 'A'); |
|
955 |
||
956 |
i = 0; |
|
957 |
while(i < aFiles) |
|
958 |
{ |
|
959 |
if (i % 10 == 0) |
|
960 |
test.Printf(_L("Creating file %d of %d...\r"), i, aFiles); |
|
961 |
FileNameGen(buffer, 8, i+3) ; |
|
962 |
path = directory; |
|
963 |
path.Append(buffer); |
|
964 |
||
965 |
// delete file first to ensure it's contents are not in the cache (file may be be on the closed file queue) |
|
966 |
r = gTheFs.Delete(path); |
|
967 |
test_Value(r, r == KErrNone || r == KErrNotFound); |
|
968 |
||
969 |
r = file.Create(gTheFs,path,EFileShareAny|EFileWrite|EFileWriteDirectIO); |
|
970 |
if(r == KErrAlreadyExists) |
|
971 |
r = file.Open(gTheFs,path,EFileShareAny|EFileWrite|EFileWriteDirectIO); |
|
972 |
test_KErrNone(r); |
|
973 |
TInt j = 0; |
|
974 |
while(j < aFileSize) |
|
975 |
{ |
|
976 |
bigBufWritePtr.SetLength(Min(KBigBifferSize, aFileSize - j)); |
|
977 |
r = file.Write(bigBufWritePtr); |
|
978 |
test_KErrNone(r); |
|
979 |
j += bigBufWritePtr.Length(); |
|
980 |
} |
|
981 |
||
982 |
file.Close(); |
|
983 |
i++; |
|
984 |
} |
|
985 |
test.Printf(_L("\nFiles created\n")); |
|
986 |
delete bigBuf; |
|
987 |
} |
|
988 |
||
989 |
/** Fills the read cache |
|
990 |
||
991 |
@param aFile Array of files needed to fill the cache |
|
992 |
@param aFiles Number of files needed to fill the cache |
|
993 |
@param aFileSize The file size |
|
994 |
*/ |
|
995 |
void FillCache(RFile aFile[KFilesNeededToFillCache], TInt aFiles, TInt aFileSize) |
|
996 |
{ |
|
997 |
TInt i = 0; |
|
998 |
TInt r = 0; |
|
999 |
TBuf16<50> directory; |
|
1000 |
||
1001 |
TBuf16<50> path; |
|
1002 |
TBuf16<50> buffer(50); |
|
1003 |
HBufC8* buf = NULL; |
|
1004 |
TPtr8 bufPtr(NULL, 0); |
|
1005 |
||
1006 |
TRAPD(res,buf = HBufC8::NewL(2)); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1007 |
test_Value(res, res == KErrNone && buf != NULL); |
0 | 1008 |
bufPtr.Set(buf->Des()); |
1009 |
||
1010 |
directory = gSessionPath; |
|
1011 |
||
1012 |
i = 0; |
|
1013 |
while(i < aFiles) |
|
1014 |
{ |
|
1015 |
FileNameGen(buffer, 8, i+3) ; |
|
1016 |
path = directory; |
|
1017 |
path.Append(buffer); |
|
1018 |
r = aFile[i].Open(gTheFs,path,EFileShareAny|EFileRead|EFileReadBuffered|EFileReadAheadOff); |
|
1019 |
test_KErrNone(r); |
|
1020 |
||
1021 |
TInt j = 0; |
|
1022 |
while(j < aFileSize) |
|
1023 |
{ |
|
1024 |
r = aFile[i].Read(j,bufPtr); |
|
1025 |
test_KErrNone(r); |
|
1026 |
j += 4*KOneK; |
|
1027 |
} |
|
1028 |
||
1029 |
i++; |
|
1030 |
} |
|
1031 |
||
1032 |
delete buf; |
|
1033 |
test.Printf(_L("Cache filled\n")); |
|
1034 |
} |
|
1035 |
||
1036 |
/** Fills the default cache |
|
1037 |
||
1038 |
*/ |
|
1039 |
void TestFillCache() |
|
1040 |
{ |
|
1041 |
TInt nFiles = KFilesNeededToFillCache; |
|
1042 |
TInt fSize = KDefaultCacheSize; |
|
1043 |
RFile file[KFilesNeededToFillCache]; |
|
1044 |
TInt r = 0; |
|
1045 |
||
1046 |
if(gMediaSize> ((fSize * nFiles)+gSecondFileSize+gFirstFileSize)) |
|
1047 |
{ |
|
1048 |
test.Start(_L("Creating files for filling the cache\n")); |
|
1049 |
CreateFiles(nFiles,fSize); |
|
1050 |
#if defined(_DEBUG) || defined(_DEBUG_RELEASE) |
|
1051 |
// get number of items on Page Cache |
|
1052 |
TFileCacheStats startPageCacheStats; |
|
1053 |
r = controlIo(gTheFs,gDrive, KControlIoFileCacheStats, startPageCacheStats); |
|
1054 |
test_Value(r, r == KErrNone || r == KErrNotSupported); |
|
1055 |
test.Printf(_L("Number of page cache lines on free list at beginning=%d\n"),startPageCacheStats.iFreeCount); |
|
1056 |
test.Printf(_L("Number of page cache lines on used list at beginning=%d\n"),startPageCacheStats.iUsedCount); |
|
1057 |
test.Printf(_L("Number of files on closed queue=%d\n"),startPageCacheStats.iFilesOnClosedQueue); |
|
1058 |
#endif |
|
1059 |
FillCache(file,nFiles,fSize); |
|
1060 |
||
1061 |
#if defined(_DEBUG) || defined(_DEBUG_RELEASE) |
|
1062 |
// get number of items on Page Cache |
|
1063 |
r = controlIo(gTheFs,gDrive, KControlIoFileCacheStats, startPageCacheStats); |
|
1064 |
test_Value(r, r == KErrNone || r == KErrNotSupported); |
|
1065 |
test.Printf(_L("Number of page cache lines on free list at end=%d\n"),startPageCacheStats.iFreeCount); |
|
1066 |
test.Printf(_L("Number of page cache lines on used list at end=%d\n"),startPageCacheStats.iUsedCount); |
|
1067 |
test.Printf(_L("Number of files on closed queue=%d\n"),startPageCacheStats.iFilesOnClosedQueue); |
|
1068 |
#endif |
|
1069 |
||
1070 |
TestBoundaries(); |
|
1071 |
||
1072 |
#if defined(_DEBUG) || defined(_DEBUG_RELEASE) |
|
1073 |
// get number of items on Page Cache |
|
1074 |
r = controlIo(gTheFs,gDrive, KControlIoFileCacheStats, startPageCacheStats); |
|
1075 |
test_Value(r, r == KErrNone || r == KErrNotSupported); |
|
1076 |
test.Printf(_L("Number of page cache lines on free list after the boundary testing=%d\n"),startPageCacheStats.iFreeCount); |
|
1077 |
test.Printf(_L("Number of page cache lines on used list after the boundary testing=%d\n"),startPageCacheStats.iUsedCount); |
|
1078 |
test.Printf(_L("Number of files on closed queue=%d\n"),startPageCacheStats.iFilesOnClosedQueue); |
|
1079 |
#endif |
|
1080 |
||
1081 |
TInt i = 0; |
|
1082 |
while( i < KFilesNeededToFillCache ) |
|
1083 |
{ |
|
1084 |
file[i++].Close(); |
|
1085 |
} |
|
1086 |
||
1087 |
r = DeleteAllL(gSessionPath); |
|
1088 |
test_KErrNone(r); |
|
1089 |
||
1090 |
test.End(); |
|
1091 |
} |
|
1092 |
else |
|
1093 |
test.Printf(_L("Skipping the fill of the cache due to lack of space in the current drive\n")); |
|
1094 |
} |
|
1095 |
||
1096 |
/** Fills the cache and generate error situations |
|
1097 |
||
1098 |
*/ |
|
1099 |
void TestFillCacheNegative() |
|
1100 |
{ |
|
1101 |
TInt nFiles = KFilesNeededToFillCache; |
|
1102 |
TInt r = 0; |
|
1103 |
||
1104 |
if(gMediaSize> ((KDefaultCacheSize * nFiles)+gSecondFileSize+gFirstFileSize)) |
|
1105 |
{ |
|
1106 |
#if defined(_DEBUG) || defined(_DEBUG_RELEASE) |
|
1107 |
// get number of items on Page Cache |
|
1108 |
TFileCacheStats startPageCacheStats; |
|
1109 |
r = controlIo(gTheFs,gDrive, KControlIoFileCacheStats, startPageCacheStats); |
|
1110 |
test_Value(r, r == KErrNone || r == KErrNotSupported); |
|
1111 |
test.Printf(_L("Number of page cache lines on free list at beginning=%d\n"),startPageCacheStats.iFreeCount); |
|
1112 |
test.Printf(_L("Number of page cache lines on used list at beginning=%d\n"),startPageCacheStats.iUsedCount); |
|
1113 |
test.Printf(_L("Number of files on closed queue=%d\n"),startPageCacheStats.iFilesOnClosedQueue); |
|
1114 |
#endif |
|
1115 |
test.Start(_L("Creating files for filling the cache, with uncommitted data\n")); |
|
1116 |
||
1117 |
TBuf<20> buf = _L("FillCache"); |
|
1118 |
||
1119 |
r = gThread1.Create(buf,CreateFilesThread,KDefaultStackSize,KHeapSize,KMaxHeapSize,NULL); |
|
1120 |
test_KErrNone(r); |
|
1121 |
||
1122 |
gThread1.Resume(); |
|
1123 |
gClient.Wait(); |
|
1124 |
||
1125 |
#if defined(_DEBUG) || defined(_DEBUG_RELEASE) |
|
1126 |
// get number of items on Page Cache |
|
1127 |
r = controlIo(gTheFs,gDrive, KControlIoFileCacheStats, startPageCacheStats); |
|
1128 |
test_Value(r, r == KErrNone || r == KErrNotSupported); |
|
1129 |
test.Printf(_L("Number of page cache lines on free list at end=%d\n"),startPageCacheStats.iFreeCount); |
|
1130 |
test.Printf(_L("Number of page cache lines on used list at end=%d\n"),startPageCacheStats.iUsedCount); |
|
1131 |
test.Printf(_L("Number of files on closed queue=%d\n"),startPageCacheStats.iFilesOnClosedQueue); |
|
1132 |
#endif |
|
1133 |
||
1134 |
TestBoundaries(); |
|
1135 |
||
1136 |
#if defined(_DEBUG) || defined(_DEBUG_RELEASE) |
|
1137 |
// get number of items on Page Cache |
|
1138 |
r = controlIo(gTheFs,gDrive, KControlIoFileCacheStats, startPageCacheStats); |
|
1139 |
test_Value(r, r == KErrNone || r == KErrNotSupported); |
|
1140 |
test.Printf(_L("Number of page cache lines on free list after the boundary testing=%d\n"),startPageCacheStats.iFreeCount); |
|
1141 |
test.Printf(_L("Number of page cache lines on used list after the boundary testing=%d\n"),startPageCacheStats.iUsedCount); |
|
1142 |
test.Printf(_L("Number of files on closed queue=%d\n"),startPageCacheStats.iFilesOnClosedQueue); |
|
1143 |
||
1144 |
User::After(180000); |
|
1145 |
||
1146 |
r = controlIo(gTheFs,gDrive, KControlIoFileCacheStats, startPageCacheStats); |
|
1147 |
test_Value(r, r == KErrNone || r == KErrNotSupported); |
|
1148 |
test.Printf(_L("Number of page cache lines on free list after the boundary testing=%d\n"),startPageCacheStats.iFreeCount); |
|
1149 |
test.Printf(_L("Number of page cache lines on used list after the boundary testing=%d\n"),startPageCacheStats.iUsedCount); |
|
1150 |
test.Printf(_L("Number of files on closed queue=%d\n"),startPageCacheStats.iFilesOnClosedQueue); |
|
1151 |
||
1152 |
#endif |
|
1153 |
test.End(); |
|
1154 |
||
1155 |
r = DeleteAllL(gSessionPath); |
|
1156 |
test_KErrNone(r); |
|
1157 |
||
1158 |
} |
|
1159 |
else |
|
1160 |
test.Printf(_L("Skipping the fill of the cache due to lack of space in the current drive\n")); |
|
1161 |
} |
|
1162 |
||
1163 |
||
1164 |
/** Manual test for card removal |
|
1165 |
||
1166 |
*/ |
|
1167 |
void TestRemoval() |
|
1168 |
{ |
|
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
1169 |
TTimeIntervalMicroSeconds time = 0, rtime = 0; |
0 | 1170 |
RFile file1, file2; |
1171 |
||
1172 |
||
1173 |
TInt r = gClient.CreateLocal(0); |
|
1174 |
test_KErrNone(r); |
|
1175 |
||
1176 |
r = gTheFs.SetSessionPath(gSessionPath); |
|
1177 |
test_KErrNone(r); |
|
1178 |
||
1179 |
r = gTheFs.MkDirAll(gSessionPath); |
|
1180 |
test_Value(r, r == KErrNone || r == KErrAlreadyExists); |
|
1181 |
||
1182 |
#if defined(_DEBUG) || defined(_DEBUG_RELEASE) |
|
1183 |
test.Printf(_L("Disabling Lock Fail simulation ...\n")); |
|
1184 |
// turn OFF lock failure mode |
|
1185 |
TBool simulatelockFailureMode = EFalse; |
|
1186 |
r = controlIo(gTheFs, gDrive, KControlIoSimulateLockFailureMode, simulatelockFailureMode); |
|
1187 |
test_KErrNone(r); |
|
1188 |
#endif |
|
1189 |
||
1190 |
TBuf16<45> dir; |
|
1191 |
||
1192 |
// FileNames/File generation |
|
1193 |
test.Start(_L("Preparing the environmnet\n")); |
|
1194 |
FileNameGen(gFirstFile, 8, gNextFile++); |
|
1195 |
FileNameGen(gSecondFile, 8, gNextFile++); |
|
1196 |
dir = gSessionPath; |
|
1197 |
dir.Append(gFirstFile); |
|
1198 |
gFirstFile = dir; |
|
1199 |
dir = gSessionPath; |
|
1200 |
dir.Append(gSecondFile); |
|
1201 |
gSecondFile = dir; |
|
1202 |
||
1203 |
||
1204 |
TRAPD(res,gBuf = HBufC8::NewL(KBlockSize+1)); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1205 |
test_Value(res, res == KErrNone && gBuf != NULL); |
0 | 1206 |
|
1207 |
gBufWritePtr.Set(gBuf->Des()); |
|
1208 |
FillBuffer(gBufWritePtr, KBlockSize, 'A'); |
|
1209 |
||
1210 |
TRAPD(res2,gBufSec = HBufC8::NewL(KBlockSize+1)); |
|
1211 |
test(res2 == KErrNone && gBufSec != NULL); |
|
1212 |
gBufReadPtr.Set(gBufSec->Des()); |
|
1213 |
||
1214 |
||
1215 |
test.Printf(_L("\nSync: Write from 1 K to 254 K \n")); |
|
1216 |
||
1217 |
time = WriteTestFile(file1, gSecondFile, KMinSize, KBlockSize, EFileShareAny|EFileWrite|EFileWriteBuffered); |
|
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
1218 |
test.Printf(_L("Time to write %d K WITH caching: %d mS\n"), KMinSize, TF32TestTimer::TimeInMilliSeconds(time)); |
0 | 1219 |
test.Printf(_L("Remove MMC card,! and then press a key\n")); |
1220 |
test.Getch(); |
|
1221 |
||
1222 |
test.Printf(_L("Wait 3 seconds and insert MMC card! and then press a key\n")); |
|
1223 |
test.Getch(); |
|
1224 |
||
1225 |
rtime = ReadTestFile(file2, gSecondFile, KMinSize, KBlockSize, EFileShareAny|EFileRead|EFileReadBuffered); |
|
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
1226 |
test.Printf(_L("Time to read %d K from the cache: %d mS\n"), KMinSize, TF32TestTimer::TimeInMilliSeconds(rtime)); |
0 | 1227 |
|
1228 |
test.Printf(_L("Remove MMC card! and then press a key\n")); |
|
1229 |
test.Getch(); |
|
1230 |
||
1231 |
test.Printf(_L("Wait 3 seconds and insert MMC card! and then press a key\n")); |
|
1232 |
test.Getch(); |
|
1233 |
||
1234 |
||
1235 |
test.Printf(_L("\nSync: Write from 1 K to 255 K \n")); |
|
1236 |
||
1237 |
time = WriteTestFile(file1, gFirstFile, KMinSize + 1 , KBlockSize, EFileShareAny|EFileWrite|EFileWriteBuffered); |
|
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
1238 |
test.Printf(_L("Time to write %d K WITH caching: %d mS\n"), KMinSize + 1, TF32TestTimer::TimeInMilliSeconds(time)); |
0 | 1239 |
test.Printf(_L("Remove MMC card and delete the file //F32-TST//FFFFFFF0.TXT and then press a key\n")); |
1240 |
test.Getch(); |
|
1241 |
||
1242 |
test.Printf(_L("Wait 3 seconds and insert MMC card! and then press a key\n")); |
|
1243 |
test.Getch(); |
|
1244 |
||
1245 |
rtime = ReadTestFile(file2, gFirstFile, KMinSize + 1, KBlockSize, EFileShareAny|EFileRead|EFileReadBuffered); |
|
247
d8d70de2bd36
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
1246 |
test.Printf(_L("Time to read %d K from the cache: %d mS\n"), KMinSize + 1, TF32TestTimer::TimeInMilliSeconds(rtime)); |
0 | 1247 |
|
1248 |
test.Printf(_L("Remove MMC card! and then press a key\n")); |
|
1249 |
test.Getch(); |
|
1250 |
||
1251 |
test.Printf(_L("Wait 3 seconds and insert MMC card! and then press a key\n")); |
|
1252 |
test.Getch(); |
|
1253 |
||
1254 |
||
1255 |
file1.Close(); |
|
1256 |
file2.Close(); |
|
1257 |
delete gBuf; |
|
1258 |
delete gBufSec; |
|
1259 |
} |
|
1260 |
||
1261 |
||
1262 |
/** Main tests function |
|
1263 |
*/ |
|
1264 |
void CallTestsL() |
|
1265 |
{ |
|
1266 |
||
1267 |
#if defined(_DEBUG) || defined(_DEBUG_RELEASE) |
|
1268 |
test.Printf(_L("Disabling Lock Fail simulation ...\n")); |
|
1269 |
// turn OFF lock failure mode |
|
1270 |
TBool simulatelockFailureMode = EFalse; |
|
1271 |
TInt r = controlIo(gTheFs, gDrive, KControlIoSimulateLockFailureMode, simulatelockFailureMode); |
|
1272 |
test_KErrNone(r); |
|
1273 |
#endif |
|
1274 |
||
1275 |
TBuf16<45> dir; |
|
1276 |
||
1277 |
// FileNames/File generation |
|
1278 |
test.Start(_L("Preparing the environmnet\n")); |
|
1279 |
FileNameGen(gFirstFile, 8, gNextFile++); |
|
1280 |
FileNameGen(gSecondFile, 8, gNextFile++); |
|
1281 |
dir = gSessionPath; |
|
1282 |
dir.Append(gFirstFile); |
|
1283 |
gFirstFile = dir; |
|
1284 |
dir = gSessionPath; |
|
1285 |
dir.Append(gSecondFile); |
|
1286 |
gSecondFile = dir; |
|
1287 |
||
1288 |
||
1289 |
TRAPD(res,gBuf = HBufC8::NewL(KBlockSize+1)); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1290 |
test_Value(res, res == KErrNone && gBuf != NULL); |
0 | 1291 |
|
1292 |
gBufWritePtr.Set(gBuf->Des()); |
|
1293 |
FillBuffer(gBufWritePtr, KBlockSize, 'A'); |
|
1294 |
||
1295 |
TRAPD(res2,gBufSec = HBufC8::NewL(KBlockSize+1)); |
|
1296 |
test(res2 == KErrNone && gBufSec != NULL); |
|
1297 |
gBufReadPtr.Set(gBufSec->Des()); |
|
1298 |
||
1299 |
test.Next(_L("Boundary test")); |
|
1300 |
TestBoundaries(); |
|
1301 |
||
1302 |
test.Next(_L("Negative test\n")); |
|
1303 |
TestNegative(); |
|
1304 |
||
1305 |
test.Next(_L("Integrity test\n")); |
|
1306 |
TestIntegrity(); |
|
1307 |
||
1308 |
||
1309 |
test.Next(_L("Fill the cache, boundary testing\n")); |
|
1310 |
TestFillCache(); |
|
1311 |
||
1312 |
test.Next(_L("Fill the cache negative, boundary testing\n")); |
|
1313 |
TestFillCacheNegative(); |
|
1314 |
||
1315 |
test.End(); |
|
1316 |
delete gBuf; |
|
1317 |
delete gBufSec; |
|
1318 |
||
1319 |
#if defined(_DEBUG) || defined(_DEBUG_RELEASE) |
|
1320 |
// turn lock failure mode back ON (if enabled) |
|
1321 |
simulatelockFailureMode = ETrue; |
|
1322 |
r = controlIo(gTheFs, gDrive, KControlIoSimulateLockFailureMode, simulatelockFailureMode); |
|
1323 |
test_KErrNone(r); |
|
1324 |
#endif |
|
1325 |
||
1326 |
} |
|
1327 |
||
1328 |
/** Initialises semaphores and call the tests |
|
1329 |
*/ |
|
1330 |
void DoTests() |
|
1331 |
{ |
|
1332 |
TInt r = 0; |
|
1333 |
||
1334 |
r = gClient.CreateLocal(0); |
|
1335 |
test_KErrNone(r); |
|
1336 |
||
1337 |
r = gTheFs.SetSessionPath(gSessionPath); |
|
1338 |
test_KErrNone(r); |
|
1339 |
||
1340 |
r = gTheFs.MkDirAll(gSessionPath); |
|
1341 |
test_Value(r, r == KErrNone || r == KErrAlreadyExists); |
|
1342 |
gTheFs.ResourceCountMarkStart(); |
|
1343 |
||
1344 |
TRAP(r,CallTestsL()); |
|
1345 |
||
1346 |
test_KErrNone(r); |
|
1347 |
gTheFs.ResourceCountMarkEnd(); |
|
1348 |
} |
|
1349 |
||
1350 |
/** Determines the space that can be used for the files |
|
1351 |
||
1352 |
*/ |
|
1353 |
TBool CheckForDiskSize() |
|
1354 |
{ |
|
1355 |
TVolumeInfo volInfo; |
|
1356 |
TInt r = gTheFs.Volume(volInfo, gDrive); |
|
1357 |
test_KErrNone(r); |
|
259
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
247
diff
changeset
|
1358 |
gMediaSize = volInfo.iFree; |
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
247
diff
changeset
|
1359 |
test.Printf(_L("\nMedia free space: %d MB\n"), gMediaSize/KOneMeg); |
0 | 1360 |
return ETrue; |
1361 |
} |
|
1362 |
||
1363 |
/** Main function |
|
1364 |
||
1365 |
@return KErrNone if everything was ok, panics otherwise |
|
1366 |
*/ |
|
1367 |
TInt E32Main() |
|
1368 |
{ |
|
1369 |
RThread t; |
|
1370 |
gMainThreadId = t.Id(); |
|
1371 |
||
1372 |
CTrapCleanup* cleanup; |
|
1373 |
cleanup = CTrapCleanup::New(); |
|
1374 |
||
1375 |
__UHEAP_MARK; |
|
1376 |
test.Start(_L("Starting tests... T_WCACHE")); |
|
1377 |
parseCommandLine(); |
|
1378 |
||
1379 |
TInt r = gTheFs.Connect(); |
|
1380 |
test_KErrNone(r); |
|
1381 |
||
1382 |
TDriveInfo info; |
|
1383 |
TVolumeInfo volInfo; |
|
1384 |
r = gTheFs.Drive(info,gDrive); |
|
1385 |
test_KErrNone(r); |
|
1386 |
||
1387 |
if(info.iMediaAtt&KMediaAttVariableSize) |
|
1388 |
{ |
|
1389 |
test.Printf(_L("Tests skipped in RAM drive\n")); |
|
1390 |
goto out; |
|
1391 |
} |
|
1392 |
||
1393 |
r = gTheFs.Volume(volInfo, gDrive); |
|
1394 |
if (r == KErrNotReady) |
|
1395 |
{ |
|
1396 |
if (info.iType == EMediaNotPresent) |
|
1397 |
test.Printf(_L("%c: Medium not present - cannot perform test.\n"), (TUint)gDriveToTest); |
|
1398 |
else |
|
1399 |
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); |
|
1400 |
} |
|
1401 |
else if (r == KErrCorrupt) |
|
1402 |
{ |
|
1403 |
test.Printf(_L("%c: Media corruption; previous test may have aborted; else, check hardware\n"), (TUint)gDriveToTest); |
|
1404 |
} |
|
1405 |
test_KErrNone(r); |
|
1406 |
||
1407 |
if(!(volInfo.iFileCacheFlags & (EFileCacheReadEnabled | EFileCacheReadAheadEnabled))) |
|
1408 |
{ |
|
1409 |
test.Printf(_L("Skipping tests, Read caching not enabled in this drive\n")); |
|
1410 |
goto out; |
|
1411 |
} |
|
1412 |
||
1413 |
if (((volInfo.iDrive.iMediaAtt & KMediaAttFormattable))) |
|
1414 |
Formatting(gDrive,ESpecialFormat); |
|
1415 |
||
1416 |
if(!CheckForDiskSize()) |
|
1417 |
{ |
|
1418 |
test.Printf(_L("Skipping tests due to lack of space to perform them in this drive\n")); |
|
1419 |
} |
|
1420 |
else if(!gManual) |
|
1421 |
{ |
|
1422 |
DoTests(); |
|
1423 |
} |
|
1424 |
else |
|
1425 |
{ |
|
1426 |
TestRemoval(); |
|
1427 |
} |
|
1428 |
||
1429 |
out: |
|
1430 |
test.End(); |
|
1431 |
||
1432 |
gTheFs.Close(); |
|
1433 |
test.Close(); |
|
1434 |
||
1435 |
__UHEAP_MARKEND; |
|
1436 |
delete cleanup; |
|
1437 |
return(KErrNone); |
|
1438 |
} |
|
1439 |