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
|
/***************************************************************************/
/* 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 */
/***************************************************************************/
/* Include necessary system files. */
#include "usbx_ux_test_cdc_ecm.h"
static ULONG rsc_cdc_thread_usage;
static ULONG rsc_cdc_mutex_usage;
static ULONG rsc_cdc_event_usage;
static ULONG rsc_cdc_sem_usage;
static ULONG error_callback_counter;
static void count_error_callback(struct UX_TEST_ACTION_STRUCT *action, VOID *params)
{
UX_TEST_ERROR_CALLBACK_PARAMS *error = (UX_TEST_ERROR_CALLBACK_PARAMS *)params;
// printf("error trap #%d: 0x%x, 0x%x, 0x%x\n", __LINE__, error->system_level, error->system_context, error->error_code);
error_callback_counter ++;
}
static UX_TEST_HCD_SIM_ACTION count_on_error_trap[] = {
{ .usbx_function = UX_TEST_OVERRIDE_ERROR_CALLBACK,
.action_func = count_error_callback,
},
{ 0 }
};
/* Define what the initial system looks like. */
#ifdef CTEST
void test_application_define(void *first_unused_memory)
#else
void usbx_ux_device_class_cdc_ecm_initialize_test_application_define(void *first_unused_memory)
#endif
{
/* Inform user. */
printf("Running ux_device_class_cdc_ecm_initialize Test..................... ");
stepinfo("\n");
/* Override error trap. */
ux_test_link_hooks_from_array(count_on_error_trap);
ux_test_cdc_ecm_initialize(first_unused_memory);
}
static void post_init_host()
{
UINT status;
ULONG mem_free;
ULONG test_n;
/* Test device deinit. */
stepinfo(">>>>>>>>>>>>>>>>>>> Test class deinit\n");
ux_test_disconnect_slave();
ux_test_disconnect_host_wait_for_enum_completion();
ux_device_stack_class_unregister(_ux_system_slave_class_cdc_ecm_name, ux_device_class_cdc_ecm_entry);
/* Reset testing counts. */
ux_test_utility_sim_thread_create_count_reset();
ux_test_utility_sim_mutex_create_count_reset();
ux_test_utility_sim_event_create_count_reset();
ux_test_utility_sim_sem_create_count_reset();
stepinfo(">>>>>>>>>>>>>>>>>>> Test class init\n");
UX_TEST_CHECK_SUCCESS(ux_device_stack_class_register(_ux_system_slave_class_cdc_ecm_name, ux_device_class_cdc_ecm_entry, 1, 0, &cdc_ecm_parameter));
/* Log create counts for further tests. */
rsc_cdc_thread_usage = ux_test_utility_sim_thread_create_count();
rsc_cdc_mutex_usage = ux_test_utility_sim_mutex_create_count();
rsc_cdc_event_usage = ux_test_utility_sim_event_create_count();
rsc_cdc_sem_usage = ux_test_utility_sim_sem_create_count();
if (rsc_cdc_thread_usage) stepinfo(">>>>>>>>>>>>>>>>>>> Thread errors cdc_ecm init test\n");
mem_free = (~0);
for (test_n = 0; test_n < rsc_cdc_thread_usage; test_n ++)
{
stepinfo("%4ld / %4ld\n", test_n, rsc_cdc_thread_usage - 1);
/* Deinit. */
ux_device_stack_class_unregister(_ux_system_slave_class_cdc_ecm_name, ux_device_class_cdc_ecm_entry);
/* Update memory free level (disconnect) */
if (mem_free == (~0))
mem_free = _ux_system -> ux_system_memory_byte_pool[UX_MEMORY_BYTE_POOL_REGULAR] -> ux_byte_pool_available;
else if (mem_free != _ux_system -> ux_system_memory_byte_pool[UX_MEMORY_BYTE_POOL_REGULAR] -> ux_byte_pool_available)
{
printf("ERROR #%d.%ld: Memory level different after re-init %ld <> %ld\n", __LINE__, test_n, mem_free, _ux_system -> ux_system_memory_byte_pool[UX_MEMORY_BYTE_POOL_REGULAR] -> ux_byte_pool_available);
test_control_return(1);
}
/* Set thread error generation */
ux_test_utility_sim_thread_error_generation_start(test_n);
/* Init. */
status = ux_device_stack_class_register(_ux_system_slave_class_cdc_ecm_name, ux_device_class_cdc_ecm_entry, 1, 0, &cdc_ecm_parameter);
/* Check error */
if (status != UX_THREAD_ERROR && status != NX_PTR_ERROR)
{
printf("ERROR #%d.%ld: code 0x%x\n", __LINE__, test_n, status);
test_control_return(1);
}
stepinfo("mem free: %ld\n", _ux_system -> ux_system_memory_byte_pool[UX_MEMORY_BYTE_POOL_REGULAR] -> ux_byte_pool_available);
}
ux_test_utility_sim_thread_error_generation_stop();
if (rsc_cdc_thread_usage) stepinfo("\n");
if (rsc_cdc_mutex_usage) stepinfo(">>>>>>>>>>>>>>>>>>> Mutex errors cdc_ecm init test\n");
mem_free = (~0);
for (test_n = 0; test_n < rsc_cdc_mutex_usage; test_n ++)
{
stepinfo("%4ld / %4ld\n", test_n, rsc_cdc_mutex_usage - 1);
/* Deinit. */
ux_device_stack_class_unregister(_ux_system_slave_class_cdc_ecm_name, ux_device_class_cdc_ecm_entry);
/* Update memory free level (disconnect) */
if (mem_free == (~0))
mem_free = _ux_system -> ux_system_memory_byte_pool[UX_MEMORY_BYTE_POOL_REGULAR] -> ux_byte_pool_available;
else if (mem_free != _ux_system -> ux_system_memory_byte_pool[UX_MEMORY_BYTE_POOL_REGULAR] -> ux_byte_pool_available)
{
printf("ERROR #%d.%ld: Memory level different after re-init %ld <> %ld\n", __LINE__, test_n, mem_free, _ux_system -> ux_system_memory_byte_pool[UX_MEMORY_BYTE_POOL_REGULAR] -> ux_byte_pool_available);
test_control_return(1);
}
/* Set thread error generation */
ux_test_utility_sim_mutex_error_generation_start(test_n);
/* Init. */
status = ux_device_stack_class_register(_ux_system_slave_class_cdc_ecm_name, ux_device_class_cdc_ecm_entry, 1, 0, &cdc_ecm_parameter);
/* Check error */
if (status != UX_MUTEX_ERROR)
{
printf("ERROR #%d.%ld: code 0x%x\n", __LINE__, test_n, status);
test_control_return(1);
}
stepinfo("mem free: %ld\n", _ux_system -> ux_system_memory_byte_pool[UX_MEMORY_BYTE_POOL_REGULAR] -> ux_byte_pool_available);
}
ux_test_utility_sim_mutex_error_generation_stop();
if (rsc_cdc_mutex_usage) stepinfo("\n");
if (rsc_cdc_sem_usage) stepinfo(">>>>>>>>>>>>>>>>>>> Semaphore errors cdc_ecm init test\n");
mem_free = (~0);
for (test_n = 0; test_n < rsc_cdc_sem_usage; test_n ++)
{
stepinfo("%4ld / %4ld\n", test_n, rsc_cdc_sem_usage - 1);
/* Deinit. */
ux_device_stack_class_unregister(_ux_system_slave_class_cdc_ecm_name, ux_device_class_cdc_ecm_entry);
/* Update memory free level (disconnect) */
if (mem_free == (~0))
mem_free = _ux_system -> ux_system_memory_byte_pool[UX_MEMORY_BYTE_POOL_REGULAR] -> ux_byte_pool_available;
else if (mem_free != _ux_system -> ux_system_memory_byte_pool[UX_MEMORY_BYTE_POOL_REGULAR] -> ux_byte_pool_available)
{
printf("ERROR #%d.%ld: Memory level different after re-init %ld <> %ld\n", __LINE__, test_n, mem_free, _ux_system -> ux_system_memory_byte_pool[UX_MEMORY_BYTE_POOL_REGULAR] -> ux_byte_pool_available);
test_control_return(1);
}
/* Set thread error generation */
ux_test_utility_sim_sem_error_generation_start(test_n);
/* Init. */
status = ux_device_stack_class_register(_ux_system_slave_class_cdc_ecm_name, ux_device_class_cdc_ecm_entry, 1, 0, &cdc_ecm_parameter);
/* Check error */
if (status != UX_SEMAPHORE_ERROR)
{
printf("ERROR #%d.%ld: code 0x%x\n", __LINE__, test_n, status);
test_control_return(1);
}
stepinfo("mem free: %ld\n", _ux_system -> ux_system_memory_byte_pool[UX_MEMORY_BYTE_POOL_REGULAR] -> ux_byte_pool_available);
}
ux_test_utility_sim_sem_error_generation_stop();
if (rsc_cdc_sem_usage) stepinfo("\n");
if (rsc_cdc_event_usage) stepinfo(">>>>>>>>>>>>>>>>>>> EventFlag errors cdc_ecm init test\n");
mem_free = (~0);
for (test_n = 0; test_n < rsc_cdc_event_usage; test_n ++)
{
stepinfo("%4ld / %4ld\n", test_n, rsc_cdc_event_usage - 1);
/* Deinit. */
ux_device_stack_class_unregister(_ux_system_slave_class_cdc_ecm_name, ux_device_class_cdc_ecm_entry);
/* Update memory free level (disconnect) */
if (mem_free == (~0))
mem_free = _ux_system -> ux_system_memory_byte_pool[UX_MEMORY_BYTE_POOL_REGULAR] -> ux_byte_pool_available;
else if (mem_free != _ux_system -> ux_system_memory_byte_pool[UX_MEMORY_BYTE_POOL_REGULAR] -> ux_byte_pool_available)
{
printf("ERROR #%d.%ld: Memory level different after re-init %ld <> %ld\n", __LINE__, test_n, mem_free, _ux_system -> ux_system_memory_byte_pool[UX_MEMORY_BYTE_POOL_REGULAR] -> ux_byte_pool_available);
test_control_return(1);
}
/* Set thread error generation */
ux_test_utility_sim_event_error_generation_start(test_n);
/* Init. */
status = ux_device_stack_class_register(_ux_system_slave_class_cdc_ecm_name, ux_device_class_cdc_ecm_entry, 1, 0, &cdc_ecm_parameter);
/* Check error */
if (status != UX_EVENT_ERROR)
{
printf("ERROR #%d.%ld: code 0x%x\n", __LINE__, test_n, status);
test_control_return(1);
}
stepinfo("mem free: %ld\n", _ux_system -> ux_system_memory_byte_pool[UX_MEMORY_BYTE_POOL_REGULAR] -> ux_byte_pool_available);
}
ux_test_utility_sim_event_error_generation_stop();
if (rsc_cdc_event_usage) stepinfo("\n");
stepinfo(">>>>>>>>>>>>>>>>>>> Test connect to avoid post post operation\n");
/* Connect. */
UX_TEST_CHECK_SUCCESS(ux_device_stack_class_register(_ux_system_slave_class_cdc_ecm_name, ux_device_class_cdc_ecm_entry, 1, 0, &cdc_ecm_parameter));
ux_test_dcd_sim_slave_connect(UX_FULL_SPEED_DEVICE);
ux_test_hcd_sim_host_connect(UX_FULL_SPEED_DEVICE);
class_cdc_ecm_get_host();
stepinfo(">>>>>>>>>>>>>>>>>>> post_init_host done\n");
}
static void post_init_device()
{
stepinfo(">>>>>>>>>>>>>>>>>>> post_init_device empty\n");
}
|