1 /* Test the condition of fat entry broken. */
2 #ifndef FX_STANDALONE_ENABLE
3 #include "tx_api.h"
4 #endif
5 #include "fx_api.h"
6 #include "fx_utility.h"
7 #include "fx_ram_driver_test.h"
8 #include <stdio.h>
9 #include <string.h>
10
11 #define DEMO_STACK_SIZE 8192
12 /* Set the cache size as the size of one sector causing frequently IO operation. */
13 #define CACHE_SIZE 128
14
15 /* Define the ThreadX and FileX object control blocks... */
16
17 #ifndef FX_STANDALONE_ENABLE
18 static TX_THREAD ftest_0;
19 #endif
20 static FX_MEDIA ram_disk;
21
22 /* Define the counters used in the test application... */
23
24 #ifndef FX_STANDALONE_ENABLE
25 static UCHAR *ram_disk_memory;
26 static UCHAR *cache_buffer;
27 #else
28 static UCHAR cache_buffer[CACHE_SIZE];
29 #endif
30
31 /* Define thread prototypes. */
32
33 void filex_unicode_2_application_define(void *first_unused_memory);
34 static void ftest_0_entry(ULONG thread_input);
35
36 VOID _fx_ram_driver(FX_MEDIA *media_ptr);
37 void test_control_return(UINT status);
38
39 /* Create a terrible driver. */
40 static UINT driver_called_counter = 0;
_fx_terrible_driver(FX_MEDIA * media_ptr)41 static void _fx_terrible_driver(FX_MEDIA *media_ptr)
42 {
43 driver_called_counter++;
44 //printf("\n_fx_terrible_driver has been called %d times.", driver_called_counter);
45
46 // Ensure the variable we want to operate normal at the rest of time.
47 media_ptr -> fx_media_root_cluster_32 = 2;
48 // To cover the branch at Line 203 in fx_unicode_directory_entry_read.c, modify fx_media_root_cluster_32 at a particular time.
49 if ( driver_called_counter == 2)
50 {
51 media_ptr -> fx_media_root_cluster_32 = 0xffffffff;
52 }
53 if ( driver_called_counter == 9)
54 {
55 media_ptr -> fx_media_root_cluster_32 = 1;
56 }
57 (* _fx_ram_driver)(media_ptr);
58 }
59
60 /* Define what the initial system looks like. */
61
62 #ifdef CTEST
test_application_define(void * first_unused_memory)63 void test_application_define(void *first_unused_memory)
64 #else
65 void filex_unicode_2_application_define(void *first_unused_memory)
66 #endif
67 {
68
69 #ifndef FX_STANDALONE_ENABLE
70 UCHAR *pointer;
71
72
73 /* Setup the working pointer. */
74 pointer = (UCHAR *) first_unused_memory;
75
76 /* Create the main thread. */
77 tx_thread_create(&ftest_0, "thread 0", ftest_0_entry, 0,
78 pointer, DEMO_STACK_SIZE,
79 4, 4, TX_NO_TIME_SLICE, TX_AUTO_START);
80
81 pointer = pointer + DEMO_STACK_SIZE;
82
83 /* Setup memory for the RAM disk and the sector cache. */
84 cache_buffer = pointer;
85 pointer = pointer + CACHE_SIZE;
86 ram_disk_memory = pointer;
87
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 static UCHAR long_unicode_name1[] = {1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 0, 0};
98 /* Define the test threads. */
99
ftest_0_entry(ULONG thread_input)100 static void ftest_0_entry(ULONG thread_input)
101 {
102 UINT status, length;
103 UCHAR destination_name[128];
104 UCHAR destination_name_1[128];
105
106 FX_PARAMETER_NOT_USED(thread_input);
107
108 /* Print out some test information banners. */
109 printf("FileX Test: Unicode 2 test.........................................");
110
111 /* Format the media as FAT32. This needs to be done before opening it! */
112 status = fx_media_format(&ram_disk,
113 _fx_ram_driver, // Driver entry
114 ram_disk_memory_large, // RAM disk memory pointer
115 cache_buffer, // Media buffer pointer
116 128, // Media buffer size
117 "MY_RAM_DISK", // Volume Name
118 1, // Number of FATs
119 32, // Directory Entries
120 0, // Hidden sectors
121 70000, // Total sectors
122 128, // Sector size
123 1, // Sectors per cluster
124 1, // Heads
125 1); // Sectors per track
126
127 return_value_if_fail( status == FX_SUCCESS, 1);
128 status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory_large, cache_buffer, CACHE_SIZE);
129 return_value_if_fail( status == FX_SUCCESS, 2);
130
131 length = fx_unicode_length_get( long_unicode_name1);
132 status = fx_unicode_directory_create( &ram_disk, long_unicode_name1, length, (CHAR *)destination_name);
133 long_unicode_name1[0]++;
134 length = fx_unicode_length_get( long_unicode_name1);
135 status = fx_unicode_file_create( &ram_disk, long_unicode_name1, length, (CHAR *)destination_name_1);
136 long_unicode_name1[0]++;
137 length = fx_unicode_length_get( long_unicode_name1);
138 status = fx_unicode_file_create( &ram_disk, long_unicode_name1, length, (CHAR *)destination_name_1);
139
140 status = fx_media_flush(&ram_disk);
141 return_value_if_fail( status == FX_SUCCESS, 3);
142
143 // Register our terrible driver.
144 ram_disk.fx_media_driver_entry = _fx_terrible_driver;
145
146 long_unicode_name1[0]++;
147 length = fx_unicode_length_get( long_unicode_name1);
148 status = fx_unicode_file_create( &ram_disk, long_unicode_name1, length, (CHAR *)destination_name_1);
149 return_value_if_fail( status == FX_SUCCESS, 4);
150
151 // Register our terrible driver.
152 ram_disk.fx_media_driver_entry = _fx_ram_driver;
153
154 /* Corrupt the media. */
155 ram_disk.fx_media_bytes_per_sector = 0;
156 status = fx_unicode_file_create(&ram_disk, long_unicode_name1, length, (CHAR*)destination_name_1);
157 return_value_if_fail(status == FX_MEDIA_INVALID, 4);
158 ram_disk.fx_media_bytes_per_sector = 128;
159
160 status = fx_media_abort( &ram_disk);
161 return_value_if_fail( status == FX_SUCCESS, 5);
162
163 /* Format the media. This needs to be done before opening it! */
164 status = fx_media_format(&ram_disk,
165 _fx_ram_driver, // Driver entry
166 ram_disk_memory_large, // RAM disk memory pointer
167 cache_buffer, // Media buffer pointer
168 128, // Media buffer size
169 "MY_RAM_DISK", // Volume Name
170 1, // Number of FATs
171 32, // Directory Entries
172 0, // Hidden sectors
173 70000, // Total sectors
174 128, // Sector size
175 1, // Sectors per cluster
176 1, // Heads
177 1); // Sectors per track
178
179 return_value_if_fail( status == FX_SUCCESS, 6);
180 status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory_large, cache_buffer, CACHE_SIZE);
181 return_value_if_fail( status == FX_SUCCESS, 7);
182
183 length = fx_unicode_length_get( long_unicode_name1);
184 status = fx_unicode_directory_create( &ram_disk, long_unicode_name1, length, (CHAR *)destination_name);
185 long_unicode_name1[0]++;
186 length = fx_unicode_length_get( long_unicode_name1);
187 status = fx_unicode_file_create( &ram_disk, long_unicode_name1, length, (CHAR *)destination_name_1);
188 long_unicode_name1[0]++;
189 length = fx_unicode_length_get( long_unicode_name1);
190 status = fx_unicode_file_create( &ram_disk, long_unicode_name1, length, (CHAR *)destination_name_1);
191
192 status = fx_media_flush(&ram_disk);
193 return_value_if_fail( status == FX_SUCCESS, 8);
194
195 // Register our terrible driver.
196 ram_disk.fx_media_driver_entry = _fx_terrible_driver;
197
198 long_unicode_name1[0]++;
199 length = fx_unicode_length_get( long_unicode_name1);
200 status = fx_unicode_file_create( &ram_disk, long_unicode_name1, length, (CHAR *)destination_name_1);
201 // Our modification will not influence the result.
202 return_value_if_fail( status == FX_SUCCESS, 9);
203
204 // Register our terrible driver.
205 ram_disk.fx_media_driver_entry = _fx_ram_driver;
206
207 status = fx_media_abort( &ram_disk);
208 return_value_if_fail( status == FX_SUCCESS, 10);
209
210 printf("SUCCESS!\n");
211 test_control_return(0);
212 }
213