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