1 /* This test is designed to test the ux_utility_descriptor_pack.  */
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_host_class_video.h"
13 
14 #include "ux_test.h"
15 
16 /* Define USBX test constants.  */
17 
18 #define UX_TEST_STACK_SIZE      4096
19 #define UX_TEST_BUFFER_SIZE     2048
20 #define UX_TEST_MEMORY_SIZE     (64*1024)
21 
22 
23 /* Define the counters used in the test application...  */
24 
25 static ULONG                           error_counter = 0;
26 
27 /* Define USBX test global variables.  */
28 
29 
30 /* Define prototypes for external Host Controller's (HCDs), classes and clients.  */
31 
32 static TX_THREAD           ux_test_thread_simulation_0;
33 static void                ux_test_thread_simulation_0_entry(ULONG);
34 
35 
36 /* Prototype for test control return.  */
37 
38 void  test_control_return(UINT status);
39 
40 /* Define what the initial system looks like.  */
41 
42 #ifdef CTEST
test_application_define(void * first_unused_memory)43 void test_application_define(void *first_unused_memory)
44 #else
45 void usbx_uxe_host_video_test_application_define(void *first_unused_memory)
46 #endif
47 {
48 
49 UINT status;
50 CHAR                            *stack_pointer;
51 CHAR                            *memory_pointer;
52 
53     /* Inform user.  */
54     printf("Running uxe_host_video APIs Test.................................... ");
55 #if !defined(UX_HOST_CLASS_VIDEO_ENABLE_ERROR_CHECKING)
56 #warning Tests skipped due to compile option!
57     printf("SKIP SUCCESS!\n");
58     test_control_return(0);
59     return;
60 #endif
61 
62     /* Initialize the free memory pointer.  */
63     stack_pointer = (CHAR *) first_unused_memory;
64     memory_pointer = stack_pointer + (UX_TEST_STACK_SIZE * 2);
65 
66     /* Initialize USBX Memory.  */
67     status =  ux_system_initialize(memory_pointer, UX_TEST_MEMORY_SIZE, UX_NULL, 0);
68 
69     /* Check for error.  */
70     if (status != UX_SUCCESS)
71     {
72 
73         printf("ERROR #%d\n", __LINE__);
74         test_control_return(1);
75     }
76 
77     /* Create the simulation thread.  */
78     status =  tx_thread_create(&ux_test_thread_simulation_0, "test simulation", ux_test_thread_simulation_0_entry, 0,
79             stack_pointer, UX_TEST_STACK_SIZE,
80             20, 20, 1, TX_AUTO_START);
81 
82     /* Check for error.  */
83     if (status != TX_SUCCESS)
84     {
85 
86         printf("ERROR #%d\n", __LINE__);
87         test_control_return(1);
88     }
89 }
90 
ux_test_thread_simulation_0_entry(ULONG arg)91 static void  ux_test_thread_simulation_0_entry(ULONG arg)
92 {
93 UINT                                            status;
94 UX_HOST_CLASS_VIDEO                             dummy_video_inst;
95 UX_HOST_CLASS_VIDEO                             *dummy_video = &dummy_video_inst;
96 UCHAR                                           dummy_buffer[64];
97 UX_HOST_CLASS_VIDEO_CONTROL                     dummy_video_control;
98 UX_HOST_CLASS_VIDEO_TRANSFER_REQUEST            dummy_video_request;
99 ULONG                                           max_payload = 0xff;
100 
101     /* ux_host_class_video_control_get()  */
102     status = ux_host_class_video_control_get(UX_NULL, &dummy_video_control);
103     UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);
104     status = ux_host_class_video_control_get(dummy_video, UX_NULL);
105     UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);
106 
107     /* ux_host_class_video_control_value_get()  */
108     status = ux_host_class_video_control_value_get(UX_NULL, &dummy_video_control);
109     UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);
110     status = ux_host_class_video_control_value_get(dummy_video, UX_NULL);
111     UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);
112 
113     /* ux_host_class_video_control_value_set()  */
114     status = ux_host_class_video_control_value_set(UX_NULL, &dummy_video_control);
115     UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);
116     status = ux_host_class_video_control_value_set(dummy_video, UX_NULL);
117     UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);
118 
119     /* ux_host_class_video_read()  */
120     status = ux_host_class_video_read(UX_NULL, &dummy_video_request);
121     UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);
122     status = ux_host_class_video_read(dummy_video, UX_NULL);
123     UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);
124 
125     /* ux_host_class_video_ioctl()  */
126     status = ux_host_class_video_ioctl(UX_NULL, 0, UX_NULL);
127     UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);
128 
129     /* ux_host_class_video_start()  */
130     status = ux_host_class_video_start(UX_NULL);
131     UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);
132 
133     /* ux_host_class_video_stop()  */
134     status = ux_host_class_video_stop(UX_NULL);
135     UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);
136 
137     /* ux_host_class_video_frame_parameters_set()  */
138     status = ux_host_class_video_frame_parameters_set(UX_NULL, 0, 255, 255, 100);
139     UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);
140 
141     /* ux_host_class_video_max_payload_get()  */
142     max_payload = ux_host_class_video_max_payload_get(UX_NULL);
143     UX_TEST_CHECK_CODE(0, max_payload);
144 
145     /* ux_host_class_video_transfer_buffer_add()  */
146     status = ux_host_class_video_transfer_buffer_add(UX_NULL, dummy_buffer);
147     UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);
148     status = ux_host_class_video_transfer_buffer_add(dummy_video, UX_NULL);
149     UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);
150 
151     /* ux_host_class_video_transfer_buffers_add()  */
152     status = ux_host_class_video_transfer_buffers_add(UX_NULL, &dummy_buffer, 1);
153     UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);
154     status = ux_host_class_video_transfer_buffers_add(dummy_video, UX_NULL, 1);
155     UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);
156     status = ux_host_class_video_transfer_buffers_add(dummy_video, &dummy_buffer, 0);
157     UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);
158 
159     /* ux_host_class_video_transfer_callback_set()  */
160     ux_host_class_video_transfer_callback_set(UX_NULL, UX_NULL);
161 
162     /* ux_host_class_video_entities_parse()  */
163     status = ux_host_class_video_entities_parse(UX_NULL, 0, UX_NULL);
164     UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);
165 
166     /* ux_host_class_video_control_request()  */
167     status = ux_host_class_video_control_request(UX_NULL, 1, 1, 1, 1, UX_NULL, 2);
168     UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);
169 
170     /* Sleep for a tick to make sure everything is complete.  */
171     tx_thread_sleep(1);
172 
173     /* Check for errors from other threads.  */
174     if (error_counter)
175     {
176 
177         /* Test error.  */
178         printf("ERROR #%d: total %ld errors\n", __LINE__, error_counter);
179         test_control_return(1);
180     }
181     else
182     {
183 
184         /* Successful test.  */
185         printf("SUCCESS!\n");
186         test_control_return(0);
187     }
188 }
189