os/kernelhwsrv/kerneltest/e32test/mmu/t_wbc.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_wbc.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,108 @@
     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_wbc.cpp
    1.18 +// Overview:
    1.19 +// Read and write RChunk data.
    1.20 +// API Information:
    1.21 +// RChunk
    1.22 +// Details:
    1.23 +// Create two local RChunk objects. Perform ReadModifyWrite, WriteOnly 
    1.24 +// and ReadOnly operations on the chunks. Verify that the results are
    1.25 +// as expected.
    1.26 +// Platforms/Drives/Compatibility:
    1.27 +// All.
    1.28 +// Assumptions/Requirement/Pre-requisites:
    1.29 +// Failures and causes:
    1.30 +// Base Port information:
    1.31 +// 
    1.32 +//
    1.33 +
    1.34 +#include <e32test.h>
    1.35 +#include <e32hal.h>
    1.36 +#include <e32svr.h>
    1.37 +
    1.38 +RTest test(_L("T_WBC"));
    1.39 +
    1.40 +TUint32 ReadModifyWrite(volatile TUint32* p, TInt aNumWords)
    1.41 +	{
    1.42 +	TUint32 x=0;
    1.43 +	while(aNumWords--)
    1.44 +		{
    1.45 +		x=*p;
    1.46 +		*p++=0;
    1.47 +		}
    1.48 +	return x;
    1.49 +	}
    1.50 +
    1.51 +void WriteOnly(volatile TUint32* p, TInt aNumWords)
    1.52 +	{
    1.53 +	while(aNumWords--)
    1.54 +		*p++=0xffffffff;
    1.55 +	}
    1.56 +
    1.57 +TUint32 ReadOnly(volatile TUint32* p, TInt aNumWords)
    1.58 +	{
    1.59 +	TUint32 x=0;
    1.60 +	while(aNumWords--)
    1.61 +		x+=*p++;
    1.62 +	return x;
    1.63 +	}
    1.64 +
    1.65 +void Dump(volatile TUint32* p, TInt aNumWords)
    1.66 +	{
    1.67 +	while(aNumWords>0)
    1.68 +		{
    1.69 +		RDebug::Print(_L("%08x: %08x %08x %08x %08x %08x %08x %08x %08x"),p,
    1.70 +			p[0],p[1],p[2],p[3],p[4],p[5],p[6],p[7]);
    1.71 +		p+=8;
    1.72 +		aNumWords-=8;
    1.73 +		}
    1.74 +	}
    1.75 +
    1.76 +void Verify(volatile TUint32* p, TInt aNumWords)
    1.77 +	{
    1.78 +	while(aNumWords--)
    1.79 +		test(*p++==0xffffffff);
    1.80 +	}
    1.81 +
    1.82 +GLDEF_C TInt E32Main()
    1.83 +	{
    1.84 +	
    1.85 +	TInt pageSize;
    1.86 +	UserHal::PageSizeInBytes(pageSize);
    1.87 +	test.Title();
    1.88 +	test.Start(_L("Create chunk 1"));
    1.89 +	RChunk c1;
    1.90 +	TInt r=c1.CreateLocal(4*pageSize,0x100000);	// initial size 4 pages
    1.91 +	test(r==KErrNone);
    1.92 +	test.Next(_L("Create chunk 2"));
    1.93 +	RChunk c2;
    1.94 +	r=c2.CreateLocal(pageSize,0x100000);		// initial size 1 page
    1.95 +	test(r==KErrNone);
    1.96 +	test.Next(_L("Fill DCache with modified lines from chunk 1"));
    1.97 +	volatile TUint32* p=(volatile TUint32*)(c1.Base()+2*pageSize);
    1.98 +	ReadModifyWrite(p,pageSize>>1);
    1.99 +	c1.Adjust(2*pageSize);		// lose the two modified pages
   1.100 +	c2.Adjust(3*pageSize);		// map them back into chunk 2
   1.101 +	p=(volatile TUint32*)(c2.Base()+pageSize);
   1.102 +	WriteOnly(p,pageSize>>1);	// write to the modified pages at new virtual address
   1.103 +	p=(volatile TUint32*)c1.Base();
   1.104 +	ReadOnly(p,pageSize>>1);	// read two other pages (this will evict the modified lines)
   1.105 +	p=(volatile TUint32*)(c2.Base()+pageSize);
   1.106 +	Dump(p,pageSize>>1);
   1.107 +	Verify(p,pageSize>>1);
   1.108 +	test.Printf(_L("\n"));
   1.109 +	test.End();
   1.110 +	return 0;
   1.111 +	}