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\t_khal.cpp
|
|
15 |
// Overview:
|
|
16 |
// Test class Kern HAL APIs
|
|
17 |
// API Information:
|
|
18 |
// Kern::AddHalEntry(), Kern::RemoveHalEntry(), Kern::FindHalEntry()
|
|
19 |
// Details:
|
|
20 |
// - Adds a new HAL handler for EHalGroupPlatformSpecific2
|
|
21 |
// - Tries to add handler for an existing group
|
|
22 |
// - Calls the installed handler
|
|
23 |
// - Tests Find API to find the installed handler
|
|
24 |
// - Removes the handler and tries to remove some fixed HAL group
|
|
25 |
// - Tries to find removed handler
|
|
26 |
// - Tries to call removed handler
|
|
27 |
// Platforms/Drives/Compatibility:
|
|
28 |
// All.
|
|
29 |
// Assumptions/Requirement/Pre-requisites:
|
|
30 |
// Failures and causes:
|
|
31 |
// Base Port information:
|
|
32 |
//
|
|
33 |
//
|
|
34 |
|
|
35 |
#define __E32TEST_EXTENSION__
|
|
36 |
|
|
37 |
#include <e32test.h>
|
|
38 |
#include <e32hal.h>
|
|
39 |
#include <u32hal.h>
|
|
40 |
#include <e32svr.h>
|
|
41 |
#include "d_khal.h"
|
|
42 |
#include <hal.h>
|
|
43 |
|
|
44 |
RLddKHalTest gLdd;
|
|
45 |
GLDEF_D RTest test(_L("T_KHAL - class Kern HAL API test"));
|
|
46 |
|
|
47 |
|
|
48 |
TBool gEntryForDevice0Registered; // indicator whether the device0 got registered
|
|
49 |
TBool gEntryForDeviceXRegistered; // indicator whether the deviceX got registered
|
|
50 |
TInt gTestDeviceNumber; // device number that was registered
|
|
51 |
|
|
52 |
|
|
53 |
void TestAddHalHandler()
|
|
54 |
{
|
|
55 |
TInt r;
|
|
56 |
|
|
57 |
// Try to register PlatformSpecific2 handler for Device 0
|
|
58 |
test.Next(_L("Register new HAL handler - device 0"));
|
|
59 |
r=gLdd.AddHalEntryDevice0();
|
|
60 |
// we dont want to test() the value, since it might actually not be able to register the
|
|
61 |
// default device, if one already exists in the system
|
|
62 |
if (r==KErrNone)
|
|
63 |
{
|
|
64 |
gEntryForDevice0Registered=ETrue;
|
|
65 |
}
|
|
66 |
else
|
|
67 |
{
|
|
68 |
gEntryForDevice0Registered=EFalse;
|
|
69 |
test.Printf(_L("Couldn't register handler for device 0 (r=%d). Some test cases will not be executed"),r);
|
|
70 |
}
|
|
71 |
// lets try again for device0 if succeeded for the first time, should return error
|
|
72 |
if (gEntryForDevice0Registered)
|
|
73 |
{
|
|
74 |
test.Next(_L("Try to register new HAL handler again for Device0"));
|
|
75 |
test_Equal(KErrInUse,gLdd.AddHalEntryDevice0());
|
|
76 |
}
|
|
77 |
|
|
78 |
// Try to register PlatformSpecific2 handler for Device X. Trying for multiple devices, so
|
|
79 |
// it's highly unlikely that baseport has added this many devices for this group.
|
|
80 |
test.Next(_L("Register new HAL handler - device X"));
|
|
81 |
|
|
82 |
r=gLdd.AddHalEntryDeviceX();
|
|
83 |
if (r==KErrNone)
|
|
84 |
{
|
|
85 |
gEntryForDeviceXRegistered = ETrue;
|
|
86 |
}
|
|
87 |
else
|
|
88 |
{
|
|
89 |
gEntryForDeviceXRegistered = EFalse;
|
|
90 |
test.Printf(_L("FAILED to register any device for EHalGroupPlatformSpecific2 (r=%d). Some test cases will not be executed"),r);
|
|
91 |
}
|
|
92 |
|
|
93 |
test_Value(r, (r==KErrNone || r==KErrInUse)); // this should not fail, but if it does, print indication
|
|
94 |
|
|
95 |
if (gEntryForDeviceXRegistered)
|
|
96 |
{
|
|
97 |
gTestDeviceNumber=gLdd.GetRegisteredDeviceNumber();
|
|
98 |
test(gTestDeviceNumber != KErrNotFound);
|
|
99 |
}
|
|
100 |
|
|
101 |
test.Next(_L("Try to register new HAL handler for fixed group (EHalGroupKernel) - should not be possible"));
|
|
102 |
test_Equal(KErrArgument,gLdd.AddHalEntryForExistingFixed());
|
|
103 |
}
|
|
104 |
|
|
105 |
void TestCallHalHandler()
|
|
106 |
{
|
|
107 |
test.Next(_L("Call HAL handler function - device 0"));
|
|
108 |
if (gEntryForDevice0Registered)
|
|
109 |
{
|
|
110 |
test_KErrNone(UserSvr::HalFunction(EHalGroupPlatformSpecific2,RLddKHalTest::ETestHalFunc,0,0));
|
|
111 |
}
|
|
112 |
else
|
|
113 |
{
|
|
114 |
test.Printf(_L("Didn't try to call handler for device 0, since it wasn't registered in the beginning"));
|
|
115 |
}
|
|
116 |
|
|
117 |
test.Next(_L("Call HAL handler function - device X"));
|
|
118 |
if (gEntryForDeviceXRegistered)
|
|
119 |
{
|
|
120 |
test_KErrNone(UserSvr::HalFunction(EHalGroupPlatformSpecific2,RLddKHalTest::ETestHalFunc,0,0,gTestDeviceNumber));
|
|
121 |
}
|
|
122 |
else
|
|
123 |
{
|
|
124 |
test.Printf(_L("Didn't try to call handler for device x, since it wasn't registered in the beginning"));
|
|
125 |
}
|
|
126 |
}
|
|
127 |
|
|
128 |
void TestCallRemovedHalHandler()
|
|
129 |
{
|
|
130 |
TInt r;
|
|
131 |
|
|
132 |
test.Next(_L("Call removed HAL handler function - device 0"));
|
|
133 |
if (gEntryForDevice0Registered)
|
|
134 |
{
|
|
135 |
r=UserSvr::HalFunction(EHalGroupPlatformSpecific2,RLddKHalTest::ETestHalFunc,0,0);
|
|
136 |
test_Compare(r, !=, KErrNone);
|
|
137 |
}
|
|
138 |
else
|
|
139 |
{
|
|
140 |
test.Printf(_L("Didn't try to call removed handler for device 0, since it wasn't registered in the beginning"));
|
|
141 |
}
|
|
142 |
|
|
143 |
test.Next(_L("Call removed HAL handler function - device X"));
|
|
144 |
if (gEntryForDeviceXRegistered)
|
|
145 |
{
|
|
146 |
r=UserSvr::HalFunction(EHalGroupPlatformSpecific2,RLddKHalTest::ETestHalFunc,0,0,gTestDeviceNumber);
|
|
147 |
test_Compare(r, !=, KErrNone);
|
|
148 |
}
|
|
149 |
else
|
|
150 |
{
|
|
151 |
test.Printf(_L("Didn't try to call removed handler for device x, since it wasn't registered in the beginning"));
|
|
152 |
}
|
|
153 |
}
|
|
154 |
|
|
155 |
void TestFindHalHandler()
|
|
156 |
{
|
|
157 |
test.Next(_L("Try with one parameter find (device 0) for own handler"));
|
|
158 |
if (gEntryForDevice0Registered)
|
|
159 |
{
|
|
160 |
test_KErrNone(gLdd.FindHalEntryDevice0());
|
|
161 |
}
|
|
162 |
else
|
|
163 |
{
|
|
164 |
test.Printf(_L("Didn't try to find handler for device 0, since it wasn't registered in the beginning"));
|
|
165 |
}
|
|
166 |
|
|
167 |
test.Next(_L("Try with one parameter find (device 0) for an existing group"));
|
|
168 |
test_KErrNone(gLdd.FindHalEntryDevice0Other()); // should find because trying to get EHalGroupKernel, which must exist
|
|
169 |
|
|
170 |
test.Next(_L("Try with two parameter find (device x)"));
|
|
171 |
if (gEntryForDeviceXRegistered)
|
|
172 |
{
|
|
173 |
test_KErrNone(gLdd.FindHalEntryDeviceX()); // should find because handler for device x has been registered
|
|
174 |
}
|
|
175 |
else
|
|
176 |
{
|
|
177 |
test.Printf(_L("Didn't try to find handler for device X, since it wasn't registered in the beginning"));
|
|
178 |
}
|
|
179 |
}
|
|
180 |
|
|
181 |
void TestRemoveHalHandler()
|
|
182 |
{
|
|
183 |
test.Next(_L("Remove HAL handler - device 0"));
|
|
184 |
if (gEntryForDevice0Registered)
|
|
185 |
{
|
|
186 |
test_KErrNone(gLdd.RemoveHalEntryDevice0());
|
|
187 |
}
|
|
188 |
else
|
|
189 |
{
|
|
190 |
test.Printf(_L("Didn't try to remove handler for device 0, since it wasn't registered in the beginning"));
|
|
191 |
}
|
|
192 |
|
|
193 |
test.Next(_L("Remove HAL handler - device X"));
|
|
194 |
if (gEntryForDeviceXRegistered)
|
|
195 |
{
|
|
196 |
test_KErrNone(gLdd.RemoveHalEntryDeviceX());
|
|
197 |
}
|
|
198 |
else
|
|
199 |
{
|
|
200 |
test.Printf(_L("Didn't try to remove handler for device x, since it wasn't registered in the beginning"));
|
|
201 |
}
|
|
202 |
|
|
203 |
test.Next(_L("Remove fixed HAL handler (EHalGroupKernel) - should not be possible"));
|
|
204 |
test_Equal(KErrArgument,gLdd.RemoveHalEntryExistingFixed());
|
|
205 |
}
|
|
206 |
|
|
207 |
void TestFindRemovedHalHandler()
|
|
208 |
{
|
|
209 |
test.Next(_L("Try with one parameter find (device 0) for removed handler"));
|
|
210 |
if (gEntryForDevice0Registered)
|
|
211 |
{
|
|
212 |
test_Equal(KErrNotFound,gLdd.FindHalEntryDevice0());
|
|
213 |
}
|
|
214 |
else
|
|
215 |
{
|
|
216 |
test.Printf(_L("didn't try to find removed HAL handler for device 0 since it wasn't registered in the beginning"));
|
|
217 |
}
|
|
218 |
|
|
219 |
test.Next(_L("Try with two parameter find (device x) for removed handler"));
|
|
220 |
if (gEntryForDeviceXRegistered)
|
|
221 |
{
|
|
222 |
test_Equal(KErrNotFound,gLdd.FindHalEntryDeviceX());
|
|
223 |
}
|
|
224 |
else
|
|
225 |
{
|
|
226 |
test.Printf(_L("didn't try to find removed HAL handler for device X since it wasn't registered in the beginning"));
|
|
227 |
}
|
|
228 |
}
|
|
229 |
|
|
230 |
void LoadDeviceDriver()
|
|
231 |
{
|
|
232 |
test_KErrNone(User::LoadLogicalDevice(KLddName));
|
|
233 |
test_KErrNone(gLdd.Open());
|
|
234 |
}
|
|
235 |
|
|
236 |
void UnLoadDeviceDriver()
|
|
237 |
{
|
|
238 |
gLdd.Close();
|
|
239 |
test_KErrNone(User::FreeLogicalDevice(KLddName));
|
|
240 |
}
|
|
241 |
|
|
242 |
|
|
243 |
GLDEF_C TInt E32Main()
|
|
244 |
//
|
|
245 |
// Test Kern HAL API
|
|
246 |
//
|
|
247 |
{
|
|
248 |
test.Title();
|
|
249 |
|
|
250 |
test.Start(_L("Test class Kern HAL API functions"));
|
|
251 |
// load the driver
|
|
252 |
LoadDeviceDriver();
|
|
253 |
|
|
254 |
// add handlers for default device (0) and Device X
|
|
255 |
TestAddHalHandler();
|
|
256 |
|
|
257 |
// call handlers that were managed to register
|
|
258 |
TestCallHalHandler();
|
|
259 |
|
|
260 |
// test find APIs
|
|
261 |
TestFindHalHandler();
|
|
262 |
|
|
263 |
// test removal of HAL handlers
|
|
264 |
TestRemoveHalHandler();
|
|
265 |
|
|
266 |
// test find APIs for removed handlers
|
|
267 |
TestFindRemovedHalHandler();
|
|
268 |
|
|
269 |
// try to call removed handlers
|
|
270 |
TestCallRemovedHalHandler();
|
|
271 |
|
|
272 |
// unload the driver
|
|
273 |
UnLoadDeviceDriver();
|
|
274 |
|
|
275 |
test.End();
|
|
276 |
test.Close();
|
|
277 |
return(KErrNone);
|
|
278 |
}
|