Skip to content

Commit aa9bd48

Browse files
authored
Merge pull request #10688 from fkjagodzinski/test_update-docs-usb
Add a top level README file for USB tests
2 parents d8c17b5 + 0ae1be0 commit aa9bd48

File tree

6 files changed

+158
-86
lines changed

6 files changed

+158
-86
lines changed

TESTS/usb_device/README.md

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
# Testing the Mbed OS USB device
2+
3+
## Setup
4+
Before running tests, please make sure to use a
5+
[top-level requirements.txt][LN-requirements] file to install all the
6+
required Python modules.
7+
8+
```
9+
pip install -r requirements.txt
10+
```
11+
12+
Additional, platform-specific setup is described below.
13+
See also [Known issues](#known-issues).
14+
15+
### Windows
16+
1. Install a **generic USB driver** for two test devices.
17+
1. Download `Zadig` application from [the Zadig website][LN-zadig].
18+
1. Unplug the Mbed device.
19+
1. Open `Zadig`.
20+
1. Select *Device -> Load Preset Device*.
21+
1. Open [TESTS/usb_device/basic/zadig_conf/mbed_os-usb_test_device1.cfg][LN-zadig_conf1]
22+
1. Choose `libusb-win32 (v1.2.6.0)` driver.
23+
1. Select `Install Driver` and click it.
24+
1. Select *Device -> Load Preset Device*.
25+
1. Open [TESTS/usb_device/basic/zadig_conf/mbed_os-usb_test_device2.cfg][LN-zadig_conf2]
26+
1. Choose `libusb-win32 (v1.2.6.0)` driver.
27+
1. Select `Install Driver` and click it.
28+
1. Close `Zadig`.
29+
1. Plug both USB interfaces (*DAPLink* and *USB device*).
30+
31+
### Linux
32+
1. Install the `hidapi` Python module, otherwise some USB HID test cases will
33+
be skipped. This module is not installed during the initial setup due to
34+
external dependencies for Linux.
35+
36+
For Debian-based Linux distros, the dependencies can be installed as follows
37+
(based on module's [README][LN-hidapi_readme]):
38+
39+
```bash
40+
apt-get install python-dev libusb-1.0-0-dev libudev-dev
41+
pip install --upgrade setuptools
42+
```
43+
44+
To install the `hidapi` module itself, please use the attached
45+
[requirements.txt][LN-hid_requirements] file:
46+
47+
```bash
48+
pip install -r TESTS/usb_device/hid/requirements.txt
49+
```
50+
51+
1. Update the `udev` rules for Mbed USB CDC device as follows
52+
([source][LN-udev_rules]):
53+
54+
```bash
55+
sudo tee /etc/udev/rules.d/99-ttyacms.rules >/dev/null <<EOF
56+
ATTRS{idVendor}=="1f00" ATTRS{idProduct}=="2013", ENV{ID_MM_DEVICE_IGNORE}="1"
57+
ATTRS{idVendor}=="1f00" ATTRS{idProduct}=="2012", ENV{ID_MM_DEVICE_IGNORE}="1"
58+
EOF
59+
sudo udevadm control --reload-rules
60+
```
61+
62+
This will prevent the `ModemManager` daemon from automatically opening the
63+
port and sending the `AT commands`, which it does for every new
64+
`/dev/ttyACM` device registered in system.
65+
66+
### Mac
67+
No setup method has been verified for this platform.
68+
69+
## Running tests
70+
1. Plug both USB interfaces (*DAPLink* and *USB device*) to your host machine.
71+
1. Run tests:
72+
```
73+
mbed test -t <toolchain> -m <target> -n tests-usb_device-*
74+
```
75+
76+
## Known issues
77+
78+
### Insufficient user permissions on a Linux machine
79+
Some of the tests require privileged access to the USB device. Running these
80+
as an unprivileged user will manifest with either of the following errors:
81+
* ```
82+
[HTST][INF] Device not found
83+
```
84+
* ```
85+
[HTST][INF] TEST ERROR: Failed with "The device has no langid". Tried 20 times.
86+
```
87+
88+
#### Solution
89+
Execute tests with elevated permissions using `sudo`:
90+
```bash
91+
mbed test -t <toolchain> -m <target> -n tests-usb_device-* --compile
92+
sudo mbed test -t <toolchain> -m <target> -n tests-usb_device-* --run -v
93+
```
94+
Note only the `mbed test --run` command requires `sudo`. You can still
95+
`mbed test --compile` as a normal user.
96+
97+
#### Alternative solution
98+
Add an `udev` rule to set the ownership of the device node
99+
[as shown here][LN-libusb_permissions].
100+
101+
### Data toggle reset test fails on a Linux machine
102+
The `tests-usb_device-basic` / `"endpoint test data toggle reset"` test fails
103+
with the following error:
104+
```
105+
[HTST][INF] TEST FAILED: Data toggle not reset when calling
106+
ClearFeature(ENDPOINT_HALT) on an endpoint that has not been halted.
107+
```
108+
109+
Implementations of the *xHCI* driver prior to version 4.17 of the Linux kernel did
110+
not have the functionality necessary to test `"endpoint test data toggle reset"`.
111+
Even though the data toggle is correctly reset on the device side, the host
112+
side will not be synchronized and the test will falsely fail.
113+
114+
#### Solution
115+
Make sure that **at least one** of the following prerequisites is met:
116+
* using the Linux kernel ***4.17* or newer**,
117+
* using the ***eHCI*** USB driver instead of *xHCI*.
118+
119+
Changing the USB driver may be as simple as updating one of the BIOS settings
120+
on your machine. If you'd rather avoid rebooting, you can try
121+
[using setpci command][LN-xhci_setpci].
122+
123+
#### Further reading
124+
1. [the Linux kernel patch adding missing xHCI behavior][LN-linux_xhci_patch],
125+
1. [LKML discussion explaining the details of this issue][LN-xhci_lkml_discussion].
126+
127+
### Mass storage tests are skipped on some targets
128+
The `tests-usb_device-msd` test outputs the following message:
129+
```
130+
[CONN][RXD] SKIP: Not enough heap memory for HeapBlockDevice creation
131+
```
132+
133+
#### Solution
134+
A device with at least *70 kB* of RAM is required to run this test.
135+
The FAT32 filesystem cannot be mounted on a device smaller than 64 kB.
136+
137+
The test can be easily extended to use any block device available in Mbed.
138+
139+
### Isochronous endpoints are skipped in loopback tests
140+
#### Unresolved
141+
142+
### Serial tests fail intermittently on a Linux machine
143+
#### Unresolved
144+
You may want to connect the device directly to the host machine with no hubs on the way.
145+
146+
<!-- LINKS -->
147+
[LN-requirements]: ../../requirements.txt
148+
[LN-zadig]: https://zadig.akeo.ie/
149+
[LN-zadig_conf1]: basic/zadig_conf/mbed_os-usb_test_device1.cfg
150+
[LN-zadig_conf2]: basic/zadig_conf/mbed_os-usb_test_device2.cfg
151+
[LN-hidapi_readme]: https://github.com/trezor/cython-hidapi/blob/master/README.rst#install
152+
[LN-hid_requirements]: hid/requirements.txt
153+
[LN-udev_rules]: https://linux-tips.com/t/prevent-modem-manager-to-capture-usb-serial-devices/284
154+
[LN-libusb_permissions]: https://stackoverflow.com/questions/3738173/why-does-pyusb-libusb-require-root-sudo-permissions-on-linux/8582398#8582398
155+
[LN-linux_xhci_patch]: https://github.com/torvalds/linux/commit/f5249461b504d35aa1a40140983b7ec415807d9e
156+
[LN-xhci_lkml_discussion]: https://lkml.org/lkml/2016/12/15/388
157+
[LN-xhci_setpci]: https://linuxmusicians.com/viewtopic.php?t=16901
158+

TESTS/usb_device/basic/README.md

Lines changed: 0 additions & 15 deletions
This file was deleted.

TESTS/usb_device/basic/zadig_conf/README.md

Lines changed: 0 additions & 18 deletions
This file was deleted.

TESTS/usb_device/hid/README.md

Lines changed: 0 additions & 23 deletions
This file was deleted.

TESTS/usb_device/msd/README.md

Lines changed: 0 additions & 12 deletions
This file was deleted.

TESTS/usb_device/serial/README.md

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)