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