tools/usb/testusb.c
Source file repositories/reference/linux-study-clean/tools/usb/testusb.c
File Facts
- System
- Linux kernel
- Corpus path
tools/usb/testusb.c- Extension
.c- Size
- 12656 bytes
- Lines
- 535
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
stdio.hstring.hftw.hstdlib.hpthread.hunistd.herrno.hlimits.hsys/types.hsys/stat.hfcntl.hsys/ioctl.hlinux/usbdevice_fs.h
Detected Declarations
struct usbtest_paramstruct usb_device_descriptorstruct usb_interface_descriptorstruct testdevenum usb_device_speedfunction testdev_ffs_ifnumfunction testdev_ifnumfunction find_testdevfunction usbdev_ioctlfunction parse_numfunction main
Annotated Snippet
struct usbtest_param {
// inputs
unsigned test_num; /* 0..(TEST_CASES-1) */
unsigned iterations;
unsigned length;
unsigned vary;
unsigned sglen;
// outputs
struct timeval duration;
};
#define USBTEST_REQUEST _IOWR('U', 100, struct usbtest_param)
/*-------------------------------------------------------------------------*/
/* #include <linux/usb_ch9.h> */
#define USB_DT_DEVICE 0x01
#define USB_DT_INTERFACE 0x04
#define USB_CLASS_PER_INTERFACE 0 /* for DeviceClass */
#define USB_CLASS_VENDOR_SPEC 0xff
struct usb_device_descriptor {
__u8 bLength;
__u8 bDescriptorType;
__u16 bcdUSB;
__u8 bDeviceClass;
__u8 bDeviceSubClass;
__u8 bDeviceProtocol;
__u8 bMaxPacketSize0;
__u16 idVendor;
__u16 idProduct;
__u16 bcdDevice;
__u8 iManufacturer;
__u8 iProduct;
__u8 iSerialNumber;
__u8 bNumConfigurations;
} __attribute__ ((packed));
struct usb_interface_descriptor {
__u8 bLength;
__u8 bDescriptorType;
__u8 bInterfaceNumber;
__u8 bAlternateSetting;
__u8 bNumEndpoints;
__u8 bInterfaceClass;
__u8 bInterfaceSubClass;
__u8 bInterfaceProtocol;
__u8 iInterface;
} __attribute__ ((packed));
enum usb_device_speed {
USB_SPEED_UNKNOWN = 0, /* enumerating */
USB_SPEED_LOW, USB_SPEED_FULL, /* usb 1.1 */
USB_SPEED_HIGH, /* usb 2.0 */
USB_SPEED_WIRELESS, /* wireless (usb 2.5) */
USB_SPEED_SUPER, /* usb 3.0 */
USB_SPEED_SUPER_PLUS, /* usb 3.1 */
};
/*-------------------------------------------------------------------------*/
static char *speed (enum usb_device_speed s)
{
switch (s) {
case USB_SPEED_UNKNOWN: return "unknown";
case USB_SPEED_LOW: return "low";
case USB_SPEED_FULL: return "full";
case USB_SPEED_HIGH: return "high";
case USB_SPEED_WIRELESS: return "wireless";
case USB_SPEED_SUPER: return "super";
case USB_SPEED_SUPER_PLUS: return "super-plus";
default: return "??";
}
}
struct testdev {
struct testdev *next;
char *name;
pthread_t thread;
enum usb_device_speed speed;
unsigned ifnum : 8;
unsigned forever : 1;
int test;
struct usbtest_param param;
};
Annotation
- Immediate include surface: `stdio.h`, `string.h`, `ftw.h`, `stdlib.h`, `pthread.h`, `unistd.h`, `errno.h`, `limits.h`.
- Detected declarations: `struct usbtest_param`, `struct usb_device_descriptor`, `struct usb_interface_descriptor`, `struct testdev`, `enum usb_device_speed`, `function testdev_ffs_ifnum`, `function testdev_ifnum`, `function find_testdev`, `function usbdev_ioctl`, `function parse_num`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.