1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/usbho/t_otgdi/src/testcase0462.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,261 @@
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 "testcase0462.h"
1.30 +
1.31 +
1.32 +
1.33 +// the name below is used to add a pointer to our construction method to a pointer MAP in
1.34 +// the class factory
1.35 +_LIT(KTestCaseId,"PBASE-USB_OTGDI-0462");
1.36 +const TTestCaseFactoryReceipt<CTestCase0462> CTestCase0462::iFactoryReceipt(KTestCaseId);
1.37 +
1.38 +CTestCase0462* CTestCase0462::NewL(TBool aHost)
1.39 + {
1.40 + LOG_FUNC
1.41 + CTestCase0462* self = new (ELeave) CTestCase0462(aHost);
1.42 + CleanupStack::PushL(self);
1.43 + self->ConstructL();
1.44 + CleanupStack::Pop(self);
1.45 + return self;
1.46 + }
1.47 +
1.48 +
1.49 +CTestCase0462::CTestCase0462(TBool aHost)
1.50 +: CTestCaseRoot(KTestCaseId, aHost)
1.51 + {
1.52 + LOG_FUNC
1.53 +
1.54 + }
1.55 +
1.56 +
1.57 +/**
1.58 + ConstructL
1.59 +*/
1.60 +void CTestCase0462::ConstructL()
1.61 + {
1.62 + LOG_FUNC
1.63 + iRepeats = KOperationRetriesMax;
1.64 + iWDTimer = CTestCaseWatchdog::NewL();
1.65 +
1.66 + BaseConstructL();
1.67 + }
1.68 +
1.69 +
1.70 +CTestCase0462::~CTestCase0462()
1.71 + {
1.72 + LOG_FUNC
1.73 +
1.74 + Cancel();
1.75 + delete iWDTimer;
1.76 + }
1.77 +
1.78 +
1.79 +void CTestCase0462::ExecuteTestCaseL()
1.80 + {
1.81 + LOG_FUNC
1.82 + iCaseStep = ELoadLdd;
1.83 +
1.84 + CActiveScheduler::Add(this);
1.85 + SelfComplete();
1.86 +
1.87 + }
1.88 +
1.89 +
1.90 +void CTestCase0462::DescribePreconditions()
1.91 + {
1.92 + test.Printf(_L("Insert 'A' connector beforehand.\n"));
1.93 + }
1.94 +
1.95 +
1.96 +void CTestCase0462::DoCancel()
1.97 + {
1.98 + LOG_FUNC
1.99 +
1.100 + // cancel our timer
1.101 + iTimer.Cancel();
1.102 + }
1.103 +
1.104 +void CTestCase0462::CancelKB(CTestCaseRoot *pThis)
1.105 + {
1.106 + CTestCase0462 * p = REINTERPRET_CAST(CTestCase0462 *,pThis);
1.107 + // cancel any pending call, and then complete our active obj with a timeout value
1.108 +
1.109 + p->iConsole->ReadCancel();
1.110 +
1.111 + }
1.112 +
1.113 +
1.114 +// handle event completion
1.115 +void CTestCase0462::RunStepL()
1.116 + {
1.117 + LOG_FUNC
1.118 + // Obtain the completion code for this CActive obj.
1.119 + TInt completionCode(iStatus.Int());
1.120 + // NOTE: Look at its iStatus.iFlags.
1.121 + // If it's 1, it's b -> you called SetActive() but the service provider didn't set it to KRequestPending or it got overwritten.
1.122 + // If it's 2, it's a -> you didn't called SetActive() when issuing a request.
1.123 +
1.124 + TBuf<MAX_DSTRLEN> aDescription;
1.125 +
1.126 + switch(iCaseStep)
1.127 + {
1.128 + case EPreconditions:
1.129 + iCaseStep = ELoadLdd;
1.130 + if (iAutomated)
1.131 + {
1.132 + iCaseStep = ELoadLdd;
1.133 + SelfComplete();
1.134 + break;
1.135 + }
1.136 + // prompt to insert connector
1.137 + test.Printf(KInsertAConnectorPrompt);
1.138 + test.Printf(KPressAnyKeyToContinue);
1.139 + RequestCharacter();
1.140 + break;
1.141 +
1.142 + case ELoadLdd:
1.143 + if (!StepLoadLDD())
1.144 + {
1.145 + break;
1.146 + }
1.147 +
1.148 + iCaseStep = ERegisterForEvents;
1.149 + iDequeAttempts = 0;
1.150 + SelfComplete();
1.151 + break;
1.152 +
1.153 + // 2. wait on ID_PIN
1.154 + case ERegisterForEvents:
1.155 + // prompt to remove connector
1.156 + test.Printf(KRemoveAConnectorPrompt);
1.157 + if (iDequeAttempts > 3)
1.158 + {
1.159 + return (TestFailed(KErrCorrupt, _L("<Error> too many irrelevant/incorrect events")));
1.160 + }
1.161 +
1.162 + otgQueueOtgEventRequest( iOTGEvent, iStatus);
1.163 + iCaseStep = EEmptyQueue;
1.164 + iIDcheckStart.HomeTime();
1.165 + SetActive();
1.166 + break;
1.167 +
1.168 + // 3. pick up events already buffered when we started test
1.169 + case EEmptyQueue:
1.170 + {
1.171 +
1.172 + TInt aMillisec;
1.173 + iIDcheckEnd.HomeTime();
1.174 + TTimeIntervalMicroSeconds ivlMicro(iIDcheckEnd.MicroSecondsFrom(iIDcheckStart));
1.175 + aMillisec = (TInt)(ivlMicro.Int64())/1000; // USB times are in uSec, but in ms for the user layer
1.176 + iCaseStep = EGetAndCancelEvent;
1.177 + // test if too quick!
1.178 + if(aMillisec < KDelayDurationForQEmpty) // use 200ms - clocked at 17ms
1.179 + {
1.180 + iCaseStep = ERegisterForEvents;
1.181 + iDequeAttempts++;
1.182 + SelfComplete();
1.183 + break;
1.184 + }
1.185 + }// drop through to next step
1.186 +
1.187 + // 4.
1.188 + case EGetAndCancelEvent:
1.189 + OtgEventString(iOTGEvent, aDescription);
1.190 + test.Printf(_L("Received event %d '%S' status(%d)"), iOTGEvent, &aDescription, completionCode);
1.191 + if (RUsbOtgDriver::EEventAPlugRemoved == iOTGEvent)
1.192 + {
1.193 + otgQueueOtgEventRequest( iOTGEvent, iStatus);
1.194 + // cancel it and then generate 6 more events
1.195 + otgCancelOtgEventRequest();
1.196 + // swallow the cancellation now too
1.197 + User::WaitForRequest(iStatus);
1.198 +
1.199 + iCaseStep = ECancelNotify;
1.200 + }
1.201 + else
1.202 + {
1.203 + // wrong event in the Q already, keep at it
1.204 + iCaseStep = ERegisterForEvents;
1.205 + iDequeAttempts++;
1.206 + }
1.207 + SelfComplete();
1.208 + break;
1.209 +
1.210 + // 5. prepare to insert 'A'
1.211 + case ECancelNotify:
1.212 + iRepeats = KOperationRetriesMax;
1.213 + iCaseStep = EInsertA;
1.214 + SelfComplete();
1.215 + break;
1.216 +
1.217 + case EInsertA: // 6. remove 'A'
1.218 + iConsole->ReadCancel();
1.219 + test.Printf(KInsertAConnectorPrompt);
1.220 +
1.221 + iCaseStep = ERemoveA;
1.222 + test.Printf(KPressAnyKeyToContinue);
1.223 + RequestCharacter();
1.224 + break;
1.225 +
1.226 + // 7.
1.227 + case ERemoveA:
1.228 + iConsole->ReadCancel();
1.229 + test.Printf(KRemoveAConnectorPrompt);
1.230 + if (iRepeats-- >0)
1.231 + iCaseStep = EInsertA;
1.232 + else
1.233 + iCaseStep = ETallyEvents;
1.234 + test.Printf(KPressAnyKeyToContinue);
1.235 + RequestCharacter();
1.236 + break;
1.237 +
1.238 + // 8.
1.239 + case ETallyEvents:
1.240 + iConsole->ReadCancel();
1.241 + // tests if the object became signalled or not!
1.242 + // we expect if it did in fact do so, our Active object would panic (stray signal)
1.243 + SelfComplete();
1.244 + iCaseStep = EUnloadLdd;
1.245 + break;
1.246 +
1.247 + // 9.
1.248 + case EUnloadLdd:
1.249 + case ELastStep:
1.250 + if (EFalse == StepUnloadLDD())
1.251 + return TestFailed(KErrAbort,_L("unload Ldd failure"));
1.252 +
1.253 + return TestPassed();
1.254 +
1.255 + default:
1.256 + test.Printf(_L("<Error> unknown test step"));
1.257 + Cancel();
1.258 + return (TestFailed(KErrCorrupt, _L("<Error> unknown test step")));
1.259 +
1.260 + }
1.261 + }
1.262 +
1.263 +
1.264 +