summaryrefslogtreecommitdiff
path: root/test/regression/usbx_cdc_ecm_alternate_setting_change_to_zero_test.c
blob: 46de58c7d69e231bf635bf721d7d501b6c1d7cbd (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
/***************************************************************************/
/* 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 host sets the device's alternate setting to
   zero.  */

#include "usbx_ux_test_cdc_ecm.h"
#include "ux_host_stack.h"

static UCHAR host_ready_for_basic_test;

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

    /* Inform user.  */
    printf("Running CDC ECM Alternate Setting Change To Zero Test............... ");

    stepinfo("\n");

    ux_test_cdc_ecm_initialize(first_unused_memory);
}

static void post_init_host()
{

    /* Change the data interface alternate setting to zero. */
    _ux_host_stack_interface_set(cdc_ecm_host->ux_host_class_cdc_ecm_interface_data);

    /* Wait for the host to change settings, which means the device has too. */
    UX_TEST_CHECK_SUCCESS(ux_test_wait_for_value_ulong(&cdc_ecm_host->ux_host_class_cdc_ecm_link_state, 0));

    /* Change the data interface alternate setting back to one. */
    _ux_host_stack_interface_set(cdc_ecm_host->ux_host_class_cdc_ecm_interface_data->ux_interface_next_interface);

    /* Wait for the host to change settings, which means the device has too. */
    UX_TEST_CHECK_SUCCESS(ux_test_wait_for_value_ulong(&cdc_ecm_host->ux_host_class_cdc_ecm_link_state, 1));

    /* Try a basic test. */
    host_ready_for_basic_test = 1;
    cdc_ecm_basic_test(BASIC_TEST_HOST, BASIC_TEST_TCP);

    /* Huzzah! */

    /* Change the data interface alternate setting to zero again - this time, with no deactivate callback. */
    cdc_ecm_device->ux_slave_class_cdc_ecm_parameter.ux_slave_class_cdc_ecm_instance_deactivate = UX_NULL;
    _ux_host_stack_interface_set(cdc_ecm_host->ux_host_class_cdc_ecm_interface_data);

    /* Wait for the host to change settings, which means the device has too. */
    UX_TEST_CHECK_SUCCESS(ux_test_wait_for_value_ulong(&cdc_ecm_host->ux_host_class_cdc_ecm_link_state, 0));

    /* Huzzah! Again! */
}

static void post_init_device()
{

    /* Wait for basic test. */
    UX_TEST_CHECK_SUCCESS(ux_test_wait_for_value_uchar(&host_ready_for_basic_test, 1));
    cdc_ecm_basic_test(BASIC_TEST_DEVICE, BASIC_TEST_TCP);
}