summaryrefslogtreecommitdiff
path: root/test/regression/usbx_hub_basic_test.c
blob: 39952ed5a15cc476a3e7fbcd0703291503cdb122 (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
/***************************************************************************/
/* 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 is a basic test for the host hub class. Note that there is no device hub
   class, so we create a barebones dummy one. We also test a device connected
   to the hub; for this, we use the DPUMP class since it is very simple. Note
   that we only test enumeration of the DPUMP device, since it is rather difficult
   and unnecessary to do test the DPUMP device behind the hub. */

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

    /* Inform user.  */
    printf("Running Hub Basic Functionality Test................................ ");

    stepinfo("\n");

    initialize_hub(first_unused_memory);
}

static void post_init_host()
{

    /* Let's initialize the memory test. */
    ux_test_disconnect_slave_and_host_wait_for_enum_completion();
    ux_test_memory_test_initialize();
    ux_test_connect_slave_and_host_wait_for_enum_completion();
    class_hub_get();
    UX_TEST_ASSERT(g_hub_device != UX_NULL);

    /* Now, let's tell the host that there's a device connection. */
    connect_device_to_hub();
#if UX_MAX_DEVICES > 1
    /* Now wait for the device hub to tell us the DPUMP device has been connected. */
    class_dpump_get();

    /* The host enumerated the DPUMP device. Awesome. Now let's disconnect and reconnect
       to test that we can reconnect. */
    /* Let's also test the case of null change function. */
    _ux_system_host->ux_system_host_change_function = UX_NULL;
    ux_test_disconnect_slave_and_host_wait_for_enum_completion();
    ux_test_connect_slave_and_host_wait_for_enum_completion();
    /* Let's also test the case where the port data is 2 bytes instead of 1. */
    connect_device_to_hub_short_with_hub();
    class_dpump_get();
    /* Let's re-add the system change function.  */
    _ux_system_host->ux_system_host_change_function = system_change_function;

    /* The host enumerated the DPUMP device. Awesome. Now let's disconnect and reconnect
       to test that we can reconnect and stuff. */
    ux_test_disconnect_slave_and_host_wait_for_enum_completion();
    /* Ensure everything is cleared. */
    UX_TEST_ASSERT(g_hub_device == UX_NULL);
    UX_TEST_ASSERT(g_hub_host_from_system_change_function == UX_NULL);
    ux_test_connect_slave_and_host_wait_for_enum_completion();
    connect_device_to_hub();
    class_dpump_get();
#endif
    /* We're done. */
}

static void post_init_device()
{
}