Exemple #1
0
    def __write_read(self, write_fn, read_fn, ep):
        for data in (utils.get_array_data1(), utils.get_array_data2()):
            length = len(data) * data.itemsize

            try:
                ret = write_fn(ep, data, 1000)
            except NotImplementedError:
                return

            self.assertEqual(ret,
                             length,
                             'Failed to write data: ' + \
                                str(data) + \
                                ', in EP = ' + \
                                str(ep))

            try:
                ret = read_fn(ep | usb.util.ENDPOINT_IN, length, 1000)
            except NotImplementedError:
                return

            self.assertEqual(ret,
                             data,
                             'Failed to read data: ' + \
                                str(data) + \
                                ', in EP = ' + \
                                str(ep))
Exemple #2
0
    def __write_read(self, write_fn, read_fn, ep):
        intf = self.backend.get_interface_descriptor(self.dev, 0, 0, 0).bInterfaceNumber
        for data in (utils.get_array_data1(), utils.get_array_data2()):
            length = len(data) * data.itemsize

            try:
                ret = write_fn(self.handle, ep, intf, data, 1000)
            except NotImplementedError:
                return

            self.assertEqual(ret,
                             length,
                             'Failed to write data: ' + \
                                str(data) + \
                                ', in EP = ' + \
                                str(ep))

            try:
                ret = read_fn(self.handle, ep | usb.util.ENDPOINT_IN, intf, length, 1000)
            except NotImplementedError:
                return

            self.assertEqual(ret,
                             data,
                             'Failed to read data: ' + \
                                str(data) + \
                                ', in EP = ' + \
                                str(ep))
Exemple #3
0
def make_data_list(length = 8):
    return (utils.get_array_data1(length),
            utils.get_array_data2(length),
            utils.get_list_data1(length),
            utils.get_list_data2(length),
            utils.get_str_data1(length),
            utils.get_str_data1(length))
Exemple #4
0
    def __write_read(self, write_fn, read_fn, ep):
        for data in (utils.get_array_data1(), utils.get_array_data2()):
            length = len(data) * data.itemsize

            try:
                ret = write_fn(ep, data, 1000)
            except NotImplementedError:
                return

            self.assertEqual(ret,
                             length,
                             'Failed to write data: ' + \
                                str(data) + \
                                ', in EP = ' + \
                                str(ep))

            try:
                ret = read_fn(ep | usb.util.ENDPOINT_IN, length, 1000)
            except NotImplementedError:
                return

            self.assertEqual(ret,
                             data,
                             'Failed to read data: ' + \
                                str(data) + \
                                ', in EP = ' + \
                                str(ep))
Exemple #5
0
    def test_ctrl_transfer(self):
        for data in (utils.get_array_data1(), utils.get_array_data2()):
            length = len(data) * data.itemsize
            buff = usb.util.create_buffer(length)

            ret = self.backend.ctrl_transfer(self.handle,
                                             0x40,
                                             devinfo.PICFW_SET_VENDOR_BUFFER,
                                             0,
                                             0,
                                             data,
                                             1000)
            self.assertEqual(ret,
                             length,
                             'Failed to write data: ' + str(data) + ', ' + str(length) + ' != ' + str(ret))

            ret = self.backend.ctrl_transfer(self.handle,
                                             0xC0,
                                             devinfo.PICFW_GET_VENDOR_BUFFER,
                                             0,
                                             0,
                                             buff,
                                             1000)

            self.assertEqual(ret, length)

            self.assertEqual(buff,
                             data,
                             'Failed to read data: ' + str(data) + ' != ' + str(ret))
Exemple #6
0
    def test_ctrl_transfer(self):
        for data in (utils.get_array_data1(), utils.get_array_data2()):
            length = len(data) * data.itemsize

            ret = self.handle.controlMsg(
                             0x40,
                             devinfo.PICFW_SET_VENDOR_BUFFER,
                             data,
                             0,
                             0,
                             1000)

            self.assertEqual(ret,
                             length,
                             'Failed to write data: ' + str(data) + ', ' + str(length) + ' != ' + str(ret))

            ret = self.handle.controlMsg(
                             0xC0,
                             devinfo.PICFW_GET_VENDOR_BUFFER,
                             length,
                             0,
                             0,
                             1000)

            self.assertEqual(ret,
                             data,
                             'Failed to read data: ' + str(data) + ' != ' + str(ret))
Exemple #7
0
    def __write_read(self, write_fn, read_fn, ep, length = 8):
        intf = self.backend.get_interface_descriptor(self.dev, 0, 0, 0).bInterfaceNumber
        for data in (utils.get_array_data1(length), utils.get_array_data2(length)):
            length = len(data) * data.itemsize

            try:
                ret = write_fn(self.handle, ep, intf, data, 1000)
            except NotImplementedError:
                return

            self.assertEqual(ret,
                             length,
                             'Failed to write data: ' + \
                                str(data) + \
                                ', in EP = ' + \
                                str(ep))

            buff = usb.util.create_buffer(length)

            try:
                ret = read_fn(self.handle, ep | usb.util.ENDPOINT_IN, intf, buff, 1000)
            except NotImplementedError:
                return

            self.assertEqual(ret, length, str(ret) + ' != ' + str(length))

            self.assertEqual(buff,
                             data,
                             'Failed to read data: ' + \
                                str(data) + \
                                ', in EP = ' + \
                                str(ep))

            if utils.is_windows():
                time.sleep(0.5)
Exemple #8
0
def make_data_list(length = 8):
    return (utils.get_array_data1(length),
            utils.get_array_data2(length),
            utils.get_list_data1(length),
            utils.get_list_data2(length),
            utils.get_str_data1(length),
            utils.get_str_data1(length))
Exemple #9
0
    def test_ctrl_transfer(self):
        for data in (utils.get_array_data1(), utils.get_array_data2()):
            length = len(data) * data.itemsize

            ret = self.handle.controlMsg(
                             0x40,
                             devinfo.PICFW_SET_VENDOR_BUFFER,
                             data,
                             0,
                             0,
                             1000)

            self.assertEqual(ret,
                             length,
                             'Failed to write data: ' + str(data) + ', ' + str(length) + ' != ' + str(ret))

            ret = self.handle.controlMsg(
                             0xC0,
                             devinfo.PICFW_GET_VENDOR_BUFFER,
                             length,
                             0,
                             0,
                             1000)

            self.assertEqual(ret,
                             data,
                             'Failed to read data: ' + str(data) + ' != ' + str(ret))
Exemple #10
0
    def __write_read(self, write_fn, read_fn, ep):
        intf = self.backend.get_interface_descriptor(self.dev, 0, 0,
                                                     0).bInterfaceNumber
        for data in (utils.get_array_data1(), utils.get_array_data2()):
            length = len(data) * data.itemsize

            try:
                ret = write_fn(self.handle, ep, intf, data, 1000)
            except NotImplementedError:
                return

            self.assertEqual(ret,
                             length,
                             'Failed to write data: ' + \
                                str(data) + \
                                ', in EP = ' + \
                                str(ep))

            try:
                ret = read_fn(self.handle, ep | usb.util.ENDPOINT_IN, intf,
                              length, 1000)
            except NotImplementedError:
                return

            self.assertEqual(ret,
                             data,
                             'Failed to read data: ' + \
                                str(data) + \
                                ', in EP = ' + \
                                str(ep))
Exemple #11
0
 def test_ctrl_transfer(self):
     for data in (utils.get_array_data1(), utils.get_array_data2()):
         length = len(data) * data.itemsize
         ret = self.backend.ctrl_transfer(self.handle, 0x40,
                                          devinfo.CTRL_LOOPBACK_WRITE, 0, 0,
                                          data, 1000)
         self.assertEqual(ret, length, 'Failed to write data: ' + str(data))
         ret = self.backend.ctrl_transfer(self.handle, 0xC0,
                                          devinfo.CTRL_LOOPBACK_READ, 0, 0,
                                          length, 1000)
         self.assertEqual(
             ret, data,
             'Failed to read data: ' + str(data) + ' != ' + str(ret))
Exemple #12
0
 def __write_read(self, write_fn, read_fn, ep_out, ep_in):
     intf = self.backend.get_interface_descriptor(self.dev, 0, 0, 0).bInterfaceNumber
     for data in (utils.get_array_data1(), utils.get_array_data2()):
         ret = write_fn(self.handle, ep_out, intf, data, 1000)
         self.assertEqual(ret,
                          len(data),
                          'Failed to write data: ' + \
                             str(data) + \
                             ', in EP = ' + \
                             str(ep_out))
         ret = read_fn(self.handle, ep_in, intf, len(data), 1000)
         self.assertEqual(ret,
                          data,
                          'Failed to read data: ' + \
                             str(data) + \
                             ', in EP = ' + \
                             str(ep_in))
 def __write_read(self, write_fn, read_fn, ep_out, ep_in):
     intf = self.backend.get_interface_descriptor(self.dev, 0, 0, 0).bInterfaceNumber
     for data in (utils.get_array_data1(), utils.get_array_data2()):
         ret = write_fn(self.handle, ep_out, intf, data, 1000)
         self.assertEqual(ret,
                          len(data),
                          'Failed to write data: ' + \
                             str(data) + \
                             ', in EP = ' + \
                             str(ep_out))
         ret = read_fn(self.handle, ep_in, intf, len(data), 1000)
         self.assertEqual(ret,
                          data,
                          'Failed to read data: ' + \
                             str(data) + \
                             ', in EP = ' + \
                             str(ep_in))
Exemple #14
0
    def test_ctrl_transfer(self):
        for data in (utils.get_array_data1(), utils.get_array_data2()):
            length = len(data) * data.itemsize
            buff = usb.util.create_buffer(length)

            ret = self.backend.ctrl_transfer(self.handle, 0x40,
                                             devinfo.PICFW_SET_VENDOR_BUFFER,
                                             0, 0, data, 1000)
            self.assertEqual(
                ret, length, 'Failed to write data: ' + str(data) + ', ' +
                str(length) + ' != ' + str(ret))

            ret = self.backend.ctrl_transfer(self.handle, 0xC0,
                                             devinfo.PICFW_GET_VENDOR_BUFFER,
                                             0, 0, buff, 1000)

            self.assertEqual(ret, length)

            self.assertEqual(
                buff, data,
                'Failed to read data: ' + str(data) + ' != ' + str(ret))
 def test_ctrl_transfer(self):
     for data in (utils.get_array_data1(), utils.get_array_data2()):
         ret = self.backend.ctrl_transfer(self.handle,
                                          0x40,
                                          devinfo.CTRL_LOOPBACK_WRITE,
                                          0,
                                          0,
                                          data,
                                          1000)
         self.assertEqual(ret,
                          len(data),
                          'Failed to write data: ' + str(data))
         ret = self.backend.ctrl_transfer(self.handle,
                                          0xC0,
                                          devinfo.CTRL_LOOPBACK_READ,
                                          0,
                                          0,
                                          len(data),
                                          1000)
         self.assertEqual(ret,
                          data,
                          'Failed to read data: ' + str(data))
Exemple #16
0
    def __write_read(self, write_fn, read_fn, ep, length=8):
        intf = self.backend.get_interface_descriptor(self.dev, 0, 0,
                                                     0).bInterfaceNumber
        for data in (utils.get_array_data1(length),
                     utils.get_array_data2(length)):
            length = len(data) * data.itemsize

            try:
                ret = write_fn(self.handle, ep, intf, data, 1000)
            except NotImplementedError:
                return

            self.assertEqual(ret,
                             length,
                             'Failed to write data: ' + \
                                str(data) + \
                                ', in EP = ' + \
                                str(ep))

            buff = usb.util.create_buffer(length)

            try:
                ret = read_fn(self.handle, ep | usb.util.ENDPOINT_IN, intf,
                              buff, 1000)
            except NotImplementedError:
                return

            self.assertEqual(ret, length, str(ret) + ' != ' + str(length))

            self.assertEqual(buff,
                             data,
                             'Failed to read data: ' + \
                                str(data) + \
                                ', in EP = ' + \
                                str(ep))

            if utils.is_windows():
                time.sleep(0.5)
Exemple #17
0
# NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
# MODIFICATIONS.

# Integration tests

import utils
import unittest
import usb.core
import devinfo
import usb._interop
import usb.util
import usb.backend.libusb0 as libusb0
import usb.backend.libusb1 as libusb1
import usb.backend.openusb as openusb

data_list = (utils.get_array_data1(), utils.get_array_data2(),
             utils.get_list_data1(), utils.get_list_data2(),
             utils.get_str_data1(), utils.get_str_data1())


class DeviceTest(unittest.TestCase):
    def __init__(self, dev):
        unittest.TestCase.__init__(self)
        self.dev = dev

    def runTest(self):
        try:
            self.test_attributes()
            self.test_timeout()
            self.test_set_configuration()
            self.test_set_interface_altsetting()
Exemple #18
0
# NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
# MODIFICATIONS.

# Integration tests

import utils
import unittest
import usb.core
import devinfo
import usb.util
import usb.backend.libusb01 as libusb01
import usb.backend.libusb10 as libusb10
import usb.backend.openusb as openusb

data_list = (utils.get_array_data1(),
             utils.get_array_data2(),
             utils.get_list_data1(),
             utils.get_list_data2(),
             utils.get_str_data1(),
             utils.get_str_data1())

class DeviceTest(unittest.TestCase):
    def __init__(self, dev):
        unittest.TestCase.__init__(self)
        self.dev = dev

    def runTest(self):
        try:
            self.test_attributes()
            self.test_timeout()
            self.test_set_configuration()
Exemple #19
0
# MODIFICATIONS.

# Integration tests

import utils
import unittest
import usb.core
import devinfo
import usb._interop
import usb.util
import usb.backend.libusb0 as libusb0
import usb.backend.libusb1 as libusb1
import usb.backend.openusb as openusb

data_list = (utils.get_array_data1(),
             utils.get_array_data2(),
             utils.get_list_data1(),
             utils.get_list_data2(),
             utils.get_str_data1(),
             utils.get_str_data1())

class DeviceTest(unittest.TestCase):
    def __init__(self, dev):
        unittest.TestCase.__init__(self)
        self.dev = dev

    def runTest(self):
        try:
            self.test_attributes()
            self.test_timeout()
            self.test_set_configuration()