1 /* This tests the case where the device is connected, disconnected, then reconnected
2    very quickly (in other words, so fast that the HCD thread doesn't detect the
3    disconnection). The specific test case is in ux_host_class_hub_port_change_connection_process.c. */
4 
5 #include "usbx_ux_test_hub.h"
6 
7 static UINT num_insertions;
8 static UINT num_removals;
9 
10 /* Define what the initial system looks like.  */
11 
12 #ifdef CTEST
test_application_define(void * first_unused_memory)13 void test_application_define(void *first_unused_memory)
14 #else
15 void usbx_hub_quick_hub_device_reconnection_test_application_define(void *first_unused_memory)
16 #endif
17 {
18 
19     /* Inform user.  */
20     printf("Running Hub Quick Hub Device Reconnection Test...................... ");
21 
22     stepinfo("\n");
23 
24     initialize_hub(first_unused_memory);
25 }
26 
my_system_change_function(ULONG event,UX_HOST_CLASS * class,VOID * instance)27 static UINT my_system_change_function(ULONG event, UX_HOST_CLASS *class, VOID *instance)
28 {
29 
30     if (event == UX_DEVICE_INSERTION)
31     {
32         if (!memcmp(class->ux_host_class_name, "ux_host_class_dpump", strlen("ux_host_class_dpump")))
33         {
34             num_insertions++;
35         }
36     }
37     else if (event == UX_DEVICE_REMOVAL)
38     {
39         if (!memcmp(class->ux_host_class_name, "ux_host_class_dpump", strlen("ux_host_class_dpump")))
40         {
41             num_removals++;
42         }
43     }
44     return(UX_SUCCESS);
45 }
46 
post_init_host()47 static void post_init_host()
48 {
49 #if UX_MAX_DEVICES > 1
50     /* We just test this by connecting the device twice with no disconnection. */
51 
52     /* Tell the host that there's a device connection, and wait for host to enumerate it. */
53     connect_device_to_hub();
54     class_dpump_get();
55 
56     _ux_system_host->ux_system_host_change_function = my_system_change_function;
57 
58     /* Now do it again. */
59     connect_device_to_hub();
60 
61     /* Wait for the removal. */
62     UX_TEST_CHECK_SUCCESS(ux_test_wait_for_value_uint(&num_removals, 1));
63 
64     /* Wait for reconnection. */
65     ux_test_wait_for_enum_thread_completion();
66 
67     /* Ensure we're all good. */
68     UX_TEST_ASSERT(num_insertions == 1);
69     class_dpump_get();
70 #endif
71 }
72 
post_init_device()73 static void post_init_device()
74 {
75 }