First public contribution.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
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.
22 #include "activecontrol.h"
25 // --- Global Top Level Variables
27 CActiveControl* gActiveControl;
29 RTest test(_L("T_USB_SCDEVICE"));
31 RTest test(_L("T_USB_DEVICE"));
33 TBool gVerbose = 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;
48 void RunAppL(TDes * aConfigFile, TDes * aScriptFile)
50 // Construct the active scheduler
51 CActiveScheduler* myScheduler = new (ELeave) CActiveScheduler();
53 // Push active scheduler onto the cleanup stack
54 CleanupStack::PushL(myScheduler);
56 // Install as the active scheduler
57 CActiveScheduler::Install(myScheduler);
59 // Create console handler
61 CConsoleBase* myConsole = Console::NewL(_L("T_USB_SCDEVICE - USB Client Test"), TSize(KConsFullScreen, KConsFullScreen));
62 CleanupStack::PushL(myConsole);
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);
67 CConsoleBase* myConsole = Console::NewL(_L("T_USB_DEVICE - USB Client Test"), TSize(KConsFullScreen, KConsFullScreen));
68 CleanupStack::PushL(myConsole);
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);
74 // outermost test begin
75 test.Start(_L("Outermost test of t_usb_device\n"));
79 gActiveControl = CActiveControl::NewL(myConsole, aConfigFile, aScriptFile);
80 CleanupStack::PushL(gActiveControl);
83 // Call request function
84 gActiveControl->RequestEp0ControlPacket();
86 CActiveScheduler::Start();
88 test.Printf (_L("Test Run Completed\n"));
95 // Suspend thread for 2 seconds
98 CleanupStack::PopAndDestroy(gActiveControl);
101 while ((gSoakCount > 0) || (gSoakCount == -1));
103 // outermost test end
107 CleanupStack::PopAndDestroy(myConsole);
109 CleanupStack::PopAndDestroy(myScheduler);
114 void ParseCommandLine (TDes& aConfigFileName, TDes& aScriptFileName)
118 User::CommandLine(c);
121 aConfigFileName.SetLength(0);
122 aScriptFileName.SetLength(0);
128 while (token.Set(lex.NextToken()), token != KNullDesC)
130 if (token == _L("/v"))
132 RDebug::Print(_L("Verbose output enabled\n"));
135 else if (token == _L("/s"))
137 RDebug::Print(_L("Skipping some tests\n"));
140 else if (token == _L("/t"))
142 RDebug::Print(_L("Temporary Test\n"));
145 else if (token == _L("/n"))
147 RDebug::Print(_L("Not Stopping on Test Fail\n"));
148 gStopOnFail = EFalse;
150 else if (token.Left(5) == _L("/soak"))
154 equalPos = token.Locate('=');
155 if ((equalPos+1) < token.Length())
157 TLex lexNum(token.Mid(equalPos+1));
158 lexNum.Val(gSoakCount,EDecimal);
160 RDebug::Print(_L("Soak test for %d iterations\n"),gSoakCount);
162 else if (token.Left(8) == _L("/script="))
164 aScriptFileName = token;
168 aConfigFileName = token;
179 CTrapCleanup* cleanup = CTrapCleanup::New(); // get clean-up stack
181 TBuf<64> configFileName;
182 TBuf<64> scriptFileName;
183 ParseCommandLine (configFileName,scriptFileName);
185 if (configFileName.Length() == 0)
187 RDebug::Print(_L("(T_USB: Warning - No Configuration File.)\n"));
191 RDebug::Print(_L("T_USB: Config File Name %s\n"),configFileName.PtrZ());
194 if (scriptFileName.Length() != 0)
196 RDebug::Print(_L("T_USB: Script File Name %s\n"),scriptFileName.PtrZ());
199 TRAPD(error, RunAppL(& configFileName, &scriptFileName));
201 __ASSERT_ALWAYS(!error, User::Panic(_L("T_USB_DEVICE: EPOC32EX"), error));
203 delete cleanup; // destroy clean-up stack
207 RDebug::Print(_L("Program exit: done.\n"));
209 return 0; // and return