Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1// SPDX-License-Identifier: GPL-2.0-or-later
2#include "tests/common.h"
3#include <string.h>
4
5#define INIT_MEMBLOCK_REGIONS 128
6#define INIT_MEMBLOCK_RESERVED_REGIONS INIT_MEMBLOCK_REGIONS
7
8static struct test_memory memory_block;
9
10void reset_memblock_regions(void)
11{
12 memset(memblock.memory.regions, 0,
13 memblock.memory.cnt * sizeof(struct memblock_region));
14 memblock.memory.cnt = 1;
15 memblock.memory.max = INIT_MEMBLOCK_REGIONS;
16 memblock.memory.total_size = 0;
17
18 memset(memblock.reserved.regions, 0,
19 memblock.reserved.cnt * sizeof(struct memblock_region));
20 memblock.reserved.cnt = 1;
21 memblock.reserved.max = INIT_MEMBLOCK_RESERVED_REGIONS;
22 memblock.reserved.total_size = 0;
23}
24
25void reset_memblock_attributes(void)
26{
27 memblock.memory.name = "memory";
28 memblock.reserved.name = "reserved";
29 memblock.bottom_up = false;
30 memblock.current_limit = MEMBLOCK_ALLOC_ANYWHERE;
31}
32
33void setup_memblock(void)
34{
35 reset_memblock_regions();
36 memblock_add((phys_addr_t)memory_block.base, MEM_SIZE);
37}
38
39void dummy_physical_memory_init(void)
40{
41 memory_block.base = malloc(MEM_SIZE);
42 assert(memory_block.base);
43}
44
45void dummy_physical_memory_cleanup(void)
46{
47 free(memory_block.base);
48}