summaryrefslogtreecommitdiff
path: root/test/regression/usbx_ux_host_class_cdc_ecm_mac_address_get_test.c
blob: d30edbee7fe4e253a71570fca250220c5bc52d3c (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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/***************************************************************************/
/* 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 ux_host_class_cdc_ecm_mac_address_get function. */

#include "usbx_ux_test_cdc_ecm.h"

static UCHAR cdc_ecm_thread_suspended;

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

    /* Inform user.  */
    printf("Running ux_host_class_cdc_ecm_mac_address_get Test.................. ");

    stepinfo("\n");

    ux_test_cdc_ecm_initialize(first_unused_memory);
}

#define CONFIGURATION_INDEX 0
static UX_TEST_SETUP get_cfg_desc_setup = {
    .ux_test_setup_type = UX_REQUEST_IN | UX_REQUEST_TYPE_STANDARD | UX_REQUEST_TARGET_DEVICE,
    .ux_test_setup_request = UX_GET_DESCRIPTOR,
    .ux_test_setup_value = (USHORT) CONFIGURATION_INDEX | (UX_CONFIGURATION_DESCRIPTOR_ITEM << 8),
    .ux_test_setup_index = 0,
};

static void post_init_host()
{

int i;

    /* Create the matching one. */
    UX_TEST_ACTION get_cfg_desc_match_action = {0};
    get_cfg_desc_match_action.usbx_function = UX_TEST_OVERRIDE_UX_HCD_SIM_HOST_ENTRY;
    get_cfg_desc_match_action.function = UX_HCD_TRANSFER_REQUEST;
    get_cfg_desc_match_action.req_action = UX_TEST_SETUP_MATCH_REQUEST | UX_TEST_SETUP_MATCH_VALUE | UX_TEST_SETUP_MATCH_INDEX;
    get_cfg_desc_match_action.req_setup = &get_cfg_desc_setup;
    get_cfg_desc_match_action.no_return = 1;

    /* Create the action that modifies the length. */
    UX_TEST_ACTION get_cfg_desc_modify_length_action = {0};
    get_cfg_desc_modify_length_action.usbx_function = UX_TEST_OVERRIDE_UX_HCD_SIM_HOST_ENTRY;
    get_cfg_desc_modify_length_action.function = UX_HCD_TRANSFER_REQUEST;
    get_cfg_desc_modify_length_action.req_action = UX_TEST_SETUP_MATCH_REQUEST | UX_TEST_SETUP_MATCH_VALUE | UX_TEST_SETUP_MATCH_INDEX | UX_TEST_SIM_REQ_ANSWER;
    get_cfg_desc_modify_length_action.req_setup = &get_cfg_desc_setup;
    get_cfg_desc_modify_length_action.req_actual_len = 0xff;
    get_cfg_desc_modify_length_action.no_return = 0;
    get_cfg_desc_modify_length_action.status = UX_SUCCESS;

    /** Test configuration descriptor invalid transfer length returned. **/

    /* Since this happens during enumeration, disconnect. */
    ux_test_disconnect_slave_and_host_wait_for_enum_completion();

    /* In theory, this should be the third time we get the config desc (the first two
       happen during enumeration), so we need two matching, and one breaking. */
    for (i = 0; i < UX_RH_ENUMERATION_RETRY; i++)
    {

        ux_test_add_action_to_main_list(get_cfg_desc_match_action);
        ux_test_add_action_to_main_list(get_cfg_desc_match_action);
        ux_test_add_action_to_main_list(get_cfg_desc_modify_length_action);
        ux_test_add_action_to_main_list(create_error_match_action(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_DESCRIPTOR_CORRUPTED));
    }
    ux_test_add_action_to_main_list(create_error_match_action(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_ROOT_HUB, UX_DEVICE_ENUMERATION_FAILURE));

    /* Now connect so that mac_address_get runs. */
    ux_test_connect_slave_and_host_wait_for_enum_completion();

    UX_TEST_ASSERT(ux_test_check_actions_empty());

    /* Disconnect for next test. */
    ux_test_disconnect_slave_and_host_wait_for_enum_completion();

    /** Test whole configuration descriptor invalid transfer length returned - note that device should still be disconnected from previous test. **/

    /* In theory, this should be the fourth time we get the config desc (the first two
       happen during enumeration, and the third in mac_address_get), so we need three matching, and one breaking. */
    for (i = 0; i < UX_RH_ENUMERATION_RETRY; i++)
    {

        ux_test_add_action_to_main_list(get_cfg_desc_match_action);
        ux_test_add_action_to_main_list(get_cfg_desc_match_action);
        ux_test_add_action_to_main_list(get_cfg_desc_match_action);
        ux_test_add_action_to_main_list(get_cfg_desc_modify_length_action);
        ux_test_add_action_to_main_list(create_error_match_action(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_DESCRIPTOR_CORRUPTED));
    }
    ux_test_add_action_to_main_list(create_error_match_action(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_ROOT_HUB, UX_DEVICE_ENUMERATION_FAILURE));

    /* Now connect so that mac_address_get runs. */
    ux_test_connect_slave_and_host_wait_for_enum_completion();

    UX_TEST_ASSERT(ux_test_check_actions_empty());
}

static void post_init_device()
{
}