linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] memblock tests: change build options to run-time options
@ 2022-07-14  3:17 Rebecca Mckeever
  2022-07-20  7:38 ` David Hildenbrand
  2022-07-20  7:47 ` Mike Rapoport
  0 siblings, 2 replies; 3+ messages in thread
From: Rebecca Mckeever @ 2022-07-14  3:17 UTC (permalink / raw)
  To: Mike Rapoport, linux-mm, linux-kernel; +Cc: David Hildenbrand, Rebecca Mckeever

Change verbose and movable node build options to run-time options.

Movable node usage:
    $ ./main -m

    Or:
    $ ./main --movable-node

Verbose usage:
    $ ./main -v

    Or:
    $ ./main --verbose

Signed-off-by: Rebecca Mckeever <remckee0@gmail.com>
---
 tools/testing/memblock/Makefile               |  5 --
 tools/testing/memblock/linux/memory_hotplug.h |  8 +-
 tools/testing/memblock/main.c                 |  2 +
 .../testing/memblock/scripts/Makefile.include | 10 ---
 tools/testing/memblock/tests/common.c         | 86 ++++++++++++++++---
 tools/testing/memblock/tests/common.h         | 10 +--
 6 files changed, 79 insertions(+), 42 deletions(-)

diff --git a/tools/testing/memblock/Makefile b/tools/testing/memblock/Makefile
index 9fde49ad73bd..246f7ac8489b 100644
--- a/tools/testing/memblock/Makefile
+++ b/tools/testing/memblock/Makefile
@@ -45,13 +45,8 @@ help:
 	@echo  '  clean		  - Remove generated files and symlinks in the directory'
 	@echo  ''
 	@echo  'Configuration:'
-	@echo  '  make VERBOSE=1            - enable verbose output, which includes the'
-	@echo  '                              names of functions being tested and the'
-	@echo  '                              number of test cases passing'
 	@echo  '  make MEMBLOCK_DEBUG=1     - enable memblock_dbg() messages'
 	@echo  '  make NUMA=1               - simulate enabled NUMA'
-	@echo  '  make MOVABLE_NODE=1       - override `movable_node_is_enabled`'
-	@echo  '                              definition to simulate movable NUMA nodes'
 	@echo  '  make 32BIT_PHYS_ADDR_T=1  - Use 32 bit physical addresses'
 
 vpath %.c ../../lib
diff --git a/tools/testing/memblock/linux/memory_hotplug.h b/tools/testing/memblock/linux/memory_hotplug.h
index 47988765a219..dabe2c556858 100644
--- a/tools/testing/memblock/linux/memory_hotplug.h
+++ b/tools/testing/memblock/linux/memory_hotplug.h
@@ -7,13 +7,11 @@
 #include <linux/cache.h>
 #include <linux/types.h>
 
+extern bool movable_node_enabled;
+
 static inline bool movable_node_is_enabled(void)
 {
-#ifdef MOVABLE_NODE
-	return true;
-#else
-	return false;
-#endif
+	return movable_node_enabled;
 }
 
 #endif
diff --git a/tools/testing/memblock/main.c b/tools/testing/memblock/main.c
index fb183c9e76d1..4ca1024342b1 100644
--- a/tools/testing/memblock/main.c
+++ b/tools/testing/memblock/main.c
@@ -3,9 +3,11 @@
 #include "tests/alloc_api.h"
 #include "tests/alloc_helpers_api.h"
 #include "tests/alloc_nid_api.h"
+#include "tests/common.h"
 
 int main(int argc, char **argv)
 {
+	parse_args(argc, argv);
 	memblock_basic_checks();
 	memblock_alloc_checks();
 	memblock_alloc_helpers_checks();
diff --git a/tools/testing/memblock/scripts/Makefile.include b/tools/testing/memblock/scripts/Makefile.include
index 4401f79bed4c..aa6d82d56a23 100644
--- a/tools/testing/memblock/scripts/Makefile.include
+++ b/tools/testing/memblock/scripts/Makefile.include
@@ -6,11 +6,6 @@ ifeq ($(NUMA), 1)
 	CFLAGS += -D CONFIG_NUMA
 endif
 
-# Simulate movable NUMA memory regions
-ifeq ($(MOVABLE_NODE), 1)
-	CFLAGS += -D MOVABLE_NODE
-endif
-
 # Use 32 bit physical addresses.
 # Remember to install 32-bit version of dependencies.
 ifeq ($(32BIT_PHYS_ADDR_T), 1)
@@ -18,11 +13,6 @@ ifeq ($(32BIT_PHYS_ADDR_T), 1)
 	LDFLAGS += -m32
 endif
 
-# Enable verbose testing output
-ifeq ($(VERBOSE), 1)
-	CFLAGS += -D VERBOSE
-endif
-
 # Enable memblock_dbg() messages
 ifeq ($(MEMBLOCK_DEBUG), 1)
 	CFLAGS += -D MEMBLOCK_DEBUG
diff --git a/tools/testing/memblock/tests/common.c b/tools/testing/memblock/tests/common.c
index ebc06b4c3255..24ce4135a83d 100644
--- a/tools/testing/memblock/tests/common.c
+++ b/tools/testing/memblock/tests/common.c
@@ -1,6 +1,9 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 #include "tests/common.h"
 #include <string.h>
+#include <getopt.h>
+#include <linux/memory_hotplug.h>
+#include <linux/build_bug.h>
 
 #define INIT_MEMBLOCK_REGIONS			128
 #define INIT_MEMBLOCK_RESERVED_REGIONS		INIT_MEMBLOCK_REGIONS
@@ -11,6 +14,27 @@ static struct test_memory memory_block;
 static const char __maybe_unused *prefixes[PREFIXES_MAX];
 static int __maybe_unused nr_prefixes;
 
+static const char *short_opts = "mv";
+static const struct option long_opts[] = {
+	{"movable-node", 0, NULL, 'm'},
+	{"verbose", 0, NULL, 'v'},
+	{NULL, 0, NULL, 0}
+};
+
+static const char * const help_opts[] = {
+	"disallow allocations from regions marked as hotplugged\n\t\t\t"
+		"by simulating enabling the \"movable_node\" kernel\n\t\t\t"
+		"parameter",
+	"enable verbose output, which includes the name of the\n\t\t\t"
+		"memblock function being tested, the name of the test,\n\t\t\t"
+		"and whether the test passed or failed."
+};
+
+static int verbose;
+
+/* sets global variable returned by movable_node_is_enabled() stub */
+bool movable_node_enabled;
+
 void reset_memblock_regions(void)
 {
 	memset(memblock.memory.regions, 0,
@@ -51,7 +75,38 @@ void dummy_physical_memory_cleanup(void)
 	free(memory_block.base);
 }
 
-#ifdef VERBOSE
+static void usage(const char *prog)
+{
+	printf("Usage: %s [-%s]\n", prog, short_opts);
+
+	BUILD_BUG_ON(ARRAY_SIZE(help_opts) != ARRAY_SIZE(long_opts) - 1);
+	for (int i = 0; long_opts[i].name; i++) {
+		printf("  -%c, --%-12s\t%s\n", long_opts[i].val,
+		       long_opts[i].name, help_opts[i]);
+	}
+
+	exit(1);
+}
+
+void parse_args(int argc, char **argv)
+{
+	int c;
+
+	while ((c = getopt_long_only(argc, argv, short_opts, long_opts,
+				     NULL)) != -1) {
+		switch (c) {
+		case 'm':
+			movable_node_enabled = true;
+			break;
+		case 'v':
+			verbose = 1;
+			break;
+		default:
+			usage(argv[0]);
+		}
+	}
+}
+
 void print_prefixes(const char *postfix)
 {
 	for (int i = 0; i < nr_prefixes; i++)
@@ -61,25 +116,31 @@ void print_prefixes(const char *postfix)
 
 void test_fail(void)
 {
-	ksft_test_result_fail(": ");
-	print_prefixes("failed\n");
+	if (verbose) {
+		ksft_test_result_fail(": ");
+		print_prefixes("failed\n");
+	}
 }
 
 void test_pass(void)
 {
-	ksft_test_result_pass(": ");
-	print_prefixes("passed\n");
+	if (verbose) {
+		ksft_test_result_pass(": ");
+		print_prefixes("passed\n");
+	}
 }
 
 void test_print(const char *fmt, ...)
 {
-	int saved_errno = errno;
-	va_list args;
-
-	va_start(args, fmt);
-	errno = saved_errno;
-	vprintf(fmt, args);
-	va_end(args);
+	if (verbose) {
+		int saved_errno = errno;
+		va_list args;
+
+		va_start(args, fmt);
+		errno = saved_errno;
+		vprintf(fmt, args);
+		va_end(args);
+	}
 }
 
 void prefix_reset(void)
@@ -102,4 +163,3 @@ void prefix_pop(void)
 		nr_prefixes--;
 	}
 }
-#endif /* VERBOSE */
diff --git a/tools/testing/memblock/tests/common.h b/tools/testing/memblock/tests/common.h
index 46de86a755f3..3e7f23d341d7 100644
--- a/tools/testing/memblock/tests/common.h
+++ b/tools/testing/memblock/tests/common.h
@@ -70,22 +70,14 @@ void reset_memblock_attributes(void);
 void setup_memblock(void);
 void dummy_physical_memory_init(void);
 void dummy_physical_memory_cleanup(void);
+void parse_args(int argc, char **argv);
 
-#ifdef VERBOSE
 void test_fail(void);
 void test_pass(void);
 void test_print(const char *fmt, ...);
 void prefix_reset(void);
 void prefix_push(const char *prefix);
 void prefix_pop(void);
-#else
-static inline void test_fail(void) {}
-static inline void test_pass(void) {}
-static inline void test_print(const char *fmt, ...) {}
-static inline void prefix_reset(void) {}
-static inline void prefix_push(const char *prefix) {}
-static inline void prefix_pop(void) {}
-#endif /* VERBOSE */
 
 static inline void test_pass_pop(void)
 {
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] memblock tests: change build options to run-time options
  2022-07-14  3:17 [PATCH] memblock tests: change build options to run-time options Rebecca Mckeever
@ 2022-07-20  7:38 ` David Hildenbrand
  2022-07-20  7:47 ` Mike Rapoport
  1 sibling, 0 replies; 3+ messages in thread
From: David Hildenbrand @ 2022-07-20  7:38 UTC (permalink / raw)
  To: Rebecca Mckeever, Mike Rapoport, linux-mm, linux-kernel

On 14.07.22 05:17, Rebecca Mckeever wrote:
> Change verbose and movable node build options to run-time options.
> 
> Movable node usage:
>     $ ./main -m
> 
>     Or:
>     $ ./main --movable-node
> 
> Verbose usage:
>     $ ./main -v
> 
>     Or:
>     $ ./main --verbose
> 
> Signed-off-by: Rebecca Mckeever <remckee0@gmail.com>

LGTM, thanks!

Reviewed-by: David Hildenbrand <david@redhat.com>


-- 
Thanks,

David / dhildenb


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] memblock tests: change build options to run-time options
  2022-07-14  3:17 [PATCH] memblock tests: change build options to run-time options Rebecca Mckeever
  2022-07-20  7:38 ` David Hildenbrand
@ 2022-07-20  7:47 ` Mike Rapoport
  1 sibling, 0 replies; 3+ messages in thread
From: Mike Rapoport @ 2022-07-20  7:47 UTC (permalink / raw)
  To: Rebecca Mckeever; +Cc: linux-mm, linux-kernel, David Hildenbrand

On Wed, Jul 13, 2022 at 10:17:17PM -0500, Rebecca Mckeever wrote:
> Change verbose and movable node build options to run-time options.
> 
> Movable node usage:
>     $ ./main -m
> 
>     Or:
>     $ ./main --movable-node
> 
> Verbose usage:
>     $ ./main -v
> 
>     Or:
>     $ ./main --verbose
> 
> Signed-off-by: Rebecca Mckeever <remckee0@gmail.com>
> ---
>  tools/testing/memblock/Makefile               |  5 --
>  tools/testing/memblock/linux/memory_hotplug.h |  8 +-
>  tools/testing/memblock/main.c                 |  2 +
>  .../testing/memblock/scripts/Makefile.include | 10 ---
>  tools/testing/memblock/tests/common.c         | 86 ++++++++++++++++---
>  tools/testing/memblock/tests/common.h         | 10 +--
>  6 files changed, 79 insertions(+), 42 deletions(-)

Applied, thanks!

-- 
Sincerely yours,
Mike.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-07-20  7:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-14  3:17 [PATCH] memblock tests: change build options to run-time options Rebecca Mckeever
2022-07-20  7:38 ` David Hildenbrand
2022-07-20  7:47 ` Mike Rapoport

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).