1 /* This test is designed to test simple memory byte pool creation, deletion, and
2    allocates and releases.  */
3 
4 #include   <stdio.h>
5 #include   "tx_api.h"
6 
7 typedef struct BYTE_MEMORY_TEST_STRUCT
8 {
9     ULONG           first;
10     ULONG           second;
11     TX_BYTE_POOL    pool;
12     ULONG           first_middle;
13     ULONG           second_middle;
14     ULONG           pool_area[2048/sizeof(ULONG)];
15     ULONG           next_to_last;
16     ULONG           last;
17 
18 } BYTE_MEMORY_TEST;
19 
20 static  BYTE_MEMORY_TEST   byte_memory;
21 
22 
23 /* Define external reference to byte pool creation status.  */
24 
25 extern UINT            test_byte_pool_create_init;
26 
27 
28 
29 /* Define the ISR dispatch.  */
30 
31 extern VOID    (*test_isr_dispatch)(void);
32 
33 UINT        _txe_byte_pool_create(TX_BYTE_POOL *pool_ptr, CHAR *name_ptr, VOID *pool_start,
34                     ULONG pool_size, UINT pool_control_block_size);
35 
36 
37 static unsigned long   thread_0_counter =  0;
38 static TX_THREAD       thread_0;
39 
40 
41 static TX_BYTE_POOL   pool_0;
42 static TX_BYTE_POOL   pool_1;
43 static TX_BYTE_POOL   pool_2;
44 static TX_BYTE_POOL   pool_3;
45 
46 static TX_BYTE_POOL   pool_4;
47 static UCHAR          *search_ptr_1;
48 static UCHAR          *block_0;
49 static UCHAR          *block_1;
50 static UCHAR          *block_2;
51 static UCHAR          *block_3;
52 static UCHAR          *block_4;
53 static CHAR           *pool_4_memory;
54 static TX_TIMER        timer_0;
55 
56 
57 static unsigned long error =  0;
58 static unsigned long timer_executed =  0;
59 static unsigned long isr_executed =  0;
60 
61 
62 /* Define thread prototypes.  */
63 
64 static void    thread_0_entry(ULONG thread_input);
65 UINT            _tx_byte_release(VOID *memory_ptr);
66 
67 
68 /* Prototype for test control return.  */
69 
70 void  test_control_return(UINT status);
71 
72 
73 /* Define the timer for this test.  */
74 
timer_entry(ULONG i)75 static void    timer_entry(ULONG i)
76 {
77 
78 #ifndef TX_DISABLE_ERROR_CHECKING
79 
80 UINT    status;
81 CHAR    *pointer;
82 
83 
84     /* Determine if calling byte pool create from initialization was successful.  */
85     if (test_byte_pool_create_init != TX_SUCCESS)
86     {
87 
88         /* Error!  */
89         error++;
90     }
91 
92     /* Attempt to create a byte pool from a timer.  */
93     pointer =  (CHAR *) 0x30000;
94     status =  tx_byte_pool_create(&pool_2, "pool 2", pointer, 108);
95 
96         /* Check status.  */
97     if (status != TX_CALLER_ERROR)
98     {
99 
100         /* Error!  */
101         error++;
102     }
103 
104     /* Attempt to create a byte pool with an invalid size.  */
105     status =  _txe_byte_pool_create(&pool_3, "pool 3", pointer,
106                     108, (sizeof(TX_BYTE_POOL)+1));
107 
108        /* Check status.  */
109     if (status != TX_POOL_ERROR)
110     {
111 
112         /* Error!  */
113         error++;
114     }
115 
116     /* Allocate memory from the pool.  */
117     status = tx_byte_allocate(&pool_0, (VOID **) &pointer, 24, TX_NO_WAIT);
118 
119     /* Check status.  */
120     if (status != TX_CALLER_ERROR)
121     {
122 
123         /* Error!  */
124         error++;
125     }
126 
127     /* Try to delete a byte pool from a timer.  */
128     status =  tx_byte_pool_delete(&pool_0);
129 
130     /* Check status.  */
131     if (status != TX_CALLER_ERROR)
132     {
133 
134         /* Error!  */
135         error++;
136     }
137 
138     /* Attempt to release byte memory from timer.  */
139     pointer = (CHAR *) 0x30000;
140     status =  tx_byte_release(pointer);
141 
142     /* Check for error status!  */
143     if (status != TX_CALLER_ERROR)
144     {
145 
146         /* Error!  */
147         error++;
148     }
149 
150     timer_executed =  1;
151 #endif
152 }
153 
154 /* Define the ISR dispatch routine.  */
155 
test_isr(void)156 static void    test_isr(void)
157 {
158 
159 #ifndef TX_DISABLE_ERROR_CHECKING
160 
161 CHAR    *pointer;
162 UINT    status;
163 
164 
165     /* Allocate memory from the pool.  */
166     status = tx_byte_allocate(&pool_0, (VOID **) &pointer, 24, 100);
167 
168     /* Check status.  */
169     if (status != TX_WAIT_ERROR)
170     {
171 
172         /* Error!  */
173         error++;
174     }
175 
176     /* Allocate memory from the pool.  */
177     status = tx_byte_allocate(&pool_0, (VOID **) &pointer, 24, TX_NO_WAIT);
178 
179     /* Check status.  */
180     if (status != TX_CALLER_ERROR)
181     {
182 
183         /* Error!  */
184         error++;
185     }
186 
187 
188     /* Attempt to create a byte pool from an ISR.  */
189     status =  tx_byte_pool_create(&pool_2, "pool 0", (void *) 0x100000, 108);
190 
191     /* Check status.  */
192     if (status != TX_CALLER_ERROR)
193     {
194 
195         /* Error!  */
196         error++;
197     }
198 
199     /* Attempt to deleate a pool from an ISR.  */
200     status =  tx_byte_pool_delete(&pool_0);
201 
202     if (status != TX_CALLER_ERROR)
203     {
204 
205         /* Error!  */
206         error++;
207     }
208 
209     /* Attempt to release byte memory from ISR.  */
210     pointer = (CHAR *) 0x30000;
211     status =  tx_byte_release(pointer);
212 
213     /* Check for error status!  */
214     if (status != TX_CALLER_ERROR)
215     {
216 
217         /* Error!  */
218         error++;
219     }
220 
221     isr_executed =  1;
222 #endif
223 }
224 
225 
226 /* Define what the initial system looks like.  */
227 
228 #ifdef CTEST
test_application_define(void * first_unused_memory)229 void test_application_define(void *first_unused_memory)
230 #else
231 void    threadx_byte_memory_basic_application_define(void *first_unused_memory)
232 #endif
233 {
234 
235 UINT    status;
236 CHAR    *pointer;
237 
238 
239     /* Put first available memory address into a character pointer.  */
240     pointer =  (CHAR *) first_unused_memory;
241 
242     /* Put system definition stuff in here, e.g. thread creates and other assorted
243        create information.  */
244 
245     status =  tx_thread_create(&thread_0, "thread 0", thread_0_entry, 1,
246             pointer, TEST_STACK_SIZE_PRINTF,
247             17, 17, 100, TX_AUTO_START);
248     pointer = pointer + TEST_STACK_SIZE_PRINTF;
249 
250     /* Check status.  */
251     if (status != TX_SUCCESS)
252     {
253 
254         printf("Running Byte Memory Basic Test...................................... ERROR #1\n");
255         test_control_return(1);
256     }
257 
258     /* Create byte pools 0 and 1.  */
259     status =  tx_byte_pool_create(&pool_0, "pool 0", pointer, 108);
260     pointer = pointer + 108;
261 
262     /* Check status.  */
263     if (status != TX_SUCCESS)
264     {
265 
266         printf("Running Byte Memory Basic Test...................................... ERROR #2\n");
267         test_control_return(1);
268     }
269 
270     status =  tx_byte_pool_create(&pool_1, "pool 1", pointer, 200);
271     pointer = pointer + 200;
272 
273     /* Check status.  */
274     if (status != TX_SUCCESS)
275     {
276 
277         printf("Running Byte Memory Basic Test...................................... ERROR #3\n");
278         test_control_return(1);
279     }
280 
281     /* Test for search pointer issue on wrapped seach with prior block to search pointer merged.  */
282     status =  tx_byte_pool_create(&pool_4, "pool 4", pointer, 300);
283     pool_4_memory =  pointer;
284     pointer = pointer + 300;
285 
286     /* Check status.  */
287     if (status != TX_SUCCESS)
288     {
289 
290         printf("Running Byte Memory Basic Test...................................... ERROR #3a\n");
291         test_control_return(1);
292     }
293 
294     /* Allocate first block.  */
295     status +=  tx_byte_allocate(&pool_4, (VOID **) &block_0, 80, TX_NO_WAIT);
296 
297     /* Save next search pointer.  */
298     search_ptr_1 =  pool_4.tx_byte_pool_search;
299 
300     /* Clear the allocatged memory.  */
301     TX_MEMSET(block_0, 0, 80);
302 
303     /* Allocate another block.  */
304     status +=  tx_byte_allocate(&pool_4, (VOID **) &block_1, 80, TX_NO_WAIT);
305 
306     /* Clear the allocated block.  */
307     TX_MEMSET(block_1, 0, 80);
308 
309     /* Allocate the third and final block.  */
310     status +=  tx_byte_allocate(&pool_4, (VOID **) &block_2, 80, TX_NO_WAIT);
311 
312     /* Clear the allocated block.  */
313     TX_MEMSET(block_2, 0, 80);
314 
315     /* Release the first block.  */
316     status +=  tx_byte_release(block_0);
317 
318     /* Release the second block.  */
319     status +=  tx_byte_release(block_1);
320 
321     /* Manually move the search pointer to create the case where the search wraps and a merge happens on the search pointer
322        necessitating its update.  */
323     pool_4.tx_byte_pool_search  = search_ptr_1;         /* Point to the middle block.  */
324 
325     /* Allocate a larger block that will wrap the search and require moving as well as an update of the search pointer.  */
326     status +=  tx_byte_allocate(&pool_4, (VOID **) &block_3, 120, TX_NO_WAIT);
327 
328     /* Clear the newly allocated block.  */
329     TX_MEMSET(block_3, 0, 120);
330 
331     /* At this point, verify the search pointer was properly updated in the previous allocation.  */
332     status +=  tx_byte_allocate(&pool_4, (VOID **) &block_4, 40, TX_NO_WAIT);   /* Should fail since search pointer is now invalid!  */
333 
334     /* Check status.  */
335     if (status != TX_SUCCESS)
336     {
337 
338         printf("Running Byte Memory Basic Test...................................... ERROR #3b\n");
339         test_control_return(1);
340     }
341 }
342 
343 
344 
345 /* Define the test threads.  */
346 
thread_0_entry(ULONG thread_input)347 static void    thread_0_entry(ULONG thread_input)
348 {
349 
350 UINT    status;
351 CHAR    *pointer_1;
352 CHAR    *pointer_2;
353 CHAR    *pointer_3;
354 CHAR    *pointer_4;
355 INT     i;
356 ULONG   array[20];
357 UCHAR   *save_search;
358 
359 
360     /* Inform user.  */
361     printf("Running Byte Memory Basic Test...................................... ");
362 
363     /* Perform byte memory test.  */
364     byte_memory.first =        0x11223344;
365     byte_memory.second =       0x55667788;
366     byte_memory.first_middle = 0x21314151;
367     byte_memory.second_middle= 0x61718191;
368     byte_memory.next_to_last = 0x99aabbcc;
369     byte_memory.last =         0xddeeff00;
370 
371     /* Create the byte pool.  */
372     status =  tx_byte_pool_create(&byte_memory.pool, "pool memory", &byte_memory.pool_area[0], (2048*sizeof(ULONG))/sizeof(ULONG));
373     tx_byte_pool_delete(&byte_memory.pool);
374 
375     /* Check for status.  */
376     if ((status != TX_SUCCESS) ||
377         (byte_memory.first != 0x11223344) ||
378         (byte_memory.second != 0x55667788) ||
379         (byte_memory.first_middle != 0x21314151) ||
380         (byte_memory.second_middle != 0x61718191) ||
381         (byte_memory.next_to_last != 0x99aabbcc) ||
382         (byte_memory.last != 0xddeeff00))
383     {
384 
385         /* Byte memory error.  */
386         printf("ERROR #4\n");
387         test_control_return(1);
388     }
389 
390     /* Increment the run counter.  */
391     thread_0_counter++;
392 
393 #ifndef TX_DISABLE_ERROR_CHECKING
394 
395     /* Try to create a NULL pool.  */
396     pointer_1 = (CHAR *) 0x30000;
397     status =  tx_byte_pool_create(TX_NULL, "pool 0", pointer_1, 108);
398 
399     /* Check status.  */
400     if (status != TX_POOL_ERROR)
401     {
402 
403         /* Byte memory error.  */
404         printf("ERROR #5\n");
405         test_control_return(1);
406     }
407 
408     /* Try to create the same pool.  */
409     status =  tx_byte_pool_create(&pool_0, "pool 0", pointer_1, 108);
410 
411     /* Check status.  */
412     if (status != TX_POOL_ERROR)
413     {
414 
415         /* Byte memory error.  */
416         printf("ERROR #6\n");
417         test_control_return(1);
418     }
419 
420     /* Try to create a pool with a NULL start address.  */
421     status =  tx_byte_pool_create(&pool_2, "pool 2", TX_NULL, 108);
422 
423     /* Check status.  */
424     if (status != TX_PTR_ERROR)
425     {
426 
427         /* Byte memory error.  */
428         printf("ERROR #7\n");
429         test_control_return(1);
430     }
431 
432     /* Try to create a pool with a a bad size.  */
433     status =  tx_byte_pool_create(&pool_2, "pool 2", pointer_1, 1);
434 
435     /* Check status.  */
436     if (status != TX_SIZE_ERROR)
437     {
438 
439         /* Byte memory error.  */
440         printf("ERROR #8\n");
441         test_control_return(1);
442     }
443 
444     /* Try to delete a byte pool with a NULL pointer.  */
445     status =  tx_byte_pool_delete(TX_NULL);
446 
447     /* Check status.  */
448     if (status != TX_POOL_ERROR)
449     {
450 
451         /* Byte memory error.  */
452         printf("ERROR #9\n");
453         test_control_return(1);
454     }
455 
456     /* Try to delete a byte pool that hasn't been created.  */
457     pool_2.tx_byte_pool_id =  0;
458     status =  tx_byte_pool_delete(&pool_2);
459 
460     /* Check status.  */
461     if (status != TX_POOL_ERROR)
462     {
463 
464         /* Byte memory error.  */
465         printf("ERROR #10\n");
466         test_control_return(1);
467     }
468 
469     /* Test NULL pool pointer.  */
470     status = tx_byte_allocate(TX_NULL, (VOID **) &pointer_1, 24, TX_NO_WAIT);
471 
472     /* Check status.  */
473     if (status != TX_POOL_ERROR)
474     {
475 
476         /* Byte memory error.  */
477         printf("ERROR #11\n");
478         test_control_return(1);
479     }
480 
481     /* Test non-created pool pointer.  */
482     pool_2.tx_byte_pool_id =  0;
483     status = tx_byte_allocate(&pool_2, (VOID **) &pointer_1, 24, TX_NO_WAIT);
484 
485     /* Check status.  */
486     if (status != TX_POOL_ERROR)
487     {
488 
489         /* Byte memory error.  */
490         printf("ERROR #12\n");
491         test_control_return(1);
492     }
493 
494     /* Test NULL memory pointer.  */
495     status = tx_byte_allocate(&pool_0, (VOID **) TX_NULL, 24, TX_NO_WAIT);
496 
497     /* Check status.  */
498     if (status != TX_PTR_ERROR)
499     {
500 
501         /* Byte memory error.  */
502         printf("ERROR #13\n");
503         test_control_return(1);
504     }
505 
506     /* Test extreme size.  */
507     status = tx_byte_allocate(&pool_0, (VOID **) &pointer_1, 240000, TX_NO_WAIT);
508 
509     /* Check status.  */
510     if (status != TX_SIZE_ERROR)
511     {
512 
513         /* Byte memory error.  */
514         printf("ERROR #14\n");
515         test_control_return(1);
516     }
517 
518     /* Test size of 0.  */
519     status = tx_byte_allocate(&pool_0, (VOID **) &pointer_1, 0, TX_NO_WAIT);
520 
521     /* Check status.  */
522     if (status != TX_SIZE_ERROR)
523     {
524 
525         /* Byte memory error.  */
526         printf("ERROR #15\n");
527         test_control_return(1);
528     }
529 #endif
530 
531     /* Test NULL pointer release.  */
532     status =  tx_byte_release(TX_NULL);
533 
534     /* Check for error status!  */
535     if (status != TX_PTR_ERROR)
536     {
537 
538         /* Byte memory error.  */
539         printf("ERROR #16\n");
540         test_control_return(1);
541     }
542 
543     /* Allocate memory from the pool.  */
544     status = tx_byte_allocate(&pool_0, (VOID **) &pointer_1, 24, TX_NO_WAIT);
545 
546     /* Check status.  */
547     if (status != TX_SUCCESS)
548     {
549 
550         /* Byte memory error.  */
551         printf("ERROR #17\n");
552         test_control_return(1);
553     }
554 
555     /* Allocate memory from the pool.  */
556     status = tx_byte_allocate(&pool_0, (VOID **) &pointer_2, 24, TX_NO_WAIT);
557 
558     /* Check status.  */
559     if (status != TX_SUCCESS)
560     {
561 
562         /* Byte memory error.  */
563         printf("ERROR #18\n");
564         test_control_return(1);
565     }
566 
567     /* Allocate memory from the pool.  */
568     status = tx_byte_allocate(&pool_0, (VOID **) &pointer_3, 24, TX_NO_WAIT);
569 
570     /* Check status.  */
571     if (status != TX_SUCCESS)
572     {
573 
574         /* Byte memory error.  */
575         printf("ERROR #19\n");
576         test_control_return(1);
577     }
578 
579     /* Attempt to allocate fourth area from the pool.  This should fail because
580        there should be not enough bytes in the pool.  */
581     status = tx_byte_allocate(&pool_0, (VOID **) &pointer_4, 24, TX_NO_WAIT);
582 
583     /* Check status.  */
584     if (status != TX_NO_MEMORY)
585     {
586 
587         /* Byte memory error.  */
588         printf("ERROR #20\n");
589         test_control_return(1);
590     }
591 
592     /* Set the memory of all of the allocated memory.  */
593     for (i =0; i < 24; i++)
594     {
595         pointer_1[i] = (CHAR) 0xFF;
596         pointer_2[i] = (CHAR) 0xFF;
597         pointer_3[i] = (CHAR) 0xFF;
598     }
599 
600     /* Test the byte release with a bad block pointer.  */
601     status =  _tx_byte_release(TX_NULL);
602 
603     /* Check for error status!  */
604     if (status != TX_PTR_ERROR)
605     {
606 
607         /* Byte memory error.  */
608         printf("ERROR #21\n");
609         test_control_return(1);
610     }
611 
612     /* Test another bad block release... no pool pointer!  */
613     array[0] =  0;
614     array[1] =  0;
615     array[2] =  0;
616     status =  _tx_byte_release(&array[2]);
617 
618     /* Check for error status!  */
619     if (status != TX_PTR_ERROR)
620     {
621 
622         /* Byte memory error.  */
623         printf("ERROR #22\n");
624         test_control_return(1);
625     }
626 
627     /* Test another bad block release.... pool pointer is not a valid pool!  */
628     array[0] =  0;
629     array[1] =  (ULONG) &array[3];
630     array[2] =  0;
631     array[3] =  0;
632     status =  _tx_byte_release(&array[2]);
633 
634     /* Check for error status!  */
635     if (status != TX_PTR_ERROR)
636     {
637 
638         /* Byte memory error.  */
639         printf("ERROR #22\n");
640         test_control_return(1);
641     }
642 
643     /* Now release each of the blocks. */
644     status =  tx_byte_release(pointer_1);
645 
646     /* Check for status.  */
647     if (status != TX_SUCCESS)
648     {
649 
650         /* Byte memory error.  */
651         printf("ERROR #23\n");
652         test_control_return(1);
653     }
654 
655     /* Now release the same block again. */
656     status =  tx_byte_release(pointer_1);
657 
658     /* Check for status.  */
659     if (status != TX_PTR_ERROR)
660     {
661 
662         /* Byte memory error.  */
663         printf("ERROR #24\n");
664         test_control_return(1);
665     }
666 
667     /* Release the second memory area.  */
668     status =  tx_byte_release(pointer_2);
669 
670     /* Check for status.  */
671     if (status != TX_SUCCESS)
672     {
673 
674         /* Byte memory error.  */
675         printf("ERROR #25\n");
676         test_control_return(1);
677     }
678 
679     /* Release the third memory area.  */
680     status =  tx_byte_release(pointer_3);
681 
682     /* Check for status.  */
683     if (status != TX_SUCCESS)
684     {
685 
686         /* Byte memory error.  */
687         printf("ERROR #26\n");
688         test_control_return(1);
689     }
690 
691     /* Allocate each block again to make sure everything still
692        works.  */
693 
694     /* Allocate memory from the pool.  */
695     status = tx_byte_allocate(&pool_0, (VOID **) &pointer_1, 24, TX_NO_WAIT);
696 
697     /* Check status.  */
698     if (status != TX_SUCCESS)
699     {
700 
701         /* Byte memory error.  */
702         printf("ERROR #27\n");
703         test_control_return(1);
704     }
705 
706     /* Allocate second memory area from the pool.  */
707     status = tx_byte_allocate(&pool_0, (VOID **) &pointer_2, 24, TX_NO_WAIT);
708 
709     /* Check status.  */
710     if (status != TX_SUCCESS)
711     {
712 
713         /* Byte memory error.  */
714         printf("ERROR #28\n");
715         test_control_return(1);
716     }
717 
718     /* Allocate third memory area from the pool.  */
719     status = tx_byte_allocate(&pool_0, (VOID **) &pointer_3, 24, TX_NO_WAIT);
720 
721     /* Check status.  */
722     if (status != TX_SUCCESS)
723     {
724 
725         /* Byte memory error.  */
726         printf("ERROR #29\n");
727         test_control_return(1);
728     }
729 
730     /* Attempt to allocate fourth memory area from the pool.  This should fail because
731        there should be not enough bytes in the pool.  */
732     status = tx_byte_allocate(&pool_0, (VOID **) &pointer_4, 24, TX_NO_WAIT);
733 
734     /* Check status.  */
735     if (status != TX_NO_MEMORY)
736     {
737 
738         /* Byte memory error.  */
739         printf("ERROR #30\n");
740         test_control_return(1);
741     }
742 
743     /* Now release each of the blocks. */
744     status =  tx_byte_release(pointer_1);
745 
746     /* Check for status.  */
747     if (status != TX_SUCCESS)
748     {
749 
750         /* Byte memory error.  */
751         printf("ERROR #31\n");
752         test_control_return(1);
753     }
754 
755     /* Release the second memory area.  */
756     status =  tx_byte_release(pointer_2);
757 
758     /* Check for status.  */
759     if (status != TX_SUCCESS)
760     {
761 
762         /* Byte memory error.  */
763         printf("ERROR #32\n");
764         test_control_return(1);
765     }
766 
767     /* Release the third memory area.  */
768     status =  tx_byte_release(pointer_3);
769 
770     /* Check for status.  */
771     if (status != TX_SUCCESS)
772     {
773 
774         /* Byte memory error.  */
775         printf("ERROR #33\n");
776         test_control_return(1);
777     }
778 
779     /* Now allocate a block that should cause all of the blocks to merge
780        together.  */
781     status = tx_byte_allocate(&pool_0, (VOID **) &pointer_3, 88, TX_NO_WAIT);
782 
783     /* Check status.  */
784     if (status != TX_SUCCESS)
785     {
786 
787         /* Byte memory error.  */
788         printf("ERROR #34\n");
789         test_control_return(1);
790     }
791 
792     /* Attempt to allocate fourth memory area from the pool.  This should fail because
793        there should be not enough bytes in the pool.  */
794     status = tx_byte_allocate(&pool_0, (VOID **) &pointer_4, 24, TX_NO_WAIT);
795 
796     /* Check status.  */
797     if (status != TX_NO_MEMORY)
798     {
799 
800         /* Byte memory error.  */
801         printf("ERROR #35\n");
802         test_control_return(1);
803     }
804 
805     /* Release the block.  */
806     status =  tx_byte_release(pointer_3);
807 
808     /* Check status.  */
809     if (status != TX_SUCCESS)
810     {
811 
812         /* Byte memory error.  */
813         printf("ERROR #36\n");
814         test_control_return(1);
815     }
816 
817     /* Now ensure the search pointer update in the byte search algorithm is updated.  */
818 
819     /* Allocate memory from the pool.  */
820     status = tx_byte_allocate(&pool_0, (VOID **) &pointer_1, 24, TX_NO_WAIT);
821 
822     /* Check status.  */
823     if (status != TX_SUCCESS)
824     {
825 
826         /* Byte memory error.  */
827         printf("ERROR #37\n");
828         test_control_return(1);
829     }
830 
831     /* Allocate second memory area from the pool.  */
832     status = tx_byte_allocate(&pool_0, (VOID **) &pointer_2, 24, TX_NO_WAIT);
833 
834     /* Check status.  */
835     if (status != TX_SUCCESS)
836     {
837 
838         /* Byte memory error.  */
839         printf("ERROR #38\n");
840         test_control_return(1);
841     }
842 
843     /* Allocate third memory area from the pool.  */
844     status = tx_byte_allocate(&pool_0, (VOID **) &pointer_3, 24, TX_NO_WAIT);
845 
846     /* Check status.  */
847     if (status != TX_SUCCESS)
848     {
849 
850         /* Byte memory error.  */
851         printf("ERROR #39\n");
852         test_control_return(1);
853     }
854 
855     /* Release the middle block.  */
856     status =  tx_byte_release(pointer_2);
857 
858     /* Check status.  */
859     if (status != TX_SUCCESS)
860     {
861 
862         /* Byte memory error.  */
863         printf("ERROR #40\n");
864         test_control_return(1);
865     }
866 
867     /* Move the search pointer to the third block to exercise that code in the byte search algorithm.  */
868     pool_0.tx_byte_pool_search =  (UCHAR *) pointer_3-8;
869 
870     /* Now allocate the block again.  */
871     status = tx_byte_allocate(&pool_0, (VOID **) &pointer_2, 24, TX_NO_WAIT);
872 
873     /* Check status.  */
874     if (status != TX_SUCCESS)
875     {
876 
877         /* Byte memory error.  */
878         printf("ERROR #41\n");
879         test_control_return(1);
880     }
881 
882     /* Now release the blocks are test the merge with the update of the search pointer.  */
883     status =   tx_byte_release(pointer_3);
884     status +=  tx_byte_release(pointer_2);
885     status +=  tx_byte_release(pointer_1);
886 
887     /* Move the search pointer to the third block to exercise that code in the byte search algorithm.  */
888     pool_0.tx_byte_pool_search =  (UCHAR *) pointer_3-8;
889 
890     /* Allocate a large block to force the search pointer update.  */
891     status = tx_byte_allocate(&pool_0, (VOID **) &pointer_3, 88, TX_NO_WAIT);
892 
893     /* Check status.  */
894     if (status != TX_SUCCESS)
895     {
896 
897         /* Byte memory error.  */
898         printf("ERROR #42\n");
899         test_control_return(1);
900     }
901 
902 
903 #ifndef TX_DISABLE_ERROR_CHECKING
904 
905     /* Create a timer for the test.  */
906     tx_timer_create(&timer_0, "timer 0", timer_entry, 0, 1, 1, TX_AUTO_ACTIVATE);
907 
908     /* Setup the ISR.  */
909     test_isr_dispatch =  test_isr;
910 
911     /* Sleep for a bit...  */
912     tx_thread_sleep(3);
913 
914     /* Clear the ISR.  */
915     test_isr_dispatch =  TX_NULL;
916 
917     /* Test for error.  */
918     if ((error) || (timer_executed != 1) || (isr_executed != 1))
919     {
920 
921         /* Byte memory error.  */
922         printf("ERROR #43\n");
923         test_control_return(1);
924     }
925 
926 #endif
927 
928     /* Delete both byte pools.  */
929     status =  tx_byte_pool_delete(&pool_0);
930 
931     /* Check status.  */
932     if (status != TX_SUCCESS)
933     {
934 
935         /* Byte memory error.  */
936         printf("ERROR #44\n");
937         test_control_return(1);
938     }
939 
940     status =  tx_byte_pool_delete(&pool_1);
941 
942     /* Check status.  */
943     if (status != TX_SUCCESS)
944     {
945 
946         /* Byte memory error.  */
947         printf("ERROR #45\n");
948         test_control_return(1);
949     }
950 
951     /* Delete pool 4.  */
952     status =  tx_byte_pool_delete(&pool_4);
953 
954     /* Check status.  */
955     if (status != TX_SUCCESS)
956     {
957 
958         /* Byte memory error.  */
959         printf("ERROR #46\n");
960         test_control_return(1);
961     }
962 
963     /* Create pool 4.  */
964     status =  tx_byte_pool_create(&pool_4, "pool 4", pool_4_memory, 300);
965 
966     /* Check status.  */
967     if (status != TX_SUCCESS)
968     {
969 
970         /* Byte memory error.  */
971         printf("ERROR #47\n");
972         test_control_return(1);
973     }
974 
975     /* Allocate three blocks...  */
976     status =   tx_byte_allocate(&pool_4, (VOID **) &pointer_1, 84, TX_NO_WAIT);
977     status +=  tx_byte_allocate(&pool_4, (VOID **) &pointer_2, 84, TX_NO_WAIT);
978     status +=  tx_byte_allocate(&pool_4, (VOID **) &pointer_3, 84, TX_NO_WAIT);
979 
980     /* Check status.  */
981     if (status != TX_SUCCESS)
982     {
983 
984         /* Byte memory error.  */
985         printf("ERROR #48\n");
986         test_control_return(1);
987     }
988 
989     /* At this point, there should be three allocated blocks and the reserved block at the end.  */
990 
991     /* Now release all the blocks in reverse order. This should leave the search pointer at the last block.  */
992     status =  tx_byte_release(pointer_3);
993     save_search =  pool_4.tx_byte_pool_search;
994     status += tx_byte_release(pointer_2);
995     status += tx_byte_release(pointer_1);
996 
997     /* Move the search pointer back to the last block.  */
998     pool_4.tx_byte_pool_search =  save_search;
999 
1000     /* Check status.  */
1001     if (status != TX_SUCCESS)
1002     {
1003 
1004         /* Byte memory error.  */
1005         printf("ERROR #49\n");
1006         test_control_return(1);
1007     }
1008 
1009     /* Now attempt to allocate a block that requires a merge, which should exercise the branch in byte search that does not
1010        result in a search pointer change.  */
1011     status =  tx_byte_allocate(&pool_4, (VOID **) &pointer_1, 168, TX_NO_WAIT);
1012 
1013     /* Check status.  */
1014     if (status != TX_SUCCESS)
1015     {
1016 
1017         /* Byte memory error.  */
1018         printf("ERROR #50\n");
1019         test_control_return(1);
1020     }
1021 
1022     /* Release the last block.  */
1023     status =  tx_byte_release(pointer_1);
1024 
1025     /* Allocate all the blocks.  */
1026     status =  tx_byte_allocate(&pool_4, (VOID **) &pointer_1, 84, TX_NO_WAIT);
1027     status += tx_byte_allocate(&pool_4, (VOID **) &pointer_2, 84, TX_NO_WAIT);
1028     status += tx_byte_allocate(&pool_4, (VOID **) &pointer_3, 84, TX_NO_WAIT);
1029 
1030     /* Release all of the blocks in order.  */
1031     status += tx_byte_release(pointer_1);
1032     status += tx_byte_release(pointer_2);
1033     status += tx_byte_release(pointer_3);
1034 
1035     /* Check status.  */
1036     if (status != TX_SUCCESS)
1037     {
1038 
1039         /* Byte memory error.  */
1040         printf("ERROR #50\n");
1041         test_control_return(1);
1042     }
1043 
1044     /* Now setup a special test to exercise the examine blocks equal to 0 path in the byte pool search.  */
1045     pool_4.tx_byte_pool_search =     save_search;
1046     pool_4.tx_byte_pool_fragments =  (UINT) (-1);
1047 
1048     /* Call byte allocate to execise the examine blocks equal to 0 path on non-merge block condition.  */
1049     status =  tx_byte_allocate(&pool_4, (VOID **) &pointer_1, 168, TX_NO_WAIT);
1050 
1051     /* Check status.  */
1052     if (status != TX_NO_MEMORY)
1053     {
1054 
1055         /* Byte memory error.  */
1056         printf("ERROR #51\n");
1057         test_control_return(1);
1058     }
1059 
1060     /* Successful test.  */
1061     printf("SUCCESS!\n");
1062     test_control_return(0);
1063 }
1064 
1065