1 /* This tests the case where the bulk in transfer fails (in the cdc-ecm thread). */
2 
3 #include "usbx_ux_test_cdc_ecm.h"
4 
5 /* Define what the initial system looks like.  */
6 #ifdef CTEST
test_application_define(void * first_unused_memory)7 void test_application_define(void *first_unused_memory)
8 #else
9 void usbx_cdc_ecm_host_bulk_in_transfer_fail_test_application_define(void *first_unused_memory)
10 #endif
11 {
12 
13     /* Inform user.  */
14     printf("Running CDC-ECM Host Bulk In Transfer Fail Test..................... ");
15 
16     stepinfo("\n");
17 
18     ux_test_cdc_ecm_initialize(first_unused_memory);
19 }
20 
21 static UCHAR is_cdc_ecm_thread_suspended;
22 
suspend_cdc_ecm_thread_action_func(UX_TEST_ACTION * action,VOID * params)23 static VOID suspend_cdc_ecm_thread_action_func(UX_TEST_ACTION *action, VOID *params)
24 {
25 
26     is_cdc_ecm_thread_suspended = 1;
27 
28     /* We're being called by nx_packet_allocate in cdc-ecm thread. Wait for test
29        thread to resume us. */
30     tx_thread_suspend(tx_thread_identify());
31 }
32 
post_init_host()33 static void post_init_host()
34 {
35 
36     /* Currently, the cdc-ecm thread should be waiting for a transfer to complete.
37        We need to create an action for having the bulk in transfer fail, add
38        the action, then send data to host so the cdc-ecm thread will re-arm the
39        transfer (which should fail). */
40 
41     /* Create the action for having bulk in transfer fail. */
42     UX_TEST_ACTION bulk_transfer_fail_action = {0};
43     bulk_transfer_fail_action.usbx_function = UX_TEST_OVERRIDE_UX_HCD_SIM_HOST_ENTRY;
44     bulk_transfer_fail_action.function = UX_HCD_TRANSFER_REQUEST;
45     bulk_transfer_fail_action.req_action = UX_TEST_MATCH_EP;
46     bulk_transfer_fail_action.req_ep_address = 0x81;
47     bulk_transfer_fail_action.no_return = 0;
48     bulk_transfer_fail_action.status = UX_ERROR;
49     ux_test_add_action_to_main_list(bulk_transfer_fail_action);
50 
51     /* Write to the host so the cdc-ecm thread will redo the bulk in transfer. */
52     write_packet_udp(&udp_socket_device, &packet_pool_device, HOST_IP_ADDRESS, HOST_SOCKET_PORT_UDP, 0, "device");
53 
54     /* Wait for the arm and fail. */
55     UX_TEST_CHECK_SUCCESS(ux_test_wait_for_empty_actions());
56 
57     /* Wait for the host to re-arm and wait for the transfer. */
58     UX_TEST_CHECK_SUCCESS(ux_test_wait_for_value_uint(&cdc_ecm_host->ux_host_class_cdc_ecm_bulk_in_endpoint->ux_endpoint_transfer_request.ux_transfer_request_semaphore.tx_semaphore_suspended_count, 1));
59 
60     /* Now we're done. */
61 }
62 
post_init_device()63 static void post_init_device()
64 {
65 }
66