mirror of https://github.com/ARMmbed/mbed-os.git
Tests: USBHID: Make report test optional on Linux
This test case uses `hidapi` -- a cross-platform Python module. To keep the initial Mbed setup as simple as possible, the `hidapi` module is skipped on Linux hosts because of its external dependancies for this platform. The module can be easily installed following instructions from the README file. The test case is skipped if the host machine lacks `hidapi` module.pull/10096/head
parent
111f485cbe
commit
852390fcdc
|
|
@ -20,7 +20,6 @@ import time
|
|||
import threading
|
||||
import uuid
|
||||
import mbed_host_tests
|
||||
import hid
|
||||
import usb.core
|
||||
from usb.util import (
|
||||
CTRL_IN,
|
||||
|
|
@ -32,6 +31,12 @@ from usb.util import (
|
|||
DESC_TYPE_CONFIG,
|
||||
build_request_type)
|
||||
|
||||
try:
|
||||
import hid
|
||||
except ImportError:
|
||||
CYTHON_HIDAPI_PRESENT = False
|
||||
else:
|
||||
CYTHON_HIDAPI_PRESENT = True
|
||||
|
||||
# USB device -- device classes
|
||||
USB_CLASS_HID = 0x03
|
||||
|
|
@ -81,6 +86,7 @@ MSG_KEY_TEST_RAW_IO = 'test_raw_io'
|
|||
MSG_KEY_TEST_CASE_FAILED = 'fail'
|
||||
MSG_KEY_TEST_CASE_PASSED = 'pass'
|
||||
MSG_VALUE_DUMMY = '0'
|
||||
MSG_VALUE_NOT_SUPPORTED = 'not_supported'
|
||||
|
||||
# Constants for the tests.
|
||||
KEYBOARD_IDLE_RATE_TO_SET = 0x00 # Duration = 0 (indefinite)
|
||||
|
|
@ -95,6 +101,8 @@ def build_get_desc_value(desc_type, desc_index):
|
|||
|
||||
def usb_hid_path(serial_number):
|
||||
"""Get a USB HID device system path based on the serial number."""
|
||||
if not CYTHON_HIDAPI_PRESENT:
|
||||
return None
|
||||
for device_info in hid.enumerate(): # pylint: disable=no-member
|
||||
if device_info.get('serial_number') == serial_number: # pylint: disable=not-callable
|
||||
return device_info['path']
|
||||
|
|
@ -544,6 +552,9 @@ class USBHIDTest(mbed_host_tests.BaseHostTest):
|
|||
|
||||
def cb_test_raw_io(self, key, value, timestamp):
|
||||
"""Receive HID reports and send them back to the device."""
|
||||
if not CYTHON_HIDAPI_PRESENT:
|
||||
self.send_kv(MSG_KEY_HOST_READY, MSG_VALUE_NOT_SUPPORTED)
|
||||
return
|
||||
try:
|
||||
# The size of input and output reports used in test.
|
||||
report_size = int(value)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,23 @@
|
|||
# Testing the USB HID device with a Linux host
|
||||
|
||||
Before running `tests-usb_device-hid` test suite on a Linux machine, please
|
||||
make sure to install the `hidapi` Python module first, otherwise some test
|
||||
cases will be skipped. Due to external dependencies for Linux, this module
|
||||
is not installed during the initial setup, to keep the process as simple
|
||||
as possible.
|
||||
|
||||
For Debian-based Linux distros, the dependencies can be installed as follows
|
||||
(based on module's [README][1]):
|
||||
|
||||
```bash
|
||||
apt-get install python-dev libusb-1.0-0-dev libudev-dev
|
||||
pip install --upgrade setuptools
|
||||
```
|
||||
To install the `hidapi` module itself, please use the attached
|
||||
`TESTS/usb_device/hid/requirements.txt` file:
|
||||
```bash
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
[1]: https://github.com/trezor/cython-hidapi/blob/master/README.rst#install
|
||||
|
||||
|
|
@ -49,6 +49,7 @@
|
|||
#define MSG_KEY_TEST_CASE_FAILED "fail"
|
||||
#define MSG_KEY_TEST_CASE_PASSED "pass"
|
||||
#define MSG_VALUE_DUMMY "0"
|
||||
#define MSG_VALUE_NOT_SUPPORTED "not_supported"
|
||||
|
||||
#define RAW_IO_REPS 16
|
||||
|
||||
|
|
@ -310,6 +311,10 @@ void test_generic_raw_io()
|
|||
char value[MSG_VALUE_LEN + 1] = { };
|
||||
greentea_parse_kv(key, value, MSG_KEY_LEN, MSG_VALUE_LEN);
|
||||
TEST_ASSERT_EQUAL_STRING(MSG_KEY_HOST_READY, key);
|
||||
if (strcmp(value, MSG_VALUE_NOT_SUPPORTED) == 0) {
|
||||
TEST_IGNORE_MESSAGE("Test case not supported by host plarform.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Report ID omitted here. There are no Report ID tags in the Report descriptor.
|
||||
HID_REPORT input_report = {};
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
hidapi>=0.7.99,<0.8.0
|
||||
|
|
@ -21,5 +21,5 @@ manifest-tool==1.4.8
|
|||
icetea>=1.2.1,<1.3
|
||||
pycryptodome>=3.7.2,<=3.7.3
|
||||
pyusb>=1.0.0,<2.0.0
|
||||
hidapi>=0.7.99,<0.8.0
|
||||
hidapi>=0.7.99,<0.8.0;platform_system!="Linux"
|
||||
cmsis-pack-manager>=0.2.3,<0.3.0
|
||||
|
|
|
|||
Loading…
Reference in New Issue