summaryrefslogtreecommitdiff
path: root/test/regression/usbx_hub_hub_device_connect_test.c
blob: dbecbd3e15cbbbfdf2a0ca25ee29e10bad8766e2 (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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/***************************************************************************/
/* 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 device connected to the hub is disconnected.
   The specific test case is in ux_host_class_hub_port_change_connection_process.c. */

#include "usbx_ux_test_hub.h"

/* Define what the initial system looks like.  */

#ifdef CTEST
void test_application_define(void *first_unused_memory)
#else
void usbx_hub_hub_device_connect_test_application_define(void *first_unused_memory)
#endif
{

    /* Inform user.  */
    printf("Running Hub Device connect Test..................................... ");

    stepinfo("\n");

    initialize_hub(first_unused_memory);
}

static void post_init_host()
{
#if UX_MAX_DEVICES > 1
UX_DEVICE   *device;
ULONG       temp;

    /* >>>>>>>>>> Test connect and enumerate. */
    g_host_change_count = 0;
    connect_device_to_hub();
    class_dpump_get();

    /* 2 events expected.  */
    UX_TEST_ASSERT(g_host_change_count == 2);

    /* 1st event : dpump class activated.  */
    UX_TEST_ASSERT(g_host_change_logs[0].event == UX_DEVICE_INSERTION);
    UX_TEST_ASSERT(g_host_change_logs[0].class != UX_NULL);
    UX_TEST_ASSERT(g_host_change_logs[0].instance != UX_NULL);

    /* 2nd event : device enumerated (connected).  */
    UX_TEST_ASSERT(g_host_change_logs[1].event == UX_DEVICE_CONNECTION);
    UX_TEST_ASSERT(g_host_change_logs[1].class == UX_NULL);
    UX_TEST_ASSERT(g_host_change_logs[1].instance != UX_NULL);

    /* >>>>>>>>>> Now we need to disconnect the device. */
    g_host_change_count = 0;
    disconnect_device_from_hub();
    UX_TEST_CHECK_SUCCESS(ux_test_wait_for_null((VOID**)&g_dpump_host_from_system_change_function));
    ux_test_wait_for_enum_thread_completion();

    /* 2 events expected.  */
    UX_TEST_ASSERT(g_host_change_count == 2);

    /* 1st event : dpump class deactivated.  */
    UX_TEST_ASSERT(g_host_change_logs[0].event == UX_DEVICE_REMOVAL);
    UX_TEST_ASSERT(g_host_change_logs[0].class != UX_NULL);
    UX_TEST_ASSERT(g_host_change_logs[0].instance != UX_NULL);

    /* 2nd event : device disconnected.  */
    UX_TEST_ASSERT(g_host_change_logs[1].event == UX_DEVICE_DISCONNECTION);
    UX_TEST_ASSERT(g_host_change_logs[1].class == UX_NULL);
    UX_TEST_ASSERT(g_host_change_logs[1].instance != UX_NULL);

    /* >>>>>>>>>> Now test case : UX_TOO_MANY_DEVICES.  */
    ux_test_ignore_all_errors();
    g_host_change_count = 0;
    temp = _ux_system_host -> ux_system_host_max_devices;
    _ux_system_host -> ux_system_host_max_devices = 1;
    connect_device_to_hub();

    /* One event expected.  */
    UX_TEST_CHECK_SUCCESS(ux_test_wait_for_value_ulong(&g_host_change_count, 1));

    /* event : device connected but no instance.  */
    UX_TEST_ASSERT(g_host_change_logs[0].event == UX_DEVICE_CONNECTION);
    UX_TEST_ASSERT(g_host_change_logs[0].class == UX_NULL);
    UX_TEST_ASSERT(g_host_change_logs[0].instance == UX_NULL);

    g_host_change_count = 0;
    disconnect_device_from_hub();
    ux_test_wait_for_enum_thread_completion();

    /* There is no change notification since no device instance allocated.  */
    UX_TEST_ASSERT(g_host_change_count == 0);

    /* Restore.  */
    _ux_system_host -> ux_system_host_max_devices = temp;
    ux_test_unignore_all_errors();

    /* >>>>>>>>>> Now test case : UX_NO_CLASS_MATCH.  */
    ux_test_ignore_all_errors();

    /* Unregister DPUMP.  */
    UX_TEST_CHECK_SUCCESS(ux_host_stack_class_unregister(ux_host_class_dpump_entry));
    g_host_change_count = 0;
    connect_device_to_hub();

    /* One event expected.  */
    UX_TEST_CHECK_SUCCESS(ux_test_wait_for_value_ulong(&g_host_change_count, 1));

    /* event : device connected but not configured.  */
    UX_TEST_ASSERT(g_host_change_logs[0].event == UX_DEVICE_CONNECTION);
    UX_TEST_ASSERT(g_host_change_logs[0].class == UX_NULL);
    UX_TEST_ASSERT(g_host_change_logs[0].instance != UX_NULL);
    device = (UX_DEVICE*)g_host_change_logs[0].instance;
    UX_TEST_ASSERT(device->ux_device_state == UX_DEVICE_ADDRESSED);

    g_host_change_count = 0;
    disconnect_device_from_hub();

    /* One event expected.  */
    UX_TEST_CHECK_SUCCESS(ux_test_wait_for_value_ulong(&g_host_change_count, 1));

    ux_test_wait_for_enum_thread_completion();

    /* event : device disconnected but not configured.  */
    UX_TEST_ASSERT(g_host_change_logs[0].event == UX_DEVICE_DISCONNECTION);
    UX_TEST_ASSERT(g_host_change_logs[0].class == UX_NULL);
    UX_TEST_ASSERT(g_host_change_logs[0].instance == (VOID*)device);

    ux_test_unignore_all_errors();

#endif
}

static void post_init_device()
{
}