kerneltest/e32test/device/t_usbcsc.cpp
changeset 270 ea2cef07f9fe
parent 253 d37db4dcc88d
child 271 dc268b18d709
equal deleted inserted replaced
255:d45b74d3fb20 270:ea2cef07f9fe
    22 #include <d32usbcsc.h>
    22 #include <d32usbcsc.h>
    23 #include <hal.h>
    23 #include <hal.h>
    24 #include "t_usblib.h"
    24 #include "t_usblib.h"
    25 #include <e32svr.h>
    25 #include <e32svr.h>
    26 #include "u32std.h"
    26 #include "u32std.h"
       
    27 #include "d32otgdi.h"
    27 #include "OstTraceDefinitions.h"
    28 #include "OstTraceDefinitions.h"
    28 #ifdef OST_TRACE_COMPILER_IN_USE
    29 #ifdef OST_TRACE_COMPILER_IN_USE
    29 #include "t_usbcscTraces.h"
    30 #include "t_usbcscTraces.h"
    30 #endif
    31 #endif
    31 
    32 
    35 #define DEBUGPRINT(a) {a;}
    36 #define DEBUGPRINT(a) {a;}
    36 #else
    37 #else
    37 #define DEBUGPRINT(a) {}
    38 #define DEBUGPRINT(a) {}
    38 #endif
    39 #endif
    39 
    40 
       
    41 void OpenStackIfOtg();
       
    42 void CloseStackIfOtg();
       
    43 
    40 LOCAL_D RTest test(_L("T_USBCSC"));
    44 LOCAL_D RTest test(_L("T_USBCSC"));
       
    45 
       
    46 _LIT(KOtgdiLddFilename, "otgdi");
       
    47 static TBool gSupportsOtg;
       
    48 static RUsbOtgDriver gOtgPort;
    41 
    49 
    42 _LIT(KLddName, "eusbcsc");
    50 _LIT(KLddName, "eusbcsc");
    43 _LIT(KUsbDeviceName, "Usbcsc");
    51 _LIT(KUsbDeviceName, "Usbcsc");
    44 
    52 
    45 static char sym[9]="`*+@$#%!";
    53 static char sym[9]="`*+@$#%!";
   307 	{
   315 	{
   308 	TInt r;
   316 	TInt r;
   309 	test.Next(_L("Buffer Construction"));
   317 	test.Next(_L("Buffer Construction"));
   310 	r = gPort.RealizeInterface(gChunk);
   318 	r = gPort.RealizeInterface(gChunk);
   311 	test_KErrNone(r);
   319 	test_KErrNone(r);
   312 
   320 	
       
   321 	OpenStackIfOtg();
       
   322 	
   313 	TUsbcScChunkHeader chunkHeader(gChunk);
   323 	TUsbcScChunkHeader chunkHeader(gChunk);
   314 
   324 
   315 	DEBUGPRINT(test.Printf(_L("iBuffers at 0x%x, iAltSettings at 0x%x\n"),chunkHeader.iBuffers, chunkHeader.iAltSettings));
   325 	DEBUGPRINT(test.Printf(_L("iBuffers at 0x%x, iAltSettings at 0x%x\n"),chunkHeader.iBuffers, chunkHeader.iAltSettings));
   316 	DEBUGPRINT(OstTraceExt2(TRACE_NORMAL, TESTBUFFERCONSTRUCTION_TESTBUFFERCONSTRUCTION, "iBuffers at 0x%x, iAltSettings at 0x%x\n",chunkHeader.iBuffers, chunkHeader.iAltSettings));
   326 	DEBUGPRINT(OstTraceExt2(TRACE_NORMAL, TESTBUFFERCONSTRUCTION_TESTBUFFERCONSTRUCTION, "iBuffers at 0x%x, iAltSettings at 0x%x\n",chunkHeader.iBuffers, chunkHeader.iAltSettings));
   317 
   327 
   870 		}
   880 		}
   871 
   881 
   872 	TInt r = gPort.RealizeInterface(gChunk);
   882 	TInt r = gPort.RealizeInterface(gChunk);
   873 	test_KErrNone(r);
   883 	test_KErrNone(r);
   874 
   884 
       
   885 	OpenStackIfOtg();
       
   886 
   875 	if (gRealHardware)
   887 	if (gRealHardware)
   876 		{
   888 		{
   877 		TUsbcScChunkHeader chunkHeader(gChunk);
   889 		TUsbcScChunkHeader chunkHeader(gChunk);
   878 		
   890 		
   879 		test.Printf(_L("\n \n Trying hardware\nPlease start the Host side application...\n"));
   891 		test.Printf(_L("\n \n Trying hardware\nPlease start the Host side application...\n"));
  1022 		CActiveScheduler::Install(NULL); // Uninstalling the scheduler
  1034 		CActiveScheduler::Install(NULL); // Uninstalling the scheduler
  1023 		delete myScheduler;			
  1035 		delete myScheduler;			
  1024 		}
  1036 		}
  1025 	delete altSetConfig;
  1037 	delete altSetConfig;
  1026 	
  1038 	
       
  1039 	CloseStackIfOtg();
  1027 	CloseChannel();
  1040 	CloseChannel();
  1028 	UnloadDriver();
  1041 	UnloadDriver();
  1029 	}
  1042 	}
  1030 
  1043 
  1031 //To do Move Around Later
  1044 //To do Move Around Later
  1475 	r = SettingOne(0);	
  1488 	r = SettingOne(0);	
  1476 	test_KErrNone(r);
  1489 	test_KErrNone(r);
  1477 	r = gPort.RealizeInterface(gChunk);
  1490 	r = gPort.RealizeInterface(gChunk);
  1478 	test_KErrNone(r);
  1491 	test_KErrNone(r);
  1479 
  1492 
       
  1493 	OpenStackIfOtg();
       
  1494 
  1480 	const TInt timeOut = 5000; //5 millisec
  1495 	const TInt timeOut = 5000; //5 millisec
  1481 	TUsbcScChunkHeader chunkHeader(gChunk);
  1496 	TUsbcScChunkHeader chunkHeader(gChunk);
  1482 		
  1497 		
  1483 	TUint base = (TUint) gChunk.Base(); 
  1498 	TUint base = (TUint) gChunk.Base(); 
  1484 	TUsbcScHdrEndpointRecord* epInfo;
  1499 	TUsbcScHdrEndpointRecord* epInfo;
  1547 		test_KErrNone(WaitUntilTimeout(timeOut, status));	
  1562 		test_KErrNone(WaitUntilTimeout(timeOut, status));	
  1548 		test_Equal(status.Int(), KErrCancel);
  1563 		test_Equal(status.Int(), KErrCancel);
  1549 		
  1564 		
  1550 	}//grealhardware
  1565 	}//grealhardware
  1551 
  1566 
       
  1567 	CloseStackIfOtg();
  1552 	CloseChannel();
  1568 	CloseChannel();
  1553 	UnloadDriver();
  1569 	UnloadDriver();
  1554 
  1570 
  1555 	test.End();
  1571 	test.End();
  1556 }
  1572 }
  1564 	TInt r = SettingTwo(altSetNo);
  1580 	TInt r = SettingTwo(altSetNo);
  1565 	test_KErrNone(r);		
  1581 	test_KErrNone(r);		
  1566 
  1582 
  1567 	r = gPort.RealizeInterface(gChunk);
  1583 	r = gPort.RealizeInterface(gChunk);
  1568 	test_KErrNone(r);
  1584 	test_KErrNone(r);
       
  1585 	
       
  1586 	OpenStackIfOtg();
  1569 
  1587 
  1570 	TInt out_buf = 0;
  1588 	TInt out_buf = 0;
  1571 	TInt in_buf = 0; 
  1589 	TInt in_buf = 0; 
  1572 	TInt in_ep = 0;
  1590 	TInt in_ep = 0;
  1573 
  1591 
  1642 	//Length greater than buffer size
  1660 	//Length greater than buffer size
  1643 	gPort.WriteData(in_buf,  bufferOffset, (length + sizeof (TUint) * 3), 0,status);
  1661 	gPort.WriteData(in_buf,  bufferOffset, (length + sizeof (TUint) * 3), 0,status);
  1644 	User::WaitForRequest(status);
  1662 	User::WaitForRequest(status);
  1645 	test_Compare(status.Int(), ==, KErrArgument);
  1663 	test_Compare(status.Int(), ==, KErrArgument);
  1646 	
  1664 	
       
  1665 	CloseStackIfOtg();
  1647 	CloseChannel();
  1666 	CloseChannel();
  1648 	UnloadDriver();	
  1667 	UnloadDriver();	
  1649 	
  1668 	
  1650 	test.End();
  1669 	test.End();
  1651 	}
  1670 	}
  1692 	// Should not be allowed to release Interface once Chunk Realized
  1711 	// Should not be allowed to release Interface once Chunk Realized
  1693 	test.Printf(_L("Release Interface %d \n"), altSetNo);
  1712 	test.Printf(_L("Release Interface %d \n"), altSetNo);
  1694 	OstTrace1(TRACE_NORMAL, TESTSETINTERFACE_TESTSETINTERFACE_DUP02, "Release Interface %d \n", altSetNo);
  1713 	OstTrace1(TRACE_NORMAL, TESTSETINTERFACE_TESTSETINTERFACE_DUP02, "Release Interface %d \n", altSetNo);
  1695 	r = gPort.ReleaseInterface(altSetNo);
  1714 	r = gPort.ReleaseInterface(altSetNo);
  1696 	test_Compare(r, ==, KErrUsbAlreadyRealized);	
  1715 	test_Compare(r, ==, KErrUsbAlreadyRealized);	
       
  1716 	CloseStackIfOtg();
  1697 	CloseChannel();
  1717 	CloseChannel();
  1698 	UnloadDriver();	
  1718 	UnloadDriver();	
  1699 
  1719 
  1700 	//1 - Test if chunk constructed correctly with two Alternate Settings
  1720 	//1 - Test if chunk constructed correctly with two Alternate Settings
  1701 	//2 - If Realize Interface is called twice driver doesn not unload properly.
  1721 	//2 - If Realize Interface is called twice driver doesn not unload properly.
  1719 
  1739 
  1720 	RChunk tmpChunk;
  1740 	RChunk tmpChunk;
  1721 	r = gPort.RealizeInterface(tmpChunk);			//TO do Uncomment to test Realize interface call twice
  1741 	r = gPort.RealizeInterface(tmpChunk);			//TO do Uncomment to test Realize interface call twice
  1722 	test_Equal(KErrUsbAlreadyRealized, r);
  1742 	test_Equal(KErrUsbAlreadyRealized, r);
  1723 
  1743 
       
  1744 	CloseStackIfOtg();
  1724 	CloseChannel();
  1745 	CloseChannel();
  1725 	TestMultipleChannels();
  1746 	TestMultipleChannels();
  1726 	UnloadDriver();			
  1747 	UnloadDriver();			
  1727 
  1748 
  1728 	test.Next(_L("Check if chunk is populated correctly with 2 settings, first setting with two endpoints and second with five endpoints \n")); 
  1749 	test.Next(_L("Check if chunk is populated correctly with 2 settings, first setting with two endpoints and second with five endpoints \n")); 
  1741 	TEndpointDescription temp1 = {5,4,1}; 
  1762 	TEndpointDescription temp1 = {5,4,1}; 
  1742 	altSetConfig->iEpsDesc[1] = temp1; //{5,4,1};
  1763 	altSetConfig->iEpsDesc[1] = temp1; //{5,4,1};
  1743 
  1764 
  1744 	TestBufferConstruction(altSetConfig);
  1765 	TestBufferConstruction(altSetConfig);
  1745 
  1766 
       
  1767 	CloseStackIfOtg();
  1746 	CloseChannel();
  1768 	CloseChannel();
  1747 	UnloadDriver();	
  1769 	UnloadDriver();	
  1748 
  1770 
  1749 
  1771 
  1750 	test.Next(_L("Test SetInterface with Dodgy alternate setting - Check if destructors Cleaning up properly \n")); 
  1772 	test.Next(_L("Test SetInterface with Dodgy alternate setting - Check if destructors Cleaning up properly \n")); 
  1764 
  1786 
  1765 	test.Printf(_L("Check chunk still populated with one interface\n")); 
  1787 	test.Printf(_L("Check chunk still populated with one interface\n")); 
  1766 	OstTrace0(TRACE_NORMAL, TESTSETINTERFACE_TESTSETINTERFACE_DUP03, "Check chunk still populated with one interface\n"); 
  1788 	OstTrace0(TRACE_NORMAL, TESTSETINTERFACE_TESTSETINTERFACE_DUP03, "Check chunk still populated with one interface\n"); 
  1767 	TestBufferConstruction(altSetConfig);
  1789 	TestBufferConstruction(altSetConfig);
  1768 
  1790 
       
  1791 	CloseStackIfOtg();
  1769 	CloseChannel();
  1792 	CloseChannel();
  1770 	UnloadDriver();		
  1793 	UnloadDriver();		
  1771 
  1794 
  1772 	test.Next(_L("Test SetInterface with invalid alternate setting \n")); 
  1795 	test.Next(_L("Test SetInterface with invalid alternate setting \n")); 
  1773 
  1796 
  1783 
  1806 
  1784 	test.Printf(_L("Check chunk still populated with one interface \n")); 
  1807 	test.Printf(_L("Check chunk still populated with one interface \n")); 
  1785 	OstTrace0(TRACE_NORMAL, TESTSETINTERFACE_TESTSETINTERFACE_DUP04, "Check chunk still populated with one interface \n"); 
  1808 	OstTrace0(TRACE_NORMAL, TESTSETINTERFACE_TESTSETINTERFACE_DUP04, "Check chunk still populated with one interface \n"); 
  1786 	TestBufferConstruction(altSetConfig);
  1809 	TestBufferConstruction(altSetConfig);
  1787 
  1810 
       
  1811 	CloseStackIfOtg();
  1788 	CloseChannel();
  1812 	CloseChannel();
  1789 	UnloadDriver();
  1813 	UnloadDriver();
  1790 
  1814 
  1791 	test.Next(_L("Test SetInterface with Number of endpoints much greater than maximum per client \n")); 
  1815 	test.Next(_L("Test SetInterface with Number of endpoints much greater than maximum per client \n")); 
  1792   	LoadDriver();
  1816   	LoadDriver();
  1801 	
  1825 	
  1802 	test.Printf(_L("Check chunk not populated with any valid data as all interfaces would be destroyed \n")); 
  1826 	test.Printf(_L("Check chunk not populated with any valid data as all interfaces would be destroyed \n")); 
  1803 	OstTrace0(TRACE_NORMAL, TESTSETINTERFACE_TESTSETINTERFACE_DUP05, "Check chunk not populated with any valid data as all interfaces would be destroyed \n"); 
  1827 	OstTrace0(TRACE_NORMAL, TESTSETINTERFACE_TESTSETINTERFACE_DUP05, "Check chunk not populated with any valid data as all interfaces would be destroyed \n"); 
  1804 	TestBufferConstruction(altSetConfig);
  1828 	TestBufferConstruction(altSetConfig);
  1805 
  1829 
       
  1830 	CloseStackIfOtg();
  1806 	CloseChannel();
  1831 	CloseChannel();
  1807 	UnloadDriver();	
  1832 	UnloadDriver();	
  1808 	test.Next(_L("Test Release Interface, No interface set but call Release interface and test Chunk construction \n")); 
  1833 	test.Next(_L("Test Release Interface, No interface set but call Release interface and test Chunk construction \n")); 
  1809 
  1834 
  1810   	LoadDriver();
  1835   	LoadDriver();
  1813 	r = gPort.ReleaseInterface(1);
  1838 	r = gPort.ReleaseInterface(1);
  1814 	test_KErrNone(r);
  1839 	test_KErrNone(r);
  1815 
  1840 
  1816 	TestBufferConstruction(altSetConfig);
  1841 	TestBufferConstruction(altSetConfig);
  1817 	
  1842 	
       
  1843 	CloseStackIfOtg();
  1818 	CloseChannel();
  1844 	CloseChannel();
  1819 	UnloadDriver();			
  1845 	UnloadDriver();			
  1820 	UserSvr::HalFunction(EHalGroupKernel, EKernelHalSupervisorBarrier, (TAny*)5000, 0);
  1846 	UserSvr::HalFunction(EHalGroupKernel, EKernelHalSupervisorBarrier, (TAny*)5000, 0);
  1821 	__KHEAP_MARKEND;
  1847 	__KHEAP_MARKEND;
  1822 	test.Next(_L("Test Release Interface, Release all interfaces one by one \n")); 
  1848 	test.Next(_L("Test Release Interface, Release all interfaces one by one \n")); 
  1835 	gPort.ReleaseInterface(0);
  1861 	gPort.ReleaseInterface(0);
  1836 	test_KErrNone(r);
  1862 	test_KErrNone(r);
  1837 
  1863 
  1838 	TestBufferConstruction(altSetConfig);
  1864 	TestBufferConstruction(altSetConfig);
  1839 
  1865 
       
  1866 	CloseStackIfOtg();
  1840 	CloseChannel();
  1867 	CloseChannel();
  1841 	UnloadDriver();			
  1868 	UnloadDriver();			
  1842 	UserSvr::HalFunction(EHalGroupKernel, EKernelHalSupervisorBarrier, (TAny*)5000, 0);
  1869 	UserSvr::HalFunction(EHalGroupKernel, EKernelHalSupervisorBarrier, (TAny*)5000, 0);
  1843 	__KHEAP_MARKEND;
  1870 	__KHEAP_MARKEND;
  1844 	delete altSetConfig;	
  1871 	delete altSetConfig;	
  3296 void OpenChannel()
  3323 void OpenChannel()
  3297 	{
  3324 	{
  3298 	test.Next(_L("Open Channel"));
  3325 	test.Next(_L("Open Channel"));
  3299 
  3326 
  3300 	TInt r = gPort.Open(0);
  3327 	TInt r = gPort.Open(0);
  3301 	test_KErrNone(r);
  3328 	test_KErrNone(r);	
       
  3329 	}
       
  3330 
       
  3331 void OpenStackIfOtg()
       
  3332 	{
       
  3333 	// On an OTG device we have to start the OTG driver, otherwise the Client
       
  3334 	// stack will remain disabled forever.
       
  3335 	if (gSupportsOtg)
       
  3336 		{
       
  3337 		test.Start(_L("Running on OTG device: loading OTG driver\n"));
       
  3338 		test.Next(_L("Load OTG LDD"));
       
  3339 		TInt r = User::LoadLogicalDevice(KOtgdiLddFilename);
       
  3340 		test((r == KErrNone) || (r == KErrAlreadyExists));
       
  3341 
       
  3342 		test.Next(_L("Open OTG channel"));
       
  3343 		r = gOtgPort.Open();
       
  3344 		test(r == KErrNone);
       
  3345 
       
  3346 		test.Next(_L("Start OTG stack"));
       
  3347 		r = gOtgPort.StartStacks();
       
  3348 		test(r == KErrNone);
       
  3349 		test.End();
       
  3350 		}
  3302 	}
  3351 	}
  3303 
  3352 
  3304 void TestMultipleChannels()
  3353 void TestMultipleChannels()
  3305 	{
  3354 	{
  3306 	RDevUsbcScClient lPort1;
  3355 	RDevUsbcScClient lPort1;
  3326 
  3375 
  3327 	test.Next(_L("Close USB Channel 3"));
  3376 	test.Next(_L("Close USB Channel 3"));
  3328 	lPort3.Close();
  3377 	lPort3.Close();
  3329 	}
  3378 	}
  3330 
  3379 
       
  3380 void CloseStackIfOtg()
       
  3381 	{
       
  3382 	if (gSupportsOtg)
       
  3383 		{
       
  3384 		test.Start(_L("Close OTG stack\n"));
       
  3385 		test.Next(_L("Stop OTG stack"));
       
  3386 		gOtgPort.StopStacks();
       
  3387 		test.Next(_L("Close OTG Channel"));
       
  3388 		gOtgPort.Close();
       
  3389 		test.Next(_L("Free OTG LDD"));
       
  3390 		TInt r = User::FreeLogicalDevice(RUsbOtgDriver::Name());
       
  3391 		test(r == KErrNone);
       
  3392 		test.End();
       
  3393 		}
       
  3394 	}
       
  3395 
  3331 void CloseChannel()
  3396 void CloseChannel()
  3332 	{
  3397 	{	
  3333 	test.Next(_L("Close Chunk Handle"));
  3398 	test.Next(_L("Close Chunk Handle"));
  3334 	gChunk.Close();
  3399 	gChunk.Close();
  3335 
  3400 
  3336 	test.Next(_L("Close USB Channel"));
  3401 	test.Next(_L("Close USB Channel"));
  3337 	gPort.Close();
  3402 	gPort.Close();
  3682 	SetupBulkInterfaces(0,1,1);
  3747 	SetupBulkInterfaces(0,1,1);
  3683 	RChunk *tChunk = &gChunk;
  3748 	RChunk *tChunk = &gChunk;
  3684 	test.Printf(_L("Finalize Interface\n"));
  3749 	test.Printf(_L("Finalize Interface\n"));
  3685 	OstTrace0(TRACE_NORMAL, TESTBILREADWRITE_TESTBILREADWRITE_DUP02, "Finalize Interface\n");
  3750 	OstTrace0(TRACE_NORMAL, TESTBILREADWRITE_TESTBILREADWRITE_DUP02, "Finalize Interface\n");
  3686 	gPort.FinalizeInterface(tChunk);
  3751 	gPort.FinalizeInterface(tChunk);
       
  3752 	OpenStackIfOtg();
  3687 
  3753 
  3688 	if(gRealHardware)
  3754 	if(gRealHardware)
  3689 		{
  3755 		{
  3690 		test.Printf(_L("Please Start the USBIO demo application on the host side \n"));
  3756 		test.Printf(_L("Please Start the USBIO demo application on the host side \n"));
  3691 		OstTrace0(TRACE_NORMAL, TESTBILREADWRITE_TESTBILREADWRITE_DUP03, "Please Start the USBIO demo application on the host side \n");
  3757 		OstTrace0(TRACE_NORMAL, TESTBILREADWRITE_TESTBILREADWRITE_DUP03, "Please Start the USBIO demo application on the host side \n");
  3714 			{
  3780 			{
  3715 			test.Printf(_L("!!warning- compare buffers found discrepancies!\n"));
  3781 			test.Printf(_L("!!warning- compare buffers found discrepancies!\n"));
  3716 			OstTrace0(TRACE_NORMAL, TESTBILREADWRITE_TESTBILREADWRITE_DUP09, "!!warning- compare buffers found discrepancies!\n");
  3782 			OstTrace0(TRACE_NORMAL, TESTBILREADWRITE_TESTBILREADWRITE_DUP09, "!!warning- compare buffers found discrepancies!\n");
  3717 			}
  3783 			}
  3718 		}
  3784 		}
       
  3785 	CloseStackIfOtg();
  3719 	gChunk.Close();
  3786 	gChunk.Close();
  3720 	test.Printf(_L("Close global USB channel\n"));
  3787 	test.Printf(_L("Close global USB channel\n"));
  3721 	OstTrace0(TRACE_NORMAL, TESTBILREADWRITE_TESTBILREADWRITE_DUP10, "Close global USB channel\n");
  3788 	OstTrace0(TRACE_NORMAL, TESTBILREADWRITE_TESTBILREADWRITE_DUP10, "Close global USB channel\n");
  3722 	gPort.Close();
  3789 	gPort.Close();
  3723 	}
  3790 	}
  3741 	SetupBulkInterfaces(1,1,1);
  3808 	SetupBulkInterfaces(1,1,1);
  3742 	RChunk *tChunk = &gChunk;
  3809 	RChunk *tChunk = &gChunk;
  3743 	test.Printf(_L("Finalize Interface\n"));
  3810 	test.Printf(_L("Finalize Interface\n"));
  3744 	OstTrace0(TRACE_NORMAL, TESTBILALTERNATESETTINGCHANGE_TESTBILALTERNATESETTINGCHANGE_DUP03, "Finalize Interface\n");
  3811 	OstTrace0(TRACE_NORMAL, TESTBILALTERNATESETTINGCHANGE_TESTBILALTERNATESETTINGCHANGE_DUP03, "Finalize Interface\n");
  3745 	gPort.FinalizeInterface(tChunk);
  3812 	gPort.FinalizeInterface(tChunk);
       
  3813 	OpenStackIfOtg();
  3746 
  3814 
  3747 	if(gRealHardware)
  3815 	if(gRealHardware)
  3748 		{
  3816 		{
  3749 		gPort.ReEnumerate(status);
  3817 		gPort.ReEnumerate(status);
  3750 		User::WaitForRequest(status);
  3818 		User::WaitForRequest(status);
  3751 		test.Printf(_L("Enumerated. status = %d\n"), status.Int());
  3819 		test.Printf(_L("Enumerated. status = %d\n"), status.Int());
  3752 		OstTrace1(TRACE_NORMAL, TESTBILALTERNATESETTINGCHANGE_TESTBILALTERNATESETTINGCHANGE_DUP04, "Enumerated. status = %d\n", status.Int());
  3820 		OstTrace1(TRACE_NORMAL, TESTBILALTERNATESETTINGCHANGE_TESTBILALTERNATESETTINGCHANGE_DUP04, "Enumerated. status = %d\n", status.Int());
  3753 		}
  3821 		}
       
  3822 	CloseStackIfOtg();
  3754 	gChunk.Close();
  3823 	gChunk.Close();
  3755 	test.Printf(_L("Close global USB channel\n"));
  3824 	test.Printf(_L("Close global USB channel\n"));
  3756 	OstTrace0(TRACE_NORMAL, TESTBILALTERNATESETTINGCHANGE_TESTBILALTERNATESETTINGCHANGE_DUP05, "Close global USB channel\n");
  3825 	OstTrace0(TRACE_NORMAL, TESTBILALTERNATESETTINGCHANGE_TESTBILALTERNATESETTINGCHANGE_DUP05, "Close global USB channel\n");
  3757 	gPort.Close();
  3826 	gPort.Close();
  3758 	}
  3827 	}
  3774 	test_KErrNone(gPort.Open(0));
  3843 	test_KErrNone(gPort.Open(0));
  3775 	//Test for a simple interface with 2 endpoints
  3844 	//Test for a simple interface with 2 endpoints
  3776 	SetupBulkInterfaces(0,1,1);
  3845 	SetupBulkInterfaces(0,1,1);
  3777 	RChunk *tChunk = &gChunk;
  3846 	RChunk *tChunk = &gChunk;
  3778 	test_KErrNone(gPort.FinalizeInterface(tChunk));
  3847 	test_KErrNone(gPort.FinalizeInterface(tChunk));
       
  3848 	OpenStackIfOtg();
  3779 
  3849 
  3780 	if(gRealHardware)
  3850 	if(gRealHardware)
  3781 		{
  3851 		{
  3782 		test.Printf(_L("With USBIO, open and configure the device, then send then and then recieve at lest 4 class/vendor requests to interface 0\n"));
  3852 		test.Printf(_L("With USBIO, open and configure the device, then send then and then recieve at lest 4 class/vendor requests to interface 0\n"));
  3783 		OstTrace0(TRACE_NORMAL, TESTBILEP0_TESTBILEP0, "With USBIO, open and configure the device, then send then and then recieve at lest 4 class/vendor requests to interface 0\n");
  3853 		OstTrace0(TRACE_NORMAL, TESTBILEP0_TESTBILEP0, "With USBIO, open and configure the device, then send then and then recieve at lest 4 class/vendor requests to interface 0\n");
  3965 
  4035 
  3966 		//Note- A disturbing fact! If host aborts data transmission and send a new setup packet, the userside is clueless as to what it's reading is
  4036 		//Note- A disturbing fact! If host aborts data transmission and send a new setup packet, the userside is clueless as to what it's reading is
  3967 		//		data/setup data.  
  4037 		//		data/setup data.  
  3968 			test.Getch();
  4038 			test.Getch();
  3969 		} // end if-real-hardware
  4039 		} // end if-real-hardware
       
  4040 	CloseStackIfOtg();
  3970 	gChunk.Close();
  4041 	gChunk.Close();
  3971 	test.Printf(_L("Close global USB channel\n"));
  4042 	test.Printf(_L("Close global USB channel\n"));
  3972 	OstTrace0(TRACE_NORMAL, TESTBILEP0_TESTBILEP0_DUP16, "Close global USB channel\n");
  4043 	OstTrace0(TRACE_NORMAL, TESTBILEP0_TESTBILEP0_DUP16, "Close global USB channel\n");
  3973 	gPort.Close();
  4044 	gPort.Close();
  3974 	} // end funcion
  4045 	} // end funcion
  4254 
  4325 
  4255 	// Check for OTG support as if OTG is supported, client stack is disabled
  4326 	// Check for OTG support as if OTG is supported, client stack is disabled
  4256 	TBuf8<KUsbDescSize_Otg> otg_desc;
  4327 	TBuf8<KUsbDescSize_Otg> otg_desc;
  4257 	r = gPort.GetOtgDescriptor(otg_desc);
  4328 	r = gPort.GetOtgDescriptor(otg_desc);
  4258 	test(r == KErrNotSupported || r == KErrNone);
  4329 	test(r == KErrNotSupported || r == KErrNone);
  4259 	TInt supportsOtg = (r != KErrNotSupported) ? ETrue : EFalse;
  4330 	gSupportsOtg = (r != KErrNotSupported) ? ETrue : EFalse;
  4260 
  4331 		
       
  4332 	OpenStackIfOtg();
       
  4333 	
  4261 	// We turn on UDC here explicitly. This is done only once and just to test the API as such
  4334 	// We turn on UDC here explicitly. This is done only once and just to test the API as such
  4262 	test.Next(_L("Powering up UDC"));
  4335 	test.Next(_L("Powering up UDC"));
  4263 	r = gPort.PowerUpUdc();
  4336 	r = gPort.PowerUpUdc();
  4264 
  4337 
  4265 	if (!supportsOtg)
  4338 	if (!gSupportsOtg)
  4266 		{
  4339 		{
  4267 		test_KErrNone(r);
  4340 		test_KErrNone(r);
  4268 		}
  4341 		}
  4269 	else
  4342 	else
  4270 		{
  4343 		{
  4271 		test((r == KErrNone) || (r == KErrNotReady));
  4344 		test((r == KErrNone) || (r == KErrNotReady));
  4272 		}
  4345 		}
  4273 
  4346 
       
  4347 	CloseStackIfOtg();
  4274 	CloseChannel();
  4348 	CloseChannel();
  4275 	UnloadDriver();
  4349 	UnloadDriver();
       
  4350 		
  4276 	if (gSpecTest == EAll)
  4351 	if (gSpecTest == EAll)
  4277 		{
  4352 		{
  4278 		for (TInt i = 1; i <= 7; i++)
  4353 		for (TInt i = 1; i <= 7; i++)
  4279 			{
  4354 			{
  4280 			gSpecTest = (TSpecTestType) i;
  4355 			gSpecTest = (TSpecTestType) i;