1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/mmu/t_ramall.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,155 @@
1.4 +// Copyright (c) 1997-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_ramall.cpp
1.18 +//
1.19 +//
1.20 +
1.21 +#define __E32TEST_EXTENSION__
1.22 +
1.23 +#include <e32test.h>
1.24 +#include <e32uid.h>
1.25 +#include <e32hal.h>
1.26 +#include "d_shadow.h"
1.27 +#include "mmudetect.h"
1.28 +#include "freeram.h"
1.29 +
1.30 +LOCAL_D RTest test(_L("T_RAMALL"));
1.31 +
1.32 +_LIT(KLddFileName,"D_SHADOW.LDD");
1.33 +
1.34 +TInt PageSize;
1.35 +TInt PageShift;
1.36 +RShadow Shadow;
1.37 +TInt InitFreeRam;
1.38 +
1.39 +TInt AllocPhysicalRam(TUint32& aAddr, TInt aSize, TInt aAlign)
1.40 + {
1.41 + return Shadow.AllocPhysicalRam(aAddr,aSize,aAlign);
1.42 + }
1.43 +
1.44 +TInt FreePhysicalRam(TUint32 aAddr, TInt aSize)
1.45 + {
1.46 + return Shadow.FreePhysicalRam(aAddr,aSize);
1.47 + }
1.48 +
1.49 +TInt ClaimPhysicalRam(TUint32 aAddr, TInt aSize)
1.50 + {
1.51 + return Shadow.ClaimPhysicalRam(aAddr,aSize);
1.52 + }
1.53 +
1.54 +void TestAlignedAllocs()
1.55 + {
1.56 + TInt align;
1.57 + TInt size;
1.58 + for (align=PageShift; align<=20; ++align)
1.59 + {
1.60 + for (size=PageSize; size<=0x100000; size+=PageSize)
1.61 + {
1.62 + TInt free=FreeRam();
1.63 + TUint32 pa=0;
1.64 + TInt r=AllocPhysicalRam(pa,size,align);
1.65 + test.Printf(_L("Size %08x Align %d r=%d pa=%08x\n"),size,align,r,pa);
1.66 + if (r==KErrNone)
1.67 + {
1.68 + TUint32 as=1u<<align;
1.69 + TUint32 am=as-1;
1.70 + test(FreeRam()==free-size);
1.71 + test((pa&am)==0);
1.72 + r=FreePhysicalRam(pa,size);
1.73 + test(r==KErrNone);
1.74 + }
1.75 + test(FreeRam()==free);
1.76 + }
1.77 + }
1.78 + }
1.79 +
1.80 +void TestClaimPhys()
1.81 + {
1.82 + TInt free=FreeRam();
1.83 +
1.84 + TUint32 pa=0;
1.85 + TInt r=AllocPhysicalRam(pa,4*PageSize,0);
1.86 + test(r==KErrNone);
1.87 + test(FreeRam()==free-4*PageSize);
1.88 +
1.89 + r=FreePhysicalRam(pa,4*PageSize);
1.90 + test(r==KErrNone);
1.91 + test(FreeRam()==free);
1.92 +
1.93 + r=ClaimPhysicalRam(pa,4*PageSize);
1.94 + test(r==KErrNone);
1.95 + test(FreeRam()==free-4*PageSize);
1.96 +
1.97 + r=FreePhysicalRam(pa,3*PageSize);
1.98 + test(r==KErrNone);
1.99 + test(FreeRam()==free-PageSize);
1.100 +
1.101 + r=ClaimPhysicalRam(pa,4*PageSize);
1.102 + test(r==KErrInUse);
1.103 + test(FreeRam()==free-PageSize);
1.104 +
1.105 +#ifdef MANUAL_PANIC_TEST
1.106 +//This section of the test should be run as a manual test as it results in
1.107 +// a panic due to attempting to Free an unclaimed page
1.108 + if (HaveVirtMem())
1.109 + {
1.110 + test.Printf(_L("HaveVirtMem() \n"));
1.111 + r=FreePhysicalRam(pa,4*PageSize);
1.112 + test.Printf(_L("FreePhysicalRam() \n"));
1.113 + test(r==KErrGeneral);
1.114 + test(FreeRam()==free-PageSize);
1.115 + }
1.116 +#endif
1.117 +
1.118 + r=FreePhysicalRam(pa+3*PageSize,PageSize);
1.119 + test(r==KErrNone);
1.120 + test(FreeRam()==free);
1.121 +
1.122 + }
1.123 +
1.124 +GLDEF_C TInt E32Main()
1.125 +//
1.126 +// Test RAM allocation
1.127 +//
1.128 + {
1.129 + test.Title();
1.130 + test.Start(_L("Load test LDD"));
1.131 + TInt r=User::LoadLogicalDevice(KLddFileName);
1.132 + test(r==KErrNone || r==KErrAlreadyExists);
1.133 +
1.134 + r=UserHal::PageSizeInBytes(PageSize);
1.135 + test(r==KErrNone);
1.136 +
1.137 + TInt psz=PageSize;
1.138 + PageShift=-1;
1.139 + for (; psz; psz>>=1, ++PageShift);
1.140 +
1.141 + InitFreeRam=FreeRam();
1.142 + test.Printf(_L("Free RAM=%08x, Page size=%x, Page shift=%d\n"),InitFreeRam,PageSize,PageShift);
1.143 +
1.144 + test.Next(_L("Open test LDD"));
1.145 + r=Shadow.Open();
1.146 + test(r==KErrNone);
1.147 +
1.148 + test.Next(_L("TestAlignedAllocs"));
1.149 + TestAlignedAllocs();
1.150 +
1.151 + test.Next(_L("TestClaimPhys"));
1.152 + TestClaimPhys();
1.153 +
1.154 + Shadow.Close();
1.155 + test.End();
1.156 + return(KErrNone);
1.157 + }
1.158 +