44
|
1 |
// Copyright (c) 2007-2009 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 "testcasewd.h"
|
|
26 |
#include "b2bwatchers.h"
|
|
27 |
#include "testcase0683.h"
|
|
28 |
|
|
29 |
#define _REPEATS (oOpenIterations*3)
|
|
30 |
|
|
31 |
|
|
32 |
/* **************************************************************************************
|
|
33 |
* the name below is used to add a pointer to our construction method to a pointer MAP in
|
|
34 |
* the class factory
|
|
35 |
*/
|
|
36 |
_LIT(KTestCaseId,"PBASE-USB_OTGDI-0683");
|
|
37 |
const TTestCaseFactoryReceipt<CTestCase0683> CTestCase0683::iFactoryReceipt(KTestCaseId);
|
|
38 |
|
|
39 |
CTestCase0683* CTestCase0683::NewL(TBool aHost)
|
|
40 |
{
|
44
|
41 |
LOG_FUNC
|
0
|
42 |
CTestCase0683* self = new (ELeave) CTestCase0683(aHost);
|
|
43 |
CleanupStack::PushL(self);
|
|
44 |
self->ConstructL();
|
|
45 |
CleanupStack::Pop(self);
|
|
46 |
return self;
|
|
47 |
}
|
|
48 |
|
|
49 |
|
|
50 |
CTestCase0683::CTestCase0683(TBool aHost)
|
|
51 |
: CTestCaseB2BRoot(KTestCaseId, aHost, iStatus)
|
|
52 |
{
|
44
|
53 |
LOG_FUNC
|
0
|
54 |
|
|
55 |
}
|
|
56 |
|
|
57 |
|
|
58 |
/**
|
|
59 |
ConstructL
|
|
60 |
*/
|
|
61 |
void CTestCase0683::ConstructL()
|
|
62 |
{
|
44
|
63 |
LOG_FUNC
|
0
|
64 |
|
|
65 |
iDualRoleCase = ETrue; // another back-back
|
|
66 |
|
|
67 |
BaseConstructL();
|
|
68 |
}
|
|
69 |
|
|
70 |
|
|
71 |
CTestCase0683::~CTestCase0683()
|
|
72 |
{
|
44
|
73 |
LOG_FUNC
|
0
|
74 |
iCollector.DestroyObservers();
|
|
75 |
Cancel();
|
|
76 |
}
|
|
77 |
|
|
78 |
|
|
79 |
void CTestCase0683::ExecuteTestCaseL()
|
|
80 |
{
|
44
|
81 |
LOG_FUNC
|
0
|
82 |
iCaseStep = EPreconditions;
|
|
83 |
iHNPCounter = 3; // To be decremented to govern the number of times we do HNP.
|
|
84 |
CActiveScheduler::Add(this);
|
|
85 |
SelfComplete();
|
|
86 |
}
|
|
87 |
|
|
88 |
|
|
89 |
void CTestCase0683::DoCancel()
|
|
90 |
{
|
44
|
91 |
LOG_FUNC
|
0
|
92 |
// cancel our timer
|
|
93 |
iTimer.Cancel();
|
|
94 |
}
|
|
95 |
|
|
96 |
|
|
97 |
// handle event completion
|
|
98 |
void CTestCase0683::RunStepL()
|
|
99 |
{
|
44
|
100 |
LOG_FUNC
|
0
|
101 |
// Obtain the completion code for this CActive obj.
|
|
102 |
TInt completionCode(iStatus.Int());
|
|
103 |
TBuf<MAX_DSTRLEN> aDescription;
|
|
104 |
TInt err(0);
|
|
105 |
|
|
106 |
switch(iCaseStep)
|
|
107 |
{
|
|
108 |
case EPreconditions:
|
|
109 |
{
|
|
110 |
LOG_STEPNAME(_L("EPreconditions"))
|
|
111 |
iCaseStep = ELoadLdd;
|
|
112 |
StepB2BPreconditions();
|
|
113 |
break;
|
|
114 |
}
|
|
115 |
|
|
116 |
// 1. Load the Client LDD
|
|
117 |
case ELoadLdd:
|
|
118 |
{
|
|
119 |
LOG_STEPNAME(_L("ELoadLdd"))
|
|
120 |
if (!StepLoadClient(0xF678/*use default settings for SRP/HNP support*/))
|
|
121 |
{
|
|
122 |
return TestFailed(KErrAbort, _L("Client Load Failure"));
|
|
123 |
}
|
|
124 |
// load OTG ldd and init.
|
|
125 |
if (!StepLoadLDD())
|
|
126 |
{
|
|
127 |
return TestFailed(KErrAbort, _L("OTG Load Failure"));
|
|
128 |
}
|
|
129 |
|
|
130 |
if(otgActivateFdfActor()!=KErrNone)
|
|
131 |
{
|
|
132 |
return TestFailed(KErrAbort, _L("Couldn't load FDF Actor"));
|
|
133 |
}
|
|
134 |
|
|
135 |
// test that the right cable is in
|
|
136 |
CheckRoleConnections();
|
|
137 |
|
|
138 |
// subscribe to OTG states,events and messages now that it has loaded OK
|
|
139 |
TRAPD(result, iCollector.CreateObserversL(*this));
|
|
140 |
if (KErrNone != result)
|
|
141 |
return(TestFailed(KErrNoMemory, _L("Unable to create observers")));
|
|
142 |
iCollector.ClearAllEvents();
|
|
143 |
iCaseStep = EReadyToRaiseVBus;
|
|
144 |
SelfComplete();
|
|
145 |
break;
|
|
146 |
}
|
|
147 |
|
|
148 |
case EReadyToRaiseVBus:
|
|
149 |
{
|
|
150 |
if (gTestRoleMaster)
|
|
151 |
{
|
|
152 |
// wait for Vbus to be raised
|
|
153 |
iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBIdle);
|
|
154 |
iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventVbusRaised);
|
|
155 |
iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBPeripheral);
|
|
156 |
// All as usual - we should report a failure if the B-Device ever reports "busy"
|
|
157 |
iCollector.AddFailureNotification(EWatcherAConnectionIdle, RUsbOtgDriver::EConnectionBusy);
|
|
158 |
}
|
|
159 |
else
|
|
160 |
{ // slave "A"
|
|
161 |
// Raise VBus, then wait for default role
|
|
162 |
err = otgBusRequest(); // ok to turn on VBus now
|
|
163 |
if (KErrNone != err)
|
|
164 |
{
|
|
165 |
return TestFailed(KErrAbort, _L("Raise Vbus - RUsbOtgDriver::BusRequest() FAILED!"));
|
|
166 |
}
|
|
167 |
|
|
168 |
// we might also wait for and EStateAIdle
|
|
169 |
iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateAIdle);
|
|
170 |
iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventVbusRaised);
|
|
171 |
iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventRoleChangedToHost);
|
|
172 |
iCollector.AddRequiredNotification(EWatcherAConnectionIdle, RUsbOtgDriver::EConnectionBusy);
|
|
173 |
}
|
|
174 |
iCaseStep = EDefaultRoles;
|
|
175 |
const TInt KTestCase0683Timeout = 30000; // 30 seconds, should be plenty of time for 3 role swaps
|
|
176 |
iCollector.AddStepTimeout(KTestCase0683Timeout);
|
|
177 |
SetActive();
|
|
178 |
break;
|
|
179 |
}
|
|
180 |
|
|
181 |
case EDefaultRoles:
|
|
182 |
{
|
|
183 |
test.Printf(_L("Into EDefaultRoles step...\n"));
|
|
184 |
|
|
185 |
if (KTestCaseWatchdogTO == iStatus.Int())
|
|
186 |
{
|
|
187 |
iCollector.DestroyObservers();
|
|
188 |
return TestFailed(KErrAbort, _L("Timeout"));
|
|
189 |
}
|
|
190 |
|
|
191 |
if ( --iHNPCounter > 0)
|
|
192 |
{
|
|
193 |
// We want to do further role swapping
|
|
194 |
if (gTestRoleMaster)
|
|
195 |
{
|
|
196 |
// B-Device should now wait until it is configured
|
|
197 |
iCollector.AddRequiredNotification(EWatcherPeripheralState, EUsbcDeviceStateConfigured);
|
|
198 |
iCaseStep = EBConfigured;
|
|
199 |
}
|
|
200 |
else
|
|
201 |
{
|
|
202 |
iCollector.AddRequiredNotification(EWatcherAConnectionIdle, RUsbOtgDriver::EConnectionIdle);
|
|
203 |
iCaseStep = EAIdleHostPriorToAPeripheral;
|
|
204 |
}
|
|
205 |
SetActive();
|
|
206 |
}
|
|
207 |
else
|
|
208 |
{
|
|
209 |
// We've done 3 x HNP cycles back to default roles.
|
|
210 |
// This time, we want A-Host to suspend B-Peripheral,
|
|
211 |
// have the B-Peripheral *not* do a bus request, then
|
|
212 |
// have the A-Device detect idle and shut down VBus.
|
|
213 |
if (gTestRoleMaster)
|
|
214 |
{
|
|
215 |
// B-Device should now wait until it is configured (for the last time this test)
|
|
216 |
iCollector.AddRequiredNotification(EWatcherPeripheralState, EUsbcDeviceStateConfigured);
|
|
217 |
iCaseStep = EBConfigured;
|
|
218 |
}
|
|
219 |
else
|
|
220 |
{
|
|
221 |
iCollector.AddRequiredNotification(EWatcherAConnectionIdle, RUsbOtgDriver::EConnectionIdle);
|
|
222 |
iCaseStep = EAIdleHostPriorToVBusDown;
|
|
223 |
}
|
|
224 |
SetActive();
|
|
225 |
}
|
|
226 |
break;
|
|
227 |
}
|
|
228 |
|
|
229 |
case EBConfigured: // A B-Device only step!
|
|
230 |
{
|
|
231 |
test.Printf(_L("Into EBConfigured step...\n"));
|
|
232 |
if (KTestCaseWatchdogTO == iStatus.Int())
|
|
233 |
{
|
|
234 |
iCollector.DestroyObservers();
|
|
235 |
return TestFailed(KErrAbort, _L("Timeout"));
|
|
236 |
}
|
|
237 |
iCollector.AddRequiredNotification(EWatcherPeripheralState, EUsbcDeviceStateSuspended);
|
|
238 |
iCaseStep = EBSuspended;
|
|
239 |
SetActive();
|
|
240 |
break;
|
|
241 |
}
|
|
242 |
|
|
243 |
case EBSuspended:
|
|
244 |
{
|
|
245 |
test.Printf(_L("Into EBSuspended step...\n"));
|
|
246 |
if (KTestCaseWatchdogTO == iStatus.Int())
|
|
247 |
{
|
|
248 |
iCollector.DestroyObservers();
|
|
249 |
return TestFailed(KErrAbort, _L("Timeout"));
|
|
250 |
}
|
|
251 |
|
|
252 |
if (iHNPCounter > 0)
|
|
253 |
{
|
|
254 |
// issue bus request to trigger HNP
|
|
255 |
test.Printf(_L("VBus present, attempting a swap.\n"));
|
|
256 |
iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBHost);
|
|
257 |
|
|
258 |
err = otgBusRequest(); // Request the host role
|
|
259 |
if (KErrNone != err)
|
|
260 |
{
|
|
261 |
test.Printf(_L("BusRequest returned %d\n"),err);
|
|
262 |
return TestFailed(KErrAbort, _L("BusRequest() failed!"));
|
|
263 |
}
|
|
264 |
|
|
265 |
iCaseStep = ESwappedRoles;
|
|
266 |
SetActive();
|
|
267 |
}
|
|
268 |
else
|
|
269 |
{
|
|
270 |
// We've done all the role-swapping we want. Now just wait for
|
|
271 |
// A-Host to drop VBus...
|
|
272 |
iCaseStep = EDropVBus;
|
|
273 |
SelfComplete();
|
|
274 |
}
|
|
275 |
|
|
276 |
break;
|
|
277 |
}
|
|
278 |
|
|
279 |
case EAIdleHostPriorToAPeripheral: // an "A-Device only" step
|
|
280 |
{
|
|
281 |
test.Printf(_L("Into EAIdleHostPriorToAPeripheral step...\n"));
|
|
282 |
if (KTestCaseWatchdogTO == iStatus.Int())
|
|
283 |
{
|
|
284 |
iCollector.DestroyObservers();
|
|
285 |
return TestFailed(KErrAbort, _L("Timeout"));
|
|
286 |
}
|
|
287 |
|
|
288 |
// A-Device should expect nothing more until it becomes A-Peripheral
|
|
289 |
iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateAPeripheral);
|
|
290 |
iCollector.AddRequiredNotification(EWatcherAConnectionIdle, RUsbOtgDriver::EConnectionBusy);
|
|
291 |
iCaseStep = ESwappedRoles;
|
|
292 |
SetActive();
|
|
293 |
break;
|
|
294 |
}
|
|
295 |
|
|
296 |
case ESwappedRoles:
|
|
297 |
{
|
|
298 |
test.Printf(_L("Into ESwappedRoles step...\n"));
|
|
299 |
if (KTestCaseWatchdogTO == iStatus.Int())
|
|
300 |
{
|
|
301 |
iCollector.DestroyObservers();
|
|
302 |
return TestFailed(KErrAbort, _L("Timeout"));
|
|
303 |
}
|
|
304 |
|
|
305 |
if (gTestRoleMaster)
|
|
306 |
{
|
|
307 |
// B-Device should now wait until it is back to B-Peripheral
|
|
308 |
iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBPeripheral);
|
|
309 |
iCaseStep = EDefaultRoles;
|
|
310 |
}
|
|
311 |
else
|
|
312 |
{
|
|
313 |
// A-Device should wait to become a configured A-Peripheral
|
|
314 |
iCollector.AddRequiredNotification(EWatcherPeripheralState, EUsbcDeviceStateConfigured);
|
|
315 |
iCaseStep = EAConfigured;
|
|
316 |
}
|
|
317 |
SetActive();
|
|
318 |
break;
|
|
319 |
}
|
|
320 |
|
|
321 |
case EAConfigured: // A-Device only step
|
|
322 |
{
|
|
323 |
test.Printf(_L("Into EAConfigured step...\n"));
|
|
324 |
if (KTestCaseWatchdogTO == iStatus.Int())
|
|
325 |
{
|
|
326 |
iCollector.DestroyObservers();
|
|
327 |
return TestFailed(KErrAbort, _L("Timeout"));
|
|
328 |
}
|
|
329 |
|
|
330 |
iCollector.AddRequiredNotification(EWatcherAConnectionIdle, RUsbOtgDriver::EConnectionIdle);
|
|
331 |
iCollector.AddRequiredNotification(EWatcherPeripheralState, EUsbcDeviceStateSuspended);
|
|
332 |
iCaseStep = EASuspended;
|
|
333 |
SetActive();
|
|
334 |
break;
|
|
335 |
}
|
|
336 |
|
|
337 |
case EASuspended: // A-Device only step
|
|
338 |
{
|
|
339 |
test.Printf(_L("Into EASuspended step...\n"));
|
|
340 |
if (KTestCaseWatchdogTO == iStatus.Int())
|
|
341 |
{
|
|
342 |
iCollector.DestroyObservers();
|
|
343 |
return TestFailed(KErrAbort, _L("Timeout"));
|
|
344 |
}
|
|
345 |
|
|
346 |
iCollector.AddRequiredNotification(EWatcherAConnectionIdle, RUsbOtgDriver::EConnectionBusy);
|
|
347 |
iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateAHost); // Swapping back to default role
|
|
348 |
|
|
349 |
iCaseStep = EDefaultRoles;
|
|
350 |
SetActive();
|
|
351 |
break;
|
|
352 |
}
|
|
353 |
|
|
354 |
case EAIdleHostPriorToVBusDown:
|
|
355 |
{
|
|
356 |
test.Printf(_L("Into EAIdleHostPriorToVBusDown step...\n"));
|
|
357 |
if (KTestCaseWatchdogTO == iStatus.Int())
|
|
358 |
{
|
|
359 |
iCollector.DestroyObservers();
|
|
360 |
return TestFailed(KErrAbort, _L("Timeout"));
|
|
361 |
}
|
|
362 |
|
|
363 |
iCaseStep = EDropVBus;
|
|
364 |
SelfComplete();
|
|
365 |
break;
|
|
366 |
}
|
|
367 |
|
|
368 |
case EDropVBus:
|
|
369 |
LOG_STEPNAME(_L("EDropVBus"))
|
|
370 |
if (KTestCaseWatchdogTO == iStatus.Int())
|
|
371 |
{
|
|
372 |
iCollector.DestroyObservers();
|
|
373 |
return TestFailed(KErrAbort, _L("Timeout"));
|
|
374 |
}
|
|
375 |
|
|
376 |
iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventVbusDropped);
|
|
377 |
if ( gTestRoleMaster)
|
|
378 |
{
|
|
379 |
iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBIdle);
|
|
380 |
}
|
|
381 |
else
|
|
382 |
{ // SLAVE "A"
|
|
383 |
otgBusDrop();
|
|
384 |
iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateAIdle);
|
|
385 |
}
|
|
386 |
iCaseStep = EVBusDropped;
|
|
387 |
SetActive();
|
|
388 |
break;
|
|
389 |
|
|
390 |
case EVBusDropped:
|
|
391 |
LOG_STEPNAME(_L("ELoopVerifyDrop"))
|
|
392 |
if (KTestCaseWatchdogTO == iStatus.Int())
|
|
393 |
{
|
|
394 |
return TestFailed(KErrAbort, _L("Timeout"));
|
|
395 |
}
|
|
396 |
|
|
397 |
if (otgVbusPresent())
|
|
398 |
{
|
|
399 |
return TestFailed(KErrAbort, _L("Vbus did not drop - FAILED!"));
|
|
400 |
}
|
|
401 |
iCaseStep = EUnloadLdd;
|
|
402 |
SelfComplete();
|
|
403 |
break;
|
|
404 |
|
|
405 |
case EUnloadLdd:
|
|
406 |
LOG_STEPNAME(_L("EUnloadLdd"))
|
|
407 |
otgDeactivateFdfActor();
|
|
408 |
iCollector.DestroyObservers();
|
|
409 |
if (EFalse == StepUnloadLDD())
|
|
410 |
return TestFailed(KErrAbort,_L("unload Ldd failure"));
|
|
411 |
if (!StepUnloadClient())
|
|
412 |
return TestFailed(KErrAbort,_L("Client Unload Failure"));
|
|
413 |
|
|
414 |
iCaseStep = ELastStep;
|
|
415 |
SelfComplete();
|
|
416 |
break;
|
|
417 |
|
|
418 |
case ELastStep:
|
|
419 |
LOG_STEPNAME(_L("ELastStep"))
|
|
420 |
TestPassed();
|
|
421 |
break;
|
|
422 |
|
|
423 |
default:
|
|
424 |
test.Printf(_L("<Error> unknown test step"));
|
|
425 |
Cancel();
|
|
426 |
return (TestFailed(KErrCorrupt, _L("<Error> unknown test step")));
|
|
427 |
}
|
|
428 |
}
|
|
429 |
|