From patchwork Thu Jul 14 03:17:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rebecca Mckeever X-Patchwork-Id: 12917259 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6F2B6C433EF for ; Thu, 14 Jul 2022 03:17:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3F18D94016A; Wed, 13 Jul 2022 23:17:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3A181940134; Wed, 13 Jul 2022 23:17:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 269C394016A; Wed, 13 Jul 2022 23:17:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 14993940134 for ; Wed, 13 Jul 2022 23:17:45 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id D5FD834D5A for ; Thu, 14 Jul 2022 03:17:44 +0000 (UTC) X-FDA: 79684245648.26.083E77B Received: from mail-oa1-f68.google.com (mail-oa1-f68.google.com [209.85.160.68]) by imf10.hostedemail.com (Postfix) with ESMTP id 85359C0099 for ; Thu, 14 Jul 2022 03:17:44 +0000 (UTC) Received: by mail-oa1-f68.google.com with SMTP id 586e51a60fabf-10c0d96953fso1053159fac.0 for ; Wed, 13 Jul 2022 20:17:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=eBM0WXJ+GgNxVQg6ZdsN14nxrV6tKpZUKkvsS9po9uk=; b=SfuBaOUHJo1YTYitIqTkgxosxnQFJ3Sr5clkO8THngRd+UKJ5N+13sGLRk84USdd23 ZBqe9Llb8rYjWbFffUZ2p/syvMvUJpKtZOb/QqXmFyBAEreQBqYrbZO9U951poUWRsU+ x/Fl/ZyjPzeEEf6gZudsX9ZIuQD8TYT9rtxT9FtQG86A3RTuK09C+oEgy8R6XGzlz10H a+jL8ZGmU61hB0a8O4CcgK9FjRztisg/OsIvnBX47JaR64KRKibo4c7eDszuHBikSMvX sAU3o6yogYnu2+UvIWOZJQQUjyu1/tfe2EiskYgV4HQoVrCUAH+vJW9KTbsniMHUHTiJ t0UQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=eBM0WXJ+GgNxVQg6ZdsN14nxrV6tKpZUKkvsS9po9uk=; b=p+k70MvAjLoLsLIjxR/uLSLzhGks2pTwZVeySjjiyGHW3CavoNJoCHm25v49sFwGKO xxSB70acNSwjKAnJnjlmoTJ1OdR9yA/7x496Gmr+3HsCtToJU2BZfwodrVqIAAQ7x5VM TX90EINyx3hZNohlhL9Z85rPSeM3wN4CRU+0ipodKNPK03Cu6Ttb2XGeGFTRPJKIAsrr 5SrBSkbE7at17ljixxhwfRUBxXNel4DRMfr6KjFyOfDS2Nia6Av3jMSWpLhIyPIqA65k gKKeEEFSs4/VTjGKXsonRUhGA50so4f3KxmnmRAFfNH/6ZO/zcoN88CpNFKWzf1lS/q1 xSXw== X-Gm-Message-State: AJIora/QO3njUWXMeqDn3Fzyqt+pRp1anNQrmvbW32j579XFYRTxNHZR aTy1y6Hf2NRXVhE0d0BVPws= X-Google-Smtp-Source: AGRyM1u0e/wyG2o85Dmsu1qJZ+yp7QTwQAHn6q2TS89Ip8yZRNTT/nz/zs22kmNiiOC2e+/tICCSAg== X-Received: by 2002:a05:6870:2053:b0:e9:3c2f:23d9 with SMTP id l19-20020a056870205300b000e93c2f23d9mr6798992oad.158.1657768663646; Wed, 13 Jul 2022 20:17:43 -0700 (PDT) Received: from bertie (072-190-140-095.res.spectrum.com. [72.190.140.95]) by smtp.gmail.com with ESMTPSA id b11-20020a4aac8b000000b00434ace74464sm160162oon.16.2022.07.13.20.17.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Jul 2022 20:17:43 -0700 (PDT) From: Rebecca Mckeever To: Mike Rapoport , linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: David Hildenbrand , Rebecca Mckeever Subject: [PATCH] memblock tests: change build options to run-time options Date: Wed, 13 Jul 2022 22:17:17 -0500 Message-Id: <20220714031717.12258-1-remckee0@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1657768664; a=rsa-sha256; cv=none; b=l/dB7WQjRw+3ggf89hf+SjY8unK7mzbuTJTNBxm+G0uP0WURxagZcon3kFZcwdhA0lsRZD SQAYcbCWO8lKszX+kFv0opTwL9fZL5uVXt4twpqOTsuUwJOBw+42Rn3qFjwVzoE/xFPXur vM9XNquJrePSXy1/+nU+euK4HSLTmJM= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=SfuBaOUH; spf=pass (imf10.hostedemail.com: domain of remckee0@gmail.com designates 209.85.160.68 as permitted sender) smtp.mailfrom=remckee0@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1657768664; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=eBM0WXJ+GgNxVQg6ZdsN14nxrV6tKpZUKkvsS9po9uk=; b=XHUy7YnCCcyNQPax9QaB1ApMdwPGLmB/2tV4RmMNdNXW2KgNYsYmv1M78ljrpUSLWI9Qf3 zk2cGzw3lSAArM5Uiu99PosCX21EmSPNTk03lPeCBZtLJhZiK1k8Q6gHYyJ7sjXi7y58Fh ya+KUvjlxIhk+kIHmgE4HFG0Vh3H5tE= X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 85359C0099 X-Rspam-User: Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=SfuBaOUH; spf=pass (imf10.hostedemail.com: domain of remckee0@gmail.com designates 209.85.160.68 as permitted sender) smtp.mailfrom=remckee0@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Stat-Signature: fywnwi3jbrsmxruhas7z37ibeu43wqu6 X-HE-Tag: 1657768664-457377 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 Reviewed-by: David Hildenbrand --- 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 #include +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 +#include +#include +#include #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) {