sl@0: // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #define __E32TEST_EXTENSION__ sl@0: #include sl@0: #include "d_prmacctst.h" sl@0: sl@0: _LIT8(KTestToc, "TOC"); sl@0: _LIT8(KTestTac1, "TAC1"); sl@0: _LIT8(KTestTac2, "TAC2"); sl@0: _LIT8(KTestTac3, "TAC3"); sl@0: sl@0: // The number of test values for multi-level resources sl@0: static const TInt KTestMultiLevelValues = 10; sl@0: sl@0: // Bit 16 in the resource ID indicates that the resource has dependencies sl@0: static const TUint32 KTestIdHasDependencies = 0x00010000; sl@0: static const TInt KTestMaxDependencies = 256; sl@0: sl@0: static const TInt KTestResourceNotInUse = -1; sl@0: sl@0: // structure for holding ResId and ResPrty sl@0: struct SResDepInfo sl@0: { sl@0: TUint iResourceId; sl@0: TUint8 iDependencyPriority; sl@0: }; sl@0: class CTestPrmAccTst : public CBase sl@0: { sl@0: public: sl@0: CTestPrmAccTst(); sl@0: ~CTestPrmAccTst(); sl@0: TInt DoTestPreamble(); sl@0: void DoTest(); sl@0: void DoTestPostamble(); sl@0: protected: sl@0: TBool ResourceInterdependency(TInt aResourceIdOrig, TInt aCurrentResourceId, TInt aResourceIdTarget); sl@0: void TestEnumerateResources(); sl@0: void TestSingleUserResources(TInt aResourceNo); sl@0: void TestSharedResources(TInt aResourceNo); sl@0: void TestBinaryResources(TInt aResourceNo); sl@0: void TestMultilevelResources(TInt aResourceNo); sl@0: void TestLatency(TInt aResourceNo); sl@0: void TestSense(TInt aResourceNo); sl@0: void TestCustomSense(TInt aResourceNo); sl@0: void TestDefaultPowerResumption(); sl@0: void TestDependenciesAreDeclared(TInt aResourceNo); sl@0: private: sl@0: enum TBinary sl@0: { sl@0: EBinaryOff = 0, sl@0: EBinaryOn = 1 sl@0: }; sl@0: protected: sl@0: RTest test; sl@0: private: sl@0: // The test PRM clients sl@0: RPrmIf iToc; // Test Observer Client (never owns any resource) sl@0: RPrmIf iTac1; // Active clients... sl@0: RPrmIf iTac2; sl@0: RPrmIf iTac3; sl@0: RPrmIf iKextc; // The Kernel Extension Client (owns Single User Resources) sl@0: // sl@0: TBool iIsPrmSupported; sl@0: // sl@0: RBuf8 iResources; sl@0: TUint iNoResources; sl@0: // sl@0: static CTestPrmAccTst* iSingletonInstance; sl@0: }; sl@0: sl@0: CTestPrmAccTst::CTestPrmAccTst() sl@0: :test(_L("T_PRMACCTST")), sl@0: iIsPrmSupported(EFalse), sl@0: iNoResources(0) sl@0: { sl@0: } sl@0: sl@0: CTestPrmAccTst::~CTestPrmAccTst() sl@0: { sl@0: iResources.Close(); sl@0: TInt r = User::FreeLogicalDevice(KPrmIfLddName); sl@0: test(r==KErrNone); sl@0: #ifdef RESOURCE_MANAGER_SIMULATED_PSL sl@0: r = User::FreePhysicalDevice(_L("resourcecontrollerextended.pdd")); sl@0: test(r==KErrNone); sl@0: #endif sl@0: User::After(100000); sl@0: } sl@0: sl@0: /* ---------------------------------------------------------------------------- sl@0: @SYMTestCaseID PBASE-PRMACCTST-ENUMRES-0559 sl@0: @SYMTestCaseDesc Ensure current resource state of PRM is correctly listed sl@0: @SYMREQ REQ7751 sl@0: @SYMPREQ PREQ1398 sl@0: @SYMTestPriority Critical sl@0: @SYMTestActions sl@0: 1. Display all resources and their properties sl@0: 2. Ensure the resource state range is coherent sl@0: @SYMTestExpectedResults sl@0: 1. All resources are shown with the correct properties sl@0: 2. Min <= Default <= Max and Min < Max if Negative Sense sl@0: Min >= Default >= Max and Max > Min if Positive Sense sl@0: Binary resources states are '0' or '1' sl@0: */ sl@0: sl@0: void CTestPrmAccTst::TestEnumerateResources() sl@0: { sl@0: test.Printf(_L("Id Resource name C LG LS T U S DefltLvl MinLevel MaxLevel\n")); sl@0: test.Printf(_L("--------+--------------------------------+-+--+--+--+--+-+--------+--------+--------\n")); sl@0: TInt i; sl@0: for (i = 0; i < (TInt) iNoResources; i++) sl@0: { sl@0: TResInfo& res = *((TResInfo*) iResources.Ptr() + i); sl@0: sl@0: // Display properties sl@0: test.Printf(_L("%08x "), res.iResourceId); sl@0: test_Compare(res.iResourceName->Length(), <=, KNameMaxLength); sl@0: TBuf tmp; sl@0: tmp.Copy(*res.iResourceName); sl@0: test.Printf(_L("%-.32S "), &tmp); sl@0: // sl@0: if (res.iClass == TResInfo::EPhysical) sl@0: { sl@0: test.Printf(_L("P ")); sl@0: } sl@0: else if (res.iClass == TResInfo::ELogical) sl@0: { sl@0: test.Printf(_L("L ")); sl@0: } sl@0: else sl@0: { sl@0: test(EFalse); sl@0: } sl@0: // sl@0: if (res.iLatencyGet == TResInfo::EInstantaneous) sl@0: { sl@0: test.Printf(_L("In ")); sl@0: } sl@0: else if (res.iLatencyGet == TResInfo::ELongLatency) sl@0: { sl@0: test.Printf(_L("Lo ")); sl@0: } sl@0: else sl@0: { sl@0: test(EFalse); sl@0: } sl@0: // sl@0: if (res.iLatencySet == TResInfo::EInstantaneous) sl@0: { sl@0: test.Printf(_L("In ")); sl@0: } sl@0: else if (res.iLatencySet == TResInfo::ELongLatency) sl@0: { sl@0: test.Printf(_L("Lo ")); sl@0: } sl@0: else sl@0: { sl@0: test(EFalse); sl@0: } sl@0: // sl@0: if (res.iType == TResInfo::EBinary) sl@0: { sl@0: test.Printf(_L("B ")); sl@0: } sl@0: else if (res.iType == TResInfo::EMultiLevel) sl@0: { sl@0: test.Printf(_L("ML ")); sl@0: } sl@0: else if (res.iType == TResInfo::EMultiProperty) sl@0: { sl@0: test.Printf(_L("MP ")); sl@0: } sl@0: else sl@0: { sl@0: test(EFalse); sl@0: } sl@0: // sl@0: if (res.iUsage == TResInfo::ESingleUse) sl@0: { sl@0: test.Printf(_L("SU ")); sl@0: } sl@0: else if (res.iUsage == TResInfo::EShared) sl@0: { sl@0: test.Printf(_L("Sh ")); sl@0: } sl@0: else sl@0: { sl@0: test(EFalse); sl@0: } sl@0: // sl@0: if (res.iSense == TResInfo::EPositive) sl@0: { sl@0: test.Printf(_L("+ ")); sl@0: } sl@0: else if (res.iSense == TResInfo::ENegative) sl@0: { sl@0: test.Printf(_L("- ")); sl@0: } sl@0: else if (res.iSense == TResInfo::ECustom) sl@0: { sl@0: test.Printf(_L("C ")); sl@0: } sl@0: else sl@0: { sl@0: test(EFalse); sl@0: } sl@0: // sl@0: test.Printf(_L("%08x "), res.iDefaultLevel); sl@0: test.Printf(_L("%08x "), res.iMinLevel); sl@0: test.Printf(_L("%08x\n"), res.iMaxLevel); sl@0: sl@0: // Retrieve resource dependencies sl@0: if (res.iResourceId & KTestIdHasDependencies) sl@0: { sl@0: RBuf8 deplist; sl@0: deplist.Create(sizeof(SResDepInfo) * KTestMaxDependencies); sl@0: iToc.GetResourceDependencies(res.iResourceId, deplist); sl@0: TInt j; sl@0: test.Printf(_L(" Direct Dependencies:")); sl@0: SResDepInfo* ptr = (SResDepInfo*)deplist.Ptr(); sl@0: for (j = 0; j < (TInt) (deplist.Length() / sizeof(SResDepInfo)); j++, ptr++) sl@0: { sl@0: test.Printf(_L("ResourceId: %08x"), ptr->iResourceId); sl@0: test.Printf(_L("Resource Priority: %08x"), ptr->iDependencyPriority); sl@0: } sl@0: test.Printf(_L("\n")); sl@0: deplist.Close(); sl@0: } sl@0: test.Printf(_L("C:Class,P:Physical,L:Logical")); sl@0: test.Printf(_L("LG/LS:Latency Get/Set,In:Instantaneous,Lo:Long Latency")); sl@0: test.Printf(_L("T:Type,MP:Multiproperty,ML:Multilevel,B:Binary")); sl@0: test.Printf(_L("U:Usage,SU:Single-User,Sh:Shared")); sl@0: test.Printf(_L("S:Sense,+:Positive,-:Negative,C:Custom")); sl@0: sl@0: // Ensure the state range of the resource does not contradict its properties sl@0: if (res.iType == TResInfo::EBinary) sl@0: { sl@0: if (res.iSense == TResInfo::EPositive) sl@0: { sl@0: test(res.iMinLevel == EBinaryOff); sl@0: test(res.iMaxLevel == EBinaryOn); sl@0: } sl@0: else if (res.iSense == TResInfo::ENegative) sl@0: { sl@0: test(res.iMinLevel == EBinaryOn); sl@0: test(res.iMaxLevel == EBinaryOff); sl@0: } sl@0: else if (res.iSense == TResInfo::ECustom) sl@0: { sl@0: test(res.iMinLevel == EBinaryOff || res.iMinLevel == EBinaryOn); sl@0: test(res.iMaxLevel == EBinaryOff || res.iMaxLevel == EBinaryOn); sl@0: test_Compare(res.iMinLevel, !=, res.iMaxLevel); sl@0: } sl@0: test((res.iDefaultLevel == EBinaryOff) || (res.iDefaultLevel == EBinaryOn)); sl@0: } sl@0: // Level range must respect resource sense sl@0: if (res.iSense == TResInfo::EPositive) sl@0: { sl@0: test_Compare(res.iMinLevel, <=, res.iMaxLevel); sl@0: test_Compare(res.iMinLevel, <=, res.iDefaultLevel); sl@0: test_Compare(res.iDefaultLevel, <=, res.iMaxLevel); sl@0: test_Compare(res.iMinLevel, <, res.iMaxLevel); sl@0: } sl@0: else if (res.iSense == TResInfo::ENegative) sl@0: { sl@0: test_Compare(res.iMinLevel, >=, res.iMaxLevel); sl@0: test_Compare(res.iMinLevel, >=, res.iDefaultLevel); sl@0: test_Compare(res.iDefaultLevel, >=, res.iMaxLevel); sl@0: test_Compare(res.iMinLevel, >, res.iMaxLevel); sl@0: } sl@0: } sl@0: } sl@0: sl@0: /* ---------------------------------------------------------------------------- sl@0: @SYMTestCaseID PBASE-PRMACCTST-SINGLEUSER-0560 sl@0: @SYMTestCaseDesc Ensure Single User resources can only be used by one client sl@0: at a time sl@0: @SYMREQ REQ7751 sl@0: @SYMPREQ PREQ1398 sl@0: @SYMTestPriority High sl@0: @SYMTestActions sl@0: Pre-condition: sl@0: The resource is not in use sl@0: For each Single User resource: sl@0: 1. Register TAC1 & TAC2 sl@0: 2. TAC1 changes resource state sl@0: 3. TAC2 changes resource state sl@0: 4. De-register TAC1 sl@0: --- sl@0: 5. Register TAC1 sl@0: 6. TAC2 changes resource state sl@0: 7. TAC1 changes resource state sl@0: 8. De-register TAC1 & TAC2 sl@0: @SYMTestExpectedResults sl@0: 1. Clients registered sl@0: 2. Resource state changed sl@0: 3. KErrAccessDenied as there is already one registered client sl@0: 4. Client de-registered sl@0: --- sl@0: 5. Client registered sl@0: 6. Resource state changed sl@0: 7. KErrAccessDenied as there is already one registered client sl@0: 8. Both clients de-registered sl@0: */ sl@0: sl@0: void CTestPrmAccTst::TestSingleUserResources(TInt aResourceNo) sl@0: { sl@0: test.Printf(_L("---Single-User ")); sl@0: TResInfo& res = *((TResInfo*) iResources.Ptr() + aResourceNo); sl@0: // Test pre-condition: resource not in use sl@0: TInt levelowner; sl@0: TInt r = iToc.GetLevelOwner(res.iResourceId, levelowner); sl@0: test_KErrNone(r); sl@0: if (levelowner != KTestResourceNotInUse) sl@0: { sl@0: test.Printf(_L("Not tested (Single-User resource already in use)\n")); sl@0: return; sl@0: } sl@0: // Define two test values sl@0: TInt state; sl@0: r = iToc.GetResourceState(res.iResourceId, state); sl@0: test_KErrNone(r); sl@0: // sl@0: TInt tstval1; sl@0: TInt tstval2; sl@0: if (state == res.iMinLevel) sl@0: { sl@0: tstval1 = res.iMaxLevel; sl@0: tstval2 = res.iMinLevel; sl@0: } sl@0: else sl@0: { sl@0: tstval1 = res.iMinLevel; sl@0: tstval2 = res.iMaxLevel; sl@0: } sl@0: // Test starts here sl@0: r = iTac1.Open(); sl@0: test_KErrNone(r); sl@0: r = iTac2.Open(); sl@0: test_KErrNone(r); sl@0: r = iTac1.RegisterClient(KTestTac1); sl@0: test_KErrNone(r); sl@0: r = iTac2.RegisterClient(KTestTac2); sl@0: test_KErrNone(r); sl@0: // sl@0: r = iTac1.ChangeResourceState(res.iResourceId, tstval1); sl@0: test_KErrNone(r); sl@0: r = iTac1.GetResourceState(res.iResourceId, state); sl@0: test_KErrNone(r); sl@0: test_Equal(tstval1, state); sl@0: r = iTac2.GetResourceState(res.iResourceId, state); sl@0: test_KErrNone(r); sl@0: test_Equal(tstval1, state); sl@0: r = iTac2.ChangeResourceState(res.iResourceId, tstval2); sl@0: test_Equal(KErrAccessDenied, r); // TAC2 cannot change the resource state sl@0: // sl@0: r = iTac1.DeRegisterClient(); sl@0: test_KErrNone(r); sl@0: r = iTac1.RegisterClient(KTestTac1); sl@0: test_KErrNone(r); sl@0: r = iTac2.ChangeResourceState(res.iResourceId, tstval2); sl@0: test_KErrNone(r); sl@0: r = iTac1.GetResourceState(res.iResourceId, state); sl@0: test_KErrNone(r); // TAC1 can still access the resource state... sl@0: test_Equal(tstval2, state); sl@0: r = iTac1.ChangeResourceState(res.iResourceId, tstval1); sl@0: test_Equal(KErrAccessDenied, r); // ... but cannot change it sl@0: r = iTac2.GetResourceState(res.iResourceId, state); sl@0: test_KErrNone(r); sl@0: test_Equal(tstval2, state); // The resource state remains unchanged indeed sl@0: // sl@0: r = iTac1.DeRegisterClient(); sl@0: test_KErrNone(r); sl@0: r = iTac2.DeRegisterClient(); sl@0: test_KErrNone(r); sl@0: iTac1.Close(); sl@0: iTac2.Close(); sl@0: test.Printf(_L("\n")); sl@0: } sl@0: sl@0: /* ---------------------------------------------------------------------------- sl@0: @SYMTestCaseID PBASE-PRMACCTST-SHARED-0561 sl@0: @SYMTestCaseDesc Ensure a Shared Resources can be changed by several sl@0: clients sl@0: @SYMREQ REQ7751 sl@0: @SYMPREQ PREQ1398 sl@0: @SYMTestPriority High sl@0: @SYMTestActions sl@0: Pre-conditions: sl@0: If in use, resource state is not equal to max level sl@0: Resource is not Custom Sense sl@0: For each Shared resource: sl@0: 1. Register TOC, TAC1 & TAC2 sl@0: 2. TAC1 changes resource state to level1 sl@0: 3. TAC2 changes resource state to level2 sl@0: 4. TAC2 changes resource state to level1 sl@0: 5. TAC1 changes resource state to level2 sl@0: 6. De-register TOC, TAC1 & TAC2 sl@0: @SYMTestExpectedResults sl@0: 1. Clients registered sl@0: 2. Resource state changed sl@0: 3. Resource state changed sl@0: 4. Resource state changed sl@0: 5. Resource state changed sl@0: 6. Clients de-registered sl@0: */ sl@0: sl@0: void CTestPrmAccTst::TestSharedResources(TInt aResourceNo) sl@0: { sl@0: test.Printf(_L("---Shared ")); sl@0: TResInfo& res = *((TResInfo*) iResources.Ptr() + aResourceNo); sl@0: // Test pre-conditions sl@0: if (res.iSense == TResInfo::ECustom) sl@0: { sl@0: test.Printf(_L("Not tested (Custom sense resource)\n")); sl@0: return; sl@0: } sl@0: // sl@0: TInt state; sl@0: TInt r = iToc.GetResourceState(res.iResourceId, state); sl@0: test_KErrNone(r); sl@0: TInt levelowner; sl@0: r = iToc.GetLevelOwner(res.iResourceId, levelowner); sl@0: test_KErrNone(r); sl@0: // sl@0: if (levelowner != KTestResourceNotInUse && state == res.iMaxLevel) sl@0: { sl@0: test.Printf(_L("Not tested: Resource is already at maximum level\n")); sl@0: return; sl@0: } sl@0: // Define two test values sl@0: TInt tstval1; sl@0: TInt tstval2; sl@0: if (levelowner != KTestResourceNotInUse) sl@0: { sl@0: // Resource already in use sl@0: tstval1 = state; sl@0: tstval2 = res.iMaxLevel; sl@0: } sl@0: else sl@0: { sl@0: // Resource not in use sl@0: tstval1 = res.iMinLevel; sl@0: tstval2 = res.iMaxLevel; sl@0: } sl@0: // Test starts here sl@0: r = iTac1.Open(); sl@0: test_KErrNone(r); sl@0: r = iTac2.Open(); sl@0: test_KErrNone(r); sl@0: r = iTac1.RegisterClient(KTestTac1); sl@0: test_KErrNone(r); sl@0: r = iTac2.RegisterClient(KTestTac2); sl@0: test_KErrNone(r); sl@0: // sl@0: r = iTac1.ChangeResourceState(res.iResourceId, tstval1); sl@0: test_KErrNone(r); sl@0: r = iToc.GetResourceState(res.iResourceId, state); sl@0: test_KErrNone(r); sl@0: test_Equal(tstval1, state); sl@0: // sl@0: r = iTac2.ChangeResourceState(res.iResourceId, tstval2); sl@0: test_KErrNone(r); sl@0: r = iToc.GetResourceState(res.iResourceId, state); sl@0: test_KErrNone(r); sl@0: test_Equal(tstval2, state); sl@0: // sl@0: r = iTac2.ChangeResourceState(res.iResourceId, tstval1); sl@0: test_KErrNone(r); sl@0: r = iToc.GetResourceState(res.iResourceId, state); sl@0: test_KErrNone(r); sl@0: test_Equal(tstval1, state); sl@0: // sl@0: r = iTac1.ChangeResourceState(res.iResourceId, tstval2); sl@0: test_KErrNone(r); sl@0: r = iToc.GetResourceState(res.iResourceId, state); sl@0: test_KErrNone(r); sl@0: test_Equal(tstval2, state); sl@0: // sl@0: r = iTac1.DeRegisterClient(); sl@0: test_KErrNone(r); sl@0: r = iTac2.DeRegisterClient(); sl@0: test_KErrNone(r); sl@0: // sl@0: iTac1.Close(); sl@0: iTac2.Close(); sl@0: test.Printf(_L("\n")); sl@0: } sl@0: sl@0: /* ---------------------------------------------------------------------------- sl@0: @SYMTestCaseID PBASE-PRMACCTST-BINARY-0562 sl@0: @SYMTestCaseDesc Ensure Binary Resources function as expected sl@0: @SYMREQ REQ7751 sl@0: @SYMPREQ PREQ1398 sl@0: @SYMTestPriority High sl@0: @SYMTestActions sl@0: Pre-conditions: sl@0: Resource not in use, or... sl@0: If Shared/Positive Sense, current resource must be off sl@0: If Shared/Negative Sense, current resource must be on sl@0: Resource is not Custom Sense sl@0: For each Binary resource: sl@0: 1. Register TAC1 sl@0: 2. Turn resource off and toggle resource state several times sl@0: 3. De-register TAC1 sl@0: @SYMTestExpectedResults sl@0: 1. Client registered sl@0: 2. Resource state changes as expected sl@0: 3. De-register TAC1 sl@0: */ sl@0: sl@0: void CTestPrmAccTst::TestBinaryResources(TInt aResourceNo) sl@0: { sl@0: test.Printf(_L("---Binary ")); sl@0: TResInfo& res = *((TResInfo*) iResources.Ptr() + aResourceNo); sl@0: // Test pre-conditions sl@0: if (res.iSense == TResInfo::ECustom) sl@0: { sl@0: test.Printf(_L("Not tested (Custom sense resource)\n")); sl@0: return; sl@0: } sl@0: TInt state; sl@0: TInt r = iToc.GetResourceState(res.iResourceId, state); sl@0: test_KErrNone(r); sl@0: TInt levelowner; sl@0: r = iToc.GetLevelOwner(res.iResourceId, levelowner); sl@0: test_KErrNone(r); sl@0: // sl@0: if (levelowner != KTestResourceNotInUse) sl@0: { sl@0: if (res.iUsage == TResInfo::ESingleUse) sl@0: { sl@0: test.Printf(_L("Not tested (Single-User resource already in use)\n")); sl@0: return; sl@0: } sl@0: if (res.iSense == TResInfo::EPositive && state == EBinaryOn) sl@0: { sl@0: test.Printf(_L("Not tested (Positive sense resource is already on)\n")); sl@0: return; sl@0: } sl@0: if (res.iSense == TResInfo::ENegative && state == EBinaryOff) sl@0: { sl@0: test.Printf(_L("Not tested (Negative sense resource is already off)\n")); sl@0: return; sl@0: } sl@0: } sl@0: // Test starts here sl@0: r = iTac1.Open(); sl@0: test_KErrNone(r); sl@0: r = iTac1.RegisterClient(KTestTac1); sl@0: test_KErrNone(r); sl@0: sl@0: // Turn Resource off sl@0: r = iTac1.ChangeResourceState(res.iResourceId, EBinaryOff); sl@0: test_KErrNone(r); sl@0: r = iToc.GetResourceState(res.iResourceId, state); sl@0: test_KErrNone(r); sl@0: test_Equal(EBinaryOff, state); sl@0: sl@0: // Turn it on sl@0: r = iTac1.ChangeResourceState(res.iResourceId, EBinaryOn); sl@0: test_KErrNone(r); sl@0: r = iToc.GetResourceState(res.iResourceId, state); sl@0: test_KErrNone(r); sl@0: test_Equal(EBinaryOn, state); sl@0: sl@0: // Turn it off sl@0: r = iTac1.ChangeResourceState(res.iResourceId, EBinaryOff); sl@0: test_KErrNone(r); sl@0: r = iToc.GetResourceState(res.iResourceId, state); sl@0: test_KErrNone(r); sl@0: test_Equal(EBinaryOff, state); sl@0: // sl@0: r = iTac1.DeRegisterClient(); sl@0: test_KErrNone(r); sl@0: iTac1.Close(); sl@0: test.Printf(_L("\n")); sl@0: } sl@0: sl@0: /* ---------------------------------------------------------------------------- sl@0: @SYMTestCaseID PBASE-PRMACCTST-MULTILEVEL-0563 sl@0: @SYMTestCaseDesc Ensure Multi-Level Resources function as expected sl@0: @SYMREQ REQ7751 sl@0: @SYMPREQ PREQ1398 sl@0: @SYMTestPriority High sl@0: @SYMTestActions sl@0: Pre-condition: sl@0: If in use, resource state is not equal to max level sl@0: If in use, resource is not Single-User sl@0: Resource is not Custom Sense sl@0: For each Multi-Level resource: sl@0: 1. Register TOC and TAC1 sl@0: 2. Define a number of gradually increasing (or decreasing if negative sl@0: sense resource) test values across the range of valid states. Attempt sl@0: to change the resource state to each of these values. sl@0: 3. De-register TOC and TAC1 sl@0: @SYMTestExpectedResults sl@0: 1. Clients registered sl@0: 2. Resource state should be changed to the test value if this value is sl@0: accepted by the PSL. If not, the resource state should be changed to sl@0: the minimum valid value that satisfies this requirement. sl@0: 3. Clients de-registered sl@0: */ sl@0: sl@0: void CTestPrmAccTst::TestMultilevelResources(TInt aResourceNo) sl@0: { sl@0: test.Printf(_L("---Multi-level ")); sl@0: TResInfo& res = *((TResInfo*) iResources.Ptr() + aResourceNo); sl@0: // Test pre-conditions sl@0: if (res.iSense == TResInfo::ECustom) sl@0: { sl@0: test.Printf(_L("Not tested (Custom sense resource)\n")); sl@0: return; sl@0: } sl@0: TInt state; sl@0: TInt r = iToc.GetResourceState(res.iResourceId, state); sl@0: test_KErrNone(r); sl@0: TInt levelowner; sl@0: r = iToc.GetLevelOwner(res.iResourceId, levelowner); sl@0: test_KErrNone(r); sl@0: // sl@0: if (levelowner != KTestResourceNotInUse) sl@0: { sl@0: if (state == res.iMaxLevel) sl@0: { sl@0: test.Printf(_L("Not tested (Resource is already at maximum level)\n")); sl@0: return; sl@0: } sl@0: if (res.iUsage == TResInfo::ESingleUse) sl@0: { sl@0: test.Printf(_L("Not tested (Single-User resource already in use)\n")); sl@0: return; sl@0: } sl@0: } sl@0: // Define test values sl@0: TInt tstval[KTestMultiLevelValues]; sl@0: TInt i; sl@0: for (i = 0; i < KTestMultiLevelValues; i++) sl@0: { sl@0: if (levelowner == KTestResourceNotInUse) sl@0: { sl@0: // If resource is not in use, we can use the entire state range sl@0: tstval[i] = res.iMinLevel + i * (res.iMaxLevel - res.iMinLevel) / (KTestMultiLevelValues - 1); sl@0: } sl@0: else sl@0: { sl@0: // Or else we are limited to the Current State-MaxLevel range sl@0: tstval[i] = state + i * (res.iMaxLevel - state) / (KTestMultiLevelValues - 1); sl@0: } sl@0: } sl@0: test_Compare(tstval[0], !=, tstval[KTestMultiLevelValues - 1]); sl@0: // Test starts here sl@0: r = iTac1.Open(); sl@0: test_KErrNone(r); sl@0: r = iTac1.RegisterClient(KTestTac1); sl@0: test_KErrNone(r); sl@0: // sl@0: for (i = 0; i < KTestMultiLevelValues; i++) sl@0: { sl@0: r = iTac1.ChangeResourceState(res.iResourceId, tstval[i]); sl@0: test_KErrNone(r); sl@0: r = iToc.GetResourceState(res.iResourceId, state); sl@0: test_KErrNone(r); sl@0: // Resource state should be equal to the test value sl@0: // or to the first valid value that satisfies the request sl@0: if (res.iSense == TResInfo::EPositive) sl@0: { sl@0: test_Compare(state, >=, tstval[i]); sl@0: } sl@0: else sl@0: { sl@0: test_Compare(state, <=, tstval[i]); sl@0: } sl@0: test.Printf(_L(".")); sl@0: } sl@0: // sl@0: r = iTac1.DeRegisterClient(); sl@0: test_KErrNone(r); sl@0: iTac1.Close(); sl@0: test.Printf(_L("\n")); sl@0: } sl@0: sl@0: /* ---------------------------------------------------------------------------- sl@0: @SYMTestCaseID PBASE-PRMACCTST-LATENCY-0564 sl@0: @SYMTestCaseDesc Ensure instantaneous resource change state instantaneously sl@0: @SYMREQ REQ7751 sl@0: @SYMPREQ PREQ1398 sl@0: @SYMTestPriority High sl@0: @SYMTestActions sl@0: Pre-condition: sl@0: If in use, resource is not Single-User sl@0: If in use, resource state is not equal to max level sl@0: If in use, resource is not Custom Sense sl@0: For each Multi-Level resource: sl@0: 1. Register TAC1 sl@0: 2. TAC1 changes resource state to max value (async) sl@0: 3. Immediately afterwards, TAC1 gets resource state (sync) sl@0: 4. Wait for callback function sl@0: 5. TAC1 changes resource state to min value (async) sl@0: 6. Immediately afterwards, TAC1 gets resource state (sync) sl@0: 7. Wait for callback function sl@0: 8. De-register TAC1 sl@0: @SYMTestExpectedResults sl@0: 1. Client registered sl@0: 2. No error reported. sl@0: 3. If resource is Instantaneous Set, then the resource state is equal to sl@0: the new state. If Long Latency Set, then the state is either the old or sl@0: the new state. sl@0: 4. Callback function is called. sl@0: 5. No error reported. sl@0: 6. If resource is Instantaneous Set, then the resource state is equal to sl@0: the new state. If Long Latency Set, then the state is either the old or sl@0: the new state. sl@0: 7. Callback function is called. sl@0: 8. Client de-registered. sl@0: */ sl@0: sl@0: void CTestPrmAccTst::TestLatency(TInt aResourceNo) sl@0: { sl@0: test.Printf(_L("---Latency ")); sl@0: TResInfo& res = *((TResInfo*) iResources.Ptr() + aResourceNo); sl@0: // Test pre-conditions sl@0: if (res.iSense == TResInfo::ECustom) sl@0: { sl@0: test.Printf(_L("Not tested (Custom sense resource)\n")); sl@0: return; sl@0: } sl@0: TInt state; sl@0: TInt r = iToc.GetResourceState(res.iResourceId, state); sl@0: test_KErrNone(r); sl@0: TInt levelowner; sl@0: r = iToc.GetLevelOwner(res.iResourceId, levelowner); sl@0: test_KErrNone(r); sl@0: // sl@0: if (levelowner != KTestResourceNotInUse) sl@0: { sl@0: if (state == res.iMaxLevel) sl@0: { sl@0: test.Printf(_L("Not tested (Resource is already at maximum level)\n")); sl@0: return; sl@0: } sl@0: if (res.iUsage == TResInfo::ESingleUse) sl@0: { sl@0: test.Printf(_L("Not tested (Single-User resource already in use)\n")); sl@0: return; sl@0: } sl@0: } sl@0: // Define the two test values sl@0: TInt tstval1; sl@0: TInt tstval2; sl@0: if (levelowner != KTestResourceNotInUse) sl@0: { sl@0: // Resource in use sl@0: tstval1 = res.iMaxLevel; sl@0: tstval2 = state; sl@0: } sl@0: else sl@0: { sl@0: tstval1 = res.iMaxLevel; sl@0: tstval2 = res.iMinLevel; sl@0: } sl@0: // Test starts here sl@0: r = iTac1.Open(); sl@0: test_KErrNone(r); sl@0: r = iTac1.RegisterClient(KTestTac1); sl@0: test_KErrNone(r); sl@0: // sl@0: TTestResourceStateBuf buf; sl@0: buf().iResourceId = res.iResourceId; sl@0: buf().iNewState = tstval1; sl@0: TRequestStatus rs; sl@0: TInt tmpstate; sl@0: iTac1.ChangeResourceStateAndGetState(rs, buf, tmpstate); sl@0: User::WaitForRequest(rs); sl@0: test_KErrNone(rs.Int()); sl@0: if (res.iLatencySet == TResInfo::EInstantaneous) sl@0: { sl@0: test_Equal(tstval1, tmpstate); // Temp state is equal to the new state sl@0: } sl@0: else if (tmpstate != state) // Temp state is not necessarily equal to the new state sl@0: { sl@0: test_Equal(tstval1, tmpstate); sl@0: } sl@0: TInt newstate; sl@0: r = iToc.GetResourceState(res.iResourceId, newstate); sl@0: test_KErrNone(r); sl@0: test_Equal(tstval1, newstate); sl@0: // sl@0: buf().iNewState = tstval2; sl@0: iTac1.ChangeResourceStateAndGetState(rs, buf, tmpstate); sl@0: User::WaitForRequest(rs); sl@0: test_KErrNone(rs.Int()); sl@0: if (res.iLatencySet == TResInfo::EInstantaneous) sl@0: { sl@0: test_Equal(tstval2, tmpstate); // Temp state is equal to the new state sl@0: } sl@0: else if (tmpstate != tstval1) // Temp state is not necessarily equal to the new state sl@0: { sl@0: test_Equal(tstval2, tmpstate); sl@0: } sl@0: r = iToc.GetResourceState(res.iResourceId, newstate); sl@0: test_KErrNone(r); sl@0: test_Equal(tstval2, newstate); sl@0: // sl@0: r = iTac1.DeRegisterClient(); sl@0: test_KErrNone(r); sl@0: iTac1.Close(); sl@0: test.Printf(_L("\n")); sl@0: } sl@0: sl@0: /* ---------------------------------------------------------------------------- sl@0: @SYMTestCaseID PBASE-PRMACCTST-SENSE-0565 sl@0: @SYMTestCaseDesc Ensure Negative and Positive Sense resources behave as sl@0: expected sl@0: @SYMREQ REQ7751 sl@0: @SYMPREQ PREQ1398 sl@0: @SYMTestPriority High sl@0: @SYMTestActions sl@0: Pre-condition: sl@0: Resource is Shared sl@0: If in use, resource state is not equal to max level sl@0: For each Positive or Negative Sense resource: sl@0: 1. Register TOC, TAC1, TAC2 and TAC3 sl@0: 2. Define three distincts test values, s1, s2 and s3, that correspond to sl@0: actual resource states in the PSL. s1 and s3 are at opposite ends of sl@0: the range of states the resource can be set to. s2 is an intermediate sl@0: state. It might not always be possible to find a distinct value for s2 sl@0: (if the resource is binary or if its current use is limiting the number sl@0: of states the resource can be set to). In this case, s2 = s1. sl@0: 3. TAC1 sets resource state to s1 sl@0: 4. TAC2 sets resource state to s2 sl@0: 5. TAC3 sets resource state to s3 sl@0: 6. De-register TAC2 sl@0: 7. De-register TAC3 sl@0: 8. De-register TAC1 and register TAC1, TAC2 and TAC3 again. sl@0: 9. TAC1 sets resource state to s1 sl@0: 10. TAC3 sets resource state to s3 sl@0: 11. TAC2 sets resource state to s2 sl@0: 12. De-register TAC3. sl@0: 13. TAC3 sets resource state to s3 sl@0: 14. De-register TOC, TAC1, TAC2 and TAC3 sl@0: @SYMTestExpectedResults sl@0: 1. Clients registered sl@0: 2. s1 <= s2 < s3 sl@0: 3. Resource state set to s1 sl@0: 4. Resource state set to s2 sl@0: 5. Resource state set to s3 sl@0: 6. Resource state remains unchanged (TAC3 owns level) sl@0: 7. Resource state returns to s1 (TAC1 now owns level) sl@0: 8. Clients registered sl@0: 9. Resource state set to s1 sl@0: 10. Resource state set to s3 sl@0: 11. Resource state remains unchanged (TAC3 owns level) sl@0: 12. Resource state changes to s2 (TAC2 now owns level) sl@0: 13. Resource state set to s3 sl@0: 14. Clients de-registered sl@0: */ sl@0: sl@0: void CTestPrmAccTst::TestSense(TInt aResourceNo) sl@0: { sl@0: test.Printf(_L("---Sense ")); sl@0: TResInfo& res = *((TResInfo*) iResources.Ptr() + aResourceNo); sl@0: // Test pre-conditions sl@0: if (res.iUsage != TResInfo::EShared) sl@0: { sl@0: test.Printf(_L("Not tested: Resource is Single-User\n")); sl@0: return; sl@0: } sl@0: // sl@0: TInt state; sl@0: TInt r = iToc.GetResourceState(res.iResourceId, state); sl@0: test_KErrNone(r); sl@0: TInt levelowner; sl@0: r = iToc.GetLevelOwner(res.iResourceId, levelowner); sl@0: test_KErrNone(r); sl@0: // sl@0: if (levelowner != KTestResourceNotInUse && state == res.iMaxLevel) sl@0: { sl@0: test.Printf(_L("Not tested (Resource is already at maximum level)\n")); sl@0: return; sl@0: } sl@0: // Define three test values sl@0: r = iTac1.Open(); sl@0: test_KErrNone(r); sl@0: r = iTac1.RegisterClient(KTestTac1); sl@0: test_KErrNone(r); sl@0: TInt tstval1; sl@0: TInt tstval2; sl@0: TInt tstval3; sl@0: if (levelowner == KTestResourceNotInUse) sl@0: { sl@0: tstval1 = res.iMinLevel; sl@0: } sl@0: else sl@0: { sl@0: tstval1 = state; sl@0: } sl@0: tstval3 = res.iMaxLevel; sl@0: // Attempt to find a distinct intermediate value by dichotomy sl@0: tstval2 = tstval3; sl@0: while ((tstval2 - tstval1 < -1) || (tstval2 - tstval1 > 1)) sl@0: { sl@0: tstval2 -= (tstval2 - tstval1 + (res.iSense == TResInfo::EPositive ? 1 : 0)) / 2; sl@0: r = iTac1.ChangeResourceState(res.iResourceId, tstval2); sl@0: test_KErrNone(r); sl@0: r = iTac1.GetResourceState(res.iResourceId, state); sl@0: test_KErrNone(r); sl@0: } sl@0: if (state == tstval1 && res.iType == TResInfo::EMultiLevel) sl@0: { sl@0: test.Printf(_L("(Could not find three distincts test values)")); sl@0: } sl@0: tstval2 = state; sl@0: r = iTac1.DeRegisterClient(); sl@0: test_KErrNone(r); sl@0: iTac1.Close(); sl@0: sl@0: // Test starts here sl@0: r = iTac1.Open(); sl@0: test_KErrNone(r); sl@0: r = iTac2.Open(); sl@0: test_KErrNone(r); sl@0: r = iTac3.Open(); sl@0: test_KErrNone(r); sl@0: r = iTac1.RegisterClient(KTestTac1); sl@0: test_KErrNone(r); sl@0: r = iTac2.RegisterClient(KTestTac2); sl@0: test_KErrNone(r); sl@0: r = iTac3.RegisterClient(KTestTac3); sl@0: test_KErrNone(r); sl@0: sl@0: // Set resource state to the first test value sl@0: r = iTac1.ChangeResourceState(res.iResourceId, tstval1); sl@0: test_KErrNone(r); sl@0: r = iToc.GetResourceState(res.iResourceId, state); sl@0: test_KErrNone(r); sl@0: test_Equal(tstval1, state); sl@0: sl@0: // Set resource state to middle test value sl@0: r = iTac2.ChangeResourceState(res.iResourceId, tstval2); sl@0: test_KErrNone(r); sl@0: r = iToc.GetResourceState(res.iResourceId, state); sl@0: test_KErrNone(r); sl@0: test_Equal(tstval2, state); sl@0: sl@0: // Set resource to the third test value sl@0: r = iTac3.ChangeResourceState(res.iResourceId, tstval3); sl@0: test_KErrNone(r); sl@0: r = iToc.GetResourceState(res.iResourceId, state); sl@0: test_KErrNone(r); sl@0: test_Equal(tstval3, state); sl@0: sl@0: // De-register second client sl@0: r = iTac2.DeRegisterClient(); sl@0: test_KErrNone(r); sl@0: r = iToc.GetResourceState(res.iResourceId, state); sl@0: test_KErrNone(r); sl@0: test_Equal(tstval3, state); // state remains unchanged sl@0: sl@0: // De-register third client sl@0: r = iTac3.DeRegisterClient(); sl@0: test_KErrNone(r); sl@0: r = iToc.GetResourceState(res.iResourceId, state); sl@0: test_KErrNone(r); sl@0: test_Equal(tstval1, state); // state changes sl@0: sl@0: // De-register and register all clients again sl@0: r = iTac1.DeRegisterClient(); sl@0: test_KErrNone(r); sl@0: r = iTac1.RegisterClient(KTestTac1); sl@0: test_KErrNone(r); sl@0: r = iTac2.RegisterClient(KTestTac2); sl@0: test_KErrNone(r); sl@0: r = iTac3.RegisterClient(KTestTac3); sl@0: test_KErrNone(r); sl@0: sl@0: // Set resource state to the first test value sl@0: r = iTac1.ChangeResourceState(res.iResourceId, tstval1); sl@0: test_KErrNone(r); sl@0: r = iToc.GetResourceState(res.iResourceId, state); sl@0: test_KErrNone(r); sl@0: test_Equal(tstval1, state); sl@0: sl@0: // Set resource to the third test value sl@0: r = iTac3.ChangeResourceState(res.iResourceId, tstval3); sl@0: test_KErrNone(r); sl@0: r = iToc.GetResourceState(res.iResourceId, state); sl@0: test_KErrNone(r); sl@0: test_Equal(tstval3, state); sl@0: sl@0: // Set resource state to middle test value sl@0: r = iTac2.ChangeResourceState(res.iResourceId, tstval2); sl@0: test_KErrNone(r); sl@0: r = iToc.GetResourceState(res.iResourceId, state); sl@0: test_KErrNone(r); sl@0: test_Equal(tstval3, state); // state does not change sl@0: sl@0: // De-register client holding resource sl@0: r = iTac3.DeRegisterClient(); sl@0: test_KErrNone(r); sl@0: r = iToc.GetResourceState(res.iResourceId, state); sl@0: test_KErrNone(r); sl@0: test_Equal(tstval2, state); sl@0: sl@0: // Register client again sl@0: r = iTac3.RegisterClient(KTestTac3); sl@0: test_KErrNone(r); sl@0: r = iTac3.ChangeResourceState(res.iResourceId, tstval3); sl@0: test_KErrNone(r); sl@0: r = iToc.GetResourceState(res.iResourceId, state); sl@0: test_KErrNone(r); sl@0: test_Equal(tstval3, state); sl@0: sl@0: // sl@0: r = iTac3.DeRegisterClient(); sl@0: test_KErrNone(r); sl@0: r = iTac2.DeRegisterClient(); sl@0: test_KErrNone(r); sl@0: r = iTac1.DeRegisterClient(); sl@0: test_KErrNone(r); sl@0: iTac3.Close(); sl@0: iTac2.Close(); sl@0: iTac1.Close(); sl@0: test.Printf(_L("\n")); sl@0: } sl@0: sl@0: /* ---------------------------------------------------------------------------- sl@0: @SYMTestCaseID PBASE-PRMACCTST-CUSTOMSENSE-0566 sl@0: @SYMTestCaseDesc Ensure the Custom Sense function is implemented sl@0: @SYMREQ REQ7751 sl@0: @SYMPREQ PREQ1398 sl@0: @SYMTestPriority High sl@0: @SYMTestActions sl@0: For each Custom Sense resource: sl@0: 1. Register TAC1 sl@0: 2. Attempt to set the state of the resource to its current state. The sl@0: purpose of this test action is to ensure that the PSL's custom function sl@0: for this resource has been implemented. If the custom function is not sl@0: present, the PIL will generate a panic. sl@0: 3. De-register TAC1 sl@0: @SYMTestExpectedResults sl@0: 1. Client registered sl@0: 2. The resource change request does not cause a panic. sl@0: 3. Client de-registered sl@0: */ sl@0: sl@0: void CTestPrmAccTst::TestCustomSense(TInt aResourceNo) sl@0: { sl@0: test.Printf(_L("---Custom Sense")); sl@0: TResInfo& res = *((TResInfo*) iResources.Ptr() + aResourceNo); sl@0: TInt r = iTac1.Open(); sl@0: test_KErrNone(r); sl@0: r = iTac1.RegisterClient(KTestTac1); sl@0: test_KErrNone(r); sl@0: // sl@0: TInt state; sl@0: r = iTac1.GetResourceState(res.iResourceId, state); sl@0: test_KErrNone(r); sl@0: r = iTac1.ChangeResourceState(res.iResourceId, state); sl@0: test_KErrNone(r); sl@0: // sl@0: r = iTac1.DeRegisterClient(); sl@0: test_KErrNone(r); sl@0: iTac1.Close(); sl@0: test.Printf(_L("\n")); sl@0: } sl@0: sl@0: /* ---------------------------------------------------------------------------- sl@0: @SYMTestCaseID PBASE-PRMACCTST-POWERRESUMPTION-0567 sl@0: @SYMTestCaseDesc Ensure resources go back to their default state when not in sl@0: use sl@0: @SYMREQ REQ7751 sl@0: @SYMPREQ PREQ1398 sl@0: @SYMTestPriority High sl@0: @SYMTestActions sl@0: Pre-condition: sl@0: Resource not in use sl@0: Not a Custom Sense resource sl@0: For each resource: sl@0: 1. Register TAC1 sl@0: 2. Set resource state to something that is not the default level sl@0: 3. De-register TAC1 sl@0: 4. Register TOC sl@0: 5. Get resource state sl@0: 6. De-register TOC sl@0: @SYMTestExpectedResults sl@0: 1. Client registered sl@0: 2. Resource state changed sl@0: 3. Client de-registered sl@0: 4. Client registered sl@0: 5. Resource state is at the default level sl@0: 6. Client de-registered sl@0: */ sl@0: sl@0: void CTestPrmAccTst::TestDefaultPowerResumption() sl@0: { sl@0: TInt i; sl@0: for (i = 0; i < (TInt) iNoResources; i++) sl@0: { sl@0: TResInfo& res = *((TResInfo*) iResources.Ptr() + i); sl@0: test.Printf(_L("Resource %08x "), res.iResourceId); sl@0: TInt levelowner; sl@0: TInt r = iToc.GetLevelOwner(res.iResourceId, levelowner); sl@0: test_KErrNone(r); sl@0: sl@0: // Test pre-condition: resource not in use sl@0: if (levelowner != KTestResourceNotInUse) sl@0: { sl@0: test.Printf(_L("Not tested (already in use)\n")); sl@0: continue; sl@0: } sl@0: if (res.iSense == TResInfo::ECustom) sl@0: { sl@0: test.Printf(_L("Not tested (custom sense)\n")); sl@0: continue; sl@0: } sl@0: sl@0: // Define a test value sl@0: TInt tstval; sl@0: if (res.iDefaultLevel == res.iMaxLevel) sl@0: { sl@0: tstval = res.iMinLevel; sl@0: } sl@0: else sl@0: { sl@0: tstval = res.iMaxLevel; sl@0: } sl@0: sl@0: // Test starts here sl@0: r = iTac1.Open(); sl@0: test_KErrNone(r); sl@0: r = iTac1.RegisterClient(KTestTac1); sl@0: test_KErrNone(r); sl@0: // Change resource state sl@0: TInt state; sl@0: r = iToc.GetResourceState(res.iResourceId, state); sl@0: test_KErrNone(r); sl@0: test_Equal(res.iDefaultLevel, state); sl@0: r = iTac1.ChangeResourceState(res.iResourceId, tstval); sl@0: test_KErrNone(r); sl@0: r = iToc.GetResourceState(res.iResourceId, state); sl@0: test_KErrNone(r); sl@0: test_Equal(tstval, state); sl@0: // De-register active client so resource is freed sl@0: r = iTac1.DeRegisterClient(); sl@0: test_KErrNone(r); sl@0: iTac1.Close(); sl@0: // Read both cached and actual values sl@0: TInt cached; sl@0: r = iToc.GetResourceStateCached(res.iResourceId, cached); sl@0: test_KErrNone(r); sl@0: r = iToc.GetResourceState(res.iResourceId, state); sl@0: test_KErrNone(r); sl@0: test_Equal(cached, state); sl@0: test_Equal(res.iDefaultLevel, state); sl@0: test.Printf(_L("\n")); sl@0: } sl@0: // sl@0: test.Printf(_L("\n")); sl@0: } sl@0: sl@0: /* ---------------------------------------------------------------------------- sl@0: @SYMTestCaseID PBASE-PRMACCTST-DEPENDENCIESDECLARED-0568 sl@0: @SYMTestCaseDesc Ensure all actual resources dependencies have been declared sl@0: @SYMREQ REQ7751 sl@0: @SYMPREQ PREQ1398 sl@0: @SYMTestPriority High sl@0: @SYMTestActions sl@0: Pre-condition: sl@0: Resource not in use sl@0: Not a Custom Sense resource sl@0: For each resource: sl@0: 1. Register TOC & TAC1 sl@0: 2. Get state of all resources sl@0: 3. Set the state of the resource under test state to something that is not sl@0: the default level sl@0: 4. Get state of all resource sl@0: 5. De-register TAC1 & TOC sl@0: @SYMTestExpectedResults sl@0: 1. Clients registered sl@0: 2. None sl@0: 3. Resource state changed sl@0: 4. Only resources with a direct or indirect dependency on the resource sl@0: under test have changed. sl@0: 5. Client de-registered sl@0: */ sl@0: sl@0: TBool CTestPrmAccTst::ResourceInterdependency(TInt aResourceIdOrig, TInt aCurrentResourceId, TInt aResourceIdTarget) sl@0: { sl@0: // Get Reference on current resource node sl@0: TBool r = EFalse; sl@0: if (aCurrentResourceId & KTestIdHasDependencies) sl@0: { sl@0: // Get dependencies of current resources sl@0: RBuf8 deplist; sl@0: deplist.Create(sizeof(SResDepInfo) * KTestMaxDependencies); sl@0: r = iToc.GetResourceDependencies(aCurrentResourceId, deplist); sl@0: if (r) sl@0: { sl@0: test.Printf(_L("ERROR: aCurrentResourceId==%08x"), aCurrentResourceId); sl@0: test_KErrNone(r); sl@0: } sl@0: TInt i; sl@0: SResDepInfo *ptr = (SResDepInfo*)deplist.Ptr(); sl@0: for (i = 0; i < (TInt) (deplist.Length() / sizeof(SResDepInfo)); i++, ptr++) sl@0: { sl@0: TInt depid = ptr->iResourceId; sl@0: if (depid == aResourceIdTarget) sl@0: { sl@0: // We've got a match sl@0: r = ETrue; sl@0: } sl@0: else if (depid == aResourceIdOrig) sl@0: { sl@0: // No going back to parent node sl@0: continue; sl@0: } sl@0: else sl@0: { sl@0: // Recurse down the tree sl@0: r = ResourceInterdependency(aCurrentResourceId, depid, aResourceIdTarget); sl@0: } sl@0: if (r) sl@0: { sl@0: break; sl@0: } sl@0: } sl@0: deplist.Close(); sl@0: } sl@0: return r; sl@0: } sl@0: sl@0: void CTestPrmAccTst::TestDependenciesAreDeclared(TInt aResourceNo) sl@0: { sl@0: test.Printf(_L("---Test all dependencies are declared\n")); sl@0: TResInfo& res = *((TResInfo*) iResources.Ptr() + aResourceNo); sl@0: // sl@0: TInt levelowner; sl@0: TInt r = iToc.GetLevelOwner(res.iResourceId, levelowner); sl@0: test_KErrNone(r); sl@0: // Test pre-condition: resource not in use sl@0: if (levelowner != KTestResourceNotInUse) sl@0: { sl@0: test.Printf(_L("Not tested (already in use)\n")); sl@0: return; sl@0: } sl@0: if (res.iSense == TResInfo::ECustom) sl@0: { sl@0: test.Printf(_L("Not tested (custom sense)\n")); sl@0: return; sl@0: } sl@0: // Define a test value sl@0: TInt tstval; sl@0: if (res.iDefaultLevel == res.iMaxLevel) sl@0: { sl@0: tstval = res.iMinLevel; sl@0: } sl@0: else sl@0: { sl@0: tstval = res.iMaxLevel; sl@0: } sl@0: sl@0: // Test starts here sl@0: // Save current state of all resources; sl@0: RArray oldstate; sl@0: TInt i; sl@0: TInt state; sl@0: for (i = 0; i < (TInt) iNoResources; i++) sl@0: { sl@0: TResInfo& tmpres = *((TResInfo*) iResources.Ptr() + i); sl@0: r = iToc.GetResourceState(tmpres.iResourceId, state); sl@0: test_KErrNone(r); sl@0: r = oldstate.Append(state); sl@0: test_KErrNone(r); sl@0: } sl@0: // sl@0: r = iTac1.Open(); sl@0: test_KErrNone(r); sl@0: r = iTac1.RegisterClient(KTestTac1); sl@0: test_KErrNone(r); sl@0: sl@0: // Change resource state sl@0: r = iToc.GetResourceState(res.iResourceId, state); sl@0: test_KErrNone(r); sl@0: test_Equal(res.iDefaultLevel, state); sl@0: r = iTac1.ChangeResourceState(res.iResourceId, tstval); sl@0: test_KErrNone(r); sl@0: r = iToc.GetResourceState(res.iResourceId, state); sl@0: test_KErrNone(r); sl@0: test_Equal(tstval, state); sl@0: sl@0: // Now we check that resources with no dependency on resource under test sl@0: // have not changed sl@0: for (i = 0; i < (TInt) iNoResources; i++) sl@0: { sl@0: test.Printf(_L(".")); sl@0: if (i == aResourceNo) sl@0: { sl@0: continue; sl@0: } sl@0: TResInfo& tmpres = *((TResInfo*) iResources.Ptr() + i); sl@0: r = iToc.GetResourceState(tmpres.iResourceId, state); sl@0: test_KErrNone(r); sl@0: if (!ResourceInterdependency(0, res.iResourceId, tmpres.iResourceId) && sl@0: (state != oldstate[i])) sl@0: { sl@0: test.Printf(_L("Resource %08x has changed!\n"), tmpres.iResourceId); sl@0: test_Equal(state, oldstate[i]); sl@0: } sl@0: } sl@0: test.Printf(_L("\n")); sl@0: sl@0: // De-register active client sl@0: r = iTac1.DeRegisterClient(); sl@0: test_KErrNone(r); sl@0: iTac1.Close(); sl@0: // sl@0: oldstate.Close(); sl@0: } sl@0: sl@0: TInt CTestPrmAccTst::DoTestPreamble() sl@0: { sl@0: test.Title(); sl@0: test.Start(_L("Preamble")); sl@0: sl@0: // Load Device Driver sl@0: TInt r; sl@0: #ifdef RESOURCE_MANAGER_SIMULATED_PSL sl@0: test.Printf(_L("Load Simulated PSL PDD\n")); sl@0: r = User::LoadPhysicalDevice(_L("RESOURCECONTROLLEREXTENDED.PDD")); sl@0: if (r == KErrNotFound) sl@0: { sl@0: test.Printf(_L("RESOURCECONTROLLEREXTENDED.PDD not found\nTest skipped\n")); sl@0: return r; sl@0: } sl@0: if (r) sl@0: { sl@0: test_Equal(KErrAlreadyExists, r); sl@0: test.Printf(_L("Already loaded\n")); sl@0: } sl@0: test.Printf(_L("Load test LDD\n")); sl@0: r = User::LoadLogicalDevice(_L("D_PRMACCTSTSIM.LDD")); sl@0: if (r) sl@0: { sl@0: test_Equal(KErrAlreadyExists, r); sl@0: test.Printf(_L("Already loaded\n")); sl@0: } sl@0: #else sl@0: test.Printf(_L("Load test LDD\n")); sl@0: r = User::LoadLogicalDevice(_L("D_PRMACCTST.LDD")); sl@0: if (r) sl@0: { sl@0: test_Equal(KErrAlreadyExists, r); sl@0: test.Printf(_L("Already loaded\n")); sl@0: } sl@0: #endif // RESOURCE_MANAGER_SIMULATED_PSL sl@0: sl@0: // Check if Device Driver was loaded as a Kernel Extension sl@0: iKextc.Open(); sl@0: TUint clientId; sl@0: r = iKextc.GetKernelExtClientId(clientId); sl@0: test_KErrNone(r); sl@0: if (!clientId) sl@0: { sl@0: test.Printf(_L("No Kernel extension PRM client\n")); sl@0: iKextc.Close(); sl@0: } sl@0: else sl@0: { sl@0: // De-register client so Single User resources can be tested sl@0: r = iKextc.OpenClient(clientId); sl@0: test_KErrNone(r); sl@0: r = iKextc.DeRegisterClient(); sl@0: test_KErrNone(r); sl@0: iKextc.Close(); sl@0: } sl@0: sl@0: // Register TOC (always on - de-registered in test postamble) sl@0: r = iToc.Open(); sl@0: test_KErrNone(r); sl@0: r = iToc.RegisterClient(KTestToc); sl@0: test_KErrNone(r); sl@0: sl@0: // Get resources info sl@0: r = iToc.GetTotalNumberOfResources(iNoResources); sl@0: test_KErrNone(r); sl@0: test.Printf(_L("Resources found: %d\n"), iNoResources); sl@0: if (iNoResources > 0) sl@0: { sl@0: r = iResources.Create(iNoResources * sizeof(TResInfo)); sl@0: test_KErrNone(r); sl@0: test.Printf(_L("Retrieving information on resources\n")); sl@0: r = iToc.GetInfoOnResourcesInUseByClient(0, iResources); sl@0: test_KErrNone(r); sl@0: iIsPrmSupported = ETrue; sl@0: } sl@0: else sl@0: { sl@0: test.Printf(_L("No resource found.\n")); sl@0: } sl@0: return KErrNone; sl@0: } sl@0: sl@0: void CTestPrmAccTst::DoTest() sl@0: { sl@0: if (!iIsPrmSupported) sl@0: { sl@0: return; sl@0: } sl@0: // sl@0: test.Next(_L("Enumerate Resources")); sl@0: TestEnumerateResources(); sl@0: // sl@0: TInt i; sl@0: test.Next(_L("Resource Properties")); sl@0: for (i = 0; i < (TInt) iNoResources; i++) sl@0: { sl@0: TResInfo& res = *((TResInfo*) iResources.Ptr() + i); sl@0: test.Printf(_L("+++Resource %08x\n"), res.iResourceId); sl@0: // sl@0: if (res.iUsage == TResInfo::ESingleUse) sl@0: { sl@0: TestSingleUserResources(i); sl@0: } sl@0: else if (res.iUsage == TResInfo::EShared) sl@0: { sl@0: TestSharedResources(i); sl@0: } sl@0: // sl@0: if (res.iType == TResInfo::EBinary) sl@0: { sl@0: TestBinaryResources(i); sl@0: } sl@0: else if (res.iType == TResInfo::EMultiLevel) sl@0: { sl@0: TestMultilevelResources(i); sl@0: } sl@0: // sl@0: TestLatency(i); sl@0: // sl@0: if ((res.iSense == TResInfo::EPositive) || (res.iSense == TResInfo::ENegative)) sl@0: { sl@0: TestSense(i); sl@0: } sl@0: else if (res.iSense == TResInfo::ECustom) sl@0: { sl@0: TestCustomSense(i); sl@0: } sl@0: } sl@0: // sl@0: test.Next(_L("Default Power Resumption")); sl@0: TestDefaultPowerResumption(); sl@0: // sl@0: test.Next(_L("PRM Extension - Dependencies")); sl@0: for (i = 0; i < (TInt) iNoResources; i++) sl@0: { sl@0: TResInfo& res = *((TResInfo*) iResources.Ptr() + i); sl@0: if (res.iResourceId & KTestIdHasDependencies) sl@0: { sl@0: test.Printf(_L("+++Resource %08x\n"), res.iResourceId); sl@0: TestDependenciesAreDeclared(i); sl@0: } sl@0: } sl@0: } sl@0: sl@0: void CTestPrmAccTst::DoTestPostamble() sl@0: { sl@0: test.Next(_L("Postamble")); sl@0: if (iToc.Handle()) sl@0: { sl@0: TInt r = iToc.DeRegisterClient(); sl@0: test_KErrNone(r); sl@0: iToc.Close(); sl@0: } sl@0: test.End(); sl@0: test.Close(); sl@0: } sl@0: sl@0: GLDEF_C TInt MainL() sl@0: { sl@0: CTestPrmAccTst* testapp; sl@0: testapp = new (ELeave) CTestPrmAccTst(); sl@0: CleanupStack::PushL(testapp); sl@0: if (testapp->DoTestPreamble() == KErrNone) sl@0: { sl@0: testapp->DoTest(); sl@0: } sl@0: testapp->DoTestPostamble(); sl@0: CleanupStack::PopAndDestroy(testapp); sl@0: return KErrNone; sl@0: } sl@0: sl@0: GLDEF_C TInt E32Main() sl@0: { sl@0: __UHEAP_MARK; sl@0: CTrapCleanup* cleanup = CTrapCleanup::New(); sl@0: if(cleanup == NULL) sl@0: { sl@0: return KErrNoMemory; sl@0: } sl@0: TRAP_IGNORE(MainL()); sl@0: delete cleanup; sl@0: __UHEAP_MARKEND; sl@0: return KErrNone; sl@0: }