1 /* This test is designed to test the ux_utility_thread_suspend. */
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_cdc_acm.h"
13 #include "ux_host_class_cdc_acm.h"
14
15 #include "ux_host_class_dpump.h"
16 #include "ux_device_class_dpump.h"
17
18 #include "ux_host_class_hid.h"
19 #include "ux_device_class_hid.h"
20
21 #include "ux_host_class_storage.h"
22 #include "ux_device_class_storage.h"
23
24 /* Define USBX test constants. */
25
26 #define UX_TEST_STACK_SIZE 4096
27 #define UX_TEST_BUFFER_SIZE 2048
28 #define UX_TEST_RUN 1
29 #define UX_TEST_MEMORY_SIZE (64*1024)
30
31 /* Define the counters used in the test application... */
32
33 static CHAR *stack_pointer;
34 static CHAR *memory_pointer;
35
36 static ULONG thread_0_counter;
37 static ULONG thread_1_counter;
38 static ULONG error_counter;
39
40 static UCHAR error_callback_ignore = UX_FALSE;
41 static ULONG error_callback_counter;
42
43 static UCHAR buffer[UX_TEST_BUFFER_SIZE];
44
45 /* Define USBX test global variables. */
46
47 /* Define prototypes for external Host Controller's (HCDs), classes and clients. */
48
49 static TX_THREAD ux_test_thread_simulation_0;
50 static TX_THREAD ux_test_thread_simulation_1;
51 static void ux_test_thread_simulation_0_entry(ULONG);
52 static void ux_test_thread_simulation_1_entry(ULONG);
53
54
55 /* Define the ISR dispatch. */
56
57 extern VOID (*test_isr_dispatch)(void);
58
59
60 /* Prototype for test control return. */
61
62 void test_control_return(UINT status);
63
64 /* Simulator actions. */
65
66 /* Define the ISR dispatch routine. */
67
test_isr(void)68 static void test_isr(void)
69 {
70
71 /* For further expansion of interrupt-level testing. */
72 }
73
74
error_callback(UINT system_level,UINT system_context,UINT error_code)75 static VOID error_callback(UINT system_level, UINT system_context, UINT error_code)
76 {
77
78 error_callback_counter ++;
79
80 if (!error_callback_ignore)
81 {
82 {
83 /* Failed test. */
84 printf("Error #%d, system_level: %d, system_context: %d, error_code: 0x%x\n", __LINE__, system_level, system_context, error_code);
85 // test_control_return(1);
86 }
87 }
88 }
89
90 /* Define what the initial system looks like. */
91
92 #ifdef CTEST
test_application_define(void * first_unused_memory)93 void test_application_define(void *first_unused_memory)
94 #else
95 void usbx_ux_utility_thread_suspend_test_application_define(void *first_unused_memory)
96 #endif
97 {
98
99 UINT status;
100
101 /* Inform user. */
102 printf("Running ux_utility_thread_suspend Test.............................. ");
103
104 /* Initialize the free memory pointer. */
105 stack_pointer = (CHAR *) first_unused_memory;
106 memory_pointer = stack_pointer + (UX_TEST_STACK_SIZE * 2);
107
108 /* Initialize USBX Memory. */
109 status = ux_system_initialize(memory_pointer, UX_TEST_MEMORY_SIZE, UX_NULL, 0);
110
111 /* Check for error. */
112 if (status != UX_SUCCESS)
113 {
114
115 printf("ERROR #%d\n", __LINE__);
116 test_control_return(1);
117 }
118
119 /* Register the error callback. */
120 _ux_utility_error_callback_register(error_callback);
121
122 /* Create the simulation thread. */
123 status = tx_thread_create(&ux_test_thread_simulation_0, "test simulation 0", ux_test_thread_simulation_0_entry, 0,
124 stack_pointer, UX_TEST_STACK_SIZE,
125 20, 20, 1, TX_AUTO_START);
126
127 /* Check for error. */
128 if (status != TX_SUCCESS)
129 {
130
131 printf("ERROR #%d\n", __LINE__);
132 test_control_return(1);
133 }
134
135 /* Reset another thread. */
136 _ux_utility_memory_set(&ux_test_thread_simulation_1, 0, sizeof(ux_test_thread_simulation_1));
137 }
138
139
ux_test_thread_simulation_0_entry(ULONG arg)140 static void ux_test_thread_simulation_0_entry(ULONG arg)
141 {
142 UINT status;
143
144 /* Suspend the thread. */
145 status = _ux_utility_thread_suspend(UX_NULL);
146 if (status != TX_THREAD_ERROR)
147 {
148 printf("ERROR #%d: expect TX_THREAD_ERROR but got 0x%x\n", __LINE__, status);
149 error_counter ++;
150 }
151
152 /* Suspend the thread. */
153 status = _ux_utility_thread_suspend(&ux_test_thread_simulation_1);
154 if (status != TX_THREAD_ERROR)
155 {
156 printf("ERROR #%d: expect TX_THREAD_ERROR but got 0x%x\n", __LINE__, status);
157 error_counter ++;
158 }
159
160 /* Create the simulation thread. */
161 status = tx_thread_create(&ux_test_thread_simulation_1, "test simulation 1", ux_test_thread_simulation_1_entry, 0,
162 stack_pointer + UX_TEST_STACK_SIZE, UX_TEST_STACK_SIZE,
163 20, 20, 1, TX_AUTO_START);
164
165 /* Check for error. */
166 if (status != TX_SUCCESS)
167 {
168
169 printf("ERROR #%d: thread create fail 0x%x\n", __LINE__, status);
170 test_control_return(1);
171 }
172
173 /* Suspend the thread. */
174 status = _ux_utility_thread_suspend(&ux_test_thread_simulation_1);
175 if (status != UX_SUCCESS)
176 {
177 printf("ERROR #%d: expect OK but got 0x%x\n", __LINE__, status);
178 error_counter ++;
179 }
180
181 /* Check for errors from other threads. */
182 if (error_counter)
183 {
184
185 /* Test error. */
186 printf("ERROR #%d: total %ld errors\n", __LINE__, error_counter);
187 test_control_return(1);
188 }
189 else
190 {
191
192 /* Successful test. */
193 printf("SUCCESS!\n");
194 test_control_return(0);
195 }
196 }
197
ux_test_thread_simulation_1_entry(ULONG arg)198 static void ux_test_thread_simulation_1_entry(ULONG arg)
199 {
200 while(1)
201 {
202 _ux_utility_delay_ms(100);
203 }
204 }
205