1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/usbho/t_usbdi/src/PBASE-T_USBDI-1232.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,448 @@
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 +// @file PBASE-T_USBDI-1232.cpp
1.18 +// @internalComponent
1.19 +//
1.20 +//
1.21 +
1.22 +#include "PBASE-T_USBDI-1232.h"
1.23 +#include <d32usbc.h>
1.24 +#include "testdebug.h"
1.25 +#include "modelleddevices.h"
1.26 +#include "TestPolicy.h"
1.27 +
1.28 +namespace NUnitTesting_USBDI
1.29 + {
1.30 +
1.31 + _LIT(KTestCaseId,"PBASE-T_USBDI-1232");
1.32 + // the name is very important
1.33 + const TFunctorTestCase<CUT_PBASE_T_USBDI_1232,TBool>
1.34 + CUT_PBASE_T_USBDI_1232::iFunctor(KTestCaseId);
1.35 +
1.36 + CUT_PBASE_T_USBDI_1232* CUT_PBASE_T_USBDI_1232::NewL(TBool aHostRole)
1.37 + {
1.38 + CUT_PBASE_T_USBDI_1232* self = new (ELeave) CUT_PBASE_T_USBDI_1232(aHostRole);
1.39 + CleanupStack::PushL(self);
1.40 + self->ConstructL();
1.41 + CleanupStack::Pop(self);
1.42 + return self;
1.43 + }
1.44 +
1.45 + CUT_PBASE_T_USBDI_1232::CUT_PBASE_T_USBDI_1232(TBool aHostRole) :
1.46 + CBaseTestCase(KTestCaseId, aHostRole)
1.47 + {
1.48 + }
1.49 +
1.50 + void CUT_PBASE_T_USBDI_1232::ConstructL()
1.51 + {
1.52 + RDebug::Printf("====> Constructor entry priority = %d", RThread().Priority());
1.53 +
1.54 + // Collect existing thread priority (to reinstate later)
1.55 + iPriority = RThread().Priority();
1.56 +
1.57 + iTestDevice = new RUsbDeviceA(this);
1.58 + BaseConstructL();
1.59 + }
1.60 +
1.61 + CUT_PBASE_T_USBDI_1232::~CUT_PBASE_T_USBDI_1232()
1.62 + {
1.63 + LOG_FUNC
1.64 +
1.65 + RDebug::Printf("====> Destructor entry priority = %d", RThread().Priority());
1.66 +
1.67 + // Reinstate original priority
1.68 +
1.69 + RThread().SetPriority(iPriority);
1.70 +
1.71 + // Cancel any async operations
1.72 +
1.73 + Cancel(); // Cancel host timer
1.74 +
1.75 + // Destroy the watchers
1.76 + // they still use opened interfaces to cancel the suspend if active
1.77 + delete iInterface1Watcher;
1.78 + delete iInterface0Watcher;
1.79 +
1.80 + // Close the interfaces
1.81 + iUsbInterface1.Close();
1.82 + iUsbInterface0.Close();
1.83 +
1.84 + delete iControlEp0;
1.85 + delete iActorFDF;
1.86 + if (!IsHost() && iTestDevice)
1.87 + {
1.88 + iTestDevice->Close();
1.89 + }
1.90 + delete iTestDevice;
1.91 + }
1.92 +
1.93 + void CUT_PBASE_T_USBDI_1232::ExecuteHostTestCaseL()
1.94 + {
1.95 + LOG_FUNC
1.96 +
1.97 + RDebug::Printf("====> ExecuteHostTestCaseL entry priority = %d",
1.98 + RThread().Priority());
1.99 +
1.100 + // Bump thread priority for this test only
1.101 +
1.102 + RThread().SetPriority(EPriorityAbsoluteHigh);
1.103 + RDebug::Printf("Thread priority raised %d->%d", iPriority, RThread().Priority());
1.104 +
1.105 + iCaseStep = EInProcess;
1.106 + iActorFDF = CActorFDF::NewL(*this);
1.107 + iControlEp0 = new (ELeave) CEp0Transfer(iUsbInterface0);
1.108 + iInterface0Watcher = new (ELeave) CInterfaceWatcher(iUsbInterface0,TCallBack(CUT_PBASE_T_USBDI_1232::Interface0ResumedL,this));
1.109 + iInterface1Watcher = new (ELeave) CInterfaceWatcher(iUsbInterface1,TCallBack(CUT_PBASE_T_USBDI_1232::Interface1ResumedL,this));
1.110 +
1.111 + // Monitor for device connections
1.112 + iActorFDF->Monitor();
1.113 +
1.114 + // Start the connection timeout
1.115 + TimeoutIn(30);
1.116 + }
1.117 +
1.118 + void CUT_PBASE_T_USBDI_1232::ExecuteDeviceTestCaseL()
1.119 + {
1.120 + LOG_FUNC
1.121 +
1.122 + // Construct the device for the test case
1.123 + iTestDevice->OpenL(TestCaseId());
1.124 + iTestDevice->SubscribeToReports(iStatus);
1.125 + SetActive();
1.126 +
1.127 + // Connect the test device
1.128 + iTestDevice->SoftwareConnect();
1.129 + }
1.130 +
1.131 + void CUT_PBASE_T_USBDI_1232::HostDoCancel()
1.132 + {
1.133 + LOG_FUNC
1.134 +
1.135 + RDebug::Printf("====> HostDoCancel entry priority = %d", RThread().Priority());
1.136 +
1.137 + // Cancel the timeout timer
1.138 + CancelTimeout();
1.139 + }
1.140 +
1.141 + void CUT_PBASE_T_USBDI_1232::DeviceDoCancel()
1.142 + {
1.143 + LOG_FUNC
1.144 +
1.145 + // Cancel the device
1.146 + iTestDevice->CancelSubscriptionToReports();
1.147 + }
1.148 +
1.149 + void CUT_PBASE_T_USBDI_1232::DeviceInsertedL(TUint aDeviceHandle)
1.150 + {
1.151 + LOG_FUNC
1.152 +
1.153 + RDebug::Printf("====> DeviceInsertedL entry priority = %d", RThread().Priority());
1.154 +
1.155 + Cancel(); // Cancel the timer
1.156 + TInt err(KErrNone);
1.157 + iDeviceHandle = aDeviceHandle;
1.158 + iActorFDF->Monitor();
1.159 +
1.160 + // Validate that device is as expected
1.161 + CUsbTestDevice& testDevice = iActorFDF->DeviceL(aDeviceHandle);
1.162 + if (testDevice.SerialNumber().Compare(TestCaseId()) != 0)
1.163 + {
1.164 + // Incorrect device for this test case
1.165 +
1.166 + RDebug::Printf(
1.167 + "<Warning %d> Incorrect device serial number (%S) connected for this test case (%S)",
1.168 + KErrNotFound, &testDevice.SerialNumber(), &TestCaseId());
1.169 +
1.170 + // Start the connection timeout again
1.171 + TimeoutIn(30);
1.172 + return;
1.173 + }
1.174 + // Check tree now
1.175 + CHECK(CheckTreeAfterDeviceInsertion(testDevice, _L("RDeviceA")) == KErrNone);
1.176 +
1.177 + // Perform the correct test step
1.178 + switch (iCaseStep)
1.179 + {
1.180 + case EInProcess:
1.181 + {
1.182 + TUint32 token1(0);
1.183 + TUint32 token2(0);
1.184 +
1.185 + RDebug::Printf("Obtaining token for interface 0");
1.186 + err = testDevice.Device().GetTokenForInterface(0, token1);
1.187 + if (err != KErrNone)
1.188 + {
1.189 + RDebug::Printf(
1.190 + "<Error %d> Token for interface 0 could not be retrieved",
1.191 + err);
1.192 + return TestFailed(err);
1.193 + }
1.194 + RDebug::Printf("Token 1 (%d) retrieved", token1);
1.195 + RDebug::Printf("Opening interface 0");
1.196 + err = iUsbInterface0.Open(token1); // Alternate interface setting 0
1.197 + if (err != KErrNone)
1.198 + {
1.199 + RDebug::Printf(
1.200 + "<Error %d> Interface 0 could not be opened", err);
1.201 + return TestFailed(err);
1.202 + }
1.203 + RDebug::Printf("Interface 0 opened");
1.204 +
1.205 + RDebug::Printf("Obtaining token for interface 1");
1.206 + err = testDevice.Device().GetTokenForInterface(1, token2);
1.207 + if (err != KErrNone)
1.208 + {
1.209 + RDebug::Printf(
1.210 + "<Error %d> Token for interface 1 could not be retrieved",
1.211 + err);
1.212 + return TestFailed(err);
1.213 + }
1.214 + RDebug::Printf("Opening interface 1");
1.215 + err = iUsbInterface1.Open(token2); // Alternate interface setting 0
1.216 + if (err != KErrNone)
1.217 + {
1.218 + RDebug::Printf(
1.219 + "<Error %d> Interface 1 could not be opened", err);
1.220 + return TestFailed(err);
1.221 + }
1.222 + RDebug::Printf("Interface 1 opened");
1.223 +
1.224 + // device go to suspend
1.225 + // Suspend interface 0
1.226 + RDebug::Printf("Suspending interface 0");
1.227 + iInterface0Watcher->SuspendAndWatch();
1.228 +
1.229 + // Suspend interface 1
1.230 + RDebug::Printf("Suspending interface 1");
1.231 + iInterface1Watcher->SuspendAndWatch();
1.232 +
1.233 + iCaseStep = ESuspendWhenResuming;
1.234 +
1.235 + TimeoutIn(10); // Give 10 seconds for device to suspend
1.236 +
1.237 +
1.238 + iUsbInterface0.CancelWaitForResume(); // a tricky way to close the watcher of interface
1.239 + iUsbInterface1.CancelWaitForResume();
1.240 + }
1.241 + break;
1.242 +
1.243 + default:
1.244 + TestFailed(KErrCorrupt);
1.245 + break;
1.246 + }
1.247 + }
1.248 +
1.249 + TInt CUT_PBASE_T_USBDI_1232::Interface0ResumedL(TAny* aPtr)
1.250 + {
1.251 + LOG_CFUNC
1.252 +
1.253 + RDebug::Printf("====> Interface0ResumedL entry priority = %d", RThread().Priority());
1.254 +
1.255 + RDebug::Printf(" -Interface 0 resumed");
1.256 + CUT_PBASE_T_USBDI_1232* self =
1.257 + reinterpret_cast<CUT_PBASE_T_USBDI_1232*>(aPtr);
1.258 + TInt completionCode = self->iInterface0Watcher->CompletionCode();
1.259 + RDebug::Printf(" -watcher 0 iStatus=%d",completionCode);
1.260 +
1.261 + switch (self->iCaseStep)
1.262 + {
1.263 +
1.264 + case EPassed:
1.265 + {
1.266 + if (completionCode == KErrNone)
1.267 + {
1.268 + RDebug::Printf("Device resume successed,test passed!");
1.269 + self->SendEp0Request(); // stop client site
1.270 + }
1.271 + else
1.272 + {
1.273 + RDebug::Printf("Device resume failed, err = %d ",completionCode);
1.274 + self->iCaseStep = EFailed;
1.275 + self->SendEp0Request();
1.276 + }
1.277 + }
1.278 + break;
1.279 + case EFailed:
1.280 + self->SendEp0Request();
1.281 + break;
1.282 +
1.283 + default:
1.284 + break;
1.285 + };
1.286 +
1.287 + return KErrNone;
1.288 + }
1.289 +
1.290 + TInt CUT_PBASE_T_USBDI_1232::Interface1ResumedL(TAny* aPtr)
1.291 + {
1.292 + LOG_CFUNC
1.293 +
1.294 + RDebug::Printf("====> Interface1ResumedL entry priority = %d", RThread().Priority());
1.295 +
1.296 + RDebug::Printf("Interface 1 resumed");
1.297 + CUT_PBASE_T_USBDI_1232* self =
1.298 + reinterpret_cast<CUT_PBASE_T_USBDI_1232*>(aPtr);
1.299 + RDebug::Printf("watcher 1 iStatus=%d", self->iInterface1Watcher->CompletionCode());
1.300 + return KErrNone;
1.301 + }
1.302 +
1.303 + void CUT_PBASE_T_USBDI_1232::DeviceRemovedL(TUint aDeviceHandle)
1.304 + {
1.305 + LOG_FUNC
1.306 +
1.307 + // The test device should not be removed until the test case has passed
1.308 + // so this test case has not completed, and state this event as an error
1.309 +
1.310 + TestFailed(KErrDisconnected);
1.311 + }
1.312 +
1.313 + void CUT_PBASE_T_USBDI_1232::BusErrorL(TInt aError)
1.314 + {
1.315 + LOG_FUNC
1.316 +
1.317 + // This test case handles no failiures on the bus
1.318 +
1.319 + TestFailed(aError);
1.320 + }
1.321 +
1.322 + void CUT_PBASE_T_USBDI_1232::DeviceStateChangeL(
1.323 + RUsbDevice::TDeviceState aPreviousState,
1.324 + RUsbDevice::TDeviceState aNewState, TInt aCompletionCode)
1.325 + {
1.326 + LOG_FUNC
1.327 + Cancel();
1.328 +
1.329 + // test RInterface , the RUsbDevice notification logic not used .
1.330 + RDebug::Printf(" -Device State change from err=%d",aCompletionCode);
1.331 +
1.332 + switch (iCaseStep)
1.333 + {
1.334 + case ESuspendWhenResuming:
1.335 + if (aNewState == RUsbDevice::EDeviceSuspended)
1.336 + {
1.337 + RDebug::Printf("====> device has suspended!");
1.338 +
1.339 + SuspendWhenResuming();
1.340 + }
1.341 + break;
1.342 + case EValidSuspendWhenResuming:
1.343 + if (aPreviousState == RUsbDevice::EDeviceSuspended&&aNewState
1.344 + == RUsbDevice::EDeviceSuspended)
1.345 + {
1.346 + RDebug::Printf("====> device suspended again,suspend while resuming succeed!");
1.347 + iCaseStep = EPassed;
1.348 + iUsbInterface0.CancelPermitSuspend();
1.349 + }
1.350 + else
1.351 + {
1.352 + iCaseStep = EFailed;
1.353 + iUsbInterface0.CancelPermitSuspend();
1.354 + }
1.355 +
1.356 + break;
1.357 + default:
1.358 + break;
1.359 + }
1.360 +
1.361 + }
1.362 +
1.363 + void CUT_PBASE_T_USBDI_1232::Ep0TransferCompleteL(TInt aCompletionCode)
1.364 + {
1.365 + LOG_FUNC
1.366 + RDebug::Printf("Ep0TransferCompleteL with aCompletionCode = %d",
1.367 + aCompletionCode);
1.368 + switch (iCaseStep)
1.369 + {
1.370 +
1.371 + default:
1.372 + case EFailed:
1.373 + TestFailed(KErrCompletion);
1.374 + break;
1.375 +
1.376 + case EPassed:
1.377 + TestPassed();
1.378 + break;
1.379 + }
1.380 + }
1.381 +
1.382 + void CUT_PBASE_T_USBDI_1232::HostRunL()
1.383 + {
1.384 + LOG_FUNC
1.385 +
1.386 + RDebug::Printf("====> HostRunL entry priority = %d", RThread().Priority());
1.387 +
1.388 + // Obtain the completion code
1.389 + TInt completionCode(iStatus.Int());
1.390 +
1.391 + if (completionCode == KErrNone)
1.392 + {
1.393 + // Action timeout
1.394 + RDebug::Printf("<Error> Action timeout");
1.395 + TestFailed(KErrTimedOut);
1.396 + }
1.397 + else
1.398 + {
1.399 + RDebug::Printf("<Error %d> Timeout timer could not complete",
1.400 + completionCode);
1.401 + TestFailed(completionCode);
1.402 + }
1.403 + }
1.404 +
1.405 + void CUT_PBASE_T_USBDI_1232::DeviceRunL()
1.406 + {
1.407 + LOG_FUNC
1.408 +
1.409 + // Disconnect the device
1.410 +
1.411 + iTestDevice->SoftwareDisconnect();
1.412 +
1.413 + // Complete the test case request
1.414 +
1.415 + TestPolicy().SignalTestComplete(iStatus.Int());
1.416 + }
1.417 +
1.418 + void CUT_PBASE_T_USBDI_1232::SuspendWhenResuming()
1.419 + {
1.420 + RDebug::Printf("====> SuspendWhenResuming entry priority = %d",
1.421 + RThread().Priority());
1.422 +
1.423 + // Cancel suspend-in-progress
1.424 + RDebug::Printf("Cancel Suspend interface 0");
1.425 +
1.426 + iUsbInterface0.CancelPermitSuspend();
1.427 +
1.428 + // how to prove, see log?
1.429 + // Suspend interface 0
1.430 + RDebug::Printf("Suspending interface 0");
1.431 + iInterface0Watcher->SuspendAndWatch();
1.432 +
1.433 + // Suspend interface 1
1.434 + RDebug::Printf("Suspending interface 1");
1.435 + iInterface1Watcher->SuspendAndWatch();
1.436 +
1.437 + iCaseStep = EValidSuspendWhenResuming;
1.438 +
1.439 + TimeoutIn(10); // Give 10 seconds for device to suspend
1.440 +
1.441 + }
1.442 +
1.443 + void CUT_PBASE_T_USBDI_1232::SendEp0Request()
1.444 + {
1.445 + TTestCasePassed request;
1.446 + iControlEp0->SendRequest(request, this);
1.447 + }
1.448 +
1.449 + }//end namespace
1.450 +
1.451 +