Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests: USB: Use libusb0 backend on Windows #11458

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions TESTS/host_tests/pyusb_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down
12 changes: 11 additions & 1 deletion TESTS/host_tests/usb_device_hid.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import time
import threading
import uuid
import sys
import mbed_host_tests
import usb.core
from usb.util import (
Expand All @@ -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:
Expand Down Expand Up @@ -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))
Expand Down