Lines Matching +full:memory +full:- +full:region
1 // SPDX-License-Identifier: GPL-2.0-or-later
17 ASSERT_NE(memblock.memory.regions, NULL); in memblock_initialization_check()
18 ASSERT_EQ(memblock.memory.cnt, 1); in memblock_initialization_check()
19 ASSERT_EQ(memblock.memory.max, EXPECTED_MEMBLOCK_REGIONS); in memblock_initialization_check()
20 ASSERT_EQ(strcmp(memblock.memory.name, "memory"), 0); in memblock_initialization_check()
24 ASSERT_EQ(memblock.memory.max, EXPECTED_MEMBLOCK_REGIONS); in memblock_initialization_check()
36 * A simple test that adds a memory block of a specified base address
37 * and size to the collection of available memory regions (memblock.memory).
38 * Expect to create a new entry. The region counter and total memory get
45 rgn = &memblock.memory.regions[0]; in memblock_add_simple_check()
47 struct region r = { in memblock_add_simple_check()
57 ASSERT_EQ(rgn->base, r.base); in memblock_add_simple_check()
58 ASSERT_EQ(rgn->size, r.size); in memblock_add_simple_check()
60 ASSERT_EQ(memblock.memory.cnt, 1); in memblock_add_simple_check()
61 ASSERT_EQ(memblock.memory.total_size, r.size); in memblock_add_simple_check()
69 * A simple test that adds a memory block of a specified base address, size,
70 * NUMA node and memory flags to the collection of available memory regions.
71 * Expect to create a new entry. The region counter and total memory get
78 rgn = &memblock.memory.regions[0]; in memblock_add_node_simple_check()
80 struct region r = { in memblock_add_node_simple_check()
90 ASSERT_EQ(rgn->base, r.base); in memblock_add_node_simple_check()
91 ASSERT_EQ(rgn->size, r.size); in memblock_add_node_simple_check()
93 ASSERT_EQ(rgn->nid, 1); in memblock_add_node_simple_check()
95 ASSERT_EQ(rgn->flags, MEMBLOCK_HOTPLUG); in memblock_add_node_simple_check()
97 ASSERT_EQ(memblock.memory.cnt, 1); in memblock_add_node_simple_check()
98 ASSERT_EQ(memblock.memory.total_size, r.size); in memblock_add_node_simple_check()
106 * A test that tries to add two memory blocks that don't overlap with one
109 * | +--------+ +--------+ |
111 * +--------+--------+--------+--------+--+
114 * available memory regions (memblock.memory). The total size and
115 * region counter fields get updated.
121 rgn1 = &memblock.memory.regions[0]; in memblock_add_disjoint_check()
122 rgn2 = &memblock.memory.regions[1]; in memblock_add_disjoint_check()
124 struct region r1 = { in memblock_add_disjoint_check()
128 struct region r2 = { in memblock_add_disjoint_check()
139 ASSERT_EQ(rgn1->base, r1.base); in memblock_add_disjoint_check()
140 ASSERT_EQ(rgn1->size, r1.size); in memblock_add_disjoint_check()
142 ASSERT_EQ(rgn2->base, r2.base); in memblock_add_disjoint_check()
143 ASSERT_EQ(rgn2->size, r2.size); in memblock_add_disjoint_check()
145 ASSERT_EQ(memblock.memory.cnt, 2); in memblock_add_disjoint_check()
146 ASSERT_EQ(memblock.memory.total_size, r1.size + r2.size); in memblock_add_disjoint_check()
154 * A test that tries to add two memory blocks r1 and r2, where r2 overlaps
157 * | +----+----+------------+ |
159 * +----+----+----+------------+----------+
166 * Expect to merge the two entries into one region that starts at r2.base
168 * the available memory is updated, and the region counter stays the same.
175 rgn = &memblock.memory.regions[0]; in memblock_add_overlap_top_check()
177 struct region r1 = { in memblock_add_overlap_top_check()
181 struct region r2 = { in memblock_add_overlap_top_check()
188 total_size = (r1.base - r2.base) + r1.size; in memblock_add_overlap_top_check()
194 ASSERT_EQ(rgn->base, r2.base); in memblock_add_overlap_top_check()
195 ASSERT_EQ(rgn->size, total_size); in memblock_add_overlap_top_check()
197 ASSERT_EQ(memblock.memory.cnt, 1); in memblock_add_overlap_top_check()
198 ASSERT_EQ(memblock.memory.total_size, total_size); in memblock_add_overlap_top_check()
206 * A test that tries to add two memory blocks r1 and r2, where r2 overlaps
209 * | +--+------+----------+ |
211 * +--+--+------+----------+--------------+
218 * Expect to merge the two entries into one region that starts at r1.base
220 * the available memory is updated, and the region counter stays the same.
227 rgn = &memblock.memory.regions[0]; in memblock_add_overlap_bottom_check()
229 struct region r1 = { in memblock_add_overlap_bottom_check()
233 struct region r2 = { in memblock_add_overlap_bottom_check()
240 total_size = (r2.base - r1.base) + r2.size; in memblock_add_overlap_bottom_check()
246 ASSERT_EQ(rgn->base, r1.base); in memblock_add_overlap_bottom_check()
247 ASSERT_EQ(rgn->size, total_size); in memblock_add_overlap_bottom_check()
249 ASSERT_EQ(memblock.memory.cnt, 1); in memblock_add_overlap_bottom_check()
250 ASSERT_EQ(memblock.memory.total_size, total_size); in memblock_add_overlap_bottom_check()
258 * A test that tries to add two memory blocks r1 and r2, where r2 is
262 * | +-------+--+-----------------------+
264 * +---+-------+--+-----------------------+
269 * Expect to merge two entries into one region that stays the same.
270 * The counter and total size of available memory are not updated.
276 rgn = &memblock.memory.regions[0]; in memblock_add_within_check()
278 struct region r1 = { in memblock_add_within_check()
282 struct region r2 = { in memblock_add_within_check()
293 ASSERT_EQ(rgn->base, r1.base); in memblock_add_within_check()
294 ASSERT_EQ(rgn->size, r1.size); in memblock_add_within_check()
296 ASSERT_EQ(memblock.memory.cnt, 1); in memblock_add_within_check()
297 ASSERT_EQ(memblock.memory.total_size, r1.size); in memblock_add_within_check()
305 * A simple test that tries to add the same memory block twice. Expect
306 * the counter and total size of available memory to not be updated.
310 struct region r = { in memblock_add_twice_check()
322 ASSERT_EQ(memblock.memory.cnt, 1); in memblock_add_twice_check()
323 ASSERT_EQ(memblock.memory.total_size, r.size); in memblock_add_twice_check()
331 * A test that tries to add two memory blocks that don't overlap with one
332 * another and then add a third memory block in the space between the first two:
334 * | +--------+--------+--------+ |
336 * +--------+--------+--------+--------+--+
338 * Expect to merge the three entries into one region that starts at r1.base
339 * and has size of r1.size + r2.size + r3.size. The region counter and total
340 * size of the available memory are updated.
347 rgn = &memblock.memory.regions[0]; in memblock_add_between_check()
349 struct region r1 = { in memblock_add_between_check()
353 struct region r2 = { in memblock_add_between_check()
357 struct region r3 = { in memblock_add_between_check()
371 ASSERT_EQ(rgn->base, r1.base); in memblock_add_between_check()
372 ASSERT_EQ(rgn->size, total_size); in memblock_add_between_check()
374 ASSERT_EQ(memblock.memory.cnt, 1); in memblock_add_between_check()
375 ASSERT_EQ(memblock.memory.total_size, total_size); in memblock_add_between_check()
383 * A simple test that tries to add a memory block r when r extends past
386 * +--------+
388 * +--------+
389 * | +----+
391 * +----------------------------+----+
393 * Expect to add a memory block of size PHYS_ADDR_MAX - r.base. Expect the
394 * total size of available memory and the counter to be updated.
401 rgn = &memblock.memory.regions[0]; in memblock_add_near_max_check()
403 struct region r = { in memblock_add_near_max_check()
404 .base = PHYS_ADDR_MAX - SZ_1M, in memblock_add_near_max_check()
410 total_size = PHYS_ADDR_MAX - r.base; in memblock_add_near_max_check()
415 ASSERT_EQ(rgn->base, r.base); in memblock_add_near_max_check()
416 ASSERT_EQ(rgn->size, total_size); in memblock_add_near_max_check()
418 ASSERT_EQ(memblock.memory.cnt, 1); in memblock_add_near_max_check()
419 ASSERT_EQ(memblock.memory.total_size, total_size); in memblock_add_near_max_check()
448 * A simple test that marks a memory block of a specified base address
449 * and size as reserved and to the collection of reserved memory regions
450 * (memblock.reserved). Expect to create a new entry. The region counter
451 * and total memory size are updated.
459 struct region r = { in memblock_reserve_simple_check()
469 ASSERT_EQ(rgn->base, r.base); in memblock_reserve_simple_check()
470 ASSERT_EQ(rgn->size, r.size); in memblock_reserve_simple_check()
478 * A test that tries to mark two memory blocks that don't overlap as reserved:
480 * | +--+ +----------------+ |
482 * +--------+--+------+----------------+--+
484 * Expect to add two entries to the collection of reserved memory regions
485 * (memblock.reserved). The total size and region counter for
495 struct region r1 = { in memblock_reserve_disjoint_check()
499 struct region r2 = { in memblock_reserve_disjoint_check()
510 ASSERT_EQ(rgn1->base, r1.base); in memblock_reserve_disjoint_check()
511 ASSERT_EQ(rgn1->size, r1.size); in memblock_reserve_disjoint_check()
513 ASSERT_EQ(rgn2->base, r2.base); in memblock_reserve_disjoint_check()
514 ASSERT_EQ(rgn2->size, r2.size); in memblock_reserve_disjoint_check()
525 * A test that tries to mark two memory blocks r1 and r2 as reserved,
529 * | +--------------+--+--------------+ |
531 * +--+--------------+--+--------------+--+
538 * Expect to merge two entries into one region that starts at r2.base and
540 * reserved memory is updated, and the region counter is not updated.
549 struct region r1 = { in memblock_reserve_overlap_top_check()
553 struct region r2 = { in memblock_reserve_overlap_top_check()
560 total_size = (r1.base - r2.base) + r1.size; in memblock_reserve_overlap_top_check()
566 ASSERT_EQ(rgn->base, r2.base); in memblock_reserve_overlap_top_check()
567 ASSERT_EQ(rgn->size, total_size); in memblock_reserve_overlap_top_check()
578 * A test that tries to mark two memory blocks r1 and r2 as reserved,
582 * | +--------------+--+--------------+ |
584 * +--+--------------+--+--------------+--+
591 * Expect to merge two entries into one region that starts at r1.base and
593 * reserved memory is updated, and the region counter is not updated.
602 struct region r1 = { in memblock_reserve_overlap_bottom_check()
606 struct region r2 = { in memblock_reserve_overlap_bottom_check()
613 total_size = (r2.base - r1.base) + r2.size; in memblock_reserve_overlap_bottom_check()
619 ASSERT_EQ(rgn->base, r1.base); in memblock_reserve_overlap_bottom_check()
620 ASSERT_EQ(rgn->size, total_size); in memblock_reserve_overlap_bottom_check()
631 * A test that tries to mark two memory blocks r1 and r2 as reserved,
635 * | +-----+--+---------------------------|
637 * +-+-----+--+---------------------------+
644 * Expect to merge two entries into one region that stays the same. The
645 * counter and total size of available memory are not updated.
653 struct region r1 = { in memblock_reserve_within_check()
657 struct region r2 = { in memblock_reserve_within_check()
668 ASSERT_EQ(rgn->base, r1.base); in memblock_reserve_within_check()
669 ASSERT_EQ(rgn->size, r1.size); in memblock_reserve_within_check()
680 * A simple test that tries to reserve the same memory block twice.
681 * Expect the region counter and total size of reserved memory to not
686 struct region r = { in memblock_reserve_twice_check()
707 * A test that tries to mark two memory blocks that don't overlap as reserved
708 * and then reserve a third memory block in the space between the first two:
710 * | +--------+--------+--------+ |
712 * +--------+--------+--------+--------+--+
714 * Expect to merge the three entries into one reserved region that starts at
715 * r1.base and has size of r1.size + r2.size + r3.size. The region counter and
725 struct region r1 = { in memblock_reserve_between_check()
729 struct region r2 = { in memblock_reserve_between_check()
733 struct region r3 = { in memblock_reserve_between_check()
747 ASSERT_EQ(rgn->base, r1.base); in memblock_reserve_between_check()
748 ASSERT_EQ(rgn->size, total_size); in memblock_reserve_between_check()
759 * A simple test that tries to reserve a memory block r when r extends past
762 * +--------+
764 * +--------+
765 * | +----+
767 * +----------------------------+----+
769 * Expect to reserve a memory block of size PHYS_ADDR_MAX - r.base. Expect the
770 * total size of reserved memory and the counter to be updated.
779 struct region r = { in memblock_reserve_near_max_check()
780 .base = PHYS_ADDR_MAX - SZ_1M, in memblock_reserve_near_max_check()
786 total_size = PHYS_ADDR_MAX - r.base; in memblock_reserve_near_max_check()
791 ASSERT_EQ(rgn->base, r.base); in memblock_reserve_near_max_check()
792 ASSERT_EQ(rgn->size, total_size); in memblock_reserve_near_max_check()
823 * A simple test that tries to remove a region r1 from the array of
824 * available memory regions. By "removing" a region we mean overwriting it
825 * with the next region r2 in memblock.memory:
827 * | ...... +----------------+ |
829 * +--+----+----------+----------------+--+
834 * Expect to add two memory blocks r1 and r2 and then remove r1 so that
835 * r2 is the first available region. The region counter and total size
842 rgn = &memblock.memory.regions[0]; in memblock_remove_simple_check()
844 struct region r1 = { in memblock_remove_simple_check()
848 struct region r2 = { in memblock_remove_simple_check()
860 ASSERT_EQ(rgn->base, r2.base); in memblock_remove_simple_check()
861 ASSERT_EQ(rgn->size, r2.size); in memblock_remove_simple_check()
863 ASSERT_EQ(memblock.memory.cnt, 1); in memblock_remove_simple_check()
864 ASSERT_EQ(memblock.memory.total_size, r2.size); in memblock_remove_simple_check()
872 * A test that tries to remove a region r2 that was not registered as
873 * available memory (i.e. has no corresponding entry in memblock.memory):
875 * +----------------+
877 * +----------------+
878 * | +----+ |
880 * +--+----+------------------------------+
891 rgn = &memblock.memory.regions[0]; in memblock_remove_absent_check()
893 struct region r1 = { in memblock_remove_absent_check()
897 struct region r2 = { in memblock_remove_absent_check()
908 ASSERT_EQ(rgn->base, r1.base); in memblock_remove_absent_check()
909 ASSERT_EQ(rgn->size, r1.size); in memblock_remove_absent_check()
911 ASSERT_EQ(memblock.memory.cnt, 1); in memblock_remove_absent_check()
912 ASSERT_EQ(memblock.memory.total_size, r1.size); in memblock_remove_absent_check()
920 * A test that tries to remove a region r2 that overlaps with the
924 * +-----------------+
926 * +-----------------+
927 * | .........+--------+ |
929 * +-----------------+--------+--------+--+
936 * available memory pool. The regions counter and total size are updated.
943 rgn = &memblock.memory.regions[0]; in memblock_remove_overlap_top_check()
945 struct region r1 = { in memblock_remove_overlap_top_check()
949 struct region r2 = { in memblock_remove_overlap_top_check()
958 total_size = r1_end - r2_end; in memblock_remove_overlap_top_check()
964 ASSERT_EQ(rgn->base, r1.base + r2.base); in memblock_remove_overlap_top_check()
965 ASSERT_EQ(rgn->size, total_size); in memblock_remove_overlap_top_check()
967 ASSERT_EQ(memblock.memory.cnt, 1); in memblock_remove_overlap_top_check()
968 ASSERT_EQ(memblock.memory.total_size, total_size); in memblock_remove_overlap_top_check()
976 * A test that tries to remove a region r2 that overlaps with the end of
977 * the already existing region r1 (that is r2.base < r1.base + r1.size):
979 * +--------------------------------+
981 * +--------------------------------+
982 * | +---+..... |
984 * +-+---+----+---------------------------+
990 * available memory pool. The regions counter and total size are updated.
997 rgn = &memblock.memory.regions[0]; in memblock_remove_overlap_bottom_check()
999 struct region r1 = { in memblock_remove_overlap_bottom_check()
1003 struct region r2 = { in memblock_remove_overlap_bottom_check()
1010 total_size = r2.base - r1.base; in memblock_remove_overlap_bottom_check()
1016 ASSERT_EQ(rgn->base, r1.base); in memblock_remove_overlap_bottom_check()
1017 ASSERT_EQ(rgn->size, total_size); in memblock_remove_overlap_bottom_check()
1019 ASSERT_EQ(memblock.memory.cnt, 1); in memblock_remove_overlap_bottom_check()
1020 ASSERT_EQ(memblock.memory.total_size, total_size); in memblock_remove_overlap_bottom_check()
1028 * A test that tries to remove a region r2 that is within the range of
1032 * +----+
1034 * +----+
1035 * | +-------------+....+---------------+ |
1037 * +-+-------------+----+---------------+-+
1042 * Expect that the region is split into two - one that ends at r2.base and
1044 * region counter and total size are updated.
1051 rgn1 = &memblock.memory.regions[0]; in memblock_remove_within_check()
1052 rgn2 = &memblock.memory.regions[1]; in memblock_remove_within_check()
1054 struct region r1 = { in memblock_remove_within_check()
1058 struct region r2 = { in memblock_remove_within_check()
1065 r1_size = r2.base - r1.base; in memblock_remove_within_check()
1066 r2_size = (r1.base + r1.size) - (r2.base + r2.size); in memblock_remove_within_check()
1073 ASSERT_EQ(rgn1->base, r1.base); in memblock_remove_within_check()
1074 ASSERT_EQ(rgn1->size, r1_size); in memblock_remove_within_check()
1076 ASSERT_EQ(rgn2->base, r2.base + r2.size); in memblock_remove_within_check()
1077 ASSERT_EQ(rgn2->size, r2_size); in memblock_remove_within_check()
1079 ASSERT_EQ(memblock.memory.cnt, 2); in memblock_remove_within_check()
1080 ASSERT_EQ(memblock.memory.total_size, total_size); in memblock_remove_within_check()
1088 * A simple test that tries to remove a region r1 from the array of
1089 * available memory regions when r1 is the only available region.
1090 * Expect to add a memory block r1 and then remove r1 so that a dummy
1091 * region is added. The region counter stays the same, and the total size
1098 rgn = &memblock.memory.regions[0]; in memblock_remove_only_region_check()
1100 struct region r1 = { in memblock_remove_only_region_check()
1111 ASSERT_EQ(rgn->base, 0); in memblock_remove_only_region_check()
1112 ASSERT_EQ(rgn->size, 0); in memblock_remove_only_region_check()
1114 ASSERT_EQ(memblock.memory.cnt, 1); in memblock_remove_only_region_check()
1115 ASSERT_EQ(memblock.memory.total_size, 0); in memblock_remove_only_region_check()
1123 * A simple test that tries remove a region r2 from the array of available
1124 * memory regions when r2 extends past PHYS_ADDR_MAX:
1126 * +--------+
1128 * +--------+
1129 * | +---+....+
1131 * +------------------------+---+----+
1134 * Expect the total size of available memory to be updated and the counter to
1142 rgn = &memblock.memory.regions[0]; in memblock_remove_near_max_check()
1144 struct region r1 = { in memblock_remove_near_max_check()
1145 .base = PHYS_ADDR_MAX - SZ_2M, in memblock_remove_near_max_check()
1149 struct region r2 = { in memblock_remove_near_max_check()
1150 .base = PHYS_ADDR_MAX - SZ_1M, in memblock_remove_near_max_check()
1156 total_size = r1.size - (PHYS_ADDR_MAX - r2.base); in memblock_remove_near_max_check()
1162 ASSERT_EQ(rgn->base, r1.base); in memblock_remove_near_max_check()
1163 ASSERT_EQ(rgn->size, total_size); in memblock_remove_near_max_check()
1165 ASSERT_EQ(memblock.memory.cnt, 1); in memblock_remove_near_max_check()
1166 ASSERT_EQ(memblock.memory.total_size, total_size); in memblock_remove_near_max_check()
1174 * A test that tries to remove a region r3 that overlaps with two existing
1177 * +----------------+
1179 * +----------------+
1180 * | +----+..... ........+--------+
1182 * +----+----+----+---+-------+--------+-----+
1185 * from the available memory pool. Expect the total size of available memory to
1193 rgn1 = &memblock.memory.regions[0]; in memblock_remove_overlap_two_check()
1194 rgn2 = &memblock.memory.regions[1]; in memblock_remove_overlap_two_check()
1196 struct region r1 = { in memblock_remove_overlap_two_check()
1200 struct region r2 = { in memblock_remove_overlap_two_check()
1204 struct region r3 = { in memblock_remove_overlap_two_check()
1213 new_r1_size = r3.base - r1.base; in memblock_remove_overlap_two_check()
1214 new_r2_size = r2_end - r3_end; in memblock_remove_overlap_two_check()
1222 ASSERT_EQ(rgn1->base, r1.base); in memblock_remove_overlap_two_check()
1223 ASSERT_EQ(rgn1->size, new_r1_size); in memblock_remove_overlap_two_check()
1225 ASSERT_EQ(rgn2->base, r3_end); in memblock_remove_overlap_two_check()
1226 ASSERT_EQ(rgn2->size, new_r2_size); in memblock_remove_overlap_two_check()
1228 ASSERT_EQ(memblock.memory.cnt, 2); in memblock_remove_overlap_two_check()
1229 ASSERT_EQ(memblock.memory.total_size, total_size); in memblock_remove_overlap_two_check()
1257 * A simple test that tries to free a memory block r1 that was marked
1258 * earlier as reserved. By "freeing" a region we mean overwriting it with
1261 * | ...... +----+ |
1263 * +--------------+----+-----------+----+-+
1268 * Expect to reserve two memory regions and then erase r1 region with the
1269 * value of r2. The region counter and total size are updated.
1277 struct region r1 = { in memblock_free_simple_check()
1281 struct region r2 = { in memblock_free_simple_check()
1293 ASSERT_EQ(rgn->base, r2.base); in memblock_free_simple_check()
1294 ASSERT_EQ(rgn->size, r2.size); in memblock_free_simple_check()
1305 * A test that tries to free a region r2 that was not marked as reserved
1308 * +----------------+
1310 * +----------------+
1311 * | +----+ |
1313 * +--+----+------------------------------+
1326 struct region r1 = { in memblock_free_absent_check()
1330 struct region r2 = { in memblock_free_absent_check()
1341 ASSERT_EQ(rgn->base, r1.base); in memblock_free_absent_check()
1342 ASSERT_EQ(rgn->size, r1.size); in memblock_free_absent_check()
1353 * A test that tries to free a region r2 that overlaps with the beginning
1356 * +----+
1358 * +----+
1359 * | ...+--------------+ |
1361 * +----+--+--------------+---------------+
1378 struct region r1 = { in memblock_free_overlap_top_check()
1382 struct region r2 = { in memblock_free_overlap_top_check()
1389 total_size = (r1.size + r1.base) - (r2.base + r2.size); in memblock_free_overlap_top_check()
1395 ASSERT_EQ(rgn->base, r2.base + r2.size); in memblock_free_overlap_top_check()
1396 ASSERT_EQ(rgn->size, total_size); in memblock_free_overlap_top_check()
1407 * A test that tries to free a region r2 that overlaps with the end of
1410 * +----------------+
1412 * +----------------+
1413 * | +-----------+..... |
1415 * +----+-----------+----+----------------+
1427 struct region r1 = { in memblock_free_overlap_bottom_check()
1431 struct region r2 = { in memblock_free_overlap_bottom_check()
1438 total_size = r2.base - r1.base; in memblock_free_overlap_bottom_check()
1444 ASSERT_EQ(rgn->base, r1.base); in memblock_free_overlap_bottom_check()
1445 ASSERT_EQ(rgn->size, total_size); in memblock_free_overlap_bottom_check()
1456 * A test that tries to free a region r2 that is within the range of the
1460 * +----+
1462 * +----+
1463 * | +------------+....+---------------+
1465 * +----+------------+----+---------------+
1470 * Expect that the region is split into two - one that ends at r2.base and
1472 * region counter and total size fields are updated.
1482 struct region r1 = { in memblock_free_within_check()
1486 struct region r2 = { in memblock_free_within_check()
1493 r1_size = r2.base - r1.base; in memblock_free_within_check()
1494 r2_size = (r1.base + r1.size) - (r2.base + r2.size); in memblock_free_within_check()
1501 ASSERT_EQ(rgn1->base, r1.base); in memblock_free_within_check()
1502 ASSERT_EQ(rgn1->size, r1_size); in memblock_free_within_check()
1504 ASSERT_EQ(rgn2->base, r2.base + r2.size); in memblock_free_within_check()
1505 ASSERT_EQ(rgn2->size, r2_size); in memblock_free_within_check()
1516 * A simple test that tries to free a memory block r1 that was marked
1517 * earlier as reserved when r1 is the only available region.
1518 * Expect to reserve a memory block r1 and then free r1 so that r1 is
1519 * overwritten with a dummy region. The region counter stays the same,
1528 struct region r1 = { in memblock_free_only_region_check()
1539 ASSERT_EQ(rgn->base, 0); in memblock_free_only_region_check()
1540 ASSERT_EQ(rgn->size, 0); in memblock_free_only_region_check()
1551 * A simple test that tries free a region r2 when r2 extends past PHYS_ADDR_MAX:
1553 * +--------+
1555 * +--------+
1556 * | +---+....+
1558 * +------------------------+---+----+
1561 * Expect the total size of reserved memory to be updated and the counter to
1571 struct region r1 = { in memblock_free_near_max_check()
1572 .base = PHYS_ADDR_MAX - SZ_2M, in memblock_free_near_max_check()
1576 struct region r2 = { in memblock_free_near_max_check()
1577 .base = PHYS_ADDR_MAX - SZ_1M, in memblock_free_near_max_check()
1583 total_size = r1.size - (PHYS_ADDR_MAX - r2.base); in memblock_free_near_max_check()
1589 ASSERT_EQ(rgn->base, r1.base); in memblock_free_near_max_check()
1590 ASSERT_EQ(rgn->size, total_size); in memblock_free_near_max_check()
1601 * A test that tries to free a reserved region r3 that overlaps with two
1604 * +----------------+
1606 * +----------------+
1607 * | +----+..... ........+--------+
1609 * +----+----+----+---+-------+--------+-----+
1612 * from the collection of reserved memory. Expect the total size of reserved
1613 * memory to be updated and the counter to not be updated.
1623 struct region r1 = { in memblock_free_overlap_two_check()
1627 struct region r2 = { in memblock_free_overlap_two_check()
1631 struct region r3 = { in memblock_free_overlap_two_check()
1640 new_r1_size = r3.base - r1.base; in memblock_free_overlap_two_check()
1641 new_r2_size = r2_end - r3_end; in memblock_free_overlap_two_check()
1649 ASSERT_EQ(rgn1->base, r1.base); in memblock_free_overlap_two_check()
1650 ASSERT_EQ(rgn1->size, new_r1_size); in memblock_free_overlap_two_check()
1652 ASSERT_EQ(rgn2->base, r3_end); in memblock_free_overlap_two_check()
1653 ASSERT_EQ(rgn2->size, new_r2_size); in memblock_free_overlap_two_check()
1728 * A test that tries to trim memory when both ends of the memory region are
1729 * aligned. Expect that the memory will not be trimmed. Expect the counter to
1737 rgn = &memblock.memory.regions[0]; in memblock_trim_memory_aligned_check()
1739 struct region r = { in memblock_trim_memory_aligned_check()
1750 ASSERT_EQ(rgn->base, r.base); in memblock_trim_memory_aligned_check()
1751 ASSERT_EQ(rgn->size, r.size); in memblock_trim_memory_aligned_check()
1753 ASSERT_EQ(memblock.memory.cnt, 1); in memblock_trim_memory_aligned_check()
1761 * A test that tries to trim memory when there are two available regions, r1 and
1762 * r2. Region r1 is aligned on both ends and region r2 is unaligned on one end
1766 * |--------|
1767 * | +-----------------+ +------+ |
1769 * +--------+-----------------+--------+------+---+
1783 rgn = &memblock.memory.regions[0]; in memblock_trim_memory_too_small_check()
1785 struct region r1 = { in memblock_trim_memory_too_small_check()
1789 struct region r2 = { in memblock_trim_memory_too_small_check()
1791 .size = alignment - SZ_2 in memblock_trim_memory_too_small_check()
1801 ASSERT_EQ(rgn->base, r1.base); in memblock_trim_memory_too_small_check()
1802 ASSERT_EQ(rgn->size, r1.size); in memblock_trim_memory_too_small_check()
1804 ASSERT_EQ(memblock.memory.cnt, 1); in memblock_trim_memory_too_small_check()
1812 * A test that tries to trim memory when there are two available regions, r1 and
1813 * r2. Region r1 is aligned on both ends and region r2 is unaligned at the base
1819 * | +-----------------+ +---------------+ |
1821 * +--------+-----------------+----------+---------------+---+
1837 rgn1 = &memblock.memory.regions[0]; in memblock_trim_memory_unaligned_base_check()
1838 rgn2 = &memblock.memory.regions[1]; in memblock_trim_memory_unaligned_base_check()
1840 struct region r1 = { in memblock_trim_memory_unaligned_base_check()
1844 struct region r2 = { in memblock_trim_memory_unaligned_base_check()
1846 .size = alignment * 2 - offset in memblock_trim_memory_unaligned_base_check()
1851 new_r2_base = r2.base + (alignment - offset); in memblock_trim_memory_unaligned_base_check()
1852 new_r2_size = r2.size - (alignment - offset); in memblock_trim_memory_unaligned_base_check()
1859 ASSERT_EQ(rgn1->base, r1.base); in memblock_trim_memory_unaligned_base_check()
1860 ASSERT_EQ(rgn1->size, r1.size); in memblock_trim_memory_unaligned_base_check()
1862 ASSERT_EQ(rgn2->base, new_r2_base); in memblock_trim_memory_unaligned_base_check()
1863 ASSERT_EQ(rgn2->size, new_r2_size); in memblock_trim_memory_unaligned_base_check()
1865 ASSERT_EQ(memblock.memory.cnt, 2); in memblock_trim_memory_unaligned_base_check()
1873 * A test that tries to trim memory when there are two available regions, r1 and
1874 * r2. Region r1 is aligned on both ends and region r2 is aligned at the base
1880 * | +-----------------+ +---------------+ |
1882 * +--------+-----------------+--------+---------------+---+
1898 rgn1 = &memblock.memory.regions[0]; in memblock_trim_memory_unaligned_end_check()
1899 rgn2 = &memblock.memory.regions[1]; in memblock_trim_memory_unaligned_end_check()
1901 struct region r1 = { in memblock_trim_memory_unaligned_end_check()
1905 struct region r2 = { in memblock_trim_memory_unaligned_end_check()
1907 .size = alignment * 2 - offset in memblock_trim_memory_unaligned_end_check()
1912 new_r2_size = r2.size - (alignment - offset); in memblock_trim_memory_unaligned_end_check()
1919 ASSERT_EQ(rgn1->base, r1.base); in memblock_trim_memory_unaligned_end_check()
1920 ASSERT_EQ(rgn1->size, r1.size); in memblock_trim_memory_unaligned_end_check()
1922 ASSERT_EQ(rgn2->base, r2.base); in memblock_trim_memory_unaligned_end_check()
1923 ASSERT_EQ(rgn2->size, new_r2_size); in memblock_trim_memory_unaligned_end_check()
1925 ASSERT_EQ(memblock.memory.cnt, 2); in memblock_trim_memory_unaligned_end_check()