1 /* This test is designed to test the ux_utility_descriptor_parse.  */
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_test.h"
10 
11 #include "ux_device_class_dfu.h"
12 #include "ux_host_class_audio.h"
13 #include "ux_host_class_cdc_ecm.h"
14 #include "ux_host_class_hid.h"
15 #include "ux_host_class_hub.h"
16 #include "ux_host_class_pima.h"
17 #include "ux_host_class_video.h"
18 
19 
20 /* Define USBX test constants.  */
21 
22 #define UX_TEST_STACK_SIZE      4096
23 #define UX_TEST_MEMORY_SIZE     (64*1024)
24 
25 
26 /* Define the counters used in the test application...  */
27 
28 static ULONG                           thread_0_counter;
29 static ULONG                           thread_1_counter;
30 static ULONG                           error_counter;
31 
32 static UCHAR                           error_callback_ignore = UX_FALSE;
33 static ULONG                           error_callback_counter;
34 
35 
36 /* Define USBX test global variables.  */
37 
38 
39 /* Define prototypes for external Host Controller's (HCDs), classes and clients.  */
40 
41 static VOID                ux_test_instance_activate(VOID  *dpump_instance);
42 static VOID                ux_test_instance_deactivate(VOID *dpump_instance);
43 
44 static TX_THREAD           ux_test_thread_simulation_0;
45 static TX_THREAD           ux_test_thread_simulation_1;
46 static void                ux_test_thread_simulation_0_entry(ULONG);
47 static void                ux_test_thread_simulation_1_entry(ULONG);
48 
49 
50 /* Define the ISR dispatch.  */
51 
52 extern VOID    (*test_isr_dispatch)(void);
53 
54 
55 /* Prototype for test control return.  */
56 
57 void  test_control_return(UINT status);
58 
59 
60 /* Define the ISR dispatch routine.  */
61 
test_isr(void)62 static void    test_isr(void)
63 {
64 
65     /* For further expansion of interrupt-level testing.  */
66 }
67 
68 
error_callback(UINT system_level,UINT system_context,UINT error_code)69 static VOID error_callback(UINT system_level, UINT system_context, UINT error_code)
70 {
71 
72     error_callback_counter ++;
73 
74     if (!error_callback_ignore)
75     {
76         {
77             /* Failed test.  */
78             printf("Error #%d, system_level: %d, system_context: %d, error_code: 0x%x\n", __LINE__, system_level, system_context, error_code);
79             // test_control_return(1);
80         }
81     }
82 }
83 
84 
85 /* Define what the initial system looks like.  */
86 
87 #ifdef CTEST
test_application_define(void * first_unused_memory)88 void test_application_define(void *first_unused_memory)
89 #else
90 void    usbx_ux_utility_descriptor_struct_test_application_define(void *first_unused_memory)
91 #endif
92 {
93 
94 UINT status;
95 CHAR                            *stack_pointer;
96 CHAR                            *memory_pointer;
97 
98     /* Inform user.  */
99     printf("Running ux_utility_descriptor_ structures Test...................... ");
100 
101     /* Initialize the free memory pointer.  */
102     stack_pointer = (CHAR *) first_unused_memory;
103     memory_pointer = stack_pointer + (UX_TEST_STACK_SIZE * 2);
104 
105     /* Initialize USBX Memory.  */
106     status =  ux_system_initialize(memory_pointer, UX_TEST_MEMORY_SIZE, UX_NULL, 0);
107 
108     /* Check for error.  */
109     if (status != UX_SUCCESS)
110     {
111 
112         printf("ERROR #%d\n", __LINE__);
113         test_control_return(1);
114     }
115 
116     /* Register the error callback. */
117     _ux_utility_error_callback_register(error_callback);
118 
119     /* Create the simulation thread.  */
120     status =  tx_thread_create(&ux_test_thread_simulation_0, "test simulation", ux_test_thread_simulation_0_entry, 0,
121             stack_pointer, UX_TEST_STACK_SIZE,
122             20, 20, 1, TX_AUTO_START);
123 
124     /* Check for error.  */
125     if (status != TX_SUCCESS)
126     {
127 
128         printf("ERROR #%d\n", __LINE__);
129         test_control_return(1);
130     }
131 }
132 
ux_test_thread_simulation_0_entry(ULONG arg)133 static void  ux_test_thread_simulation_0_entry(ULONG arg)
134 {
135 
136     /* Print STD framework descriptor's sizes  */
137     printf("\n");
138     printf("Descriptor    %7s %7s %7s\n", "nFields", "Size4", "SizeNew");
139     printf("Device        %7d %7d %7u\n", UX_DEVICE_DESCRIPTOR_ENTRIES, UX_DEVICE_DESCRIPTOR_ENTRIES * 4, (unsigned)_ux_utility_descriptor_parse_size(_ux_system_device_descriptor_structure, UX_DEVICE_DESCRIPTOR_ENTRIES, 0x3u));
140     printf("Configuration %7d %7d %7u\n", UX_CONFIGURATION_DESCRIPTOR_ENTRIES, UX_CONFIGURATION_DESCRIPTOR_ENTRIES * 4, (unsigned)_ux_utility_descriptor_parse_size(_ux_system_configuration_descriptor_structure, UX_CONFIGURATION_DESCRIPTOR_ENTRIES, 0x3u));
141     printf("Interface     %7d %7d %7u\n", UX_INTERFACE_DESCRIPTOR_ENTRIES, UX_INTERFACE_DESCRIPTOR_ENTRIES * 4, (unsigned)_ux_utility_descriptor_parse_size(_ux_system_interface_descriptor_structure, UX_INTERFACE_DESCRIPTOR_ENTRIES, 0x3u));
142     printf("Endpoint      %7d %7d %7u\n", UX_ENDPOINT_DESCRIPTOR_ENTRIES, UX_ENDPOINT_DESCRIPTOR_ENTRIES * 4, (unsigned)_ux_utility_descriptor_parse_size(_ux_system_endpoint_descriptor_structure, UX_ENDPOINT_DESCRIPTOR_ENTRIES, 0x3u));
143 
144     /* Test struct parse sizes.  */
145     UX_TEST_ASSERT((_ux_utility_descriptor_parse_size(_ux_system_endpoint_descriptor_structure, UX_ENDPOINT_DESCRIPTOR_ENTRIES, 0x3u)) == sizeof(UX_ENDPOINT_DESCRIPTOR));
146     UX_TEST_ASSERT((_ux_utility_descriptor_parse_size(_ux_system_device_descriptor_structure, UX_DEVICE_DESCRIPTOR_ENTRIES, 0x3u)) == sizeof(UX_DEVICE_DESCRIPTOR));
147     UX_TEST_ASSERT((_ux_utility_descriptor_parse_size(_ux_system_configuration_descriptor_structure, UX_CONFIGURATION_DESCRIPTOR_ENTRIES, 0x3u)) == sizeof(UX_CONFIGURATION_DESCRIPTOR));
148     UX_TEST_ASSERT((_ux_utility_descriptor_parse_size(_ux_system_interface_descriptor_structure, UX_INTERFACE_DESCRIPTOR_ENTRIES, 0x3u)) == sizeof(UX_INTERFACE_DESCRIPTOR));
149     UX_TEST_ASSERT((_ux_utility_descriptor_parse_size(_ux_system_interface_association_descriptor_structure, UX_INTERFACE_ASSOCIATION_DESCRIPTOR_ENTRIES, 0x3u)) == sizeof(UX_INTERFACE_ASSOCIATION_DESCRIPTOR));
150     UX_TEST_ASSERT((_ux_utility_descriptor_parse_size(_ux_system_string_descriptor_structure, UX_STRING_DESCRIPTOR_ENTRIES, 0x3u)) == sizeof(UX_STRING_DESCRIPTOR));
151 
152     UX_TEST_ASSERT((_ux_utility_descriptor_parse_size(_ux_system_dfu_functional_descriptor_structure, UX_DFU_FUNCTIONAL_DESCRIPTOR_ENTRIES, 0x3u)) == sizeof(UX_DFU_FUNCTIONAL_DESCRIPTOR));
153 
154     UX_TEST_ASSERT((_ux_utility_descriptor_parse_size(_ux_system_bos_descriptor_structure, UX_BOS_DESCRIPTOR_ENTRIES, 0x3u)) == sizeof(UX_BOS_DESCRIPTOR));
155     UX_TEST_ASSERT((_ux_utility_descriptor_parse_size(_ux_system_usb_2_0_extension_descriptor_structure, UX_USB_2_0_EXTENSION_DESCRIPTOR_ENTRIES, 0x3u)) == sizeof(UX_USB_2_0_EXTENSION_DESCRIPTOR));
156     UX_TEST_ASSERT((_ux_utility_descriptor_parse_size(_ux_system_container_id_descriptor_structure, UX_CONTAINER_ID_DESCRIPTOR_ENTRIES, 0x3u)) == sizeof(UX_CONTAINER_ID_DESCRIPTOR));
157 
158     UX_TEST_ASSERT((_ux_utility_descriptor_parse_size(_ux_system_class_audio_interface_descriptor_structure, UX_HOST_CLASS_AUDIO_INTERFACE_DESCRIPTOR_ENTRIES, 0x3u)) == sizeof(UX_HOST_CLASS_AUDIO_INTERFACE_DESCRIPTOR));
159     UX_TEST_ASSERT((_ux_utility_descriptor_parse_size(_ux_system_class_audio_input_terminal_descriptor_structure, UX_HOST_CLASS_AUDIO_INPUT_TERMINAL_DESCRIPTOR_ENTRIES, 0x3u)) == sizeof(UX_HOST_CLASS_AUDIO_INPUT_TERMINAL_DESCRIPTOR));
160     UX_TEST_ASSERT((_ux_utility_descriptor_parse_size(_ux_system_class_audio_output_terminal_descriptor_structure, UX_HOST_CLASS_AUDIO_OUTPUT_TERMINAL_DESCRIPTOR_ENTRIES, 0x3u)) == sizeof(UX_HOST_CLASS_AUDIO_OUTPUT_TERMINAL_DESCRIPTOR));
161     UX_TEST_ASSERT((_ux_utility_descriptor_parse_size(_ux_system_class_audio_feature_unit_descriptor_structure, UX_HOST_CLASS_AUDIO_FEATURE_UNIT_DESCRIPTOR_ENTRIES, 0x3u)) == sizeof(UX_HOST_CLASS_AUDIO_FEATURE_UNIT_DESCRIPTOR));
162     UX_TEST_ASSERT((_ux_utility_descriptor_parse_size(_ux_system_class_audio_streaming_interface_descriptor_structure, UX_HOST_CLASS_AUDIO_STREAMING_INTERFACE_DESCRIPTOR_ENTRIES, 0x3u)) == sizeof(UX_HOST_CLASS_AUDIO_STREAMING_INTERFACE_DESCRIPTOR));
163     UX_TEST_ASSERT((_ux_utility_descriptor_parse_size(_ux_system_class_audio_streaming_endpoint_descriptor_structure, UX_HOST_CLASS_AUDIO_STREAMING_ENDPOINT_DESCRIPTOR_ENTRIES, 0x3u)) == sizeof(UX_HOST_CLASS_AUDIO_STREAMING_ENDPOINT_DESCRIPTOR));
164 
165     UX_TEST_ASSERT((_ux_utility_descriptor_parse_size(_ux_system_hid_descriptor_structure, UX_HID_DESCRIPTOR_ENTRIES, 0x3u)) == sizeof(UX_HID_DESCRIPTOR));
166 
167     UX_TEST_ASSERT((_ux_utility_descriptor_parse_size(_ux_system_class_pima_storage_structure, 8, 0x3u)) == 4*7);
168     UX_TEST_ASSERT((_ux_utility_descriptor_parse_size(_ux_system_class_pima_object_structure, 15, 0x3u)) == 4*14);
169 
170     UX_TEST_ASSERT((_ux_utility_descriptor_parse_size(_ux_system_ecm_interface_descriptor_structure, UX_HOST_CLASS_CDC_ECM_INTERFACE_DESCRIPTOR_ENTRIES, 0x3u)) == sizeof(UX_HOST_CLASS_ECM_INTERFACE_DESCRIPTOR));
171 
172     UX_TEST_ASSERT((_ux_utility_descriptor_parse_size(_ux_system_hub_descriptor_structure, UX_HUB_DESCRIPTOR_ENTRIES, 0x3u)) == sizeof(UX_HUB_DESCRIPTOR));
173 
174     /* Sleep for a tick to make sure everything is complete.  */
175     tx_thread_sleep(1);
176 
177     /* Check for errors from other threads.  */
178     if (error_counter)
179     {
180 
181         /* Test error.  */
182         printf("ERROR #%d: total %ld errors\n", __LINE__, error_counter);
183         test_control_return(1);
184     }
185     else
186     {
187 
188         /* Successful test.  */
189         printf("SUCCESS!\n");
190         test_control_return(0);
191     }
192 }
193