From db2995052f107987b6ac7f83cef4c09da667b26d Mon Sep 17 00:00:00 2001 From: Filip Jagodzinski Date: Tue, 10 Sep 2019 17:37:13 +0200 Subject: [PATCH 1/2] Tests: USB: Use libusb0 backend on Windows libusb0 supports all features used for testing. A newer version (libusb1) does not have a complete implementation for Windows. --- TESTS/host_tests/pyusb_basic.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/TESTS/host_tests/pyusb_basic.py b/TESTS/host_tests/pyusb_basic.py index 2f39678fe29..54ecc265e4a 100644 --- a/TESTS/host_tests/pyusb_basic.py +++ b/TESTS/host_tests/pyusb_basic.py @@ -38,6 +38,14 @@ import struct +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 def get_interface(dev, interface, alternate=0): intf = None @@ -314,11 +322,10 @@ def _callback_reset_support(self, key, value, timestamp): def find_device(self, serial_number): # to make it more reliable, 20 retries in 2[s] for _ in range(20): - dev = usb.core.find(custom_match=TestMatch(serial_number)) + dev = usb.core.find(custom_match=TestMatch(serial_number), backend=USB_BACKEND) if dev is not None: break time.sleep(0.1) - if dev is None: self.log("Device not found") self.send_kv("failed", "0") From 01e6bc5827dfe8366ecd335ae44d66fbdf7a4d43 Mon Sep 17 00:00:00 2001 From: Filip Jagodzinski Date: Wed, 11 Sep 2019 10:52:44 +0200 Subject: [PATCH 2/2] 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. --- TESTS/host_tests/usb_device_hid.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/TESTS/host_tests/usb_device_hid.py b/TESTS/host_tests/usb_device_hid.py index 9a1c0f7142b..415718f6307 100644 --- a/TESTS/host_tests/usb_device_hid.py +++ b/TESTS/host_tests/usb_device_hid.py @@ -19,6 +19,7 @@ import time import threading import uuid +import sys import mbed_host_tests import usb.core from usb.util import ( @@ -31,6 +32,15 @@ DESC_TYPE_CONFIG, 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: import hid except ImportError: @@ -232,7 +242,7 @@ def get_usb_dev(usb_id_str): during test suite setup. 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: err_msg = 'USB device (SN={}) not found.' raise RuntimeError(err_msg.format(usb_id_str))