1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/usbho/t_otgdi/src/testcase1233.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,399 @@
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 "testcase1233.h"
1.30 +
1.31 +#include <e32debug.h>
1.32 +
1.33 +#define LOG_INTO_STEP(a) test.Printf(_L("\nInto Step [%S]\n\n"), &a);
1.34 +
1.35 +/* **************************************************************************************
1.36 + * the name below is used to add a pointer to our construction method to a pointer MAP in
1.37 + * the class factory
1.38 + */
1.39 +_LIT(KTestCaseId,"PBASE-USB_OTGDI-1233");
1.40 +const TTestCaseFactoryReceipt<CTestCase1233> CTestCase1233::iFactoryReceipt(KTestCaseId);
1.41 +
1.42 +CTestCase1233* CTestCase1233::NewL(TBool aHost)
1.43 + {
1.44 + LOG_FUNC
1.45 + CTestCase1233* self = new (ELeave) CTestCase1233(aHost);
1.46 + CleanupStack::PushL(self);
1.47 + self->ConstructL();
1.48 + CleanupStack::Pop(self);
1.49 + return self;
1.50 + }
1.51 +
1.52 +
1.53 +CTestCase1233::CTestCase1233(TBool aHost)
1.54 + : CTestCaseB2BRoot(KTestCaseId, aHost, iStatus)
1.55 + {
1.56 + LOG_FUNC
1.57 +
1.58 + }
1.59 +
1.60 +
1.61 +/**
1.62 + ConstructL
1.63 +*/
1.64 +void CTestCase1233::ConstructL()
1.65 + {
1.66 + LOG_FUNC
1.67 +
1.68 + iTestVID = 0x0E22; // Symbian
1.69 + iTestPID = 0xF000 + 1233; // Test 1233
1.70 +
1.71 + BaseConstructL();
1.72 + }
1.73 +
1.74 +
1.75 +CTestCase1233::~CTestCase1233()
1.76 + {
1.77 + LOG_FUNC
1.78 + iCollector.DestroyObservers();
1.79 + Cancel();
1.80 + }
1.81 +
1.82 +
1.83 +void CTestCase1233::ExecuteTestCaseL()
1.84 + {
1.85 + LOG_FUNC
1.86 + iCaseStep = EPreconditions;
1.87 + CActiveScheduler::Add(this);
1.88 + SelfComplete();
1.89 + }
1.90 +
1.91 +
1.92 +void CTestCase1233::DoCancel()
1.93 + {
1.94 + LOG_FUNC
1.95 + // cancel our timer
1.96 + iTimer.Cancel();
1.97 + }
1.98 +
1.99 +
1.100 +void CTestCase1233::RunStepL()
1.101 + {
1.102 + LOG_FUNC
1.103 +
1.104 + // Obtain the completion code for this CActive obj.
1.105 + TInt completionCode(iStatus.Int());
1.106 + TBuf<MAX_DSTRLEN> aDescription;
1.107 +
1.108 + switch(iCaseStep)
1.109 + {
1.110 + /*==================================================*/
1.111 + /* Fixed 'pre' steps */
1.112 + /*==================================================*/
1.113 + case EPreconditions:
1.114 + {
1.115 + LOG_INTO_STEP(_L("EPreconditions"))
1.116 +
1.117 + iCaseStep = ELoadLdd;
1.118 + StepB2BPreconditions();
1.119 + break;
1.120 + }
1.121 +
1.122 + case ELoadLdd:
1.123 + {
1.124 + LOG_INTO_STEP(_L("ELoadLdd"))
1.125 +
1.126 + // Note we use here the hex equivalent of #1233 for the PID
1.127 +
1.128 + if (!StepLoadClient(0xF4D1/*use default settings for SRP/HNP support*/))
1.129 + {
1.130 + return TestFailed(KErrAbort, _L("Client Load Failure"));
1.131 + }
1.132 +
1.133 + // load OTG ldd and init.
1.134 + if (!StepLoadLDD())
1.135 + {
1.136 + return TestFailed(KErrAbort, _L("OTG Load Failure"));
1.137 + }
1.138 +
1.139 + if(otgActivateFdfActor()!=KErrNone)
1.140 + {
1.141 + return TestFailed(KErrAbort, _L("Couldn't load FDF Actor"));
1.142 + }
1.143 +
1.144 + // test that the right cable is in
1.145 + CheckRoleConnections();
1.146 +
1.147 + // subscribe to OTG states,events and messages now that it has loaded OK
1.148 + TRAPD(result, iCollector.CreateObserversL(*this));
1.149 + if (KErrNone != result)
1.150 + {
1.151 + return(TestFailed(KErrNoMemory, _L("Unable to create observers")));
1.152 + }
1.153 +
1.154 + // Allow enough time for 8 enumerations, say a second each, plus two of the
1.155 + // tests require 15 seconds of SOF traffic
1.156 +
1.157 + const TInt KTestCase1233Timeout = 45000;
1.158 + iCollector.AddStepTimeout(KTestCase1233Timeout);
1.159 +
1.160 + iCollector.ClearAllEvents();
1.161 + iCaseStep = ERaiseVBus;
1.162 +
1.163 + SelfComplete();
1.164 + break;
1.165 + }
1.166 +
1.167 + /*==================================================*/
1.168 + /* Steps for this test case only */
1.169 + /*==================================================*/
1.170 +
1.171 + case ELoopToNextPID:
1.172 + {
1.173 + LOG_INTO_STEP(_L("ELoopToNextPID"));
1.174 +
1.175 + if (KTestCaseWatchdogTO == iStatus.Int())
1.176 + {
1.177 + iCollector.DestroyObservers();
1.178 + return TestFailed(KErrAbort, _L("Timeout"));
1.179 + }
1.180 +
1.181 + if ( iTestVID == 0x0E22 )
1.182 + {
1.183 + iTestVID = 0x1A0A; // OPT and test devices
1.184 + iTestPID = 0x0100; // One *before* the first HS test ID
1.185 + }
1.186 +
1.187 + iTestPID++;
1.188 +
1.189 + if ( iTestPID > 0x0108 )
1.190 + {
1.191 + test.Printf(_L("All VID/PID pairs done\n"));
1.192 +
1.193 + iCaseStep = EUnloadLdd;
1.194 + }
1.195 + else
1.196 + {
1.197 + if(gTestRoleMaster)
1.198 + {
1.199 + // B
1.200 + test.Printf(_L("Setting VID/PID of 0x%04x/0x%04x\n"),iTestVID,iTestPID);
1.201 +
1.202 + if (!StepChangeVidPid(iTestVID,iTestPID))
1.203 + {
1.204 + return TestFailed(KErrAbort, _L("VID/PID Change Failure"));
1.205 + }
1.206 + }
1.207 + else
1.208 + {
1.209 + // A
1.210 + test.Printf(_L("Expecting VID/PID of 0x%04x/0x%04x\n"),iTestVID,iTestPID);
1.211 + }
1.212 +
1.213 + iCollector.ClearAllEvents();
1.214 + iCaseStep = ERaiseVBus;
1.215 + }
1.216 +
1.217 + SelfComplete();
1.218 + break;
1.219 + }
1.220 +
1.221 + case ERaiseVBus:
1.222 + {
1.223 + LOG_INTO_STEP(_L("ERaiseVBus"));
1.224 +
1.225 + if (KTestCaseWatchdogTO == iStatus.Int())
1.226 + {
1.227 + iCollector.DestroyObservers();
1.228 + return TestFailed(KErrAbort, _L("Timeout"));
1.229 + }
1.230 +
1.231 + if (gTestRoleMaster)
1.232 + {
1.233 + // B device
1.234 + iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventVbusRaised);
1.235 + iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateBPeripheral);
1.236 + iCollector.AddRequiredNotification(EWatcherPeripheralState, EUsbcDeviceStateDefault);
1.237 + iCollector.AddRequiredNotification(EWatcherPeripheralState, EUsbcDeviceStateAddress);
1.238 + iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventHnpEnabled);
1.239 + iCollector.AddRequiredNotification(EWatcherPeripheralState, EUsbcDeviceStateConfigured);
1.240 + }
1.241 + else
1.242 + {
1.243 + // A device
1.244 + test.Printf(_L("Raising VBUS for VID/PID = 0x%04x/0x%04x\n"),iTestVID,iTestPID);
1.245 +
1.246 + if ( otgBusRequest() != KErrNone )
1.247 + {
1.248 + return TestFailed(KErrAbort, _L("Raise Vbus - RUsbOtgDriver::BusRequest() FAILED!"));
1.249 + }
1.250 +
1.251 + iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventVbusRaised);
1.252 + iCollector.AddRequiredNotification(EWatcherAConnectionIdle, RUsbOtgDriver::EConnectionBusy);
1.253 + iCollector.AddRequiredNotification(EWatcherState, RUsbOtgDriver::EStateAHost);
1.254 + }
1.255 +
1.256 + iCaseStep = EVBusRaised;
1.257 + SetActive();
1.258 + break;
1.259 + }
1.260 +
1.261 + case EVBusRaised:
1.262 + {
1.263 + LOG_INTO_STEP(_L("EVBusRaised"));
1.264 +
1.265 + if (KTestCaseWatchdogTO == iStatus.Int())
1.266 + {
1.267 + return TestFailed(KErrAbort, _L("Timeout"));
1.268 + }
1.269 +
1.270 + if ( otgVbusPresent() )
1.271 + {
1.272 + test.Printf(_L("...VBUS is UP\n"));
1.273 + iCaseStep = EDropVBus;
1.274 + }
1.275 + else
1.276 + {
1.277 + test.Printf(_L("...VBUS is DOWN\n"));
1.278 + return TestFailed(KErrAbort, _L("Vbus did not rise - FAILED!"));
1.279 + }
1.280 +
1.281 + if (gTestRoleMaster)
1.282 + {
1.283 + // B device
1.284 + SelfComplete();
1.285 + }
1.286 + else
1.287 + {
1.288 + // A device
1.289 +
1.290 + // The default device (0x0E22/0xB4D1) is passed to the FDF, which will (eventually)
1.291 + // suspend and enter connection idle state.
1.292 +
1.293 + // The HS test devices (0x1A0A) will not be presented to FDF, so there will be no
1.294 + // trailing connection idle to find.
1.295 +
1.296 + if ( iTestVID == 0x0E22 )
1.297 + {
1.298 + iCollector.AddRequiredNotification(EWatcherAConnectionIdle, RUsbOtgDriver::EConnectionIdle);
1.299 + SetActive();
1.300 + }
1.301 + else
1.302 + {
1.303 + SelfComplete();
1.304 + }
1.305 + }
1.306 +
1.307 + break;
1.308 + }
1.309 +
1.310 + case EDropVBus:
1.311 + {
1.312 + LOG_INTO_STEP(_L("EDropVBus"));
1.313 +
1.314 + if (KTestCaseWatchdogTO == iStatus.Int())
1.315 + {
1.316 + iCollector.DestroyObservers();
1.317 + return TestFailed(KErrAbort, _L("Timeout"));
1.318 + }
1.319 +
1.320 + if ( gTestRoleMaster)
1.321 + {
1.322 + // B device
1.323 + iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventVbusDropped);
1.324 + }
1.325 + else
1.326 + {
1.327 + // A device
1.328 + otgBusDrop();
1.329 +
1.330 + iCollector.AddRequiredNotification(EWatcherEvent, RUsbOtgDriver::EEventVbusDropped);
1.331 + }
1.332 +
1.333 + iCaseStep = EVBusDropped;
1.334 + SetActive();
1.335 + break;
1.336 + }
1.337 +
1.338 + case EVBusDropped:
1.339 + {
1.340 + LOG_INTO_STEP(_L("EVBusDropped"));
1.341 +
1.342 + if (KTestCaseWatchdogTO == iStatus.Int())
1.343 + {
1.344 + return TestFailed(KErrAbort, _L("Timeout"));
1.345 + }
1.346 +
1.347 + if ( otgVbusPresent() )
1.348 + {
1.349 + test.Printf(_L("...VBUS is UP\n"));
1.350 + return TestFailed(KErrAbort, _L("Vbus did not rise - FAILED!"));
1.351 + }
1.352 + else
1.353 + {
1.354 + test.Printf(_L("...VBUS is DOWN\n"));
1.355 + iCaseStep = ELoopToNextPID;
1.356 + }
1.357 +
1.358 + SelfComplete();
1.359 + break;
1.360 + }
1.361 +
1.362 + /*==================================================*/
1.363 + /* Fixed 'post' steps */
1.364 + /*==================================================*/
1.365 +
1.366 + case EUnloadLdd:
1.367 + {
1.368 + LOG_INTO_STEP(_L("EUnloadLdd"))
1.369 +
1.370 + otgDeactivateFdfActor();
1.371 + iCollector.DestroyObservers();
1.372 + if (EFalse == StepUnloadLDD()){
1.373 + return TestFailed(KErrAbort,_L("unload Ldd failure"));
1.374 + }
1.375 + if (!StepUnloadClient()){
1.376 + return TestFailed(KErrAbort,_L("Client Unload Failure"));
1.377 + }
1.378 +
1.379 + iCaseStep = ELastStep;
1.380 + SelfComplete();
1.381 + break;
1.382 + }
1.383 +
1.384 + case ELastStep:
1.385 + {
1.386 + LOG_INTO_STEP(_L("ELastStep"))
1.387 +
1.388 + TestPassed();
1.389 + RequestCharacter();
1.390 + break;
1.391 + }
1.392 +
1.393 + default:
1.394 + {
1.395 + LOG_INTO_STEP(_L("DEFAULT! (unknown test step)"));
1.396 + Cancel();
1.397 + RequestCharacter();
1.398 + return (TestFailed(KErrCorrupt, _L("<Error> unknown test step")));
1.399 + }
1.400 + }
1.401 +
1.402 + }