author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Thu, 02 Sep 2010 21:54:16 +0300 | |
changeset 259 | 57b9594f5772 |
parent 0 | a41df078684a |
child 257 | 3e88ff8f41d5 |
permissions | -rw-r--r-- |
259
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
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 |
// @internalComponent |
|
15 |
// |
|
16 |
// |
|
17 |
||
18 |
#include <e32std.h> |
|
19 |
#include <e32std_private.h> |
|
20 |
#include <u32std.h> // unicode builds |
|
21 |
#include <e32base.h> |
|
22 |
#include <e32base_private.h> |
|
23 |
#include <e32Test.h> // RTest headder |
|
24 |
#include "testcaseroot.h" |
|
25 |
#include "b2bwatchers.h" |
|
26 |
#include "testcase0680.h" |
|
259
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
27 |
#include "OstTraceDefinitions.h" |
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
28 |
#ifdef OST_TRACE_COMPILER_IN_USE |
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
29 |
#include "testcase0680Traces.h" |
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
30 |
#endif |
0 | 31 |
|
32 |
#define _REPEATS (oOpenIterations*3) |
|
33 |
||
34 |
||
35 |
/* ************************************************************************************** |
|
36 |
* the name below is used to add a pointer to our construction method to a pointer MAP in |
|
37 |
* the class factory |
|
38 |
*/ |
|
39 |
_LIT(KTestCaseId,"PBASE-USB_OTGDI-0680"); |
|
40 |
const TTestCaseFactoryReceipt<CTestCase0680> CTestCase0680::iFactoryReceipt(KTestCaseId); |
|
41 |
||
42 |
CTestCase0680* CTestCase0680::NewL(TBool aHost) |
|
43 |
{ |
|
259
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
44 |
if(gVerboseOutput) |
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
45 |
{ |
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
46 |
OstTraceFunctionEntry0(CTESTCASE0680_NEWL); |
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
47 |
} |
0 | 48 |
CTestCase0680* self = new (ELeave) CTestCase0680(aHost); |
49 |
CleanupStack::PushL(self); |
|
50 |
self->ConstructL(); |
|
51 |
CleanupStack::Pop(self); |
|
52 |
return self; |
|
53 |
} |
|
54 |
||
55 |
||
56 |
CTestCase0680::CTestCase0680(TBool aHost) |
|
57 |
: CTestCaseB2BRoot(KTestCaseId, aHost, iStatus) |
|
58 |
{ |
|
259
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
59 |
if(gVerboseOutput) |
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
60 |
{ |
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
61 |
OstTraceFunctionEntry0(CTESTCASE0680_CTESTCASE0680); |
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
62 |
} |
0 | 63 |
|
64 |
} |
|
65 |
||
66 |
||
67 |
/** |
|
68 |
ConstructL |
|
69 |
*/ |
|
70 |
void CTestCase0680::ConstructL() |
|
71 |
{ |
|
259
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
72 |
if(gVerboseOutput) |
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
73 |
{ |
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
74 |
OstTraceFunctionEntry0(CTESTCASE0680_CONSTRUCTL); |
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
75 |
} |
0 | 76 |
|
77 |
iDualRoleCase = ETrue; // another back-back |
|
78 |
||
79 |
BaseConstructL(); |
|
80 |
} |
|
81 |
||
82 |
||
83 |
CTestCase0680::~CTestCase0680() |
|
84 |
{ |
|
259
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
85 |
if(gVerboseOutput) |
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
86 |
{ |
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
87 |
OstTraceFunctionEntry0(CTESTCASE0680_DCTESTCASE0680); |
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
88 |
} |
0 | 89 |
iCollector.DestroyObservers(); |
90 |
Cancel(); |
|
91 |
} |
|
92 |
||
93 |
||
94 |
void CTestCase0680::ExecuteTestCaseL() |
|
95 |
{ |
|
259
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
96 |
if(gVerboseOutput) |
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
97 |
{ |
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
98 |
OstTraceFunctionEntry0(CTESTCASE0680_EXECUTETESTCASEL); |
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
99 |
} |
0 | 100 |
iCaseStep = EPreconditions; |
101 |
CActiveScheduler::Add(this); |
|
102 |
SelfComplete(); |
|
103 |
} |
|
104 |
||
105 |
||
106 |
void CTestCase0680::DoCancel() |
|
107 |
{ |
|
259
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
108 |
if(gVerboseOutput) |
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
109 |
{ |
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
110 |
OstTraceFunctionEntry0(CTESTCASE0680_DOCANCEL); |
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
111 |
} |
0 | 112 |
// cancel our timer |
113 |
iTimer.Cancel(); |
|
114 |
} |
|
115 |
||
116 |
||
117 |
// handle event completion |
|
118 |
void CTestCase0680::RunStepL() |
|
119 |
{ |
|
259
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
120 |
if(gVerboseOutput) |
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
121 |
{ |
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
122 |
OstTraceFunctionEntry0(CTESTCASE0680_RUNSTEPL); |
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
123 |
} |
0 | 124 |
// Obtain the completion code for this CActive obj. |
125 |
TInt completionCode(iStatus.Int()); |
|
126 |
TBuf<MAX_DSTRLEN> aDescription; |
|
127 |
TInt err(0); |
|
128 |
||
129 |
switch(iCaseStep) |
|
130 |
{ |
|
131 |
case EPreconditions: |
|
132 |
{ |
|
133 |
LOG_STEPNAME(_L("EPreconditions")) |
|
134 |
iCaseStep = ELoadLdd; |
|
135 |
StepB2BPreconditions(); |
|
136 |
break; |
|
137 |
} |
|
138 |
||
139 |
// 1. Load the Client LDD |
|
140 |
case ELoadLdd: |
|
141 |
{ |
|
142 |
LOG_STEPNAME(_L("ELoadLdd")) |
|
143 |
if (!StepLoadClient(0xF680)) // Use default params, so HNP/SRP both supported |
|
144 |
{ |
|
145 |
return TestFailed(KErrAbort, _L("Client Load Failure")); |
|
146 |
} |
|
147 |
// load OTG ldd and init. |
|
148 |
if (!StepLoadLDD()) |
|
149 |
{ |
|
150 |
return TestFailed(KErrAbort, _L("OTG Load Failure")); |
|
151 |
} |
|
152 |
||
153 |
// NB. We don't load the FDF Actor, because we don't want |
|
154 |
// the A-Host to suspend the attached B-Peripheral. |
|
155 |
||
156 |
// test that the right cable is in |
|
157 |
CheckRoleConnections(); |
|
158 |
||
159 |
// subscribe to OTG states,events and messages now that it has loaded OK |
|
160 |
TRAPD(result, iCollector.CreateObserversL(*this)); |
|
161 |
if (KErrNone != result) |
|
162 |
return(TestFailed(KErrNoMemory, _L("Unable to create observers"))); |
|
163 |
iCollector.ClearAllEvents(); |
|
164 |
iCaseStep = EReadyToRaiseVBus; |
|
165 |
SelfComplete(); |
|
166 |
break; |
|
167 |
} |
|
168 |
||
169 |
case EReadyToRaiseVBus: |
|
170 |
{ |
|
171 |
test.Printf(_L("Into EReadyToRaiseVBus step...\n")); |
|
259
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
172 |
OstTrace0(TRACE_NORMAL, CTESTCASE0680_RUNSTEPL_DUP01, "Into EReadyToRaiseVBus step...\n"); |
0 | 173 |
if (gTestRoleMaster) |
174 |
{ |
|
175 |
// wait for Vbus to be raised |
|
176 |
iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBIdle); |
|
177 |
iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventVbusRaised); |
|
178 |
iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBPeripheral); |
|
179 |
} |
|
180 |
else |
|
181 |
{ // slave "A" |
|
182 |
// Raise VBus, then wait for default role |
|
183 |
err = otgBusRequest(); // ok to turn on VBus now |
|
184 |
if (KErrNone != err) |
|
185 |
{ |
|
186 |
return TestFailed(KErrAbort, _L("Raise Vbus - RUsbOtgDriver::BusRequest() FAILED!")); |
|
187 |
} |
|
188 |
||
189 |
// we might also wait for and EStateAIdle |
|
190 |
iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateAIdle); |
|
191 |
iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventVbusRaised); |
|
192 |
iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventRoleChangedToHost); |
|
193 |
} |
|
194 |
||
195 |
const TInt KTestCase0680VBusRaiseTimeout = 2000; // 2 seconds, should be plenty of time for this test |
|
196 |
iCollector.AddStepTimeout(KTestCase0680VBusRaiseTimeout); |
|
197 |
||
198 |
iCaseStep = EDefaultRoles; |
|
199 |
SetActive(); |
|
200 |
break; |
|
201 |
} |
|
202 |
||
203 |
case EDefaultRoles: |
|
204 |
{ |
|
205 |
test.Printf(_L("Into EDefaultRoles step...\n")); |
|
259
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
206 |
OstTrace0(TRACE_NORMAL, CTESTCASE0680_RUNSTEPL_DUP02, "Into EDefaultRoles step...\n"); |
0 | 207 |
LOG_STEPNAME(_L("EWaitEnumeration")); |
208 |
||
209 |
if (gTestRoleMaster) |
|
210 |
{ |
|
211 |
// B-Device should now wait until it is configured |
|
212 |
iCollector.AddRequiredNotification(EWatcherPeripheralState, EUsbcDeviceStateConfigured); |
|
213 |
||
214 |
const TInt KTestCase0680BTimeout = 5000; // 5 seconds, should be plenty of time for overall test |
|
215 |
iCollector.AddStepTimeout(KTestCase0680BTimeout); |
|
216 |
||
217 |
iCaseStep = EBConfigured; |
|
218 |
} |
|
219 |
else |
|
220 |
{ |
|
221 |
// A-Device should expect nothing more (role swap won't happen |
|
222 |
// because the B-Device doesn't indicate support for OTG in its |
|
223 |
// OTG descriptor, so the host won't have sent SetFeature(b_hnp_enable)) |
|
224 |
// Instead, just rely on the test timeout and display a request for the user |
|
225 |
// to observe the B-Device test code for the pass/fail |
|
226 |
const TInt KTestCase0680ATimeout = 4000; // 4 seconds before A-Device drops VBus (before B test times out at 5 seconds) |
|
227 |
iCollector.AddStepTimeout(KTestCase0680ATimeout); // NB. In this test on the A-Device, we expect to timeout |
|
228 |
// so a timeout isn't treated as a failure |
|
229 |
test.Printf(_L("NOTE : Please observe test result on B-Device...\n")); |
|
259
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
230 |
OstTrace0(TRACE_NORMAL, CTESTCASE0680_RUNSTEPL_DUP03, "NOTE : Please observe test result on B-Device...\n"); |
0 | 231 |
iCaseStep = EDropVBus; // This is the step the A-Device will go to |
232 |
// when the timer (set up in previous test) fires |
|
233 |
} |
|
234 |
SetActive(); |
|
235 |
break; |
|
236 |
} |
|
237 |
||
238 |
||
239 |
case EBConfigured: // A B-Device only step! |
|
240 |
{ |
|
241 |
test.Printf(_L("Into EBConfigured step...\n")); |
|
259
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
242 |
OstTrace0(TRACE_NORMAL, CTESTCASE0680_RUNSTEPL_DUP04, "Into EBConfigured step...\n"); |
0 | 243 |
if (KTestCaseWatchdogTO == iStatus.Int()) |
244 |
{ |
|
245 |
iCollector.DestroyObservers(); |
|
246 |
return TestFailed(KErrAbort, _L("Timeout")); |
|
247 |
} |
|
248 |
||
249 |
iCollector.AddRequiredNotification(EWatcherMessage, RUsbOtgDriver::EMessageHnpNotSuspended); |
|
250 |
||
251 |
test.Printf(_L("Attempting a swap on an unsuspended link...\n")); |
|
259
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
252 |
OstTrace0(TRACE_NORMAL, CTESTCASE0680_RUNSTEPL_DUP05, "Attempting a swap on an unsuspended link...\n"); |
0 | 253 |
err = otgBusRequest(); // Request the host role |
254 |
||
255 |
if (KErrNone != err) |
|
256 |
{ |
|
257 |
test.Printf(_L("BusRequest returned %d)"),err); |
|
259
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
258 |
OstTrace1(TRACE_NORMAL, CTESTCASE0680_RUNSTEPL_DUP06, "BusRequest returned %d)",err); |
0 | 259 |
return TestFailed(KErrAbort, _L("BusRequest() failed!")); |
260 |
} |
|
261 |
||
262 |
iCaseStep = EBErrorReceived; |
|
263 |
SetActive(); |
|
264 |
break; |
|
265 |
} |
|
266 |
||
267 |
case EBErrorReceived: |
|
268 |
{ |
|
269 |
if (KTestCaseWatchdogTO == iStatus.Int()) |
|
270 |
{ |
|
271 |
iCollector.DestroyObservers(); |
|
272 |
return TestFailed(KErrAbort, _L("Timeout")); |
|
273 |
} |
|
274 |
||
275 |
test.Printf(_L("Into EBErrorReceived step...\n")); |
|
259
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
276 |
OstTrace0(TRACE_NORMAL, CTESTCASE0680_RUNSTEPL_DUP07, "Into EBErrorReceived step...\n"); |
0 | 277 |
iCaseStep = EDropVBus; // Test has pretty much passed now. Just wait for A-Device to drop VBus. |
278 |
SelfComplete(); |
|
279 |
break; |
|
280 |
} |
|
281 |
||
282 |
case EDropVBus: |
|
283 |
LOG_STEPNAME(_L("EDropVBus")) |
|
284 |
||
285 |
iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventVbusDropped); |
|
286 |
if ( gTestRoleMaster) |
|
287 |
{ |
|
288 |
iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBIdle); |
|
289 |
} |
|
290 |
else |
|
291 |
{ // SLAVE "A" |
|
292 |
iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateAIdle); |
|
293 |
otgBusDrop(); |
|
294 |
} |
|
295 |
iCaseStep = EVBusDropped; |
|
296 |
SetActive(); |
|
297 |
break; |
|
298 |
||
299 |
case EVBusDropped: |
|
300 |
LOG_STEPNAME(_L("ELoopVerifyDrop")) |
|
301 |
if (KTestCaseWatchdogTO == iStatus.Int() && gTestRoleMaster) |
|
302 |
{ |
|
303 |
// Remember, a timeout is only a failure for the B-Device in this test, |
|
304 |
// we're expecting and relying on a timeout on the A-Device to conclude |
|
305 |
// the test and bring VBus down. |
|
306 |
return TestFailed(KErrAbort, _L("Timeout")); |
|
307 |
} |
|
308 |
||
309 |
if (otgVbusPresent()) |
|
310 |
{ |
|
311 |
return TestFailed(KErrAbort, _L("Vbus did not drop - FAILED!")); |
|
312 |
} |
|
313 |
iCaseStep = EUnloadLdd; |
|
314 |
SelfComplete(); |
|
315 |
break; |
|
316 |
||
317 |
case EUnloadLdd: |
|
318 |
LOG_STEPNAME(_L("EUnloadLdd")) |
|
319 |
iCollector.DestroyObservers(); |
|
320 |
||
321 |
if (EFalse == StepUnloadLDD()) |
|
322 |
return TestFailed(KErrAbort,_L("unload Ldd failure")); |
|
323 |
if (!StepUnloadClient()) |
|
324 |
return TestFailed(KErrAbort,_L("Client Unload Failure")); |
|
325 |
||
326 |
iCaseStep = ELastStep; |
|
327 |
SelfComplete(); |
|
328 |
break; |
|
329 |
||
330 |
case ELastStep: |
|
331 |
LOG_STEPNAME(_L("ELastStep")) |
|
332 |
TestPassed(); |
|
333 |
break; |
|
334 |
||
335 |
default: |
|
336 |
test.Printf(_L("<Error> unknown test step")); |
|
259
57b9594f5772
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
337 |
OstTrace0(TRACE_NORMAL, CTESTCASE0680_RUNSTEPL_DUP08, "<Error> unknown test step"); |
0 | 338 |
Cancel(); |
339 |
return (TestFailed(KErrCorrupt, _L("<Error> unknown test step"))); |
|
340 |
} |
|
341 |
} |