sl@0: // Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // e32test\mmu\t_mwait.cpp sl@0: // Overview: sl@0: // Memory Wait State tests sl@0: // API Information: sl@0: // RChunk sl@0: // Details: sl@0: // - Load and open the logical device driver ("D_SHADOW.LDD"). Verify sl@0: // results. sl@0: // - Create a user writable code chunk and copy a small "SpeedTest" function sl@0: // into the chunk. sl@0: // - Perform a speed test in shadow ROM and RAM and report the relative performance. sl@0: // Platforms/Drives/Compatibility: sl@0: // All. sl@0: // Assumptions/Requirement/Pre-requisites: sl@0: // Failures and causes: sl@0: // Base Port information: sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include "u32std.h" sl@0: #include "d_shadow.h" sl@0: sl@0: RTest test(_L("T_MWAIT")); sl@0: sl@0: typedef TLinAddr (*TMemSpeedTest)(TInt,TInt&); sl@0: sl@0: extern TLinAddr MemSpeedTest(TInt /*aLoopSize*/, TInt& /*aCount*/); sl@0: sl@0: TMemSpeedTest TheSpeedTestFunction; sl@0: TInt TheLoopSize; sl@0: TInt Count; sl@0: RSemaphore TheSemaphore; sl@0: TUint8* RamSpeedTestCodePtr; // speed test code will be copied here to run from RAM sl@0: sl@0: void CopyCode(RChunk& aC) sl@0: { sl@0: TLinAddr code_begin=(TLinAddr)&MemSpeedTest; sl@0: TInt dummy; sl@0: TLinAddr code_end=MemSpeedTest(0,dummy); sl@0: TInt code_size=TInt(code_end-code_begin); sl@0: test.Printf(_L("ROM Code start: %08x\n"), code_begin); sl@0: test.Printf(_L("ROM Code end : %08x\n"), code_end); sl@0: test.Printf(_L("ROM Code size : %08x\n"), code_size); sl@0: TInt r = aC.CreateLocalCode(code_size, code_size); sl@0: test(r==KErrNone); sl@0: RamSpeedTestCodePtr = aC.Base(); sl@0: Mem::Copy(RamSpeedTestCodePtr, (const TAny*)code_begin, code_size); sl@0: User::IMB_Range(RamSpeedTestCodePtr, RamSpeedTestCodePtr + code_size - 1); sl@0: test.Printf(_L("RAM Code base : %08x\n"), RamSpeedTestCodePtr); sl@0: } sl@0: sl@0: TInt MemSpeedTestThread(TAny*) sl@0: { sl@0: TheSemaphore.Signal(); sl@0: (*TheSpeedTestFunction)(TheLoopSize,Count); sl@0: return 0; sl@0: } sl@0: sl@0: const TInt KHeapSize=4096; sl@0: TInt KMemSpeedTestAddress = (TInt)(&MemSpeedTest); sl@0: sl@0: TInt DoMemSpeedTest(TBool aRam, TInt aLoopSize) sl@0: { sl@0: if (aRam) sl@0: #ifdef __MARM__ sl@0: TheSpeedTestFunction=(TMemSpeedTest)(RamSpeedTestCodePtr+(KMemSpeedTestAddress&1)); // add 1 if THUMB function sl@0: #else sl@0: TheSpeedTestFunction=(TMemSpeedTest)RamSpeedTestCodePtr; sl@0: #endif sl@0: else sl@0: TheSpeedTestFunction=MemSpeedTest; sl@0: Count=0; sl@0: TheLoopSize=aLoopSize; sl@0: RShadow sh; sl@0: TInt r=sh.Open(); sl@0: test(r==KErrNone); sl@0: RThread t; sl@0: r=t.Create(_L("Speedy"),MemSpeedTestThread,KDefaultStackSize,KHeapSize,KHeapSize,NULL); sl@0: test(r==KErrNone); sl@0: // t.SetPriority(EPriorityLess); sl@0: sh.SetPriority(t.Handle(),25); sl@0: sh.SetPriority(RThread().Handle(),26); sl@0: TRequestStatus s; sl@0: t.Logon(s); sl@0: t.Resume(); sl@0: TheSemaphore.Wait(); sl@0: User::After(1000000); sl@0: t.Kill(0); sl@0: sh.SetPriority(RThread().Handle(),12); // so thread gets cleaned up sl@0: User::WaitForRequest(s); sl@0: test(s.Int()==KErrNone); sl@0: test(t.ExitType()==EExitKill); sl@0: CLOSE_AND_WAIT(t); sl@0: sh.Close(); sl@0: return Count; sl@0: } sl@0: sl@0: void DoFullTest(TBool aRam) sl@0: { sl@0: TInt count[32]; sl@0: TInt i; sl@0: for (i=0; i<32; i++) sl@0: { sl@0: TInt loopSize=(i+1)*2048; sl@0: test.Printf(_L("Loop size %dK "),loopSize>>10); sl@0: count[i]=DoMemSpeedTest(aRam,loopSize); sl@0: TInt64 inst = TInt64(count[i]) * TInt64(loopSize>>2); sl@0: test.Printf(_L("%d loops %ld instructions\n"),count[i],inst); sl@0: } sl@0: test.Printf(_L("\n")); sl@0: } sl@0: sl@0: GLDEF_C TInt E32Main() sl@0: { sl@0: test.Title(); sl@0: sl@0: test.Start(_L("Memory Wait State tests")); sl@0: sl@0: TInt r=TheSemaphore.CreateLocal(0); sl@0: test(r==KErrNone); sl@0: sl@0: r=User::LoadLogicalDevice(_L("D_SHADOW")); sl@0: test(r==KErrNone || r==KErrAlreadyExists); sl@0: sl@0: RChunk c; sl@0: CopyCode(c); sl@0: sl@0: test.Next(_L("Testing ROM wait states...")); sl@0: DoFullTest(EFalse); sl@0: sl@0: test.Next(_L("Testing RAM wait states...")); sl@0: DoFullTest(ETrue); sl@0: sl@0: c.Close(); sl@0: test.End(); sl@0: return 0; sl@0: }