sl@0
|
1 |
// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
// @internalComponent
|
sl@0
|
15 |
//
|
sl@0
|
16 |
//
|
sl@0
|
17 |
|
sl@0
|
18 |
|
sl@0
|
19 |
#include <e32std.h>
|
sl@0
|
20 |
#include <e32std_private.h>
|
sl@0
|
21 |
#include <u32std.h> // unicode builds
|
sl@0
|
22 |
#include <e32base.h>
|
sl@0
|
23 |
#include <e32base_private.h>
|
sl@0
|
24 |
#include <e32cons.h>
|
sl@0
|
25 |
#include <e32Test.h> // RTest headder
|
sl@0
|
26 |
#include <e32debug.h>
|
sl@0
|
27 |
#include "TestCaseFactory.h"
|
sl@0
|
28 |
#include "debugmacros.h"
|
sl@0
|
29 |
#include "testpolicy.h"
|
sl@0
|
30 |
#include "testengine.h"
|
sl@0
|
31 |
#include "testcaseroot.h"
|
sl@0
|
32 |
#include "b2bwatchers.h"
|
sl@0
|
33 |
|
sl@0
|
34 |
|
sl@0
|
35 |
|
sl@0
|
36 |
TPtrC KMyApplicationName _L("t_otgdi.exe");
|
sl@0
|
37 |
|
sl@0
|
38 |
// The RTest object (used for console in/output)
|
sl@0
|
39 |
RTest test(_L("OTGDI Unit/Dev. Testing"));
|
sl@0
|
40 |
|
sl@0
|
41 |
// Parameters modified from the command-line
|
sl@0
|
42 |
// semi-automation mode off: (if we skip some keyboard prompts)
|
sl@0
|
43 |
TBool gSemiAutomated = EFalse;
|
sl@0
|
44 |
TBool gVerboseOutput = EFalse;
|
sl@0
|
45 |
TInt gOpenIterations = 3; // default to 3 repeats (used for the open/close
|
sl@0
|
46 |
// and other tests that use repeating)
|
sl@0
|
47 |
TInt gOOMIterations = 10; // default to 10 allocs
|
sl@0
|
48 |
TBool gTestRoleMaster = ETrue; // master by default
|
sl@0
|
49 |
TUint gUSBVidPid = KTestProductID; // Symbian VID+PID 0x2670
|
sl@0
|
50 |
|
sl@0
|
51 |
|
sl@0
|
52 |
extern RUsbOtgDriver oUsbOtgDriver;
|
sl@0
|
53 |
|
sl@0
|
54 |
// comment this line out for normal testing
|
sl@0
|
55 |
//#define TESTSOMETHING_DEF 1
|
sl@0
|
56 |
|
sl@0
|
57 |
|
sl@0
|
58 |
#ifdef TESTSOMETHING_DEF
|
sl@0
|
59 |
// Wait for Event with timeout, EFalse if we time out
|
sl@0
|
60 |
// @RETURNS : ETrue if the aStatus was signalled before the timeout
|
sl@0
|
61 |
TInt WaitForRequestWTime(TRequestStatus &aStatus, TTimeIntervalMicroSeconds32 aMicroseconds)
|
sl@0
|
62 |
{
|
sl@0
|
63 |
RTimer timer;
|
sl@0
|
64 |
TRequestStatus statusT;
|
sl@0
|
65 |
TRequestStatus *statarray[] = { &aStatus, &statusT};
|
sl@0
|
66 |
|
sl@0
|
67 |
timer.CreateLocal();
|
sl@0
|
68 |
timer.After(statusT, aMicroseconds);
|
sl@0
|
69 |
User::WaitForNRequest( statarray, 2 );
|
sl@0
|
70 |
if ( statusT == KRequestPending )
|
sl@0
|
71 |
{
|
sl@0
|
72 |
timer.Cancel();
|
sl@0
|
73 |
return(ETrue);
|
sl@0
|
74 |
}
|
sl@0
|
75 |
else
|
sl@0
|
76 |
{
|
sl@0
|
77 |
return(EFalse);
|
sl@0
|
78 |
}
|
sl@0
|
79 |
}
|
sl@0
|
80 |
|
sl@0
|
81 |
// Test basic API premises function:
|
sl@0
|
82 |
// define TESTSOMETHING_DEF if you want to test a new API or the priority of CActive
|
sl@0
|
83 |
// or the scheduler + test framework is creating doubt.
|
sl@0
|
84 |
void ProtoTypeCode()
|
sl@0
|
85 |
{
|
sl@0
|
86 |
// This block of code is a prototype area, a rough approximation of a test
|
sl@0
|
87 |
// without any Active Schedulers interfering
|
sl@0
|
88 |
TInt err(0);
|
sl@0
|
89 |
|
sl@0
|
90 |
{
|
sl@0
|
91 |
TRequestStatus status1; // calls
|
sl@0
|
92 |
|
sl@0
|
93 |
RUsbOtgDriver::TOtgEvent event;
|
sl@0
|
94 |
TBuf<MAX_DSTRLEN> aDescription;
|
sl@0
|
95 |
RUsbOtgDriver::TOtgIdPin OTGIdPin;
|
sl@0
|
96 |
RUsbOtgDriver::TOtgVbus OTGVBus;
|
sl@0
|
97 |
RUsbOtgDriver::TOtgEvent OtgEvent;
|
sl@0
|
98 |
//RUsbOtgDriver::TOtgIdPin idPinState;
|
sl@0
|
99 |
|
sl@0
|
100 |
// LOAD OTG- User-driver
|
sl@0
|
101 |
err = User::LoadLogicalDevice(KOTGDeviceInterfaceDriverName);
|
sl@0
|
102 |
if ( (err != KErrNone) && (err != KErrAlreadyExists) )
|
sl@0
|
103 |
{
|
sl@0
|
104 |
test.Printf(_L("<Error %d> Unable to load driver: %S"), err, &KOTGDeviceInterfaceDriverName);
|
sl@0
|
105 |
}
|
sl@0
|
106 |
err = oUsbOtgDriver.Open();
|
sl@0
|
107 |
if (err != KErrNone)
|
sl@0
|
108 |
test.Printf(_L("<Error %d> Unable to OPEN driver: %S"), err, &KOTGDeviceInterfaceDriverName);
|
sl@0
|
109 |
else
|
sl@0
|
110 |
test.Printf(_L("OPEN driver: %S OK!"), &KOTGDeviceInterfaceDriverName);
|
sl@0
|
111 |
|
sl@0
|
112 |
oUsbOtgDriver.StartStacks();
|
sl@0
|
113 |
test.Printf(_L("Stack started\n"));
|
sl@0
|
114 |
|
sl@0
|
115 |
/*
|
sl@0
|
116 |
for (TInt loop=0; loop <6; loop++)
|
sl@0
|
117 |
// TEST Events
|
sl@0
|
118 |
do
|
sl@0
|
119 |
{
|
sl@0
|
120 |
test.Printf(_L("Waiting for OTG...\n"));
|
sl@0
|
121 |
status1 = KRequestPending; // reset the status object
|
sl@0
|
122 |
oUsbOtgDriver.QueueOtgEventRequest( event, status1 );
|
sl@0
|
123 |
|
sl@0
|
124 |
// wait
|
sl@0
|
125 |
User::WaitForRequest(status1);
|
sl@0
|
126 |
TInt completionCode(status1.Int());
|
sl@0
|
127 |
CTestCaseRoot::OtgEventString(event, aDescription);
|
sl@0
|
128 |
test.Printf(_L("Received event %d '%S' status(%d) \n"), event, &aDescription, completionCode);
|
sl@0
|
129 |
}
|
sl@0
|
130 |
while (event != RUsbOtgDriver::EEventAPlugInserted); // 'A' plug found
|
sl@0
|
131 |
|
sl@0
|
132 |
*/
|
sl@0
|
133 |
test.Printf(_L("API QueueOtgIdPinNotification test:\n"));
|
sl@0
|
134 |
|
sl@0
|
135 |
for (TInt loop=0; loop <6; loop++)
|
sl@0
|
136 |
// TEST Events
|
sl@0
|
137 |
do
|
sl@0
|
138 |
{
|
sl@0
|
139 |
test.Printf(_L("Waiting for OTG...\n"));
|
sl@0
|
140 |
status1 = KRequestPending; // reset the status object
|
sl@0
|
141 |
oUsbOtgDriver.QueueOtgIdPinNotification( OTGIdPin, status1 );
|
sl@0
|
142 |
test.Printf(_L("Current pin %d \n"), OTGIdPin);
|
sl@0
|
143 |
|
sl@0
|
144 |
// wait
|
sl@0
|
145 |
User::WaitForRequest(status1);
|
sl@0
|
146 |
TInt completionCode(status1.Int());
|
sl@0
|
147 |
switch(OTGIdPin)
|
sl@0
|
148 |
{
|
sl@0
|
149 |
case RUsbOtgDriver::EIdPinAPlug:
|
sl@0
|
150 |
aDescription = _L("A-plug");
|
sl@0
|
151 |
break;
|
sl@0
|
152 |
case RUsbOtgDriver::EIdPinBPlug:
|
sl@0
|
153 |
aDescription = _L("B-plug");
|
sl@0
|
154 |
break;
|
sl@0
|
155 |
default:
|
sl@0
|
156 |
aDescription = _L("other");
|
sl@0
|
157 |
break;
|
sl@0
|
158 |
}
|
sl@0
|
159 |
test.Printf(_L("Received pin %d '%S' status(%d) \n"), OTGIdPin, &aDescription, completionCode);
|
sl@0
|
160 |
}
|
sl@0
|
161 |
while (OTGIdPin != RUsbOtgDriver::EIdPinAPlug); // 'A' plug found
|
sl@0
|
162 |
|
sl@0
|
163 |
test.Printf(_L("Press any key.\n"));
|
sl@0
|
164 |
test.Getch();
|
sl@0
|
165 |
|
sl@0
|
166 |
test.Printf(_L("Shutting down stack.\n"));
|
sl@0
|
167 |
oUsbOtgDriver.StopStacks();
|
sl@0
|
168 |
|
sl@0
|
169 |
oUsbOtgDriver.Close();
|
sl@0
|
170 |
|
sl@0
|
171 |
test.Printf(_L("Free the LDD.\n"));
|
sl@0
|
172 |
err = User::FreeLogicalDevice( RUsbOtgDriver::Name() );
|
sl@0
|
173 |
if (err != KErrNone)
|
sl@0
|
174 |
{
|
sl@0
|
175 |
test.Printf(_L("<Error %d> Unable to UN-load driver: %S"), err, &KOTGDeviceInterfaceDriverName);
|
sl@0
|
176 |
}
|
sl@0
|
177 |
test.Printf(_L("#############\nPress any key.\n"));
|
sl@0
|
178 |
}
|
sl@0
|
179 |
test.Getch();
|
sl@0
|
180 |
|
sl@0
|
181 |
test.Printf(_L("Free the LDD.\n"));
|
sl@0
|
182 |
// end this process, if we do not want to run a test now as well
|
sl@0
|
183 |
RProcess process;
|
sl@0
|
184 |
process.Open(RProcess().Id());
|
sl@0
|
185 |
process.Terminate(0);
|
sl@0
|
186 |
}
|
sl@0
|
187 |
#endif //TESTSOMETHING_DEF
|
sl@0
|
188 |
|
sl@0
|
189 |
|
sl@0
|
190 |
|
sl@0
|
191 |
static void MainL()
|
sl@0
|
192 |
{
|
sl@0
|
193 |
LOG_FUNC
|
sl@0
|
194 |
// Leave the hooks in for platform security
|
sl@0
|
195 |
#ifdef __DATA_CAGING__
|
sl@0
|
196 |
RProcess().DataCaging(RProcess::EDataCagingOn);
|
sl@0
|
197 |
RProcess().SecureApi(RProcess::ESecureApiOn);
|
sl@0
|
198 |
#endif
|
sl@0
|
199 |
|
sl@0
|
200 |
// Identify the process and main thread
|
sl@0
|
201 |
RProcess testProcess;
|
sl@0
|
202 |
RThread().Process(testProcess);
|
sl@0
|
203 |
testProcess.RenameMe(KMyApplicationName);
|
sl@0
|
204 |
RThread().RenameMe(_L("t_otgdi.exe main thread"));
|
sl@0
|
205 |
|
sl@0
|
206 |
// Allocate and provide the console for output
|
sl@0
|
207 |
test.SetConsole(Console::NewL(KMyApplicationName, TSize(KConsFullScreen,KConsFullScreen)));
|
sl@0
|
208 |
|
sl@0
|
209 |
|
sl@0
|
210 |
|
sl@0
|
211 |
#ifdef TESTSOMETHING_DEF
|
sl@0
|
212 |
ProtoTypeCode()
|
sl@0
|
213 |
// exitprocess
|
sl@0
|
214 |
#endif // TESTSOMETHING_DEF
|
sl@0
|
215 |
|
sl@0
|
216 |
__UHEAP_MARK;
|
sl@0
|
217 |
|
sl@0
|
218 |
// Create a new active scheduler for this main thread
|
sl@0
|
219 |
// we do this because console app has no scheduler, and we
|
sl@0
|
220 |
// want to be able to call async APIs
|
sl@0
|
221 |
CActiveScheduler* sched = new (ELeave) CActiveScheduler;
|
sl@0
|
222 |
CleanupStack::PushL(sched);
|
sl@0
|
223 |
CActiveScheduler::Install(sched);
|
sl@0
|
224 |
|
sl@0
|
225 |
__UHEAP_MARK;
|
sl@0
|
226 |
// Create the test case Engine in USB host mode
|
sl@0
|
227 |
CTestEngine* testEngine(NULL);
|
sl@0
|
228 |
|
sl@0
|
229 |
TRAPD(err, testEngine = CTestEngine::NewL());
|
sl@0
|
230 |
if (err == KErrNone)
|
sl@0
|
231 |
{
|
sl@0
|
232 |
CleanupStack::PushL(testEngine);
|
sl@0
|
233 |
|
sl@0
|
234 |
// Synchronise with the client (not currently necessary, no peer)
|
sl@0
|
235 |
//DS Commenting out as "not currently necessary" RProcess::Rendezvous(KErrNone);
|
sl@0
|
236 |
|
sl@0
|
237 |
// and start the active scheduler
|
sl@0
|
238 |
CActiveScheduler::Start();
|
sl@0
|
239 |
|
sl@0
|
240 |
// display results
|
sl@0
|
241 |
testEngine->Report();
|
sl@0
|
242 |
|
sl@0
|
243 |
// done with the test engine now
|
sl@0
|
244 |
CleanupStack::PopAndDestroy(testEngine);
|
sl@0
|
245 |
}
|
sl@0
|
246 |
else
|
sl@0
|
247 |
{
|
sl@0
|
248 |
if (-2 == err)
|
sl@0
|
249 |
test.Printf(_L("Warning, no tests were selected!: %d\n"), err);
|
sl@0
|
250 |
else
|
sl@0
|
251 |
test.Printf(_L("Unable to create the test engine: %d\n"), err);
|
sl@0
|
252 |
}
|
sl@0
|
253 |
|
sl@0
|
254 |
// test DONE, if we are running manual, have a delay
|
sl@0
|
255 |
if (!gSemiAutomated)
|
sl@0
|
256 |
{
|
sl@0
|
257 |
// Get the engine to hang around so we can look at the screen output
|
sl@0
|
258 |
test.Printf(KPressAnyKeyToEnd);
|
sl@0
|
259 |
test.Getch();
|
sl@0
|
260 |
}
|
sl@0
|
261 |
|
sl@0
|
262 |
__UHEAP_MARKEND;
|
sl@0
|
263 |
#ifdef _DEBUG
|
sl@0
|
264 |
test.Printf(_L("Test heap leaks #1 OK\n"));
|
sl@0
|
265 |
#endif
|
sl@0
|
266 |
|
sl@0
|
267 |
CleanupStack::PopAndDestroy(sched);
|
sl@0
|
268 |
__UHEAP_MARKEND;
|
sl@0
|
269 |
#ifdef _DEBUG
|
sl@0
|
270 |
test.Printf(_L("Test heap leaks #2 OK\n"));
|
sl@0
|
271 |
#endif
|
sl@0
|
272 |
|
sl@0
|
273 |
// Finish test and release resources - this ends up closing the console (our application window)
|
sl@0
|
274 |
test.End();
|
sl@0
|
275 |
test.Close();
|
sl@0
|
276 |
|
sl@0
|
277 |
}
|
sl@0
|
278 |
|
sl@0
|
279 |
|
sl@0
|
280 |
TInt E32Main()
|
sl@0
|
281 |
{
|
sl@0
|
282 |
LOG_FUNC
|
sl@0
|
283 |
// Create the new trap-cleanup mechanism
|
sl@0
|
284 |
CTrapCleanup* cleanup = CTrapCleanup::New();
|
sl@0
|
285 |
|
sl@0
|
286 |
if (cleanup == NULL)
|
sl@0
|
287 |
{
|
sl@0
|
288 |
return KErrNoMemory;
|
sl@0
|
289 |
}
|
sl@0
|
290 |
|
sl@0
|
291 |
// Perform the tests
|
sl@0
|
292 |
TRAPD(err,MainL());
|
sl@0
|
293 |
if (err != KErrNone)
|
sl@0
|
294 |
{
|
sl@0
|
295 |
test.Printf(_L("MainL error: %d\n"),err);
|
sl@0
|
296 |
}
|
sl@0
|
297 |
|
sl@0
|
298 |
delete cleanup;
|
sl@0
|
299 |
|
sl@0
|
300 |
// Provide no error
|
sl@0
|
301 |
return KErrNone;
|
sl@0
|
302 |
}
|
sl@0
|
303 |
|