os/kernelhwsrv/kerneltest/e32test/mmu/t_chunk2.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/mmu/t_chunk2.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,238 @@
     1.4 +// Copyright (c) 1995-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_chunk2.cpp
    1.18 +// Overview:
    1.19 +// Test RChunk class
    1.20 +// API Information:
    1.21 +// RChunk
    1.22 +// Details:
    1.23 +// - Test creating local chunks and moving chunks home address, verify
    1.24 +// results are as expected.
    1.25 +// - Create numerous local chunks, test allocating more space by 
    1.26 +// adjusting chunk size, check for allocation failure, verify results 
    1.27 +// are as expected.
    1.28 +// Platforms/Drives/Compatibility:
    1.29 +// All.
    1.30 +// Assumptions/Requirement/Pre-requisites:
    1.31 +// Failures and causes:
    1.32 +// Base Port information:
    1.33 +// 
    1.34 +//
    1.35 +
    1.36 +#define __E32TEST_EXTENSION__
    1.37 +#include <e32test.h>
    1.38 +#include <e32hal.h>
    1.39 +#include <e32panic.h>
    1.40 +#include "mmudetect.h"
    1.41 +#include "d_gobble.h"
    1.42 +#include "freeram.h"
    1.43 +
    1.44 +TInt GlobalValue=299792458;
    1.45 +TInt *GlobalPtr=&GlobalValue;
    1.46 +
    1.47 +LOCAL_D RTest test(_L("T_CHUNK2"));
    1.48 +LOCAL_D RTest t(_L("ShareThread"));
    1.49 +LOCAL_D RChunk gChunk;
    1.50 +
    1.51 +LOCAL_D TPtr nullPtr(NULL,0);
    1.52 +
    1.53 +LOCAL_C void TestAllocFailure(RChunk& c1, RChunk& c2)
    1.54 +	{
    1.55 +	TInt free=FreeRam();
    1.56 +	test.Printf(_L("Free RAM %dK\n"),free/1024);
    1.57 +	TInt size1=free-0x80000;	// 512K less than available
    1.58 +	TInt size2=0xFF000;			// 255 pages
    1.59 +	test.Printf(_L("Adjusting chunk 1 to size %dK\n"),size1/1024);
    1.60 +	TInt r=c1.Adjust(size1);
    1.61 +	test(r==KErrNone);
    1.62 +	test.Printf(_L("Attempting to adjust chunk 2 to size %dK\n"),size2/1024);
    1.63 +	r=c2.Adjust(size2);
    1.64 +	test(r==KErrNoMemory);
    1.65 +	TInt size3=FreeRam();
    1.66 +	test.Printf(_L("Attempting to adjust chunk 2 to size %dK\n"),size3/1024);
    1.67 +	r=c2.Adjust(size3);
    1.68 +	TInt free2=FreeRam();
    1.69 +	if (r==KErrNone)
    1.70 +		{
    1.71 +		test.Printf(_L("Succeeded - free RAM now %dK\n"),free2/1024);
    1.72 +		test.Printf(_L("Freeing chunk 2\n"));
    1.73 +		r=c2.Adjust(0);
    1.74 +		test(r==KErrNone);
    1.75 +		}
    1.76 +	else
    1.77 +		test.Printf(_L("Failed - free RAM now %dK\n"),free2/1024);
    1.78 +	test.Printf(_L("Freeing chunk 1\n"));
    1.79 +	r=c1.Adjust(0);
    1.80 +	test(r==KErrNone);
    1.81 +	test.Printf(_L("Checking free RAM\n"));
    1.82 +	UserSvr::HalFunction(EHalGroupKernel, EKernelHalSupervisorBarrier, 0, 0);
    1.83 +	free2=FreeRam();
    1.84 +	test.Printf(_L("Free RAM %dK\n"),free2/1024);
    1.85 +	test(free==free2);
    1.86 +	}
    1.87 +
    1.88 +void TestInterleavedAlloc()
    1.89 +	{
    1.90 +	TInt pageSize;
    1.91 +	RChunk c1;
    1.92 +	RChunk c2;
    1.93 +	TInt r;
    1.94 +	r=UserHal::PageSizeInBytes(pageSize);
    1.95 +	test(r==KErrNone);
    1.96 +	r=c1.CreateLocal(0,0x100000);
    1.97 +	test(r==KErrNone);
    1.98 +	r=c2.CreateLocal(0,0x100000);
    1.99 +	test(r==KErrNone);
   1.100 +	TInt step;
   1.101 +	for (step=1; step<=32; ++step)
   1.102 +		{
   1.103 +		test.Printf(_L("Step size %x\n"),step*pageSize);
   1.104 +		while (c1.Size()<64*pageSize)
   1.105 +			{
   1.106 +			r=c1.Adjust(c1.Size()+step*pageSize);
   1.107 +			test(r==KErrNone);
   1.108 +			r=c2.Adjust(c2.Size()+step*pageSize);
   1.109 +			test(r==KErrNone);
   1.110 +			}
   1.111 +		c1.Adjust(0);
   1.112 +		c2.Adjust(0);
   1.113 +		}
   1.114 +	c1.Close();
   1.115 +	c2.Close();
   1.116 +	}
   1.117 +
   1.118 +TInt E32Main()
   1.119 +//
   1.120 +//	Test RChunk class
   1.121 +//
   1.122 +	{
   1.123 +
   1.124 +	test.Title();
   1.125 +	if (!HaveVirtMem())
   1.126 +		{
   1.127 +		test.Printf(_L("This test requires an MMU\n"));
   1.128 +		return KErrNone;
   1.129 +		}
   1.130 +	TestInterleavedAlloc();
   1.131 +	test.Start(_L("Test moving chunks home addresses"));
   1.132 +	test.Printf(_L("GlobalValue=%d\n"),*GlobalPtr);
   1.133 +	++*GlobalPtr;
   1.134 +	test.Printf(_L("GlobalValue=%d\n"),GlobalValue);
   1.135 +
   1.136 +	test.Next(_L("Load gobbler LDD"));
   1.137 +	TInt r = User::LoadLogicalDevice(KGobblerLddFileName);
   1.138 +	test(r==KErrNone || r==KErrAlreadyExists);
   1.139 +	RGobbler gobbler;
   1.140 +	r = gobbler.Open();
   1.141 +	test(r==KErrNone);
   1.142 +	TUint32 taken = gobbler.GobbleRAM(128*1024*1024);
   1.143 +	test.Printf(_L("Gobbled: %dK\n"), taken/1024);
   1.144 +
   1.145 +	TInt free=FreeRam();
   1.146 +	test.Printf(_L("Free RAM 0x%08X bytes\n"),free);
   1.147 +
   1.148 +	RChunk chunk1;
   1.149 +	r=chunk1.CreateLocal(0x400,0x800000);
   1.150 +	test (r==KErrNone);
   1.151 +	TInt i;
   1.152 +	TInt *p=(TInt*)chunk1.Base();
   1.153 +	test.Printf(_L("Chunk 1 Base %08X\n"),p);
   1.154 +	for (i=0; i<0x100; i++)
   1.155 +		*p++=i*i+41;
   1.156 +	RChunk chunk2;
   1.157 +	r=chunk2.CreateLocal(0x400,0x800000);
   1.158 +	test (r==KErrNone);
   1.159 +	TInt *p2=(TInt*)chunk2.Base();
   1.160 +	test.Printf(_L("Chunk 2 Base %08X\n"),p2);
   1.161 +	for (i=0; i<0x100; i++)
   1.162 +		*p2++=i*i*i+487;
   1.163 +	r=chunk1.Adjust(0x120000);
   1.164 +	test (r==KErrNone);
   1.165 +	for (i=0x100; i<0x48000; i++)
   1.166 +		*p++=i*i+41;
   1.167 +	r=chunk2.Adjust(0x120000);
   1.168 +	test (r==KErrNone);
   1.169 +	for (i=0x100; i<0x48000; i++)
   1.170 +		*p2++=i*i*i+487;
   1.171 +	p=(TInt*)chunk1.Base();
   1.172 +	p2=(TInt*)chunk2.Base();
   1.173 +	for(i=0; i<0x48000; i++)
   1.174 +		{
   1.175 +		TInt read1=*p++;
   1.176 +		TInt read2=*p2++;
   1.177 +		if (read1 != (i*i+41))
   1.178 +			{
   1.179 +			test.Printf(_L("Chunk 1 i=%X, read %08X expected %08X\n"),i,read1,i*i+41);
   1.180 +			//test.Getch();
   1.181 +			}
   1.182 +		if (read2 != (i*i*i+487))
   1.183 +			{
   1.184 +			test.Printf(_L("Chunk 2 i=%X, read %08X expected %08X\n"),i,read2,i*i*i+487);
   1.185 +			//test.Getch();
   1.186 +			}
   1.187 +		}
   1.188 +	chunk1.Close();
   1.189 +	chunk2.Close();
   1.190 +	
   1.191 +	TInt free2=FreeRam();
   1.192 +	test.Printf(_L("Free RAM 0x%08X bytes\n"),free2);
   1.193 +	test(free2==free);
   1.194 +
   1.195 +	// Chunks must not be paged otherwise they will not effect the amount 
   1.196 +	// of free ram reported plus on h4 swap size is less than the total ram.
   1.197 +	TChunkCreateInfo createInfo;
   1.198 +	createInfo.SetNormal(0, free+2097152);
   1.199 +	createInfo.SetPaging(TChunkCreateInfo::EUnpaged);
   1.200 +	RChunk c1;
   1.201 +	test_KErrNone(c1.Create(createInfo));
   1.202 +	createInfo.SetNormal(0, 0x1000000);
   1.203 +	RChunk c2;
   1.204 +	RChunk c3;
   1.205 +	RChunk c4;
   1.206 +	RChunk c5;
   1.207 +	RChunk c6;
   1.208 +	test_KErrNone(c2.Create(createInfo));
   1.209 +	test_KErrNone(c3.Create(createInfo));
   1.210 +	test_KErrNone(c4.Create(createInfo));
   1.211 +	test_KErrNone(c5.Create(createInfo));
   1.212 +	test_KErrNone(c6.Create(createInfo));
   1.213 +
   1.214 +	TestAllocFailure(c1,c2);
   1.215 +	r=c3.Adjust(1024);
   1.216 +	test(r==KErrNone);
   1.217 +	TestAllocFailure(c1,c2);
   1.218 +	r=c4.Adjust(1024);
   1.219 +	test(r==KErrNone);
   1.220 +	TestAllocFailure(c1,c2);
   1.221 +	r=c5.Adjust(1024);
   1.222 +	test(r==KErrNone);
   1.223 +	TestAllocFailure(c1,c2);
   1.224 +	r=c6.Adjust(1024);
   1.225 +	test(r==KErrNone);
   1.226 +	TestAllocFailure(c1,c2);
   1.227 +
   1.228 +	c1.Close();
   1.229 +	c2.Close();
   1.230 +	c3.Close();
   1.231 +	c4.Close();
   1.232 +	c5.Close();
   1.233 +	c6.Close();
   1.234 +	gobbler.Close();
   1.235 +
   1.236 +	test.End();
   1.237 +	test.Close();
   1.238 +	return(KErrNone);
   1.239 +	}
   1.240 +
   1.241 +