Skip to content

Commit d0954c9

Browse files
author
Josuah Demangeon
committed
tests: usb: host: test basic API functionality
Add tests making sure the USB Host class APIs introduced build and run as expected. Signed-off-by: Josuah Demangeon <[email protected]>
1 parent 56e2e84 commit d0954c9

20 files changed

+706
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Copyright (c) 2025 Nordic Semiconductor ASA
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
cmake_minimum_required(VERSION 3.20.0)
5+
6+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
7+
project(test_usb_host)
8+
9+
target_include_directories(app PRIVATE ${ZEPHYR_BASE}/subsys/usb/host)
10+
target_include_directories(app PRIVATE ${ZEPHYR_BASE}/tests/subsys/usb/host/common/include)
11+
12+
target_sources(app PRIVATE src/main.c)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CONFIG_SYS_CLOCK_TICKS_PER_SEC=1000000
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Copyright (c) 2023 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/delete-node/ &zephyr_udc0;
8+
9+
/ {
10+
zephyr_uhc0: uhc_vrt0 {
11+
compatible = "zephyr,uhc-virtual";
12+
13+
zephyr_udc0: udc_vrt0 {
14+
compatible = "zephyr,udc-virtual";
15+
num-bidir-endpoints = <8>;
16+
maximum-speed = "high-speed";
17+
};
18+
};
19+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CONFIG_SYS_CLOCK_TICKS_PER_SEC=1000000
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include "native_sim.overlay"
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* Copyright (c) 2023 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/ {
8+
zephyr_uhc0: uhc_vrt0 {
9+
compatible = "zephyr,uhc-virtual";
10+
11+
zephyr_udc0: udc_vrt0 {
12+
compatible = "zephyr,udc-virtual";
13+
num-bidir-endpoints = <8>;
14+
maximum-speed = "high-speed";
15+
};
16+
};
17+
};
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#ifndef ZEPHYR_TEST_USB_HOST_SAMPLE_DESC_H_
8+
#define ZEPHYR_TEST_USB_HOST_SAMPLE_DESC_H_
9+
10+
#include <stddef.h>
11+
#include <stdint.h>
12+
13+
#define _LE16(n) ((n) & 0xff), ((n) >> 8)
14+
15+
/*
16+
* Obtained with lsusb then verified against the
17+
* USB 2.0 standard's sample HUB descriptor
18+
*/
19+
20+
#define TEST_HUB_DEVICE_DESCRIPTOR \
21+
18, /* bLength */ \
22+
1, /* bDescriptorType */ \
23+
_LE16(0x0200), /* bcdUSB */ \
24+
0x09, /* bDeviceClass */ \
25+
0x00, /* bDeviceSubClass */ \
26+
0x02, /* bDeviceProtocol */ \
27+
64, /* bMaxPacketSize0 */ \
28+
_LE16(0x0bda), /* idVendor */ \
29+
_LE16(0x5411), /* idProduct */ \
30+
_LE16(0x0001), /* bcdDevice */ \
31+
0, /* iManufacturer */ \
32+
0, /* iProduct */ \
33+
0, /* iSerial */ \
34+
1, /* bNumConfigurations */
35+
36+
#define TEST_HUB_CONFIG_DESCRIPTOR \
37+
9, /* bLength */ \
38+
2, /* bDescriptorType */ \
39+
_LE16(0x0029), /* wTotalLength */ \
40+
1, /* bNumInterfaces */ \
41+
1, /* bConfigurationValue */ \
42+
0, /* iConfiguration */ \
43+
0xe0, /* bmAttributes */ \
44+
0, /* MaxPower */
45+
46+
#define TEST_HUB_INTERFACE_ALT0_DESCRIPTOR \
47+
9, /* bLength */ \
48+
4, /* bDescriptorType */ \
49+
0, /* bInterfaceNumber */ \
50+
0, /* bAlternateSetting */ \
51+
1, /* bNumEndpoints */ \
52+
9, /* bInterfaceClass */ \
53+
0, /* bInterfaceSubClass */ \
54+
1, /* bInterfaceProtocol */ \
55+
0, /* iInterface */
56+
57+
#define TEST_HUB_INTERFACE_ALT1_DESCRIPTOR \
58+
9, /* bLength */ \
59+
4, /* bDescriptorType */ \
60+
0, /* bInterfaceNumber */ \
61+
1, /* bAlternateSetting */ \
62+
1, /* bNumEndpoints */ \
63+
9, /* bInterfaceClass */ \
64+
0, /* bInterfaceSubClass */ \
65+
2, /* bInterfaceProtocol */ \
66+
0, /* iInterface */
67+
68+
#define TEST_HUB_ENDPOINT_DESCRIPTOR \
69+
7, /* bLength */ \
70+
5, /* bDescriptorType */ \
71+
0x81, /* bEndpointAddress */ \
72+
0x03, /* bmAttributes */ \
73+
_LE16(1), /* wMaxPacketSize */ \
74+
12, /* bInterval */
75+
76+
#define TEST_HUB_DESCRIPTOR \
77+
TEST_HUB_DEVICE_DESCRIPTOR \
78+
TEST_HUB_CONFIG_DESCRIPTOR \
79+
TEST_HUB_INTERFACE_ALT0_DESCRIPTOR \
80+
TEST_HUB_ENDPOINT_DESCRIPTOR \
81+
TEST_HUB_INTERFACE_ALT1_DESCRIPTOR \
82+
TEST_HUB_ENDPOINT_DESCRIPTOR
83+
84+
#endif /* ZEPHYR_TEST_USB_HOST_SAMPLE_DESC_H_ */
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Copyright (c) 2025 Nordic Semiconductor ASA
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
CONFIG_LOG=y
5+
CONFIG_ZTEST=y
6+
7+
CONFIG_USB_HOST_STACK=y
8+
CONFIG_UHC_DRIVER=y

0 commit comments

Comments
 (0)