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\realtime\t_frag.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_FRAG")); sl@0: const TInt KHeapSize=4096; sl@0: sl@0: LOCAL_C TInt ThreadFunction(TAny* aRandomNumber) sl@0: { sl@0: TUint seed[2]; sl@0: seed[0]=(TUint)aRandomNumber; sl@0: seed[1]=0; sl@0: sl@0: RChunk c; sl@0: TInt r=c.CreateLocal(0x1000,0x01000000); // initial 4k max 16Mb sl@0: if (r!=KErrNone) sl@0: User::Panic(_L("T_FRAG"),r); sl@0: FOREVER sl@0: { sl@0: TUint wait=Random(seed); sl@0: wait &= 16383; // delay in us between 0 and 16383 sl@0: User::After(wait); sl@0: TUint size=Random(seed); sl@0: size &= 4194303; // size in bytes between 0 and 4194303 sl@0: c.Adjust(size); // adjust chunk, ignore any errors sl@0: } sl@0: } sl@0: sl@0: GLDEF_C TInt E32Main() sl@0: { sl@0: test.Title(); sl@0: test.Start(_L("Testing allocation/deallocation with fragmented memory")); sl@0: sl@0: TInt r=KErrNone; sl@0: sl@0: RThread t1; sl@0: TRequestStatus s1; sl@0: r=t1.Create(_L("Thread1"),ThreadFunction,KDefaultStackSize,KHeapSize,KHeapSize,(TAny*)0xb504f334); sl@0: test(r==KErrNone); sl@0: t1.SetPriority(EPriorityLess); sl@0: t1.Logon(s1); sl@0: t1.Resume(); sl@0: sl@0: RThread t2; sl@0: TRequestStatus s2; sl@0: r=t2.Create(_L("Thread2"),ThreadFunction,KDefaultStackSize,KHeapSize,KHeapSize,(TAny*)0xddb3d743); sl@0: test(r==KErrNone); sl@0: t2.SetPriority(EPriorityMuchLess); sl@0: t2.Logon(s2); sl@0: t2.Resume(); sl@0: sl@0: RThread t3; sl@0: TRequestStatus s3; sl@0: r=t3.Create(_L("Thread3"),ThreadFunction,KDefaultStackSize,KHeapSize,KHeapSize,(TAny*)0xc90fdaa2); sl@0: test(r==KErrNone); sl@0: t3.SetPriority(EPriorityMuchLess); sl@0: t3.Logon(s3); sl@0: t3.Resume(); sl@0: sl@0: User::WaitForAnyRequest(); sl@0: sl@0: if (s1!=KRequestPending) sl@0: { sl@0: TExitCategoryName t1ExitCategory = t1.ExitCategory(); sl@0: test.Printf(_L("Thread1 exited %d,%d,%S\n"),t1.ExitType(),t1.ExitReason(),&t1ExitCategory); sl@0: } sl@0: if (s2!=KRequestPending) sl@0: { sl@0: TExitCategoryName t2ExitCategory = t2.ExitCategory(); sl@0: test.Printf(_L("Thread2 exited %d,%d,%S\n"),t2.ExitType(),t2.ExitReason(),&t2ExitCategory); sl@0: } sl@0: if (s3!=KRequestPending) sl@0: { sl@0: TExitCategoryName t3ExitCategory = t3.ExitCategory(); sl@0: test.Printf(_L("Thread3 exited %d,%d,%S\n"),t3.ExitType(),t3.ExitReason(),&t3ExitCategory); sl@0: } sl@0: t1.Kill(0); sl@0: t2.Kill(0); sl@0: t3.Kill(0); sl@0: sl@0: test.End(); sl@0: return 0; sl@0: }