1 /* This tests the case the nx_packet_allocate fails in the cdc-ecm thread. */
2 
3 #define TEST_NX_PACKET_CHAIN
4 #include "usbx_ux_test_cdc_ecm.h"
5 
6 /* Define what the initial system looks like.  */
7 #ifdef CTEST
test_application_define(void * first_unused_memory)8 void test_application_define(void *first_unused_memory)
9 #else
10 void usbx_cdc_ecm_host_thread_packet_allocate_fail_test_application_define(void *first_unused_memory)
11 #endif
12 {
13 
14     /* Inform user.  */
15     printf("Running CDC-ECM Host Thread Packet Append Fail Test................. ");
16     stepinfo("\n");
17 #if (UX_DEVICE_ENDPOINT_BUFFER_OWNER == 1) && defined(UX_DEVICE_CLASS_CDC_ECM_ZERO_COPY)
18     printf("Skipped\n");
19     return;
20 #endif
21 
22     ux_test_cdc_ecm_initialize(first_unused_memory);
23 }
24 
post_init_host()25 static void post_init_host()
26 {
27 
28 ULONG   n_available;
29 int i;
30 int device_num_writes = 0;
31 int host_num_reads = 0;
32 
33     /* Have the device send the max number of packets to the host. */
34     ux_utility_delay_ms(1000);
35     n_available = cdc_ecm_host->ux_host_class_cdc_ecm_packet_pool->nx_packet_pool_available;
36     for (i = 0; i < n_available; i++)
37         write_udp(&udp_socket_device, &packet_pool_device, HOST_IP_ADDRESS, HOST_SOCKET_PORT_UDP, device_num_writes++, "device", 4);
38     ux_utility_delay_ms(1000);
39 
40     /* Time to setup our action since we expect an error. */
41     ux_test_add_action_to_main_list(create_error_match_action(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_CLASS_ETH_PACKET_ERROR));
42 
43     /* Now send the one that should make the append error (discarded). */
44     write_packet_udp(&udp_socket_device, &packet_pool_device, HOST_IP_ADDRESS, HOST_SOCKET_PORT_UDP, device_num_writes, "device");
45 
46     /* Now wait for error to occur. */
47     UX_TEST_CHECK_SUCCESS(ux_test_wait_for_empty_actions());
48 
49     /* Let's be good sports and make sure everything else works. */
50     for (i = 0; i < n_available; i++)
51         read_packet_udp(&udp_socket_host, host_num_reads++, "host");
52 
53     /* Send one more. */
54     write_packet_udp(&udp_socket_device, &packet_pool_device, HOST_IP_ADDRESS, HOST_SOCKET_PORT_UDP, device_num_writes++, "device");
55     /* Read one more.  */
56     read_packet_udp(&udp_socket_host, host_num_reads++, "host");
57 }
58 
post_init_device()59 static void post_init_device()
60 {
61 }