0
|
1 |
// Copyright (c) 1995-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_filecache.cpp
|
|
15 |
//
|
|
16 |
//
|
|
17 |
#define __E32TEST_EXTENSION__
|
|
18 |
#include <f32file.h>
|
|
19 |
#include <e32test.h>
|
|
20 |
#include <e32svr.h>
|
|
21 |
#include <f32dbg.h>
|
|
22 |
#include "t_server.h"
|
|
23 |
#include <e32twin.h>
|
|
24 |
#include <e32rom.h>
|
131
|
25 |
#include <u32hal.h> //*test*
|
0
|
26 |
|
|
27 |
|
|
28 |
//----------------------------------------------------------------------------------------------
|
|
29 |
//! @SYMTestCaseID PBASE-T_FILECACHE-0189
|
|
30 |
//! @SYMTestType UT
|
|
31 |
//! @SYMPREQ PREQ914
|
|
32 |
//! @SYMTestCaseDesc Unit tests for fair scheduling, read caching and lazy writing
|
|
33 |
//! @SYMTestActions 0 setup the environment to execute the tests
|
|
34 |
//! 1 Reads a file with different blocksizes
|
|
35 |
//! 2 Write a file with different blocksizes
|
|
36 |
//! 3 Small reads while controlling the cache
|
|
37 |
//! 4 Read operations with and without read ahead
|
|
38 |
//! 5 Write operations with write buffer
|
|
39 |
//! @SYMTestExpectedResults finishes if the implementation of PREQ914 behaves as expected, panics otherwise
|
|
40 |
//! @SYMTestPriority High
|
|
41 |
//! @SYMTestStatus Critical
|
|
42 |
//----------------------------------------------------------------------------------------------
|
|
43 |
|
|
44 |
|
|
45 |
//#define SYMBIAN_TEST_EXTENDED_BUFFER_SIZES
|
|
46 |
|
|
47 |
|
|
48 |
GLDEF_D RTest test(_L("T_FILECACHE"));
|
|
49 |
|
|
50 |
GLDEF_D RFs TheFs;
|
|
51 |
GLDEF_D TChar gDriveToTest;
|
|
52 |
GLDEF_D TInt gDrive;
|
|
53 |
GLDEF_D TFileName gSessionPath;
|
|
54 |
|
|
55 |
GLDEF_D TVolumeInfo gVolInfo; // volume info for current drive
|
|
56 |
GLDEF_D TFileCacheFlags gDriveCacheFlags = TFileCacheFlags(0);
|
|
57 |
|
|
58 |
#if defined(_DEBUG) || defined(_DEBUG_RELEASE)
|
|
59 |
static TFileCacheConfig gFileCacheConfig;
|
|
60 |
static TBool gDisplayCacheFlags = EFalse;
|
|
61 |
static TBool gWriteCacheFlags = EFalse;
|
|
62 |
static TBool gRomPaged = EFalse;
|
|
63 |
#endif
|
|
64 |
static TBool gRunTests = ETrue;
|
|
65 |
static TBool gRunUnitTests = ETrue;
|
|
66 |
static TBool gRunPerformanceTests = EFalse;
|
|
67 |
static TBool gRunManualTests = EFalse;
|
|
68 |
|
|
69 |
|
|
70 |
LOCAL_D TInt KMaxFileSize = 768 * 1024;
|
|
71 |
|
|
72 |
// Chosing a file size of 128K ensures entire file will be cached
|
|
73 |
//LOCAL_D TInt KMaxFileSize = 128 * 1024;
|
|
74 |
|
|
75 |
LOCAL_D TBuf8<256*1024> DataBuf;
|
|
76 |
|
|
77 |
const TInt KBufSize = 513 * 1024 - 16;
|
|
78 |
HBufC8* gBuf = NULL;
|
|
79 |
|
|
80 |
|
|
81 |
LOCAL_D TPtr8 gBufPtr(NULL, 0);
|
|
82 |
|
|
83 |
const TReal KOneK = 1024;
|
|
84 |
const TReal KOneMeg = 1024 * KOneK;
|
|
85 |
|
|
86 |
const TInt KSegmentSize = 4096;
|
|
87 |
const TInt KSegmentSizeMask = (4096-1);
|
|
88 |
|
|
89 |
GLDEF_D template <class C>
|
|
90 |
GLDEF_C TInt controlIo(RFs &fs, TInt drv, TInt fkn, C &c)
|
|
91 |
{
|
|
92 |
TPtr8 ptrC((TUint8 *)&c, sizeof(C), sizeof(C));
|
|
93 |
|
|
94 |
TInt r = fs.ControlIo(drv, fkn, ptrC);
|
|
95 |
|
|
96 |
return r;
|
|
97 |
}
|
|
98 |
|
|
99 |
#if defined(_DEBUG) || defined(_DEBUG_RELEASE)
|
|
100 |
void PrintFileCacheStats(TFileCacheStats& fileCacheStats, TBool aDisplay = ETrue)
|
|
101 |
{
|
|
102 |
TInt r = controlIo(TheFs,gDrive, KControlIoFileCacheStats, fileCacheStats);
|
|
103 |
test_KErrNone(r);
|
|
104 |
if (!aDisplay)
|
|
105 |
return;
|
|
106 |
test.Printf(_L("File cache: Cachelines (free %d, used %d), Segments(allocated %d locked %d). Closed files(%d) Holes %d Failures (commit %d Lock %d)\n"),
|
|
107 |
fileCacheStats.iFreeCount, fileCacheStats.iUsedCount, fileCacheStats.iAllocatedSegmentCount,fileCacheStats.iLockedSegmentCount,fileCacheStats.iFilesOnClosedQueue, fileCacheStats.iHoleCount, fileCacheStats.iCommitFailureCount, fileCacheStats.iLockFailureCount);
|
|
108 |
test.Printf(_L("File cache: iUncachedPacketsRead %d iUncachedBytesRead %d iUncachedPacketsWritten %d iUncachedBytesWritten %d\n"),
|
|
109 |
fileCacheStats.iUncachedPacketsRead,
|
|
110 |
fileCacheStats.iUncachedBytesRead,
|
|
111 |
fileCacheStats.iUncachedPacketsWritten,
|
|
112 |
fileCacheStats.iUncachedBytesWritten);
|
|
113 |
}
|
|
114 |
|
|
115 |
void PrintFileCacheConfig(TFileCacheConfig& aFileCacheConfig, TBool aDisplay = ETrue)
|
|
116 |
{
|
|
117 |
TInt r = controlIo(TheFs,gDrive, KControlIoFileCacheConfig, aFileCacheConfig);
|
131
|
118 |
test_KErrNone(r);
|
0
|
119 |
if (!aDisplay)
|
|
120 |
return;
|
|
121 |
|
|
122 |
test.Printf(_L("File cache:\nDrive %c\nFlags %08X\nFileCacheReadAsync %d\nFairSchedulingLen %d\nCacheSize %d\nMaxReadAheadLen %d\nClosedFileKeepAliveTime %d\nDirtyDataFlushTime %d"),
|
|
123 |
aFileCacheConfig.iDrive + 'A',
|
|
124 |
aFileCacheConfig.iFlags,
|
|
125 |
aFileCacheConfig.iFileCacheReadAsync,
|
|
126 |
aFileCacheConfig.iFairSchedulingLen,
|
|
127 |
aFileCacheConfig.iCacheSize,
|
|
128 |
aFileCacheConfig.iMaxReadAheadLen,
|
|
129 |
aFileCacheConfig.iClosedFileKeepAliveTime,
|
|
130 |
aFileCacheConfig.iDirtyDataFlushTime);
|
|
131 |
|
|
132 |
}
|
|
133 |
|
|
134 |
void TestDirtyDataWrittenToDisk(TFileCacheStats& fileCacheStats)
|
|
135 |
{
|
|
136 |
test.Next(_L("test dirty data has been written to disk"));
|
|
137 |
// wait a maximum of double KDefaultDirtyDataFlushTime for dirty data to be flushed
|
|
138 |
const TInt KWaitTime = 250; // 250 milisecs
|
|
139 |
for (TInt n=0; n<(gFileCacheConfig.iDirtyDataFlushTime/1000)<<1 ; n+= KWaitTime)
|
|
140 |
{
|
|
141 |
test.Printf(_L("After %d milisecs : "), n );
|
|
142 |
PrintFileCacheStats(fileCacheStats);
|
|
143 |
User::After(KWaitTime * 1000); // wait 100 ms
|
|
144 |
if (fileCacheStats.iLockedSegmentCount == 0)
|
|
145 |
break;
|
|
146 |
}
|
|
147 |
PrintFileCacheStats(fileCacheStats);
|
|
148 |
test(fileCacheStats.iLockedSegmentCount == 0);
|
|
149 |
}
|
|
150 |
#endif
|
|
151 |
|
|
152 |
void TestsInit()
|
|
153 |
{
|
|
154 |
gBuf = HBufC8::NewL(KBufSize);
|
|
155 |
test(gBuf!=NULL);
|
|
156 |
gBufPtr.Set(gBuf->Des());
|
|
157 |
}
|
|
158 |
void TestsEnd()
|
|
159 |
{
|
|
160 |
delete gBuf;
|
|
161 |
gBuf = NULL;
|
|
162 |
}
|
|
163 |
|
|
164 |
LOCAL_C void SetSessionPath(TInt aDrive)
|
|
165 |
{
|
|
166 |
gSessionPath=_L("?:\\F32-TST\\");
|
|
167 |
TChar driveLetter;
|
|
168 |
TInt r=TheFs.DriveToChar(aDrive,driveLetter);
|
|
169 |
test_KErrNone(r);
|
|
170 |
gSessionPath[0]=(TText)driveLetter;
|
|
171 |
r=TheFs.SetSessionPath(gSessionPath);
|
|
172 |
test_KErrNone(r);
|
|
173 |
}
|
|
174 |
|
|
175 |
LOCAL_C void PrintFileMode(TUint aFileMode)
|
|
176 |
{
|
|
177 |
TBuf<80> buf;
|
|
178 |
|
|
179 |
buf.Format(_L("FileMode = %08X"), aFileMode);
|
|
180 |
|
|
181 |
if (aFileMode & EFileWriteBuffered)
|
|
182 |
buf.Append(_L(", EFileWriteBuffered"));
|
|
183 |
|
|
184 |
if (aFileMode & EFileWriteDirectIO)
|
|
185 |
buf.Append(_L(", EFileWriteDirectIO"));
|
|
186 |
|
|
187 |
if (aFileMode & EFileReadBuffered)
|
|
188 |
buf.Append(_L(", EFileReadBuffered"));
|
|
189 |
|
|
190 |
if (aFileMode & EFileReadDirectIO)
|
|
191 |
buf.Append(_L(", EFileReadDirectIO"));
|
|
192 |
|
|
193 |
if (aFileMode & EFileReadAheadOn)
|
|
194 |
buf.Append(_L(", EFileReadAheadOn"));
|
|
195 |
|
|
196 |
if (aFileMode & EFileReadAheadOff)
|
|
197 |
buf.Append(_L(", EFileReadAheadOff"));
|
|
198 |
|
|
199 |
buf.Append(_L("\n"));
|
|
200 |
test.Printf(buf);
|
|
201 |
}
|
|
202 |
|
|
203 |
void FillBuffer(TDes8& aBuffer, TInt aLength)
|
|
204 |
{
|
|
205 |
test (aBuffer.MaxLength() >= aLength);
|
|
206 |
for(TInt i=0; i<aLength; i+=2)
|
|
207 |
{
|
|
208 |
aBuffer[i]=(TUint8) (i >> 8);
|
|
209 |
aBuffer[i+1]=(TUint8) i;
|
|
210 |
}
|
|
211 |
}
|
|
212 |
|
|
213 |
void TestBufferFail(TDes8& aBuffer, TInt aPos, TInt aLength)
|
|
214 |
{
|
|
215 |
test.Printf(_L("TestBuffer failed at pos %d len %d\n"), aPos, aLength);
|
|
216 |
|
|
217 |
#define PRINTCH(ch) ((ch >= 0x20 && ch < 0x7F)?ch:' ')
|
|
218 |
TInt startPos = Max(0, aPos - 64);
|
|
219 |
TInt endPos = startPos + 64;
|
|
220 |
|
|
221 |
for(TInt n=startPos; n<=endPos; n+=16)
|
|
222 |
RDebug::Print(_L("%08X: %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X [%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c]"),
|
|
223 |
//&aBuffer[aPos+n],
|
|
224 |
n,
|
|
225 |
aBuffer[n+0], aBuffer[n+1], aBuffer[n+2], aBuffer[n+3], aBuffer[n+4], aBuffer[n+5], aBuffer[n+6], aBuffer[n+7], aBuffer[n+8], aBuffer[n+9], aBuffer[n+10], aBuffer[n+11], aBuffer[n+12], aBuffer[n+13], aBuffer[n+14], aBuffer[n+15],
|
|
226 |
PRINTCH(aBuffer[n+0]), PRINTCH(aBuffer[n+1]), PRINTCH(aBuffer[n+2]), PRINTCH(aBuffer[n+3]), PRINTCH(aBuffer[n+4]), PRINTCH(aBuffer[n+5]), PRINTCH(aBuffer[n+6]), PRINTCH(aBuffer[n+7]), PRINTCH(aBuffer[n+8]), PRINTCH(aBuffer[n+9]), PRINTCH(aBuffer[n+10]), PRINTCH(aBuffer[n+11]), PRINTCH(aBuffer[n+12]), PRINTCH(aBuffer[n+13]), PRINTCH(aBuffer[n+14]), PRINTCH(aBuffer[n+15]));
|
|
227 |
|
|
228 |
#if defined(_DEBUG) || defined(_DEBUG_RELEASE)
|
|
229 |
TInt x;
|
|
230 |
TInt r = controlIo(TheFs,gDrive, KControlIoFileCacheDump, x);
|
|
231 |
test_KErrNone(r);
|
|
232 |
#endif
|
|
233 |
test (0);
|
|
234 |
}
|
|
235 |
|
|
236 |
void TestBuffer(TDes8& aBuffer, TInt aPos, TInt aLength)
|
|
237 |
{
|
|
238 |
TInt pos = aPos;
|
|
239 |
for(TInt i=0; i<aLength; i++, pos++)
|
|
240 |
{
|
|
241 |
if (pos & 1)
|
|
242 |
{
|
|
243 |
if (aBuffer[pos] != (TUint8) pos-1)
|
|
244 |
TestBufferFail(aBuffer, pos, aLength);
|
|
245 |
}
|
|
246 |
else
|
|
247 |
{
|
|
248 |
if (aBuffer[pos] != (TUint8) (pos >> 8))
|
|
249 |
TestBufferFail(aBuffer, pos, aLength);
|
|
250 |
}
|
|
251 |
}
|
|
252 |
}
|
|
253 |
|
131
|
254 |
//*test**************************************************************************
|
|
255 |
TInt FreeRam()
|
|
256 |
{
|
|
257 |
// wait for any async cleanup in the supervisor to finish first...
|
|
258 |
UserSvr::HalFunction(EHalGroupKernel, EKernelHalSupervisorBarrier, 0, 0);
|
|
259 |
|
|
260 |
TMemoryInfoV1Buf meminfo;
|
|
261 |
UserHal::MemoryInfo(meminfo);
|
|
262 |
return meminfo().iFreeRamInBytes;
|
|
263 |
}
|
|
264 |
//*test**************************************************************************
|
|
265 |
|
0
|
266 |
|
|
267 |
LOCAL_C void UnitTests()
|
|
268 |
//
|
|
269 |
// Test read file handling.
|
|
270 |
//
|
|
271 |
{
|
|
272 |
|
|
273 |
test.Start(_L("File cache read and write unit tests"));
|
|
274 |
|
|
275 |
//TheFs.SetDebugRegister(KCACHE);
|
|
276 |
|
|
277 |
RFile f;
|
|
278 |
TInt r;
|
|
279 |
TInt pos;
|
|
280 |
TInt len;
|
|
281 |
TInt testNum;
|
|
282 |
|
|
283 |
#if defined(_DEBUG) || defined(_DEBUG_RELEASE)
|
|
284 |
TBool simulatelockFailureMode;
|
|
285 |
TFileCacheStats fileCacheStats;
|
|
286 |
r = controlIo(TheFs, gDrive, KControlIoFileCacheStats, fileCacheStats);
|
131
|
287 |
test_KErrNone(r);
|
0
|
288 |
test.Printf(_L("Number of files on closed queue=%d\n"),fileCacheStats.iFilesOnClosedQueue);
|
|
289 |
test(fileCacheStats.iFilesOnClosedQueue == 0);
|
|
290 |
#endif
|
|
291 |
|
|
292 |
#if defined(_DEBUG) || defined(_DEBUG_RELEASE)
|
|
293 |
// turn OFF lock failure mode
|
|
294 |
simulatelockFailureMode = EFalse;
|
|
295 |
r = controlIo(TheFs, gDrive, KControlIoSimulateLockFailureMode, simulatelockFailureMode);
|
131
|
296 |
test_KErrNone(r);
|
0
|
297 |
#endif
|
|
298 |
|
|
299 |
TFileName testFile = _L("TEST.BIN");
|
|
300 |
|
|
301 |
//**********************************
|
|
302 |
// Test Read-Modify-Write
|
|
303 |
//**********************************
|
|
304 |
test.Next(_L("Test read-modify-write"));
|
|
305 |
gBufPtr.SetLength(KBufSize);
|
|
306 |
FillBuffer(gBufPtr, KBufSize);
|
|
307 |
TestBuffer(gBufPtr, 0,KBufSize);
|
|
308 |
TPtrC8 writePtr;
|
|
309 |
TPtr8 readPtr(gBuf->Des());
|
|
310 |
#if defined(_DEBUG) || defined(_DEBUG_RELEASE)
|
|
311 |
TInt uncachedBytesRead;
|
|
312 |
TInt uncachedPacketsRead;
|
|
313 |
#endif
|
|
314 |
|
131
|
315 |
//*test**************************************************************************
|
|
316 |
{
|
|
317 |
TInt fileSize = 0;
|
|
318 |
|
|
319 |
const TInt KWriteLen = 128*1024;
|
|
320 |
test.Next(_L("Test appending to a file with low memory"));
|
|
321 |
gBufPtr.SetLength(KBufSize);
|
|
322 |
|
|
323 |
r = f.Replace(TheFs, testFile, EFileWrite | EFileWriteBuffered);
|
|
324 |
test_KErrNone(r);
|
|
325 |
|
|
326 |
pos = 0;
|
|
327 |
|
|
328 |
writePtr.Set(gBufPtr.MidTPtr(pos, KWriteLen));
|
|
329 |
|
|
330 |
r = f.Write(pos, writePtr);
|
|
331 |
test_KErrNone(r);
|
|
332 |
pos+= writePtr.Length();
|
|
333 |
|
|
334 |
r = f.Size(fileSize);
|
|
335 |
test_KErrNone(r);
|
|
336 |
test_Equal(fileSize,pos);
|
|
337 |
|
|
338 |
|
|
339 |
|
|
340 |
TInt freeRam = FreeRam();
|
|
341 |
test.Printf(_L("FreeRam = %d"), freeRam);
|
|
342 |
const TInt KPageSize=4096;
|
|
343 |
|
|
344 |
RChunk chunk;
|
|
345 |
TChunkCreateInfo chunkInfo;
|
|
346 |
chunkInfo.SetDisconnected(0, 0, freeRam);
|
|
347 |
chunkInfo.SetPaging(TChunkCreateInfo::EUnpaged);
|
|
348 |
test_KErrNone(chunk.Create(chunkInfo));
|
|
349 |
|
|
350 |
TUint commitEnd = 0;
|
|
351 |
TInt r;
|
|
352 |
while(KErrNone == (r = chunk.Commit(commitEnd,KPageSize)))
|
|
353 |
{
|
|
354 |
commitEnd += KPageSize;
|
|
355 |
}
|
|
356 |
test_Equal(KErrNoMemory, r);
|
|
357 |
|
|
358 |
|
|
359 |
|
|
360 |
pos-= KSegmentSize;
|
|
361 |
writePtr.Set(gBufPtr.MidTPtr(pos, KWriteLen));
|
|
362 |
|
|
363 |
r = f.Write(pos, writePtr);
|
|
364 |
test_KErrNone(r);
|
|
365 |
pos+= writePtr.Length();
|
|
366 |
|
|
367 |
r = f.Size(fileSize);
|
|
368 |
test_KErrNone(r);
|
|
369 |
test_Equal(fileSize,pos);
|
|
370 |
|
|
371 |
f.Close();
|
|
372 |
|
|
373 |
chunk.Close();
|
|
374 |
}
|
|
375 |
//*test**************************************************************************
|
|
376 |
|
0
|
377 |
// create an empty file, so that any writes overlapping segemt boundaries
|
|
378 |
// need a read first
|
|
379 |
// create a test file using directIO and then re-open it in buffered mode,
|
|
380 |
// so that any writes overlapping segemt boundaries need a read first
|
|
381 |
r = f.Replace(TheFs, testFile, EFileWrite | EFileWriteDirectIO);
|
|
382 |
test_KErrNone(r);
|
|
383 |
writePtr.Set(gBuf->Des());
|
|
384 |
r = f.Write(0, writePtr);
|
|
385 |
test_KErrNone(r);
|
|
386 |
f.Close();
|
|
387 |
r = f.Open(TheFs, testFile, EFileReadBuffered | EFileWrite | EFileWriteBuffered);
|
|
388 |
test_KErrNone(r);
|
|
389 |
|
|
390 |
TInt cacheLineLen = 128*1024;
|
|
391 |
|
|
392 |
#if defined(_DEBUG) || defined(_DEBUG_RELEASE)
|
|
393 |
PrintFileCacheStats(fileCacheStats);
|
|
394 |
uncachedBytesRead = fileCacheStats.iUncachedBytesRead;
|
|
395 |
uncachedPacketsRead = fileCacheStats.iUncachedPacketsRead;
|
|
396 |
#endif
|
|
397 |
|
|
398 |
// write 1 partial segment at offset 0 to 7 in segment
|
|
399 |
test.Next(_L("Test read-modify-write #1"));
|
|
400 |
pos = cacheLineLen*0 + KSegmentSize*2 + 0;
|
|
401 |
len = 7;
|
|
402 |
writePtr.Set(gBuf->Mid(pos, len));
|
|
403 |
r = f.Write(pos, writePtr, len);
|
|
404 |
test_KErrNone(r);
|
|
405 |
// read back & verify whole segment
|
|
406 |
pos&= ~KSegmentSizeMask; len = (len + KSegmentSize-1) & ~KSegmentSizeMask;
|
|
407 |
readPtr.Set(gBufPtr.MidTPtr(pos, len));
|
|
408 |
readPtr.SetLength(len);
|
|
409 |
readPtr.FillZ();
|
|
410 |
r = f.Read(pos, readPtr, len);
|
|
411 |
test_KErrNone(r);
|
|
412 |
TestBuffer(gBufPtr, pos, len);
|
|
413 |
test_KErrNone(r);
|
|
414 |
#if defined(_DEBUG) || defined(_DEBUG_RELEASE)
|
|
415 |
PrintFileCacheStats(fileCacheStats);
|
|
416 |
test (fileCacheStats.iUncachedBytesRead - uncachedBytesRead == KSegmentSize);
|
|
417 |
test (fileCacheStats.iUncachedPacketsRead - uncachedPacketsRead == 1);
|
|
418 |
uncachedBytesRead = fileCacheStats.iUncachedBytesRead;
|
|
419 |
uncachedPacketsRead = fileCacheStats.iUncachedPacketsRead;
|
|
420 |
#endif
|
|
421 |
|
|
422 |
// write 1 partial segment at offset 7 to 4096 in segment
|
|
423 |
test.Next(_L("Test read-modify-write #2"));
|
|
424 |
pos = cacheLineLen*0 + KSegmentSize*3 + 7;
|
|
425 |
len = KSegmentSize - 7;
|
|
426 |
writePtr.Set(gBuf->Mid(pos, len));
|
|
427 |
r = f.Write(pos, writePtr, len);
|
|
428 |
test_KErrNone(r);
|
|
429 |
// read back & verify whole segment
|
|
430 |
pos&= ~KSegmentSizeMask; len = (len + KSegmentSize-1) & ~KSegmentSizeMask;
|
|
431 |
readPtr.Set(gBufPtr.MidTPtr(pos, len));
|
|
432 |
readPtr.SetLength(len);
|
|
433 |
readPtr.FillZ();
|
|
434 |
r = f.Read(pos, readPtr, len);
|
|
435 |
test_KErrNone(r);
|
|
436 |
TestBuffer(gBufPtr, pos, len);
|
|
437 |
test_KErrNone(r);
|
|
438 |
#if defined(_DEBUG) || defined(_DEBUG_RELEASE)
|
|
439 |
PrintFileCacheStats(fileCacheStats);
|
|
440 |
test (fileCacheStats.iUncachedBytesRead - uncachedBytesRead == KSegmentSize);
|
|
441 |
test (fileCacheStats.iUncachedPacketsRead - uncachedPacketsRead == 1);
|
|
442 |
uncachedBytesRead = fileCacheStats.iUncachedBytesRead;
|
|
443 |
uncachedPacketsRead = fileCacheStats.iUncachedPacketsRead;
|
|
444 |
#endif
|
|
445 |
|
|
446 |
// write 1 partial segment at offset 7 to 37 in segment
|
|
447 |
test.Next(_L("Test read-modify-write #3"));
|
|
448 |
pos = cacheLineLen*0 + KSegmentSize*4 + 7;
|
|
449 |
len = 30;
|
|
450 |
writePtr.Set(gBuf->Mid(pos, len));
|
|
451 |
r = f.Write(pos, writePtr, len);
|
|
452 |
test_KErrNone(r);
|
|
453 |
// read back & verify whole segment
|
|
454 |
pos&= ~KSegmentSizeMask; len = (len + KSegmentSize-1) & ~KSegmentSizeMask;
|
|
455 |
readPtr.Set(gBufPtr.MidTPtr(pos, len));
|
|
456 |
readPtr.SetLength(len);
|
|
457 |
readPtr.FillZ();
|
|
458 |
r = f.Read(pos, readPtr, len);
|
|
459 |
test_KErrNone(r);
|
|
460 |
TestBuffer(gBufPtr, pos, len);
|
|
461 |
test_KErrNone(r);
|
|
462 |
#if defined(_DEBUG) || defined(_DEBUG_RELEASE)
|
|
463 |
PrintFileCacheStats(fileCacheStats);
|
|
464 |
test (fileCacheStats.iUncachedBytesRead - uncachedBytesRead == KSegmentSize);
|
|
465 |
test (fileCacheStats.iUncachedPacketsRead - uncachedPacketsRead == 1);
|
|
466 |
uncachedBytesRead = fileCacheStats.iUncachedBytesRead;
|
|
467 |
uncachedPacketsRead = fileCacheStats.iUncachedPacketsRead;
|
|
468 |
#endif
|
|
469 |
|
|
470 |
// write 2 segments, first and last both partial
|
|
471 |
test.Next(_L("Test read-modify-write #4"));
|
|
472 |
pos = cacheLineLen*1 + KSegmentSize*2 + 3;
|
|
473 |
len = KSegmentSize * 1;
|
|
474 |
writePtr.Set(gBuf->Mid(pos, len));
|
|
475 |
r = f.Write(pos, writePtr, len);
|
|
476 |
test_KErrNone(r);
|
|
477 |
// read back & verify whole segment
|
|
478 |
pos&= ~KSegmentSizeMask; len = (len + KSegmentSize-1) & ~KSegmentSizeMask;
|
|
479 |
readPtr.Set(gBufPtr.MidTPtr(pos, len));
|
|
480 |
readPtr.SetLength(len);
|
|
481 |
readPtr.FillZ();
|
|
482 |
r = f.Read(pos, readPtr, len);
|
|
483 |
test_KErrNone(r);
|
|
484 |
TestBuffer(gBufPtr, pos, len);
|
|
485 |
test_KErrNone(r);
|
|
486 |
#if defined(_DEBUG) || defined(_DEBUG_RELEASE)
|
|
487 |
PrintFileCacheStats(fileCacheStats);
|
|
488 |
test (fileCacheStats.iUncachedBytesRead - uncachedBytesRead == KSegmentSize*2);
|
|
489 |
// should read both segments in one read as they are contiguous
|
|
490 |
test (fileCacheStats.iUncachedPacketsRead - uncachedPacketsRead == 1);
|
|
491 |
uncachedBytesRead = fileCacheStats.iUncachedBytesRead;
|
|
492 |
uncachedPacketsRead = fileCacheStats.iUncachedPacketsRead;
|
|
493 |
#endif
|
|
494 |
|
|
495 |
// write 3 segments, first and last both partial
|
|
496 |
test.Next(_L("Test read-modify-write #5"));
|
|
497 |
pos = cacheLineLen*2 + KSegmentSize*2 + 7;
|
|
498 |
len = KSegmentSize * 2;
|
|
499 |
writePtr.Set(gBuf->Mid(pos, len));
|
|
500 |
r = f.Write(pos, writePtr, len);
|
|
501 |
test_KErrNone(r);
|
|
502 |
// read back & verify whole segment
|
|
503 |
pos&= ~KSegmentSizeMask; len = (len + KSegmentSize-1) & ~KSegmentSizeMask;
|
|
504 |
readPtr.Set(gBufPtr.MidTPtr(pos, len));
|
|
505 |
readPtr.SetLength(len);
|
|
506 |
readPtr.FillZ();
|
|
507 |
r = f.Read(pos, readPtr, len);
|
|
508 |
test_KErrNone(r);
|
|
509 |
TestBuffer(gBufPtr, pos, len);
|
|
510 |
test_KErrNone(r);
|
|
511 |
#if defined(_DEBUG) || defined(_DEBUG_RELEASE)
|
|
512 |
PrintFileCacheStats(fileCacheStats);
|
|
513 |
test (fileCacheStats.iUncachedBytesRead - uncachedBytesRead == KSegmentSize*2);
|
|
514 |
test (fileCacheStats.iUncachedPacketsRead - uncachedPacketsRead == 2);
|
|
515 |
uncachedBytesRead = fileCacheStats.iUncachedBytesRead;
|
|
516 |
uncachedPacketsRead = fileCacheStats.iUncachedPacketsRead;
|
|
517 |
#endif
|
|
518 |
|
|
519 |
f.Close();
|
|
520 |
|
|
521 |
//**************************************************************
|
|
522 |
// Test dirty data NOT written to disk if continuously writing to a file which fits in tke cache
|
|
523 |
//**************************************************************
|
|
524 |
#if defined(_DEBUG) || defined(_DEBUG_RELEASE)
|
|
525 |
test.Printf(_L("Test dirty data NOT written to disk if continuously writing to a file which fits in tke cache...\n"));
|
|
526 |
|
|
527 |
// flush closed files queue to empty cache
|
|
528 |
test.Printf(_L("Flushing close queue to empty cache...\n"));
|
|
529 |
r = TheFs.ControlIo(gDrive, KControlIoFlushClosedFiles);
|
|
530 |
test_KErrNone(r);
|
|
531 |
|
|
532 |
r = f.Replace(TheFs, testFile, EFileReadBuffered | EFileWrite | EFileWriteBuffered);
|
|
533 |
test_KErrNone(r);
|
|
534 |
|
|
535 |
RTimer timer;
|
|
536 |
timer.CreateLocal();
|
|
537 |
TRequestStatus reqStat;
|
|
538 |
timer.After(reqStat,gFileCacheConfig.iClosedFileKeepAliveTime*3); // write 3 times the flush timer
|
|
539 |
|
|
540 |
pos = 0;
|
|
541 |
TInt bufLen = 7;
|
|
542 |
TInt maxLockedSegmentCount = 0;
|
|
543 |
while (reqStat == KRequestPending)
|
|
544 |
{
|
|
545 |
bufLen = (bufLen + 1023) & 0x3FFF;
|
|
546 |
len = Min(bufLen, KBufSize - pos);
|
|
547 |
len = Min(len, gFileCacheConfig.iCacheSize-pos);
|
|
548 |
TPtrC8 writePtr = gBuf->Mid(pos, len);
|
|
549 |
r = f.Write(pos, writePtr, len);
|
|
550 |
test_KErrNone(r);
|
|
551 |
pos+= len;
|
|
552 |
TInt r = controlIo(TheFs,gDrive, KControlIoFileCacheStats, fileCacheStats);
|
|
553 |
test_KErrNone(r);
|
|
554 |
// test the locked (i.e. dirty) count always goes up & never down (down would indicate a flush)
|
|
555 |
if (fileCacheStats.iLockedSegmentCount != maxLockedSegmentCount)
|
|
556 |
test.Printf(_L("iLockedSegmentCount %d...\n"), fileCacheStats.iLockedSegmentCount);
|
|
557 |
|
|
558 |
test(fileCacheStats.iLockedSegmentCount >= maxLockedSegmentCount);
|
|
559 |
maxLockedSegmentCount = Max(maxLockedSegmentCount, fileCacheStats.iLockedSegmentCount);
|
|
560 |
// wrap to start of file
|
|
561 |
if (pos >= gFileCacheConfig.iCacheSize)
|
|
562 |
pos = 0;
|
|
563 |
}
|
|
564 |
timer.Close();
|
|
565 |
|
|
566 |
test(fileCacheStats.iLockedSegmentCount > 0);
|
|
567 |
|
|
568 |
if (gDriveCacheFlags & (EFileCacheWriteEnabled | EFileCacheWriteOn))
|
|
569 |
TestDirtyDataWrittenToDisk(fileCacheStats);
|
|
570 |
f.Close();
|
|
571 |
#endif
|
|
572 |
|
|
573 |
|
|
574 |
//**************************************************************
|
|
575 |
// Test dirty data written to disk
|
|
576 |
//**************************************************************
|
|
577 |
enum {ETestDataWrittenAfterTimeout, ETestDataWrittenAfterFileClose, ETestDataWrittenAfterSessionClose, ETestEnd};
|
|
578 |
#if defined(_DEBUG) || defined(_DEBUG_RELEASE)
|
|
579 |
for (testNum = 0; testNum < ETestEnd; testNum++)
|
|
580 |
#else
|
|
581 |
for (testNum = 0; testNum < 1; testNum++)
|
|
582 |
#endif
|
|
583 |
{
|
|
584 |
switch(testNum)
|
|
585 |
{
|
|
586 |
case ETestDataWrittenAfterTimeout : test.Next(_L("ETestDataWrittenAfterTimeout")); break;
|
|
587 |
case ETestDataWrittenAfterFileClose : test.Next(_L("ETestDataWrittenAfterFileClose")); break;
|
|
588 |
case ETestDataWrittenAfterSessionClose : test.Next(_L("ETestDataWrittenAfterSessionClose")); break;
|
|
589 |
};
|
|
590 |
|
|
591 |
#if defined(_DEBUG) || defined(_DEBUG_RELEASE)
|
|
592 |
// flush closed files queue to empty cache
|
|
593 |
test.Printf(_L("Flushing close queue to empty cache...\n"));
|
|
594 |
r = TheFs.ControlIo(gDrive, KControlIoFlushClosedFiles);
|
|
595 |
test_KErrNone(r);
|
|
596 |
#endif
|
|
597 |
|
|
598 |
r = f.Replace(TheFs, testFile, EFileReadBuffered | EFileWrite | EFileWriteBuffered);
|
|
599 |
test_KErrNone(r);
|
|
600 |
|
|
601 |
|
|
602 |
gBufPtr.SetLength(KBufSize);
|
|
603 |
|
|
604 |
test.Printf(_L("writing file in small blocks to test write caching...\n"));
|
|
605 |
|
|
606 |
FillBuffer(gBufPtr, KBufSize);
|
|
607 |
TestBuffer(gBufPtr, 0,KBufSize);
|
|
608 |
|
|
609 |
pos = 0;
|
|
610 |
TInt bufLen = 7;
|
|
611 |
#if defined(_DEBUG) || defined(_DEBUG_RELEASE)
|
|
612 |
TInt maxLockedSegmentCount = 0;
|
|
613 |
TInt maxUsedCount = 0;
|
|
614 |
#endif
|
|
615 |
while (pos < KBufSize)
|
|
616 |
{
|
|
617 |
bufLen = (bufLen + 1023) & 0x3FFF;
|
|
618 |
len = Min(bufLen, KBufSize - pos);
|
|
619 |
//RDebug::Print(_L("write len %d"), len);
|
|
620 |
TPtrC8 writePtr = gBuf->Mid(pos, len);
|
|
621 |
r = f.Write(pos, writePtr, len);
|
|
622 |
test_KErrNone(r);
|
|
623 |
pos+= len;
|
|
624 |
#if defined(_DEBUG) || defined(_DEBUG_RELEASE)
|
|
625 |
// PrintFileCacheStats(fileCacheStats);
|
|
626 |
TInt r = controlIo(TheFs,gDrive, KControlIoFileCacheStats, fileCacheStats);
|
|
627 |
test_KErrNone(r);
|
|
628 |
maxLockedSegmentCount = Max(maxLockedSegmentCount, fileCacheStats.iLockedSegmentCount);
|
|
629 |
maxUsedCount = Max(maxUsedCount, fileCacheStats.iUsedCount);
|
|
630 |
#endif
|
|
631 |
}
|
|
632 |
#if defined(_DEBUG) || defined(_DEBUG_RELEASE)
|
|
633 |
test.Next(_L("Test maxiimum locked page and cacheline count is reasonable"));
|
|
634 |
test.Printf(_L("maxLockedSegmentCount %d maxUsedCount %d"), maxLockedSegmentCount, maxUsedCount);
|
|
635 |
test (maxLockedSegmentCount > 0 && maxLockedSegmentCount <= (gFileCacheConfig.iCacheSize * 2) / KSegmentSize );
|
|
636 |
test (maxUsedCount > 0 && maxUsedCount <= 5);
|
|
637 |
#endif
|
|
638 |
|
|
639 |
|
|
640 |
|
|
641 |
if (testNum == ETestDataWrittenAfterTimeout)
|
|
642 |
{
|
|
643 |
#if defined(_DEBUG) || defined(_DEBUG_RELEASE)
|
|
644 |
if (gDriveCacheFlags & (EFileCacheWriteEnabled | EFileCacheWriteOn))
|
|
645 |
TestDirtyDataWrittenToDisk(fileCacheStats);
|
|
646 |
#endif
|
|
647 |
f.Close();
|
|
648 |
}
|
|
649 |
|
|
650 |
if (testNum == ETestDataWrittenAfterFileClose)
|
|
651 |
{
|
|
652 |
f.Close();
|
|
653 |
#if defined(_DEBUG) || defined(_DEBUG_RELEASE)
|
|
654 |
test.Next(_L("test dirty data has been written to disk after file close"));
|
|
655 |
PrintFileCacheStats(fileCacheStats);
|
|
656 |
test(fileCacheStats.iLockedSegmentCount == 0);
|
|
657 |
#endif
|
|
658 |
}
|
|
659 |
|
|
660 |
if (testNum == ETestDataWrittenAfterSessionClose)
|
|
661 |
{
|
|
662 |
// verify that closing the file server session (i.e. not the file)
|
|
663 |
// flushes the data to disk...
|
|
664 |
// *** NB This is likely to complete sometime AFTER returning from RFs::Close()
|
|
665 |
// *** as the file server doesn't wait for the disconnect thread to complete !!!
|
|
666 |
|
|
667 |
TheFs.Close();
|
|
668 |
TheFs.Connect();
|
|
669 |
SetSessionPath(gDrive);
|
|
670 |
#if defined(_DEBUG) || defined(_DEBUG_RELEASE)
|
|
671 |
test.Next(_L("Test dirty data is eventually written to disk after session close"));
|
|
672 |
TestDirtyDataWrittenToDisk(fileCacheStats);
|
|
673 |
test(fileCacheStats.iLockedSegmentCount == 0);
|
|
674 |
#endif
|
|
675 |
}
|
|
676 |
|
|
677 |
} // for (TInt testNum = 0; testNum < ETestEnd; testNum++)
|
|
678 |
|
|
679 |
|
|
680 |
//#if defined(_DEBUG) || defined(_DEBUG_RELEASE)
|
|
681 |
// PrintFileCacheStats(fileCacheStats);
|
|
682 |
//#endif
|
|
683 |
|
|
684 |
#if defined(_DEBUG) || defined(_DEBUG_RELEASE)
|
|
685 |
// flush closed files queue to empty cache
|
|
686 |
test.Printf(_L("Flushing close queue to empty cache...\n"));
|
|
687 |
r = TheFs.ControlIo(gDrive, KControlIoFlushClosedFiles);
|
|
688 |
test_KErrNone(r);
|
|
689 |
#endif
|
|
690 |
|
|
691 |
r = f.Open(TheFs, testFile, EFileRead | EFileReadBuffered | EFileWrite);
|
|
692 |
test_KErrNone(r);
|
|
693 |
|
|
694 |
TInt size;
|
|
695 |
r = f.Size(size);
|
131
|
696 |
test_KErrNone(r);
|
0
|
697 |
test (size = KBufSize);
|
|
698 |
|
|
699 |
readPtr.Set(gBuf->Des());
|
|
700 |
|
|
701 |
#if defined(_DEBUG) || defined(_DEBUG_RELEASE)
|
|
702 |
// Allocate full cachelines - so we can enable hole testing
|
|
703 |
TBool allocateAllSegmentsInCacheLine = ETrue;
|
|
704 |
r = controlIo(TheFs, gDrive, KControlIoAllocateMaxSegments, allocateAllSegmentsInCacheLine);
|
131
|
705 |
test_KErrNone(r);
|
0
|
706 |
PrintFileCacheStats(fileCacheStats, EFalse);
|
|
707 |
TInt holesDetected = fileCacheStats.iHoleCount;
|
|
708 |
TInt lockFailures = fileCacheStats.iCommitFailureCount + fileCacheStats.iLockFailureCount;
|
|
709 |
#endif
|
|
710 |
|
|
711 |
test.Next(_L("Test reading a partially filled cacheline"));
|
|
712 |
// create a cacheline with only the first segment filled
|
|
713 |
TInt startPos = KSegmentSize;
|
|
714 |
pos = startPos;
|
|
715 |
len = KSegmentSize;
|
|
716 |
writePtr.Set(gBuf->Mid(pos, len));
|
|
717 |
r = f.Write(pos, writePtr, len);
|
|
718 |
test_KErrNone(r);
|
|
719 |
|
|
720 |
// read from first & second segments
|
|
721 |
pos = startPos;
|
|
722 |
len = 8192;
|
|
723 |
RDebug::Print(_L("+%x, %x\n"), pos, len);
|
|
724 |
readPtr.Set(gBufPtr.MidTPtr(pos, len));
|
|
725 |
readPtr.SetLength(len);
|
|
726 |
r = f.Read(pos, readPtr, len);
|
|
727 |
test_KErrNone(r);
|
|
728 |
TestBuffer(gBufPtr, pos, len);
|
|
729 |
|
|
730 |
|
|
731 |
test.Next(_L("Test reading an empty segment towards the end of a partially filled cacheline (hole test)"));
|
|
732 |
// read from segment #4 and beyond end of cacheline into next
|
|
733 |
pos = startPos + KSegmentSize * 4;
|
|
734 |
len = KSegmentSize * 33; // 132 K
|
|
735 |
RDebug::Print(_L("+%x, %x\n"), pos, len);
|
|
736 |
readPtr.Set(gBufPtr.MidTPtr(pos, len));
|
|
737 |
readPtr.SetLength(len);
|
|
738 |
r = f.Read(pos, readPtr, len);
|
|
739 |
test_KErrNone(r);
|
|
740 |
TestBuffer(gBufPtr, pos, len);
|
|
741 |
|
|
742 |
|
|
743 |
test.Next(_L("Test writing to an empty segment towards the end of a partially filled cacheline (hole test)"));
|
|
744 |
// create a cacheline with only the first segment filled
|
|
745 |
startPos = 256 * 1024;
|
|
746 |
pos = startPos;
|
|
747 |
len = KSegmentSize;
|
|
748 |
writePtr.Set(gBuf->Mid(pos, len));
|
|
749 |
r = f.Write(pos, writePtr, len);
|
|
750 |
test_KErrNone(r);
|
|
751 |
|
|
752 |
|
|
753 |
// write into segment 3, 4 & 5
|
|
754 |
pos = startPos + KSegmentSize * 2;
|
|
755 |
len = KSegmentSize * 3;
|
|
756 |
writePtr.Set(gBuf->Mid(pos, len));
|
|
757 |
r = f.Write(pos, writePtr, len);
|
|
758 |
test_KErrNone(r);
|
|
759 |
// read back whole cacheline & verify
|
|
760 |
pos = startPos;
|
|
761 |
len = KSegmentSize * 32; // 128 K
|
|
762 |
RDebug::Print(_L("+%x, %x\n"), pos, len);
|
|
763 |
readPtr.Set(gBufPtr.MidTPtr(pos, len));
|
|
764 |
readPtr.SetLength(len);
|
|
765 |
r = f.Read(pos, readPtr, len);
|
|
766 |
test_KErrNone(r);
|
|
767 |
TestBuffer(gBufPtr, pos, len);
|
|
768 |
|
|
769 |
#if defined(_DEBUG) || defined(_DEBUG_RELEASE)
|
|
770 |
PrintFileCacheStats(fileCacheStats);
|
|
771 |
if (fileCacheStats.iCommitFailureCount + fileCacheStats.iLockFailureCount != lockFailures)
|
|
772 |
{
|
|
773 |
if (gRomPaged)
|
|
774 |
{
|
|
775 |
test.Printf(_L("Lock failures detected on paged ROM, abandoning hole test"));
|
|
776 |
}
|
|
777 |
else
|
|
778 |
{
|
|
779 |
test.Printf(_L("Unexpected lock failures detected on unpaged ROM!!!"));
|
|
780 |
test(0);
|
|
781 |
}
|
|
782 |
}
|
|
783 |
else
|
|
784 |
{
|
|
785 |
test(fileCacheStats.iHoleCount > holesDetected);
|
|
786 |
}
|
|
787 |
// Don't allocate full cachelines any more
|
|
788 |
allocateAllSegmentsInCacheLine = EFalse;
|
|
789 |
r = controlIo(TheFs, gDrive, KControlIoAllocateMaxSegments, allocateAllSegmentsInCacheLine);
|
131
|
790 |
test_KErrNone(r);
|
0
|
791 |
#endif
|
|
792 |
|
|
793 |
|
|
794 |
|
|
795 |
gBufPtr.FillZ();
|
|
796 |
gBufPtr.SetLength(KBufSize);
|
|
797 |
|
|
798 |
|
|
799 |
|
|
800 |
readPtr.SetLength(0);
|
|
801 |
|
|
802 |
|
|
803 |
// read from middle of fifth sector to half way thru seventh
|
|
804 |
test.Next(_L("Test read that spans two pages"));
|
|
805 |
pos = 512*4 + 16;
|
|
806 |
len = 512*2;
|
|
807 |
RDebug::Print(_L("+%x, %x\n"), pos, len);
|
|
808 |
readPtr.Set(gBufPtr.MidTPtr(pos, len));
|
|
809 |
readPtr.SetLength(len);
|
|
810 |
r = f.Read(pos, readPtr, len);
|
|
811 |
test_KErrNone(r);
|
|
812 |
TestBuffer(gBufPtr, pos, len);
|
|
813 |
|
|
814 |
|
|
815 |
|
|
816 |
// read to end of file
|
|
817 |
test.Next(_L("Test reading past end of file"));
|
|
818 |
pos = KBufSize - 0x100; // 0xfb05;
|
|
819 |
len = KBufSize - pos;
|
|
820 |
// pos = KBufSize - 16;
|
|
821 |
// len = 512;;
|
|
822 |
// len = Min(len, KBufSize-pos);
|
|
823 |
RDebug::Print(_L("+%x, %x\n"), pos, len);
|
|
824 |
readPtr.Set(gBufPtr.MidTPtr(pos, len));
|
|
825 |
readPtr.SetLength(len);
|
|
826 |
r = f.Read(pos, readPtr, len/* + 0x67*/);
|
|
827 |
test_KErrNone(r);
|
|
828 |
|
|
829 |
test.Next(_L("Test async reads"));
|
|
830 |
// issue 2 async reads
|
|
831 |
pos = KSegmentSize*7 + 16;
|
|
832 |
len = KSegmentSize;
|
|
833 |
RDebug::Print(_L("+%x, %x\n"), pos, len);
|
|
834 |
readPtr.Set(gBufPtr.MidTPtr(pos, len));
|
|
835 |
readPtr.SetLength(len);
|
|
836 |
|
|
837 |
TInt pos2 = pos + len;
|
|
838 |
TInt len2 = KSegmentSize;
|
|
839 |
TPtr8 readPtr2 = gBuf->Des();
|
|
840 |
readPtr2.Set(gBufPtr.MidTPtr(pos2, len2));
|
|
841 |
readPtr2.SetLength(len2);
|
|
842 |
|
|
843 |
TRequestStatus status1(KRequestPending);
|
|
844 |
TRequestStatus status2(KRequestPending);
|
|
845 |
|
|
846 |
f.Read(pos, readPtr, len, status1);
|
|
847 |
f.Read(readPtr2, len2, status2);
|
|
848 |
|
|
849 |
|
|
850 |
User::WaitForRequest(status1);
|
|
851 |
User::WaitForRequest(status2);
|
|
852 |
test.Printf(_L("status1 %d status2 %d\n"), status1.Int(), status2.Int());
|
|
853 |
TestBuffer(gBufPtr, pos, len);
|
|
854 |
TestBuffer(gBufPtr, pos2, len2);
|
|
855 |
|
|
856 |
|
|
857 |
test.Next(_L("Read entire file"));
|
|
858 |
|
|
859 |
for (pos = 0, len = 1; len <= 1024 && pos < KBufSize; len = (len+1) & 0x3FF)
|
|
860 |
{
|
|
861 |
len = Min(len, KBufSize-pos);
|
|
862 |
// RDebug::Print(_L("+%x, %x\n"), pos, len);
|
|
863 |
readPtr.Set(gBufPtr.MidTPtr(pos, len));
|
|
864 |
readPtr.SetLength(len);
|
|
865 |
|
|
866 |
r = f.Read(pos, readPtr, len);
|
|
867 |
test_KErrNone(r);
|
|
868 |
TestBuffer(gBufPtr, pos, len);
|
|
869 |
test_KErrNone(r);
|
|
870 |
pos+= len;
|
|
871 |
}
|
|
872 |
|
|
873 |
TestBuffer(gBufPtr, 0, KBufSize);
|
|
874 |
|
|
875 |
// read from position zero to ensure it's cached
|
|
876 |
pos = 0;
|
|
877 |
len = 512;
|
|
878 |
readPtr.Set(gBufPtr.MidTPtr(pos, len));
|
|
879 |
readPtr.SetLength(len);
|
|
880 |
r = f.Read(pos, readPtr, len);
|
|
881 |
test_KErrNone(r);
|
|
882 |
TestBuffer(gBufPtr, pos, len);
|
|
883 |
test_KErrNone(r);
|
|
884 |
|
|
885 |
f.Close();
|
|
886 |
|
|
887 |
|
|
888 |
#if defined(_DEBUG) || defined(_DEBUG_RELEASE)
|
|
889 |
r = controlIo(TheFs, gDrive, KControlIoFileCacheStats, fileCacheStats);
|
131
|
890 |
test_KErrNone(r);
|
0
|
891 |
test.Printf(_L("Number of files on closed queue=%d\n"),fileCacheStats.iFilesOnClosedQueue);
|
|
892 |
test(fileCacheStats.iFilesOnClosedQueue == 1);
|
|
893 |
#endif
|
|
894 |
//
|
|
895 |
|
|
896 |
|
|
897 |
//**************************************************************
|
|
898 |
// Test closed file queue
|
|
899 |
//**************************************************************
|
|
900 |
enum
|
|
901 |
{
|
|
902 |
ETestCloseQueueEmptyAfterTimeout,
|
|
903 |
ETestCloseQueueEmptyAfterOpenWithDirectIo,
|
|
904 |
ETestCloseQueueEmptyAfterDelete,
|
|
905 |
ETestCloseEnd};
|
|
906 |
for (testNum = 0; testNum < ETestCloseEnd; testNum++)
|
|
907 |
{
|
|
908 |
|
|
909 |
test.Next(_L("Reopen file & verify closed queue is empty"));
|
|
910 |
|
|
911 |
r = f.Open(TheFs, testFile, EFileRead | EFileReadBuffered);
|
|
912 |
test_KErrNone(r);
|
|
913 |
pos = 0;
|
|
914 |
len = 512;
|
|
915 |
readPtr.Set(gBufPtr.MidTPtr(pos, len));
|
|
916 |
readPtr.SetLength(len);
|
|
917 |
r = f.Read(pos, readPtr, len);
|
|
918 |
test_KErrNone(r);
|
|
919 |
TestBuffer(gBufPtr, pos, len);
|
|
920 |
test_KErrNone(r);
|
|
921 |
|
|
922 |
#if defined(_DEBUG) || defined(_DEBUG_RELEASE)
|
|
923 |
r = controlIo(TheFs, gDrive, KControlIoFileCacheStats, fileCacheStats);
|
131
|
924 |
test_KErrNone(r);
|
0
|
925 |
test.Printf(_L("Number of files on closed queue=%d\n"),fileCacheStats.iFilesOnClosedQueue);
|
|
926 |
test(fileCacheStats.iFilesOnClosedQueue == 0);
|
|
927 |
#endif
|
|
928 |
f.Close();
|
|
929 |
|
|
930 |
test.Next(_L("close & verify file is back on close queue"));
|
|
931 |
|
|
932 |
|
|
933 |
#if defined(_DEBUG) || defined(_DEBUG_RELEASE)
|
|
934 |
r = controlIo(TheFs, gDrive, KControlIoFileCacheStats, fileCacheStats);
|
131
|
935 |
test_KErrNone(r);
|
0
|
936 |
test.Printf(_L("Number of files on closed queue=%d\n"),fileCacheStats.iFilesOnClosedQueue);
|
|
937 |
test(fileCacheStats.iFilesOnClosedQueue == 1);
|
|
938 |
#endif
|
|
939 |
|
|
940 |
if (testNum == ETestCloseQueueEmptyAfterDelete)
|
|
941 |
{
|
|
942 |
test.Next(_L("delete file and verify closed queue is empty"));
|
|
943 |
r = TheFs.Delete(testFile);
|
|
944 |
test_KErrNone(r);
|
|
945 |
}
|
|
946 |
if (testNum == ETestCloseQueueEmptyAfterTimeout)
|
|
947 |
{
|
|
948 |
test.Next(_L("wait for a while and verify closed queue is empty"));
|
|
949 |
// wait for closed file queue to empty
|
|
950 |
#if defined(_DEBUG) || defined(_DEBUG_RELEASE)
|
|
951 |
User::After(gFileCacheConfig.iClosedFileKeepAliveTime + 1000000);
|
|
952 |
#endif
|
|
953 |
}
|
|
954 |
if (testNum == ETestCloseQueueEmptyAfterOpenWithDirectIo)
|
|
955 |
{
|
|
956 |
test.Next(_L("Re-open file in directIo mode and then close and verify closed queue is empty"));
|
|
957 |
r = f.Open(TheFs, testFile, EFileRead | EFileReadDirectIO);
|
|
958 |
test_KErrNone(r);
|
|
959 |
f.Close();
|
|
960 |
}
|
|
961 |
|
|
962 |
#if defined(_DEBUG) || defined(_DEBUG_RELEASE)
|
|
963 |
r = controlIo(TheFs, gDrive, KControlIoFileCacheStats, fileCacheStats);
|
131
|
964 |
test_KErrNone(r);
|
0
|
965 |
test.Printf(_L("Number of files on closed queue=%d\n"),fileCacheStats.iFilesOnClosedQueue);
|
|
966 |
test(fileCacheStats.iFilesOnClosedQueue == 0);
|
|
967 |
#endif
|
|
968 |
}
|
|
969 |
|
|
970 |
#if defined(_DEBUG) || defined(_DEBUG_RELEASE)
|
|
971 |
// turn lock failure mode back ON (if enabled)
|
|
972 |
simulatelockFailureMode = ETrue;
|
|
973 |
r = controlIo(TheFs, gDrive, KControlIoSimulateLockFailureMode, simulatelockFailureMode);
|
131
|
974 |
test_KErrNone(r);
|
0
|
975 |
#endif
|
|
976 |
|
|
977 |
//**************************************************************
|
|
978 |
// Test opening a file with a silly open mode flags combinations
|
|
979 |
//**************************************************************
|
|
980 |
test.Next(_L("Open file with illegal cache on/off bits"));
|
|
981 |
r = f.Open(TheFs, testFile, EFileRead | EFileReadBuffered | EFileReadDirectIO);
|
|
982 |
test_Value(r, r==KErrArgument);
|
|
983 |
r = f.Open(TheFs, testFile, EFileRead | EFileWriteBuffered | EFileWriteDirectIO);
|
|
984 |
test_Value(r, r==KErrArgument);
|
|
985 |
//**********************************
|
|
986 |
// Test that continuously appending to a file yields the correct size...
|
|
987 |
// NB: Must have lock failure more ON in debug mode for this test to pass
|
|
988 |
//**********************************
|
|
989 |
test.Next(_L("Test appending to a file & checking the file size..."));
|
|
990 |
gBufPtr.SetLength(KBufSize);
|
|
991 |
|
|
992 |
r = f.Replace(TheFs, testFile, EFileWrite | EFileWriteBuffered);
|
|
993 |
test_KErrNone(r);
|
|
994 |
|
|
995 |
const TInt KWriteLen = KSegmentSize+1;
|
|
996 |
writePtr.Set(gBuf->Des().Ptr(), KWriteLen);
|
|
997 |
|
|
998 |
#if defined(_DEBUG) || defined(_DEBUG_RELEASE)
|
|
999 |
r = controlIo(TheFs, gDrive, KControlIoFileCacheStats, fileCacheStats);
|
131
|
1000 |
test_KErrNone(r);
|
0
|
1001 |
test.Printf(_L("Number of Write-throughs with dirty data=%d\n"),fileCacheStats.iWriteThroughWithDirtyDataCount);
|
|
1002 |
TInt writeThroughWithDirtyDataCountOld = fileCacheStats.iWriteThroughWithDirtyDataCount;
|
|
1003 |
TInt writeThroughWithDirtyDataCountNew = writeThroughWithDirtyDataCountOld;
|
|
1004 |
#endif
|
|
1005 |
|
|
1006 |
TInt fileSize = 0;
|
|
1007 |
for (TInt i=0; i<4; i++)
|
|
1008 |
{
|
|
1009 |
fileSize = 0;
|
|
1010 |
r = f.SetSize(fileSize);
|
131
|
1011 |
test_KErrNone(r);
|
0
|
1012 |
for (pos = 0; pos < KMaxFileSize; )
|
|
1013 |
{
|
|
1014 |
r = f.Write(pos, writePtr);
|
|
1015 |
if (r != KErrNone)
|
|
1016 |
{
|
|
1017 |
test.Printf(_L("Iter #%d, write pos %d size %d, Write() returned %d"), i, pos, fileSize, r);
|
|
1018 |
r = f.Flush();
|
|
1019 |
test.Printf(_L("Flush returned %d"), r);
|
|
1020 |
test(0);
|
|
1021 |
}
|
131
|
1022 |
test_KErrNone(r);
|
0
|
1023 |
pos+= writePtr.Length();
|
|
1024 |
|
|
1025 |
r = f.Size(fileSize);
|
131
|
1026 |
test_KErrNone(r);
|
0
|
1027 |
if (fileSize != pos)
|
|
1028 |
{
|
|
1029 |
test.Printf(_L("Iter #%d, write pos %d != size %d"), i, pos, fileSize);
|
|
1030 |
r = f.Flush();
|
|
1031 |
test.Printf(_L("Flush returned %d"), r);
|
|
1032 |
test(0);
|
|
1033 |
}
|
|
1034 |
test (fileSize == pos);
|
|
1035 |
|
|
1036 |
#if defined(_DEBUG) || defined(_DEBUG_RELEASE)
|
|
1037 |
r = controlIo(TheFs, gDrive, KControlIoFileCacheStats, fileCacheStats);
|
131
|
1038 |
test_KErrNone(r);
|
0
|
1039 |
writeThroughWithDirtyDataCountNew = fileCacheStats.iWriteThroughWithDirtyDataCount;
|
|
1040 |
if (writeThroughWithDirtyDataCountNew > writeThroughWithDirtyDataCountOld)
|
|
1041 |
{
|
|
1042 |
test.Printf(_L("Iter #%d, write pos %d size %d"), i, pos, fileSize);
|
|
1043 |
test.Printf(_L("Number of Write-throughs with dirty data=%d\n"),fileCacheStats.iWriteThroughWithDirtyDataCount);
|
|
1044 |
i = 4;
|
|
1045 |
break;
|
|
1046 |
}
|
|
1047 |
#endif
|
|
1048 |
|
|
1049 |
}
|
|
1050 |
}
|
|
1051 |
|
|
1052 |
#if defined(_DEBUG) || defined(_DEBUG_RELEASE)
|
|
1053 |
test(writeThroughWithDirtyDataCountNew > writeThroughWithDirtyDataCountOld);
|
|
1054 |
#endif
|
|
1055 |
|
|
1056 |
|
|
1057 |
f.Close();
|
|
1058 |
|
|
1059 |
|
|
1060 |
//TheFs.SetDebugRegister(0);
|
|
1061 |
test.End();
|
|
1062 |
}
|
|
1063 |
|
|
1064 |
|
|
1065 |
// This thread is used to test what happens if requests are sent to the file server
|
|
1066 |
// while the drive thread is hung in the critical notifier server. The requests should
|
|
1067 |
// complete immediately with KErrNotReady
|
|
1068 |
TInt ReaderThread(TAny* aFileName)
|
|
1069 |
{
|
|
1070 |
RTest test(_L("T_FILECACHE, ReaderThread"));
|
|
1071 |
|
|
1072 |
TDesC& fileName = *(TDesC*) aFileName;
|
|
1073 |
|
|
1074 |
RFs fs;
|
|
1075 |
TInt r = fs.Connect();
|
131
|
1076 |
test_KErrNone(r);
|
0
|
1077 |
r = fs.SetSessionPath(gSessionPath);
|
131
|
1078 |
test_KErrNone(r);
|
0
|
1079 |
|
|
1080 |
|
|
1081 |
RFile file;
|
|
1082 |
r = file.Open(fs, fileName, EFileRead | EFileReadBuffered | EFileShareReadersOrWriters);
|
|
1083 |
test_KErrNone(r);
|
|
1084 |
|
|
1085 |
RTimer timer;
|
|
1086 |
timer.CreateLocal();
|
|
1087 |
TRequestStatus reqStat;
|
|
1088 |
timer.After(reqStat,10000000); // Read for 10 secs
|
|
1089 |
|
|
1090 |
TInt pos=0;
|
|
1091 |
TInt KReadLen = 32768;
|
|
1092 |
TInt retCode = KErrNone;
|
|
1093 |
|
|
1094 |
for (TInt i=0; reqStat == KRequestPending; i++)
|
|
1095 |
{
|
|
1096 |
r = file.Read(pos, DataBuf, KReadLen);
|
|
1097 |
test_Value(r, r == KErrNone || r == KErrNotReady);
|
|
1098 |
|
|
1099 |
//test.Printf(_L("ReaderThread: iter %d, read at %d ret %d\n"), i, pos, r);
|
|
1100 |
if (r == KErrNotReady)
|
|
1101 |
retCode = r;
|
|
1102 |
else if (r == KErrNone)
|
|
1103 |
pos = DataBuf.Length() == 0 ? 0: pos + DataBuf.Length();
|
|
1104 |
if (retCode == KErrNotReady)
|
|
1105 |
test.Printf(_L("ReaderThread: iter %d, read at %d ret %d \n"), i, pos, r);
|
|
1106 |
}
|
|
1107 |
|
|
1108 |
timer.Close();
|
|
1109 |
file.Close();
|
|
1110 |
fs.Close();
|
|
1111 |
|
|
1112 |
return retCode;
|
|
1113 |
}
|
|
1114 |
|
|
1115 |
|
|
1116 |
void ManualTests()
|
|
1117 |
{
|
|
1118 |
RFile f;
|
|
1119 |
TInt r;
|
|
1120 |
gBufPtr.SetLength(KBufSize);
|
|
1121 |
FillBuffer(gBufPtr, KBufSize);
|
|
1122 |
TestBuffer(gBufPtr, 0,KBufSize);
|
|
1123 |
|
|
1124 |
TPtrC8 writePtr;
|
|
1125 |
writePtr.Set(gBuf->Des());
|
|
1126 |
|
|
1127 |
TFileName testFile = _L("TEST.BIN");
|
|
1128 |
|
|
1129 |
#if defined(_DEBUG)
|
|
1130 |
test.Next(_L("Testing writing and then closing with an immediate simulated card eject"));
|
|
1131 |
test.Printf(_L("**********************************************************\n"));
|
|
1132 |
test.Printf(_L("When critical notifier message appears, PRESS RETRY\n"));
|
|
1133 |
test.Printf(_L("**********************************************************\n"));
|
|
1134 |
|
|
1135 |
r = f.Replace(TheFs, testFile, EFileWrite | EFileWriteBuffered | EFileShareReadersOrWriters);
|
|
1136 |
test_KErrNone(r);
|
|
1137 |
|
|
1138 |
test.Printf(_L("Writing...."));
|
|
1139 |
r = f.Write(0, writePtr);
|
|
1140 |
test.Printf(_L("Write returned %d\n"), r);
|
|
1141 |
test_KErrNone(r);
|
|
1142 |
|
|
1143 |
r=TheFs.ControlIo(gDrive, KControlIoSimulateFileCacheWriteFailure);
|
|
1144 |
test_KErrNone(r);
|
|
1145 |
|
|
1146 |
f.Close();
|
|
1147 |
|
|
1148 |
TEntry entry;
|
|
1149 |
|
|
1150 |
// wait for re-insertion....
|
|
1151 |
do
|
|
1152 |
{
|
|
1153 |
r = TheFs.Entry(testFile, entry);
|
|
1154 |
User::After(500000);
|
|
1155 |
}
|
|
1156 |
while (r == KErrNotReady);
|
|
1157 |
test_KErrNone(r);
|
|
1158 |
|
|
1159 |
test.Printf(_L("FileSize %d expected %d\n"), entry.iSize, writePtr.Length());
|
|
1160 |
|
|
1161 |
// test all data is written to disk
|
|
1162 |
test (entry.iSize == writePtr.Length());
|
|
1163 |
#endif
|
|
1164 |
|
|
1165 |
|
|
1166 |
test.Next(_L("Testing writing and then ejecting card"));
|
|
1167 |
|
|
1168 |
// r = f.Replace(TheFs, testFile, EFileWrite | EFileWriteDirectIO);
|
|
1169 |
r = f.Replace(TheFs, testFile, EFileWrite | EFileWriteBuffered | EFileShareReadersOrWriters);
|
|
1170 |
test_KErrNone(r);
|
|
1171 |
writePtr.Set(gBuf->Des());
|
|
1172 |
|
|
1173 |
|
|
1174 |
// set the file size first so that the cluster chain already exists
|
|
1175 |
r = f.SetSize(writePtr.Length());
|
|
1176 |
test.Printf(_L("SetSize returned %d"));
|
|
1177 |
|
|
1178 |
// Create another thread which will attempt to issue reads while this thread is suspended
|
|
1179 |
// These reads should complete with KErrNotReady
|
|
1180 |
const TInt KHeapSize = 32768;
|
|
1181 |
test.Printf(_L("Creating file-reading thread\n"));
|
|
1182 |
RThread readerThread;
|
|
1183 |
readerThread.Create(_L("FileReaderThread"), ReaderThread, KDefaultStackSize, KHeapSize, KHeapSize, &testFile);
|
|
1184 |
|
|
1185 |
test.Printf(_L("Writing...."));
|
|
1186 |
r = f.Write(0, writePtr);
|
|
1187 |
test.Printf(_L("Write returned %d\n"), r);
|
|
1188 |
|
|
1189 |
|
|
1190 |
test.Printf(_L("Waiting 5 seconds.\n"));
|
|
1191 |
test.Printf(_L("**********************************************************\n"));
|
|
1192 |
test.Printf(_L("Please press a key, EJECT MEDIA BEFORE WRITE TIMER EXPIRES,\n"));
|
|
1193 |
test.Printf(_L("wait for critical notifier, replace media and retry\n"));
|
|
1194 |
test.Printf(_L("**********************************************************\n"));
|
|
1195 |
// test.Printf(_L("press any key..."));
|
|
1196 |
test.Getch();
|
|
1197 |
test.Printf(_L("\n"));
|
|
1198 |
|
|
1199 |
test.Printf(_L("Writing...."));
|
|
1200 |
r = f.Write(0, writePtr);
|
|
1201 |
test.Printf(_L("Write returned %d\n"), r);
|
|
1202 |
readerThread.Resume();
|
|
1203 |
|
|
1204 |
User::After(5000000);
|
|
1205 |
|
|
1206 |
do
|
|
1207 |
{
|
|
1208 |
test.Printf(_L("Flushing....\n"));
|
|
1209 |
r = f.Flush();
|
|
1210 |
test.Printf(_L("Flush returned %d\n"), r);
|
|
1211 |
if (r != KErrNone)
|
|
1212 |
User::After(5000000);
|
|
1213 |
}
|
|
1214 |
while (r != KErrNone);
|
|
1215 |
|
|
1216 |
|
|
1217 |
// r = f.Write(0, writePtr);
|
|
1218 |
// test.Printf(_L("Write returned %d"));
|
|
1219 |
|
|
1220 |
// test_KErrNone(r);
|
|
1221 |
|
|
1222 |
test.Next(_L("Testing reader thread completed with KErrNotReady"));
|
|
1223 |
TRequestStatus status;
|
|
1224 |
readerThread.Logon(status);
|
|
1225 |
readerThread.Resume();
|
|
1226 |
User::WaitForRequest(status);
|
|
1227 |
test.Printf(_L("ReaderThread status %d\n"), status.Int());
|
|
1228 |
test (status.Int() == KErrNotReady);
|
|
1229 |
readerThread.Close();
|
|
1230 |
|
|
1231 |
test.Printf(_L("press any key..."));
|
|
1232 |
test.Getch();
|
|
1233 |
test.Printf(_L("\n"));
|
|
1234 |
|
|
1235 |
f.Close();
|
|
1236 |
}
|
|
1237 |
|
|
1238 |
|
|
1239 |
LOCAL_C void DoTestFileRead(TUint aFileMode, TInt aReadBlockSize)
|
|
1240 |
//
|
|
1241 |
// Do Read Test
|
|
1242 |
//
|
|
1243 |
{
|
|
1244 |
|
|
1245 |
RFile file;
|
|
1246 |
TInt r=file.Open(TheFs,_L("READTEST.XXX"),EFileStream | aFileMode);
|
|
1247 |
test_KErrNone(r);
|
|
1248 |
|
|
1249 |
TInt maxReadCount=KMaxFileSize/aReadBlockSize;
|
|
1250 |
TInt loopCount=0;
|
|
1251 |
|
|
1252 |
TTime startTime;
|
|
1253 |
TTime endTime;
|
|
1254 |
|
|
1255 |
RTimer timer;
|
|
1256 |
timer.CreateLocal();
|
|
1257 |
TRequestStatus reqStat;
|
|
1258 |
timer.After(reqStat,10000000); // After 10 secs
|
|
1259 |
startTime.HomeTime();
|
|
1260 |
|
|
1261 |
FOREVER
|
|
1262 |
{
|
|
1263 |
TInt pos=0;
|
|
1264 |
file.Seek(ESeekStart,pos);
|
|
1265 |
for(TInt ii=0;ii<maxReadCount;ii++)
|
|
1266 |
{
|
|
1267 |
r = file.Read(DataBuf,aReadBlockSize);
|
|
1268 |
test_KErrNone(r);
|
|
1269 |
#if defined(_DEBUG)
|
|
1270 |
for(TInt jj=0;jj<DataBuf.Size();jj++)
|
|
1271 |
{
|
|
1272 |
if (DataBuf[jj] != ((jj+ii*aReadBlockSize)%256))
|
|
1273 |
{
|
|
1274 |
test.Printf(_L("len %d size %d jj %d ii %d"), DataBuf.Length(), DataBuf.Size(), jj, ii);
|
|
1275 |
test(0);
|
|
1276 |
}
|
|
1277 |
// test(DataBuf[jj] == ((jj+ii*aReadBlockSize)%256) );
|
|
1278 |
}
|
|
1279 |
#endif
|
|
1280 |
if (reqStat!=KRequestPending)
|
|
1281 |
{
|
|
1282 |
endTime.HomeTime();
|
|
1283 |
|
|
1284 |
TInt functionCalls=loopCount*maxReadCount+ii;
|
|
1285 |
// TReal rate = ( TReal32(functionCalls) * TReal32(aReadBlockSize) ) / 10;
|
|
1286 |
// test.Printf(_L("Read %5d byte blocks:\t%11.3f KBytes/s\n"), aReadBlockSize, rate / (KOneK));
|
|
1287 |
|
|
1288 |
TReal transferRate =
|
|
1289 |
(TReal32(functionCalls) * TReal32(aReadBlockSize)) /
|
|
1290 |
TReal(endTime.MicroSecondsFrom(startTime).Int64()) * TReal(KOneMeg) / TReal(KOneK);
|
|
1291 |
test.Printf(_L("Read %5d byte blocks:\t%11.3f KBytes/s\n"), aReadBlockSize,transferRate);
|
|
1292 |
|
|
1293 |
timer.Close();
|
|
1294 |
file.Close();
|
|
1295 |
|
|
1296 |
return;
|
|
1297 |
}
|
|
1298 |
}
|
|
1299 |
loopCount++;
|
|
1300 |
}
|
|
1301 |
}
|
|
1302 |
|
|
1303 |
LOCAL_C void DoTestFileWrite(TUint aFileMode, TInt aWriteBlockSize)
|
|
1304 |
//
|
|
1305 |
// Do Write benchmark
|
|
1306 |
//
|
|
1307 |
{
|
|
1308 |
DataBuf.SetLength(aWriteBlockSize);
|
|
1309 |
TInt maxWriteCount=KMaxFileSize/aWriteBlockSize;
|
|
1310 |
TInt loopCount=0;
|
|
1311 |
|
|
1312 |
RFile file;
|
|
1313 |
TInt r = file.Replace(TheFs,_L("WRITETST"),EFileStream | aFileMode);
|
131
|
1314 |
test_KErrNone(r);
|
0
|
1315 |
|
|
1316 |
TTime startTime;
|
|
1317 |
TTime endTime;
|
|
1318 |
|
|
1319 |
RTimer timer;
|
|
1320 |
timer.CreateLocal();
|
|
1321 |
TRequestStatus reqStat;
|
|
1322 |
timer.After(reqStat,10000000); // After 10 secs
|
|
1323 |
startTime.HomeTime();
|
|
1324 |
|
|
1325 |
|
|
1326 |
|
|
1327 |
FOREVER
|
|
1328 |
{
|
|
1329 |
TInt pos=0;
|
|
1330 |
file.Seek(ESeekStart,pos);
|
|
1331 |
for(TInt ii=0;ii<maxWriteCount;ii++)
|
|
1332 |
{
|
|
1333 |
r = file.Write(DataBuf);
|
|
1334 |
test_KErrNone(r);
|
|
1335 |
if (reqStat!=KRequestPending)
|
|
1336 |
{
|
|
1337 |
|
|
1338 |
// TReal rate = (TReal32(functionCalls) * TReal32(aWriteBlockSize)) / 10;
|
|
1339 |
// test.Printf(_L("Write %5d byte blocks:\t%11.3f KBytes/s\n"), aWriteBlockSize, rate / (KOneK));
|
|
1340 |
|
|
1341 |
r = file.Flush();
|
|
1342 |
test_KErrNone(r);
|
|
1343 |
|
|
1344 |
endTime.HomeTime();
|
|
1345 |
|
|
1346 |
TInt functionCalls=loopCount*maxWriteCount+ii;
|
|
1347 |
TReal transferRate =
|
|
1348 |
(TReal32(functionCalls) * TReal32(aWriteBlockSize)) /
|
|
1349 |
TReal(endTime.MicroSecondsFrom(startTime).Int64()) * TReal(KOneMeg) / TReal(KOneK);
|
|
1350 |
test.Printf(_L("Write %5d byte blocks:\t%11.3f KBytes/s\n"), aWriteBlockSize,transferRate);
|
|
1351 |
|
|
1352 |
file.Close();
|
|
1353 |
timer.Close();
|
|
1354 |
TInt r=TheFs.Delete(_L("WRITETST"));
|
|
1355 |
test_KErrNone(r);
|
|
1356 |
return;
|
|
1357 |
}
|
|
1358 |
}
|
|
1359 |
loopCount++;
|
|
1360 |
}
|
|
1361 |
}
|
|
1362 |
|
|
1363 |
LOCAL_C void TestFileRead(TUint aFileMode)
|
|
1364 |
//
|
|
1365 |
// Benchmark read method
|
|
1366 |
//
|
|
1367 |
{
|
|
1368 |
|
|
1369 |
// ClearSessionDirectory();
|
|
1370 |
test.Next(_L("Benchmark read method"));
|
|
1371 |
// test.Printf(_L("aFileMode %08X\n"), aFileMode);
|
|
1372 |
PrintFileMode(aFileMode);
|
|
1373 |
|
|
1374 |
// Create test data
|
|
1375 |
TBuf8<1024> testdata(1024);
|
|
1376 |
for (TInt i=0;i<testdata.MaxSize();i++)
|
|
1377 |
testdata[i]=TText8(i%256);
|
|
1378 |
|
|
1379 |
// create & fill the file
|
|
1380 |
RFile file;
|
|
1381 |
TInt r=file.Replace(TheFs,_L("READTEST.XXX"),EFileStream | aFileMode);
|
|
1382 |
test_KErrNone(r);
|
|
1383 |
|
|
1384 |
test.Printf(_L("Creating test file....."));
|
|
1385 |
TInt count=KMaxFileSize/testdata.Length();
|
|
1386 |
while (count--)
|
|
1387 |
file.Write(testdata);
|
|
1388 |
file.Close();
|
|
1389 |
test.Printf(_L("done.\n"));
|
|
1390 |
|
|
1391 |
#ifdef SYMBIAN_TEST_EXTENDED_BUFFER_SIZES
|
|
1392 |
|
|
1393 |
DoTestFileRead(aFileMode, 1);
|
|
1394 |
DoTestFileRead(aFileMode, 2);
|
|
1395 |
DoTestFileRead(aFileMode, 4);
|
|
1396 |
DoTestFileRead(aFileMode, 8);
|
|
1397 |
DoTestFileRead(aFileMode, 16);
|
|
1398 |
DoTestFileRead(aFileMode, 32);
|
|
1399 |
DoTestFileRead(aFileMode, 64);
|
|
1400 |
DoTestFileRead(aFileMode, 128);
|
|
1401 |
DoTestFileRead(aFileMode, 256);
|
|
1402 |
DoTestFileRead(aFileMode, 512);
|
|
1403 |
DoTestFileRead(aFileMode, 1024);
|
|
1404 |
DoTestFileRead(aFileMode, 2048);
|
|
1405 |
DoTestFileRead(aFileMode, 4096);
|
|
1406 |
DoTestFileRead(aFileMode, 8192);
|
|
1407 |
DoTestFileRead(aFileMode, 16384);
|
|
1408 |
DoTestFileRead(aFileMode, 32768);
|
|
1409 |
DoTestFileRead(aFileMode, 65536);
|
|
1410 |
DoTestFileRead(aFileMode, 131072);
|
|
1411 |
#else
|
|
1412 |
//TheFs.SetDebugRegister(KCACHE);
|
|
1413 |
DoTestFileRead(aFileMode, 1);
|
|
1414 |
DoTestFileRead(aFileMode, 16);
|
|
1415 |
DoTestFileRead(aFileMode, 512);
|
|
1416 |
//TheFs.SetDebugRegister(0);
|
|
1417 |
DoTestFileRead(aFileMode, 4 * 1024);
|
|
1418 |
DoTestFileRead(aFileMode, 32 * 1024);
|
|
1419 |
DoTestFileRead(aFileMode, 64 * 1024);
|
|
1420 |
DoTestFileRead(aFileMode, 128 * 1024);
|
|
1421 |
DoTestFileRead(aFileMode, 256 * 1024);
|
|
1422 |
#endif
|
|
1423 |
|
|
1424 |
r=TheFs.Delete(_L("READTEST.XXX"));
|
|
1425 |
|
|
1426 |
|
|
1427 |
|
|
1428 |
test_KErrNone(r);
|
|
1429 |
}
|
|
1430 |
|
|
1431 |
|
|
1432 |
LOCAL_C void TestFileWrite(TUint aFileMode)
|
|
1433 |
//
|
|
1434 |
// Benchmark write method
|
|
1435 |
//
|
|
1436 |
{
|
|
1437 |
// ClearSessionDirectory();
|
|
1438 |
test.Next(_L("Benchmark write method"));
|
|
1439 |
// test.Printf(_L("aFileMode %08X\n"), aFileMode);
|
|
1440 |
PrintFileMode(aFileMode);
|
|
1441 |
|
|
1442 |
|
|
1443 |
// RFile file;
|
|
1444 |
// TInt r = file.Replace(TheFs,_L("WRITETST"),EFileStream | aFileMode);
|
|
1445 |
// test_KErrNone(r);
|
|
1446 |
|
|
1447 |
|
|
1448 |
#ifdef SYMBIAN_TEST_EXTENDED_BUFFER_SIZES
|
|
1449 |
DoTestFileWrite(aFileMode, 1);
|
|
1450 |
DoTestFileWrite(aFileMode, 2);
|
|
1451 |
DoTestFileWrite(aFileMode, 4);
|
|
1452 |
DoTestFileWrite(aFileMode, 8);
|
|
1453 |
DoTestFileWrite(aFileMode, 16);
|
|
1454 |
DoTestFileWrite(aFileMode, 32);
|
|
1455 |
DoTestFileWrite(aFileMode, 64);
|
|
1456 |
DoTestFileWrite(aFileMode, 128);
|
|
1457 |
DoTestFileWrite(aFileMode, 256);
|
|
1458 |
DoTestFileWrite(aFileMode, 512);
|
|
1459 |
DoTestFileWrite(aFileMode, 1024);
|
|
1460 |
DoTestFileWrite(aFileMode, 2048);
|
|
1461 |
DoTestFileWrite(aFileMode, 4096);
|
|
1462 |
DoTestFileWrite(aFileMode, 8192);
|
|
1463 |
DoTestFileWrite(aFileMode, 16384);
|
|
1464 |
DoTestFileWrite(aFileMode, 32768);
|
|
1465 |
DoTestFileWrite(aFileMode, 65536);
|
|
1466 |
DoTestFileWrite(aFileMode, 131072);
|
|
1467 |
#else
|
|
1468 |
DoTestFileWrite(aFileMode, 1);
|
|
1469 |
DoTestFileWrite(aFileMode, 16);
|
|
1470 |
DoTestFileWrite(aFileMode, 512);
|
|
1471 |
DoTestFileWrite(aFileMode, 4 * 1024);
|
|
1472 |
DoTestFileWrite(aFileMode, 32 * 1024);
|
|
1473 |
DoTestFileWrite(aFileMode, 64 * 1024);
|
|
1474 |
DoTestFileWrite(aFileMode, 128 * 1024);
|
|
1475 |
DoTestFileWrite(aFileMode, 256 * 1024);
|
|
1476 |
#endif
|
|
1477 |
}
|
|
1478 |
|
|
1479 |
enum CommandId {
|
|
1480 |
CMD_NO_COMMAND,
|
|
1481 |
CMD_HELP,
|
|
1482 |
CMD_DISPLAY_CACHE_FLAGS,
|
|
1483 |
CMD_WRITE_CACHE_FLAGS,
|
|
1484 |
CMD_PERFORMANCE_TEST,
|
|
1485 |
CMD_MANUAL_TEST
|
|
1486 |
};
|
|
1487 |
|
|
1488 |
|
|
1489 |
class CommandLineOption {
|
|
1490 |
public:
|
|
1491 |
CommandLineOption(const TPtrC &s, CommandId i) : str(s), id(i) { }
|
|
1492 |
|
|
1493 |
const TPtrC str;
|
|
1494 |
CommandId id;
|
|
1495 |
|
|
1496 |
private:
|
|
1497 |
CommandLineOption() { }
|
|
1498 |
};
|
|
1499 |
|
|
1500 |
// Lists of command line options
|
|
1501 |
static const CommandLineOption commandList[] = {
|
|
1502 |
CommandLineOption(_L("-help"), CMD_HELP),
|
|
1503 |
CommandLineOption(_L("-h"), CMD_HELP),
|
|
1504 |
CommandLineOption(_L("-?"), CMD_HELP),
|
|
1505 |
CommandLineOption(_L("/?"), CMD_HELP),
|
|
1506 |
CommandLineOption(_L("-d"), CMD_DISPLAY_CACHE_FLAGS),
|
|
1507 |
CommandLineOption(_L("-w"), CMD_WRITE_CACHE_FLAGS),
|
|
1508 |
CommandLineOption(_L("-p"), CMD_PERFORMANCE_TEST),
|
|
1509 |
CommandLineOption(_L("-m"), CMD_MANUAL_TEST),
|
|
1510 |
};
|
|
1511 |
|
|
1512 |
|
|
1513 |
|
|
1514 |
LOCAL_C void printHelp() {
|
|
1515 |
test.Printf(_L("Option Explanation\r\n"));
|
|
1516 |
test.Printf(_L("-help Print this text\r\n"));
|
|
1517 |
test.Printf(_L("-d Display cache flags\n"));
|
|
1518 |
test.Printf(_L("-p Performance test\n"));
|
|
1519 |
}
|
|
1520 |
|
|
1521 |
|
|
1522 |
|
|
1523 |
/////////////////////////////////////////////////////////////////////////////
|
|
1524 |
// Function:
|
|
1525 |
// bool parseCommandLine()
|
|
1526 |
//
|
|
1527 |
// Parameters:
|
|
1528 |
// -
|
|
1529 |
//
|
|
1530 |
// Return value:
|
|
1531 |
// true if command line options was correct, false if any command was
|
|
1532 |
// invalid
|
|
1533 |
//
|
|
1534 |
// Purpose:
|
|
1535 |
// Parses the command line
|
|
1536 |
//
|
|
1537 |
/////////////////////////////////////////////////////////////////////////////
|
|
1538 |
|
|
1539 |
//TBuf<512> commandLine;
|
|
1540 |
|
|
1541 |
|
|
1542 |
LOCAL_C bool ParseCommandLine( const TDesC& aCommand )
|
|
1543 |
{
|
|
1544 |
TLex lex(aCommand);
|
|
1545 |
TInt tokenCount = 0;
|
|
1546 |
|
|
1547 |
gDriveToTest='C';
|
|
1548 |
gRunTests = ETrue;
|
|
1549 |
|
|
1550 |
for (TPtrC token=lex.NextToken(); token.Length() != 0;token.Set(lex.NextToken()))
|
|
1551 |
{
|
|
1552 |
tokenCount++;
|
|
1553 |
|
|
1554 |
//
|
|
1555 |
// Search the list of commands for a match.
|
|
1556 |
//
|
|
1557 |
CommandId commandId = CMD_NO_COMMAND;
|
|
1558 |
for (TUint i = 0; i < sizeof commandList / sizeof commandList[0]; i++)
|
|
1559 |
{
|
|
1560 |
if (token.CompareF(commandList[i].str) == 0)
|
|
1561 |
{
|
|
1562 |
//
|
|
1563 |
// Found a matching string
|
|
1564 |
//
|
|
1565 |
commandId = commandList[i].id;
|
|
1566 |
break;
|
|
1567 |
}
|
|
1568 |
}
|
|
1569 |
|
|
1570 |
switch (commandId)
|
|
1571 |
{
|
|
1572 |
case CMD_NO_COMMAND:
|
|
1573 |
{
|
|
1574 |
TFileName thisfile=RProcess().FileName();
|
|
1575 |
if (token.MatchF(thisfile)==0)
|
|
1576 |
{
|
|
1577 |
token.Set(lex.NextToken());
|
|
1578 |
}
|
|
1579 |
test.Printf(_L("CLP=%S\n"),&token);
|
|
1580 |
|
|
1581 |
TChar ch = token[0];
|
|
1582 |
if (ch.IsAlpha())
|
|
1583 |
{
|
|
1584 |
if(token.Length()!=0)
|
|
1585 |
{
|
|
1586 |
gDriveToTest=token[0];
|
|
1587 |
gDriveToTest.UpperCase();
|
|
1588 |
}
|
|
1589 |
else
|
|
1590 |
gDriveToTest='C';
|
|
1591 |
lex.NextToken();
|
|
1592 |
}
|
|
1593 |
}
|
|
1594 |
break;
|
|
1595 |
|
|
1596 |
case CMD_HELP:
|
|
1597 |
printHelp();
|
|
1598 |
gRunTests = EFalse;
|
|
1599 |
break;
|
|
1600 |
|
|
1601 |
#if defined(_DEBUG) || defined(_DEBUG_RELEASE)
|
|
1602 |
case CMD_WRITE_CACHE_FLAGS:
|
|
1603 |
{
|
|
1604 |
token.Set(lex.NextToken());
|
|
1605 |
if (token.Length() == 0) {
|
|
1606 |
printHelp();
|
|
1607 |
return false;
|
|
1608 |
}
|
|
1609 |
//
|
|
1610 |
// Extract flags (in hex) from next token.
|
|
1611 |
//
|
|
1612 |
TPtrC numStr(token);
|
|
1613 |
TUint val;
|
|
1614 |
TInt r = TLex(numStr).Val(val, EHex);
|
|
1615 |
if (r != KErrNone) {
|
|
1616 |
printHelp();
|
|
1617 |
return false;
|
|
1618 |
}
|
|
1619 |
gDriveCacheFlags = TFileCacheFlags(val);
|
|
1620 |
gWriteCacheFlags = ETrue;
|
|
1621 |
gRunTests = EFalse;
|
|
1622 |
break;
|
|
1623 |
}
|
|
1624 |
|
|
1625 |
case CMD_DISPLAY_CACHE_FLAGS:
|
|
1626 |
gDisplayCacheFlags = ETrue;
|
|
1627 |
gRunTests = EFalse;
|
|
1628 |
break;
|
|
1629 |
#endif
|
|
1630 |
case CMD_PERFORMANCE_TEST:
|
|
1631 |
gRunPerformanceTests = ETrue;
|
|
1632 |
gRunUnitTests = EFalse;
|
|
1633 |
break;
|
|
1634 |
|
|
1635 |
case CMD_MANUAL_TEST:
|
|
1636 |
gRunManualTests = ETrue;
|
|
1637 |
gRunUnitTests = EFalse;
|
|
1638 |
break;
|
|
1639 |
|
|
1640 |
default:
|
|
1641 |
test.Printf(_L("Sorry, command option '%S' not implemented\n"),
|
|
1642 |
&token);
|
|
1643 |
break;
|
|
1644 |
}
|
|
1645 |
|
|
1646 |
}
|
|
1647 |
return true;
|
|
1648 |
}
|
|
1649 |
|
|
1650 |
|
|
1651 |
LOCAL_C TBool parseCommandLine() {
|
|
1652 |
//
|
|
1653 |
// Loop through all tokens in the command line
|
|
1654 |
//
|
|
1655 |
TInt cmdLineLen = User::CommandLineLength();
|
|
1656 |
HBufC* cmdLineBuf = HBufC::New( cmdLineLen );
|
|
1657 |
if( !cmdLineBuf )
|
|
1658 |
{
|
|
1659 |
return false;
|
|
1660 |
}
|
|
1661 |
TPtr ptr = cmdLineBuf->Des();
|
|
1662 |
User::CommandLine(ptr);
|
|
1663 |
|
|
1664 |
bool err = ParseCommandLine( *cmdLineBuf );
|
|
1665 |
delete cmdLineBuf;
|
|
1666 |
return err;
|
|
1667 |
}
|
|
1668 |
|
|
1669 |
GLDEF_C void CallTestsL()
|
|
1670 |
//
|
|
1671 |
// Do tests relative to the session path
|
|
1672 |
//
|
|
1673 |
{
|
|
1674 |
TestsInit();
|
|
1675 |
|
|
1676 |
TVolumeInfo volInfo;
|
|
1677 |
TInt r = TheFs.Volume(volInfo, gDrive);
|
131
|
1678 |
test_KErrNone(r);
|
0
|
1679 |
|
|
1680 |
TFullName extName;
|
|
1681 |
r = TheFs.ExtensionName(extName,gDrive, 0);
|
|
1682 |
if (r == KErrNone)
|
|
1683 |
{
|
|
1684 |
test.Printf(_L("File system extension present (%S)\n"), &extName);
|
|
1685 |
}
|
|
1686 |
|
|
1687 |
if ((volInfo.iDrive.iType == EMediaRam) ||
|
|
1688 |
((gDriveCacheFlags & (EFileCacheReadEnabled | EFileCacheReadOn)) == 0))
|
|
1689 |
{
|
|
1690 |
if (gRunPerformanceTests)
|
|
1691 |
{
|
|
1692 |
TestFileRead(EFileReadDirectIO);
|
|
1693 |
TestFileWrite(EFileWriteDirectIO);
|
|
1694 |
}
|
|
1695 |
TestsEnd();
|
|
1696 |
return;
|
|
1697 |
}
|
|
1698 |
|
|
1699 |
if (gRunUnitTests)
|
|
1700 |
UnitTests();
|
|
1701 |
|
|
1702 |
if (gRunManualTests)
|
|
1703 |
{
|
|
1704 |
ManualTests();
|
|
1705 |
}
|
|
1706 |
|
|
1707 |
if (gRunPerformanceTests)
|
|
1708 |
{
|
|
1709 |
#if defined(_DEBUG) || defined(_DEBUG_RELEASE)
|
|
1710 |
// turn OFF lock failure mode
|
|
1711 |
TBool simulatelockFailureMode = EFalse;
|
|
1712 |
r = controlIo(TheFs, gDrive, KControlIoSimulateLockFailureMode, simulatelockFailureMode);
|
131
|
1713 |
test_KErrNone(r);
|
0
|
1714 |
#endif
|
|
1715 |
|
|
1716 |
TestFileRead(EFileReadDirectIO);
|
|
1717 |
if (gDriveCacheFlags & (EFileCacheReadEnabled | EFileCacheReadOn))
|
|
1718 |
{
|
|
1719 |
TestFileRead(EFileReadBuffered | EFileReadAheadOff);
|
|
1720 |
TestFileRead(EFileReadBuffered | EFileReadAheadOn);
|
|
1721 |
}
|
|
1722 |
|
|
1723 |
TestFileWrite(EFileWriteDirectIO);
|
|
1724 |
|
|
1725 |
if (gDriveCacheFlags & (EFileCacheWriteEnabled | EFileCacheWriteOn))
|
|
1726 |
TestFileWrite(EFileWriteBuffered);
|
|
1727 |
|
|
1728 |
|
|
1729 |
#if defined(_DEBUG) || defined(_DEBUG_RELEASE)
|
|
1730 |
// turn lock failure mode back ON (if enabled)
|
|
1731 |
simulatelockFailureMode = ETrue;
|
|
1732 |
r = controlIo(TheFs, gDrive, KControlIoSimulateLockFailureMode, simulatelockFailureMode);
|
131
|
1733 |
test_KErrNone(r);
|
0
|
1734 |
#endif
|
|
1735 |
} // if (gRunPerformanceTests)
|
|
1736 |
|
|
1737 |
TestsEnd();
|
|
1738 |
}
|
|
1739 |
|
|
1740 |
|
|
1741 |
|
|
1742 |
LOCAL_C void DoTests(TInt aDrive)
|
|
1743 |
//
|
|
1744 |
// Do testing on aDrive
|
|
1745 |
//
|
|
1746 |
{
|
|
1747 |
|
|
1748 |
SetSessionPath(aDrive);
|
|
1749 |
|
|
1750 |
// !!! Disable platform security tests until we get the new APIs
|
|
1751 |
// if(User::Capability() & KCapabilityRoot)
|
|
1752 |
// CheckMountLFFS(TheFs,driveLetter);
|
|
1753 |
|
|
1754 |
User::After(1000000);
|
|
1755 |
|
|
1756 |
TInt r=TheFs.MkDirAll(gSessionPath);
|
|
1757 |
test_Value(r, r == KErrNone || r == KErrAlreadyExists);
|
|
1758 |
TheFs.ResourceCountMarkStart();
|
|
1759 |
|
|
1760 |
TRAP(r,CallTestsL());
|
|
1761 |
test_KErrNone(r);
|
|
1762 |
|
|
1763 |
TheFs.ResourceCountMarkEnd();
|
|
1764 |
}
|
|
1765 |
|
|
1766 |
|
|
1767 |
void Format(TInt aDrive)
|
|
1768 |
//
|
|
1769 |
// Format current drive
|
|
1770 |
//
|
|
1771 |
{
|
|
1772 |
|
|
1773 |
test.Next(_L("Format"));
|
|
1774 |
TBuf<4> driveBuf=_L("?:\\");
|
|
1775 |
driveBuf[0]=(TText)(aDrive+'A');
|
|
1776 |
RFormat format;
|
|
1777 |
TInt count;
|
|
1778 |
TInt r=format.Open(TheFs,driveBuf,EQuickFormat,count);
|
|
1779 |
//TInt r=format.Open(TheFs,driveBuf,EFullFormat,count);
|
|
1780 |
test.Printf(_L("RFormat::Open() returned %d\n"), r);
|
|
1781 |
test_KErrNone(r);
|
|
1782 |
while(count)
|
|
1783 |
{
|
|
1784 |
TInt r=format.Next(count);
|
|
1785 |
test_KErrNone(r);
|
|
1786 |
}
|
|
1787 |
format.Close();
|
|
1788 |
}
|
|
1789 |
|
|
1790 |
GLDEF_C TInt E32Main()
|
|
1791 |
//
|
|
1792 |
// Test with drive nearly full
|
|
1793 |
//
|
|
1794 |
{
|
|
1795 |
|
|
1796 |
CTrapCleanup* cleanup;
|
|
1797 |
cleanup=CTrapCleanup::New();
|
|
1798 |
|
|
1799 |
__UHEAP_MARK;
|
|
1800 |
|
|
1801 |
TBool parseOk = parseCommandLine();
|
|
1802 |
if (!parseOk)
|
|
1803 |
User::Leave(KErrNotSupported);
|
|
1804 |
|
|
1805 |
|
|
1806 |
TInt r = TheFs.Connect();
|
|
1807 |
test_KErrNone(r);
|
|
1808 |
|
|
1809 |
r=TheFs.CharToDrive(gDriveToTest,gDrive);
|
|
1810 |
test_KErrNone(r);
|
|
1811 |
|
|
1812 |
#if !defined(__WINS__)
|
|
1813 |
#if defined(_DEBUG) || defined(_DEBUG_RELEASE)
|
|
1814 |
test.Start(_L("Check that the rom is paged"));
|
|
1815 |
TRomHeader* romHeader = (TRomHeader*)UserSvr::RomHeaderAddress();
|
|
1816 |
if (romHeader->iPageableRomStart != NULL)
|
|
1817 |
{
|
|
1818 |
test.Printf(_L("ROM is paged\n"));
|
|
1819 |
gRomPaged = ETrue;
|
|
1820 |
}
|
|
1821 |
#endif
|
|
1822 |
#endif
|
|
1823 |
|
|
1824 |
// Get the TFileCacheFlags for this drive
|
|
1825 |
r = TheFs.Volume(gVolInfo, gDrive);
|
|
1826 |
if (r == KErrNotReady)
|
|
1827 |
{
|
|
1828 |
TDriveInfo info;
|
|
1829 |
TInt err = TheFs.Drive(info,gDrive);
|
|
1830 |
test_KErrNone(err);
|
|
1831 |
if (info.iType == EMediaNotPresent)
|
|
1832 |
test.Printf(_L("%c: Medium not present - cannot perform test.\n"), (TUint)gDriveToTest);
|
|
1833 |
else
|
|
1834 |
test.Printf(_L("medium found (type %d) but drive %c: not ready\nPrevious test may have hung; else, check hardware.\n"), (TInt)info.iType, (TUint)gDriveToTest);
|
|
1835 |
}
|
|
1836 |
else if (r == KErrCorrupt)
|
|
1837 |
{
|
|
1838 |
test.Printf(_L("%c: Media corruption; previous test may have aborted; else, check hardware\n"), (TUint)gDriveToTest);
|
|
1839 |
}
|
|
1840 |
test_KErrNone(r);
|
|
1841 |
gDriveCacheFlags = gVolInfo.iFileCacheFlags;
|
|
1842 |
test.Printf(_L("DriveCacheFlags for drive %C = %08X\n"), (TInt) gDriveToTest, gDriveCacheFlags);
|
|
1843 |
|
|
1844 |
#if defined(_DEBUG) || defined(_DEBUG_RELEASE)
|
|
1845 |
PrintFileCacheConfig(gFileCacheConfig, gDrive);
|
|
1846 |
|
|
1847 |
if (gDisplayCacheFlags)
|
|
1848 |
{
|
|
1849 |
test.Printf(_L("Press any key...\n"));
|
|
1850 |
test.Getch();
|
|
1851 |
}
|
|
1852 |
|
|
1853 |
if (gWriteCacheFlags)
|
|
1854 |
{
|
|
1855 |
test.Printf(_L("Writing DriveCacheFlags for drive %C = %08X\n"), (TInt) gDriveToTest, gDriveCacheFlags);
|
|
1856 |
r = controlIo(TheFs,gDrive, KControlIoFileCacheFlagsWrite, gDriveCacheFlags);
|
131
|
1857 |
test_KErrNone(r);
|
0
|
1858 |
}
|
|
1859 |
#endif
|
|
1860 |
|
|
1861 |
if (gRunTests)
|
|
1862 |
{
|
|
1863 |
test.Title();
|
|
1864 |
|
|
1865 |
|
|
1866 |
test.Start(_L("Starting tests..."));
|
|
1867 |
|
|
1868 |
if ((gVolInfo.iDrive.iMediaAtt & KMediaAttFormattable))
|
|
1869 |
Format(gDrive);
|
|
1870 |
|
|
1871 |
//TheFs.SetDebugRegister(KCACHE);
|
|
1872 |
DoTests(gDrive);
|
|
1873 |
//TheFs.SetDebugRegister(0);
|
|
1874 |
test.End();
|
|
1875 |
// }
|
|
1876 |
}
|
|
1877 |
|
|
1878 |
#if defined(_DEBUG) || defined(_DEBUG_RELEASE)
|
|
1879 |
TFileCacheStats fileCacheStats;
|
|
1880 |
PrintFileCacheStats(fileCacheStats);
|
|
1881 |
#endif
|
|
1882 |
|
|
1883 |
TheFs.Close();
|
|
1884 |
test.Close();
|
|
1885 |
__UHEAP_MARKEND;
|
|
1886 |
delete cleanup;
|
|
1887 |
return(KErrNone);
|
|
1888 |
}
|