1 /* This FileX test concentrates on the basic media check operation. */
2
3 #ifndef FX_STANDALONE_ENABLE
4 #include "tx_api.h"
5 #endif
6 #include "fx_api.h"
7 #include "fx_utility.h"
8 #include "fx_fault_tolerant.h"
9 #include "fx_ram_driver_test.h"
10 #include <stdio.h>
11 extern void test_control_return(UINT status);
12 void filex_fault_tolerant_media_check_application_define(void *first_unused_memory);
13
14 #if defined (FX_ENABLE_FAULT_TOLERANT) && defined (FX_FAULT_TOLERANT)
15 #define DEMO_STACK_SIZE 4096
16 #define CACHE_SIZE 2048
17 #define SCRATCH_MEMORY_SIZE 2000
18
19
20 /* Define the ThreadX and FileX object control blocks... */
21
22 #ifndef FX_STANDALONE_ENABLE
23 static TX_THREAD ftest_0;
24 #endif
25 static FX_MEDIA ram_disk;
26 static UCHAR fault_tolerant_buffer[FX_FAULT_TOLERANT_MINIMAL_BUFFER_SIZE];
27
28
29 /* Define the counters used in the test application... */
30
31 #ifndef FX_STANDALONE_ENABLE
32 static UCHAR ram_disk_memory[2048 * 256];
33 static UCHAR cache_buffer[CACHE_SIZE];
34 static UCHAR *scratch_memory;
35 #else
36 static UCHAR cache_buffer[CACHE_SIZE];
37 static UCHAR scratch_memory[SCRATCH_MEMORY_SIZE];
38 #endif
39
40
41
42
43 /* Define thread prototypes. */
44
45 static void ftest_0_entry(ULONG thread_input);
46
47 VOID _fx_ram_driver(FX_MEDIA *media_ptr);
48
49
50
51 /* Define what the initial system looks like. */
52
53 #ifdef CTEST
test_application_define(void * first_unused_memory)54 void test_application_define(void *first_unused_memory)
55 #else
56 void filex_fault_tolerant_media_check_application_define(void *first_unused_memory)
57 #endif
58 {
59 #ifndef FX_STANDALONE_ENABLE
60 UCHAR *pointer;
61
62
63 /* Setup the working pointer. */
64 pointer = (UCHAR *) first_unused_memory;
65
66 /* Create the main thread. */
67
68 tx_thread_create(&ftest_0, "thread 0", ftest_0_entry, 0,
69 pointer, DEMO_STACK_SIZE,
70 4, 4, TX_NO_TIME_SLICE, TX_AUTO_START);
71
72 pointer = pointer + DEMO_STACK_SIZE;
73
74 /* Setup memory for the RAM disk and the sector cache. */
75 scratch_memory = pointer;
76 #endif
77
78 /* Initialize the FileX system. */
79 fx_system_initialize();
80 #ifdef FX_STANDALONE_ENABLE
81 ftest_0_entry(0);
82 #endif
83 }
84
85
86
87 /* Define the test threads. */
88
ftest_0_entry(ULONG thread_input)89 static void ftest_0_entry(ULONG thread_input)
90 {
91
92 UINT status;
93 ULONG errors_detected;
94
95 FX_PARAMETER_NOT_USED(thread_input);
96
97 /* Print out some test information banners. */
98 printf("FileX Test: Fault Tolerant Media Check Test........................");
99
100 /* Format the media. This needs to be done before opening it! */
101 status = fx_media_format(&ram_disk,
102 _fx_ram_driver, // Driver entry
103 ram_disk_memory, // RAM disk memory pointer
104 cache_buffer, // Media buffer pointer
105 sizeof(cache_buffer), // Media buffer size
106 "MY_RAM_DISK", // Volume Name
107 1, // Number of FATs
108 32, // Directory Entries
109 0, // Hidden sectors
110 256, // Total sectors
111 2048, // Sector size
112 1, // Sectors per cluster
113 1, // Heads
114 1); // Sectors per track
115
116 /* Determine if the format had an error. */
117 if (status)
118 {
119
120 printf("ERROR!\n");
121 test_control_return(2);
122 }
123
124 /* Open the ram_disk. */
125 status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, sizeof(cache_buffer));
126
127 /* Check the status. */
128 if (status != FX_SUCCESS)
129 {
130
131 /* Error, return error code. */
132 printf("ERROR!\n");
133 test_control_return(3);
134 }
135
136 /* Enable fault tolerant. */
137 status = fx_fault_tolerant_enable(&ram_disk, fault_tolerant_buffer, sizeof(fault_tolerant_buffer));
138
139 /* Check the status. */
140 if (status != FX_SUCCESS)
141 {
142
143 /* Error, return error code. */
144 printf("ERROR!\n");
145 test_control_return(4);
146 }
147
148 /* Check the media for errors. */
149 status = fx_media_check(&ram_disk, scratch_memory, SCRATCH_MEMORY_SIZE, FX_LOST_CLUSTER_ERROR, &errors_detected);
150
151 /* Determine if any were found - should not have found any errors at this point. */
152 if ((status != FX_SUCCESS) || (errors_detected))
153 {
154
155 /* Error in the media. Return to caller. */
156 printf("ERROR!\n");
157 test_control_return(5);
158 }
159
160 /* Close the media. */
161 status = fx_media_close(&ram_disk);
162
163 /* Check the status. */
164 if (status != FX_SUCCESS)
165 {
166
167 /* Error, return error code. */
168 printf("ERROR!\n");
169 test_control_return(6);
170 }
171
172 printf("SUCCESS!\n");
173 test_control_return(0);
174 }
175
176 #else
177 #ifdef CTEST
test_application_define(void * first_unused_memory)178 void test_application_define(void *first_unused_memory)
179 #else
180 void filex_fault_tolerant_media_check_application_define(void *first_unused_memory)
181 #endif
182 {
183
184 FX_PARAMETER_NOT_USED(first_unused_memory);
185
186 /* Print out some test information banners. */
187 printf("FileX Test: Fault Tolerant Media Check Test........................N/A\n");
188
189 test_control_return(255);
190 }
191 #endif
192