|
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_dircache.cpp |
|
15 // |
|
16 // |
|
17 #define __E32TEST_EXTENSION__ |
|
18 #include <f32file.h> |
|
19 #include <f32fsys.h> |
|
20 #include <e32test.h> |
|
21 #include <f32dbg.h> |
|
22 #include "t_server.h" |
|
23 #include "t_chlffs.h" |
|
24 #include "f32_test_utils.h" |
|
25 #include "fat_utils.h" |
|
26 #include "d_pagestress.h" |
|
27 |
|
28 RTest test(_L("T_DIRCACHE")); |
|
29 |
|
30 /* |
|
31 * This whole test execute on UDEB mode only. |
|
32 */ |
|
33 #if defined(_DEBUG) || defined(_DEBUG_RELEASE) |
|
34 |
|
35 TInt gDrive=-1; |
|
36 const TInt32 KDef_KLeafDirCacheSize = 32; // default leaf dir cache number |
|
37 const TInt32 KDef_DynamicDirCacheMinInBytes = 128 << 10; // default minimum fat dir cache size in bytes |
|
38 const TInt32 KDef_DynamicDirCacheMaxInBytes = 256 << 10; // default maximum fat dir cache size in bytes |
|
39 const TInt32 KDef_MaxDynamicDirCachePageSzLog2 = 14; // default value for directory cache single page |
|
40 // maximal size Log2, 2^14 (16K) by default |
|
41 const TInt32 KMaxThreadCount = 1; // the maximum number of multiple threads that can |
|
42 // access dir cache concurrently. |
|
43 const TInt32 KSegmentSize = 1 << 12; // the smallest memory unit that Kernel manages |
|
44 |
|
45 template <class C> |
|
46 TInt controlIo(RFs &fs, TInt drv, TInt fkn, C &c) |
|
47 { |
|
48 TPtr8 ptrC((TUint8 *)&c, sizeof(C), sizeof(C)); |
|
49 |
|
50 TInt r = fs.ControlIo(drv, fkn, ptrC); |
|
51 |
|
52 return r; |
|
53 } |
|
54 |
|
55 // See f32\sfile\sf_memory_man.cpp for the default value settings |
|
56 const TInt KDefaultGlobalCacheMemorySize = (8 << 10) << 10; |
|
57 const TInt KDefaultLowMemoryThreshold = 10; |
|
58 //---------------------------------------------------------------------------------------------- |
|
59 //@SYMTestCaseID PBASE-XXXX |
|
60 //@SYMTestType FT |
|
61 //@SYMPREQ PREQ1885 |
|
62 //@SYMTestCaseDesc Check global cache settings. The global cache should be either: |
|
63 // 1. 0 (disabled) |
|
64 // 2. no less than the sum of all per-drive settings |
|
65 //---------------------------------------------------------------------------------------------- |
|
66 void TestGlobalSettings() |
|
67 { |
|
68 test.Next(_L("Test global cache settings")); |
|
69 // read global cache settings from estart.txt |
|
70 TGlobalCacheConfig globalCacheConfig; |
|
71 TInt r = controlIo(TheFs,gDrive, KControlIoGlobalCacheConfig, globalCacheConfig); |
|
72 test_KErrNone(r); |
|
73 test_Value (globalCacheConfig.iGlobalCacheSizeInBytes, |
|
74 globalCacheConfig.iGlobalCacheSizeInBytes > 0 || globalCacheConfig.iGlobalCacheSizeInBytes == KErrNotFound); |
|
75 test_Value (globalCacheConfig.iGlobalLowMemoryThreshold, |
|
76 globalCacheConfig.iGlobalLowMemoryThreshold >= 0 || globalCacheConfig.iGlobalLowMemoryThreshold == KErrNotFound); |
|
77 |
|
78 const TInt32 globalCacheSize = globalCacheConfig.iGlobalCacheSizeInBytes > 0 ? |
|
79 globalCacheConfig.iGlobalCacheSizeInBytes : KDefaultGlobalCacheMemorySize; |
|
80 |
|
81 // test if global cache is enabled, it is configured in the way that its figure is no less |
|
82 // than the sum of per-drive max size settings (taking default values into account). |
|
83 TInt32 sumDirCacheMaxSize = 0; |
|
84 for (TInt i = 0; i < KMaxDrives; i++) |
|
85 { |
|
86 TBuf<0x20> fsName; |
|
87 r = TheFs.FileSystemName(fsName, i); |
|
88 |
|
89 if (r == KErrNone && (F32_Test_Utils::Is_Fat(TheFs, i) || F32_Test_Utils::Is_ExFat(TheFs, i))) |
|
90 { |
|
91 test.Printf(_L("drive[%C:] file system: (\"%S\")\n"), 'A' + i, &fsName); |
|
92 TDirCacheConfig dirCacheConfig; |
|
93 r = controlIo(TheFs,gDrive, KControlIoDirCacheConfig, dirCacheConfig); |
|
94 test_KErrNone(r); |
|
95 if(dirCacheConfig.iDirCacheSizeMax > 0) |
|
96 { |
|
97 sumDirCacheMaxSize += (dirCacheConfig.iDirCacheSizeMax > KDef_DynamicDirCacheMaxInBytes ? dirCacheConfig.iDirCacheSizeMax : KDef_DynamicDirCacheMaxInBytes); |
|
98 } |
|
99 else |
|
100 { |
|
101 sumDirCacheMaxSize += KDef_DynamicDirCacheMaxInBytes; |
|
102 } |
|
103 test.Printf(_L("++sumDirCacheMaxSize = %d\n"), sumDirCacheMaxSize); |
|
104 } |
|
105 } |
|
106 test_Compare(globalCacheSize, >=, sumDirCacheMaxSize); |
|
107 } |
|
108 |
|
109 //---------------------------------------------------------------------------------------------- |
|
110 //@SYMTestCaseID PBASE-XXXX |
|
111 //@SYMTestType FT |
|
112 //@SYMPREQ PREQ1885 |
|
113 //@SYMTestCaseDesc Test current drive's dir cache configurations, the current dir cache info should |
|
114 // match the configurations read from estart.txt file. |
|
115 //---------------------------------------------------------------------------------------------- |
|
116 void TestDirCacheSettings() |
|
117 { |
|
118 test.Next(_L("Test current drive's dir cache settings")); |
|
119 |
|
120 // test global cache config is ON |
|
121 TGlobalCacheConfig globalCacheConfig; |
|
122 TInt r = controlIo(TheFs,gDrive, KControlIoGlobalCacheConfig, globalCacheConfig); |
|
123 test_KErrNone(r); |
|
124 test_Value (globalCacheConfig.iGlobalCacheSizeInBytes, |
|
125 globalCacheConfig.iGlobalCacheSizeInBytes > 0 || globalCacheConfig.iGlobalCacheSizeInBytes == KErrNotFound); |
|
126 test_Value (globalCacheConfig.iGlobalLowMemoryThreshold, |
|
127 globalCacheConfig.iGlobalLowMemoryThreshold >= 0 || globalCacheConfig.iGlobalLowMemoryThreshold == KErrNotFound); |
|
128 |
|
129 // test global cache info is corresponding to the configurations |
|
130 TGlobalCacheInfo globalCacheInfo; |
|
131 r = controlIo(TheFs,gDrive, KControlIoGlobalCacheInfo, globalCacheInfo); |
|
132 test_KErrNone(r); |
|
133 |
|
134 if (globalCacheConfig.iGlobalCacheSizeInBytes == KErrNotFound) |
|
135 { |
|
136 test_Equal(KDefaultGlobalCacheMemorySize, globalCacheInfo.iGlobalCacheSizeInBytes); |
|
137 } |
|
138 else |
|
139 { |
|
140 test_Equal(globalCacheConfig.iGlobalCacheSizeInBytes, globalCacheInfo.iGlobalCacheSizeInBytes); |
|
141 } |
|
142 |
|
143 if (globalCacheConfig.iGlobalLowMemoryThreshold == KErrNotFound) |
|
144 { |
|
145 test_Equal(KDefaultLowMemoryThreshold, globalCacheInfo.iGlobalLowMemoryThreshold); |
|
146 } |
|
147 else |
|
148 { |
|
149 test_Equal(globalCacheConfig.iGlobalLowMemoryThreshold, globalCacheInfo.iGlobalLowMemoryThreshold); |
|
150 } |
|
151 |
|
152 // read per-drive settings from estart.txt |
|
153 TDirCacheConfig dirCacheConfig; |
|
154 r = controlIo(TheFs,gDrive, KControlIoDirCacheConfig, dirCacheConfig); |
|
155 test_KErrNone(r); |
|
156 test_Value (dirCacheConfig.iLeafDirCacheSize, |
|
157 dirCacheConfig.iLeafDirCacheSize >= 0 || dirCacheConfig.iLeafDirCacheSize == KErrNotFound); |
|
158 test_Value (dirCacheConfig.iDirCacheSizeMin, |
|
159 dirCacheConfig.iDirCacheSizeMin >= 0 || dirCacheConfig.iDirCacheSizeMin == KErrNotFound); |
|
160 test_Value (dirCacheConfig.iDirCacheSizeMax, |
|
161 dirCacheConfig.iDirCacheSizeMax >= 0 || dirCacheConfig.iDirCacheSizeMax == KErrNotFound); |
|
162 |
|
163 // caculate expected settings according to the readings from estart.txt |
|
164 if (dirCacheConfig.iLeafDirCacheSize == 0) |
|
165 dirCacheConfig.iLeafDirCacheSize = 1; |
|
166 if (dirCacheConfig.iLeafDirCacheSize == KErrNotFound) |
|
167 dirCacheConfig.iLeafDirCacheSize = KDef_KLeafDirCacheSize; |
|
168 if (dirCacheConfig.iDirCacheSizeMin < KDef_DynamicDirCacheMinInBytes) |
|
169 dirCacheConfig.iDirCacheSizeMin = KDef_DynamicDirCacheMinInBytes; |
|
170 if (dirCacheConfig.iDirCacheSizeMax < KDef_DynamicDirCacheMaxInBytes) |
|
171 dirCacheConfig.iDirCacheSizeMax = KDef_DynamicDirCacheMaxInBytes; |
|
172 |
|
173 TVolumeIOParamInfo ioParam; |
|
174 r = TheFs.VolumeIOParam(gDrive, ioParam); |
|
175 test_KErrNone(r); |
|
176 const TInt32 KClusterSize = ioParam.iClusterSize; |
|
177 test.Printf(_L("DRV[%C:] cluster = %d\n"), gDrive + 'A', ioParam.iClusterSize); |
|
178 |
|
179 const TInt32 KDefMaxCachePageSize = 1 << KDef_MaxDynamicDirCachePageSzLog2; |
|
180 const TInt32 KPageSizeInData = KClusterSize < KDefMaxCachePageSize ? KClusterSize : KDefMaxCachePageSize; |
|
181 const TInt32 KPageSizeInMem = KPageSizeInData < KSegmentSize ? KSegmentSize : KPageSizeInData; |
|
182 const TInt32 KCacheSizeMinInPages = dirCacheConfig.iDirCacheSizeMin / KPageSizeInMem; |
|
183 const TInt32 KCacheSizeMaxInPages = dirCacheConfig.iDirCacheSizeMax / KPageSizeInMem; |
|
184 const TInt32 KUnlockedPageNum = 0; |
|
185 |
|
186 // remount drive, get current dir cache info and test |
|
187 r = F32_Test_Utils::RemountFS (TheFs, CurrentDrive(), NULL); |
|
188 test_KErrNone(r); |
|
189 |
|
190 TDirCacheInfo dirCacheInfo; |
|
191 r = controlIo(TheFs,gDrive, KControlIoDirCacheInfo, dirCacheInfo); |
|
192 test_KErrNone(r); |
|
193 |
|
194 test_Equal(KSegmentSize, dirCacheInfo.iMemorySegmentSize); |
|
195 test_Equal(KPageSizeInMem, dirCacheInfo.iPageSizeInMemory); |
|
196 test_Equal(KPageSizeInData, dirCacheInfo.iPageSizeInData); |
|
197 test_Equal(KCacheSizeMinInPages, dirCacheInfo.iMinCacheSizeInPages); |
|
198 test_Equal(KCacheSizeMaxInPages, dirCacheInfo.iMaxCacheSizeInPages); |
|
199 test_Equal(KMaxThreadCount, dirCacheInfo.iLockedPageNumber); |
|
200 test_Equal(KUnlockedPageNum, dirCacheInfo.iUnlockedPageNumber); |
|
201 } |
|
202 |
|
203 //---------------------------------------------------------------------------------------------- |
|
204 //@SYMTestCaseID PBASE-XXXX |
|
205 //@SYMTestType FT |
|
206 //@SYMPREQ PREQ1885 |
|
207 //@SYMTestCaseDesc Test populating dir cache under normal memory conditions. |
|
208 //---------------------------------------------------------------------------------------------- |
|
209 void TestPopulateCache() |
|
210 { |
|
211 test.Next(_L("Test populating dir cache under normal memory conditions")); |
|
212 |
|
213 CFileMan* fileMan = CFileMan::NewL(TheFs); |
|
214 test_NotNull(fileMan); |
|
215 TInt r = fileMan->RmDir(_L("\\TEST_DIRCACHE\\")); |
|
216 test_Value(r, r==KErrNone || r==KErrPathNotFound); |
|
217 |
|
218 // remount drive, get current dir cache info |
|
219 r = F32_Test_Utils::RemountFS (TheFs, CurrentDrive(), NULL); |
|
220 test_KErrNone(r); |
|
221 |
|
222 /* |
|
223 * Test populating dir cache |
|
224 */ |
|
225 TVolumeIOParamInfo ioParam; |
|
226 r = TheFs.VolumeIOParam(gDrive, ioParam); |
|
227 test_KErrNone(r); |
|
228 const TInt32 KClusterSize = ioParam.iClusterSize; |
|
229 |
|
230 TFileName dirPath = _L("\\TEST_DIRCACHE\\"); |
|
231 r = TheFs.MkDirAll(dirPath); |
|
232 test_KErrNone(r); |
|
233 |
|
234 TDirCacheInfo dirCacheInfo; |
|
235 r = controlIo(TheFs,gDrive, KControlIoDirCacheInfo, dirCacheInfo); |
|
236 test_KErrNone(r); |
|
237 |
|
238 // this calculation is for volumes that have a large cluster size, larger than the allowed maximum |
|
239 // page size. on this case, creating a new directory will generate two or more new pages in the |
|
240 // dir cache |
|
241 const TUint pagesPerDir = KClusterSize > dirCacheInfo.iPageSizeInMemory ? |
|
242 KClusterSize / dirCacheInfo.iPageSizeInMemory : 1; |
|
243 |
|
244 // should be KMaxThreadCount + root dir (1 page) + "\\TEST_DIRCACHE\\" (number of pages that are |
|
245 // needed for new directories, i.e. pagesPerDir) |
|
246 test_Equal(KMaxThreadCount + 1 + pagesPerDir, dirCacheInfo.iLockedPageNumber); |
|
247 |
|
248 const TInt initialUnlockedPage = dirCacheInfo.iUnlockedPageNumber; |
|
249 |
|
250 const TInt createdNewDirs = dirCacheInfo.iMinCacheSizeInPages - dirCacheInfo.iLockedPageNumber; |
|
251 // create directories so that it grows to KCacheSizeMinInPages |
|
252 for (TInt i = 1; i <= createdNewDirs; i++) |
|
253 { |
|
254 dirPath = _L("\\TEST_DIRCACHE\\"); |
|
255 TFileName dirName; |
|
256 dirName.Format(_L("DIR%d\\"), i); |
|
257 dirPath += dirName; |
|
258 r = TheFs.MkDirAll(dirPath); |
|
259 test_KErrNone(r); |
|
260 } |
|
261 |
|
262 const TInt KFatDirEntrySize = 32; |
|
263 const TInt subDirNum = dirCacheInfo.iMinCacheSizeInPages - dirCacheInfo.iLockedPageNumber; |
|
264 // calculate the extra pages needed for the newly created sub dir entries (plus the original |
|
265 // "." and ".." entries) |
|
266 TInt extraPagesForLeafdir = ((subDirNum + 2) * KFatDirEntrySize / dirCacheInfo.iPageSizeInData) - 1; |
|
267 if (((subDirNum + 2) * KFatDirEntrySize) % dirCacheInfo.iPageSizeInData > 0) |
|
268 extraPagesForLeafdir++; |
|
269 test.Printf(_L("!!Extra pages needed for leafdir = %d\n"), extraPagesForLeafdir); //kk |
|
270 |
|
271 r = controlIo(TheFs,gDrive, KControlIoDirCacheInfo, dirCacheInfo); |
|
272 test_KErrNone(r); |
|
273 r = controlIo(TheFs,gDrive, 15, dirCacheInfo); |
|
274 test_KErrNone(r); |
|
275 |
|
276 test_Equal(dirCacheInfo.iMinCacheSizeInPages, dirCacheInfo.iLockedPageNumber); |
|
277 |
|
278 const TInt maxUnlockedPage = dirCacheInfo.iMaxCacheSizeInPages - dirCacheInfo.iMinCacheSizeInPages; |
|
279 // calculating the expected unlocked page number here. |
|
280 TInt newUnlockedPage = initialUnlockedPage; |
|
281 newUnlockedPage += extraPagesForLeafdir; // if any extra pages are created for the leafdir |
|
282 newUnlockedPage += createdNewDirs * (pagesPerDir - 1); // if more than one page is needed for each dir creation |
|
283 test_Equal((newUnlockedPage > maxUnlockedPage ? maxUnlockedPage : newUnlockedPage), dirCacheInfo.iUnlockedPageNumber); |
|
284 |
|
285 // create directories so that it grows to KCacheSizeMinInPages + KCacheSizeMaxInPages |
|
286 if (dirCacheInfo.iMaxCacheSizeInPages > dirCacheInfo.iMinCacheSizeInPages) |
|
287 { |
|
288 for (TInt i = 1; i <= dirCacheInfo.iMaxCacheSizeInPages - dirCacheInfo.iMinCacheSizeInPages; i++) |
|
289 { |
|
290 dirPath = _L("\\TEST_DIRCACHE\\"); |
|
291 TFileName dirName; |
|
292 dirName.Format(_L("DIR_UNLOCKED%d\\"), i); |
|
293 dirPath += dirName; |
|
294 r = TheFs.MkDirAll(dirPath); |
|
295 test_KErrNone(r); |
|
296 } |
|
297 r = controlIo(TheFs,gDrive, KControlIoDirCacheInfo, dirCacheInfo); |
|
298 test_KErrNone(r); |
|
299 r = controlIo(TheFs,gDrive, 15, dirCacheInfo); |
|
300 test_KErrNone(r); |
|
301 |
|
302 test_Equal(dirCacheInfo.iMinCacheSizeInPages, dirCacheInfo.iLockedPageNumber); |
|
303 |
|
304 test_Equal(dirCacheInfo.iMaxCacheSizeInPages - dirCacheInfo.iMinCacheSizeInPages, dirCacheInfo.iUnlockedPageNumber); |
|
305 } |
|
306 |
|
307 // create more directories and check that dir cache doesn't grow beyond KCacheSizeMaxInPages |
|
308 for (TInt j = 1; j <= dirCacheInfo.iMinCacheSizeInPages; j++) |
|
309 { |
|
310 dirPath = _L("\\TEST_DIRCACHE\\"); |
|
311 TFileName dirName; |
|
312 dirName.Format(_L("DIR_MORE%d\\"), j); |
|
313 dirPath += dirName; |
|
314 r = TheFs.MkDirAll(dirPath); |
|
315 test_KErrNone(r); |
|
316 } |
|
317 r = controlIo(TheFs,gDrive, KControlIoDirCacheInfo, dirCacheInfo); |
|
318 test_KErrNone(r); |
|
319 r = controlIo(TheFs,gDrive, 15, dirCacheInfo); |
|
320 test_KErrNone(r); |
|
321 |
|
322 test_Equal(dirCacheInfo.iMinCacheSizeInPages, dirCacheInfo.iLockedPageNumber); |
|
323 test_Equal(dirCacheInfo.iMaxCacheSizeInPages - dirCacheInfo.iMinCacheSizeInPages, dirCacheInfo.iUnlockedPageNumber); |
|
324 |
|
325 r = controlIo(TheFs,gDrive, KControlIoDirCacheInfo, dirCacheInfo); |
|
326 test_KErrNone(r); |
|
327 |
|
328 r = fileMan->RmDir(_L("\\TEST_DIRCACHE\\")); |
|
329 test_KErrNone(r); |
|
330 |
|
331 delete fileMan; |
|
332 } |
|
333 |
|
334 //---------------------------------------------------------------------------------------------- |
|
335 //@SYMTestCaseID PBASE-XXXX |
|
336 //@SYMTestType FT |
|
337 //@SYMPREQ PREQ1885 |
|
338 //@SYMTestCaseDesc Test simulating low memory condition. |
|
339 // 1. The cache should stop growing when it is at its minimum cache size in pages |
|
340 // 2. The cache should function properly when it stops simulating low memory condition |
|
341 //---------------------------------------------------------------------------------------------- |
|
342 void TestSimulatingLowMemory() |
|
343 { |
|
344 // remount drive, get current dir cache info and test |
|
345 test.Next(_L("Test dir cache growth when simulating low memory condition")); |
|
346 |
|
347 CFileMan* fileMan = CFileMan::NewL(TheFs); |
|
348 test(fileMan != NULL); |
|
349 TInt r = fileMan->RmDir(_L("\\TEST_DIRCACHE\\")); |
|
350 test_Value(r, r==KErrNone || r==KErrPathNotFound); |
|
351 |
|
352 r = F32_Test_Utils::RemountFS (TheFs, CurrentDrive(), NULL); |
|
353 test_KErrNone(r); |
|
354 |
|
355 r = TheFs.ControlIo(gDrive, KControlIoSimulateMemoryLow); |
|
356 test_KErrNone(r); |
|
357 |
|
358 /* |
|
359 * Test populating dir cache |
|
360 */ |
|
361 TFileName dirPath = _L("\\TEST_DIRCACHE\\"); |
|
362 r = TheFs.MkDirAll(dirPath); |
|
363 test_KErrNone(r); |
|
364 |
|
365 TDirCacheInfo dirCacheInfo; |
|
366 r = controlIo(TheFs,gDrive, KControlIoDirCacheInfo, dirCacheInfo); |
|
367 test_KErrNone(r); |
|
368 |
|
369 // create directories so that it grows to KCacheSizeMaxInPages |
|
370 for (TInt i = 1; i <= dirCacheInfo.iMaxCacheSizeInPages; i++) |
|
371 { |
|
372 dirPath = _L("\\TEST_DIRCACHE\\"); |
|
373 TFileName dirName; |
|
374 dirName.Format(_L("DIR%d\\"), i); |
|
375 dirPath += dirName; |
|
376 r = TheFs.MkDirAll(dirPath); |
|
377 test_KErrNone(r); |
|
378 } |
|
379 |
|
380 r = controlIo(TheFs,gDrive, KControlIoDirCacheInfo, dirCacheInfo); |
|
381 test_KErrNone(r); |
|
382 |
|
383 test_Equal(dirCacheInfo.iMinCacheSizeInPages, dirCacheInfo.iLockedPageNumber); |
|
384 test_Equal(0, dirCacheInfo.iUnlockedPageNumber); |
|
385 |
|
386 r = fileMan->RmDir(_L("\\TEST_DIRCACHE\\")); |
|
387 test_KErrNone(r); |
|
388 |
|
389 // test when stop simulating the low memory condition, cache grows normally |
|
390 test.Next(_L("Test dir cache growth when stop simulating low memory condition")); |
|
391 r = TheFs.ControlIo(gDrive, KControlIoStopSimulateMemoryLow); |
|
392 test_KErrNone(r); |
|
393 |
|
394 r = F32_Test_Utils::RemountFS (TheFs, CurrentDrive(), NULL); |
|
395 test_KErrNone(r); |
|
396 |
|
397 /* |
|
398 * Test populating dir cache |
|
399 */ |
|
400 dirPath = _L("\\TEST_DIRCACHE\\"); |
|
401 r = TheFs.MkDirAll(dirPath); |
|
402 test_KErrNone(r); |
|
403 |
|
404 // create directories so that it grows to KCacheSizeMaxInPages |
|
405 for (TInt j = 1; j <= dirCacheInfo.iMaxCacheSizeInPages; j++) |
|
406 { |
|
407 dirPath = _L("\\TEST_DIRCACHE\\"); |
|
408 TFileName dirName; |
|
409 dirName.Format(_L("DIR%d\\"), j); |
|
410 dirPath += dirName; |
|
411 r = TheFs.MkDirAll(dirPath); |
|
412 test_KErrNone(r); |
|
413 } |
|
414 |
|
415 r = controlIo(TheFs,gDrive, KControlIoDirCacheInfo, dirCacheInfo); |
|
416 test_KErrNone(r); |
|
417 |
|
418 test_Equal(dirCacheInfo.iMinCacheSizeInPages, dirCacheInfo.iLockedPageNumber); |
|
419 test_Equal(dirCacheInfo.iMaxCacheSizeInPages - dirCacheInfo.iMinCacheSizeInPages, dirCacheInfo.iUnlockedPageNumber); |
|
420 |
|
421 r = fileMan->RmDir(_L("\\TEST_DIRCACHE\\")); |
|
422 test_KErrNone(r); |
|
423 |
|
424 delete fileMan; |
|
425 } |
|
426 |
|
427 //---------------------------------------------------------------------------------------------- |
|
428 //@SYMTestCaseID PBASE-XXXX |
|
429 //@SYMTestType FT |
|
430 //@SYMPREQ PREQ1885 |
|
431 //@SYMTestCaseDesc Test low memory threshold on hardware platforms |
|
432 // 1. Stress the system memory to below the low memory threshold configured |
|
433 // 2. The cache should stop growing when it is at its minimum cache size in pages |
|
434 // 3. Resume the system memory before step 1. |
|
435 // 2. The cache should function properly when it stops simulating low memory condition |
|
436 //---------------------------------------------------------------------------------------------- |
|
437 void TestLowMemoryHW() |
|
438 { |
|
439 test.Next(_L("Test low memory threshold on hardware")); |
|
440 #if !defined(__WINS__) |
|
441 |
|
442 CFileMan* fileMan = CFileMan::NewL(TheFs); |
|
443 test_NotNull(fileMan); |
|
444 TInt r = fileMan->RmDir(_L("\\TEST_DIRCACHE\\")); |
|
445 test_Value(r, r==KErrNone || r==KErrPathNotFound); |
|
446 |
|
447 r = F32_Test_Utils::RemountFS (TheFs, CurrentDrive(), NULL); |
|
448 test_KErrNone(r); |
|
449 |
|
450 RPageStressTestLdd PagestressLdd; |
|
451 TMemoryInfoV1Buf memInfo; |
|
452 r = UserHal::MemoryInfo(memInfo); |
|
453 test_KErrNone(r); |
|
454 |
|
455 TGlobalCacheInfo globalCacheInfo; |
|
456 r = controlIo(TheFs,gDrive, KControlIoGlobalCacheInfo, globalCacheInfo); |
|
457 test_KErrNone(r); |
|
458 |
|
459 test.Printf(_L("Free RAM before setup %d\n"), memInfo().iFreeRamInBytes); |
|
460 const TReal lowMemThreshold = globalCacheInfo.iGlobalLowMemoryThreshold / 200.00; |
|
461 test.Printf(_L("Low memory threshold = %d%%\n"), globalCacheInfo.iGlobalLowMemoryThreshold); |
|
462 test.Printf(_L("Current memory available = %d%%\n"), lowMemThreshold * 100); |
|
463 |
|
464 const TInt totalRamInBytes = memInfo().iTotalRamInBytes; |
|
465 const TInt setupFreeRamInBytes = (TInt) (lowMemThreshold * totalRamInBytes); |
|
466 const TInt setupFreeRamInPages = setupFreeRamInBytes / KSegmentSize; |
|
467 |
|
468 r = User::LoadLogicalDevice(KPageStressTestLddName); |
|
469 test_Value(r, r==KErrNone || r==KErrAlreadyExists); |
|
470 r = PagestressLdd.Open(); |
|
471 test_KErrNone(r); |
|
472 r = PagestressLdd.DoSetDebugFlag((TInt)ETrue); |
|
473 test_KErrNone(r); |
|
474 if (setupFreeRamInPages > 0 && setupFreeRamInBytes < totalRamInBytes) |
|
475 { |
|
476 r = PagestressLdd.DoConsumeRamSetup(setupFreeRamInPages, 1); |
|
477 test_KErrNone(r); |
|
478 r = UserHal::MemoryInfo(memInfo); |
|
479 test_KErrNone(r); |
|
480 test.Printf(_L("Free RAM after setup %d\n"), memInfo().iFreeRamInBytes); |
|
481 } |
|
482 else |
|
483 { |
|
484 test.Printf(_L("Current memory is already low: %d\n"), memInfo().iFreeRamInBytes); |
|
485 } |
|
486 |
|
487 /* |
|
488 * Test populating dir cache |
|
489 */ |
|
490 TFileName dirPath = _L("\\TEST_DIRCACHE\\"); |
|
491 r = TheFs.MkDirAll(dirPath); |
|
492 test_KErrNone(r); |
|
493 |
|
494 TDirCacheInfo dirCacheInfo; |
|
495 r = controlIo(TheFs,gDrive, KControlIoDirCacheInfo, dirCacheInfo); |
|
496 test_KErrNone(r); |
|
497 |
|
498 // create directories so that it grows to KCacheSizeMaxInPages |
|
499 for (TInt i = 1; i <= dirCacheInfo.iMaxCacheSizeInPages; i++) |
|
500 { |
|
501 dirPath = _L("\\TEST_DIRCACHE\\"); |
|
502 TFileName dirName; |
|
503 dirName.Format(_L("DIR%d\\"), i); |
|
504 dirPath += dirName; |
|
505 r = TheFs.MkDirAll(dirPath); |
|
506 test_KErrNone(r); |
|
507 } |
|
508 |
|
509 r = controlIo(TheFs,gDrive, KControlIoDirCacheInfo, dirCacheInfo); |
|
510 test_KErrNone(r); |
|
511 |
|
512 test_Equal(dirCacheInfo.iMinCacheSizeInPages, dirCacheInfo.iLockedPageNumber); |
|
513 test_Equal(0, dirCacheInfo.iUnlockedPageNumber); |
|
514 |
|
515 // release memory |
|
516 PagestressLdd.DoConsumeRamFinish(); |
|
517 PagestressLdd.Close(); |
|
518 r = User::FreeLogicalDevice(KPageStressTestLddName); |
|
519 test_KErrNone(r); |
|
520 |
|
521 r = UserHal::MemoryInfo(memInfo); |
|
522 test_KErrNone(r); |
|
523 test.Printf(_L("Free RAM after test %d\n"), memInfo().iFreeRamInBytes); |
|
524 |
|
525 r = fileMan->RmDir(_L("\\TEST_DIRCACHE\\")); |
|
526 test_KErrNone(r); |
|
527 delete fileMan; |
|
528 #else |
|
529 test.Printf(_L("This test step only runs on hardware!!\n")); |
|
530 #endif //#if !defined(__WINS__) |
|
531 } |
|
532 |
|
533 #endif // #if defined(_DEBUG) || defined(_DEBUG_RELEASE) |
|
534 |
|
535 GLDEF_C void CallTestsL() |
|
536 // |
|
537 // Test the file server. |
|
538 // |
|
539 { |
|
540 #if defined(_DEBUG) || defined(_DEBUG_RELEASE) |
|
541 TInt nRes=TheFs.CharToDrive(gDriveToTest, gDrive); |
|
542 test_KErrNone(nRes); |
|
543 |
|
544 TDriveInfo driveInfo; |
|
545 nRes = TheFs.Drive(driveInfo, gDrive); |
|
546 test.Printf(_L("MediaType: 0x%x\n"), driveInfo.iType); |
|
547 test_KErrNone(nRes); |
|
548 |
|
549 if (F32_Test_Utils::Is_Fat(TheFs, gDrive) && driveInfo.iType != EMediaRam) |
|
550 { |
|
551 nRes = F32_Test_Utils::FormatDrive(TheFs, gDrive, ETrue); |
|
552 test_KErrNone(nRes); |
|
553 |
|
554 F32_Test_Utils::PrintDrvInfo(TheFs, gDrive); |
|
555 |
|
556 TVolumeInfo v; |
|
557 TInt r=TheFs.Volume(v, CurrentDrive()); |
|
558 test_KErrNone(r); |
|
559 |
|
560 CreateTestDirectory(_L("\\F32-TST\\TDIRCACHE\\")); |
|
561 |
|
562 TestGlobalSettings(); |
|
563 TestDirCacheSettings(); |
|
564 TestPopulateCache(); |
|
565 TestSimulatingLowMemory(); |
|
566 TestLowMemoryHW(); |
|
567 |
|
568 DeleteTestDirectory(); |
|
569 } |
|
570 else |
|
571 { |
|
572 test.Printf(_L("This test executes on FAT drives and non-RAM media only!!\n")); |
|
573 } |
|
574 #else |
|
575 test.Printf(_L("This test executes on DEBUG mode only!!\n")); |
|
576 #endif //#if defined(_DEBUG) || defined(_DEBUG_RELEASE) |
|
577 } |
|
578 |
|
579 /* |
|
580 void TestReadEstart() |
|
581 { |
|
582 TDirCacheConfig dirCacheConfig; |
|
583 TInt r = controlIo(TheFs,gDrive, KControlIoDirCacheConfig, dirCacheConfig); |
|
584 test_KErrNone(r); |
|
585 test.Printf(_L("Dir cache: \n Drive %C \n iLeafDirCacheSize %d \n iDirCacheSizeMin %d \n iDirCacheSizeMax %d \n iGlobalCacheMemorySize %d \n iLowMemoryThreshold %%%d"), |
|
586 dirCacheConfig.iDrive + 'A', |
|
587 dirCacheConfig.iLeafDirCacheSize, |
|
588 dirCacheConfig.iDirCacheSizeMin, |
|
589 dirCacheConfig.iDirCacheSizeMax); |
|
590 } |
|
591 |
|
592 */ |
|
593 |
|
594 // const TInt KControlIoGlobalCacheConfig=KMaxTInt-21; |
|
595 // const TInt KControlIoGlobalCacheInfo=KMaxTInt-22; |
|
596 // const TInt KControlIoDirCacheConfig=KMaxTInt-23; |
|
597 // const TInt KControlIoDirCacheInfo=KMaxTInt-24; |
|
598 // |
|
599 //class TGlobalCacheConfig |
|
600 //class TGlobalCacheInfo |
|
601 //class TDirCacheConfig |
|
602 //class TDirCacheInfo |
|
603 |
|
604 // this test is for FAT only!! |
|
605 //if (F32_Test_Utils::Is_ExFat(TheFs, gDrive)) |
|
606 // { |
|
607 // // test cluster size |
|
608 // TVolumeIOParamInfo ioParam; |
|
609 // TInt r = TheFs.VolumeIOParam(gDrive, ioParam); |
|
610 // test.Printf(_L("TheFs.VolumeIOParam for EXFAT: (cluster = %d) = %d\n"), ioParam.iClusterSize, r); |
|
611 // } |
|
612 // |