author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 11 May 2010 17:28:22 +0300 | |
branch | RCL_3 |
changeset 26 | c734af59ce98 |
parent 19 | 4a8fed1c0ef6 |
child 28 | 5b5d147c7838 |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 2003-2009 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/device/t_usbapi.cpp |
|
15 |
// Overview: |
|
16 |
// USB API Test Program (a standalone USB test program). |
|
17 |
// API Information: |
|
18 |
// Details: |
|
19 |
// - Query whether the platform is operating HS (or it is connected to a HS host) or not, |
|
20 |
// and executes the appropiate tests in each case (see RunTests() for the actual code, |
|
21 |
// state machine enclosed for clarity): |
|
22 |
// - Load and open an EUSBC device driver (logical device) |
|
23 |
// - Setup the USB interface: query device capabilities, setup interface. |
|
24 |
// - Test allocating DMA and double buffering resources with |
|
25 |
// AllocateEndpointResource results in their use being correctly reported by |
|
26 |
// QueryEndpointResourceUse |
|
27 |
// - Test descriptor manipulation: validate the device, configuration, |
|
28 |
// interface, alternate interface, endpoint and string descriptor |
|
29 |
// manipulation. |
|
30 |
// HS: device_qualifier and other_speed_configuation descriptors. |
|
31 |
// - Check and validate the EndpointZeroMaxPacketSizes. |
|
32 |
// - Quick test that calling the following APIs doesn't generate errors: device |
|
33 |
// control, AlternateDeviceStatusNotify, EndpointStatusNotify |
|
34 |
// - Test HaltEndpoint and ClearHaltEndpoint correctly result in endpoint |
|
35 |
// status being reported as stalled/not stalled. |
|
36 |
// - Test OTG extensions: OTG descriptor manipulations; set/get OTG feature |
|
37 |
// - Close and free the logical device. |
|
38 |
// Platforms/Drives/Compatibility: |
|
39 |
// All. |
|
40 |
// Assumptions/Requirement/Pre-requisites: |
|
41 |
// Failures and causes: |
|
42 |
// Base Port information: |
|
43 |
// |
|
44 |
// |
|
45 |
||
46 |
||
47 |
#include <e32test.h> |
|
48 |
#include <e32debug.h> |
|
49 |
#include <hal.h> |
|
50 |
#include <d32usbc.h> |
|
51 |
#include <d32otgdi.h> |
|
52 |
||
53 |
#include "t_usblib.h" |
|
54 |
||
55 |
||
56 |
// --- Local Top Level Variables |
|
57 |
||
58 |
static RTest test(_L("T_USBAPI")); |
|
59 |
static RDevUsbcClient gPort; |
|
60 |
static RUsbOtgDriver gOTG; |
|
61 |
static TBool gSupportsOtg; |
|
62 |
static TBool gSupportsHighSpeed; |
|
19
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
63 |
static TBool gSupportResouceAllocationV2; |
0 | 64 |
static TBool gUsingHighSpeed; |
65 |
static TBool gSoak; |
|
66 |
static TChar gKeychar = 'a'; |
|
67 |
||
68 |
// Store the actual endpoint number(s) of our alternate interface |
|
69 |
static TInt INT_IN_ep = -1; |
|
70 |
||
71 |
_LIT(KUsbLddFilename, "eusbc"); |
|
72 |
_LIT(KOtgdiLddFilename, "otgdi"); |
|
73 |
_LIT(KUsbDeviceName, "Usbc"); |
|
74 |
||
75 |
||
76 |
// --- Local Constants |
|
77 |
||
78 |
static const TInt KUsbDesc_SizeOffset = 0; |
|
79 |
static const TInt KUsbDesc_TypeOffset = 1; |
|
80 |
||
81 |
static const TInt KDevDesc_SpecOffset = 2; |
|
82 |
static const TInt KDevDesc_DevClassOffset = 4; |
|
83 |
static const TInt KDevDesc_DevSubClassOffset = 5; |
|
84 |
static const TInt KDevDesc_DevProtocolOffset = 6; |
|
85 |
static const TInt KDevDesc_Ep0SizeOffset = 7; |
|
86 |
static const TInt KDevDesc_VendorIdOffset = 8; |
|
87 |
static const TInt KDevDesc_ProductIdOffset = 10; |
|
88 |
static const TInt KDevDesc_DevReleaseOffset = 12; |
|
89 |
||
90 |
static const TInt KConfDesc_AttribOffset = 7; |
|
91 |
static const TInt KConfDesc_MaxPowerOffset = 8; |
|
92 |
||
93 |
static const TInt KIfcDesc_SettingOffset = 2; |
|
94 |
static const TInt KIfcDesc_ProtocolOffset = 7; |
|
95 |
||
96 |
static const TInt KEpDesc_PacketSizeOffset = 4; |
|
97 |
static const TInt KEpDesc_IntervalOffset = 6; |
|
98 |
static const TInt KEpDesc_SynchAddressOffset = 8; |
|
99 |
||
100 |
||
101 |
// |
|
102 |
// Helper. |
|
103 |
// |
|
104 |
static TEndpointState QueryEndpointState(TEndpointNumber aEndpoint) |
|
105 |
{ |
|
106 |
TEndpointState ep_state = EEndpointStateUnknown; |
|
107 |
TInt r = gPort.EndpointStatus(aEndpoint, ep_state); |
|
108 |
test(r == KErrNone); |
|
109 |
test.Printf(_L("Endpoint %d state: %s\n"), aEndpoint, |
|
110 |
(ep_state == EEndpointStateNotStalled) ? _S("Not stalled") : |
|
111 |
((ep_state == EEndpointStateStalled) ? _S("Stalled") : |
|
112 |
_S("Unknown..."))); |
|
113 |
return ep_state; |
|
114 |
} |
|
115 |
||
116 |
||
117 |
// --- Class CActiveKeypressNotifier |
|
118 |
||
119 |
class CActiveKeypressNotifier : public CActive |
|
120 |
{ |
|
121 |
public: |
|
122 |
static CActiveKeypressNotifier* NewL(CConsoleBase* aConsole); |
|
123 |
~CActiveKeypressNotifier(); |
|
124 |
void RequestCharacter(); |
|
125 |
void ProcessKeyPressL(TChar aChar); |
|
126 |
private: |
|
127 |
virtual void DoCancel(); |
|
128 |
virtual void RunL(); |
|
129 |
CActiveKeypressNotifier(CConsoleBase* aConsole); |
|
130 |
void ConstructL() {}; |
|
131 |
private: |
|
132 |
CConsoleBase* iConsole; |
|
133 |
}; |
|
134 |
||
135 |
||
136 |
CActiveKeypressNotifier* CActiveKeypressNotifier::NewL(CConsoleBase* aConsole) |
|
137 |
{ |
|
138 |
CActiveKeypressNotifier* self = new (ELeave) CActiveKeypressNotifier(aConsole); |
|
139 |
CleanupStack::PushL(self); |
|
140 |
self->ConstructL(); |
|
141 |
CActiveScheduler::Add(self); |
|
142 |
CleanupStack::Pop(); |
|
143 |
return self; |
|
144 |
} |
|
145 |
||
146 |
||
147 |
CActiveKeypressNotifier::CActiveKeypressNotifier(CConsoleBase* aConsole) |
|
148 |
: CActive(EPriorityNormal), iConsole(aConsole) |
|
149 |
{} |
|
150 |
||
151 |
||
152 |
CActiveKeypressNotifier::~CActiveKeypressNotifier() |
|
153 |
{ |
|
154 |
Cancel(); // base class cancel -> calls our DoCancel |
|
155 |
} |
|
156 |
||
157 |
||
158 |
void CActiveKeypressNotifier::RunL() |
|
159 |
{ |
|
160 |
gKeychar = (static_cast<TChar>(iConsole->KeyCode())); |
|
161 |
RequestCharacter(); |
|
162 |
} |
|
163 |
||
164 |
||
165 |
void CActiveKeypressNotifier::DoCancel() |
|
166 |
{ |
|
167 |
iConsole->ReadCancel(); |
|
168 |
} |
|
169 |
||
170 |
||
171 |
void CActiveKeypressNotifier::RequestCharacter() |
|
172 |
{ |
|
173 |
// A request is issued to the CConsoleBase to accept a character from the keyboard. |
|
174 |
if (IsActive()) |
|
175 |
{ |
|
176 |
return; |
|
177 |
} |
|
178 |
iConsole->Read(iStatus); |
|
179 |
SetActive(); |
|
180 |
} |
|
181 |
||
182 |
||
183 |
// --- Actual Test Functions |
|
184 |
||
185 |
// 2nd Thread helper function |
|
186 |
static TInt TestThreadFunction(TAny* aPtr) |
|
187 |
{ |
|
188 |
RThread* other = static_cast<RThread*>(aPtr); |
|
189 |
RDevUsbcClient port = gPort; |
|
190 |
// Now try to duplicate the USB channel handle |
|
191 |
TInt r = port.Duplicate(*other); |
|
192 |
// Wait for 1 second |
|
193 |
User::After(1000000); |
|
194 |
return r; |
|
195 |
} |
|
196 |
||
197 |
||
198 |
static void OpenChannel() |
|
199 |
{ |
|
200 |
test.Start(_L("Open Channel")); |
|
201 |
||
202 |
test.Next(_L("Load USB LDD")); |
|
203 |
TInt r = User::LoadLogicalDevice(KUsbLddFilename); |
|
204 |
test(r == KErrNone || r == KErrAlreadyExists); |
|
205 |
||
206 |
RDevUsbcClient port1; |
|
207 |
test.Next(_L("Open local USB channel 1")); |
|
208 |
r = port1.Open(0); |
|
209 |
test(r == KErrNone); |
|
210 |
||
211 |
test.Next(_L("Open global USB channel")); |
|
212 |
r = gPort.Open(0); |
|
213 |
test(r == KErrNone); |
|
214 |
||
215 |
RDevUsbcClient port2; |
|
216 |
test.Next(_L("Open local USB channel 2")); |
|
217 |
r = port2.Open(0); |
|
218 |
test(r == KErrNone); |
|
219 |
||
220 |
test.Next(_L("Close USB channel 1")); |
|
221 |
port1.Close(); |
|
222 |
||
223 |
RDevUsbcClient port3; |
|
224 |
test.Next(_L("Open local USB channel 3")); |
|
225 |
r = port3.Open(0); |
|
226 |
test(r == KErrNone); |
|
227 |
||
228 |
test.Next(_L("Close USB channel 2")); |
|
229 |
port2.Close(); |
|
230 |
||
231 |
test.Next(_L("Close USB channel 3")); |
|
232 |
port3.Close(); |
|
233 |
||
234 |
// Check for OTG support |
|
235 |
TBuf8<KUsbDescSize_Otg> otg_desc; |
|
236 |
r = gPort.GetOtgDescriptor(otg_desc); |
|
237 |
test(r == KErrNotSupported || r == KErrNone); |
|
238 |
gSupportsOtg = (r != KErrNotSupported) ? ETrue : EFalse; |
|
239 |
||
240 |
// On an OTG device we have to start the OTG driver, otherwise the Client |
|
241 |
// stack will remain disabled forever. |
|
242 |
if (gSupportsOtg) |
|
243 |
{ |
|
244 |
test.Printf(_L("Running on OTG device: loading OTG driver\n")); |
|
245 |
test.Next(_L("Load OTG LDD")); |
|
246 |
r = User::LoadLogicalDevice(KOtgdiLddFilename); |
|
247 |
test((r == KErrNone) || (r == KErrAlreadyExists)); |
|
248 |
||
249 |
test.Next(_L("Open OTG channel")); |
|
250 |
r = gOTG.Open(); |
|
251 |
test(r == KErrNone); |
|
252 |
||
253 |
test.Next(_L("Start OTG stack")); |
|
254 |
r = gOTG.StartStacks(); |
|
255 |
test(r == KErrNone); |
|
256 |
} |
|
257 |
||
258 |
// Try duplicating channel handle in a second thread |
|
259 |
// (which should not work because we don't support it) |
|
260 |
||
261 |
test.Next(_L("Create 2nd Thread")); |
|
262 |
RThread me; |
|
263 |
TThreadId me_id = me.Id(); |
|
264 |
// We need to open the RThread object, otherwise we'll only get the |
|
265 |
// 'special' handle 0xFFFF8001. |
|
266 |
test(me.Open(me_id) == KErrNone); |
|
267 |
RThread test_thread; |
|
268 |
TBuf<17> name = _L("tusbapitestthread"); |
|
269 |
test(test_thread.Create(name, TestThreadFunction, 0x1000, NULL, &me) == KErrNone); |
|
270 |
test.Next(_L("Logon to 2nd Thread")); |
|
271 |
TRequestStatus stat; |
|
272 |
test_thread.Logon(stat); |
|
273 |
test(stat == KRequestPending); |
|
274 |
test_thread.Resume(); |
|
275 |
test.Next(_L("Wait for 2nd Thread to exit")); |
|
276 |
User::WaitForRequest(stat); |
|
277 |
// Check correct return value of RDevUsbcClient::Duplicate() |
|
278 |
test(stat == KErrAccessDenied); |
|
279 |
test.Next(_L("Close 2nd Thread")); |
|
280 |
test_thread.Close(); |
|
281 |
||
282 |
test.End(); |
|
283 |
} |
|
284 |
||
285 |
||
19
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
286 |
static void TestResourceAllocationV1() |
0 | 287 |
{ |
288 |
test.Start(_L("Test Endpoint Resource Allocation")); |
|
289 |
||
290 |
test.Next(_L("Request DMA resource")); |
|
291 |
const TInt dma = gPort.AllocateEndpointResource(EEndpoint1, EUsbcEndpointResourceDMA); |
|
292 |
TBool res = gPort.QueryEndpointResourceUse(EEndpoint1, EUsbcEndpointResourceDMA); |
|
293 |
test.Printf(_L("DMA on endpoint 1 %s\n"), |
|
294 |
res ? _S("now allocated") : _S("not allocated")); |
|
295 |
if (dma == KErrNone) |
|
296 |
// Only if DMA resource was successfully allocated should we expect truth here: |
|
297 |
test(res); |
|
298 |
else |
|
299 |
test(!res); |
|
300 |
||
301 |
test.Next(_L("Request Double Buffering resource")); |
|
302 |
const TInt db = gPort.AllocateEndpointResource(EEndpoint1, EUsbcEndpointResourceDoubleBuffering); |
|
303 |
res = gPort.QueryEndpointResourceUse(EEndpoint1, EUsbcEndpointResourceDoubleBuffering); |
|
304 |
test.Printf(_L("Double Buffering on endpoint 1 %s\n"), |
|
305 |
res ? _S("now allocated") : _S("not allocated")); |
|
306 |
if (db == KErrNone) |
|
307 |
// Only if DB resource was successfully allocated should we expect truth here: |
|
308 |
test(res); |
|
309 |
else |
|
310 |
test(!res); |
|
311 |
||
312 |
test.Next(_L("Deallocate Double Buffering resource")); |
|
313 |
TInt r = gPort.DeAllocateEndpointResource(EEndpoint1, EUsbcEndpointResourceDoubleBuffering); |
|
314 |
// Whether DB is dynamic or permanent - deallocation (if supported) should always return success: |
|
315 |
if (db == KErrNone) |
|
316 |
test(r == KErrNone); |
|
317 |
else |
|
318 |
test(r != KErrNone); |
|
319 |
res = gPort.QueryEndpointResourceUse(EEndpoint1, EUsbcEndpointResourceDoubleBuffering); |
|
320 |
test.Printf(_L("Double Buffering on endpoint 1 %s\n"), |
|
321 |
res ? _S("still allocated") : _S("not (longer) allocated")); |
|
322 |
||
323 |
test.Next(_L("Deallocate DMA resource")); |
|
324 |
r = gPort.DeAllocateEndpointResource(EEndpoint1, EUsbcEndpointResourceDMA); |
|
325 |
// Whether DMA is dynamic or permanent - deallocation (if supported) should always return success: |
|
326 |
if (dma == KErrNone) |
|
327 |
test(r == KErrNone); |
|
328 |
else |
|
329 |
test(r != KErrNone); |
|
330 |
res = gPort.QueryEndpointResourceUse(EEndpoint1, EUsbcEndpointResourceDMA); |
|
331 |
test.Printf(_L("DMA on endpoint 1 %s\n"), |
|
332 |
res ? _S("still allocated") : _S("not (longer) allocated")); |
|
333 |
||
334 |
test.End(); |
|
335 |
} |
|
336 |
||
337 |
||
338 |
static void SetupInterface() |
|
339 |
{ |
|
340 |
test.Start(_L("Query USB device caps and set up interface")); |
|
341 |
||
342 |
// Device caps |
|
343 |
test.Next(_L("Query USB device caps")); |
|
344 |
TUsbDeviceCaps d_caps; |
|
345 |
TInt r = gPort.DeviceCaps(d_caps); |
|
346 |
test(r == KErrNone); |
|
347 |
TInt n = d_caps().iTotalEndpoints; |
|
348 |
||
349 |
// Global variable - we'll need this value later |
|
350 |
gSupportsHighSpeed = d_caps().iHighSpeed; |
|
19
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
351 |
gSupportResouceAllocationV2 = (d_caps().iFeatureWord1 & KUsbDevCapsFeatureWord1_EndpointResourceAllocV2); |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
352 |
|
0 | 353 |
test.Printf(_L("### USB device capabilities:\n")); |
354 |
test.Printf(_L("Number of endpoints: %d\n"), n); |
|
355 |
test.Printf(_L("Supports Software-Connect: %s\n"), |
|
356 |
d_caps().iConnect ? _S("yes") : _S("no")); |
|
357 |
test.Printf(_L("Device is Self-Powered: %s\n"), |
|
358 |
d_caps().iSelfPowered ? _S("yes") : _S("no")); |
|
359 |
test.Printf(_L("Supports Remote-Wakeup: %s\n"), |
|
360 |
d_caps().iRemoteWakeup ? _S("yes") : _S("no")); |
|
361 |
test.Printf(_L("Supports High-speed: %s\n"), |
|
362 |
gSupportsHighSpeed ? _S("yes") : _S("no")); |
|
363 |
test.Printf(_L("Supports OTG: %s\n"), |
|
364 |
gSupportsOtg ? _S("yes") : _S("no")); |
|
365 |
test.Printf(_L("Supports unpowered cable detection: %s\n"), |
|
366 |
(d_caps().iFeatureWord1 & KUsbDevCapsFeatureWord1_CableDetectWithoutPower) ? |
|
367 |
_S("yes") : _S("no")); |
|
368 |
test.Printf(_L("Supports endpoint resource alloc scheme V2: %s\n"), |
|
19
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
369 |
gSupportResouceAllocationV2 ? _S("yes") : _S("no")); |
0 | 370 |
|
371 |
test(n >= 2); |
|
372 |
test.Printf(_L("(Device has sufficient endpoints.)\n")); |
|
373 |
||
374 |
// Endpoint caps |
|
375 |
test.Next(_L("Query USB endpoint caps")); |
|
376 |
TUsbcEndpointData data[KUsbcMaxEndpoints]; |
|
377 |
TPtr8 dataptr(reinterpret_cast<TUint8*>(data), sizeof(data), sizeof(data)); |
|
378 |
r = gPort.EndpointCaps(dataptr); |
|
379 |
test(r == KErrNone); |
|
380 |
||
381 |
test.Printf(_L("### USB device endpoint capabilities:\n")); |
|
382 |
for (TInt i = 0; i < n; i++) |
|
383 |
{ |
|
384 |
const TUsbcEndpointCaps* caps = &data[i].iCaps; |
|
385 |
test.Printf(_L("Endpoint: SizeMask = 0x%08x TypeDirMask = 0x%08x\n"), |
|
386 |
caps->iSizes, caps->iTypesAndDir); |
|
387 |
if (caps->iHighBandwidth) |
|
388 |
{ |
|
389 |
test.Printf(_L(" (high-speed, high bandwidth endpoint)\n")); |
|
390 |
// Must be HS Int or Iso ep |
|
391 |
test(gSupportsHighSpeed); |
|
392 |
test(caps->iTypesAndDir & (KUsbEpTypeIsochronous | KUsbEpTypeInterrupt)); |
|
393 |
} |
|
394 |
} |
|
395 |
||
396 |
test.Next(_L("Looking for suitable endpoints")); |
|
397 |
// Set the active interface |
|
398 |
TUsbcInterfaceInfoBuf ifc; |
|
399 |
TInt ep_found = 0; |
|
400 |
TBool foundBulkIN = EFalse; |
|
401 |
TBool foundBulkOUT = EFalse; |
|
402 |
for (TInt i = 0; i < n; i++) |
|
403 |
{ |
|
404 |
const TUsbcEndpointCaps* caps = &data[i].iCaps; |
|
405 |
const TInt mps = caps->MaxPacketSize(); |
|
406 |
if (!foundBulkIN && |
|
407 |
(caps->iTypesAndDir & (KUsbEpTypeBulk | KUsbEpDirIn)) == |
|
408 |
(KUsbEpTypeBulk | KUsbEpDirIn)) |
|
409 |
{ |
|
410 |
// EEndpoint1 is going to be our TX (IN, write) endpoint |
|
411 |
ifc().iEndpointData[0].iType = KUsbEpTypeBulk; |
|
412 |
ifc().iEndpointData[0].iDir = KUsbEpDirIn; |
|
413 |
ifc().iEndpointData[0].iSize = mps; |
|
414 |
foundBulkIN = ETrue; |
|
415 |
if (++ep_found == 2) |
|
416 |
break; |
|
417 |
} |
|
418 |
else if (!foundBulkOUT && |
|
419 |
(caps->iTypesAndDir & (KUsbEpTypeBulk | KUsbEpDirOut)) == |
|
420 |
(KUsbEpTypeBulk | KUsbEpDirOut)) |
|
421 |
{ |
|
422 |
// EEndpoint2 is going to be our RX (OUT, read) endpoint |
|
423 |
ifc().iEndpointData[1].iType = KUsbEpTypeBulk; |
|
424 |
ifc().iEndpointData[1].iDir = KUsbEpDirOut; |
|
425 |
ifc().iEndpointData[1].iSize = mps; |
|
426 |
foundBulkOUT = ETrue; |
|
427 |
if (++ep_found == 2) |
|
428 |
break; |
|
429 |
} |
|
430 |
} |
|
431 |
test(ep_found == 2); |
|
432 |
||
433 |
test.Next(_L("Setting up main interface")); |
|
434 |
_LIT16(string, "T_USBAPI Test Interface (Setting 0)"); |
|
435 |
ifc().iString = const_cast<TDesC16*>(&string); |
|
436 |
ifc().iTotalEndpointsUsed = 2; |
|
437 |
ifc().iClass.iClassNum = 0xff; |
|
438 |
ifc().iClass.iSubClassNum = 0xff; |
|
439 |
ifc().iClass.iProtocolNum = 0xff; |
|
440 |
// Set up the interface. |
|
441 |
r = gPort.SetInterface(0, ifc); |
|
442 |
test(r == KErrNone); |
|
443 |
||
444 |
TInt ifc_no = -1; |
|
445 |
r = gPort.GetAlternateSetting(ifc_no); |
|
446 |
test(r == KErrUsbDeviceNotConfigured); |
|
447 |
||
448 |
// Some UDCs won't allow endpoint resource manipulation once the hardware has been |
|
449 |
// configured and turned on. So we do it here & now: |
|
19
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
450 |
if (!gSupportResouceAllocationV2) |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
451 |
{ |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
452 |
TestResourceAllocationV1(); |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
453 |
} |
0 | 454 |
|
455 |
// On the other hand, since some UDCs won't let us test many features which require |
|
456 |
// register access until the USB hardware is powered up (and because it might start |
|
457 |
// out unpowered), we should turn it on here explicitly. |
|
458 |
// (It will be turned off automatically by the PIL after all tests have been run, |
|
459 |
// when the interface gets deleted.) |
|
460 |
test.Next(_L("Powering up UDC (1)")); |
|
461 |
r = gPort.PowerUpUdc(); |
|
462 |
if (!gSupportsOtg) |
|
463 |
{ |
|
464 |
test(r == KErrNone); |
|
465 |
} |
|
466 |
else |
|
467 |
{ |
|
468 |
test((r == KErrNone) || (r == KErrNotReady)); |
|
469 |
} |
|
470 |
if (gSupportsOtg && (r == KErrNotReady)) |
|
471 |
{ |
|
472 |
test.Printf(_L("OTG device but not connected to Host, stopping subtest here.\n")); |
|
473 |
test.End(); |
|
474 |
return; |
|
475 |
} |
|
476 |
// The board might be attached to a PC with HS controller, thus enabling us |
|
477 |
// to test some HS-specific features. For that to work we have to connect |
|
478 |
// the board to the PC. The "Found new device" box that may pop up on the PC |
|
479 |
// in response to this can be ignored (i.e. just closed). |
|
480 |
test.Next(_L("Connecting to Host (1)")); |
|
481 |
r = gPort.DeviceConnectToHost(); |
|
482 |
test(r == KErrNone); |
|
483 |
// Suspend thread to let things get stable on the bus. |
|
484 |
test.Printf(_L("Waiting a short moment...")); |
|
485 |
User::After(2000000); |
|
486 |
test.Printf(_L(" done.\n")); |
|
487 |
||
488 |
// Check the speed of the physical connection (if any). |
|
489 |
gUsingHighSpeed = gPort.CurrentlyUsingHighSpeed(); |
|
490 |
if (gUsingHighSpeed) |
|
491 |
{ |
|
492 |
test(gSupportsHighSpeed); // sane? |
|
493 |
test.Printf(_L("---> USB High-speed Testing\n")); |
|
494 |
} |
|
495 |
else |
|
496 |
{ |
|
497 |
test.Printf(_L("---> USB Full-speed Testing\n")); |
|
498 |
} |
|
499 |
||
500 |
// By pulling down the interface/connection and bringing them up again we |
|
501 |
// simulate a starting/stopping of the USB service by a control app. |
|
502 |
||
503 |
test.Next(_L("Disconnecting from Host")); |
|
504 |
r = gPort.DeviceDisconnectFromHost(); |
|
505 |
test(r == KErrNone); |
|
506 |
||
507 |
test.Next(_L("Releasing interface")); |
|
508 |
r = gPort.ReleaseInterface(0); |
|
509 |
test(r == KErrNone); |
|
510 |
||
19
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
511 |
if (gSupportResouceAllocationV2) |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
512 |
{ |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
513 |
test.Next(_L("setting resource allocation info on endpoint 1 with resource allocation scheme v2")); |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
514 |
ifc().iEndpointData[0].iFeatureWord1 |= KUsbcEndpointInfoFeatureWord1_DMA; |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
515 |
ifc().iEndpointData[0].iFeatureWord1 |= KUsbcEndpointInfoFeatureWord1_DoubleBuffering; |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
516 |
} |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
517 |
|
0 | 518 |
test.Next(_L("Setting interface")); |
519 |
r = gPort.SetInterface(0, ifc); |
|
520 |
test(r == KErrNone); |
|
521 |
||
522 |
// Suspend thread before connecting again. |
|
523 |
test.Printf(_L("Waiting a short moment...")); |
|
524 |
User::After(1000000); |
|
525 |
test.Printf(_L(" done.\n")); |
|
526 |
||
527 |
test.Next(_L("Powering up UDC (2)")); |
|
528 |
r = gPort.PowerUpUdc(); |
|
529 |
if (!gSupportsOtg) |
|
530 |
{ |
|
531 |
test(r == KErrNone); |
|
532 |
} |
|
533 |
else |
|
534 |
{ |
|
535 |
test((r == KErrNone) || (r == KErrNotReady)); |
|
536 |
} |
|
537 |
if (gSupportsOtg && (r == KErrNotReady)) |
|
538 |
{ |
|
539 |
test.Printf(_L("OTG device but not connected to Host, stopping subtest here.\n")); |
|
540 |
test.End(); |
|
541 |
return; |
|
542 |
} |
|
543 |
||
544 |
test.Next(_L("Connecting to Host (2)")); |
|
545 |
r = gPort.DeviceConnectToHost(); |
|
546 |
test(r == KErrNone); |
|
547 |
// Suspend thread to let things get stable on the bus. |
|
548 |
User::After(2000000); |
|
549 |
||
19
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
550 |
if (gSupportResouceAllocationV2) |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
551 |
{ |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
552 |
test.Next(_L("endpoint 1 resource allocation results(resource allocation V2)")); |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
553 |
TBool res = gPort.QueryEndpointResourceUse(EEndpoint1, EUsbcEndpointResourceDoubleBuffering); |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
554 |
test.Printf(_L("Double Buffering on endpoint 1 %s\n"), |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
555 |
res ? _S("now allocated") : _S("not allocated")); |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
556 |
|
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
557 |
res = gPort.QueryEndpointResourceUse(EEndpoint1, EUsbcEndpointResourceDMA); |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
558 |
test.Printf(_L("DMA on endpoint 1 %s\n"), |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
559 |
res ? _S("still allocated") : _S("not allocated")); |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
560 |
} |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
561 |
|
0 | 562 |
test.End(); |
563 |
} |
|
564 |
||
565 |
||
566 |
static void TestDeviceDescriptor() |
|
567 |
{ |
|
568 |
test.Start(_L("Device Descriptor Manipulation")); |
|
569 |
||
570 |
test.Next(_L("GetDeviceDescriptorSize()")); |
|
571 |
TInt desc_size = 0; |
|
572 |
gPort.GetDeviceDescriptorSize(desc_size); |
|
573 |
test(static_cast<TUint>(desc_size) == KUsbDescSize_Device); |
|
574 |
||
575 |
test.Next(_L("GetDeviceDescriptor()")); |
|
576 |
TBuf8<KUsbDescSize_Device> descriptor; |
|
577 |
TInt r = gPort.GetDeviceDescriptor(descriptor); |
|
578 |
test(r == KErrNone); |
|
579 |
||
580 |
test.Next(_L("SetDeviceDescriptor()")); |
|
581 |
// Change the USB spec number to 2.30 |
|
582 |
descriptor[KDevDesc_SpecOffset] = 0x30; |
|
583 |
descriptor[KDevDesc_SpecOffset+1] = 0x02; |
|
584 |
// Change the device vendor ID (VID) to 0x1234 |
|
585 |
descriptor[KDevDesc_VendorIdOffset] = 0x34; // little endian |
|
586 |
descriptor[KDevDesc_VendorIdOffset+1] = 0x12; |
|
587 |
// Change the device product ID (PID) to 0x1111 |
|
588 |
descriptor[KDevDesc_ProductIdOffset] = 0x11; |
|
589 |
descriptor[KDevDesc_ProductIdOffset+1] = 0x11; |
|
590 |
// Change the device release number to 3.05 |
|
591 |
descriptor[KDevDesc_DevReleaseOffset] = 0x05; |
|
592 |
descriptor[KDevDesc_DevReleaseOffset+1] = 0x03; |
|
593 |
r = gPort.SetDeviceDescriptor(descriptor); |
|
594 |
test(r == KErrNone); |
|
595 |
||
596 |
test.Next(_L("GetDeviceDescriptor()")); |
|
597 |
TBuf8<KUsbDescSize_Device> descriptor2; |
|
598 |
r = gPort.GetDeviceDescriptor(descriptor2); |
|
599 |
test(r == KErrNone); |
|
600 |
||
601 |
test.Next(_L("Compare device descriptor with value set")); |
|
602 |
r = descriptor2.Compare(descriptor); |
|
603 |
test(r == KErrNone); |
|
604 |
||
605 |
if (gUsingHighSpeed) |
|
606 |
{ |
|
607 |
// HS only allows one possible packet size. |
|
608 |
test(descriptor[KDevDesc_Ep0SizeOffset] == 64); |
|
609 |
} |
|
610 |
||
611 |
test.End(); |
|
612 |
} |
|
613 |
||
614 |
||
615 |
static void TestDeviceQualifierDescriptor() |
|
616 |
{ |
|
617 |
test.Start(_L("Device_Qualifier Descriptor Manipulation")); |
|
618 |
||
619 |
if (!gSupportsHighSpeed) |
|
620 |
{ |
|
621 |
test.Printf(_L("*** Not supported - skipping Device_Qualifier descriptor tests\n")); |
|
622 |
test.End(); |
|
623 |
return; |
|
624 |
} |
|
625 |
||
626 |
test.Next(_L("GetDeviceQualifierDescriptor()")); |
|
627 |
TBuf8<KUsbDescSize_DeviceQualifier> descriptor; |
|
628 |
TInt r = gPort.GetDeviceQualifierDescriptor(descriptor); |
|
629 |
test(r == KErrNone); |
|
630 |
||
631 |
test.Next(_L("SetDeviceQualifierDescriptor()")); |
|
632 |
// Change the USB spec number to 3.00 |
|
633 |
descriptor[KDevDesc_SpecOffset] = 0x00; |
|
634 |
descriptor[KDevDesc_SpecOffset+1] = 0x03; |
|
635 |
// Change the device class, subclass and protocol codes |
|
636 |
descriptor[KDevDesc_DevClassOffset] = 0xA1; |
|
637 |
descriptor[KDevDesc_DevSubClassOffset] = 0xB2; |
|
638 |
descriptor[KDevDesc_DevProtocolOffset] = 0xC3; |
|
639 |
r = gPort.SetDeviceQualifierDescriptor(descriptor); |
|
640 |
test(r == KErrNone); |
|
641 |
||
642 |
test.Next(_L("GetDeviceQualifierDescriptor()")); |
|
643 |
TBuf8<KUsbDescSize_DeviceQualifier> descriptor2; |
|
644 |
r = gPort.GetDeviceQualifierDescriptor(descriptor2); |
|
645 |
test(r == KErrNone); |
|
646 |
||
647 |
test.Next(_L("Compare Device_Qualifier desc with value set")); |
|
648 |
r = descriptor2.Compare(descriptor); |
|
649 |
test(r == 0); |
|
650 |
||
651 |
if (!gUsingHighSpeed) |
|
652 |
{ |
|
653 |
// HS only allows one possible packet size. |
|
654 |
test(descriptor[KDevDesc_Ep0SizeOffset] == 64); |
|
655 |
} |
|
656 |
||
657 |
test.End(); |
|
658 |
} |
|
659 |
||
660 |
||
661 |
static void TestConfigurationDescriptor() |
|
662 |
{ |
|
663 |
test.Start(_L("Configuration Descriptor Manipulation")); |
|
664 |
||
665 |
test.Next(_L("GetConfigurationDescriptorSize()")); |
|
666 |
TInt desc_size = 0; |
|
667 |
gPort.GetConfigurationDescriptorSize(desc_size); |
|
668 |
test(static_cast<TUint>(desc_size) == KUsbDescSize_Config); |
|
669 |
||
670 |
test.Next(_L("GetConfigurationDescriptor()")); |
|
671 |
TBuf8<KUsbDescSize_Config> descriptor; |
|
672 |
TInt r = gPort.GetConfigurationDescriptor(descriptor); |
|
673 |
test(r == KErrNone); |
|
674 |
||
675 |
test.Next(_L("SetConfigurationDescriptor()")); |
|
676 |
// Invert Remote-Wakup support |
|
677 |
descriptor[KConfDesc_AttribOffset] = (descriptor[KConfDesc_AttribOffset] ^ KUsbDevAttr_RemoteWakeup); |
|
678 |
// Change the reported max power to 200mA (2 * 0x64) |
|
679 |
descriptor[KConfDesc_MaxPowerOffset] = 0x64; |
|
680 |
r = gPort.SetConfigurationDescriptor(descriptor); |
|
681 |
test(r == KErrNone); |
|
682 |
||
683 |
test.Next(_L("GetConfigurationDescriptor()")); |
|
684 |
TBuf8<KUsbDescSize_Config> descriptor2; |
|
685 |
r = gPort.GetConfigurationDescriptor(descriptor2); |
|
686 |
test(r == KErrNone); |
|
687 |
||
688 |
test.Next(_L("Compare configuration desc with value set")); |
|
689 |
r = descriptor2.Compare(descriptor); |
|
690 |
test(r == KErrNone); |
|
691 |
||
692 |
test.End(); |
|
693 |
} |
|
694 |
||
695 |
||
696 |
static void TestOtherSpeedConfigurationDescriptor() |
|
697 |
{ |
|
698 |
test.Start(_L("Other_Speed_Configuration Desc Manipulation")); |
|
699 |
||
700 |
if (!gSupportsHighSpeed) |
|
701 |
{ |
|
702 |
test.Printf(_L("*** Not supported - skipping Other_Speed_Configuration desc tests\n")); |
|
703 |
test.End(); |
|
704 |
return; |
|
705 |
} |
|
706 |
||
707 |
test.Next(_L("GetOtherSpeedConfigurationDescriptor()")); |
|
708 |
TBuf8<KUsbDescSize_OtherSpeedConfig> descriptor; |
|
709 |
TInt r = gPort.GetOtherSpeedConfigurationDescriptor(descriptor); |
|
710 |
test(r == KErrNone); |
|
711 |
||
712 |
test.Next(_L("SetOtherSpeedConfigurationDescriptor()")); |
|
713 |
// Invert Remote-Wakup support |
|
714 |
descriptor[KConfDesc_AttribOffset] = (descriptor[KConfDesc_AttribOffset] ^ KUsbDevAttr_RemoteWakeup); |
|
715 |
// Change the reported max power to 330mA (2 * 0xA5) |
|
716 |
descriptor[KConfDesc_MaxPowerOffset] = 0xA5; |
|
717 |
r = gPort.SetOtherSpeedConfigurationDescriptor(descriptor); |
|
718 |
test(r == KErrNone); |
|
719 |
||
720 |
test.Next(_L("GetOtherSpeedConfigurationDescriptor()")); |
|
721 |
TBuf8<KUsbDescSize_OtherSpeedConfig> descriptor2; |
|
722 |
r = gPort.GetOtherSpeedConfigurationDescriptor(descriptor2); |
|
723 |
test(r == KErrNone); |
|
724 |
||
725 |
test.Next(_L("Compare O_S_Config desc with value set")); |
|
726 |
r = descriptor2.Compare(descriptor); |
|
727 |
test(r == KErrNone); |
|
728 |
||
729 |
test.End(); |
|
730 |
} |
|
731 |
||
732 |
||
733 |
static void TestInterfaceDescriptor() |
|
734 |
{ |
|
735 |
test.Start(_L("Interface Descriptor Manipulation")); |
|
736 |
||
737 |
// First the standard Interface descriptor |
|
738 |
||
739 |
test.Next(_L("GetInterfaceDescriptorSize()")); |
|
740 |
TInt desc_size = 0; |
|
741 |
TInt r = gPort.GetInterfaceDescriptorSize(0, desc_size); |
|
742 |
test(r == KErrNone); |
|
743 |
test(static_cast<TUint>(desc_size) == KUsbDescSize_Interface); |
|
744 |
||
745 |
test.Next(_L("GetInterfaceDescriptor()")); |
|
746 |
TBuf8<KUsbDescSize_Interface> descriptor; |
|
747 |
r = gPort.GetInterfaceDescriptor(0, descriptor); |
|
748 |
test(r == KErrNone); |
|
749 |
||
750 |
test.Next(_L("SetInterfaceDescriptor()")); |
|
751 |
// Change the interface protocol to 0x78(+) |
|
752 |
TUint8 prot = 0x78; |
|
753 |
if (descriptor[KIfcDesc_ProtocolOffset] == prot) |
|
754 |
prot++; |
|
755 |
descriptor[KIfcDesc_ProtocolOffset] = prot; |
|
756 |
r = gPort.SetInterfaceDescriptor(0, descriptor); |
|
757 |
test(r == KErrNone); |
|
758 |
||
759 |
test.Next(_L("GetInterfaceDescriptor()")); |
|
760 |
TBuf8<KUsbDescSize_Interface> descriptor2; |
|
761 |
r = gPort.GetInterfaceDescriptor(0, descriptor2); |
|
762 |
test(r == KErrNone); |
|
763 |
||
764 |
test.Next(_L("Compare interface descriptor with value set")); |
|
765 |
r = descriptor2.Compare(descriptor); |
|
766 |
test(r == KErrNone); |
|
767 |
||
768 |
test.End(); |
|
769 |
} |
|
770 |
||
771 |
||
772 |
static void TestClassSpecificDescriptors() |
|
773 |
{ |
|
774 |
test.Start(_L("Class-specific Descriptor Manipulation")); |
|
775 |
||
776 |
// First a class-specific Interface descriptor |
|
777 |
||
778 |
test.Next(_L("SetCSInterfaceDescriptorBlock()")); |
|
779 |
// choose arbitrary new descriptor size |
|
780 |
const TInt KUsbDescSize_CS_Interface = KUsbDescSize_Interface + 10; |
|
781 |
TBuf8<KUsbDescSize_CS_Interface> cs_ifc_descriptor; |
|
782 |
cs_ifc_descriptor.FillZ(cs_ifc_descriptor.MaxLength()); |
|
783 |
cs_ifc_descriptor[KUsbDesc_SizeOffset] = KUsbDescSize_CS_Interface; |
|
784 |
cs_ifc_descriptor[KUsbDesc_TypeOffset] = KUsbDescType_CS_Interface; |
|
785 |
TInt r = gPort.SetCSInterfaceDescriptorBlock(0, cs_ifc_descriptor); |
|
786 |
test(r == KErrNone); |
|
787 |
||
788 |
test.Next(_L("GetCSInterfaceDescriptorBlockSize()")); |
|
789 |
TInt desc_size = 0; |
|
790 |
r = gPort.GetCSInterfaceDescriptorBlockSize(0, desc_size); |
|
791 |
test(r == KErrNone); |
|
792 |
test(desc_size == KUsbDescSize_CS_Interface); |
|
793 |
||
794 |
test.Next(_L("GetCSInterfaceDescriptorBlock()")); |
|
795 |
TBuf8<KUsbDescSize_CS_Interface> descriptor; |
|
796 |
r = gPort.GetCSInterfaceDescriptorBlock(0, descriptor); |
|
797 |
test(r == KErrNone); |
|
798 |
||
799 |
test.Next(_L("Compare CS ifc descriptor with value set")); |
|
800 |
r = descriptor.Compare(cs_ifc_descriptor); |
|
801 |
test(r == KErrNone); |
|
802 |
||
803 |
// Next a class-specific Endpoint descriptor |
|
804 |
||
805 |
test.Next(_L("SetCSEndpointDescriptorBlock()")); |
|
806 |
// choose arbitrary new descriptor size |
|
807 |
const TInt KUsbDescSize_CS_Endpoint = KUsbDescSize_Endpoint + 5; |
|
808 |
TBuf8<KUsbDescSize_CS_Endpoint> cs_ep_descriptor; |
|
809 |
cs_ep_descriptor.FillZ(cs_ep_descriptor.MaxLength()); |
|
810 |
cs_ep_descriptor[KUsbDesc_SizeOffset] = KUsbDescSize_CS_Endpoint; |
|
811 |
cs_ep_descriptor[KUsbDesc_TypeOffset] = KUsbDescType_CS_Endpoint; |
|
812 |
r = gPort.SetCSEndpointDescriptorBlock(0, 2, cs_ep_descriptor); |
|
813 |
test(r == KErrNone); |
|
814 |
||
815 |
test.Next(_L("GetCSEndpointDescriptorBlockSize()")); |
|
816 |
r = gPort.GetCSEndpointDescriptorBlockSize(0, 2, desc_size); |
|
817 |
test(r == KErrNone); |
|
818 |
test(desc_size == KUsbDescSize_CS_Endpoint); |
|
819 |
||
820 |
test.Next(_L("GetCSEndpointDescriptorBlock()")); |
|
821 |
TBuf8<KUsbDescSize_CS_Endpoint> descriptor2; |
|
822 |
r = gPort.GetCSEndpointDescriptorBlock(0, 2, descriptor2); |
|
823 |
test(r == KErrNone); |
|
824 |
||
825 |
test.Next(_L("Compare CS ep descriptor with value set")); |
|
826 |
r = descriptor2.Compare(cs_ep_descriptor); |
|
827 |
test(r == KErrNone); |
|
828 |
||
829 |
test.End(); |
|
830 |
} |
|
831 |
||
832 |
||
833 |
static void TestAlternateInterfaceManipulation() |
|
834 |
{ |
|
835 |
test.Start(_L("Alternate Interface Setting Manipulation")); |
|
836 |
||
837 |
if (!SupportsAlternateInterfaces()) |
|
838 |
{ |
|
839 |
test.Printf(_L("*** Not supported - skipping alternate interface settings tests\n")); |
|
840 |
test.End(); |
|
841 |
return; |
|
842 |
} |
|
843 |
||
844 |
// Fetch endpoint data (again) |
|
845 |
test.Next(_L("Get endpoint capabilities")); |
|
846 |
TUsbDeviceCaps d_caps; |
|
847 |
TInt r = gPort.DeviceCaps(d_caps); |
|
848 |
test(r == KErrNone); |
|
849 |
const TInt n = d_caps().iTotalEndpoints; |
|
850 |
TUsbcEndpointData data[KUsbcMaxEndpoints]; |
|
851 |
TPtr8 dataptr(reinterpret_cast<TUint8*>(data), sizeof(data), sizeof(data)); |
|
852 |
r = gPort.EndpointCaps(dataptr); |
|
853 |
test(r == KErrNone); |
|
854 |
||
855 |
// Find ep's for alternate ifc setting |
|
856 |
test.Next(_L("Find suitable endpoints")); |
|
857 |
TInt ep_found = 0; |
|
858 |
TBool foundIsoIN = EFalse; |
|
859 |
TBool foundIsoOUT = EFalse; |
|
860 |
TBool foundIntIN = EFalse; |
|
861 |
TUsbcInterfaceInfoBuf ifc; |
|
862 |
||
863 |
// NB! We cannot assume that any specific device has any given set of |
|
864 |
// capabilities, so whilst we try and set an assortment of endpoint types |
|
865 |
// we may not get what we want. |
|
866 |
||
867 |
// Also, note that the endpoint[] array in the interface descriptor |
|
868 |
// must be filled from ep[0]...ep[n-1]. |
|
869 |
||
870 |
for (TInt i = 0; i < n; i++) |
|
871 |
{ |
|
872 |
const TUsbcEndpointCaps* const caps = &data[i].iCaps; |
|
873 |
const TInt mps = caps->MaxPacketSize(); |
|
874 |
if (!foundIsoIN && |
|
875 |
(caps->iTypesAndDir & (KUsbEpTypeIsochronous | KUsbEpDirIn)) == |
|
876 |
(KUsbEpTypeIsochronous | KUsbEpDirIn)) |
|
877 |
{ |
|
878 |
// This is going to be our Iso TX (IN) endpoint |
|
879 |
ifc().iEndpointData[ep_found].iType = KUsbEpTypeIsochronous; |
|
880 |
ifc().iEndpointData[ep_found].iDir = KUsbEpDirIn; |
|
881 |
ifc().iEndpointData[ep_found].iSize = mps; |
|
882 |
ifc().iEndpointData[ep_found].iInterval = 0x01; // 2^(bInterval-1)ms, bInterval must be [1..16] |
|
883 |
ifc().iEndpointData[ep_found].iInterval_Hs = 0x01; // same as for FS |
|
884 |
test.Printf(_L("ISO IN size = %4d (ep %d)\n"), mps, ep_found + 1); |
|
885 |
foundIsoIN = ETrue; |
|
886 |
if (++ep_found == 3) |
|
887 |
break; |
|
888 |
} |
|
889 |
else if (!foundIsoOUT && |
|
890 |
(caps->iTypesAndDir & (KUsbEpTypeIsochronous | KUsbEpDirOut)) == |
|
891 |
(KUsbEpTypeIsochronous | KUsbEpDirOut)) |
|
892 |
{ |
|
893 |
// This is going to be our Iso RX (OUT) endpoint |
|
894 |
ifc().iEndpointData[ep_found].iType = KUsbEpTypeIsochronous; |
|
895 |
ifc().iEndpointData[ep_found].iDir = KUsbEpDirOut; |
|
896 |
ifc().iEndpointData[ep_found].iSize = mps; |
|
897 |
ifc().iEndpointData[ep_found].iInterval = 0x01; // 2^(bInterval-1)ms, bInterval must be [1..16] |
|
898 |
test.Printf(_L("ISO OUT size = %4d (ep %d)\n"), mps, ep_found + 1); |
|
899 |
foundIsoOUT = ETrue; |
|
900 |
if (++ep_found == 3) |
|
901 |
break; |
|
902 |
} |
|
903 |
else if (!foundIntIN && |
|
904 |
(caps->iTypesAndDir & (KUsbEpTypeInterrupt | KUsbEpDirIn)) == |
|
905 |
(KUsbEpTypeInterrupt | KUsbEpDirIn)) |
|
906 |
{ |
|
907 |
// This is going to be our Interrupt TX (IN) endpoint |
|
908 |
ifc().iEndpointData[ep_found].iType = KUsbEpTypeInterrupt; |
|
909 |
ifc().iEndpointData[ep_found].iDir = KUsbEpDirIn; |
|
910 |
ifc().iEndpointData[ep_found].iSize = mps; |
|
911 |
ifc().iEndpointData[ep_found].iInterval = 10; // interval = 10ms, valid range [1..255] |
|
912 |
ifc().iEndpointData[ep_found].iInterval_Hs = 4; // interval = 2^(bInterval-1)ms = 8ms |
|
913 |
ifc().iEndpointData[ep_found].iExtra = 2; // 2 extra bytes for Audio Class EP descriptor |
|
914 |
test.Printf(_L("INT IN size = %4d (ep %d)\n"), mps, ep_found + 1); |
|
915 |
foundIntIN = ETrue; |
|
916 |
INT_IN_ep = ep_found + 1; |
|
917 |
if (++ep_found == 3) |
|
918 |
break; |
|
919 |
} |
|
920 |
} |
|
921 |
||
922 |
// Let's try to add some more Bulk endpoints up to the max # of 5. |
|
923 |
for (TInt i = 0; i < n; i++) |
|
924 |
{ |
|
925 |
TUsbcEndpointCaps& caps = data[i].iCaps; |
|
926 |
const TUint mps = caps.MaxPacketSize(); |
|
927 |
if (caps.iTypesAndDir & KUsbEpTypeBulk) |
|
928 |
{ |
|
929 |
const TUint dir = (caps.iTypesAndDir & KUsbEpDirIn) ? KUsbEpDirIn : KUsbEpDirOut; |
|
930 |
ifc().iEndpointData[ep_found].iType = KUsbEpTypeBulk; |
|
931 |
ifc().iEndpointData[ep_found].iDir = dir; |
|
932 |
if (gUsingHighSpeed) |
|
933 |
{ |
|
934 |
test.Printf(_L("Checking if correct Bulk packet size is reported in HS case\n")); |
|
935 |
test(mps == KUsbEpSize512); // sane? |
|
936 |
} |
|
937 |
// The PSL should in any case also offer the 'legacy' FS size: |
|
938 |
test(caps.iSizes & KUsbEpSize64); |
|
939 |
ifc().iEndpointData[ep_found].iSize = mps; |
|
940 |
test.Printf(_L("BULK %s size = %4d (ep %d)\n"), |
|
941 |
dir == KUsbEpDirIn ? _S("IN ") : _S("OUT"), mps, ep_found + 1); |
|
942 |
if (++ep_found == 5) |
|
943 |
break; |
|
944 |
} |
|
945 |
} |
|
946 |
||
947 |
test.Printf(_L("Total: %d endpoints found for the alt. ifc setting\n"), ep_found); |
|
948 |
if (ep_found < 3) |
|
949 |
{ |
|
950 |
test.Printf(_L("(3 endpoints are at least required. Skipping test...)\n")); |
|
951 |
test.End(); |
|
952 |
return; |
|
953 |
} |
|
954 |
||
955 |
if (!foundIsoIN && !foundIsoOUT) |
|
956 |
{ |
|
957 |
test.Printf(_L("(No Isochronous endpoints found)\n")); |
|
958 |
} |
|
959 |
||
960 |
if (!foundIntIN) |
|
961 |
{ |
|
962 |
test.Printf(_L("(No Interrupt endpoint found)\n")); |
|
963 |
test.Printf(_L("Adjusting endpoint size for later test\n")); |
|
964 |
// We want to make sure that at least one descriptor has the 2 extra bytes. |
|
965 |
// It doesn't matter that this ep could be a Bulk one, or that the 2 Iso ep's might be missing - |
|
966 |
// we just want to test some functionality and we're not going to use this interface in earnest. |
|
967 |
ifc().iEndpointData[2].iExtra = 2; // 2 extra bytes for Audio Class Ep descriptor |
|
968 |
INT_IN_ep = 3; // pretend it's an INT ep |
|
969 |
} |
|
970 |
||
971 |
test.Next(_L("Create alternate interface setting")); |
|
972 |
_LIT16(string, "T_USBAPI Test Interface (Setting 1: Audio)"); |
|
973 |
ifc().iString = const_cast<TDesC16*>(&string); |
|
974 |
ifc().iTotalEndpointsUsed = ep_found; |
|
975 |
ifc().iClass.iClassNum = KUsbAudioInterfaceClassCode; |
|
976 |
ifc().iClass.iSubClassNum = KUsbAudioInterfaceSubclassCode_Audiostreaming; |
|
977 |
ifc().iClass.iProtocolNum = KUsbAudioInterfaceProtocolCode_Pr_Protocol_Undefined; |
|
978 |
r = gPort.SetInterface(1, ifc); |
|
979 |
test(r == KErrNone); |
|
980 |
||
981 |
test.Next(_L("Set alternate setting number to 8")); |
|
982 |
TBuf8<KUsbDescSize_Interface> descriptor; |
|
983 |
r = gPort.GetInterfaceDescriptor(1, descriptor); |
|
984 |
test(r == KErrNone); |
|
985 |
descriptor[KIfcDesc_SettingOffset] = 8; |
|
986 |
r = gPort.SetInterfaceDescriptor(1, descriptor); |
|
987 |
test(r != KErrNone); |
|
988 |
||
989 |
test.Next(_L("Change ifc # in def setting whith alt ifcs")); |
|
990 |
r = gPort.GetInterfaceDescriptor(0, descriptor); |
|
991 |
test(r == KErrNone); |
|
992 |
descriptor[KIfcDesc_SettingOffset] = 8; |
|
993 |
r = gPort.SetInterfaceDescriptor(0, descriptor); |
|
994 |
test(r != KErrNone); |
|
995 |
||
996 |
test.Next(_L("Change the ifc # in default setting to 8")); |
|
997 |
r = gPort.ReleaseInterface(1); |
|
998 |
test(r == KErrNone); |
|
999 |
r = gPort.SetInterfaceDescriptor(0, descriptor); |
|
1000 |
test(r == KErrNone); |
|
1001 |
||
1002 |
test.Next(_L("Create new setting - this should also get #8")); |
|
1003 |
r = gPort.SetInterface(1, ifc); |
|
1004 |
test(r == KErrNone); |
|
1005 |
r = gPort.GetInterfaceDescriptor(1, descriptor); |
|
1006 |
test(r == KErrNone); |
|
1007 |
test(descriptor[KIfcDesc_SettingOffset] == 8); |
|
1008 |
||
1009 |
test.Next(_L("Change the ifc # in default setting to 0")); |
|
1010 |
r = gPort.ReleaseInterface(1); |
|
1011 |
test(r == KErrNone); |
|
1012 |
r = gPort.GetInterfaceDescriptor(0, descriptor); |
|
1013 |
test(r == KErrNone); |
|
1014 |
descriptor[KIfcDesc_SettingOffset] = 0; |
|
1015 |
r = gPort.SetInterfaceDescriptor(0, descriptor); |
|
1016 |
test(r == KErrNone); |
|
1017 |
||
1018 |
test.Next(_L("Create new setting - this should also get #0")); |
|
1019 |
r = gPort.SetInterface(1, ifc); |
|
1020 |
test(r == KErrNone); |
|
1021 |
r = gPort.GetInterfaceDescriptor(1, descriptor); |
|
1022 |
test(r == KErrNone); |
|
1023 |
test(descriptor[KIfcDesc_SettingOffset] == 0); |
|
1024 |
||
1025 |
test.End(); |
|
1026 |
} |
|
1027 |
||
1028 |
||
1029 |
static void TestEndpointDescriptor() |
|
1030 |
{ |
|
1031 |
test.Start(_L("Endpoint Descriptor Manipulation")); |
|
1032 |
||
1033 |
test.Next(_L("GetEndpointDescriptorSize(1)")); |
|
1034 |
TInt epNumber = 1; |
|
1035 |
TInt desc_size = 0; |
|
1036 |
TInt r = gPort.GetEndpointDescriptorSize(0, epNumber, desc_size); |
|
1037 |
test(r == KErrNone); |
|
1038 |
test(static_cast<TUint>(desc_size) == KUsbDescSize_Endpoint); |
|
1039 |
||
1040 |
test.Next(_L("GetEndpointDescriptor(1)")); |
|
1041 |
TBuf8<KUsbDescSize_Endpoint> descriptor; |
|
1042 |
r = gPort.GetEndpointDescriptor(0, epNumber, descriptor); |
|
1043 |
test(r == KErrNone); |
|
1044 |
||
1045 |
test.Next(_L("SetEndpointDescriptor(1)")); |
|
1046 |
// Change the endpoint poll interval |
|
1047 |
TUint8 ival = 0x66; |
|
1048 |
if (descriptor[KEpDesc_IntervalOffset] == ival) |
|
1049 |
ival++; |
|
1050 |
descriptor[KEpDesc_IntervalOffset] = ival; |
|
1051 |
r = gPort.SetEndpointDescriptor(0, epNumber, descriptor); |
|
1052 |
test(r == KErrNone); |
|
1053 |
||
1054 |
test.Next(_L("GetEndpointDescriptor(1)")); |
|
1055 |
TBuf8<KUsbDescSize_Endpoint> descriptor2; |
|
1056 |
r = gPort.GetEndpointDescriptor(0, epNumber, descriptor2); |
|
1057 |
test(r == KErrNone); |
|
1058 |
||
1059 |
test.Next(_L("Compare endpoint descriptor with value set")); |
|
1060 |
r = descriptor2.Compare(descriptor); |
|
1061 |
test(r == KErrNone); |
|
1062 |
||
1063 |
test.Next(_L("Check endpoint max packet size")); |
|
1064 |
const TUint16 ep_size = EpSize(descriptor[KEpDesc_PacketSizeOffset], |
|
1065 |
descriptor[KEpDesc_PacketSizeOffset+1]); |
|
1066 |
test.Printf(_L(" Size: %d\n"), ep_size); |
|
1067 |
if (gUsingHighSpeed) |
|
1068 |
{ |
|
1069 |
// HS Bulk ep can only have one possible packet size. |
|
1070 |
test(ep_size == 512); |
|
1071 |
} |
|
1072 |
else |
|
1073 |
{ |
|
1074 |
// FS Bulk ep cannot be larger than 64 bytes. |
|
1075 |
test(ep_size <= 64); |
|
1076 |
} |
|
1077 |
||
1078 |
test.End(); |
|
1079 |
} |
|
1080 |
||
1081 |
||
1082 |
static void TestExtendedEndpointDescriptor() |
|
1083 |
{ |
|
1084 |
test.Start(_L("Extended Endpoint Descriptor Manipulation")); |
|
1085 |
||
1086 |
if (!SupportsAlternateInterfaces()) |
|
1087 |
{ |
|
1088 |
test.Printf(_L("*** Not supported - skipping Extended Endpoint descriptor tests\n")); |
|
1089 |
test.End(); |
|
1090 |
return; |
|
1091 |
} |
|
1092 |
||
1093 |
// Extended Endpoint Descriptor manipulation (Audio class endpoint) |
|
1094 |
||
1095 |
test.Next(_L("GetEndpointDescriptorSize()")); |
|
1096 |
TInt epNumber = INT_IN_ep; |
|
1097 |
TInt desc_size = 0; |
|
1098 |
TInt r = gPort.GetEndpointDescriptorSize(1, epNumber, desc_size); |
|
1099 |
test(r == KErrNone); |
|
1100 |
test(static_cast<TUint>(desc_size) == KUsbDescSize_AudioEndpoint); |
|
1101 |
||
1102 |
test.Next(_L("GetEndpointDescriptor()")); |
|
1103 |
TBuf8<KUsbDescSize_AudioEndpoint> descriptor; |
|
1104 |
r = gPort.GetEndpointDescriptor(1, epNumber, descriptor); |
|
1105 |
test(r == KErrNone); |
|
1106 |
||
1107 |
test.Next(_L("SetEndpointDescriptor()")); |
|
1108 |
// Change the Audio Endpoint bSynchAddress field |
|
1109 |
TUint8 addr = 0x85; // bogus address |
|
1110 |
if (descriptor[KEpDesc_SynchAddressOffset] == addr) |
|
1111 |
addr++; |
|
1112 |
descriptor[KEpDesc_SynchAddressOffset] = addr; |
|
1113 |
r = gPort.SetEndpointDescriptor(1, epNumber, descriptor); |
|
1114 |
test(r == KErrNone); |
|
1115 |
||
1116 |
test.Next(_L("GetEndpointDescriptor()")); |
|
1117 |
TBuf8<KUsbDescSize_AudioEndpoint> descriptor2; |
|
1118 |
r = gPort.GetEndpointDescriptor(1, epNumber, descriptor2); |
|
1119 |
test(r == KErrNone); |
|
1120 |
||
1121 |
test.Next(_L("Compare endpoint descriptor with value set")); |
|
1122 |
r = descriptor2.Compare(descriptor); |
|
1123 |
test(r == KErrNone); |
|
1124 |
||
1125 |
test.Next(_L("Check endpoint max packet size")); |
|
1126 |
const TUint16 ep_size = EpSize(descriptor[KEpDesc_PacketSizeOffset], |
|
1127 |
descriptor[KEpDesc_PacketSizeOffset+1]); |
|
1128 |
if (gUsingHighSpeed) |
|
1129 |
{ |
|
1130 |
// HS Interrupt ep. |
|
1131 |
test(ep_size <= 1024); |
|
1132 |
} |
|
1133 |
else |
|
1134 |
{ |
|
1135 |
// FS Interrupt ep cannot be larger than 64 bytes. |
|
1136 |
test(ep_size <= 64); |
|
1137 |
} |
|
1138 |
||
1139 |
test.End(); |
|
1140 |
} |
|
1141 |
||
1142 |
||
1143 |
static void TestStandardStringDescriptors() |
|
1144 |
{ |
|
1145 |
test.Start(_L("String Descriptor Manipulation")); |
|
1146 |
||
1147 |
// |
|
1148 |
// --- LANGID code |
|
1149 |
// |
|
1150 |
||
1151 |
test.Next(_L("GetStringDescriptorLangId()")); |
|
1152 |
TUint16 rd_langid_orig; |
|
1153 |
TInt r = gPort.GetStringDescriptorLangId(rd_langid_orig); |
|
1154 |
test(r == KErrNone); |
|
1155 |
test.Printf(_L("Original LANGID code: 0x%04X\n"), rd_langid_orig); |
|
1156 |
||
1157 |
test.Next(_L("SetStringDescriptorLangId()")); |
|
1158 |
TUint16 wr_langid = 0x0809; // English (UK) Language ID |
|
1159 |
if (wr_langid == rd_langid_orig) |
|
1160 |
wr_langid = 0x0444; // Tatar Language ID |
|
1161 |
r = gPort.SetStringDescriptorLangId(wr_langid); |
|
1162 |
test(r == KErrNone); |
|
1163 |
||
1164 |
test.Next(_L("GetStringDescriptorLangId()")); |
|
1165 |
TUint16 rd_langid; |
|
1166 |
r = gPort.GetStringDescriptorLangId(rd_langid); |
|
1167 |
test(r == KErrNone); |
|
1168 |
test.Printf(_L("New LANGID code: 0x%04X\n"), rd_langid); |
|
1169 |
||
1170 |
test.Next(_L("Compare LANGID codes")); |
|
1171 |
test(rd_langid == wr_langid); |
|
1172 |
||
1173 |
test.Next(_L("Restore original LANGID code")); |
|
1174 |
r = gPort.SetStringDescriptorLangId(rd_langid_orig); |
|
1175 |
test(r == KErrNone); |
|
1176 |
r = gPort.GetStringDescriptorLangId(rd_langid); |
|
1177 |
test(r == KErrNone); |
|
1178 |
test(rd_langid == rd_langid_orig); |
|
1179 |
||
1180 |
// |
|
1181 |
// --- Manufacturer string |
|
1182 |
// |
|
1183 |
||
1184 |
test.Next(_L("GetManufacturerStringDescriptor()")); |
|
1185 |
TBuf16<KUsbStringDescStringMaxSize / 2> rd_str_orig; |
|
1186 |
r = gPort.GetManufacturerStringDescriptor(rd_str_orig); |
|
1187 |
test(r == KErrNone || r == KErrNotFound); |
|
1188 |
TBool restore_string; |
|
1189 |
if (r == KErrNone) |
|
1190 |
{ |
|
1191 |
test.Printf(_L("Original Manufacturer string: \"%lS\"\n"), &rd_str_orig); |
|
1192 |
restore_string = ETrue; |
|
1193 |
} |
|
1194 |
else |
|
1195 |
{ |
|
1196 |
test.Printf(_L("No Manufacturer string set\n")); |
|
1197 |
restore_string = EFalse; |
|
1198 |
} |
|
1199 |
||
1200 |
test.Next(_L("SetManufacturerStringDescriptor()")); |
|
1201 |
_LIT16(manufacturer, "Manufacturer Which Manufactures Devices"); |
|
1202 |
TBuf16<KUsbStringDescStringMaxSize / 2> wr_str(manufacturer); |
|
1203 |
r = gPort.SetManufacturerStringDescriptor(wr_str); |
|
1204 |
test(r == KErrNone); |
|
1205 |
||
1206 |
test.Next(_L("GetManufacturerStringDescriptor()")); |
|
1207 |
TBuf16<KUsbStringDescStringMaxSize / 2> rd_str; |
|
1208 |
r = gPort.GetManufacturerStringDescriptor(rd_str); |
|
1209 |
test(r == KErrNone); |
|
1210 |
test.Printf(_L("New Manufacturer string: \"%lS\"\n"), &rd_str); |
|
1211 |
||
1212 |
test.Next(_L("Compare Manufacturer strings")); |
|
1213 |
r = rd_str.Compare(wr_str); |
|
1214 |
test(r == KErrNone); |
|
1215 |
||
1216 |
test.Next(_L("SetManufacturerStringDescriptor()")); |
|
1217 |
_LIT16(manufacturer2, "Different Manufacturer Which Manufactures Different Devices"); |
|
1218 |
wr_str.FillZ(wr_str.MaxLength()); |
|
1219 |
wr_str = manufacturer2; |
|
1220 |
r = gPort.SetManufacturerStringDescriptor(wr_str); |
|
1221 |
test(r == KErrNone); |
|
1222 |
||
1223 |
test.Next(_L("GetManufacturerStringDescriptor()")); |
|
1224 |
rd_str.FillZ(rd_str.MaxLength()); |
|
1225 |
r = gPort.GetManufacturerStringDescriptor(rd_str); |
|
1226 |
test(r == KErrNone); |
|
1227 |
test.Printf(_L("New Manufacturer string: \"%lS\"\n"), &rd_str); |
|
1228 |
||
1229 |
test.Next(_L("Compare Manufacturer strings")); |
|
1230 |
r = rd_str.Compare(wr_str); |
|
1231 |
test(r == KErrNone); |
|
1232 |
||
1233 |
test.Next(_L("RemoveManufacturerStringDescriptor()")); |
|
1234 |
r = gPort.RemoveManufacturerStringDescriptor(); |
|
1235 |
test(r == KErrNone); |
|
1236 |
r = gPort.GetManufacturerStringDescriptor(rd_str); |
|
1237 |
test(r == KErrNotFound); |
|
1238 |
||
1239 |
if (restore_string) |
|
1240 |
{ |
|
1241 |
test.Next(_L("Restore original string")); |
|
1242 |
r = gPort.SetManufacturerStringDescriptor(rd_str_orig); |
|
1243 |
test(r == KErrNone); |
|
1244 |
r = gPort.GetManufacturerStringDescriptor(rd_str); |
|
1245 |
test(r == KErrNone); |
|
1246 |
r = rd_str.Compare(rd_str_orig); |
|
1247 |
test(r == KErrNone); |
|
1248 |
} |
|
1249 |
||
1250 |
// |
|
1251 |
// --- Product string |
|
1252 |
// |
|
1253 |
||
1254 |
test.Next(_L("GetProductStringDescriptor()")); |
|
1255 |
rd_str_orig.FillZ(rd_str.MaxLength()); |
|
1256 |
r = gPort.GetProductStringDescriptor(rd_str_orig); |
|
1257 |
test(r == KErrNone || r == KErrNotFound); |
|
1258 |
if (r == KErrNone) |
|
1259 |
{ |
|
1260 |
test.Printf(_L("Old Product string: \"%lS\"\n"), &rd_str_orig); |
|
1261 |
restore_string = ETrue; |
|
1262 |
} |
|
1263 |
else |
|
1264 |
restore_string = EFalse; |
|
1265 |
||
1266 |
test.Next(_L("SetProductStringDescriptor()")); |
|
1267 |
_LIT16(product, "Product That Was Produced By A Manufacturer"); |
|
1268 |
wr_str.FillZ(wr_str.MaxLength()); |
|
1269 |
wr_str = product; |
|
1270 |
r = gPort.SetProductStringDescriptor(wr_str); |
|
1271 |
test(r == KErrNone); |
|
1272 |
||
1273 |
test.Next(_L("GetProductStringDescriptor()")); |
|
1274 |
rd_str.FillZ(rd_str.MaxLength()); |
|
1275 |
r = gPort.GetProductStringDescriptor(rd_str); |
|
1276 |
test(r == KErrNone); |
|
1277 |
test.Printf(_L("New Product string: \"%lS\"\n"), &rd_str); |
|
1278 |
||
1279 |
test.Next(_L("Compare Product strings")); |
|
1280 |
r = rd_str.Compare(wr_str); |
|
1281 |
test(r == KErrNone); |
|
1282 |
||
1283 |
test.Next(_L("SetProductStringDescriptor()")); |
|
1284 |
_LIT16(product2, "Different Product That Was Produced By A Different Manufacturer"); |
|
1285 |
wr_str.FillZ(wr_str.MaxLength()); |
|
1286 |
wr_str = product2; |
|
1287 |
r = gPort.SetProductStringDescriptor(wr_str); |
|
1288 |
test(r == KErrNone); |
|
1289 |
||
1290 |
test.Next(_L("GetProductStringDescriptor()")); |
|
1291 |
rd_str.FillZ(rd_str.MaxLength()); |
|
1292 |
r = gPort.GetProductStringDescriptor(rd_str); |
|
1293 |
test(r == KErrNone); |
|
1294 |
test.Printf(_L("New Product string: \"%lS\"\n"), &rd_str); |
|
1295 |
||
1296 |
test.Next(_L("Compare Product strings")); |
|
1297 |
r = rd_str.Compare(wr_str); |
|
1298 |
test(r == KErrNone); |
|
1299 |
||
1300 |
test.Next(_L("RemoveProductStringDescriptor()")); |
|
1301 |
r = gPort.RemoveProductStringDescriptor(); |
|
1302 |
test(r == KErrNone); |
|
1303 |
r = gPort.GetProductStringDescriptor(rd_str); |
|
1304 |
test(r == KErrNotFound); |
|
1305 |
||
1306 |
if (restore_string) |
|
1307 |
{ |
|
1308 |
test.Next(_L("Restore original string")); |
|
1309 |
r = gPort.SetProductStringDescriptor(rd_str_orig); |
|
1310 |
test(r == KErrNone); |
|
1311 |
r = gPort.GetProductStringDescriptor(rd_str); |
|
1312 |
test(r == KErrNone); |
|
1313 |
r = rd_str.Compare(rd_str_orig); |
|
1314 |
test(r == KErrNone); |
|
1315 |
} |
|
1316 |
||
1317 |
// |
|
1318 |
// --- Serial Number string |
|
1319 |
// |
|
1320 |
||
1321 |
test.Next(_L("GetSerialNumberStringDescriptor()")); |
|
1322 |
rd_str_orig.FillZ(rd_str.MaxLength()); |
|
1323 |
r = gPort.GetSerialNumberStringDescriptor(rd_str_orig); |
|
1324 |
test(r == KErrNone || r == KErrNotFound); |
|
1325 |
if (r == KErrNone) |
|
1326 |
{ |
|
1327 |
test.Printf(_L("Old Serial Number: \"%lS\"\n"), &rd_str_orig); |
|
1328 |
restore_string = ETrue; |
|
1329 |
} |
|
1330 |
else |
|
1331 |
restore_string = EFalse; |
|
1332 |
||
1333 |
test.Next(_L("SetSerialNumberStringDescriptor()")); |
|
1334 |
_LIT16(serial, "000666000XYZ"); |
|
1335 |
wr_str.FillZ(wr_str.MaxLength()); |
|
1336 |
wr_str = serial; |
|
1337 |
r = gPort.SetSerialNumberStringDescriptor(wr_str); |
|
1338 |
test(r == KErrNone); |
|
1339 |
||
1340 |
test.Next(_L("GetSerialNumberStringDescriptor()")); |
|
1341 |
rd_str.FillZ(rd_str.MaxLength()); |
|
1342 |
r = gPort.GetSerialNumberStringDescriptor(rd_str); |
|
1343 |
test(r == KErrNone); |
|
1344 |
test.Printf(_L("New Serial Number: \"%lS\"\n"), &rd_str); |
|
1345 |
||
1346 |
test.Next(_L("Compare Serial Number strings")); |
|
1347 |
r = rd_str.Compare(wr_str); |
|
1348 |
test(r == KErrNone); |
|
1349 |
||
1350 |
test.Next(_L("SetSerialNumberStringDescriptor()")); |
|
1351 |
_LIT16(serial2, "Y11611193111711111Y"); |
|
1352 |
wr_str.FillZ(wr_str.MaxLength()); |
|
1353 |
wr_str = serial2; |
|
1354 |
r = gPort.SetSerialNumberStringDescriptor(wr_str); |
|
1355 |
test(r == KErrNone); |
|
1356 |
||
1357 |
test.Next(_L("GetSerialNumberStringDescriptor()")); |
|
1358 |
rd_str.FillZ(rd_str.MaxLength()); |
|
1359 |
r = gPort.GetSerialNumberStringDescriptor(rd_str); |
|
1360 |
test(r == KErrNone); |
|
1361 |
test.Printf(_L("New Serial Number: \"%lS\"\n"), &rd_str); |
|
1362 |
||
1363 |
test.Next(_L("Compare Serial Number strings")); |
|
1364 |
r = rd_str.Compare(wr_str); |
|
1365 |
test(r == KErrNone); |
|
1366 |
||
1367 |
test.Next(_L("RemoveSerialNumberStringDescriptor()")); |
|
1368 |
r = gPort.RemoveSerialNumberStringDescriptor(); |
|
1369 |
test(r == KErrNone); |
|
1370 |
r = gPort.GetSerialNumberStringDescriptor(rd_str); |
|
1371 |
test(r == KErrNotFound); |
|
1372 |
||
1373 |
if (restore_string) |
|
1374 |
{ |
|
1375 |
test.Next(_L("Restore original string")); |
|
1376 |
r = gPort.SetSerialNumberStringDescriptor(rd_str_orig); |
|
1377 |
test(r == KErrNone); |
|
1378 |
r = gPort.GetSerialNumberStringDescriptor(rd_str); |
|
1379 |
test(r == KErrNone); |
|
1380 |
r = rd_str.Compare(rd_str_orig); |
|
1381 |
test(r == KErrNone); |
|
1382 |
} |
|
1383 |
||
1384 |
// |
|
1385 |
// --- Configuration string |
|
1386 |
// |
|
1387 |
||
1388 |
test.Next(_L("GetConfigurationStringDescriptor()")); |
|
1389 |
rd_str_orig.FillZ(rd_str.MaxLength()); |
|
1390 |
r = gPort.GetConfigurationStringDescriptor(rd_str_orig); |
|
1391 |
test(r == KErrNone || r == KErrNotFound); |
|
1392 |
if (r == KErrNone) |
|
1393 |
{ |
|
1394 |
test.Printf(_L("Old Configuration string: \"%lS\"\n"), &rd_str_orig); |
|
1395 |
restore_string = ETrue; |
|
1396 |
} |
|
1397 |
else |
|
1398 |
restore_string = EFalse; |
|
1399 |
||
1400 |
test.Next(_L("SetConfigurationStringDescriptor()")); |
|
1401 |
_LIT16(config, "Relatively Simple Configuration That Is Still Useful"); |
|
1402 |
wr_str.FillZ(wr_str.MaxLength()); |
|
1403 |
wr_str = config; |
|
1404 |
r = gPort.SetConfigurationStringDescriptor(wr_str); |
|
1405 |
test(r == KErrNone); |
|
1406 |
||
1407 |
test.Next(_L("GetConfigurationStringDescriptor()")); |
|
1408 |
rd_str.FillZ(rd_str.MaxLength()); |
|
1409 |
r = gPort.GetConfigurationStringDescriptor(rd_str); |
|
1410 |
test(r == KErrNone); |
|
1411 |
test.Printf(_L("New Configuration string: \"%lS\"\n"), &rd_str); |
|
1412 |
||
1413 |
test.Next(_L("Compare Configuration strings")); |
|
1414 |
r = rd_str.Compare(wr_str); |
|
1415 |
test(r == KErrNone); |
|
1416 |
||
1417 |
test.Next(_L("SetConfigurationStringDescriptor()")); |
|
1418 |
_LIT16(config2, "Convenient Configuration That Can Be Very Confusing"); |
|
1419 |
wr_str.FillZ(wr_str.MaxLength()); |
|
1420 |
wr_str = config2; |
|
1421 |
r = gPort.SetConfigurationStringDescriptor(wr_str); |
|
1422 |
test(r == KErrNone); |
|
1423 |
||
1424 |
test.Next(_L("GetConfigurationStringDescriptor()")); |
|
1425 |
rd_str.FillZ(rd_str.MaxLength()); |
|
1426 |
r = gPort.GetConfigurationStringDescriptor(rd_str); |
|
1427 |
test(r == KErrNone); |
|
1428 |
test.Printf(_L("New Configuration string: \"%lS\"\n"), &rd_str); |
|
1429 |
||
1430 |
test.Next(_L("Compare Configuration strings")); |
|
1431 |
r = rd_str.Compare(wr_str); |
|
1432 |
test(r == KErrNone); |
|
1433 |
||
1434 |
test.Next(_L("RemoveConfigurationStringDescriptor()")); |
|
1435 |
r = gPort.RemoveConfigurationStringDescriptor(); |
|
1436 |
test(r == KErrNone); |
|
1437 |
r = gPort.GetConfigurationStringDescriptor(rd_str); |
|
1438 |
test(r == KErrNotFound); |
|
1439 |
||
1440 |
if (restore_string) |
|
1441 |
{ |
|
1442 |
test.Next(_L("Restore original string")); |
|
1443 |
r = gPort.SetConfigurationStringDescriptor(rd_str_orig); |
|
1444 |
test(r == KErrNone); |
|
1445 |
r = gPort.GetConfigurationStringDescriptor(rd_str); |
|
1446 |
test(r == KErrNone); |
|
1447 |
r = rd_str.Compare(rd_str_orig); |
|
1448 |
test(r == KErrNone); |
|
1449 |
} |
|
1450 |
||
1451 |
test.End(); |
|
1452 |
} |
|
1453 |
||
1454 |
||
1455 |
//--------------------------------------------- |
|
1456 |
//! @SYMTestCaseID KBASE-T_USBAPI-0041 |
|
1457 |
//! @SYMTestType UT |
|
1458 |
//! @SYMREQ REQ5662 |
|
1459 |
//! @SYMTestCaseDesc USB Device Driver API extension to support setting of a string descriptor at a specific index |
|
1460 |
//! @SYMTestActions Tests GetStringDescriptor(), SetStringDescriptor() and RemoveStringDescriptor() to verify |
|
1461 |
//! the right values are retrieved, set and deleted at specific positions |
|
1462 |
//! @SYMTestExpectedResults KErrNone in positive testing and KErrNotFound in negative one |
|
1463 |
//! @SYMTestPriority High |
|
1464 |
//! @SYMTestStatus Implemented |
|
1465 |
//--------------------------------------------- |
|
1466 |
static void TestArbitraryStringDescriptors() |
|
1467 |
{ |
|
1468 |
test.Start(_L("Arbitrary String Descriptor Manipulation")); |
|
1469 |
||
1470 |
const TUint8 stridx1 = 0xEE; |
|
1471 |
const TUint8 stridx2 = 0xCC; |
|
1472 |
const TUint8 stridx3 = 0xDD; |
|
1473 |
const TUint8 stridx4 = 0xFF; |
|
1474 |
||
1475 |
// First test string |
|
1476 |
||
1477 |
test.Next(_L("GetStringDescriptor() 1")); |
|
1478 |
TBuf16<KUsbStringDescStringMaxSize / 2> rd_str; |
|
1479 |
TInt r = gPort.GetStringDescriptor(stridx1, rd_str); |
|
1480 |
test(r == KErrNotFound); |
|
1481 |
||
1482 |
test.Next(_L("SetStringDescriptor() 1")); |
|
1483 |
_LIT16(string_one, "Arbitrary String Descriptor Test String 1"); |
|
1484 |
TBuf16<KUsbStringDescStringMaxSize / 2> wr_str(string_one); |
|
1485 |
r = gPort.SetStringDescriptor(stridx1, wr_str); |
|
1486 |
test(r == KErrNone); |
|
1487 |
||
1488 |
test.Next(_L("GetStringDescriptor() 1")); |
|
1489 |
r = gPort.GetStringDescriptor(stridx1, rd_str); |
|
1490 |
test(r == KErrNone); |
|
1491 |
test.Printf(_L("New test string @ idx %d: \"%lS\"\n"), stridx1, &rd_str); |
|
1492 |
||
1493 |
test.Next(_L("Compare test strings 1")); |
|
1494 |
r = rd_str.Compare(wr_str); |
|
1495 |
test(r == KErrNone); |
|
1496 |
||
1497 |
// Second test string |
|
1498 |
||
1499 |
test.Next(_L("GetStringDescriptor() 2")); |
|
1500 |
rd_str.FillZ(rd_str.MaxLength()); |
|
1501 |
r = gPort.GetStringDescriptor(stridx2, rd_str); |
|
1502 |
test(r == KErrNotFound); |
|
1503 |
||
1504 |
test.Next(_L("SetStringDescriptor() 2")); |
|
1505 |
_LIT16(string_two, "Arbitrary String Descriptor Test String 2"); |
|
1506 |
wr_str.FillZ(wr_str.MaxLength()); |
|
1507 |
wr_str = string_two; |
|
1508 |
r = gPort.SetStringDescriptor(stridx2, wr_str); |
|
1509 |
test(r == KErrNone); |
|
1510 |
||
1511 |
// In between we create another interface setting to see what happens |
|
1512 |
// to the existing string descriptor indices. |
|
1513 |
// (We don't have to test this on every platform - |
|
1514 |
// besides, those that don't support alt settings |
|
1515 |
// are by now very rare.) |
|
1516 |
if (SupportsAlternateInterfaces()) |
|
1517 |
{ |
|
1518 |
TUsbcInterfaceInfoBuf ifc; |
|
1519 |
_LIT16(string, "T_USBAPI Bogus Test Interface (Setting 2)"); |
|
1520 |
ifc().iString = const_cast<TDesC16*>(&string); |
|
1521 |
ifc().iTotalEndpointsUsed = 0; |
|
1522 |
TInt r = gPort.SetInterface(2, ifc); |
|
1523 |
test(r == KErrNone); |
|
1524 |
} |
|
1525 |
||
1526 |
test.Next(_L("GetStringDescriptor() 2")); |
|
1527 |
r = gPort.GetStringDescriptor(stridx2, rd_str); |
|
1528 |
test(r == KErrNone); |
|
1529 |
test.Printf(_L("New test string @ idx %d: \"%lS\"\n"), stridx2, &rd_str); |
|
1530 |
||
1531 |
test.Next(_L("Compare test strings 2")); |
|
1532 |
r = rd_str.Compare(wr_str); |
|
1533 |
test(r == KErrNone); |
|
1534 |
||
1535 |
// Third test string |
|
1536 |
||
1537 |
test.Next(_L("GetStringDescriptor() 3")); |
|
1538 |
rd_str.FillZ(rd_str.MaxLength()); |
|
1539 |
r = gPort.GetStringDescriptor(stridx3, rd_str); |
|
1540 |
test(r == KErrNotFound); |
|
1541 |
||
1542 |
test.Next(_L("SetStringDescriptor() 3")); |
|
1543 |
_LIT16(string_three, "Arbitrary String Descriptor Test String 3"); |
|
1544 |
wr_str.FillZ(wr_str.MaxLength()); |
|
1545 |
wr_str = string_three; |
|
1546 |
r = gPort.SetStringDescriptor(stridx3, wr_str); |
|
1547 |
test(r == KErrNone); |
|
1548 |
||
1549 |
test.Next(_L("GetStringDescriptor() 3")); |
|
1550 |
r = gPort.GetStringDescriptor(stridx3, rd_str); |
|
1551 |
test(r == KErrNone); |
|
1552 |
test.Printf(_L("New test string @ idx %d: \"%lS\"\n"), stridx3, &rd_str); |
|
1553 |
||
1554 |
test.Next(_L("Compare test strings 3")); |
|
1555 |
r = rd_str.Compare(wr_str); |
|
1556 |
test(r == KErrNone); |
|
1557 |
||
1558 |
// Remove string descriptors |
|
1559 |
||
1560 |
test.Next(_L("RemoveStringDescriptor() 4")); |
|
1561 |
r = gPort.RemoveStringDescriptor(stridx4); |
|
1562 |
test(r == KErrNotFound); |
|
1563 |
||
1564 |
test.Next(_L("RemoveStringDescriptor() 3")); |
|
1565 |
r = gPort.RemoveStringDescriptor(stridx3); |
|
1566 |
test(r == KErrNone); |
|
1567 |
r = gPort.GetStringDescriptor(stridx3, rd_str); |
|
1568 |
test(r == KErrNotFound); |
|
1569 |
||
1570 |
test.Next(_L("RemoveStringDescriptor() 2")); |
|
1571 |
r = gPort.RemoveStringDescriptor(stridx2); |
|
1572 |
test(r == KErrNone); |
|
1573 |
r = gPort.GetStringDescriptor(stridx2, rd_str); |
|
1574 |
test(r == KErrNotFound); |
|
1575 |
||
1576 |
test.Next(_L("RemoveStringDescriptor() 1")); |
|
1577 |
r = gPort.RemoveStringDescriptor(stridx1); |
|
1578 |
test(r == KErrNone); |
|
1579 |
r = gPort.GetStringDescriptor(stridx1, rd_str); |
|
1580 |
test(r == KErrNotFound); |
|
1581 |
||
1582 |
test.End(); |
|
1583 |
} |
|
1584 |
||
1585 |
||
1586 |
static void TestDescriptorManipulation() |
|
1587 |
{ |
|
1588 |
test.Start(_L("Test USB Descriptor Manipulation")); |
|
1589 |
||
1590 |
TestDeviceDescriptor(); |
|
1591 |
||
1592 |
TestDeviceQualifierDescriptor(); |
|
1593 |
||
1594 |
TestConfigurationDescriptor(); |
|
1595 |
||
1596 |
TestOtherSpeedConfigurationDescriptor(); |
|
1597 |
||
1598 |
TestInterfaceDescriptor(); |
|
1599 |
||
1600 |
TestClassSpecificDescriptors(); |
|
1601 |
||
1602 |
TestAlternateInterfaceManipulation(); |
|
1603 |
||
1604 |
TestEndpointDescriptor(); |
|
1605 |
||
1606 |
TestExtendedEndpointDescriptor(); |
|
1607 |
||
1608 |
TestStandardStringDescriptors(); |
|
1609 |
||
1610 |
TestArbitraryStringDescriptors(); |
|
1611 |
||
1612 |
test.End(); |
|
1613 |
} |
|
1614 |
||
1615 |
||
1616 |
//--------------------------------------------- |
|
1617 |
//! @SYMTestCaseID KBASE-T_USBAPI-0040 |
|
1618 |
//! @SYMTestType UT |
|
1619 |
//! @SYMTestCaseDesc Test OTG extensions |
|
1620 |
//! @SYMTestExpectedResults All APIs behave as expected |
|
1621 |
//! @SYMTestPriority Medium |
|
1622 |
//! @SYMTestStatus Implemented |
|
1623 |
//--------------------------------------------- |
|
1624 |
static void TestOtgExtensions() |
|
1625 |
{ |
|
1626 |
test.Start(_L("Test Some OTG API Extensions")); |
|
1627 |
||
1628 |
// Test OTG descriptor manipulation |
|
1629 |
test.Next(_L("Get OTG Descriptor Size")); |
|
1630 |
TInt size; |
|
1631 |
gPort.GetOtgDescriptorSize(size); |
|
1632 |
test(static_cast<TUint>(size) == KUsbDescSize_Otg); |
|
1633 |
||
1634 |
test.Next(_L("Get OTG Descriptor")); |
|
1635 |
TBuf8<KUsbDescSize_Otg> otgDesc; |
|
1636 |
TInt r = gPort.GetOtgDescriptor(otgDesc); |
|
1637 |
test(r == KErrNotSupported || r == KErrNone); |
|
1638 |
||
1639 |
test.Next(_L("Set OTG Descriptor")); |
|
1640 |
if (r == KErrNotSupported) |
|
1641 |
{ |
|
1642 |
r = gPort.SetOtgDescriptor(otgDesc); |
|
1643 |
test(r == KErrNotSupported); |
|
1644 |
} |
|
1645 |
else |
|
1646 |
{ |
|
1647 |
otgDesc[0] = KUsbDescSize_Otg; |
|
1648 |
otgDesc[1] = KUsbDescType_Otg; |
|
1649 |
// The next step is likely to reset KUsbOtgAttr_HnpSupp |
|
1650 |
otgDesc[2] = KUsbOtgAttr_SrpSupp; |
|
1651 |
r = gPort.SetOtgDescriptor(otgDesc); |
|
1652 |
test(r == KErrNone); |
|
1653 |
TBuf8<KUsbDescSize_Otg> desc; |
|
1654 |
r = gPort.GetOtgDescriptor(desc); |
|
1655 |
test(r == KErrNone); |
|
1656 |
test(desc.Compare(otgDesc) == 0); |
|
1657 |
} |
|
1658 |
||
1659 |
// Test get OTG features |
|
1660 |
test.Next(_L("Get OTG Features")); |
|
1661 |
TUint8 features; |
|
1662 |
r = gPort.GetOtgFeatures(features); |
|
1663 |
if (gSupportsOtg) |
|
1664 |
{ |
|
1665 |
test(r == KErrNone); |
|
1666 |
TBool b_HnpEnable = (features & KUsbOtgAttr_B_HnpEnable) ? ETrue : EFalse; |
|
1667 |
TBool a_HnpSupport = (features & KUsbOtgAttr_A_HnpSupport) ? ETrue : EFalse; |
|
1668 |
TBool a_AltHnpSupport = (features & KUsbOtgAttr_A_AltHnpSupport) ? ETrue : EFalse; |
|
1669 |
test.Printf(_L("### OTG Features:\nB_HnpEnable(%d)\nA_HnpSupport(%d)\nA_Alt_HnpSupport(%d)\n"), |
|
1670 |
b_HnpEnable, a_HnpSupport, a_AltHnpSupport); |
|
1671 |
} |
|
1672 |
else |
|
1673 |
{ |
|
1674 |
test(r == KErrNotSupported); |
|
1675 |
test.Printf(_L("GetOtgFeatures() not supported\n")); |
|
1676 |
} |
|
1677 |
||
1678 |
test.End(); |
|
1679 |
} |
|
1680 |
||
1681 |
||
1682 |
static void TestEndpoint0MaxPacketSizes() |
|
1683 |
{ |
|
1684 |
test.Start(_L("Test Endpoint0 MaxPacketSizes")); |
|
1685 |
||
1686 |
TUint32 sizes = gPort.EndpointZeroMaxPacketSizes(); |
|
1687 |
TInt r = KErrNone; |
|
1688 |
TBool good; |
|
1689 |
TInt mpsize = 0; |
|
1690 |
for (TInt i = 0; i < 32; i++) |
|
1691 |
{ |
|
1692 |
TUint bit = sizes & (1 << i); |
|
1693 |
if (bit != 0) |
|
1694 |
{ |
|
1695 |
switch (bit) |
|
1696 |
{ |
|
1697 |
case KUsbEpSizeCont: |
|
1698 |
good = EFalse; |
|
1699 |
break; |
|
1700 |
case KUsbEpSize8: |
|
1701 |
mpsize = 8; |
|
1702 |
good = ETrue; |
|
1703 |
break; |
|
1704 |
case KUsbEpSize16: |
|
1705 |
mpsize = 16; |
|
1706 |
good = ETrue; |
|
1707 |
break; |
|
1708 |
case KUsbEpSize32: |
|
1709 |
mpsize = 32; |
|
1710 |
good = ETrue; |
|
1711 |
break; |
|
1712 |
case KUsbEpSize64: |
|
1713 |
mpsize = 64; |
|
1714 |
good = ETrue; |
|
1715 |
break; |
|
1716 |
case KUsbEpSize128: |
|
1717 |
case KUsbEpSize256: |
|
1718 |
case KUsbEpSize512: |
|
1719 |
case KUsbEpSize1023: |
|
1720 |
default: |
|
1721 |
good = EFalse; |
|
1722 |
break; |
|
1723 |
} |
|
1724 |
if (good) |
|
1725 |
{ |
|
1726 |
test.Printf(_L("Ep0 supports %d bytes MaxPacketSize\n"), mpsize); |
|
1727 |
} |
|
1728 |
else |
|
1729 |
{ |
|
1730 |
test.Printf(_L("Bad Ep0 size: 0x%08x, failure will occur\n"), bit); |
|
1731 |
r = KErrGeneral; |
|
1732 |
} |
|
1733 |
} |
|
1734 |
} |
|
1735 |
test(r == KErrNone); |
|
1736 |
||
1737 |
test.End(); |
|
1738 |
} |
|
1739 |
||
1740 |
||
1741 |
static void TestDeviceControl() |
|
1742 |
{ |
|
1743 |
test.Start(_L("Test Device Control")); |
|
1744 |
||
1745 |
// This is a quick and crude test, to make sure that we don't get a steaming heap |
|
1746 |
// as a result of calling the device control API's. |
|
1747 |
test.Next(_L("SetDeviceControl()")); |
|
1748 |
TInt r = gPort.SetDeviceControl(); |
|
1749 |
test(r == KErrNone); |
|
1750 |
test.Next(_L("ReleaseDeviceControl()")); |
|
1751 |
r = gPort.ReleaseDeviceControl(); |
|
1752 |
test(r == KErrNone); |
|
1753 |
||
1754 |
test.End(); |
|
1755 |
} |
|
1756 |
||
1757 |
||
1758 |
static void TestAlternateDeviceStatusNotify() |
|
1759 |
{ |
|
1760 |
test.Start(_L("Test Alternate Device Status Notification")); |
|
1761 |
||
1762 |
TRequestStatus dev_status; |
|
1763 |
TUint deviceState = 0xffffffff; // put in a nonsense value |
|
1764 |
test.Next(_L("AlternateDeviceStatusNotify()")); |
|
1765 |
gPort.AlternateDeviceStatusNotify(dev_status, deviceState); |
|
1766 |
test.Next(_L("AlternateDeviceStatusNotifyCancel()")); |
|
1767 |
gPort.AlternateDeviceStatusNotifyCancel(); |
|
1768 |
User::WaitForRequest(dev_status); |
|
1769 |
test(dev_status == KErrCancel || dev_status == KErrNone); |
|
1770 |
if (deviceState & KUsbAlternateSetting) |
|
1771 |
{ |
|
1772 |
TUint setting = (deviceState & ~KUsbAlternateSetting); |
|
1773 |
test.Printf(_L("Alternate setting change to setting %d - unexpected"), setting); |
|
1774 |
test(EFalse); |
|
1775 |
} |
|
1776 |
else |
|
1777 |
{ |
|
1778 |
switch (deviceState) |
|
1779 |
{ |
|
1780 |
case EUsbcDeviceStateUndefined: |
|
1781 |
test.Printf(_L("TestAlternateDeviceStatusNotify: Undefined state\n")); |
|
1782 |
break; |
|
1783 |
case EUsbcDeviceStateAttached: |
|
1784 |
test.Printf(_L("TestAlternateDeviceStatusNotify: Attached state\n")); |
|
1785 |
break; |
|
1786 |
case EUsbcDeviceStatePowered: |
|
1787 |
test.Printf(_L("TestAlternateDeviceStatusNotify: Powered state\n")); |
|
1788 |
break; |
|
1789 |
case EUsbcDeviceStateDefault: |
|
1790 |
test.Printf(_L("TestAlternateDeviceStatusNotify: Default state\n")); |
|
1791 |
break; |
|
1792 |
case EUsbcDeviceStateAddress: |
|
1793 |
test.Printf(_L("TestAlternateDeviceStatusNotify: Address state\n")); |
|
1794 |
break; |
|
1795 |
case EUsbcDeviceStateConfigured: |
|
1796 |
test.Printf(_L("TestAlternateDeviceStatusNotify: Configured state\n")); |
|
1797 |
break; |
|
1798 |
case EUsbcDeviceStateSuspended: |
|
1799 |
test.Printf(_L("TestAlternateDeviceStatusNotify: Suspended state\n")); |
|
1800 |
break; |
|
1801 |
case EUsbcNoState: |
|
1802 |
test.Printf(_L("TestAlternateDeviceStatusNotify: State buffering error\n")); |
|
1803 |
test(EFalse); |
|
1804 |
break; |
|
1805 |
default: |
|
1806 |
test.Printf(_L("TestAlternateDeviceStatusNotify: Unknown state\n")); |
|
1807 |
test(EFalse); |
|
1808 |
} |
|
1809 |
} |
|
1810 |
||
1811 |
test.End(); |
|
1812 |
} |
|
1813 |
||
1814 |
||
1815 |
static void TestEndpointStatusNotify() |
|
1816 |
{ |
|
1817 |
test.Start(_L("Test Endpoint Status Notification")); |
|
1818 |
||
1819 |
TRequestStatus ep_status; |
|
1820 |
TUint epStateBitmap = 0xffffffff; // put in a nonsense value |
|
1821 |
test.Next(_L("EndpointStatusNotify()")); |
|
1822 |
gPort.EndpointStatusNotify(ep_status, epStateBitmap); |
|
1823 |
test.Next(_L("EndpointStatusNotifyCancel()")); |
|
1824 |
gPort.EndpointStatusNotifyCancel(); |
|
1825 |
User::WaitForRequest(ep_status); |
|
1826 |
test(ep_status.Int() == KErrCancel); |
|
1827 |
test.Next(_L("Check endpoint state bitmap returned")); |
|
1828 |
// Our ifc only uses 2 eps + ep0 is automatically granted: |
|
1829 |
const TUint usedEpBitmap = (1 << EEndpoint0 | 1 << EEndpoint1 | 1 << EEndpoint2); |
|
1830 |
// Must not return info about non existent Eps: |
|
1831 |
test((epStateBitmap & ~usedEpBitmap) == 0); |
|
1832 |
for (TInt i = 0; i <= 2; i++) |
|
1833 |
{ |
|
1834 |
if ((epStateBitmap & (1 << i)) == EEndpointStateNotStalled) |
|
1835 |
{ |
|
1836 |
test.Printf(_L("EndpointStatusNotify: Ep %d NOT STALLED\n"), i); |
|
1837 |
} |
|
1838 |
else |
|
1839 |
{ |
|
1840 |
test.Printf(_L("EndpointStatusNotify: Ep %d STALLED\n"), i); |
|
1841 |
} |
|
1842 |
} |
|
1843 |
||
1844 |
test.End(); |
|
1845 |
} |
|
1846 |
||
1847 |
||
1848 |
static void TestEndpointStallStatus() |
|
1849 |
{ |
|
1850 |
test.Start(_L("Test Endpoint Stall Status")); |
|
1851 |
||
1852 |
if (!SupportsEndpointStall()) |
|
1853 |
{ |
|
1854 |
test.Printf(_L("*** Not supported - skipping endpoint stall status tests\n")); |
|
1855 |
test.End(); |
|
1856 |
return; |
|
1857 |
} |
|
1858 |
||
1859 |
test.Next(_L("Endpoint stall status")); |
|
1860 |
TEndpointState epState = EEndpointStateUnknown; |
|
1861 |
QueryEndpointState(EEndpoint1); |
|
1862 |
QueryEndpointState(EEndpoint2); |
|
1863 |
||
1864 |
test.Next(_L("Stall Ep1")); |
|
1865 |
gPort.HaltEndpoint(EEndpoint1); |
|
1866 |
epState = QueryEndpointState(EEndpoint1); |
|
1867 |
test(epState == EEndpointStateStalled); |
|
1868 |
||
1869 |
test.Next(_L("Clear Stall Ep1")); |
|
1870 |
gPort.ClearHaltEndpoint(EEndpoint1); |
|
1871 |
epState = QueryEndpointState(EEndpoint1); |
|
1872 |
test(epState == EEndpointStateNotStalled); |
|
1873 |
||
1874 |
test.Next(_L("Stall Ep2")); |
|
1875 |
gPort.HaltEndpoint(EEndpoint2); |
|
1876 |
epState = QueryEndpointState(EEndpoint2); |
|
1877 |
test(epState == EEndpointStateStalled); |
|
1878 |
||
1879 |
test.Next(_L("Clear Stall Ep2")); |
|
1880 |
gPort.ClearHaltEndpoint(EEndpoint2); |
|
1881 |
epState = QueryEndpointState(EEndpoint2); |
|
1882 |
test(epState == EEndpointStateNotStalled); |
|
1883 |
||
1884 |
test.End(); |
|
1885 |
} |
|
1886 |
||
1887 |
||
1888 |
static void CloseChannel() |
|
1889 |
{ |
|
1890 |
test.Start(_L("Close Channel")); |
|
1891 |
||
1892 |
test.Next(_L("Disconnect Device from Host")); |
|
1893 |
TInt r = gPort.DeviceDisconnectFromHost(); |
|
1894 |
test(r != KErrGeneral); |
|
1895 |
||
1896 |
if (gSupportsOtg) |
|
1897 |
{ |
|
1898 |
test.Next(_L("Stop OTG stack")); |
|
1899 |
gOTG.StopStacks(); |
|
1900 |
test.Next(_L("Close OTG Channel")); |
|
1901 |
gOTG.Close(); |
|
1902 |
test.Next(_L("Free OTG LDD")); |
|
1903 |
r = User::FreeLogicalDevice(RUsbOtgDriver::Name()); |
|
1904 |
test(r == KErrNone); |
|
1905 |
} |
|
1906 |
||
1907 |
test.Next(_L("Close USB Channel")); |
|
1908 |
gPort.Close(); |
|
1909 |
test.Next(_L("Free USB LDD")); |
|
1910 |
r = User::FreeLogicalDevice(KUsbDeviceName); |
|
1911 |
test(r == KErrNone); |
|
1912 |
||
1913 |
test.End(); |
|
1914 |
} |
|
1915 |
||
1916 |
||
1917 |
static const TInt KPrologue = 0; |
|
1918 |
static const TInt KMain = 1; |
|
1919 |
static const TInt KEpilogue = 2; |
|
1920 |
||
1921 |
static TInt RunTests(void* /*aArg*/) |
|
1922 |
{ |
|
1923 |
static TInt step = KPrologue; |
|
1924 |
static TReal loops = 0; |
|
1925 |
||
1926 |
switch (step) |
|
1927 |
{ |
|
1928 |
case KPrologue: |
|
1929 |
test.Title(); |
|
1930 |
// outermost test begin |
|
1931 |
test.Start(_L("Test of USB APIs not requiring a host connection\n")); |
|
1932 |
if (SupportsUsb()) |
|
1933 |
{ |
|
1934 |
step = KMain; |
|
1935 |
} |
|
1936 |
else |
|
1937 |
{ |
|
1938 |
step = KEpilogue; |
|
1939 |
test.Printf(_L("*** Test platform does not support USB - skipping all tests\n")); |
|
1940 |
} |
|
1941 |
return ETrue; |
|
1942 |
case KMain: |
|
1943 |
OpenChannel(); |
|
1944 |
SetupInterface(); |
|
1945 |
TestDescriptorManipulation(); |
|
1946 |
TestOtgExtensions(); |
|
1947 |
TestEndpoint0MaxPacketSizes(); |
|
1948 |
TestDeviceControl(); |
|
1949 |
TestAlternateDeviceStatusNotify(); |
|
1950 |
TestEndpointStatusNotify(); |
|
1951 |
TestEndpointStallStatus(); |
|
1952 |
CloseChannel(); |
|
1953 |
loops++; |
|
1954 |
if (gSoak && (gKeychar != EKeyEscape)) |
|
1955 |
{ |
|
1956 |
step = KMain; |
|
1957 |
} |
|
1958 |
else |
|
1959 |
{ |
|
1960 |
step = KEpilogue; |
|
1961 |
} |
|
1962 |
return ETrue; |
|
1963 |
case KEpilogue: |
|
1964 |
test.Printf(_L("USBAPI tests were run %.0f time(s)\n"), loops); |
|
1965 |
// outermost test end |
|
1966 |
test.End(); |
|
1967 |
CActiveScheduler::Stop(); |
|
1968 |
return EFalse; |
|
1969 |
} |
|
1970 |
return EFalse; |
|
1971 |
} |
|
1972 |
||
1973 |
||
1974 |
static void RunAppL() |
|
1975 |
{ |
|
1976 |
// Create the active scheduler |
|
1977 |
CActiveScheduler* scheduler = new (ELeave) CActiveScheduler(); |
|
1978 |
// Push active scheduler onto the cleanup stack |
|
1979 |
CleanupStack::PushL(scheduler); |
|
1980 |
// Install as the active scheduler |
|
1981 |
CActiveScheduler::Install(scheduler); |
|
1982 |
||
1983 |
// Create console handler |
|
1984 |
CConsoleBase* console = |
|
1985 |
Console::NewL(_L("T_USBAPI - USB Client Test Program"), TSize(KConsFullScreen, KConsFullScreen)); |
|
1986 |
CleanupStack::PushL(console); |
|
1987 |
// Make this one also RTest's console |
|
1988 |
test.SetConsole(console); |
|
1989 |
||
1990 |
// Create keypress notifier active object |
|
1991 |
CActiveKeypressNotifier* keypress_notifier = CActiveKeypressNotifier::NewL(console); |
|
1992 |
test(keypress_notifier != NULL); |
|
1993 |
CleanupStack::PushL(keypress_notifier); |
|
1994 |
keypress_notifier->RequestCharacter(); |
|
1995 |
||
1996 |
// Create long-running test task active object |
|
1997 |
CIdle* active_test = CIdle::NewL(CActive::EPriorityIdle); |
|
1998 |
test(active_test != NULL); |
|
1999 |
CleanupStack::PushL(active_test); |
|
2000 |
active_test->Start(TCallBack(RunTests)); |
|
2001 |
||
2002 |
// Start active scheduler |
|
2003 |
CActiveScheduler::Start(); |
|
2004 |
||
2005 |
// Suspend thread for a short while |
|
2006 |
User::After(1000000); |
|
2007 |
||
2008 |
// active_test, keypress_notifier, console, scheduler |
|
2009 |
CleanupStack::PopAndDestroy(4); |
|
2010 |
||
2011 |
return; |
|
2012 |
} |
|
2013 |
||
2014 |
||
2015 |
GLDEF_C TInt E32Main() |
|
2016 |
{ |
|
2017 |
||
2018 |
CTrapCleanup* cleanup = CTrapCleanup::New(); // get clean-up stack |
|
2019 |
||
2020 |
__UHEAP_MARK; |
|
2021 |
||
2022 |
_LIT(KArg, "soak"); |
|
2023 |
TBuf<64> c; |
|
2024 |
User::CommandLine(c); |
|
2025 |
if (c.CompareF(KArg) == 0) |
|
2026 |
gSoak = ETrue; |
|
2027 |
else |
|
2028 |
gSoak = EFalse; |
|
2029 |
TRAPD(r, RunAppL()); |
|
2030 |
__ASSERT_ALWAYS(!r, User::Panic(_L("E32EX"), r)); |
|
2031 |
||
2032 |
__UHEAP_MARKEND; |
|
2033 |
||
2034 |
delete cleanup; // destroy clean-up stack |
|
2035 |
return KErrNone; |
|
2036 |
} |