1 /* This is a basic test for the host hub class. Note that there is no device hub
2    class, so we create a barebones dummy one. We also test a device connected
3    to the hub; for this, we use the DPUMP class since it is very simple. Note
4    that we only test enumeration of the DPUMP device, since it is rather difficult
5    and unnecessary to do test the DPUMP device behind the hub. */
6 
7 #include "usbx_ux_test_hub.h"
8 
9 /* Define what the initial system looks like.  */
10 
11 #ifdef CTEST
test_application_define(void * first_unused_memory)12 void test_application_define(void *first_unused_memory)
13 #else
14 void usbx_hub_basic_test_application_define(void *first_unused_memory)
15 #endif
16 {
17 
18     /* Inform user.  */
19     printf("Running Hub Basic Functionality Test................................ ");
20 
21     stepinfo("\n");
22 
23     initialize_hub(first_unused_memory);
24 }
25 
post_init_host()26 static void post_init_host()
27 {
28 
29     /* Let's initialize the memory test. */
30     ux_test_disconnect_slave_and_host_wait_for_enum_completion();
31     ux_test_memory_test_initialize();
32     ux_test_connect_slave_and_host_wait_for_enum_completion();
33     class_hub_get();
34     UX_TEST_ASSERT(g_hub_device != UX_NULL);
35 
36     /* Now, let's tell the host that there's a device connection. */
37     connect_device_to_hub();
38 #if UX_MAX_DEVICES > 1
39     /* Now wait for the device hub to tell us the DPUMP device has been connected. */
40     class_dpump_get();
41 
42     /* The host enumerated the DPUMP device. Awesome. Now let's disconnect and reconnect
43        to test that we can reconnect. */
44     /* Let's also test the case of null change function. */
45     _ux_system_host->ux_system_host_change_function = UX_NULL;
46     ux_test_disconnect_slave_and_host_wait_for_enum_completion();
47     ux_test_connect_slave_and_host_wait_for_enum_completion();
48     /* Let's also test the case where the port data is 2 bytes instead of 1. */
49     connect_device_to_hub_short_with_hub();
50     class_dpump_get();
51     /* Let's re-add the system change function.  */
52     _ux_system_host->ux_system_host_change_function = system_change_function;
53 
54     /* The host enumerated the DPUMP device. Awesome. Now let's disconnect and reconnect
55        to test that we can reconnect and stuff. */
56     ux_test_disconnect_slave_and_host_wait_for_enum_completion();
57     /* Ensure everything is cleared. */
58     UX_TEST_ASSERT(g_hub_device == UX_NULL);
59     UX_TEST_ASSERT(g_hub_host_from_system_change_function == UX_NULL);
60     ux_test_connect_slave_and_host_wait_for_enum_completion();
61     connect_device_to_hub();
62     class_dpump_get();
63 #endif
64     /* We're done. */
65 }
66 
post_init_device()67 static void post_init_device()
68 {
69 }