mirror of https://github.com/ARMmbed/mbed-os.git
Tests: USBHID: Use libusb0 backend on Windows
libusb0 supports all features used for testing. A newer version (libusb1) does not have a complete implementation for Windows.pull/11696/head
parent
7aeb5c97dd
commit
2c2a91ce87
|
@ -19,6 +19,7 @@ import functools
|
||||||
import time
|
import time
|
||||||
import threading
|
import threading
|
||||||
import uuid
|
import uuid
|
||||||
|
import sys
|
||||||
import mbed_host_tests
|
import mbed_host_tests
|
||||||
import usb.core
|
import usb.core
|
||||||
from usb.util import (
|
from usb.util import (
|
||||||
|
@ -31,6 +32,15 @@ from usb.util import (
|
||||||
DESC_TYPE_CONFIG,
|
DESC_TYPE_CONFIG,
|
||||||
build_request_type)
|
build_request_type)
|
||||||
|
|
||||||
|
if sys.platform.startswith('win'):
|
||||||
|
# Use libusb0 on Windows. libusb1 implementation for Windows
|
||||||
|
# does not support all features necessary for testing.
|
||||||
|
import usb.backend.libusb0
|
||||||
|
USB_BACKEND = usb.backend.libusb0.get_backend()
|
||||||
|
else:
|
||||||
|
# Use a default backend on other platforms.
|
||||||
|
USB_BACKEND = None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import hid
|
import hid
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
@ -232,7 +242,7 @@ class USBHIDTest(mbed_host_tests.BaseHostTest):
|
||||||
during test suite setup.
|
during test suite setup.
|
||||||
Raises RuntimeError if the device is not found.
|
Raises RuntimeError if the device is not found.
|
||||||
"""
|
"""
|
||||||
usb_dev = usb.core.find(custom_match=lambda d: d.serial_number == usb_id_str)
|
usb_dev = usb.core.find(custom_match=lambda d: d.serial_number == usb_id_str, backend=USB_BACKEND)
|
||||||
if usb_dev is None:
|
if usb_dev is None:
|
||||||
err_msg = 'USB device (SN={}) not found.'
|
err_msg = 'USB device (SN={}) not found.'
|
||||||
raise RuntimeError(err_msg.format(usb_id_str))
|
raise RuntimeError(err_msg.format(usb_id_str))
|
||||||
|
|
Loading…
Reference in New Issue