1 /* This tests the case where the device connected to the hub is disconnected. 2 The specific test case is in ux_host_class_hub_port_change_connection_process.c. */ 3 4 #include "usbx_ux_test_hub.h" 5 6 /* Define what the initial system looks like. */ 7 8 #ifdef CTEST test_application_define(void * first_unused_memory)9void test_application_define(void *first_unused_memory) 10 #else 11 void usbx_hub_hub_device_connect_test_application_define(void *first_unused_memory) 12 #endif 13 { 14 15 /* Inform user. */ 16 printf("Running Hub Device connect Test..................................... "); 17 18 stepinfo("\n"); 19 20 initialize_hub(first_unused_memory); 21 } 22 post_init_host()23static void post_init_host() 24 { 25 #if UX_MAX_DEVICES > 1 26 UX_DEVICE *device; 27 ULONG temp; 28 29 /* >>>>>>>>>> Test connect and enumerate. */ 30 g_host_change_count = 0; 31 connect_device_to_hub(); 32 class_dpump_get(); 33 34 /* 2 events expected. */ 35 UX_TEST_ASSERT(g_host_change_count == 2); 36 37 /* 1st event : dpump class activated. */ 38 UX_TEST_ASSERT(g_host_change_logs[0].event == UX_DEVICE_INSERTION); 39 UX_TEST_ASSERT(g_host_change_logs[0].class != UX_NULL); 40 UX_TEST_ASSERT(g_host_change_logs[0].instance != UX_NULL); 41 42 /* 2nd event : device enumerated (connected). */ 43 UX_TEST_ASSERT(g_host_change_logs[1].event == UX_DEVICE_CONNECTION); 44 UX_TEST_ASSERT(g_host_change_logs[1].class == UX_NULL); 45 UX_TEST_ASSERT(g_host_change_logs[1].instance != UX_NULL); 46 47 /* >>>>>>>>>> Now we need to disconnect the device. */ 48 g_host_change_count = 0; 49 disconnect_device_from_hub(); 50 UX_TEST_CHECK_SUCCESS(ux_test_wait_for_null((VOID**)&g_dpump_host_from_system_change_function)); 51 ux_test_wait_for_enum_thread_completion(); 52 53 /* 2 events expected. */ 54 UX_TEST_ASSERT(g_host_change_count == 2); 55 56 /* 1st event : dpump class deactivated. */ 57 UX_TEST_ASSERT(g_host_change_logs[0].event == UX_DEVICE_REMOVAL); 58 UX_TEST_ASSERT(g_host_change_logs[0].class != UX_NULL); 59 UX_TEST_ASSERT(g_host_change_logs[0].instance != UX_NULL); 60 61 /* 2nd event : device disconnected. */ 62 UX_TEST_ASSERT(g_host_change_logs[1].event == UX_DEVICE_DISCONNECTION); 63 UX_TEST_ASSERT(g_host_change_logs[1].class == UX_NULL); 64 UX_TEST_ASSERT(g_host_change_logs[1].instance != UX_NULL); 65 66 /* >>>>>>>>>> Now test case : UX_TOO_MANY_DEVICES. */ 67 ux_test_ignore_all_errors(); 68 g_host_change_count = 0; 69 temp = _ux_system_host -> ux_system_host_max_devices; 70 _ux_system_host -> ux_system_host_max_devices = 1; 71 connect_device_to_hub(); 72 73 /* One event expected. */ 74 UX_TEST_CHECK_SUCCESS(ux_test_wait_for_value_ulong(&g_host_change_count, 1)); 75 76 /* event : device connected but no instance. */ 77 UX_TEST_ASSERT(g_host_change_logs[0].event == UX_DEVICE_CONNECTION); 78 UX_TEST_ASSERT(g_host_change_logs[0].class == UX_NULL); 79 UX_TEST_ASSERT(g_host_change_logs[0].instance == UX_NULL); 80 81 g_host_change_count = 0; 82 disconnect_device_from_hub(); 83 ux_test_wait_for_enum_thread_completion(); 84 85 /* There is no change notification since no device instance allocated. */ 86 UX_TEST_ASSERT(g_host_change_count == 0); 87 88 /* Restore. */ 89 _ux_system_host -> ux_system_host_max_devices = temp; 90 ux_test_unignore_all_errors(); 91 92 /* >>>>>>>>>> Now test case : UX_NO_CLASS_MATCH. */ 93 ux_test_ignore_all_errors(); 94 95 /* Unregister DPUMP. */ 96 UX_TEST_CHECK_SUCCESS(ux_host_stack_class_unregister(ux_host_class_dpump_entry)); 97 g_host_change_count = 0; 98 connect_device_to_hub(); 99 100 /* One event expected. */ 101 UX_TEST_CHECK_SUCCESS(ux_test_wait_for_value_ulong(&g_host_change_count, 1)); 102 103 /* event : device connected but not configured. */ 104 UX_TEST_ASSERT(g_host_change_logs[0].event == UX_DEVICE_CONNECTION); 105 UX_TEST_ASSERT(g_host_change_logs[0].class == UX_NULL); 106 UX_TEST_ASSERT(g_host_change_logs[0].instance != UX_NULL); 107 device = (UX_DEVICE*)g_host_change_logs[0].instance; 108 UX_TEST_ASSERT(device->ux_device_state == UX_DEVICE_ADDRESSED); 109 110 g_host_change_count = 0; 111 disconnect_device_from_hub(); 112 113 /* One event expected. */ 114 UX_TEST_CHECK_SUCCESS(ux_test_wait_for_value_ulong(&g_host_change_count, 1)); 115 116 ux_test_wait_for_enum_thread_completion(); 117 118 /* event : device disconnected but not configured. */ 119 UX_TEST_ASSERT(g_host_change_logs[0].event == UX_DEVICE_DISCONNECTION); 120 UX_TEST_ASSERT(g_host_change_logs[0].class == UX_NULL); 121 UX_TEST_ASSERT(g_host_change_logs[0].instance == (VOID*)device); 122 123 ux_test_unignore_all_errors(); 124 125 #endif 126 } 127 post_init_device()128static void post_init_device() 129 { 130 }