summaryrefslogtreecommitdiff
path: root/test/regression/usbx_cdc_ecm_host_thread_packet_append_fail_test.c
blob: 60cdb97bba09488d387113b394bf72a84bbef1e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/***************************************************************************/
/* Copyright (c) 2024 Microsoft Corporation                                */
/* Copyright (c) 2026 Eclipse ThreadX contributors                         */
/*                                                                         */
/* This program and the accompanying materials are made available under    */
/* the terms of the MIT License which is available at                      */
/* https://opensource.org/licenses/MIT.                                    */
/*                                                                         */
/* SPDX-License-Identifier: MIT                                            */
/***************************************************************************/

/* This tests the case the nx_packet_allocate fails in the cdc-ecm thread. */

#define TEST_NX_PACKET_CHAIN
#include "usbx_ux_test_cdc_ecm.h"

/* Define what the initial system looks like.  */
#ifdef CTEST
void test_application_define(void *first_unused_memory)
#else
void usbx_cdc_ecm_host_thread_packet_allocate_fail_test_application_define(void *first_unused_memory)
#endif
{

    /* Inform user.  */
    printf("Running CDC-ECM Host Thread Packet Append Fail Test................. ");
    stepinfo("\n");
#if (UX_DEVICE_ENDPOINT_BUFFER_OWNER == 1) && defined(UX_DEVICE_CLASS_CDC_ECM_ZERO_COPY)
    printf("Skipped\n");
    return;
#endif

    ux_test_cdc_ecm_initialize(first_unused_memory);
}

static void post_init_host()
{

ULONG   n_available;
int i;
int device_num_writes = 0;
int host_num_reads = 0;

    /* Have the device send the max number of packets to the host. */
    ux_utility_delay_ms(1000);
    n_available = cdc_ecm_host->ux_host_class_cdc_ecm_packet_pool->nx_packet_pool_available;
    for (i = 0; i < n_available; i++)
        write_udp(&udp_socket_device, &packet_pool_device, HOST_IP_ADDRESS, HOST_SOCKET_PORT_UDP, device_num_writes++, "device", 4);
    ux_utility_delay_ms(1000);

    /* Time to setup our action since we expect an error. */
    ux_test_add_action_to_main_list(create_error_match_action(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_CLASS_ETH_PACKET_ERROR));

    /* Now send the one that should make the append error (discarded). */
    write_packet_udp(&udp_socket_device, &packet_pool_device, HOST_IP_ADDRESS, HOST_SOCKET_PORT_UDP, device_num_writes, "device");

    /* Now wait for error to occur. */
    UX_TEST_CHECK_SUCCESS(ux_test_wait_for_empty_actions());

    /* Let's be good sports and make sure everything else works. */
    for (i = 0; i < n_available; i++)
        read_packet_udp(&udp_socket_host, host_num_reads++, "host");

    /* Send one more. */
    write_packet_udp(&udp_socket_device, &packet_pool_device, HOST_IP_ADDRESS, HOST_SOCKET_PORT_UDP, device_num_writes++, "device");
    /* Read one more.  */
    read_packet_udp(&udp_socket_host, host_num_reads++, "host");
}

static void post_init_device()
{
}