filex_unicode_2_test.c 8.3 KB

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