First public contribution.
1 // Copyright (c) 2006-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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32test\debug\t_cache.cpp
16 // Performs cache checking in order to ensure it is running correctly.
17 // Runs automatically or as manual test. (Type "t_cache help" for details.)
22 // -Test1 - Displays cache properties.
23 // -Test2 - Gets thresholds.
24 // -Test3 - Sets thresholds.
25 // -Test4 - Compares different memory mappings of data.
26 // -Test5 - Compares different memory mappings of code.
27 // -Test6 - Tests Write Back mode.
28 // -Test7 - Tests cache maintenance functions
29 // It can also perform more specified tests if run manually:
30 // - t_cache info Test1 only
31 // - t_cache data <size_hex> Runs data chunk test (Test 4) with specified chunk size. For example,
32 // "t_cache data 10000" will run data chunk test against 64KB chunk.
33 // - t_cache code <size_hex> Runs code chunk test (Test 5) for specified chink size. For example,
34 // "t_cache code 10000" will run code chunk test against 64KB chunk.
35 // - t_cache data+<size_hex> Runs data chunk test for specified set of chunk sizes. For example,
36 // "t_cache data+1000" will perform data chunk test for sizes 4K, 8K,... up to 512K.
37 // - t_cache code+<size_hex> Runs code chunk test for specified set of sizes. For example,
38 // "t_cache code+1000" will perform code chunk test for sizes 4K, 8K,... up to 512K.
39 // - t_cache threshold Diplays thresholds for all caches on the platform.
40 // - t_cache threshold T P C H Sets new values for cache thresholds:
41 // - "T" specifies the type of cache to whose threshould are to be chenged:
42 // 1 for Instruction (or Unified) Cache.
43 // 2 for Data Cache (for ARMv7 and later, this is Point-of-Coherency threshold.
44 // 4 for XScale AltData Cache.
45 // 8 for Point-of-Unification Data Cache Threshold for ARMv7 and later platforms.
46 // 10 for L2 (L210 or XScale L2 cache)
47 // - "P" "C" & "H" are hex values for purge, clean & flush thresholds.
48 // For example: "t_cache 1 10000 10000 10000" sets 64KB for all thresholds in Instruction Cache.
49 // - t_cache usecase Runs particular use case tests.
50 // - t_cache help Displays the list of manual commands.
51 // Platforms/Drives/Compatibility:
52 // Hardware - ARM only (Manual). Not supported on emulator.
53 // Assumptions/Requirement/Pre-requisites:
54 // Failures and causes:
55 // Base Port information:
56 // d_cache.mmp to be built from the baseport.
63 //------------globals---------------------
64 LOCAL_D RTest test(_L("T_CACHE"));
65 _LIT(KPrintCacheInfos,"info");
66 _LIT(KTestData,"data");
67 _LIT(KTestCode,"code");
69 _LIT(KThreshold,"threshold");
70 _LIT(KIncremental,"+");
71 _LIT(KUseCase,"usecase");
73 RCacheTestDevice Device;
74 RCacheTestDevice::TCacheInfo CacheInfo;
75 TBuf<KCacheDescSize> TempBuff;
77 const TInt KDefaultDataSize = 0x20000;
78 const TInt KDefaultCodeSize = 0x804; //2K+4. Should be <= TestCodeFuncSize(). Otherwise, code test won't run against rom image.
79 const TInt KMaxChunkSize = 0x80000; //512KB Incremental tests limit
80 const TInt KWriteBackTestSizeSize = 0x4000; // Shouldn't go over cache thresholds (where purge becomes flush).
82 extern void DataSegmetTestFunct(void* aBase, TInt aSize);
84 /** Loads & opens LDD.*/
87 TInt r = User::LoadLogicalDevice(KCacheTestDriverName);
88 test( r==KErrNone || r==KErrAlreadyExists);
89 if((r = Device.Open())!=KErrNone)
91 User::FreeLogicalDevice(KCacheTestDriverName);
92 test.Printf(_L("Could not open LDD"));
97 /** Closes and unloads LDD.*/
101 User::FreeLogicalDevice(KCacheTestDriverName);
104 /** Get cache info from device driver. This will update CacheInfo global variable.*/
107 TInt r = Device.GetCacheInfo(CacheInfo);
111 //---------------------------------------------
112 //! @SYMTestCaseID MMU-T_CACHE-01
116 //! @SYMTestCaseDesc Displays cache properties.
117 //! @SYMTestExpectedResults KErrNone
118 //! @SYMTestPriority Low
119 //! @SYMTestStatus Implemented
120 //---------------------------------------------
125 test.Printf(_L("General Info:\n"));
126 TPtr ptr = CacheInfo.iDesc.Expand();
128 test.Printf(_L("CacheCount:%d, MaxCacheSize:%xH, MemoryRemapping:%d, OuterCache:%d\n"),CacheInfo.iCacheCount, CacheInfo.iMaxCacheSize, CacheInfo.iMemoryRemapping, CacheInfo.iOuterCache);
129 test.Printf(_L("DMAMemoryAlignement:%d\n"),CacheInfo.iDmaBufferAlignment);
132 test.Printf(_L("Per Level Info:\n"));
133 test.Printf(_L("Level\tData\tInstr\tSize(b)\tLine(b)\tWays\tSets\tDescription\n"));
135 for (i = 0; i<CacheInfo.iCacheCount; i++)
137 TempBuff.SetLength(0);
138 RCacheTestDevice::TCacheSingle& cs = CacheInfo.iCache[i];
139 TempBuff.Format(_L("%d\t%d\t%d\t%xH\t%xH\t%xH\t%xH\t"), cs.iLevel, cs.iData, cs.iCode, cs.iSize, cs.iLineSize, cs.iWays, cs.iSets);
140 ptr = cs.iDesc.Expand();
141 TempBuff.Append(ptr);
142 TempBuff.Append(_L("\n"));
143 test.Printf(TempBuff);
147 //---------------------------------------------
148 //! @SYMTestCaseID MMU-T_CACHE-02
150 //! @SYMPREQ PREQ1068
152 //! @SYMTestCaseDesc Gets thresholds.
153 //! @SYMTestActions Fetches Cache Thresholds from the driver.
154 //! @SYMTestExpectedResults KErrNone
155 //! @SYMTestPriority High
156 //! @SYMTestStatus Implemented
157 //---------------------------------------------
160 RCacheTestDevice::TThresholdInfo info;
162 test.Printf(_L("Cache: Purge Clear Flush\n"));
165 if (KErrNone == Device.GetThreshold(info))
166 test.Printf(_L("Instr:%6x %6x %6x\n"),info.iPurge,info.iClean,info.iFlush);
169 if (KErrNone == Device.GetThreshold(info))
170 test.Printf(_L("Data: %6x %6x %6x\n"),info.iPurge,info.iClean,info.iFlush);
173 if (KErrNone == Device.GetThreshold(info))
174 test.Printf(_L("AltD: %6x %6x %6x\n"),info.iPurge,info.iClean,info.iFlush);
177 if (KErrNone == Device.GetThreshold(info))
178 test.Printf(_L("D_IMB:%6x %6x %6x\n"),info.iPurge,info.iClean,info.iFlush);
181 if (KErrNone == Device.GetThreshold(info))
182 test.Printf(_L("L2: %6x %6x %6x\n"),info.iPurge,info.iClean,info.iFlush);
185 //---------------------------------------------
186 //! @SYMTestCaseID MMU-T_CACHE-03
188 //! @SYMPREQ PREQ1068
190 //! @SYMTestCaseDesc Sets thresholds.
191 //! @SYMTestActions Sets new values forr Cache Thresholds. Then, sets back the old values.
192 //! @SYMTestExpectedResults KErrNone
193 //! @SYMTestPriority High
194 //! @SYMTestStatus Implemented
195 //---------------------------------------------
199 RCacheTestDevice::TThresholdInfo info[5]; //for 5 types og cache
206 info[i].iCacheType= 1<<i;
207 returned[i] = Device.GetThreshold(info[i]);
213 if (returned[i] != KErrNone) continue; //not a valid cache type for running platform
218 test(KErrNone==Device.SetThreshold(info[i]));
221 //Put back the old values
224 if (returned[i] != KErrNone) continue; //not a valid cache type for running platform
228 test(KErrNone==Device.SetThreshold(info[i]));
230 test.Printf(_L(" ... %d caches present & tested\n"), tested);
235 void DoTest4(RCacheTestDevice::TCacheAttr aCacheAttr, RCacheTestDevice::TChunkTest& aDC, TInt& aTime1, TInt& aTime2)
237 aDC.iCacheAttr = aCacheAttr;
239 aDC.iShared = EFalse;
240 test(KErrNone==Device.TestDataChunk(aDC));
244 test(KErrNone==Device.TestDataChunk(aDC));
247 //---------------------------------------------
248 //! @SYMTestCaseID MMU-T_CACHE-04
252 //! @SYMTestCaseDesc Compares different memory mappings of data.
253 //! @SYMTestActions Runs the same performance test against data in the chunks with different cache attributes.
254 //! Also, runs the same test against data from user & kernel heaps.
255 //! @SYMTestExpectedResults KErrNone
256 //! @SYMTestPriority Low
257 //! @SYMTestStatus Implemented
258 //---------------------------------------------
259 void Test4(TInt aSize)
261 RCacheTestDevice::TChunkTest dC;
263 dC.iUseCase = 0; //not used
264 dC.iLoops = 0; //not used
265 TInt timeNS=0, timeS=0;
267 test.Printf(_L(" Time\n"));
268 test.Printf(_L("Mem_Type ActualMapAttr NotShared Shared\n"));
269 test.Printf(_L("----------------------------------------------\n"));
271 DoTest4(RCacheTestDevice::E_FullyBlocking, dC, timeNS, timeS);
272 test.Printf(_L("FullyBlocking %08xH\t%7d\t%7d\n"),dC.iActualMapAttr, timeNS, timeS);
273 DoTest4(RCacheTestDevice::E_Buffered_NC, dC, timeNS, timeS);
274 test.Printf(_L("Buffered_NC %08xH\t%7d\t%7d\n"),dC.iActualMapAttr, timeNS, timeS);
275 DoTest4(RCacheTestDevice::E_Buffered_C, dC, timeNS, timeS);
276 test.Printf(_L("Buffered_C %08xH\t%7d\t%7d\n"),dC.iActualMapAttr, timeNS, timeS);
279 DoTest4(RCacheTestDevice::E_InnerWT, dC, timeNS, timeS);
280 test.Printf(_L("InnerWT %08xH\t%7d\t%7d\n"),dC.iActualMapAttr, timeNS, timeS);
281 DoTest4(RCacheTestDevice::E_InnerWBRA, dC, timeNS, timeS);
282 test.Printf(_L("InnerWBRA %08xH\t%7d\t%7d\n"),dC.iActualMapAttr, timeNS, timeS);
283 DoTest4(RCacheTestDevice::E_InnerWB, dC, timeNS, timeS);
284 test.Printf(_L("InnerWB %08xH\t%7d\t%7d\n"),dC.iActualMapAttr, timeNS, timeS);
286 if(CacheInfo.iOuterCache)
288 DoTest4(RCacheTestDevice::E_OuterWT, dC, timeNS, timeS);
289 test.Printf(_L("OuterWT %08xH\t%7d\t%7d\n"),dC.iActualMapAttr, timeNS, timeS);
290 DoTest4(RCacheTestDevice::E_OuterWBRA, dC, timeNS, timeS);
291 test.Printf(_L("OuterWBRA %08xH\t%7d\t%7d\n"),dC.iActualMapAttr, timeNS, timeS);
292 DoTest4(RCacheTestDevice::E_OuterWB, dC, timeNS, timeS);
293 test.Printf(_L("OuterWB %08xH\t%7d\t%7d\n"),dC.iActualMapAttr, timeNS, timeS);
295 DoTest4(RCacheTestDevice::E_InOutWT, dC, timeNS, timeS);
296 test.Printf(_L("InOutWT %08xH\t%7d\t%7d\n"),dC.iActualMapAttr, timeNS, timeS);
297 DoTest4(RCacheTestDevice::E_InOutWBRA, dC, timeNS, timeS);
298 test.Printf(_L("InOutWBRA %08xH\t%7d\t%7d\n"),dC.iActualMapAttr, timeNS, timeS);
299 DoTest4(RCacheTestDevice::E_InOutWB, dC, timeNS, timeS);
300 test.Printf(_L("InOutWB %08xH\t%7d\t%7d\n"),dC.iActualMapAttr, timeNS, timeS);
304 DoTest4(RCacheTestDevice::E_StronglyOrder, dC, timeNS, timeS);
305 test.Printf(_L("StronglyOrder %08xH\t%7d\t%7d\n"),dC.iActualMapAttr, timeNS, timeS);
306 DoTest4(RCacheTestDevice::E_Device, dC, timeNS, timeS);
307 test.Printf(_L("Device %08xH\t%7d\t%7d\n"),dC.iActualMapAttr, timeNS, timeS);
308 DoTest4(RCacheTestDevice::E_Normal_Uncached, dC, timeNS, timeS);
309 test.Printf(_L("Normal_Uncached %08xH\t%7d\t%7d\n"),dC.iActualMapAttr, timeNS, timeS);
310 DoTest4(RCacheTestDevice::E_Normal_Cached, dC, timeNS, timeS);
311 test.Printf(_L("Normal_Cached %08xH\t%7d\t%7d\n"),dC.iActualMapAttr, timeNS, timeS);
313 if(CacheInfo.iMemoryRemapping)
315 DoTest4(RCacheTestDevice::E_KernelInternal4, dC, timeNS, timeS);
316 test.Printf(_L("KernelInternal4 %08xH\t%7d\t%7d\n"),dC.iActualMapAttr, timeNS, timeS);
317 DoTest4(RCacheTestDevice::E_PlatformSpecific5, dC, timeNS, timeS);
318 test.Printf(_L("PlatSpecific5 %08xH\t%7d\t%7d\n"),dC.iActualMapAttr, timeNS, timeS);
319 DoTest4(RCacheTestDevice::E_PlatformSpecific6, dC, timeNS, timeS);
320 test.Printf(_L("PlatSpecific6 %08xH\t%7d\t%7d\n"),dC.iActualMapAttr, timeNS, timeS);
321 DoTest4(RCacheTestDevice::E_PlatformSpecific7, dC, timeNS, timeS);
322 test.Printf(_L("PlatSpecific7 %08xH\t%7d\t%7d\n"),dC.iActualMapAttr, timeNS, timeS);
325 DoTest4(RCacheTestDevice::E_InnerWT_Remapped, dC, timeNS, timeS);
326 test.Printf(_L("InnerWT_Remap %08xH\t%7d\t%7d\n"),dC.iActualMapAttr, timeNS, timeS);
327 DoTest4(RCacheTestDevice::E_InnerWBRA_Remapped, dC, timeNS, timeS);
328 test.Printf(_L("InnerWBRA_Remap %08xH\t%7d\t%7d\n"),dC.iActualMapAttr, timeNS, timeS);
329 DoTest4(RCacheTestDevice::E_InnerWB_Remapped, dC, timeNS, timeS);
330 test.Printf(_L("InnerWB_Remap %08xH\t%7d\t%7d\n"),dC.iActualMapAttr, timeNS, timeS);
332 if(CacheInfo.iOuterCache)
334 DoTest4(RCacheTestDevice::E_OuterWT_Remapped, dC, timeNS, timeS);
335 test.Printf(_L("OuterWT_Remap %08xH\t%7d\t%7d\n"),dC.iActualMapAttr, timeNS, timeS);
336 DoTest4(RCacheTestDevice::E_OuterWBRA_Remapped, dC, timeNS, timeS);
337 test.Printf(_L("OuterWBRA_Remap %08xH\t%7d\t%7d\n"),dC.iActualMapAttr, timeNS, timeS);
338 DoTest4(RCacheTestDevice::E_OuterWB_Remapped, dC, timeNS, timeS);
339 test.Printf(_L("OuterWB_Remap %08xH\t%7d\t%7d\n"),dC.iActualMapAttr, timeNS, timeS);
341 DoTest4(RCacheTestDevice::E_InOutWT_Remapped, dC, timeNS, timeS);
342 test.Printf(_L("InOutWT_Remap %08xH\t%7d\t%7d\n"),dC.iActualMapAttr, timeNS, timeS);
343 DoTest4(RCacheTestDevice::E_InOutWBRA_Remapped, dC, timeNS, timeS);
344 test.Printf(_L("InOutWBRA_Remap %08xH\t%7d\t%7d\n"),dC.iActualMapAttr, timeNS, timeS);
345 DoTest4(RCacheTestDevice::E_InOutWB_Remapped, dC, timeNS, timeS);
346 test.Printf(_L("InOutWB_Remap %08xH\t%7d\t%7d\n"),dC.iActualMapAttr, timeNS, timeS);
350 //Run against kernel heap - allow the test to fail due to OOM
351 dC.iCacheAttr = RCacheTestDevice::E_Default;
352 TInt r = Device.TestDataChunk(dC);
353 if (r==KErrNone) test.Printf(_L("Kernel Heap ---------\t%7d\t-------\n"), dC.iTime);
354 else if (r==KErrNoMemory) test.Printf(_L("Kernel Heap Cannot allocate memory\n"));
357 //Run against user heap - allow the test to fail due to OOM
358 void* buffer = User::Alloc(dC.iSize);
361 test.Printf(_L("User Heap Cannot allocate memory\n"));
364 TInt time = User::NTickCount();
365 DataSegmetTestFunct(buffer , dC.iSize);
366 time = User::NTickCount() - time;
368 test.Printf(_L("User Heap ---------\t%7d\t-------\n"), time);
373 void DoTest5(RCacheTestDevice::TCacheAttr aCacheAttr, RCacheTestDevice::TChunkTest& aDC, TInt& aTime1, TInt& aTime2)
375 aDC.iCacheAttr = aCacheAttr;
377 aDC.iShared = EFalse;
378 test(KErrNone==Device.TestCodeChunk(aDC));
382 test(KErrNone==Device.TestCodeChunk(aDC));
385 //---------------------------------------------
386 //! @SYMTestCaseID MMU-T_CACHE-05
390 //! @SYMTestCaseDesc Compares different memory mappings of code.
391 //! @SYMTestActions Runs the same performance test against code in chunks with different cache attributes.
392 //! Also, runs the same test against code from rom..
393 //! @SYMTestExpectedResults KErrNone
394 //! @SYMTestPriority Low
395 //! @SYMTestStatus Implemented
396 //---------------------------------------------
397 void Test5(TInt aSize)
399 RCacheTestDevice::TChunkTest dC;
401 dC.iUseCase = 0; //not used
402 dC.iLoops = 0; //not used
403 TInt timeNS=0, timeS=0;
405 test.Printf(_L(" Time\n"));
406 test.Printf(_L("Mem_Type AttemptedMapAttr NotShared Shared\n"));
407 test.Printf(_L("----------------------------------------------\n"));
409 DoTest5(RCacheTestDevice::E_FullyBlocking, dC, timeNS, timeS);
410 test.Printf(_L("FullyBlocking %08xH\t%7d\t%7d\n"),dC.iActualMapAttr, timeNS, timeS);
411 DoTest5(RCacheTestDevice::E_Buffered_NC, dC, timeNS, timeS);
412 test.Printf(_L("Buffered_NC %08xH\t%7d\t%7d\n"),dC.iActualMapAttr, timeNS, timeS);
413 DoTest5(RCacheTestDevice::E_Buffered_C, dC, timeNS, timeS);
414 test.Printf(_L("Buffered_C %08xH\t%7d\t%7d\n"),dC.iActualMapAttr, timeNS, timeS);
417 DoTest5(RCacheTestDevice::E_InnerWT, dC, timeNS, timeS);
418 test.Printf(_L("InnerWT %08xH\t%7d\t%7d\n"),dC.iActualMapAttr, timeNS, timeS);
419 DoTest5(RCacheTestDevice::E_InnerWBRA, dC, timeNS, timeS);
420 test.Printf(_L("InnerWBRA %08xH\t%7d\t%7d\n"),dC.iActualMapAttr, timeNS, timeS);
421 DoTest5(RCacheTestDevice::E_InnerWB, dC, timeNS, timeS);
422 test.Printf(_L("InnerWB %08xH\t%7d\t%7d\n"),dC.iActualMapAttr, timeNS, timeS);
424 if(CacheInfo.iOuterCache)
426 DoTest5(RCacheTestDevice::E_OuterWT, dC, timeNS, timeS);
427 test.Printf(_L("OuterWT %08xH\t%7d\t%7d\n"),dC.iActualMapAttr, timeNS, timeS);
428 DoTest5(RCacheTestDevice::E_OuterWBRA, dC, timeNS, timeS);
429 test.Printf(_L("OuterWBRA %08xH\t%7d\t%7d\n"),dC.iActualMapAttr, timeNS, timeS);
430 DoTest5(RCacheTestDevice::E_OuterWB, dC, timeNS, timeS);
431 test.Printf(_L("OuterWB %08xH\t%7d\t%7d\n"),dC.iActualMapAttr, timeNS, timeS);
433 DoTest5(RCacheTestDevice::E_InOutWT, dC, timeNS, timeS);
434 test.Printf(_L("InOutWT %08xH\t%7d\t%7d\n"),dC.iActualMapAttr, timeNS, timeS);
435 DoTest5(RCacheTestDevice::E_InOutWBRA, dC, timeNS, timeS);
436 test.Printf(_L("InOutWBRA %08xH\t%7d\t%7d\n"),dC.iActualMapAttr, timeNS, timeS);
437 DoTest5(RCacheTestDevice::E_InOutWB, dC, timeNS, timeS);
438 test.Printf(_L("InOutWB %08xH\t%7d\t%7d\n"),dC.iActualMapAttr, timeNS, timeS);
442 DoTest5(RCacheTestDevice::E_StronglyOrder, dC, timeNS, timeS);
443 test.Printf(_L("StronglyOrder %08xH\t%7d\t%7d\n"),dC.iActualMapAttr, timeNS, timeS);
444 DoTest5(RCacheTestDevice::E_Device, dC, timeNS, timeS);
445 test.Printf(_L("Device %08xH\t%7d\t%7d\n"),dC.iActualMapAttr, timeNS, timeS);
446 DoTest5(RCacheTestDevice::E_Normal_Uncached, dC, timeNS, timeS);
447 test.Printf(_L("Normal_Uncached %08xH\t%7d\t%7d\n"),dC.iActualMapAttr, timeNS, timeS);
448 DoTest5(RCacheTestDevice::E_Normal_Cached, dC, timeNS, timeS);
449 test.Printf(_L("Normal_Cached %08xH\t%7d\t%7d\n"),dC.iActualMapAttr, timeNS, timeS);
451 if(CacheInfo.iMemoryRemapping)
453 DoTest5(RCacheTestDevice::E_InnerWT_Remapped, dC, timeNS, timeS);
454 test.Printf(_L("InnerWT_Remap %08xH\t%7d\t%7d\n"),dC.iActualMapAttr, timeNS, timeS);
455 DoTest5(RCacheTestDevice::E_InnerWBRA_Remapped, dC, timeNS, timeS);
456 test.Printf(_L("InnerWBRA_Remap %08xH\t%7d\t%7d\n"),dC.iActualMapAttr, timeNS, timeS);
457 DoTest5(RCacheTestDevice::E_InnerWB_Remapped, dC, timeNS, timeS);
458 test.Printf(_L("InnerWB_Remap %08xH\t%7d\t%7d\n"),dC.iActualMapAttr, timeNS, timeS);
460 if(CacheInfo.iOuterCache)
462 DoTest5(RCacheTestDevice::E_OuterWT_Remapped, dC, timeNS, timeS);
463 test.Printf(_L("OuterWT_Remap %08xH\t%7d\t%7d\n"),dC.iActualMapAttr, timeNS, timeS);
464 DoTest5(RCacheTestDevice::E_OuterWBRA_Remapped, dC, timeNS, timeS);
465 test.Printf(_L("OuterWBRA_Remap %08xH\t%7d\t%7d\n"),dC.iActualMapAttr, timeNS, timeS);
466 DoTest5(RCacheTestDevice::E_OuterWB_Remapped, dC, timeNS, timeS);
467 test.Printf(_L("OuterWB_Remap %08xH\t%7d\t%7d\n"),dC.iActualMapAttr, timeNS, timeS);
469 DoTest5(RCacheTestDevice::E_InOutWT_Remapped, dC, timeNS, timeS);
470 test.Printf(_L("InOutWT_Remap %08xH\t%7d\t%7d\n"),dC.iActualMapAttr, timeNS, timeS);
471 DoTest5(RCacheTestDevice::E_InOutWBRA_Remapped, dC, timeNS, timeS);
472 test.Printf(_L("InOutWBRA_Remap %08xH\t%7d\t%7d\n"),dC.iActualMapAttr, timeNS, timeS);
473 DoTest5(RCacheTestDevice::E_InOutWB_Remapped, dC, timeNS, timeS);
474 test.Printf(_L("InOutWB_Remap %08xH\t%7d\t%7d\n"),dC.iActualMapAttr, timeNS, timeS);
478 //Run against kernel heap - allow the test to fail due to OOM
479 dC.iCacheAttr = RCacheTestDevice::E_Default;
480 TInt r = Device.TestCodeChunk(dC);
481 if (r==KErrNone) test.Printf(_L("Run from rom ---------\t%7d\t-------\n"), dC.iTime);
482 else if (r==KErrNoMemory) test.Printf(_L("Run from rom Cannot allocate memory\n"));
489 //---------------------------------------------
490 //! @SYMTestCaseID MMU-T_CACHE-06
494 //! @SYMTestCaseDesc Tests Write Back mode.
495 //! @SYMTestActions The driver allocates write back chunk, write data into it and invalidate (aka purge)
496 // the chunk from the cache. Then, it counts the number of bytes of the chunk that
497 // reached the physical memory.
498 //! @SYMTestExpectedResults KErrNone
499 //! @SYMTestPriority Low
500 //! @SYMTestStatus Implemented
501 //---------------------------------------------
505 test.Printf(_L("Test4: Testing WriteBack cache mode...\n"));
506 RCacheTestDevice::TChunkTest dC;
509 test.Printf(_L("Cache\tMemType\tChecking\tSize\tBytesInRAM\tVerdict\n"));
510 test.Printf(_L("-----\t-------\t--------\t----\t----------\t-------\n"));
512 dC.iSize = KWriteBackTestSizeSize;
513 if(CacheInfo.iMemoryRemapping) dC.iCacheAttr = RCacheTestDevice::E_InnerWBRA_Remapped;
514 else dC.iCacheAttr = RCacheTestDevice::E_InnerWBRA;
515 test(Device.TestWriteBackReadAllocate(dC)==KErrNone);
516 if (dC.iSize<KWriteBackTestSizeSize)test.Printf(_L("Inner\tWBRA\tReadAlloc\t%xH\t%xH\tOK\n"), KWriteBackTestSizeSize, dC.iSize);
517 else test.Printf(_L("Inner\tWBRA\tReadAlloc\t%xH\t%xH\tWarning: Didn't pass\n"), KWriteBackTestSizeSize, dC.iSize);
519 dC.iSize = KWriteBackTestSizeSize;
520 if(CacheInfo.iMemoryRemapping) dC.iCacheAttr = RCacheTestDevice::E_InnerWB_Remapped;
521 else dC.iCacheAttr = RCacheTestDevice::E_InnerWB;
522 test(Device.TestWriteBackReadAllocate(dC)==KErrNone);
523 if (dC.iSize<KWriteBackTestSizeSize)test.Printf(_L("Inner\tWBWA\tReadAlloc\t%xH\t%xH\tOK\n"), KWriteBackTestSizeSize, dC.iSize);
524 else test.Printf(_L("Inner\tWBWA\tReadAlloc\t%xH\t%xH\tWarning: Didn't pass\n"), KWriteBackTestSizeSize, dC.iSize);
526 dC.iSize = KWriteBackTestSizeSize;
527 if(CacheInfo.iMemoryRemapping) dC.iCacheAttr = RCacheTestDevice::E_InnerWB_Remapped;
528 else dC.iCacheAttr = RCacheTestDevice::E_InnerWB;
529 test(Device.TestWriteBackWriteAllocate(dC)==KErrNone);
530 if (dC.iSize<KWriteBackTestSizeSize)test.Printf(_L("Inner\tWBWA\tWriteAlloc\t%xH\t%xH\tOK\n"), KWriteBackTestSizeSize, dC.iSize);
531 else test.Printf(_L("Inner\tWBWA\tWriteAlloc\t%xH\t%xH\tWarning: Didn't pass\n"), KWriteBackTestSizeSize, dC.iSize);
533 if(!CacheInfo.iOuterCache) return;
535 dC.iSize = KWriteBackTestSizeSize;
536 if(CacheInfo.iMemoryRemapping) dC.iCacheAttr = RCacheTestDevice::E_OuterWBRA_Remapped;
537 else dC.iCacheAttr = RCacheTestDevice::E_OuterWBRA;
538 test(Device.TestWriteBackReadAllocate(dC)==KErrNone);
539 if (dC.iSize<KWriteBackTestSizeSize)test.Printf(_L("Outer\tWBRA\tReadAlloc\t%xH\t%xH\tOK\n"), KWriteBackTestSizeSize, dC.iSize);
540 else test.Printf(_L("Outer\tWBRA\tReadAlloc\t%xH\t%xH\tWarning: Didn't pass\n"), KWriteBackTestSizeSize, dC.iSize);
542 dC.iSize = KWriteBackTestSizeSize;
543 if(CacheInfo.iMemoryRemapping) dC.iCacheAttr = RCacheTestDevice::E_OuterWB_Remapped;
544 else dC.iCacheAttr = RCacheTestDevice::E_OuterWB;
545 test(Device.TestWriteBackReadAllocate(dC)==KErrNone);
546 if (dC.iSize<KWriteBackTestSizeSize)test.Printf(_L("Outer\tWBWA\tReadAlloc\t%xH\t%xH\tOK\n"), KWriteBackTestSizeSize, dC.iSize);
547 else test.Printf(_L("Outer\tWBWA\tReadAlloc\t%xH\t%xH\tWarning: Didn't pass\n"), KWriteBackTestSizeSize, dC.iSize);
549 dC.iSize = KWriteBackTestSizeSize;
550 if(CacheInfo.iMemoryRemapping) dC.iCacheAttr = RCacheTestDevice::E_OuterWB_Remapped;
551 else dC.iCacheAttr = RCacheTestDevice::E_OuterWB;
552 test(Device.TestWriteBackWriteAllocate(dC)==KErrNone);
553 if (dC.iSize<KWriteBackTestSizeSize)test.Printf(_L("Outer\tWBWA\tWriteAlloc\t%xH\t%xH\tOK\n"), KWriteBackTestSizeSize, dC.iSize);
554 else test.Printf(_L("Outer\tWBWA\tWriteAlloc\t%xH\t%xH\tWarning: Didn't pass\n"), KWriteBackTestSizeSize, dC.iSize);
559 //---------------------------------------------
560 //! @SYMTestCaseID MMU-T_CACHE-07
564 //! @SYMTestCaseDesc Tests Cache Maintanence Functions.
565 //! @SYMTestActions Does not do any sort of functional test. Just makes sure nothing panics.
566 //! @SYMTestExpectedResults KErrNone
567 //! @SYMTestPriority High
568 //! @SYMTestStatus Implemented
569 //---------------------------------------------
572 test(KErrNone== Device.TestL2Maintenance());
575 // The main function of automatic test.
578 test.Start(_L("Test1: Display cache attributes:"));
579 test.Printf(_L("Starting Driver...\n"));
581 test.Printf(_L("Getting CacheInfo...\n"));
585 test.Next(_L("Test2:Thresholds (hex)..."));
588 test.Next(_L("Test3:Setting Cache Thresholds..."));
591 test.Next(_L("Test4: Data chunk test..."));
592 test.Printf(_L("chunk size=%xH \n"),KDefaultDataSize);
593 Test4(KDefaultDataSize);
595 test.Next(_L("Test5: Code chunk test..."));
596 test.Printf(_L("chunk size=%xH \n"),KDefaultCodeSize);
597 Test5(KDefaultCodeSize);
599 test.Next(_L("Test6: Testing WriteBack cache mode..."));
602 test.Next(_L("Test7: Testing L2 cache maintenance..."));
609 //////////////////////Manual tests start here///////////////////////////////
611 // Gets the size of the chunk from the command line
612 TInt GetSizeFromCommandLine(TBuf<64>& command)
615 TInt length = command.Length()-5;
618 TPtrC ptr = command.Mid(5,length);
624 /** Invoked by "t_cache info"*/
625 void ManualCacheInfo()
628 test.Start(_L("Cache Info:"));
632 test.Printf(_L("Press any key...\n"));
639 /** Invoked by "t_cache code threshold [<C> <P> <C> <F>]"*/
640 TInt ManualThresholds(TBuf<64>& command)
644 TInt argStart = 9; //jump over "threshold"
648 test.Start(_L("Thresholds:"));
653 // Decode input arguments from the command line
657 if (argStart >= command.Length()) break;
658 c = command[argStart];
667 if (argEnd >= command.Length()) goto get_arg;
669 if (c.IsSpace()) goto get_arg;
674 TPtrC ptr = command.Mid(argStart,argEnd-argStart);
676 lex.Val(arg[argCurrent++], EHex);
680 test.Printf(_L("%d argument(s) decoded\n"),argCurrent);
682 RCacheTestDevice::TThresholdInfo info;
684 //If te values are provided in the command line, set thresholds with the given paramaters.
687 test.Printf(_L("Setting thresholds: ...\n"));
688 test.Printf(_L("Cache Type:%xh P:%xh C:%xh F:%xh\n"),arg[0], arg[1], arg[2], arg[3]);
689 info.iCacheType=arg[0];
690 info.iPurge = arg[1];
691 info.iClean = arg[2];
692 info.iFlush = arg[3];
693 TInt r = Device.SetThreshold(info);
694 test.Printf(_L("... returned %d\n"),r);
697 //Read thresholds from Kernel.
698 test.Printf(_L("Reading thresholds(hex)...\n"));
701 test.Printf(_L("Press any key...\n"));
709 /** Invoked by "t_cache data <size>"*/
710 void ManualDataTest(TInt aSize)
717 test.Printf(_L("Press any key...\n"));
723 /** Invoked by "t_cache code <size>"*/
724 void ManualCodeTest(TInt aSize)
731 test.Printf(_L("Press any key...\n"));
737 void DoUseCase(TInt aUseCase, TInt aMaxSize, TInt aLoops )
739 RCacheTestDevice::TChunkTest dC(aUseCase, 0x1000, aLoops);
743 test.Printf(_L("size(H)\tloops\tNormal/NC\tNormal/WT\tFullyCached\n"));
744 test.Printf(_L("-------\t-----\t---------\t---------\t-----------\n"));
746 while (dC.iSize<=aMaxSize)
748 dC.iCacheAttr = RCacheTestDevice::E_Normal_Cached;
749 test(Device.TestUseCase(dC)==KErrNone);
753 {dC.iLoops *=2; continue;} //Time too short. Double the loops and try the same chunk size.
755 dC.iCacheAttr = RCacheTestDevice::E_Normal_Uncached;
756 test(Device.TestUseCase(dC)==KErrNone);
759 if(CacheInfo.iMemoryRemapping) dC.iCacheAttr = RCacheTestDevice::E_InOutWT_Remapped;
760 else dC.iCacheAttr = RCacheTestDevice::E_InOutWT;
761 test(Device.TestUseCase(dC)==KErrNone);
765 test.Printf(_L("%6xH\t%5d\t%9d\t%9d\t%11d\n"),dC.iSize,dC.iLoops,time[0],time[1],time[2]);
767 if ((time[2] > 100) && (dC.iLoops >= 8))
768 dC.iLoops /=2; //Time too long. Half the loops.
770 dC.iSize+=0x1000; // Next chunk size.
774 /** Invoked by "t_cache usecase"*/
777 test.Start(_L("Use Case manual tests"));
781 test.Printf(_L("\nUseCase: Read From Chunk\n"));
782 DoUseCase(0,Min(CacheInfo.iMaxCacheSize*4, 0x40000),32);
784 test.Printf(_L("\nUseCase: Read From Chunk & Read From Heap\n"));
785 DoUseCase(1,Min(CacheInfo.iMaxCacheSize*4, 0x40000),32);
787 test.Printf(_L("\nUseCase: Write To Chunk\n"));
788 DoUseCase(2,Min(CacheInfo.iMaxCacheSize*4, 0x40000),32);
790 test.Printf(_L("\nUseCase: Write To Chunk & Read From Heap\n"));
791 DoUseCase(3,Min(CacheInfo.iMaxCacheSize*4, 0x40000),32);
794 test.Printf(_L("Press any key...\n"));
801 // Invoked by "t_cache data+<size_hex>"
802 void ManualDataTestIncremental(TInt aIncrement)
806 TInt size = aIncrement;
807 RCacheTestDevice::TChunkTest dC;
812 test.Printf(_L("Chunk\t\tTime(KernelTicks):\n"));
813 test.Printf(_L("Size(KB)\tUnCached\tInner\tOuter\tIn&Out\n"));
815 while(size < KMaxChunkSize)
819 dC.iCacheAttr = RCacheTestDevice::E_Buffered_C;
820 r = Device.TestDataChunk(dC);
821 if (r!=KErrNone) break;
824 if(CacheInfo.iMemoryRemapping) dC.iCacheAttr = RCacheTestDevice::E_InnerWB_Remapped;
825 else dC.iCacheAttr = RCacheTestDevice::E_InnerWB;
826 r = Device.TestDataChunk(dC);
827 if (r!=KErrNone) break;
830 if(CacheInfo.iOuterCache)
832 if(CacheInfo.iMemoryRemapping) dC.iCacheAttr = RCacheTestDevice::E_OuterWB_Remapped;
833 else dC.iCacheAttr = RCacheTestDevice::E_OuterWB;
834 r = Device.TestDataChunk(dC);
835 if (r!=KErrNone) break;
838 dC.iCacheAttr = RCacheTestDevice::E_InOutWB;
839 r = Device.TestDataChunk(dC);
840 if (r!=KErrNone) break;
847 test.Printf(_L("%d\t%d\t%d\t%d\t%d\n"),size/0x400, time[0],time[1],time[2],time[3]);
851 test.Printf(_L("The test exited with %d\n"), r);
852 test.Printf(_L("Press any key...\n"));
858 // Invoked by "t_cache code+<size_hex>"
859 void ManualCodeTestIncremental(TInt aIncrement)
863 TInt size = aIncrement;
864 RCacheTestDevice::TChunkTest dC;
869 test.Printf(_L("Chunk\t\tTime(KernelTicks):\n"));
870 test.Printf(_L("Size(KB)\tUnCached\tInner\tOuter\tIn&Out\n"));
872 while(size < KMaxChunkSize)
874 TempBuff.SetLength(0);
878 dC.iCacheAttr = RCacheTestDevice::E_Buffered_C;
879 r = Device.TestCodeChunk(dC);
880 if (r!=KErrNone) break;
883 if(CacheInfo.iMemoryRemapping) dC.iCacheAttr = RCacheTestDevice::E_InnerWB_Remapped;
884 else dC.iCacheAttr = RCacheTestDevice::E_InnerWB;
885 r = Device.TestCodeChunk(dC);
886 if (r!=KErrNone) break;
889 if(CacheInfo.iOuterCache)
891 if(CacheInfo.iMemoryRemapping) dC.iCacheAttr = RCacheTestDevice::E_OuterWB_Remapped;
892 else dC.iCacheAttr = RCacheTestDevice::E_OuterWB;
893 r = Device.TestCodeChunk(dC);
894 if (r!=KErrNone) break;
897 dC.iCacheAttr = RCacheTestDevice::E_InOutWB;
898 r = Device.TestCodeChunk(dC);
899 if (r!=KErrNone) break;
907 test.Printf(_L("%d\t%d\t%d\t%d\t%d\n"),size/0x400, time[0],time[1],time[2],time[3]);
911 test.Printf(_L("The test exited with %d\n"), r);
912 test.Printf(_L("Press any key...\n"));
923 User::CommandLine(c);
924 if (c.FindF(KPrintCacheInfos) >= 0) {ManualCacheInfo(); return 0;}
925 if (c.FindF(KUseCase) >= 0) {ManualUseCase(); return 0;}
926 if (c.FindF(KThreshold) >= 0) {ManualThresholds(c); return 0;}
928 if (c.FindF(KTestData) >= 0)
930 test.Start(_L("Data Chunk"));
931 size = GetSizeFromCommandLine(c);
932 // Always round up the size to 1K boundary (because of DataSegmetTestFunct)
933 size +=0x3ff; size &=~0x3ff;
935 if (c.FindF(KIncremental) >= 0)
937 // Invoked by "t_cache data+<size>"
938 test.Printf(_L(" size + %xH\n"),size);
941 ManualDataTestIncremental(size);
945 // Invoked by "t_cache data <size>"
946 test.Printf(_L("chunk size %xH\n"),size);
949 ManualDataTest(size);
954 if (c.FindF(KTestCode) >= 0)
956 test.Start(_L("Code Chunk"));
957 size = GetSizeFromCommandLine(c);
958 // Always round up the size to 1K boundary
959 size +=0x3ff; size &=~0x3ff;
960 if (c.FindF(KIncremental) >= 0)
962 // Invoked by "t_cache code+<size>"
963 test.Printf(_L(" size + %xH\n"),size);
966 ManualCodeTestIncremental(size);
970 // Invoked by "t_cache code <size>"
971 test.Printf(_L("chunk size %xH\n"),size);
974 ManualCodeTest(size);
979 if (c.FindF(KHelp) >= 0)
981 // Invoked by "t_cache help"
982 test.Start(_L("t_cache usage:\n"));
983 test.Printf(_L("t_cache info\n"));
984 test.Printf(_L("t_cache data <size_hex>\n"));
985 test.Printf(_L("t_cache code <size_hex>\n"));
986 test.Printf(_L("t_cache data+<size_hex>\n"));
987 test.Printf(_L("t_cache code+<size_hex>\n"));
988 test.Printf(_L("t_cache usecase\n\n"));
989 test.Printf(_L("t_cache threshold [<cache> <purge> <clean> <flush>]\n\n"));
990 test.Printf(_L("... where <cache>= 1,2,4,8 or 10\n\n"));
991 test.Printf(_L("Press any key...\n"));
998 // auto test starts here
999 CTrapCleanup* trap = CTrapCleanup::New();
1001 return KErrNoMemory;
1004 TRAPD(r,AutoTestL());