Skip to content

Commit 01e6bc5

Browse files
author
Filip Jagodzinski
committed
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.
1 parent db29950 commit 01e6bc5

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

TESTS/host_tests/usb_device_hid.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import time
2020
import threading
2121
import uuid
22+
import sys
2223
import mbed_host_tests
2324
import usb.core
2425
from usb.util import (
@@ -31,6 +32,15 @@
3132
DESC_TYPE_CONFIG,
3233
build_request_type)
3334

35+
if sys.platform.startswith('win'):
36+
# Use libusb0 on Windows. libusb1 implementation for Windows
37+
# does not support all features necessary for testing.
38+
import usb.backend.libusb0
39+
USB_BACKEND = usb.backend.libusb0.get_backend()
40+
else:
41+
# Use a default backend on other platforms.
42+
USB_BACKEND = None
43+
3444
try:
3545
import hid
3646
except ImportError:
@@ -232,7 +242,7 @@ def get_usb_dev(usb_id_str):
232242
during test suite setup.
233243
Raises RuntimeError if the device is not found.
234244
"""
235-
usb_dev = usb.core.find(custom_match=lambda d: d.serial_number == usb_id_str)
245+
usb_dev = usb.core.find(custom_match=lambda d: d.serial_number == usb_id_str, backend=USB_BACKEND)
236246
if usb_dev is None:
237247
err_msg = 'USB device (SN={}) not found.'
238248
raise RuntimeError(err_msg.format(usb_id_str))

0 commit comments

Comments
 (0)