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