filex_utility_test.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821
  1. /* This FileX test concentrates on the utility APIs. */
  2. #include "fx_api.h"
  3. #include "fx_ram_driver_test.h"
  4. #include "fx_utility.h"
  5. #include <stdio.h>
  6. void filex_utility_application_define(void *first_unused_memory);
  7. void test_control_return(UINT status);
  8. #define DEMO_STACK_SIZE 8192
  9. #define CACHE_SIZE 16*128
  10. /* Define the ThreadX and FileX object control blocks... */
  11. #ifndef FX_STANDALONE_ENABLE
  12. static TX_THREAD ftest_0;
  13. #endif
  14. static FX_MEDIA ram_disk;
  15. /* Define the counters used in the test application... */
  16. #ifndef FX_STANDALONE_ENABLE
  17. static UCHAR *ram_disk_memory;
  18. static UCHAR *cache_buffer;
  19. #else
  20. static UCHAR cache_buffer[CACHE_SIZE];
  21. #endif
  22. extern UCHAR _fx_media_format_oem_name[8];
  23. extern UCHAR _fx_media_format_media_type;
  24. extern ULONG _fx_media_format_volume_id;
  25. static UCHAR partition_sector[] = {
  26. 0xfa, 0xb8, 0x00, 0x00, 0x8e, 0xd0, 0xbc, 0x00, 0x7c, 0x8b, 0xf4, 0x50, 0x07, 0x50, 0x1f, 0xfb,
  27. 0xfc, 0xbf, 0x00, 0x06, 0xb9, 0x00, 0x01, 0xf3, 0xa5, 0xea, 0x1e, 0x06, 0x00, 0x00, 0xbe, 0xbe,
  28. 0x07, 0x80, 0x3c, 0x80, 0x74, 0x02, 0xcd, 0x18, 0x56, 0x53, 0x06, 0xbb, 0x00, 0x7c, 0xb9, 0x01,
  29. 0x00, 0xba, 0x00, 0x00, 0xb8, 0x01, 0x02, 0xcd, 0x13, 0x07, 0x5b, 0x5e, 0xb2, 0x80, 0x72, 0x0b,
  30. 0xbf, 0xbc, 0x7d, 0x81, 0x3d, 0x55, 0x53, 0x75, 0x02, 0xb2, 0x00, 0xbf, 0xeb, 0x06, 0x88, 0x15,
  31. 0x8a, 0x74, 0x01, 0x8b, 0x4c, 0x02, 0x8b, 0xee, 0xeb, 0x15, 0xbe, 0x9b, 0x06, 0xac, 0x3c, 0x00,
  32. 0x74, 0x0b, 0x56, 0xbb, 0x07, 0x00, 0xb4, 0x0e, 0xcd, 0x10, 0x5e, 0xeb, 0xf0, 0xeb, 0xfe, 0xbb,
  33. 0x00, 0x7c, 0xb8, 0x01, 0x02, 0xcd, 0x13, 0x73, 0x05, 0xbe, 0xb3, 0x06, 0xeb, 0xdf, 0xbe, 0xd2,
  34. 0x06, 0xbf, 0xfe, 0x7d, 0x81, 0x3d, 0x55, 0xaa, 0x75, 0xd3, 0xbf, 0x24, 0x7c, 0xbe, 0xeb, 0x06,
  35. 0x8a, 0x04, 0x88, 0x05, 0x8b, 0xf5, 0xea, 0x00, 0x7c, 0x00, 0x00, 0x49, 0x6e, 0x76, 0x61, 0x6c,
  36. 0x69, 0x64, 0x20, 0x70, 0x61, 0x72, 0x74, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x74, 0x61, 0x62,
  37. 0x6c, 0x65, 0x00, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x20, 0x6c, 0x6f, 0x61, 0x64, 0x69, 0x6e, 0x67,
  38. 0x20, 0x6f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6e, 0x67, 0x20, 0x73, 0x79, 0x73, 0x74, 0x65,
  39. 0x6d, 0x00, 0x4d, 0x69, 0x73, 0x73, 0x69, 0x6e, 0x67, 0x20, 0x6f, 0x70, 0x65, 0x72, 0x61, 0x74,
  40. 0x69, 0x6e, 0x67, 0x20, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  41. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  42. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  43. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  44. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  45. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  46. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  47. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  48. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  49. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  50. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  51. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  52. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  53. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x52, 0x1a, 0xb8, 0x5e, 0x00, 0x00, 0x00, 0x14,
  54. 0x35, 0x00, 0x0c, 0xfe, 0xff, 0xe9, 0x20, 0x05, 0x00, 0x00, 0xe0, 0xa2, 0xf5, 0x00, 0x00, 0x00,
  55. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  56. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  57. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, 0xaa
  58. };
  59. #define TEST_COUNT 5
  60. /* Define thread prototypes. */
  61. static void ftest_0_entry(ULONG thread_input);
  62. VOID _fx_ram_driver(FX_MEDIA *media_ptr);
  63. UINT fx_media_format_oem_name_set(UCHAR new_oem_name[8]);
  64. UINT fx_media_format_type_set(UCHAR new_media_type);
  65. UINT fx_media_format_volume_id_set(ULONG new_volume_id);
  66. UINT _fx_partition_offset_calculate(void *partition_sector, UINT partition,
  67. ULONG *partition_start, ULONG *partition_size);
  68. /* Define what the initial system looks like. */
  69. #ifdef CTEST
  70. void test_application_define(void *first_unused_memory)
  71. #else
  72. void filex_utility_application_define(void *first_unused_memory)
  73. #endif
  74. {
  75. #ifndef FX_STANDALONE_ENABLE
  76. UCHAR *pointer;
  77. /* Setup the working pointer. */
  78. pointer = (UCHAR *) first_unused_memory;
  79. /* Create the main thread. */
  80. tx_thread_create(&ftest_0, "thread 0", ftest_0_entry, 0,
  81. pointer, DEMO_STACK_SIZE,
  82. 4, 4, TX_NO_TIME_SLICE, TX_AUTO_START);
  83. pointer = pointer + DEMO_STACK_SIZE;
  84. /* Setup memory for the RAM disk and the sector cache. */
  85. cache_buffer = pointer;
  86. pointer = pointer + CACHE_SIZE;
  87. ram_disk_memory = pointer;
  88. #endif
  89. /* Initialize the FileX system. */
  90. fx_system_initialize();
  91. #ifdef FX_STANDALONE_ENABLE
  92. ftest_0_entry(0);
  93. #endif
  94. }
  95. static void no_partition_test()
  96. {
  97. UINT i;
  98. UINT status;
  99. ULONG total_sectors;
  100. ULONG partition_start;
  101. ULONG partition_size;
  102. /* Loop to test FAT 12, 16, 32. */
  103. for (i = 0; i < TEST_COUNT; i ++)
  104. {
  105. if (i == 0)
  106. {
  107. /* Format the media with FAT12. This needs to be done before opening it! */
  108. total_sectors = 256;
  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. CACHE_SIZE, // Media buffer size
  114. "MY_RAM_DISK", // Volume Name
  115. 1, // Number of FATs
  116. 32, // Directory Entries
  117. 0, // Hidden sectors
  118. total_sectors, // Total sectors
  119. 512, // Sector size
  120. 8, // Sectors per cluster
  121. 1, // Heads
  122. 1); // Sectors per track
  123. }
  124. else if (i == 1)
  125. {
  126. /* Format the media with FAT16. This needs to be done before opening it! */
  127. total_sectors = 4200 * 8;
  128. status = fx_media_format(&ram_disk,
  129. _fx_ram_driver, // Driver entry
  130. ram_disk_memory_large, // RAM disk memory pointer
  131. cache_buffer, // Media buffer pointer
  132. CACHE_SIZE, // Media buffer size
  133. "MY_RAM_DISK", // Volume Name
  134. 1, // Number of FATs
  135. 32, // Directory Entries
  136. 0, // Hidden sectors
  137. total_sectors, // Total sectors
  138. 512, // Sector size
  139. 8, // Sectors per cluster
  140. 1, // Heads
  141. 1); // Sectors per track
  142. }
  143. else if (i == 2)
  144. {
  145. /* Format the media with FAT32. This needs to be done before opening it! */
  146. total_sectors = 70000 * 8;
  147. status = fx_media_format(&ram_disk,
  148. _fx_ram_driver, // Driver entry
  149. ram_disk_memory_large, // RAM disk memory pointer
  150. cache_buffer, // Media buffer pointer
  151. CACHE_SIZE, // Media buffer size
  152. "MY_RAM_DISK", // Volume Name
  153. 1, // Number of FATs
  154. 32, // Directory Entries
  155. 0, // Hidden sectors
  156. total_sectors, // Total sectors
  157. 512, // Sector size
  158. 8, // Sectors per cluster
  159. 1, // Heads
  160. 1); // Sectors per track
  161. }
  162. else if (i == 3)
  163. {
  164. /* Format the media with FAT12. This needs to be done before opening it! */
  165. total_sectors = 256;
  166. status = fx_media_format(&ram_disk,
  167. _fx_ram_driver, // Driver entry
  168. ram_disk_memory_large, // RAM disk memory pointer
  169. cache_buffer, // Media buffer pointer
  170. CACHE_SIZE, // Media buffer size
  171. "MY_RAM_DISK", // Volume Name
  172. 1, // Number of FATs
  173. 32, // Directory Entries
  174. 0, // Hidden sectors
  175. total_sectors, // Total sectors
  176. 128, // Sector size
  177. 8, // Sectors per cluster
  178. 1, // Heads
  179. 1); // Sectors per track
  180. }
  181. else if (i == 4)
  182. {
  183. /* Format the media with FAT12. This needs to be done before opening it! */
  184. total_sectors = 256;
  185. status = fx_media_format(&ram_disk,
  186. _fx_ram_driver, // Driver entry
  187. ram_disk_memory_large, // RAM disk memory pointer
  188. cache_buffer, // Media buffer pointer
  189. CACHE_SIZE, // Media buffer size
  190. "MY_RAM_DISK", // Volume Name
  191. 1, // Number of FATs
  192. 32, // Directory Entries
  193. 0, // Hidden sectors
  194. total_sectors, // Total sectors
  195. 1024, // Sector size
  196. 8, // Sectors per cluster
  197. 1, // Heads
  198. 1); // Sectors per track
  199. }
  200. return_if_fail( status == FX_SUCCESS);
  201. /* Get partition offset and size. */
  202. _fx_partition_offset_calculate(ram_disk_memory_large, 0, &partition_start, &partition_size);
  203. /* Check partition offset and size. */
  204. return_value_if_fail(partition_start == 0, 6);
  205. return_value_if_fail(partition_size == total_sectors, 7);
  206. }
  207. }
  208. /* Define the test threads. */
  209. static void ftest_0_entry(ULONG thread_input)
  210. {
  211. UCHAR oem_name[8] = {'O', 'E', 'M', ' ', 'N', 'A', 'M', 'E'};
  212. ULONG partition_start;
  213. ULONG partition_size;
  214. ULONG FAT_sector;
  215. ULONG64 value;
  216. CHAR buffer[16];
  217. UINT size;
  218. UINT status;
  219. UINT partition_sector_value;
  220. FX_MEDIA tmp_media;
  221. ULONG temp;
  222. ULONG temp1;
  223. ULONG temp2;
  224. ULONG temp3;
  225. ULONG temp4;
  226. ULONG temp5;
  227. ULONG temp6;
  228. FX_PARAMETER_NOT_USED(thread_input);
  229. /* Print out some test information banners. */
  230. printf("FileX Test: Utility test...........................................");
  231. /* Modify OEM_NAME. */
  232. fx_media_format_oem_name_set(oem_name);
  233. /* Check OEM_NAME. */
  234. return_value_if_fail(memcmp(oem_name, _fx_media_format_oem_name, sizeof(oem_name)) == 0, 1);
  235. /* Modify media_type. */
  236. fx_media_format_type_set(0xF0);
  237. /* Check media_type. */
  238. return_value_if_fail(_fx_media_format_media_type == 0xF0, 2);
  239. /* Modify volume_id. */
  240. fx_media_format_volume_id_set(0xFF);
  241. /* Check media_type. */
  242. return_value_if_fail(_fx_media_format_volume_id == 0xFF, 3);
  243. /* Get partition offset and size. */
  244. _fx_partition_offset_calculate(partition_sector, 0, &partition_start, &partition_size);
  245. /* Check partition offset and size. */
  246. return_value_if_fail(partition_start == 0x0520, 4);
  247. return_value_if_fail(partition_size == 0xF5A2E0, 5);
  248. /* Check for error in _fx_partition_offset_calculate when buffer is invalid. */
  249. /* Induce error in buffer */
  250. partition_sector[510] = 0xFF;
  251. status = _fx_partition_offset_calculate(partition_sector, 0, &partition_start, &partition_size);
  252. /* Check for the error. */
  253. if (status != FX_NOT_FOUND)
  254. {
  255. /* Print error message. */
  256. printf("Error in checking of _fx_partition_offset_calculate!\n");
  257. test_control_return(1);
  258. }
  259. /* Restore buffer */
  260. partition_sector[510] = 0x55;
  261. /* BRANCH COVERAGE TESTS START */
  262. /* Induce error in buffer */
  263. partition_sector[511] = 0xFF;
  264. status = _fx_partition_offset_calculate(partition_sector, 0, &partition_start, &partition_size);
  265. /* Check for the error. */
  266. if (status != FX_NOT_FOUND)
  267. {
  268. /* Print error message. */
  269. printf("Error in checking of _fx_partition_offset_calculate!\n");
  270. test_control_return(2);
  271. }
  272. /* Restore buffer */
  273. partition_sector[511] = 0xAA;
  274. partition_sector_value = partition_sector[0];
  275. /* Induce error in buffer */
  276. partition_sector[0] = 0xFF;
  277. status = _fx_partition_offset_calculate(partition_sector, 100, &partition_start, &partition_size);
  278. /* Check for the error. */
  279. if (status != FX_NOT_FOUND)
  280. {
  281. /* Print error message. */
  282. printf("Error in checking of _fx_partition_offset_calculate! %d\n",status);
  283. test_control_return(3);
  284. }
  285. /* Restore buffer */
  286. partition_sector[0] = partition_sector_value;
  287. partition_sector_value = partition_sector[2];
  288. /* Induce error in buffer */
  289. partition_sector[2] = 0xFF;
  290. status = _fx_partition_offset_calculate(partition_sector, 100, &partition_start, &partition_size);
  291. /* Check for the error. */
  292. if (status != FX_NOT_FOUND)
  293. {
  294. /* Print error message. */
  295. printf("Error in checking of _fx_partition_offset_calculate! %d\n",status);
  296. test_control_return(4);
  297. }
  298. /* Restore buffer */
  299. partition_sector[2] = partition_sector_value;
  300. partition_sector_value = partition_sector[0];
  301. /* Induce error in buffer */
  302. partition_sector[0] = 0xe9;
  303. status = _fx_partition_offset_calculate(partition_sector, 0, &partition_start, &partition_size);
  304. /* Check for the error. */
  305. if (status != FX_SUCCESS)
  306. {
  307. /* Print error message. */
  308. printf("Error in checking of _fx_partition_offset_calculate! %d\n",status);
  309. test_control_return(5);
  310. }
  311. /* Restore buffer */
  312. partition_sector[0] = partition_sector_value;
  313. partition_sector_value = partition_sector[0];
  314. /* Induce error in buffer */
  315. partition_sector[0] = 0xeb;
  316. status = _fx_partition_offset_calculate(partition_sector, 100, &partition_start, &partition_size);
  317. /* Check for the error. */
  318. if (status != FX_NOT_FOUND)
  319. {
  320. /* Print error message. */
  321. printf("Error in checking of _fx_partition_offset_calculate! %d\n",status);
  322. test_control_return(5);
  323. }
  324. /* Restore buffer */
  325. partition_sector[0] = partition_sector_value;
  326. partition_sector_value = partition_sector[0];
  327. temp = partition_sector[2];
  328. /* Induce error in buffer */
  329. partition_sector[0] = 0xeb;
  330. partition_sector[2] = 0x90;
  331. status = _fx_partition_offset_calculate(partition_sector, 0, &partition_start, &partition_size);
  332. /* Check for the error. */
  333. if (status != FX_SUCCESS)
  334. {
  335. /* Print error message. */
  336. printf("Error in checking of _fx_partition_offset_calculate! %d\n",status);
  337. test_control_return(6);
  338. }
  339. /* Restore buffer */
  340. partition_sector[0] = partition_sector_value;
  341. partition_sector[2] = temp;
  342. partition_sector_value = partition_sector[0];
  343. temp = partition_sector[2];
  344. /* Induce error in buffer */
  345. partition_sector[0] = 0xe9;
  346. partition_sector[2] = 0x90;
  347. status = _fx_partition_offset_calculate(partition_sector, 0, &partition_start, &partition_size);
  348. /* Check for the error. */
  349. if (status != FX_SUCCESS)
  350. {
  351. /* Print error message. */
  352. printf("Error in checking of _fx_partition_offset_calculate! %d\n",status);
  353. test_control_return(6);
  354. }
  355. /* Restore buffer */
  356. partition_sector[0] = partition_sector_value;
  357. partition_sector[2] = temp;
  358. /* Test to check the partition_sector values, if there are good values for sectors per FAT.
  359. We want the test code to return FX_NOT_FOUND after _fx_utility_partition_get() is called */
  360. /* Set real boot sector check to true */
  361. temp6 = partition_sector[0];
  362. partition_sector[0] = 0xe9;
  363. temp = partition_sector[0x16];
  364. temp1 = partition_sector[0x17];
  365. temp2 = partition_sector[0x24];
  366. temp3 = partition_sector[0x25];
  367. temp4 = partition_sector[0x26];
  368. temp5 = partition_sector[0x27];
  369. /* Induce error in buffer */
  370. partition_sector[0x16] = 0;
  371. partition_sector[0x17] = 0;
  372. partition_sector[0x24] = 0;
  373. partition_sector[0x25] = 0;
  374. partition_sector[0x26] = 0;
  375. partition_sector[0x27] = 0;
  376. status = _fx_partition_offset_calculate(partition_sector, 100, &partition_start, &partition_size);
  377. /* Check for the error. */
  378. if (status != FX_NOT_FOUND)
  379. {
  380. /* Print error message. */
  381. printf("Error in checking of _fx_partition_offset_calculate! %d\n",status);
  382. test_control_return(7);
  383. }
  384. /* Restore buffer */
  385. partition_sector[0x16] = temp;
  386. partition_sector[0x17] = temp1;
  387. partition_sector[0x24] = temp2;
  388. partition_sector[0x25] = temp3;
  389. partition_sector[0x26] = temp4;
  390. partition_sector[0x27] = temp5;
  391. /* Induce error in buffer */
  392. partition_sector[0x17] = 0;
  393. partition_sector[0x24] = 0;
  394. partition_sector[0x25] = 0;
  395. partition_sector[0x26] = 0;
  396. partition_sector[0x27] = 0;
  397. status = _fx_partition_offset_calculate(partition_sector, 0, &partition_start, &partition_size);
  398. /* Check for the error. */
  399. if (status != FX_SUCCESS)
  400. {
  401. /* Print error message. */
  402. printf("Error in checking of _fx_partition_offset_calculate! %d\n",status);
  403. test_control_return(8);
  404. }
  405. /* Restore buffer */
  406. partition_sector[0x17] = temp1;
  407. partition_sector[0x24] = temp2;
  408. partition_sector[0x25] = temp3;
  409. partition_sector[0x26] = temp4;
  410. partition_sector[0x27] = temp5;
  411. /* Induce error in buffer */
  412. partition_sector[0x16] = 0;
  413. partition_sector[0x24] = 0;
  414. partition_sector[0x25] = 0;
  415. partition_sector[0x26] = 0;
  416. partition_sector[0x27] = 0;
  417. status = _fx_partition_offset_calculate(partition_sector, 0, &partition_start, &partition_size);
  418. /* Check for the error. */
  419. if (status != FX_SUCCESS)
  420. {
  421. /* Print error message. */
  422. printf("Error in checking of _fx_partition_offset_calculate! %d\n",status);
  423. test_control_return(9);
  424. }
  425. /* Restore buffer */
  426. partition_sector[0x16] = temp;
  427. partition_sector[0x24] = temp2;
  428. partition_sector[0x25] = temp3;
  429. partition_sector[0x26] = temp4;
  430. partition_sector[0x27] = temp5;
  431. /* Induce error in buffer */
  432. partition_sector[0x16] = 0;
  433. partition_sector[0x17] = 0;
  434. partition_sector[0x25] = 0;
  435. partition_sector[0x26] = 0;
  436. partition_sector[0x27] = 0;
  437. status = _fx_partition_offset_calculate(partition_sector, 0, &partition_start, &partition_size);
  438. /* Check for the error. */
  439. if (status != FX_SUCCESS)
  440. {
  441. /* Print error message. */
  442. printf("Error in checking of _fx_partition_offset_calculate! %d\n",status);
  443. test_control_return(10);
  444. }
  445. /* Restore buffer */
  446. partition_sector[0x16] = temp;
  447. partition_sector[0x17] = temp1;
  448. partition_sector[0x25] = temp3;
  449. partition_sector[0x26] = temp4;
  450. partition_sector[0x27] = temp5;
  451. /* Induce error in buffer */
  452. partition_sector[0x16] = 0;
  453. partition_sector[0x17] = 0;
  454. partition_sector[0x24] = 0;
  455. partition_sector[0x26] = 0;
  456. partition_sector[0x27] = 0;
  457. status = _fx_partition_offset_calculate(partition_sector, 0, &partition_start, &partition_size);
  458. /* Check for the error. */
  459. if (status != FX_SUCCESS)
  460. {
  461. /* Print error message. */
  462. printf("Error in checking of _fx_partition_offset_calculate! %d\n",status);
  463. test_control_return(11);
  464. }
  465. /* Restore buffer */
  466. partition_sector[0x16] = temp;
  467. partition_sector[0x17] = temp1;
  468. partition_sector[0x24] = temp2;
  469. partition_sector[0x26] = temp4;
  470. partition_sector[0x27] = temp5;
  471. /* Induce error in buffer */
  472. partition_sector[0x16] = 0;
  473. partition_sector[0x17] = 0;
  474. partition_sector[0x24] = 0;
  475. partition_sector[0x25] = 0;
  476. partition_sector[0x27] = 0;
  477. status = _fx_partition_offset_calculate(partition_sector, 0, &partition_start, &partition_size);
  478. /* Check for the error. */
  479. if (status != FX_SUCCESS)
  480. {
  481. /* Print error message. */
  482. printf("Error in checking of _fx_partition_offset_calculate! %d\n",status);
  483. test_control_return(12);
  484. }
  485. /* Restore buffer */
  486. partition_sector[0x16] = temp;
  487. partition_sector[0x17] = temp1;
  488. partition_sector[0x24] = temp2;
  489. partition_sector[0x25] = temp3;
  490. partition_sector[0x27] = temp5;
  491. /* Induce error in buffer */
  492. partition_sector[0x16] = 0;
  493. partition_sector[0x17] = 0;
  494. partition_sector[0x24] = 0;
  495. partition_sector[0x25] = 0;
  496. partition_sector[0x26] = 0;
  497. status = _fx_partition_offset_calculate(partition_sector, 0, &partition_start, &partition_size);
  498. /* Check for the error. */
  499. if (status != FX_SUCCESS)
  500. {
  501. /* Print error message. */
  502. printf("Error in checking of _fx_partition_offset_calculate! %d\n",status);
  503. test_control_return(13);
  504. }
  505. /* Restore buffer */
  506. partition_sector[0x16] = temp;
  507. partition_sector[0x17] = temp1;
  508. partition_sector[0x24] = temp2;
  509. partition_sector[0x25] = temp3;
  510. partition_sector[0x26] = temp4;
  511. temp = partition_sector[0x20];
  512. temp1 = partition_sector[0x21];
  513. temp2 = partition_sector[0x22];
  514. temp3 = partition_sector[0x23];
  515. /* Set calculatation of the total sectors based of FAT32 */
  516. temp4 = partition_sector[0x13];
  517. temp5 = partition_sector[0x14];
  518. partition_sector[0x13] = 0;
  519. partition_sector[0x14] = 0;
  520. /* Induce error in buffer */
  521. partition_sector[0x20] = 0;
  522. partition_sector[0x21] = 0;
  523. partition_sector[0x22] = 0;
  524. partition_sector[0x23] = 0;
  525. status = _fx_partition_offset_calculate(partition_sector, 100, &partition_start, &partition_size);
  526. /* Check for the error. */
  527. if (status != FX_NOT_FOUND)
  528. {
  529. /* Print error message. */
  530. printf("Error in checking of _fx_partition_offset_calculate! %d\n",status);
  531. test_control_return(14);
  532. }
  533. /* Restore buffer */
  534. partition_sector[0x20] = temp;
  535. partition_sector[0x21] = temp1;
  536. partition_sector[0x22] = temp2;
  537. partition_sector[0x23] = temp3;
  538. /* Induce error in buffer */
  539. partition_sector[0x21] = 0;
  540. partition_sector[0x22] = 0;
  541. partition_sector[0x23] = 0;
  542. status = _fx_partition_offset_calculate(partition_sector, 0, &partition_start, &partition_size);
  543. /* Check for the error. */
  544. if (status != FX_SUCCESS)
  545. {
  546. /* Print error message. */
  547. printf("Error in checking of _fx_partition_offset_calculate! %d\n",status);
  548. test_control_return(15);
  549. }
  550. /* Restore buffer */
  551. partition_sector[0x21] = temp1;
  552. partition_sector[0x22] = temp2;
  553. partition_sector[0x23] = temp3;
  554. /* Induce error in buffer */
  555. partition_sector[0x20] = 0;
  556. partition_sector[0x22] = 0;
  557. partition_sector[0x23] = 0;
  558. status = _fx_partition_offset_calculate(partition_sector, 0, &partition_start, &partition_size);
  559. /* Check for the error. */
  560. if (status != FX_SUCCESS)
  561. {
  562. /* Print error message. */
  563. printf("Error in checking of _fx_partition_offset_calculate! %d\n",status);
  564. test_control_return(16);
  565. }
  566. /* Restore buffer */
  567. partition_sector[0x20] = temp;
  568. partition_sector[0x22] = temp2;
  569. partition_sector[0x23] = temp3;
  570. /* Induce error in buffer */
  571. partition_sector[0x20] = 0;
  572. partition_sector[0x21] = 0;
  573. partition_sector[0x23] = 0;
  574. status = _fx_partition_offset_calculate(partition_sector, 0, &partition_start, &partition_size);
  575. /* Check for the error. */
  576. if (status != FX_SUCCESS)
  577. {
  578. /* Print error message. */
  579. printf("Error in checking of _fx_partition_offset_calculate! %d\n",status);
  580. test_control_return(17);
  581. }
  582. /* Restore buffer */
  583. partition_sector[0x20] = temp;
  584. partition_sector[0x21] = temp1;
  585. partition_sector[0x23] = temp3;
  586. /* Induce error in buffer */
  587. partition_sector[0x20] = 0;
  588. partition_sector[0x21] = 0;
  589. partition_sector[0x22] = 0;
  590. status = _fx_partition_offset_calculate(partition_sector, 0, &partition_start, &partition_size);
  591. /* Check for the error. */
  592. if (status != FX_SUCCESS)
  593. {
  594. /* Print error message. */
  595. printf("Error in checking of _fx_partition_offset_calculate! %d\n",status);
  596. test_control_return(18);
  597. }
  598. /* Check for partition_start and partition_size to be NULL */
  599. status = _fx_partition_offset_calculate(partition_sector, 0, FX_NULL, FX_NULL);
  600. /* Check for the error. */
  601. if (status != FX_SUCCESS)
  602. {
  603. /* Print error message. */
  604. printf("Error in checking of _fx_partition_offset_calculate! %d\n",status);
  605. test_control_return(19);
  606. }
  607. /* Restore buffer */
  608. partition_sector[0x20] = temp;
  609. partition_sector[0x21] = temp1;
  610. partition_sector[0x22] = temp2;
  611. /* Restore real boot sector and the total sector check to default */
  612. partition_sector[0] = temp6;
  613. partition_sector[0x13] = temp4;
  614. partition_sector[0x14] = temp5;
  615. /* Check for partition_start and partition_size to be NULL to cover line 236 and 242 */
  616. status = _fx_partition_offset_calculate(partition_sector, 0, FX_NULL, FX_NULL);
  617. /* Check for the error. */
  618. if (status != FX_SUCCESS)
  619. {
  620. /* Print error message. */
  621. printf("Error in checking of _fx_partition_offset_calculate! %d\n",status);
  622. test_control_return(20);
  623. }
  624. /* BRANCH COVERAGE TESTS END */
  625. /* Invoke _fx_utility_memory_set and _fx_utility_string_length_get. */
  626. _fx_utility_memory_set((UCHAR*)buffer, 0, 0);
  627. _fx_utility_memory_set((UCHAR*)buffer, 0, sizeof(buffer));
  628. size = _fx_utility_string_length_get(buffer, sizeof(buffer));
  629. return_if_fail(size == 0);
  630. buffer[0] = 'a';
  631. size = _fx_utility_string_length_get(buffer, sizeof(buffer));
  632. return_if_fail(size == 1);
  633. _fx_utility_memory_set((UCHAR*)buffer, 'a', sizeof(buffer));
  634. size = _fx_utility_string_length_get(buffer, sizeof(buffer));
  635. return_if_fail(size == sizeof(buffer));
  636. _fx_utility_memory_set((UCHAR*)buffer, 'a', sizeof(buffer));
  637. size = _fx_utility_string_length_get(buffer, 1);
  638. return_if_fail(size == 1);
  639. /* Tests for utility_64_unsigned_read, utility_64_unsigned_write and utility_FAT_sector_get. */
  640. _fx_utility_64_unsigned_write((UCHAR*)buffer, 0x0001);
  641. value = _fx_utility_64_unsigned_read((UCHAR*)buffer);
  642. return_if_fail(0x0001 == value);
  643. /* Tests for utility_FAT_sector_get. */
  644. tmp_media.fx_media_bytes_per_sector = 512;
  645. tmp_media.fx_media_reserved_sectors = 0;
  646. /* 12-bit FAT. */
  647. tmp_media.fx_media_12_bit_FAT = 1;
  648. /* The FAT entry of cluster 400 is located at the second sector. */
  649. FAT_sector = _fx_utility_FAT_sector_get(&tmp_media, 400);
  650. return_if_fail(1 == FAT_sector);
  651. /* 16-bit FAT. */
  652. tmp_media.fx_media_12_bit_FAT = 0;
  653. tmp_media.fx_media_32_bit_FAT = 0;
  654. /* The FAT entry of cluster 400 is located at the second sector. */
  655. FAT_sector = _fx_utility_FAT_sector_get(&tmp_media, 400);
  656. return_if_fail(1 == FAT_sector);
  657. /* 32-bit FAT. */
  658. tmp_media.fx_media_12_bit_FAT = 0;
  659. tmp_media.fx_media_32_bit_FAT = 1;
  660. /* The FAT entry of cluster 400 is located at the fourth sector. */
  661. FAT_sector = _fx_utility_FAT_sector_get(&tmp_media, 400);
  662. return_if_fail(3 == FAT_sector);
  663. no_partition_test();
  664. printf("SUCCESS!\n");
  665. test_control_return(0);
  666. }