os/kernelhwsrv/kerneltest/e32test/realtime/t_frag.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 // Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of the License "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // e32test\realtime\t_frag.cpp
    15 // 
    16 //
    17 
    18 #include <e32test.h>
    19 #include "u32std.h"
    20 #include "../misc/prbs.h"
    21 
    22 RTest test(_L("T_FRAG"));
    23 const TInt KHeapSize=4096;
    24 
    25 LOCAL_C TInt ThreadFunction(TAny* aRandomNumber)
    26 	{
    27 	TUint seed[2];
    28 	seed[0]=(TUint)aRandomNumber;
    29 	seed[1]=0;
    30 
    31 	RChunk c;
    32 	TInt r=c.CreateLocal(0x1000,0x01000000);	// initial 4k max 16Mb
    33 	if (r!=KErrNone)
    34 		User::Panic(_L("T_FRAG"),r);
    35 	FOREVER
    36 		{
    37 		TUint wait=Random(seed);
    38 		wait &= 16383;	// delay in us between 0 and 16383
    39 		User::After(wait);
    40 		TUint size=Random(seed);
    41 		size &= 4194303;	// size in bytes between 0 and 4194303
    42 		c.Adjust(size);		// adjust chunk, ignore any errors
    43 		}
    44 	}
    45 
    46 GLDEF_C TInt E32Main()
    47 	{
    48 	test.Title();
    49 	test.Start(_L("Testing allocation/deallocation with fragmented memory"));
    50 
    51 	TInt r=KErrNone;
    52 
    53 	RThread t1;
    54 	TRequestStatus s1;
    55 	r=t1.Create(_L("Thread1"),ThreadFunction,KDefaultStackSize,KHeapSize,KHeapSize,(TAny*)0xb504f334);
    56 	test(r==KErrNone);
    57 	t1.SetPriority(EPriorityLess);
    58 	t1.Logon(s1);
    59 	t1.Resume();
    60 
    61 	RThread t2;
    62 	TRequestStatus s2;
    63 	r=t2.Create(_L("Thread2"),ThreadFunction,KDefaultStackSize,KHeapSize,KHeapSize,(TAny*)0xddb3d743);
    64 	test(r==KErrNone);
    65 	t2.SetPriority(EPriorityMuchLess);
    66 	t2.Logon(s2);
    67 	t2.Resume();
    68 
    69 	RThread t3;
    70 	TRequestStatus s3;
    71 	r=t3.Create(_L("Thread3"),ThreadFunction,KDefaultStackSize,KHeapSize,KHeapSize,(TAny*)0xc90fdaa2);
    72 	test(r==KErrNone);
    73 	t3.SetPriority(EPriorityMuchLess);
    74 	t3.Logon(s3);
    75 	t3.Resume();
    76 
    77 	User::WaitForAnyRequest();
    78 
    79 	if (s1!=KRequestPending)
    80 		{
    81 		TExitCategoryName t1ExitCategory =  t1.ExitCategory();
    82 		test.Printf(_L("Thread1 exited %d,%d,%S\n"),t1.ExitType(),t1.ExitReason(),&t1ExitCategory);
    83 		}
    84 	if (s2!=KRequestPending)
    85 		{
    86 		TExitCategoryName t2ExitCategory =  t2.ExitCategory();
    87 		test.Printf(_L("Thread2 exited %d,%d,%S\n"),t2.ExitType(),t2.ExitReason(),&t2ExitCategory);
    88 		}
    89 	if (s3!=KRequestPending)
    90 		{
    91 		TExitCategoryName t3ExitCategory =  t3.ExitCategory();
    92 		test.Printf(_L("Thread3 exited %d,%d,%S\n"),t3.ExitType(),t3.ExitReason(),&t3ExitCategory);
    93 		}
    94 	t1.Kill(0);
    95 	t2.Kill(0);
    96 	t3.Kill(0);
    97 
    98 	test.End();
    99 	return 0;
   100 	}