kerneltest/e32test/usbho/t_otgdi/src/t_otgdi.cpp
changeset 253 d37db4dcc88d
parent 0 a41df078684a
child 257 3e88ff8f41d5
equal deleted inserted replaced
252:0a40b8675b23 253:d37db4dcc88d
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2007-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".
    28 #include "debugmacros.h"
    28 #include "debugmacros.h"
    29 #include "testpolicy.h"
    29 #include "testpolicy.h"
    30 #include "testengine.h"
    30 #include "testengine.h"
    31 #include "testcaseroot.h"
    31 #include "testcaseroot.h"
    32 #include "b2bwatchers.h"
    32 #include "b2bwatchers.h"
       
    33 #include "OstTraceDefinitions.h"
       
    34 #ifdef OST_TRACE_COMPILER_IN_USE
       
    35 #include "t_otgdiTraces.h"
       
    36 #endif
    33 
    37 
    34 
    38 
    35 
    39 
    36 TPtrC KMyApplicationName _L("t_otgdi.exe");
    40 TPtrC KMyApplicationName _L("t_otgdi.exe");
    37 
    41 
   100 		// LOAD OTG- User-driver					
   104 		// LOAD OTG- User-driver					
   101 		err = User::LoadLogicalDevice(KOTGDeviceInterfaceDriverName);
   105 		err = User::LoadLogicalDevice(KOTGDeviceInterfaceDriverName);
   102 		if ( (err != KErrNone) && (err != KErrAlreadyExists) )
   106 		if ( (err != KErrNone) && (err != KErrAlreadyExists) )
   103 			{
   107 			{
   104 			test.Printf(_L("<Error %d> Unable to load driver: %S"), err, &KOTGDeviceInterfaceDriverName);
   108 			test.Printf(_L("<Error %d> Unable to load driver: %S"), err, &KOTGDeviceInterfaceDriverName);
       
   109 			OstTraceExt2(TRACE_NORMAL, PROTOTYPECODE_PROTOTYPECODE, "<Error %d> Unable to load driver: %S", err, KOTGDeviceInterfaceDriverName);
   105 			}
   110 			}
   106 		err = oUsbOtgDriver.Open();
   111 		err = oUsbOtgDriver.Open();
   107 		if (err != KErrNone)
   112 		if (err != KErrNone)
       
   113 		    {
   108 			test.Printf(_L("<Error %d> Unable to OPEN driver: %S"), err, &KOTGDeviceInterfaceDriverName);
   114 			test.Printf(_L("<Error %d> Unable to OPEN driver: %S"), err, &KOTGDeviceInterfaceDriverName);
   109 		else	
   115 			OstTraceExt2(TRACE_NORMAL, PROTOTYPECODE_PROTOTYPECODE_DUP01, "<Error %d> Unable to OPEN driver: %S", err, KOTGDeviceInterfaceDriverName);
       
   116 			}
       
   117 		else
       
   118 			{	
   110 			test.Printf(_L("OPEN driver: %S OK!"), &KOTGDeviceInterfaceDriverName);
   119 			test.Printf(_L("OPEN driver: %S OK!"), &KOTGDeviceInterfaceDriverName);
       
   120 			OstTraceExt1(TRACE_NORMAL, PROTOTYPECODE_PROTOTYPECODE_DUP02, "OPEN driver: %S OK!", KOTGDeviceInterfaceDriverName);
       
   121 			}
   111 		
   122 		
   112 		oUsbOtgDriver.StartStacks();
   123 		oUsbOtgDriver.StartStacks();
   113 		test.Printf(_L("Stack started\n"));
   124 		test.Printf(_L("Stack started\n"));
   114 		
   125 		OstTrace0(TRACE_NORMAL, PROTOTYPECODE_PROTOTYPECODE_DUP03, "Stack started\n");
   115 /*
   126 		
       
   127 
       
   128 		test.Printf(_L("API QueueOtgIdPinNotification test:\n"));
       
   129 		OstTrace0(TRACE_NORMAL, PROTOTYPECODE_PROTOTYPECODE_DUP06, "API QueueOtgIdPinNotification test:\n");
       
   130 
   116 		for (TInt loop=0; loop <6; loop++)
   131 		for (TInt loop=0; loop <6; loop++)
   117 			// TEST Events
   132 			// TEST Events
   118 			do		
   133 			do		
   119 				{
   134 				{
   120 				test.Printf(_L("Waiting for OTG...\n"));
   135 				test.Printf(_L("Waiting for OTG...\n"));
   121 				status1 = KRequestPending; // reset the status object
   136 				OstTrace0(TRACE_NORMAL, PROTOTYPECODE_PROTOTYPECODE_DUP07, "Waiting for OTG...\n");
   122 				oUsbOtgDriver.QueueOtgEventRequest( event, status1 );
       
   123 				
       
   124 				// wait			
       
   125 				User::WaitForRequest(status1);
       
   126 				TInt completionCode(status1.Int());
       
   127 				CTestCaseRoot::OtgEventString(event, aDescription);
       
   128 				test.Printf(_L("Received event %d '%S' status(%d) \n"), event, &aDescription, completionCode);
       
   129 				}
       
   130 			while (event != RUsbOtgDriver::EEventAPlugInserted); // 'A' plug found
       
   131 
       
   132 */
       
   133 		test.Printf(_L("API QueueOtgIdPinNotification test:\n"));
       
   134 
       
   135 		for (TInt loop=0; loop <6; loop++)
       
   136 			// TEST Events
       
   137 			do		
       
   138 				{
       
   139 				test.Printf(_L("Waiting for OTG...\n"));
       
   140 				status1 = KRequestPending; // reset the status object
   137 				status1 = KRequestPending; // reset the status object
   141 				oUsbOtgDriver.QueueOtgIdPinNotification( OTGIdPin, status1 );
   138 				oUsbOtgDriver.QueueOtgIdPinNotification( OTGIdPin, status1 );
   142 				test.Printf(_L("Current pin %d  \n"), OTGIdPin);
   139 				test.Printf(_L("Current pin %d  \n"), OTGIdPin);
       
   140 				OstTrace1(TRACE_NORMAL, PROTOTYPECODE_PROTOTYPECODE_DUP08, "Current pin %d  \n", OTGIdPin);
   143 				
   141 				
   144 				// wait			
   142 				// wait			
   145 				User::WaitForRequest(status1);
   143 				User::WaitForRequest(status1);
   146 				TInt completionCode(status1.Int());
   144 				TInt completionCode(status1.Int());
   147 				switch(OTGIdPin)
   145 				switch(OTGIdPin)
   155 					default:
   153 					default:
   156 						aDescription = _L("other");
   154 						aDescription = _L("other");
   157 						break;
   155 						break;
   158 					}
   156 					}
   159 				test.Printf(_L("Received pin %d '%S' status(%d) \n"), OTGIdPin, &aDescription, completionCode);
   157 				test.Printf(_L("Received pin %d '%S' status(%d) \n"), OTGIdPin, &aDescription, completionCode);
       
   158 				OstTraceExt3(TRACE_NORMAL, PROTOTYPECODE_PROTOTYPECODE_DUP09, "Received pin %d '%S' status(%d) \n", OTGIdPin, aDescription, completionCode);
   160 				}
   159 				}
   161 			while (OTGIdPin != RUsbOtgDriver::EIdPinAPlug); // 'A' plug found
   160 			while (OTGIdPin != RUsbOtgDriver::EIdPinAPlug); // 'A' plug found
   162 
   161 
   163 		test.Printf(_L("Press any key.\n"));
   162 		test.Printf(_L("Press any key.\n"));
       
   163 		OstTrace0(TRACE_NORMAL, PROTOTYPECODE_PROTOTYPECODE_DUP10, "Press any key.\n");
   164 		test.Getch();
   164 		test.Getch();
   165 
   165 
   166 		test.Printf(_L("Shutting down stack.\n"));
   166 		test.Printf(_L("Shutting down stack.\n"));
       
   167 		OstTrace0(TRACE_NORMAL, PROTOTYPECODE_PROTOTYPECODE_DUP11, "Shutting down stack.\n");
   167 		oUsbOtgDriver.StopStacks();
   168 		oUsbOtgDriver.StopStacks();
   168 
   169 
   169 		oUsbOtgDriver.Close();
   170 		oUsbOtgDriver.Close();
   170 
   171 
   171 		test.Printf(_L("Free the LDD.\n"));
   172 		test.Printf(_L("Free the LDD.\n"));
       
   173 		OstTrace0(TRACE_NORMAL, PROTOTYPECODE_PROTOTYPECODE_DUP12, "Free the LDD.\n");
   172 		err = User::FreeLogicalDevice( RUsbOtgDriver::Name() );			
   174 		err = User::FreeLogicalDevice( RUsbOtgDriver::Name() );			
   173 		if (err != KErrNone)
   175 		if (err != KErrNone)
   174 			{
   176 			{
   175 			test.Printf(_L("<Error %d> Unable to UN-load driver: %S"), err, &KOTGDeviceInterfaceDriverName);
   177 			test.Printf(_L("<Error %d> Unable to UN-load driver: %S"), err, &KOTGDeviceInterfaceDriverName);
       
   178 			OstTraceExt2(TRACE_NORMAL, PROTOTYPECODE_PROTOTYPECODE_DUP13, "<Error %d> Unable to UN-load driver: %S", err, KOTGDeviceInterfaceDriverName);
   176 			}		
   179 			}		
   177 		test.Printf(_L("#############\nPress any key.\n"));
   180 		test.Printf(_L("#############\nPress any key.\n"));
       
   181 		OstTrace0(TRACE_NORMAL, PROTOTYPECODE_PROTOTYPECODE_DUP14, "#############\nPress any key.\n");
   178 		}
   182 		}
   179 		test.Getch();
   183 		test.Getch();
   180 
   184 
   181 		test.Printf(_L("Free the LDD.\n"));
   185 		test.Printf(_L("Free the LDD.\n"));
       
   186 		OstTrace0(TRACE_NORMAL, PROTOTYPECODE_PROTOTYPECODE_DUP15, "Free the LDD.\n");
   182 		// end this process, if we do not want to run a test now as well
   187 		// end this process, if we do not want to run a test now as well
   183 		RProcess process;
   188 		RProcess process;
   184 		process.Open(RProcess().Id());
   189 		process.Open(RProcess().Id());
   185 		process.Terminate(0); 
   190 		process.Terminate(0); 
   186 	}
   191 	}
   188 
   193 
   189 
   194 
   190 
   195 
   191 static void MainL()
   196 static void MainL()
   192 	{
   197 	{
   193 	LOG_FUNC
   198 	if(gVerboseOutput)
       
   199 	    {
       
   200 	    OstTraceFunctionEntry0(MAINL_MAINL);
       
   201 	    }
   194 	// Leave the hooks in for platform security
   202 	// Leave the hooks in for platform security
   195 #ifdef __DATA_CAGING__
   203 #ifdef __DATA_CAGING__
   196 	RProcess().DataCaging(RProcess::EDataCagingOn);
   204 	RProcess().DataCaging(RProcess::EDataCagingOn);
   197 	RProcess().SecureApi(RProcess::ESecureApiOn);
   205 	RProcess().SecureApi(RProcess::ESecureApiOn);
   198 #endif		
   206 #endif		
   244 		CleanupStack::PopAndDestroy(testEngine);
   252 		CleanupStack::PopAndDestroy(testEngine);
   245 		}
   253 		}
   246 	else
   254 	else
   247 		{
   255 		{
   248 		if (-2 == err)
   256 		if (-2 == err)
       
   257 		    {
   249 			test.Printf(_L("Warning, no tests were selected!: %d\n"), err);
   258 			test.Printf(_L("Warning, no tests were selected!: %d\n"), err);
       
   259 			OstTrace1(TRACE_NORMAL, MAINL_MAINL_DUP01, "Warning, no tests were selected!: %d\n", err);
       
   260 			}
   250 		else
   261 		else
       
   262 		    {
   251 			test.Printf(_L("Unable to create the test engine: %d\n"), err);
   263 			test.Printf(_L("Unable to create the test engine: %d\n"), err);
       
   264 			OstTrace1(TRACE_NORMAL, MAINL_MAINL_DUP02, "Unable to create the test engine: %d\n", err);
       
   265 			}
   252 		}
   266 		}
   253 
   267 
   254 	// test DONE, if we are running manual, have a delay
   268 	// test DONE, if we are running manual, have a delay
   255 	if (!gSemiAutomated)
   269 	if (!gSemiAutomated)
   256 		{
   270 		{
   257 		// Get the engine to hang around so we can look at the screen output
   271 		// Get the engine to hang around so we can look at the screen output
   258 		test.Printf(KPressAnyKeyToEnd);
   272 		test.Printf(KPressAnyKeyToEnd);
       
   273 		OstTrace0(TRACE_NORMAL, MAINL_MAINL_DUP03, KPressAnyKeyToEnd);
   259 		test.Getch();
   274 		test.Getch();
   260 		}
   275 		}
   261 
   276 
   262 	__UHEAP_MARKEND;
   277 	__UHEAP_MARKEND;
   263 #ifdef _DEBUG
   278 #ifdef _DEBUG
   264 	test.Printf(_L("Test heap leaks #1 OK\n"));
   279 	test.Printf(_L("Test heap leaks #1 OK\n"));
       
   280 	OstTrace0(TRACE_NORMAL, MAINL_MAINL_DUP04, "Test heap leaks #1 OK\n");
   265 #endif
   281 #endif
   266 
   282 
   267 	CleanupStack::PopAndDestroy(sched);
   283 	CleanupStack::PopAndDestroy(sched);
   268 	__UHEAP_MARKEND;
   284 	__UHEAP_MARKEND;
   269 #ifdef _DEBUG
   285 #ifdef _DEBUG
   270 	test.Printf(_L("Test heap leaks #2 OK\n"));
   286 	test.Printf(_L("Test heap leaks #2 OK\n"));
       
   287 	OstTrace0(TRACE_NORMAL, MAINL_MAINL_DUP05, "Test heap leaks #2 OK\n");
   271 #endif
   288 #endif
   272 	
   289 	
   273 	// Finish test and release resources - this ends up closing the console (our application window)
   290 	// Finish test and release resources - this ends up closing the console (our application window)
   274 	test.End();
   291 	test.End();
   275 	test.Close();
   292 	test.Close();
   277 	}
   294 	}
   278 
   295 
   279 
   296 
   280 TInt E32Main()
   297 TInt E32Main()
   281 	{
   298 	{
   282 	LOG_FUNC
   299 	if(gVerboseOutput)
       
   300 	    {
       
   301 	    OstTraceFunctionEntry0(E32MAIN_E32MAIN);
       
   302 	    }
   283 	// Create the new trap-cleanup mechanism
   303 	// Create the new trap-cleanup mechanism
   284 	CTrapCleanup* cleanup = CTrapCleanup::New();
   304 	CTrapCleanup* cleanup = CTrapCleanup::New();
   285 	
   305 	
   286 	if (cleanup == NULL)
   306 	if (cleanup == NULL)
   287 		{
   307 		{
   291 	// Perform the tests
   311 	// Perform the tests
   292 	TRAPD(err,MainL());
   312 	TRAPD(err,MainL());
   293 	if (err != KErrNone)
   313 	if (err != KErrNone)
   294 		{
   314 		{
   295 		test.Printf(_L("MainL error: %d\n"),err);		
   315 		test.Printf(_L("MainL error: %d\n"),err);		
       
   316 		OstTrace1(TRACE_NORMAL, E32MAIN_E32MAIN_DUP01, "MainL error: %d\n",err);		
   296 		}
   317 		}
   297 	
   318 	
   298 	delete cleanup;
   319 	delete cleanup;
   299 	
   320 	
   300 	// Provide no error
   321 	// Provide no error