253
|
1 |
// Copyright (c) 2007-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 |
// @file PBASE-T_USBDI-1236.cpp
|
|
15 |
// @internalComponent
|
|
16 |
//
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
#include "PBASE-T_USBDI-1236.h"
|
|
21 |
#include <d32usbc.h>
|
|
22 |
#include <d32usbdescriptors.h>
|
|
23 |
#include "testdebug.h"
|
|
24 |
#include "TestPolicy.h"
|
253
|
25 |
#include "OstTraceDefinitions.h"
|
|
26 |
#ifdef OST_TRACE_COMPILER_IN_USE
|
|
27 |
#include "PBASE-T_USBDI-1236Traces.h"
|
|
28 |
#endif
|
0
|
29 |
|
|
30 |
namespace NUnitTesting_USBDI
|
|
31 |
{
|
|
32 |
|
|
33 |
_LIT(KTestCaseId,"PBASE-T_USBDI-1236");
|
|
34 |
const TFunctorTestCase<CUT_PBASE_T_USBDI_1236,TBool> CUT_PBASE_T_USBDI_1236::iFunctor(KTestCaseId);
|
|
35 |
|
|
36 |
CUT_PBASE_T_USBDI_1236* CUT_PBASE_T_USBDI_1236::NewL(TBool aHostRole)
|
|
37 |
{
|
253
|
38 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_1236_NEWL_ENTRY, aHostRole );
|
0
|
39 |
CUT_PBASE_T_USBDI_1236* self = new (ELeave) CUT_PBASE_T_USBDI_1236(aHostRole);
|
|
40 |
CleanupStack::PushL(self);
|
|
41 |
self->ConstructL();
|
|
42 |
CleanupStack::Pop(self);
|
253
|
43 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_1236_NEWL_EXIT, ( TUint )( self ) );
|
0
|
44 |
return self;
|
|
45 |
}
|
|
46 |
|
|
47 |
|
|
48 |
CUT_PBASE_T_USBDI_1236::CUT_PBASE_T_USBDI_1236(TBool aHostRole)
|
|
49 |
: CBaseTestCase(KTestCaseId,aHostRole)
|
|
50 |
{
|
253
|
51 |
OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_1236_CUT_PBASE_T_USBDI_1236_ENTRY, this );
|
|
52 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_1236_CUT_PBASE_T_USBDI_1236_EXIT, this );
|
0
|
53 |
}
|
|
54 |
|
|
55 |
|
|
56 |
void CUT_PBASE_T_USBDI_1236::ConstructL()
|
|
57 |
{
|
253
|
58 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_1236_CONSTRUCTL_ENTRY, this );
|
0
|
59 |
iTestDevice = new RUsbDeviceA(this);
|
|
60 |
BaseConstructL();
|
253
|
61 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_1236_CONSTRUCTL_EXIT, this );
|
0
|
62 |
}
|
|
63 |
|
|
64 |
|
|
65 |
CUT_PBASE_T_USBDI_1236::~CUT_PBASE_T_USBDI_1236()
|
|
66 |
{
|
253
|
67 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_1236_CUT_PBASE_T_USBDI_1236_ENTRY_DUP01, this );
|
0
|
68 |
|
|
69 |
// Cancel any async operations
|
|
70 |
|
|
71 |
Cancel(); // Cancel host timer
|
|
72 |
|
|
73 |
// Close the interfaces
|
|
74 |
iUsbInterface1.Close();
|
|
75 |
iUsbInterface0.Close();
|
|
76 |
|
|
77 |
delete iControlEp0;
|
|
78 |
delete iActorFDF;
|
|
79 |
if(!IsHost() && iTestDevice)
|
|
80 |
{
|
|
81 |
iTestDevice->Close();
|
|
82 |
}
|
|
83 |
delete iTestDevice;
|
253
|
84 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_1236_CUT_PBASE_T_USBDI_1236_EXIT_DUP01, this );
|
0
|
85 |
}
|
|
86 |
|
|
87 |
|
|
88 |
void CUT_PBASE_T_USBDI_1236::ExecuteHostTestCaseL()
|
|
89 |
{
|
253
|
90 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_1236_EXECUTEHOSTTESTCASEL_ENTRY, this );
|
0
|
91 |
iCaseStep = EStepGetInterfaceString;
|
|
92 |
iActorFDF = CActorFDF::NewL(*this);
|
|
93 |
iControlEp0 = new (ELeave) CEp0Transfer(iUsbInterface0);
|
|
94 |
|
|
95 |
// Monitor for device connections
|
|
96 |
iActorFDF->Monitor();
|
|
97 |
|
|
98 |
// Start the connection timeout
|
|
99 |
TimeoutIn(30);
|
253
|
100 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_1236_EXECUTEHOSTTESTCASEL_EXIT, this );
|
0
|
101 |
}
|
|
102 |
|
|
103 |
void CUT_PBASE_T_USBDI_1236::ExecuteDeviceTestCaseL()
|
|
104 |
{
|
253
|
105 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_1236_EXECUTEDEVICETESTCASEL_ENTRY, this );
|
0
|
106 |
|
|
107 |
// Construct the device for the test case
|
|
108 |
iTestDevice->OpenL(TestCaseId());
|
|
109 |
iTestDevice->SubscribeToReports(iStatus);
|
|
110 |
SetActive();
|
|
111 |
|
|
112 |
// Connect the test device
|
|
113 |
iTestDevice->SoftwareConnect();
|
253
|
114 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_1236_EXECUTEDEVICETESTCASEL_EXIT, this );
|
0
|
115 |
}
|
|
116 |
|
|
117 |
|
|
118 |
void CUT_PBASE_T_USBDI_1236::DeviceInsertedL(TUint aDeviceHandle)
|
|
119 |
{
|
253
|
120 |
OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_1236_DEVICEINSERTEDL_ENTRY, this );
|
0
|
121 |
|
|
122 |
Cancel(); // Cancel the timer
|
|
123 |
TInt err(KErrNone);
|
|
124 |
iDeviceHandle = aDeviceHandle;
|
|
125 |
iActorFDF->Monitor();
|
|
126 |
|
|
127 |
// Validate that device is as expected
|
|
128 |
CUsbTestDevice& testDevice = iActorFDF->DeviceL(aDeviceHandle);
|
|
129 |
if(testDevice.SerialNumber().Compare(TestCaseId()) != 0)
|
|
130 |
{
|
|
131 |
// Incorrect device for this test case
|
|
132 |
|
253
|
133 |
OstTraceExt3(TRACE_NORMAL, CUT_PBASE_T_USBDI_1236_DEVICEINSERTEDL, "<Warning %d> Incorrect device serial number (%S) connected for this test case (%S)",
|
|
134 |
KErrNotFound,testDevice.SerialNumber(),TestCaseId());
|
0
|
135 |
|
|
136 |
// Start the connection timeout again
|
|
137 |
TimeoutIn(30);
|
253
|
138 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_1236_DEVICEINSERTEDL_EXIT, this );
|
0
|
139 |
return;
|
|
140 |
}
|
|
141 |
|
|
142 |
// Perform the correct test step
|
|
143 |
switch(iCaseStep)
|
|
144 |
{
|
|
145 |
case EStepGetInterfaceString:
|
|
146 |
{
|
|
147 |
TUint32 token1(0);
|
|
148 |
TUint32 token2(0);
|
|
149 |
|
253
|
150 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_1236_DEVICEINSERTEDL_DUP01, "Obtaining token for interface 0");
|
0
|
151 |
err = testDevice.Device().GetTokenForInterface(0,token1);
|
|
152 |
if(err != KErrNone)
|
|
153 |
{
|
253
|
154 |
OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_1236_DEVICEINSERTEDL_DUP02, "<Error %d> Token for interface 0 could not be retrieved",err);
|
0
|
155 |
return TestFailed(err);
|
|
156 |
}
|
253
|
157 |
OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_1236_DEVICEINSERTEDL_DUP03, "Token 1 (%d) retrieved",token1);
|
|
158 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_1236_DEVICEINSERTEDL_DUP04, "Opening interface 0");
|
0
|
159 |
err = iUsbInterface0.Open(token1); // Alternate interface setting 0
|
|
160 |
if(err != KErrNone)
|
|
161 |
{
|
253
|
162 |
OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_1236_DEVICEINSERTEDL_DUP05, "<Error %d> Interface 0 could not be opened",err);
|
0
|
163 |
return TestFailed(err);
|
|
164 |
}
|
253
|
165 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_1236_DEVICEINSERTEDL_DUP06, "Interface 0 opened");
|
0
|
166 |
|
|
167 |
|
253
|
168 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_1236_DEVICEINSERTEDL_DUP07, "Obtaining token for interface 1");
|
0
|
169 |
err = testDevice.Device().GetTokenForInterface(1,token2);
|
|
170 |
if(err != KErrNone)
|
|
171 |
{
|
253
|
172 |
OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_1236_DEVICEINSERTEDL_DUP08, "<Error %d> Token for interface 1 could not be retrieved",err);
|
0
|
173 |
return TestFailed(err);
|
|
174 |
}
|
253
|
175 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_1236_DEVICEINSERTEDL_DUP09, "Opening interface 1");
|
0
|
176 |
err = iUsbInterface1.Open(token2); // Alternate interface setting 0
|
|
177 |
if(err != KErrNone)
|
|
178 |
{
|
253
|
179 |
OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_1236_DEVICEINSERTEDL_DUP10, "<Error %d> Interface 1 could not be opened",err);
|
0
|
180 |
return TestFailed(err);
|
|
181 |
}
|
253
|
182 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_1236_DEVICEINSERTEDL_DUP11, "Interface 1 opened");
|
0
|
183 |
|
|
184 |
// close it
|
|
185 |
iUsbInterface1.Close();
|
253
|
186 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_1236_DEVICEINSERTEDL_DUP12, "Interface 1 closed");
|
0
|
187 |
|
|
188 |
//re-open now
|
|
189 |
err = iUsbInterface1.Open(token2); // Alternate interface setting 0
|
|
190 |
if(err != KErrNone)
|
|
191 |
{
|
253
|
192 |
OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_1236_DEVICEINSERTEDL_DUP13, "<Error %d> Interface 1 could not be re-opened",err);
|
0
|
193 |
return TestFailed(err);
|
|
194 |
}
|
253
|
195 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_1236_DEVICEINSERTEDL_DUP14, "Interface 1 re-opened");
|
0
|
196 |
|
|
197 |
|
|
198 |
|
|
199 |
TBuf8<256> interfaceStringDes;
|
|
200 |
const TUint16 KLangIdUsEng = 0x0409;
|
|
201 |
TUsbInterfaceDescriptor interfaceDescriptor;
|
|
202 |
iUsbInterface1.GetInterfaceDescriptor(interfaceDescriptor);
|
|
203 |
TUint8 index = interfaceDescriptor.Interface();
|
|
204 |
iUsbInterface1.GetStringDescriptor(interfaceStringDes, index, KLangIdUsEng);
|
|
205 |
TUint8 length = interfaceStringDes[0];
|
|
206 |
TUint8 type = interfaceStringDes[1];
|
|
207 |
TPtr8 interfaceString = interfaceStringDes.MidTPtr(2, length-2);
|
|
208 |
TBuf16<128> u16String((TUint16*)interfaceString.Ptr());
|
|
209 |
u16String.SetLength(interfaceString.Length()/2);
|
|
210 |
if (u16String.Compare(_L16("i1s0")) == 0)
|
|
211 |
{
|
253
|
212 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_1236_DEVICEINSERTEDL_DUP15, "interface String match");
|
0
|
213 |
iCaseStep = EPassed;
|
|
214 |
TTestCasePassed request;
|
|
215 |
iControlEp0->SendRequest(request,this);
|
|
216 |
}
|
|
217 |
else
|
|
218 |
{
|
253
|
219 |
OstTraceExt1(TRACE_NORMAL, CUT_PBASE_T_USBDI_1236_DEVICEINSERTEDL_DUP16, "interface String not match %s", interfaceString);
|
0
|
220 |
iCaseStep = EFailed;
|
|
221 |
TTestCaseFailed request(KErrCompletion, _L8("interface string not match"));
|
|
222 |
iControlEp0->SendRequest(request,this);
|
|
223 |
}
|
|
224 |
}
|
|
225 |
break;
|
|
226 |
|
|
227 |
default:
|
|
228 |
TestFailed(KErrCorrupt);
|
|
229 |
break;
|
|
230 |
}
|
253
|
231 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_1236_DEVICEINSERTEDL_EXIT_DUP01, this );
|
0
|
232 |
}
|
|
233 |
|
|
234 |
|
|
235 |
|
|
236 |
void CUT_PBASE_T_USBDI_1236::DeviceRemovedL(TUint aDeviceHandle)
|
|
237 |
{
|
253
|
238 |
OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_1236_DEVICEREMOVEDL_ENTRY, this );
|
0
|
239 |
|
|
240 |
// The test device should not be removed until the test case has passed
|
|
241 |
// so this test case has not completed, and state this event as an error
|
|
242 |
|
|
243 |
TestFailed(KErrDisconnected);
|
253
|
244 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_1236_DEVICEREMOVEDL_EXIT, this );
|
0
|
245 |
}
|
|
246 |
|
|
247 |
|
|
248 |
void CUT_PBASE_T_USBDI_1236::BusErrorL(TInt aError)
|
|
249 |
{
|
253
|
250 |
OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_1236_BUSERRORL_ENTRY, this );
|
0
|
251 |
|
|
252 |
// This test case handles no failiures on the bus
|
|
253 |
|
|
254 |
TestFailed(aError);
|
253
|
255 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_1236_BUSERRORL_EXIT, this );
|
0
|
256 |
}
|
|
257 |
|
|
258 |
void CUT_PBASE_T_USBDI_1236::DeviceStateChangeL(RUsbDevice::TDeviceState aPreviousState,RUsbDevice::TDeviceState aNewState,TInt aCompletionCode)
|
|
259 |
{
|
253
|
260 |
OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_1236_DEVICESTATECHANGEL_ENTRY, this );
|
0
|
261 |
Cancel();
|
253
|
262 |
OstTraceExt3(TRACE_NORMAL, CUT_PBASE_T_USBDI_1236_DEVICESTATECHANGEL, "Device State change from %d to %d err=%d",aPreviousState,aNewState,aCompletionCode);
|
|
263 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_1236_DEVICESTATECHANGEL_EXIT, this );
|
0
|
264 |
}
|
|
265 |
|
|
266 |
|
|
267 |
void CUT_PBASE_T_USBDI_1236::Ep0TransferCompleteL(TInt aCompletionCode)
|
|
268 |
{
|
253
|
269 |
OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_1236_EP0TRANSFERCOMPLETEL_ENTRY, this );
|
|
270 |
OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_1236_EP0TRANSFERCOMPLETEL, "Ep0TransferCompleteL with aCompletionCode = %d",aCompletionCode);
|
0
|
271 |
switch(iCaseStep)
|
|
272 |
{
|
|
273 |
// Fail the test case
|
|
274 |
default:
|
|
275 |
case EFailed:
|
|
276 |
TestFailed(KErrCompletion);
|
|
277 |
break;
|
|
278 |
|
|
279 |
// Pass the test case
|
|
280 |
|
|
281 |
case EPassed:
|
|
282 |
TestPassed();
|
|
283 |
break;
|
|
284 |
}
|
253
|
285 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_1236_EP0TRANSFERCOMPLETEL_EXIT, this );
|
0
|
286 |
}
|
|
287 |
|
|
288 |
|
|
289 |
void CUT_PBASE_T_USBDI_1236::HostRunL()
|
|
290 |
{
|
253
|
291 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_1236_HOSTRUNL_ENTRY, this );
|
0
|
292 |
|
|
293 |
// Obtain the completion code
|
|
294 |
TInt completionCode(iStatus.Int());
|
|
295 |
|
|
296 |
if(completionCode == KErrNone)
|
|
297 |
{
|
|
298 |
// Action timeout
|
253
|
299 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_1236_HOSTRUNL, "<Error> Action timeout");
|
0
|
300 |
TestFailed(KErrTimedOut);
|
|
301 |
}
|
|
302 |
else
|
|
303 |
{
|
253
|
304 |
OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_1236_HOSTRUNL_DUP01, "<Error %d> Timeout timer could not complete",completionCode);
|
0
|
305 |
TestFailed(completionCode);
|
|
306 |
}
|
253
|
307 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_1236_HOSTRUNL_EXIT, this );
|
0
|
308 |
}
|
|
309 |
|
|
310 |
|
|
311 |
void CUT_PBASE_T_USBDI_1236::DeviceRunL()
|
|
312 |
{
|
253
|
313 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_1236_DEVICERUNL_ENTRY, this );
|
0
|
314 |
|
|
315 |
// Disconnect the device
|
|
316 |
|
|
317 |
iTestDevice->SoftwareDisconnect();
|
|
318 |
|
|
319 |
// Complete the test case request
|
|
320 |
|
|
321 |
TestPolicy().SignalTestComplete(iStatus.Int());
|
253
|
322 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_1236_DEVICERUNL_EXIT, this );
|
0
|
323 |
}
|
|
324 |
|
|
325 |
void CUT_PBASE_T_USBDI_1236::HostDoCancel()
|
|
326 |
{
|
253
|
327 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_1236_HOSTDOCANCEL_ENTRY, this );
|
0
|
328 |
|
|
329 |
// Cancel the timeout timer
|
|
330 |
CancelTimeout();
|
253
|
331 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_1236_HOSTDOCANCEL_EXIT, this );
|
0
|
332 |
}
|
|
333 |
|
|
334 |
|
|
335 |
void CUT_PBASE_T_USBDI_1236::DeviceDoCancel()
|
|
336 |
{
|
253
|
337 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_1236_DEVICEDOCANCEL_ENTRY, this );
|
0
|
338 |
|
|
339 |
// Cancel the device
|
|
340 |
iTestDevice->CancelSubscriptionToReports();
|
253
|
341 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_1236_DEVICEDOCANCEL_EXIT, this );
|
0
|
342 |
}
|
|
343 |
|
|
344 |
}
|