1 /* This FileX test concentrates on the Fault-Tolerant redo log write interrupt operation.
2 * The available bytes before/after file write should be decreased write_buffer_size only. */
3
4 #ifndef FX_STANDALONE_ENABLE
5 #include "tx_api.h"
6 #endif
7 #include "fx_api.h"
8 #include "fx_system.h"
9 #include "fx_fault_tolerant.h"
10 #include <stdio.h>
11 #include "fx_ram_driver_test.h"
12 extern void test_control_return(UINT status);
13 void filex_fault_tolerant_log_full_test_application_define(void *first_unused_memory);
14
15 #if defined (FX_ENABLE_FAULT_TOLERANT) && defined (FX_FAULT_TOLERANT) && defined (FX_FAULT_TOLERANT_DATA)
16
17 #define DEMO_STACK_SIZE 4096
18 #define CACHE_SIZE 2048
19 #define FAULT_TOLERANT_SIZE FX_FAULT_TOLERANT_MINIMAL_BUFFER_SIZE
20
21
22
23
24 /* Define the ThreadX and FileX object control blocks... */
25
26 #ifndef FX_STANDALONE_ENABLE
27 static TX_THREAD ftest_0;
28 static TX_THREAD ftest_1;
29 #endif
30 static FX_MEDIA ram_disk;
31 static FX_FILE my_file;
32 static UCHAR *pointer;
33
34 /* Define the counters used in the test application... */
35
36 #ifndef FX_STANDALONE_ENABLE
37 static UCHAR *cache_buffer;
38 static UCHAR *fault_tolerant_buffer;
39 static UCHAR *thread_buffer;
40 #else
41 static UCHAR cache_buffer[CACHE_SIZE];
42 static UCHAR fault_tolerant_buffer[FAULT_TOLERANT_SIZE];
43 #endif
44 static CHAR write_buffer[2048];
45 static UINT i;
46
47 #define FAT_COUNT 3 /* FAT12, 16, 32. */
48 #define TEST_COUNT FAT_COUNT
49
50 /* Define thread prototypes. */
51
52 static void ftest_0_entry(ULONG thread_input);
53 extern void _fx_ram_driver(FX_MEDIA *media_ptr);
54 extern void test_control_return(UINT status);
55 extern UINT _filex_fault_tolerant_log_check(FX_MEDIA *media_ptr);
56 extern UINT (*driver_write_callback)(FX_MEDIA *media_ptr, UINT sector_type, UCHAR *block_ptr, UINT *operation_ptr);
57 static UINT my_driver_write(FX_MEDIA *media_ptr, UINT sector_type, UCHAR *block_ptr, UINT *operation_ptr);
58
59
60
61 /* Define what the initial system looks like. */
62
63 #ifdef CTEST
test_application_define(void * first_unused_memory)64 void test_application_define(void *first_unused_memory)
65 #else
66 void filex_fault_tolerant_log_full_test_application_define(void *first_unused_memory)
67 #endif
68 {
69
70
71 #ifndef FX_STANDALONE_ENABLE
72 /* Setup the working pointer. */
73 pointer = (UCHAR *) first_unused_memory;
74
75 /* Create the main thread. */
76 tx_thread_create(&ftest_0, "thread 0", ftest_0_entry, 0,
77 pointer, DEMO_STACK_SIZE,
78 4, 4, TX_NO_TIME_SLICE, TX_AUTO_START);
79 pointer = pointer + DEMO_STACK_SIZE;
80
81 /* Setup memory for the RAM disk and the sector cache. */
82 cache_buffer = pointer;
83 pointer += CACHE_SIZE;
84 fault_tolerant_buffer = pointer;
85 pointer += FAULT_TOLERANT_SIZE;
86 thread_buffer = pointer;
87 pointer += DEMO_STACK_SIZE;
88 #endif
89
90 /* Initialize the FileX system. */
91 fx_system_initialize();
92 #ifdef FX_STANDALONE_ENABLE
93 ftest_0_entry(0);
94 #endif
95 }
96
97
98
99 /* Define the test threads. */
100
ftest_0_entry(ULONG thread_input)101 static void ftest_0_entry(ULONG thread_input)
102 {
103
104 UINT status;
105
106 FX_PARAMETER_NOT_USED(thread_input);
107
108 /* Print out some test information banners. */
109 printf("FileX Test: Fault Tolerant Log Full Tes............................");
110
111 /* Loop to test FAT 12, 16, 32. */
112 for (i = 0; i < TEST_COUNT; i ++)
113 {
114 if (i == 0)
115 {
116 /* Format the media with FAT12. This needs to be done before opening it! */
117 status = fx_media_format(&ram_disk,
118 _fx_ram_driver, // Driver entry
119 ram_disk_memory_large, // RAM disk memory pointer
120 cache_buffer, // Media buffer pointer
121 CACHE_SIZE, // Media buffer size
122 "MY_RAM_DISK", // Volume Name
123 1, // Number of FATs
124 32, // Directory Entries
125 0, // Hidden sectors
126 256, // Total sectors
127 256, // Sector size
128 8, // Sectors per cluster
129 1, // Heads
130 1); // Sectors per track
131 }
132 else if (i == 1)
133 {
134 /* Format the media with FAT16. This needs to be done before opening it! */
135 status = fx_media_format(&ram_disk,
136 _fx_ram_driver, // Driver entry
137 ram_disk_memory_large, // RAM disk memory pointer
138 cache_buffer, // Media buffer pointer
139 CACHE_SIZE, // Media buffer size
140 "MY_RAM_DISK", // Volume Name
141 1, // Number of FATs
142 32, // Directory Entries
143 0, // Hidden sectors
144 4200 * 8, // Total sectors
145 256, // Sector size
146 8, // Sectors per cluster
147 1, // Heads
148 1); // Sectors per track
149 }
150 else if (i == 2)
151 {
152 /* Format the media with FAT32. This needs to be done before opening it! */
153 status = fx_media_format(&ram_disk,
154 _fx_ram_driver, // Driver entry
155 ram_disk_memory_large, // RAM disk memory pointer
156 cache_buffer, // Media buffer pointer
157 CACHE_SIZE, // Media buffer size
158 "MY_RAM_DISK", // Volume Name
159 1, // Number of FATs
160 32, // Directory Entries
161 0, // Hidden sectors
162 70000 * 4, // Total sectors
163 512, // Sector size
164 4, // Sectors per cluster
165 1, // Heads
166 1); // Sectors per track
167 }
168
169 /* Determine if the format had an error. */
170 if (status)
171 {
172
173 printf("ERROR!\n");
174 test_control_return(1);
175 }
176
177 /* Open the ram_disk. */
178 status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory_large, cache_buffer, CACHE_SIZE);
179
180 /* Check the status. */
181 if (status != FX_SUCCESS)
182 {
183
184 /* Error, return error code. */
185 printf("ERROR!\n");
186 test_control_return(2);
187 }
188
189 /* Enable the Fault-tolerant feature. */
190 status = fx_fault_tolerant_enable(&ram_disk, fault_tolerant_buffer, FAULT_TOLERANT_SIZE);
191
192 /* Check the create status. */
193 if (status != FX_SUCCESS)
194 {
195
196 printf("ERROR!\n");
197 test_control_return(4);
198 }
199
200 /* Create a file. */
201 status = fx_file_create(&ram_disk, "TEST.TXT");
202 status += fx_file_open(&ram_disk, &my_file, "TEST.TXT", FX_OPEN_FOR_WRITE);
203
204 /* Check the create status. */
205 if (status != FX_SUCCESS)
206 {
207
208 printf("ERROR!\n");
209 test_control_return(5);
210 }
211
212 /* Set the callback function to modify size of fault tolerant log. */
213 driver_write_callback = my_driver_write;
214
215 /* Write one cluster of information to the TEST.TXT file. */
216 status = fx_file_write(&my_file, write_buffer, sizeof(write_buffer));
217
218 /* Check the create status. */
219 if (status != FX_NO_MORE_SPACE)
220 {
221
222 printf("ERROR!\n");
223 test_control_return(6);
224 }
225
226 /* Close the secondary file. */
227 status = fx_file_close(&my_file);
228
229 /* Check the create status. */
230 if (status != FX_SUCCESS)
231 {
232
233 printf("ERROR!\n");
234 test_control_return(7);
235 }
236
237 /* Close the media. */
238 status = fx_media_close(&ram_disk);
239
240 /* Determine if the test was successful. */
241 if (status != FX_SUCCESS)
242 {
243
244 printf("ERROR!\n");
245 test_control_return(8);
246 }
247
248 /* Delete the thread. */
249 #ifndef FX_STANDALONE_ENABLE
250 tx_thread_delete(&ftest_1);
251 #endif
252 }
253
254 /* Output successful. */
255 printf("SUCCESS!\n");
256 test_control_return(0);
257 }
258
my_driver_write(FX_MEDIA * media_ptr,UINT sector_type,UCHAR * block_ptr,UINT * operation_ptr)259 static UINT my_driver_write(FX_MEDIA *media_ptr, UINT sector_type, UCHAR *block_ptr, UINT *operation_ptr)
260 {
261
262 FX_PARAMETER_NOT_USED(media_ptr);
263 FX_PARAMETER_NOT_USED(sector_type);
264 FX_PARAMETER_NOT_USED(block_ptr);
265 FX_PARAMETER_NOT_USED(operation_ptr);
266
267 if (ram_disk.fx_media_fault_tolerant_state == FX_FAULT_TOLERANT_STATE_STARTED)
268 {
269 ram_disk.fx_media_fault_tolerant_file_size = FX_FAULT_TOLERANT_MINIMAL_BUFFER_SIZE;
270 }
271
272 /* Return. */
273 return FX_SUCCESS;
274 }
275
276 #else
277
278 #ifdef CTEST
test_application_define(void * first_unused_memory)279 void test_application_define(void *first_unused_memory)
280 #else
281 void filex_fault_tolerant_log_full_test_application_define(void *first_unused_memory)
282 #endif
283 {
284
285 FX_PARAMETER_NOT_USED(first_unused_memory);
286
287 /* Print out some test information banners. */
288 printf("FileX Test: Fault Tolerant Log Full Tes............................N/A\n");
289
290 test_control_return(255);
291 }
292 #endif
293
294