diff --git a/README.md b/README.md index 42f7c3b..004155d 100644 --- a/README.md +++ b/README.md @@ -86,10 +86,12 @@ $ mbedls --json "mount_point": "D:", "platform_name": "K64F", "platform_name_unique": "K64F[0]", + "product_id": "0204", "serial_port": "COM18", "target_id": "0240000032044e4500257009997b00386781000097969900", "target_id_mbed_htm": "0240000032044e4500257009997b00386781000097969900", - "target_id_usb_id": "0240000032044e4500257009997b00386781000097969900" + "target_id_usb_id": "0240000032044e4500257009997b00386781000097969900", + "vendor_id": "0d28" } ] ``` @@ -288,7 +290,7 @@ If set to `'+'`, the mocked platform is enabled. If `'-'`, the mocked platform i ## Logging -Mbed LS uses the Python `logging` module for all of its logging needs. Mbed LS uses the logger `"mbedls"` as its root, and all other loggers start with `"mbedls."`. Configuring the Python root logger automatically redirects all of the Mbed LS logs to the configured endpoint. When using the Python API, configure logging, such as by calling `logging.basicConfig()`. +Mbed LS uses the Python `logging` module for all of its logging needs. Mbed LS uses the logger `"mbedls"` as its root, and all other loggers start with `"mbedls."`. Configuring the Python root logger automatically redirects all of the Mbed LS logs to the configured endpoint. When using the Python API, configure logging, such as by calling `logging.basicConfig()`. # Testing diff --git a/mbed_lstools/darwin.py b/mbed_lstools/darwin.py index d9ccd33..62c514a 100644 --- a/mbed_lstools/darwin.py +++ b/mbed_lstools/darwin.py @@ -45,13 +45,13 @@ def _find_TTY(obj): def _prune(current, keys): - """ Reduce the amount of data we have to sift through to only + """ Reduce the amount of data we have to sift through to only include the specified keys, and children that contain the specified keys """ pruned_current = {k: current[k] for k in keys if k in current} pruned_children = list( - filter(None, [_prune(c, keys) for c in + filter(None, [_prune(c, keys) for c in current.get('IORegistryEntryChildren', [])])) keep_current = any(k in current for k in keys) or pruned_children if keep_current: @@ -63,7 +63,7 @@ def _prune(current, keys): def _dfs_usb_info(obj, parents): - """ Find all of the usb info that we can from this particular IORegistry + """ Find all of the usb info that we can from this particular IORegistry tree with depth first search (and searching the parent stack....) """ output = {} @@ -80,10 +80,10 @@ def _dfs_usb_info(obj, parents): if 'USB Serial Number' in parent: usb_info['serial'] = parent['USB Serial Number'] if 'idVendor' in parent and 'idProduct' in parent: - usb_info['vendor_id'] = parent['idVendor'] - usb_info['product_id'] = parent['idProduct'] + usb_info['vendor_id'] = format(parent['idVendor'], '04x') + usb_info['product_id'] = format(parent['idProduct'], '04x') if usb_info['serial']: - usb_info['tty'] = _find_TTY(parent) + usb_info['tty'] = _find_TTY(parent) if all(usb_info.values()): break logger.debug("found usb info %r", usb_info) @@ -111,7 +111,9 @@ def find_candidates(self): { 'mount_point': mounts[v], 'serial_port': volumes[v]['tty'], - 'target_id_usb_id': volumes[v].get('serial') + 'target_id_usb_id': volumes[v].get('serial'), + 'vendor_id': volumes[v].get('vendor_id'), + 'product_id': volumes[v].get('product_id') } for v in set(volumes.keys()) and set(mounts.keys()) if v in mounts and v in volumes ] diff --git a/mbed_lstools/linux.py b/mbed_lstools/linux.py index 26e44ca..ca78d57 100644 --- a/mbed_lstools/linux.py +++ b/mbed_lstools/linux.py @@ -26,6 +26,8 @@ logger.addHandler(logging.NullHandler()) del logging +SYSFS_BLOCK_DEVICE_PATH = '/sys/class/block' + def _readlink(link): content = os.readlink(link) if content.startswith(".."): @@ -45,18 +47,22 @@ def __init__(self, **kwargs): r'(pci|usb)-[0-9a-zA-Z_-]*_(?P[0-9a-zA-Z]*)-.*$') self.mmp = re.compile( r'(?P(/[^/ ]*)+) on (?P(/[^/ ]*)+) ') + self.udp = re.compile(r'[0-9]+-[0-9]+') def find_candidates(self): disk_ids = self._dev_by_id('disk') serial_ids = self._dev_by_id('serial') mount_ids = dict(self._fat_mounts()) + usb_info = self._sysfs_block_devices(disk_ids.values()) logger.debug("Mount mapping %r", mount_ids) return [ { 'mount_point' : mount_ids.get(disk_dev), 'serial_port' : serial_ids.get(disk_uuid), - 'target_id_usb_id' : disk_uuid + 'target_id_usb_id' : disk_uuid, + 'vendor_id': usb_info[disk_dev]['vendor_id'], + 'product_id': usb_info[disk_dev]['product_id'] } for disk_uuid, disk_dev in disk_ids.items() ] @@ -104,3 +110,52 @@ def _hex_ids(self, dev_list): match = self.nlp.search(dl) if match: yield match.group("usbid"), _readlink(dl) + + def _sysfs_block_devices(self, block_devices): + device_names = { os.path.basename(d): d for d in block_devices } + sysfs_block_devices = set(os.listdir(SYSFS_BLOCK_DEVICE_PATH)) + common_device_names = sysfs_block_devices.intersection(set(device_names.keys())) + result = {} + + for common_device_name in common_device_names: + sysfs_path = os.path.join(SYSFS_BLOCK_DEVICE_PATH, common_device_name) + full_sysfs_path = os.readlink(sysfs_path) + path_parts = full_sysfs_path.split('/') + + end_index = None + for index, part in enumerate(path_parts): + if self.udp.search(part): + end_index = index + break + + if end_index == None: + logger.debug('Did not find suitable usb folder for usb info: %s', full_sysfs_path) + continue + + usb_info_rel_path = path_parts[:end_index + 1] + usb_info_path = os.path.join(SYSFS_BLOCK_DEVICE_PATH, os.sep.join(usb_info_rel_path)) + + vendor_id = None + product_id = None + + vendor_id_file_paths = os.path.join(usb_info_path, 'idVendor') + product_id_file_paths = os.path.join(usb_info_path, 'idProduct') + + try: + with open(vendor_id_file_paths, 'r') as vendor_file: + vendor_id = vendor_file.read().strip() + except OSError as e: + logger.debug('Failed to read vendor id file %s weith error:', vendor_id_file_paths, e) + + try: + with open(product_id_file_paths, 'r') as product_file: + product_id = product_file.read().strip() + except OSError as e: + logger.debug('Failed to read product id file %s weith error:', product_id_file_paths, e) + + result[device_names[common_device_name]] = { + 'vendor_id': vendor_id, + 'product_id': product_id + } + + return result diff --git a/mbed_lstools/windows.py b/mbed_lstools/windows.py index 5f30197..1e4231f 100644 --- a/mbed_lstools/windows.py +++ b/mbed_lstools/windows.py @@ -157,6 +157,8 @@ def _determine_valid_non_composite_devices(devices, target_id_usb_id_mount_point 'target_id_usb_id': target_id_usb_id, 'mount_point': target_id_usb_id_mount_point_map[target_id_usb_id] } + + candidates[target_id_usb_id].update(_vid_pid_path_to_usb_info(device['vid_pid_path'])) except KeyError: pass @@ -180,6 +182,32 @@ def _determine_subdevice_capability(key): logger.debug('Unknown capabilities from the following ids: %s', compatible_ids) return None + +def _vid_pid_path_to_usb_info(vid_pid_path): + """! Provide the vendor ID and product ID of a device based on its entry in the registry + @return Returns {'vendor_id': '', 'product': ''} + @details If the vendor ID or product ID can't be determined, they will be returned + as None. + """ + result = { + 'vendor_id': None, + 'product_id': None + } + + for component in vid_pid_path.split('&'): + component_part = component.lower().split('_') + + if len(component_part) != 2: + logger.debug('Unexpected VID/PID string structure %s', component) + break + + if component_part[0] == 'vid': + result['vendor_id'] = component_part[1] + elif component_part[0] == 'pid': + result['product_id'] = component_part[1] + + return result + # =============================== Start Registry Functions ==================================== def _iter_keys_as_str(key): @@ -350,6 +378,7 @@ def find_candidates(self): if capability == 'msd': candidates[entry_data['target_id_usb_id']]['mount_point'] = \ target_id_usb_id_mount_point_map[entry_data['target_id_usb_id']] + candidates[entry_data['target_id_usb_id']].update(_vid_pid_path_to_usb_info(vid_pid_path)) elif capability == 'serial': try: device_parameters_key = winreg.OpenKey(subdevice_key, @@ -361,6 +390,7 @@ def find_candidates(self): try: candidates[entry_data['target_id_usb_id']]['serial_port'], _ = winreg.QueryValueEx( device_parameters_key, 'PortName') + candidates[entry_data['target_id_usb_id']].update(_vid_pid_path_to_usb_info(vid_pid_path)) except OSError: logger.debug('"PortName" value not found under serial device entry') continue diff --git a/test/os_darwin.py b/test/os_darwin.py index 9859157..d134c1f 100644 --- a/test/os_darwin.py +++ b/test/os_darwin.py @@ -165,5 +165,7 @@ def do_popen(command, *args, **kwargs): candidates = self.darwin.find_candidates() self.assertIn({'mount_point': '/Volumes/DAPLINK', 'serial_port': '/dev/tty.usbmodem1422', - 'target_id_usb_id': '0240000034544e45003a00048e3800525a91000097969900'}, + 'target_id_usb_id': '0240000034544e45003a00048e3800525a91000097969900', + 'vendor_id': '0d28', + 'product_id': '0204'}, candidates) diff --git a/test/os_linux_generic.py b/test/os_linux_generic.py index 80513a8..e803808 100644 --- a/test/os_linux_generic.py +++ b/test/os_linux_generic.py @@ -19,9 +19,10 @@ import unittest import sys import os -from mock import patch +from mock import patch, mock_open from mbed_lstools.linux import MbedLsToolsLinuxGeneric + class LinuxPortTestCase(unittest.TestCase): ''' Basic test cases checking trivial asserts ''' @@ -79,14 +80,21 @@ def test_get_mount_point_ext(self): self.assertEqual('/mnt/DAPLINK_', mount_dict['/dev/sdh']) self.assertEqual('/mnt/DAPLINK__', mount_dict['/dev/sdi']) - def find_candidates_with_patch(self, mount_list, link_dict, listdir_dict): + def find_candidates_with_patch(self, mount_list, link_dict, listdir_dict, open_dict): if not getattr(sys.modules['os'], 'readlink', None): sys.modules['os'].readlink = None + def do_open(path, mode='r'): + path = path.replace('\\', '/') + file_object = mock_open(read_data=open_dict[path]).return_value + file_object.__iter__.return_value = open_dict[path].splitlines(True) + return file_object + with patch('mbed_lstools.linux.MbedLsToolsLinuxGeneric._run_cli_process') as _cliproc,\ patch('os.readlink') as _readlink,\ patch('os.listdir') as _listdir,\ patch('mbed_lstools.linux.abspath') as _abspath,\ + patch('mbed_lstools.linux.open', do_open) as _,\ patch('mbed_lstools.linux.isdir') as _isdir: _isdir.return_value = True _cliproc.return_value = (b'\n'.join(mount_list), None, 0) @@ -125,9 +133,56 @@ def do_abspath(dir): 'usb-ARM_DAPLink_CMSIS-DAP_0240000028884e450018700f6bf000338021000097969900-if01', 'usb-ARM_DAPLink_CMSIS-DAP_0240000028884e450036700f6bf000118021000097969900-if01', 'usb-ARM_DAPLink_CMSIS-DAP_0240000029164e45001b0012706e000df301000097969900-if01' + ], + '/sys/class/block': [ + 'sdb', + 'sdc', + 'sdd', + 'sde', + 'sdf', + 'sdg' + ], + '/sys/class/block/../../devices/pci0000:00/0000:00:06.0/usb1/1-2': [ + 'idVendor', + 'idProduct' + ], + '/sys/class/block/../../devices/pci0000:00/0000:00:06.0/usb1/1-3': [ + 'idVendor', + 'idProduct' + ], + '/sys/class/block/../../devices/pci0000:00/0000:00:06.0/usb1/1-4': [ + 'idVendor', + 'idProduct' + ], + '/sys/class/block/../../devices/pci0000:00/0000:00:06.0/usb1/1-5': [ + 'idVendor', + 'idProduct' + ], + '/sys/class/block/../../devices/pci0000:00/0000:00:06.0/usb1/1-6': [ + 'idVendor', + 'idProduct' + ], + '/sys/class/block/../../devices/pci0000:00/0000:00:06.0/usb1/1-7': [ + 'idVendor', + 'idProduct' ] } + open_dict_rpi = { + '/sys/class/block/../../devices/pci0000:00/0000:00:06.0/usb1/1-2/idVendor': '0d28\n', + '/sys/class/block/../../devices/pci0000:00/0000:00:06.0/usb1/1-2/idProduct': '0204\n', + '/sys/class/block/../../devices/pci0000:00/0000:00:06.0/usb1/1-3/idVendor': '0d28\n', + '/sys/class/block/../../devices/pci0000:00/0000:00:06.0/usb1/1-3/idProduct': '0204\n', + '/sys/class/block/../../devices/pci0000:00/0000:00:06.0/usb1/1-4/idVendor': '0d28\n', + '/sys/class/block/../../devices/pci0000:00/0000:00:06.0/usb1/1-4/idProduct': '0204\n', + '/sys/class/block/../../devices/pci0000:00/0000:00:06.0/usb1/1-5/idVendor': '0d28\n', + '/sys/class/block/../../devices/pci0000:00/0000:00:06.0/usb1/1-5/idProduct': '0204\n', + '/sys/class/block/../../devices/pci0000:00/0000:00:06.0/usb1/1-6/idVendor': '0d28\n', + '/sys/class/block/../../devices/pci0000:00/0000:00:06.0/usb1/1-6/idProduct': '0204\n', + '/sys/class/block/../../devices/pci0000:00/0000:00:06.0/usb1/1-7/idVendor': '0d28\n', + '/sys/class/block/../../devices/pci0000:00/0000:00:06.0/usb1/1-7/idProduct': '0204\n' + } + link_dict_rpi = { '/dev/disk/by-id/usb-MBED_VFS_0240000028634e4500135006691700105f21000097969900-0:0': '../../sdb', '/dev/disk/by-id/usb-MBED_VFS_0240000028884e450018700f6bf000338021000097969900-0:0': '../../sdc', @@ -138,7 +193,13 @@ def do_abspath(dir): '/dev/serial/by-id/usb-ARM_DAPLink_CMSIS-DAP_0240000028634e4500135006691700105f21000097969900-if01': '../../ttyACM0', '/dev/serial/by-id/usb-ARM_DAPLink_CMSIS-DAP_0240000028884e450018700f6bf000338021000097969900-if01': '../../ttyACM1', '/dev/serial/by-id/usb-ARM_DAPLink_CMSIS-DAP_0240000028884e450036700f6bf000118021000097969900-if01': '../../ttyACM3', - '/dev/serial/by-id/usb-ARM_DAPLink_CMSIS-DAP_0240000029164e45001b0012706e000df301000097969900-if01': '../../ttyACM2' + '/dev/serial/by-id/usb-ARM_DAPLink_CMSIS-DAP_0240000029164e45001b0012706e000df301000097969900-if01': '../../ttyACM2', + '/sys/class/block/sdb': '../../devices/pci0000:00/0000:00:06.0/usb1/1-2/1-2:1.0/host3/target3:0:0/3:0:0:0/block/sdb', + '/sys/class/block/sdc': '../../devices/pci0000:00/0000:00:06.0/usb1/1-3/1-3:1.0/host4/target4:0:0/4:0:0:0/block/sdc', + '/sys/class/block/sdd': '../../devices/pci0000:00/0000:00:06.0/usb1/1-4/1-4:1.0/host5/target5:0:0/5:0:0:0/block/sdd', + '/sys/class/block/sde': '../../devices/pci0000:00/0000:00:06.0/usb1/1-5/1-5:1.0/host6/target6:0:0/6:0:0:0/block/sde', + '/sys/class/block/sdf': '../../devices/pci0000:00/0000:00:06.0/usb1/1-6/1-6:1.0/host7/target7:0:0/7:0:0:0/block/sdf', + '/sys/class/block/sdg': '../../devices/pci0000:00/0000:00:06.0/usb1/1-7/1-7:1.0/host8/target8:0:0/8:0:0:0/block/sdg' } mount_list_rpi = [ @@ -151,28 +212,36 @@ def do_abspath(dir): ] def test_get_detected_rpi(self): mbed_det = self.find_candidates_with_patch( - self.mount_list_rpi, self.link_dict_rpi, self.listdir_dict_rpi) + self.mount_list_rpi, self.link_dict_rpi, self.listdir_dict_rpi, self.open_dict_rpi) self.assertIn({ 'mount_point': '/media/usb0', 'serial_port': '/dev/ttyACM0', - 'target_id_usb_id': '0240000028634e4500135006691700105f21000097969900' + 'target_id_usb_id': '0240000028634e4500135006691700105f21000097969900', + 'vendor_id': '0d28', + 'product_id': '0204' }, mbed_det) self.assertIn({ 'mount_point': '/media/usb1', 'serial_port': '/dev/ttyACM1', - 'target_id_usb_id': '0240000028884e450018700f6bf000338021000097969900' + 'target_id_usb_id': '0240000028884e450018700f6bf000338021000097969900', + 'vendor_id': '0d28', + 'product_id': '0204' }, mbed_det) self.assertIn({ 'mount_point': '/media/usb4', 'serial_port': '/dev/ttyACM2', - 'target_id_usb_id': '0240000029164e45001b0012706e000df301000097969900' + 'target_id_usb_id': '0240000029164e45001b0012706e000df301000097969900', + 'vendor_id': '0d28', + 'product_id': '0204' }, mbed_det) self.assertIn({ 'mount_point': '/media/usb3', 'serial_port': '/dev/ttyACM3', - 'target_id_usb_id': '0240000028884e450036700f6bf000118021000097969900' + 'target_id_usb_id': '0240000028884e450036700f6bf000118021000097969900', + 'vendor_id': '0d28', + 'product_id': '0204' }, mbed_det) @@ -193,6 +262,18 @@ def test_get_detected_rpi(self): '/dev/serial/by-id': [ '/dev/serial/by-id/usb-MBED_MBED_CMSIS-DAP_0240020152986E5EAF6693E6-if01', '/dev/serial/by-id/usb-MBED_MBED_CMSIS-DAP_A000000001-if01', + ], + '/sys/class/block': [ + 'sdb', + 'sdc' + ], + '/sys/class/block/../../devices/pci0000:00/0000:00:06.0/usb1/1-2': [ + 'idVendor', + 'idProduct' + ], + '/sys/class/block/../../devices/pci0000:00/0000:00:06.0/usb1/1-3': [ + 'idVendor', + 'idProduct' ] } @@ -209,7 +290,16 @@ def test_get_detected_rpi(self): '/dev/disk/by-id/wwn-0x5000cca30ccffb77-part2': '../../sda2', '/dev/disk/by-id/wwn-0x5000cca30ccffb77-part5': '../../sda5', '/dev/serial/by-id/usb-MBED_MBED_CMSIS-DAP_0240020152986E5EAF6693E6-if01': '../../ttyACM1', - '/dev/serial/by-id/usb-MBED_MBED_CMSIS-DAP_A000000001-if01': '../../ttyACM0' + '/dev/serial/by-id/usb-MBED_MBED_CMSIS-DAP_A000000001-if01': '../../ttyACM0', + '/sys/class/block/sdb': '../../devices/pci0000:00/0000:00:06.0/usb1/1-2/1-2:1.0/host3/target3:0:0/3:0:0:0/block/sdb', + '/sys/class/block/sdc': '../../devices/pci0000:00/0000:00:06.0/usb1/1-3/1-3:1.0/host4/target4:0:0/4:0:0:0/block/sdc' + } + + open_dict_1 = { + '/sys/class/block/../../devices/pci0000:00/0000:00:06.0/usb1/1-2/idVendor': '0d28\n', + '/sys/class/block/../../devices/pci0000:00/0000:00:06.0/usb1/1-2/idProduct': '0204\n', + '/sys/class/block/../../devices/pci0000:00/0000:00:06.0/usb1/1-3/idVendor': '0d28\n', + '/sys/class/block/../../devices/pci0000:00/0000:00:06.0/usb1/1-3/idProduct': '0204\n' } mount_list_1 = [ @@ -218,17 +308,21 @@ def test_get_detected_rpi(self): ] def test_get_detected_1_k64f(self): mbed_det = self.find_candidates_with_patch( - self.mount_list_1, self.link_dict_1, self.listdir_dict_1) + self.mount_list_1, self.link_dict_1, self.listdir_dict_1, self.open_dict_1) self.assertIn({ 'mount_point': '/media/usb0', 'serial_port': '/dev/ttyACM1', - 'target_id_usb_id': '0240020152986E5EAF6693E6' + 'target_id_usb_id': '0240020152986E5EAF6693E6', + 'vendor_id': '0d28', + 'product_id': '0204' }, mbed_det) self.assertIn({ 'mount_point': '/media/usb1', 'serial_port': '/dev/ttyACM0', - 'target_id_usb_id': 'A000000001' + 'target_id_usb_id': 'A000000001', + 'vendor_id': '0d28', + 'product_id': '0204' }, mbed_det) @@ -255,9 +349,49 @@ def test_get_detected_1_k64f(self): 'usb-MBED_MBED_CMSIS-DAP_0240020152A06E54AF5E93EC-if01', 'usb-MBED_MBED_CMSIS-DAP_A000000001-if01', 'usb-STMicroelectronics_STM32_STLink_0672FF485649785087171742-if02' + ], + '/sys/class/block': [ + 'sdb', + 'sdc', + 'sdd', + 'sde', + 'sdf' + ], + '/sys/class/block/../../devices/pci0000:00/0000:00:06.0/usb1/1-2': [ + 'idVendor', + 'idProduct' + ], + '/sys/class/block/../../devices/pci0000:00/0000:00:06.0/usb1/1-3': [ + 'idVendor', + 'idProduct' + ], + '/sys/class/block/../../devices/pci0000:00/0000:00:06.0/usb1/1-4': [ + 'idVendor', + 'idProduct' + ], + '/sys/class/block/../../devices/pci0000:00/0000:00:06.0/usb1/1-5': [ + 'idVendor', + 'idProduct' + ], + '/sys/class/block/../../devices/pci0000:00/0000:00:06.0/usb1/1-6': [ + 'idVendor', + 'idProduct' ] } + open_dict_2 = { + '/sys/class/block/../../devices/pci0000:00/0000:00:06.0/usb1/1-2/idVendor': '0d28\n', + '/sys/class/block/../../devices/pci0000:00/0000:00:06.0/usb1/1-2/idProduct': '0204\n', + '/sys/class/block/../../devices/pci0000:00/0000:00:06.0/usb1/1-3/idVendor': '0d28\n', + '/sys/class/block/../../devices/pci0000:00/0000:00:06.0/usb1/1-3/idProduct': '0204\n', + '/sys/class/block/../../devices/pci0000:00/0000:00:06.0/usb1/1-4/idVendor': '0d28\n', + '/sys/class/block/../../devices/pci0000:00/0000:00:06.0/usb1/1-4/idProduct': '0204\n', + '/sys/class/block/../../devices/pci0000:00/0000:00:06.0/usb1/1-5/idVendor': '0d28\n', + '/sys/class/block/../../devices/pci0000:00/0000:00:06.0/usb1/1-5/idProduct': '0204\n', + '/sys/class/block/../../devices/pci0000:00/0000:00:06.0/usb1/1-6/idVendor': '0d28\n', + '/sys/class/block/../../devices/pci0000:00/0000:00:06.0/usb1/1-6/idProduct': '0204\n' + } + link_dict_2 = { '/dev/disk/by-id/ata-HDS728080PLA380_40Y9028LEN_PFDB32S7S44XLM': '../../sda', '/dev/disk/by-id/ata-HDS728080PLA380_40Y9028LEN_PFDB32S7S44XLM-part1': '../../sda1', @@ -277,7 +411,12 @@ def test_get_detected_1_k64f(self): '/dev/serial/by-id/usb-MBED_MBED_CMSIS-DAP_0240020152986E5EAF6693E6-if01': '../../ttyACM1', '/dev/serial/by-id/usb-MBED_MBED_CMSIS-DAP_0240020152A06E54AF5E93EC-if01': '../../ttyACM4', '/dev/serial/by-id/usb-MBED_MBED_CMSIS-DAP_A000000001-if01': '../../ttyACM0', - '/dev/serial/by-id/usb-STMicroelectronics_STM32_STLink_0672FF485649785087171742-if02': '../../ttyACM2' + '/dev/serial/by-id/usb-STMicroelectronics_STM32_STLink_0672FF485649785087171742-if02': '../../ttyACM2', + '/sys/class/block/sdb': '../../devices/pci0000:00/0000:00:06.0/usb1/1-2/1-2:1.0/host3/target3:0:0/3:0:0:0/block/sdb', + '/sys/class/block/sdc': '../../devices/pci0000:00/0000:00:06.0/usb1/1-3/1-3:1.0/host4/target4:0:0/4:0:0:0/block/sdc', + '/sys/class/block/sdd': '../../devices/pci0000:00/0000:00:06.0/usb1/1-4/1-4:1.0/host5/target5:0:0/5:0:0:0/block/sdd', + '/sys/class/block/sde': '../../devices/pci0000:00/0000:00:06.0/usb1/1-5/1-5:1.0/host6/target6:0:0/6:0:0:0/block/sde', + '/sys/class/block/sdf': '../../devices/pci0000:00/0000:00:06.0/usb1/1-6/1-6:1.0/host7/target7:0:0/7:0:0:0/block/sdf' } mount_list_2 = [ @@ -289,39 +428,49 @@ def test_get_detected_1_k64f(self): ] def test_get_detected_2_k64f(self): mbed_det = self.find_candidates_with_patch( - self.mount_list_2, self.link_dict_2, self.listdir_dict_2) + self.mount_list_2, self.link_dict_2, self.listdir_dict_2, self.open_dict_2) self.assertIn({ 'mount_point': '/media/usb1', 'serial_port': '/dev/ttyACM0', - 'target_id_usb_id': 'A000000001' + 'target_id_usb_id': 'A000000001', + 'vendor_id': '0d28', + 'product_id': '0204' }, mbed_det) self.assertIn({ 'mount_point': '/media/usb2', 'serial_port': '/dev/ttyACM2', - 'target_id_usb_id': '0672FF485649785087171742' + 'target_id_usb_id': '0672FF485649785087171742', + 'vendor_id': '0d28', + 'product_id': '0204' }, mbed_det) self.assertIn({ 'mount_point': '/media/usb4', 'serial_port': '/dev/ttyACM4', - 'target_id_usb_id': '0240020152A06E54AF5E93EC' + 'target_id_usb_id': '0240020152A06E54AF5E93EC', + 'vendor_id': '0d28', + 'product_id': '0204' }, mbed_det) self.assertIn({ 'mount_point': '/media/usb3', 'serial_port': '/dev/ttyACM3', - 'target_id_usb_id': '02400201489A1E6CB564E3D4' + 'target_id_usb_id': '02400201489A1E6CB564E3D4', + 'vendor_id': '0d28', + 'product_id': '0204' }, mbed_det) self.assertIn({ 'mount_point': '/media/usb0', 'serial_port': '/dev/ttyACM1', - 'target_id_usb_id': '0240020152986E5EAF6693E6' + 'target_id_usb_id': '0240020152986E5EAF6693E6', + 'vendor_id': '0d28', + 'product_id': '0204' }, mbed_det) @@ -334,14 +483,27 @@ def test_get_detected_2_k64f(self): ], '/dev/serial/by-id': [ 'pci-ARM_DAPLink_CMSIS-DAP_0240000033514e45001f500585d40014e981000097969900-if01' - ] + ], + '/sys/class/block': [ + 'sdb' + ], + '/sys/class/block/../../devices/pci0000:00/0000:00:06.0/usb1/1-2': [ + 'idVendor', + 'idProduct' + ], + } + + open_dict_4 = { + '/sys/class/block/../../devices/pci0000:00/0000:00:06.0/usb1/1-2/idVendor': '0d28\n', + '/sys/class/block/../../devices/pci0000:00/0000:00:06.0/usb1/1-2/idProduct': '0204\n' } link_dict_4 = { '/dev/disk/by-id/ata-VMware_Virtual_SATA_CDRW_Drive_00000000000000000001': '../../sr0', '/dev/disk/by-id/ata-VMware_Virtual_SATA_CDRW_Drive_01000000000000000001': '../../sr1', '/dev/disk/by-id/usb-MBED_VFS_0240000033514e45001f500585d40014e981000097969900-0:0': '../../sdb', - '/dev/serial/by-id/pci-ARM_DAPLink_CMSIS-DAP_0240000033514e45001f500585d40014e981000097969900-if01': '../../ttyACM0' + '/dev/serial/by-id/pci-ARM_DAPLink_CMSIS-DAP_0240000033514e45001f500585d40014e981000097969900-if01': '../../ttyACM0', + '/sys/class/block/sdb': '../../devices/pci0000:00/0000:00:06.0/usb1/1-2/1-2:1.0/host3/target3:0:0/3:0:0:0/block/sdb' } mount_list_4 = [ @@ -349,12 +511,14 @@ def test_get_detected_2_k64f(self): ] def test_get_detected_3_k64f(self): mbed_det = self.find_candidates_with_patch( - self.mount_list_4, self.link_dict_4, self.listdir_dict_4) + self.mount_list_4, self.link_dict_4, self.listdir_dict_4, self.open_dict_4) self.assertIn({ 'mount_point': '/media/przemek/DAPLINK', 'serial_port': '/dev/ttyACM0', - 'target_id_usb_id': '0240000033514e45001f500585d40014e981000097969900' + 'target_id_usb_id': '0240000033514e45001f500585d40014e981000097969900', + 'vendor_id': '0d28', + 'product_id': '0204' }, mbed_det) diff --git a/test/os_win7.py b/test/os_win7.py index 6040d43..2ad9ff2 100644 --- a/test/os_win7.py +++ b/test/os_win7.py @@ -381,7 +381,9 @@ def test_one_composite_dev(self): expected_info = { 'mount_point': 'F:', 'serial_port': 'COM7', - 'target_id_usb_id': u'0240000032044e4500257009997b00386781000097969900' + 'target_id_usb_id': u'0240000032044e4500257009997b00386781000097969900', + 'vendor_id': '0d28', + 'product_id': '0204' } devices = self.lstool.find_candidates() @@ -417,7 +419,9 @@ def test_one_non_composite_dev(self): expected_info = { 'mount_point': 'F:', 'serial_port': None, - 'target_id_usb_id': u'0000000032044e4500257009997b00386781000097969900' + 'target_id_usb_id': u'0000000032044e4500257009997b00386781000097969900', + 'vendor_id': '0d28', + 'product_id': '0204' } devices = self.lstool.find_candidates()