1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/usbho/t_otgdi/src/testcase0679.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,323 @@
1.4 +// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// @internalComponent
1.18 +//
1.19 +//
1.20 +
1.21 +#include <e32std.h>
1.22 +#include <e32std_private.h>
1.23 +#include <u32std.h> // unicode builds
1.24 +#include <e32base.h>
1.25 +#include <e32base_private.h>
1.26 +#include <e32Test.h> // RTest headder
1.27 +#include "testcaseroot.h"
1.28 +#include "b2bwatchers.h"
1.29 +#include "testcase0679.h"
1.30 +
1.31 +#define _REPEATS (oOpenIterations*3)
1.32 +
1.33 +
1.34 +/* **************************************************************************************
1.35 + * the name below is used to add a pointer to our construction method to a pointer MAP in
1.36 + * the class factory
1.37 + */
1.38 +_LIT(KTestCaseId,"PBASE-USB_OTGDI-0679");
1.39 +const TTestCaseFactoryReceipt<CTestCase0679> CTestCase0679::iFactoryReceipt(KTestCaseId);
1.40 +
1.41 +CTestCase0679* CTestCase0679::NewL(TBool aHost)
1.42 + {
1.43 + LOG_FUNC
1.44 + CTestCase0679* self = new (ELeave) CTestCase0679(aHost);
1.45 + CleanupStack::PushL(self);
1.46 + self->ConstructL();
1.47 + CleanupStack::Pop(self);
1.48 + return self;
1.49 + }
1.50 +
1.51 +
1.52 +CTestCase0679::CTestCase0679(TBool aHost)
1.53 + : CTestCaseB2BRoot(KTestCaseId, aHost, iStatus)
1.54 + {
1.55 + LOG_FUNC
1.56 +
1.57 + }
1.58 +
1.59 +
1.60 +/**
1.61 + ConstructL
1.62 +*/
1.63 +void CTestCase0679::ConstructL()
1.64 + {
1.65 + LOG_FUNC
1.66 +
1.67 + iDualRoleCase = ETrue; // another back-back
1.68 +
1.69 + BaseConstructL();
1.70 + }
1.71 +
1.72 +
1.73 +CTestCase0679::~CTestCase0679()
1.74 + {
1.75 + LOG_FUNC
1.76 + iCollector.DestroyObservers();
1.77 + Cancel();
1.78 + }
1.79 +
1.80 +
1.81 +void CTestCase0679::ExecuteTestCaseL()
1.82 + {
1.83 + LOG_FUNC
1.84 + iCaseStep = EPreconditions;
1.85 + CActiveScheduler::Add(this);
1.86 + SelfComplete();
1.87 + }
1.88 +
1.89 +
1.90 +void CTestCase0679::DoCancel()
1.91 + {
1.92 + LOG_FUNC
1.93 + // cancel our timer
1.94 + iTimer.Cancel();
1.95 + }
1.96 +
1.97 +
1.98 +// handle event completion
1.99 +void CTestCase0679::RunStepL()
1.100 + {
1.101 + LOG_FUNC
1.102 + // Obtain the completion code for this CActive obj.
1.103 + TInt completionCode(iStatus.Int());
1.104 + TBuf<MAX_DSTRLEN> aDescription;
1.105 + TInt err(0);
1.106 +
1.107 + switch(iCaseStep)
1.108 + {
1.109 + case EPreconditions:
1.110 + {
1.111 + LOG_STEPNAME(_L("EPreconditions"))
1.112 + iCaseStep = ELoadLdd;
1.113 + StepB2BPreconditions();
1.114 + break;
1.115 + }
1.116 +
1.117 + // 1. Load the Client LDD
1.118 + case ELoadLdd:
1.119 + {
1.120 + LOG_STEPNAME(_L("ELoadLdd"))
1.121 + if (!StepLoadClient(0xF679, EFalse /*no HNP support!*/))
1.122 + {
1.123 + return TestFailed(KErrAbort, _L("Client Load Failure"));
1.124 + }
1.125 + // load OTG ldd and init.
1.126 + if (!StepLoadLDD())
1.127 + {
1.128 + return TestFailed(KErrAbort, _L("OTG Load Failure"));
1.129 + }
1.130 +
1.131 + if(otgActivateFdfActor()!=KErrNone)
1.132 + {
1.133 + return TestFailed(KErrAbort, _L("Couldn't load FDF Actor"));
1.134 + }
1.135 +
1.136 + // test that the right cable is in
1.137 + CheckRoleConnections();
1.138 +
1.139 + // subscribe to OTG states,events and messages now that it has loaded OK
1.140 + TRAPD(result, iCollector.CreateObserversL(*this));
1.141 + if (KErrNone != result)
1.142 + return(TestFailed(KErrNoMemory, _L("Unable to create observers")));
1.143 + iCollector.ClearAllEvents();
1.144 + iCaseStep = EReadyToRaiseVBus;
1.145 + SelfComplete();
1.146 + break;
1.147 + }
1.148 +
1.149 + case EReadyToRaiseVBus:
1.150 + {
1.151 + if (gTestRoleMaster)
1.152 + {
1.153 + // wait for Vbus to be raised
1.154 + iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBIdle);
1.155 + iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventVbusRaised);
1.156 + iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBPeripheral);
1.157 + }
1.158 + else
1.159 + { // slave "A"
1.160 + // Raise VBus, then wait for default role
1.161 + err = otgBusRequest(); // ok to turn on VBus now
1.162 + if (KErrNone != err)
1.163 + {
1.164 + return TestFailed(KErrAbort, _L("Raise Vbus - RUsbOtgDriver::BusRequest() FAILED!"));
1.165 + }
1.166 +
1.167 + // we might also wait for and EStateAIdle
1.168 + iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateAIdle);
1.169 + iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventVbusRaised);
1.170 + iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventRoleChangedToHost);
1.171 + }
1.172 +
1.173 + const TInt KTestCase0679VBusRaiseTimeout = 2000; // 2 seconds, should be plenty of time for this test
1.174 + iCollector.AddStepTimeout(KTestCase0679VBusRaiseTimeout);
1.175 +
1.176 + iCaseStep = EDefaultRoles;
1.177 + SetActive();
1.178 + break;
1.179 + }
1.180 +
1.181 + case EDefaultRoles:
1.182 + {
1.183 + test.Printf(_L("Into EDefaultRoles step...\n"));
1.184 + LOG_STEPNAME(_L("EWaitEnumeration"));
1.185 +
1.186 + if (gTestRoleMaster)
1.187 + {
1.188 + // B-Device should now wait until it is configured
1.189 + iCollector.AddRequiredNotification(EWatcherPeripheralState, EUsbcDeviceStateConfigured);
1.190 +
1.191 + const TInt KTestCase0679BTimeout = 5000; // 5 seconds, should be plenty of time for overall test
1.192 + iCollector.AddStepTimeout(KTestCase0679BTimeout);
1.193 +
1.194 + iCaseStep = EBConfigured;
1.195 + }
1.196 + else
1.197 + {
1.198 + // A-Device should expect nothing more (role swap won't happen
1.199 + // because the B-Device doesn't indicate support for OTG in its
1.200 + // OTG descriptor, so the host won't have sent SetFeature(b_hnp_enable))
1.201 + // Instead, just rely on the test timeout and display a request for the user
1.202 + // to observe the B-Device test code for the pass/fail
1.203 + const TInt KTestCase0679ATimeout = 4000; // 4 seconds before A-Device drops VBus (before B test times out at 5 seconds)
1.204 + iCollector.AddStepTimeout(KTestCase0679ATimeout); // NB. In this test on the A-Device, we expect to timeout
1.205 + // so a timeout isn't treated as a failure
1.206 + test.Printf(_L("NOTE : Please observe test result on B-Device...\n"));
1.207 + iCaseStep = EDropVBus; // This is the step the A-Device will go to
1.208 + // when the timer (set up in previous test) fires
1.209 + }
1.210 + SetActive();
1.211 + break;
1.212 + }
1.213 +
1.214 +
1.215 + case EBConfigured: // A B-Device only step!
1.216 + {
1.217 + test.Printf(_L("Into EBConfigured step...\n"));
1.218 + if (KTestCaseWatchdogTO == iStatus.Int())
1.219 + {
1.220 + iCollector.DestroyObservers();
1.221 + return TestFailed(KErrAbort, _L("Timeout"));
1.222 + }
1.223 + iCollector.AddRequiredNotification(EWatcherPeripheralState, EUsbcDeviceStateSuspended);
1.224 + iCaseStep = EBSuspended;
1.225 + SetActive();
1.226 + break;
1.227 + }
1.228 +
1.229 + case EBSuspended:
1.230 + {
1.231 + test.Printf(_L("Into EBSuspended step...\n"));
1.232 + if (KTestCaseWatchdogTO == iStatus.Int())
1.233 + {
1.234 + iCollector.DestroyObservers();
1.235 + return TestFailed(KErrAbort, _L("Timeout"));
1.236 + }
1.237 +
1.238 + // issue HNP
1.239 + test.Printf(_L("Attempting a swap on a non-HNP enabled link...\n"));
1.240 + iCollector.AddRequiredNotification(EWatcherMessage, RUsbOtgDriver::EMessageHnpNotEnabled);
1.241 +
1.242 + err = otgBusRequest(); // Request the host role
1.243 +
1.244 + if (KErrNone != err)
1.245 + {
1.246 + test.Printf(_L("BusRequest returned %d)"),err);
1.247 + //DS Temp! return TestFailed(KErrAbort, _L("BusRequest() failed!"));
1.248 + }
1.249 +
1.250 + iCaseStep = EBErrorReceived;
1.251 + SetActive();
1.252 + break;
1.253 + }
1.254 +
1.255 + case EBErrorReceived:
1.256 + {
1.257 + test.Printf(_L("Into EBErrorReceived step...\n"));
1.258 + if (KTestCaseWatchdogTO == iStatus.Int())
1.259 + {
1.260 + iCollector.DestroyObservers();
1.261 + return TestFailed(KErrAbort, _L("Timeout"));
1.262 + }
1.263 + iCaseStep = EDropVBus; // Test has pretty much passed now. Just wait for A-Device to drop VBus.
1.264 + SelfComplete();
1.265 + break;
1.266 + }
1.267 +
1.268 + case EDropVBus:
1.269 + LOG_STEPNAME(_L("EDropVBus"))
1.270 +
1.271 + iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventVbusDropped);
1.272 + if ( gTestRoleMaster)
1.273 + {
1.274 + iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBIdle);
1.275 + }
1.276 + else
1.277 + { // SLAVE "A"
1.278 + iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateAIdle);
1.279 + otgBusDrop();
1.280 + }
1.281 + iCaseStep = EVBusDropped;
1.282 + SetActive();
1.283 + break;
1.284 +
1.285 + case EVBusDropped:
1.286 + LOG_STEPNAME(_L("EVBusDropped"))
1.287 + if (KTestCaseWatchdogTO == iStatus.Int() && gTestRoleMaster)
1.288 + {
1.289 + // Remember, a timeout is only a failure for the B-Device in this test,
1.290 + // we're expecting and relying on a timeout on the A-Device to conclude
1.291 + // the test and bring VBus down.
1.292 + return TestFailed(KErrAbort, _L("Timeout"));
1.293 + }
1.294 +
1.295 + if (otgVbusPresent())
1.296 + {
1.297 + return TestFailed(KErrAbort, _L("Vbus did not drop - FAILED!"));
1.298 + }
1.299 + iCaseStep = EUnloadLdd;
1.300 + SelfComplete();
1.301 + break;
1.302 +
1.303 + case EUnloadLdd:
1.304 + LOG_STEPNAME(_L("EUnloadLdd"))
1.305 + iCollector.DestroyObservers();
1.306 + otgDeactivateFdfActor();
1.307 + if (EFalse == StepUnloadLDD())
1.308 + return TestFailed(KErrAbort,_L("unload Ldd failure"));
1.309 + if (!StepUnloadClient())
1.310 + return TestFailed(KErrAbort,_L("Client Unload Failure"));
1.311 +
1.312 + iCaseStep = ELastStep;
1.313 + SelfComplete();
1.314 + break;
1.315 +
1.316 + case ELastStep:
1.317 + LOG_STEPNAME(_L("ELastStep"))
1.318 + TestPassed();
1.319 + break;
1.320 +
1.321 + default:
1.322 + test.Printf(_L("<Error> unknown test step"));
1.323 + Cancel();
1.324 + return (TestFailed(KErrCorrupt, _L("<Error> unknown test step")));
1.325 + }
1.326 + }