Update contrib.
1 // Copyright (c) 2007-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.
16 #define __E32TEST_EXTENSION__
18 #include "d_prmacctst.h"
20 _LIT8(KTestToc, "TOC");
21 _LIT8(KTestTac1, "TAC1");
22 _LIT8(KTestTac2, "TAC2");
23 _LIT8(KTestTac3, "TAC3");
25 // The number of test values for multi-level resources
26 static const TInt KTestMultiLevelValues = 10;
28 // Bit 16 in the resource ID indicates that the resource has dependencies
29 static const TUint32 KTestIdHasDependencies = 0x00010000;
30 static const TInt KTestMaxDependencies = 256;
32 static const TInt KTestResourceNotInUse = -1;
34 // structure for holding ResId and ResPrty
38 TUint8 iDependencyPriority;
40 class CTestPrmAccTst : public CBase
45 TInt DoTestPreamble();
47 void DoTestPostamble();
49 TBool ResourceInterdependency(TInt aResourceIdOrig, TInt aCurrentResourceId, TInt aResourceIdTarget);
50 void TestEnumerateResources();
51 void TestSingleUserResources(TInt aResourceNo);
52 void TestSharedResources(TInt aResourceNo);
53 void TestBinaryResources(TInt aResourceNo);
54 void TestMultilevelResources(TInt aResourceNo);
55 void TestLatency(TInt aResourceNo);
56 void TestSense(TInt aResourceNo);
57 void TestCustomSense(TInt aResourceNo);
58 void TestDefaultPowerResumption();
59 void TestDependenciesAreDeclared(TInt aResourceNo);
69 // The test PRM clients
70 RPrmIf iToc; // Test Observer Client (never owns any resource)
71 RPrmIf iTac1; // Active clients...
74 RPrmIf iKextc; // The Kernel Extension Client (owns Single User Resources)
76 TBool iIsPrmSupported;
81 static CTestPrmAccTst* iSingletonInstance;
84 CTestPrmAccTst::CTestPrmAccTst()
85 :test(_L("T_PRMACCTST")),
86 iIsPrmSupported(EFalse),
91 CTestPrmAccTst::~CTestPrmAccTst()
94 TInt r = User::FreeLogicalDevice(KPrmIfLddName);
96 #ifdef RESOURCE_MANAGER_SIMULATED_PSL
97 r = User::FreePhysicalDevice(_L("resourcecontrollerextended.pdd"));
103 /* ----------------------------------------------------------------------------
104 @SYMTestCaseID PBASE-PRMACCTST-ENUMRES-0559
105 @SYMTestCaseDesc Ensure current resource state of PRM is correctly listed
108 @SYMTestPriority Critical
110 1. Display all resources and their properties
111 2. Ensure the resource state range is coherent
112 @SYMTestExpectedResults
113 1. All resources are shown with the correct properties
114 2. Min <= Default <= Max and Min < Max if Negative Sense
115 Min >= Default >= Max and Max > Min if Positive Sense
116 Binary resources states are '0' or '1'
119 void CTestPrmAccTst::TestEnumerateResources()
121 test.Printf(_L("Id Resource name C LG LS T U S DefltLvl MinLevel MaxLevel\n"));
122 test.Printf(_L("--------+--------------------------------+-+--+--+--+--+-+--------+--------+--------\n"));
124 for (i = 0; i < (TInt) iNoResources; i++)
126 TResInfo& res = *((TResInfo*) iResources.Ptr() + i);
128 // Display properties
129 test.Printf(_L("%08x "), res.iResourceId);
130 test_Compare(res.iResourceName->Length(), <=, KNameMaxLength);
131 TBuf<KNameMaxLength> tmp;
132 tmp.Copy(*res.iResourceName);
133 test.Printf(_L("%-.32S "), &tmp);
135 if (res.iClass == TResInfo::EPhysical)
137 test.Printf(_L("P "));
139 else if (res.iClass == TResInfo::ELogical)
141 test.Printf(_L("L "));
148 if (res.iLatencyGet == TResInfo::EInstantaneous)
150 test.Printf(_L("In "));
152 else if (res.iLatencyGet == TResInfo::ELongLatency)
154 test.Printf(_L("Lo "));
161 if (res.iLatencySet == TResInfo::EInstantaneous)
163 test.Printf(_L("In "));
165 else if (res.iLatencySet == TResInfo::ELongLatency)
167 test.Printf(_L("Lo "));
174 if (res.iType == TResInfo::EBinary)
176 test.Printf(_L("B "));
178 else if (res.iType == TResInfo::EMultiLevel)
180 test.Printf(_L("ML "));
182 else if (res.iType == TResInfo::EMultiProperty)
184 test.Printf(_L("MP "));
191 if (res.iUsage == TResInfo::ESingleUse)
193 test.Printf(_L("SU "));
195 else if (res.iUsage == TResInfo::EShared)
197 test.Printf(_L("Sh "));
204 if (res.iSense == TResInfo::EPositive)
206 test.Printf(_L("+ "));
208 else if (res.iSense == TResInfo::ENegative)
210 test.Printf(_L("- "));
212 else if (res.iSense == TResInfo::ECustom)
214 test.Printf(_L("C "));
221 test.Printf(_L("%08x "), res.iDefaultLevel);
222 test.Printf(_L("%08x "), res.iMinLevel);
223 test.Printf(_L("%08x\n"), res.iMaxLevel);
225 // Retrieve resource dependencies
226 if (res.iResourceId & KTestIdHasDependencies)
229 deplist.Create(sizeof(SResDepInfo) * KTestMaxDependencies);
230 iToc.GetResourceDependencies(res.iResourceId, deplist);
232 test.Printf(_L(" Direct Dependencies:"));
233 SResDepInfo* ptr = (SResDepInfo*)deplist.Ptr();
234 for (j = 0; j < (TInt) (deplist.Length() / sizeof(SResDepInfo)); j++, ptr++)
236 test.Printf(_L("ResourceId: %08x"), ptr->iResourceId);
237 test.Printf(_L("Resource Priority: %08x"), ptr->iDependencyPriority);
239 test.Printf(_L("\n"));
242 test.Printf(_L("C:Class,P:Physical,L:Logical"));
243 test.Printf(_L("LG/LS:Latency Get/Set,In:Instantaneous,Lo:Long Latency"));
244 test.Printf(_L("T:Type,MP:Multiproperty,ML:Multilevel,B:Binary"));
245 test.Printf(_L("U:Usage,SU:Single-User,Sh:Shared"));
246 test.Printf(_L("S:Sense,+:Positive,-:Negative,C:Custom"));
248 // Ensure the state range of the resource does not contradict its properties
249 if (res.iType == TResInfo::EBinary)
251 if (res.iSense == TResInfo::EPositive)
253 test(res.iMinLevel == EBinaryOff);
254 test(res.iMaxLevel == EBinaryOn);
256 else if (res.iSense == TResInfo::ENegative)
258 test(res.iMinLevel == EBinaryOn);
259 test(res.iMaxLevel == EBinaryOff);
261 else if (res.iSense == TResInfo::ECustom)
263 test(res.iMinLevel == EBinaryOff || res.iMinLevel == EBinaryOn);
264 test(res.iMaxLevel == EBinaryOff || res.iMaxLevel == EBinaryOn);
265 test_Compare(res.iMinLevel, !=, res.iMaxLevel);
267 test((res.iDefaultLevel == EBinaryOff) || (res.iDefaultLevel == EBinaryOn));
269 // Level range must respect resource sense
270 if (res.iSense == TResInfo::EPositive)
272 test_Compare(res.iMinLevel, <=, res.iMaxLevel);
273 test_Compare(res.iMinLevel, <=, res.iDefaultLevel);
274 test_Compare(res.iDefaultLevel, <=, res.iMaxLevel);
275 test_Compare(res.iMinLevel, <, res.iMaxLevel);
277 else if (res.iSense == TResInfo::ENegative)
279 test_Compare(res.iMinLevel, >=, res.iMaxLevel);
280 test_Compare(res.iMinLevel, >=, res.iDefaultLevel);
281 test_Compare(res.iDefaultLevel, >=, res.iMaxLevel);
282 test_Compare(res.iMinLevel, >, res.iMaxLevel);
287 /* ----------------------------------------------------------------------------
288 @SYMTestCaseID PBASE-PRMACCTST-SINGLEUSER-0560
289 @SYMTestCaseDesc Ensure Single User resources can only be used by one client
293 @SYMTestPriority High
296 The resource is not in use
297 For each Single User resource:
298 1. Register TAC1 & TAC2
299 2. TAC1 changes resource state
300 3. TAC2 changes resource state
304 6. TAC2 changes resource state
305 7. TAC1 changes resource state
306 8. De-register TAC1 & TAC2
307 @SYMTestExpectedResults
308 1. Clients registered
309 2. Resource state changed
310 3. KErrAccessDenied as there is already one registered client
311 4. Client de-registered
314 6. Resource state changed
315 7. KErrAccessDenied as there is already one registered client
316 8. Both clients de-registered
319 void CTestPrmAccTst::TestSingleUserResources(TInt aResourceNo)
321 test.Printf(_L("---Single-User "));
322 TResInfo& res = *((TResInfo*) iResources.Ptr() + aResourceNo);
323 // Test pre-condition: resource not in use
325 TInt r = iToc.GetLevelOwner(res.iResourceId, levelowner);
327 if (levelowner != KTestResourceNotInUse)
329 test.Printf(_L("Not tested (Single-User resource already in use)\n"));
332 // Define two test values
334 r = iToc.GetResourceState(res.iResourceId, state);
339 if (state == res.iMinLevel)
341 tstval1 = res.iMaxLevel;
342 tstval2 = res.iMinLevel;
346 tstval1 = res.iMinLevel;
347 tstval2 = res.iMaxLevel;
354 r = iTac1.RegisterClient(KTestTac1);
356 r = iTac2.RegisterClient(KTestTac2);
359 r = iTac1.ChangeResourceState(res.iResourceId, tstval1);
361 r = iTac1.GetResourceState(res.iResourceId, state);
363 test_Equal(tstval1, state);
364 r = iTac2.GetResourceState(res.iResourceId, state);
366 test_Equal(tstval1, state);
367 r = iTac2.ChangeResourceState(res.iResourceId, tstval2);
368 test_Equal(KErrAccessDenied, r); // TAC2 cannot change the resource state
370 r = iTac1.DeRegisterClient();
372 r = iTac1.RegisterClient(KTestTac1);
374 r = iTac2.ChangeResourceState(res.iResourceId, tstval2);
376 r = iTac1.GetResourceState(res.iResourceId, state);
377 test_KErrNone(r); // TAC1 can still access the resource state...
378 test_Equal(tstval2, state);
379 r = iTac1.ChangeResourceState(res.iResourceId, tstval1);
380 test_Equal(KErrAccessDenied, r); // ... but cannot change it
381 r = iTac2.GetResourceState(res.iResourceId, state);
383 test_Equal(tstval2, state); // The resource state remains unchanged indeed
385 r = iTac1.DeRegisterClient();
387 r = iTac2.DeRegisterClient();
391 test.Printf(_L("\n"));
394 /* ----------------------------------------------------------------------------
395 @SYMTestCaseID PBASE-PRMACCTST-SHARED-0561
396 @SYMTestCaseDesc Ensure a Shared Resources can be changed by several
400 @SYMTestPriority High
403 If in use, resource state is not equal to max level
404 Resource is not Custom Sense
405 For each Shared resource:
406 1. Register TOC, TAC1 & TAC2
407 2. TAC1 changes resource state to level1
408 3. TAC2 changes resource state to level2
409 4. TAC2 changes resource state to level1
410 5. TAC1 changes resource state to level2
411 6. De-register TOC, TAC1 & TAC2
412 @SYMTestExpectedResults
413 1. Clients registered
414 2. Resource state changed
415 3. Resource state changed
416 4. Resource state changed
417 5. Resource state changed
418 6. Clients de-registered
421 void CTestPrmAccTst::TestSharedResources(TInt aResourceNo)
423 test.Printf(_L("---Shared "));
424 TResInfo& res = *((TResInfo*) iResources.Ptr() + aResourceNo);
425 // Test pre-conditions
426 if (res.iSense == TResInfo::ECustom)
428 test.Printf(_L("Not tested (Custom sense resource)\n"));
433 TInt r = iToc.GetResourceState(res.iResourceId, state);
436 r = iToc.GetLevelOwner(res.iResourceId, levelowner);
439 if (levelowner != KTestResourceNotInUse && state == res.iMaxLevel)
441 test.Printf(_L("Not tested: Resource is already at maximum level\n"));
444 // Define two test values
447 if (levelowner != KTestResourceNotInUse)
449 // Resource already in use
451 tstval2 = res.iMaxLevel;
455 // Resource not in use
456 tstval1 = res.iMinLevel;
457 tstval2 = res.iMaxLevel;
464 r = iTac1.RegisterClient(KTestTac1);
466 r = iTac2.RegisterClient(KTestTac2);
469 r = iTac1.ChangeResourceState(res.iResourceId, tstval1);
471 r = iToc.GetResourceState(res.iResourceId, state);
473 test_Equal(tstval1, state);
475 r = iTac2.ChangeResourceState(res.iResourceId, tstval2);
477 r = iToc.GetResourceState(res.iResourceId, state);
479 test_Equal(tstval2, state);
481 r = iTac2.ChangeResourceState(res.iResourceId, tstval1);
483 r = iToc.GetResourceState(res.iResourceId, state);
485 test_Equal(tstval1, state);
487 r = iTac1.ChangeResourceState(res.iResourceId, tstval2);
489 r = iToc.GetResourceState(res.iResourceId, state);
491 test_Equal(tstval2, state);
493 r = iTac1.DeRegisterClient();
495 r = iTac2.DeRegisterClient();
500 test.Printf(_L("\n"));
503 /* ----------------------------------------------------------------------------
504 @SYMTestCaseID PBASE-PRMACCTST-BINARY-0562
505 @SYMTestCaseDesc Ensure Binary Resources function as expected
508 @SYMTestPriority High
511 Resource not in use, or...
512 If Shared/Positive Sense, current resource must be off
513 If Shared/Negative Sense, current resource must be on
514 Resource is not Custom Sense
515 For each Binary resource:
517 2. Turn resource off and toggle resource state several times
519 @SYMTestExpectedResults
521 2. Resource state changes as expected
525 void CTestPrmAccTst::TestBinaryResources(TInt aResourceNo)
527 test.Printf(_L("---Binary "));
528 TResInfo& res = *((TResInfo*) iResources.Ptr() + aResourceNo);
529 // Test pre-conditions
530 if (res.iSense == TResInfo::ECustom)
532 test.Printf(_L("Not tested (Custom sense resource)\n"));
536 TInt r = iToc.GetResourceState(res.iResourceId, state);
539 r = iToc.GetLevelOwner(res.iResourceId, levelowner);
542 if (levelowner != KTestResourceNotInUse)
544 if (res.iUsage == TResInfo::ESingleUse)
546 test.Printf(_L("Not tested (Single-User resource already in use)\n"));
549 if (res.iSense == TResInfo::EPositive && state == EBinaryOn)
551 test.Printf(_L("Not tested (Positive sense resource is already on)\n"));
554 if (res.iSense == TResInfo::ENegative && state == EBinaryOff)
556 test.Printf(_L("Not tested (Negative sense resource is already off)\n"));
563 r = iTac1.RegisterClient(KTestTac1);
567 r = iTac1.ChangeResourceState(res.iResourceId, EBinaryOff);
569 r = iToc.GetResourceState(res.iResourceId, state);
571 test_Equal(EBinaryOff, state);
574 r = iTac1.ChangeResourceState(res.iResourceId, EBinaryOn);
576 r = iToc.GetResourceState(res.iResourceId, state);
578 test_Equal(EBinaryOn, state);
581 r = iTac1.ChangeResourceState(res.iResourceId, EBinaryOff);
583 r = iToc.GetResourceState(res.iResourceId, state);
585 test_Equal(EBinaryOff, state);
587 r = iTac1.DeRegisterClient();
590 test.Printf(_L("\n"));
593 /* ----------------------------------------------------------------------------
594 @SYMTestCaseID PBASE-PRMACCTST-MULTILEVEL-0563
595 @SYMTestCaseDesc Ensure Multi-Level Resources function as expected
598 @SYMTestPriority High
601 If in use, resource state is not equal to max level
602 If in use, resource is not Single-User
603 Resource is not Custom Sense
604 For each Multi-Level resource:
605 1. Register TOC and TAC1
606 2. Define a number of gradually increasing (or decreasing if negative
607 sense resource) test values across the range of valid states. Attempt
608 to change the resource state to each of these values.
609 3. De-register TOC and TAC1
610 @SYMTestExpectedResults
611 1. Clients registered
612 2. Resource state should be changed to the test value if this value is
613 accepted by the PSL. If not, the resource state should be changed to
614 the minimum valid value that satisfies this requirement.
615 3. Clients de-registered
618 void CTestPrmAccTst::TestMultilevelResources(TInt aResourceNo)
620 test.Printf(_L("---Multi-level "));
621 TResInfo& res = *((TResInfo*) iResources.Ptr() + aResourceNo);
622 // Test pre-conditions
623 if (res.iSense == TResInfo::ECustom)
625 test.Printf(_L("Not tested (Custom sense resource)\n"));
629 TInt r = iToc.GetResourceState(res.iResourceId, state);
632 r = iToc.GetLevelOwner(res.iResourceId, levelowner);
635 if (levelowner != KTestResourceNotInUse)
637 if (state == res.iMaxLevel)
639 test.Printf(_L("Not tested (Resource is already at maximum level)\n"));
642 if (res.iUsage == TResInfo::ESingleUse)
644 test.Printf(_L("Not tested (Single-User resource already in use)\n"));
648 // Define test values
649 TInt tstval[KTestMultiLevelValues];
651 for (i = 0; i < KTestMultiLevelValues; i++)
653 if (levelowner == KTestResourceNotInUse)
655 // If resource is not in use, we can use the entire state range
656 tstval[i] = res.iMinLevel + i * (res.iMaxLevel - res.iMinLevel) / (KTestMultiLevelValues - 1);
660 // Or else we are limited to the Current State-MaxLevel range
661 tstval[i] = state + i * (res.iMaxLevel - state) / (KTestMultiLevelValues - 1);
664 test_Compare(tstval[0], !=, tstval[KTestMultiLevelValues - 1]);
668 r = iTac1.RegisterClient(KTestTac1);
671 for (i = 0; i < KTestMultiLevelValues; i++)
673 r = iTac1.ChangeResourceState(res.iResourceId, tstval[i]);
675 r = iToc.GetResourceState(res.iResourceId, state);
677 // Resource state should be equal to the test value
678 // or to the first valid value that satisfies the request
679 if (res.iSense == TResInfo::EPositive)
681 test_Compare(state, >=, tstval[i]);
685 test_Compare(state, <=, tstval[i]);
687 test.Printf(_L("."));
690 r = iTac1.DeRegisterClient();
693 test.Printf(_L("\n"));
696 /* ----------------------------------------------------------------------------
697 @SYMTestCaseID PBASE-PRMACCTST-LATENCY-0564
698 @SYMTestCaseDesc Ensure instantaneous resource change state instantaneously
701 @SYMTestPriority High
704 If in use, resource is not Single-User
705 If in use, resource state is not equal to max level
706 If in use, resource is not Custom Sense
707 For each Multi-Level resource:
709 2. TAC1 changes resource state to max value (async)
710 3. Immediately afterwards, TAC1 gets resource state (sync)
711 4. Wait for callback function
712 5. TAC1 changes resource state to min value (async)
713 6. Immediately afterwards, TAC1 gets resource state (sync)
714 7. Wait for callback function
716 @SYMTestExpectedResults
718 2. No error reported.
719 3. If resource is Instantaneous Set, then the resource state is equal to
720 the new state. If Long Latency Set, then the state is either the old or
722 4. Callback function is called.
723 5. No error reported.
724 6. If resource is Instantaneous Set, then the resource state is equal to
725 the new state. If Long Latency Set, then the state is either the old or
727 7. Callback function is called.
728 8. Client de-registered.
731 void CTestPrmAccTst::TestLatency(TInt aResourceNo)
733 test.Printf(_L("---Latency "));
734 TResInfo& res = *((TResInfo*) iResources.Ptr() + aResourceNo);
735 // Test pre-conditions
736 if (res.iSense == TResInfo::ECustom)
738 test.Printf(_L("Not tested (Custom sense resource)\n"));
742 TInt r = iToc.GetResourceState(res.iResourceId, state);
745 r = iToc.GetLevelOwner(res.iResourceId, levelowner);
748 if (levelowner != KTestResourceNotInUse)
750 if (state == res.iMaxLevel)
752 test.Printf(_L("Not tested (Resource is already at maximum level)\n"));
755 if (res.iUsage == TResInfo::ESingleUse)
757 test.Printf(_L("Not tested (Single-User resource already in use)\n"));
761 // Define the two test values
764 if (levelowner != KTestResourceNotInUse)
767 tstval1 = res.iMaxLevel;
772 tstval1 = res.iMaxLevel;
773 tstval2 = res.iMinLevel;
778 r = iTac1.RegisterClient(KTestTac1);
781 TTestResourceStateBuf buf;
782 buf().iResourceId = res.iResourceId;
783 buf().iNewState = tstval1;
786 iTac1.ChangeResourceStateAndGetState(rs, buf, tmpstate);
787 User::WaitForRequest(rs);
788 test_KErrNone(rs.Int());
789 if (res.iLatencySet == TResInfo::EInstantaneous)
791 test_Equal(tstval1, tmpstate); // Temp state is equal to the new state
793 else if (tmpstate != state) // Temp state is not necessarily equal to the new state
795 test_Equal(tstval1, tmpstate);
798 r = iToc.GetResourceState(res.iResourceId, newstate);
800 test_Equal(tstval1, newstate);
802 buf().iNewState = tstval2;
803 iTac1.ChangeResourceStateAndGetState(rs, buf, tmpstate);
804 User::WaitForRequest(rs);
805 test_KErrNone(rs.Int());
806 if (res.iLatencySet == TResInfo::EInstantaneous)
808 test_Equal(tstval2, tmpstate); // Temp state is equal to the new state
810 else if (tmpstate != tstval1) // Temp state is not necessarily equal to the new state
812 test_Equal(tstval2, tmpstate);
814 r = iToc.GetResourceState(res.iResourceId, newstate);
816 test_Equal(tstval2, newstate);
818 r = iTac1.DeRegisterClient();
821 test.Printf(_L("\n"));
824 /* ----------------------------------------------------------------------------
825 @SYMTestCaseID PBASE-PRMACCTST-SENSE-0565
826 @SYMTestCaseDesc Ensure Negative and Positive Sense resources behave as
830 @SYMTestPriority High
834 If in use, resource state is not equal to max level
835 For each Positive or Negative Sense resource:
836 1. Register TOC, TAC1, TAC2 and TAC3
837 2. Define three distincts test values, s1, s2 and s3, that correspond to
838 actual resource states in the PSL. s1 and s3 are at opposite ends of
839 the range of states the resource can be set to. s2 is an intermediate
840 state. It might not always be possible to find a distinct value for s2
841 (if the resource is binary or if its current use is limiting the number
842 of states the resource can be set to). In this case, s2 = s1.
843 3. TAC1 sets resource state to s1
844 4. TAC2 sets resource state to s2
845 5. TAC3 sets resource state to s3
848 8. De-register TAC1 and register TAC1, TAC2 and TAC3 again.
849 9. TAC1 sets resource state to s1
850 10. TAC3 sets resource state to s3
851 11. TAC2 sets resource state to s2
852 12. De-register TAC3.
853 13. TAC3 sets resource state to s3
854 14. De-register TOC, TAC1, TAC2 and TAC3
855 @SYMTestExpectedResults
856 1. Clients registered
858 3. Resource state set to s1
859 4. Resource state set to s2
860 5. Resource state set to s3
861 6. Resource state remains unchanged (TAC3 owns level)
862 7. Resource state returns to s1 (TAC1 now owns level)
863 8. Clients registered
864 9. Resource state set to s1
865 10. Resource state set to s3
866 11. Resource state remains unchanged (TAC3 owns level)
867 12. Resource state changes to s2 (TAC2 now owns level)
868 13. Resource state set to s3
869 14. Clients de-registered
872 void CTestPrmAccTst::TestSense(TInt aResourceNo)
874 test.Printf(_L("---Sense "));
875 TResInfo& res = *((TResInfo*) iResources.Ptr() + aResourceNo);
876 // Test pre-conditions
877 if (res.iUsage != TResInfo::EShared)
879 test.Printf(_L("Not tested: Resource is Single-User\n"));
884 TInt r = iToc.GetResourceState(res.iResourceId, state);
887 r = iToc.GetLevelOwner(res.iResourceId, levelowner);
890 if (levelowner != KTestResourceNotInUse && state == res.iMaxLevel)
892 test.Printf(_L("Not tested (Resource is already at maximum level)\n"));
895 // Define three test values
898 r = iTac1.RegisterClient(KTestTac1);
903 if (levelowner == KTestResourceNotInUse)
905 tstval1 = res.iMinLevel;
911 tstval3 = res.iMaxLevel;
912 // Attempt to find a distinct intermediate value by dichotomy
914 while ((tstval2 - tstval1 < -1) || (tstval2 - tstval1 > 1))
916 tstval2 -= (tstval2 - tstval1 + (res.iSense == TResInfo::EPositive ? 1 : 0)) / 2;
917 r = iTac1.ChangeResourceState(res.iResourceId, tstval2);
919 r = iTac1.GetResourceState(res.iResourceId, state);
922 if (state == tstval1 && res.iType == TResInfo::EMultiLevel)
924 test.Printf(_L("(Could not find three distincts test values)"));
927 r = iTac1.DeRegisterClient();
938 r = iTac1.RegisterClient(KTestTac1);
940 r = iTac2.RegisterClient(KTestTac2);
942 r = iTac3.RegisterClient(KTestTac3);
945 // Set resource state to the first test value
946 r = iTac1.ChangeResourceState(res.iResourceId, tstval1);
948 r = iToc.GetResourceState(res.iResourceId, state);
950 test_Equal(tstval1, state);
952 // Set resource state to middle test value
953 r = iTac2.ChangeResourceState(res.iResourceId, tstval2);
955 r = iToc.GetResourceState(res.iResourceId, state);
957 test_Equal(tstval2, state);
959 // Set resource to the third test value
960 r = iTac3.ChangeResourceState(res.iResourceId, tstval3);
962 r = iToc.GetResourceState(res.iResourceId, state);
964 test_Equal(tstval3, state);
966 // De-register second client
967 r = iTac2.DeRegisterClient();
969 r = iToc.GetResourceState(res.iResourceId, state);
971 test_Equal(tstval3, state); // state remains unchanged
973 // De-register third client
974 r = iTac3.DeRegisterClient();
976 r = iToc.GetResourceState(res.iResourceId, state);
978 test_Equal(tstval1, state); // state changes
980 // De-register and register all clients again
981 r = iTac1.DeRegisterClient();
983 r = iTac1.RegisterClient(KTestTac1);
985 r = iTac2.RegisterClient(KTestTac2);
987 r = iTac3.RegisterClient(KTestTac3);
990 // Set resource state to the first test value
991 r = iTac1.ChangeResourceState(res.iResourceId, tstval1);
993 r = iToc.GetResourceState(res.iResourceId, state);
995 test_Equal(tstval1, state);
997 // Set resource to the third test value
998 r = iTac3.ChangeResourceState(res.iResourceId, tstval3);
1000 r = iToc.GetResourceState(res.iResourceId, state);
1002 test_Equal(tstval3, state);
1004 // Set resource state to middle test value
1005 r = iTac2.ChangeResourceState(res.iResourceId, tstval2);
1007 r = iToc.GetResourceState(res.iResourceId, state);
1009 test_Equal(tstval3, state); // state does not change
1011 // De-register client holding resource
1012 r = iTac3.DeRegisterClient();
1014 r = iToc.GetResourceState(res.iResourceId, state);
1016 test_Equal(tstval2, state);
1018 // Register client again
1019 r = iTac3.RegisterClient(KTestTac3);
1021 r = iTac3.ChangeResourceState(res.iResourceId, tstval3);
1023 r = iToc.GetResourceState(res.iResourceId, state);
1025 test_Equal(tstval3, state);
1028 r = iTac3.DeRegisterClient();
1030 r = iTac2.DeRegisterClient();
1032 r = iTac1.DeRegisterClient();
1037 test.Printf(_L("\n"));
1040 /* ----------------------------------------------------------------------------
1041 @SYMTestCaseID PBASE-PRMACCTST-CUSTOMSENSE-0566
1042 @SYMTestCaseDesc Ensure the Custom Sense function is implemented
1045 @SYMTestPriority High
1047 For each Custom Sense resource:
1049 2. Attempt to set the state of the resource to its current state. The
1050 purpose of this test action is to ensure that the PSL's custom function
1051 for this resource has been implemented. If the custom function is not
1052 present, the PIL will generate a panic.
1054 @SYMTestExpectedResults
1055 1. Client registered
1056 2. The resource change request does not cause a panic.
1057 3. Client de-registered
1060 void CTestPrmAccTst::TestCustomSense(TInt aResourceNo)
1062 test.Printf(_L("---Custom Sense"));
1063 TResInfo& res = *((TResInfo*) iResources.Ptr() + aResourceNo);
1064 TInt r = iTac1.Open();
1066 r = iTac1.RegisterClient(KTestTac1);
1070 r = iTac1.GetResourceState(res.iResourceId, state);
1072 r = iTac1.ChangeResourceState(res.iResourceId, state);
1075 r = iTac1.DeRegisterClient();
1078 test.Printf(_L("\n"));
1081 /* ----------------------------------------------------------------------------
1082 @SYMTestCaseID PBASE-PRMACCTST-POWERRESUMPTION-0567
1083 @SYMTestCaseDesc Ensure resources go back to their default state when not in
1087 @SYMTestPriority High
1091 Not a Custom Sense resource
1094 2. Set resource state to something that is not the default level
1097 5. Get resource state
1099 @SYMTestExpectedResults
1100 1. Client registered
1101 2. Resource state changed
1102 3. Client de-registered
1103 4. Client registered
1104 5. Resource state is at the default level
1105 6. Client de-registered
1108 void CTestPrmAccTst::TestDefaultPowerResumption()
1111 for (i = 0; i < (TInt) iNoResources; i++)
1113 TResInfo& res = *((TResInfo*) iResources.Ptr() + i);
1114 test.Printf(_L("Resource %08x "), res.iResourceId);
1116 TInt r = iToc.GetLevelOwner(res.iResourceId, levelowner);
1119 // Test pre-condition: resource not in use
1120 if (levelowner != KTestResourceNotInUse)
1122 test.Printf(_L("Not tested (already in use)\n"));
1125 if (res.iSense == TResInfo::ECustom)
1127 test.Printf(_L("Not tested (custom sense)\n"));
1131 // Define a test value
1133 if (res.iDefaultLevel == res.iMaxLevel)
1135 tstval = res.iMinLevel;
1139 tstval = res.iMaxLevel;
1145 r = iTac1.RegisterClient(KTestTac1);
1147 // Change resource state
1149 r = iToc.GetResourceState(res.iResourceId, state);
1151 test_Equal(res.iDefaultLevel, state);
1152 r = iTac1.ChangeResourceState(res.iResourceId, tstval);
1154 r = iToc.GetResourceState(res.iResourceId, state);
1156 test_Equal(tstval, state);
1157 // De-register active client so resource is freed
1158 r = iTac1.DeRegisterClient();
1161 // Read both cached and actual values
1163 r = iToc.GetResourceStateCached(res.iResourceId, cached);
1165 r = iToc.GetResourceState(res.iResourceId, state);
1167 test_Equal(cached, state);
1168 test_Equal(res.iDefaultLevel, state);
1169 test.Printf(_L("\n"));
1172 test.Printf(_L("\n"));
1175 /* ----------------------------------------------------------------------------
1176 @SYMTestCaseID PBASE-PRMACCTST-DEPENDENCIESDECLARED-0568
1177 @SYMTestCaseDesc Ensure all actual resources dependencies have been declared
1180 @SYMTestPriority High
1184 Not a Custom Sense resource
1186 1. Register TOC & TAC1
1187 2. Get state of all resources
1188 3. Set the state of the resource under test state to something that is not
1190 4. Get state of all resource
1191 5. De-register TAC1 & TOC
1192 @SYMTestExpectedResults
1193 1. Clients registered
1195 3. Resource state changed
1196 4. Only resources with a direct or indirect dependency on the resource
1197 under test have changed.
1198 5. Client de-registered
1201 TBool CTestPrmAccTst::ResourceInterdependency(TInt aResourceIdOrig, TInt aCurrentResourceId, TInt aResourceIdTarget)
1203 // Get Reference on current resource node
1205 if (aCurrentResourceId & KTestIdHasDependencies)
1207 // Get dependencies of current resources
1209 deplist.Create(sizeof(SResDepInfo) * KTestMaxDependencies);
1210 r = iToc.GetResourceDependencies(aCurrentResourceId, deplist);
1213 test.Printf(_L("ERROR: aCurrentResourceId==%08x"), aCurrentResourceId);
1217 SResDepInfo *ptr = (SResDepInfo*)deplist.Ptr();
1218 for (i = 0; i < (TInt) (deplist.Length() / sizeof(SResDepInfo)); i++, ptr++)
1220 TInt depid = ptr->iResourceId;
1221 if (depid == aResourceIdTarget)
1223 // We've got a match
1226 else if (depid == aResourceIdOrig)
1228 // No going back to parent node
1233 // Recurse down the tree
1234 r = ResourceInterdependency(aCurrentResourceId, depid, aResourceIdTarget);
1246 void CTestPrmAccTst::TestDependenciesAreDeclared(TInt aResourceNo)
1248 test.Printf(_L("---Test all dependencies are declared\n"));
1249 TResInfo& res = *((TResInfo*) iResources.Ptr() + aResourceNo);
1252 TInt r = iToc.GetLevelOwner(res.iResourceId, levelowner);
1254 // Test pre-condition: resource not in use
1255 if (levelowner != KTestResourceNotInUse)
1257 test.Printf(_L("Not tested (already in use)\n"));
1260 if (res.iSense == TResInfo::ECustom)
1262 test.Printf(_L("Not tested (custom sense)\n"));
1265 // Define a test value
1267 if (res.iDefaultLevel == res.iMaxLevel)
1269 tstval = res.iMinLevel;
1273 tstval = res.iMaxLevel;
1277 // Save current state of all resources;
1278 RArray<TInt> oldstate;
1281 for (i = 0; i < (TInt) iNoResources; i++)
1283 TResInfo& tmpres = *((TResInfo*) iResources.Ptr() + i);
1284 r = iToc.GetResourceState(tmpres.iResourceId, state);
1286 r = oldstate.Append(state);
1292 r = iTac1.RegisterClient(KTestTac1);
1295 // Change resource state
1296 r = iToc.GetResourceState(res.iResourceId, state);
1298 test_Equal(res.iDefaultLevel, state);
1299 r = iTac1.ChangeResourceState(res.iResourceId, tstval);
1301 r = iToc.GetResourceState(res.iResourceId, state);
1303 test_Equal(tstval, state);
1305 // Now we check that resources with no dependency on resource under test
1307 for (i = 0; i < (TInt) iNoResources; i++)
1309 test.Printf(_L("."));
1310 if (i == aResourceNo)
1314 TResInfo& tmpres = *((TResInfo*) iResources.Ptr() + i);
1315 r = iToc.GetResourceState(tmpres.iResourceId, state);
1317 if (!ResourceInterdependency(0, res.iResourceId, tmpres.iResourceId) &&
1318 (state != oldstate[i]))
1320 test.Printf(_L("Resource %08x has changed!\n"), tmpres.iResourceId);
1321 test_Equal(state, oldstate[i]);
1324 test.Printf(_L("\n"));
1326 // De-register active client
1327 r = iTac1.DeRegisterClient();
1334 TInt CTestPrmAccTst::DoTestPreamble()
1337 test.Start(_L("Preamble"));
1339 // Load Device Driver
1341 #ifdef RESOURCE_MANAGER_SIMULATED_PSL
1342 test.Printf(_L("Load Simulated PSL PDD\n"));
1343 r = User::LoadPhysicalDevice(_L("RESOURCECONTROLLEREXTENDED.PDD"));
1344 if (r == KErrNotFound)
1346 test.Printf(_L("RESOURCECONTROLLEREXTENDED.PDD not found\nTest skipped\n"));
1351 test_Equal(KErrAlreadyExists, r);
1352 test.Printf(_L("Already loaded\n"));
1354 test.Printf(_L("Load test LDD\n"));
1355 r = User::LoadLogicalDevice(_L("D_PRMACCTSTSIM.LDD"));
1358 test_Equal(KErrAlreadyExists, r);
1359 test.Printf(_L("Already loaded\n"));
1362 test.Printf(_L("Load test LDD\n"));
1363 r = User::LoadLogicalDevice(_L("D_PRMACCTST.LDD"));
1366 test_Equal(KErrAlreadyExists, r);
1367 test.Printf(_L("Already loaded\n"));
1369 #endif // RESOURCE_MANAGER_SIMULATED_PSL
1371 // Check if Device Driver was loaded as a Kernel Extension
1374 r = iKextc.GetKernelExtClientId(clientId);
1378 test.Printf(_L("No Kernel extension PRM client\n"));
1383 // De-register client so Single User resources can be tested
1384 r = iKextc.OpenClient(clientId);
1386 r = iKextc.DeRegisterClient();
1391 // Register TOC (always on - de-registered in test postamble)
1394 r = iToc.RegisterClient(KTestToc);
1397 // Get resources info
1398 r = iToc.GetTotalNumberOfResources(iNoResources);
1400 test.Printf(_L("Resources found: %d\n"), iNoResources);
1401 if (iNoResources > 0)
1403 r = iResources.Create(iNoResources * sizeof(TResInfo));
1405 test.Printf(_L("Retrieving information on resources\n"));
1406 r = iToc.GetInfoOnResourcesInUseByClient(0, iResources);
1408 iIsPrmSupported = ETrue;
1412 test.Printf(_L("No resource found.\n"));
1417 void CTestPrmAccTst::DoTest()
1419 if (!iIsPrmSupported)
1424 test.Next(_L("Enumerate Resources"));
1425 TestEnumerateResources();
1428 test.Next(_L("Resource Properties"));
1429 for (i = 0; i < (TInt) iNoResources; i++)
1431 TResInfo& res = *((TResInfo*) iResources.Ptr() + i);
1432 test.Printf(_L("+++Resource %08x\n"), res.iResourceId);
1434 if (res.iUsage == TResInfo::ESingleUse)
1436 TestSingleUserResources(i);
1438 else if (res.iUsage == TResInfo::EShared)
1440 TestSharedResources(i);
1443 if (res.iType == TResInfo::EBinary)
1445 TestBinaryResources(i);
1447 else if (res.iType == TResInfo::EMultiLevel)
1449 TestMultilevelResources(i);
1454 if ((res.iSense == TResInfo::EPositive) || (res.iSense == TResInfo::ENegative))
1458 else if (res.iSense == TResInfo::ECustom)
1464 test.Next(_L("Default Power Resumption"));
1465 TestDefaultPowerResumption();
1467 test.Next(_L("PRM Extension - Dependencies"));
1468 for (i = 0; i < (TInt) iNoResources; i++)
1470 TResInfo& res = *((TResInfo*) iResources.Ptr() + i);
1471 if (res.iResourceId & KTestIdHasDependencies)
1473 test.Printf(_L("+++Resource %08x\n"), res.iResourceId);
1474 TestDependenciesAreDeclared(i);
1479 void CTestPrmAccTst::DoTestPostamble()
1481 test.Next(_L("Postamble"));
1484 TInt r = iToc.DeRegisterClient();
1492 GLDEF_C TInt MainL()
1494 CTestPrmAccTst* testapp;
1495 testapp = new (ELeave) CTestPrmAccTst();
1496 CleanupStack::PushL(testapp);
1497 if (testapp->DoTestPreamble() == KErrNone)
1501 testapp->DoTestPostamble();
1502 CleanupStack::PopAndDestroy(testapp);
1506 GLDEF_C TInt E32Main()
1509 CTrapCleanup* cleanup = CTrapCleanup::New();
1512 return KErrNoMemory;
1514 TRAP_IGNORE(MainL());