1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/realtime/t_frag.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,100 @@
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\realtime\t_frag.cpp
1.18 +//
1.19 +//
1.20 +
1.21 +#include <e32test.h>
1.22 +#include "u32std.h"
1.23 +#include "../misc/prbs.h"
1.24 +
1.25 +RTest test(_L("T_FRAG"));
1.26 +const TInt KHeapSize=4096;
1.27 +
1.28 +LOCAL_C TInt ThreadFunction(TAny* aRandomNumber)
1.29 + {
1.30 + TUint seed[2];
1.31 + seed[0]=(TUint)aRandomNumber;
1.32 + seed[1]=0;
1.33 +
1.34 + RChunk c;
1.35 + TInt r=c.CreateLocal(0x1000,0x01000000); // initial 4k max 16Mb
1.36 + if (r!=KErrNone)
1.37 + User::Panic(_L("T_FRAG"),r);
1.38 + FOREVER
1.39 + {
1.40 + TUint wait=Random(seed);
1.41 + wait &= 16383; // delay in us between 0 and 16383
1.42 + User::After(wait);
1.43 + TUint size=Random(seed);
1.44 + size &= 4194303; // size in bytes between 0 and 4194303
1.45 + c.Adjust(size); // adjust chunk, ignore any errors
1.46 + }
1.47 + }
1.48 +
1.49 +GLDEF_C TInt E32Main()
1.50 + {
1.51 + test.Title();
1.52 + test.Start(_L("Testing allocation/deallocation with fragmented memory"));
1.53 +
1.54 + TInt r=KErrNone;
1.55 +
1.56 + RThread t1;
1.57 + TRequestStatus s1;
1.58 + r=t1.Create(_L("Thread1"),ThreadFunction,KDefaultStackSize,KHeapSize,KHeapSize,(TAny*)0xb504f334);
1.59 + test(r==KErrNone);
1.60 + t1.SetPriority(EPriorityLess);
1.61 + t1.Logon(s1);
1.62 + t1.Resume();
1.63 +
1.64 + RThread t2;
1.65 + TRequestStatus s2;
1.66 + r=t2.Create(_L("Thread2"),ThreadFunction,KDefaultStackSize,KHeapSize,KHeapSize,(TAny*)0xddb3d743);
1.67 + test(r==KErrNone);
1.68 + t2.SetPriority(EPriorityMuchLess);
1.69 + t2.Logon(s2);
1.70 + t2.Resume();
1.71 +
1.72 + RThread t3;
1.73 + TRequestStatus s3;
1.74 + r=t3.Create(_L("Thread3"),ThreadFunction,KDefaultStackSize,KHeapSize,KHeapSize,(TAny*)0xc90fdaa2);
1.75 + test(r==KErrNone);
1.76 + t3.SetPriority(EPriorityMuchLess);
1.77 + t3.Logon(s3);
1.78 + t3.Resume();
1.79 +
1.80 + User::WaitForAnyRequest();
1.81 +
1.82 + if (s1!=KRequestPending)
1.83 + {
1.84 + TExitCategoryName t1ExitCategory = t1.ExitCategory();
1.85 + test.Printf(_L("Thread1 exited %d,%d,%S\n"),t1.ExitType(),t1.ExitReason(),&t1ExitCategory);
1.86 + }
1.87 + if (s2!=KRequestPending)
1.88 + {
1.89 + TExitCategoryName t2ExitCategory = t2.ExitCategory();
1.90 + test.Printf(_L("Thread2 exited %d,%d,%S\n"),t2.ExitType(),t2.ExitReason(),&t2ExitCategory);
1.91 + }
1.92 + if (s3!=KRequestPending)
1.93 + {
1.94 + TExitCategoryName t3ExitCategory = t3.ExitCategory();
1.95 + test.Printf(_L("Thread3 exited %d,%d,%S\n"),t3.ExitType(),t3.ExitReason(),&t3ExitCategory);
1.96 + }
1.97 + t1.Kill(0);
1.98 + t2.Kill(0);
1.99 + t3.Kill(0);
1.100 +
1.101 + test.End();
1.102 + return 0;
1.103 + }