Skip to content

Commit 06c8580

Browse files
remckeerppt
authored andcommitted
memblock tests: change build options to run-time options
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 <[email protected]> Reviewed-by: David Hildenbrand <[email protected]> Signed-off-by: Mike Rapoport <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent fe833b4 commit 06c8580

File tree

6 files changed

+80
-42
lines changed

6 files changed

+80
-42
lines changed

tools/testing/memblock/Makefile

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,8 @@ help:
4545
@echo ' clean - Remove generated files and symlinks in the directory'
4646
@echo ''
4747
@echo 'Configuration:'
48-
@echo ' make VERBOSE=1 - enable verbose output, which includes the'
49-
@echo ' names of functions being tested and the'
50-
@echo ' number of test cases passing'
5148
@echo ' make MEMBLOCK_DEBUG=1 - enable memblock_dbg() messages'
5249
@echo ' make NUMA=1 - simulate enabled NUMA'
53-
@echo ' make MOVABLE_NODE=1 - override `movable_node_is_enabled`'
54-
@echo ' definition to simulate movable NUMA nodes'
5550
@echo ' make 32BIT_PHYS_ADDR_T=1 - Use 32 bit physical addresses'
5651

5752
vpath %.c ../../lib

tools/testing/memblock/linux/memory_hotplug.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,11 @@
77
#include <linux/cache.h>
88
#include <linux/types.h>
99

10+
extern bool movable_node_enabled;
11+
1012
static inline bool movable_node_is_enabled(void)
1113
{
12-
#ifdef MOVABLE_NODE
13-
return true;
14-
#else
15-
return false;
16-
#endif
14+
return movable_node_enabled;
1715
}
1816

1917
#endif

tools/testing/memblock/main.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
#include "tests/alloc_api.h"
44
#include "tests/alloc_helpers_api.h"
55
#include "tests/alloc_nid_api.h"
6+
#include "tests/common.h"
67

78
int main(int argc, char **argv)
89
{
10+
parse_args(argc, argv);
911
memblock_basic_checks();
1012
memblock_alloc_checks();
1113
memblock_alloc_helpers_checks();

tools/testing/memblock/scripts/Makefile.include

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,13 @@ ifeq ($(NUMA), 1)
66
CFLAGS += -D CONFIG_NUMA
77
endif
88

9-
# Simulate movable NUMA memory regions
10-
ifeq ($(MOVABLE_NODE), 1)
11-
CFLAGS += -D MOVABLE_NODE
12-
endif
13-
149
# Use 32 bit physical addresses.
1510
# Remember to install 32-bit version of dependencies.
1611
ifeq ($(32BIT_PHYS_ADDR_T), 1)
1712
CFLAGS += -m32 -U CONFIG_PHYS_ADDR_T_64BIT
1813
LDFLAGS += -m32
1914
endif
2015

21-
# Enable verbose testing output
22-
ifeq ($(VERBOSE), 1)
23-
CFLAGS += -D VERBOSE
24-
endif
25-
2616
# Enable memblock_dbg() messages
2717
ifeq ($(MEMBLOCK_DEBUG), 1)
2818
CFLAGS += -D MEMBLOCK_DEBUG

tools/testing/memblock/tests/common.c

Lines changed: 74 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
// SPDX-License-Identifier: GPL-2.0-or-later
22
#include "tests/common.h"
33
#include <string.h>
4+
#include <getopt.h>
5+
#include <linux/memory_hotplug.h>
6+
#include <linux/build_bug.h>
47

58
#define INIT_MEMBLOCK_REGIONS 128
69
#define INIT_MEMBLOCK_RESERVED_REGIONS INIT_MEMBLOCK_REGIONS
@@ -11,6 +14,27 @@ static struct test_memory memory_block;
1114
static const char __maybe_unused *prefixes[PREFIXES_MAX];
1215
static int __maybe_unused nr_prefixes;
1316

17+
static const char *short_opts = "mv";
18+
static const struct option long_opts[] = {
19+
{"movable-node", 0, NULL, 'm'},
20+
{"verbose", 0, NULL, 'v'},
21+
{NULL, 0, NULL, 0}
22+
};
23+
24+
static const char * const help_opts[] = {
25+
"disallow allocations from regions marked as hotplugged\n\t\t\t"
26+
"by simulating enabling the \"movable_node\" kernel\n\t\t\t"
27+
"parameter",
28+
"enable verbose output, which includes the name of the\n\t\t\t"
29+
"memblock function being tested, the name of the test,\n\t\t\t"
30+
"and whether the test passed or failed."
31+
};
32+
33+
static int verbose;
34+
35+
/* sets global variable returned by movable_node_is_enabled() stub */
36+
bool movable_node_enabled;
37+
1438
void reset_memblock_regions(void)
1539
{
1640
memset(memblock.memory.regions, 0,
@@ -51,7 +75,39 @@ void dummy_physical_memory_cleanup(void)
5175
free(memory_block.base);
5276
}
5377

54-
#ifdef VERBOSE
78+
static void usage(const char *prog)
79+
{
80+
BUILD_BUG_ON(ARRAY_SIZE(help_opts) != ARRAY_SIZE(long_opts) - 1);
81+
82+
printf("Usage: %s [-%s]\n", prog, short_opts);
83+
84+
for (int i = 0; long_opts[i].name; i++) {
85+
printf(" -%c, --%-12s\t%s\n", long_opts[i].val,
86+
long_opts[i].name, help_opts[i]);
87+
}
88+
89+
exit(1);
90+
}
91+
92+
void parse_args(int argc, char **argv)
93+
{
94+
int c;
95+
96+
while ((c = getopt_long_only(argc, argv, short_opts, long_opts,
97+
NULL)) != -1) {
98+
switch (c) {
99+
case 'm':
100+
movable_node_enabled = true;
101+
break;
102+
case 'v':
103+
verbose = 1;
104+
break;
105+
default:
106+
usage(argv[0]);
107+
}
108+
}
109+
}
110+
55111
void print_prefixes(const char *postfix)
56112
{
57113
for (int i = 0; i < nr_prefixes; i++)
@@ -61,25 +117,31 @@ void print_prefixes(const char *postfix)
61117

62118
void test_fail(void)
63119
{
64-
ksft_test_result_fail(": ");
65-
print_prefixes("failed\n");
120+
if (verbose) {
121+
ksft_test_result_fail(": ");
122+
print_prefixes("failed\n");
123+
}
66124
}
67125

68126
void test_pass(void)
69127
{
70-
ksft_test_result_pass(": ");
71-
print_prefixes("passed\n");
128+
if (verbose) {
129+
ksft_test_result_pass(": ");
130+
print_prefixes("passed\n");
131+
}
72132
}
73133

74134
void test_print(const char *fmt, ...)
75135
{
76-
int saved_errno = errno;
77-
va_list args;
78-
79-
va_start(args, fmt);
80-
errno = saved_errno;
81-
vprintf(fmt, args);
82-
va_end(args);
136+
if (verbose) {
137+
int saved_errno = errno;
138+
va_list args;
139+
140+
va_start(args, fmt);
141+
errno = saved_errno;
142+
vprintf(fmt, args);
143+
va_end(args);
144+
}
83145
}
84146

85147
void prefix_reset(void)
@@ -102,4 +164,3 @@ void prefix_pop(void)
102164
nr_prefixes--;
103165
}
104166
}
105-
#endif /* VERBOSE */

tools/testing/memblock/tests/common.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,22 +70,14 @@ void reset_memblock_attributes(void);
7070
void setup_memblock(void);
7171
void dummy_physical_memory_init(void);
7272
void dummy_physical_memory_cleanup(void);
73+
void parse_args(int argc, char **argv);
7374

74-
#ifdef VERBOSE
7575
void test_fail(void);
7676
void test_pass(void);
7777
void test_print(const char *fmt, ...);
7878
void prefix_reset(void);
7979
void prefix_push(const char *prefix);
8080
void prefix_pop(void);
81-
#else
82-
static inline void test_fail(void) {}
83-
static inline void test_pass(void) {}
84-
static inline void test_print(const char *fmt, ...) {}
85-
static inline void prefix_reset(void) {}
86-
static inline void prefix_push(const char *prefix) {}
87-
static inline void prefix_pop(void) {}
88-
#endif /* VERBOSE */
8981

9082
static inline void test_pass_pop(void)
9183
{

0 commit comments

Comments
 (0)