os/kernelhwsrv/kerneltest/e32test/power/d_lddpowerseqtest.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/power/d_lddpowerseqtest.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,280 @@
     1.4 +// Copyright (c) 2006-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 +// e32test\power\d_lddpowerseqtest.cpp
    1.18 +// LDD for testing the power up and down sequence
    1.19 +// 
    1.20 +//
    1.21 +
    1.22 +#include <kernel/kernel.h>
    1.23 +#include <kernel/kpower.h>
    1.24 +#include "d_lddpowerseqtest.h"
    1.25 +
    1.26 +
    1.27 +_LIT(KLitPower1,"PowerSeqTest1");
    1.28 +_LIT(KLitPower2,"PowerSeqTest2");
    1.29 +
    1.30 +//
    1.31 +// Variables to store asynchronous status request and time count user variables address.
    1.32 +//
    1.33 +TRequestStatus *aStatus_up1;
    1.34 +TRequestStatus *aStatus_up2;
    1.35 +TRequestStatus *aStatus_down1;
    1.36 +TRequestStatus *aStatus_down2;
    1.37 +TUint *time_power1down;
    1.38 +TUint *time_power2down;
    1.39 +TUint *time_power1up;
    1.40 +TUint *time_power2up;
    1.41 +TUint sleepTime;
    1.42 +
    1.43 +
    1.44 +class DTest1;
    1.45 +//
    1.46 +// Power handler1
    1.47 +//
    1.48 +class DTest1PowerHandler : public DPowerHandler
    1.49 +	{
    1.50 +public:
    1.51 +	DTest1PowerHandler();
    1.52 +
    1.53 +	void PowerUp();
    1.54 +	void PowerDown(TPowerState);
    1.55 +	};
    1.56 +
    1.57 +//
    1.58 +// Power handler2
    1.59 +//
    1.60 +class DTest2PowerHandler : public DPowerHandler
    1.61 +	{
    1.62 +public:
    1.63 +	DTest2PowerHandler();
    1.64 +	void PowerUp();
    1.65 +	void PowerDown(TPowerState);
    1.66 +	};
    1.67 +
    1.68 +class DTestFactory : public DLogicalDevice
    1.69 +//
    1.70 +// Test LDD factory
    1.71 +//
    1.72 +	{
    1.73 +public:
    1.74 +	DTestFactory();
    1.75 +	virtual TInt Install(); 					//overriding pure virtual
    1.76 +	virtual void GetCaps(TDes8& aDes) const;	//overriding pure virtual
    1.77 +	virtual TInt Create(DLogicalChannelBase*& aChannel); 	//overriding pure virtual
    1.78 +	};
    1.79 +
    1.80 +class DTest1 : public DLogicalChannelBase
    1.81 +//
    1.82 +// Test logical channel
    1.83 +//
    1.84 +	{
    1.85 +public:
    1.86 +	virtual ~DTest1();
    1.87 +protected:
    1.88 +	virtual TInt DoCreate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer);
    1.89 +	virtual TInt Request(TInt aReqNo, TAny* a1, TAny* a2);
    1.90 +	DTest1PowerHandler power1;
    1.91 +	DTest2PowerHandler power2;
    1.92 +	};
    1.93 +
    1.94 +
    1.95 +
    1.96 +DECLARE_STANDARD_LDD()
    1.97 +	{
    1.98 +	return new DTestFactory;
    1.99 +	}
   1.100 +
   1.101 +//
   1.102 +// Constructor
   1.103 +//
   1.104 +DTestFactory::DTestFactory()
   1.105 +	{
   1.106 +
   1.107 +	}
   1.108 +
   1.109 +TInt DTestFactory::Create(DLogicalChannelBase*& aChannel)
   1.110 +	{
   1.111 +//
   1.112 +// Create new channel
   1.113 +//
   1.114 +	aChannel=new DTest1;
   1.115 +	return aChannel?KErrNone:KErrNoMemory;
   1.116 +	}
   1.117 +
   1.118 +TInt DTestFactory::Install()
   1.119 +//
   1.120 +// Install the LDD - overriding pure virtual
   1.121 +//
   1.122 +	{
   1.123 +	return SetName(&KLddName);
   1.124 +	}
   1.125 +
   1.126 +void DTestFactory::GetCaps(TDes8& /*aDes*/) const
   1.127 +//
   1.128 +// Get capabilities - overriding pure virtual
   1.129 +//
   1.130 +	{
   1.131 +	}
   1.132 +
   1.133 +TInt DTest1::DoCreate(TInt /*aUnit*/, const TDesC8* /*aInfo*/, const TVersion& /*aVer*/)
   1.134 +//
   1.135 +// Create channel
   1.136 +//
   1.137 +	{
   1.138 +	//try to remove a handler that hasn't been added yet - should not cause any problems
   1.139 +	power1.Remove();
   1.140 +	//Add power handlers
   1.141 +	power2.Add();
   1.142 +	power1.Add();
   1.143 +	return KErrNone;
   1.144 +	}
   1.145 +
   1.146 +DTest1::~DTest1()
   1.147 +//
   1.148 +// Destructor
   1.149 +//
   1.150 +	{
   1.151 +	power1.Remove();
   1.152 +	power2.Remove();
   1.153 +	//try to remove a handler twice - should not cause any problems
   1.154 +	power2.Remove();
   1.155 +	}
   1.156 +
   1.157 +TInt DTest1::Request(TInt aReqNo, TAny* a1, TAny* a2)
   1.158 +	{
   1.159 +//
   1.160 +// Store status requests and time stamp variable for each power up and power down
   1.161 +//
   1.162 +
   1.163 +	if(aReqNo<0)
   1.164 +		{
   1.165 +		// 'Request' functions...
   1.166 +		TRequestStatus* s = (TRequestStatus*)a1;
   1.167 +		TAny* args[2];
   1.168 +		kumemget32(args,a2,sizeof(args)); // get user side arguments
   1.169 +
   1.170 +		switch(~aReqNo)
   1.171 +			{
   1.172 +			case RLddTest1::EPOWERDOWN_POWER1:
   1.173 +				aStatus_down1 = s;
   1.174 +				time_power1down = (TUint*)args[0];
   1.175 +				break;
   1.176 +
   1.177 +			case RLddTest1::EPOWERDOWN_POWER2:
   1.178 +				aStatus_down2 = s;
   1.179 +				time_power2down = (TUint*)args[0];
   1.180 +				break;
   1.181 +
   1.182 +			case RLddTest1::EPOWERUP_POWER1:
   1.183 +				aStatus_up1 = s;
   1.184 +				time_power1up = (TUint*)args[0];
   1.185 +				break;
   1.186 +
   1.187 +			case RLddTest1::EPOWERUP_POWER2:
   1.188 +				aStatus_up2 = s;
   1.189 +				time_power2up = (TUint*)args[0];
   1.190 +				break;
   1.191 +			}
   1.192 +		}
   1.193 +	else
   1.194 +		{
   1.195 +		// 'Control' functions...
   1.196 +		switch(aReqNo)
   1.197 +			{
   1.198 +			// DoControl
   1.199 +			case RLddTest1::ESET_SLEEPTIME:
   1.200 +				sleepTime = (TUint)a1;
   1.201 +				break;
   1.202 +			}
   1.203 +		}
   1.204 +
   1.205 +	return KErrNone;
   1.206 +	}
   1.207 +
   1.208 +DTest1PowerHandler::DTest1PowerHandler():DPowerHandler(KLitPower1)
   1.209 +	{
   1.210 +//
   1.211 +// Power handler1 constructor
   1.212 +//
   1.213 +	}
   1.214 +
   1.215 +DTest2PowerHandler::DTest2PowerHandler():DPowerHandler(KLitPower2)
   1.216 +	{
   1.217 +//
   1.218 +// Power handler2 constructor
   1.219 +//
   1.220 +	}
   1.221 +
   1.222 +
   1.223 +void DTest1PowerHandler::PowerUp()
   1.224 +	{
   1.225 +//
   1.226 +// Sleep for sometime to get different tick counts for comparision.
   1.227 +// Copy the tick count to user variable and complete the request
   1.228 +//
   1.229 +	NKern::Sleep(sleepTime);
   1.230 +
   1.231 +	TUint temp = NKern::TickCount();
   1.232 +	kumemput(time_power1up, (const TUint *)&temp, sizeof(temp));
   1.233 +
   1.234 +	Kern::RequestComplete(aStatus_up1, KErrNone);
   1.235 +
   1.236 +	PowerUpDone();
   1.237 +
   1.238 +	}
   1.239 +
   1.240 +void DTest2PowerHandler::PowerUp()
   1.241 +	{
   1.242 +//
   1.243 +// Copy the tick count to user variable and complete the request
   1.244 +//
   1.245 +
   1.246 +	TUint temp = NKern::TickCount();
   1.247 +	kumemput(time_power2up, (const TUint *)&temp, sizeof(temp));
   1.248 +
   1.249 +	Kern::RequestComplete(aStatus_up2, KErrNone);
   1.250 +
   1.251 +	PowerUpDone();
   1.252 +	}
   1.253 +
   1.254 +void DTest1PowerHandler::PowerDown(TPowerState /*aState*/)
   1.255 +	{
   1.256 +//
   1.257 +// Copy the tick count to user variable and complete the request
   1.258 +//
   1.259 +
   1.260 +	TUint temp = NKern::TickCount();
   1.261 +	kumemput(time_power1down, (const TUint *)&temp, sizeof(temp));
   1.262 +
   1.263 +	Kern::RequestComplete(aStatus_down1, KErrNone);
   1.264 +
   1.265 +	PowerDownDone();
   1.266 +	}
   1.267 +
   1.268 +void DTest2PowerHandler::PowerDown(TPowerState /*aState*/)
   1.269 +	{
   1.270 +//
   1.271 +// Sleep for sometime to get different tick counts for comparision.
   1.272 +// Copy the tick count to user variable and complete the request
   1.273 +//
   1.274 +
   1.275 +	NKern::Sleep(sleepTime);
   1.276 +
   1.277 +	TUint temp = NKern::TickCount();
   1.278 +	kumemput(time_power2down, (const TUint *)&temp, sizeof(temp));
   1.279 +
   1.280 +	Kern::RequestComplete(aStatus_down2, KErrNone);
   1.281 +
   1.282 +	PowerDownDone();
   1.283 +	}