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-0478.cpp
|
|
15 |
// @internalComponent
|
|
16 |
//
|
|
17 |
//
|
|
18 |
|
|
19 |
#include "PBASE-T_USBDI-0478.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-0478Traces.h"
|
|
25 |
#endif
|
0
|
26 |
|
|
27 |
|
|
28 |
namespace NUnitTesting_USBDI
|
|
29 |
{
|
|
30 |
|
|
31 |
_LIT(KTestCaseId,"PBASE-T_USBDI-0478");
|
|
32 |
const TFunctorTestCase<CUT_PBASE_T_USBDI_0478,TBool> CUT_PBASE_T_USBDI_0478::iFunctor(KTestCaseId);
|
|
33 |
|
|
34 |
CUT_PBASE_T_USBDI_0478* CUT_PBASE_T_USBDI_0478::NewL(TBool aHostRole)
|
|
35 |
{
|
253
|
36 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0478_NEWL_ENTRY, aHostRole );
|
0
|
37 |
CUT_PBASE_T_USBDI_0478* self = new (ELeave) CUT_PBASE_T_USBDI_0478(aHostRole);
|
|
38 |
CleanupStack::PushL(self);
|
|
39 |
self->ConstructL();
|
|
40 |
CleanupStack::Pop(self);
|
253
|
41 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0478_NEWL_EXIT, ( TUint )( self ) );
|
0
|
42 |
return self;
|
|
43 |
}
|
|
44 |
|
|
45 |
|
|
46 |
CUT_PBASE_T_USBDI_0478::CUT_PBASE_T_USBDI_0478(TBool aHostRole)
|
|
47 |
: CBaseTestCase(KTestCaseId,aHostRole),
|
|
48 |
iCaseStep(EInProgress)
|
|
49 |
{
|
253
|
50 |
OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0478_CUT_PBASE_T_USBDI_0478_ENTRY, this );
|
|
51 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0478_CUT_PBASE_T_USBDI_0478_EXIT, this );
|
0
|
52 |
}
|
|
53 |
|
|
54 |
|
|
55 |
void CUT_PBASE_T_USBDI_0478::ConstructL()
|
|
56 |
{
|
253
|
57 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0478_CONSTRUCTL_ENTRY, this );
|
0
|
58 |
iTestDevice = new RUsbDeviceA(this);
|
|
59 |
BaseConstructL();
|
253
|
60 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0478_CONSTRUCTL_EXIT, this );
|
0
|
61 |
}
|
|
62 |
|
|
63 |
|
|
64 |
CUT_PBASE_T_USBDI_0478::~CUT_PBASE_T_USBDI_0478()
|
|
65 |
{
|
253
|
66 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0478_CUT_PBASE_T_USBDI_0478_ENTRY_DUP01, this );
|
0
|
67 |
|
|
68 |
Cancel();
|
|
69 |
|
|
70 |
// Close the interfaces
|
|
71 |
|
|
72 |
iDuplicateUsbInterface1.Close();
|
|
73 |
iUsbInterface1.Close();
|
|
74 |
iUsbInterface0.Close();
|
|
75 |
|
|
76 |
delete iControlEp0;
|
|
77 |
delete iActorFDF;
|
|
78 |
if(!IsHost() && iTestDevice)
|
|
79 |
{
|
|
80 |
iTestDevice->Close();
|
|
81 |
}
|
|
82 |
delete iTestDevice;
|
253
|
83 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0478_CUT_PBASE_T_USBDI_0478_EXIT_DUP01, this );
|
0
|
84 |
}
|
|
85 |
|
|
86 |
void CUT_PBASE_T_USBDI_0478::ExecuteHostTestCaseL()
|
|
87 |
{
|
253
|
88 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0478_EXECUTEHOSTTESTCASEL_ENTRY, this );
|
0
|
89 |
|
|
90 |
// Create the actor for the Function Driver Framework
|
|
91 |
|
|
92 |
iActorFDF = CActorFDF::NewL(*this);
|
|
93 |
|
|
94 |
// Create the control transfer for requests
|
|
95 |
|
|
96 |
iControlEp0 = new (ELeave) CEp0Transfer(iUsbInterface0);
|
|
97 |
|
|
98 |
// Monitor for devices
|
|
99 |
|
|
100 |
iActorFDF->Monitor();
|
|
101 |
|
|
102 |
// Start the connection timeout timer
|
|
103 |
|
|
104 |
TimeoutIn(30);
|
253
|
105 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0478_EXECUTEHOSTTESTCASEL_EXIT, this );
|
0
|
106 |
}
|
|
107 |
|
|
108 |
void CUT_PBASE_T_USBDI_0478::HostDoCancel()
|
|
109 |
{
|
253
|
110 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0478_HOSTDOCANCEL_ENTRY, this );
|
0
|
111 |
|
|
112 |
// Cancel the timeout timer for activity
|
|
113 |
|
|
114 |
CancelTimeout();
|
253
|
115 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0478_HOSTDOCANCEL_EXIT, this );
|
0
|
116 |
}
|
|
117 |
|
|
118 |
|
|
119 |
void CUT_PBASE_T_USBDI_0478::ExecuteDeviceTestCaseL()
|
|
120 |
{
|
253
|
121 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0478_EXECUTEDEVICETESTCASEL_ENTRY, this );
|
0
|
122 |
|
|
123 |
// Create the test device for this test case
|
|
124 |
|
|
125 |
iTestDevice->OpenL(TestCaseId());
|
|
126 |
iTestDevice->SubscribeToReports(iStatus);
|
|
127 |
SetActive();
|
|
128 |
|
|
129 |
// Connect the test device to the host
|
|
130 |
|
|
131 |
iTestDevice->SoftwareConnect();
|
253
|
132 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0478_EXECUTEDEVICETESTCASEL_EXIT, this );
|
0
|
133 |
}
|
|
134 |
|
|
135 |
void CUT_PBASE_T_USBDI_0478::DeviceDoCancel()
|
|
136 |
{
|
253
|
137 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0478_DEVICEDOCANCEL_ENTRY, this );
|
0
|
138 |
|
|
139 |
// Cancel the test device
|
|
140 |
|
|
141 |
iTestDevice->CancelSubscriptionToReports();
|
253
|
142 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0478_DEVICEDOCANCEL_EXIT, this );
|
0
|
143 |
}
|
|
144 |
|
|
145 |
|
|
146 |
void CUT_PBASE_T_USBDI_0478::DeviceStateChangeL(RUsbDevice::TDeviceState aPreviousState,
|
|
147 |
RUsbDevice::TDeviceState aNewState,TInt aCompletionCode)
|
|
148 |
{
|
253
|
149 |
OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0478_DEVICESTATECHANGEL_ENTRY, this );
|
0
|
150 |
|
|
151 |
Cancel();
|
253
|
152 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0478_DEVICESTATECHANGEL_EXIT, this );
|
0
|
153 |
}
|
|
154 |
|
|
155 |
|
|
156 |
void CUT_PBASE_T_USBDI_0478::DeviceInsertedL(TUint aDeviceHandle)
|
|
157 |
{
|
253
|
158 |
OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0478_DEVICEINSERTEDL_ENTRY, this );
|
0
|
159 |
|
|
160 |
Cancel();
|
|
161 |
TInt err(KErrNone);
|
|
162 |
|
|
163 |
// Validate that device is as expected
|
|
164 |
CUsbTestDevice& testDevice = iActorFDF->DeviceL(aDeviceHandle);
|
|
165 |
if(testDevice.SerialNumber().Compare(TestCaseId()) != 0)
|
|
166 |
{
|
|
167 |
// Incorrect device for this test case
|
|
168 |
|
253
|
169 |
OstTraceExt3(TRACE_NORMAL, CUT_PBASE_T_USBDI_0478_DEVICEINSERTEDL, "<Warning %d> Incorrect device serial number (%S) connected for this test case (%S)",
|
|
170 |
KErrNotFound,testDevice.SerialNumber(),TestCaseId());
|
0
|
171 |
|
|
172 |
// Start the connection timeout again
|
|
173 |
|
|
174 |
TimeoutIn(30);
|
253
|
175 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0478_DEVICEINSERTEDL_EXIT, this );
|
0
|
176 |
return;
|
|
177 |
}
|
|
178 |
|
|
179 |
TUint32 token0,token1;
|
|
180 |
err = testDevice.Device().GetTokenForInterface(0,token0);
|
|
181 |
if(err != KErrNone)
|
|
182 |
{
|
253
|
183 |
OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0478_DEVICEINSERTEDL_DUP01, "<Error %d> Token for interface 0 could not be retrieved",err);
|
0
|
184 |
return TestFailed(err);
|
|
185 |
}
|
|
186 |
err = iUsbInterface0.Open(token0); // Default interface setting 0
|
|
187 |
if(err != KErrNone)
|
|
188 |
{
|
253
|
189 |
OstTraceExt2(TRACE_NORMAL, CUT_PBASE_T_USBDI_0478_DEVICEINSERTEDL_DUP02, "<Error %d> Unable to open interface 0 using token %d",err,token0);
|
0
|
190 |
return TestFailed(err);
|
|
191 |
}
|
|
192 |
|
|
193 |
err = testDevice.Device().GetTokenForInterface(1,token1);
|
|
194 |
if(err != KErrNone)
|
|
195 |
{
|
253
|
196 |
OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0478_DEVICEINSERTEDL_DUP03, "<Error %d> Token for interface 1 could not be retrieved",err);
|
0
|
197 |
return TestFailed(err);
|
|
198 |
}
|
|
199 |
|
|
200 |
err = iUsbInterface1.Open(token1);
|
|
201 |
if(err != KErrNone)
|
|
202 |
{
|
253
|
203 |
OstTraceExt2(TRACE_NORMAL, CUT_PBASE_T_USBDI_0478_DEVICEINSERTEDL_DUP04, "<Error %d> Unable to open interface using token %d",err,token1);
|
0
|
204 |
return TestFailed(err);
|
|
205 |
}
|
|
206 |
|
|
207 |
// Acting as another FD open the interface
|
|
208 |
|
|
209 |
err = iDuplicateUsbInterface1.Open(token1);
|
|
210 |
if(err == KErrNone)
|
|
211 |
{
|
|
212 |
TBuf<64> msg;
|
|
213 |
msg.Format(_L("<Error> Able to open a concurrent hande to an interface"));
|
253
|
214 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0478_DEVICEINSERTEDL_DUP05, msg);
|
0
|
215 |
iCaseStep = EFailed;
|
|
216 |
TTestCaseFailed request(KErrCompletion,msg);
|
|
217 |
iControlEp0->SendRequest(request,this);
|
253
|
218 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0478_DEVICEINSERTEDL_EXIT_DUP01, this );
|
0
|
219 |
return;
|
|
220 |
}
|
253
|
221 |
OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0478_DEVICEINSERTEDL_DUP06, "Attempt to open concurrent interface handle failed with: %d",err);
|
0
|
222 |
|
|
223 |
// Inform client device test case successful
|
|
224 |
User::After(1000000);
|
|
225 |
iCaseStep = EPassed;
|
|
226 |
TTestCasePassed request;
|
|
227 |
iControlEp0->SendRequest(request,this);
|
253
|
228 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0478_DEVICEINSERTEDL_EXIT_DUP02, this );
|
0
|
229 |
}
|
|
230 |
|
|
231 |
|
|
232 |
void CUT_PBASE_T_USBDI_0478::Ep0TransferCompleteL(TInt aCompletionCode)
|
|
233 |
{
|
253
|
234 |
OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0478_EP0TRANSFERCOMPLETEL_ENTRY, this );
|
0
|
235 |
|
253
|
236 |
OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0478_EP0TRANSFERCOMPLETEL, "Ep0TransferCompleteL with aCompletionCode = %d",aCompletionCode);
|
0
|
237 |
|
|
238 |
if(aCompletionCode != KErrNone)
|
|
239 |
{
|
|
240 |
TBuf<256> msg;
|
|
241 |
msg.Format(_L("<Error %d> Transfer to control endpoint 0 was not successful"),aCompletionCode);
|
253
|
242 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0478_EP0TRANSFERCOMPLETEL_DUP01, msg);
|
0
|
243 |
}
|
|
244 |
|
|
245 |
if(iCaseStep == EPassed)
|
|
246 |
{
|
|
247 |
if(aCompletionCode == KErrNone)
|
|
248 |
{
|
|
249 |
return TestPassed();
|
|
250 |
}
|
|
251 |
// else error
|
|
252 |
iCaseStep = EFailed;
|
|
253 |
}
|
|
254 |
|
|
255 |
if(iCaseStep == EFailed)
|
|
256 |
{
|
|
257 |
return TestFailed(KErrCompletion);
|
|
258 |
}
|
253
|
259 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0478_EP0TRANSFERCOMPLETEL_EXIT, this );
|
0
|
260 |
}
|
|
261 |
|
|
262 |
|
|
263 |
void CUT_PBASE_T_USBDI_0478::DeviceRemovedL(TUint aDeviceHandle)
|
|
264 |
{
|
253
|
265 |
OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0478_DEVICEREMOVEDL_ENTRY, this );
|
0
|
266 |
|
|
267 |
// The test device should not be removed until the test case has passed
|
|
268 |
// so this test case has not completed, and state this event as an error
|
|
269 |
|
|
270 |
TestFailed(KErrDisconnected);
|
253
|
271 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0478_DEVICEREMOVEDL_EXIT, this );
|
0
|
272 |
}
|
|
273 |
|
|
274 |
|
|
275 |
void CUT_PBASE_T_USBDI_0478::BusErrorL(TInt aError)
|
|
276 |
{
|
253
|
277 |
OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0478_BUSERRORL_ENTRY, this );
|
0
|
278 |
|
|
279 |
// This test case handles no failiures on the bus
|
|
280 |
|
|
281 |
TestFailed(aError);
|
253
|
282 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0478_BUSERRORL_EXIT, this );
|
0
|
283 |
}
|
|
284 |
|
|
285 |
void CUT_PBASE_T_USBDI_0478::HostRunL()
|
|
286 |
{
|
253
|
287 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0478_HOSTRUNL_ENTRY, this );
|
0
|
288 |
|
|
289 |
// Obtain the completion code
|
|
290 |
TInt completionCode(iStatus.Int());
|
|
291 |
|
|
292 |
if(completionCode == KErrNone)
|
|
293 |
{
|
|
294 |
// Action timeout
|
253
|
295 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0478_HOSTRUNL, "<Error> Action timeout");
|
0
|
296 |
TestFailed(KErrTimedOut);
|
|
297 |
}
|
|
298 |
else
|
|
299 |
{
|
253
|
300 |
OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0478_HOSTRUNL_DUP01, "<Error %d> Timeout timer could not complete",completionCode);
|
0
|
301 |
TestFailed(completionCode);
|
|
302 |
}
|
253
|
303 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0478_HOSTRUNL_EXIT, this );
|
0
|
304 |
}
|
|
305 |
|
|
306 |
void CUT_PBASE_T_USBDI_0478::DeviceRunL()
|
|
307 |
{
|
253
|
308 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0478_DEVICERUNL_ENTRY, this );
|
0
|
309 |
|
|
310 |
// Disconnect the device
|
|
311 |
|
|
312 |
iTestDevice->SoftwareDisconnect();
|
|
313 |
|
|
314 |
// Complete the test case request
|
|
315 |
|
|
316 |
TestPolicy().SignalTestComplete(iStatus.Int());
|
253
|
317 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0478_DEVICERUNL_EXIT, this );
|
0
|
318 |
}
|
|
319 |
|
|
320 |
|
|
321 |
}
|