From: Karolina Drobnik <karolinadrobnik@gmail.com>
To: linux-mm@kvack.org
Cc: rppt@kernel.org, akpm@linux-foundation.org,
linux-kernel@vger.kernel.org,
Karolina Drobnik <karolinadrobnik@gmail.com>
Subject: [PATCH 2/9] memblock tests: Add simulation of physical memory
Date: Mon, 28 Feb 2022 15:46:44 +0100 [thread overview]
Message-ID: <dce115503c74a6936c44694b00014658a1bb6522.1646055639.git.karolinadrobnik@gmail.com> (raw)
In-Reply-To: <cover.1646055639.git.karolinadrobnik@gmail.com>
Allocation functions that return virtual addresses (with an exception
of _raw variant) clear the allocated memory after reserving it. This
requires valid memory ranges in memblock.memory.
Introduce memory_block variable to store memory that can be registered
with memblock data structure. Move assert.h and size.h includes to common.h
to share them between the test files.
Signed-off-by: Karolina Drobnik <karolinadrobnik@gmail.com>
---
tools/testing/memblock/tests/basic_api.c | 1 -
tools/testing/memblock/tests/basic_api.h | 1 -
tools/testing/memblock/tests/common.c | 19 +++++++++++++++++++
tools/testing/memblock/tests/common.h | 18 ++++++++++++++++++
4 files changed, 37 insertions(+), 2 deletions(-)
diff --git a/tools/testing/memblock/tests/basic_api.c b/tools/testing/memblock/tests/basic_api.c
index d5035a3dcce8..fbc1ce160303 100644
--- a/tools/testing/memblock/tests/basic_api.c
+++ b/tools/testing/memblock/tests/basic_api.c
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: GPL-2.0-or-later
#include <string.h>
#include <linux/memblock.h>
-#include <linux/sizes.h>
#include "basic_api.h"
#define EXPECTED_MEMBLOCK_REGIONS 128
diff --git a/tools/testing/memblock/tests/basic_api.h b/tools/testing/memblock/tests/basic_api.h
index 1ceecfca1f47..1873faa54754 100644
--- a/tools/testing/memblock/tests/basic_api.h
+++ b/tools/testing/memblock/tests/basic_api.h
@@ -2,7 +2,6 @@
#ifndef _MEMBLOCK_BASIC_H
#define _MEMBLOCK_BASIC_H
-#include <assert.h>
#include "common.h"
int memblock_basic_checks(void);
diff --git a/tools/testing/memblock/tests/common.c b/tools/testing/memblock/tests/common.c
index dd7e87c589fe..62d3191f7c9a 100644
--- a/tools/testing/memblock/tests/common.c
+++ b/tools/testing/memblock/tests/common.c
@@ -5,6 +5,8 @@
#define INIT_MEMBLOCK_REGIONS 128
#define INIT_MEMBLOCK_RESERVED_REGIONS INIT_MEMBLOCK_REGIONS
+static struct test_memory memory_block;
+
void reset_memblock_regions(void)
{
memset(memblock.memory.regions, 0,
@@ -27,3 +29,20 @@ void reset_memblock_attributes(void)
memblock.bottom_up = false;
memblock.current_limit = MEMBLOCK_ALLOC_ANYWHERE;
}
+
+void setup_memblock(void)
+{
+ reset_memblock_regions();
+ memblock_add((phys_addr_t)memory_block.base, MEM_SIZE);
+}
+
+void dummy_physical_memory_init(void)
+{
+ memory_block.base = malloc(MEM_SIZE);
+ assert(memory_block.base);
+}
+
+void dummy_physical_memory_cleanup(void)
+{
+ free(memory_block.base);
+}
diff --git a/tools/testing/memblock/tests/common.h b/tools/testing/memblock/tests/common.h
index b864c64fb60f..619054d03219 100644
--- a/tools/testing/memblock/tests/common.h
+++ b/tools/testing/memblock/tests/common.h
@@ -2,8 +2,23 @@
#ifndef _MEMBLOCK_TEST_H
#define _MEMBLOCK_TEST_H
+#include <stdlib.h>
+#include <assert.h>
#include <linux/types.h>
#include <linux/memblock.h>
+#include <linux/sizes.h>
+
+#define MEM_SIZE SZ_16K
+
+/*
+ * Available memory registered with memblock needs to be valid for allocs
+ * test to run. This is a convenience wrapper for memory allocated in
+ * dummy_physical_memory_init() that is later registered with memblock
+ * in setup_memblock().
+ */
+struct test_memory {
+ void *base;
+};
struct region {
phys_addr_t base;
@@ -12,5 +27,8 @@ struct region {
void reset_memblock_regions(void);
void reset_memblock_attributes(void);
+void setup_memblock(void);
+void dummy_physical_memory_init(void);
+void dummy_physical_memory_cleanup(void);
#endif
--
2.30.2
next prev parent reply other threads:[~2022-02-28 14:47 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-28 14:46 [PATCH 0/9] Add tests for memblock allocation functions Karolina Drobnik
2022-02-28 14:46 ` [PATCH 1/9] memblock tests: Split up reset_memblock function Karolina Drobnik
2022-02-28 14:46 ` Karolina Drobnik [this message]
2022-02-28 14:46 ` [PATCH 3/9] memblock tests: Add memblock_alloc tests for top down Karolina Drobnik
2022-02-28 14:46 ` [PATCH 4/9] memblock tests: Add memblock_alloc tests for bottom up Karolina Drobnik
2022-02-28 14:46 ` [PATCH 5/9] memblock tests: Add memblock_alloc_from tests for top down Karolina Drobnik
2022-02-28 14:46 ` [PATCH 6/9] memblock tests: Add memblock_alloc_from tests for bottom up Karolina Drobnik
2022-02-28 14:46 ` [PATCH 7/9] memblock tests: Add memblock_alloc_try_nid tests for top down Karolina Drobnik
2022-02-28 14:46 ` [PATCH 8/9] memblock tests: Add memblock_alloc_try_nid tests for bottom up Karolina Drobnik
2022-02-28 14:46 ` [PATCH 9/9] memblock tests: Add TODO and README files Karolina Drobnik
2022-03-07 18:13 ` Mike Rapoport
2022-03-07 18:17 ` [PATCH 0/9] Add tests for memblock allocation functions Mike Rapoport
2022-03-09 15:10 ` Mike Rapoport
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=dce115503c74a6936c44694b00014658a1bb6522.1646055639.git.karolinadrobnik@gmail.com \
--to=karolinadrobnik@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=rppt@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).