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_storage.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
41 /* Define what the initial system looks like. */
42
43 #ifdef CTEST
test_application_define(void * first_unused_memory)44 void test_application_define(void *first_unused_memory)
45 #else
46 void usbx_uxe_host_storage_test_application_define(void *first_unused_memory)
47 #endif
48 {
49
50 UINT status;
51 CHAR *stack_pointer;
52 CHAR *memory_pointer;
53
54 /* Inform user. */
55 printf("Running uxe_host_storage APIs Test.................................... ");
56 #if !defined(UX_HOST_CLASS_STORAGE_ENABLE_ERROR_CHECKING)
57 #warning Tests skipped due to compile option!
58 printf("SKIP SUCCESS!\n");
59 test_control_return(0);
60 return;
61 #endif
62
63 /* Initialize the free memory pointer. */
64 stack_pointer = (CHAR *) first_unused_memory;
65 memory_pointer = stack_pointer + (UX_TEST_STACK_SIZE * 2);
66
67 /* Initialize USBX Memory. */
68 status = ux_system_initialize(memory_pointer, UX_TEST_MEMORY_SIZE, UX_NULL, 0);
69
70 /* Check for error. */
71 if (status != UX_SUCCESS)
72 {
73
74 printf("ERROR #%d\n", __LINE__);
75 test_control_return(1);
76 }
77
78 /* Create the simulation thread. */
79 status = tx_thread_create(&ux_test_thread_simulation_0, "test simulation", ux_test_thread_simulation_0_entry, 0,
80 stack_pointer, UX_TEST_STACK_SIZE,
81 20, 20, 1, TX_AUTO_START);
82
83 /* Check for error. */
84 if (status != TX_SUCCESS)
85 {
86
87 printf("ERROR #%d\n", __LINE__);
88 test_control_return(1);
89 }
90 }
91
92
ux_test_thread_simulation_0_entry(ULONG arg)93 static void ux_test_thread_simulation_0_entry(ULONG arg)
94 {
95 UINT status;
96 UX_HOST_CLASS_STORAGE dummy_storage;
97 UX_HOST_CLASS_STORAGE *dummy_storage_ptr = UX_NULL;
98 UX_HOST_CLASS_STORAGE_MEDIA dummy_storage_media;
99 UX_HOST_CLASS_STORAGE_MEDIA *dummy_storage_media_ptr = UX_NULL;
100 UCHAR dummy_buffer[512];
101
102 /* ux_host_class_storage_lock() */
103 status = ux_host_class_storage_lock(dummy_storage_ptr, UX_WAIT_FOREVER);
104 UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);
105 ux_host_class_storage_lock(dummy_storage_ptr, UX_WAIT_FOREVER);
106
107 #if defined(UX_HOST_CLASS_STORAGE_NO_FILEX)
108
109 /* ux_host_class_storage_unlock() */
110 ux_host_class_storage_unlock(dummy_storage_ptr);
111
112 /* ux_host_class_storage_lun_select() */
113 ux_host_class_storage_lun_select(dummy_storage_ptr, 0);
114
115 /* ux_host_class_storage_media_read() */
116 status = ux_host_class_storage_media_read(UX_NULL, 1, 1, dummy_buffer);
117 UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);
118 status = ux_host_class_storage_media_read(&dummy_storage, 1, 1, UX_NULL);
119 UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);
120
121 /* ux_host_class_storage_media_write() */
122 status = ux_host_class_storage_media_write(UX_NULL, 1, 1, dummy_buffer);
123 UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);
124
125 /* ux_host_class_storage_media_get() */
126 status = ux_host_class_storage_media_get(UX_NULL, 0, &dummy_storage_media_ptr);
127 UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);
128 status = ux_host_class_storage_media_get(&dummy_storage, 0, UX_NULL);
129 UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);
130
131 dummy_storage_media_ptr = UX_NULL;
132
133 /* ux_host_class_storage_media_lock() */
134 status = ux_host_class_storage_media_lock(dummy_storage_media_ptr, UX_WAIT_FOREVER);
135 UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);
136
137 /* ux_host_class_storage_media_unlock() */
138 ux_host_class_storage_media_unlock(dummy_storage_media_ptr);
139
140 #if defined(uX_HOST_STANDALONE)
141 /* ux_host_class_storage_media_check() */
142 status = ux_host_class_storage_media_check(UX_NULL);
143 UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);
144 #endif
145
146 #else
147
148 /* ux_host_class_storage_unlock() */
149 status = ux_host_class_storage_unlock(dummy_storage_ptr);
150 UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);
151 ux_host_class_storage_unlock(dummy_storage_ptr);
152
153 /* ux_host_class_storage_lun_select() */
154 ux_host_class_storage_lun_select(dummy_storage_ptr, 0);
155
156 #endif
157
158
159 /* Sleep for a tick to make sure everything is complete. */
160 tx_thread_sleep(1);
161
162 /* Check for errors from other threads. */
163 if (error_counter)
164 {
165
166 /* Test error. */
167 printf("ERROR #%d: total %ld errors\n", __LINE__, error_counter);
168 test_control_return(1);
169 }
170 else
171 {
172
173 /* Successful test. */
174 printf("SUCCESS!\n");
175 test_control_return(0);
176 }
177 }
178