1 /* This test is designed to test the ux_utility_memory_.... */
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_test_utility_sim.h"
11
12
13 /* Define USBX test constants. */
14
15 #define UX_TEST_STACK_SIZE 4096
16 #define UX_TEST_MEMORY_SIZE (64*1024)
17
18 #define LSB(x) ( (x) & 0x00ff)
19 #define MSB(x) (((x) & 0xff00) >> 8)
20
21 /* Define the counters used in the test application... */
22
23 static ULONG thread_0_counter;
24 static ULONG thread_1_counter;
25 static ULONG error_counter;
26
27 static UCHAR error_callback_ignore = UX_FALSE;
28 static ULONG error_callback_counter;
29
30 /* Define USBX test global variables. */
31
32
33 /* Define prototypes for external Host Controller's (HCDs), classes and clients. */
34
35 static TX_THREAD ux_test_thread_simulation_0;
36 static TX_THREAD ux_test_thread_simulation_1;
37 static void ux_test_thread_simulation_0_entry(ULONG);
38 static void ux_test_thread_simulation_1_entry(ULONG);
39
40 /* Prototype for test control return. */
41
42 void test_control_return(UINT status);
43
error_callback(UINT system_level,UINT system_context,UINT error_code)44 static VOID error_callback(UINT system_level, UINT system_context, UINT error_code)
45 {
46
47 error_callback_counter ++;
48
49 if (!error_callback_ignore)
50 {
51 {
52 /* Failed test. */
53 printf("Error #%d, system_level: %d, system_context: %d, error_code: 0x%x\n", __LINE__, system_level, system_context, error_code);
54 // test_control_return(1);
55 }
56 }
57 }
58
59 /* Define what the initial system looks like. */
60
61 #ifdef CTEST
test_application_define(void * first_unused_memory)62 void test_application_define(void *first_unused_memory)
63 #else
64 void usbx_ux_host_stack_uninitialize_test_application_define(void *first_unused_memory)
65 #endif
66 {
67
68 UINT status;
69 UCHAR *stack_pointer;
70 UCHAR *memory_pointer;
71
72
73 /* Inform user. */
74 printf("Running ux_host_stack_uninitialize Test............................. ");
75
76 /* Initialize the free memory pointer. */
77 stack_pointer = (CHAR *) first_unused_memory;
78 memory_pointer = stack_pointer + (UX_TEST_STACK_SIZE * 2);
79
80 /* Initialize USBX Memory. */
81 status = ux_system_initialize(memory_pointer, UX_TEST_MEMORY_SIZE, UX_NULL, 0);
82
83 /* Check for error. */
84 if (status != UX_SUCCESS)
85 {
86
87 printf("ERROR #%d: 0x%x\n", __LINE__, status);
88 test_control_return(1);
89 }
90
91 /* Register the error callback. */
92 _ux_utility_error_callback_register(error_callback);
93
94 /* Create the simulation thread. */
95 status = tx_thread_create(&ux_test_thread_simulation_0, "test simulation", ux_test_thread_simulation_0_entry, 0,
96 stack_pointer, UX_TEST_STACK_SIZE,
97 20, 20, 1, TX_AUTO_START);
98
99 /* Check for error. */
100 if (status != UX_SUCCESS)
101 {
102
103 printf("ERROR #%d: 0x%x\n", __LINE__, status);
104 test_control_return(1);
105 }
106 }
107
ux_test_thread_simulation_0_entry(ULONG arg)108 static void ux_test_thread_simulation_0_entry(ULONG arg)
109 {
110
111 UINT status;
112 ULONG rfree;
113
114 rfree = _ux_system -> ux_system_memory_byte_pool[UX_MEMORY_BYTE_POOL_REGULAR] -> ux_byte_pool_available;
115
116 status = _ux_host_stack_initialize(UX_NULL);
117 if (status != UX_SUCCESS)
118 {
119 printf("ERROR #%d: 0x%x\n", __LINE__, status);
120 test_control_return(1);
121 }
122 if (rfree <= _ux_system -> ux_system_memory_byte_pool[UX_MEMORY_BYTE_POOL_REGULAR] -> ux_byte_pool_available)
123 {
124 printf("ERROR #%d\n", __LINE__);
125 test_control_return(1);
126 }
127
128 status = _ux_host_stack_uninitialize();
129 if (status != UX_SUCCESS)
130 {
131 printf("ERROR #%d: 0x%x\n", __LINE__, status);
132 test_control_return(1);
133 }
134 if (rfree != _ux_system -> ux_system_memory_byte_pool[UX_MEMORY_BYTE_POOL_REGULAR] -> ux_byte_pool_available)
135 {
136 printf("ERROR #%d\n", __LINE__);
137 test_control_return(1);
138 }
139
140 /* Check for errors from other threads. */
141 if (error_counter)
142 {
143
144 /* Test error. */
145 printf("ERROR #%d: total %ld errors\n", __LINE__, error_counter);
146 test_control_return(1);
147 }
148 else
149 {
150
151 /* Successful test. */
152 printf("SUCCESS!\n");
153 test_control_return(0);
154 }
155 }