Skip to content

Commit 67c5d37

Browse files
Merge branch 'feat/usb_host_create_usb_cmock' into 'master'
feat(usb_host): Create USB Host mock for CMock host tests Closes IDF-11234 See merge request espressif/esp-idf!33619
2 parents 70ff700 + d071bb4 commit 67c5d37

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

components/usb/usb_helpers.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -27,7 +27,7 @@ const usb_standard_desc_t *usb_parse_next_descriptor(const usb_standard_desc_t *
2727
return NULL; // Next descriptor is out of bounds
2828
}
2929
// Return the next descriptor, update offset
30-
const usb_standard_desc_t *ret_desc = (const usb_standard_desc_t *)(((uint32_t)cur_desc) + cur_desc->bLength);
30+
const usb_standard_desc_t *ret_desc = (const usb_standard_desc_t *)(((uintptr_t)cur_desc) + cur_desc->bLength);
3131
*offset += cur_desc->bLength;
3232
return ret_desc;
3333
}

tools/mocks/usb/CMakeLists.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# NOTE: This kind of mocking currently works on Linux targets only.
2+
# On Espressif chips, too many dependencies are missing at the moment.
3+
message(STATUS "building USB HOST MOCKS")
4+
5+
idf_component_get_property(original_usb_dir usb COMPONENT_OVERRIDEN_DIR)
6+
7+
idf_component_mock(INCLUDE_DIRS "${original_usb_dir}/include"
8+
"${original_usb_dir}/include/esp_private"
9+
"${original_usb_dir}/include/usb"
10+
"${original_usb_dir}/private_include"
11+
MOCK_HEADER_FILES ${original_usb_dir}/include/usb/usb_host.h
12+
${original_usb_dir}/include/esp_private/usb_phy.h
13+
REQUIRES freertos)
14+
15+
16+
# We do not mock usb_helpers. We use the original implementation.
17+
# This way, we can test Class drivers descriptor parsing
18+
target_sources(${COMPONENT_LIB} PRIVATE "${original_usb_dir}/usb_helpers.c")
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
:cmock:
2+
:plugins:
3+
- expect
4+
- expect_any_args
5+
- return_thru_ptr
6+
- ignore
7+
- ignore_arg

0 commit comments

Comments
 (0)