1 #ifndef FX_STANDALONE_ENABLE
2 #include "tx_api.h"
3 #endif
4 #include "fx_api.h"
5 #include "fx_utility.h"
6 #include "fx_ram_driver_test.h"
7 #include <stdio.h>
8 #include <string.h>
9
10 #define DEMO_STACK_SIZE 8192
11 /* Set the cache size as the size of one sector causing frequently IO operation. */
12 #define CACHE_SIZE 128
13
14 /* Define the ThreadX and FileX object control blocks... */
15
16 #ifndef FX_STANDALONE_ENABLE
17 static TX_THREAD ftest_0;
18 #endif
19 static FX_MEDIA ram_disk;
20
21 /* Define the counters used in the test application... */
22
23 #ifndef FX_STANDALONE_ENABLE
24 static UCHAR *ram_disk_memory;
25 static UCHAR *cache_buffer;
26 #else
27 static UCHAR cache_buffer[CACHE_SIZE];
28 #endif
29
30 /* Define thread prototypes. */
31
32 void filex_unicode_3_application_define(void *first_unused_memory);
33 static void ftest_0_entry(ULONG thread_input);
34
35 VOID _fx_ram_driver(FX_MEDIA *media_ptr);
36 void test_control_return(UINT status);
37
38 /* Create a terrible driver. */
39 static UINT driver_called_counter = 0;
_fx_terrible_driver(FX_MEDIA * media_ptr)40 static void _fx_terrible_driver(FX_MEDIA *media_ptr)
41 {
42 driver_called_counter++;
43 // printf("\n_fx_terrible_driver has been called %d times.", driver_called_counter);
44 if (
45 // Make IO ERROR to reach the Line 202 in fx_unicode_directory_search.c
46 (driver_called_counter == 1)
47 )
48 {
49 media_ptr -> fx_media_driver_status = FX_IO_ERROR;
50 return;
51 }
52 (* _fx_ram_driver)(media_ptr);
53 }
54
55 /* Define what the initial system looks like. */
56
57 #ifdef CTEST
test_application_define(void * first_unused_memory)58 void test_application_define(void *first_unused_memory)
59 #else
60 void filex_unicode_3_application_define(void *first_unused_memory)
61 #endif
62 {
63
64 #ifndef FX_STANDALONE_ENABLE
65 UCHAR *pointer;
66
67
68 /* Setup the working pointer. */
69 pointer = (UCHAR *) first_unused_memory;
70
71 /* Create the main thread. */
72 tx_thread_create(&ftest_0, "thread 0", ftest_0_entry, 0,
73 pointer, DEMO_STACK_SIZE,
74 4, 4, TX_NO_TIME_SLICE, TX_AUTO_START);
75
76 pointer = pointer + DEMO_STACK_SIZE;
77
78 /* Setup memory for the RAM disk and the sector cache. */
79 cache_buffer = pointer;
80 pointer = pointer + CACHE_SIZE;
81 ram_disk_memory = pointer;
82
83 #endif
84
85 /* Initialize the FileX system. */
86 fx_system_initialize();
87 #ifdef FX_STANDALONE_ENABLE
88 ftest_0_entry(0);
89 #endif
90 }
91
92 static UCHAR long_unicode_name1[] = {1, 0, 0, 0};
93 static UCHAR long_unicode_name2[] = {1, 0, 2, 0, 0, 0};
94
95 /* Define the test threads. */
96
ftest_0_entry(ULONG thread_input)97 static void ftest_0_entry(ULONG thread_input)
98 {
99
100 UINT status, length;
101 UCHAR destination_name[128];
102 FX_LOCAL_PATH local_path;
103
104 FX_PARAMETER_NOT_USED(thread_input);
105
106 /* Print out some test information banners. */
107 printf("FileX Test: Unicode 3 test.........................................");
108 /* Format the media. This needs to be done before opening it! */
109 status = fx_media_format(&ram_disk,
110 _fx_ram_driver, // Driver entry
111 ram_disk_memory_large, // RAM disk memory pointer
112 cache_buffer, // Media buffer pointer
113 128, // Media buffer size
114 "MY_RAM_DISK", // Volume Name
115 1, // Number of FATs
116 32, // Directory Entries
117 0, // Hidden sectors
118 70000, // Total sectors
119 128, // Sector size
120 1, // Sectors per cluster
121 1, // Heads
122 1); // Sectors per track
123
124 return_value_if_fail( status == FX_SUCCESS, 1);
125 status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory_large, cache_buffer, CACHE_SIZE);
126 return_value_if_fail( status == FX_SUCCESS, 2);
127
128 // Locate at a subdir.
129 length = fx_unicode_length_get( long_unicode_name1);
130 status = fx_unicode_directory_create( &ram_disk, long_unicode_name1, length, (CHAR *)destination_name);
131 #ifndef FX_STANDALONE_ENABLE
132 status = fx_directory_local_path_set(&ram_disk, &local_path, (CHAR *)destination_name);
133 #else
134 status = fx_directory_default_set(&ram_disk, (CHAR *)destination_name);
135 #endif
136
137 /* Flush everything out. */
138 status += fx_media_flush( &ram_disk);
139 status += _fx_utility_FAT_flush( &ram_disk);
140 status += _fx_utility_logical_sector_flush( &ram_disk, 1, 60000, FX_TRUE);
141 return_value_if_fail( status == FX_SUCCESS, 3);
142
143 for (UINT i = 0; i < FX_MAX_FAT_CACHE; i++)
144 {
145 ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_cluster = 0;
146 ram_disk.fx_media_fat_cache[i].fx_fat_cache_entry_value = 0;
147 }
148
149 // Register our terrible driver.
150 ram_disk.fx_media_driver_entry = _fx_terrible_driver;
151
152 // fx_unicode_file_create will call fx_unicode_directory_search where we will make an IO ERROR.
153 length = fx_unicode_length_get( long_unicode_name2);
154 status = fx_unicode_file_create( &ram_disk, long_unicode_name2, length, (CHAR *)destination_name);
155 return_value_if_fail( status == FX_SUCCESS, 4);
156
157 // Register our terrible driver.
158 ram_disk.fx_media_driver_entry = _fx_ram_driver;
159
160 status = fx_media_close( &ram_disk);
161 return_value_if_fail( status == FX_SUCCESS, 5);
162
163 printf("SUCCESS!\n");
164 test_control_return(0);
165 }
166