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