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