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