sl@0: // Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // e32test\mmu\t_wbc.cpp sl@0: // Overview: sl@0: // Read and write RChunk data. sl@0: // API Information: sl@0: // RChunk sl@0: // Details: sl@0: // Create two local RChunk objects. Perform ReadModifyWrite, WriteOnly sl@0: // and ReadOnly operations on the chunks. Verify that the results are sl@0: // as expected. sl@0: // Platforms/Drives/Compatibility: sl@0: // All. sl@0: // Assumptions/Requirement/Pre-requisites: sl@0: // Failures and causes: sl@0: // Base Port information: sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: RTest test(_L("T_WBC")); sl@0: sl@0: TUint32 ReadModifyWrite(volatile TUint32* p, TInt aNumWords) sl@0: { sl@0: TUint32 x=0; sl@0: while(aNumWords--) sl@0: { sl@0: x=*p; sl@0: *p++=0; sl@0: } sl@0: return x; sl@0: } sl@0: sl@0: void WriteOnly(volatile TUint32* p, TInt aNumWords) sl@0: { sl@0: while(aNumWords--) sl@0: *p++=0xffffffff; sl@0: } sl@0: sl@0: TUint32 ReadOnly(volatile TUint32* p, TInt aNumWords) sl@0: { sl@0: TUint32 x=0; sl@0: while(aNumWords--) sl@0: x+=*p++; sl@0: return x; sl@0: } sl@0: sl@0: void Dump(volatile TUint32* p, TInt aNumWords) sl@0: { sl@0: while(aNumWords>0) sl@0: { sl@0: RDebug::Print(_L("%08x: %08x %08x %08x %08x %08x %08x %08x %08x"),p, sl@0: p[0],p[1],p[2],p[3],p[4],p[5],p[6],p[7]); sl@0: p+=8; sl@0: aNumWords-=8; sl@0: } sl@0: } sl@0: sl@0: void Verify(volatile TUint32* p, TInt aNumWords) sl@0: { sl@0: while(aNumWords--) sl@0: test(*p++==0xffffffff); sl@0: } sl@0: sl@0: GLDEF_C TInt E32Main() sl@0: { sl@0: sl@0: TInt pageSize; sl@0: UserHal::PageSizeInBytes(pageSize); sl@0: test.Title(); sl@0: test.Start(_L("Create chunk 1")); sl@0: RChunk c1; sl@0: TInt r=c1.CreateLocal(4*pageSize,0x100000); // initial size 4 pages sl@0: test(r==KErrNone); sl@0: test.Next(_L("Create chunk 2")); sl@0: RChunk c2; sl@0: r=c2.CreateLocal(pageSize,0x100000); // initial size 1 page sl@0: test(r==KErrNone); sl@0: test.Next(_L("Fill DCache with modified lines from chunk 1")); sl@0: volatile TUint32* p=(volatile TUint32*)(c1.Base()+2*pageSize); sl@0: ReadModifyWrite(p,pageSize>>1); sl@0: c1.Adjust(2*pageSize); // lose the two modified pages sl@0: c2.Adjust(3*pageSize); // map them back into chunk 2 sl@0: p=(volatile TUint32*)(c2.Base()+pageSize); sl@0: WriteOnly(p,pageSize>>1); // write to the modified pages at new virtual address sl@0: p=(volatile TUint32*)c1.Base(); sl@0: ReadOnly(p,pageSize>>1); // read two other pages (this will evict the modified lines) sl@0: p=(volatile TUint32*)(c2.Base()+pageSize); sl@0: Dump(p,pageSize>>1); sl@0: Verify(p,pageSize>>1); sl@0: test.Printf(_L("\n")); sl@0: test.End(); sl@0: return 0; sl@0: }