Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 #include "alloc_api.h"
0003 
0004 /*
0005  * A simple test that tries to allocate a small memory region.
0006  * Expect to allocate an aligned region near the end of the available memory.
0007  */
0008 static int alloc_top_down_simple_check(void)
0009 {
0010     struct memblock_region *rgn = &memblock.reserved.regions[0];
0011     void *allocated_ptr = NULL;
0012 
0013     PREFIX_PUSH();
0014 
0015     phys_addr_t size = SZ_2;
0016     phys_addr_t expected_start;
0017 
0018     setup_memblock();
0019 
0020     expected_start = memblock_end_of_DRAM() - SMP_CACHE_BYTES;
0021 
0022     allocated_ptr = memblock_alloc(size, SMP_CACHE_BYTES);
0023 
0024     ASSERT_NE(allocated_ptr, NULL);
0025     ASSERT_EQ(rgn->size, size);
0026     ASSERT_EQ(rgn->base, expected_start);
0027 
0028     ASSERT_EQ(memblock.reserved.cnt, 1);
0029     ASSERT_EQ(memblock.reserved.total_size, size);
0030 
0031     test_pass_pop();
0032 
0033     return 0;
0034 }
0035 
0036 /*
0037  * A test that tries to allocate memory next to a reserved region that starts at
0038  * the misaligned address. Expect to create two separate entries, with the new
0039  * entry aligned to the provided alignment:
0040  *
0041  *              +
0042  * |            +--------+         +--------|
0043  * |            |  rgn2  |         |  rgn1  |
0044  * +------------+--------+---------+--------+
0045  *              ^
0046  *              |
0047  *              Aligned address boundary
0048  *
0049  * The allocation direction is top-down and region arrays are sorted from lower
0050  * to higher addresses, so the new region will be the first entry in
0051  * memory.reserved array. The previously reserved region does not get modified.
0052  * Region counter and total size get updated.
0053  */
0054 static int alloc_top_down_disjoint_check(void)
0055 {
0056     /* After allocation, this will point to the "old" region */
0057     struct memblock_region *rgn1 = &memblock.reserved.regions[1];
0058     struct memblock_region *rgn2 = &memblock.reserved.regions[0];
0059     struct region r1;
0060     void *allocated_ptr = NULL;
0061 
0062     PREFIX_PUSH();
0063 
0064     phys_addr_t r2_size = SZ_16;
0065     /* Use custom alignment */
0066     phys_addr_t alignment = SMP_CACHE_BYTES * 2;
0067     phys_addr_t total_size;
0068     phys_addr_t expected_start;
0069 
0070     setup_memblock();
0071 
0072     r1.base = memblock_end_of_DRAM() - SZ_2;
0073     r1.size = SZ_2;
0074 
0075     total_size = r1.size + r2_size;
0076     expected_start = memblock_end_of_DRAM() - alignment;
0077 
0078     memblock_reserve(r1.base, r1.size);
0079 
0080     allocated_ptr = memblock_alloc(r2_size, alignment);
0081 
0082     ASSERT_NE(allocated_ptr, NULL);
0083     ASSERT_EQ(rgn1->size, r1.size);
0084     ASSERT_EQ(rgn1->base, r1.base);
0085 
0086     ASSERT_EQ(rgn2->size, r2_size);
0087     ASSERT_EQ(rgn2->base, expected_start);
0088 
0089     ASSERT_EQ(memblock.reserved.cnt, 2);
0090     ASSERT_EQ(memblock.reserved.total_size, total_size);
0091 
0092     test_pass_pop();
0093 
0094     return 0;
0095 }
0096 
0097 /*
0098  * A test that tries to allocate memory when there is enough space at the end
0099  * of the previously reserved block (i.e. first fit):
0100  *
0101  *  |              +--------+--------------|
0102  *  |              |   r1   |      r2      |
0103  *  +--------------+--------+--------------+
0104  *
0105  * Expect a merge of both regions. Only the region size gets updated.
0106  */
0107 static int alloc_top_down_before_check(void)
0108 {
0109     struct memblock_region *rgn = &memblock.reserved.regions[0];
0110     void *allocated_ptr = NULL;
0111 
0112     PREFIX_PUSH();
0113 
0114     /*
0115      * The first region ends at the aligned address to test region merging
0116      */
0117     phys_addr_t r1_size = SMP_CACHE_BYTES;
0118     phys_addr_t r2_size = SZ_512;
0119     phys_addr_t total_size = r1_size + r2_size;
0120 
0121     setup_memblock();
0122 
0123     memblock_reserve(memblock_end_of_DRAM() - total_size, r1_size);
0124 
0125     allocated_ptr = memblock_alloc(r2_size, SMP_CACHE_BYTES);
0126 
0127     ASSERT_NE(allocated_ptr, NULL);
0128     ASSERT_EQ(rgn->size, total_size);
0129     ASSERT_EQ(rgn->base, memblock_end_of_DRAM() - total_size);
0130 
0131     ASSERT_EQ(memblock.reserved.cnt, 1);
0132     ASSERT_EQ(memblock.reserved.total_size, total_size);
0133 
0134     test_pass_pop();
0135 
0136     return 0;
0137 }
0138 
0139 /*
0140  * A test that tries to allocate memory when there is not enough space at the
0141  * end of the previously reserved block (i.e. second fit):
0142  *
0143  *  |            +-----------+------+     |
0144  *  |            |     r2    |  r1  |     |
0145  *  +------------+-----------+------+-----+
0146  *
0147  * Expect a merge of both regions. Both the base address and size of the region
0148  * get updated.
0149  */
0150 static int alloc_top_down_after_check(void)
0151 {
0152     struct memblock_region *rgn = &memblock.reserved.regions[0];
0153     struct region r1;
0154     void *allocated_ptr = NULL;
0155 
0156     PREFIX_PUSH();
0157 
0158     phys_addr_t r2_size = SZ_512;
0159     phys_addr_t total_size;
0160 
0161     setup_memblock();
0162 
0163     /*
0164      * The first region starts at the aligned address to test region merging
0165      */
0166     r1.base = memblock_end_of_DRAM() - SMP_CACHE_BYTES;
0167     r1.size = SZ_8;
0168 
0169     total_size = r1.size + r2_size;
0170 
0171     memblock_reserve(r1.base, r1.size);
0172 
0173     allocated_ptr = memblock_alloc(r2_size, SMP_CACHE_BYTES);
0174 
0175     ASSERT_NE(allocated_ptr, NULL);
0176     ASSERT_EQ(rgn->size, total_size);
0177     ASSERT_EQ(rgn->base, r1.base - r2_size);
0178 
0179     ASSERT_EQ(memblock.reserved.cnt, 1);
0180     ASSERT_EQ(memblock.reserved.total_size, total_size);
0181 
0182     test_pass_pop();
0183 
0184     return 0;
0185 }
0186 
0187 /*
0188  * A test that tries to allocate memory when there are two reserved regions with
0189  * a gap too small to fit the new region:
0190  *
0191  *  |       +--------+----------+   +------|
0192  *  |       |   r3   |    r2    |   |  r1  |
0193  *  +-------+--------+----------+---+------+
0194  *
0195  * Expect to allocate a region before the one that starts at the lower address,
0196  * and merge them into one. The region counter and total size fields get
0197  * updated.
0198  */
0199 static int alloc_top_down_second_fit_check(void)
0200 {
0201     struct memblock_region *rgn = &memblock.reserved.regions[0];
0202     struct region r1, r2;
0203     void *allocated_ptr = NULL;
0204 
0205     PREFIX_PUSH();
0206 
0207     phys_addr_t r3_size = SZ_1K;
0208     phys_addr_t total_size;
0209 
0210     setup_memblock();
0211 
0212     r1.base = memblock_end_of_DRAM() - SZ_512;
0213     r1.size = SZ_512;
0214 
0215     r2.base = r1.base - SZ_512;
0216     r2.size = SZ_256;
0217 
0218     total_size = r1.size + r2.size + r3_size;
0219 
0220     memblock_reserve(r1.base, r1.size);
0221     memblock_reserve(r2.base, r2.size);
0222 
0223     allocated_ptr = memblock_alloc(r3_size, SMP_CACHE_BYTES);
0224 
0225     ASSERT_NE(allocated_ptr, NULL);
0226     ASSERT_EQ(rgn->size, r2.size + r3_size);
0227     ASSERT_EQ(rgn->base, r2.base - r3_size);
0228 
0229     ASSERT_EQ(memblock.reserved.cnt, 2);
0230     ASSERT_EQ(memblock.reserved.total_size, total_size);
0231 
0232     test_pass_pop();
0233 
0234     return 0;
0235 }
0236 
0237 /*
0238  * A test that tries to allocate memory when there are two reserved regions with
0239  * a gap big enough to accommodate the new region:
0240  *
0241  *  |     +--------+--------+--------+     |
0242  *  |     |   r2   |   r3   |   r1   |     |
0243  *  +-----+--------+--------+--------+-----+
0244  *
0245  * Expect to merge all of them, creating one big entry in memblock.reserved
0246  * array. The region counter and total size fields get updated.
0247  */
0248 static int alloc_in_between_generic_check(void)
0249 {
0250     struct memblock_region *rgn = &memblock.reserved.regions[0];
0251     struct region r1, r2;
0252     void *allocated_ptr = NULL;
0253 
0254     PREFIX_PUSH();
0255 
0256     phys_addr_t gap_size = SMP_CACHE_BYTES;
0257     phys_addr_t r3_size = SZ_64;
0258     /*
0259      * Calculate regions size so there's just enough space for the new entry
0260      */
0261     phys_addr_t rgn_size = (MEM_SIZE - (2 * gap_size + r3_size)) / 2;
0262     phys_addr_t total_size;
0263 
0264     setup_memblock();
0265 
0266     r1.size = rgn_size;
0267     r1.base = memblock_end_of_DRAM() - (gap_size + rgn_size);
0268 
0269     r2.size = rgn_size;
0270     r2.base = memblock_start_of_DRAM() + gap_size;
0271 
0272     total_size = r1.size + r2.size + r3_size;
0273 
0274     memblock_reserve(r1.base, r1.size);
0275     memblock_reserve(r2.base, r2.size);
0276 
0277     allocated_ptr = memblock_alloc(r3_size, SMP_CACHE_BYTES);
0278 
0279     ASSERT_NE(allocated_ptr, NULL);
0280     ASSERT_EQ(rgn->size, total_size);
0281     ASSERT_EQ(rgn->base, r1.base - r2.size - r3_size);
0282 
0283     ASSERT_EQ(memblock.reserved.cnt, 1);
0284     ASSERT_EQ(memblock.reserved.total_size, total_size);
0285 
0286     test_pass_pop();
0287 
0288     return 0;
0289 }
0290 
0291 /*
0292  * A test that tries to allocate memory when the memory is filled with reserved
0293  * regions with memory gaps too small to fit the new region:
0294  *
0295  * +-------+
0296  * |  new  |
0297  * +--+----+
0298  *    |    +-----+    +-----+    +-----+    |
0299  *    |    | res |    | res |    | res |    |
0300  *    +----+-----+----+-----+----+-----+----+
0301  *
0302  * Expect no allocation to happen.
0303  */
0304 static int alloc_small_gaps_generic_check(void)
0305 {
0306     void *allocated_ptr = NULL;
0307 
0308     PREFIX_PUSH();
0309 
0310     phys_addr_t region_size = SZ_1K;
0311     phys_addr_t gap_size = SZ_256;
0312     phys_addr_t region_end;
0313 
0314     setup_memblock();
0315 
0316     region_end = memblock_start_of_DRAM();
0317 
0318     while (region_end < memblock_end_of_DRAM()) {
0319         memblock_reserve(region_end + gap_size, region_size);
0320         region_end += gap_size + region_size;
0321     }
0322 
0323     allocated_ptr = memblock_alloc(region_size, SMP_CACHE_BYTES);
0324 
0325     ASSERT_EQ(allocated_ptr, NULL);
0326 
0327     test_pass_pop();
0328 
0329     return 0;
0330 }
0331 
0332 /*
0333  * A test that tries to allocate memory when all memory is reserved.
0334  * Expect no allocation to happen.
0335  */
0336 static int alloc_all_reserved_generic_check(void)
0337 {
0338     void *allocated_ptr = NULL;
0339 
0340     PREFIX_PUSH();
0341 
0342     setup_memblock();
0343 
0344     /* Simulate full memory */
0345     memblock_reserve(memblock_start_of_DRAM(), MEM_SIZE);
0346 
0347     allocated_ptr = memblock_alloc(SZ_256, SMP_CACHE_BYTES);
0348 
0349     ASSERT_EQ(allocated_ptr, NULL);
0350 
0351     test_pass_pop();
0352 
0353     return 0;
0354 }
0355 
0356 /*
0357  * A test that tries to allocate memory when the memory is almost full,
0358  * with not enough space left for the new region:
0359  *
0360  *                                +-------+
0361  *                                |  new  |
0362  *                                +-------+
0363  *  |-----------------------------+   |
0364  *  |          reserved           |   |
0365  *  +-----------------------------+---+
0366  *
0367  * Expect no allocation to happen.
0368  */
0369 static int alloc_no_space_generic_check(void)
0370 {
0371     void *allocated_ptr = NULL;
0372 
0373     PREFIX_PUSH();
0374 
0375     setup_memblock();
0376 
0377     phys_addr_t available_size = SZ_256;
0378     phys_addr_t reserved_size = MEM_SIZE - available_size;
0379 
0380     /* Simulate almost-full memory */
0381     memblock_reserve(memblock_start_of_DRAM(), reserved_size);
0382 
0383     allocated_ptr = memblock_alloc(SZ_1K, SMP_CACHE_BYTES);
0384 
0385     ASSERT_EQ(allocated_ptr, NULL);
0386 
0387     test_pass_pop();
0388 
0389     return 0;
0390 }
0391 
0392 /*
0393  * A test that tries to allocate memory when the memory is almost full,
0394  * but there is just enough space left:
0395  *
0396  *  |---------------------------+---------|
0397  *  |          reserved         |   new   |
0398  *  +---------------------------+---------+
0399  *
0400  * Expect to allocate memory and merge all the regions. The total size field
0401  * gets updated.
0402  */
0403 static int alloc_limited_space_generic_check(void)
0404 {
0405     struct memblock_region *rgn = &memblock.reserved.regions[0];
0406     void *allocated_ptr = NULL;
0407 
0408     PREFIX_PUSH();
0409 
0410     phys_addr_t available_size = SZ_256;
0411     phys_addr_t reserved_size = MEM_SIZE - available_size;
0412 
0413     setup_memblock();
0414 
0415     /* Simulate almost-full memory */
0416     memblock_reserve(memblock_start_of_DRAM(), reserved_size);
0417 
0418     allocated_ptr = memblock_alloc(available_size, SMP_CACHE_BYTES);
0419 
0420     ASSERT_NE(allocated_ptr, NULL);
0421     ASSERT_EQ(rgn->size, MEM_SIZE);
0422     ASSERT_EQ(rgn->base, memblock_start_of_DRAM());
0423 
0424     ASSERT_EQ(memblock.reserved.cnt, 1);
0425     ASSERT_EQ(memblock.reserved.total_size, MEM_SIZE);
0426 
0427     test_pass_pop();
0428 
0429     return 0;
0430 }
0431 
0432 /*
0433  * A test that tries to allocate memory when there is no available memory
0434  * registered (i.e. memblock.memory has only a dummy entry).
0435  * Expect no allocation to happen.
0436  */
0437 static int alloc_no_memory_generic_check(void)
0438 {
0439     struct memblock_region *rgn = &memblock.reserved.regions[0];
0440     void *allocated_ptr = NULL;
0441 
0442     PREFIX_PUSH();
0443 
0444     reset_memblock_regions();
0445 
0446     allocated_ptr = memblock_alloc(SZ_1K, SMP_CACHE_BYTES);
0447 
0448     ASSERT_EQ(allocated_ptr, NULL);
0449     ASSERT_EQ(rgn->size, 0);
0450     ASSERT_EQ(rgn->base, 0);
0451     ASSERT_EQ(memblock.reserved.total_size, 0);
0452 
0453     test_pass_pop();
0454 
0455     return 0;
0456 }
0457 
0458 /*
0459  * A simple test that tries to allocate a small memory region.
0460  * Expect to allocate an aligned region at the beginning of the available
0461  * memory.
0462  */
0463 static int alloc_bottom_up_simple_check(void)
0464 {
0465     struct memblock_region *rgn = &memblock.reserved.regions[0];
0466     void *allocated_ptr = NULL;
0467 
0468     PREFIX_PUSH();
0469 
0470     setup_memblock();
0471 
0472     allocated_ptr = memblock_alloc(SZ_2, SMP_CACHE_BYTES);
0473 
0474     ASSERT_NE(allocated_ptr, NULL);
0475     ASSERT_EQ(rgn->size, SZ_2);
0476     ASSERT_EQ(rgn->base, memblock_start_of_DRAM());
0477 
0478     ASSERT_EQ(memblock.reserved.cnt, 1);
0479     ASSERT_EQ(memblock.reserved.total_size, SZ_2);
0480 
0481     test_pass_pop();
0482 
0483     return 0;
0484 }
0485 
0486 /*
0487  * A test that tries to allocate memory next to a reserved region that starts at
0488  * the misaligned address. Expect to create two separate entries, with the new
0489  * entry aligned to the provided alignment:
0490  *
0491  *                      +
0492  *  |    +----------+   +----------+     |
0493  *  |    |   rgn1   |   |   rgn2   |     |
0494  *  +----+----------+---+----------+-----+
0495  *                      ^
0496  *                      |
0497  *                      Aligned address boundary
0498  *
0499  * The allocation direction is bottom-up, so the new region will be the second
0500  * entry in memory.reserved array. The previously reserved region does not get
0501  * modified. Region counter and total size get updated.
0502  */
0503 static int alloc_bottom_up_disjoint_check(void)
0504 {
0505     struct memblock_region *rgn1 = &memblock.reserved.regions[0];
0506     struct memblock_region *rgn2 = &memblock.reserved.regions[1];
0507     struct region r1;
0508     void *allocated_ptr = NULL;
0509 
0510     PREFIX_PUSH();
0511 
0512     phys_addr_t r2_size = SZ_16;
0513     /* Use custom alignment */
0514     phys_addr_t alignment = SMP_CACHE_BYTES * 2;
0515     phys_addr_t total_size;
0516     phys_addr_t expected_start;
0517 
0518     setup_memblock();
0519 
0520     r1.base = memblock_start_of_DRAM() + SZ_2;
0521     r1.size = SZ_2;
0522 
0523     total_size = r1.size + r2_size;
0524     expected_start = memblock_start_of_DRAM() + alignment;
0525 
0526     memblock_reserve(r1.base, r1.size);
0527 
0528     allocated_ptr = memblock_alloc(r2_size, alignment);
0529 
0530     ASSERT_NE(allocated_ptr, NULL);
0531 
0532     ASSERT_EQ(rgn1->size, r1.size);
0533     ASSERT_EQ(rgn1->base, r1.base);
0534 
0535     ASSERT_EQ(rgn2->size, r2_size);
0536     ASSERT_EQ(rgn2->base, expected_start);
0537 
0538     ASSERT_EQ(memblock.reserved.cnt, 2);
0539     ASSERT_EQ(memblock.reserved.total_size, total_size);
0540 
0541     test_pass_pop();
0542 
0543     return 0;
0544 }
0545 
0546 /*
0547  * A test that tries to allocate memory when there is enough space at
0548  * the beginning of the previously reserved block (i.e. first fit):
0549  *
0550  *  |------------------+--------+         |
0551  *  |        r1        |   r2   |         |
0552  *  +------------------+--------+---------+
0553  *
0554  * Expect a merge of both regions. Only the region size gets updated.
0555  */
0556 static int alloc_bottom_up_before_check(void)
0557 {
0558     struct memblock_region *rgn = &memblock.reserved.regions[0];
0559     void *allocated_ptr = NULL;
0560 
0561     PREFIX_PUSH();
0562 
0563     phys_addr_t r1_size = SZ_512;
0564     phys_addr_t r2_size = SZ_128;
0565     phys_addr_t total_size = r1_size + r2_size;
0566 
0567     setup_memblock();
0568 
0569     memblock_reserve(memblock_start_of_DRAM() + r1_size, r2_size);
0570 
0571     allocated_ptr = memblock_alloc(r1_size, SMP_CACHE_BYTES);
0572 
0573     ASSERT_NE(allocated_ptr, NULL);
0574     ASSERT_EQ(rgn->size, total_size);
0575     ASSERT_EQ(rgn->base, memblock_start_of_DRAM());
0576 
0577     ASSERT_EQ(memblock.reserved.cnt, 1);
0578     ASSERT_EQ(memblock.reserved.total_size, total_size);
0579 
0580     test_pass_pop();
0581 
0582     return 0;
0583 }
0584 
0585 /*
0586  * A test that tries to allocate memory when there is not enough space at
0587  * the beginning of the previously reserved block (i.e. second fit):
0588  *
0589  *  |    +--------+--------------+         |
0590  *  |    |   r1   |      r2      |         |
0591  *  +----+--------+--------------+---------+
0592  *
0593  * Expect a merge of both regions. Only the region size gets updated.
0594  */
0595 static int alloc_bottom_up_after_check(void)
0596 {
0597     struct memblock_region *rgn = &memblock.reserved.regions[0];
0598     struct region r1;
0599     void *allocated_ptr = NULL;
0600 
0601     PREFIX_PUSH();
0602 
0603     phys_addr_t r2_size = SZ_512;
0604     phys_addr_t total_size;
0605 
0606     setup_memblock();
0607 
0608     /*
0609      * The first region starts at the aligned address to test region merging
0610      */
0611     r1.base = memblock_start_of_DRAM() + SMP_CACHE_BYTES;
0612     r1.size = SZ_64;
0613 
0614     total_size = r1.size + r2_size;
0615 
0616     memblock_reserve(r1.base, r1.size);
0617 
0618     allocated_ptr = memblock_alloc(r2_size, SMP_CACHE_BYTES);
0619 
0620     ASSERT_NE(allocated_ptr, NULL);
0621     ASSERT_EQ(rgn->size, total_size);
0622     ASSERT_EQ(rgn->base, r1.base);
0623 
0624     ASSERT_EQ(memblock.reserved.cnt, 1);
0625     ASSERT_EQ(memblock.reserved.total_size, total_size);
0626 
0627     test_pass_pop();
0628 
0629     return 0;
0630 }
0631 
0632 /*
0633  * A test that tries to allocate memory when there are two reserved regions, the
0634  * first one starting at the beginning of the available memory, with a gap too
0635  * small to fit the new region:
0636  *
0637  *  |------------+     +--------+--------+  |
0638  *  |     r1     |     |   r2   |   r3   |  |
0639  *  +------------+-----+--------+--------+--+
0640  *
0641  * Expect to allocate after the second region, which starts at the higher
0642  * address, and merge them into one. The region counter and total size fields
0643  * get updated.
0644  */
0645 static int alloc_bottom_up_second_fit_check(void)
0646 {
0647     struct memblock_region *rgn  = &memblock.reserved.regions[1];
0648     struct region r1, r2;
0649     void *allocated_ptr = NULL;
0650 
0651     PREFIX_PUSH();
0652 
0653     phys_addr_t r3_size = SZ_1K;
0654     phys_addr_t total_size;
0655 
0656     setup_memblock();
0657 
0658     r1.base = memblock_start_of_DRAM();
0659     r1.size = SZ_512;
0660 
0661     r2.base = r1.base + r1.size + SZ_512;
0662     r2.size = SZ_256;
0663 
0664     total_size = r1.size + r2.size + r3_size;
0665 
0666     memblock_reserve(r1.base, r1.size);
0667     memblock_reserve(r2.base, r2.size);
0668 
0669     allocated_ptr = memblock_alloc(r3_size, SMP_CACHE_BYTES);
0670 
0671     ASSERT_NE(allocated_ptr, NULL);
0672     ASSERT_EQ(rgn->size, r2.size + r3_size);
0673     ASSERT_EQ(rgn->base, r2.base);
0674 
0675     ASSERT_EQ(memblock.reserved.cnt, 2);
0676     ASSERT_EQ(memblock.reserved.total_size, total_size);
0677 
0678     test_pass_pop();
0679 
0680     return 0;
0681 }
0682 
0683 /* Test case wrappers */
0684 static int alloc_simple_check(void)
0685 {
0686     test_print("\tRunning %s...\n", __func__);
0687     memblock_set_bottom_up(false);
0688     alloc_top_down_simple_check();
0689     memblock_set_bottom_up(true);
0690     alloc_bottom_up_simple_check();
0691 
0692     return 0;
0693 }
0694 
0695 static int alloc_disjoint_check(void)
0696 {
0697     test_print("\tRunning %s...\n", __func__);
0698     memblock_set_bottom_up(false);
0699     alloc_top_down_disjoint_check();
0700     memblock_set_bottom_up(true);
0701     alloc_bottom_up_disjoint_check();
0702 
0703     return 0;
0704 }
0705 
0706 static int alloc_before_check(void)
0707 {
0708     test_print("\tRunning %s...\n", __func__);
0709     memblock_set_bottom_up(false);
0710     alloc_top_down_before_check();
0711     memblock_set_bottom_up(true);
0712     alloc_bottom_up_before_check();
0713 
0714     return 0;
0715 }
0716 
0717 static int alloc_after_check(void)
0718 {
0719     test_print("\tRunning %s...\n", __func__);
0720     memblock_set_bottom_up(false);
0721     alloc_top_down_after_check();
0722     memblock_set_bottom_up(true);
0723     alloc_bottom_up_after_check();
0724 
0725     return 0;
0726 }
0727 
0728 static int alloc_in_between_check(void)
0729 {
0730     test_print("\tRunning %s...\n", __func__);
0731     memblock_set_bottom_up(false);
0732     alloc_in_between_generic_check();
0733     memblock_set_bottom_up(true);
0734     alloc_in_between_generic_check();
0735 
0736     return 0;
0737 }
0738 
0739 static int alloc_second_fit_check(void)
0740 {
0741     test_print("\tRunning %s...\n", __func__);
0742     memblock_set_bottom_up(false);
0743     alloc_top_down_second_fit_check();
0744     memblock_set_bottom_up(true);
0745     alloc_bottom_up_second_fit_check();
0746 
0747     return 0;
0748 }
0749 
0750 static int alloc_small_gaps_check(void)
0751 {
0752     test_print("\tRunning %s...\n", __func__);
0753     memblock_set_bottom_up(false);
0754     alloc_small_gaps_generic_check();
0755     memblock_set_bottom_up(true);
0756     alloc_small_gaps_generic_check();
0757 
0758     return 0;
0759 }
0760 
0761 static int alloc_all_reserved_check(void)
0762 {
0763     test_print("\tRunning %s...\n", __func__);
0764     memblock_set_bottom_up(false);
0765     alloc_all_reserved_generic_check();
0766     memblock_set_bottom_up(true);
0767     alloc_all_reserved_generic_check();
0768 
0769     return 0;
0770 }
0771 
0772 static int alloc_no_space_check(void)
0773 {
0774     test_print("\tRunning %s...\n", __func__);
0775     memblock_set_bottom_up(false);
0776     alloc_no_space_generic_check();
0777     memblock_set_bottom_up(true);
0778     alloc_no_space_generic_check();
0779 
0780     return 0;
0781 }
0782 
0783 static int alloc_limited_space_check(void)
0784 {
0785     test_print("\tRunning %s...\n", __func__);
0786     memblock_set_bottom_up(false);
0787     alloc_limited_space_generic_check();
0788     memblock_set_bottom_up(true);
0789     alloc_limited_space_generic_check();
0790 
0791     return 0;
0792 }
0793 
0794 static int alloc_no_memory_check(void)
0795 {
0796     test_print("\tRunning %s...\n", __func__);
0797     memblock_set_bottom_up(false);
0798     alloc_no_memory_generic_check();
0799     memblock_set_bottom_up(true);
0800     alloc_no_memory_generic_check();
0801 
0802     return 0;
0803 }
0804 
0805 int memblock_alloc_checks(void)
0806 {
0807     const char *func_testing = "memblock_alloc";
0808 
0809     prefix_reset();
0810     prefix_push(func_testing);
0811     test_print("Running %s tests...\n", func_testing);
0812 
0813     reset_memblock_attributes();
0814     dummy_physical_memory_init();
0815 
0816     alloc_simple_check();
0817     alloc_disjoint_check();
0818     alloc_before_check();
0819     alloc_after_check();
0820     alloc_second_fit_check();
0821     alloc_small_gaps_check();
0822     alloc_in_between_check();
0823     alloc_all_reserved_check();
0824     alloc_no_space_check();
0825     alloc_limited_space_check();
0826     alloc_no_memory_check();
0827 
0828     dummy_physical_memory_cleanup();
0829 
0830     prefix_pop();
0831 
0832     return 0;
0833 }