summaryrefslogtreecommitdiff
path: root/test/regression/ux_test.h
blob: d9c8642ed3ab9e5fd7c3f197eaeb9305a76f29b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
/***************************************************************************/
/* Copyright (c) 2024 Microsoft Corporation                                */
/* Copyright (c) 2026 Eclipse ThreadX contributors                         */
/*                                                                         */
/* This program and the accompanying materials are made available under    */
/* the terms of the MIT License which is available at                      */
/* https://opensource.org/licenses/MIT.                                    */
/*                                                                         */
/* SPDX-License-Identifier: MIT                                            */
/***************************************************************************/

/* USBX common things for testing. */

#ifndef _UX_TEST_H
#define _UX_TEST_H

#include "nx_api.h"
#include "ux_api.h"

#if 0
#define stepinfo printf
#else
#define stepinfo(...)
#endif


/* Compile options check.  */
/*
UX_MAX_HCD=1
UX_MAX_CLASS_DRIVER=1
UX_MAX_DEVICES=1
UX_DEVICE_INITIALIZE_FRAMEWORK_SCAN_DISABLE
UX_MAX_DEVICE_ENDPOINTS=2
UX_MAX_DEVICE_INTERFACES=1
UX_MAX_SLAVE_INTERFACES=1
UX_MAX_SLAVE_CLASS_DRIVER=1
UX_MAX_SLAVE_LUN=1
*/
#define UX_TEST_MULTI_HCD_ON        (UX_MAX_HCD > 1)
#define UX_TEST_MULTI_IFC_OVER(n)   (                           \
    (UX_MAX_SLAVE_INTERFACES > (n)) &&                          \
    (!defined(UX_DEVICE_INITIALIZE_FRAMEWORK_SCAN_DISABLE) ||   \
        (UX_MAX_DEVICE_INTERFACES > (n))) )
#define UX_TEST_MULTI_IFC_ON        UX_TEST_MULTI_IFC_OVER(1)
#define UX_TEST_MULTI_ALT_ON        (                           \
    !defined(UX_DEVICE_ALTERNATE_SETTING_SUPPORT_DISABLE))
#define UX_TEST_MULTI_CLS_OVER(n)   (                           \
    UX_MAX_CLASS_DRIVER > (n) &&                                \
    UX_MAX_SLAVE_CLASS_DRIVER > (n) )
#define UX_TEST_MULTI_CLS_ON        UX_TEST_MULTI_CLS_OVER(1)
#define UX_TEST_MULTI_DEV_ON        (UX_MAX_DEVICES > 1)
#define UX_TEST_MULTI_EP_OVER(n)    (                           \
    (UX_MAX_DEVICE_ENDPOINTS > (n)) ||                          \
    (!defined(UX_DEVICE_INITIALIZE_FRAMEWORK_SCAN_DISABLE)))

/* Define macros. */
#define ARRAY_COUNT(array)  (sizeof(array)/sizeof(array[0]))

extern char *ux_test_file_base_name(char *path, int n);
#define UX_TEST_FILE_BASE_NAME(s)                   (ux_test_file_base_name(s, sizeof(s)))
#define UX_TEST_FILE                                UX_TEST_FILE_BASE_NAME(__FILE__)

#define UX_TEST_ASSERT(expression)                  if (!(expression)) { printf("%s:%d Assert failed\n", UX_TEST_FILE, __LINE__); test_control_return(1); }
#define UX_TEST_ASSERT_MESSAGE(expression, ...)     if (!(expression)) { printf("%s:%d Assert failed; ", UX_TEST_FILE, __LINE__); printf(__VA_ARGS__); test_control_return(1); }
#define UX_TEST_CHECK_CODE(code, expression) \
    { \
        UINT __status__ = (expression); \
        if (__status__ != (code)) \
        { \
            printf("%s : %d, error: 0x%x\n", UX_TEST_FILE_BASE_NAME(__FILE__), __LINE__, __status__); \
            test_control_return(1); \
        } \
    }
#define UX_TEST_CHECK_NOT_CODE(code, expression) \
    { \
        UINT __status__ = (expression); \
        if (__status__ == (code)) \
        { \
            printf("%s:%d error: 0x%x\n", UX_TEST_FILE, __LINE__, __status__); \
            test_control_return(1); \
        } \
    }
#define UX_TEST_CHECK_SUCCESS(expression) UX_TEST_CHECK_CODE(UX_SUCCESS, expression)
#define UX_TEST_CHECK_NOT_SUCCESS(expression) UX_TEST_CHECK_NOT_CODE(UX_SUCCESS, expression)

typedef struct UX_TEST_ERROR_CALLBACK_ERROR_STRUCT
{
    UINT system_level;
    UINT system_context;
    UINT error_code;

    struct UX_TEST_ERROR_CALLBACK_ERROR_STRUCT *next;
} UX_TEST_ERROR_CALLBACK_ERROR;

typedef struct UX_TEST_ERROR_CALLBACK_ACTION_STRUCT
{
    UX_TEST_ERROR_CALLBACK_ERROR *error;
    VOID (*entry_func_error_callback_action)();
    UINT do_return;

    struct UX_TEST_ERROR_CALLBACK_ACTION *next;
} UX_TEST_ERROR_CALLBACK_ACTION;

/* General setup request */

typedef struct _UX_TEST_SETUP_STRUCT {
    UCHAR  ux_test_setup_type;
    UCHAR  ux_test_setup_request;
    USHORT ux_test_setup_value;
    USHORT ux_test_setup_index;
} UX_TEST_SETUP;

/* Interaction descriptor to insert action on specific entry function call. */
/* 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 */

typedef struct UX_TEST_ACTION_STRUCT {

    /* Function code to match */
    ULONG function;
    /* Setup request to match */
    UX_TEST_SETUP *req_setup;

    /* Port action flags */
    ULONG port_action;
    ULONG port_status;

    /* Request action flags */
    ULONG req_action;
    ULONG req_ep_address;
    UCHAR *req_data;
    /* For comparing data, use this, not req_requested_len. */
    ULONG  req_actual_len;
    ULONG  req_status;

    /* Status to return */
    ULONG status;

    /* Additional callback */
    VOID (*action_func)(struct UX_TEST_ACTION_STRUCT *action, VOID *params);

    /* No return */
    ULONG no_return;

    ULONG req_requested_len;

    /* _ux_host_stack_class_instance_create */
    UCHAR   *class_name;
    UINT    class_name_length;

    /* _ux_device_stack_transfer_request */
    UCHAR   endpoint_address;
    ULONG   slave_length;
    ULONG   host_length;

    /* ux_host_stack_transfer_request_action */
    ULONG   requested_length;
    UINT    type;
    UINT    value;
    UINT    index;
    UCHAR   *data;
    /* For matching parts of a transfer.  */
    UCHAR   *req_data_match_mask;

    /* _ux_device_stack_transfer_abort (none) */

    /* _ux_host_class_storage_media_write */
    ULONG   sector_start;
    ULONG   sector_count;
    UCHAR   *data_pointer;

    /* _ux_host_stack_interface_set */
    ULONG   bInterfaceNumber;
    ULONG   bAlternateSetting;

    /* _ux_utility_memory_allocate */
    ULONG memory_alignment;
    ULONG memory_cache_flag;
    ULONG memory_size_requested;

    /* if there is name.  */
    CHAR *name_ptr;

    /* tx_semaphore_get */
    TX_SEMAPHORE    *semaphore_ptr;
    ULONG           wait_option;

    /* tx_semaphore_get */
    TX_MUTEX    *mutex_ptr;
    UINT         inherit;

    /* tx_semaphore_create */
    CHAR        *semaphore_name;

    /* ux_test_error_callback */
    UINT system_level;
    UINT system_context;
    UINT error_code;

    /* ux_slave_class_storage_media_read/write */
    VOID    *storage;
    ULONG   lun;
    USHORT  number_blocks;
    ULONG lba;
    ULONG *media_status;

    /* ux_slave_class_storage_media_status */
    ULONG media_id;

    /* tx_thread_preemption_change */
    TX_THREAD *thread_ptr;
    UINT new_threshold;

    /* _ux_host_stack_interface_set */
    UX_INTERFACE *interface;

    /* Thread to match. Necessary due to the following case: The storage class has a background thread that runs every 2
       seconds and performs a bulk transaction. What could happen is that we call ux_test_hcd_sim_host_set_actions and
       get preempted before actually starting the test. This could cause the action to match a transaction made by
       storage's background thread. */
    TX_THREAD *thread_to_match;

    /* Whether we invoke our callback before or after we call the real HCD. */
    UCHAR do_after;

    /* User data. */
    ALIGN_TYPE user_data;

    /* Additional check. */
    UCHAR (*check_func)();

    /* If set, the params are ignored. */
    UCHAR ignore_params;

    struct UX_TEST_ACTION_STRUCT *next;
    struct UX_TEST_ACTION_STRUCT *created_list_next;
    UCHAR matched;
    ULONG usbx_function;
} UX_TEST_ACTION;

typedef UX_TEST_ACTION UX_TEST_SIM_ENTRY_ACTION;

typedef enum UX_TEST_FUNCTIONS
{
    UX_TEST_NULL,
    UX_TEST_OVERRIDE_TX_SEMAPHORE_GET,
    UX_TEST_OVERRIDE_TX_SEMAPHORE_CREATE,
    UX_TEST_OVERRIDE_TX_THREAD_PREEMPTION_CHANGE,
    UX_TEST_OVERRIDE_TX_THREAD_CREATE,
    UX_TEST_OVERRIDE_NX_PACKET_POOL_CREATE,
    UX_TEST_OVERRIDE_NX_PACKET_ALLOCATE,
    UX_TEST_OVERRIDE_TX_MUTEX_CREATE,
    UX_TEST_OVERRIDE_TX_MUTEX_PUT,
    UX_TEST_OVERRIDE_TX_MUTEX_GET,
    UX_TEST_OVERRIDE_UX_HCD_SIM_HOST_ENTRY,
    UX_TEST_OVERRIDE_UX_DCD_SIM_SLAVE_FUNCTION,
    UX_TEST_OVERRIDE_UX_UTILITY_MEMORY_ALLOCATE,

    /* Define functions where it's okay to return/change the logic. This should
       only include user callbacks.  */
    UX_TEST_OVERRIDE_USER_CALLBACKS,
    UX_TEST_OVERRIDE_ERROR_CALLBACK,
    UX_TEST_OVERRIDE_UX_DEVICE_MEDIA_READ,
    UX_TEST_OVERRIDE_UX_DEVICE_MEDIA_WRITE,
    UX_TEST_OVERRIDE_UX_DEVICE_MEDIA_FLUSH,
    UX_TEST_OVERRIDE_UX_DEVICE_MEDIA_STATUS,

    /* Only for race condition tests. */
    UX_TEST_OVERRIDE_RACE_CONDITION_OVERRIDES,
    UX_TEST_OVERRIDE_UX_HOST_STACK_TRANSFER_REQUEST,
    UX_TEST_OVERRIDE_UX_HOST_STACK_INTERFACE_SET,

    UX_TEST_NUMBER_OVERRIDES,
} UX_TEST_FUNCTION;

typedef struct UX_TEST_OVERRIDE_NX_PACKET_ALLOCATE_PARAMS
{
    NX_PACKET_POOL  *pool_ptr;
} UX_TEST_OVERRIDE_NX_PACKET_ALLOCATE_PARAMS;

typedef struct UX_TEST_OVERRIDE_NX_PACKET_POOL_CREATE_PARAMS
{
    CHAR *name_ptr;
} UX_TEST_OVERRIDE_NX_PACKET_POOL_CREATE_PARAMS;

typedef struct UX_TEST_OVERRIDE_UX_DEVICE_MEDIA_READ_WRITE_PARAMS
{
    VOID *storage;
    ULONG lun;
    UCHAR *data_pointer;
    ULONG number_blocks;
    ULONG lba;
    ULONG *media_status;
} UX_TEST_OVERRIDE_UX_DEVICE_MEDIA_READ_WRITE_FLUSH_PARAMS;

typedef struct UX_TEST_OVERRIDE_UX_DEVICE_MEDIA_STATUS_PARAMS
{
    VOID *storage;
    ULONG lun;
    ULONG media_id;
    ULONG *media_status;
} UX_TEST_OVERRIDE_UX_DEVICE_MEDIA_STATUS_PARAMS;

typedef struct UX_TEST_OVERRIDE_UX_UTILITY_MEMORY_ALLOCATE_PARAMS
{
    ULONG memory_alignment;
    ULONG memory_cache_flag;
    ULONG memory_size_requested;
} UX_TEST_OVERRIDE_UX_UTILITY_MEMORY_ALLOCATE_PARAMS;

typedef struct UX_TEST_OVERRIDE_UX_DCD_SIM_SLAVE_FUNCTION_PARAMS
{
    UX_SLAVE_DCD *dcd;
    UINT function;
    VOID *parameter;
} UX_TEST_OVERRIDE_UX_DCD_SIM_SLAVE_FUNCTION_PARAMS;

typedef struct UX_TEST_OVERRIDE_UX_HCD_SIM_HOST_ENTRY_PARAMS
{
    UX_HCD *hcd;
    UINT function;
    VOID *parameter;
} UX_TEST_OVERRIDE_UX_HCD_SIM_HOST_ENTRY_PARAMS;

typedef struct UX_TEST_OVERRIDE_TX_SEMAPHORE_GET_PARAMS
{
    TX_SEMAPHORE *semaphore_ptr;
    ULONG wait_option;
} UX_TEST_OVERRIDE_TX_SEMAPHORE_GET_PARAMS;

typedef struct UX_TEST_OVERRIDE_TX_MUTEX_CREATE_PARAMS
{
    TX_MUTEX *mutex_ptr;
    CHAR     *name_ptr;
    UINT     inherit;
} UX_TEST_OVERRIDE_TX_MUTEX_CREATE_PARAMS;

typedef struct UX_TEST_OVERRIDE_TX_MUTEX_GET_PARAMS
{
    TX_MUTEX *mutex_ptr;
    ULONG wait_option;
} UX_TEST_OVERRIDE_TX_MUTEX_GET_PARAMS;

typedef struct UX_TEST_OVERRIDE_TX_MUTEX_PUT_PARAMS
{
    TX_MUTEX *mutex_ptr;
} UX_TEST_OVERRIDE_TX_MUTEX_PUT_PARAMS;

typedef struct UX_TEST_OVERRIDE_TX_SEMAPHORE_CREATE_PARAMS
{
    TX_SEMAPHORE *semaphore;
    CHAR *semaphore_name;
    UINT initial_count;
} UX_TEST_OVERRIDE_TX_SEMAPHORE_CREATE_PARAMS;

typedef struct UX_TEST_OVERRIDE_TX_THREAD_CREATE_PARAMS
{
    /* We only care about the name. */
    CHAR *name_ptr;
} UX_TEST_OVERRIDE_TX_THREAD_CREATE_PARAMS;

typedef struct UX_TEST_OVERRIDE_UX_HOST_STACK_TRANSFER_REQUEST_PARAMS
{
    UX_TRANSFER *transfer_request;
} UX_TEST_OVERRIDE_UX_HOST_STACK_TRANSFER_REQUEST_PARAMS;

typedef struct UX_TEST_OVERRIDE_TX_THREAD_PREEMPTION_CHANGE_PARAMS
{
    TX_THREAD *thread_ptr;
    UINT new_threshold;
} UX_TEST_OVERRIDE_TX_THREAD_PREEMPTION_CHANGE_PARAMS;

typedef struct UX_TEST_OVERRIDE_UX_HOST_STACK_INTERFACE_SET_PARAMS
{
    UX_INTERFACE *interface;
} UX_TEST_OVERRIDE_UX_HOST_STACK_INTERFACE_SET_PARAMS;

typedef struct UX_TEST_OVERRIDE_NX_PACKET_TRANSMIT_RELEASE_PARAMS
{
    NX_PACKET **packet_ptr_ptr;
} UX_TEST_OVERRIDE_NX_PACKET_TRANSMIT_RELEASE_PARAMS;

typedef struct UX_TEST_ERROR_CALLBACK_PARAMS
{
    UINT system_level;
    UINT system_context;
    UINT error_code;
} UX_TEST_ERROR_CALLBACK_PARAMS;

typedef struct UX_TEST_GENERIC_CD
{
    VOID *controller_driver;
    UINT function;
    VOID *parameter;
} UX_TEST_GENERIC_CD;

typedef struct UX_MEMORY_BLOCK_STRUCT
{
    struct UX_MEMORY_BLOCK_STRUCT *ux_memory_block_next;
    UX_MEMORY_BYTE_POOL           *ux_memory_byte_pool;
} UX_MEMORY_BLOCK;

UINT ux_test_list_action_compare(UX_TEST_ACTION *list_item, UX_TEST_ACTION *action);

VOID ux_test_remove_hook(UX_TEST_ACTION *action);
VOID ux_test_remove_hooks_from_array(UX_TEST_ACTION *actions);
VOID ux_test_remove_hooks_from_list(UX_TEST_ACTION *actions);

UINT ux_test_link_hook(UX_TEST_ACTION *action);
VOID ux_test_link_hooks_from_array(UX_TEST_ACTION *actions);
VOID ux_test_link_hooks_from_list(UX_TEST_ACTION *actions);

UINT ux_test_add_hook(UX_TEST_ACTION action);
VOID ux_test_add_hooks_from_array(UX_TEST_ACTION *actions);
VOID ux_test_add_hooks_from_list(UX_TEST_ACTION *actions);

ULONG ux_test_do_hooks_before(UX_TEST_FUNCTION usbx_function, VOID *params);
VOID ux_test_do_hooks_after(UX_TEST_FUNCTION usbx_function, VOID *params);

VOID ux_test_free_hook_actions();

VOID ux_test_free_user_list_actions();
VOID ux_test_set_main_action_list_from_array(UX_TEST_ACTION *action);
VOID ux_test_set_main_action_list_from_list(UX_TEST_ACTION *new_actions);
VOID ux_test_add_action_to_user_list(UX_TEST_ACTION *list, UX_TEST_ACTION new_action);
VOID ux_test_add_action_to_main_list(UX_TEST_ACTION action);
VOID ux_test_add_action_to_main_list_multiple(UX_TEST_ACTION action, UINT);
VOID ux_test_hcd_sim_host_set_actions(UX_TEST_ACTION *action);
VOID ux_test_dcd_sim_slave_set_actions(UX_TEST_ACTION *action);
UX_TEST_ACTION ux_test_action_handler(UX_TEST_FUNCTION usbx_function, void *_params);
VOID ux_test_do_action_before(UX_TEST_ACTION *action, VOID *params);
VOID ux_test_do_action_after(UX_TEST_ACTION *action, VOID *params);
VOID ux_test_ignore_all_errors();
VOID ux_test_unignore_all_errors();
VOID ux_test_clear_main_list_actions();
VOID ux_test_cleanup_everything(VOID);
VOID ux_test_turn_off_expedient(UCHAR *);
VOID ux_test_turn_on_expedient(UCHAR *);
UCHAR ux_test_is_expedient_on();
VOID ux_test_set_expedient(UCHAR);
UCHAR ux_test_check_actions_empty();
UINT ux_test_wait_for_empty_actions();
UINT ux_test_get_num_actions_left();
extern UX_TEST_ERROR_CALLBACK_ERROR ux_error_hcd_transfer_stalled;
VOID ux_test_error_callback(UINT system_level, UINT system_context, UINT error_code);
void ux_test_disconnect_slave_and_host_wait_for_enum_completion();
VOID ux_test_connect_slave_and_host_wait_for_enum_completion();
void ux_test_memory_test_initialize();
void ux_test_memory_test_check();
void ux_test_disconnect_slave_and_host_wait_for_enum_completion();
VOID ux_test_wait_for_enum_thread_completion();
UINT ux_test_host_stack_class_instance_get(UX_HOST_CLASS *host_class, UINT class_index, VOID **class_instance);
UINT ux_test_wait_for_value_uint(UINT *current_value, UINT desired_value);
UINT ux_test_wait_for_value_ulong(ULONG *current_value, ULONG desired_value);
UINT ux_test_wait_for_value_uchar(UCHAR *current_value_ptr, UCHAR desired_value);
UINT ux_test_wait_for_non_null(VOID **current_value_ptr);
UINT ux_test_wait_for_null(VOID **current_value_ptr);
VOID ux_test_connect_host_wait_for_enum_completion();
VOID ux_test_disconnect_host_no_wait();
VOID ux_test_disconnect_slave();
VOID ux_test_connect_slave();
VOID ux_test_disconnect_host_wait_for_enum_completion();
VOID ux_test_change_device_parameters(UCHAR * device_framework_high_speed, ULONG device_framework_length_high_speed,
                                      UCHAR * device_framework_full_speed, ULONG device_framework_length_full_speed,
                                      UCHAR * string_framework, ULONG string_framework_length,
                                      UCHAR * language_id_framework, ULONG language_id_framework_length,
                                      UINT(*ux_system_slave_change_function)(ULONG));
UINT ux_test_wait_for_empty_actions_wait_time(UINT wait_time_ms);
UINT ux_test_wait_for_null_wait_time(VOID **current_value_ptr, UINT wait_time_ms);

VOID _ux_test_main_action_list_thread_update(TX_THREAD *old, TX_THREAD *new);
VOID _ux_test_main_action_list_semaphore_update(TX_SEMAPHORE *old, TX_SEMAPHORE *new);
VOID _ux_test_main_action_list_mutex_update(TX_MUTEX *old, TX_MUTEX *new);

UINT ux_test_host_endpoint_write(UX_ENDPOINT *endpoint, UCHAR *buffer, ULONG length, ULONG *actual_length);

/* Action flags */

#define UX_TEST_SIM_REQ_ANSWER 0x80

#define UX_TEST_MATCH_EP      0x01
#define UX_TEST_MATCH_REQ_LEN 0x40

#define UX_TEST_SETUP_MATCH_REQUEST 0x02
#define UX_TEST_SETUP_MATCH_VALUE   0x04
#define UX_TEST_SETUP_MATCH_INDEX   0x08

#define UX_TEST_SETUP_MATCH_REQ (UX_TEST_SETUP_MATCH_REQUEST)
#define UX_TEST_SETUP_MATCH_REQ_V (UX_TEST_SETUP_MATCH_REQ | UX_TEST_SETUP_MATCH_VALUE)
#define UX_TEST_SETUP_MATCH_REQ_V_I (UX_TEST_SETUP_MATCH_REQ_V | UX_TEST_SETUP_MATCH_INDEX)

#define UX_TEST_SETUP_MATCH_EP_REQ (UX_TEST_SETUP_MATCH_REQUEST | UX_TEST_MATCH_EP)
#define UX_TEST_SETUP_MATCH_EP_REQ_V (UX_TEST_SETUP_MATCH_EP_REQ | UX_TEST_SETUP_MATCH_VALUE)
#define UX_TEST_SETUP_MATCH_EP_REQ_V_I (UX_TEST_SETUP_MATCH_EP_REQ_V | UX_TEST_SETUP_MATCH_INDEX)

/* Expected Requests */

#define UX_TEST_SETUP_SetAddress   {0x00,0x05,0x0001,0x0000}
#define UX_TEST_SETUP_GetDevDescr  {0x80,0x06,0x0100,0x0000}
#define UX_TEST_SETUP_GetCfgDescr  {0x80,0x06,0x0200,0x0000}
#define UX_TEST_SETUP_SetConfigure {0x00,0x09,0x0001,0x0000}

#define UX_TEST_SETUP_CDCACM_GetLineCoding    {0xa1, 0x21, 0x0000, 0x0000}
#define UX_TEST_SETUP_CDCACM_SetLineCoding    {0x21, 0x20, 0x0000, 0x0000}
#define UX_TEST_SETUP_CDCACM_SetLineState     {0x21, 0x22, 0x0003, 0x0000}

#define UX_TEST_SETUP_STORAGE_GetMaxLun       {0xa1, 0xfe, 0x0000, 0x0001}
#define UX_TEST_SETUP_STORAGE_Reset           {0x21, 0xff, 0x0000, 0x0000}

#define UX_TEST_PORT_STATUS_DISC    0
#define UX_TEST_PORT_STATUS_LS_CONN UX_PS_CCS | UX_PS_DS_LS
#define UX_TEST_PORT_STATUS_FS_CONN UX_PS_CCS | UX_PS_DS_FS
#define UX_TEST_PORT_STATUS_HS_CONN UX_PS_CCS | UX_PS_DS_HS



UINT ux_test_breakable_sleep(ULONG tick, UINT (*sleep_break_check_callback)(VOID));
UINT ux_test_sleep_break_if(ULONG tick, UINT (*check)(VOID), UINT break_on_match_or_not, UINT rc_to_match);
#define ux_test_sleep(t) ux_test_sleep_break_if(t, UX_NULL, 1, UX_SUCCESS)
#define ux_test_sleep_break_on_success(t,c) ux_test_sleep_break_if(t, c, 1, UX_SUCCESS)
#define ux_test_sleep_break_on_error(t,c) ux_test_sleep_break_if(t, c, 0, UX_SUCCESS)

void  test_control_return(UINT status);

void  ux_test_assert_hit_hint(UCHAR on_off);
void  ux_test_assert_hit_exit(UCHAR on_off);
ULONG ux_test_assert_hit_count_get(void);
void  ux_test_assert_hit_count_reset(void);

static inline int ux_test_memory_is_freed(void *memory)
{
UCHAR               *work_ptr;
UCHAR               *temp_ptr;
ALIGN_TYPE          *free_ptr;
int                 is_free = 0;
    UX_TEST_ASSERT(memory);
    _ux_system_mutex_on(&_ux_system -> ux_system_mutex);
    work_ptr =  UX_VOID_TO_UCHAR_POINTER_CONVERT(memory);
    {
        work_ptr =  UX_UCHAR_POINTER_SUB(work_ptr, UX_MEMORY_BLOCK_HEADER_SIZE);
        temp_ptr =  UX_UCHAR_POINTER_ADD(work_ptr, (sizeof(UCHAR *)));
        free_ptr =  UX_UCHAR_TO_ALIGN_TYPE_POINTER_CONVERT(temp_ptr);
        if ((*free_ptr) == UX_BYTE_BLOCK_FREE)
            is_free = 1;
    }
    _ux_system_mutex_off(&_ux_system -> ux_system_mutex);
    return(is_free);
}
#define ux_test_regular_memory_free() _ux_system -> ux_system_memory_byte_pool[UX_MEMORY_BYTE_POOL_REGULAR] -> ux_byte_pool_available

#endif /* _UX_TEST_H */