Update contrib.
     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".
 
     8 // Initial Contributors:
 
     9 // Nokia Corporation - initial contribution.
 
    14 // e32test\mmu\t_mwait.cpp
 
    16 // Memory Wait State tests
 
    20 // - Load and open the logical device driver ("D_SHADOW.LDD"). Verify
 
    22 // - Create a user writable code chunk and copy a small "SpeedTest" function
 
    24 // - Perform a speed test in shadow ROM and RAM and report the relative performance.
 
    25 // Platforms/Drives/Compatibility:
 
    27 // Assumptions/Requirement/Pre-requisites:
 
    28 // Failures and causes:
 
    29 // Base Port information:
 
    37 RTest test(_L("T_MWAIT"));
 
    39 typedef TLinAddr (*TMemSpeedTest)(TInt,TInt&);
 
    41 extern TLinAddr MemSpeedTest(TInt /*aLoopSize*/, TInt& /*aCount*/);
 
    43 TMemSpeedTest TheSpeedTestFunction;
 
    46 RSemaphore TheSemaphore;
 
    47 TUint8* RamSpeedTestCodePtr;	// speed test code will be copied here to run from RAM
 
    49 void CopyCode(RChunk& aC)
 
    51 	TLinAddr code_begin=(TLinAddr)&MemSpeedTest;
 
    53 	TLinAddr code_end=MemSpeedTest(0,dummy);
 
    54 	TInt code_size=TInt(code_end-code_begin);
 
    55 	test.Printf(_L("ROM Code start: %08x\n"), code_begin);
 
    56 	test.Printf(_L("ROM Code end  : %08x\n"), code_end);
 
    57 	test.Printf(_L("ROM Code size : %08x\n"), code_size);
 
    58 	TInt r = aC.CreateLocalCode(code_size, code_size);
 
    60 	RamSpeedTestCodePtr = aC.Base();
 
    61 	Mem::Copy(RamSpeedTestCodePtr, (const TAny*)code_begin, code_size);
 
    62 	User::IMB_Range(RamSpeedTestCodePtr, RamSpeedTestCodePtr + code_size - 1);
 
    63 	test.Printf(_L("RAM Code base : %08x\n"), RamSpeedTestCodePtr);
 
    66 TInt MemSpeedTestThread(TAny*)
 
    68 	TheSemaphore.Signal();
 
    69 	(*TheSpeedTestFunction)(TheLoopSize,Count);
 
    73 const TInt KHeapSize=4096;
 
    74 TInt KMemSpeedTestAddress = (TInt)(&MemSpeedTest);
 
    76 TInt DoMemSpeedTest(TBool aRam, TInt aLoopSize)
 
    80 		TheSpeedTestFunction=(TMemSpeedTest)(RamSpeedTestCodePtr+(KMemSpeedTestAddress&1));	// add 1 if THUMB function
 
    82 		TheSpeedTestFunction=(TMemSpeedTest)RamSpeedTestCodePtr;
 
    85 		TheSpeedTestFunction=MemSpeedTest;
 
    87 	TheLoopSize=aLoopSize;
 
    92 	r=t.Create(_L("Speedy"),MemSpeedTestThread,KDefaultStackSize,KHeapSize,KHeapSize,NULL);
 
    94 //	t.SetPriority(EPriorityLess);
 
    95 	sh.SetPriority(t.Handle(),25);
 
    96 	sh.SetPriority(RThread().Handle(),26);
 
   101 	User::After(1000000);
 
   103 	sh.SetPriority(RThread().Handle(),12);	// so thread gets cleaned up
 
   104 	User::WaitForRequest(s);
 
   105 	test(s.Int()==KErrNone);
 
   106 	test(t.ExitType()==EExitKill);
 
   112 void DoFullTest(TBool aRam)
 
   118 		TInt loopSize=(i+1)*2048;
 
   119 		test.Printf(_L("Loop size %dK "),loopSize>>10);
 
   120 		count[i]=DoMemSpeedTest(aRam,loopSize);
 
   121 		TInt64 inst = TInt64(count[i]) * TInt64(loopSize>>2);
 
   122 		test.Printf(_L("%d loops %ld instructions\n"),count[i],inst);
 
   124 	test.Printf(_L("\n"));
 
   127 GLDEF_C TInt E32Main()
 
   131 	test.Start(_L("Memory Wait State tests"));
 
   133 	TInt r=TheSemaphore.CreateLocal(0);
 
   136 	r=User::LoadLogicalDevice(_L("D_SHADOW"));
 
   137 	test(r==KErrNone || r==KErrAlreadyExists);
 
   142 	test.Next(_L("Testing ROM wait states..."));
 
   145 	test.Next(_L("Testing RAM wait states..."));