1 /* This test is determined to cover lines in fx_unicode_directory_entry_read.c. */
2 /* We need a dir_entry whose first byte, ordinal number byte, is big enoutgh to exceed the the */
3 /* limit of FX_MAX_LONG_NAME_LEN, so we created a disk with a corrupt dir_entry. */
4 #ifndef FX_STANDALONE_ENABLE
5 #include "tx_api.h"
6 #endif
7 #include "fx_api.h"
8 #include <stdio.h>
9 #include <string.h>
10 #include "fx_ram_driver_test.h"
11
12 #define DEMO_STACK_SIZE 8192
13 #define CACHE_SIZE 16*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_fat_entry_2_test_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 /* Define what the initial system looks like. */
40
41 #ifdef CTEST
test_application_define(void * first_unused_memory)42 void test_application_define(void *first_unused_memory)
43 #else
44 void filex_unicode_fat_entry_2_test_application_define(void *first_unused_memory)
45 #endif
46 {
47
48 #ifndef FX_STANDALONE_ENABLE
49 UCHAR *pointer;
50
51
52 /* Setup the working pointer. */
53 pointer = (UCHAR *) first_unused_memory;
54
55 /* Create the main thread. */
56 tx_thread_create(&ftest_0, "thread 0", ftest_0_entry, 0,
57 pointer, DEMO_STACK_SIZE,
58 4, 4, TX_NO_TIME_SLICE, TX_AUTO_START);
59
60 pointer = pointer + DEMO_STACK_SIZE;
61
62 /* Setup memory for the RAM disk and the sector cache. */
63 cache_buffer = pointer;
64 pointer = pointer + CACHE_SIZE;
65 ram_disk_memory = pointer;
66
67 #endif
68
69 /* Initialize the FileX system. */
70 fx_system_initialize();
71 #ifdef FX_STANDALONE_ENABLE
72 ftest_0_entry(0);
73 #endif
74 }
75
76
77 /* Define the test threads. */
78
ftest_0_entry(ULONG thread_input)79 static void ftest_0_entry(ULONG thread_input)
80 {
81
82 UINT status;
83 UCHAR destination_name[100] = {0};
84 UCHAR destination_name2[100] = {0};
85 UCHAR long_unicode_name[] = {2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0, 9, 0, 10, 0, 11, 0, 12, 0, 13, 0, 14, 0, 15, 0, 0, 0};
86 ULONG length = 14;
87 FX_LOCAL_PATH local_path;
88
89 FX_PARAMETER_NOT_USED(thread_input);
90
91 /* Print out some test information banners. */
92 printf("FileX Test: Unicode fat entry 2 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 /* Open the ram_disk. */
111 status += fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
112 status += fx_unicode_directory_create(&ram_disk, long_unicode_name, length, (CHAR *)destination_name);
113 /* Chdir to the created directory and create a subdirectory. */
114 #ifndef FX_STANDALONE_ENABLE
115 status = fx_directory_local_path_set(&ram_disk, &local_path, (CHAR *)destination_name);
116 #else
117 status = fx_directory_default_set(&ram_disk, (CHAR *)destination_name);
118 #endif
119
120 status += fx_unicode_directory_create(&ram_disk, long_unicode_name, length, (CHAR *)destination_name2);
121
122 /* Fat entry destory. */
123 ram_disk.fx_media_fat_cache[8].fx_fat_cache_entry_value = 0x1ff;
124 ram_disk.fx_media_fat_cache[8].fx_fat_cache_entry_dirty = 1;
125
126 /* Close the media to flush buffer. Now we have a disk with a corrupt dir_entry. */
127 status += fx_media_close(&ram_disk);
128
129 /* Open the ram_disk. */
130 status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
131 if (status != FX_SUCCESS)
132 {
133 printf("ERROR!\n");
134 test_control_return(19);
135 }
136
137 #ifndef FX_STANDALONE_ENABLE
138 status = fx_directory_local_path_set(&ram_disk, &local_path, (CHAR *)destination_name);
139 #else
140 status = fx_directory_default_set(&ram_disk, (CHAR *)destination_name);
141 #endif
142 status += fx_unicode_directory_create(&ram_disk, long_unicode_name, length, (CHAR *)destination_name);
143
144 if (status == FX_SUCCESS)
145 {
146 printf("ERROR!\n");
147 test_control_return(19);
148 }
149 else
150 {
151 printf("SUCCESS!\n");
152 test_control_return(0);
153 }
154 }
155