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