Skip to content

Commit 2139de2

Browse files
author
Rich Barlow
committed
Fix getting of extra descriptors
Also add a test to check that getting of extra descriptors works (requires a USB device with extra descriptors, such as a UVC webcam, which has at least one InterfaceAssociation descriptor).
1 parent 4826b68 commit 2139de2

2 files changed

Lines changed: 17 additions & 3 deletions

File tree

usb1/libusb1.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1103,7 +1103,7 @@ def get_extra(descriptor):
11031103
result = []
11041104
extra_length = descriptor.extra_length
11051105
if extra_length:
1106-
extra = buffer_at(descriptor.extra.value, extra_length)
1106+
extra = buffer_at(descriptor.extra, extra_length)
11071107
append = result.append
11081108
while extra:
11091109
length = _string_item_to_int(extra[0])

usb1/testUSB1.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,15 +244,15 @@ def exceptionHandler(exc):
244244
self.assertTrue(exception_list, exception_list)
245245
self.assertTrue(poller.is_alive())
246246

247-
@staticmethod
248-
def testDescriptors():
247+
def _testDescriptors(self, get_extra=False):
249248
"""
250249
Test descriptor walk.
251250
Needs any usb device, which won't be opened.
252251
"""
253252
with USBContext() as context:
254253
device_list = context.getDeviceList(skip_on_error=True)
255254
found = False
255+
seen_extra = False
256256
for device in device_list:
257257
device.getBusNumber()
258258
device.getPortNumber()
@@ -262,12 +262,26 @@ def testDescriptors():
262262
for endpoint in settings:
263263
pass
264264
for configuration in device.iterConfigurations():
265+
if get_extra and len(configuration.getExtra()) > 0:
266+
seen_extra = True
265267
for interface in configuration:
266268
for settings in interface:
269+
if get_extra and len(settings.getExtra()) > 0:
270+
seen_extra = True
267271
for endpoint in settings:
272+
if get_extra and len(endpoint.getExtra()) > 0:
273+
seen_extra = True
268274
found = True
269275
if not found:
270276
raise unittest.SkipTest('descriptor walk test did not complete')
277+
if get_extra and not seen_extra:
278+
raise unittest.SkipTest('did not see any extra descriptors')
279+
280+
def testDescriptors(self):
281+
self._testDescriptors()
282+
283+
def testDescriptorsWithExtra(self):
284+
self._testDescriptors(get_extra=True)
271285

272286
def testDefaultEnumScope(self):
273287
"""

0 commit comments

Comments
 (0)