os/kernelhwsrv/kerneltest/e32test/mmu/t_mwait.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.
sl@0
     1
// Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of the License "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// e32test\mmu\t_mwait.cpp
sl@0
    15
// Overview:
sl@0
    16
// Memory Wait State tests
sl@0
    17
// API Information:
sl@0
    18
// RChunk
sl@0
    19
// Details:
sl@0
    20
// - Load and open the logical device driver ("D_SHADOW.LDD"). Verify
sl@0
    21
// results.
sl@0
    22
// - Create a user writable code chunk and copy a small "SpeedTest" function
sl@0
    23
// into the chunk.
sl@0
    24
// - Perform a speed test in shadow ROM and RAM and report the relative performance.
sl@0
    25
// Platforms/Drives/Compatibility:
sl@0
    26
// All.
sl@0
    27
// Assumptions/Requirement/Pre-requisites:
sl@0
    28
// Failures and causes:
sl@0
    29
// Base Port information:
sl@0
    30
// 
sl@0
    31
//
sl@0
    32
sl@0
    33
#include <e32test.h>
sl@0
    34
#include "u32std.h"
sl@0
    35
#include "d_shadow.h"
sl@0
    36
sl@0
    37
RTest test(_L("T_MWAIT"));
sl@0
    38
sl@0
    39
typedef TLinAddr (*TMemSpeedTest)(TInt,TInt&);
sl@0
    40
sl@0
    41
extern TLinAddr MemSpeedTest(TInt /*aLoopSize*/, TInt& /*aCount*/);
sl@0
    42
sl@0
    43
TMemSpeedTest TheSpeedTestFunction;
sl@0
    44
TInt TheLoopSize;
sl@0
    45
TInt Count;
sl@0
    46
RSemaphore TheSemaphore;
sl@0
    47
TUint8* RamSpeedTestCodePtr;	// speed test code will be copied here to run from RAM
sl@0
    48
sl@0
    49
void CopyCode(RChunk& aC)
sl@0
    50
	{
sl@0
    51
	TLinAddr code_begin=(TLinAddr)&MemSpeedTest;
sl@0
    52
	TInt dummy;
sl@0
    53
	TLinAddr code_end=MemSpeedTest(0,dummy);
sl@0
    54
	TInt code_size=TInt(code_end-code_begin);
sl@0
    55
	test.Printf(_L("ROM Code start: %08x\n"), code_begin);
sl@0
    56
	test.Printf(_L("ROM Code end  : %08x\n"), code_end);
sl@0
    57
	test.Printf(_L("ROM Code size : %08x\n"), code_size);
sl@0
    58
	TInt r = aC.CreateLocalCode(code_size, code_size);
sl@0
    59
	test(r==KErrNone);
sl@0
    60
	RamSpeedTestCodePtr = aC.Base();
sl@0
    61
	Mem::Copy(RamSpeedTestCodePtr, (const TAny*)code_begin, code_size);
sl@0
    62
	User::IMB_Range(RamSpeedTestCodePtr, RamSpeedTestCodePtr + code_size - 1);
sl@0
    63
	test.Printf(_L("RAM Code base : %08x\n"), RamSpeedTestCodePtr);
sl@0
    64
	}
sl@0
    65
sl@0
    66
TInt MemSpeedTestThread(TAny*)
sl@0
    67
	{
sl@0
    68
	TheSemaphore.Signal();
sl@0
    69
	(*TheSpeedTestFunction)(TheLoopSize,Count);
sl@0
    70
	return 0;
sl@0
    71
	}
sl@0
    72
sl@0
    73
const TInt KHeapSize=4096;
sl@0
    74
TInt KMemSpeedTestAddress = (TInt)(&MemSpeedTest);
sl@0
    75
sl@0
    76
TInt DoMemSpeedTest(TBool aRam, TInt aLoopSize)
sl@0
    77
	{
sl@0
    78
	if (aRam)
sl@0
    79
#ifdef __MARM__
sl@0
    80
		TheSpeedTestFunction=(TMemSpeedTest)(RamSpeedTestCodePtr+(KMemSpeedTestAddress&1));	// add 1 if THUMB function
sl@0
    81
#else
sl@0
    82
		TheSpeedTestFunction=(TMemSpeedTest)RamSpeedTestCodePtr;
sl@0
    83
#endif
sl@0
    84
	else
sl@0
    85
		TheSpeedTestFunction=MemSpeedTest;
sl@0
    86
	Count=0;
sl@0
    87
	TheLoopSize=aLoopSize;
sl@0
    88
	RShadow sh;
sl@0
    89
	TInt r=sh.Open();
sl@0
    90
	test(r==KErrNone);
sl@0
    91
	RThread t;
sl@0
    92
	r=t.Create(_L("Speedy"),MemSpeedTestThread,KDefaultStackSize,KHeapSize,KHeapSize,NULL);
sl@0
    93
	test(r==KErrNone);
sl@0
    94
//	t.SetPriority(EPriorityLess);
sl@0
    95
	sh.SetPriority(t.Handle(),25);
sl@0
    96
	sh.SetPriority(RThread().Handle(),26);
sl@0
    97
	TRequestStatus s;
sl@0
    98
	t.Logon(s);
sl@0
    99
	t.Resume();
sl@0
   100
	TheSemaphore.Wait();
sl@0
   101
	User::After(1000000);
sl@0
   102
	t.Kill(0);
sl@0
   103
	sh.SetPriority(RThread().Handle(),12);	// so thread gets cleaned up
sl@0
   104
	User::WaitForRequest(s);
sl@0
   105
	test(s.Int()==KErrNone);
sl@0
   106
	test(t.ExitType()==EExitKill);
sl@0
   107
	CLOSE_AND_WAIT(t);
sl@0
   108
	sh.Close();
sl@0
   109
	return Count;
sl@0
   110
	}
sl@0
   111
sl@0
   112
void DoFullTest(TBool aRam)
sl@0
   113
	{
sl@0
   114
	TInt count[32];
sl@0
   115
	TInt i;
sl@0
   116
	for (i=0; i<32; i++)
sl@0
   117
		{
sl@0
   118
		TInt loopSize=(i+1)*2048;
sl@0
   119
		test.Printf(_L("Loop size %dK "),loopSize>>10);
sl@0
   120
		count[i]=DoMemSpeedTest(aRam,loopSize);
sl@0
   121
		TInt64 inst = TInt64(count[i]) * TInt64(loopSize>>2);
sl@0
   122
		test.Printf(_L("%d loops %ld instructions\n"),count[i],inst);
sl@0
   123
		}
sl@0
   124
	test.Printf(_L("\n"));
sl@0
   125
	}
sl@0
   126
sl@0
   127
GLDEF_C TInt E32Main()
sl@0
   128
	{
sl@0
   129
	test.Title();
sl@0
   130
sl@0
   131
	test.Start(_L("Memory Wait State tests"));
sl@0
   132
sl@0
   133
	TInt r=TheSemaphore.CreateLocal(0);
sl@0
   134
	test(r==KErrNone);
sl@0
   135
sl@0
   136
	r=User::LoadLogicalDevice(_L("D_SHADOW"));
sl@0
   137
	test(r==KErrNone || r==KErrAlreadyExists);
sl@0
   138
sl@0
   139
	RChunk c;
sl@0
   140
	CopyCode(c);
sl@0
   141
sl@0
   142
	test.Next(_L("Testing ROM wait states..."));
sl@0
   143
	DoFullTest(EFalse);
sl@0
   144
sl@0
   145
	test.Next(_L("Testing RAM wait states..."));
sl@0
   146
	DoFullTest(ETrue);
sl@0
   147
sl@0
   148
	c.Close();
sl@0
   149
	test.End();
sl@0
   150
	return 0;
sl@0
   151
	}