os/kernelhwsrv/kerneltest/e32test/mmu/t_mwait.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/mmu/t_mwait.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,151 @@
     1.4 +// Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of the License "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// e32test\mmu\t_mwait.cpp
    1.18 +// Overview:
    1.19 +// Memory Wait State tests
    1.20 +// API Information:
    1.21 +// RChunk
    1.22 +// Details:
    1.23 +// - Load and open the logical device driver ("D_SHADOW.LDD"). Verify
    1.24 +// results.
    1.25 +// - Create a user writable code chunk and copy a small "SpeedTest" function
    1.26 +// into the chunk.
    1.27 +// - Perform a speed test in shadow ROM and RAM and report the relative performance.
    1.28 +// Platforms/Drives/Compatibility:
    1.29 +// All.
    1.30 +// Assumptions/Requirement/Pre-requisites:
    1.31 +// Failures and causes:
    1.32 +// Base Port information:
    1.33 +// 
    1.34 +//
    1.35 +
    1.36 +#include <e32test.h>
    1.37 +#include "u32std.h"
    1.38 +#include "d_shadow.h"
    1.39 +
    1.40 +RTest test(_L("T_MWAIT"));
    1.41 +
    1.42 +typedef TLinAddr (*TMemSpeedTest)(TInt,TInt&);
    1.43 +
    1.44 +extern TLinAddr MemSpeedTest(TInt /*aLoopSize*/, TInt& /*aCount*/);
    1.45 +
    1.46 +TMemSpeedTest TheSpeedTestFunction;
    1.47 +TInt TheLoopSize;
    1.48 +TInt Count;
    1.49 +RSemaphore TheSemaphore;
    1.50 +TUint8* RamSpeedTestCodePtr;	// speed test code will be copied here to run from RAM
    1.51 +
    1.52 +void CopyCode(RChunk& aC)
    1.53 +	{
    1.54 +	TLinAddr code_begin=(TLinAddr)&MemSpeedTest;
    1.55 +	TInt dummy;
    1.56 +	TLinAddr code_end=MemSpeedTest(0,dummy);
    1.57 +	TInt code_size=TInt(code_end-code_begin);
    1.58 +	test.Printf(_L("ROM Code start: %08x\n"), code_begin);
    1.59 +	test.Printf(_L("ROM Code end  : %08x\n"), code_end);
    1.60 +	test.Printf(_L("ROM Code size : %08x\n"), code_size);
    1.61 +	TInt r = aC.CreateLocalCode(code_size, code_size);
    1.62 +	test(r==KErrNone);
    1.63 +	RamSpeedTestCodePtr = aC.Base();
    1.64 +	Mem::Copy(RamSpeedTestCodePtr, (const TAny*)code_begin, code_size);
    1.65 +	User::IMB_Range(RamSpeedTestCodePtr, RamSpeedTestCodePtr + code_size - 1);
    1.66 +	test.Printf(_L("RAM Code base : %08x\n"), RamSpeedTestCodePtr);
    1.67 +	}
    1.68 +
    1.69 +TInt MemSpeedTestThread(TAny*)
    1.70 +	{
    1.71 +	TheSemaphore.Signal();
    1.72 +	(*TheSpeedTestFunction)(TheLoopSize,Count);
    1.73 +	return 0;
    1.74 +	}
    1.75 +
    1.76 +const TInt KHeapSize=4096;
    1.77 +TInt KMemSpeedTestAddress = (TInt)(&MemSpeedTest);
    1.78 +
    1.79 +TInt DoMemSpeedTest(TBool aRam, TInt aLoopSize)
    1.80 +	{
    1.81 +	if (aRam)
    1.82 +#ifdef __MARM__
    1.83 +		TheSpeedTestFunction=(TMemSpeedTest)(RamSpeedTestCodePtr+(KMemSpeedTestAddress&1));	// add 1 if THUMB function
    1.84 +#else
    1.85 +		TheSpeedTestFunction=(TMemSpeedTest)RamSpeedTestCodePtr;
    1.86 +#endif
    1.87 +	else
    1.88 +		TheSpeedTestFunction=MemSpeedTest;
    1.89 +	Count=0;
    1.90 +	TheLoopSize=aLoopSize;
    1.91 +	RShadow sh;
    1.92 +	TInt r=sh.Open();
    1.93 +	test(r==KErrNone);
    1.94 +	RThread t;
    1.95 +	r=t.Create(_L("Speedy"),MemSpeedTestThread,KDefaultStackSize,KHeapSize,KHeapSize,NULL);
    1.96 +	test(r==KErrNone);
    1.97 +//	t.SetPriority(EPriorityLess);
    1.98 +	sh.SetPriority(t.Handle(),25);
    1.99 +	sh.SetPriority(RThread().Handle(),26);
   1.100 +	TRequestStatus s;
   1.101 +	t.Logon(s);
   1.102 +	t.Resume();
   1.103 +	TheSemaphore.Wait();
   1.104 +	User::After(1000000);
   1.105 +	t.Kill(0);
   1.106 +	sh.SetPriority(RThread().Handle(),12);	// so thread gets cleaned up
   1.107 +	User::WaitForRequest(s);
   1.108 +	test(s.Int()==KErrNone);
   1.109 +	test(t.ExitType()==EExitKill);
   1.110 +	CLOSE_AND_WAIT(t);
   1.111 +	sh.Close();
   1.112 +	return Count;
   1.113 +	}
   1.114 +
   1.115 +void DoFullTest(TBool aRam)
   1.116 +	{
   1.117 +	TInt count[32];
   1.118 +	TInt i;
   1.119 +	for (i=0; i<32; i++)
   1.120 +		{
   1.121 +		TInt loopSize=(i+1)*2048;
   1.122 +		test.Printf(_L("Loop size %dK "),loopSize>>10);
   1.123 +		count[i]=DoMemSpeedTest(aRam,loopSize);
   1.124 +		TInt64 inst = TInt64(count[i]) * TInt64(loopSize>>2);
   1.125 +		test.Printf(_L("%d loops %ld instructions\n"),count[i],inst);
   1.126 +		}
   1.127 +	test.Printf(_L("\n"));
   1.128 +	}
   1.129 +
   1.130 +GLDEF_C TInt E32Main()
   1.131 +	{
   1.132 +	test.Title();
   1.133 +
   1.134 +	test.Start(_L("Memory Wait State tests"));
   1.135 +
   1.136 +	TInt r=TheSemaphore.CreateLocal(0);
   1.137 +	test(r==KErrNone);
   1.138 +
   1.139 +	r=User::LoadLogicalDevice(_L("D_SHADOW"));
   1.140 +	test(r==KErrNone || r==KErrAlreadyExists);
   1.141 +
   1.142 +	RChunk c;
   1.143 +	CopyCode(c);
   1.144 +
   1.145 +	test.Next(_L("Testing ROM wait states..."));
   1.146 +	DoFullTest(EFalse);
   1.147 +
   1.148 +	test.Next(_L("Testing RAM wait states..."));
   1.149 +	DoFullTest(ETrue);
   1.150 +
   1.151 +	c.Close();
   1.152 +	test.End();
   1.153 +	return 0;
   1.154 +	}