1 /* USBX common things for testing. */
2 
3 #ifndef _UX_TEST_H
4 #define _UX_TEST_H
5 
6 #include "nx_api.h"
7 #include "ux_api.h"
8 
9 #if 0
10 #define stepinfo printf
11 #else
12 #define stepinfo(...)
13 #endif
14 
15 
16 /* Compile options check.  */
17 /*
18 UX_MAX_HCD=1
19 UX_MAX_CLASS_DRIVER=1
20 UX_MAX_DEVICES=1
21 UX_DEVICE_INITIALIZE_FRAMEWORK_SCAN_DISABLE
22 UX_MAX_DEVICE_ENDPOINTS=2
23 UX_MAX_DEVICE_INTERFACES=1
24 UX_MAX_SLAVE_INTERFACES=1
25 UX_MAX_SLAVE_CLASS_DRIVER=1
26 UX_MAX_SLAVE_LUN=1
27 */
28 #define UX_TEST_MULTI_HCD_ON        (UX_MAX_HCD > 1)
29 #define UX_TEST_MULTI_IFC_OVER(n)   (                           \
30     (UX_MAX_SLAVE_INTERFACES > (n)) &&                          \
31     (!defined(UX_DEVICE_INITIALIZE_FRAMEWORK_SCAN_DISABLE) ||   \
32         (UX_MAX_DEVICE_INTERFACES > (n))) )
33 #define UX_TEST_MULTI_IFC_ON        UX_TEST_MULTI_IFC_OVER(1)
34 #define UX_TEST_MULTI_ALT_ON        (                           \
35     !defined(UX_DEVICE_ALTERNATE_SETTING_SUPPORT_DISABLE))
36 #define UX_TEST_MULTI_CLS_OVER(n)   (                           \
37     UX_MAX_CLASS_DRIVER > (n) &&                                \
38     UX_MAX_SLAVE_CLASS_DRIVER > (n) )
39 #define UX_TEST_MULTI_CLS_ON        UX_TEST_MULTI_CLS_OVER(1)
40 #define UX_TEST_MULTI_DEV_ON        (UX_MAX_DEVICES > 1)
41 #define UX_TEST_MULTI_EP_OVER(n)    (                           \
42     (UX_MAX_DEVICE_ENDPOINTS > (n)) ||                          \
43     (!defined(UX_DEVICE_INITIALIZE_FRAMEWORK_SCAN_DISABLE)))
44 
45 /* Define macros. */
46 #define ARRAY_COUNT(array)  (sizeof(array)/sizeof(array[0]))
47 
48 extern char *ux_test_file_base_name(char *path, int n);
49 #define UX_TEST_FILE_BASE_NAME(s)                   (ux_test_file_base_name(s, sizeof(s)))
50 #define UX_TEST_FILE                                UX_TEST_FILE_BASE_NAME(__FILE__)
51 
52 #define UX_TEST_ASSERT(expression)                  if (!(expression)) { printf("%s:%d Assert failed\n", UX_TEST_FILE, __LINE__); test_control_return(1); }
53 #define UX_TEST_ASSERT_MESSAGE(expression, ...)     if (!(expression)) { printf("%s:%d Assert failed; ", UX_TEST_FILE, __LINE__); printf(__VA_ARGS__); test_control_return(1); }
54 #define UX_TEST_CHECK_CODE(code, expression) \
55     { \
56         UINT __status__ = (expression); \
57         if (__status__ != (code)) \
58         { \
59             printf("%s : %d, error: 0x%x\n", UX_TEST_FILE_BASE_NAME(__FILE__), __LINE__, __status__); \
60             test_control_return(1); \
61         } \
62     }
63 #define UX_TEST_CHECK_NOT_CODE(code, expression) \
64     { \
65         UINT __status__ = (expression); \
66         if (__status__ == (code)) \
67         { \
68             printf("%s:%d error: 0x%x\n", UX_TEST_FILE, __LINE__, __status__); \
69             test_control_return(1); \
70         } \
71     }
72 #define UX_TEST_CHECK_SUCCESS(expression) UX_TEST_CHECK_CODE(UX_SUCCESS, expression)
73 #define UX_TEST_CHECK_NOT_SUCCESS(expression) UX_TEST_CHECK_NOT_CODE(UX_SUCCESS, expression)
74 
75 typedef struct UX_TEST_ERROR_CALLBACK_ERROR_STRUCT
76 {
77     UINT system_level;
78     UINT system_context;
79     UINT error_code;
80 
81     struct UX_TEST_ERROR_CALLBACK_ERROR_STRUCT *next;
82 } UX_TEST_ERROR_CALLBACK_ERROR;
83 
84 typedef struct UX_TEST_ERROR_CALLBACK_ACTION_STRUCT
85 {
86     UX_TEST_ERROR_CALLBACK_ERROR *error;
87     VOID (*entry_func_error_callback_action)();
88     UINT do_return;
89 
90     struct UX_TEST_ERROR_CALLBACK_ACTION *next;
91 } UX_TEST_ERROR_CALLBACK_ACTION;
92 
93 /* General setup request */
94 
95 typedef struct _UX_TEST_SETUP_STRUCT {
96     UCHAR  ux_test_setup_type;
97     UCHAR  ux_test_setup_request;
98     USHORT ux_test_setup_value;
99     USHORT ux_test_setup_index;
100 } UX_TEST_SETUP;
101 
102 /* Interaction descriptor to insert action on specific entry function call. */
103 /* function, request to match, port action, port status, request action, request EP, request data, request actual length, request status, status, additional callback, no return, thread */
104 
105 typedef struct UX_TEST_ACTION_STRUCT {
106 
107     /* Function code to match */
108     ULONG function;
109     /* Setup request to match */
110     UX_TEST_SETUP *req_setup;
111 
112     /* Port action flags */
113     ULONG port_action;
114     ULONG port_status;
115 
116     /* Request action flags */
117     ULONG req_action;
118     ULONG req_ep_address;
119     UCHAR *req_data;
120     /* For comparing data, use this, not req_requested_len. */
121     ULONG  req_actual_len;
122     ULONG  req_status;
123 
124     /* Status to return */
125     ULONG status;
126 
127     /* Additional callback */
128     VOID (*action_func)(struct UX_TEST_ACTION_STRUCT *action, VOID *params);
129 
130     /* No return */
131     ULONG no_return;
132 
133     ULONG req_requested_len;
134 
135     /* _ux_host_stack_class_instance_create */
136     UCHAR   *class_name;
137     UINT    class_name_length;
138 
139     /* _ux_device_stack_transfer_request */
140     UCHAR   endpoint_address;
141     ULONG   slave_length;
142     ULONG   host_length;
143 
144     /* ux_host_stack_transfer_request_action */
145     ULONG   requested_length;
146     UINT    type;
147     UINT    value;
148     UINT    index;
149     UCHAR   *data;
150     /* For matching parts of a transfer.  */
151     UCHAR   *req_data_match_mask;
152 
153     /* _ux_device_stack_transfer_abort (none) */
154 
155     /* _ux_host_class_storage_media_write */
156     ULONG   sector_start;
157     ULONG   sector_count;
158     UCHAR   *data_pointer;
159 
160     /* _ux_host_stack_interface_set */
161     ULONG   bInterfaceNumber;
162     ULONG   bAlternateSetting;
163 
164     /* _ux_utility_memory_allocate */
165     ULONG memory_alignment;
166     ULONG memory_cache_flag;
167     ULONG memory_size_requested;
168 
169     /* if there is name.  */
170     CHAR *name_ptr;
171 
172     /* tx_semaphore_get */
173     TX_SEMAPHORE    *semaphore_ptr;
174     ULONG           wait_option;
175 
176     /* tx_semaphore_get */
177     TX_MUTEX    *mutex_ptr;
178     UINT         inherit;
179 
180     /* tx_semaphore_create */
181     CHAR        *semaphore_name;
182 
183     /* ux_test_error_callback */
184     UINT system_level;
185     UINT system_context;
186     UINT error_code;
187 
188     /* ux_slave_class_storage_media_read/write */
189     VOID    *storage;
190     ULONG   lun;
191     USHORT  number_blocks;
192     ULONG lba;
193     ULONG *media_status;
194 
195     /* ux_slave_class_storage_media_status */
196     ULONG media_id;
197 
198     /* tx_thread_preemption_change */
199     TX_THREAD *thread_ptr;
200     UINT new_threshold;
201 
202     /* _ux_host_stack_interface_set */
203     UX_INTERFACE *interface;
204 
205     /* Thread to match. Necessary due to the following case: The storage class has a background thread that runs every 2
206        seconds and performs a bulk transaction. What could happen is that we call ux_test_hcd_sim_host_set_actions and
207        get preempted before actually starting the test. This could cause the action to match a transaction made by
208        storage's background thread. */
209     TX_THREAD *thread_to_match;
210 
211     /* Whether we invoke our callback before or after we call the real HCD. */
212     UCHAR do_after;
213 
214     /* User data. */
215     ALIGN_TYPE user_data;
216 
217     /* Additional check. */
218     UCHAR (*check_func)();
219 
220     /* If set, the params are ignored. */
221     UCHAR ignore_params;
222 
223     struct UX_TEST_ACTION_STRUCT *next;
224     struct UX_TEST_ACTION_STRUCT *created_list_next;
225     UCHAR matched;
226     ULONG usbx_function;
227 } UX_TEST_ACTION;
228 
229 typedef UX_TEST_ACTION UX_TEST_SIM_ENTRY_ACTION;
230 
231 typedef enum UX_TEST_FUNCTIONS
232 {
233     UX_TEST_NULL,
234     UX_TEST_OVERRIDE_TX_SEMAPHORE_GET,
235     UX_TEST_OVERRIDE_TX_SEMAPHORE_CREATE,
236     UX_TEST_OVERRIDE_TX_THREAD_PREEMPTION_CHANGE,
237     UX_TEST_OVERRIDE_TX_THREAD_CREATE,
238     UX_TEST_OVERRIDE_NX_PACKET_POOL_CREATE,
239     UX_TEST_OVERRIDE_NX_PACKET_ALLOCATE,
240     UX_TEST_OVERRIDE_TX_MUTEX_CREATE,
241     UX_TEST_OVERRIDE_TX_MUTEX_PUT,
242     UX_TEST_OVERRIDE_TX_MUTEX_GET,
243     UX_TEST_OVERRIDE_UX_HCD_SIM_HOST_ENTRY,
244     UX_TEST_OVERRIDE_UX_DCD_SIM_SLAVE_FUNCTION,
245     UX_TEST_OVERRIDE_UX_UTILITY_MEMORY_ALLOCATE,
246 
247     /* Define functions where it's okay to return/change the logic. This should
248        only include user callbacks.  */
249     UX_TEST_OVERRIDE_USER_CALLBACKS,
250     UX_TEST_OVERRIDE_ERROR_CALLBACK,
251     UX_TEST_OVERRIDE_UX_DEVICE_MEDIA_READ,
252     UX_TEST_OVERRIDE_UX_DEVICE_MEDIA_WRITE,
253     UX_TEST_OVERRIDE_UX_DEVICE_MEDIA_FLUSH,
254     UX_TEST_OVERRIDE_UX_DEVICE_MEDIA_STATUS,
255 
256     /* Only for race condition tests. */
257     UX_TEST_OVERRIDE_RACE_CONDITION_OVERRIDES,
258     UX_TEST_OVERRIDE_UX_HOST_STACK_TRANSFER_REQUEST,
259     UX_TEST_OVERRIDE_UX_HOST_STACK_INTERFACE_SET,
260 
261     UX_TEST_NUMBER_OVERRIDES,
262 } UX_TEST_FUNCTION;
263 
264 typedef struct UX_TEST_OVERRIDE_NX_PACKET_ALLOCATE_PARAMS
265 {
266     NX_PACKET_POOL  *pool_ptr;
267 } UX_TEST_OVERRIDE_NX_PACKET_ALLOCATE_PARAMS;
268 
269 typedef struct UX_TEST_OVERRIDE_NX_PACKET_POOL_CREATE_PARAMS
270 {
271     CHAR *name_ptr;
272 } UX_TEST_OVERRIDE_NX_PACKET_POOL_CREATE_PARAMS;
273 
274 typedef struct UX_TEST_OVERRIDE_UX_DEVICE_MEDIA_READ_WRITE_PARAMS
275 {
276     VOID *storage;
277     ULONG lun;
278     UCHAR *data_pointer;
279     ULONG number_blocks;
280     ULONG lba;
281     ULONG *media_status;
282 } UX_TEST_OVERRIDE_UX_DEVICE_MEDIA_READ_WRITE_FLUSH_PARAMS;
283 
284 typedef struct UX_TEST_OVERRIDE_UX_DEVICE_MEDIA_STATUS_PARAMS
285 {
286     VOID *storage;
287     ULONG lun;
288     ULONG media_id;
289     ULONG *media_status;
290 } UX_TEST_OVERRIDE_UX_DEVICE_MEDIA_STATUS_PARAMS;
291 
292 typedef struct UX_TEST_OVERRIDE_UX_UTILITY_MEMORY_ALLOCATE_PARAMS
293 {
294     ULONG memory_alignment;
295     ULONG memory_cache_flag;
296     ULONG memory_size_requested;
297 } UX_TEST_OVERRIDE_UX_UTILITY_MEMORY_ALLOCATE_PARAMS;
298 
299 typedef struct UX_TEST_OVERRIDE_UX_DCD_SIM_SLAVE_FUNCTION_PARAMS
300 {
301     UX_SLAVE_DCD *dcd;
302     UINT function;
303     VOID *parameter;
304 } UX_TEST_OVERRIDE_UX_DCD_SIM_SLAVE_FUNCTION_PARAMS;
305 
306 typedef struct UX_TEST_OVERRIDE_UX_HCD_SIM_HOST_ENTRY_PARAMS
307 {
308     UX_HCD *hcd;
309     UINT function;
310     VOID *parameter;
311 } UX_TEST_OVERRIDE_UX_HCD_SIM_HOST_ENTRY_PARAMS;
312 
313 typedef struct UX_TEST_OVERRIDE_TX_SEMAPHORE_GET_PARAMS
314 {
315     TX_SEMAPHORE *semaphore_ptr;
316     ULONG wait_option;
317 } UX_TEST_OVERRIDE_TX_SEMAPHORE_GET_PARAMS;
318 
319 typedef struct UX_TEST_OVERRIDE_TX_MUTEX_CREATE_PARAMS
320 {
321     TX_MUTEX *mutex_ptr;
322     CHAR     *name_ptr;
323     UINT     inherit;
324 } UX_TEST_OVERRIDE_TX_MUTEX_CREATE_PARAMS;
325 
326 typedef struct UX_TEST_OVERRIDE_TX_MUTEX_GET_PARAMS
327 {
328     TX_MUTEX *mutex_ptr;
329     ULONG wait_option;
330 } UX_TEST_OVERRIDE_TX_MUTEX_GET_PARAMS;
331 
332 typedef struct UX_TEST_OVERRIDE_TX_MUTEX_PUT_PARAMS
333 {
334     TX_MUTEX *mutex_ptr;
335 } UX_TEST_OVERRIDE_TX_MUTEX_PUT_PARAMS;
336 
337 typedef struct UX_TEST_OVERRIDE_TX_SEMAPHORE_CREATE_PARAMS
338 {
339     TX_SEMAPHORE *semaphore;
340     CHAR *semaphore_name;
341     UINT initial_count;
342 } UX_TEST_OVERRIDE_TX_SEMAPHORE_CREATE_PARAMS;
343 
344 typedef struct UX_TEST_OVERRIDE_TX_THREAD_CREATE_PARAMS
345 {
346     /* We only care about the name. */
347     CHAR *name_ptr;
348 } UX_TEST_OVERRIDE_TX_THREAD_CREATE_PARAMS;
349 
350 typedef struct UX_TEST_OVERRIDE_UX_HOST_STACK_TRANSFER_REQUEST_PARAMS
351 {
352     UX_TRANSFER *transfer_request;
353 } UX_TEST_OVERRIDE_UX_HOST_STACK_TRANSFER_REQUEST_PARAMS;
354 
355 typedef struct UX_TEST_OVERRIDE_TX_THREAD_PREEMPTION_CHANGE_PARAMS
356 {
357     TX_THREAD *thread_ptr;
358     UINT new_threshold;
359 } UX_TEST_OVERRIDE_TX_THREAD_PREEMPTION_CHANGE_PARAMS;
360 
361 typedef struct UX_TEST_OVERRIDE_UX_HOST_STACK_INTERFACE_SET_PARAMS
362 {
363     UX_INTERFACE *interface;
364 } UX_TEST_OVERRIDE_UX_HOST_STACK_INTERFACE_SET_PARAMS;
365 
366 typedef struct UX_TEST_OVERRIDE_NX_PACKET_TRANSMIT_RELEASE_PARAMS
367 {
368     NX_PACKET **packet_ptr_ptr;
369 } UX_TEST_OVERRIDE_NX_PACKET_TRANSMIT_RELEASE_PARAMS;
370 
371 typedef struct UX_TEST_ERROR_CALLBACK_PARAMS
372 {
373     UINT system_level;
374     UINT system_context;
375     UINT error_code;
376 } UX_TEST_ERROR_CALLBACK_PARAMS;
377 
378 typedef struct UX_TEST_GENERIC_CD
379 {
380     VOID *controller_driver;
381     UINT function;
382     VOID *parameter;
383 } UX_TEST_GENERIC_CD;
384 
385 typedef struct UX_MEMORY_BLOCK_STRUCT
386 {
387     struct UX_MEMORY_BLOCK_STRUCT *ux_memory_block_next;
388     UX_MEMORY_BYTE_POOL           *ux_memory_byte_pool;
389 } UX_MEMORY_BLOCK;
390 
391 UINT ux_test_list_action_compare(UX_TEST_ACTION *list_item, UX_TEST_ACTION *action);
392 
393 VOID ux_test_remove_hook(UX_TEST_ACTION *action);
394 VOID ux_test_remove_hooks_from_array(UX_TEST_ACTION *actions);
395 VOID ux_test_remove_hooks_from_list(UX_TEST_ACTION *actions);
396 
397 UINT ux_test_link_hook(UX_TEST_ACTION *action);
398 VOID ux_test_link_hooks_from_array(UX_TEST_ACTION *actions);
399 VOID ux_test_link_hooks_from_list(UX_TEST_ACTION *actions);
400 
401 UINT ux_test_add_hook(UX_TEST_ACTION action);
402 VOID ux_test_add_hooks_from_array(UX_TEST_ACTION *actions);
403 VOID ux_test_add_hooks_from_list(UX_TEST_ACTION *actions);
404 
405 ULONG ux_test_do_hooks_before(UX_TEST_FUNCTION usbx_function, VOID *params);
406 VOID ux_test_do_hooks_after(UX_TEST_FUNCTION usbx_function, VOID *params);
407 
408 VOID ux_test_free_hook_actions();
409 
410 VOID ux_test_free_user_list_actions();
411 VOID ux_test_set_main_action_list_from_array(UX_TEST_ACTION *action);
412 VOID ux_test_set_main_action_list_from_list(UX_TEST_ACTION *new_actions);
413 VOID ux_test_add_action_to_user_list(UX_TEST_ACTION *list, UX_TEST_ACTION new_action);
414 VOID ux_test_add_action_to_main_list(UX_TEST_ACTION action);
415 VOID ux_test_add_action_to_main_list_multiple(UX_TEST_ACTION action, UINT);
416 VOID ux_test_hcd_sim_host_set_actions(UX_TEST_ACTION *action);
417 VOID ux_test_dcd_sim_slave_set_actions(UX_TEST_ACTION *action);
418 UX_TEST_ACTION ux_test_action_handler(UX_TEST_FUNCTION usbx_function, void *_params);
419 VOID ux_test_do_action_before(UX_TEST_ACTION *action, VOID *params);
420 VOID ux_test_do_action_after(UX_TEST_ACTION *action, VOID *params);
421 VOID ux_test_ignore_all_errors();
422 VOID ux_test_unignore_all_errors();
423 VOID ux_test_clear_main_list_actions();
424 VOID ux_test_cleanup_everything(VOID);
425 VOID ux_test_turn_off_expedient(UCHAR *);
426 VOID ux_test_turn_on_expedient(UCHAR *);
427 UCHAR ux_test_is_expedient_on();
428 VOID ux_test_set_expedient(UCHAR);
429 ULONG ux_test_calc_total_memory_allocated(ULONG memory_alignment, ULONG memory_cache_flag, ULONG memory_size_requested);
430 UCHAR ux_test_check_actions_empty();
431 UINT ux_test_wait_for_empty_actions();
432 UINT ux_test_get_num_actions_left();
433 extern UX_TEST_ERROR_CALLBACK_ERROR ux_error_hcd_transfer_stalled;
434 VOID ux_test_error_callback(UINT system_level, UINT system_context, UINT error_code);
435 void ux_test_disconnect_slave_and_host_wait_for_enum_completion();
436 VOID ux_test_connect_slave_and_host_wait_for_enum_completion();
437 void ux_test_memory_test_initialize();
438 void ux_test_memory_test_check();
439 void ux_test_disconnect_slave_and_host_wait_for_enum_completion();
440 VOID ux_test_wait_for_enum_thread_completion();
441 UINT ux_test_host_stack_class_instance_get(UX_HOST_CLASS *host_class, UINT class_index, VOID **class_instance);
442 UINT ux_test_wait_for_value_uint(UINT *current_value, UINT desired_value);
443 UINT ux_test_wait_for_value_ulong(ULONG *current_value, ULONG desired_value);
444 UINT ux_test_wait_for_value_uchar(UCHAR *current_value_ptr, UCHAR desired_value);
445 UINT ux_test_wait_for_non_null(VOID **current_value_ptr);
446 UINT ux_test_wait_for_null(VOID **current_value_ptr);
447 VOID ux_test_connect_host_wait_for_enum_completion();
448 VOID ux_test_disconnect_host_no_wait();
449 VOID ux_test_disconnect_slave();
450 VOID ux_test_connect_slave();
451 VOID ux_test_disconnect_host_wait_for_enum_completion();
452 VOID ux_test_change_device_parameters(UCHAR * device_framework_high_speed, ULONG device_framework_length_high_speed,
453                                       UCHAR * device_framework_full_speed, ULONG device_framework_length_full_speed,
454                                       UCHAR * string_framework, ULONG string_framework_length,
455                                       UCHAR * language_id_framework, ULONG language_id_framework_length,
456                                       UINT(*ux_system_slave_change_function)(ULONG));
457 UINT ux_test_wait_for_empty_actions_wait_time(UINT wait_time_ms);
458 UINT ux_test_wait_for_null_wait_time(VOID **current_value_ptr, UINT wait_time_ms);
459 
460 VOID _ux_test_main_action_list_thread_update(TX_THREAD *old, TX_THREAD *new);
461 VOID _ux_test_main_action_list_semaphore_update(TX_SEMAPHORE *old, TX_SEMAPHORE *new);
462 VOID _ux_test_main_action_list_mutex_update(TX_MUTEX *old, TX_MUTEX *new);
463 
464 UINT ux_test_host_endpoint_write(UX_ENDPOINT *endpoint, UCHAR *buffer, ULONG length, ULONG *actual_length);
465 
466 /* Action flags */
467 
468 #define UX_TEST_SIM_REQ_ANSWER 0x80
469 
470 #define UX_TEST_MATCH_EP      0x01
471 #define UX_TEST_MATCH_REQ_LEN 0x40
472 
473 #define UX_TEST_SETUP_MATCH_REQUEST 0x02
474 #define UX_TEST_SETUP_MATCH_VALUE   0x04
475 #define UX_TEST_SETUP_MATCH_INDEX   0x08
476 
477 #define UX_TEST_SETUP_MATCH_REQ (UX_TEST_SETUP_MATCH_REQUEST)
478 #define UX_TEST_SETUP_MATCH_REQ_V (UX_TEST_SETUP_MATCH_REQ | UX_TEST_SETUP_MATCH_VALUE)
479 #define UX_TEST_SETUP_MATCH_REQ_V_I (UX_TEST_SETUP_MATCH_REQ_V | UX_TEST_SETUP_MATCH_INDEX)
480 
481 #define UX_TEST_SETUP_MATCH_EP_REQ (UX_TEST_SETUP_MATCH_REQUEST | UX_TEST_MATCH_EP)
482 #define UX_TEST_SETUP_MATCH_EP_REQ_V (UX_TEST_SETUP_MATCH_EP_REQ | UX_TEST_SETUP_MATCH_VALUE)
483 #define UX_TEST_SETUP_MATCH_EP_REQ_V_I (UX_TEST_SETUP_MATCH_EP_REQ_V | UX_TEST_SETUP_MATCH_INDEX)
484 
485 /* Expected Requests */
486 
487 #define UX_TEST_SETUP_SetAddress   {0x00,0x05,0x0001,0x0000}
488 #define UX_TEST_SETUP_GetDevDescr  {0x80,0x06,0x0100,0x0000}
489 #define UX_TEST_SETUP_GetCfgDescr  {0x80,0x06,0x0200,0x0000}
490 #define UX_TEST_SETUP_SetConfigure {0x00,0x09,0x0001,0x0000}
491 
492 #define UX_TEST_SETUP_CDCACM_GetLineCoding    {0xa1, 0x21, 0x0000, 0x0000}
493 #define UX_TEST_SETUP_CDCACM_SetLineCoding    {0x21, 0x20, 0x0000, 0x0000}
494 #define UX_TEST_SETUP_CDCACM_SetLineState     {0x21, 0x22, 0x0003, 0x0000}
495 
496 #define UX_TEST_SETUP_STORAGE_GetMaxLun       {0xa1, 0xfe, 0x0000, 0x0001}
497 #define UX_TEST_SETUP_STORAGE_Reset           {0x21, 0xff, 0x0000, 0x0000}
498 
499 #define UX_TEST_PORT_STATUS_DISC    0
500 #define UX_TEST_PORT_STATUS_LS_CONN UX_PS_CCS | UX_PS_DS_LS
501 #define UX_TEST_PORT_STATUS_FS_CONN UX_PS_CCS | UX_PS_DS_FS
502 #define UX_TEST_PORT_STATUS_HS_CONN UX_PS_CCS | UX_PS_DS_HS
503 
504 
505 
506 UINT ux_test_breakable_sleep(ULONG tick, UINT (*sleep_break_check_callback)(VOID));
507 UINT ux_test_sleep_break_if(ULONG tick, UINT (*check)(VOID), UINT break_on_match_or_not, UINT rc_to_match);
508 #define ux_test_sleep(t) ux_test_sleep_break_if(t, UX_NULL, 1, UX_SUCCESS)
509 #define ux_test_sleep_break_on_success(t,c) ux_test_sleep_break_if(t, c, 1, UX_SUCCESS)
510 #define ux_test_sleep_break_on_error(t,c) ux_test_sleep_break_if(t, c, 0, UX_SUCCESS)
511 
512 void  test_control_return(UINT status);
513 
514 void  ux_test_assert_hit_hint(UCHAR on_off);
515 void  ux_test_assert_hit_exit(UCHAR on_off);
516 ULONG ux_test_assert_hit_count_get(void);
517 void  ux_test_assert_hit_count_reset(void);
518 
ux_test_memory_is_freed(void * memory)519 static inline int ux_test_memory_is_freed(void *memory)
520 {
521 UCHAR               *work_ptr;
522 UCHAR               *temp_ptr;
523 ALIGN_TYPE          *free_ptr;
524 int                 is_free = 0;
525     UX_TEST_ASSERT(memory);
526     _ux_system_mutex_on(&_ux_system -> ux_system_mutex);
527     work_ptr =  UX_VOID_TO_UCHAR_POINTER_CONVERT(memory);
528     {
529         work_ptr =  UX_UCHAR_POINTER_SUB(work_ptr, UX_MEMORY_BLOCK_HEADER_SIZE);
530         temp_ptr =  UX_UCHAR_POINTER_ADD(work_ptr, (sizeof(UCHAR *)));
531         free_ptr =  UX_UCHAR_TO_ALIGN_TYPE_POINTER_CONVERT(temp_ptr);
532         if ((*free_ptr) == UX_BYTE_BLOCK_FREE)
533             is_free = 1;
534     }
535     _ux_system_mutex_off(&_ux_system -> ux_system_mutex);
536     return(is_free);
537 }
538 #define ux_test_regular_memory_free() _ux_system -> ux_system_memory_byte_pool[UX_MEMORY_BYTE_POOL_REGULAR] -> ux_byte_pool_available
539 
540 #endif /* _UX_TEST_H */
541