Update contrib.
1 // Copyright (c) 1996-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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32test\misc\t_stres1.cpp
20 #include <e32atomics.h>
21 #include "../misc/prbs.h"
23 RTest test(_L("T_STRES1"));
25 _LIT(KLibraryFileName,"STRES1");
28 LOCAL_D RSemaphore Semaphore;
30 LOCAL_D RLibrary Library;
32 LOCAL_D TBool CheckerHasRun=EFalse;
33 LOCAL_D TInt TotalChecks=0;
34 LOCAL_D TInt CheckerBumped=0;
35 LOCAL_D TInt HeapUserIterations=0;
36 LOCAL_D TInt CreatorIterations=0;
37 LOCAL_D RSemaphore KillerSem;
39 LOCAL_C TInt HeapChecker(TAny*)
44 User::Allocator().Check();
50 User::CompressAllHeaps();
52 RThread().SetPriority(EPriorityMuchLess);
56 LOCAL_C TAny* HeapAlloc(TUint* aSeed)
58 TInt size=(Random(aSeed)&0x3ffc)+8;
59 TUint32* p=(TUint32*)User::Alloc(size);
62 size=User::Allocator().AllocLen(p);
66 for (i=2; i<(size>>2); i++)
72 LOCAL_C void HeapFree(TAny* aPtr)
76 TInt size=User::Allocator().AllocLen(aPtr);
77 TUint32* p=(TUint32*)aPtr;
82 for (i=2; i<(size>>2); i++)
84 if (p[i]!=Random(seed))
85 User::Panic(_L("VERIFY"),i);
90 LOCAL_C TInt HeapUser(TAny* aSeed)
97 TAny* p0=HeapAlloc(seed);
98 TAny* p1=HeapAlloc(seed);
99 TAny* p2=HeapAlloc(seed);
101 TAny* p3=HeapAlloc(seed);
102 TAny* p4=HeapAlloc(seed);
105 TAny* p5=HeapAlloc(seed);
107 TAny* p6=HeapAlloc(seed);
108 TAny* p7=HeapAlloc(seed);
113 __e32_atomic_add_ord32(&HeapUserIterations, 1);
114 TInt ms=Random(seed)&63;
115 TTimeIntervalMicroSeconds32 wait(1000*ms);
116 User::AfterHighRes(wait);
120 LOCAL_C TInt KernelObjectCreator(TAny* aSeed)
123 seed[0]=(TUint)aSeed;
127 TInt rm=Mutex.CreateLocal(EOwnerThread);
128 TInt rs=Semaphore.CreateLocal(0,EOwnerThread);
129 TInt rc=Chunk.CreateLocal(0x10000,0x100000,EOwnerThread);
130 TInt rl=Library.Load(KLibraryFileName);
148 TInt ms=Random(seed)&63;
149 TTimeIntervalMicroSeconds32 wait(1000*ms);
150 User::AfterHighRes(wait);
154 LOCAL_C TInt KillerThread(TAny* aSeed)
157 seed[0]=(TUint)aSeed;
162 TInt ms=Random(seed)&127;
164 TTimeIntervalMicroSeconds32 wait(1000*ms);
165 User::AfterHighRes(wait);
167 TFindThread ft(_L("*Creator"));
171 User::Panic(_L("FindErr"),r);
174 User::Panic(_L("OpenErr"),r);
180 LOCAL_C TInt StartThread(const TDesC& aName, TThreadFunction aFunction, TAny* aPtr, TThreadPriority aPriority, RThread* aThread)
183 TInt r=t.Create(aName,aFunction,0x1000,NULL,aPtr);
186 t.SetPriority(aPriority);
189 aThread->SetHandle(t.Handle());
195 LOCAL_C void Initialise(RThread& aChecker)
197 TInt r=StartThread(_L("HeapChecker"),HeapChecker,NULL,EPriorityMuchLess,&aChecker);
199 r=StartThread(_L("HeapUser1"),HeapUser,(TAny*)0xb504f333,EPriorityNormal,NULL);
201 r=StartThread(_L("HeapUser2"),HeapUser,(TAny*)0xddb3d743,EPriorityNormal,NULL);
203 r=StartThread(_L("Creator"),KernelObjectCreator,(TAny*)0xadf85458,EPriorityNormal,NULL);
205 r=KillerSem.CreateLocal(1);
207 r=StartThread(_L("Killer"),KillerThread,(TAny*)0xb17217f8,EPriorityMore,NULL);
211 LOCAL_C void Restart(const TDesC&)
215 TInt r=StartThread(_L("Creator"),KernelObjectCreator,(TAny*)0xadf85458,EPriorityNormal,NULL);
223 GLDEF_C TInt E32Main()
227 RThread().SetPriority(EPriorityMuchMore);
230 test.Start(_L("Initialise"));
233 test.Next(_L("Create undertaker"));
237 test.Next(_L("Create timer"));
239 r=timer.CreateLocal();
245 test.Next(_L("Logon to undertaker"));
247 test.Next(_L("Start timer"));
248 timer.After(st,500000);
251 User::WaitForRequest(su,st);
252 if (su!=KRequestPending)
257 TExitType exitType=t.ExitType();
258 TInt exitReason=t.ExitReason();
259 TName exitCategory=t.ExitCategory();
261 if (exitType==EExitPanic)
263 test.Printf(_L("Thread %S Panic %S %d\n"),&n,&exitCategory,exitReason);
266 if (exitType==EExitKill)
273 if (st!=KRequestPending)
277 checker.SetPriority(EPriorityMuchMore);
280 CheckerHasRun=EFalse;
284 test.Printf(_L("Heap user iterations %d Creator iterations %d\n"),HeapUserIterations,CreatorIterations);
285 test.Printf(_L("Checks %d Bumped %d\n"),TotalChecks,CheckerBumped);
287 timer.After(st,500000);