Update contrib.
1 // Copyright (c) 2008-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\demandpaging\t_threadcreate.cpp
18 #define __E32TEST_EXTENSION__
36 _LIT(KGlobalThreadName, "gThreadGlobal");
41 TUint8* gStackPtr = NULL;
43 struct SThreadPagedInfo
49 TUint8 ReadByte(volatile TUint8* aPtr)
54 TInt TestThreadFunction(TAny* aPtr)
56 for (TInt i = 0; i<2; i++)
60 User::SetRealtimeState(User::ERealtimeStateOn);
61 RDebug::Printf("aPtr %x",aPtr);
62 ReadByte((TUint8*)aPtr);
71 // Determine whether the stack is paged by flushing the cache and attempting
72 // to read a byte that has been paged out
75 TInt IsStackPaged(const TUint8* aPtr)
79 r = thread.Create(KNullDesC, TestThreadFunction, 0x1000, NULL, (TAny*)aPtr);
85 TRequestStatus status;
87 if(status.Int() != KRequestPending)
92 User::WaitForRequest(status);
93 if (thread.ExitType() == EExitPanic &&
94 thread.ExitCategory() == _L("KERN-EXEC") &&
95 thread.ExitReason() == EIllegalFunctionForRealtimeThread)
101 r = thread.ExitReason();
105 if (EExitKill != thread.ExitType())
107 gStackPaged = EFalse;
112 RDebug::Printf(" %08x present", aPtr);
116 RDebug::Printf(" %08x not present", aPtr);
122 Thread that just returns the data paging attributes of the thread.
124 TInt ThreadFunc(TAny* aThreadInfo)
126 SThreadPagedInfo& info = *(SThreadPagedInfo*)aThreadInfo;
127 RHeap& heap = User::Heap();
129 chunk.SetHandle(heap.ChunkHandle());
130 info.iHeapPaged = chunk.IsPaged();
131 gStackPtr = (TUint8*)&chunk;
132 RDebug::Printf("&chunk %x",&chunk);
135 info.iStackPaged = gStackPaged;
139 TInt DummyFunction(TAny*)
144 TInt PanicThreadCreate(TAny* aCreateInfo)
147 TThreadCreateInfo createInfo((*(TThreadCreateInfo*) aCreateInfo));
148 thread.Create(createInfo);
149 return KErrGeneral; // Should never reach here
153 // CheckHeapStackPaged
155 // Using the TThreadCreateInfo used to create the cheap, determine
156 // whether the stack and the heap are paged or not
159 TInt CheckHeapStackPaged(TThreadCreateInfo& aCreateInfo, TInt aPaged, SThreadPagedInfo& aPagedInfo, TBool aUseProcessHeap = EFalse)
166 test.Printf(_L("Testing gProcessPaged\n"));
167 paged = gProcessPaged;
171 test.Printf(_L("Testing Paged\n"));
172 aCreateInfo.SetPaging(TThreadCreateInfo::EPaged);
177 test.Printf(_L("Testing Unpaged\n"));
178 aCreateInfo.SetPaging(TThreadCreateInfo::EUnpaged);
184 test_KErrNone(thread.Create(aCreateInfo));
186 // Disable JIT debugging.
187 TBool justInTime=User::JustInTime();
188 User::SetJustInTime(EFalse);
190 TRequestStatus status;
191 thread.Logon(status);
196 DPTest::FlushCache();
197 TInt r = IsStackPaged(gStackPtr);
201 User::WaitForRequest(status);
202 test (EExitKill == thread.ExitType());
203 test(KErrNone == status.Int());
205 test(KErrNone == thread.ExitReason());
207 if (thread.ExitType() == EExitPanic)
209 test(thread.ExitCategory()==_L("USER"));
212 CLOSE_AND_WAIT(thread);
214 // Put JIT debugging back to previous status.
215 User::SetJustInTime(justInTime);
219 {// If using existing thread heap, heap will take the process paging status
220 test_Equal(gProcessPaged, aPagedInfo.iHeapPaged);
224 test_Equal(paged, aPagedInfo.iHeapPaged);
226 test_Equal(paged, aPagedInfo.iStackPaged);
233 //----------------------------------------------------------------------------------------------
234 //! @SYMTestCaseID KBASE-T_THREADHEAPCREATE-xxxx
236 //! @SYMPREQ PREQ1954
237 //! @SYMTestCaseDesc TThreadCreateInfo tests
238 //! Verify the thread heap creation implementation
240 //! 1. Call TThreadCreateInfo::TThreadCreateInfo() with valid parameters.
241 //! Following this call RThread::Create()
242 //! 2. Call TThreadCreateInfo::TThreadCreateInfo() with an invalid stack size.
243 //! Following this call RThread::Create()
244 //! 3. Call TThreadCreateInfo::SetCreateHeap() with an invalid min heap size.
245 //! Following this call RThread::Create()
246 //! 4. Call TThreadCreateInfo::SetCreateHeap() with an invalid max heap size.
247 //! Following this call RThread::Create()
248 //! 5. Call TThreadCreateInfo::SetCreateHeap() with minHeapSize. > maxHeapSize
249 //! Following this call RThread::Create()
250 //! 6. Call TThreadCreateInfo::SetUseHeap() specifying NULL. Following this call RThread::Create()
251 //! 7. Call TThreadCreateInfo::SetOwner() with aOwner set to EOwnerProcess.
252 //! Following this call RThread::Create()
253 //! 8. Call TThreadCreateInfo::SetOwner() with aOwner set to EOwnerThread.
254 //! Following this call RThread::Create()
255 //! 9. Call TThreadCreateInfo::SetPaging() with aPaging set to unspecified.
256 //! Following this call RThread::Create() and check the paging status of the thread
257 //! 10. Call TThreadCreateInfo::SetPaging() with aPaging set to EPaged.
258 //! Following this call RThread::Create() and check the paging status of the thread
259 //! 11. Call TThreadCreateInfo::SetPaging() with aPaging set to EUnpaged.
260 //! Following this call RThread::Create() and check the paging status of the thread
262 //! @SYMTestExpectedResults All tests should pass.
263 //! @SYMTestPriority High
264 //! @SYMTestStatus Implemented
265 //----------------------------------------------------------------------------------------------
266 void TestThreadCreate()
269 test.Start(_L("Test RThread::Create() (New Heap)"));
272 TThreadCreateInfo createInfo(KGlobalThreadName, DummyFunction, KDefaultStackSize, NULL);
273 createInfo.SetCreateHeap(KMinHeapSize, KMinHeapSize);
274 r = thread.Create(createInfo);
276 test_KErrNone(TestThreadExit(thread, EExitKill, KErrNone));
280 test.Next(_L("Test RThread::Create() - invalid stack size"));
282 TThreadCreateInfo createInfo(KGlobalThreadName, DummyFunction, -1 , NULL);
283 createInfo.SetCreateHeap(KMinHeapSize, KMinHeapSize);
286 test_KErrNone(threadPanic.Create(_L("Panic UserHeap"), PanicThreadCreate, KDefaultStackSize, KMinHeapSize,
287 KMinHeapSize, (TAny*) &createInfo));
288 test_KErrNone(TestThreadExit(threadPanic, EExitPanic, EThrdStackSizeNegative));
291 test.Next(_L("Test RThread::Create() - invalid min heap size"));
293 TThreadCreateInfo createInfo(KGlobalThreadName, DummyFunction, KDefaultStackSize , NULL);
294 createInfo.SetCreateHeap(-1, KMinHeapSize);
297 test_KErrNone(threadPanic.Create(_L("Panic UserHeap"), PanicThreadCreate, KDefaultStackSize, KMinHeapSize,
298 KMinHeapSize, (TAny*) &createInfo));
300 test_KErrNone(TestThreadExit(threadPanic, EExitPanic, EThrdHeapMinTooSmall));
303 test.Next(_L("Test RThread::Create() - invalid max heap size"));
305 TThreadCreateInfo createInfo(KGlobalThreadName, DummyFunction, KDefaultStackSize , NULL);
306 createInfo.SetCreateHeap(KMinHeapSize, -1);
309 test_KErrNone(threadPanic.Create(_L("Panic UserHeap"), PanicThreadCreate, KDefaultStackSize, KMinHeapSize,
310 KMinHeapSize, (TAny*) &createInfo));
312 test_KErrNone(TestThreadExit(threadPanic, EExitPanic, EThrdHeapMaxLessThanMin));
315 test.Next(_L("Test RThread::Create() - min heap size > max heap size"));
317 TThreadCreateInfo createInfo(KGlobalThreadName, DummyFunction, KDefaultStackSize , NULL);
318 createInfo.SetCreateHeap(KMinHeapSize << 1, KMinHeapSize);
321 test_KErrNone(threadPanic.Create(_L("Panic UserHeap"), PanicThreadCreate, KDefaultStackSize, KMinHeapSize,
322 KMinHeapSize, (TAny*) &createInfo));
324 test_KErrNone(TestThreadExit(threadPanic, EExitPanic, EThrdHeapMaxLessThanMin));
327 test.Next(_L("Test TThreadCreateInfo::SetUseHeap() "));
330 TThreadCreateInfo createInfo(KGlobalThreadName, DummyFunction, KDefaultStackSize, NULL);
331 createInfo.SetUseHeap(NULL);
332 r = thread.Create(createInfo);
334 test_KErrNone(TestThreadExit(thread, EExitKill, KErrNone));
338 test.Next(_L("Test TThreadCreateInfo::SetOwner(EOwnerProcess) "));
341 TThreadCreateInfo createInfo(KGlobalThreadName, DummyFunction, KDefaultStackSize, NULL);
342 createInfo.SetCreateHeap(KMinHeapSize, KMinHeapSize);
343 createInfo.SetOwner(EOwnerProcess);
344 r = thread.Create(createInfo);
346 test_KErrNone(TestThreadExit(thread, EExitKill, KErrNone));
351 test.Next(_L("Test TThreadCreateInfo::SetOwner(EOwnerThread) "));
354 TThreadCreateInfo createInfo(KGlobalThreadName, DummyFunction, KDefaultStackSize, NULL);
355 createInfo.SetCreateHeap(KMinHeapSize, KMinHeapSize);
356 createInfo.SetOwner(EOwnerThread);
357 r = thread.Create(createInfo);
359 test_KErrNone(TestThreadExit(thread, EExitKill, KErrNone));
365 gSem1.CreateLocal(0);
366 gSem2.CreateLocal(0);
367 test.Next(_L("Test Thread paging (New Heap)"));
369 TBool aPaged = gProcessPaged;
370 SThreadPagedInfo pagedInfo;
371 test.Printf(_L("Testing gProcessPaged: aPaged = %x\n"), aPaged);
372 TThreadCreateInfo createInfo( KGlobalThreadName, ThreadFunc, KDefaultStackSize,
374 createInfo.SetCreateHeap(KMinHeapSize, KMinHeapSize);
376 test_KErrNone(CheckHeapStackPaged(createInfo, EUnspecified, pagedInfo));
377 test_KErrNone(CheckHeapStackPaged(createInfo, EPaged, pagedInfo));
378 test_KErrNone(CheckHeapStackPaged(createInfo, EUnpaged, pagedInfo));
382 test.Next(_L("Test RThread::Create() (Existing Heap)"));
384 SThreadPagedInfo pagedInfo;
385 TThreadCreateInfo createInfo( KGlobalThreadName, ThreadFunc, KDefaultStackSize,
387 createInfo.SetUseHeap(NULL);
389 test_KErrNone(CheckHeapStackPaged(createInfo, EUnspecified, pagedInfo, ETrue));
390 test_KErrNone(CheckHeapStackPaged(createInfo, EPaged, pagedInfo, ETrue));
391 test_KErrNone(CheckHeapStackPaged(createInfo, EUnpaged, pagedInfo, ETrue));
398 TInt TestingTThreadCreate()
400 test.Printf(_L("Test TThreadCreateInfo\n"));