|
1 // Copyright (c) 2002-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". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // e32test/usb/t_usb_device/main.cpp |
|
15 // USB Test Program, main part. |
|
16 // Device-side part, to work against t_usb_host running on the host. |
|
17 // |
|
18 // |
|
19 |
|
20 #include "general.h" |
|
21 #include "config.h" |
|
22 #include "activecontrol.h" |
|
23 #include "activeRW.h" |
|
24 |
|
25 // --- Global Top Level Variables |
|
26 |
|
27 CActiveControl* gActiveControl; |
|
28 #ifdef USB_SC |
|
29 RTest test(_L("T_USB_SCDEVICE")); |
|
30 #else |
|
31 RTest test(_L("T_USB_DEVICE")); |
|
32 #endif |
|
33 TBool gVerbose = EFalse; |
|
34 TBool gSkip = EFalse; |
|
35 TBool gTempTest = EFalse; |
|
36 TBool gStopOnFail = ETrue; |
|
37 TBool gAltSettingOnNotify = ETrue; |
|
38 TInt8 gSettingNumber [128]; |
|
39 TInt32 gSoakCount = 1; |
|
40 CActiveRW* gRW[KMaxConcurrentTests]; // the USB read/write active object |
|
41 IFConfigPtr gInterfaceConfig [128] [KMaxInterfaceSettings]; |
|
42 TInt gActiveTestCount = 0; |
|
43 #ifdef USB_SC |
|
44 RChunk gChunk; |
|
45 #endif |
|
46 |
|
47 |
|
48 void RunAppL(TDes * aConfigFile, TDes * aScriptFile) |
|
49 { |
|
50 // Construct the active scheduler |
|
51 CActiveScheduler* myScheduler = new (ELeave) CActiveScheduler(); |
|
52 |
|
53 // Push active scheduler onto the cleanup stack |
|
54 CleanupStack::PushL(myScheduler); |
|
55 |
|
56 // Install as the active scheduler |
|
57 CActiveScheduler::Install(myScheduler); |
|
58 |
|
59 // Create console handler |
|
60 #ifdef USB_SC |
|
61 CConsoleBase* myConsole = Console::NewL(_L("T_USB_SCDEVICE - USB Client Test"), TSize(KConsFullScreen, KConsFullScreen)); |
|
62 CleanupStack::PushL(myConsole); |
|
63 |
|
64 myConsole->Printf(_L("T_USB_SCDEVICE v%d.%d.%d\n"),KDeviceVersionMajor,KDeviceVersionMinor,KDeviceVersionMicro); |
|
65 test.Printf(_L("T_USB_SCDEVICE v%d.%d.%d\n"),KDeviceVersionMajor,KDeviceVersionMinor,KDeviceVersionMicro); |
|
66 #else |
|
67 CConsoleBase* myConsole = Console::NewL(_L("T_USB_DEVICE - USB Client Test"), TSize(KConsFullScreen, KConsFullScreen)); |
|
68 CleanupStack::PushL(myConsole); |
|
69 |
|
70 myConsole->Printf(_L("T_USB_DEVICE v%d.%d.%d\n"),KDeviceVersionMajor,KDeviceVersionMinor,KDeviceVersionMicro); |
|
71 test.Printf(_L("T_USB_DEVICE v%d.%d.%d\n"),KDeviceVersionMajor,KDeviceVersionMinor,KDeviceVersionMicro); |
|
72 #endif |
|
73 |
|
74 // outermost test begin |
|
75 test.Start(_L("Outermost test of t_usb_device\n")); |
|
76 |
|
77 do |
|
78 { |
|
79 gActiveControl = CActiveControl::NewL(myConsole, aConfigFile, aScriptFile); |
|
80 CleanupStack::PushL(gActiveControl); |
|
81 |
|
82 |
|
83 // Call request function |
|
84 gActiveControl->RequestEp0ControlPacket(); |
|
85 |
|
86 CActiveScheduler::Start(); |
|
87 |
|
88 test.Printf (_L("Test Run Completed\n")); |
|
89 |
|
90 if (gSoakCount > 0) |
|
91 { |
|
92 gSoakCount--; |
|
93 } |
|
94 |
|
95 // Suspend thread for 2 seconds |
|
96 User::After(2000000); |
|
97 |
|
98 CleanupStack::PopAndDestroy(gActiveControl); |
|
99 |
|
100 } |
|
101 while ((gSoakCount > 0) || (gSoakCount == -1)); |
|
102 |
|
103 // outermost test end |
|
104 test.End(); |
|
105 test.Close(); |
|
106 |
|
107 CleanupStack::PopAndDestroy(myConsole); |
|
108 |
|
109 CleanupStack::PopAndDestroy(myScheduler); |
|
110 |
|
111 return; |
|
112 } |
|
113 |
|
114 void ParseCommandLine (TDes& aConfigFileName, TDes& aScriptFileName) |
|
115 { |
|
116 TBuf<64> c; |
|
117 |
|
118 User::CommandLine(c); |
|
119 c.LowerCase(); |
|
120 |
|
121 aConfigFileName.SetLength(0); |
|
122 aScriptFileName.SetLength(0); |
|
123 if (c != KNullDesC) |
|
124 { |
|
125 TLex lex(c); |
|
126 TPtrC token; |
|
127 |
|
128 while (token.Set(lex.NextToken()), token != KNullDesC) |
|
129 { |
|
130 if (token == _L("/v")) |
|
131 { |
|
132 RDebug::Print(_L("Verbose output enabled\n")); |
|
133 gVerbose = ETrue; |
|
134 } |
|
135 else if (token == _L("/s")) |
|
136 { |
|
137 RDebug::Print(_L("Skipping some tests\n")); |
|
138 gSkip = ETrue; |
|
139 } |
|
140 else if (token == _L("/t")) |
|
141 { |
|
142 RDebug::Print(_L("Temporary Test\n")); |
|
143 gTempTest = ETrue; |
|
144 } |
|
145 else if (token == _L("/n")) |
|
146 { |
|
147 RDebug::Print(_L("Not Stopping on Test Fail\n")); |
|
148 gStopOnFail = EFalse; |
|
149 } |
|
150 else if (token.Left(5) == _L("/soak")) |
|
151 { |
|
152 TInt equalPos; |
|
153 gSoakCount = -1; |
|
154 equalPos = token.Locate('='); |
|
155 if ((equalPos+1) < token.Length()) |
|
156 { |
|
157 TLex lexNum(token.Mid(equalPos+1)); |
|
158 lexNum.Val(gSoakCount,EDecimal); |
|
159 } |
|
160 RDebug::Print(_L("Soak test for %d iterations\n"),gSoakCount); |
|
161 } |
|
162 else if (token.Left(8) == _L("/script=")) |
|
163 { |
|
164 aScriptFileName = token; |
|
165 } |
|
166 else |
|
167 { |
|
168 aConfigFileName = token; |
|
169 } |
|
170 } |
|
171 } |
|
172 |
|
173 } |
|
174 |
|
175 TInt E32Main() |
|
176 { |
|
177 __UHEAP_MARK; |
|
178 |
|
179 CTrapCleanup* cleanup = CTrapCleanup::New(); // get clean-up stack |
|
180 |
|
181 TBuf<64> configFileName; |
|
182 TBuf<64> scriptFileName; |
|
183 ParseCommandLine (configFileName,scriptFileName); |
|
184 |
|
185 if (configFileName.Length() == 0) |
|
186 { |
|
187 RDebug::Print(_L("(T_USB: Warning - No Configuration File.)\n")); |
|
188 } |
|
189 else |
|
190 { |
|
191 RDebug::Print(_L("T_USB: Config File Name %s\n"),configFileName.PtrZ()); |
|
192 } |
|
193 |
|
194 if (scriptFileName.Length() != 0) |
|
195 { |
|
196 RDebug::Print(_L("T_USB: Script File Name %s\n"),scriptFileName.PtrZ()); |
|
197 } |
|
198 |
|
199 TRAPD(error, RunAppL(& configFileName, &scriptFileName)); |
|
200 |
|
201 __ASSERT_ALWAYS(!error, User::Panic(_L("T_USB_DEVICE: EPOC32EX"), error)); |
|
202 |
|
203 delete cleanup; // destroy clean-up stack |
|
204 |
|
205 __UHEAP_MARKEND; |
|
206 |
|
207 RDebug::Print(_L("Program exit: done.\n")); |
|
208 |
|
209 return 0; // and return |
|
210 } |
|
211 |
|
212 |
|
213 // -eof- |