Update contrib.
1 // Copyright (c) 2004-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\system\t_dobject.cpp
16 // Test RObjectIx strategy of memory reallocation and
17 // free list maintenance.
18 // Test DObjectCon findhandle methods
22 // - Add a number of DObjects to RObjectIx, then remove them
23 // in the same order. Verify results are as expected. Time
24 // how long the process takes to complete.
25 // - Add a number of DObjects to RObjectIx, then remove them
26 // in the reverse order. Verify results are as expected. Time
27 // how long the process takes to complete.
28 // - Add and remove a random number of DObjects to/from RObjectIx.
29 // Time how long the process takes to complete.
30 // Platforms/Drives/Compatibility:
32 // Assumptions/Requirement/Pre-requisites:
33 // Failures and causes:
34 // Base Port information:
38 #define __E32TEST_EXTENSION__
41 #include "d_dobject.h"
43 LOCAL_D RTest test(_L("T_DOBJECT"));
45 TInt TestRObjectIxAccess(TAny* aRObjectIxPtr)
47 const TInt KConcurrentDObjectTestRepeats = 1;
55 for (TInt repeat = 0; repeat < KConcurrentDObjectTestRepeats; repeat++)
57 ret = ldd.RObjectIxThreadTestExerciseIx(aRObjectIxPtr);
67 } // TestRObjectIxAccess
69 void TestConcurrentRObjectIxAccess(RTestDObject& aLdd)
71 const TInt KConcurrentDObjectThreads = 4;
72 _LIT(KConcurrentDObjectThreadName, "T_DObject_Thread");
77 // Create a RObjectIx in the driver (pointer not valid user side!)...
79 void* objectIxPtr = NULL;
81 ret = aLdd.RObjectIxThreadTestCreateIx(objectIxPtr);
85 // Run KConcurrentDObjectThreads number of threads which random add/remove
86 // DObjects to the same RObjectIx...
88 RThread threadHandle[KConcurrentDObjectThreads];
89 TRequestStatus status[KConcurrentDObjectThreads];
93 for (thread = 0; thread < KConcurrentDObjectThreads; thread++)
95 threadName.Copy(KConcurrentDObjectThreadName);
96 threadName.AppendNum(thread);
98 ret = threadHandle[thread].Create(threadName, TestRObjectIxAccess, KDefaultStackSize, NULL, objectIxPtr);
101 threadHandle[thread].Logon(status[thread]);
105 // The test thread must be higher priority to ensure all the threads start.
106 // All the threads are then resumed and allowed to run to completion...
108 RThread().SetPriority(EPriorityMore);
110 for (thread = 0; thread < KConcurrentDObjectThreads; thread++)
112 threadHandle[thread].Resume();
115 for (thread = 0; thread < KConcurrentDObjectThreads; thread++)
117 User::WaitForRequest(status[thread]);
118 test_KErrNone(status[thread].Int());
119 CLOSE_AND_WAIT(threadHandle[thread]);
122 RThread().SetPriority(EPriorityNormal);
125 // Free the RObjectIx in the driver...
127 ret = aLdd.RObjectIxThreadTestFreeIx(objectIxPtr);
129 } // TestConcurrentRObjectIxAccess
132 void ListAllMutexes()
134 test.Printf(_L("Mutexes:\n"));
137 while (find.Next(name) == KErrNone)
139 test.Printf(_L(" %S (find handle == %08x)\n"), &name, find.Handle());
143 const TInt KObjectCount = 20;
144 _LIT(KDoubleMatch, "*double*");
145 _LIT(KTrippleMatch, "*tripple*");
147 RMutex Mutexes[KObjectCount];
150 const TDesC& MutexName(TInt i)
153 ObjectName.AppendFormat(_L("Mutex_%02d"), i);
155 ObjectName.Append(_L("_double"));
157 ObjectName.Append(_L("_tripple"));
163 for (TInt i = 0 ; i < KObjectCount ; ++i)
165 test(Mutexes[i].CreateGlobal(MutexName(i)) == KErrNone);
171 for (TInt i = 0 ; i < KObjectCount ; ++i)
177 void TestMutexesCreated()
179 test.Next(_L("Test mutexes have been created"));
183 for (TInt i = 0 ; i < KObjectCount ; ++i)
185 TFindMutex find(MutexName(i));
186 test(find.Next(name) == KErrNone);
187 test.Printf(_L(" %02d: found handle %08x\n"), i, find.Handle());
191 void TestMutexesDeleted()
193 test.Next(_L("Test mutexes deleted"));
197 for (TInt i = 0 ; i < KObjectCount ; ++i)
199 TFindMutex find(MutexName(i));
200 test(find.Next(name) == KErrNotFound);
205 void TestFindSpecificMutex()
207 test.Next(_L("Test finding specific mutexes"));
209 for (TInt i = 0 ; i < KObjectCount ; ++i)
212 TFindMutex find(MutexName(i));
213 test(find.Next(name) == KErrNone);
214 test.Printf(_L(" %02d: found handle %08x\n"), i, find.Handle());
215 test(name == MutexName(i));
217 test(mutex.Open(find) == KErrNone);
218 test(mutex.Name() == MutexName(i));
220 test(find.Next(name) == KErrNotFound);
224 void TestFindMutexGroups()
226 test.Next(_L("Test finding groups of mutexes using wildcard name matching"));
231 TFindMutex find2(KDoubleMatch);
232 for (i = 0 ; i < KObjectCount ; i += 2)
234 test(find2.Next(name) == KErrNone);
235 test.Printf(_L(" %02d: found handle %08x\n"), i, find2.Handle());
236 test(name == MutexName(i));
238 test(find2.Next(name) == KErrNotFound);
240 TFindMutex find3(KTrippleMatch);
241 for (i = 0 ; i < KObjectCount ; i += 3)
243 test(find3.Next(name) == KErrNone);
244 test.Printf(_L(" %02d: found handle %08x\n"), i, find3.Handle());
245 test(name == MutexName(i));
247 test(find3.Next(name) == KErrNotFound);
250 void TestMatchChange()
252 test.Next(_L("Test changing match half way through find"));
258 TFindMutex find(KDoubleMatch);
259 for (i = 0 ; i < KObjectCount/2 ; i += 2)
261 test(find.Next(name) == KErrNone);
262 test.Printf(_L(" %02d: found handle %08x\n"), i, find.Handle());
263 test(name == MutexName(i));
266 find.Find(KTrippleMatch);
267 for (i = 0 ; i < KObjectCount ; i += 3)
269 test(find.Next(name) == KErrNone);
270 test.Printf(_L(" %02d: found handle %08x\n"), i, find.Handle());
271 test(name == MutexName(i));
273 test(find.Next(name) == KErrNotFound);
276 void TestFindAndDeleteMutex1()
278 test.Next(_L("Test finding mutexes when the last found object has been deleted"));
280 // Find and delete even mutexes
283 for (i = 0 ; i < KObjectCount ; i += 2)
285 TFindMutex find2(MutexName(i));
286 test(find2.Next(name) == KErrNone);
287 test.Printf(_L(" %02d: found handle %08x\n"), i, find2.Handle());
290 test(mutex.Open(find2) == KErrNotFound);
293 // Check odd mutexes remaining
294 for (i = 1 ; i < KObjectCount ; i += 2)
296 TFindMutex find(MutexName(i));
297 test(find.Next(name) == KErrNone);
301 void TestFindAndDeleteMutex2()
303 test.Next(_L("Test finding mutexes when the last found object has moved in the container"));
305 // Find even mutexes and delete odd
308 for (i = 0 ; i < KObjectCount ; i += 2)
310 TFindMutex find2(MutexName(i));
311 test(find2.Next(name) == KErrNone);
312 test.Printf(_L(" %02d: found handle %08x\n"), i, find2.Handle());
313 Mutexes[(i+KObjectCount-1)%KObjectCount].Close(); // -1%n = -1 or n-1, unspecified
315 test(mutex.Open(find2) == KErrNone);
316 test(mutex.Name() == MutexName(i));
320 // Check even mutexes remaining
321 for (i = 0 ; i < KObjectCount ; i += 2)
323 TFindMutex find(MutexName(i));
324 test(find.Next(name) == KErrNone);
329 void TestFindWithCreation()
331 test.Next(_L("Test finding mutexes interleaved with creation"));
335 for (TInt i = 0 ; i < KObjectCount ; ++i)
337 test(Mutexes[i].CreateGlobal(MutexName(i)) == KErrNone);
338 TFindMutex find(MutexName(i));
339 test(find.Next(name) == KErrNone);
340 test.Printf(_L(" %02d: found handle %08x\n"), i, find.Handle());
342 test(mutex.Open(find) == KErrNone);
343 test(mutex.Name() == MutexName(i));
348 void TestFindWithCreation2()
350 test.Next(_L("Test finding mutexes interleaved with creation and deletion"));
354 for (TInt i = 0 ; i < KObjectCount ; ++i)
357 test(mutex.CreateGlobal(MutexName(0)) == KErrNone);
358 TFindMutex find(MutexName(0));
359 test(find.Next(name) == KErrNone);
360 test(name == MutexName(0));
361 test.Printf(_L(" %02d: found handle %08x\n"), i, find.Handle());
364 TFindMutex find2(MutexName(0));
365 test(find2.Next(name) == KErrNotFound);
369 void TestFindHandleOutOfRange()
371 test.Next(_L("Test finding mutexes when find handle index is off the end of container's array"));
375 for (TInt i = 0 ; i < KObjectCount ; ++i)
377 TFindMutex find(MutexName(i));
378 test(find.Next(name) == KErrNone);
379 test.Printf(_L(" %02d: found handle %08x\n"), i, find.Handle());
381 test(mutex.Open(find) == KErrNone);
382 test(mutex.Name() == MutexName(i));
385 // towards the end, suddenly delete half the mutexes
386 if (i == (3 * KObjectCount) / 4)
388 for (TInt j = 0 ; j < KObjectCount / 2 ; ++j)
394 void TestFindHandles()
396 test.Start(_L("Test FindHandle APIs using mutex classes"));
400 TestMutexesCreated();
401 TestFindSpecificMutex();
402 TestFindMutexGroups();
405 TestMutexesDeleted();
408 TestFindAndDeleteMutex1();
412 TestFindHandleOutOfRange();
416 TestFindAndDeleteMutex2();
419 TestFindWithCreation();
422 TestFindWithCreation2();
423 TestMutexesDeleted();
428 GLDEF_C TInt E32Main()
436 test.Start(_L("Loading test driver..."));
438 r=User::LoadLogicalDevice(KDObjectTestLddName);
439 test(r==KErrNone || r==KErrAlreadyExists);
443 test.Next(_L("RObjectIxTest1 test ..."));
444 r=ldd.RObjectIxTest1(duration);
446 test.Printf(_L("... completed in %d kernel ticks\n") , duration);
448 test.Next(_L("RObjectIxTest2 test ..."));
449 r=ldd.RObjectIxTest2(duration);
451 test.Printf(_L("... completed in %d kernel ticks\n") , duration);
453 test.Next(_L("RObjectIxTest3 test (performance) ..."));
456 param.iPerformanceTest = ETrue;
457 r=ldd.RObjectIxTest3(param);
459 test.Printf(_L("... completed in %d kernel ticks\n") , param.duration);
461 test.Next(_L("RObjectIxTest3 test (random)..."));
462 param.iSeed[0]=User::TickCount();
463 param.iSeed[1]=User::TickCount();
464 param.iPerformanceTest = EFalse;
465 test.Printf(_L("... seeds=%xh and %xh ..."),param.iSeed[0],param.iSeed[1]);
466 r=ldd.RObjectIxTest3(param);
468 test.Printf(_L("... completed in %d kernel ticks\n") , param.duration);
470 test.Next(_L("RObjectIxTest4 test (reserved slots)..."));
471 test_KErrNone(ldd.RObjectIxTest4(duration));
472 test.Printf(_L("... completed in %d kernel ticks\n") , duration);
474 test.Next(_L("Test Concurrent access to RObjectIx"));
475 TestConcurrentRObjectIxAccess(ldd);
477 test.Next(_L("Test Invalid handle look up"));
478 test_KErrNone(ldd.InvalidHandleLookupTest());
480 test.Next(_L("Test Kern::ValidateName and Kern::ValidateFullName"));
481 test_KErrNone(ldd.DObjectNameTest());
483 test.Next(_L("Closing test driver"));
486 test.Next(_L("FindHandles test"));