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