1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/usbho/t_otgdi/src/testcase0680.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,308 @@
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 "testcase0680.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-0680");
1.39 +const TTestCaseFactoryReceipt<CTestCase0680> CTestCase0680::iFactoryReceipt(KTestCaseId);
1.40 +
1.41 +CTestCase0680* CTestCase0680::NewL(TBool aHost)
1.42 + {
1.43 + LOG_FUNC
1.44 + CTestCase0680* self = new (ELeave) CTestCase0680(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 +CTestCase0680::CTestCase0680(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 CTestCase0680::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 +CTestCase0680::~CTestCase0680()
1.74 + {
1.75 + LOG_FUNC
1.76 + iCollector.DestroyObservers();
1.77 + Cancel();
1.78 + }
1.79 +
1.80 +
1.81 +void CTestCase0680::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 CTestCase0680::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 CTestCase0680::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(0xF680)) // Use default params, so HNP/SRP both supported
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 + // NB. We don't load the FDF Actor, because we don't want
1.132 + // the A-Host to suspend the attached B-Peripheral.
1.133 +
1.134 + // test that the right cable is in
1.135 + CheckRoleConnections();
1.136 +
1.137 + // subscribe to OTG states,events and messages now that it has loaded OK
1.138 + TRAPD(result, iCollector.CreateObserversL(*this));
1.139 + if (KErrNone != result)
1.140 + return(TestFailed(KErrNoMemory, _L("Unable to create observers")));
1.141 + iCollector.ClearAllEvents();
1.142 + iCaseStep = EReadyToRaiseVBus;
1.143 + SelfComplete();
1.144 + break;
1.145 + }
1.146 +
1.147 + case EReadyToRaiseVBus:
1.148 + {
1.149 + test.Printf(_L("Into EReadyToRaiseVBus step...\n"));
1.150 + if (gTestRoleMaster)
1.151 + {
1.152 + // wait for Vbus to be raised
1.153 + iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBIdle);
1.154 + iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventVbusRaised);
1.155 + iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBPeripheral);
1.156 + }
1.157 + else
1.158 + { // slave "A"
1.159 + // Raise VBus, then wait for default role
1.160 + err = otgBusRequest(); // ok to turn on VBus now
1.161 + if (KErrNone != err)
1.162 + {
1.163 + return TestFailed(KErrAbort, _L("Raise Vbus - RUsbOtgDriver::BusRequest() FAILED!"));
1.164 + }
1.165 +
1.166 + // we might also wait for and EStateAIdle
1.167 + iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateAIdle);
1.168 + iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventVbusRaised);
1.169 + iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventRoleChangedToHost);
1.170 + }
1.171 +
1.172 + const TInt KTestCase0680VBusRaiseTimeout = 2000; // 2 seconds, should be plenty of time for this test
1.173 + iCollector.AddStepTimeout(KTestCase0680VBusRaiseTimeout);
1.174 +
1.175 + iCaseStep = EDefaultRoles;
1.176 + SetActive();
1.177 + break;
1.178 + }
1.179 +
1.180 + case EDefaultRoles:
1.181 + {
1.182 + test.Printf(_L("Into EDefaultRoles step...\n"));
1.183 + LOG_STEPNAME(_L("EWaitEnumeration"));
1.184 +
1.185 + if (gTestRoleMaster)
1.186 + {
1.187 + // B-Device should now wait until it is configured
1.188 + iCollector.AddRequiredNotification(EWatcherPeripheralState, EUsbcDeviceStateConfigured);
1.189 +
1.190 + const TInt KTestCase0680BTimeout = 5000; // 5 seconds, should be plenty of time for overall test
1.191 + iCollector.AddStepTimeout(KTestCase0680BTimeout);
1.192 +
1.193 + iCaseStep = EBConfigured;
1.194 + }
1.195 + else
1.196 + {
1.197 + // A-Device should expect nothing more (role swap won't happen
1.198 + // because the B-Device doesn't indicate support for OTG in its
1.199 + // OTG descriptor, so the host won't have sent SetFeature(b_hnp_enable))
1.200 + // Instead, just rely on the test timeout and display a request for the user
1.201 + // to observe the B-Device test code for the pass/fail
1.202 + const TInt KTestCase0680ATimeout = 4000; // 4 seconds before A-Device drops VBus (before B test times out at 5 seconds)
1.203 + iCollector.AddStepTimeout(KTestCase0680ATimeout); // NB. In this test on the A-Device, we expect to timeout
1.204 + // so a timeout isn't treated as a failure
1.205 + test.Printf(_L("NOTE : Please observe test result on B-Device...\n"));
1.206 + iCaseStep = EDropVBus; // This is the step the A-Device will go to
1.207 + // when the timer (set up in previous test) fires
1.208 + }
1.209 + SetActive();
1.210 + break;
1.211 + }
1.212 +
1.213 +
1.214 + case EBConfigured: // A B-Device only step!
1.215 + {
1.216 + test.Printf(_L("Into EBConfigured step...\n"));
1.217 + if (KTestCaseWatchdogTO == iStatus.Int())
1.218 + {
1.219 + iCollector.DestroyObservers();
1.220 + return TestFailed(KErrAbort, _L("Timeout"));
1.221 + }
1.222 +
1.223 + iCollector.AddRequiredNotification(EWatcherMessage, RUsbOtgDriver::EMessageHnpNotSuspended);
1.224 +
1.225 + test.Printf(_L("Attempting a swap on an unsuspended link...\n"));
1.226 + err = otgBusRequest(); // Request the host role
1.227 +
1.228 + if (KErrNone != err)
1.229 + {
1.230 + test.Printf(_L("BusRequest returned %d)"),err);
1.231 + return TestFailed(KErrAbort, _L("BusRequest() failed!"));
1.232 + }
1.233 +
1.234 + iCaseStep = EBErrorReceived;
1.235 + SetActive();
1.236 + break;
1.237 + }
1.238 +
1.239 + case EBErrorReceived:
1.240 + {
1.241 + if (KTestCaseWatchdogTO == iStatus.Int())
1.242 + {
1.243 + iCollector.DestroyObservers();
1.244 + return TestFailed(KErrAbort, _L("Timeout"));
1.245 + }
1.246 +
1.247 + test.Printf(_L("Into EBErrorReceived step...\n"));
1.248 + iCaseStep = EDropVBus; // Test has pretty much passed now. Just wait for A-Device to drop VBus.
1.249 + SelfComplete();
1.250 + break;
1.251 + }
1.252 +
1.253 + case EDropVBus:
1.254 + LOG_STEPNAME(_L("EDropVBus"))
1.255 +
1.256 + iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventVbusDropped);
1.257 + if ( gTestRoleMaster)
1.258 + {
1.259 + iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBIdle);
1.260 + }
1.261 + else
1.262 + { // SLAVE "A"
1.263 + iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateAIdle);
1.264 + otgBusDrop();
1.265 + }
1.266 + iCaseStep = EVBusDropped;
1.267 + SetActive();
1.268 + break;
1.269 +
1.270 + case EVBusDropped:
1.271 + LOG_STEPNAME(_L("ELoopVerifyDrop"))
1.272 + if (KTestCaseWatchdogTO == iStatus.Int() && gTestRoleMaster)
1.273 + {
1.274 + // Remember, a timeout is only a failure for the B-Device in this test,
1.275 + // we're expecting and relying on a timeout on the A-Device to conclude
1.276 + // the test and bring VBus down.
1.277 + return TestFailed(KErrAbort, _L("Timeout"));
1.278 + }
1.279 +
1.280 + if (otgVbusPresent())
1.281 + {
1.282 + return TestFailed(KErrAbort, _L("Vbus did not drop - FAILED!"));
1.283 + }
1.284 + iCaseStep = EUnloadLdd;
1.285 + SelfComplete();
1.286 + break;
1.287 +
1.288 + case EUnloadLdd:
1.289 + LOG_STEPNAME(_L("EUnloadLdd"))
1.290 + iCollector.DestroyObservers();
1.291 +
1.292 + if (EFalse == StepUnloadLDD())
1.293 + return TestFailed(KErrAbort,_L("unload Ldd failure"));
1.294 + if (!StepUnloadClient())
1.295 + return TestFailed(KErrAbort,_L("Client Unload Failure"));
1.296 +
1.297 + iCaseStep = ELastStep;
1.298 + SelfComplete();
1.299 + break;
1.300 +
1.301 + case ELastStep:
1.302 + LOG_STEPNAME(_L("ELastStep"))
1.303 + TestPassed();
1.304 + break;
1.305 +
1.306 + default:
1.307 + test.Printf(_L("<Error> unknown test step"));
1.308 + Cancel();
1.309 + return (TestFailed(KErrCorrupt, _L("<Error> unknown test step")));
1.310 + }
1.311 + }