kerneltest/e32test/mmu/t_ramall.cpp
changeset 0 a41df078684a
child 4 56f325a607ea
equal deleted inserted replaced
-1:000000000000 0:a41df078684a
       
     1 // Copyright (c) 1997-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_ramall.cpp
       
    15 // 
       
    16 //
       
    17 
       
    18 #define __E32TEST_EXTENSION__
       
    19 
       
    20 #include <e32test.h>
       
    21 #include <e32uid.h>
       
    22 #include <e32hal.h>
       
    23 #include "d_shadow.h"
       
    24 #include "mmudetect.h"
       
    25 #include "freeram.h"
       
    26 
       
    27 LOCAL_D RTest test(_L("T_RAMALL"));
       
    28 
       
    29 _LIT(KLddFileName,"D_SHADOW.LDD");
       
    30 
       
    31 TInt PageSize;
       
    32 TInt PageShift;
       
    33 RShadow Shadow;
       
    34 TInt InitFreeRam;
       
    35 
       
    36 TInt AllocPhysicalRam(TUint32& aAddr, TInt aSize, TInt aAlign)
       
    37 	{
       
    38 	return Shadow.AllocPhysicalRam(aAddr,aSize,aAlign);
       
    39 	}
       
    40 
       
    41 TInt FreePhysicalRam(TUint32 aAddr, TInt aSize)
       
    42 	{
       
    43 	return Shadow.FreePhysicalRam(aAddr,aSize);
       
    44 	}
       
    45 
       
    46 TInt ClaimPhysicalRam(TUint32 aAddr, TInt aSize)
       
    47 	{
       
    48 	return Shadow.ClaimPhysicalRam(aAddr,aSize);
       
    49 	}
       
    50 
       
    51 void TestAlignedAllocs()
       
    52 	{
       
    53 	TInt align;
       
    54 	TInt size;
       
    55 	for (align=PageShift; align<=20; ++align)
       
    56 		{
       
    57 		for (size=PageSize; size<=0x100000; size+=PageSize)
       
    58 			{
       
    59 			TInt free=FreeRam();
       
    60 			TUint32 pa=0;
       
    61 			TInt r=AllocPhysicalRam(pa,size,align);
       
    62 			test.Printf(_L("Size %08x Align %d r=%d pa=%08x\n"),size,align,r,pa);
       
    63 			if (r==KErrNone)
       
    64 				{
       
    65 				TUint32 as=1u<<align;
       
    66 				TUint32 am=as-1;
       
    67 				test(FreeRam()==free-size);
       
    68 				test((pa&am)==0);
       
    69 				r=FreePhysicalRam(pa,size);
       
    70 				test(r==KErrNone);
       
    71 				}
       
    72 			test(FreeRam()==free);
       
    73 			}
       
    74 		}
       
    75 	}
       
    76 
       
    77 void TestClaimPhys()
       
    78 	{
       
    79 	TInt free=FreeRam();
       
    80 	TUint32 pa=0;
       
    81 	TInt r=AllocPhysicalRam(pa,4*PageSize,0);
       
    82 	test(r==KErrNone);
       
    83 	test(FreeRam()==free-4*PageSize);
       
    84 	r=FreePhysicalRam(pa,4*PageSize);
       
    85 	test(r==KErrNone);
       
    86 	test(FreeRam()==free);
       
    87 	r=ClaimPhysicalRam(pa,4*PageSize);
       
    88 	test(r==KErrNone);
       
    89 	test(FreeRam()==free-4*PageSize);
       
    90 	r=FreePhysicalRam(pa,3*PageSize);
       
    91 	test(r==KErrNone);
       
    92 	test(FreeRam()==free-PageSize);
       
    93 	r=ClaimPhysicalRam(pa,4*PageSize);
       
    94 	test(r==KErrInUse);
       
    95 	test(FreeRam()==free-PageSize);
       
    96 	if (HaveVirtMem())
       
    97 		{
       
    98 		r=FreePhysicalRam(pa,4*PageSize);
       
    99 		test(r==KErrGeneral);
       
   100 		test(FreeRam()==free-PageSize);
       
   101 		}
       
   102 	r=FreePhysicalRam(pa+3*PageSize,PageSize);
       
   103 	test(r==KErrNone);
       
   104 	test(FreeRam()==free);
       
   105 	}
       
   106 
       
   107 GLDEF_C TInt E32Main()
       
   108 //
       
   109 // Test RAM allocation
       
   110 //
       
   111     {
       
   112 	test.Title();
       
   113 	test.Start(_L("Load test LDD"));
       
   114 	TInt r=User::LoadLogicalDevice(KLddFileName);
       
   115 	test(r==KErrNone || r==KErrAlreadyExists);
       
   116 
       
   117 	r=UserHal::PageSizeInBytes(PageSize);
       
   118 	test(r==KErrNone);
       
   119 
       
   120 	TInt psz=PageSize;
       
   121 	PageShift=-1;
       
   122 	for (; psz; psz>>=1, ++PageShift);
       
   123 
       
   124 	InitFreeRam=FreeRam();
       
   125 	test.Printf(_L("Free RAM=%08x, Page size=%x, Page shift=%d\n"),InitFreeRam,PageSize,PageShift);
       
   126 
       
   127 	test.Next(_L("Open test LDD"));
       
   128 	r=Shadow.Open();
       
   129 	test(r==KErrNone);
       
   130 
       
   131 	TestAlignedAllocs();
       
   132 	TestClaimPhys();
       
   133 
       
   134 	Shadow.Close();
       
   135 	test.End();
       
   136 	return(KErrNone);
       
   137     }
       
   138