1 /* This FileX test concentrates on the file attributes read/set operation. */
2
3 #ifndef FX_STANDALONE_ENABLE
4 #include "tx_api.h"
5 #endif
6 #include "fx_api.h"
7 #include <stdio.h>
8 #include "fx_ram_driver_test.h"
9
10 void test_control_return(UINT status);
11
12 #define DEMO_STACK_SIZE 4096
13 #define CACHE_SIZE 128*128
14
15
16 /* Define the ThreadX and FileX object control blocks... */
17
18 #ifndef FX_STANDALONE_ENABLE
19 static TX_THREAD ftest_0;
20 #endif
21 static FX_MEDIA ram_disk;
22
23
24 /* Define the counters used in the test application... */
25
26 #ifndef FX_STANDALONE_ENABLE
27 static UCHAR *ram_disk_memory;
28 static UCHAR *cache_buffer;
29 #else
30 static UCHAR cache_buffer[CACHE_SIZE];
31 #endif
32
33
34 /* Define thread prototypes. */
35
36 void filex_directory_attributes_read_set_application_define(void *first_unused_memory);
37 static void ftest_0_entry(ULONG thread_input);
38
39 VOID _fx_ram_driver(FX_MEDIA *media_ptr);
40
41
42
43 /* Define what the initial system looks like. */
44
45 #ifdef CTEST
test_application_define(void * first_unused_memory)46 void test_application_define(void *first_unused_memory)
47 #else
48 void filex_directory_attributes_read_set_application_define(void *first_unused_memory)
49 #endif
50 {
51
52 #ifndef FX_STANDALONE_ENABLE
53 UCHAR *pointer;
54
55
56 /* Setup the working pointer. */
57 pointer = (UCHAR *) first_unused_memory;
58
59 /* Create the main thread. */
60 tx_thread_create(&ftest_0, "thread 0", ftest_0_entry, 0,
61 pointer, DEMO_STACK_SIZE,
62 4, 4, TX_NO_TIME_SLICE, TX_AUTO_START);
63
64 pointer = pointer + DEMO_STACK_SIZE;
65
66 /* Setup memory for the RAM disk and the sector cache. */
67 cache_buffer = pointer;
68 pointer = pointer + CACHE_SIZE;
69 ram_disk_memory = pointer;
70 #endif
71
72 /* Initialize the FileX system. */
73 fx_system_initialize();
74 #ifdef FX_STANDALONE_ENABLE
75 ftest_0_entry(0);
76 #endif
77 }
78
79
80
81 /* Define the test threads. */
82
ftest_0_entry(ULONG thread_input)83 static void ftest_0_entry(ULONG thread_input)
84 {
85
86 UINT status;
87 UINT attributes;
88
89 FX_PARAMETER_NOT_USED(thread_input);
90
91 /* Print out some test information banners. */
92 printf("FileX Test: Directory attributes read/set test.....................");
93
94 /* Format the media. This needs to be done before opening it! */
95 status = fx_media_format(&ram_disk,
96 _fx_ram_driver, // Driver entry
97 ram_disk_memory, // RAM disk memory pointer
98 cache_buffer, // Media buffer pointer
99 CACHE_SIZE, // Media buffer size
100 "MY_RAM_DISK", // Volume Name
101 1, // Number of FATs
102 32, // Directory Entries
103 0, // Hidden sectors
104 512, // Total sectors
105 128, // Sector size
106 1, // Sectors per cluster
107 1, // Heads
108 1); // Sectors per track
109
110 /* Determine if the format had an error. */
111 if (status)
112 {
113
114 printf("ERROR!\n");
115 test_control_return(2);
116 }
117
118 /* test error checking */
119 #ifndef FX_DISABLE_ERROR_CHECKING
120
121 /* check directory attributes read null pointer error */
122 status = fx_directory_attributes_read(FX_NULL, "TEST_DIR", &attributes);
123 if (status != FX_PTR_ERROR)
124 {
125 printf("ERROR!\n");
126 test_control_return(99);
127 }
128
129 /* check directory attributes set null pointer error */
130 status = fx_directory_attributes_set(FX_NULL, "TEST_DIR", attributes);
131 if (status != FX_PTR_ERROR)
132 {
133 printf("ERROR!\n");
134 test_control_return(99);
135 }
136
137 /* check directory attributes set null pointer error */
138 status = fx_directory_attributes_set(&ram_disk, "TEST_DIR", 0x1111);
139 if (status != FX_INVALID_ATTR)
140 {
141 printf("ERROR!\n");
142 test_control_return(99);
143 }
144
145 #endif
146
147 /* check directory attributes read to make sure it throws an error when the media hasnt been opened */
148 status = fx_directory_attributes_read(&ram_disk, "TEST_DIR", &attributes);
149 if (status != FX_MEDIA_NOT_OPEN)
150 {
151 printf("ERROR!\n");
152 test_control_return(99);
153 }
154
155 /* check directory attributes set to make sure it throws an error when the media hasnt been opened */
156 status = fx_directory_attributes_set(&ram_disk, "TEST_DIR", 0x0000);
157 if (status != FX_MEDIA_NOT_OPEN)
158 {
159 printf("ERROR!\n");
160 test_control_return(99);
161 }
162
163 /* Open the ram_disk. */
164 status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
165
166 /* Check the status. */
167 if (status != FX_SUCCESS)
168 {
169
170 /* Error, return error code. */
171 printf("ERROR!\n");
172 test_control_return(3);
173 }
174
175 /* Create a directory called TEST_DIR in the root directory. */
176 status = fx_directory_create(&ram_disk, "TEST_DIR");
177
178 /* Check the create status. */
179 if (status != FX_SUCCESS)
180 {
181
182 printf("ERROR!\n");
183 test_control_return(4);
184 }
185
186 /* Create a file called NOT_A_DIR in the root directory. */
187 status = fx_file_create(&ram_disk, "NOT_A_DIR");
188
189 /* Check the create status. */
190 if (status != FX_SUCCESS)
191 {
192
193 printf("ERROR!\n");
194 test_control_return(4);
195 }
196
197 /* Invalidate the media cache. */
198 fx_media_cache_invalidate(&ram_disk);
199
200 /* Pickup the attributes of the directory. */
201 status = fx_directory_attributes_read(&ram_disk, "TEST_DIR", &attributes);
202
203 /* Check the attributes read status. */
204 if ((status != FX_SUCCESS) || (attributes != FX_DIRECTORY))
205 {
206
207 printf("ERROR!\n");
208 test_control_return(5);
209 }
210
211 /* check directory attributes set to make sure it throws an error when the directory is write protected */
212 ram_disk.fx_media_driver_write_protect = FX_TRUE;
213 status = fx_directory_attributes_set(&ram_disk, "TEST_DIR", attributes);
214 if (status == FX_SUCCESS)
215 {
216 printf("ERROR!\n");
217 test_control_return(99);
218 }
219 ram_disk.fx_media_driver_write_protect = FX_FALSE;
220
221 /* check directory attributes read to make sure it throws an error when it isnt a directory */
222 status = fx_directory_attributes_read(&ram_disk, "NOT_A_DIR", &attributes);
223 if (status != FX_NOT_DIRECTORY)
224 {
225 printf("ERROR!\n");
226 test_control_return(99);
227 }
228
229 /* check directory attributes read to make sure it throws an error when the directory isnt found */
230 status = fx_directory_attributes_read(&ram_disk, "DOES_NOT_EXIST", &attributes);
231 if (status == FX_SUCCESS)
232 {
233 printf("ERROR!\n");
234 test_control_return(99);
235 }
236
237 /* check directory attributes set to make sure it throws an error when it isnt a directory */
238 status = fx_directory_attributes_set(&ram_disk, "NOT_A_DIR", attributes);
239 if (status != FX_NOT_DIRECTORY)
240 {
241 printf("ERROR!\n");
242 test_control_return(99);
243 }
244
245 /* check directory attributes set to make sure it throws an error when the directory isnt found */
246 status = fx_directory_attributes_set(&ram_disk, "DOES_NOT_EXIST", attributes);
247 if (status == FX_SUCCESS)
248 {
249 printf("ERROR!\n");
250 test_control_return(99);
251 }
252
253 /* Invalidate the media cache. */
254 fx_media_cache_invalidate(&ram_disk);
255
256 /* Now write the attributes out for the directory. */
257 status = fx_directory_attributes_set(&ram_disk, "TEST_DIR", attributes | FX_ARCHIVE | FX_SYSTEM | FX_READ_ONLY | FX_HIDDEN);
258
259 /* Check the attributes set status. */
260 if (status != FX_SUCCESS)
261 {
262
263 printf("ERROR!\n");
264 test_control_return(6);
265 }
266
267 /* Invalidate the media cache. */
268 fx_media_cache_invalidate(&ram_disk);
269
270 /* Pickup the attributes of the directory again. */
271 status = fx_directory_attributes_read(&ram_disk, "TEST_DIR", &attributes);
272
273 /* Check the attributes read status. */
274 if ((status != FX_SUCCESS) || (attributes != (FX_ARCHIVE | FX_READ_ONLY | FX_DIRECTORY | FX_SYSTEM | FX_HIDDEN)))
275 {
276
277 printf("ERROR!\n");
278 test_control_return(7);
279 }
280
281 /* Close the media. */
282 status = fx_media_close(&ram_disk);
283
284 /* Determine if the test was successful. */
285 if (status != FX_SUCCESS)
286 {
287
288 printf("ERROR!\n");
289 test_control_return(8);
290 }
291 else
292 {
293
294 printf("SUCCESS!\n");
295 test_control_return(0);
296 }
297 }
298
299