filex_unicode_3_test.c 5.6 KB

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