1 /* Include necessary system files.  */
2 
3 #include "usbx_ux_test_cdc_ecm.h"
4 
5 static ULONG                error_callback_counter;
6 
count_error_callback(struct UX_TEST_ACTION_STRUCT * action,VOID * params)7 static void count_error_callback(struct UX_TEST_ACTION_STRUCT *action, VOID *params)
8 {
9 UX_TEST_ERROR_CALLBACK_PARAMS *error = (UX_TEST_ERROR_CALLBACK_PARAMS *)params;
10 
11     // printf("error trap #%d: 0x%x, 0x%x, 0x%x\n", __LINE__, error->system_level, error->system_context, error->error_code);
12     error_callback_counter ++;
13 }
14 
15 static UX_TEST_HCD_SIM_ACTION count_on_error_trap[] = {
16 {   .usbx_function = UX_TEST_OVERRIDE_ERROR_CALLBACK,
17     .action_func = count_error_callback,
18 },
19 {   0   }
20 };
21 
22 static UX_TEST_ACTION bulk_transfer_replace[] =
23 {
24     {
25         .usbx_function = UX_TEST_OVERRIDE_UX_DCD_SIM_SLAVE_FUNCTION,
26         .function = UX_DCD_TRANSFER_REQUEST,
27         .req_setup = UX_NULL,
28         .req_action = UX_TEST_MATCH_EP | UX_TEST_SIM_REQ_ANSWER,
29         .req_ep_address = 0x81,
30         .req_actual_len = 0,
31         .req_status = UX_SUCCESS,
32         .status = UX_SUCCESS,
33         .do_after = UX_FALSE,
34         .no_return = UX_FALSE,
35     },
36     {
37         .usbx_function = UX_TEST_OVERRIDE_UX_DCD_SIM_SLAVE_FUNCTION,
38         .function = UX_DCD_TRANSFER_REQUEST,
39         .req_setup = UX_NULL,
40         .req_action = UX_TEST_MATCH_EP | UX_TEST_SIM_REQ_ANSWER,
41         .req_ep_address = 0x81,
42         .req_actual_len = 0,
43         .req_status = UX_SUCCESS,
44         .status = UX_SUCCESS,
45         .do_after = UX_FALSE,
46         .no_return = UX_FALSE,
47     },
48 { 0 },
49 };
50 
51 
52 /* Define what the initial system looks like.  */
53 #ifdef CTEST
test_application_define(void * first_unused_memory)54 void test_application_define(void *first_unused_memory)
55 #else
56 void usbx_ux_device_class_cdc_ecm_bulkin_thread_test_application_define(void *first_unused_memory)
57 #endif
58 {
59 
60     /* Inform user.  */
61     printf("Running ux_device_class_cdc_ecm_bulkin_thread Test.................. ");
62 
63     stepinfo("\n");
64 
65     /* Override error trap. */
66     ux_test_link_hooks_from_array(count_on_error_trap);
67 
68     ux_test_cdc_ecm_initialize(first_unused_memory);
69 }
70 
post_init_host()71 static void post_init_host()
72 {
73 
74 ULONG              link_state[] = {0,1,2,3,0,1};
75 UINT               i;
76 UCHAR              buffer[64];
77 NX_PACKET          packet = {0};
78 
79     /* Point the prepend ptr to some valid memory so there's no crash. */
80     packet.nx_packet_prepend_ptr = buffer;
81 
82     stepinfo(">>>>>>>>>>>>>>>>>>> Test activate check\n");
83     UX_TEST_ASSERT(cdc_ecm_device != UX_NULL);
84 
85     /* Disable the other threads.  */
86     // _ux_utility_thread_suspend(&cdc_ecm_device->ux_slave_class_cdc_ecm_bulkin_thread);
87     _ux_utility_thread_suspend(&cdc_ecm_device->ux_slave_class_cdc_ecm_bulkout_thread);
88     _ux_utility_thread_suspend(&cdc_ecm_device->ux_slave_class_cdc_ecm_interrupt_thread);
89 
90 #if 0
91     stepinfo(">>>>>>>>>>>>>>>>>>> Test endpoint closed\n");
92     ep = cdc_ecm_device->ux_slave_class_cdc_ecm_bulkin_endpoint;
93     cdc_ecm_device->ux_slave_class_cdc_ecm_bulkin_endpoint = UX_NULL;
94     _ux_utility_event_flags_set(&cdc_ecm_device -> ux_slave_class_cdc_ecm_event_flags_group, UX_DEVICE_CLASS_CDC_ECM_NEW_DEVICE_STATE_CHANGE_EVENT, TX_OR);
95     _ux_utility_thread_sleep(2);
96     cdc_ecm_device->ux_slave_class_cdc_ecm_bulkin_endpoint = ep;
97     _ux_utility_thread_resume(&cdc_ecm_device->ux_slave_class_cdc_ecm_bulkin_thread);
98 #endif
99 
100     i = (cdc_ecm_device -> ux_slave_class_cdc_ecm_link_state == 0) ? 1 : 0;
101     for (;i < 5; i ++)
102     {
103 
104         stepinfo(">>>>>>>>>>>>>>>>>>> Test %d write length overflow\n", i);
105         packet.nx_packet_length = 1 + UX_SLAVE_REQUEST_DATA_MAX_LENGTH;
106         ux_device_class_cdc_ecm_write(cdc_ecm_device, &packet);
107 
108         stepinfo(">>>>>>>>>>>>>>>>>>> Test %d bulkin UX_ERROR\n", i);
109         bulk_transfer_replace[0].req_status = UX_ERROR;
110         bulk_transfer_replace[0].status = UX_ERROR;
111         bulk_transfer_replace[1].req_status = UX_ERROR;
112         bulk_transfer_replace[1].status = UX_ERROR;
113         ux_test_dcd_sim_slave_set_actions(bulk_transfer_replace);
114         error_callback_counter = 0;
115         packet.nx_packet_length = 1;
116         ux_device_class_cdc_ecm_write(cdc_ecm_device, &packet);
117         _ux_utility_thread_sleep(2);
118         if (cdc_ecm_device -> ux_slave_class_cdc_ecm_link_state == UX_DEVICE_CLASS_CDC_ECM_LINK_STATE_UP)
119             UX_TEST_ASSERT(error_callback_counter);
120 
121         stepinfo(">>>>>>>>>>>>>>>>>>> Test %d bulkin UX_TRANSFER_BUS_RESET\n", i);
122         bulk_transfer_replace[0].req_status = UX_TRANSFER_BUS_RESET;
123         bulk_transfer_replace[0].status = UX_TRANSFER_BUS_RESET;
124         bulk_transfer_replace[1].req_status = UX_TRANSFER_BUS_RESET;
125         bulk_transfer_replace[1].status = UX_TRANSFER_BUS_RESET;
126         ux_test_dcd_sim_slave_set_actions(bulk_transfer_replace);
127         packet.nx_packet_length = 1;
128         ux_device_class_cdc_ecm_write(cdc_ecm_device, &packet);
129         _ux_utility_thread_sleep(2);
130 
131         stepinfo(">>>>>>>>>>>>>>>>>>> Test %d link state change\n", i);
132         cdc_ecm_device -> ux_slave_class_cdc_ecm_link_state = link_state[i];
133         if (i & 1)
134             cdc_ecm_device -> ux_slave_class_cdc_ecm_xmit_queue = &packet;
135         _ux_utility_event_flags_set(&cdc_ecm_device -> ux_slave_class_cdc_ecm_event_flags_group, UX_DEVICE_CLASS_CDC_ECM_NEW_BULKIN_EVENT, TX_OR);
136         if (i & 1)
137             cdc_ecm_device -> ux_slave_class_cdc_ecm_xmit_queue = &packet;
138         _ux_utility_event_flags_set(&cdc_ecm_device -> ux_slave_class_cdc_ecm_event_flags_group, UX_DEVICE_CLASS_CDC_ECM_NEW_DEVICE_STATE_CHANGE_EVENT, TX_OR);
139         _ux_utility_thread_sleep(2);
140     }
141 
142     // stepinfo(">>>>>>>>>>>>>>>>>>> Test connect to avoid post post operation\n");
143     // /* Connect. */
144     // ux_test_dcd_sim_slave_connect(UX_FULL_SPEED_DEVICE);
145     // ux_test_hcd_sim_host_connect(UX_FULL_SPEED_DEVICE);
146     // class_cdc_ecm_get_host();
147 
148     stepinfo(">>>>>>>>>>>>>>>>>>> post_init_host done\n");
149 }
150 
post_init_device()151 static void post_init_device()
152 {
153     stepinfo(">>>>>>>>>>>>>>>>>>> post_init_device empty\n");
154 }