filex_unicode_fat_entry_2_test.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. #define DEMO_STACK_SIZE 8192
  12. #define CACHE_SIZE 16*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_fat_entry_2_test_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. /* Define what the initial system looks like. */
  31. #ifdef CTEST
  32. void test_application_define(void *first_unused_memory)
  33. #else
  34. void filex_unicode_fat_entry_2_test_application_define(void *first_unused_memory)
  35. #endif
  36. {
  37. #ifndef FX_STANDALONE_ENABLE
  38. UCHAR *pointer;
  39. /* Setup the working pointer. */
  40. pointer = (UCHAR *) first_unused_memory;
  41. /* Create the main thread. */
  42. tx_thread_create(&ftest_0, "thread 0", ftest_0_entry, 0,
  43. pointer, DEMO_STACK_SIZE,
  44. 4, 4, TX_NO_TIME_SLICE, TX_AUTO_START);
  45. pointer = pointer + DEMO_STACK_SIZE;
  46. /* Setup memory for the RAM disk and the sector cache. */
  47. cache_buffer = pointer;
  48. pointer = pointer + CACHE_SIZE;
  49. ram_disk_memory = pointer;
  50. #endif
  51. /* Initialize the FileX system. */
  52. fx_system_initialize();
  53. #ifdef FX_STANDALONE_ENABLE
  54. ftest_0_entry(0);
  55. #endif
  56. }
  57. /* Define the test threads. */
  58. static void ftest_0_entry(ULONG thread_input)
  59. {
  60. UINT status;
  61. UCHAR destination_name[100] = {0};
  62. UCHAR destination_name2[100] = {0};
  63. 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};
  64. ULONG length = 14;
  65. FX_LOCAL_PATH local_path;
  66. FX_PARAMETER_NOT_USED(thread_input);
  67. /* Print out some test information banners. */
  68. printf("FileX Test: Unicode fat entry 2 test...............................");
  69. /* Format the media. This needs to be done before opening it! */
  70. status = fx_media_format(&ram_disk,
  71. _fx_ram_driver, // Driver entry
  72. ram_disk_memory, // RAM disk memory pointer
  73. cache_buffer, // Media buffer pointer
  74. CACHE_SIZE, // Media buffer size
  75. "MY_RAM_DISK", // Volume Name
  76. 1, // Number of FATs
  77. 32, // Directory Entries
  78. 0, // Hidden sectors
  79. 512, // Total sectors
  80. 128, // Sector size
  81. 1, // Sectors per cluster
  82. 1, // Heads
  83. 1); // Sectors per track
  84. /* Open the ram_disk. */
  85. status += fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
  86. status += fx_unicode_directory_create(&ram_disk, long_unicode_name, length, (CHAR *)destination_name);
  87. /* Chdir to the created directory and create a subdirectory. */
  88. #ifndef FX_STANDALONE_ENABLE
  89. status = fx_directory_local_path_set(&ram_disk, &local_path, (CHAR *)destination_name);
  90. #else
  91. status = fx_directory_default_set(&ram_disk, (CHAR *)destination_name);
  92. #endif
  93. status += fx_unicode_directory_create(&ram_disk, long_unicode_name, length, (CHAR *)destination_name2);
  94. /* Fat entry destory. */
  95. ram_disk.fx_media_fat_cache[8].fx_fat_cache_entry_value = 0x1ff;
  96. ram_disk.fx_media_fat_cache[8].fx_fat_cache_entry_dirty = 1;
  97. /* Close the media to flush buffer. Now we have a disk with a corrupt dir_entry. */
  98. status += fx_media_close(&ram_disk);
  99. /* Open the ram_disk. */
  100. status = fx_media_open(&ram_disk, "RAM DISK", _fx_ram_driver, ram_disk_memory, cache_buffer, CACHE_SIZE);
  101. if (status != FX_SUCCESS)
  102. {
  103. printf("ERROR!\n");
  104. test_control_return(19);
  105. }
  106. #ifndef FX_STANDALONE_ENABLE
  107. status = fx_directory_local_path_set(&ram_disk, &local_path, (CHAR *)destination_name);
  108. #else
  109. status = fx_directory_default_set(&ram_disk, (CHAR *)destination_name);
  110. #endif
  111. status += fx_unicode_directory_create(&ram_disk, long_unicode_name, length, (CHAR *)destination_name);
  112. if (status == FX_SUCCESS)
  113. {
  114. printf("ERROR!\n");
  115. test_control_return(19);
  116. }
  117. else
  118. {
  119. printf("SUCCESS!\n");
  120. test_control_return(0);
  121. }
  122. }