os/kernelhwsrv/kerneltest/e32test/mmu/t_cache.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
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".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // e32test\debug\t_cache.cpp
    15 // Overview:
    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.)
    18 // API Information:
    19 // class Cache
    20 // class L2Cache
    21 // 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.
    57 // 
    58 //
    59 
    60 #include <e32test.h>
    61 #include "d_cache.h"
    62 
    63 //------------globals---------------------
    64 LOCAL_D RTest test(_L("T_CACHE"));
    65 _LIT(KPrintCacheInfos,"info");
    66 _LIT(KTestData,"data");
    67 _LIT(KTestCode,"code");
    68 _LIT(KHelp,"help");
    69 _LIT(KThreshold,"threshold");
    70 _LIT(KIncremental,"+");
    71 _LIT(KUseCase,"usecase");
    72 
    73 RCacheTestDevice Device;
    74 RCacheTestDevice::TCacheInfo CacheInfo;
    75 TBuf<KCacheDescSize> TempBuff;
    76 
    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).
    81 
    82 extern void DataSegmetTestFunct(void* aBase, TInt aSize);
    83 
    84 /** Loads & opens LDD.*/
    85 void StartDriver()
    86 	{
    87 	TInt r = User::LoadLogicalDevice(KCacheTestDriverName);
    88 	test( r==KErrNone || r==KErrAlreadyExists);
    89 	if((r = Device.Open())!=KErrNone)	
    90 		{
    91 		User::FreeLogicalDevice(KCacheTestDriverName);
    92 		test.Printf(_L("Could not open LDD"));
    93 		test(0);
    94 		}
    95 	}
    96 
    97 /** Closes and unloads LDD.*/
    98 void StopDriver()
    99 	{
   100 	Device.Close();
   101 	User::FreeLogicalDevice(KCacheTestDriverName);
   102 	}
   103 
   104 /** Get cache info from device driver. This will update CacheInfo global variable.*/
   105 void GetCacheInfo()
   106 	{
   107 	TInt r = Device.GetCacheInfo(CacheInfo);
   108 	test(r==KErrNone);
   109 	}
   110 
   111 //---------------------------------------------
   112 //! @SYMTestCaseID			MMU-T_CACHE-01
   113 //! @SYMTestType 			ST
   114 //! @SYMPREQ 				PREQ305
   115 //! @SYMREQ 				REQ5795
   116 //! @SYMTestCaseDesc 		Displays cache properties.
   117 //! @SYMTestExpectedResults KErrNone 
   118 //! @SYMTestPriority 		Low
   119 //! @SYMTestStatus 			Implemented
   120 //---------------------------------------------
   121 void Test1()
   122 	{
   123 	TInt i;
   124 	
   125 	test.Printf(_L("General Info:\n"));
   126 	TPtr ptr = CacheInfo.iDesc.Expand();
   127 	test.Printf(ptr);
   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);
   130 
   131 
   132 	test.Printf(_L("Per Level Info:\n"));
   133 	test.Printf(_L("Level\tData\tInstr\tSize(b)\tLine(b)\tWays\tSets\tDescription\n"));
   134 
   135 	for (i = 0; i<CacheInfo.iCacheCount; i++)
   136 		{
   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);
   144 		}
   145 	}
   146 
   147 //---------------------------------------------
   148 //! @SYMTestCaseID			MMU-T_CACHE-02
   149 //! @SYMTestType 			ST
   150 //! @SYMPREQ 				PREQ1068
   151 //! @SYMREQ 				REQ5909
   152 //! @SYMTestCaseDesc 		Gets thresholds.
   153 //! @SYMTestActions 		Fetches Cache Thresholds from the driver.
   154 //! @SYMTestExpectedResults KErrNone 
   155 //! @SYMTestPriority 		High
   156 //! @SYMTestStatus 			Implemented
   157 //---------------------------------------------
   158 void Test2()
   159 	{
   160 	RCacheTestDevice::TThresholdInfo info;
   161 	
   162 	test.Printf(_L("Cache: Purge  Clear  Flush\n"));
   163 	
   164 	info.iCacheType=1;
   165 	if (KErrNone == Device.GetThreshold(info))
   166 		test.Printf(_L("Instr:%6x %6x %6x\n"),info.iPurge,info.iClean,info.iFlush);
   167 	
   168 	info.iCacheType=2;
   169 	if (KErrNone == Device.GetThreshold(info))
   170 		test.Printf(_L("Data: %6x %6x %6x\n"),info.iPurge,info.iClean,info.iFlush);
   171 	
   172 	info.iCacheType=4;
   173 	if (KErrNone == Device.GetThreshold(info))
   174 		test.Printf(_L("AltD: %6x %6x %6x\n"),info.iPurge,info.iClean,info.iFlush);
   175 	
   176 	info.iCacheType=8;
   177 	if (KErrNone == Device.GetThreshold(info))
   178 		test.Printf(_L("D_IMB:%6x %6x %6x\n"),info.iPurge,info.iClean,info.iFlush);
   179 	
   180 	info.iCacheType=16;
   181 	if (KErrNone == Device.GetThreshold(info))
   182 		test.Printf(_L("L2:   %6x %6x %6x\n"),info.iPurge,info.iClean,info.iFlush);
   183 	}
   184 
   185 //---------------------------------------------
   186 //! @SYMTestCaseID			MMU-T_CACHE-03
   187 //! @SYMTestType 			ST
   188 //! @SYMPREQ 				PREQ1068
   189 //! @SYMREQ 				REQ5909
   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 //---------------------------------------------
   196 void Test3()
   197 	{
   198 	TInt i, tested=0;
   199 	RCacheTestDevice::TThresholdInfo info[5]; //for 5 types og cache
   200 	TInt returned[5];
   201 	
   202 
   203 	//Get the old values
   204 	for (i=0;i<5;i++)
   205 		{
   206 		info[i].iCacheType= 1<<i;
   207 		returned[i] = Device.GetThreshold(info[i]);
   208 		}
   209 
   210 	//Double them all
   211 	for (i=0;i<5;i++)
   212 		{
   213 		if (returned[i] != KErrNone) continue; //not a valid cache type for running platform
   214 		tested++;
   215 		info[i].iPurge <<=1;
   216 		info[i].iClean <<=1;
   217 		info[i].iFlush <<=1;
   218 		test(KErrNone==Device.SetThreshold(info[i]));
   219 		}
   220 
   221 	//Put back the old values
   222 	for (i=0;i<5;i++)
   223 		{
   224 		if (returned[i] != KErrNone) continue; //not a valid cache type for running platform
   225 		info[i].iPurge >>=1;
   226 		info[i].iClean >>=1;
   227 		info[i].iFlush >>=1;
   228 		test(KErrNone==Device.SetThreshold(info[i]));
   229 		}
   230 	test.Printf(_L(" ... %d caches present & tested\n"), tested);
   231 	}
   232 
   233 
   234 
   235 void DoTest4(RCacheTestDevice::TCacheAttr aCacheAttr, RCacheTestDevice::TChunkTest& aDC, TInt& aTime1, TInt& aTime2)
   236 	{
   237 	aDC.iCacheAttr = aCacheAttr;
   238 	
   239 	aDC.iShared = EFalse;
   240 	test(KErrNone==Device.TestDataChunk(aDC));
   241 	aTime1 = aDC.iTime;
   242 
   243 	aDC.iShared = ETrue;
   244 	test(KErrNone==Device.TestDataChunk(aDC));
   245 	aTime2 = aDC.iTime;
   246 	}
   247 //---------------------------------------------
   248 //! @SYMTestCaseID 			MMU-T_CACHE-04
   249 //! @SYMTestType 			ST
   250 //! @SYMPREQ 				PREQ305
   251 //! @SYMREQ 				REQ5795
   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)
   260 	{
   261 	RCacheTestDevice::TChunkTest dC;
   262 	dC.iSize = aSize;
   263 	dC.iUseCase = 0;  //not used
   264 	dC.iLoops = 0; //not used
   265 	TInt timeNS=0, timeS=0;
   266 
   267 	test.Printf(_L("                                  	Time\n"));
   268 	test.Printf(_L("Mem_Type      ActualMapAttr	NotShared	Shared\n"));
   269 	test.Printf(_L("----------------------------------------------\n"));
   270 
   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);
   277 
   278 
   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);
   285 
   286 	if(CacheInfo.iOuterCache)
   287 		{
   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);
   294 
   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);
   301 		}
   302 
   303 
   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);
   312 
   313 	if(CacheInfo.iMemoryRemapping)
   314 		{
   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);
   323 
   324 
   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);
   331 
   332 		if(CacheInfo.iOuterCache)
   333 			{
   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);
   340 
   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);
   347 			}
   348 		}
   349 
   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"));
   355 	else						test(0);//fail
   356 
   357 	//Run against user heap - allow the test to fail due to OOM
   358 	void* buffer = User::Alloc(dC.iSize);
   359 	if (buffer == NULL)
   360 		{
   361 		test.Printf(_L("User Heap      Cannot allocate memory\n"));
   362 		return;
   363 		}
   364 	TInt time = User::NTickCount();
   365 	DataSegmetTestFunct(buffer , dC.iSize);
   366 	time = User::NTickCount() - time;
   367 	User::Free(buffer);
   368 	test.Printf(_L("User Heap       ---------\t%7d\t-------\n"), time);
   369 
   370 	}		
   371 
   372 
   373 void DoTest5(RCacheTestDevice::TCacheAttr aCacheAttr, RCacheTestDevice::TChunkTest& aDC, TInt& aTime1, TInt& aTime2)
   374 	{
   375 	aDC.iCacheAttr = aCacheAttr;
   376 	
   377 	aDC.iShared = EFalse;
   378 	test(KErrNone==Device.TestCodeChunk(aDC));
   379 	aTime1 = aDC.iTime;
   380 
   381 	aDC.iShared = ETrue;
   382 	test(KErrNone==Device.TestCodeChunk(aDC));
   383 	aTime2 = aDC.iTime;
   384 	}
   385 //---------------------------------------------
   386 //! @SYMTestCaseID 			MMU-T_CACHE-05
   387 //! @SYMTestType 			ST
   388 //! @SYMPREQ 				PREQ305
   389 //! @SYMREQ 				REQ5795
   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)
   398 	{
   399 	RCacheTestDevice::TChunkTest dC;
   400 	dC.iSize = aSize;
   401 	dC.iUseCase = 0;  //not used
   402 	dC.iLoops = 0; //not used
   403 	TInt timeNS=0, timeS=0;
   404 
   405 	test.Printf(_L("                                  	Time\n"));
   406 	test.Printf(_L("Mem_Type   AttemptedMapAttr	NotShared	Shared\n"));
   407 	test.Printf(_L("----------------------------------------------\n"));
   408 
   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);
   415 
   416 
   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);
   423 
   424 	if(CacheInfo.iOuterCache)
   425 		{
   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);
   432 
   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);
   439 		}
   440 
   441 
   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);
   450 
   451 	if(CacheInfo.iMemoryRemapping)
   452 		{
   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);
   459 
   460 		if(CacheInfo.iOuterCache)
   461 			{
   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);
   468 
   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);
   475 			}
   476 		}
   477 
   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"));
   483 		else						test(0);//fail
   484 
   485 	}
   486 
   487 
   488 
   489 //---------------------------------------------
   490 //! @SYMTestCaseID 			MMU-T_CACHE-06
   491 //! @SYMTestType 			ST
   492 //! @SYMPREQ 				PREQ305
   493 //! @SYMREQ 				REQ5795
   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 //---------------------------------------------
   502 
   503 void Test6()
   504 	{
   505 	test.Printf(_L("Test4: Testing WriteBack cache mode...\n"));
   506 	RCacheTestDevice::TChunkTest dC;
   507 
   508 
   509 	test.Printf(_L("Cache\tMemType\tChecking\tSize\tBytesInRAM\tVerdict\n"));
   510 	test.Printf(_L("-----\t-------\t--------\t----\t----------\t-------\n"));
   511 //
   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);
   518 //
   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);
   525 //
   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);
   532 	
   533 	if(!CacheInfo.iOuterCache) return;
   534 		
   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);
   541 //
   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);
   548 //
   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);
   555 	}
   556 
   557 
   558 
   559 //---------------------------------------------
   560 //! @SYMTestCaseID 			MMU-T_CACHE-07
   561 //! @SYMTestType 			UT
   562 //! @SYMPREQ 				PREQ305
   563 //! @SYMREQ 				REQ5795
   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 //---------------------------------------------
   570 void Test7()
   571 	{
   572 	test(KErrNone== Device.TestL2Maintenance());
   573 	}
   574 
   575 // The main function of automatic test.
   576 void AutoTestL()
   577 	{
   578 	test.Start(_L("Test1: Display cache attributes:"));
   579 	test.Printf(_L("Starting Driver...\n"));
   580 	StartDriver();	
   581 	test.Printf(_L("Getting CacheInfo...\n"));
   582 	GetCacheInfo();
   583 	Test1();
   584 
   585 	test.Next(_L("Test2:Thresholds (hex)..."));
   586 	Test2();
   587 
   588 	test.Next(_L("Test3:Setting Cache Thresholds..."));
   589 	Test3();
   590 
   591 	test.Next(_L("Test4: Data chunk test..."));
   592 	test.Printf(_L("chunk size=%xH \n"),KDefaultDataSize);
   593 	Test4(KDefaultDataSize);
   594 
   595 	test.Next(_L("Test5: Code chunk test..."));
   596 	test.Printf(_L("chunk size=%xH \n"),KDefaultCodeSize);
   597 	Test5(KDefaultCodeSize);
   598 
   599 	test.Next(_L("Test6: Testing WriteBack cache mode..."));
   600 	Test6(); 
   601 
   602 	test.Next(_L("Test7: Testing L2 cache maintenance..."));
   603 	Test7();
   604 
   605 	StopDriver();	
   606 	test.End();
   607 	}
   608 
   609 //////////////////////Manual tests start here///////////////////////////////
   610 
   611 // Gets the size of the chunk from the command line
   612 TInt GetSizeFromCommandLine(TBuf<64>& command)
   613 	{
   614 	TUint arg;
   615 	TInt length = command.Length()-5;
   616 	if (length <=0)
   617 		return KErrArgument;
   618 	TPtrC ptr = command.Mid(5,length);
   619 	TLex lex(ptr);
   620 	lex.Val(arg, EHex);
   621 	return arg;
   622 	}
   623 
   624 /** Invoked by "t_cache info"*/
   625 void ManualCacheInfo()
   626 	{
   627 	
   628 	test.Start(_L("Cache Info:"));
   629 	StartDriver();	
   630 	GetCacheInfo();
   631 	Test1();
   632 	test.Printf(_L("Press any key...\n"));
   633 	test.Getch();
   634 	StopDriver();
   635 	test.End();		
   636 	return;
   637 	}
   638 
   639 /** Invoked by "t_cache code threshold [<C> <P> <C> <F>]"*/
   640 TInt ManualThresholds(TBuf<64>& command)
   641 	{
   642 	TUint arg[4];
   643 	TInt argCurrent=0;
   644 	TInt argStart = 9; //jump over "threshold"
   645 	TInt argEnd;
   646 	TChar c;
   647 
   648 	test.Start(_L("Thresholds:"));
   649 	StartDriver();	
   650 	GetCacheInfo();
   651 
   652 
   653 	// Decode input arguments from the command line
   654 	while (argCurrent<4)
   655 		{
   656 		find_arg_start:
   657 		if (argStart >= command.Length()) break;
   658 		c = command[argStart];
   659 		if (c.IsSpace())
   660 			{
   661 			argStart++;
   662 			goto find_arg_start;
   663 			}
   664 		
   665 		argEnd = argStart+1;
   666 		find_arg_end:
   667 		if (argEnd >= command.Length()) goto get_arg;
   668 		c = command[argEnd];
   669 		if (c.IsSpace()) goto get_arg;
   670 		argEnd++;
   671 		goto find_arg_end;
   672 
   673 		get_arg:
   674 		TPtrC ptr = command.Mid(argStart,argEnd-argStart);
   675 		TLex lex(ptr);
   676 		lex.Val(arg[argCurrent++], EHex);
   677 		argStart=argEnd;
   678 		}
   679 
   680 	test.Printf(_L("%d argument(s) decoded\n"),argCurrent);
   681 	
   682 	RCacheTestDevice::TThresholdInfo info;
   683 
   684 	//If te values are provided in the command line, set thresholds with the given paramaters.
   685 	if (argCurrent == 4)
   686 		{
   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);
   695 		}
   696 
   697 	//Read thresholds from Kernel.
   698 	test.Printf(_L("Reading thresholds(hex)...\n"));
   699 	Test2();
   700 
   701 	test.Printf(_L("Press any key...\n"));
   702 	test.Getch();
   703 	StopDriver();
   704 	test.End();		
   705 	return 0;
   706 	}
   707 
   708 
   709 /** Invoked by "t_cache data <size>"*/
   710 void ManualDataTest(TInt aSize)
   711 	{
   712 	StartDriver();	
   713 	GetCacheInfo();
   714 
   715 	Test4(aSize);
   716 
   717 	test.Printf(_L("Press any key...\n"));
   718 	test.Getch();
   719 	StopDriver();	
   720 	test.End();
   721 	}
   722 
   723 /** Invoked by "t_cache code <size>"*/
   724 void ManualCodeTest(TInt aSize)
   725 	{
   726 	StartDriver();	
   727 	GetCacheInfo();
   728 
   729 	Test5(aSize);
   730 
   731 	test.Printf(_L("Press any key...\n"));
   732 	test.Getch();
   733 	StopDriver();	
   734 	test.End();
   735 	}
   736 
   737 void DoUseCase(TInt aUseCase, TInt aMaxSize, TInt aLoops )
   738 	{
   739 	RCacheTestDevice::TChunkTest dC(aUseCase, 0x1000, aLoops);
   740 	
   741 	TInt time[5];
   742 
   743 	test.Printf(_L("size(H)\tloops\tNormal/NC\tNormal/WT\tFullyCached\n"));
   744 	test.Printf(_L("-------\t-----\t---------\t---------\t-----------\n"));
   745 
   746 	while (dC.iSize<=aMaxSize)
   747 		{
   748 		dC.iCacheAttr = RCacheTestDevice::E_Normal_Cached;
   749 		test(Device.TestUseCase(dC)==KErrNone);
   750 		time[2]=dC.iTime;
   751 
   752 		if(time[2] < 20)
   753 			{dC.iLoops *=2;	continue;} //Time too short. Double the loops and try the same chunk size.
   754 
   755 		dC.iCacheAttr = RCacheTestDevice::E_Normal_Uncached;
   756 		test(Device.TestUseCase(dC)==KErrNone);
   757 		time[0]=dC.iTime;
   758 
   759 		if(CacheInfo.iMemoryRemapping)	dC.iCacheAttr = RCacheTestDevice::E_InOutWT_Remapped;
   760 		else							dC.iCacheAttr = RCacheTestDevice::E_InOutWT;
   761 		test(Device.TestUseCase(dC)==KErrNone);
   762 		time[1]=dC.iTime;
   763 
   764 
   765 		test.Printf(_L("%6xH\t%5d\t%9d\t%9d\t%11d\n"),dC.iSize,dC.iLoops,time[0],time[1],time[2]);
   766 
   767 		if ((time[2] > 100) && (dC.iLoops >= 8))
   768 			dC.iLoops /=2; //Time too long. Half the loops.
   769 
   770 		dC.iSize+=0x1000; // Next chunk size.
   771 		}
   772 	}		
   773 
   774 /** Invoked by "t_cache usecase"*/
   775 void ManualUseCase()
   776 	{
   777 	test.Start(_L("Use Case manual tests"));
   778 	StartDriver();	
   779 	GetCacheInfo();
   780 
   781 	test.Printf(_L("\nUseCase: Read From Chunk\n"));
   782 	DoUseCase(0,Min(CacheInfo.iMaxCacheSize*4, 0x40000),32);
   783 	
   784 	test.Printf(_L("\nUseCase: Read From Chunk & Read From Heap\n"));
   785 	DoUseCase(1,Min(CacheInfo.iMaxCacheSize*4, 0x40000),32);
   786 
   787 	test.Printf(_L("\nUseCase: Write To Chunk\n"));
   788 	DoUseCase(2,Min(CacheInfo.iMaxCacheSize*4, 0x40000),32);
   789 	
   790 	test.Printf(_L("\nUseCase: Write To Chunk & Read From Heap\n"));
   791 	DoUseCase(3,Min(CacheInfo.iMaxCacheSize*4, 0x40000),32);
   792 
   793 
   794 	test.Printf(_L("Press any key...\n"));
   795 	test.Getch();
   796 	StopDriver();	
   797 	test.End();
   798 	}
   799 
   800 
   801 // Invoked by "t_cache data+<size_hex>"
   802 void ManualDataTestIncremental(TInt aIncrement)
   803 	{
   804 	TInt time[4];
   805 	TInt r = KErrNone;
   806 	TInt size = aIncrement;
   807 	RCacheTestDevice::TChunkTest dC;
   808 
   809 	StartDriver();	
   810 	GetCacheInfo();
   811 
   812 	test.Printf(_L("Chunk\t\tTime(KernelTicks):\n"));
   813 	test.Printf(_L("Size(KB)\tUnCached\tInner\tOuter\tIn&Out\n"));
   814 
   815 	while(size < KMaxChunkSize)
   816 		{
   817 		dC.iSize = size;
   818 
   819 		dC.iCacheAttr = RCacheTestDevice::E_Buffered_C;
   820 		r = Device.TestDataChunk(dC);
   821 		if (r!=KErrNone) break;
   822 		time[0] = dC.iTime;
   823 
   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;
   828 		time[1] = dC.iTime;
   829 
   830 		if(CacheInfo.iOuterCache)
   831 			{
   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;
   836 			time[2] = dC.iTime;
   837 
   838 			dC.iCacheAttr = RCacheTestDevice::E_InOutWB;
   839 			r = Device.TestDataChunk(dC);
   840 			if (r!=KErrNone) break;
   841 			time[3] = dC.iTime;
   842 			}
   843 		else 
   844 			{
   845 			time[2]= time[3]=0;
   846 			}
   847 		test.Printf(_L("%d\t%d\t%d\t%d\t%d\n"),size/0x400, time[0],time[1],time[2],time[3]);
   848 		size += aIncrement;
   849 		}
   850 
   851 	test.Printf(_L("The test exited with %d\n"), r);
   852 	test.Printf(_L("Press any key...\n"));
   853 	test.Getch();
   854 	StopDriver();	
   855 	test.End();
   856 	}
   857 
   858 // Invoked by "t_cache code+<size_hex>"
   859 void ManualCodeTestIncremental(TInt aIncrement)
   860 	{
   861 	TInt time[4];
   862 	TInt r = KErrNone;
   863 	TInt size = aIncrement;
   864 	RCacheTestDevice::TChunkTest dC;
   865 
   866 	StartDriver();	
   867 	GetCacheInfo();
   868 
   869 	test.Printf(_L("Chunk\t\tTime(KernelTicks):\n"));
   870 	test.Printf(_L("Size(KB)\tUnCached\tInner\tOuter\tIn&Out\n"));
   871 
   872 	while(size < KMaxChunkSize)
   873 		{
   874 		TempBuff.SetLength(0);
   875 
   876 		dC.iSize = size;
   877 
   878 		dC.iCacheAttr = RCacheTestDevice::E_Buffered_C;
   879 		r = Device.TestCodeChunk(dC);
   880 		if (r!=KErrNone) break;
   881 		time[0] = dC.iTime;
   882 
   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;
   887 		time[1] = dC.iTime;
   888 
   889 		if(CacheInfo.iOuterCache)
   890 			{
   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;
   895 			time[2] = dC.iTime;
   896 			//
   897 			dC.iCacheAttr = RCacheTestDevice::E_InOutWB;
   898 			r = Device.TestCodeChunk(dC);
   899 			if (r!=KErrNone) break;
   900 			time[3] = dC.iTime;
   901 			}
   902 		else
   903 			{
   904 			time[2]=time[3] = 0;
   905 			}	
   906 
   907 		test.Printf(_L("%d\t%d\t%d\t%d\t%d\n"),size/0x400, time[0],time[1],time[2],time[3]);
   908 		size += aIncrement;
   909 		}
   910 
   911 	test.Printf(_L("The test exited with %d\n"), r);
   912 	test.Printf(_L("Press any key...\n"));
   913 	test.Getch();
   914 	StopDriver();	
   915 	test.End();
   916 	}
   917 
   918 TInt E32Main()
   919 	{
   920 
   921 	TBuf<64> c;
   922 	TInt size;
   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;}
   927 
   928 	if (c.FindF(KTestData) >= 0)
   929 		{
   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;
   934 		
   935 		if (c.FindF(KIncremental) >= 0)
   936 			{
   937 			// Invoked by "t_cache data+<size>"
   938 			test.Printf(_L(" size + %xH\n"),size);
   939 			if (size<=0)
   940 					return KErrArgument;
   941 			ManualDataTestIncremental(size);	
   942 			}
   943 		else
   944 			{
   945 			// Invoked by "t_cache data <size>"
   946 			test.Printf(_L("chunk size %xH\n"),size);
   947 			if (size<=0)
   948 					return KErrArgument;
   949 			ManualDataTest(size);	
   950 			}
   951 		return 0;
   952 		}
   953 
   954 	if (c.FindF(KTestCode) >= 0)
   955 		{
   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)
   961 			{
   962 			// Invoked by "t_cache code+<size>"
   963 			test.Printf(_L(" size + %xH\n"),size);
   964 			if (size<=0)
   965 					return KErrArgument;
   966 			ManualCodeTestIncremental(size);	
   967 			}
   968 		else
   969 			{
   970 			// Invoked by "t_cache code <size>"
   971 			test.Printf(_L("chunk size %xH\n"),size);
   972 			if (size<=0)
   973 					return KErrArgument;
   974 			ManualCodeTest(size);	
   975 			}
   976 		return 0;
   977 		}
   978 
   979 	if (c.FindF(KHelp) >= 0)
   980 		{
   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"));
   992 		test.Getch();
   993 		test.End();
   994 		return 0;
   995 		}
   996 
   997 	
   998 	// auto test starts here
   999 	CTrapCleanup* trap = CTrapCleanup::New();
  1000 	if (!trap)
  1001 		return KErrNoMemory;
  1002 	test.Title();
  1003 	__UHEAP_MARK;
  1004 	TRAPD(r,AutoTestL());
  1005 	__UHEAP_MARKEND;
  1006 	delete trap;
  1007 	return r;
  1008 	}