Skip to content

Commit e393c09

Browse files
drobnikrppt
authored andcommitted
memblock tests: Add memblock_add_node test
Add a simple test for NUMA-aware variant of memblock_add function. Signed-off-by: Karolina Drobnik <[email protected]> Signed-off-by: Mike Rapoport <[email protected]> Link: https://lore.kernel.org/r/e2d0e6dd264c8c169242b556f7c5b12153f3dee5.1643796665.git.karolinadrobnik@gmail.com
1 parent b4d9689 commit e393c09

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

tools/testing/memblock/tests/basic_api.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,39 @@ static int memblock_add_simple_check(void)
5555
return 0;
5656
}
5757

58+
/*
59+
* A simple test that adds a memory block of a specified base address, size
60+
* NUMA node and memory flags to the collection of available memory regions.
61+
* It checks if the new entry, region counter and total memory size have
62+
* expected values.
63+
*/
64+
static int memblock_add_node_simple_check(void)
65+
{
66+
struct memblock_region *rgn;
67+
68+
rgn = &memblock.memory.regions[0];
69+
70+
struct region r = {
71+
.base = SZ_1M,
72+
.size = SZ_16M
73+
};
74+
75+
reset_memblock();
76+
memblock_add_node(r.base, r.size, 1, MEMBLOCK_HOTPLUG);
77+
78+
assert(rgn->base == r.base);
79+
assert(rgn->size == r.size);
80+
#ifdef CONFIG_NUMA
81+
assert(rgn->nid == 1);
82+
#endif
83+
assert(rgn->flags == MEMBLOCK_HOTPLUG);
84+
85+
assert(memblock.memory.cnt == 1);
86+
assert(memblock.memory.total_size == r.size);
87+
88+
return 0;
89+
}
90+
5891
/*
5992
* A test that tries to add two memory blocks that don't overlap with one
6093
* another. It checks if two correctly initialized entries were added to the
@@ -230,6 +263,7 @@ static int memblock_add_twice_check(void)
230263
static int memblock_add_checks(void)
231264
{
232265
memblock_add_simple_check();
266+
memblock_add_node_simple_check();
233267
memblock_add_disjoint_check();
234268
memblock_add_overlap_top_check();
235269
memblock_add_overlap_bottom_check();

0 commit comments

Comments
 (0)