Fix the USB Mass Storage Device test so it can run as a CI user without root (#65)

pull/15339/head
Jamie Smith 2022-10-03 00:08:09 -07:00 committed by GitHub
parent ffc33676d1
commit 555345cbd5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 16 deletions

View File

@ -196,12 +196,30 @@ class MSDUtils(object):
@staticmethod
def _disk_path_linux(serial):
output = subprocess.check_output(['lsblk', '-dnoserial,mountpoint']).split(b'\n')
# This generates a table of serial number, mount point (e.g. /media/foo/DISK), and path (e.g. /dev/sdd)
output = subprocess.check_output(['lsblk', '-dnoserial,mountpoint,path']).decode("UTF-8").split('\n')
for line in output:
serial_and_mount_point = line.split()
if len(serial_and_mount_point) == 2:
if serial_and_mount_point[0] == str(serial):
return serial_and_mount_point[1]
fields = line.split()
if len(fields) >= 2 and fields[0] == str(serial):
# Found the correct device
if len(fields) == 2:
# "mountpoint" column (idx 1) is empty, meaning the device is not mounted.
# Ask the OS to mount it under our user account.
# Note: This requires that no other processes are trying to automount disks at the same
# time -- this often requires changing file manager settings.
subprocess.check_call(['udisksctl', 'mount', '-b', fields[1]])
# The OS will now mount the disk. Return so that the query can be run again and we'll get it
# next time.
return None
else:
# Disk has a mount point, return it
return fields[1]
return None
@staticmethod

View File

@ -1,12 +1,11 @@
# Testing the Mbed OS USB device
## Setup
Before running tests, please make sure to use a
[top-level requirements.txt][LN-requirements] file to install all the
Before running tests, please make sure to install all the
required Python modules.
```
pip install -r requirements.txt
pip install -r mbed-os/tools/requirements-ci-build.txt
```
Additional, platform-specific setup is described below.
@ -29,7 +28,7 @@ See also [Known issues](#known-issues).
1. Plug both USB interfaces (*DAPLink* and *USB device*).
### Linux
1. Install the `hidapi` Python module, otherwise some USB HID test cases will
1. Install the `hidapi` Python module, otherwise some USB HID test cases will
be skipped. This module is not installed during the initial setup due to
external dependencies for Linux.
@ -47,21 +46,26 @@ See also [Known issues](#known-issues).
```bash
pip install -r TESTS/usb_device/hid/requirements.txt
```
1. Update the `udev` rules for Mbed USB CDC device as follows
([source][LN-udev_rules]):
2. Add your user to the `plugdev` group with `sudo usermod -G plugdev <your username>`
3. Update the `udev` rules for the USB VIDs/PIDs used in the test as follows:
```bash
sudo tee /etc/udev/rules.d/99-ttyacms.rules >/dev/null <<EOF
ATTRS{idVendor}=="1f00" ATTRS{idProduct}=="2013", ENV{ID_MM_DEVICE_IGNORE}="1"
ATTRS{idVendor}=="1f00" ATTRS{idProduct}=="2012", ENV{ID_MM_DEVICE_IGNORE}="1"
# Mbed OS USB Device test suite
ATTRS{idVendor}=="0d28", ATTRS{idProduct}=="0007", MODE="660", GROUP="plugdev", TAG+="uaccess"
ATTRS{idVendor}=="0d28", ATTRS{idProduct}=="0205", MODE="660", GROUP="plugdev", TAG+="uaccess"
ATTRS{idVendor}=="0d28", ATTRS{idProduct}=="0206", MODE="660", GROUP="plugdev", TAG+="uaccess"
ATTRS{idVendor}=="1f00" ATTRS{idProduct}=="2013", ENV{ID_MM_DEVICE_IGNORE}="1", MODE="660", GROUP="plugdev"
ATTRS{idVendor}=="1f00" ATTRS{idProduct}=="2012", ENV{ID_MM_DEVICE_IGNORE}="1", MODE="660", GROUP="plugdev"
EOF
sudo udevadm control --reload-rules
sudo udevadm trigger
```
This will prevent the `ModemManager` daemon from automatically opening the
Among other things, this will [prevent][LN-udev_rules] the `ModemManager` daemon from automatically opening the
port and sending the `AT commands`, which it does for every new
`/dev/ttyACM` device registered in system.
4. Install the `udisks2` package, which the test script uses to mount USB disks. Additionally, you may need to disable any automounting of disks provided by your file manager / distro.
### Mac
No setup method has been verified for this platform.
@ -152,7 +156,6 @@ To prevent Windows from writing to removable drives on connect drive indexing ca
You may want to connect the device directly to the host machine with no hubs on the way.
<!-- LINKS -->
[LN-requirements]: ../../requirements.txt
[LN-zadig]: https://zadig.akeo.ie/
[LN-zadig_conf1]: basic/zadig_conf/mbed_os-usb_test_device1.cfg
[LN-zadig_conf2]: basic/zadig_conf/mbed_os-usb_test_device2.cfg