os/kernelhwsrv/kerneltest/e32test/power/d_lddpowerseqtest.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of the License "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// e32test\power\d_lddpowerseqtest.cpp
sl@0
    15
// LDD for testing the power up and down sequence
sl@0
    16
// 
sl@0
    17
//
sl@0
    18
sl@0
    19
#include <kernel/kernel.h>
sl@0
    20
#include <kernel/kpower.h>
sl@0
    21
#include "d_lddpowerseqtest.h"
sl@0
    22
sl@0
    23
sl@0
    24
_LIT(KLitPower1,"PowerSeqTest1");
sl@0
    25
_LIT(KLitPower2,"PowerSeqTest2");
sl@0
    26
sl@0
    27
//
sl@0
    28
// Variables to store asynchronous status request and time count user variables address.
sl@0
    29
//
sl@0
    30
TRequestStatus *aStatus_up1;
sl@0
    31
TRequestStatus *aStatus_up2;
sl@0
    32
TRequestStatus *aStatus_down1;
sl@0
    33
TRequestStatus *aStatus_down2;
sl@0
    34
TUint *time_power1down;
sl@0
    35
TUint *time_power2down;
sl@0
    36
TUint *time_power1up;
sl@0
    37
TUint *time_power2up;
sl@0
    38
TUint sleepTime;
sl@0
    39
sl@0
    40
sl@0
    41
class DTest1;
sl@0
    42
//
sl@0
    43
// Power handler1
sl@0
    44
//
sl@0
    45
class DTest1PowerHandler : public DPowerHandler
sl@0
    46
	{
sl@0
    47
public:
sl@0
    48
	DTest1PowerHandler();
sl@0
    49
sl@0
    50
	void PowerUp();
sl@0
    51
	void PowerDown(TPowerState);
sl@0
    52
	};
sl@0
    53
sl@0
    54
//
sl@0
    55
// Power handler2
sl@0
    56
//
sl@0
    57
class DTest2PowerHandler : public DPowerHandler
sl@0
    58
	{
sl@0
    59
public:
sl@0
    60
	DTest2PowerHandler();
sl@0
    61
	void PowerUp();
sl@0
    62
	void PowerDown(TPowerState);
sl@0
    63
	};
sl@0
    64
sl@0
    65
class DTestFactory : public DLogicalDevice
sl@0
    66
//
sl@0
    67
// Test LDD factory
sl@0
    68
//
sl@0
    69
	{
sl@0
    70
public:
sl@0
    71
	DTestFactory();
sl@0
    72
	virtual TInt Install(); 					//overriding pure virtual
sl@0
    73
	virtual void GetCaps(TDes8& aDes) const;	//overriding pure virtual
sl@0
    74
	virtual TInt Create(DLogicalChannelBase*& aChannel); 	//overriding pure virtual
sl@0
    75
	};
sl@0
    76
sl@0
    77
class DTest1 : public DLogicalChannelBase
sl@0
    78
//
sl@0
    79
// Test logical channel
sl@0
    80
//
sl@0
    81
	{
sl@0
    82
public:
sl@0
    83
	virtual ~DTest1();
sl@0
    84
protected:
sl@0
    85
	virtual TInt DoCreate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer);
sl@0
    86
	virtual TInt Request(TInt aReqNo, TAny* a1, TAny* a2);
sl@0
    87
	DTest1PowerHandler power1;
sl@0
    88
	DTest2PowerHandler power2;
sl@0
    89
	};
sl@0
    90
sl@0
    91
sl@0
    92
sl@0
    93
DECLARE_STANDARD_LDD()
sl@0
    94
	{
sl@0
    95
	return new DTestFactory;
sl@0
    96
	}
sl@0
    97
sl@0
    98
//
sl@0
    99
// Constructor
sl@0
   100
//
sl@0
   101
DTestFactory::DTestFactory()
sl@0
   102
	{
sl@0
   103
sl@0
   104
	}
sl@0
   105
sl@0
   106
TInt DTestFactory::Create(DLogicalChannelBase*& aChannel)
sl@0
   107
	{
sl@0
   108
//
sl@0
   109
// Create new channel
sl@0
   110
//
sl@0
   111
	aChannel=new DTest1;
sl@0
   112
	return aChannel?KErrNone:KErrNoMemory;
sl@0
   113
	}
sl@0
   114
sl@0
   115
TInt DTestFactory::Install()
sl@0
   116
//
sl@0
   117
// Install the LDD - overriding pure virtual
sl@0
   118
//
sl@0
   119
	{
sl@0
   120
	return SetName(&KLddName);
sl@0
   121
	}
sl@0
   122
sl@0
   123
void DTestFactory::GetCaps(TDes8& /*aDes*/) const
sl@0
   124
//
sl@0
   125
// Get capabilities - overriding pure virtual
sl@0
   126
//
sl@0
   127
	{
sl@0
   128
	}
sl@0
   129
sl@0
   130
TInt DTest1::DoCreate(TInt /*aUnit*/, const TDesC8* /*aInfo*/, const TVersion& /*aVer*/)
sl@0
   131
//
sl@0
   132
// Create channel
sl@0
   133
//
sl@0
   134
	{
sl@0
   135
	//try to remove a handler that hasn't been added yet - should not cause any problems
sl@0
   136
	power1.Remove();
sl@0
   137
	//Add power handlers
sl@0
   138
	power2.Add();
sl@0
   139
	power1.Add();
sl@0
   140
	return KErrNone;
sl@0
   141
	}
sl@0
   142
sl@0
   143
DTest1::~DTest1()
sl@0
   144
//
sl@0
   145
// Destructor
sl@0
   146
//
sl@0
   147
	{
sl@0
   148
	power1.Remove();
sl@0
   149
	power2.Remove();
sl@0
   150
	//try to remove a handler twice - should not cause any problems
sl@0
   151
	power2.Remove();
sl@0
   152
	}
sl@0
   153
sl@0
   154
TInt DTest1::Request(TInt aReqNo, TAny* a1, TAny* a2)
sl@0
   155
	{
sl@0
   156
//
sl@0
   157
// Store status requests and time stamp variable for each power up and power down
sl@0
   158
//
sl@0
   159
sl@0
   160
	if(aReqNo<0)
sl@0
   161
		{
sl@0
   162
		// 'Request' functions...
sl@0
   163
		TRequestStatus* s = (TRequestStatus*)a1;
sl@0
   164
		TAny* args[2];
sl@0
   165
		kumemget32(args,a2,sizeof(args)); // get user side arguments
sl@0
   166
sl@0
   167
		switch(~aReqNo)
sl@0
   168
			{
sl@0
   169
			case RLddTest1::EPOWERDOWN_POWER1:
sl@0
   170
				aStatus_down1 = s;
sl@0
   171
				time_power1down = (TUint*)args[0];
sl@0
   172
				break;
sl@0
   173
sl@0
   174
			case RLddTest1::EPOWERDOWN_POWER2:
sl@0
   175
				aStatus_down2 = s;
sl@0
   176
				time_power2down = (TUint*)args[0];
sl@0
   177
				break;
sl@0
   178
sl@0
   179
			case RLddTest1::EPOWERUP_POWER1:
sl@0
   180
				aStatus_up1 = s;
sl@0
   181
				time_power1up = (TUint*)args[0];
sl@0
   182
				break;
sl@0
   183
sl@0
   184
			case RLddTest1::EPOWERUP_POWER2:
sl@0
   185
				aStatus_up2 = s;
sl@0
   186
				time_power2up = (TUint*)args[0];
sl@0
   187
				break;
sl@0
   188
			}
sl@0
   189
		}
sl@0
   190
	else
sl@0
   191
		{
sl@0
   192
		// 'Control' functions...
sl@0
   193
		switch(aReqNo)
sl@0
   194
			{
sl@0
   195
			// DoControl
sl@0
   196
			case RLddTest1::ESET_SLEEPTIME:
sl@0
   197
				sleepTime = (TUint)a1;
sl@0
   198
				break;
sl@0
   199
			}
sl@0
   200
		}
sl@0
   201
sl@0
   202
	return KErrNone;
sl@0
   203
	}
sl@0
   204
sl@0
   205
DTest1PowerHandler::DTest1PowerHandler():DPowerHandler(KLitPower1)
sl@0
   206
	{
sl@0
   207
//
sl@0
   208
// Power handler1 constructor
sl@0
   209
//
sl@0
   210
	}
sl@0
   211
sl@0
   212
DTest2PowerHandler::DTest2PowerHandler():DPowerHandler(KLitPower2)
sl@0
   213
	{
sl@0
   214
//
sl@0
   215
// Power handler2 constructor
sl@0
   216
//
sl@0
   217
	}
sl@0
   218
sl@0
   219
sl@0
   220
void DTest1PowerHandler::PowerUp()
sl@0
   221
	{
sl@0
   222
//
sl@0
   223
// Sleep for sometime to get different tick counts for comparision.
sl@0
   224
// Copy the tick count to user variable and complete the request
sl@0
   225
//
sl@0
   226
	NKern::Sleep(sleepTime);
sl@0
   227
sl@0
   228
	TUint temp = NKern::TickCount();
sl@0
   229
	kumemput(time_power1up, (const TUint *)&temp, sizeof(temp));
sl@0
   230
sl@0
   231
	Kern::RequestComplete(aStatus_up1, KErrNone);
sl@0
   232
sl@0
   233
	PowerUpDone();
sl@0
   234
sl@0
   235
	}
sl@0
   236
sl@0
   237
void DTest2PowerHandler::PowerUp()
sl@0
   238
	{
sl@0
   239
//
sl@0
   240
// Copy the tick count to user variable and complete the request
sl@0
   241
//
sl@0
   242
sl@0
   243
	TUint temp = NKern::TickCount();
sl@0
   244
	kumemput(time_power2up, (const TUint *)&temp, sizeof(temp));
sl@0
   245
sl@0
   246
	Kern::RequestComplete(aStatus_up2, KErrNone);
sl@0
   247
sl@0
   248
	PowerUpDone();
sl@0
   249
	}
sl@0
   250
sl@0
   251
void DTest1PowerHandler::PowerDown(TPowerState /*aState*/)
sl@0
   252
	{
sl@0
   253
//
sl@0
   254
// Copy the tick count to user variable and complete the request
sl@0
   255
//
sl@0
   256
sl@0
   257
	TUint temp = NKern::TickCount();
sl@0
   258
	kumemput(time_power1down, (const TUint *)&temp, sizeof(temp));
sl@0
   259
sl@0
   260
	Kern::RequestComplete(aStatus_down1, KErrNone);
sl@0
   261
sl@0
   262
	PowerDownDone();
sl@0
   263
	}
sl@0
   264
sl@0
   265
void DTest2PowerHandler::PowerDown(TPowerState /*aState*/)
sl@0
   266
	{
sl@0
   267
//
sl@0
   268
// Sleep for sometime to get different tick counts for comparision.
sl@0
   269
// Copy the tick count to user variable and complete the request
sl@0
   270
//
sl@0
   271
sl@0
   272
	NKern::Sleep(sleepTime);
sl@0
   273
sl@0
   274
	TUint temp = NKern::TickCount();
sl@0
   275
	kumemput(time_power2down, (const TUint *)&temp, sizeof(temp));
sl@0
   276
sl@0
   277
	Kern::RequestComplete(aStatus_down2, KErrNone);
sl@0
   278
sl@0
   279
	PowerDownDone();
sl@0
   280
	}