Page MenuHomeFreeBSD

PR 291774: expand range of errors reported by libusb_open(3)
Needs ReviewPublic

Authored by unitrunker_unitrunker.net on Thu, Dec 18, 8:32 PM.
Tags
None
Referenced Files
F140191982: D54296.id168364.diff
Sun, Dec 21, 7:20 AM
F140167488: D54296.diff
Sun, Dec 21, 1:36 AM
F140138455: D54296.id168364.diff
Sat, Dec 20, 6:05 PM
Unknown Object (File)
Fri, Dec 19, 9:52 AM
Unknown Object (File)
Fri, Dec 19, 7:01 AM
Unknown Object (File)
Thu, Dec 18, 9:24 PM
Subscribers

Details

Reviewers
aokblast
markj
lwhsu
Group Reviewers
USB
Summary

Expand the range of errors reported by libusb_open.

Currently, libusb_open reports LIBUSB_SUCCESS and LIBUSB_ERROR_NO_MEM. The latter is, in most cases, misleading. A failure is more likely to be permissions or a device that is in use elsewhere. Conveying the issue to the client software, and ultimately to the user gives the user the opportunity to better diagnose and remedy the problem.

Test Plan

Tests

  1. LIBUSB_ERROR_BUSY - open the same device twice
  2. LIBUSB_ERROR_NO_DEVICE - get list of devices, pause, unplug device, attempt to open the unplugged device.
  3. LIBUSB_ERROR_ACCESS - get list of devices, pause, alter permissions on the device node, attempt to open a device.
  4. LIBUSB_ERROR_INVALID_PARAM - pass a null device handle.
  5. LIBUSB_ERROR_NO_MEM - get list of devices, pause, simulate heap full, attempt to open a device.

A program covering the above tests - included in Bugzilla - has been run against actual hardware to verify correctness.

https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=291774

Update: a set of twenty one unit tests added. These can be run from kyua and do not require physical hardware.

usb_opener_atf/build $ kyua test
usb_opener:test_case_libusb20_access -> passed [0.002s]
usb_opener:test_case_libusb20_busy -> passed [0.002s]
usb_opener:test_case_libusb20_invalid -> passed [0.002s]
usb_opener:test_case_libusb20_no_device -> passed [0.002s]
usb_opener:test_case_libusb20_no_mem -> passed [0.002s]
usb_opener:test_case_libusb20_other -> passed [0.002s]
usb_opener:test_case_libusb20_success -> passed [0.002s]
usb_opener:test_case_libusb_access -> passed [0.002s]
usb_opener:test_case_libusb_busy -> passed [0.002s]
usb_opener:test_case_libusb_invalid -> passed [0.002s]
usb_opener:test_case_libusb_no_device -> passed [0.002s]
usb_opener:test_case_libusb_no_mem -> passed [0.002s]
usb_opener:test_case_libusb_other -> passed [0.002s]
usb_opener:test_case_libusb_success -> passed [0.003s]
usb_opener:test_case_libusb_with_vid_pid_access -> passed [0.002s]
usb_opener:test_case_libusb_with_vid_pid_busy -> passed [0.002s]
usb_opener:test_case_libusb_with_vid_pid_invalid -> passed [0.002s]
usb_opener:test_case_libusb_with_vid_pid_no_device -> passed [0.002s]
usb_opener:test_case_libusb_with_vid_pid_no_mem -> passed [0.002s]
usb_opener:test_case_libusb_with_vid_pid_other -> passed [0.002s]
usb_opener:test_case_libusb_with_vid_pid_success -> passed [0.002s]

Results file id is usb_opener_atf_build.20251220-103547-089277
Results saved to ~/.kyua/store/results.usb_opener_atf_build.20251220-103547-089277.db

21/21 passed (0 broken, 0 failed, 0 skipped)

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 69394
Build 66277: arc lint + arc unit

Event Timeline

unitrunker_unitrunker.net retitled this revision from Bug 291774: libusb_open errors to Bug 291774: expand range of errors reported by libusb_open(3).Thu, Dec 18, 11:05 PM

D54296: Bug 291774: expand range of errors reported by libusb_open(3)
Unexpected one-line fix to backend.

The BUSY test currently fails because we're are blocked by D54218. Currently, opening the same device twice (via a different backend or dev-list) isn't an error. I'm proposing we proceed as-is. If/when D54218 is accepted, this code need not change.

For test #5 above, the unit test "hooks" malloc - using dlsym to force a NULL return on demand to simulate a "NO MEM" condition.

unitrunker_unitrunker.net retitled this revision from Bug 291774: expand range of errors reported by libusb_open(3) to PR 291774: expand range of errors reported by libusb_open(3).Fri, Dec 19, 5:07 PM
unitrunker_unitrunker.net edited the summary of this revision. (Show Details)
unitrunker_unitrunker.net edited the test plan for this revision. (Show Details)
unitrunker_unitrunker.net edited the summary of this revision. (Show Details)
unitrunker_unitrunker.net edited the test plan for this revision. (Show Details)

I have no idea about USB code

lib/libusb/libusb20_ugen20.c
396
unitrunker_unitrunker.net edited the test plan for this revision. (Show Details)

D54296: PR 291774: expand range of errors reported by libusb_open(3)
line too long

D54296: PR 291774: expand range of errors reported by libusb_open(3)
Kyua unit tests included in build

Repository

rG FreeBSD src repository

Lint

Lint Passed

Unit

**No Test Coverage**	<-- this

Build Status

Buildable 69414	
Build 66297: arc lint + arc unit

Clearly I have test coverage. No idea how to get phabricator to show that.