1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/usbho/t_otgdi/src/testcase0465.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,266 @@
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 "testcasewd.h"
1.29 +#include "testcase0465.h"
1.30 +
1.31 +
1.32 +
1.33 +
1.34 +// the name below is used to add a pointer to our construction method to a pointer MAP in
1.35 +// the class factory
1.36 +_LIT(KTestCaseId,"PBASE-USB_OTGDI-0465");
1.37 +const TTestCaseFactoryReceipt<CTestCase0465> CTestCase0465::iFactoryReceipt(KTestCaseId);
1.38 +
1.39 +CTestCase0465* CTestCase0465::NewL(TBool aHost)
1.40 + {
1.41 + LOG_FUNC
1.42 + CTestCase0465* self = new (ELeave) CTestCase0465(aHost);
1.43 + CleanupStack::PushL(self);
1.44 + self->ConstructL();
1.45 + CleanupStack::Pop(self);
1.46 + return self;
1.47 + }
1.48 +
1.49 +
1.50 +CTestCase0465::CTestCase0465(TBool aHost)
1.51 +: CTestCaseRoot(KTestCaseId, aHost)
1.52 + {
1.53 + LOG_FUNC
1.54 +
1.55 + }
1.56 +
1.57 +
1.58 +/**
1.59 + ConstructL
1.60 +*/
1.61 +void CTestCase0465::ConstructL()
1.62 + {
1.63 + LOG_FUNC
1.64 + iWDTimer = CTestCaseWatchdog::NewL();
1.65 +
1.66 + BaseConstructL();
1.67 + }
1.68 +
1.69 +
1.70 +CTestCase0465::~CTestCase0465()
1.71 + {
1.72 + LOG_FUNC
1.73 +
1.74 + Cancel();
1.75 + delete iWDTimer;
1.76 +
1.77 + }
1.78 +
1.79 +
1.80 +void CTestCase0465::ExecuteTestCaseL()
1.81 + {
1.82 + LOG_FUNC
1.83 + iCaseStep = EPreconditions;
1.84 +
1.85 + iRepeats = KOperationRetriesMax; // VBus event rise retries
1.86 +
1.87 + CActiveScheduler::Add(this);
1.88 + SelfComplete();
1.89 +
1.90 + }
1.91 +
1.92 +
1.93 +void CTestCase0465::DoCancel()
1.94 + {
1.95 + LOG_FUNC
1.96 +
1.97 + // cancel our timer
1.98 + iTimer.Cancel();
1.99 + }
1.100 +
1.101 +
1.102 +void CTestCase0465::CancelKB(CTestCaseRoot *pThis)
1.103 + {
1.104 + CTestCase0465 * p = REINTERPRET_CAST(CTestCase0465 *,pThis);
1.105 + // cancel the pending call
1.106 +
1.107 + p->iConsole->ReadCancel();
1.108 +
1.109 + }
1.110 +
1.111 +
1.112 +void CTestCase0465::CancelDrive(CTestCaseRoot *pThis)
1.113 + {
1.114 + CTestCase0465 * p = REINTERPRET_CAST(CTestCase0465 *,pThis);
1.115 + // cancel any pending call, and then complete our active obj with a timeout value
1.116 + p->SelfComplete(KTestCaseWatchdogTO);
1.117 + }
1.118 +
1.119 +
1.120 +// This test result depends on all the ID detection tests and the VBus driving and dropping tests have not yet passed
1.121 +void CTestCase0465::DescribePreconditions()
1.122 + {
1.123 + test.Printf(_L("BEFORE running this test\n"));
1.124 + test.Printf(_L("\n"));
1.125 + test.Printf(_L("Insert 'A' connector\n"));
1.126 + test.Printf(_L("\n"));
1.127 + test.Printf(_L("Confirm passing tests\n"));
1.128 + test.Printf(_L("\n"));
1.129 + test.Printf(_L("ID_PIN detection\n"));
1.130 + test.Printf(_L("VBus Driving\n"));
1.131 + test.Printf(_L("\n"));
1.132 + }
1.133 +
1.134 +
1.135 +// handle event completion
1.136 +void CTestCase0465::RunStepL()
1.137 + {
1.138 + LOG_FUNC
1.139 + // Obtain the completion code for this CActive obj.
1.140 + TInt completionCode(iStatus.Int());
1.141 + TBuf<MAX_DSTRLEN> aDescription;
1.142 + TInt err(0);
1.143 +
1.144 + switch(iCaseStep)
1.145 + {
1.146 + case EPreconditions:
1.147 + iCaseStep = ELoadLdd;
1.148 + if (iAutomated)
1.149 + {
1.150 + iCaseStep = ELoadLdd;
1.151 + SelfComplete();
1.152 + break;
1.153 + }
1.154 + // prompt to insert connector
1.155 + test.Printf(_L("\n"));
1.156 + test.Printf(KInsertAConnectorPrompt);
1.157 + test.Printf(_L("\n"));
1.158 + test.Printf(KPressAnyKeyToContinue);
1.159 + test.Printf(_L("\n"));
1.160 + RequestCharacter();
1.161 + break;
1.162 +
1.163 + case ELoadLdd:
1.164 + // 1. load the LDD and init.
1.165 + if (!StepLoadLDD())
1.166 + {
1.167 + break;
1.168 + }
1.169 + iCaseStep = EDriveVBus;
1.170 + SelfComplete();
1.171 + break;
1.172 +
1.173 + case EDriveVBus:
1.174 + // 2. DRIVE VBUS
1.175 + // wait for 100 ms to allow the stack time to settle
1.176 + User::After(100000);
1.177 + err = otgBusRequest();
1.178 + if (KErrNone != err)
1.179 + {
1.180 + return TestFailed(KErrAbort, _L("Raise VBus - RUsbOtgDriver::BusRequest() FAILED!"));
1.181 + }
1.182 +
1.183 + // wait for 1000 ms as per test document
1.184 + User::After(1000000);
1.185 +
1.186 + // test for VBus rise next
1.187 + otgQueueOtgEventRequest( iOTGEvent, iStatus );
1.188 + SetActive();
1.189 + iCaseStep = EVerifyVBus;
1.190 + break;
1.191 +
1.192 + case EVerifyVBus:
1.193 + // 3. get VBus rise event
1.194 + iCaseStep = EUnloadLdd;
1.195 + OtgEventString(iOTGEvent, aDescription);
1.196 + test.Printf(_L("Received event %d '%S' status(%d)\n"), iOTGEvent, &aDescription, completionCode);
1.197 +
1.198 + if (iOTGEvent != RUsbOtgDriver::EEventVbusRaised)
1.199 + {
1.200 + iCaseStep = EVerifyVBus;
1.201 + iRepeats--;
1.202 + if (iRepeats <0)
1.203 + {
1.204 + return TestFailed(KErrAbort, _L("Raise VBus event not detected. FAILED!"));
1.205 + }
1.206 +
1.207 + otgQueueOtgEventRequest( iOTGEvent, iStatus );
1.208 + SetActive();
1.209 + break;
1.210 + }
1.211 + test.Printf(_L("VBus seen OK.\n"));
1.212 +
1.213 + SelfComplete();
1.214 + break;
1.215 +
1.216 + case EUnloadLdd:
1.217 + // unload
1.218 + if (EFalse == StepUnloadLDD())
1.219 + {
1.220 + return TestFailed(KErrAbort,_L("unload Ldd failure"));
1.221 + }
1.222 +
1.223 + // wait for 100 ms to allow the stack time to settle
1.224 + User::After(100000);
1.225 +
1.226 + test.Printf(_L("Use meter or oscilloscope\n"));
1.227 + test.Printf(_L("to measure VBUS, which should\n"));
1.228 + test.Printf(_L("have dropped\n"));
1.229 + test.Printf(_L("\n"));
1.230 + test.Printf(_L("Is it below 0.2 volts?\n"));
1.231 + test.Printf(_L("\n"));
1.232 + test.Printf(_L("Select Y or N to continue\n"));
1.233 + RequestCharacter();
1.234 + iWDTimer->IssueRequest(KDelayDurationForUserActivityMS, this, &CancelKB);
1.235 + iCaseStep = EVerifyBusGone;
1.236 + break;
1.237 +
1.238 + case EVerifyBusGone:
1.239 + // since the LDD is gone, there is no OTGDI API from here on
1.240 + if (KTestCaseWatchdogTO == iStatus.Int())
1.241 + {
1.242 + return TestFailed(KErrAbort, _L("Operator response timeout"));
1.243 + }
1.244 + iWDTimer->Cancel();
1.245 + // user intput
1.246 + if (('y' == iKeyCodeInput) ||('Y' == iKeyCodeInput))
1.247 + {
1.248 + test.Printf(_L("VBUS 'drop' seen\n"));
1.249 + SelfComplete();
1.250 + }
1.251 + else
1.252 + {
1.253 + return TestFailed(KErrAbort, _L("VBus drop NOT 'seen' - FAILED!"));
1.254 + }
1.255 + iCaseStep = ELastStep;
1.256 + break;
1.257 +
1.258 + case ELastStep:
1.259 + TestPassed();
1.260 + break;
1.261 +
1.262 + default:
1.263 + test.Printf(_L("<Error> unknown test step\n"));
1.264 + Cancel();
1.265 + return (TestFailed(KErrCorrupt, _L("<Error> unknown test step")));
1.266 + }
1.267 + }
1.268 +
1.269 +