253
|
1 |
// Copyright (c) 2008-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-0499.cpp
|
|
15 |
// @internalComponent
|
|
16 |
//
|
|
17 |
//
|
|
18 |
|
|
19 |
#include "PBASE-T_USBDI-0499.h"
|
|
20 |
#include "testpolicy.h"
|
|
21 |
#include "modelleddevices.h"
|
|
22 |
#include "testliterals.h"
|
253
|
23 |
#include "OstTraceDefinitions.h"
|
|
24 |
#ifdef OST_TRACE_COMPILER_IN_USE
|
|
25 |
#include "PBASE-T_USBDI-0499Traces.h"
|
|
26 |
#endif
|
0
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
namespace NUnitTesting_USBDI
|
|
32 |
{
|
|
33 |
const TInt KBulkMaxINTransferSize = 1200;
|
|
34 |
const TInt KBulkMaxOUTTransferSize = 150000;
|
|
35 |
const TUint KHostNumWriteBytesPreHalt1 = 128000;
|
|
36 |
const TUint KHostNumWriteBytesPreHalt2 = 128000;
|
|
37 |
const TUint KHostNumWriteBytesPostHalt1 = 512;
|
|
38 |
const TUint KHostNumWriteBytesPostHalt2 = 512;
|
|
39 |
const TInt KDeviceNumWrittenBytesPreHalt = KHostNumWriteBytesPreHalt1+KHostNumWriteBytesPreHalt2;
|
|
40 |
const TInt KDeviceNumReadBytesPostHalt = KHostNumWriteBytesPostHalt1+KHostNumWriteBytesPostHalt2;
|
|
41 |
const TInt KDeviceNumReadBytesPreHalt = 128;
|
|
42 |
const TInt KHostNumReadBytesPostHalt = KDeviceNumReadBytesPostHalt+1; //read cached data, allow 1 for ZLP
|
|
43 |
|
|
44 |
|
|
45 |
//Make these single bit values ...
|
|
46 |
// ... so that their completion can be easily recorded in a bit mask!
|
|
47 |
const TInt KBulkTransferInId0 = 1<<0;
|
|
48 |
const TInt KBulkTransferOutId0 = 1<<3;
|
|
49 |
const TInt KBulkTransferOutId1 = 1<<4;
|
|
50 |
|
|
51 |
const TInt KUnexpectedTransferID = -101;
|
|
52 |
const TInt KUndefinedStep = -102;
|
|
53 |
|
|
54 |
|
|
55 |
_LIT(KTestCaseId,"PBASE-T_USBDI-0499");
|
|
56 |
const TFunctorTestCase<CUT_PBASE_T_USBDI_0499,TBool> CUT_PBASE_T_USBDI_0499::iFunctor(KTestCaseId);
|
|
57 |
|
|
58 |
CUT_PBASE_T_USBDI_0499* CUT_PBASE_T_USBDI_0499::NewL(TBool aHostRole)
|
|
59 |
{
|
253
|
60 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0499_NEWL_ENTRY, aHostRole );
|
0
|
61 |
CUT_PBASE_T_USBDI_0499* self = new (ELeave) CUT_PBASE_T_USBDI_0499(aHostRole);
|
|
62 |
CleanupStack::PushL(self);
|
|
63 |
self->ConstructL();
|
|
64 |
CleanupStack::Pop(self);
|
253
|
65 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0499_NEWL_EXIT, ( TUint )( self ) );
|
0
|
66 |
return self;
|
|
67 |
}
|
|
68 |
|
|
69 |
|
|
70 |
CUT_PBASE_T_USBDI_0499::CUT_PBASE_T_USBDI_0499(TBool aHostRole)
|
|
71 |
: CBaseBulkTestCase(KTestCaseId,aHostRole),
|
|
72 |
iCaseStep(EInProgress)
|
|
73 |
{
|
253
|
74 |
OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0499_CUT_PBASE_T_USBDI_0499_ENTRY, this );
|
|
75 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0499_CUT_PBASE_T_USBDI_0499_EXIT, this );
|
0
|
76 |
}
|
|
77 |
|
|
78 |
|
|
79 |
void CUT_PBASE_T_USBDI_0499::ConstructL()
|
|
80 |
{
|
253
|
81 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0499_CONSTRUCTL_ENTRY, this );
|
0
|
82 |
BaseBulkConstructL();
|
253
|
83 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0499_CONSTRUCTL_EXIT, this );
|
0
|
84 |
}
|
|
85 |
|
|
86 |
|
|
87 |
CUT_PBASE_T_USBDI_0499::~CUT_PBASE_T_USBDI_0499()
|
|
88 |
{
|
253
|
89 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0499_CUT_PBASE_T_USBDI_0499_ENTRY_DUP01, this );
|
|
90 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0499_CUT_PBASE_T_USBDI_0499_EXIT_DUP01, this );
|
0
|
91 |
}
|
|
92 |
|
|
93 |
|
|
94 |
void CUT_PBASE_T_USBDI_0499::Ep0TransferCompleteL(TInt aCompletionCode)
|
|
95 |
{
|
253
|
96 |
OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0499_EP0TRANSFERCOMPLETEL_ENTRY, this );
|
0
|
97 |
|
253
|
98 |
OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0499_EP0TRANSFERCOMPLETEL, "Ep0TransferCompleteL with aCompletionCode = %d",aCompletionCode);
|
0
|
99 |
|
|
100 |
if(aCompletionCode != KErrNone)
|
|
101 |
{
|
|
102 |
if(iCaseStep == EFailed)
|
|
103 |
{// ignore error, nad catch the TestFailed method called further down.
|
253
|
104 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0499_EP0TRANSFERCOMPLETEL_DUP01, "***Failure sending FAIL message to client on endpoint 0***");
|
0
|
105 |
}
|
|
106 |
else
|
|
107 |
{
|
|
108 |
TBuf<256> msg;
|
|
109 |
msg.Format(_L("<Error %d> Transfer to control endpoint 0 was not successful"),aCompletionCode);
|
253
|
110 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0499_EP0TRANSFERCOMPLETEL_DUP02, msg);
|
0
|
111 |
iCaseStep = EFailed;
|
|
112 |
TTestCaseFailed request(aCompletionCode,msg);
|
|
113 |
iControlEp0->SendRequest(request,this);
|
253
|
114 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0499_EP0TRANSFERCOMPLETEL_EXIT, this );
|
0
|
115 |
return;
|
|
116 |
}
|
|
117 |
}
|
|
118 |
|
|
119 |
switch(iCaseStep)
|
|
120 |
{
|
|
121 |
// Test case passed
|
|
122 |
case EPassed:
|
|
123 |
TestPassed();
|
|
124 |
break;
|
|
125 |
|
|
126 |
// Test case failed
|
|
127 |
case EFailed:
|
|
128 |
TestFailed(KErrCompletion);
|
|
129 |
break;
|
|
130 |
|
|
131 |
case ETransferOutHalt:
|
|
132 |
iOutTransfer[0]->TransferOut(KLiteralFrench4(), KHostNumWriteBytesPreHalt1, EFalse);
|
|
133 |
iOutTransfer[1]->TransferOut(KLiteralFrench4(), KHostNumWriteBytesPreHalt2, EFalse);
|
|
134 |
break;
|
|
135 |
|
|
136 |
case EAwaitClearPreHalt:
|
|
137 |
{
|
253
|
138 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0499_EP0TRANSFERCOMPLETEL_DUP03, "Client has been asked to clear endpoint buffer");
|
0
|
139 |
User::After(1000000); //Give client time to clear buffer
|
|
140 |
TEndpointCancelReadRequest request(1,1);
|
|
141 |
iControlEp0->SendRequest(request,this);
|
|
142 |
iCaseStep = EAwaitCancelRead;
|
|
143 |
}
|
|
144 |
break;
|
|
145 |
|
|
146 |
case EAwaitCancelRead:
|
|
147 |
{
|
|
148 |
TEndpointReadRequest request(1,1, KDeviceNumReadBytesPostHalt);// EP1 because 1st writter EP
|
|
149 |
iControlEp0->SendRequest(request,this);
|
|
150 |
iCaseStep = ETransferOut;
|
|
151 |
}
|
|
152 |
break;
|
|
153 |
|
|
154 |
case ETransferOut:
|
253
|
155 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0499_EP0TRANSFERCOMPLETEL_DUP04, "Try to send data (post halt)");
|
0
|
156 |
iOutTransfer[0]->TransferOut(KLiteralEnglish8().Mid(0, KHostNumWriteBytesPostHalt1), EFalse);
|
|
157 |
iOutTransfer[1]->TransferOut(KLiteralEnglish8().Mid(KHostNumWriteBytesPostHalt1, KHostNumWriteBytesPostHalt2), EFalse);
|
|
158 |
break;
|
|
159 |
|
|
160 |
case ETransferIn:
|
253
|
161 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0499_EP0TRANSFERCOMPLETEL_DUP05, "Try to receive data");
|
0
|
162 |
iInTransfer[0]->TransferIn(KHostNumReadBytesPostHalt);
|
|
163 |
break;
|
|
164 |
|
|
165 |
default:
|
253
|
166 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0499_EP0TRANSFERCOMPLETEL_DUP06, "<Error> Unknown test step");
|
0
|
167 |
TestFailed(KErrUnknown);
|
|
168 |
break;
|
|
169 |
}
|
253
|
170 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0499_EP0TRANSFERCOMPLETEL_EXIT_DUP01, this );
|
0
|
171 |
}
|
|
172 |
|
|
173 |
void CUT_PBASE_T_USBDI_0499::TransferCompleteL(TInt aTransferId,TInt aCompletionCode)
|
|
174 |
{
|
253
|
175 |
OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0499_TRANSFERCOMPLETEL_ENTRY, this );
|
0
|
176 |
Cancel();
|
|
177 |
|
|
178 |
TInt err(KErrNone);
|
|
179 |
TBuf<256> msg;
|
253
|
180 |
OstTraceExt2(TRACE_NORMAL, CUT_PBASE_T_USBDI_0499_TRANSFERCOMPLETEL, "Transfer completed (id=%d), aCompletionCode = %d",aTransferId, aCompletionCode);
|
0
|
181 |
|
|
182 |
switch(iCaseStep)
|
|
183 |
{
|
|
184 |
case ETransferOutHalt:
|
|
185 |
{
|
|
186 |
if(aCompletionCode != KErrUsbStalled)
|
|
187 |
{
|
|
188 |
iOutTransfer[0]->Cancel();
|
|
189 |
iOutTransfer[1]->Cancel();
|
|
190 |
err = KErrCorrupt;
|
|
191 |
msg.Format(_L("<Error %d> The transfer completed with no errors but the endpoint should have halted"),aCompletionCode);
|
|
192 |
break; //switch(iCaseStep)
|
|
193 |
}
|
|
194 |
|
|
195 |
switch(aTransferId)
|
|
196 |
{
|
|
197 |
case KBulkTransferOutId0:
|
|
198 |
case KBulkTransferOutId1:
|
|
199 |
iTransferComplete |= aTransferId;
|
253
|
200 |
OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0499_TRANSFERCOMPLETEL_DUP01, "Transfer %d stalled", aTransferId);
|
0
|
201 |
break; //switch(aTransferId)
|
|
202 |
|
|
203 |
default:
|
|
204 |
iTransferComplete = 0; //reset
|
|
205 |
err = KUnexpectedTransferID;
|
|
206 |
msg.Format(_L("<Error %d> Unexpected transfer ID, wanted %d or %d, got %d"),
|
|
207 |
err, KBulkTransferOutId0, KBulkTransferOutId1, aTransferId);
|
|
208 |
break; //switch(aTransferId)
|
|
209 |
}
|
|
210 |
|
|
211 |
if(err==KErrNone && iTransferComplete == (KBulkTransferOutId0 | KBulkTransferOutId1))
|
|
212 |
{
|
253
|
213 |
OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0499_TRANSFERCOMPLETEL_DUP02, "Clear halt and try to send data again. Transfers Completed %d", iTransferComplete);
|
0
|
214 |
// Acknowledge the stall and clear
|
|
215 |
err = iTestPipeInterface1BulkOut.ClearRemoteStall();
|
|
216 |
if(err != KErrNone)
|
|
217 |
{
|
|
218 |
msg.Format(_L("<Error %d> The remote stall cannot be cleared"),err);
|
|
219 |
break; //switch(iCaseStep)
|
|
220 |
}
|
|
221 |
iCaseStep = EAwaitClearPreHalt;
|
|
222 |
TEndpointReadRequest request(1,1, KDeviceNumWrittenBytesPreHalt);// EP1 because 1st writter EP
|
|
223 |
iControlEp0->SendRequest(request,this);
|
|
224 |
iTransferComplete = 0; //reset
|
|
225 |
}
|
|
226 |
}
|
|
227 |
break; //switch(iCaseStep)
|
|
228 |
|
|
229 |
case ETransferOut:
|
|
230 |
{
|
|
231 |
if(aCompletionCode != KErrNone)
|
|
232 |
{
|
|
233 |
iOutTransfer[0]->Cancel();
|
|
234 |
iOutTransfer[1]->Cancel();
|
|
235 |
err = KErrCorrupt;
|
|
236 |
msg.Format(_L("<Error %d> No data sent on bulk OUT request"),aCompletionCode);
|
|
237 |
break; //switch(iCaseStep)
|
|
238 |
}
|
|
239 |
|
|
240 |
switch(aTransferId)
|
|
241 |
{
|
|
242 |
case KBulkTransferOutId0:
|
|
243 |
case KBulkTransferOutId1:
|
|
244 |
iTransferComplete |= aTransferId;
|
253
|
245 |
OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0499_TRANSFERCOMPLETEL_DUP03, "Transfer %d completed", aTransferId);
|
0
|
246 |
break; //switch(aTransferId)
|
|
247 |
|
|
248 |
default:
|
|
249 |
iTransferComplete = 0; //reset
|
|
250 |
err = KUnexpectedTransferID;
|
|
251 |
msg.Format(_L("<Error %d> Unexpected transfer ID, wanted %d or %d, got %d"),
|
|
252 |
err, KBulkTransferOutId0, KBulkTransferOutId1, aTransferId);
|
|
253 |
break; //switch(aTransferId)
|
|
254 |
}
|
|
255 |
|
|
256 |
if(err==KErrNone && iTransferComplete == (KBulkTransferOutId0 | KBulkTransferOutId1))
|
|
257 |
{
|
253
|
258 |
OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0499_TRANSFERCOMPLETEL_DUP04, "Try to receive back sent data. Transfers Completed %d", iTransferComplete);
|
0
|
259 |
iCaseStep = ETransferIn;
|
|
260 |
TWriteSynchronousCachedReadDataRequest request(1,1,1);
|
|
261 |
iControlEp0->SendRequest(request,this);
|
|
262 |
iTransferComplete = 0; //reset
|
|
263 |
}
|
|
264 |
break; //switch(iCaseStep)
|
|
265 |
|
|
266 |
case ETransferIn:
|
|
267 |
if(aCompletionCode != KErrNone)
|
|
268 |
{
|
|
269 |
err = KErrCorrupt;
|
|
270 |
msg.Format(_L("<Error %d> No data sent on bulk IN request"),aCompletionCode);
|
|
271 |
break; //switch(iCaseStep)
|
|
272 |
}
|
|
273 |
|
|
274 |
if(aTransferId != KBulkTransferInId0)
|
|
275 |
{
|
|
276 |
iTransferComplete = 0; //reset
|
|
277 |
err = KUnexpectedTransferID;
|
|
278 |
msg.Format(_L("<Error %d> Unexpected transfer ID, wanted %d , got %d"),
|
|
279 |
err, KBulkTransferInId0, aTransferId);
|
|
280 |
break; //switch(iCaseStep)
|
|
281 |
}
|
|
282 |
|
|
283 |
// else ok, compare data rcvd now
|
|
284 |
TPtrC8 data1(iInTransfer[0]->DataPolled());
|
|
285 |
if(ValidateData(data1, KLiteralEnglish8().Mid(0, KDeviceNumReadBytesPostHalt)) == EFalse)
|
|
286 |
{
|
|
287 |
err = KErrCompletion; //indicates data validation failure
|
|
288 |
msg.Format(_L("<Error %d> Bulk transfer IN data received does not match Bulk Transfer OUT data"), err);
|
|
289 |
break; //switch(iCaseStep)
|
|
290 |
}
|
|
291 |
|
|
292 |
// Comparison is a match
|
253
|
293 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0499_TRANSFERCOMPLETEL_DUP05, "Comparison for IN transfer is a match");
|
0
|
294 |
iCaseStep = EPassed;
|
|
295 |
TTestCasePassed request;
|
|
296 |
iControlEp0->SendRequest(request,this);
|
|
297 |
iTransferComplete = 0; //reset
|
|
298 |
}
|
|
299 |
break; //switch(iCaseStep)
|
|
300 |
|
|
301 |
default:
|
|
302 |
err = KUndefinedStep;
|
|
303 |
msg.Format(_L("<Error %d> Undefined case step %d reached"),KUndefinedStep, iCaseStep);
|
|
304 |
break; //switch(iCaseStep)
|
|
305 |
}
|
|
306 |
|
|
307 |
if(err == KErrCompletion)
|
|
308 |
//indicates data validation failure
|
|
309 |
{
|
|
310 |
msg.Format(_L("<Error %d> Bulk transfer IN data received does not match Bulk Transfer OUT data"), err);
|
|
311 |
}
|
|
312 |
|
|
313 |
if(err!=KErrNone)
|
|
314 |
{
|
253
|
315 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0499_TRANSFERCOMPLETEL_DUP06, msg);
|
0
|
316 |
iCaseStep = EFailed;
|
|
317 |
TTestCaseFailed request(err,msg);
|
|
318 |
return iControlEp0->SendRequest(request,this);
|
|
319 |
}
|
253
|
320 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0499_TRANSFERCOMPLETEL_EXIT, this );
|
0
|
321 |
}
|
|
322 |
|
|
323 |
void CUT_PBASE_T_USBDI_0499::DeviceInsertedL(TUint aDeviceHandle)
|
|
324 |
{
|
253
|
325 |
OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0499_DEVICEINSERTEDL_ENTRY, this );
|
0
|
326 |
|
|
327 |
Cancel();
|
|
328 |
|
|
329 |
if(BaseBulkDeviceInsertedL(aDeviceHandle) == EDeviceConfigurationError)
|
|
330 |
// Prepare for response from control transfer to client
|
|
331 |
{
|
|
332 |
iCaseStep = EFailed;
|
|
333 |
}
|
|
334 |
|
|
335 |
// Create the bulk transfers
|
|
336 |
iInTransfer[0] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkIn,iUsbInterface1,KBulkMaxINTransferSize,*this,KBulkTransferInId0);
|
|
337 |
iOutTransfer[0] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkOut,iUsbInterface1,KBulkMaxOUTTransferSize,*this,KBulkTransferOutId0);
|
|
338 |
iOutTransfer[1] = new (ELeave) CBulkTransfer(iTestPipeInterface1BulkOut,iUsbInterface1,KBulkMaxOUTTransferSize,*this,KBulkTransferOutId1);
|
|
339 |
|
|
340 |
// Initialise the descriptors for transfer
|
253
|
341 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0499_DEVICEINSERTEDL, "Initialising the transfer descriptors");
|
0
|
342 |
TInt err = iUsbInterface1.InitialiseTransferDescriptors();
|
|
343 |
if(err != KErrNone)
|
|
344 |
{
|
|
345 |
TBuf<256> msg;
|
|
346 |
msg.Format(_L("<Error %d> Unable to initialise transfer descriptors"),err);
|
253
|
347 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0499_DEVICEINSERTEDL_DUP01, msg);
|
0
|
348 |
iCaseStep = EFailed;
|
|
349 |
TTestCaseFailed request(err,msg);
|
|
350 |
iControlEp0->SendRequest(request,this);
|
253
|
351 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0499_DEVICEINSERTEDL_EXIT, this );
|
0
|
352 |
return;
|
|
353 |
}
|
|
354 |
|
|
355 |
iCaseStep = ETransferOutHalt;
|
|
356 |
TEndpointReadAndHaltRequest request(1,1,KDeviceNumReadBytesPreHalt);// EP1 means endpoint index 1 not the actual endpoint number
|
|
357 |
iControlEp0->SendRequest(request,this);
|
253
|
358 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0499_DEVICEINSERTEDL_EXIT_DUP01, this );
|
0
|
359 |
}
|
|
360 |
|
|
361 |
} //end namespace
|