1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/resourceman/acctst/t_prmacctst.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,1518 @@
1.4 +// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#define __E32TEST_EXTENSION__
1.20 +#include <e32test.h>
1.21 +#include "d_prmacctst.h"
1.22 +
1.23 +_LIT8(KTestToc, "TOC");
1.24 +_LIT8(KTestTac1, "TAC1");
1.25 +_LIT8(KTestTac2, "TAC2");
1.26 +_LIT8(KTestTac3, "TAC3");
1.27 +
1.28 +// The number of test values for multi-level resources
1.29 +static const TInt KTestMultiLevelValues = 10;
1.30 +
1.31 +// Bit 16 in the resource ID indicates that the resource has dependencies
1.32 +static const TUint32 KTestIdHasDependencies = 0x00010000;
1.33 +static const TInt KTestMaxDependencies = 256;
1.34 +
1.35 +static const TInt KTestResourceNotInUse = -1;
1.36 +
1.37 +// structure for holding ResId and ResPrty
1.38 +struct SResDepInfo
1.39 + {
1.40 + TUint iResourceId;
1.41 + TUint8 iDependencyPriority;
1.42 + };
1.43 +class CTestPrmAccTst : public CBase
1.44 + {
1.45 +public:
1.46 + CTestPrmAccTst();
1.47 + ~CTestPrmAccTst();
1.48 + TInt DoTestPreamble();
1.49 + void DoTest();
1.50 + void DoTestPostamble();
1.51 +protected:
1.52 + TBool ResourceInterdependency(TInt aResourceIdOrig, TInt aCurrentResourceId, TInt aResourceIdTarget);
1.53 + void TestEnumerateResources();
1.54 + void TestSingleUserResources(TInt aResourceNo);
1.55 + void TestSharedResources(TInt aResourceNo);
1.56 + void TestBinaryResources(TInt aResourceNo);
1.57 + void TestMultilevelResources(TInt aResourceNo);
1.58 + void TestLatency(TInt aResourceNo);
1.59 + void TestSense(TInt aResourceNo);
1.60 + void TestCustomSense(TInt aResourceNo);
1.61 + void TestDefaultPowerResumption();
1.62 + void TestDependenciesAreDeclared(TInt aResourceNo);
1.63 +private:
1.64 + enum TBinary
1.65 + {
1.66 + EBinaryOff = 0,
1.67 + EBinaryOn = 1
1.68 + };
1.69 +protected:
1.70 + RTest test;
1.71 +private:
1.72 + // The test PRM clients
1.73 + RPrmIf iToc; // Test Observer Client (never owns any resource)
1.74 + RPrmIf iTac1; // Active clients...
1.75 + RPrmIf iTac2;
1.76 + RPrmIf iTac3;
1.77 + RPrmIf iKextc; // The Kernel Extension Client (owns Single User Resources)
1.78 + //
1.79 + TBool iIsPrmSupported;
1.80 + //
1.81 + RBuf8 iResources;
1.82 + TUint iNoResources;
1.83 + //
1.84 + static CTestPrmAccTst* iSingletonInstance;
1.85 + };
1.86 +
1.87 +CTestPrmAccTst::CTestPrmAccTst()
1.88 + :test(_L("T_PRMACCTST")),
1.89 + iIsPrmSupported(EFalse),
1.90 + iNoResources(0)
1.91 + {
1.92 + }
1.93 +
1.94 +CTestPrmAccTst::~CTestPrmAccTst()
1.95 + {
1.96 + iResources.Close();
1.97 + TInt r = User::FreeLogicalDevice(KPrmIfLddName);
1.98 + test(r==KErrNone);
1.99 +#ifdef RESOURCE_MANAGER_SIMULATED_PSL
1.100 + r = User::FreePhysicalDevice(_L("resourcecontrollerextended.pdd"));
1.101 + test(r==KErrNone);
1.102 +#endif
1.103 + User::After(100000);
1.104 + }
1.105 +
1.106 +/* ----------------------------------------------------------------------------
1.107 +@SYMTestCaseID PBASE-PRMACCTST-ENUMRES-0559
1.108 +@SYMTestCaseDesc Ensure current resource state of PRM is correctly listed
1.109 +@SYMREQ REQ7751
1.110 +@SYMPREQ PREQ1398
1.111 +@SYMTestPriority Critical
1.112 +@SYMTestActions
1.113 + 1. Display all resources and their properties
1.114 + 2. Ensure the resource state range is coherent
1.115 +@SYMTestExpectedResults
1.116 + 1. All resources are shown with the correct properties
1.117 + 2. Min <= Default <= Max and Min < Max if Negative Sense
1.118 + Min >= Default >= Max and Max > Min if Positive Sense
1.119 + Binary resources states are '0' or '1'
1.120 +*/
1.121 +
1.122 +void CTestPrmAccTst::TestEnumerateResources()
1.123 + {
1.124 + test.Printf(_L("Id Resource name C LG LS T U S DefltLvl MinLevel MaxLevel\n"));
1.125 + test.Printf(_L("--------+--------------------------------+-+--+--+--+--+-+--------+--------+--------\n"));
1.126 + TInt i;
1.127 + for (i = 0; i < (TInt) iNoResources; i++)
1.128 + {
1.129 + TResInfo& res = *((TResInfo*) iResources.Ptr() + i);
1.130 +
1.131 + // Display properties
1.132 + test.Printf(_L("%08x "), res.iResourceId);
1.133 + test_Compare(res.iResourceName->Length(), <=, KNameMaxLength);
1.134 + TBuf<KNameMaxLength> tmp;
1.135 + tmp.Copy(*res.iResourceName);
1.136 + test.Printf(_L("%-.32S "), &tmp);
1.137 + //
1.138 + if (res.iClass == TResInfo::EPhysical)
1.139 + {
1.140 + test.Printf(_L("P "));
1.141 + }
1.142 + else if (res.iClass == TResInfo::ELogical)
1.143 + {
1.144 + test.Printf(_L("L "));
1.145 + }
1.146 + else
1.147 + {
1.148 + test(EFalse);
1.149 + }
1.150 + //
1.151 + if (res.iLatencyGet == TResInfo::EInstantaneous)
1.152 + {
1.153 + test.Printf(_L("In "));
1.154 + }
1.155 + else if (res.iLatencyGet == TResInfo::ELongLatency)
1.156 + {
1.157 + test.Printf(_L("Lo "));
1.158 + }
1.159 + else
1.160 + {
1.161 + test(EFalse);
1.162 + }
1.163 + //
1.164 + if (res.iLatencySet == TResInfo::EInstantaneous)
1.165 + {
1.166 + test.Printf(_L("In "));
1.167 + }
1.168 + else if (res.iLatencySet == TResInfo::ELongLatency)
1.169 + {
1.170 + test.Printf(_L("Lo "));
1.171 + }
1.172 + else
1.173 + {
1.174 + test(EFalse);
1.175 + }
1.176 + //
1.177 + if (res.iType == TResInfo::EBinary)
1.178 + {
1.179 + test.Printf(_L("B "));
1.180 + }
1.181 + else if (res.iType == TResInfo::EMultiLevel)
1.182 + {
1.183 + test.Printf(_L("ML "));
1.184 + }
1.185 + else if (res.iType == TResInfo::EMultiProperty)
1.186 + {
1.187 + test.Printf(_L("MP "));
1.188 + }
1.189 + else
1.190 + {
1.191 + test(EFalse);
1.192 + }
1.193 + //
1.194 + if (res.iUsage == TResInfo::ESingleUse)
1.195 + {
1.196 + test.Printf(_L("SU "));
1.197 + }
1.198 + else if (res.iUsage == TResInfo::EShared)
1.199 + {
1.200 + test.Printf(_L("Sh "));
1.201 + }
1.202 + else
1.203 + {
1.204 + test(EFalse);
1.205 + }
1.206 + //
1.207 + if (res.iSense == TResInfo::EPositive)
1.208 + {
1.209 + test.Printf(_L("+ "));
1.210 + }
1.211 + else if (res.iSense == TResInfo::ENegative)
1.212 + {
1.213 + test.Printf(_L("- "));
1.214 + }
1.215 + else if (res.iSense == TResInfo::ECustom)
1.216 + {
1.217 + test.Printf(_L("C "));
1.218 + }
1.219 + else
1.220 + {
1.221 + test(EFalse);
1.222 + }
1.223 + //
1.224 + test.Printf(_L("%08x "), res.iDefaultLevel);
1.225 + test.Printf(_L("%08x "), res.iMinLevel);
1.226 + test.Printf(_L("%08x\n"), res.iMaxLevel);
1.227 +
1.228 + // Retrieve resource dependencies
1.229 + if (res.iResourceId & KTestIdHasDependencies)
1.230 + {
1.231 + RBuf8 deplist;
1.232 + deplist.Create(sizeof(SResDepInfo) * KTestMaxDependencies);
1.233 + iToc.GetResourceDependencies(res.iResourceId, deplist);
1.234 + TInt j;
1.235 + test.Printf(_L(" Direct Dependencies:"));
1.236 + SResDepInfo* ptr = (SResDepInfo*)deplist.Ptr();
1.237 + for (j = 0; j < (TInt) (deplist.Length() / sizeof(SResDepInfo)); j++, ptr++)
1.238 + {
1.239 + test.Printf(_L("ResourceId: %08x"), ptr->iResourceId);
1.240 + test.Printf(_L("Resource Priority: %08x"), ptr->iDependencyPriority);
1.241 + }
1.242 + test.Printf(_L("\n"));
1.243 + deplist.Close();
1.244 + }
1.245 + test.Printf(_L("C:Class,P:Physical,L:Logical"));
1.246 + test.Printf(_L("LG/LS:Latency Get/Set,In:Instantaneous,Lo:Long Latency"));
1.247 + test.Printf(_L("T:Type,MP:Multiproperty,ML:Multilevel,B:Binary"));
1.248 + test.Printf(_L("U:Usage,SU:Single-User,Sh:Shared"));
1.249 + test.Printf(_L("S:Sense,+:Positive,-:Negative,C:Custom"));
1.250 +
1.251 + // Ensure the state range of the resource does not contradict its properties
1.252 + if (res.iType == TResInfo::EBinary)
1.253 + {
1.254 + if (res.iSense == TResInfo::EPositive)
1.255 + {
1.256 + test(res.iMinLevel == EBinaryOff);
1.257 + test(res.iMaxLevel == EBinaryOn);
1.258 + }
1.259 + else if (res.iSense == TResInfo::ENegative)
1.260 + {
1.261 + test(res.iMinLevel == EBinaryOn);
1.262 + test(res.iMaxLevel == EBinaryOff);
1.263 + }
1.264 + else if (res.iSense == TResInfo::ECustom)
1.265 + {
1.266 + test(res.iMinLevel == EBinaryOff || res.iMinLevel == EBinaryOn);
1.267 + test(res.iMaxLevel == EBinaryOff || res.iMaxLevel == EBinaryOn);
1.268 + test_Compare(res.iMinLevel, !=, res.iMaxLevel);
1.269 + }
1.270 + test((res.iDefaultLevel == EBinaryOff) || (res.iDefaultLevel == EBinaryOn));
1.271 + }
1.272 + // Level range must respect resource sense
1.273 + if (res.iSense == TResInfo::EPositive)
1.274 + {
1.275 + test_Compare(res.iMinLevel, <=, res.iMaxLevel);
1.276 + test_Compare(res.iMinLevel, <=, res.iDefaultLevel);
1.277 + test_Compare(res.iDefaultLevel, <=, res.iMaxLevel);
1.278 + test_Compare(res.iMinLevel, <, res.iMaxLevel);
1.279 + }
1.280 + else if (res.iSense == TResInfo::ENegative)
1.281 + {
1.282 + test_Compare(res.iMinLevel, >=, res.iMaxLevel);
1.283 + test_Compare(res.iMinLevel, >=, res.iDefaultLevel);
1.284 + test_Compare(res.iDefaultLevel, >=, res.iMaxLevel);
1.285 + test_Compare(res.iMinLevel, >, res.iMaxLevel);
1.286 + }
1.287 + }
1.288 + }
1.289 +
1.290 +/* ----------------------------------------------------------------------------
1.291 +@SYMTestCaseID PBASE-PRMACCTST-SINGLEUSER-0560
1.292 +@SYMTestCaseDesc Ensure Single User resources can only be used by one client
1.293 + at a time
1.294 +@SYMREQ REQ7751
1.295 +@SYMPREQ PREQ1398
1.296 +@SYMTestPriority High
1.297 +@SYMTestActions
1.298 +Pre-condition:
1.299 + The resource is not in use
1.300 +For each Single User resource:
1.301 + 1. Register TAC1 & TAC2
1.302 + 2. TAC1 changes resource state
1.303 + 3. TAC2 changes resource state
1.304 + 4. De-register TAC1
1.305 + ---
1.306 + 5. Register TAC1
1.307 + 6. TAC2 changes resource state
1.308 + 7. TAC1 changes resource state
1.309 + 8. De-register TAC1 & TAC2
1.310 +@SYMTestExpectedResults
1.311 + 1. Clients registered
1.312 + 2. Resource state changed
1.313 + 3. KErrAccessDenied as there is already one registered client
1.314 + 4. Client de-registered
1.315 + ---
1.316 + 5. Client registered
1.317 + 6. Resource state changed
1.318 + 7. KErrAccessDenied as there is already one registered client
1.319 + 8. Both clients de-registered
1.320 +*/
1.321 +
1.322 +void CTestPrmAccTst::TestSingleUserResources(TInt aResourceNo)
1.323 + {
1.324 + test.Printf(_L("---Single-User "));
1.325 + TResInfo& res = *((TResInfo*) iResources.Ptr() + aResourceNo);
1.326 + // Test pre-condition: resource not in use
1.327 + TInt levelowner;
1.328 + TInt r = iToc.GetLevelOwner(res.iResourceId, levelowner);
1.329 + test_KErrNone(r);
1.330 + if (levelowner != KTestResourceNotInUse)
1.331 + {
1.332 + test.Printf(_L("Not tested (Single-User resource already in use)\n"));
1.333 + return;
1.334 + }
1.335 + // Define two test values
1.336 + TInt state;
1.337 + r = iToc.GetResourceState(res.iResourceId, state);
1.338 + test_KErrNone(r);
1.339 + //
1.340 + TInt tstval1;
1.341 + TInt tstval2;
1.342 + if (state == res.iMinLevel)
1.343 + {
1.344 + tstval1 = res.iMaxLevel;
1.345 + tstval2 = res.iMinLevel;
1.346 + }
1.347 + else
1.348 + {
1.349 + tstval1 = res.iMinLevel;
1.350 + tstval2 = res.iMaxLevel;
1.351 + }
1.352 + // Test starts here
1.353 + r = iTac1.Open();
1.354 + test_KErrNone(r);
1.355 + r = iTac2.Open();
1.356 + test_KErrNone(r);
1.357 + r = iTac1.RegisterClient(KTestTac1);
1.358 + test_KErrNone(r);
1.359 + r = iTac2.RegisterClient(KTestTac2);
1.360 + test_KErrNone(r);
1.361 + //
1.362 + r = iTac1.ChangeResourceState(res.iResourceId, tstval1);
1.363 + test_KErrNone(r);
1.364 + r = iTac1.GetResourceState(res.iResourceId, state);
1.365 + test_KErrNone(r);
1.366 + test_Equal(tstval1, state);
1.367 + r = iTac2.GetResourceState(res.iResourceId, state);
1.368 + test_KErrNone(r);
1.369 + test_Equal(tstval1, state);
1.370 + r = iTac2.ChangeResourceState(res.iResourceId, tstval2);
1.371 + test_Equal(KErrAccessDenied, r); // TAC2 cannot change the resource state
1.372 + //
1.373 + r = iTac1.DeRegisterClient();
1.374 + test_KErrNone(r);
1.375 + r = iTac1.RegisterClient(KTestTac1);
1.376 + test_KErrNone(r);
1.377 + r = iTac2.ChangeResourceState(res.iResourceId, tstval2);
1.378 + test_KErrNone(r);
1.379 + r = iTac1.GetResourceState(res.iResourceId, state);
1.380 + test_KErrNone(r); // TAC1 can still access the resource state...
1.381 + test_Equal(tstval2, state);
1.382 + r = iTac1.ChangeResourceState(res.iResourceId, tstval1);
1.383 + test_Equal(KErrAccessDenied, r); // ... but cannot change it
1.384 + r = iTac2.GetResourceState(res.iResourceId, state);
1.385 + test_KErrNone(r);
1.386 + test_Equal(tstval2, state); // The resource state remains unchanged indeed
1.387 + //
1.388 + r = iTac1.DeRegisterClient();
1.389 + test_KErrNone(r);
1.390 + r = iTac2.DeRegisterClient();
1.391 + test_KErrNone(r);
1.392 + iTac1.Close();
1.393 + iTac2.Close();
1.394 + test.Printf(_L("\n"));
1.395 + }
1.396 +
1.397 +/* ----------------------------------------------------------------------------
1.398 +@SYMTestCaseID PBASE-PRMACCTST-SHARED-0561
1.399 +@SYMTestCaseDesc Ensure a Shared Resources can be changed by several
1.400 + clients
1.401 +@SYMREQ REQ7751
1.402 +@SYMPREQ PREQ1398
1.403 +@SYMTestPriority High
1.404 +@SYMTestActions
1.405 +Pre-conditions:
1.406 + If in use, resource state is not equal to max level
1.407 + Resource is not Custom Sense
1.408 +For each Shared resource:
1.409 + 1. Register TOC, TAC1 & TAC2
1.410 + 2. TAC1 changes resource state to level1
1.411 + 3. TAC2 changes resource state to level2
1.412 + 4. TAC2 changes resource state to level1
1.413 + 5. TAC1 changes resource state to level2
1.414 + 6. De-register TOC, TAC1 & TAC2
1.415 +@SYMTestExpectedResults
1.416 + 1. Clients registered
1.417 + 2. Resource state changed
1.418 + 3. Resource state changed
1.419 + 4. Resource state changed
1.420 + 5. Resource state changed
1.421 + 6. Clients de-registered
1.422 +*/
1.423 +
1.424 +void CTestPrmAccTst::TestSharedResources(TInt aResourceNo)
1.425 + {
1.426 + test.Printf(_L("---Shared "));
1.427 + TResInfo& res = *((TResInfo*) iResources.Ptr() + aResourceNo);
1.428 + // Test pre-conditions
1.429 + if (res.iSense == TResInfo::ECustom)
1.430 + {
1.431 + test.Printf(_L("Not tested (Custom sense resource)\n"));
1.432 + return;
1.433 + }
1.434 + //
1.435 + TInt state;
1.436 + TInt r = iToc.GetResourceState(res.iResourceId, state);
1.437 + test_KErrNone(r);
1.438 + TInt levelowner;
1.439 + r = iToc.GetLevelOwner(res.iResourceId, levelowner);
1.440 + test_KErrNone(r);
1.441 + //
1.442 + if (levelowner != KTestResourceNotInUse && state == res.iMaxLevel)
1.443 + {
1.444 + test.Printf(_L("Not tested: Resource is already at maximum level\n"));
1.445 + return;
1.446 + }
1.447 + // Define two test values
1.448 + TInt tstval1;
1.449 + TInt tstval2;
1.450 + if (levelowner != KTestResourceNotInUse)
1.451 + {
1.452 + // Resource already in use
1.453 + tstval1 = state;
1.454 + tstval2 = res.iMaxLevel;
1.455 + }
1.456 + else
1.457 + {
1.458 + // Resource not in use
1.459 + tstval1 = res.iMinLevel;
1.460 + tstval2 = res.iMaxLevel;
1.461 + }
1.462 + // Test starts here
1.463 + r = iTac1.Open();
1.464 + test_KErrNone(r);
1.465 + r = iTac2.Open();
1.466 + test_KErrNone(r);
1.467 + r = iTac1.RegisterClient(KTestTac1);
1.468 + test_KErrNone(r);
1.469 + r = iTac2.RegisterClient(KTestTac2);
1.470 + test_KErrNone(r);
1.471 + //
1.472 + r = iTac1.ChangeResourceState(res.iResourceId, tstval1);
1.473 + test_KErrNone(r);
1.474 + r = iToc.GetResourceState(res.iResourceId, state);
1.475 + test_KErrNone(r);
1.476 + test_Equal(tstval1, state);
1.477 + //
1.478 + r = iTac2.ChangeResourceState(res.iResourceId, tstval2);
1.479 + test_KErrNone(r);
1.480 + r = iToc.GetResourceState(res.iResourceId, state);
1.481 + test_KErrNone(r);
1.482 + test_Equal(tstval2, state);
1.483 + //
1.484 + r = iTac2.ChangeResourceState(res.iResourceId, tstval1);
1.485 + test_KErrNone(r);
1.486 + r = iToc.GetResourceState(res.iResourceId, state);
1.487 + test_KErrNone(r);
1.488 + test_Equal(tstval1, state);
1.489 + //
1.490 + r = iTac1.ChangeResourceState(res.iResourceId, tstval2);
1.491 + test_KErrNone(r);
1.492 + r = iToc.GetResourceState(res.iResourceId, state);
1.493 + test_KErrNone(r);
1.494 + test_Equal(tstval2, state);
1.495 + //
1.496 + r = iTac1.DeRegisterClient();
1.497 + test_KErrNone(r);
1.498 + r = iTac2.DeRegisterClient();
1.499 + test_KErrNone(r);
1.500 + //
1.501 + iTac1.Close();
1.502 + iTac2.Close();
1.503 + test.Printf(_L("\n"));
1.504 + }
1.505 +
1.506 +/* ----------------------------------------------------------------------------
1.507 +@SYMTestCaseID PBASE-PRMACCTST-BINARY-0562
1.508 +@SYMTestCaseDesc Ensure Binary Resources function as expected
1.509 +@SYMREQ REQ7751
1.510 +@SYMPREQ PREQ1398
1.511 +@SYMTestPriority High
1.512 +@SYMTestActions
1.513 +Pre-conditions:
1.514 +Resource not in use, or...
1.515 + If Shared/Positive Sense, current resource must be off
1.516 + If Shared/Negative Sense, current resource must be on
1.517 +Resource is not Custom Sense
1.518 +For each Binary resource:
1.519 + 1. Register TAC1
1.520 + 2. Turn resource off and toggle resource state several times
1.521 + 3. De-register TAC1
1.522 +@SYMTestExpectedResults
1.523 + 1. Client registered
1.524 + 2. Resource state changes as expected
1.525 + 3. De-register TAC1
1.526 +*/
1.527 +
1.528 +void CTestPrmAccTst::TestBinaryResources(TInt aResourceNo)
1.529 + {
1.530 + test.Printf(_L("---Binary "));
1.531 + TResInfo& res = *((TResInfo*) iResources.Ptr() + aResourceNo);
1.532 + // Test pre-conditions
1.533 + if (res.iSense == TResInfo::ECustom)
1.534 + {
1.535 + test.Printf(_L("Not tested (Custom sense resource)\n"));
1.536 + return;
1.537 + }
1.538 + TInt state;
1.539 + TInt r = iToc.GetResourceState(res.iResourceId, state);
1.540 + test_KErrNone(r);
1.541 + TInt levelowner;
1.542 + r = iToc.GetLevelOwner(res.iResourceId, levelowner);
1.543 + test_KErrNone(r);
1.544 + //
1.545 + if (levelowner != KTestResourceNotInUse)
1.546 + {
1.547 + if (res.iUsage == TResInfo::ESingleUse)
1.548 + {
1.549 + test.Printf(_L("Not tested (Single-User resource already in use)\n"));
1.550 + return;
1.551 + }
1.552 + if (res.iSense == TResInfo::EPositive && state == EBinaryOn)
1.553 + {
1.554 + test.Printf(_L("Not tested (Positive sense resource is already on)\n"));
1.555 + return;
1.556 + }
1.557 + if (res.iSense == TResInfo::ENegative && state == EBinaryOff)
1.558 + {
1.559 + test.Printf(_L("Not tested (Negative sense resource is already off)\n"));
1.560 + return;
1.561 + }
1.562 + }
1.563 + // Test starts here
1.564 + r = iTac1.Open();
1.565 + test_KErrNone(r);
1.566 + r = iTac1.RegisterClient(KTestTac1);
1.567 + test_KErrNone(r);
1.568 +
1.569 + // Turn Resource off
1.570 + r = iTac1.ChangeResourceState(res.iResourceId, EBinaryOff);
1.571 + test_KErrNone(r);
1.572 + r = iToc.GetResourceState(res.iResourceId, state);
1.573 + test_KErrNone(r);
1.574 + test_Equal(EBinaryOff, state);
1.575 +
1.576 + // Turn it on
1.577 + r = iTac1.ChangeResourceState(res.iResourceId, EBinaryOn);
1.578 + test_KErrNone(r);
1.579 + r = iToc.GetResourceState(res.iResourceId, state);
1.580 + test_KErrNone(r);
1.581 + test_Equal(EBinaryOn, state);
1.582 +
1.583 + // Turn it off
1.584 + r = iTac1.ChangeResourceState(res.iResourceId, EBinaryOff);
1.585 + test_KErrNone(r);
1.586 + r = iToc.GetResourceState(res.iResourceId, state);
1.587 + test_KErrNone(r);
1.588 + test_Equal(EBinaryOff, state);
1.589 + //
1.590 + r = iTac1.DeRegisterClient();
1.591 + test_KErrNone(r);
1.592 + iTac1.Close();
1.593 + test.Printf(_L("\n"));
1.594 + }
1.595 +
1.596 +/* ----------------------------------------------------------------------------
1.597 +@SYMTestCaseID PBASE-PRMACCTST-MULTILEVEL-0563
1.598 +@SYMTestCaseDesc Ensure Multi-Level Resources function as expected
1.599 +@SYMREQ REQ7751
1.600 +@SYMPREQ PREQ1398
1.601 +@SYMTestPriority High
1.602 +@SYMTestActions
1.603 +Pre-condition:
1.604 + If in use, resource state is not equal to max level
1.605 + If in use, resource is not Single-User
1.606 + Resource is not Custom Sense
1.607 +For each Multi-Level resource:
1.608 + 1. Register TOC and TAC1
1.609 + 2. Define a number of gradually increasing (or decreasing if negative
1.610 + sense resource) test values across the range of valid states. Attempt
1.611 + to change the resource state to each of these values.
1.612 + 3. De-register TOC and TAC1
1.613 +@SYMTestExpectedResults
1.614 + 1. Clients registered
1.615 + 2. Resource state should be changed to the test value if this value is
1.616 + accepted by the PSL. If not, the resource state should be changed to
1.617 + the minimum valid value that satisfies this requirement.
1.618 + 3. Clients de-registered
1.619 +*/
1.620 +
1.621 +void CTestPrmAccTst::TestMultilevelResources(TInt aResourceNo)
1.622 + {
1.623 + test.Printf(_L("---Multi-level "));
1.624 + TResInfo& res = *((TResInfo*) iResources.Ptr() + aResourceNo);
1.625 + // Test pre-conditions
1.626 + if (res.iSense == TResInfo::ECustom)
1.627 + {
1.628 + test.Printf(_L("Not tested (Custom sense resource)\n"));
1.629 + return;
1.630 + }
1.631 + TInt state;
1.632 + TInt r = iToc.GetResourceState(res.iResourceId, state);
1.633 + test_KErrNone(r);
1.634 + TInt levelowner;
1.635 + r = iToc.GetLevelOwner(res.iResourceId, levelowner);
1.636 + test_KErrNone(r);
1.637 + //
1.638 + if (levelowner != KTestResourceNotInUse)
1.639 + {
1.640 + if (state == res.iMaxLevel)
1.641 + {
1.642 + test.Printf(_L("Not tested (Resource is already at maximum level)\n"));
1.643 + return;
1.644 + }
1.645 + if (res.iUsage == TResInfo::ESingleUse)
1.646 + {
1.647 + test.Printf(_L("Not tested (Single-User resource already in use)\n"));
1.648 + return;
1.649 + }
1.650 + }
1.651 + // Define test values
1.652 + TInt tstval[KTestMultiLevelValues];
1.653 + TInt i;
1.654 + for (i = 0; i < KTestMultiLevelValues; i++)
1.655 + {
1.656 + if (levelowner == KTestResourceNotInUse)
1.657 + {
1.658 + // If resource is not in use, we can use the entire state range
1.659 + tstval[i] = res.iMinLevel + i * (res.iMaxLevel - res.iMinLevel) / (KTestMultiLevelValues - 1);
1.660 + }
1.661 + else
1.662 + {
1.663 + // Or else we are limited to the Current State-MaxLevel range
1.664 + tstval[i] = state + i * (res.iMaxLevel - state) / (KTestMultiLevelValues - 1);
1.665 + }
1.666 + }
1.667 + test_Compare(tstval[0], !=, tstval[KTestMultiLevelValues - 1]);
1.668 + // Test starts here
1.669 + r = iTac1.Open();
1.670 + test_KErrNone(r);
1.671 + r = iTac1.RegisterClient(KTestTac1);
1.672 + test_KErrNone(r);
1.673 + //
1.674 + for (i = 0; i < KTestMultiLevelValues; i++)
1.675 + {
1.676 + r = iTac1.ChangeResourceState(res.iResourceId, tstval[i]);
1.677 + test_KErrNone(r);
1.678 + r = iToc.GetResourceState(res.iResourceId, state);
1.679 + test_KErrNone(r);
1.680 + // Resource state should be equal to the test value
1.681 + // or to the first valid value that satisfies the request
1.682 + if (res.iSense == TResInfo::EPositive)
1.683 + {
1.684 + test_Compare(state, >=, tstval[i]);
1.685 + }
1.686 + else
1.687 + {
1.688 + test_Compare(state, <=, tstval[i]);
1.689 + }
1.690 + test.Printf(_L("."));
1.691 + }
1.692 + //
1.693 + r = iTac1.DeRegisterClient();
1.694 + test_KErrNone(r);
1.695 + iTac1.Close();
1.696 + test.Printf(_L("\n"));
1.697 + }
1.698 +
1.699 +/* ----------------------------------------------------------------------------
1.700 +@SYMTestCaseID PBASE-PRMACCTST-LATENCY-0564
1.701 +@SYMTestCaseDesc Ensure instantaneous resource change state instantaneously
1.702 +@SYMREQ REQ7751
1.703 +@SYMPREQ PREQ1398
1.704 +@SYMTestPriority High
1.705 +@SYMTestActions
1.706 +Pre-condition:
1.707 + If in use, resource is not Single-User
1.708 + If in use, resource state is not equal to max level
1.709 + If in use, resource is not Custom Sense
1.710 +For each Multi-Level resource:
1.711 + 1. Register TAC1
1.712 + 2. TAC1 changes resource state to max value (async)
1.713 + 3. Immediately afterwards, TAC1 gets resource state (sync)
1.714 + 4. Wait for callback function
1.715 + 5. TAC1 changes resource state to min value (async)
1.716 + 6. Immediately afterwards, TAC1 gets resource state (sync)
1.717 + 7. Wait for callback function
1.718 + 8. De-register TAC1
1.719 +@SYMTestExpectedResults
1.720 + 1. Client registered
1.721 + 2. No error reported.
1.722 + 3. If resource is Instantaneous Set, then the resource state is equal to
1.723 + the new state. If Long Latency Set, then the state is either the old or
1.724 + the new state.
1.725 + 4. Callback function is called.
1.726 + 5. No error reported.
1.727 + 6. If resource is Instantaneous Set, then the resource state is equal to
1.728 + the new state. If Long Latency Set, then the state is either the old or
1.729 + the new state.
1.730 + 7. Callback function is called.
1.731 + 8. Client de-registered.
1.732 +*/
1.733 +
1.734 +void CTestPrmAccTst::TestLatency(TInt aResourceNo)
1.735 + {
1.736 + test.Printf(_L("---Latency "));
1.737 + TResInfo& res = *((TResInfo*) iResources.Ptr() + aResourceNo);
1.738 + // Test pre-conditions
1.739 + if (res.iSense == TResInfo::ECustom)
1.740 + {
1.741 + test.Printf(_L("Not tested (Custom sense resource)\n"));
1.742 + return;
1.743 + }
1.744 + TInt state;
1.745 + TInt r = iToc.GetResourceState(res.iResourceId, state);
1.746 + test_KErrNone(r);
1.747 + TInt levelowner;
1.748 + r = iToc.GetLevelOwner(res.iResourceId, levelowner);
1.749 + test_KErrNone(r);
1.750 + //
1.751 + if (levelowner != KTestResourceNotInUse)
1.752 + {
1.753 + if (state == res.iMaxLevel)
1.754 + {
1.755 + test.Printf(_L("Not tested (Resource is already at maximum level)\n"));
1.756 + return;
1.757 + }
1.758 + if (res.iUsage == TResInfo::ESingleUse)
1.759 + {
1.760 + test.Printf(_L("Not tested (Single-User resource already in use)\n"));
1.761 + return;
1.762 + }
1.763 + }
1.764 + // Define the two test values
1.765 + TInt tstval1;
1.766 + TInt tstval2;
1.767 + if (levelowner != KTestResourceNotInUse)
1.768 + {
1.769 + // Resource in use
1.770 + tstval1 = res.iMaxLevel;
1.771 + tstval2 = state;
1.772 + }
1.773 + else
1.774 + {
1.775 + tstval1 = res.iMaxLevel;
1.776 + tstval2 = res.iMinLevel;
1.777 + }
1.778 + // Test starts here
1.779 + r = iTac1.Open();
1.780 + test_KErrNone(r);
1.781 + r = iTac1.RegisterClient(KTestTac1);
1.782 + test_KErrNone(r);
1.783 + //
1.784 + TTestResourceStateBuf buf;
1.785 + buf().iResourceId = res.iResourceId;
1.786 + buf().iNewState = tstval1;
1.787 + TRequestStatus rs;
1.788 + TInt tmpstate;
1.789 + iTac1.ChangeResourceStateAndGetState(rs, buf, tmpstate);
1.790 + User::WaitForRequest(rs);
1.791 + test_KErrNone(rs.Int());
1.792 + if (res.iLatencySet == TResInfo::EInstantaneous)
1.793 + {
1.794 + test_Equal(tstval1, tmpstate); // Temp state is equal to the new state
1.795 + }
1.796 + else if (tmpstate != state) // Temp state is not necessarily equal to the new state
1.797 + {
1.798 + test_Equal(tstval1, tmpstate);
1.799 + }
1.800 + TInt newstate;
1.801 + r = iToc.GetResourceState(res.iResourceId, newstate);
1.802 + test_KErrNone(r);
1.803 + test_Equal(tstval1, newstate);
1.804 + //
1.805 + buf().iNewState = tstval2;
1.806 + iTac1.ChangeResourceStateAndGetState(rs, buf, tmpstate);
1.807 + User::WaitForRequest(rs);
1.808 + test_KErrNone(rs.Int());
1.809 + if (res.iLatencySet == TResInfo::EInstantaneous)
1.810 + {
1.811 + test_Equal(tstval2, tmpstate); // Temp state is equal to the new state
1.812 + }
1.813 + else if (tmpstate != tstval1) // Temp state is not necessarily equal to the new state
1.814 + {
1.815 + test_Equal(tstval2, tmpstate);
1.816 + }
1.817 + r = iToc.GetResourceState(res.iResourceId, newstate);
1.818 + test_KErrNone(r);
1.819 + test_Equal(tstval2, newstate);
1.820 + //
1.821 + r = iTac1.DeRegisterClient();
1.822 + test_KErrNone(r);
1.823 + iTac1.Close();
1.824 + test.Printf(_L("\n"));
1.825 + }
1.826 +
1.827 +/* ----------------------------------------------------------------------------
1.828 +@SYMTestCaseID PBASE-PRMACCTST-SENSE-0565
1.829 +@SYMTestCaseDesc Ensure Negative and Positive Sense resources behave as
1.830 + expected
1.831 +@SYMREQ REQ7751
1.832 +@SYMPREQ PREQ1398
1.833 +@SYMTestPriority High
1.834 +@SYMTestActions
1.835 +Pre-condition:
1.836 + Resource is Shared
1.837 + If in use, resource state is not equal to max level
1.838 +For each Positive or Negative Sense resource:
1.839 + 1. Register TOC, TAC1, TAC2 and TAC3
1.840 + 2. Define three distincts test values, s1, s2 and s3, that correspond to
1.841 + actual resource states in the PSL. s1 and s3 are at opposite ends of
1.842 + the range of states the resource can be set to. s2 is an intermediate
1.843 + state. It might not always be possible to find a distinct value for s2
1.844 + (if the resource is binary or if its current use is limiting the number
1.845 + of states the resource can be set to). In this case, s2 = s1.
1.846 + 3. TAC1 sets resource state to s1
1.847 + 4. TAC2 sets resource state to s2
1.848 + 5. TAC3 sets resource state to s3
1.849 + 6. De-register TAC2
1.850 + 7. De-register TAC3
1.851 + 8. De-register TAC1 and register TAC1, TAC2 and TAC3 again.
1.852 + 9. TAC1 sets resource state to s1
1.853 + 10. TAC3 sets resource state to s3
1.854 + 11. TAC2 sets resource state to s2
1.855 + 12. De-register TAC3.
1.856 + 13. TAC3 sets resource state to s3
1.857 + 14. De-register TOC, TAC1, TAC2 and TAC3
1.858 +@SYMTestExpectedResults
1.859 + 1. Clients registered
1.860 + 2. s1 <= s2 < s3
1.861 + 3. Resource state set to s1
1.862 + 4. Resource state set to s2
1.863 + 5. Resource state set to s3
1.864 + 6. Resource state remains unchanged (TAC3 owns level)
1.865 + 7. Resource state returns to s1 (TAC1 now owns level)
1.866 + 8. Clients registered
1.867 + 9. Resource state set to s1
1.868 + 10. Resource state set to s3
1.869 + 11. Resource state remains unchanged (TAC3 owns level)
1.870 + 12. Resource state changes to s2 (TAC2 now owns level)
1.871 + 13. Resource state set to s3
1.872 + 14. Clients de-registered
1.873 +*/
1.874 +
1.875 +void CTestPrmAccTst::TestSense(TInt aResourceNo)
1.876 + {
1.877 + test.Printf(_L("---Sense "));
1.878 + TResInfo& res = *((TResInfo*) iResources.Ptr() + aResourceNo);
1.879 + // Test pre-conditions
1.880 + if (res.iUsage != TResInfo::EShared)
1.881 + {
1.882 + test.Printf(_L("Not tested: Resource is Single-User\n"));
1.883 + return;
1.884 + }
1.885 + //
1.886 + TInt state;
1.887 + TInt r = iToc.GetResourceState(res.iResourceId, state);
1.888 + test_KErrNone(r);
1.889 + TInt levelowner;
1.890 + r = iToc.GetLevelOwner(res.iResourceId, levelowner);
1.891 + test_KErrNone(r);
1.892 + //
1.893 + if (levelowner != KTestResourceNotInUse && state == res.iMaxLevel)
1.894 + {
1.895 + test.Printf(_L("Not tested (Resource is already at maximum level)\n"));
1.896 + return;
1.897 + }
1.898 + // Define three test values
1.899 + r = iTac1.Open();
1.900 + test_KErrNone(r);
1.901 + r = iTac1.RegisterClient(KTestTac1);
1.902 + test_KErrNone(r);
1.903 + TInt tstval1;
1.904 + TInt tstval2;
1.905 + TInt tstval3;
1.906 + if (levelowner == KTestResourceNotInUse)
1.907 + {
1.908 + tstval1 = res.iMinLevel;
1.909 + }
1.910 + else
1.911 + {
1.912 + tstval1 = state;
1.913 + }
1.914 + tstval3 = res.iMaxLevel;
1.915 + // Attempt to find a distinct intermediate value by dichotomy
1.916 + tstval2 = tstval3;
1.917 + while ((tstval2 - tstval1 < -1) || (tstval2 - tstval1 > 1))
1.918 + {
1.919 + tstval2 -= (tstval2 - tstval1 + (res.iSense == TResInfo::EPositive ? 1 : 0)) / 2;
1.920 + r = iTac1.ChangeResourceState(res.iResourceId, tstval2);
1.921 + test_KErrNone(r);
1.922 + r = iTac1.GetResourceState(res.iResourceId, state);
1.923 + test_KErrNone(r);
1.924 + }
1.925 + if (state == tstval1 && res.iType == TResInfo::EMultiLevel)
1.926 + {
1.927 + test.Printf(_L("(Could not find three distincts test values)"));
1.928 + }
1.929 + tstval2 = state;
1.930 + r = iTac1.DeRegisterClient();
1.931 + test_KErrNone(r);
1.932 + iTac1.Close();
1.933 +
1.934 + // Test starts here
1.935 + r = iTac1.Open();
1.936 + test_KErrNone(r);
1.937 + r = iTac2.Open();
1.938 + test_KErrNone(r);
1.939 + r = iTac3.Open();
1.940 + test_KErrNone(r);
1.941 + r = iTac1.RegisterClient(KTestTac1);
1.942 + test_KErrNone(r);
1.943 + r = iTac2.RegisterClient(KTestTac2);
1.944 + test_KErrNone(r);
1.945 + r = iTac3.RegisterClient(KTestTac3);
1.946 + test_KErrNone(r);
1.947 +
1.948 + // Set resource state to the first test value
1.949 + r = iTac1.ChangeResourceState(res.iResourceId, tstval1);
1.950 + test_KErrNone(r);
1.951 + r = iToc.GetResourceState(res.iResourceId, state);
1.952 + test_KErrNone(r);
1.953 + test_Equal(tstval1, state);
1.954 +
1.955 + // Set resource state to middle test value
1.956 + r = iTac2.ChangeResourceState(res.iResourceId, tstval2);
1.957 + test_KErrNone(r);
1.958 + r = iToc.GetResourceState(res.iResourceId, state);
1.959 + test_KErrNone(r);
1.960 + test_Equal(tstval2, state);
1.961 +
1.962 + // Set resource to the third test value
1.963 + r = iTac3.ChangeResourceState(res.iResourceId, tstval3);
1.964 + test_KErrNone(r);
1.965 + r = iToc.GetResourceState(res.iResourceId, state);
1.966 + test_KErrNone(r);
1.967 + test_Equal(tstval3, state);
1.968 +
1.969 + // De-register second client
1.970 + r = iTac2.DeRegisterClient();
1.971 + test_KErrNone(r);
1.972 + r = iToc.GetResourceState(res.iResourceId, state);
1.973 + test_KErrNone(r);
1.974 + test_Equal(tstval3, state); // state remains unchanged
1.975 +
1.976 + // De-register third client
1.977 + r = iTac3.DeRegisterClient();
1.978 + test_KErrNone(r);
1.979 + r = iToc.GetResourceState(res.iResourceId, state);
1.980 + test_KErrNone(r);
1.981 + test_Equal(tstval1, state); // state changes
1.982 +
1.983 + // De-register and register all clients again
1.984 + r = iTac1.DeRegisterClient();
1.985 + test_KErrNone(r);
1.986 + r = iTac1.RegisterClient(KTestTac1);
1.987 + test_KErrNone(r);
1.988 + r = iTac2.RegisterClient(KTestTac2);
1.989 + test_KErrNone(r);
1.990 + r = iTac3.RegisterClient(KTestTac3);
1.991 + test_KErrNone(r);
1.992 +
1.993 + // Set resource state to the first test value
1.994 + r = iTac1.ChangeResourceState(res.iResourceId, tstval1);
1.995 + test_KErrNone(r);
1.996 + r = iToc.GetResourceState(res.iResourceId, state);
1.997 + test_KErrNone(r);
1.998 + test_Equal(tstval1, state);
1.999 +
1.1000 + // Set resource to the third test value
1.1001 + r = iTac3.ChangeResourceState(res.iResourceId, tstval3);
1.1002 + test_KErrNone(r);
1.1003 + r = iToc.GetResourceState(res.iResourceId, state);
1.1004 + test_KErrNone(r);
1.1005 + test_Equal(tstval3, state);
1.1006 +
1.1007 + // Set resource state to middle test value
1.1008 + r = iTac2.ChangeResourceState(res.iResourceId, tstval2);
1.1009 + test_KErrNone(r);
1.1010 + r = iToc.GetResourceState(res.iResourceId, state);
1.1011 + test_KErrNone(r);
1.1012 + test_Equal(tstval3, state); // state does not change
1.1013 +
1.1014 + // De-register client holding resource
1.1015 + r = iTac3.DeRegisterClient();
1.1016 + test_KErrNone(r);
1.1017 + r = iToc.GetResourceState(res.iResourceId, state);
1.1018 + test_KErrNone(r);
1.1019 + test_Equal(tstval2, state);
1.1020 +
1.1021 + // Register client again
1.1022 + r = iTac3.RegisterClient(KTestTac3);
1.1023 + test_KErrNone(r);
1.1024 + r = iTac3.ChangeResourceState(res.iResourceId, tstval3);
1.1025 + test_KErrNone(r);
1.1026 + r = iToc.GetResourceState(res.iResourceId, state);
1.1027 + test_KErrNone(r);
1.1028 + test_Equal(tstval3, state);
1.1029 +
1.1030 + //
1.1031 + r = iTac3.DeRegisterClient();
1.1032 + test_KErrNone(r);
1.1033 + r = iTac2.DeRegisterClient();
1.1034 + test_KErrNone(r);
1.1035 + r = iTac1.DeRegisterClient();
1.1036 + test_KErrNone(r);
1.1037 + iTac3.Close();
1.1038 + iTac2.Close();
1.1039 + iTac1.Close();
1.1040 + test.Printf(_L("\n"));
1.1041 + }
1.1042 +
1.1043 +/* ----------------------------------------------------------------------------
1.1044 +@SYMTestCaseID PBASE-PRMACCTST-CUSTOMSENSE-0566
1.1045 +@SYMTestCaseDesc Ensure the Custom Sense function is implemented
1.1046 +@SYMREQ REQ7751
1.1047 +@SYMPREQ PREQ1398
1.1048 +@SYMTestPriority High
1.1049 +@SYMTestActions
1.1050 +For each Custom Sense resource:
1.1051 + 1. Register TAC1
1.1052 + 2. Attempt to set the state of the resource to its current state. The
1.1053 + purpose of this test action is to ensure that the PSL's custom function
1.1054 + for this resource has been implemented. If the custom function is not
1.1055 + present, the PIL will generate a panic.
1.1056 + 3. De-register TAC1
1.1057 +@SYMTestExpectedResults
1.1058 + 1. Client registered
1.1059 + 2. The resource change request does not cause a panic.
1.1060 + 3. Client de-registered
1.1061 +*/
1.1062 +
1.1063 +void CTestPrmAccTst::TestCustomSense(TInt aResourceNo)
1.1064 + {
1.1065 + test.Printf(_L("---Custom Sense"));
1.1066 + TResInfo& res = *((TResInfo*) iResources.Ptr() + aResourceNo);
1.1067 + TInt r = iTac1.Open();
1.1068 + test_KErrNone(r);
1.1069 + r = iTac1.RegisterClient(KTestTac1);
1.1070 + test_KErrNone(r);
1.1071 + //
1.1072 + TInt state;
1.1073 + r = iTac1.GetResourceState(res.iResourceId, state);
1.1074 + test_KErrNone(r);
1.1075 + r = iTac1.ChangeResourceState(res.iResourceId, state);
1.1076 + test_KErrNone(r);
1.1077 + //
1.1078 + r = iTac1.DeRegisterClient();
1.1079 + test_KErrNone(r);
1.1080 + iTac1.Close();
1.1081 + test.Printf(_L("\n"));
1.1082 + }
1.1083 +
1.1084 +/* ----------------------------------------------------------------------------
1.1085 +@SYMTestCaseID PBASE-PRMACCTST-POWERRESUMPTION-0567
1.1086 +@SYMTestCaseDesc Ensure resources go back to their default state when not in
1.1087 + use
1.1088 +@SYMREQ REQ7751
1.1089 +@SYMPREQ PREQ1398
1.1090 +@SYMTestPriority High
1.1091 +@SYMTestActions
1.1092 +Pre-condition:
1.1093 + Resource not in use
1.1094 + Not a Custom Sense resource
1.1095 +For each resource:
1.1096 + 1. Register TAC1
1.1097 + 2. Set resource state to something that is not the default level
1.1098 + 3. De-register TAC1
1.1099 + 4. Register TOC
1.1100 + 5. Get resource state
1.1101 + 6. De-register TOC
1.1102 +@SYMTestExpectedResults
1.1103 + 1. Client registered
1.1104 + 2. Resource state changed
1.1105 + 3. Client de-registered
1.1106 + 4. Client registered
1.1107 + 5. Resource state is at the default level
1.1108 + 6. Client de-registered
1.1109 +*/
1.1110 +
1.1111 +void CTestPrmAccTst::TestDefaultPowerResumption()
1.1112 + {
1.1113 + TInt i;
1.1114 + for (i = 0; i < (TInt) iNoResources; i++)
1.1115 + {
1.1116 + TResInfo& res = *((TResInfo*) iResources.Ptr() + i);
1.1117 + test.Printf(_L("Resource %08x "), res.iResourceId);
1.1118 + TInt levelowner;
1.1119 + TInt r = iToc.GetLevelOwner(res.iResourceId, levelowner);
1.1120 + test_KErrNone(r);
1.1121 +
1.1122 + // Test pre-condition: resource not in use
1.1123 + if (levelowner != KTestResourceNotInUse)
1.1124 + {
1.1125 + test.Printf(_L("Not tested (already in use)\n"));
1.1126 + continue;
1.1127 + }
1.1128 + if (res.iSense == TResInfo::ECustom)
1.1129 + {
1.1130 + test.Printf(_L("Not tested (custom sense)\n"));
1.1131 + continue;
1.1132 + }
1.1133 +
1.1134 + // Define a test value
1.1135 + TInt tstval;
1.1136 + if (res.iDefaultLevel == res.iMaxLevel)
1.1137 + {
1.1138 + tstval = res.iMinLevel;
1.1139 + }
1.1140 + else
1.1141 + {
1.1142 + tstval = res.iMaxLevel;
1.1143 + }
1.1144 +
1.1145 + // Test starts here
1.1146 + r = iTac1.Open();
1.1147 + test_KErrNone(r);
1.1148 + r = iTac1.RegisterClient(KTestTac1);
1.1149 + test_KErrNone(r);
1.1150 + // Change resource state
1.1151 + TInt state;
1.1152 + r = iToc.GetResourceState(res.iResourceId, state);
1.1153 + test_KErrNone(r);
1.1154 + test_Equal(res.iDefaultLevel, state);
1.1155 + r = iTac1.ChangeResourceState(res.iResourceId, tstval);
1.1156 + test_KErrNone(r);
1.1157 + r = iToc.GetResourceState(res.iResourceId, state);
1.1158 + test_KErrNone(r);
1.1159 + test_Equal(tstval, state);
1.1160 + // De-register active client so resource is freed
1.1161 + r = iTac1.DeRegisterClient();
1.1162 + test_KErrNone(r);
1.1163 + iTac1.Close();
1.1164 + // Read both cached and actual values
1.1165 + TInt cached;
1.1166 + r = iToc.GetResourceStateCached(res.iResourceId, cached);
1.1167 + test_KErrNone(r);
1.1168 + r = iToc.GetResourceState(res.iResourceId, state);
1.1169 + test_KErrNone(r);
1.1170 + test_Equal(cached, state);
1.1171 + test_Equal(res.iDefaultLevel, state);
1.1172 + test.Printf(_L("\n"));
1.1173 + }
1.1174 + //
1.1175 + test.Printf(_L("\n"));
1.1176 + }
1.1177 +
1.1178 +/* ----------------------------------------------------------------------------
1.1179 +@SYMTestCaseID PBASE-PRMACCTST-DEPENDENCIESDECLARED-0568
1.1180 +@SYMTestCaseDesc Ensure all actual resources dependencies have been declared
1.1181 +@SYMREQ REQ7751
1.1182 +@SYMPREQ PREQ1398
1.1183 +@SYMTestPriority High
1.1184 +@SYMTestActions
1.1185 +Pre-condition:
1.1186 + Resource not in use
1.1187 + Not a Custom Sense resource
1.1188 +For each resource:
1.1189 + 1. Register TOC & TAC1
1.1190 + 2. Get state of all resources
1.1191 + 3. Set the state of the resource under test state to something that is not
1.1192 + the default level
1.1193 + 4. Get state of all resource
1.1194 + 5. De-register TAC1 & TOC
1.1195 +@SYMTestExpectedResults
1.1196 + 1. Clients registered
1.1197 + 2. None
1.1198 + 3. Resource state changed
1.1199 + 4. Only resources with a direct or indirect dependency on the resource
1.1200 + under test have changed.
1.1201 + 5. Client de-registered
1.1202 +*/
1.1203 +
1.1204 +TBool CTestPrmAccTst::ResourceInterdependency(TInt aResourceIdOrig, TInt aCurrentResourceId, TInt aResourceIdTarget)
1.1205 + {
1.1206 + // Get Reference on current resource node
1.1207 + TBool r = EFalse;
1.1208 + if (aCurrentResourceId & KTestIdHasDependencies)
1.1209 + {
1.1210 + // Get dependencies of current resources
1.1211 + RBuf8 deplist;
1.1212 + deplist.Create(sizeof(SResDepInfo) * KTestMaxDependencies);
1.1213 + r = iToc.GetResourceDependencies(aCurrentResourceId, deplist);
1.1214 + if (r)
1.1215 + {
1.1216 + test.Printf(_L("ERROR: aCurrentResourceId==%08x"), aCurrentResourceId);
1.1217 + test_KErrNone(r);
1.1218 + }
1.1219 + TInt i;
1.1220 + SResDepInfo *ptr = (SResDepInfo*)deplist.Ptr();
1.1221 + for (i = 0; i < (TInt) (deplist.Length() / sizeof(SResDepInfo)); i++, ptr++)
1.1222 + {
1.1223 + TInt depid = ptr->iResourceId;
1.1224 + if (depid == aResourceIdTarget)
1.1225 + {
1.1226 + // We've got a match
1.1227 + r = ETrue;
1.1228 + }
1.1229 + else if (depid == aResourceIdOrig)
1.1230 + {
1.1231 + // No going back to parent node
1.1232 + continue;
1.1233 + }
1.1234 + else
1.1235 + {
1.1236 + // Recurse down the tree
1.1237 + r = ResourceInterdependency(aCurrentResourceId, depid, aResourceIdTarget);
1.1238 + }
1.1239 + if (r)
1.1240 + {
1.1241 + break;
1.1242 + }
1.1243 + }
1.1244 + deplist.Close();
1.1245 + }
1.1246 + return r;
1.1247 + }
1.1248 +
1.1249 +void CTestPrmAccTst::TestDependenciesAreDeclared(TInt aResourceNo)
1.1250 + {
1.1251 + test.Printf(_L("---Test all dependencies are declared\n"));
1.1252 + TResInfo& res = *((TResInfo*) iResources.Ptr() + aResourceNo);
1.1253 + //
1.1254 + TInt levelowner;
1.1255 + TInt r = iToc.GetLevelOwner(res.iResourceId, levelowner);
1.1256 + test_KErrNone(r);
1.1257 + // Test pre-condition: resource not in use
1.1258 + if (levelowner != KTestResourceNotInUse)
1.1259 + {
1.1260 + test.Printf(_L("Not tested (already in use)\n"));
1.1261 + return;
1.1262 + }
1.1263 + if (res.iSense == TResInfo::ECustom)
1.1264 + {
1.1265 + test.Printf(_L("Not tested (custom sense)\n"));
1.1266 + return;
1.1267 + }
1.1268 + // Define a test value
1.1269 + TInt tstval;
1.1270 + if (res.iDefaultLevel == res.iMaxLevel)
1.1271 + {
1.1272 + tstval = res.iMinLevel;
1.1273 + }
1.1274 + else
1.1275 + {
1.1276 + tstval = res.iMaxLevel;
1.1277 + }
1.1278 +
1.1279 + // Test starts here
1.1280 + // Save current state of all resources;
1.1281 + RArray<TInt> oldstate;
1.1282 + TInt i;
1.1283 + TInt state;
1.1284 + for (i = 0; i < (TInt) iNoResources; i++)
1.1285 + {
1.1286 + TResInfo& tmpres = *((TResInfo*) iResources.Ptr() + i);
1.1287 + r = iToc.GetResourceState(tmpres.iResourceId, state);
1.1288 + test_KErrNone(r);
1.1289 + r = oldstate.Append(state);
1.1290 + test_KErrNone(r);
1.1291 + }
1.1292 + //
1.1293 + r = iTac1.Open();
1.1294 + test_KErrNone(r);
1.1295 + r = iTac1.RegisterClient(KTestTac1);
1.1296 + test_KErrNone(r);
1.1297 +
1.1298 + // Change resource state
1.1299 + r = iToc.GetResourceState(res.iResourceId, state);
1.1300 + test_KErrNone(r);
1.1301 + test_Equal(res.iDefaultLevel, state);
1.1302 + r = iTac1.ChangeResourceState(res.iResourceId, tstval);
1.1303 + test_KErrNone(r);
1.1304 + r = iToc.GetResourceState(res.iResourceId, state);
1.1305 + test_KErrNone(r);
1.1306 + test_Equal(tstval, state);
1.1307 +
1.1308 + // Now we check that resources with no dependency on resource under test
1.1309 + // have not changed
1.1310 + for (i = 0; i < (TInt) iNoResources; i++)
1.1311 + {
1.1312 + test.Printf(_L("."));
1.1313 + if (i == aResourceNo)
1.1314 + {
1.1315 + continue;
1.1316 + }
1.1317 + TResInfo& tmpres = *((TResInfo*) iResources.Ptr() + i);
1.1318 + r = iToc.GetResourceState(tmpres.iResourceId, state);
1.1319 + test_KErrNone(r);
1.1320 + if (!ResourceInterdependency(0, res.iResourceId, tmpres.iResourceId) &&
1.1321 + (state != oldstate[i]))
1.1322 + {
1.1323 + test.Printf(_L("Resource %08x has changed!\n"), tmpres.iResourceId);
1.1324 + test_Equal(state, oldstate[i]);
1.1325 + }
1.1326 + }
1.1327 + test.Printf(_L("\n"));
1.1328 +
1.1329 + // De-register active client
1.1330 + r = iTac1.DeRegisterClient();
1.1331 + test_KErrNone(r);
1.1332 + iTac1.Close();
1.1333 + //
1.1334 + oldstate.Close();
1.1335 + }
1.1336 +
1.1337 +TInt CTestPrmAccTst::DoTestPreamble()
1.1338 + {
1.1339 + test.Title();
1.1340 + test.Start(_L("Preamble"));
1.1341 +
1.1342 + // Load Device Driver
1.1343 + TInt r;
1.1344 +#ifdef RESOURCE_MANAGER_SIMULATED_PSL
1.1345 + test.Printf(_L("Load Simulated PSL PDD\n"));
1.1346 + r = User::LoadPhysicalDevice(_L("RESOURCECONTROLLEREXTENDED.PDD"));
1.1347 + if (r == KErrNotFound)
1.1348 + {
1.1349 + test.Printf(_L("RESOURCECONTROLLEREXTENDED.PDD not found\nTest skipped\n"));
1.1350 + return r;
1.1351 + }
1.1352 + if (r)
1.1353 + {
1.1354 + test_Equal(KErrAlreadyExists, r);
1.1355 + test.Printf(_L("Already loaded\n"));
1.1356 + }
1.1357 + test.Printf(_L("Load test LDD\n"));
1.1358 + r = User::LoadLogicalDevice(_L("D_PRMACCTSTSIM.LDD"));
1.1359 + if (r)
1.1360 + {
1.1361 + test_Equal(KErrAlreadyExists, r);
1.1362 + test.Printf(_L("Already loaded\n"));
1.1363 + }
1.1364 +#else
1.1365 + test.Printf(_L("Load test LDD\n"));
1.1366 + r = User::LoadLogicalDevice(_L("D_PRMACCTST.LDD"));
1.1367 + if (r)
1.1368 + {
1.1369 + test_Equal(KErrAlreadyExists, r);
1.1370 + test.Printf(_L("Already loaded\n"));
1.1371 + }
1.1372 +#endif // RESOURCE_MANAGER_SIMULATED_PSL
1.1373 +
1.1374 + // Check if Device Driver was loaded as a Kernel Extension
1.1375 + iKextc.Open();
1.1376 + TUint clientId;
1.1377 + r = iKextc.GetKernelExtClientId(clientId);
1.1378 + test_KErrNone(r);
1.1379 + if (!clientId)
1.1380 + {
1.1381 + test.Printf(_L("No Kernel extension PRM client\n"));
1.1382 + iKextc.Close();
1.1383 + }
1.1384 + else
1.1385 + {
1.1386 + // De-register client so Single User resources can be tested
1.1387 + r = iKextc.OpenClient(clientId);
1.1388 + test_KErrNone(r);
1.1389 + r = iKextc.DeRegisterClient();
1.1390 + test_KErrNone(r);
1.1391 + iKextc.Close();
1.1392 + }
1.1393 +
1.1394 + // Register TOC (always on - de-registered in test postamble)
1.1395 + r = iToc.Open();
1.1396 + test_KErrNone(r);
1.1397 + r = iToc.RegisterClient(KTestToc);
1.1398 + test_KErrNone(r);
1.1399 +
1.1400 + // Get resources info
1.1401 + r = iToc.GetTotalNumberOfResources(iNoResources);
1.1402 + test_KErrNone(r);
1.1403 + test.Printf(_L("Resources found: %d\n"), iNoResources);
1.1404 + if (iNoResources > 0)
1.1405 + {
1.1406 + r = iResources.Create(iNoResources * sizeof(TResInfo));
1.1407 + test_KErrNone(r);
1.1408 + test.Printf(_L("Retrieving information on resources\n"));
1.1409 + r = iToc.GetInfoOnResourcesInUseByClient(0, iResources);
1.1410 + test_KErrNone(r);
1.1411 + iIsPrmSupported = ETrue;
1.1412 + }
1.1413 + else
1.1414 + {
1.1415 + test.Printf(_L("No resource found.\n"));
1.1416 + }
1.1417 + return KErrNone;
1.1418 + }
1.1419 +
1.1420 +void CTestPrmAccTst::DoTest()
1.1421 + {
1.1422 + if (!iIsPrmSupported)
1.1423 + {
1.1424 + return;
1.1425 + }
1.1426 + //
1.1427 + test.Next(_L("Enumerate Resources"));
1.1428 + TestEnumerateResources();
1.1429 + //
1.1430 + TInt i;
1.1431 + test.Next(_L("Resource Properties"));
1.1432 + for (i = 0; i < (TInt) iNoResources; i++)
1.1433 + {
1.1434 + TResInfo& res = *((TResInfo*) iResources.Ptr() + i);
1.1435 + test.Printf(_L("+++Resource %08x\n"), res.iResourceId);
1.1436 + //
1.1437 + if (res.iUsage == TResInfo::ESingleUse)
1.1438 + {
1.1439 + TestSingleUserResources(i);
1.1440 + }
1.1441 + else if (res.iUsage == TResInfo::EShared)
1.1442 + {
1.1443 + TestSharedResources(i);
1.1444 + }
1.1445 + //
1.1446 + if (res.iType == TResInfo::EBinary)
1.1447 + {
1.1448 + TestBinaryResources(i);
1.1449 + }
1.1450 + else if (res.iType == TResInfo::EMultiLevel)
1.1451 + {
1.1452 + TestMultilevelResources(i);
1.1453 + }
1.1454 + //
1.1455 + TestLatency(i);
1.1456 + //
1.1457 + if ((res.iSense == TResInfo::EPositive) || (res.iSense == TResInfo::ENegative))
1.1458 + {
1.1459 + TestSense(i);
1.1460 + }
1.1461 + else if (res.iSense == TResInfo::ECustom)
1.1462 + {
1.1463 + TestCustomSense(i);
1.1464 + }
1.1465 + }
1.1466 + //
1.1467 + test.Next(_L("Default Power Resumption"));
1.1468 + TestDefaultPowerResumption();
1.1469 + //
1.1470 + test.Next(_L("PRM Extension - Dependencies"));
1.1471 + for (i = 0; i < (TInt) iNoResources; i++)
1.1472 + {
1.1473 + TResInfo& res = *((TResInfo*) iResources.Ptr() + i);
1.1474 + if (res.iResourceId & KTestIdHasDependencies)
1.1475 + {
1.1476 + test.Printf(_L("+++Resource %08x\n"), res.iResourceId);
1.1477 + TestDependenciesAreDeclared(i);
1.1478 + }
1.1479 + }
1.1480 + }
1.1481 +
1.1482 +void CTestPrmAccTst::DoTestPostamble()
1.1483 + {
1.1484 + test.Next(_L("Postamble"));
1.1485 + if (iToc.Handle())
1.1486 + {
1.1487 + TInt r = iToc.DeRegisterClient();
1.1488 + test_KErrNone(r);
1.1489 + iToc.Close();
1.1490 + }
1.1491 + test.End();
1.1492 + test.Close();
1.1493 + }
1.1494 +
1.1495 +GLDEF_C TInt MainL()
1.1496 + {
1.1497 + CTestPrmAccTst* testapp;
1.1498 + testapp = new (ELeave) CTestPrmAccTst();
1.1499 + CleanupStack::PushL(testapp);
1.1500 + if (testapp->DoTestPreamble() == KErrNone)
1.1501 + {
1.1502 + testapp->DoTest();
1.1503 + }
1.1504 + testapp->DoTestPostamble();
1.1505 + CleanupStack::PopAndDestroy(testapp);
1.1506 + return KErrNone;
1.1507 + }
1.1508 +
1.1509 +GLDEF_C TInt E32Main()
1.1510 + {
1.1511 + __UHEAP_MARK;
1.1512 + CTrapCleanup* cleanup = CTrapCleanup::New();
1.1513 + if(cleanup == NULL)
1.1514 + {
1.1515 + return KErrNoMemory;
1.1516 + }
1.1517 + TRAP_IGNORE(MainL());
1.1518 + delete cleanup;
1.1519 + __UHEAP_MARKEND;
1.1520 + return KErrNone;
1.1521 + }