1 /* This test is designed to test the ux_host_stack_interface_setting_select.  */
2 
3 #include <stdio.h>
4 #include "tx_api.h"
5 #include "ux_api.h"
6 #include "ux_system.h"
7 #include "ux_utility.h"
8 
9 #include "ux_host_stack.h"
10 #include "ux_device_stack.h"
11 
12 #include "ux_device_class_cdc_acm.h"
13 #include "ux_host_class_cdc_acm.h"
14 
15 #include "ux_host_class_dpump.h"
16 #include "ux_device_class_dpump.h"
17 
18 #include "ux_host_class_hid.h"
19 #include "ux_device_class_hid.h"
20 
21 #include "ux_host_class_storage.h"
22 #include "ux_device_class_storage.h"
23 
24 #include "ux_test_dcd_sim_slave.h"
25 #include "ux_test_hcd_sim_host.h"
26 #include "ux_test_utility_sim.h"
27 
28 
29 /* Define USBX test constants.  */
30 
31 #define UX_TEST_STACK_SIZE      4096
32 #define UX_TEST_BUFFER_SIZE     2048
33 #define UX_TEST_RUN             1
34 #define UX_TEST_MEMORY_SIZE     (64*1024)
35 
36 /* HID mouse related descriptors */
37 
38 static UCHAR hid_mouse_report[] = {
39 
40     0x05, 0x01,                    // USAGE_PAGE (Generic Desktop)
41     0x09, 0x02,                    // USAGE (Mouse)
42     0xa1, 0x01,                    // COLLECTION (Application)
43     0x09, 0x01,                    //   USAGE (Pointer)
44     0xa1, 0x00,                    //   COLLECTION (Physical)
45     0x05, 0x09,                    //     USAGE_PAGE (Button)
46     0x19, 0x01,                    //     USAGE_MINIMUM (Button 1)
47     0x29, 0x03,                    //     USAGE_MAXIMUM (Button 3)
48     0x15, 0x00,                    //     LOGICAL_MINIMUM (0)
49     0x25, 0x01,                    //     LOGICAL_MAXIMUM (1)
50     0x95, 0x03,                    //     REPORT_COUNT (3)
51     0x75, 0x01,                    //     REPORT_SIZE (1)
52     0x81, 0x02,                    //     INPUT (Data,Var,Abs)
53     0x95, 0x01,                    //     REPORT_COUNT (1)
54     0x75, 0x05,                    //     REPORT_SIZE (5)
55     0x81, 0x03,                    //     INPUT (Cnst,Var,Abs)
56     0x05, 0x01,                    //     USAGE_PAGE (Generic Desktop)
57     0x09, 0x30,                    //     USAGE (X)
58     0x09, 0x31,                    //     USAGE (Y)
59     0x15, 0x81,                    //     LOGICAL_MINIMUM (-127)
60     0x25, 0x7f,                    //     LOGICAL_MAXIMUM (127)
61     0x75, 0x08,                    //     REPORT_SIZE (8)
62     0x95, 0x02,                    //     REPORT_COUNT (2)
63     0x81, 0x06,                    //     INPUT (Data,Var,Rel)
64     0x09, 0x38,                    //     USAGE (Mouse Wheel)
65     0x15, 0x81,                    //     LOGICAL_MINIMUM (-127)
66     0x25, 0x7f,                    //     LOGICAL_MAXIMUM (127)
67     0x75, 0x08,                    //     REPORT_SIZE (8)
68     0x95, 0x01,                    //     REPORT_COUNT (1)
69     0x81, 0x06,                    //     INPUT (Data,Var,Rel)
70     0xc0,                          //   END_COLLECTION
71     0xc0                           // END_COLLECTION
72 };
73 #define HID_MOUSE_REPORT_LENGTH (sizeof(hid_mouse_report)/sizeof(hid_mouse_report[0]))
74 
75 #define     LSB(x) (x & 0x00ff)
76 #define     MSB(x) ((x & 0xff00) >> 8)
77 
78 /* Configuration descriptor 9 bytes */
79 #define CFG_DESC(wTotalLength, bNumInterfaces, bConfigurationValue)\
80     /* Configuration 1 descriptor 9 bytes */\
81     0x09, 0x02, LSB(wTotalLength), MSB(wTotalLength),\
82     (bNumInterfaces), (bConfigurationValue), 0x00,\
83     0x40, 0x00,
84 #define CFG_DESC_LEN 9
85 
86 /* DPUMP interface descriptors 9+7+7=23 bytes. */
87 #define DPUMP_IFC0_DESC_ALL(ifc, bulk_in_epa, bulk_out_epa, bulk_eps) \
88     /* Interface descriptor */\
89     0x09, 0x04, (ifc), 0x00, 0x02, 0x99, 0x99, 0x99, 0x00,\
90     /* Endpoint descriptor (Bulk Out) */\
91     0x07, 0x05, (bulk_out_epa), 0x02, LSB(bulk_eps), MSB(bulk_eps), 0x00,\
92     /* Endpoint descriptor (Bulk In) */\
93     0x07, 0x05, (bulk_in_epa), 0x02, LSB(bulk_eps), MSB(bulk_eps), 0x00,
94 #define DPUMP_IFC0_DESC_ALL_LEN 23
95 
96 /* DPUMP interface descriptors 9 bytes. */
97 #define DPUMP_IFC1_DESC_ALL(ifc) \
98     /* Interface descriptor */\
99     0x09, 0x04, (ifc), 0x01, 0x00, 0x99, 0x99, 0x99, 0x00,
100 #define DPUMP_IFC1_DESC_ALL_LEN 9
101 
102 /* HID Mouse interface descriptors 9+9+7=25 bytes */
103 #define HID_MOUSE_IFC0_DESC_ALL(ifc, interrupt_epa)     \
104     /* Interface descriptor */\
105     0x09, 0x04, (ifc), 0x00, 0x01, 0x03, 0x00, 0x00, 0x00,\
106     /* HID descriptor */\
107     0x09, 0x21, 0x10, 0x01, 0x21, 0x01, 0x22, LSB(HID_MOUSE_REPORT_LENGTH),\
108     MSB(HID_MOUSE_REPORT_LENGTH),\
109     /* Endpoint descriptor (Interrupt) */\
110     0x07, 0x05, (interrupt_epa), 0x03, 0x08, 0x00, 0x08,
111 #define HID_MOUSE_IFC0_DESC_ALL_LEN 25
112 
113 /* HID Mouse interface descriptors 9+9=18 bytes */
114 #define HID_MOUSE_IFC1_DESC_ALL(ifc)     \
115     /* Interface descriptor */\
116     0x09, 0x04, (ifc), 0x01, 0x00, 0x03, 0x00, 0x00, 0x00,\
117     /* HID descriptor */\
118     0x09, 0x21, 0x10, 0x01, 0x21, 0x01, 0x22, LSB(HID_MOUSE_REPORT_LENGTH),\
119     MSB(HID_MOUSE_REPORT_LENGTH),
120 #define HID_MOUSE_IFC1_DESC_ALL_LEN 18
121 
122 /* Define the counters used in the test application...  */
123 
124 static ULONG                           thread_0_counter;
125 static ULONG                           thread_1_counter;
126 static ULONG                           error_counter;
127 
128 static UCHAR                           expect_errors = UX_FALSE;
129 
130 static UCHAR                           skip_class_activations = UX_FALSE;
131 
132 
133 /* Define USBX test global variables.  */
134 
135 static UX_HOST_CLASS                   *class_driver;
136 static UX_HOST_CLASS_DPUMP             *dpump;
137 static UX_SLAVE_CLASS_DPUMP            *dpump_slave = UX_NULL;
138 
139 
140 static UCHAR device_framework_full_speed[] = {
141 
142     /* Device descriptor 18 bytes */
143     0x12, 0x01, 0x10, 0x01, 0x00, 0x00, 0x00, 0x08,
144     0xec, 0x08, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,
145     0x00, 0x01,
146 
147     CFG_DESC(CFG_DESC_LEN + DPUMP_IFC0_DESC_ALL_LEN + DPUMP_IFC1_DESC_ALL_LEN + HID_MOUSE_IFC0_DESC_ALL_LEN + HID_MOUSE_IFC1_DESC_ALL_LEN, 2, 1)
148     DPUMP_IFC0_DESC_ALL(0, 0x81, 0x02, 64)
149     DPUMP_IFC1_DESC_ALL(0)
150     HID_MOUSE_IFC0_DESC_ALL(1, 0x83)
151     HID_MOUSE_IFC1_DESC_ALL(1)
152 };
153 #define DEVICE_FRAMEWORK_LENGTH_FULL_SPEED sizeof(device_framework_full_speed)
154 
155 static UCHAR device_framework_high_speed[] = {
156 
157     /* Device descriptor */
158     0x12, 0x01, 0x00, 0x02, 0x00, 0x00, 0x00, 0x40,
159     0x0a, 0x07, 0x25, 0x40, 0x01, 0x00, 0x01, 0x02,
160     0x03, 0x01,
161 
162     /* Device qualifier descriptor */
163     0x0a, 0x06, 0x00, 0x02, 0x00, 0x00, 0x00, 0x40,
164     0x01, 0x00,
165 
166     CFG_DESC(CFG_DESC_LEN + DPUMP_IFC0_DESC_ALL_LEN + DPUMP_IFC1_DESC_ALL_LEN + HID_MOUSE_IFC0_DESC_ALL_LEN + HID_MOUSE_IFC1_DESC_ALL_LEN, 2, 1)
167     DPUMP_IFC0_DESC_ALL(0, 0x81, 0x02, 64)
168     DPUMP_IFC1_DESC_ALL(0)
169     HID_MOUSE_IFC0_DESC_ALL(1, 0x83)
170     HID_MOUSE_IFC1_DESC_ALL(1)
171 };
172 #define DEVICE_FRAMEWORK_LENGTH_HIGH_SPEED sizeof(device_framework_high_speed)
173 
174 /* String Device Framework :
175     Byte 0 and 1 : Word containing the language ID : 0x0904 for US
176     Byte 2       : Byte containing the index of the descriptor
177     Byte 3       : Byte containing the length of the descriptor string
178 */
179 
180 static UCHAR string_framework[] = {
181 
182     /* Manufacturer string descriptor : Index 1 */
183     0x09, 0x04, 0x01, 0x0c,
184     0x45, 0x78, 0x70, 0x72,0x65, 0x73, 0x20, 0x4c,
185     0x6f, 0x67, 0x69, 0x63,
186 
187     /* Product string descriptor : Index 2 */
188     0x09, 0x04, 0x02, 0x0c,
189     0x44, 0x61, 0x74, 0x61, 0x50, 0x75, 0x6d, 0x70,
190     0x44, 0x65, 0x6d, 0x6f,
191 
192     /* Serial Number string descriptor : Index 3 */
193     0x09, 0x04, 0x03, 0x04,
194     0x30, 0x30, 0x30, 0x31
195 };
196 #define STRING_FRAMEWORK_LENGTH sizeof(string_framework)
197 
198     /* Multiple languages are supported on the device, to add
199        a language besides English, the unicode language code must
200        be appended to the language_id_framework array and the length
201        adjusted accordingly. */
202 static UCHAR language_id_framework[] = {
203 
204 /* English. */
205     0x09, 0x04
206 };
207 #define LANGUAGE_ID_FRAMEWORK_LENGTH sizeof(language_id_framework)
208 
209 
210 
211 /* Define prototypes for external Host Controller's (HCDs), classes and clients.  */
212 
213 static VOID                ux_test_instance_activate(VOID  *dpump_instance);
214 static VOID                ux_test_instance_deactivate(VOID *dpump_instance);
215 
216 UINT                       _ux_host_class_dpump_entry(UX_HOST_CLASS_COMMAND *command);
217 UINT                       ux_hcd_sim_initialize(UX_HCD *hcd);
218 UINT                       _ux_host_class_dpump_write(UX_HOST_CLASS_DPUMP *dpump, UCHAR * data_pointer,
219                                     ULONG requested_length, ULONG *actual_length);
220 UINT                       _ux_host_class_dpump_read (UX_HOST_CLASS_DPUMP *dpump, UCHAR *data_pointer,
221                                     ULONG requested_length, ULONG *actual_length);
222 
223 static TX_THREAD           ux_test_thread_simulation_0;
224 static TX_THREAD           ux_test_thread_simulation_1;
225 static void                ux_test_thread_simulation_0_entry(ULONG);
226 static void                ux_test_thread_simulation_1_entry(ULONG);
227 
228 /* Simulation actions. */
229 
230 static UX_TEST_SETUP _SetInterface = {0x01,UX_SET_INTERFACE,0x0000,0x0000};
231 
232 static UX_TEST_SIM_ENTRY_ACTION hcd_set_interface_fail[] = {
233 /* function, request to match,
234    port action, port status,
235    request action, request EP, request data, request actual length, request status,
236    status, additional callback,
237    no_return */
238 {   UX_HCD_TRANSFER_REQUEST, &_SetInterface,
239         UX_FALSE, 0,
240         UX_TEST_SETUP_MATCH_REQ, 0, UX_NULL, 0, 0,
241         UX_ERROR , UX_NULL},
242 {   0   }
243 };
244 
245 static UX_TEST_SIM_ENTRY_ACTION hcd_create_endpoint_fail[] = {
246 /* function, request to match,
247    port action, port status,
248    request action, request EP, request data, request actual length, request status,
249    status, additional callback,
250    no_return */
251 {   UX_HCD_CREATE_ENDPOINT, UX_NULL,
252         UX_FALSE, 0,
253         0, 0, UX_NULL, 0, 0,
254         UX_ERROR , UX_NULL},
255 {   0   }
256 };
257 
258 
259 /* Define the ISR dispatch.  */
260 
261 extern VOID    (*test_isr_dispatch)(void);
262 
263 
264 /* Prototype for test control return.  */
265 
266 void  test_control_return(UINT status);
267 
268 
269 /* Define the ISR dispatch routine.  */
270 
test_isr(void)271 static void    test_isr(void)
272 {
273 
274     /* For further expansion of interrupt-level testing.  */
275 }
276 
277 
error_callback(UINT system_level,UINT system_context,UINT error_code)278 static VOID error_callback(UINT system_level, UINT system_context, UINT error_code)
279 {
280     if (!expect_errors)
281     {
282 
283         /* Failed test.  */
284         printf("Error on line %d, system_level: %d, system_context: %d, error code: %x\n", __LINE__, system_level, system_context, error_code);
285         test_control_return(1);
286     }
287 }
288 
test_ux_host_class_dpump_entry(UX_HOST_CLASS_COMMAND * command)289 UINT test_ux_host_class_dpump_entry(UX_HOST_CLASS_COMMAND *command)
290 {
291 
292     if (skip_class_activations && command->ux_host_class_command_request != UX_HOST_CLASS_COMMAND_QUERY)
293         return UX_SUCCESS;
294 
295     return _ux_host_class_dpump_entry(command);
296 }
297 
test_ux_device_class_dpump_entry(UX_SLAVE_CLASS_COMMAND * command)298 static UINT test_ux_device_class_dpump_entry(UX_SLAVE_CLASS_COMMAND *command)
299 {
300 
301     if (skip_class_activations && command->ux_slave_class_command_request != UX_SLAVE_CLASS_COMMAND_QUERY)
302         return UX_SUCCESS;
303 
304     return _ux_device_class_dpump_entry(command);
305 }
306 
test_ux_device_class_hid_entry(UX_SLAVE_CLASS_COMMAND * command)307 static UINT test_ux_device_class_hid_entry(UX_SLAVE_CLASS_COMMAND *command)
308 {
309 
310     if (skip_class_activations && command->ux_slave_class_command_request != UX_SLAVE_CLASS_COMMAND_QUERY)
311         return UX_SUCCESS;
312 
313     return _ux_device_class_hid_entry(command);
314 }
315 
316 /* Define what the initial system looks like.  */
317 
318 #ifdef CTEST
test_application_define(void * first_unused_memory)319 void test_application_define(void *first_unused_memory)
320 #else
321 void    usbx_ux_host_stack_interface_setting_select_test_application_define(void *first_unused_memory)
322 #endif
323 {
324 
325 UINT status;
326 CHAR                            *stack_pointer;
327 CHAR                            *memory_pointer;
328 UX_SLAVE_CLASS_DPUMP_PARAMETER  parameter;
329 UX_SLAVE_CLASS_HID_PARAMETER    hid_parameter;
330 
331     /* Initialize the free memory pointer.  */
332     stack_pointer = (CHAR *) first_unused_memory;
333     memory_pointer = stack_pointer + (UX_TEST_STACK_SIZE * 2);
334 
335     /* Initialize USBX Memory.  */
336     status =  ux_system_initialize(memory_pointer, UX_TEST_MEMORY_SIZE, UX_NULL, 0);
337 
338     /* Check for error.  */
339     if (status != UX_SUCCESS)
340     {
341 
342         printf("Running ux_host_stack_interface_setting_select Test................. ERROR #1\n");
343         test_control_return(1);
344     }
345 
346     /* Register the error callback. */
347     _ux_utility_error_callback_register(error_callback);
348 
349     /* The code below is required for installing the host portion of USBX.  */
350     status =  ux_host_stack_initialize(UX_NULL);
351 
352     /* Check for error.  */
353     if (status != UX_SUCCESS)
354     {
355 
356         printf("Running ux_host_stack_interface_setting_select Test................. ERROR #2\n");
357         test_control_return(1);
358     }
359 
360     /* Register all the host class drivers for this USBX implementation.  */
361     status =  ux_host_stack_class_register(_ux_system_host_class_dpump_name, test_ux_host_class_dpump_entry);
362 
363     /* Check for error.  */
364     if (status != UX_SUCCESS)
365     {
366 
367         printf("Running ux_host_stack_interface_setting_select Test................. ERROR #3\n");
368         test_control_return(1);
369     }
370 
371     /* The code below is required for installing the device portion of USBX */
372     status =  ux_device_stack_initialize(device_framework_high_speed, DEVICE_FRAMEWORK_LENGTH_HIGH_SPEED,
373                                        device_framework_full_speed, DEVICE_FRAMEWORK_LENGTH_FULL_SPEED,
374                                        string_framework, STRING_FRAMEWORK_LENGTH,
375                                        language_id_framework, LANGUAGE_ID_FRAMEWORK_LENGTH, UX_NULL);
376 
377     /* Check for error.  */
378     if (status != UX_SUCCESS)
379     {
380 
381         printf("Running ux_host_stack_interface_setting_select Test................. ERROR #5\n");
382         test_control_return(1);
383     }
384 
385     /* Set the parameters for callback when insertion/extraction of a Data Pump device.  */
386     parameter.ux_slave_class_dpump_instance_activate   =  ux_test_instance_activate;
387     parameter.ux_slave_class_dpump_instance_deactivate =  ux_test_instance_deactivate;
388 
389     /* Initialize the device dpump class. The class is connected with interface 0 */
390     status =  ux_device_stack_class_register(_ux_system_slave_class_dpump_name, test_ux_device_class_dpump_entry,
391                                               1, 0, &parameter);
392 
393     /* Initialize the hid class parameters.  */
394     ux_utility_memory_set(&hid_parameter, 0, sizeof(UX_SLAVE_CLASS_HID_PARAMETER));
395     hid_parameter.ux_device_class_hid_parameter_report_address = hid_mouse_report;
396     hid_parameter.ux_device_class_hid_parameter_report_length  = HID_MOUSE_REPORT_LENGTH;
397     hid_parameter.ux_device_class_hid_parameter_callback       = UX_NULL;
398     hid_parameter.ux_slave_class_hid_instance_activate         = UX_NULL;
399 
400     status |= ux_device_stack_class_register(_ux_system_slave_class_hid_name, test_ux_device_class_hid_entry,
401                                               1, 1, &hid_parameter);
402 #if UX_MAX_SLAVE_CLASS_DRIVER > 1
403     /* Check for error.  */
404     if (status != UX_SUCCESS)
405     {
406 
407         printf("Running ux_host_stack_interface_setting_select Test................. ERROR #6\n");
408         test_control_return(1);
409     }
410 #endif
411     /* Initialize the simulated device controller.  */
412     status =  _ux_test_dcd_sim_slave_initialize();
413 
414     /* Check for error.  */
415     if (status != UX_SUCCESS)
416     {
417 
418         printf("Running ux_host_stack_interface_setting_select Test................. ERROR #7\n");
419         test_control_return(1);
420     }
421 
422     /* Register all the USB host controllers available in this system */
423     status =  ux_host_stack_hcd_register(_ux_system_host_hcd_simulator_name, _ux_test_hcd_sim_host_initialize,0,0);
424 
425     /* Check for error.  */
426     if (status != UX_SUCCESS)
427     {
428 
429         printf("Running ux_host_stack_interface_setting_select Test................. ERROR #4\n");
430         test_control_return(1);
431     }
432 
433     /* Create the main host simulation thread.  */
434     status =  tx_thread_create(&ux_test_thread_simulation_0, "test host simulation", ux_test_thread_simulation_0_entry, 0,
435             stack_pointer, UX_TEST_STACK_SIZE,
436             20, 20, 1, TX_AUTO_START);
437 
438     /* Check for error.  */
439     if (status != TX_SUCCESS)
440     {
441 
442         printf("Running ux_host_stack_interface_setting_select Test................. ERROR #8\n");
443         test_control_return(1);
444     }
445 }
446 
447 
ux_test_thread_simulation_0_entry(ULONG arg)448 static void  ux_test_thread_simulation_0_entry(ULONG arg)
449 {
450 
451 UINT                     status;
452 INT                      i;
453 UX_DEVICE               *device;
454 UX_CONFIGURATION        *configuration;
455 UX_INTERFACE            *interface;
456 UX_INTERFACE            *interfaces[8];
457 
458 
459     /* Inform user.  */
460     printf("Running ux_host_stack_interface_setting_select Test................. ");
461 
462     ux_test_dcd_sim_slave_connect(UX_HIGH_SPEED_DEVICE);
463     ux_test_hcd_sim_host_connect(UX_HIGH_SPEED_DEVICE);
464 
465     /* Enumeration check. */
466     if (dpump_slave == UX_NULL)
467     {
468 
469         printf("ERROR #%d: Enum fail\n", __LINE__);
470         test_control_return(1);
471     }
472 
473     status = ux_host_stack_device_get(0, &device);
474     if (status != UX_SUCCESS)
475     {
476 
477         printf("ERROR #%d: device_get fail\n", __LINE__);
478         test_control_return(1);
479     }
480 
481     status = ux_host_stack_device_configuration_get(device, 0, &configuration);
482     if (status != UX_SUCCESS)
483     {
484 
485         printf("ERROR #%d: cfg_get fail\n", __LINE__);
486         test_control_return(1);
487     }
488 
489     interface = configuration->ux_configuration_first_interface;
490     for (i = 0; i < 8; i ++)
491     {
492 
493         if (interface == UX_NULL)
494             break;
495 
496         interfaces[i] = interface;
497         interface = interface->ux_interface_next_interface;
498     }
499 
500     /* Switch to interface 0.1 */
501     status = ux_host_stack_interface_setting_select(interfaces[1]);
502     if (status != UX_SUCCESS)
503     {
504 
505         printf("ERROR #%d: ifc_set fail\n", __LINE__);
506         error_counter ++;
507     }
508 
509     /* Switch to interface 0.0 */
510     status = ux_host_stack_interface_setting_select(interfaces[0]);
511     if (status != UX_SUCCESS)
512     {
513 
514         printf("ERROR #%d: ifc_set fail\n", __LINE__);
515         error_counter ++;
516     }
517 
518     /* Expect errors so skip them in error handler. */
519     expect_errors = UX_TRUE;
520 
521     /* Test invalid interface handler. */
522     interface = interfaces[0];
523     interface->ux_interface_handle = 0;
524 
525     status = ux_host_stack_interface_setting_select(interface);
526     if (status != UX_INTERFACE_HANDLE_UNKNOWN)
527     {
528 
529         printf("ERROR #%d: expect UX_INTERFACE_HANDLE_UNKNOWN but get %x\n", __LINE__, status);
530         error_counter ++;
531     }
532     interface->ux_interface_handle = (ULONG)(ALIGN_TYPE)interface;
533 
534     /* Test interface instance creation failure. */
535     /* Simulate endpoint creation fail. */
536     status  = ux_host_stack_interface_setting_select(interfaces[1]);
537     ux_test_hcd_sim_host_set_actions(hcd_create_endpoint_fail);
538     status |= ux_host_stack_interface_setting_select(interfaces[0]);
539     if (status == UX_SUCCESS)
540     {
541 
542         printf("ERROR #%d: expect error but get %x\n", __LINE__, status);
543         error_counter ++;
544     }
545 
546     /* Test SET_INTERFACE request error. */
547     status  = ux_host_stack_interface_setting_select(interfaces[1]);
548     ux_test_hcd_sim_host_set_actions(hcd_set_interface_fail);
549     status |= ux_host_stack_interface_setting_select(interfaces[0]);
550     if (status == UX_SUCCESS)
551     {
552 
553         printf("ERROR #%d: expect error but get %x\n", __LINE__, status);
554         error_counter ++;
555     }
556 
557     /* Break on errors. */
558     expect_errors = UX_TRUE;
559 
560     /* Switch to interface 2 0 */
561     UX_TEST_ASSERT(ux_test_check_actions_empty());
562     status = ux_host_stack_interface_setting_select(interfaces[2]);
563     if (status != UX_SUCCESS)
564     {
565 
566         printf("ERROR #%d: ifc_set fail\n", __LINE__);
567         error_counter ++;
568     }
569 
570     /* Test Semphor get error */
571     _ux_utility_semaphore_delete(&device -> ux_device_protection_semaphore);
572     status = ux_host_stack_interface_setting_select(interfaces[2]);
573     if (status == UX_SUCCESS)
574     {
575 
576         printf("ERROR #%d: expect error but get %x\n", __LINE__, status);
577         error_counter ++;
578     }
579     _ux_utility_semaphore_create(&device -> ux_device_protection_semaphore, "ux_device_protection_semaphore", 1);
580     /* Sleep for a tick to make sure everything is complete.  */
581     tx_thread_sleep(1);
582 
583     /* Check for errors from other threads.  */
584     if (error_counter)
585     {
586 
587         /* Test error.  */
588         printf("ERROR #14\n");
589         test_control_return(1);
590     }
591     else
592     {
593 
594         /* Successful test.  */
595         printf("SUCCESS!\n");
596         test_control_return(0);
597     }
598 }
599 
ux_test_instance_activate(VOID * dpump_instance)600 static VOID  ux_test_instance_activate(VOID *dpump_instance)
601 {
602 
603     /* Save the DPUMP instance.  */
604     dpump_slave = (UX_SLAVE_CLASS_DPUMP *) dpump_instance;
605 }
606 
ux_test_instance_deactivate(VOID * dpump_instance)607 static VOID  ux_test_instance_deactivate(VOID *dpump_instance)
608 {
609 
610     /* Reset the DPUMP instance.  */
611     dpump_slave = UX_NULL;
612 }
613 
614