Update contrib.
1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
20 #include <e32std_private.h>
21 #include <u32std.h> // unicode builds
23 #include <e32base_private.h>
25 #include <e32Test.h> // RTest headder
27 #include "TestCaseFactory.h"
28 #include "debugmacros.h"
29 #include "testpolicy.h"
30 #include "testengine.h"
31 #include "testcaseroot.h"
32 #include "b2bwatchers.h"
36 TPtrC KMyApplicationName _L("t_otgdi.exe");
38 // The RTest object (used for console in/output)
39 RTest test(_L("OTGDI Unit/Dev. Testing"));
41 // Parameters modified from the command-line
42 // semi-automation mode off: (if we skip some keyboard prompts)
43 TBool gSemiAutomated = EFalse;
44 TBool gVerboseOutput = EFalse;
45 TInt gOpenIterations = 3; // default to 3 repeats (used for the open/close
46 // and other tests that use repeating)
47 TInt gOOMIterations = 10; // default to 10 allocs
48 TBool gTestRoleMaster = ETrue; // master by default
49 TUint gUSBVidPid = KTestProductID; // Symbian VID+PID 0x2670
52 extern RUsbOtgDriver oUsbOtgDriver;
54 // comment this line out for normal testing
55 //#define TESTSOMETHING_DEF 1
58 #ifdef TESTSOMETHING_DEF
59 // Wait for Event with timeout, EFalse if we time out
60 // @RETURNS : ETrue if the aStatus was signalled before the timeout
61 TInt WaitForRequestWTime(TRequestStatus &aStatus, TTimeIntervalMicroSeconds32 aMicroseconds)
64 TRequestStatus statusT;
65 TRequestStatus *statarray[] = { &aStatus, &statusT};
68 timer.After(statusT, aMicroseconds);
69 User::WaitForNRequest( statarray, 2 );
70 if ( statusT == KRequestPending )
81 // Test basic API premises function:
82 // define TESTSOMETHING_DEF if you want to test a new API or the priority of CActive
83 // or the scheduler + test framework is creating doubt.
86 // This block of code is a prototype area, a rough approximation of a test
87 // without any Active Schedulers interfering
91 TRequestStatus status1; // calls
93 RUsbOtgDriver::TOtgEvent event;
94 TBuf<MAX_DSTRLEN> aDescription;
95 RUsbOtgDriver::TOtgIdPin OTGIdPin;
96 RUsbOtgDriver::TOtgVbus OTGVBus;
97 RUsbOtgDriver::TOtgEvent OtgEvent;
98 //RUsbOtgDriver::TOtgIdPin idPinState;
100 // LOAD OTG- User-driver
101 err = User::LoadLogicalDevice(KOTGDeviceInterfaceDriverName);
102 if ( (err != KErrNone) && (err != KErrAlreadyExists) )
104 test.Printf(_L("<Error %d> Unable to load driver: %S"), err, &KOTGDeviceInterfaceDriverName);
106 err = oUsbOtgDriver.Open();
108 test.Printf(_L("<Error %d> Unable to OPEN driver: %S"), err, &KOTGDeviceInterfaceDriverName);
110 test.Printf(_L("OPEN driver: %S OK!"), &KOTGDeviceInterfaceDriverName);
112 oUsbOtgDriver.StartStacks();
113 test.Printf(_L("Stack started\n"));
116 for (TInt loop=0; loop <6; loop++)
120 test.Printf(_L("Waiting for OTG...\n"));
121 status1 = KRequestPending; // reset the status object
122 oUsbOtgDriver.QueueOtgEventRequest( event, status1 );
125 User::WaitForRequest(status1);
126 TInt completionCode(status1.Int());
127 CTestCaseRoot::OtgEventString(event, aDescription);
128 test.Printf(_L("Received event %d '%S' status(%d) \n"), event, &aDescription, completionCode);
130 while (event != RUsbOtgDriver::EEventAPlugInserted); // 'A' plug found
133 test.Printf(_L("API QueueOtgIdPinNotification test:\n"));
135 for (TInt loop=0; loop <6; loop++)
139 test.Printf(_L("Waiting for OTG...\n"));
140 status1 = KRequestPending; // reset the status object
141 oUsbOtgDriver.QueueOtgIdPinNotification( OTGIdPin, status1 );
142 test.Printf(_L("Current pin %d \n"), OTGIdPin);
145 User::WaitForRequest(status1);
146 TInt completionCode(status1.Int());
149 case RUsbOtgDriver::EIdPinAPlug:
150 aDescription = _L("A-plug");
152 case RUsbOtgDriver::EIdPinBPlug:
153 aDescription = _L("B-plug");
156 aDescription = _L("other");
159 test.Printf(_L("Received pin %d '%S' status(%d) \n"), OTGIdPin, &aDescription, completionCode);
161 while (OTGIdPin != RUsbOtgDriver::EIdPinAPlug); // 'A' plug found
163 test.Printf(_L("Press any key.\n"));
166 test.Printf(_L("Shutting down stack.\n"));
167 oUsbOtgDriver.StopStacks();
169 oUsbOtgDriver.Close();
171 test.Printf(_L("Free the LDD.\n"));
172 err = User::FreeLogicalDevice( RUsbOtgDriver::Name() );
175 test.Printf(_L("<Error %d> Unable to UN-load driver: %S"), err, &KOTGDeviceInterfaceDriverName);
177 test.Printf(_L("#############\nPress any key.\n"));
181 test.Printf(_L("Free the LDD.\n"));
182 // end this process, if we do not want to run a test now as well
184 process.Open(RProcess().Id());
185 process.Terminate(0);
187 #endif //TESTSOMETHING_DEF
194 // Leave the hooks in for platform security
195 #ifdef __DATA_CAGING__
196 RProcess().DataCaging(RProcess::EDataCagingOn);
197 RProcess().SecureApi(RProcess::ESecureApiOn);
200 // Identify the process and main thread
201 RProcess testProcess;
202 RThread().Process(testProcess);
203 testProcess.RenameMe(KMyApplicationName);
204 RThread().RenameMe(_L("t_otgdi.exe main thread"));
206 // Allocate and provide the console for output
207 test.SetConsole(Console::NewL(KMyApplicationName, TSize(KConsFullScreen,KConsFullScreen)));
211 #ifdef TESTSOMETHING_DEF
214 #endif // TESTSOMETHING_DEF
218 // Create a new active scheduler for this main thread
219 // we do this because console app has no scheduler, and we
220 // want to be able to call async APIs
221 CActiveScheduler* sched = new (ELeave) CActiveScheduler;
222 CleanupStack::PushL(sched);
223 CActiveScheduler::Install(sched);
226 // Create the test case Engine in USB host mode
227 CTestEngine* testEngine(NULL);
229 TRAPD(err, testEngine = CTestEngine::NewL());
232 CleanupStack::PushL(testEngine);
234 // Synchronise with the client (not currently necessary, no peer)
235 //DS Commenting out as "not currently necessary" RProcess::Rendezvous(KErrNone);
237 // and start the active scheduler
238 CActiveScheduler::Start();
241 testEngine->Report();
243 // done with the test engine now
244 CleanupStack::PopAndDestroy(testEngine);
249 test.Printf(_L("Warning, no tests were selected!: %d\n"), err);
251 test.Printf(_L("Unable to create the test engine: %d\n"), err);
254 // test DONE, if we are running manual, have a delay
257 // Get the engine to hang around so we can look at the screen output
258 test.Printf(KPressAnyKeyToEnd);
264 test.Printf(_L("Test heap leaks #1 OK\n"));
267 CleanupStack::PopAndDestroy(sched);
270 test.Printf(_L("Test heap leaks #2 OK\n"));
273 // Finish test and release resources - this ends up closing the console (our application window)
283 // Create the new trap-cleanup mechanism
284 CTrapCleanup* cleanup = CTrapCleanup::New();
295 test.Printf(_L("MainL error: %d\n"),err);