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-0488.cpp
|
|
15 |
// @internalComponent
|
|
16 |
//
|
|
17 |
//
|
|
18 |
|
|
19 |
#include "PBASE-T_USBDI-0488.h"
|
|
20 |
#include "testpolicy.h"
|
|
21 |
#include "modelleddevices.h"
|
253
|
22 |
#include "OstTraceDefinitions.h"
|
|
23 |
#ifdef OST_TRACE_COMPILER_IN_USE
|
|
24 |
#include "PBASE-T_USBDI-0488Traces.h"
|
|
25 |
#endif
|
0
|
26 |
#include <d32usbdi_errors.h>
|
|
27 |
|
|
28 |
namespace NUnitTesting_USBDI
|
|
29 |
{
|
|
30 |
|
|
31 |
_LIT(KTestCaseId,"PBASE-T_USBDI-0488");
|
|
32 |
const TFunctorTestCase<CUT_PBASE_T_USBDI_0488,TBool> CUT_PBASE_T_USBDI_0488::iFunctor(KTestCaseId);
|
|
33 |
|
|
34 |
CUT_PBASE_T_USBDI_0488* CUT_PBASE_T_USBDI_0488::NewL(TBool aHostRole)
|
|
35 |
{
|
253
|
36 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0488_NEWL_ENTRY, aHostRole );
|
0
|
37 |
CUT_PBASE_T_USBDI_0488* self = new (ELeave) CUT_PBASE_T_USBDI_0488(aHostRole);
|
|
38 |
CleanupStack::PushL(self);
|
|
39 |
self->ConstructL();
|
|
40 |
CleanupStack::Pop(self);
|
253
|
41 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0488_NEWL_EXIT, ( TUint )( self ) );
|
0
|
42 |
return self;
|
|
43 |
}
|
|
44 |
|
|
45 |
|
|
46 |
CUT_PBASE_T_USBDI_0488::CUT_PBASE_T_USBDI_0488(TBool aHostRole)
|
|
47 |
: CBaseTestCase(KTestCaseId,aHostRole),
|
|
48 |
iCaseStep(EInProgress)
|
|
49 |
{
|
253
|
50 |
OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0488_CUT_PBASE_T_USBDI_0488_ENTRY, this );
|
|
51 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0488_CUT_PBASE_T_USBDI_0488_EXIT, this );
|
0
|
52 |
}
|
|
53 |
|
|
54 |
|
|
55 |
void CUT_PBASE_T_USBDI_0488::ConstructL()
|
|
56 |
{
|
253
|
57 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0488_CONSTRUCTL_ENTRY, this );
|
0
|
58 |
iTestDevice = new RUsbDeviceA(this);
|
|
59 |
BaseConstructL();
|
253
|
60 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0488_CONSTRUCTL_EXIT, this );
|
0
|
61 |
}
|
|
62 |
|
|
63 |
|
|
64 |
CUT_PBASE_T_USBDI_0488::~CUT_PBASE_T_USBDI_0488()
|
|
65 |
{
|
253
|
66 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0488_CUT_PBASE_T_USBDI_0488_ENTRY_DUP01, this );
|
0
|
67 |
|
|
68 |
Cancel();
|
|
69 |
|
|
70 |
// Close the interface
|
|
71 |
iUsbInterface0.Close();
|
|
72 |
|
|
73 |
delete iControlEp0;
|
|
74 |
delete iActorFDF;
|
|
75 |
if(!IsHost() && iTestDevice)
|
|
76 |
{
|
|
77 |
iTestDevice->Close();
|
|
78 |
}
|
|
79 |
delete iTestDevice;
|
253
|
80 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0488_CUT_PBASE_T_USBDI_0488_EXIT_DUP01, this );
|
0
|
81 |
}
|
|
82 |
|
|
83 |
|
|
84 |
void CUT_PBASE_T_USBDI_0488::ExecuteHostTestCaseL()
|
|
85 |
{
|
253
|
86 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0488_EXECUTEHOSTTESTCASEL_ENTRY, this );
|
0
|
87 |
|
|
88 |
iActorFDF = CActorFDF::NewL(*this);
|
|
89 |
iControlEp0 = new (ELeave) CEp0Transfer(iUsbInterface0);
|
|
90 |
iActorFDF->Monitor();
|
|
91 |
|
|
92 |
TimeoutIn(30);
|
253
|
93 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0488_EXECUTEHOSTTESTCASEL_EXIT, this );
|
0
|
94 |
}
|
|
95 |
|
|
96 |
/*static*/ TInt CUT_PBASE_T_USBDI_0488::TestSelectAlternateInterfaceThenPanic(TAny* aTest)
|
|
97 |
{
|
253
|
98 |
OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0488_TESTSELECTALTERNATEINTERFACETHENPANIC_ENTRY, 0 );
|
0
|
99 |
|
|
100 |
CTrapCleanup* trapHandler=CTrapCleanup::New();
|
|
101 |
if(!trapHandler)
|
|
102 |
{
|
253
|
103 |
OstTraceFunctionExitExt( CUT_PBASE_T_USBDI_0488_TESTSELECTALTERNATEINTERFACETHENPANIC_EXIT, 0, KErrNoMemory );
|
0
|
104 |
return KErrNoMemory;
|
|
105 |
}
|
|
106 |
|
|
107 |
CUT_PBASE_T_USBDI_0488* pTest = reinterpret_cast<CUT_PBASE_T_USBDI_0488*>(aTest);
|
|
108 |
|
|
109 |
// change interface setting whilst pipes are opened in another alt. setting, should panic
|
|
110 |
pTest->iUsbInterface1.SelectAlternateInterface(0); // panic expected
|
|
111 |
|
|
112 |
// Should never get here.*/
|
253
|
113 |
OstTraceFunctionExitExt( CUT_PBASE_T_USBDI_0488_TESTSELECTALTERNATEINTERFACETHENPANIC_EXIT_DUP01, 0, KErrNone );
|
0
|
114 |
return KErrNone;
|
|
115 |
}
|
|
116 |
|
|
117 |
|
|
118 |
|
|
119 |
void CUT_PBASE_T_USBDI_0488::HostDoCancel()
|
|
120 |
{
|
253
|
121 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0488_HOSTDOCANCEL_ENTRY, this );
|
0
|
122 |
// Cancel the timeout timer
|
|
123 |
CancelTimeout();
|
253
|
124 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0488_HOSTDOCANCEL_EXIT, this );
|
0
|
125 |
}
|
|
126 |
|
|
127 |
|
|
128 |
void CUT_PBASE_T_USBDI_0488::ExecuteDeviceTestCaseL()
|
|
129 |
{
|
253
|
130 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0488_EXECUTEDEVICETESTCASEL_ENTRY, this );
|
0
|
131 |
iTestDevice->OpenL(TestCaseId());
|
|
132 |
iTestDevice->SubscribeToReports(iStatus);
|
|
133 |
SetActive();
|
|
134 |
iTestDevice->SoftwareConnect();
|
253
|
135 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0488_EXECUTEDEVICETESTCASEL_EXIT, this );
|
0
|
136 |
}
|
|
137 |
|
|
138 |
void CUT_PBASE_T_USBDI_0488::DeviceDoCancel()
|
|
139 |
{
|
253
|
140 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0488_DEVICEDOCANCEL_ENTRY, this );
|
0
|
141 |
// Cancel the device
|
|
142 |
iTestDevice->CancelSubscriptionToReports();
|
253
|
143 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0488_DEVICEDOCANCEL_EXIT, this );
|
0
|
144 |
}
|
|
145 |
|
|
146 |
|
|
147 |
void CUT_PBASE_T_USBDI_0488::DeviceStateChangeL(RUsbDevice::TDeviceState aPreviousState,RUsbDevice::TDeviceState aNewState,
|
|
148 |
TInt aCompletionCode)
|
|
149 |
{
|
253
|
150 |
OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0488_DEVICESTATECHANGEL_ENTRY, this );
|
|
151 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0488_DEVICESTATECHANGEL_EXIT, this );
|
0
|
152 |
}
|
|
153 |
|
|
154 |
|
|
155 |
void CUT_PBASE_T_USBDI_0488::DeviceInsertedL(TUint aDeviceHandle)
|
|
156 |
{
|
253
|
157 |
OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0488_DEVICEINSERTEDL_ENTRY, this );
|
0
|
158 |
Cancel();
|
|
159 |
TInt err(KErrNone);
|
|
160 |
|
|
161 |
// Validate that device is as expected
|
|
162 |
CUsbTestDevice& testDevice = iActorFDF->DeviceL(aDeviceHandle);
|
|
163 |
if(testDevice.SerialNumber().Compare(TestCaseId()) != 0)
|
|
164 |
{
|
|
165 |
// Incorrect device for this test case
|
253
|
166 |
OstTraceExt3(TRACE_NORMAL, CUT_PBASE_T_USBDI_0488_DEVICEINSERTEDL, "<Warning %d> Incorrect device serial number (%S) connected for this test case (%S)",
|
|
167 |
KErrNotFound,testDevice.SerialNumber(),TestCaseId());
|
0
|
168 |
// Start the connection timeout again
|
|
169 |
CancelTimeout();
|
|
170 |
iTimer.After(iStatus,30000000);
|
|
171 |
SetActive();
|
253
|
172 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0488_DEVICEINSERTEDL_EXIT, this );
|
0
|
173 |
return;
|
|
174 |
}
|
|
175 |
|
|
176 |
|
|
177 |
TUint32 token0,token1;
|
|
178 |
err = testDevice.Device().GetTokenForInterface(0,token0);
|
|
179 |
if(err != KErrNone)
|
|
180 |
{
|
253
|
181 |
OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0488_DEVICEINSERTEDL_DUP01, "<Error %d> Token for interface 0 could not be retrieved",err);
|
0
|
182 |
return TestFailed(err);
|
|
183 |
}
|
|
184 |
err = iUsbInterface0.Open(token0); // Default interface setting 0
|
|
185 |
if(err != KErrNone)
|
|
186 |
{
|
253
|
187 |
OstTraceExt2(TRACE_NORMAL, CUT_PBASE_T_USBDI_0488_DEVICEINSERTEDL_DUP02, "<Error %d> Unable to open interface 0 using token %d",err,token0);
|
0
|
188 |
return TestFailed(err);
|
|
189 |
}
|
|
190 |
|
|
191 |
__UHEAP_MARK;
|
|
192 |
err = testDevice.Device().GetTokenForInterface(1,token1);
|
|
193 |
if(err != KErrNone)
|
|
194 |
{
|
|
195 |
TBuf<256> msg;
|
|
196 |
msg.Format(_L("<Error %d> Token for interface 1 could not be retrieved"),err);
|
253
|
197 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0488_DEVICEINSERTEDL_DUP03, msg);
|
0
|
198 |
iCaseStep = EFailed;
|
|
199 |
TTestCaseFailed request(err,msg);
|
|
200 |
return iControlEp0->SendRequest(request,this);
|
|
201 |
}
|
|
202 |
err = iUsbInterface1.Open(token1); // Default interface setting 0
|
|
203 |
if(err != KErrNone)
|
|
204 |
{
|
|
205 |
TBuf<256> msg;
|
|
206 |
msg.Format(_L("<Error %d> Unable to open interface 1 using token %d"),err,token1);
|
253
|
207 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0488_DEVICEINSERTEDL_DUP04, msg);
|
0
|
208 |
iCaseStep = EFailed;
|
|
209 |
TTestCaseFailed request(err,msg);
|
|
210 |
return iControlEp0->SendRequest(request,this);
|
|
211 |
}
|
|
212 |
|
|
213 |
// Select alternate interface setting 1
|
|
214 |
err = iUsbInterface1.SelectAlternateInterface(1);
|
|
215 |
if(err != KErrNone)
|
|
216 |
{
|
|
217 |
TBuf<256> msg;
|
|
218 |
msg.Format(_L("<Error %d> Selecting alternate interface setting 1 on interface 1"),err);
|
253
|
219 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0488_DEVICEINSERTEDL_DUP05, msg);
|
0
|
220 |
iCaseStep = EFailed;
|
|
221 |
TTestCaseFailed request(err,msg);
|
|
222 |
iControlEp0->SendRequest(request,this);
|
253
|
223 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0488_DEVICEINSERTEDL_EXIT_DUP01, this );
|
0
|
224 |
return;
|
|
225 |
}
|
|
226 |
|
|
227 |
// Open a pipe for endpoint (Int in)
|
|
228 |
TInt endpointAddress;
|
|
229 |
err = GetEndpointAddress(iUsbInterface1,1,KTransferTypeInterrupt,KEpDirectionIn,endpointAddress);
|
|
230 |
if(err != KErrNone)
|
|
231 |
{
|
|
232 |
TBuf<256> msg;
|
|
233 |
msg.Format(_L("<Error %d> unable to get endpoint address for interrupt in endpoint"),err);
|
253
|
234 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0488_DEVICEINSERTEDL_DUP06, msg);
|
0
|
235 |
iCaseStep = EFailed;
|
|
236 |
TTestCaseFailed request(err,msg);
|
|
237 |
iControlEp0->SendRequest(request,this);
|
253
|
238 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0488_DEVICEINSERTEDL_EXIT_DUP02, this );
|
0
|
239 |
return;
|
|
240 |
}
|
|
241 |
|
|
242 |
err = iUsbInterface1.OpenPipeForEndpoint(iInPipe,endpointAddress,EFalse);
|
|
243 |
if(err != KErrNone)
|
|
244 |
{
|
|
245 |
TBuf<256> msg;
|
|
246 |
msg.Format(_L("<Error %d> Unable to open pipe for endpoint 1"),err);
|
253
|
247 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0488_DEVICEINSERTEDL_DUP07, msg);
|
0
|
248 |
iCaseStep = EFailed;
|
|
249 |
TTestCaseFailed request(err,msg);
|
|
250 |
return iControlEp0->SendRequest(request,this);
|
|
251 |
}
|
|
252 |
|
|
253 |
RThread rt;
|
|
254 |
TInt r = rt.Create(_L("PanicThread"), CUT_PBASE_T_USBDI_0488::TestSelectAlternateInterfaceThenPanic, KDefaultStackSize, 0x1000, 0x1000, reinterpret_cast<TAny*>(this));
|
|
255 |
gtest(r == KErrNone);
|
|
256 |
TRequestStatus status;
|
|
257 |
rt.Logon(status);
|
|
258 |
rt.Resume();
|
|
259 |
rt.Close();
|
|
260 |
User::WaitForRequest(status);
|
|
261 |
gtest(status.Int() == UsbdiPanics::EInterfaceSettingChangeWithPipeOpen);
|
|
262 |
|
|
263 |
iUsbInterface1.Close();
|
|
264 |
|
|
265 |
__UHEAP_MARKEND;
|
|
266 |
|
|
267 |
// ok now, inform client that the test has passed
|
|
268 |
iCaseStep = EPassed;
|
|
269 |
TTestCasePassed request;
|
|
270 |
return iControlEp0->SendRequest(request,this);
|
|
271 |
}
|
|
272 |
|
|
273 |
|
|
274 |
void CUT_PBASE_T_USBDI_0488::Ep0TransferCompleteL(TInt aCompletionCode)
|
|
275 |
{
|
253
|
276 |
OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0488_EP0TRANSFERCOMPLETEL_ENTRY, this );
|
0
|
277 |
|
253
|
278 |
OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0488_EP0TRANSFERCOMPLETEL, "Ep0TransferCompleteL with aCompletionCode = %d",aCompletionCode);
|
0
|
279 |
|
|
280 |
if(aCompletionCode != KErrNone)
|
|
281 |
{
|
|
282 |
TBuf<256> msg;
|
|
283 |
msg.Format(_L("<Error %d> Transfer to control endpoint 0 was not successful"),aCompletionCode);
|
253
|
284 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0488_EP0TRANSFERCOMPLETEL_DUP01, msg);
|
0
|
285 |
}
|
|
286 |
|
|
287 |
if(iCaseStep == EPassed)
|
|
288 |
{
|
|
289 |
if(aCompletionCode == KErrNone)
|
|
290 |
{
|
|
291 |
return TestPassed();
|
|
292 |
}
|
|
293 |
// else error
|
|
294 |
iCaseStep = EFailed;
|
|
295 |
}
|
|
296 |
|
|
297 |
if(iCaseStep == EFailed)
|
|
298 |
{
|
|
299 |
return TestFailed(KErrCompletion);
|
|
300 |
}
|
253
|
301 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0488_EP0TRANSFERCOMPLETEL_EXIT, this );
|
0
|
302 |
}
|
|
303 |
|
|
304 |
|
|
305 |
void CUT_PBASE_T_USBDI_0488::DeviceRemovedL(TUint aDeviceHandle)
|
|
306 |
{
|
253
|
307 |
OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0488_DEVICEREMOVEDL_ENTRY, this );
|
0
|
308 |
|
|
309 |
// The test device should not be removed until the test case has passed
|
|
310 |
// so this test case has not completed, and state this event as an error
|
|
311 |
TestFailed(KErrDisconnected);
|
253
|
312 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0488_DEVICEREMOVEDL_EXIT, this );
|
0
|
313 |
}
|
|
314 |
|
|
315 |
|
|
316 |
void CUT_PBASE_T_USBDI_0488::BusErrorL(TInt aError)
|
|
317 |
{
|
253
|
318 |
OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0488_BUSERRORL_ENTRY, this );
|
0
|
319 |
|
|
320 |
// This test case handles no failiures on the bus
|
|
321 |
TestFailed(KErrCompletion);
|
253
|
322 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0488_BUSERRORL_EXIT, this );
|
0
|
323 |
}
|
|
324 |
|
|
325 |
void CUT_PBASE_T_USBDI_0488::HostRunL()
|
|
326 |
{
|
253
|
327 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0488_HOSTRUNL_ENTRY, this );
|
0
|
328 |
// Obtain the completion code
|
|
329 |
TInt completionCode(iStatus.Int());
|
|
330 |
|
|
331 |
if(completionCode == KErrNone)
|
|
332 |
{
|
|
333 |
// Action timeout
|
253
|
334 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0488_HOSTRUNL, "<Error> Action timeout");
|
0
|
335 |
TestFailed(KErrTimedOut);
|
|
336 |
}
|
|
337 |
else
|
|
338 |
{
|
253
|
339 |
OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0488_HOSTRUNL_DUP01, "<Error %d> Timeout timer could not complete",completionCode);
|
0
|
340 |
TestFailed(completionCode);
|
|
341 |
}
|
253
|
342 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0488_HOSTRUNL_EXIT, this );
|
0
|
343 |
}
|
|
344 |
|
|
345 |
void CUT_PBASE_T_USBDI_0488::DeviceRunL()
|
|
346 |
{
|
253
|
347 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0488_DEVICERUNL_ENTRY, this );
|
0
|
348 |
|
|
349 |
// Disconnect the device
|
|
350 |
iTestDevice->SoftwareDisconnect();
|
|
351 |
|
|
352 |
// Complete the test case request
|
|
353 |
TestPolicy().SignalTestComplete(iStatus.Int());
|
253
|
354 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0488_DEVICERUNL_EXIT, this );
|
0
|
355 |
}
|
|
356 |
|
|
357 |
|
|
358 |
}
|