From: Karolina Drobnik <karolinadrobnik@gmail.com>
To: linux-mm@kvack.org
Cc: akpm@linux-foundation.org, mike.rapoport@gmail.com,
linux-kernel@vger.kernel.org,
Karolina Drobnik <karolinadrobnik@gmail.com>
Subject: [PATCH 11/16] memblock tests: Add memblock reset function
Date: Thu, 27 Jan 2022 14:21:29 +0100 [thread overview]
Message-ID: <4ceb25e17a162c7e15c1cbe138019a4be48d3c93.1643206612.git.karolinadrobnik@gmail.com> (raw)
In-Reply-To: <cover.1643206612.git.karolinadrobnik@gmail.com>
Memblock simulator needs to be able to reset memblock data structures
between different test cases. Add a function that sets all fields to
their default values.
Add a test checking if memblock is being initialized to expected values.
Signed-off-by: Karolina Drobnik <karolinadrobnik@gmail.com>
---
tools/testing/memblock/Makefile | 4 ++-
tools/testing/memblock/main.c | 2 ++
tools/testing/memblock/tests/basic_api.c | 32 ++++++++++++++++++++++++
tools/testing/memblock/tests/basic_api.h | 10 ++++++++
tools/testing/memblock/tests/common.c | 27 ++++++++++++++++++++
tools/testing/memblock/tests/common.h | 15 +++++++++++
6 files changed, 89 insertions(+), 1 deletion(-)
create mode 100644 tools/testing/memblock/tests/basic_api.c
create mode 100644 tools/testing/memblock/tests/basic_api.h
create mode 100644 tools/testing/memblock/tests/common.c
create mode 100644 tools/testing/memblock/tests/common.h
diff --git a/tools/testing/memblock/Makefile b/tools/testing/memblock/Makefile
index 35105923f235..31c4ef625ede 100644
--- a/tools/testing/memblock/Makefile
+++ b/tools/testing/memblock/Makefile
@@ -5,7 +5,9 @@ CFLAGS += -I. -I../../include -Wall -O2 -fsanitize=address \
-fsanitize=undefined -D CONFIG_PHYS_ADDR_T_64BIT
LDFLAGS += -fsanitize=address -fsanitize=undefined
TARGETS = main
-OFILES = main.o memblock.o lib/slab.o mmzone.o slab.o
+TEST_OFILES = tests/basic_api.o tests/common.o
+DEP_OFILES = memblock.o lib/slab.o mmzone.o slab.o
+OFILES = main.o $(DEP_OFILES) $(TEST_OFILES)
EXTR_SRC = ../../../mm/memblock.c
ifeq ($(BUILD), 32)
diff --git a/tools/testing/memblock/main.c b/tools/testing/memblock/main.c
index 62958da35d0f..da65b0adee91 100644
--- a/tools/testing/memblock/main.c
+++ b/tools/testing/memblock/main.c
@@ -1,6 +1,8 @@
// SPDX-License-Identifier: GPL-2.0-or-later
+#include "tests/basic_api.h"
int main(int argc, char **argv)
{
+ memblock_basic_checks();
return 0;
}
diff --git a/tools/testing/memblock/tests/basic_api.c b/tools/testing/memblock/tests/basic_api.c
new file mode 100644
index 000000000000..7f2597b3dd4d
--- /dev/null
+++ b/tools/testing/memblock/tests/basic_api.c
@@ -0,0 +1,32 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+#include <string.h>
+#include <linux/memblock.h>
+#include "basic_api.h"
+
+#define EXPECTED_MEMBLOCK_REGIONS 128
+
+static int memblock_initialization_check(void)
+{
+ reset_memblock();
+
+ assert(memblock.memory.regions);
+ assert(memblock.memory.cnt == 1);
+ assert(memblock.memory.max == EXPECTED_MEMBLOCK_REGIONS);
+ assert(strcmp(memblock.memory.name, "memory") == 0);
+
+ assert(memblock.reserved.regions);
+ assert(memblock.reserved.cnt == 1);
+ assert(memblock.memory.max == EXPECTED_MEMBLOCK_REGIONS);
+ assert(strcmp(memblock.reserved.name, "reserved") == 0);
+
+ assert(!memblock.bottom_up);
+ assert(memblock.current_limit == MEMBLOCK_ALLOC_ANYWHERE);
+
+ return 0;
+}
+
+int memblock_basic_checks(void)
+{
+ memblock_initialization_check();
+ return 0;
+}
diff --git a/tools/testing/memblock/tests/basic_api.h b/tools/testing/memblock/tests/basic_api.h
new file mode 100644
index 000000000000..1ceecfca1f47
--- /dev/null
+++ b/tools/testing/memblock/tests/basic_api.h
@@ -0,0 +1,10 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+#ifndef _MEMBLOCK_BASIC_H
+#define _MEMBLOCK_BASIC_H
+
+#include <assert.h>
+#include "common.h"
+
+int memblock_basic_checks(void);
+
+#endif
diff --git a/tools/testing/memblock/tests/common.c b/tools/testing/memblock/tests/common.c
new file mode 100644
index 000000000000..03de6eab0c3c
--- /dev/null
+++ b/tools/testing/memblock/tests/common.c
@@ -0,0 +1,27 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+#include "tests/common.h"
+#include <string.h>
+
+#define INIT_MEMBLOCK_REGIONS 128
+#define INIT_MEMBLOCK_RESERVED_REGIONS INIT_MEMBLOCK_REGIONS
+
+void reset_memblock(void)
+{
+ memset(memblock.memory.regions, 0,
+ memblock.memory.cnt * sizeof(struct memblock_region));
+ memset(memblock.reserved.regions, 0,
+ memblock.reserved.cnt * sizeof(struct memblock_region));
+
+ memblock.memory.cnt = 1;
+ memblock.memory.max = INIT_MEMBLOCK_REGIONS;
+ memblock.memory.name = "memory";
+ memblock.memory.total_size = 0;
+
+ memblock.reserved.cnt = 1;
+ memblock.reserved.max = INIT_MEMBLOCK_RESERVED_REGIONS;
+ memblock.reserved.name = "reserved";
+ memblock.reserved.total_size = 0;
+
+ memblock.bottom_up = false;
+ memblock.current_limit = MEMBLOCK_ALLOC_ANYWHERE;
+}
diff --git a/tools/testing/memblock/tests/common.h b/tools/testing/memblock/tests/common.h
new file mode 100644
index 000000000000..48efc4270ea1
--- /dev/null
+++ b/tools/testing/memblock/tests/common.h
@@ -0,0 +1,15 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+#ifndef _MEMBLOCK_TEST_H
+#define _MEMBLOCK_TEST_H
+
+#include <linux/types.h>
+#include <linux/memblock.h>
+
+struct region {
+ phys_addr_t base;
+ phys_addr_t size;
+};
+
+void reset_memblock(void);
+
+#endif
--
2.30.2
next prev parent reply other threads:[~2022-01-27 13:22 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-27 13:21 [PATCH 00/16] Introduce memblock simulator Karolina Drobnik
2022-01-27 13:21 ` [PATCH 01/16] tools: Move gfp.h and slab.h from radix-tree to lib Karolina Drobnik
2022-01-27 13:28 ` Matthew Wilcox
2022-01-28 11:00 ` Karolina Drobnik
2022-01-27 13:36 ` Matthew Wilcox
2022-01-28 11:02 ` Karolina Drobnik
2022-01-28 17:30 ` Karolina Drobnik
2022-01-27 13:21 ` [PATCH 02/16] tools/include: Add phys_addr_t to types.h Karolina Drobnik
2022-01-27 13:21 ` [PATCH 03/16] tools/include: Add _RET_IP_ and math definitions to kernel.h Karolina Drobnik
2022-01-27 13:54 ` Matthew Wilcox
2022-01-28 11:05 ` Karolina Drobnik
2022-01-27 13:21 ` [PATCH 04/16] tools/include: Update atomic.h header Karolina Drobnik
2022-01-27 13:56 ` Matthew Wilcox
2022-01-28 11:08 ` Karolina Drobnik
2022-01-27 13:21 ` [PATCH 05/16] tools/include: Add mm.h file Karolina Drobnik
2022-01-27 13:21 ` [PATCH 06/16] tools/include: Add cache.h stub Karolina Drobnik
2022-01-27 14:00 ` Matthew Wilcox
2022-01-28 11:13 ` Karolina Drobnik
2022-01-28 13:10 ` Matthew Wilcox
2022-01-27 13:21 ` [PATCH 07/16] tools/include: Add io.h stub Karolina Drobnik
2022-01-27 14:09 ` Matthew Wilcox
2022-01-28 11:21 ` Karolina Drobnik
2022-01-30 16:10 ` Mike Rapoport
2022-01-30 17:53 ` Matthew Wilcox
2022-01-30 19:00 ` Mike Rapoport
2022-01-31 10:55 ` Karolina Drobnik
2022-01-31 13:30 ` Arnd Bergmann
2022-01-31 15:18 ` Mike Rapoport
2022-01-31 16:26 ` Arnd Bergmann
2022-01-31 10:54 ` Karolina Drobnik
2022-01-27 13:21 ` [PATCH 08/16] tools/include: Add pfn.h stub Karolina Drobnik
2022-01-27 13:21 ` [PATCH 09/16] tools/include: Add debugfs.h stub Karolina Drobnik
2022-01-27 13:21 ` [PATCH 10/16] memblock tests: Add skeleton of the memblock simulator Karolina Drobnik
2022-01-27 14:02 ` Matthew Wilcox
2022-01-27 14:06 ` Matthew Wilcox
2022-01-28 11:25 ` Karolina Drobnik
2022-01-28 13:11 ` Matthew Wilcox
2022-01-27 13:21 ` Karolina Drobnik [this message]
2022-01-27 13:21 ` [PATCH 12/16] memblock tests: Add memblock_add tests Karolina Drobnik
2022-01-27 13:21 ` [PATCH 13/16] memblock tests: Add memblock_reserve tests Karolina Drobnik
2022-01-27 13:21 ` [PATCH 14/16] memblock tests: Add memblock_remove tests Karolina Drobnik
2022-01-27 13:21 ` [PATCH 15/16] memblock tests: Add memblock_add_node test Karolina Drobnik
2022-01-27 13:21 ` [PATCH 16/16] memblock tests: Add memblock_free tests Karolina Drobnik
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=4ceb25e17a162c7e15c1cbe138019a4be48d3c93.1643206612.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=mike.rapoport@gmail.com \
/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).