kerneltest/e32test/usb/t_usb_device/src/main.cpp
branchRCL_3
changeset 256 c1f20ce4abcf
parent 0 a41df078684a
child 257 3e88ff8f41d5
equal deleted inserted replaced
249:a179b74831c9 256:c1f20ce4abcf
     1 // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2002-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of the License "Eclipse Public License v1.0"
     4 // under the terms of the License "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
    12 //
    12 //
    13 // Description:
    13 // Description:
    14 // e32test/usb/t_usb_device/main.cpp
    14 // e32test/usb/t_usb_device/main.cpp
    15 // USB Test Program, main part.
    15 // USB Test Program, main part.
    16 // Device-side part, to work against t_usb_host running on the host.
    16 // Device-side part, to work against t_usb_host running on the host.
    17 // 
    17 //
    18 //
    18 //
    19 
    19 
    20 #include "general.h"
    20 #include "general.h"
    21 #include "config.h"
    21 #include "config.h"
    22 #include "activecontrol.h"
    22 #include "activecontrol.h"
    23 #include "activeRW.h"
    23 #include "OstTraceDefinitions.h"
       
    24 #ifdef OST_TRACE_COMPILER_IN_USE
       
    25 #include "mainTraces.h"
       
    26 #endif
       
    27 #include "activerw.h"
    24 
    28 
    25 // --- Global Top Level Variables
    29 // --- Global Top Level Variables
    26 
    30 
    27 CActiveControl* gActiveControl;
    31 CActiveControl* gActiveControl;
    28 #ifdef USB_SC
    32 #ifdef USB_SC
    29 RTest test(_L("T_USB_SCDEVICE"));
    33 RTest test(_L("T_USB_SCDEVICE"));
    30 #else
    34 #else
    31 RTest test(_L("T_USB_DEVICE"));
    35 RTest test(_L("T_USB_DEVICE"));
       
    36 #endif
       
    37 
       
    38 #ifdef USB_SC
       
    39 TBool gShareHandle = EFalse;
    32 #endif
    40 #endif
    33 TBool gVerbose = EFalse;
    41 TBool gVerbose = EFalse;
    34 TBool gSkip = EFalse;
    42 TBool gSkip = EFalse;
    35 TBool gTempTest = EFalse;
    43 TBool gTempTest = EFalse;
    36 TBool gStopOnFail = ETrue;
    44 TBool gStopOnFail = ETrue;
    41 IFConfigPtr gInterfaceConfig [128] [KMaxInterfaceSettings];
    49 IFConfigPtr gInterfaceConfig [128] [KMaxInterfaceSettings];
    42 TInt gActiveTestCount = 0;
    50 TInt gActiveTestCount = 0;
    43 #ifdef USB_SC
    51 #ifdef USB_SC
    44 RChunk gChunk;
    52 RChunk gChunk;
    45 #endif
    53 #endif
    46 	
    54 
    47 
    55 
    48 void RunAppL(TDes * aConfigFile, TDes * aScriptFile)
    56 void RunAppL(TDes * aConfigFile, TDes * aScriptFile)
    49 	{
    57 	{
    50 	// Construct the active scheduler
    58 	// Construct the active scheduler
    51 	CActiveScheduler* myScheduler = new (ELeave) CActiveScheduler();
    59 	CActiveScheduler* myScheduler = new (ELeave) CActiveScheduler();
    60 	#ifdef USB_SC
    68 	#ifdef USB_SC
    61 	CConsoleBase* myConsole = Console::NewL(_L("T_USB_SCDEVICE - USB Client Test"), TSize(KConsFullScreen, KConsFullScreen));
    69 	CConsoleBase* myConsole = Console::NewL(_L("T_USB_SCDEVICE - USB Client Test"), TSize(KConsFullScreen, KConsFullScreen));
    62 	CleanupStack::PushL(myConsole);
    70 	CleanupStack::PushL(myConsole);
    63 
    71 
    64 	myConsole->Printf(_L("T_USB_SCDEVICE v%d.%d.%d\n"),KDeviceVersionMajor,KDeviceVersionMinor,KDeviceVersionMicro);
    72 	myConsole->Printf(_L("T_USB_SCDEVICE v%d.%d.%d\n"),KDeviceVersionMajor,KDeviceVersionMinor,KDeviceVersionMicro);
       
    73 	OstTraceExt3(TRACE_NORMAL, RUNAPPL_RUNAPPL, "T_USB_SCDEVICE v%d.%d.%d\n",(TInt32)KDeviceVersionMajor,(TInt32)KDeviceVersionMinor,(TInt32)KDeviceVersionMicro);
    65 	test.Printf(_L("T_USB_SCDEVICE v%d.%d.%d\n"),KDeviceVersionMajor,KDeviceVersionMinor,KDeviceVersionMicro);
    74 	test.Printf(_L("T_USB_SCDEVICE v%d.%d.%d\n"),KDeviceVersionMajor,KDeviceVersionMinor,KDeviceVersionMicro);
       
    75 	OstTraceExt3(TRACE_NORMAL, RUNAPPL_RUNAPPL_DUP01, "T_USB_SCDEVICE v%d.%d.%d\n",(TInt32)KDeviceVersionMajor,(TInt32)KDeviceVersionMinor,(TInt32)KDeviceVersionMicro);
    66 	#else
    76 	#else
    67 	CConsoleBase* myConsole = Console::NewL(_L("T_USB_DEVICE - USB Client Test"), TSize(KConsFullScreen, KConsFullScreen));
    77 	CConsoleBase* myConsole = Console::NewL(_L("T_USB_DEVICE - USB Client Test"), TSize(KConsFullScreen, KConsFullScreen));
    68 	CleanupStack::PushL(myConsole);
    78 	CleanupStack::PushL(myConsole);
    69 
    79 
    70 	myConsole->Printf(_L("T_USB_DEVICE v%d.%d.%d\n"),KDeviceVersionMajor,KDeviceVersionMinor,KDeviceVersionMicro);
    80 	myConsole->Printf(_L("T_USB_DEVICE v%d.%d.%d\n"),KDeviceVersionMajor,KDeviceVersionMinor,KDeviceVersionMicro);
       
    81 	OstTraceExt3(TRACE_NORMAL, RUNAPPL_RUNAPPL_DUP02, "T_USB_DEVICE v%u.%u.%u\n",KDeviceVersionMajor,KDeviceVersionMinor,KDeviceVersionMicro);
    71 	test.Printf(_L("T_USB_DEVICE v%d.%d.%d\n"),KDeviceVersionMajor,KDeviceVersionMinor,KDeviceVersionMicro);
    82 	test.Printf(_L("T_USB_DEVICE v%d.%d.%d\n"),KDeviceVersionMajor,KDeviceVersionMinor,KDeviceVersionMicro);
       
    83 	OstTraceExt3(TRACE_NORMAL, RUNAPPL_RUNAPPL_DUP03, "T_USB_DEVICE v%u.%u.%u\n",KDeviceVersionMajor,KDeviceVersionMinor,KDeviceVersionMicro);
    72 	#endif
    84 	#endif
    73 	
    85 
    74 	// outermost test begin
    86 	// outermost test begin
    75 	test.Start(_L("Outermost test of t_usb_device\n"));
    87 	test.Start(_L("Outermost test of t_usb_device\n"));
    76 
    88 
    77 	do
    89 	do
    78 		{
    90 		{
    79 		gActiveControl = CActiveControl::NewL(myConsole, aConfigFile, aScriptFile);
    91 		gActiveControl = CActiveControl::NewL(myConsole, aConfigFile, aScriptFile);
    80 		CleanupStack::PushL(gActiveControl);
    92 		CleanupStack::PushL(gActiveControl);
    81 
    93 
    82 	
    94 
    83 		// Call request function
    95 		// Call request function
       
    96 #ifdef USB_SC
       
    97 		if (!gShareHandle)
       
    98 			gActiveControl->RequestEp0ControlPacket();
       
    99 #else
    84 		gActiveControl->RequestEp0ControlPacket();
   100 		gActiveControl->RequestEp0ControlPacket();
    85 
   101 #endif
    86 		CActiveScheduler::Start();
   102 		CActiveScheduler::Start();
    87 		
   103 
    88 		test.Printf (_L("Test Run Completed\n"));
   104 		test.Printf (_L("Test Run Completed\n"));
    89 		
   105 		OstTrace0(TRACE_NORMAL, RUNAPPL_RUNAPPL_DUP04, "Test Run Completed\n");
       
   106 
    90 		if (gSoakCount > 0)
   107 		if (gSoakCount > 0)
    91 			{
   108 			{
    92 			gSoakCount--;
   109 			gSoakCount--;
    93 			}
   110 			}
    94 
   111 
    95 		// Suspend thread for 2 seconds
   112 		// Suspend thread for 2 seconds
    96 		User::After(2000000);
   113 		User::After(2000000);
    97 		
   114 
    98 		CleanupStack::PopAndDestroy(gActiveControl);
   115 		CleanupStack::PopAndDestroy(gActiveControl);
    99 
   116 
   100 		}
   117 		}
   101 	while ((gSoakCount > 0) || (gSoakCount == -1));
   118 	while ((gSoakCount > 0) || (gSoakCount == -1));
   102 
   119 
   112 	}
   129 	}
   113 
   130 
   114 void ParseCommandLine (TDes& aConfigFileName, TDes& aScriptFileName)
   131 void ParseCommandLine (TDes& aConfigFileName, TDes& aScriptFileName)
   115 	{
   132 	{
   116 	TBuf<64> c;
   133 	TBuf<64> c;
   117 	
   134 
   118 	User::CommandLine(c);
   135 	User::CommandLine(c);
   119 	c.LowerCase();
   136 	c.LowerCase();
   120 
   137 
   121 	aConfigFileName.SetLength(0);
   138 	aConfigFileName.SetLength(0);
   122 	aScriptFileName.SetLength(0);
   139 	aScriptFileName.SetLength(0);
   127 
   144 
   128 		while (token.Set(lex.NextToken()), token != KNullDesC)
   145 		while (token.Set(lex.NextToken()), token != KNullDesC)
   129 			{
   146 			{
   130 			if (token == _L("/v"))
   147 			if (token == _L("/v"))
   131 				{
   148 				{
   132 				RDebug::Print(_L("Verbose output enabled\n"));
   149 				OstTrace0(TRACE_NORMAL, PARSECOMMANDLINE_PARSECOMMANDLINE, "Verbose output enabled\n");
   133 				gVerbose = ETrue;
   150 				gVerbose = ETrue;
   134 				}
   151 				}
   135 			else if (token == _L("/s"))
   152 			else if (token == _L("/s"))
   136 				{
   153 				{
   137 				RDebug::Print(_L("Skipping some tests\n"));
   154 				OstTrace0(TRACE_NORMAL, PARSECOMMANDLINE_PARSECOMMANDLINE_DUP01, "Skipping some tests\n");
   138 				gSkip = ETrue;
   155 				gSkip = ETrue;
   139 				}
   156 				}
   140 			else if (token == _L("/t"))
   157 			else if (token == _L("/t"))
   141 				{
   158 				{
   142 				RDebug::Print(_L("Temporary Test\n"));
   159 				OstTrace0(TRACE_NORMAL, PARSECOMMANDLINE_PARSECOMMANDLINE_DUP02, "Temporary Test\n");
   143 				gTempTest = ETrue;
   160 				gTempTest = ETrue;
   144 				}
   161 				}
   145 			else if (token == _L("/n"))
   162 			else if (token == _L("/n"))
   146 				{
   163 				{
   147 				RDebug::Print(_L("Not Stopping on Test Fail\n"));
   164 				OstTrace0(TRACE_NORMAL, PARSECOMMANDLINE_PARSECOMMANDLINE_DUP03, "Not Stopping on Test Fail\n");
   148 				gStopOnFail = EFalse;
   165 				gStopOnFail = EFalse;
   149 				}
   166 				}
       
   167 #ifdef USB_SC
       
   168 			else if (token == _L("/a"))
       
   169 				{
       
   170 				OstTrace0(TRACE_NORMAL, PARSECOMMANDLINE_PARSECOMMANDLINE_DUP04, "share handle test\n");
       
   171 				gShareHandle = ETrue;
       
   172 				}
       
   173 #endif
   150 			else if (token.Left(5) == _L("/soak"))
   174 			else if (token.Left(5) == _L("/soak"))
   151 				{
   175 				{
   152 				TInt equalPos;
   176 				TInt equalPos;
   153 				gSoakCount = -1;
   177 				gSoakCount = -1;
   154 				equalPos = token.Locate('=');
   178 				equalPos = token.Locate('=');
   155 				if ((equalPos+1) < token.Length())
   179 				if ((equalPos+1) < token.Length())
   156 					{
   180 					{
   157 					TLex lexNum(token.Mid(equalPos+1));
   181 					TLex lexNum(token.Mid(equalPos+1));
   158 					lexNum.Val(gSoakCount,EDecimal);	
   182 					lexNum.Val(gSoakCount,EDecimal);
   159 					}
   183 					}
   160 				RDebug::Print(_L("Soak test for %d iterations\n"),gSoakCount);
   184 				OstTrace1(TRACE_NORMAL, PARSECOMMANDLINE_PARSECOMMANDLINE_DUP05, "Soak test for %d iterations\n",gSoakCount);
   161 				}
   185 				}
   162 			else if (token.Left(8) == _L("/script="))
   186 			else if (token.Left(8) == _L("/script="))
   163 				{
   187 				{
   164 				aScriptFileName = token;
   188 				aScriptFileName = token;
   165 				}
   189 				}
   167 				{
   191 				{
   168 				aConfigFileName = token;
   192 				aConfigFileName = token;
   169 				}
   193 				}
   170 			}
   194 			}
   171 		}
   195 		}
   172 		
   196 
   173 	}
   197 	}
   174 	
   198 
   175 TInt E32Main()
   199 TInt E32Main()
   176 	{
   200 	{
   177 	__UHEAP_MARK;
   201 	__UHEAP_MARK;
   178 	
   202 
   179 	CTrapCleanup* cleanup = CTrapCleanup::New();			// get clean-up stack
   203 	CTrapCleanup* cleanup = CTrapCleanup::New();			// get clean-up stack
   180 
   204 
   181 	TBuf<64> configFileName;
   205 	TBuf<64> configFileName;
   182 	TBuf<64> scriptFileName;
   206 	TBuf<64> scriptFileName;
   183 	ParseCommandLine (configFileName,scriptFileName);
   207 	ParseCommandLine (configFileName,scriptFileName);
   184 	
   208 
   185 	if (configFileName.Length() == 0)
   209 	if (configFileName.Length() == 0)
   186 		{
   210 		{
   187 			RDebug::Print(_L("(T_USB: Warning - No Configuration File.)\n"));		
   211 		OstTrace0(TRACE_NORMAL, E32MAIN_E32MAIN, "(T_USB: Warning - No Configuration File.\n");
   188 		}
   212 		}
   189 	else
   213 	else
   190 		{
   214 		{
   191 		RDebug::Print(_L("T_USB: Config File Name %s\n"),configFileName.PtrZ());
   215 		OstTraceExt1(TRACE_NORMAL, E32MAIN_E32MAIN_DUP01, "T_USB: Config File Name %S\n",configFileName);
   192 		}
   216 		}
   193 
   217 
   194 	if (scriptFileName.Length() != 0)
   218 	if (scriptFileName.Length() != 0)
   195 		{
   219 		{
   196 		RDebug::Print(_L("T_USB: Script File Name %s\n"),scriptFileName.PtrZ());
   220 		OstTraceExt1(TRACE_NORMAL, E32MAIN_E32MAIN_DUP02, "T_USB: Script File Name %S\n",scriptFileName);
   197 		}
   221 		}
   198 
   222 
   199 	TRAPD(error, RunAppL(& configFileName, &scriptFileName));
   223 	TRAPD(error, RunAppL(& configFileName, &scriptFileName));
   200 
   224 
   201 	__ASSERT_ALWAYS(!error, User::Panic(_L("T_USB_DEVICE: EPOC32EX"), error));
   225 	__ASSERT_ALWAYS(!error, User::Panic(_L("T_USB_DEVICE: EPOC32EX"), error));
   202 
   226 
   203 	delete cleanup;											// destroy clean-up stack
   227 	delete cleanup;											// destroy clean-up stack
   204 
   228 
   205 	__UHEAP_MARKEND;
   229 	__UHEAP_MARKEND;
   206 
   230 
   207 	RDebug::Print(_L("Program exit: done.\n"));
   231 	OstTrace0(TRACE_NORMAL, E32MAIN_E32MAIN_DUP03, "Program exit: done.\n");
   208 
   232 
   209 	return 0;												// and return
   233 	return 0;												// and return
   210 	}
   234 	}
   211 
   235 
   212 
   236