def test_write_read(self): altsettings = (devinfo.INTF_BULK, devinfo.INTF_INTR, devinfo.INTF_ISO) eps = (devinfo.EP_BULK, devinfo.EP_INTR, devinfo.EP_ISO) for alt in altsettings: self.dev.set_interface_altsetting(0, alt) for data in data_list: adata = utils.to_array(data) length = utils.data_len(data) try: ret = self.dev.write(eps[alt], data) except NotImplementedError: continue self.assertEqual(ret, length, 'Failed to write data: ' + \ str(data) + ', in interface = ' + \ str(alt) ) try: ret = self.dev.read(eps[alt] | usb.util.ENDPOINT_IN, length) except NotImplementedError: continue self.assertTrue(utils.array_equals(ret, adata), str(ret) + ' != ' + \ str(adata) + ', in interface = ' + \ str(alt) )
def test_ctrl_transfer(self): for data in make_data_list(): length = utils.data_len(data) adata = utils.to_array(data) ret = self.dev.ctrl_transfer(0x40, devinfo.PICFW_SET_VENDOR_BUFFER, 0, 0, data) self.assertEqual(ret, length, 'Failed to write data: ' + str(data)) ret = utils.to_array( self.dev.ctrl_transfer(0xC0, devinfo.PICFW_GET_VENDOR_BUFFER, 0, 0, length)) self.assertTrue(utils.array_equals(ret, adata), str(ret) + ' != ' + str(adata)) buff = usb.util.create_buffer(length) ret = self.dev.ctrl_transfer(0x40, devinfo.PICFW_SET_VENDOR_BUFFER, 0, 0, data) self.assertEqual(ret, length, 'Failed to write data: ' + str(data)) ret = self.dev.ctrl_transfer(0xC0, devinfo.PICFW_GET_VENDOR_BUFFER, 0, 0, buff) self.assertEqual(ret, length) self.assertTrue(utils.array_equals(buff, adata), str(buff) + ' != ' + str(adata))
def test_write_read(self): for data in data_list: adata = utils.to_array(data) ret = self.ep_out.write(data) length = utils.data_len(data) self.assertEqual(ret, length, 'Failed to write data: ' + str(data)) ret = self.ep_in.read(length) self.assertTrue(utils.array_equals(ret, adata), str(ret) + ' != ' + str(adata))
def test_write_read(self): self.dev.set_interface_altsetting(0, 0) for data in data_list: adata = utils.to_array(data) ret = self.ep_out.write(data) length = utils.data_len(data) self.assertEqual(ret, length, 'Failed to write data: ' + str(data)) ret = self.ep_in.read(length) self.assertTrue(utils.array_equals(ret, adata), str(ret) + ' != ' + str(adata))
def test_ctrl_transfer(self): for data in data_list: length = utils.data_len(data) adata = utils.to_array(data) ret = self.dev.ctrl_transfer(0x40, devinfo.CTRL_LOOPBACK_WRITE, 0, 0, data) self.assertEqual(ret, length, 'Failed to write data: ' + str(data)) ret = utils.to_array( self.dev.ctrl_transfer(0xC0, devinfo.CTRL_LOOPBACK_READ, 0, 0, length)) self.assertTrue(utils.array_equals(ret, adata), str(ret) + ' != ' + str(adata))
def test_ctrl_transfer(self): for data in data_list: length = utils.data_len(data) adata = utils.to_array(data) ret = self.dev.ctrl_transfer( 0x40, devinfo.PICFW_SET_VENDOR_BUFFER, 0, 0, data) self.assertEqual(ret, length, 'Failed to write data: ' + str(data)) ret = utils.to_array(self.dev.ctrl_transfer( 0xC0, devinfo.PICFW_GET_VENDOR_BUFFER, 0, 0, length)) self.assertTrue(utils.array_equals(ret, adata), str(ret) + ' != ' + str(adata)) buff = usb.util.create_buffer(length) ret = self.dev.ctrl_transfer( 0x40, devinfo.PICFW_SET_VENDOR_BUFFER, 0, 0, data) self.assertEqual(ret, length, 'Failed to write data: ' + str(data)) ret = self.dev.ctrl_transfer( 0xC0, devinfo.PICFW_GET_VENDOR_BUFFER, 0, 0, buff) self.assertEqual(ret, length) self.assertTrue(utils.array_equals(buff, adata), str(buff) + ' != ' + str(adata))
def test_write_read(self): self.dev.set_interface_altsetting(0, 0) for data in data_list: adata = utils.to_array(data) length = utils.data_len(data) buff = usb.util.create_buffer(length) ret = self.ep_out.write(data) self.assertEqual(ret, length, 'Failed to write data: ' + str(data)) ret = self.ep_in.read(length) self.assertTrue(utils.array_equals(ret, adata), str(ret) + ' != ' + str(adata)) ret = self.ep_out.write(data) self.assertEqual(ret, length, 'Failed to write data: ' + str(data)) ret = self.ep_in.read(buff) self.assertEqual(ret, length) self.assertTrue(utils.array_equals(buff, adata), str(buff) + ' != ' + str(adata))
def test_write_read(self): ep_list = ((devinfo.EP_BULK_OUT, devinfo.EP_BULK_IN), (devinfo.EP_INTR_OUT, devinfo.EP_INTR_IN)) for ep in ep_list: for data in data_list: adata = utils.to_array(data) length = utils.data_len(data) ret = self.dev.write(ep[0], data) self.assertEqual(ret, length, 'Failed to write data: ' + \ str(data) + ', in EP = ' + \ str(ep[0]) ) ret = self.dev.read(ep[1], length) self.assertTrue(utils.array_equals(ret, adata), str(ret) + ' != ' + \ str(adata) + ', in EP = ' + \ str(ep[1]) )
def test_write_read(self): altsettings = (0, 1) for alt in altsettings: self.dev.set_interface_altsetting(0, alt) for data in data_list: adata = utils.to_array(data) length = utils.data_len(data) ret = self.dev.write(0x01, data) self.assertEqual(ret, length, 'Failed to write data: ' + \ str(data) + ', in interface = ' + \ str(alt) ) ret = self.dev.read(0x81, length) self.assertTrue(utils.array_equals(ret, adata), str(ret) + ' != ' + \ str(adata) + ', in interface = ' + \ str(alt) )
def test_ctrl_transfer(self): for data in data_list: length = utils.data_len(data) adata = utils.to_array(data) ret = self.dev.ctrl_transfer( 0x40, devinfo.CTRL_LOOPBACK_WRITE, 0, 0, data ) self.assertEqual(ret, length, 'Failed to write data: ' + str(data)) ret = utils.to_array(self.dev.ctrl_transfer( 0xC0, devinfo.CTRL_LOOPBACK_READ, 0, 0, length )) self.assertTrue(utils.array_equals(ret, adata), str(ret) + ' != ' + str(adata))
def test_write_read(self): altsettings = [devinfo.INTF_BULK, devinfo.INTF_INTR] eps = [devinfo.EP_BULK, devinfo.EP_INTR] data_len = [8, 8] if utils.is_iso_test_allowed(): altsettings.append(devinfo.INTF_ISO) eps.append(devinfo.EP_ISO) data_len.append(64) def delay(alt): # Hack to avoid two consecutive isochronous transfers to fail if alt == devinfo.INTF_ISO and utils.is_windows(): time.sleep(0.5) for alt, length in zip(altsettings, data_len): self.dev.set_interface_altsetting(0, alt) for data in make_data_list(length): adata = utils.to_array(data) length = utils.data_len(data) buff = usb.util.create_buffer(length) try: ret = self.dev.write(eps[alt], data) except NotImplementedError: continue self.assertEqual(ret, length) self.assertEqual( ret, length, 'Failed to write data: ' + \ str(data) + ', in interface = ' + \ str(alt)) try: ret = self.dev.read(eps[alt] | usb.util.ENDPOINT_IN, length) except NotImplementedError: continue self.assertTrue( utils.array_equals(ret, adata), str(ret) + ' != ' + \ str(adata) + ', in interface = ' + \ str(alt)) delay(alt) try: ret = self.dev.write(eps[alt], data) except NotImplementedError: continue self.assertEqual(ret, length) self.assertEqual( ret, length, 'Failed to write data: ' + \ str(data) + ', in interface = ' + \ str(alt)) try: ret = self.dev.read(eps[alt] | usb.util.ENDPOINT_IN, buff) except NotImplementedError: continue self.assertEqual(ret, length) self.assertTrue( utils.array_equals(buff, adata), str(buff) + ' != ' + \ str(adata) + ', in interface = ' + \ str(alt)) delay(alt)