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()
427 * A test that trying to add the 129th memory block.
429 * memblock.memory.max, find a new valid memory as
430 * memory.regions.
436 struct region r = { in memblock_add_many_check()
451 * We allocated enough memory by using dummy_physical_memory_init(), and in memblock_add_many_check()
452 * split it into small block. First we split a large enough memory block in memblock_add_many_check()
453 * as the memory region which will be choosed by memblock_double_array(). in memblock_add_many_check()
460 /* This is the base of small memory block. */ in memblock_add_many_check()
463 orig_region = memblock.memory.regions; in memblock_add_many_check()
468 * gap between the nearby memory to avoid being merged. in memblock_add_many_check()
473 ASSERT_EQ(memblock.memory.cnt, i + 2); in memblock_add_many_check()
474 ASSERT_EQ(memblock.memory.total_size, new_memory_regions_size + in memblock_add_many_check()
480 * update the memory.max. in memblock_add_many_check()
482 ASSERT_EQ(memblock.memory.max, INIT_MEMBLOCK_REGIONS * 2); in memblock_add_many_check()
484 /* memblock_double_array() will reserve the memory it used. Check it. */ in memblock_add_many_check()
493 ASSERT_EQ(memblock.memory.regions[0].base, r.base); in memblock_add_many_check()
494 ASSERT_EQ(memblock.memory.regions[0].size, r.size); in memblock_add_many_check()
496 ASSERT_EQ(memblock.memory.cnt, INIT_MEMBLOCK_REGIONS + 2); in memblock_add_many_check()
497 ASSERT_EQ(memblock.memory.total_size, INIT_MEMBLOCK_REGIONS * size + in memblock_add_many_check()
500 ASSERT_EQ(memblock.memory.max, INIT_MEMBLOCK_REGIONS * 2); in memblock_add_many_check()
505 * The current memory.regions is occupying a range of memory that in memblock_add_many_check()
506 * allocated from dummy_physical_memory_init(). After free the memory, in memblock_add_many_check()
507 * we must not use it. So restore the origin memory region to make sure in memblock_add_many_check()
510 memblock.memory.regions = orig_region; in memblock_add_many_check()
511 memblock.memory.cnt = INIT_MEMBLOCK_REGIONS; in memblock_add_many_check()
541 * A simple test that marks a memory block of a specified base address
542 * and size as reserved and to the collection of reserved memory regions
543 * (memblock.reserved). Expect to create a new entry. The region counter
544 * and total memory size are updated.
552 struct region r = { in memblock_reserve_simple_check()
562 ASSERT_EQ(rgn->base, r.base); in memblock_reserve_simple_check()
563 ASSERT_EQ(rgn->size, r.size); in memblock_reserve_simple_check()
571 * A test that tries to mark two memory blocks that don't overlap as reserved:
573 * | +--+ +----------------+ |
575 * +--------+--+------+----------------+--+
577 * Expect to add two entries to the collection of reserved memory regions
578 * (memblock.reserved). The total size and region counter for
588 struct region r1 = { in memblock_reserve_disjoint_check()
592 struct region r2 = { in memblock_reserve_disjoint_check()
603 ASSERT_EQ(rgn1->base, r1.base); in memblock_reserve_disjoint_check()
604 ASSERT_EQ(rgn1->size, r1.size); in memblock_reserve_disjoint_check()
606 ASSERT_EQ(rgn2->base, r2.base); in memblock_reserve_disjoint_check()
607 ASSERT_EQ(rgn2->size, r2.size); in memblock_reserve_disjoint_check()
618 * A test that tries to mark two memory blocks r1 and r2 as reserved,
622 * | +--------------+--+--------------+ |
624 * +--+--------------+--+--------------+--+
631 * Expect to merge two entries into one region that starts at r2.base and
633 * reserved memory is updated, and the region counter is not updated.
642 struct region r1 = { in memblock_reserve_overlap_top_check()
646 struct region r2 = { in memblock_reserve_overlap_top_check()
653 total_size = (r1.base - r2.base) + r1.size; in memblock_reserve_overlap_top_check()
659 ASSERT_EQ(rgn->base, r2.base); in memblock_reserve_overlap_top_check()
660 ASSERT_EQ(rgn->size, total_size); in memblock_reserve_overlap_top_check()
671 * A test that tries to mark two memory blocks r1 and r2 as reserved,
675 * | +--------------+--+--------------+ |
677 * +--+--------------+--+--------------+--+
684 * Expect to merge two entries into one region that starts at r1.base and
686 * reserved memory is updated, and the region counter is not updated.
695 struct region r1 = { in memblock_reserve_overlap_bottom_check()
699 struct region r2 = { in memblock_reserve_overlap_bottom_check()
706 total_size = (r2.base - r1.base) + r2.size; in memblock_reserve_overlap_bottom_check()
712 ASSERT_EQ(rgn->base, r1.base); in memblock_reserve_overlap_bottom_check()
713 ASSERT_EQ(rgn->size, total_size); in memblock_reserve_overlap_bottom_check()
724 * A test that tries to mark two memory blocks r1 and r2 as reserved,
728 * | +-----+--+---------------------------|
730 * +-+-----+--+---------------------------+
737 * Expect to merge two entries into one region that stays the same. The
738 * counter and total size of available memory are not updated.
746 struct region r1 = { in memblock_reserve_within_check()
750 struct region r2 = { in memblock_reserve_within_check()
761 ASSERT_EQ(rgn->base, r1.base); in memblock_reserve_within_check()
762 ASSERT_EQ(rgn->size, r1.size); in memblock_reserve_within_check()
773 * A simple test that tries to reserve the same memory block twice.
774 * Expect the region counter and total size of reserved memory to not
779 struct region r = { in memblock_reserve_twice_check()
800 * A test that tries to mark two memory blocks that don't overlap as reserved
801 * and then reserve a third memory block in the space between the first two:
803 * | +--------+--------+--------+ |
805 * +--------+--------+--------+--------+--+
807 * Expect to merge the three entries into one reserved region that starts at
808 * r1.base and has size of r1.size + r2.size + r3.size. The region counter and
818 struct region r1 = { in memblock_reserve_between_check()
822 struct region r2 = { in memblock_reserve_between_check()
826 struct region r3 = { in memblock_reserve_between_check()
840 ASSERT_EQ(rgn->base, r1.base); in memblock_reserve_between_check()
841 ASSERT_EQ(rgn->size, total_size); in memblock_reserve_between_check()
852 * A simple test that tries to reserve a memory block r when r extends past
855 * +--------+
857 * +--------+
858 * | +----+
860 * +----------------------------+----+
862 * Expect to reserve a memory block of size PHYS_ADDR_MAX - r.base. Expect the
863 * total size of reserved memory and the counter to be updated.
872 struct region r = { in memblock_reserve_near_max_check()
873 .base = PHYS_ADDR_MAX - SZ_1M, in memblock_reserve_near_max_check()
879 total_size = PHYS_ADDR_MAX - r.base; in memblock_reserve_near_max_check()
884 ASSERT_EQ(rgn->base, r.base); in memblock_reserve_near_max_check()
885 ASSERT_EQ(rgn->size, total_size); in memblock_reserve_near_max_check()
896 * A test that trying to reserve the 129th memory block.
898 * memblock.memory.max, find a new valid memory as
905 struct region r = { in memblock_reserve_many_check()
917 /* Add a valid memory region used by double_array(). */ in memblock_reserve_many_check()
922 /* Reserve some fakes memory region to fulfill the memblock. */ in memblock_reserve_many_check()
928 /* Keep the gap so these memory region will not be merged. */ in memblock_reserve_many_check()
938 * This is the memory region size used by the doubled reserved.regions, in memblock_reserve_many_check()
945 * The double_array() will find a free memory region as the new in memblock_reserve_many_check()
946 * reserved.regions, and the used memory region will be reserved, so in memblock_reserve_many_check()
947 * there will be one more region exist in the reserved memblock. And the in memblock_reserve_many_check()
948 * one more reserved region's size is new_reserved_regions_size. in memblock_reserve_many_check()
972 * The current reserved.regions is occupying a range of memory that in memblock_reserve_many_check()
973 * allocated from dummy_physical_memory_init(). After free the memory, in memblock_reserve_many_check()
974 * we must not use it. So restore the origin memory region to make sure in memblock_reserve_many_check()
1007 * A simple test that tries to remove a region r1 from the array of
1008 * available memory regions. By "removing" a region we mean overwriting it
1009 * with the next region r2 in memblock.memory:
1011 * | ...... +----------------+ |
1013 * +--+----+----------+----------------+--+
1018 * Expect to add two memory blocks r1 and r2 and then remove r1 so that
1019 * r2 is the first available region. The region counter and total size
1026 rgn = &memblock.memory.regions[0]; in memblock_remove_simple_check()
1028 struct region r1 = { in memblock_remove_simple_check()
1032 struct region r2 = { in memblock_remove_simple_check()
1044 ASSERT_EQ(rgn->base, r2.base); in memblock_remove_simple_check()
1045 ASSERT_EQ(rgn->size, r2.size); in memblock_remove_simple_check()
1047 ASSERT_EQ(memblock.memory.cnt, 1); in memblock_remove_simple_check()
1048 ASSERT_EQ(memblock.memory.total_size, r2.size); in memblock_remove_simple_check()
1056 * A test that tries to remove a region r2 that was not registered as
1057 * available memory (i.e. has no corresponding entry in memblock.memory):
1059 * +----------------+
1061 * +----------------+
1062 * | +----+ |
1064 * +--+----+------------------------------+
1075 rgn = &memblock.memory.regions[0]; in memblock_remove_absent_check()
1077 struct region r1 = { in memblock_remove_absent_check()
1081 struct region r2 = { in memblock_remove_absent_check()
1092 ASSERT_EQ(rgn->base, r1.base); in memblock_remove_absent_check()
1093 ASSERT_EQ(rgn->size, r1.size); in memblock_remove_absent_check()
1095 ASSERT_EQ(memblock.memory.cnt, 1); in memblock_remove_absent_check()
1096 ASSERT_EQ(memblock.memory.total_size, r1.size); in memblock_remove_absent_check()
1104 * A test that tries to remove a region r2 that overlaps with the
1108 * +-----------------+
1110 * +-----------------+
1111 * | .........+--------+ |
1113 * +-----------------+--------+--------+--+
1120 * available memory pool. The regions counter and total size are updated.
1127 rgn = &memblock.memory.regions[0]; in memblock_remove_overlap_top_check()
1129 struct region r1 = { in memblock_remove_overlap_top_check()
1133 struct region r2 = { in memblock_remove_overlap_top_check()
1142 total_size = r1_end - r2_end; in memblock_remove_overlap_top_check()
1148 ASSERT_EQ(rgn->base, r1.base + r2.base); in memblock_remove_overlap_top_check()
1149 ASSERT_EQ(rgn->size, total_size); in memblock_remove_overlap_top_check()
1151 ASSERT_EQ(memblock.memory.cnt, 1); in memblock_remove_overlap_top_check()
1152 ASSERT_EQ(memblock.memory.total_size, total_size); in memblock_remove_overlap_top_check()
1160 * A test that tries to remove a region r2 that overlaps with the end of
1161 * the already existing region r1 (that is r2.base < r1.base + r1.size):
1163 * +--------------------------------+
1165 * +--------------------------------+
1166 * | +---+..... |
1168 * +-+---+----+---------------------------+
1174 * available memory pool. The regions counter and total size are updated.
1181 rgn = &memblock.memory.regions[0]; in memblock_remove_overlap_bottom_check()
1183 struct region r1 = { in memblock_remove_overlap_bottom_check()
1187 struct region r2 = { in memblock_remove_overlap_bottom_check()
1194 total_size = r2.base - r1.base; in memblock_remove_overlap_bottom_check()
1200 ASSERT_EQ(rgn->base, r1.base); in memblock_remove_overlap_bottom_check()
1201 ASSERT_EQ(rgn->size, total_size); in memblock_remove_overlap_bottom_check()
1203 ASSERT_EQ(memblock.memory.cnt, 1); in memblock_remove_overlap_bottom_check()
1204 ASSERT_EQ(memblock.memory.total_size, total_size); in memblock_remove_overlap_bottom_check()
1212 * A test that tries to remove a region r2 that is within the range of
1216 * +----+
1218 * +----+
1219 * | +-------------+....+---------------+ |
1221 * +-+-------------+----+---------------+-+
1226 * Expect that the region is split into two - one that ends at r2.base and
1228 * region counter and total size are updated.
1235 rgn1 = &memblock.memory.regions[0]; in memblock_remove_within_check()
1236 rgn2 = &memblock.memory.regions[1]; in memblock_remove_within_check()
1238 struct region r1 = { in memblock_remove_within_check()
1242 struct region r2 = { in memblock_remove_within_check()
1249 r1_size = r2.base - r1.base; in memblock_remove_within_check()
1250 r2_size = (r1.base + r1.size) - (r2.base + r2.size); in memblock_remove_within_check()
1257 ASSERT_EQ(rgn1->base, r1.base); in memblock_remove_within_check()
1258 ASSERT_EQ(rgn1->size, r1_size); in memblock_remove_within_check()
1260 ASSERT_EQ(rgn2->base, r2.base + r2.size); in memblock_remove_within_check()
1261 ASSERT_EQ(rgn2->size, r2_size); in memblock_remove_within_check()
1263 ASSERT_EQ(memblock.memory.cnt, 2); in memblock_remove_within_check()
1264 ASSERT_EQ(memblock.memory.total_size, total_size); in memblock_remove_within_check()
1272 * A simple test that tries to remove a region r1 from the array of
1273 * available memory regions when r1 is the only available region.
1274 * Expect to add a memory block r1 and then remove r1 so that a dummy
1275 * region is added. The region counter stays the same, and the total size
1282 rgn = &memblock.memory.regions[0]; in memblock_remove_only_region_check()
1284 struct region r1 = { in memblock_remove_only_region_check()
1295 ASSERT_EQ(rgn->base, 0); in memblock_remove_only_region_check()
1296 ASSERT_EQ(rgn->size, 0); in memblock_remove_only_region_check()
1298 ASSERT_EQ(memblock.memory.cnt, 1); in memblock_remove_only_region_check()
1299 ASSERT_EQ(memblock.memory.total_size, 0); in memblock_remove_only_region_check()
1307 * A simple test that tries remove a region r2 from the array of available
1308 * memory regions when r2 extends past PHYS_ADDR_MAX:
1310 * +--------+
1312 * +--------+
1313 * | +---+....+
1315 * +------------------------+---+----+
1318 * Expect the total size of available memory to be updated and the counter to
1326 rgn = &memblock.memory.regions[0]; in memblock_remove_near_max_check()
1328 struct region r1 = { in memblock_remove_near_max_check()
1329 .base = PHYS_ADDR_MAX - SZ_2M, in memblock_remove_near_max_check()
1333 struct region r2 = { in memblock_remove_near_max_check()
1334 .base = PHYS_ADDR_MAX - SZ_1M, in memblock_remove_near_max_check()
1340 total_size = r1.size - (PHYS_ADDR_MAX - r2.base); in memblock_remove_near_max_check()
1346 ASSERT_EQ(rgn->base, r1.base); in memblock_remove_near_max_check()
1347 ASSERT_EQ(rgn->size, total_size); in memblock_remove_near_max_check()
1349 ASSERT_EQ(memblock.memory.cnt, 1); in memblock_remove_near_max_check()
1350 ASSERT_EQ(memblock.memory.total_size, total_size); in memblock_remove_near_max_check()
1358 * A test that tries to remove a region r3 that overlaps with two existing
1361 * +----------------+
1363 * +----------------+
1364 * | +----+..... ........+--------+
1366 * +----+----+----+---+-------+--------+-----+
1369 * from the available memory pool. Expect the total size of available memory to
1377 rgn1 = &memblock.memory.regions[0]; in memblock_remove_overlap_two_check()
1378 rgn2 = &memblock.memory.regions[1]; in memblock_remove_overlap_two_check()
1380 struct region r1 = { in memblock_remove_overlap_two_check()
1384 struct region r2 = { in memblock_remove_overlap_two_check()
1388 struct region r3 = { in memblock_remove_overlap_two_check()
1397 new_r1_size = r3.base - r1.base; in memblock_remove_overlap_two_check()
1398 new_r2_size = r2_end - r3_end; in memblock_remove_overlap_two_check()
1406 ASSERT_EQ(rgn1->base, r1.base); in memblock_remove_overlap_two_check()
1407 ASSERT_EQ(rgn1->size, new_r1_size); in memblock_remove_overlap_two_check()
1409 ASSERT_EQ(rgn2->base, r3_end); in memblock_remove_overlap_two_check()
1410 ASSERT_EQ(rgn2->size, new_r2_size); in memblock_remove_overlap_two_check()
1412 ASSERT_EQ(memblock.memory.cnt, 2); in memblock_remove_overlap_two_check()
1413 ASSERT_EQ(memblock.memory.total_size, total_size); in memblock_remove_overlap_two_check()
1441 * A simple test that tries to free a memory block r1 that was marked
1442 * earlier as reserved. By "freeing" a region we mean overwriting it with
1445 * | ...... +----+ |
1447 * +--------------+----+-----------+----+-+
1452 * Expect to reserve two memory regions and then erase r1 region with the
1453 * value of r2. The region counter and total size are updated.
1461 struct region r1 = { in memblock_free_simple_check()
1465 struct region r2 = { in memblock_free_simple_check()
1477 ASSERT_EQ(rgn->base, r2.base); in memblock_free_simple_check()
1478 ASSERT_EQ(rgn->size, r2.size); in memblock_free_simple_check()
1489 * A test that tries to free a region r2 that was not marked as reserved
1492 * +----------------+
1494 * +----------------+
1495 * | +----+ |
1497 * +--+----+------------------------------+
1510 struct region r1 = { in memblock_free_absent_check()
1514 struct region r2 = { in memblock_free_absent_check()
1525 ASSERT_EQ(rgn->base, r1.base); in memblock_free_absent_check()
1526 ASSERT_EQ(rgn->size, r1.size); in memblock_free_absent_check()
1537 * A test that tries to free a region r2 that overlaps with the beginning
1540 * +----+
1542 * +----+
1543 * | ...+--------------+ |
1545 * +----+--+--------------+---------------+
1562 struct region r1 = { in memblock_free_overlap_top_check()
1566 struct region r2 = { in memblock_free_overlap_top_check()
1573 total_size = (r1.size + r1.base) - (r2.base + r2.size); in memblock_free_overlap_top_check()
1579 ASSERT_EQ(rgn->base, r2.base + r2.size); in memblock_free_overlap_top_check()
1580 ASSERT_EQ(rgn->size, total_size); in memblock_free_overlap_top_check()
1591 * A test that tries to free a region r2 that overlaps with the end of
1594 * +----------------+
1596 * +----------------+
1597 * | +-----------+..... |
1599 * +----+-----------+----+----------------+
1611 struct region r1 = { in memblock_free_overlap_bottom_check()
1615 struct region r2 = { in memblock_free_overlap_bottom_check()
1622 total_size = r2.base - r1.base; in memblock_free_overlap_bottom_check()
1628 ASSERT_EQ(rgn->base, r1.base); in memblock_free_overlap_bottom_check()
1629 ASSERT_EQ(rgn->size, total_size); in memblock_free_overlap_bottom_check()
1640 * A test that tries to free a region r2 that is within the range of the
1644 * +----+
1646 * +----+
1647 * | +------------+....+---------------+
1649 * +----+------------+----+---------------+
1654 * Expect that the region is split into two - one that ends at r2.base and
1656 * region counter and total size fields are updated.
1666 struct region r1 = { in memblock_free_within_check()
1670 struct region r2 = { in memblock_free_within_check()
1677 r1_size = r2.base - r1.base; in memblock_free_within_check()
1678 r2_size = (r1.base + r1.size) - (r2.base + r2.size); in memblock_free_within_check()
1685 ASSERT_EQ(rgn1->base, r1.base); in memblock_free_within_check()
1686 ASSERT_EQ(rgn1->size, r1_size); in memblock_free_within_check()
1688 ASSERT_EQ(rgn2->base, r2.base + r2.size); in memblock_free_within_check()
1689 ASSERT_EQ(rgn2->size, r2_size); in memblock_free_within_check()
1700 * A simple test that tries to free a memory block r1 that was marked
1701 * earlier as reserved when r1 is the only available region.
1702 * Expect to reserve a memory block r1 and then free r1 so that r1 is
1703 * overwritten with a dummy region. The region counter stays the same,
1712 struct region r1 = { in memblock_free_only_region_check()
1723 ASSERT_EQ(rgn->base, 0); in memblock_free_only_region_check()
1724 ASSERT_EQ(rgn->size, 0); in memblock_free_only_region_check()
1735 * A simple test that tries free a region r2 when r2 extends past PHYS_ADDR_MAX:
1737 * +--------+
1739 * +--------+
1740 * | +---+....+
1742 * +------------------------+---+----+
1745 * Expect the total size of reserved memory to be updated and the counter to
1755 struct region r1 = { in memblock_free_near_max_check()
1756 .base = PHYS_ADDR_MAX - SZ_2M, in memblock_free_near_max_check()
1760 struct region r2 = { in memblock_free_near_max_check()
1761 .base = PHYS_ADDR_MAX - SZ_1M, in memblock_free_near_max_check()
1767 total_size = r1.size - (PHYS_ADDR_MAX - r2.base); in memblock_free_near_max_check()
1773 ASSERT_EQ(rgn->base, r1.base); in memblock_free_near_max_check()
1774 ASSERT_EQ(rgn->size, total_size); in memblock_free_near_max_check()
1785 * A test that tries to free a reserved region r3 that overlaps with two
1788 * +----------------+
1790 * +----------------+
1791 * | +----+..... ........+--------+
1793 * +----+----+----+---+-------+--------+-----+
1796 * from the collection of reserved memory. Expect the total size of reserved
1797 * memory to be updated and the counter to not be updated.
1807 struct region r1 = { in memblock_free_overlap_two_check()
1811 struct region r2 = { in memblock_free_overlap_two_check()
1815 struct region r3 = { in memblock_free_overlap_two_check()
1824 new_r1_size = r3.base - r1.base; in memblock_free_overlap_two_check()
1825 new_r2_size = r2_end - r3_end; in memblock_free_overlap_two_check()
1833 ASSERT_EQ(rgn1->base, r1.base); in memblock_free_overlap_two_check()
1834 ASSERT_EQ(rgn1->size, new_r1_size); in memblock_free_overlap_two_check()
1836 ASSERT_EQ(rgn2->base, r3_end); in memblock_free_overlap_two_check()
1837 ASSERT_EQ(rgn2->size, new_r2_size); in memblock_free_overlap_two_check()
1912 * A test that tries to trim memory when both ends of the memory region are
1913 * aligned. Expect that the memory will not be trimmed. Expect the counter to
1921 rgn = &memblock.memory.regions[0]; in memblock_trim_memory_aligned_check()
1923 struct region r = { in memblock_trim_memory_aligned_check()
1934 ASSERT_EQ(rgn->base, r.base); in memblock_trim_memory_aligned_check()
1935 ASSERT_EQ(rgn->size, r.size); in memblock_trim_memory_aligned_check()
1937 ASSERT_EQ(memblock.memory.cnt, 1); in memblock_trim_memory_aligned_check()
1945 * A test that tries to trim memory when there are two available regions, r1 and
1946 * r2. Region r1 is aligned on both ends and region r2 is unaligned on one end
1950 * |--------|
1951 * | +-----------------+ +------+ |
1953 * +--------+-----------------+--------+------+---+
1967 rgn = &memblock.memory.regions[0]; in memblock_trim_memory_too_small_check()
1969 struct region r1 = { in memblock_trim_memory_too_small_check()
1973 struct region r2 = { in memblock_trim_memory_too_small_check()
1975 .size = alignment - SZ_2 in memblock_trim_memory_too_small_check()
1985 ASSERT_EQ(rgn->base, r1.base); in memblock_trim_memory_too_small_check()
1986 ASSERT_EQ(rgn->size, r1.size); in memblock_trim_memory_too_small_check()
1988 ASSERT_EQ(memblock.memory.cnt, 1); in memblock_trim_memory_too_small_check()
1996 * A test that tries to trim memory when there are two available regions, r1 and
1997 * r2. Region r1 is aligned on both ends and region r2 is unaligned at the base
2003 * | +-----------------+ +---------------+ |
2005 * +--------+-----------------+----------+---------------+---+
2021 rgn1 = &memblock.memory.regions[0]; in memblock_trim_memory_unaligned_base_check()
2022 rgn2 = &memblock.memory.regions[1]; in memblock_trim_memory_unaligned_base_check()
2024 struct region r1 = { in memblock_trim_memory_unaligned_base_check()
2028 struct region r2 = { in memblock_trim_memory_unaligned_base_check()
2030 .size = alignment * 2 - offset in memblock_trim_memory_unaligned_base_check()
2035 new_r2_base = r2.base + (alignment - offset); in memblock_trim_memory_unaligned_base_check()
2036 new_r2_size = r2.size - (alignment - offset); in memblock_trim_memory_unaligned_base_check()
2043 ASSERT_EQ(rgn1->base, r1.base); in memblock_trim_memory_unaligned_base_check()
2044 ASSERT_EQ(rgn1->size, r1.size); in memblock_trim_memory_unaligned_base_check()
2046 ASSERT_EQ(rgn2->base, new_r2_base); in memblock_trim_memory_unaligned_base_check()
2047 ASSERT_EQ(rgn2->size, new_r2_size); in memblock_trim_memory_unaligned_base_check()
2049 ASSERT_EQ(memblock.memory.cnt, 2); in memblock_trim_memory_unaligned_base_check()
2057 * A test that tries to trim memory when there are two available regions, r1 and
2058 * r2. Region r1 is aligned on both ends and region r2 is aligned at the base
2064 * | +-----------------+ +---------------+ |
2066 * +--------+-----------------+--------+---------------+---+
2082 rgn1 = &memblock.memory.regions[0]; in memblock_trim_memory_unaligned_end_check()
2083 rgn2 = &memblock.memory.regions[1]; in memblock_trim_memory_unaligned_end_check()
2085 struct region r1 = { in memblock_trim_memory_unaligned_end_check()
2089 struct region r2 = { in memblock_trim_memory_unaligned_end_check()
2091 .size = alignment * 2 - offset in memblock_trim_memory_unaligned_end_check()
2096 new_r2_size = r2.size - (alignment - offset); in memblock_trim_memory_unaligned_end_check()
2103 ASSERT_EQ(rgn1->base, r1.base); in memblock_trim_memory_unaligned_end_check()
2104 ASSERT_EQ(rgn1->size, r1.size); in memblock_trim_memory_unaligned_end_check()
2106 ASSERT_EQ(rgn2->base, r2.base); in memblock_trim_memory_unaligned_end_check()
2107 ASSERT_EQ(rgn2->size, new_r2_size); in memblock_trim_memory_unaligned_end_check()
2109 ASSERT_EQ(memblock.memory.cnt, 2); in memblock_trim_memory_unaligned_end_check()