231
|
1 |
// Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
|
2 |
// All rights reserved.
|
|
3 |
// This component and the accompanying materials are made available
|
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
|
5 |
// which accompanies this distribution, and is available
|
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
7 |
//
|
|
8 |
// Initial Contributors:
|
|
9 |
// Nokia Corporation - initial contribution.
|
|
10 |
//
|
|
11 |
// Contributors:
|
|
12 |
//
|
|
13 |
// Description:
|
|
14 |
// e32test\system\d_khal.cpp
|
|
15 |
// LDD for testing class Kern HAL APIs
|
|
16 |
// Kern::AddHalEntry(), Kern::RemoveHalEntry(), Kern::FindHalEntry()
|
|
17 |
//
|
|
18 |
//
|
|
19 |
|
|
20 |
#include <kernel/kernel.h>
|
|
21 |
|
|
22 |
#include "d_khal.h"
|
|
23 |
|
|
24 |
#define KMaxDeviceNumber 8 // same as KMaxHalEntries
|
|
25 |
|
|
26 |
TUint gDeviceNumber=1; // Device Number
|
|
27 |
TUint gRegisteredDeviceNumber; // Holds the device number which we managed to register for
|
|
28 |
TBool gEntryForDevice0Registered; // indicator whether the device0 got registered
|
|
29 |
TBool gEntryForDeviceXRegistered; // States HAL Entry Successfully registered or not
|
|
30 |
TBool gFirstCall=ETrue; // for add function, this tells if this is first call or not
|
|
31 |
|
|
32 |
class DKHalLDDTestFactory : public DLogicalDevice
|
|
33 |
//
|
|
34 |
// Test LDD factory
|
|
35 |
//
|
|
36 |
{
|
|
37 |
public:
|
|
38 |
DKHalLDDTestFactory();
|
|
39 |
virtual TInt Install(); //overriding pure virtual
|
|
40 |
virtual void GetCaps(TDes8& aDes) const; //overriding pure virtual
|
|
41 |
virtual TInt Create(DLogicalChannelBase*& aChannel); //overriding pure virtual
|
|
42 |
};
|
|
43 |
|
|
44 |
class DKHalLDDTestChannel : public DLogicalChannelBase
|
|
45 |
//
|
|
46 |
// Test logical channel
|
|
47 |
//
|
|
48 |
{
|
|
49 |
public:
|
|
50 |
virtual ~DKHalLDDTestChannel();
|
|
51 |
protected:
|
|
52 |
virtual TInt DoCreate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer);
|
|
53 |
virtual TInt Request(TInt aReqNo, TAny* a1, TAny* a2);
|
|
54 |
};
|
|
55 |
|
|
56 |
|
|
57 |
LOCAL_C TInt halFunction0(TAny* /*aPtr*/, TInt aFunction, TAny* /*a1*/, TAny* /*a2*/)
|
|
58 |
{
|
|
59 |
TInt r=KErrNotSupported;
|
|
60 |
|
|
61 |
switch(aFunction)
|
|
62 |
{
|
|
63 |
case RLddKHalTest::ETestHalFunc:
|
|
64 |
Kern::Printf("HAL function0 called successfully !");
|
|
65 |
r=KErrNone; // just return KErrNone
|
|
66 |
break;
|
|
67 |
default:
|
|
68 |
break;
|
|
69 |
}
|
|
70 |
return r;
|
|
71 |
}
|
|
72 |
|
|
73 |
|
|
74 |
LOCAL_C TInt halFunctionX(TAny* /*aPtr*/, TInt aFunction, TAny* /*a1*/, TAny* /*a2*/)
|
|
75 |
{
|
|
76 |
TInt r=KErrNotSupported;
|
|
77 |
|
|
78 |
switch(aFunction)
|
|
79 |
{
|
|
80 |
case RLddKHalTest::ETestHalFunc:
|
|
81 |
Kern::Printf("HAL functionX called successfully !");
|
|
82 |
r=KErrNone; // just return KErrNone
|
|
83 |
break;
|
|
84 |
default:
|
|
85 |
break;
|
|
86 |
}
|
|
87 |
return r;
|
|
88 |
}
|
|
89 |
|
|
90 |
DECLARE_STANDARD_LDD()
|
|
91 |
{
|
|
92 |
return new DKHalLDDTestFactory;
|
|
93 |
}
|
|
94 |
|
|
95 |
//
|
|
96 |
// Constructor
|
|
97 |
//
|
|
98 |
DKHalLDDTestFactory::DKHalLDDTestFactory()
|
|
99 |
{
|
|
100 |
}
|
|
101 |
|
|
102 |
TInt DKHalLDDTestFactory::Create(DLogicalChannelBase*& aChannel)
|
|
103 |
{
|
|
104 |
//
|
|
105 |
// Create new channel
|
|
106 |
//
|
|
107 |
aChannel=new DKHalLDDTestChannel;
|
|
108 |
return aChannel?KErrNone:KErrNoMemory;
|
|
109 |
}
|
|
110 |
|
|
111 |
TInt DKHalLDDTestFactory::Install()
|
|
112 |
//
|
|
113 |
// Install the LDD - overriding pure virtual
|
|
114 |
{
|
|
115 |
return SetName(&KLddName);
|
|
116 |
}
|
|
117 |
|
|
118 |
void DKHalLDDTestFactory::GetCaps(TDes8& /*aDes*/) const
|
|
119 |
//
|
|
120 |
// Get capabilities - overriding pure virtual
|
|
121 |
//
|
|
122 |
{
|
|
123 |
}
|
|
124 |
|
|
125 |
TInt DKHalLDDTestChannel::DoCreate(TInt /*aUnit*/, const TDesC8* /*aInfo*/, const TVersion& /*aVer*/)
|
|
126 |
//
|
|
127 |
// Create channel
|
|
128 |
//
|
|
129 |
{
|
|
130 |
return KErrNone;
|
|
131 |
}
|
|
132 |
|
|
133 |
DKHalLDDTestChannel::~DKHalLDDTestChannel()
|
|
134 |
//
|
|
135 |
// Destructor
|
|
136 |
//
|
|
137 |
{
|
|
138 |
}
|
|
139 |
|
|
140 |
TInt DKHalLDDTestChannel::Request(TInt aReqNo, TAny* /*a1*/, TAny* /*a2*/)
|
|
141 |
{
|
|
142 |
TInt r=KErrNone;
|
|
143 |
switch(aReqNo)
|
|
144 |
{
|
|
145 |
case RLddKHalTest::EAddHalEntryDevice0:
|
|
146 |
{
|
|
147 |
// try to register the halfunction for PlatformSpecific category, device 0
|
|
148 |
NKern::ThreadEnterCS();
|
|
149 |
r=Kern::AddHalEntry(EHalGroupPlatformSpecific2,halFunction0,this);
|
|
150 |
NKern::ThreadLeaveCS();
|
|
151 |
//this function gets called twice, second time must not changed these values
|
|
152 |
if (gFirstCall)
|
|
153 |
{
|
|
154 |
if (r==KErrNone)
|
|
155 |
{
|
|
156 |
gEntryForDevice0Registered=ETrue;
|
|
157 |
}
|
|
158 |
else
|
|
159 |
{
|
|
160 |
gEntryForDevice0Registered=EFalse;
|
|
161 |
}
|
|
162 |
gFirstCall=EFalse;
|
|
163 |
}
|
|
164 |
|
|
165 |
break;
|
|
166 |
}
|
|
167 |
case RLddKHalTest::EAddHalEntryDeviceX:
|
|
168 |
{
|
|
169 |
// try to register the halfunction for PlatformSpecific category, device x
|
|
170 |
NKern::ThreadEnterCS();
|
|
171 |
do
|
|
172 |
{
|
|
173 |
r=Kern::AddHalEntry(EHalGroupPlatformSpecific2,halFunctionX,this,gDeviceNumber);
|
|
174 |
}
|
|
175 |
while((r==KErrInUse) && (++gDeviceNumber < KMaxDeviceNumber));
|
|
176 |
NKern::ThreadLeaveCS();
|
|
177 |
|
|
178 |
if((gDeviceNumber < KMaxDeviceNumber) && (r==KErrNone))
|
|
179 |
{
|
|
180 |
gEntryForDeviceXRegistered=ETrue;
|
|
181 |
gRegisteredDeviceNumber=gDeviceNumber;
|
|
182 |
}
|
|
183 |
else
|
|
184 |
{
|
|
185 |
gEntryForDeviceXRegistered=EFalse;
|
|
186 |
r=KErrInUse;
|
|
187 |
}
|
|
188 |
|
|
189 |
break;
|
|
190 |
}
|
|
191 |
case RLddKHalTest::EAddHalEntryForExistingFixed:
|
|
192 |
{
|
|
193 |
// try to add HAL entry for Kernel, should fail
|
|
194 |
NKern::ThreadEnterCS();
|
|
195 |
r=Kern::AddHalEntry(EHalGroupKernel,halFunction0,this);
|
|
196 |
NKern::ThreadLeaveCS();
|
|
197 |
break;
|
|
198 |
}
|
|
199 |
case RLddKHalTest::ERemoveHalEntryDevice0:
|
|
200 |
{
|
|
201 |
// try to remove the registered halfunction for device 0
|
|
202 |
if(gEntryForDevice0Registered)
|
|
203 |
r=Kern::RemoveHalEntry(EHalGroupPlatformSpecific2);
|
|
204 |
|
|
205 |
break;
|
|
206 |
}
|
|
207 |
case RLddKHalTest::ERemoveHalEntryDeviceX:
|
|
208 |
{
|
|
209 |
// try to remove the registered halfunction for device x
|
|
210 |
if(gEntryForDeviceXRegistered)
|
|
211 |
r=Kern::RemoveHalEntry(EHalGroupPlatformSpecific2,gRegisteredDeviceNumber);
|
|
212 |
break;
|
|
213 |
}
|
|
214 |
case RLddKHalTest::ERemoveHalEntryExistingFixed:
|
|
215 |
{
|
|
216 |
// try to remove EGroupHalKernel. This operation should return an error
|
|
217 |
r=Kern::RemoveHalEntry(EHalGroupKernel);
|
|
218 |
break;
|
|
219 |
}
|
|
220 |
case RLddKHalTest::EGetRegisteredDeviceNumber:
|
|
221 |
{
|
|
222 |
// return the device number which we managed to register
|
|
223 |
if(gEntryForDeviceXRegistered)
|
|
224 |
{
|
|
225 |
r=gRegisteredDeviceNumber;
|
|
226 |
}
|
|
227 |
else
|
|
228 |
{
|
|
229 |
r=KErrNotFound;
|
|
230 |
}
|
|
231 |
break;
|
|
232 |
}
|
|
233 |
case RLddKHalTest::EFindHalEntryDevice0:
|
|
234 |
{
|
|
235 |
SHalEntry* pEntry=Kern::FindHalEntry(EHalGroupPlatformSpecific2);
|
|
236 |
// returns valid pEntry if EAddHalEntryForDevice0 managed to register
|
|
237 |
// an entry earlier
|
|
238 |
if (pEntry && pEntry->iFunction!=NULL)
|
|
239 |
{
|
|
240 |
r=KErrNone;
|
|
241 |
}
|
|
242 |
else
|
|
243 |
{
|
|
244 |
r=KErrNotFound;
|
|
245 |
}
|
|
246 |
break;
|
|
247 |
}
|
|
248 |
case RLddKHalTest::EFindHalEntryDevice0Other:
|
|
249 |
{
|
|
250 |
SHalEntry* pEntry=Kern::FindHalEntry(EHalGroupKernel);
|
|
251 |
//try to find an existing HAL group (kernel must exist)
|
|
252 |
if (pEntry && pEntry->iFunction!=NULL)
|
|
253 |
{
|
|
254 |
r=KErrNone;
|
|
255 |
}
|
|
256 |
else
|
|
257 |
{
|
|
258 |
r=KErrNotFound;
|
|
259 |
}
|
|
260 |
break;
|
|
261 |
}
|
|
262 |
case RLddKHalTest::EFindHalEntryDeviceX:
|
|
263 |
{
|
|
264 |
SHalEntry* pEntry=Kern::FindHalEntry(EHalGroupPlatformSpecific2,gRegisteredDeviceNumber);
|
|
265 |
// Should return valid pEntry if EAddHalEntryForDeviceX managed to register
|
|
266 |
// one earlier
|
|
267 |
if (pEntry && pEntry->iFunction!=NULL)
|
|
268 |
{
|
|
269 |
r=KErrNone;
|
|
270 |
}
|
|
271 |
else
|
|
272 |
{
|
|
273 |
r=KErrNotFound;
|
|
274 |
}
|
|
275 |
break;
|
|
276 |
}
|
|
277 |
|
|
278 |
default:
|
|
279 |
r=KErrNotSupported;
|
|
280 |
break;
|
|
281 |
}
|
|
282 |
|
|
283 |
return r;
|
|
284 |
}
|