diff --git a/src/test/java/javax/usb/tck/BulkIOTests.java b/src/test/java/javax/usb/tck/BulkIOTests.java new file mode 100755 index 0000000..e805bdb --- /dev/null +++ b/src/test/java/javax/usb/tck/BulkIOTests.java @@ -0,0 +1,576 @@ +/** + * Copyright (c) 2004, International Business Machines Corporation. + * All Rights Reserved. + * + * This software is provided and licensed under the terms and conditions + * of the Common Public License: + * http://oss.software.ibm.com/developerworks/opensource/license-cpl.html + */ + +package javax.usb.tck; + +import java.util.*; + +import javax.usb.*; + +import org.junit.runner.RunWith; + +import de.ailis.usb4java.TCKRunner; + +import junit.framework.*; + +/** + * Bulk IO Test -- Synchronous and asynchronous byte[], IRP, and IRP List submissions + *

+ * The goal of the Bulk, Interrupt, and Isochronous IO test is to + * verify that IN and OUT pipes can be opened and closed, and verify + * that bulk, interrupt, and isochronous transfer operations work successfully, proper + * events are generated, and proper exceptions are thrown in the operation. + * + * @author Leslie Blair + */ + + +@SuppressWarnings("all") +@RunWith(TCKRunner.class) +public class BulkIOTests extends TestCase +{ + public void setUp() throws Exception + { + endpointType = UsbConst.ENDPOINT_TYPE_BULK; + usbDevice = FindProgrammableDevice.getInstance().getProgrammableDevice(); + Assert.assertNotNull("Device required for test not found",usbDevice); + IOMethods.createListofAllAvailablePipesOfSpecifiedEndpointType(usbDevice, endpointType, usbPipeListGlobal); + super.setUp(); + } + public void tearDown() throws Exception + { + IOMethods.releaseListOfPipes(usbPipeListGlobal); + super.tearDown(); + } + + public void testByteArray_BuffersMultiplesOfMaxPacketSize_maxPacketSizeOf8bytes_buffer8bytes_passthrough() + { + + byte testType = IOTests.BYTE_ARRAY; + /* + * values from table + */ + int numberOfIrps = 1; + int endpointmaxPacketSize = 8; + byte []transformType = {IOTests.TRANSFORM_TYPE_PASSTHROUGH}; + + boolean[] IrpAcceptShortPacket = {true}; + boolean[] verifyAcceptShortPacket = {true}; + + + int []OUTLength = {8}; + int []OUTOffset = {0}; + int []OUTExpectedActualLength = {OUTLength[0]}; + Exception[] OUTExpectedException = {null}; + + int []INLength = {OUTLength[0]}; + int []INOffset = {OUTOffset[0]}; + int []INExpectedActualLength = {OUTLength[0]}; + Exception[] INExpectedException = {null}; + + IOTests thisIOTest = new IOTests(usbDevice, usbPipeListGlobal, endpointType, testType); + thisIOTest.RoundTripIOTest(testType, numberOfIrps, endpointmaxPacketSize, + IrpAcceptShortPacket, verifyAcceptShortPacket, OUTLength, OUTOffset, OUTExpectedActualLength, + OUTExpectedException, + INLength, INOffset, INExpectedActualLength, + INExpectedException, + transformType ); + + + }; + + public void testByteArray_BuffersMultiplesOfMaxPacketSize_maxPacketSizeOf8bytes_buffer16bytes_invertBits() + { + + byte testType = IOTests.BYTE_ARRAY; + /* + * values from table + */ + int numberOfIrps = 1; + int endpointmaxPacketSize = 8; + byte []transformType = {IOTests.TRANSFORM_TYPE_INVERT_BITS}; + + boolean[] IrpAcceptShortPacket = {true}; + boolean[] verifyAcceptShortPacket = {true}; + + + int []OUTLength = {16}; + int []OUTOffset = {0}; + int []OUTExpectedActualLength = {OUTLength[0]}; + Exception[] OUTExpectedException = {null}; + + int []INLength = {OUTLength[0]}; + int []INOffset = {OUTOffset[0]}; + int []INExpectedActualLength = {OUTLength[0]}; + Exception[] INExpectedException = {null}; + + IOTests thisIOTest = new IOTests(usbDevice, usbPipeListGlobal, endpointType, testType); + thisIOTest.RoundTripIOTest(testType, numberOfIrps, endpointmaxPacketSize, + IrpAcceptShortPacket, verifyAcceptShortPacket, OUTLength, OUTOffset, OUTExpectedActualLength, + OUTExpectedException, + INLength, INOffset, INExpectedActualLength, + INExpectedException, + transformType ); + + + }; + public void testByteArray_BuffersMultiplesOfMaxPacketSize_maxPacketSizeOf8bytes_buffer24bytes_invertAltBits() + { + + byte testType = IOTests.BYTE_ARRAY; + /* + * values from table + */ + int numberOfIrps = 1; + int endpointmaxPacketSize = 8; + byte []transformType = {IOTests.TRANSFORM_TYPE_INVERT_ALTERNATE_BITS}; + + boolean[] IrpAcceptShortPacket = {true}; + boolean[] verifyAcceptShortPacket = {true}; + + + int []OUTLength = {24}; + int []OUTOffset = {0}; + int []OUTExpectedActualLength = {OUTLength[0]}; + Exception[] OUTExpectedException = {null}; + + int []INLength = {OUTLength[0]}; + int []INOffset = {OUTOffset[0]}; + int []INExpectedActualLength = {OUTLength[0]}; + Exception[] INExpectedException = {null}; + + IOTests thisIOTest = new IOTests(usbDevice, usbPipeListGlobal, endpointType, testType); + thisIOTest.RoundTripIOTest(testType, numberOfIrps, endpointmaxPacketSize, + IrpAcceptShortPacket, verifyAcceptShortPacket, OUTLength, OUTOffset, OUTExpectedActualLength, + OUTExpectedException, + INLength, INOffset, INExpectedActualLength, + INExpectedException, + transformType ); + + + }; + // TODO Disabled because 64 byte packet size not supported by test firmware + public void disabled_testByteArray_BuffersNOTMultiplesOfMaxPacketSize_maxPacketSizeOf64bytes_buffer17bytes_passthrough() + { + byte testType = IOTests.BYTE_ARRAY; + /* + * values from table + */ + int numberOfIrps = 1; + int endpointmaxPacketSize = 64; + byte []transformType = {IOTests.TRANSFORM_TYPE_PASSTHROUGH}; + + boolean[] IrpAcceptShortPacket = {true}; + boolean[] verifyAcceptShortPacket = {true}; + + + int []OUTLength = {17}; + int []OUTOffset = {0}; + int []OUTExpectedActualLength = {OUTLength[0]}; + Exception[] OUTExpectedException = {null}; + + int []INLength = {OUTLength[0]}; + int []INOffset = {OUTOffset[0]}; + int []INExpectedActualLength = {OUTLength[0]}; + Exception[] INExpectedException = {null}; + + IOTests thisIOTest = new IOTests(usbDevice, usbPipeListGlobal, endpointType, testType); + thisIOTest.RoundTripIOTest(testType, numberOfIrps, endpointmaxPacketSize, + IrpAcceptShortPacket, verifyAcceptShortPacket, OUTLength, OUTOffset, OUTExpectedActualLength, + OUTExpectedException, + INLength, INOffset, INExpectedActualLength, + INExpectedException, + transformType ); + + + }; + // TODO Disabled because 64 byte packet size not supported by test firmware + public void disabled_testByteArray_BuffersNOTMultiplesOfMaxPacketSize_maxPacketSizeOf64bytes_buffer66bytes_invertBits() + { + byte testType = IOTests.BYTE_ARRAY; + /* + * values from table + */ + int numberOfIrps = 1; + int endpointmaxPacketSize = 64; + byte []transformType = {IOTests.TRANSFORM_TYPE_INVERT_BITS}; + + boolean[] IrpAcceptShortPacket = {true}; + boolean[] verifyAcceptShortPacket = {true}; + + + int []OUTLength = {66}; + int []OUTOffset = {0}; + int []OUTExpectedActualLength = {OUTLength[0]}; + Exception[] OUTExpectedException = {null}; + + int []INLength = {OUTLength[0]}; + int []INOffset = {OUTOffset[0]}; + int []INExpectedActualLength = {OUTLength[0]}; + Exception[] INExpectedException = {null}; + + IOTests thisIOTest = new IOTests(usbDevice, usbPipeListGlobal, endpointType, testType); + thisIOTest.RoundTripIOTest(testType, numberOfIrps, endpointmaxPacketSize, + IrpAcceptShortPacket, verifyAcceptShortPacket, OUTLength, OUTOffset, OUTExpectedActualLength, + OUTExpectedException, + INLength, INOffset, INExpectedActualLength, + INExpectedException, + transformType ); + + + }; + // TODO Disabled because 64 byte packet size not supported by test firmware + public void disabled_testByteArray_BuffersNOTMultiplesOfMaxPacketSize_maxPacketSizeOf64bytes_buffer129bytes_invertAltBits() + { + byte testType = IOTests.BYTE_ARRAY; + /* + * values from table + */ + int numberOfIrps = 1; + int endpointmaxPacketSize = 64; + byte []transformType = {IOTests.TRANSFORM_TYPE_INVERT_ALTERNATE_BITS}; + + boolean[] IrpAcceptShortPacket = {true}; + boolean[] verifyAcceptShortPacket = {true}; + + + int []OUTLength = {129}; + int []OUTOffset = {0}; + int []OUTExpectedActualLength = {OUTLength[0]}; + Exception[] OUTExpectedException = {null}; + + int []INLength = {OUTLength[0]}; + int []INOffset = {OUTOffset[0]}; + int []INExpectedActualLength = {OUTLength[0]}; + Exception[] INExpectedException = {null}; + + IOTests thisIOTest = new IOTests(usbDevice, usbPipeListGlobal, endpointType, testType); + thisIOTest.RoundTripIOTest(testType, numberOfIrps, endpointmaxPacketSize, + IrpAcceptShortPacket, verifyAcceptShortPacket, OUTLength, OUTOffset, OUTExpectedActualLength, + OUTExpectedException, + INLength, INOffset, INExpectedActualLength, + INExpectedException, + transformType ); + + + }; + public void testSingleIRP_BuffersMultiplesOfMaxPacketSize_maxPacketSizeOf8bytes_buffer8bytes_invertBits() + { + + byte testType = IOTests.IRP; + /* + * values from table + */ + int numberOfIrps = 1; + int endpointmaxPacketSize = 8; + byte []transformType = {IOTests.TRANSFORM_TYPE_INVERT_BITS}; + + boolean[] IrpAcceptShortPacket = {true}; + boolean[] verifyAcceptShortPacket = {true}; + + + int []OUTLength = {8}; + int []OUTOffset = {0}; + int []OUTExpectedActualLength = {OUTLength[0]}; + Exception[] OUTExpectedException = {null}; + + int []INLength = {OUTLength[0]}; + int []INOffset = {OUTOffset[0]}; + int []INExpectedActualLength = {OUTLength[0]}; + Exception[] INExpectedException = {null}; + + IOTests thisIOTest = new IOTests(usbDevice, usbPipeListGlobal, endpointType, testType); + thisIOTest.RoundTripIOTest(testType, numberOfIrps, endpointmaxPacketSize, + IrpAcceptShortPacket, verifyAcceptShortPacket, OUTLength, OUTOffset, OUTExpectedActualLength, + OUTExpectedException, + INLength, INOffset, INExpectedActualLength, + INExpectedException, + transformType ); + + + }; + public void testSingleIRP_BuffersMultiplesOfMaxPacketSize_maxPacketSizeOf8bytes_buffer16bytes_invertAltBits() + { + + byte testType = IOTests.IRP; + /* + * values from table + */ + int numberOfIrps = 1; + int endpointmaxPacketSize = 8; + byte []transformType = {IOTests.TRANSFORM_TYPE_INVERT_ALTERNATE_BITS}; + + boolean[] IrpAcceptShortPacket = {true}; + boolean[] verifyAcceptShortPacket = {true}; + + + int []OUTLength = {16}; + int []OUTOffset = {0}; + int []OUTExpectedActualLength = {OUTLength[0]}; + Exception[] OUTExpectedException = {null}; + + int []INLength = {OUTLength[0]}; + int []INOffset = {OUTOffset[0]}; + int []INExpectedActualLength = {OUTLength[0]}; + Exception[] INExpectedException = {null}; + + IOTests thisIOTest = new IOTests(usbDevice, usbPipeListGlobal, endpointType, testType); + thisIOTest.RoundTripIOTest(testType, numberOfIrps, endpointmaxPacketSize, + IrpAcceptShortPacket, verifyAcceptShortPacket, OUTLength, OUTOffset, OUTExpectedActualLength, + OUTExpectedException, + INLength, INOffset, INExpectedActualLength, + INExpectedException, + transformType ); + + + }; + public void testSingleIRP_BuffersMultiplesOfMaxPacketSize_maxPacketSizeOf8bytes_buffer64bytes_passthrough() + { + + byte testType = IOTests.IRP; + /* + * values from table + */ + int numberOfIrps = 1; + int endpointmaxPacketSize = 8; + byte []transformType = {IOTests.TRANSFORM_TYPE_PASSTHROUGH}; + + boolean[] IrpAcceptShortPacket = {true}; + boolean[] verifyAcceptShortPacket = {true}; + + + int []OUTLength = {64}; + int []OUTOffset = {0}; + int []OUTExpectedActualLength = {OUTLength[0]}; + Exception[] OUTExpectedException = {null}; + + int []INLength = {OUTLength[0]}; + int []INOffset = {OUTOffset[0]}; + int []INExpectedActualLength = {OUTLength[0]}; + Exception[] INExpectedException = {null}; + + IOTests thisIOTest = new IOTests(usbDevice, usbPipeListGlobal, endpointType, testType); + thisIOTest.RoundTripIOTest(testType, numberOfIrps, endpointmaxPacketSize, + IrpAcceptShortPacket, verifyAcceptShortPacket, OUTLength, OUTOffset, OUTExpectedActualLength, + OUTExpectedException, + INLength, INOffset, INExpectedActualLength, + INExpectedException, + transformType ); + + + }; + // TODO Disabled because 64 byte packet size not supported by test firmware + public void disabled_testSingleIRP_BuffersNOTMultiplesOfMaxPacketSize_maxPacketSizeOf64bytes_buffer25bytes_invertBits() + { + byte testType = IOTests.IRP; + /* + * values from table + */ + int numberOfIrps = 1; + int endpointmaxPacketSize = 64; + byte []transformType = {IOTests.TRANSFORM_TYPE_INVERT_BITS}; + + boolean[] IrpAcceptShortPacket = {true}; + boolean[] verifyAcceptShortPacket = {true}; + + + int []OUTLength = {25}; + int []OUTOffset = {0}; + int []OUTExpectedActualLength = {OUTLength[0]}; + Exception[] OUTExpectedException = {null}; + + int []INLength = {OUTLength[0]}; + int []INOffset = {OUTOffset[0]}; + int []INExpectedActualLength = {OUTLength[0]}; + Exception[] INExpectedException = {null}; + + IOTests thisIOTest = new IOTests(usbDevice, usbPipeListGlobal, endpointType, testType); + thisIOTest.RoundTripIOTest(testType, numberOfIrps, endpointmaxPacketSize, + IrpAcceptShortPacket, verifyAcceptShortPacket, OUTLength, OUTOffset, OUTExpectedActualLength, + OUTExpectedException, + INLength, INOffset, INExpectedActualLength, + INExpectedException, + transformType ); + + + }; + // TODO Disabled because 64 byte packet size not supported by test firmware + public void disabled_testSingleIRP_BuffersNOTMultiplesOfMaxPacketSize_maxPacketSizeOf64bytes_buffer72bytes_invertAltBits() + { + byte testType = IOTests.IRP; + /* + * values from table + */ + int numberOfIrps = 1; + int endpointmaxPacketSize = 64; + byte []transformType = {IOTests.TRANSFORM_TYPE_INVERT_ALTERNATE_BITS}; + + boolean[] IrpAcceptShortPacket = {true}; + boolean[] verifyAcceptShortPacket = {true}; + + + int []OUTLength = {72}; + int []OUTOffset = {0}; + int []OUTExpectedActualLength = {OUTLength[0]}; + Exception[] OUTExpectedException = {null}; + + int []INLength = {OUTLength[0]}; + int []INOffset = {OUTOffset[0]}; + int []INExpectedActualLength = {OUTLength[0]}; + Exception[] INExpectedException = {null}; + + IOTests thisIOTest = new IOTests(usbDevice, usbPipeListGlobal, endpointType, testType); + thisIOTest.RoundTripIOTest(testType, numberOfIrps, endpointmaxPacketSize, + IrpAcceptShortPacket, verifyAcceptShortPacket, OUTLength, OUTOffset, OUTExpectedActualLength, + OUTExpectedException, + INLength, INOffset, INExpectedActualLength, + INExpectedException, + transformType ); + + + }; + + // TODO Disabled because 64 byte packet size not supported by test firmware + public void disabled_testSingleIRP_BuffersNOTMultiplesOfMaxPacketSize_maxPacketSizeOf64bytes_buffer130bytes_passthrough() + { + byte testType = IOTests.IRP; + /* + * values from table + */ + int numberOfIrps = 1; + int endpointmaxPacketSize = 64; + byte []transformType = {IOTests.TRANSFORM_TYPE_PASSTHROUGH}; + + boolean[] IrpAcceptShortPacket = {true}; + boolean[] verifyAcceptShortPacket = {true}; + + + int []OUTLength = {130}; + int []OUTOffset = {0}; + int []OUTExpectedActualLength = {OUTLength[0]}; + Exception[] OUTExpectedException = {null}; + + int []INLength = {OUTLength[0]}; + int []INOffset = {OUTOffset[0]}; + int []INExpectedActualLength = {OUTLength[0]}; + Exception[] INExpectedException = {null}; + + IOTests thisIOTest = new IOTests(usbDevice, usbPipeListGlobal, endpointType, testType); + thisIOTest.RoundTripIOTest(testType, numberOfIrps, endpointmaxPacketSize, + IrpAcceptShortPacket, verifyAcceptShortPacket, OUTLength, OUTOffset, OUTExpectedActualLength, + OUTExpectedException, + INLength, INOffset, INExpectedActualLength, + INExpectedException, + transformType ); + + + }; + public void testIRPListBuffersMultiplesOfMaxPacketSizeOf8bytes() + { + + byte testType = IOTests.IRPLIST; + /* + * values from table + */ + int numberOfIrps = 3; + int endpointmaxPacketSize = 8; + byte []transformType = {IOTests.TRANSFORM_TYPE_INVERT_BITS, IOTests.TRANSFORM_TYPE_INVERT_ALTERNATE_BITS, + IOTests.TRANSFORM_TYPE_PASSTHROUGH}; + + boolean[] IrpAcceptShortPacket = {true, true, true}; + boolean[] verifyAcceptShortPacket = {true, true, true}; + + + int []OUTLength = {8,16, 24}; + int []OUTOffset = {0, 8, 24}; + int []OUTExpectedActualLength = {OUTLength[0], OUTLength[1], OUTLength[2]}; + Exception[] OUTExpectedException = {null, null, null}; + + int []INLength = {OUTLength[0], OUTLength[1], OUTLength[2]}; + int []INOffset = {OUTOffset[0], OUTOffset[1], OUTOffset[2]}; + int []INExpectedActualLength = {OUTLength[0],OUTLength[1], OUTLength[2]}; + Exception[] INExpectedException = {null, null, null}; + + IOTests thisIOTest = new IOTests(usbDevice, usbPipeListGlobal, endpointType, testType); + thisIOTest.RoundTripIOTest(testType, numberOfIrps, endpointmaxPacketSize, + IrpAcceptShortPacket, verifyAcceptShortPacket, OUTLength, OUTOffset, OUTExpectedActualLength, + OUTExpectedException, + INLength, INOffset, INExpectedActualLength, + INExpectedException, + transformType ); + + + }; + // TODO Disabled because 64 byte packet size not supported by test firmware + public void disabled_testIRPListBuffersNOTMultiplesOfMaxPacketSizeOf64bytes() + { + byte testType = IOTests.IRPLIST; + /* + * values from table + */ + int numberOfIrps = 3; + int endpointmaxPacketSize = 64; + byte []transformType = {IOTests.TRANSFORM_TYPE_INVERT_BITS, IOTests.TRANSFORM_TYPE_INVERT_ALTERNATE_BITS, + IOTests.TRANSFORM_TYPE_PASSTHROUGH}; + + boolean[] IrpAcceptShortPacket = {true, true, true}; + boolean[] verifyAcceptShortPacket = {true, true, true}; + + + int []OUTLength = {12, 75, 130}; + int []OUTOffset = {0, 12, 87}; + int []OUTExpectedActualLength = {OUTLength[0], OUTLength[1], OUTLength[2]}; + Exception[] OUTExpectedException = {null, null, null}; + + int []INLength = {OUTLength[0], OUTLength[1], OUTLength[2]}; + int []INOffset = {OUTOffset[0], OUTOffset[1], OUTOffset[2]}; + int []INExpectedActualLength = {OUTLength[0],OUTLength[1], OUTLength[2]}; + Exception[] INExpectedException = {null, null, null}; + + IOTests thisIOTest = new IOTests(usbDevice, usbPipeListGlobal, endpointType, testType); + thisIOTest.RoundTripIOTest(testType, numberOfIrps, endpointmaxPacketSize, + IrpAcceptShortPacket, verifyAcceptShortPacket, OUTLength, OUTOffset, OUTExpectedActualLength, + OUTExpectedException, + INLength, INOffset, INExpectedActualLength, + INExpectedException, + transformType ); + + }; + /** + * Constructor + */ + public BulkIOTests() + { + super(); + }; + + protected BulkIOTests(UsbDevice newUsbDevice, List newUsbPipeList, byte newEndpointType) + { + usbPipeListGlobal = newUsbPipeList; + usbDevice = newUsbDevice; + endpointType = newEndpointType; + }; + + + + private List usbPipeListGlobal = new ArrayList(); + private byte endpointType; + private UsbDevice usbDevice; + + + private static void printDebug(String infoString) + { + if ( printDebug ) + { + System.out.println(infoString); + } + } + private static boolean printDebug = false; + //private static boolean printDebug = true; +} diff --git a/src/test/java/javax/usb/tck/IOMethods.java b/src/test/java/javax/usb/tck/IOMethods.java new file mode 100755 index 0000000..9544045 --- /dev/null +++ b/src/test/java/javax/usb/tck/IOMethods.java @@ -0,0 +1,314 @@ +package javax.usb.tck; + +/** + * Copyright (c) 2004, International Business Machines Corporation. + * All Rights Reserved. + * + * This software is provided and licensed under the terms and conditions + * of the Common Public License: + * http://oss.software.ibm.com/developerworks/opensource/license-cpl.html + */ + +/* + * Change Activity: See below. + * + * FLAG REASON RELEASE DATE WHO DESCRIPTION + * ---- -------- -------- ------ -------- ------------------------------------ + * 0000 nnnnnnn yymmdd Initial Development + * $P1 tck.rel1 040804 raulortz Support for UsbDisconnectedException + * $P2 tck.rel1 040916 raulortz Redesign TCK to create base and optional + * tests. Separate setConfig, setInterface + * and isochronous transfers as optionals. + */ + +import junit.framework.Assert; + +import java.util.*; + +import javax.usb.*; +import javax.usb.util.*; + +/** + * IOMethods + *

+ * Helper functions for IO tests + * + * @author Leslie Blair + */ +@SuppressWarnings("all") +public class IOMethods +{ + protected static void claimInterface(UsbInterface usbInterface) + { + Assert.assertFalse("Interface already claimed.", usbInterface.isClaimed()); + try + { + usbInterface.claim(); + Assert.assertTrue("usbInterface.isClaimed() returns false after interface is claimed.", usbInterface.isClaimed()); + } catch ( UsbDisconnectedException uDE ) // @P1C + { // @P1A + Assert.fail ("A connected device should't throw the UsbDisconnectedException!"); // @P1A + } catch ( Exception e ) // @P1C + { + Assert.fail("Exception claiming interface. " + e.toString()); + } + + }; + protected static void releaseInterface(UsbInterface usbInterface) + { + Assert.assertTrue("Attempting to release an interface that is not claimed.", usbInterface.isClaimed()); + try + { + usbInterface.release(); + Assert.assertFalse("usbInterface.isClaimed() returns true after interface is released.", usbInterface.isClaimed()); + } catch ( UsbDisconnectedException uDE ) // @P1C + { // @P1A + Assert.fail ("A connected device should't throw the UsbDisconnectedException!"); // @P1A + } catch ( Exception e ) // @P1A + { + Assert.fail("Exception releasing interface. " + e.toString()); + } + + }; + + protected static void openPipe(UsbPipe usbPipe) + { + Assert.assertTrue("Can't open pipe if it is not active.",usbPipe.isActive()); + + Assert.assertFalse("Pipe already claimed.", usbPipe.isOpen()); + try + { + usbPipe.open(); + Assert.assertTrue("usbPipe.isOpen() returns false after pipe is opened.", usbPipe.isOpen()); + } catch ( UsbDisconnectedException uDE ) // @P1C + { // @P1A + Assert.fail ("A connected device should't throw the UsbDisconnectedException!"); // @P1A + } catch ( Exception e ) // @P1A + { + Assert.fail("Exception opening pipe. " + e.toString()); + } + + }; + protected static void closePipe(UsbPipe usbPipe) + { + Assert.assertTrue("Trying to close a pipe that is not open.", usbPipe.isOpen()); + try + { + usbPipe.close(); + Assert.assertFalse("usbPipe.isOpen() returns true after pipe is closed.", usbPipe.isOpen()); + } catch ( UsbDisconnectedException uDE ) // @P1C + { // @P1A + Assert.fail ("A connected device should't throw the UsbDisconnectedException!"); // @P1A + } catch ( Exception e ) // @P1C + { + Assert.fail("Exception closing pipe. " + e.toString()); + } + + }; + + + protected static void createListofAllAvailablePipesOfSpecifiedEndpointType(UsbDevice usbDevice, byte endpointType, List usbPipeList) + { + //The following are the expected configuration, interface, and alternate setting location of the following types of pipes + if ( (endpointType == UsbConst.ENDPOINT_TYPE_INTERRUPT) || (endpointType == UsbConst.ENDPOINT_TYPE_BULK) ) + { + byte configurationNumber = 1; + byte interfaceNumber = 0; + byte alternateSetting = 0; // Now end point is on AS 0 @P2A + createListofAllAvailablePipesOfSpecifiedEndpointType(usbDevice, endpointType, configurationNumber, + interfaceNumber, alternateSetting, usbPipeList); + } else if ( endpointType == UsbConst.ENDPOINT_TYPE_ISOCHRONOUS ) + { + byte configurationNumber = 1; + byte interfaceNumber = 0; + byte alternateSetting = 0; + createListofAllAvailablePipesOfSpecifiedEndpointType(usbDevice, endpointType, configurationNumber, + interfaceNumber, alternateSetting, usbPipeList); + } + + }; + + protected static void createListofAllAvailablePipesOfSpecifiedEndpointType(UsbDevice usbDevice, byte endpointType, byte configurationNumber, + byte interfaceNumber, byte alternateSetting, List usbPipeList ) + { + // @P2D + selectAlternateSetting(usbDevice, configurationNumber, interfaceNumber, alternateSetting); + + UsbConfiguration usbConfiguration = usbDevice.getUsbConfiguration(configurationNumber); + UsbInterface usbInterface = usbConfiguration.getUsbInterface(interfaceNumber); + + List endpointList = new ArrayList(); + List endpointListFromImplementation = null; + endpointListFromImplementation = usbInterface.getUsbEndpoints(); + for ( int i = 0; i< endpointListFromImplementation.size(); i++ ) + { + endpointList.add(endpointListFromImplementation.get(i)); + } + + //get rid of all the endpoints that are not of the desired type + int numInList = 0; + while ( numInList != endpointList.size() ) + { + if ( (((UsbEndpoint)endpointList.get(numInList)).getType()) != endpointType ) + { + //it's not the right endpoint type, so remove it from list + endpointList.remove(numInList); + } else + { + //point to next entry in list + numInList++; + } + } + + //get pipes for all the endpoints + for ( int i = 0; i < endpointList.size(); i++ ) + { + usbPipeList.add(((UsbEndpoint)endpointList.get(i)).getUsbPipe()); + } + }; + + /** + * select alternate setting for the programmable board (AS0 or AS1) + */ + protected static void selectAlternateSetting(UsbDevice usbDevice, + byte requiredUsbConfigurationNumber, + byte requiredInterfaceNumber, + byte desiredAlternateSetting) + { + try + { + if ( usbDevice.isConfigured() ) + { + if ( debug ) + System.out.println("Active ConfigurationNumber: " + usbDevice.getActiveUsbConfigurationNumber() ); + // @P2D6 + //get UsbConfiguraion + UsbConfiguration usbConfiguration = usbDevice.getActiveUsbConfiguration(); + + //getUsbInterface + UsbInterface usbInterface = usbConfiguration.getUsbInterface(requiredInterfaceNumber); + if ( debug ) + System.out.println("Select Alternate Setting 1"); + // claim the interface: the interface has to be claimed to select an alternate setting. + if (!usbInterface.isClaimed()) + claimInterface(usbInterface); + // @P2D + } + } catch ( Exception e ) + { + Assert.fail("Error setting alternate setting. " + e.toString()); + } + + }; + + protected static void releaseListOfPipes(List pipeList ) + { + //all pipes in list are expected to be on the same interface + UsbInterface usbInterface = ((UsbPipe)pipeList.get(0)).getUsbEndpoint().getUsbInterface(); + while ( pipeList.size() != 0 ) + { + //make sure all pipes are closed (needed for error conditions) + if ( ((UsbPipe) pipeList.get(0)).isOpen() == true ) + { + closePipe((UsbPipe) pipeList.get(0)); + } + pipeList.remove(0); + } + releaseInterface(usbInterface); + }; + + protected static void findINandOUTPipesForTest(List pipeList, int endpointSize, int[] pipeIndexes, + int inPipeArrayIndex, int outPipeArrayIndex) + { + int i; + int j; + + int inPipeListIndex = 0; + int outPipeListIndex = 0; + + Assert.assertFalse("There are no pipes in list.",(0 == pipeList.size())); + + boolean pipeIndexesFound = false; + + for ( i = 0; i< pipeList.size(); i++ ) + { + + UsbPipe usbPipe1 = (UsbPipe) pipeList.get(i); + if ( usbPipe1.getUsbEndpoint().getUsbEndpointDescriptor().wMaxPacketSize() == endpointSize ) + { + //it's the correct endpoint size, now get a matching pair + //For a pair to match, they must be an IN/OUT endpoint pair and their maxPacketSizes must be the same + byte endpointAddress1 = usbPipe1.getUsbEndpoint().getUsbEndpointDescriptor().bEndpointAddress(); + byte endpointAddress2; + if ( usbPipe1.getUsbEndpoint().getDirection() == UsbConst.ENDPOINT_DIRECTION_IN ) + { + endpointAddress2 = (byte)(endpointAddress1 & ~UsbConst.ENDPOINT_DIRECTION_MASK); + inPipeListIndex = i; + } else + { + endpointAddress2 = (byte) (endpointAddress1 | UsbConst.ENDPOINT_DIRECTION_MASK); + outPipeListIndex = i; + } + + //go through list looking for address 2 + for ( j = i+1; j< pipeList.size(); j++ ) + { + UsbPipe usbPipe2 = (UsbPipe) pipeList.get(j); + if ( (usbPipe2.getUsbEndpoint().getUsbEndpointDescriptor().bEndpointAddress() == endpointAddress2) + && (usbPipe2.getUsbEndpoint().getUsbEndpointDescriptor().wMaxPacketSize() == endpointSize) + ) + { + //a pair of endpoints has been found + if ( usbPipe2.getUsbEndpoint().getDirection() == UsbConst.ENDPOINT_DIRECTION_IN ) + { + inPipeListIndex = j; + } else + { + outPipeListIndex = j; + } + pipeIndexesFound = true; + break; //break out of inner loop as a pair has been found + } + + } + } + + if ( pipeIndexesFound ) + { + pipeIndexes[inPipeArrayIndex] = inPipeListIndex; + pipeIndexes[outPipeArrayIndex] = outPipeListIndex; + break; + } + + } + + }; + protected static void verifyThePipes(UsbPipe inPipe, UsbPipe outPipe, int endpointSize) + { + Assert.assertNotNull("IN pipe should not be null.", inPipe); + Assert.assertNotNull("OUT pipe should not be null.",outPipe); + Assert.assertTrue("These pipes are not from matchine endpoint pairs.", + ((inPipe.getUsbEndpoint().getUsbEndpointDescriptor().bEndpointAddress()) - UsbConst.ENDPOINT_DIRECTION_MASK) + == (outPipe.getUsbEndpoint().getUsbEndpointDescriptor().bEndpointAddress())); + Assert.assertEquals("The IN pipe does not have the correct maxPacketSize.", + endpointSize,inPipe.getUsbEndpoint().getUsbEndpointDescriptor().wMaxPacketSize()); + Assert.assertEquals("The OUT pipe does not have the correct maxPacketSize.", + endpointSize,outPipe.getUsbEndpoint().getUsbEndpointDescriptor().wMaxPacketSize()); + + }; + + /** + * printDebug method will print the specified string if "debug" is true. + * Useful function for debugging + * @param infoString + */ + protected static void printDebug(String infoString) + { + if ( debug ) + { + System.out.println(infoString); + } + } + private static boolean debug = false; + //private static boolean debug = true; +} diff --git a/src/test/java/javax/usb/tck/IOTests.java b/src/test/java/javax/usb/tck/IOTests.java new file mode 100755 index 0000000..e1da886 --- /dev/null +++ b/src/test/java/javax/usb/tck/IOTests.java @@ -0,0 +1,689 @@ +/** + * Copyright (c) 2004, International Business Machines Corporation. + * All Rights Reserved. + * + * This software is provided and licensed under the terms and conditions + * of the Common Public License: + * http://oss.software.ibm.com/developerworks/opensource/license-cpl.html + */ + +/* + * Change Activity: See below. + * + * FLAG REASON RELEASE DATE WHO DESCRIPTION + * ---- -------- -------- ------ ------- ------------------------------------ + * 0000 nnnnnnn yymmdd Initial Development + * $P1 tck.rel1 040804 raulortz Support for UsbDisconnectedException + */ + +package javax.usb.tck; + +import java.util.*; + +import javax.usb.*; +import javax.usb.event.*; +import javax.usb.util.*; + + +import junit.framework.Assert; + +/** + * IOTests -- Helper methods for Bulk, Interrupt, and Isochronous IO Tests + *

+ * The goal of the Bulk, Interrupt, and Isochronous IO test is to + * verify that IN and OUT pipes can be opened and closed, and verify + * that bulk, interrupt, and isochronous transfer operations work successfully, proper + * events are generated, and proper exceptions are thrown in the operation. + * + * @author Leslie Blair + */ + + +@SuppressWarnings("all") +public class IOTests +{ + + + + + protected void RoundTripIOTest(byte testType, int numIrps, int endpointmaxPacketSize, + boolean []acceptShortPacket, boolean []verifyAcceptShortPacket, + int[] OUTLength, int[] OUTOffset, int[] OUTExpectedLength, + Exception []OUTexpectedException, + + int[] INLength, int[]INOffset, int[]INExpectedLength, + Exception []INexpectedException, + byte [] transformType + ) + + { + + //ensure all values set up + Assert.assertEquals(numIrps,transformType.length); + Assert.assertEquals(numIrps,OUTLength.length); + Assert.assertEquals(numIrps,OUTOffset.length); + Assert.assertEquals(numIrps,acceptShortPacket.length); + Assert.assertEquals(numIrps,verifyAcceptShortPacket.length); + Assert.assertEquals(numIrps,OUTExpectedLength.length); + Assert.assertEquals(numIrps,OUTexpectedException.length); + Assert.assertEquals(numIrps,INLength.length); + Assert.assertEquals(numIrps,INOffset.length); + Assert.assertEquals(numIrps,INExpectedLength.length); + Assert.assertEquals(numIrps,INexpectedException.length); + + Assert.assertNotNull("usbDevice is null, but should not be null.", usbDevice); + + + /* + * set up Pipes and add listeners + */ + UsbPipe inPipe = null; + UsbPipe outPipe = null; + + //we need two int values back from method call so we'll put them in the array + int [] pipeListIndexes = new int[2]; + int inPipeArrayIndex = 0; + int outPipeArrayIndex = 1; + + IOMethods.findINandOUTPipesForTest(usbPipeListGlobal, endpointmaxPacketSize, pipeListIndexes, inPipeArrayIndex, outPipeArrayIndex); + inPipe = (UsbPipe) usbPipeListGlobal.get(pipeListIndexes[inPipeArrayIndex]); + outPipe = (UsbPipe) usbPipeListGlobal.get(pipeListIndexes[outPipeArrayIndex]); + IOMethods.verifyThePipes(inPipe, outPipe, endpointmaxPacketSize); + + inPipe.addUsbPipeListener(inPipeListener); + outPipe.addUsbPipeListener(outPipeListener); + + IOMethods.openPipe(inPipe); + IOMethods.openPipe(outPipe); + + if ( (inPipe instanceof UsbUtil.SynchronizedUsbPipe) && (outPipe instanceof UsbUtil.SynchronizedUsbPipe) ) + printDebug("SynchronizedUsbPipes under test."); + + /* + * set up the IRPs or byte arrays and send and verify the data + */ + for ( int iterations=0; (iterations < totalIterations); iterations++ ) + { + for ( int syncOrAsync=0; syncOrAsync standardISOINBufferLength ) + { + standardISOINBufferLength = INLength[l]; + } + } + //now that the largest has been found, set the length for each in IRP to the new length + for ( int l = 0; l=0; i-- ) + { + //all of the IRPs in which we are interested SHOULD have a non zero length + //amount of data returned. + //Once the zero length data IRP events are removed, only the IRP events that received the + //expected OUT data should be left in the list + + Assert.assertTrue("There should be no error events in the list.",((UsbPipeEvent) listOfPipeEvents.get(i)).getClass() == UsbPipeDataEvent.class); + if ( ((UsbPipeDataEvent) listOfPipeEvents.get(i)).getUsbIrp().getActualLength() == 0 ) + { + listOfPipeEvents.remove(i); + Assert.assertEquals("Original Irps and pipe event Irps should be zero actual length in the same position in the list.",0,((UsbIrp) listOfIrps.get(i)).getActualLength()); + listOfIrps.remove(i); + } + else + { + Assert.assertEquals("Original Irps and pipe event Irps actual length should be the same at the same position in the list.", + ((UsbPipeDataEvent) listOfPipeEvents.get(i)).getUsbIrp().getActualLength(), + ((UsbIrp) listOfIrps.get(i)).getActualLength()); + printDebug("Non-zero actual length pipe event found at index " + i); + } + } + Assert.assertFalse("None of the Isochronous IN IRPs received any data",0 == listOfPipeEvents.size()); + }; + + + + + //------------------------------------------------------------------------- + // Instance variables + // + + private UsbPipeListener inPipeListener = new UsbPipeListener() + { + public void dataEventOccurred(UsbPipeDataEvent updE) + { + Assert.assertNotNull(updE); + inPipeEvents.add(updE); + } + + public void errorEventOccurred(UsbPipeErrorEvent upeE) + { + Assert.assertNotNull(upeE); + //inPipeEvents.add(upeE); + Assert.fail("No IN pipe error events expected during this test. Exception is " + upeE.getUsbException().getMessage()); + } + }; + + private UsbPipeListener outPipeListener = new UsbPipeListener() + { + public void dataEventOccurred(UsbPipeDataEvent updE) + { + Assert.assertNotNull(updE); + outPipeEvents.add(updE); + } + + public void errorEventOccurred(UsbPipeErrorEvent upeE) + { + Assert.assertNotNull(upeE); + //outPipeEvents.add(upeE); + Assert.fail("No OUT pipe error events expected during this test. Exception is " + upeE.getUsbException().getMessage()); + } + }; + + /** + * Constructor + */ + public IOTests() + { + super(); + }; + + protected IOTests(UsbDevice newUsbDevice, List newUsbPipeList, byte newEndpointType, byte newTestType) + { + usbPipeListGlobal = newUsbPipeList; + usbDevice = newUsbDevice; + endpointType = newEndpointType; + testType = newTestType; + }; + + private List inPipeEvents = new ArrayList(); + private List outPipeEvents = new ArrayList(); + + private List usbPipeListGlobal = new ArrayList(); + + private byte endpointType; + private static final int MAX_SIZE_IRP_BUFFER = 750; + + + protected static final byte TRANSFORM_TYPE_PASSTHROUGH = (byte)0x01; + protected static final byte TRANSFORM_TYPE_INVERT_BITS = (byte)0x02; + protected static final byte TRANSFORM_TYPE_INVERT_ALTERNATE_BITS = (byte)0x03; + + private UsbDevice usbDevice; + private int totalIterations = 10; + //private int totalIterations = 1; + private static final boolean SYNC_SUBMIT = true; + private static final boolean ASYNC_SUBMIT = false; + private static final boolean [] transmitList= {SYNC_SUBMIT, ASYNC_SUBMIT}; + private static final String [] transmitListStrings = {"SYNC","ASYNC"}; + protected static final byte BYTE_ARRAY = 0; + protected static final byte IRP = 1; + protected static final byte IRPLIST = 2; + private static final String [] endpointTypeStrings = {"CONTROL","ISOCHRONOUS", "BULK", "INTERRUPT"}; + byte testType; + + protected static void printDebug(String infoString) + { + if ( printDebug ) + { + System.out.println(infoString); + } + } + private static boolean printDebug = false; + //private static boolean printDebug = true; +}