blob: 1b996fce9b373a164f8b3385413522b0185adbfb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
/***************************************************************************/
/* Copyright (c) 2024 Microsoft Corporation */
/* Copyright (c) 2026 Eclipse ThreadX contributors */
/* */
/* This program and the accompanying materials are made available under */
/* the terms of the MIT License which is available at */
/* https://opensource.org/licenses/MIT. */
/* */
/* SPDX-License-Identifier: MIT */
/***************************************************************************/
/* This tests the case where the length of the hub descriptor is invalid. The
exact test case is in ux_host_class_hub_descriptor_get.c. */
#include "usbx_ux_test_hub.h"
static DEVICE_INIT_DATA device_init_data = {
.dont_enumerate = 1
};
#ifdef CTEST
void test_application_define(void *first_unused_memory)
#else
void usbx_hub_invalid_hub_descriptor_length_test_application_define(void *first_unused_memory)
#endif
{
/* Inform user. */
printf("Running Hub Invalid Hub Descriptor Length Test...................... ");
stepinfo("\n");
initialize_hub_with_device_init_data(first_unused_memory, &device_init_data);
}
static void post_init_host()
{
int i;
/* Setup setup for matching the GET_DESCRIPTOR for hub request. */
UX_TEST_SETUP setup = {0};
setup.ux_test_setup_request = UX_HOST_CLASS_HUB_GET_DESCRIPTOR;
setup.ux_test_setup_type = UX_REQUEST_IN | UX_REQUEST_TYPE_CLASS | UX_REQUEST_TARGET_DEVICE;
setup.ux_test_setup_value = (UX_HUB_DESCRIPTOR_ITEM << 8);
setup.ux_test_setup_index = 0;
/* Make action to make the length invalid. */
UX_TEST_ACTION action = {0};
action.usbx_function = UX_TEST_OVERRIDE_UX_HCD_SIM_HOST_ENTRY;
action.function = UX_HCD_TRANSFER_REQUEST;
action.req_action = UX_TEST_SETUP_MATCH_REQUEST | UX_TEST_SIM_REQ_ANSWER;
action.req_setup = &setup;
action.req_ep_address = 0x81;
action.req_actual_len = 1; /* Invalid length. */
action.no_return = 0;
action.status = UX_SUCCESS;
/* We expect error to happen multiple times. */
for (i = 0; i < UX_RH_ENUMERATION_RETRY; i++)
{
ux_test_add_action_to_main_list(action);
ux_test_add_action_to_main_list(create_error_match_action(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_HUB, UX_DESCRIPTOR_CORRUPTED));
}
ux_test_add_action_to_main_list(create_error_match_action(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_ROOT_HUB, UX_DEVICE_ENUMERATION_FAILURE));
/* Enumerate. */
UX_TEST_CHECK_SUCCESS(ux_host_stack_hcd_register(_ux_system_host_hcd_simulator_name, _ux_test_hcd_sim_host_initialize, 0, 0));
ux_test_wait_for_enum_thread_completion();
/* Ensure all expected actions occurred. */
UX_TEST_ASSERT(ux_test_check_actions_empty());
UX_TEST_ASSERT(g_hub_host_from_system_change_function == UX_NULL);
}
static void post_init_device()
{
}
|