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