summaryrefslogtreecommitdiff
path: root/test/regression/usbx_cdc_ecm_host_bulk_in_transfer_fail_test.c
blob: 2ac480e3b06e1edb710758e2769580cbd153d734 (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
73
74
75
76
/***************************************************************************/
/* 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 where the bulk in transfer fails (in the cdc-ecm thread). */

#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_bulk_in_transfer_fail_test_application_define(void *first_unused_memory)
#endif
{

    /* Inform user.  */
    printf("Running CDC-ECM Host Bulk In Transfer Fail Test..................... ");

    stepinfo("\n");

    ux_test_cdc_ecm_initialize(first_unused_memory);
}

static UCHAR is_cdc_ecm_thread_suspended;

static VOID suspend_cdc_ecm_thread_action_func(UX_TEST_ACTION *action, VOID *params)
{

    is_cdc_ecm_thread_suspended = 1;

    /* We're being called by nx_packet_allocate in cdc-ecm thread. Wait for test
       thread to resume us. */
    tx_thread_suspend(tx_thread_identify());
}

static void post_init_host()
{

    /* Currently, the cdc-ecm thread should be waiting for a transfer to complete.
       We need to create an action for having the bulk in transfer fail, add
       the action, then send data to host so the cdc-ecm thread will re-arm the
       transfer (which should fail). */

    /* Create the action for having bulk in transfer fail. */
    UX_TEST_ACTION bulk_transfer_fail_action = {0};
    bulk_transfer_fail_action.usbx_function = UX_TEST_OVERRIDE_UX_HCD_SIM_HOST_ENTRY;
    bulk_transfer_fail_action.function = UX_HCD_TRANSFER_REQUEST;
    bulk_transfer_fail_action.req_action = UX_TEST_MATCH_EP;
    bulk_transfer_fail_action.req_ep_address = 0x81;
    bulk_transfer_fail_action.no_return = 0;
    bulk_transfer_fail_action.status = UX_ERROR;
    ux_test_add_action_to_main_list(bulk_transfer_fail_action);

    /* Write to the host so the cdc-ecm thread will redo the bulk in transfer. */
    write_packet_udp(&udp_socket_device, &packet_pool_device, HOST_IP_ADDRESS, HOST_SOCKET_PORT_UDP, 0, "device");

    /* Wait for the arm and fail. */
    UX_TEST_CHECK_SUCCESS(ux_test_wait_for_empty_actions());

    /* Wait for the host to re-arm and wait for the transfer. */
    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));

    /* Now we're done. */
}

static void post_init_device()
{
}