sl@0: // Copyright (c) 1998-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\misc\t_mem.cpp sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include "u32std.h" sl@0: #include "../misc/prbs.h" sl@0: sl@0: RTest test(_L("T_MEM")); sl@0: sl@0: TInt E32Main() sl@0: { sl@0: test.Title(); sl@0: test.Start(_L("Create chunk")); sl@0: TMemoryInfoV1 minfo; sl@0: TPckg infoPckg(minfo); sl@0: TInt r = UserHal::MemoryInfo(infoPckg); sl@0: test(r==KErrNone); sl@0: test.Printf(_L("MaxFree = %08x\n"), minfo.iMaxFreeRamInBytes); sl@0: test.Printf(_L("Free = %08x\n"), minfo.iFreeRamInBytes); sl@0: TInt overhead = ((minfo.iFreeRamInBytes + 0x003FFFFF)>>22)<<12; sl@0: test.Printf(_L("Overhead = %08x\n"), overhead); sl@0: TInt size = Min(minfo.iFreeRamInBytes-0x00100000, minfo.iFreeRamInBytes-overhead); sl@0: test.Printf(_L("Initial = %08x\n"), size); sl@0: RChunk c; sl@0: r=c.CreateLocal(size, minfo.iFreeRamInBytes); sl@0: test(r==KErrNone); sl@0: while (r==KErrNone) sl@0: { sl@0: r = c.Adjust(size + 0x1000); sl@0: if (r==KErrNone) sl@0: size += 0x1000; sl@0: }; sl@0: test.Printf(_L("Final = %08x\n"), size); sl@0: sl@0: TUint seed[2]; sl@0: seed[0]=User::NTickCount(); sl@0: seed[1]=0; sl@0: TUint8* p=c.Base(); sl@0: test.Printf(_L("Chunk Base %08x\n"),p); sl@0: Mem::FillZ(p,size); sl@0: TInt sizepg = size>>12; sl@0: TUint iterations = 0; sl@0: FOREVER sl@0: { sl@0: TUint x=Random(seed); sl@0: x%=TUint(sizepg); sl@0: TInt offset=x<<12; sl@0: TUint init=Random(seed); sl@0: TUint seed2[2]; sl@0: seed2[0]=init; sl@0: seed2[1]=0; sl@0: TUint* pW=(TUint*)(p+offset); sl@0: *pW++=init; sl@0: TInt i; sl@0: for (i=1; i<1024; i++) sl@0: *pW++=Random(seed2); sl@0: TInt j; sl@0: for (j=0; j<19; j++) sl@0: { sl@0: x=Random(seed); sl@0: x%=TUint(sizepg); sl@0: offset=x<<12; sl@0: pW=(TUint*)(p+offset); sl@0: seed2[0]=*pW++; sl@0: seed2[1]=0; sl@0: for (i=1; i<1024; i++) sl@0: { sl@0: TUint actual=*pW++; sl@0: TUint expected=Random(seed2); sl@0: TUint diff = actual ^ expected; sl@0: if (diff) sl@0: { sl@0: test.Printf(_L("Address %08x: Got %08x Expected %08x Diff %08x\n"),pW-1,actual,expected,diff); sl@0: pW[-1] = expected; sl@0: // test.Getch(); sl@0: // test(0); sl@0: } sl@0: } sl@0: } sl@0: ++iterations; sl@0: if ((iterations & 0x3ff)==0) sl@0: test.Printf(_L("%u\n"),iterations); sl@0: } sl@0: }