1 /* This tests the case the nx_packet_allocate 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_thread_packet_allocate_fail_test_application_define(void *first_unused_memory)
10 #endif
11 {
12 
13     /* Inform user.  */
14     printf("Running CDC-ECM Host Thread Packet Allocate Fail Test............... ");
15 
16     stepinfo("\n");
17 
18     ux_test_cdc_ecm_initialize(first_unused_memory);
19 }
20 
post_init_host()21 static void post_init_host()
22 {
23 
24 int i;
25 int device_num_writes = 0;
26 int host_num_reads = 0;
27 
28     /* Have the device send the max number of packets to the host. */
29     for (i = 0; i < UX_HOST_CLASS_CDC_ECM_NX_PKPOOL_ENTRIES; i++)
30     {
31 
32         write_packet_udp(&udp_socket_device, &packet_pool_device, HOST_IP_ADDRESS, HOST_SOCKET_PORT_UDP, device_num_writes++, "device");
33     }
34 
35     /* Time to setup our action since we expect an error. */
36     ux_test_add_action_to_main_list(create_error_match_action(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_MEMORY_INSUFFICIENT));
37 
38     /* Now send the one that should make the call overflow. */
39     write_packet_udp(&udp_socket_device, &packet_pool_device, HOST_IP_ADDRESS, HOST_SOCKET_PORT_UDP, device_num_writes++, "device");
40 
41     /* Now wait for error to occur. */
42     UX_TEST_CHECK_SUCCESS(ux_test_wait_for_empty_actions());
43 
44     /* Let's be good sports and make sure everything else works. */
45     for (i = 0; i < UX_HOST_CLASS_CDC_ECM_NX_PKPOOL_ENTRIES + 1; i++)
46     {
47 
48         read_packet_udp(&udp_socket_host, host_num_reads++, "host");
49     }
50 
51     /* Send one more. */
52     write_packet_udp(&udp_socket_device, &packet_pool_device, HOST_IP_ADDRESS, HOST_SOCKET_PORT_UDP, device_num_writes++, "device");
53     /* Read one more.  */
54     read_packet_udp(&udp_socket_host, host_num_reads++, "host");
55 }
56 
post_init_device()57 static void post_init_device()
58 {
59 }