kerneltest/e32test/iic/t_iic.cpp
changeset 247 d8d70de2bd36
parent 109 b3a1d9898418
child 293 0659d0e1a03c
equal deleted inserted replaced
201:43365a9b78a3 247:d8d70de2bd36
    35 _LIT(KIicProxySlaveFileNameRootCtrlLess, "iic_slaveclient_ctrless");
    35 _LIT(KIicProxySlaveFileNameRootCtrlLess, "iic_slaveclient_ctrless");
    36 _LIT(KIicProxyFileName, "iic_client.ldd");		// Kernel-side proxy LDD acting as a client of the IIC
    36 _LIT(KIicProxyFileName, "iic_client.ldd");		// Kernel-side proxy LDD acting as a client of the IIC
    37 _LIT(KIicProxyFileNameRoot, "iic_client");
    37 _LIT(KIicProxyFileNameRoot, "iic_client");
    38 _LIT(KIicProxySlaveFileName, "iic_slaveclient.ldd");	// Kernel-side proxy LDD acting as a slave client of the IIC
    38 _LIT(KIicProxySlaveFileName, "iic_slaveclient.ldd");	// Kernel-side proxy LDD acting as a slave client of the IIC
    39 _LIT(KIicProxySlaveFileNameRoot, "iic_slaveclient");
    39 _LIT(KIicProxySlaveFileNameRoot, "iic_slaveclient");
       
    40 //These are used to exercise stub functions.
       
    41 _LIT(KIicProxyFileNameStubs, "iic_client_stubs.ldd");
       
    42 _LIT(KIicProxyFileNameRootStubs, "iic_client_stubs");
       
    43 _LIT(KIicProxySlaveFileNameStubs, "iic_slaveclient_stubs.ldd");
       
    44 _LIT(KIicProxySlaveFileNameRootStubs, "iic_slaveclient_stubs");
       
    45 
    40 
    46 
    41 #ifdef IIC_SIMULATED_PSL
    47 #ifdef IIC_SIMULATED_PSL
    42 _LIT(KSpiFileNameCtrlLess, "spi_ctrless.pdd");	// Simulated PSL bus implementation
    48 _LIT(KSpiFileNameCtrlLess, "spi_ctrless.pdd");	// Simulated PSL bus implementation
    43 _LIT(KI2cFileNameCtrlLess, "i2c_ctrless.pdd");	// Simulated PSL bus implementation
    49 _LIT(KI2cFileNameCtrlLess, "i2c_ctrless.pdd");  // Simulated PSL bus implementation
    44 _LIT(KIicPslFileName, "iic_testpsl.pdd");	// Simulated PSL implementation
    50 _LIT(KIicPslFileName, "iic_testpsl.pdd");	// Simulated PSL implementation
    45 _LIT(KSpiFileName, "spi.pdd");	// Simulated PSL bus implementation
    51 _LIT(KSpiFileName, "spi.pdd");	// Simulated PSL bus implementation
    46 _LIT(KI2cFileName, "i2c.pdd");	// Simulated PSL bus implementation
    52 _LIT(KI2cFileName, "i2c.pdd");  // Simulated PSL bus implementation
       
    53 //These are used to exercise stubs. The I2C pdd to use for stub tests will depend on
       
    54 //whether Master, Slave mode has been selected. 
       
    55 #if defined(MASTER_MODE)&&!defined(SLAVE_MODE)
       
    56 _LIT(KI2cFileNameStubs, "i2c_slavestubs_ctrless.pdd");
       
    57 #elif !defined(MASTER_MODE)&& defined(SLAVE_MODE)
       
    58 _LIT(KI2cFileNameStubs, "i2c_masterstubs_ctrless.pdd");
       
    59 #else
       
    60 _LIT(KI2cFileNameStubs, "i2c_ctrless.pdd");
       
    61 #endif
    47 #endif
    62 #endif
    48 
    63 
    49 _LIT(KIicPslFileNameRoot, "iic.pdd");
    64 _LIT(KIicPslFileNameRoot, "iic.pdd");
    50 
    65 
    51 // Specify a stand-alone channel
    66 // Specify a stand-alone channel
   728 //!						11) Use controlIO to instruct the simulated bus to block Master response. Specify a notification trigger for bus error
   743 //!						11) Use controlIO to instruct the simulated bus to block Master response. Specify a notification trigger for bus error
   729 //!						    events. Use controlIO to instruct the simulated bus to indicate that it has received more than the required number
   744 //!						    events. Use controlIO to instruct the simulated bus to indicate that it has received more than the required number
   730 //!						    of words. Wait for the TRequestStatus to be completed (with KErrNone). Specify a notification trigger for Tx and
   745 //!						    of words. Wait for the TRequestStatus to be completed (with KErrNone). Specify a notification trigger for Tx and
   731 //!							Tx Overrun, then use controlIO to instruct the simulated bus to unblock Master responses.Wait for the TRequestStatus
   746 //!							Tx Overrun, then use controlIO to instruct the simulated bus to unblock Master responses.Wait for the TRequestStatus
   732 //!							to be completed.
   747 //!							to be completed.
       
   748 //!         
       
   749 //!                     12) Test the PIL behavior for a client timeout: request notification of an event but deliberately delay the client response.  
       
   750 //!                         The PIL should return KErrTimedOut when a subsequent request for a notification is made.
   733 //!
   751 //!
   734 //! @SYMTestExpectedResults 0) Kernel-side proxy client should return with KErrNone, exits otherwise.
   752 //! @SYMTestExpectedResults 0) Kernel-side proxy client should return with KErrNone, exits otherwise.
   735 //!						1) Kernel-side proxy client should return with KErrNone, exits otherwise.
   753 //!						1) Kernel-side proxy client should return with KErrNone, exits otherwise.
   736 //!						2) Kernel-side proxy client should return with KErrNone, exits otherwise.
   754 //!						2) Kernel-side proxy client should return with KErrNone, exits otherwise.
   737 //!						3) Kernel-side proxy client should return with KErrAlreadyExists, exits otherwise.
   755 //!						3) Kernel-side proxy client should return with KErrAlreadyExists, exits otherwise.
   748 //!						   TRequestStatus should be set to KErrNone, exits otherwise.
   766 //!						   TRequestStatus should be set to KErrNone, exits otherwise.
   749 //!						10) Kernel-side proxy client should return with KErrNone for each API call, exits otherwise. The associated
   767 //!						10) Kernel-side proxy client should return with KErrNone for each API call, exits otherwise. The associated
   750 //!						   TRequestStatus should be set to KErrNone, exits otherwise.
   768 //!						   TRequestStatus should be set to KErrNone, exits otherwise.
   751 //!						11) Kernel-side proxy client should return with KErrNone for each API call, exits otherwise. The associated
   769 //!						11) Kernel-side proxy client should return with KErrNone for each API call, exits otherwise. The associated
   752 //!						   TRequestStatus should be set to KErrNone in both cases, exits otherwise.
   770 //!						   TRequestStatus should be set to KErrNone in both cases, exits otherwise.
       
   771 //!                     12) Kernel-side proxy client should return with KErrNone for each API call, exits otherwise. The associated
       
   772 //!                        TRequestStatus should be set to KErrNone in both cases, exits otherwise, except for when the client response
       
   773 //!                        exceeds the timeout period, and the next request for a notification expects KErrTimedOut.
   753 //!
   774 //!
   754 //! @SYMTestPriority        High
   775 //! @SYMTestPriority        High
   755 //! @SYMTestStatus          Implemented
   776 //! @SYMTestStatus          Implemented
   756 //----------------------------------------------------------------------------------------------
   777 //----------------------------------------------------------------------------------------------
   757 
   778 
  1187 	gTest.Printf(_L("Starting SetNotificationTrigger with 0\n"));
  1208 	gTest.Printf(_L("Starting SetNotificationTrigger with 0\n"));
  1188 	triggerMask=0;
  1209 	triggerMask=0;
  1189 	r=gChanSlaveI2c.SetNotificationTrigger(chanId,triggerMask,&status);
  1210 	r=gChanSlaveI2c.SetNotificationTrigger(chanId,triggerMask,&status);
  1190 	gTest(r==KErrNone);
  1211 	gTest(r==KErrNone);
  1191 
  1212 
       
  1213 	//Test the PIL behavior for a client timeout: request notification of an event
       
  1214 	//but deliberately delay the client response. The PIL should return KErrTimedOut 
       
  1215 	//when a subsequent request for a notification is made.
       
  1216 	gTest.Printf(_L("Starting test for SendBusErrorAndReturn.\n"));
       
  1217 	
       
  1218 	// For Rx, specify buffer granularity=4 (32-bit words), 8 words to receive, offset of 16 bytes
       
  1219 	// 64 bytes as 16 words: words 0-3 offset, words 4-11 data, words 12-15 unused
       
  1220 	gTest.Printf(_L("Starting RegisterRxBuffer\n"));
       
  1221 	r=gChanSlaveI2c.RegisterRxBuffer(chanId, 4, 8, 16);
       
  1222 	gTest(r==KErrNone);
       
  1223 
       
  1224 	// Now set the notification trigger
       
  1225 	//TRequestStatus status;
       
  1226 	triggerMask=ERxAllBytes;
       
  1227 	
       
  1228     gTest.Printf(_L("Starting SetNotificationTrigger with ERxAllBytes\n"));
       
  1229     r=gChanSlaveI2c.SetNotificationTrigger(chanId,triggerMask,&status);
       
  1230     gTest(r==KErrNone);
       
  1231     // Now instruct the bus implementation to represent receipt of the required number of words from the bus master.
       
  1232     gTest.Printf(_L("Starting SimulateRxNWords\n"));
       
  1233     r=gChanSlaveI2c.SimulateRxNWords(busIdI2c, chanId, 8);
       
  1234     gTest(r==KErrNone);
       
  1235     //
       
  1236     // Wait for the notification
       
  1237     User::WaitForRequest(status);
       
  1238     r=status.Int();
       
  1239     if(r != KErrNone)
       
  1240         {
       
  1241         gTest.Printf(_L("TRequestStatus value after receiving data = %d\n"),r);
       
  1242         gTest(r==KErrNone);
       
  1243         }
       
  1244     //Delay the client response to exceed the timeout period, and check that the next
       
  1245     //request for a notification encounters the expected error code.
       
  1246     User::After(1000 * 1000);
       
  1247     r=gChanSlaveI2c.SetNotificationTrigger(chanId,triggerMask,&status);
       
  1248     gTest(r==KErrNone);
       
  1249     User::WaitForRequest(status);
       
  1250 	r = status.Int();
       
  1251     if(r!=KErrTimedOut)
       
  1252         {
       
  1253         gTest.Printf(_L("TRequestStatus value = %d\n"),status.Int());
       
  1254         gTest(r==KErrTimedOut);
       
  1255         } 
       
  1256     gTest.Printf(_L("The test for SendBusErrorAndReturn is completed OK\n"));
  1192 	// Release the channel
  1257 	// Release the channel
  1193 	r = gChanSlaveI2c.ReleaseChannel( chanId );
  1258 	r = gChanSlaveI2c.ReleaseChannel( chanId );
  1194 	gTest(r==KErrNone);
  1259 	gTest(r==KErrNone);
  1195 
  1260 
  1196 	delete i2cBuf;
  1261 	delete i2cBuf;
  1401         gTest.Printf(_L("\nIicInterfaceInlineTests can only be run in Standalone mode\n"));
  1466         gTest.Printf(_L("\nIicInterfaceInlineTests can only be run in Standalone mode\n"));
  1402         return KErrNone;
  1467         return KErrNone;
  1403         }
  1468         }
  1404     }
  1469     }
  1405 
  1470 
       
  1471 //Only get called in stand alone mode
       
  1472 LOCAL_C TInt IicTestStubs()
       
  1473     {
       
  1474     //Function to call the stub methods for Master and slave channels
       
  1475     //when Master and Slave functionality has not been built. The stubs
       
  1476     //return KErrNotSupported.
       
  1477     TInt r=KErrNone;
       
  1478     
       
  1479     TUint32 busIdI2c = 0;
       
  1480     TConfigI2cBufV01* i2cBuf=NULL;
       
  1481     TRequestStatus status;
       
  1482 
       
  1483     //Starting master channel stubs test.
       
  1484     //a valid transaction is required when calling the Master QueueTransaction stub.
       
  1485     //Use I2C channel here. In MASTER_MODE, channelId starting from 10, 
       
  1486     //and 10 is a master channel
       
  1487     SET_BUS_TYPE(busIdI2c,EI2c);
       
  1488     SET_CHAN_NUM(busIdI2c,10);
       
  1489     // aDeviceId=1 ... 100kHz ... aTimeoutPeriod=100 ... aTransactionWaitCycles=10 - arbitrary paarmeters.
       
  1490     r=CreateI2cBuf(i2cBuf, EI2cAddr7Bit, 36, ELittleEndian, 100);
       
  1491     gTest(r==KErrNone);
       
  1492 
       
  1493     // Use a single transfer
       
  1494     _LIT(halfDuplexText,"Half Duplex Text");
       
  1495     TBuf8<17> halfDuplexBuf_8;
       
  1496     halfDuplexBuf_8.Copy(halfDuplexText);
       
  1497     TUsideTferDesc* tfer = NULL;
       
  1498     r = CreateSingleUserSideTransfer(tfer, EMasterWrite, 8, &halfDuplexBuf_8, NULL);
       
  1499     gTest(r==KErrNone);
       
  1500 
       
  1501     // Create the transaction object
       
  1502     TUsideTracnDesc* tracn = NULL;
       
  1503     r = CreateSingleUserSideTransaction(tracn, EI2c, i2cBuf, tfer, NULL, 0, NULL, NULL);
       
  1504     gTest(r==KErrNone);
       
  1505 
       
  1506     // queue a synchronous transaction
       
  1507     gTest.Printf(_L("\n\nStarting synchronous QueueTransaction \n"));
       
  1508     r = gChanMasterI2c.QueueTransaction(busIdI2c, tracn);
       
  1509     gTest.Printf(_L("Synchronous QueueTransaction returned = %d\n"),r);
       
  1510     //Queueing a transaction in SLAVE_MODE should return KErrNotSupported 
       
  1511     gTest(r==KErrNotSupported); 
       
  1512     
       
  1513     // queue an asynchronous transaction and cancel the trasnaction
       
  1514     // QueueTransaction actually completes before CancelAsyncOperation with KErrNotSupported
       
  1515     // In test driver, we pretend the request is still in the queue and then cancel it.
       
  1516     gChanMasterI2c.QueueTransaction(status, busIdI2c, tracn);
       
  1517     gChanMasterI2c.CancelAsyncOperation(&status, busIdI2c);
       
  1518     User::WaitForRequest(status);
       
  1519     if(status != KErrNotSupported)
       
  1520         {
       
  1521         gTest.Printf(_L("TRequestStatus value after queue = %d\n"),status.Int());
       
  1522         gTest(r==KErrNotSupported);
       
  1523         }
       
  1524     //spare1 is an unused method that is present to provide for future extension,
       
  1525     //which just returns KErrNotSupported. 
       
  1526     r = gChanMasterI2c.TestSpare1(busIdI2c);
       
  1527     gTest(r == KErrNotSupported);
       
  1528     //StaticExtension is present for PSL implementations to override, the default
       
  1529     //implementation just returns KErrNotSupported
       
  1530     r = gChanMasterI2c.TestStaticExtension(busIdI2c);
       
  1531     gTest(r == KErrNotSupported);
       
  1532     //free the memory
       
  1533     delete i2cBuf;
       
  1534     delete tfer;
       
  1535     delete tracn;
       
  1536 
       
  1537     //Start to test slave channel operations
       
  1538     SET_BUS_TYPE(busIdI2c,EI2c);
       
  1539     SET_CHAN_NUM(busIdI2c,11); // 11 is the Slave channel number
       
  1540     //
       
  1541     // clock speed=36Hz, aTimeoutPeriod=100 - arbitrary parameter
       
  1542     r=CreateI2cBuf(i2cBuf, EI2cAddr7Bit, 36, ELittleEndian, 100);
       
  1543     gTest(r==KErrNone);
       
  1544 
       
  1545     // Synchronous capture of a Slave channel.
       
  1546     TInt chanId = 0; // Initialise to zero to silence compiler ...
       
  1547     gTest.Printf(_L("\n\nStarting synchronous CaptureChannel \n"));
       
  1548     r = gChanSlaveI2c.CaptureChannel(busIdI2c, i2cBuf, chanId );
       
  1549     gTest.Printf(_L("Synchronous CaptureChannel returned = %d, aChanId=0x%x\n"),r,chanId);
       
  1550     gTest(r==KErrNotSupported);
       
  1551     
       
  1552     gTest.Printf(_L("Starting RegisterRxBuffer\n"));
       
  1553     r=gChanSlaveI2c.RegisterRxBuffer(chanId, 4, 8, 16);
       
  1554     gTest(r==KErrNotSupported);
       
  1555     
       
  1556     gTest.Printf(_L("\nStarting RegisterTxBuffer\n"));
       
  1557     r=gChanSlaveI2c.RegisterTxBuffer(chanId, 4, 12, 8);
       
  1558     gTest(r==KErrNotSupported);
       
  1559     //
       
  1560     // Now set the notification trigger
       
  1561     TInt triggerMask=ERxAllBytes;
       
  1562 
       
  1563     gTest.Printf(_L("Starting SetNotificationTrigger with ERxAllBytes\n"));
       
  1564     r=gChanSlaveI2c.SetNotificationTrigger(chanId,triggerMask,&status);
       
  1565     gTest(r==KErrNotSupported);
       
  1566     
       
  1567     r = gChanSlaveI2c.TestSpare1(busIdI2c);
       
  1568     gTest(r == KErrNotSupported);
       
  1569     r = gChanSlaveI2c.TestStaticExtension(busIdI2c);
       
  1570     gTest(r == KErrNotSupported);
       
  1571     delete i2cBuf;
       
  1572 
       
  1573     //Start to test MasterSlave channel operations
       
  1574     //Create a Master-Slave channel
       
  1575     RBusDevIicClient chanMasterSlaveI2c;
       
  1576     TBufC<18> proxyName;
       
  1577     proxyName = KIicProxyFileNameRootStubs;
       
  1578     r = chanMasterSlaveI2c.Open(proxyName);
       
  1579     gTest(r==KErrNone);
       
  1580     
       
  1581     SET_BUS_TYPE(busIdI2c,EI2c);
       
  1582     SET_CHAN_NUM(busIdI2c,12); // 12 is the MasterSlave channel number
       
  1583     r = chanMasterSlaveI2c.TestStaticExtension(busIdI2c);
       
  1584     gTest(r==KErrNotSupported);
       
  1585     chanMasterSlaveI2c.Close();
       
  1586 
       
  1587     return KErrNone;
       
  1588     }
       
  1589 
  1406 LOCAL_C TInt RunTests()
  1590 LOCAL_C TInt RunTests()
  1407 //
  1591 //
  1408 //	Utility method to invoke the separate tests
  1592 //	Utility method to invoke the separate tests
  1409 //
  1593 //
  1410 	{
  1594 	{
  1617 	gTest(err==KErrNone);
  1801 	gTest(err==KErrNone);
  1618 
  1802 
  1619 	gTest.Next(_L("Free Simulated PSL SPI bus driver"));
  1803 	gTest.Next(_L("Free Simulated PSL SPI bus driver"));
  1620 	err = User::FreePhysicalDevice(KSpiFileNameCtrlLess);
  1804 	err = User::FreePhysicalDevice(KSpiFileNameCtrlLess);
  1621 	gTest(err==KErrNone);
  1805 	gTest(err==KErrNone);
       
  1806 	
       
  1807     //For simplicity, the code coverage tests are executed in STANDALONE_CHANNEL mode
       
  1808 	//All the changes are made in test code, and not affect PIL.
       
  1809 	gTest.Next(_L("Start the code coverage tests"));
       
  1810 
       
  1811     gTest.Next(_L("Load Simulated PSL I2C bus driver"));
       
  1812     r = User::LoadPhysicalDevice(KI2cFileNameStubs);
       
  1813     gTest.Printf(_L("return value r=%d"),r);
       
  1814     gTest(r==KErrNone || r==KErrAlreadyExists);
       
  1815 
       
  1816     gTest.Next(_L("Load kernel-side proxy IIC client"));
       
  1817     r = User::LoadLogicalDevice(KIicProxyFileNameStubs);
       
  1818     gTest(r==KErrNone || r==KErrAlreadyExists);
       
  1819 
       
  1820     gTest.Next(_L("Load kernel-side proxy IIC slave client"));
       
  1821     r = User::LoadLogicalDevice(KIicProxySlaveFileNameStubs);
       
  1822     gTest(r==KErrNone || r==KErrAlreadyExists);
       
  1823 
       
  1824     __KHEAP_MARK;
       
  1825     TBufC<30> proxyNameStubs(KIicProxyFileNameRootStubs);
       
  1826     // Open a Master I2C channel to the kernel side proxy
       
  1827     r = gChanMasterI2c.Open(proxyNameStubs);
       
  1828 
       
  1829     gTest(r==KErrNone);
       
  1830     TBufC<35> proxySlaveNameStubs(KIicProxySlaveFileNameRootStubs);
       
  1831 
       
  1832     r = gChanSlaveI2c.Open(proxySlaveNameStubs);
       
  1833     gTest(r==KErrNone);
       
  1834     r = gChanSlaveI2c.InitSlaveClient();
       
  1835     gTest(r==KErrNone);
       
  1836 
       
  1837     // Instigate tests
       
  1838     r = IicTestStubs();
       
  1839     gTest(r==KErrNone);
       
  1840 
       
  1841     gTest.Printf(_L("Tests completed OK, about to close channel\n"));
       
  1842     gChanMasterI2c.Close();
       
  1843     gChanSlaveI2c.Close();
       
  1844 
       
  1845     UserSvr::HalFunction(EHalGroupKernel, EKernelHalSupervisorBarrier, 0, 0);
       
  1846     // Not safe to assume that heap clean-up has completed for the channels just closed, so insert a delay.(DEF145202)
       
  1847     User::After(20 * 1000);
       
  1848     __KHEAP_MARKEND;
       
  1849 
       
  1850     gTest.Next(_L("Free kernel-side proxy IIC client"));
       
  1851 
       
  1852     err = User::FreeLogicalDevice(KIicProxyFileNameRootStubs);
       
  1853     gTest(err==KErrNone || err==KErrAlreadyExists);
       
  1854     gTest.Next(_L("Free kernel-side proxy IIC slave client"));
       
  1855     err = User::FreeLogicalDevice(KIicProxySlaveFileNameRootStubs);
       
  1856     gTest(err==KErrNone || err==KErrAlreadyExists);
       
  1857 
       
  1858     gTest.Next(_L("Free Simulated PSL I2C bus driver"));
       
  1859     err = User::FreePhysicalDevice(KI2cFileNameStubs);
       
  1860     gTest(err==KErrNone);
       
  1861 
       
  1862 	gTest.Next(_L("End the code coverage tests"));
  1622 #else
  1863 #else
  1623 	gTest.Printf(_L("Don't do the test if it is not IIC_SIMULATED_PSL"));
  1864 	gTest.Printf(_L("Don't do the test if it is not IIC_SIMULATED_PSL"));
  1624 #endif
  1865 #endif
  1625 	gTest.End();
  1866 	gTest.End();
  1626 	return r;
  1867 	return r;