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_device_class_dummy.h"
13 #include "ux_host_class_dummy.h"
14 
15 #include "ux_test.h"
16 
17 /* Define USBX test constants.  */
18 
19 #define UX_TEST_STACK_SIZE      4096
20 #define UX_TEST_BUFFER_SIZE     2048
21 #define UX_TEST_MEMORY_SIZE     (64*1024)
22 
23 
24 /* Define the counters used in the test application...  */
25 
26 static ULONG                           thread_0_counter;
27 static ULONG                           thread_1_counter;
28 static ULONG                           error_counter;
29 
30 static UCHAR                           error_callback_ignore = UX_FALSE;
31 static ULONG                           error_callback_counter;
32 
33 
34 /* Define USBX test global variables.  */
35 
36 
37 /* Define prototypes for external Host Controller's (HCDs), classes and clients.  */
38 
39 static TX_THREAD           ux_test_thread_simulation_0;
40 static TX_THREAD           ux_test_thread_simulation_1;
41 static void                ux_test_thread_simulation_0_entry(ULONG);
42 static void                ux_test_thread_simulation_1_entry(ULONG);
43 
44 
45 /* Prototype for test control return.  */
46 
47 void  test_control_return(UINT status);
48 
49 
50 /* Define what the initial system looks like.  */
51 
52 #ifdef CTEST
test_application_define(void * first_unused_memory)53 void test_application_define(void *first_unused_memory)
54 #else
55 void usbx_uxe_system_test_application_define(void *first_unused_memory)
56 #endif
57 {
58 
59 UINT status;
60 CHAR                            *stack_pointer;
61 CHAR                            *memory_pointer;
62 
63     /* Inform user.  */
64     printf("Running uxe_system APIs Test........................................ ");
65 #if !defined(UX_DEVICE_CLASS_AUDIO_ENABLE_ERROR_CHECKING)
66 #warning Tests skipped due to compile option!
67     printf("SKIP SUCCESS!\n");
68     test_control_return(0);
69     return;
70 #endif
71 
72     /* Initialize the free memory pointer.  */
73     stack_pointer = (CHAR *) first_unused_memory;
74     memory_pointer = stack_pointer + (UX_TEST_STACK_SIZE * 2);
75 #if 1
76     /* Initialize USBX Memory.  */
77     status =  ux_system_initialize(memory_pointer, UX_TEST_MEMORY_SIZE, UX_NULL, 0);
78 
79     /* Check for error.  */
80     if (status != UX_SUCCESS)
81     {
82 
83         printf("ERROR #%d\n", __LINE__);
84         test_control_return(1);
85     }
86 #endif
87     /* Create the simulation thread.  */
88     status =  tx_thread_create(&ux_test_thread_simulation_0, "test simulation", ux_test_thread_simulation_0_entry, 0,
89             stack_pointer, UX_TEST_STACK_SIZE,
90             20, 20, 1, TX_AUTO_START);
91 
92     /* Check for error.  */
93     if (status != TX_SUCCESS)
94     {
95 
96         printf("ERROR #%d\n", __LINE__);
97         test_control_return(1);
98     }
99 }
100 
101 
ux_test_thread_simulation_0_entry(ULONG arg)102 static void  ux_test_thread_simulation_0_entry(ULONG arg)
103 {
104 UINT                                    status;
105 UCHAR                                  *buffer = (UCHAR *)&status;
106 
107     /* ux_device_stack_initialize()  */
108     status =  ux_device_stack_initialize(UX_NULL, 64, buffer, 64, buffer, 64, buffer, 64, UX_NULL);
109     UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);
110     status =  ux_device_stack_initialize(buffer, 64, UX_NULL, 64, buffer, 64, buffer, 64, UX_NULL);
111     UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);
112     status =  ux_device_stack_initialize(buffer, 64, buffer, 0, buffer, 64, buffer, 64, UX_NULL);
113     UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);
114     status =  ux_device_stack_initialize(buffer, 64, buffer, 64, UX_NULL, 64, buffer, 64, UX_NULL);
115     UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);
116     status =  ux_device_stack_initialize(buffer, 64, buffer, 64, buffer, 64, UX_NULL, 64, UX_NULL);
117     UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);
118     status =  ux_device_stack_initialize(buffer, 64, buffer, 64, buffer, 64, buffer, 0, UX_NULL);
119     UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);
120 
121     /* ux_device_stack_class_register()  */
122     status =  ux_device_stack_class_register(UX_NULL, _ux_device_class_dummy_entry, 0, 1, UX_NULL);
123     UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);
124     status =  ux_device_stack_class_register(_ux_device_class_dummy_name, UX_NULL, 0, 1, UX_NULL);
125     UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);
126 
127     /* ux_device_stack_class_unregister()  */
128     status =  ux_device_stack_class_unregister(UX_NULL, _ux_device_class_dummy_entry);
129     UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);
130     status =  ux_device_stack_class_unregister(_ux_device_class_dummy_name, UX_NULL);
131     UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);
132 
133 #if defined(UX_DEVICE_STANDALONE)
134 #endif
135 
136     /* Sleep for a tick to make sure everything is complete.  */
137     tx_thread_sleep(1);
138 
139     /* Check for errors from other threads.  */
140     if (error_counter)
141     {
142 
143         /* Test error.  */
144         printf("ERROR #%d: total %ld errors\n", __LINE__, error_counter);
145         test_control_return(1);
146     }
147     else
148     {
149 
150         /* Successful test.  */
151         printf("SUCCESS!\n");
152         test_control_return(0);
153     }
154 }
155