kerneltest/e32test/mmu/t_mwait.cpp
changeset 0 a41df078684a
equal deleted inserted replaced
-1:000000000000 0:a41df078684a
       
     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".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // e32test\mmu\t_mwait.cpp
       
    15 // Overview:
       
    16 // Memory Wait State tests
       
    17 // API Information:
       
    18 // RChunk
       
    19 // Details:
       
    20 // - Load and open the logical device driver ("D_SHADOW.LDD"). Verify
       
    21 // results.
       
    22 // - Create a user writable code chunk and copy a small "SpeedTest" function
       
    23 // into the chunk.
       
    24 // - Perform a speed test in shadow ROM and RAM and report the relative performance.
       
    25 // Platforms/Drives/Compatibility:
       
    26 // All.
       
    27 // Assumptions/Requirement/Pre-requisites:
       
    28 // Failures and causes:
       
    29 // Base Port information:
       
    30 // 
       
    31 //
       
    32 
       
    33 #include <e32test.h>
       
    34 #include "u32std.h"
       
    35 #include "d_shadow.h"
       
    36 
       
    37 RTest test(_L("T_MWAIT"));
       
    38 
       
    39 typedef TLinAddr (*TMemSpeedTest)(TInt,TInt&);
       
    40 
       
    41 extern TLinAddr MemSpeedTest(TInt /*aLoopSize*/, TInt& /*aCount*/);
       
    42 
       
    43 TMemSpeedTest TheSpeedTestFunction;
       
    44 TInt TheLoopSize;
       
    45 TInt Count;
       
    46 RSemaphore TheSemaphore;
       
    47 TUint8* RamSpeedTestCodePtr;	// speed test code will be copied here to run from RAM
       
    48 
       
    49 void CopyCode(RChunk& aC)
       
    50 	{
       
    51 	TLinAddr code_begin=(TLinAddr)&MemSpeedTest;
       
    52 	TInt dummy;
       
    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);
       
    59 	test(r==KErrNone);
       
    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);
       
    64 	}
       
    65 
       
    66 TInt MemSpeedTestThread(TAny*)
       
    67 	{
       
    68 	TheSemaphore.Signal();
       
    69 	(*TheSpeedTestFunction)(TheLoopSize,Count);
       
    70 	return 0;
       
    71 	}
       
    72 
       
    73 const TInt KHeapSize=4096;
       
    74 TInt KMemSpeedTestAddress = (TInt)(&MemSpeedTest);
       
    75 
       
    76 TInt DoMemSpeedTest(TBool aRam, TInt aLoopSize)
       
    77 	{
       
    78 	if (aRam)
       
    79 #ifdef __MARM__
       
    80 		TheSpeedTestFunction=(TMemSpeedTest)(RamSpeedTestCodePtr+(KMemSpeedTestAddress&1));	// add 1 if THUMB function
       
    81 #else
       
    82 		TheSpeedTestFunction=(TMemSpeedTest)RamSpeedTestCodePtr;
       
    83 #endif
       
    84 	else
       
    85 		TheSpeedTestFunction=MemSpeedTest;
       
    86 	Count=0;
       
    87 	TheLoopSize=aLoopSize;
       
    88 	RShadow sh;
       
    89 	TInt r=sh.Open();
       
    90 	test(r==KErrNone);
       
    91 	RThread t;
       
    92 	r=t.Create(_L("Speedy"),MemSpeedTestThread,KDefaultStackSize,KHeapSize,KHeapSize,NULL);
       
    93 	test(r==KErrNone);
       
    94 //	t.SetPriority(EPriorityLess);
       
    95 	sh.SetPriority(t.Handle(),25);
       
    96 	sh.SetPriority(RThread().Handle(),26);
       
    97 	TRequestStatus s;
       
    98 	t.Logon(s);
       
    99 	t.Resume();
       
   100 	TheSemaphore.Wait();
       
   101 	User::After(1000000);
       
   102 	t.Kill(0);
       
   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);
       
   107 	CLOSE_AND_WAIT(t);
       
   108 	sh.Close();
       
   109 	return Count;
       
   110 	}
       
   111 
       
   112 void DoFullTest(TBool aRam)
       
   113 	{
       
   114 	TInt count[32];
       
   115 	TInt i;
       
   116 	for (i=0; i<32; i++)
       
   117 		{
       
   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);
       
   123 		}
       
   124 	test.Printf(_L("\n"));
       
   125 	}
       
   126 
       
   127 GLDEF_C TInt E32Main()
       
   128 	{
       
   129 	test.Title();
       
   130 
       
   131 	test.Start(_L("Memory Wait State tests"));
       
   132 
       
   133 	TInt r=TheSemaphore.CreateLocal(0);
       
   134 	test(r==KErrNone);
       
   135 
       
   136 	r=User::LoadLogicalDevice(_L("D_SHADOW"));
       
   137 	test(r==KErrNone || r==KErrAlreadyExists);
       
   138 
       
   139 	RChunk c;
       
   140 	CopyCode(c);
       
   141 
       
   142 	test.Next(_L("Testing ROM wait states..."));
       
   143 	DoFullTest(EFalse);
       
   144 
       
   145 	test.Next(_L("Testing RAM wait states..."));
       
   146 	DoFullTest(ETrue);
       
   147 
       
   148 	c.Close();
       
   149 	test.End();
       
   150 	return 0;
       
   151 	}