diff --git a/drivers/usb/tests/TESTS/host_tests/pyusb_msd.py b/drivers/usb/tests/TESTS/host_tests/pyusb_msd.py index 27e43a2..05c0773 100644 --- a/drivers/usb/tests/TESTS/host_tests/pyusb_msd.py +++ b/drivers/usb/tests/TESTS/host_tests/pyusb_msd.py @@ -196,12 +196,30 @@ @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 diff --git a/drivers/usb/tests/TESTS/usb_device/README.md b/drivers/usb/tests/TESTS/usb_device/README.md index 0e0b147..9ab8d0a 100644 --- a/drivers/usb/tests/TESTS/usb_device/README.md +++ b/drivers/usb/tests/TESTS/usb_device/README.md @@ -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 @@ 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 @@ ```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 ` +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 < -[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