From patchwork Fri Sep 2 07:10:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Song Chen X-Patchwork-Id: 12963701 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 54295ECAAA1 for ; Fri, 2 Sep 2022 07:07:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D45A5800CB; Fri, 2 Sep 2022 03:06:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CF4108008D; Fri, 2 Sep 2022 03:06:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BE32C800CB; Fri, 2 Sep 2022 03:06:59 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id B01278008D for ; Fri, 2 Sep 2022 03:06:59 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 89CEB1A0979 for ; Fri, 2 Sep 2022 07:06:59 +0000 (UTC) X-FDA: 79866263358.04.661284B Received: from 189.cn (ptr.189.cn [183.61.185.102]) by imf14.hostedemail.com (Postfix) with ESMTP id 4815C10002B for ; Fri, 2 Sep 2022 07:06:57 +0000 (UTC) HMM_SOURCE_IP: 10.64.8.41:36230.1646632855 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP Received: from clientip-123.150.8.42 (unknown [10.64.8.41]) by 189.cn (HERMES) with SMTP id 17AC31002F3; Fri, 2 Sep 2022 15:06:50 +0800 (CST) Received: from ([123.150.8.42]) by gateway-153622-dep-84fc4d489d-ngzxf with ESMTP id eaf4a5f2bc3445ba8b7b6c9d2ffe168f for karolinadrobnik@gmail.com; Fri, 02 Sep 2022 15:06:54 CST X-Transaction-ID: eaf4a5f2bc3445ba8b7b6c9d2ffe168f X-Real-From: chensong_2000@189.cn X-Receive-IP: 123.150.8.42 X-MEDUSA-Status: 0 From: Song Chen To: karolinadrobnik@gmail.com, rppt@kernel.org, david@redhat.com, remckee0@gmail.com, shaoqin.huang@intel.com Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Song Chen Subject: [PATCH] tools/testing/memblock: add double array test Date: Fri, 2 Sep 2022 15:10:45 +0800 Message-Id: <1662102645-8272-1-git-send-email-chensong_2000@189.cn> X-Mailer: git-send-email 2.7.4 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1662102419; a=rsa-sha256; cv=none; b=Ai/39/hLIejVX3qRNlVdNxIhXq7JKTpLTDdlytKtevccyS/8mSETSFCYaZFaDjIVF4FY9O HT5TpxbpCUfVB0whspOp4y77EO2Z6S5CxzqwPoWqch8yI85Y+A20blhx3ldoE118BPw2hW j8rB5WRmXEDEKJ1f67ASYLv0yp84tpY= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=none; spf=pass (imf14.hostedemail.com: domain of chensong_2000@189.cn designates 183.61.185.102 as permitted sender) smtp.mailfrom=chensong_2000@189.cn; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1662102419; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=o7ws8hhb+GV1Jr+eAWxjF9b7WsPXnwAL5A+TQvkhHp0=; b=Vrjk4tsPGQ/1gi1K1zXOFnjaT2eYjMO7beWw2vfaiZrhWPRBC29cx4lvW2aUdaD1+WDuGI 1Tw/uwQt50aGaxk4vG3ioHoOK+2d59wzzXfzcPGR1iPNBoveKnaYNG8e+6nI9trpi3EGOf QuWI1erDkMLPhQejUOPT+I/lirJuIY8= Authentication-Results: imf14.hostedemail.com; dkim=none; spf=pass (imf14.hostedemail.com: domain of chensong_2000@189.cn designates 183.61.185.102 as permitted sender) smtp.mailfrom=chensong_2000@189.cn; dmarc=none X-Stat-Signature: 3fg3oxr8w8xuuqhsbyaq1u5ojw5zuums X-Rspamd-Queue-Id: 4815C10002B X-Rspamd-Server: rspam04 X-Rspam-User: X-HE-Tag: 1662102417-232579 X-Bogosity: Ham, tests=bogofilter, spamicity=0.004960, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: By default, there are 128 memblock_regions in memblock.memory.regions. This test is trying to add the 129th region by calling memblock_add, expects to trigger memblock_double_array. The test will pass if memblock.memory.cnt == 129 and memblock.memory.max == 256 Below is the output: ./main -v Running memblock_double_array tests... memblock_add: [0x7fffdccdf0a0a-0x7fffdccdf080a] 0x5616cca50dc4S ..... memblock_add: [0x7fffdccdf0a0a-0x7fffdccdf080a] 0x5616cca50de4S memblock: memory is doubled to 256 at [0x7fffdccdeeb0a-0x7fffdccdeed0a] ok 25 : memblock_double_array: passed Signed-off-by: Song Chen --- tools/testing/memblock/tests/basic_api.c | 42 ++++++++++++++++++++++++ tools/testing/memblock/tests/common.c | 5 --- tools/testing/memblock/tests/common.h | 4 +++ 3 files changed, 46 insertions(+), 5 deletions(-) diff --git a/tools/testing/memblock/tests/basic_api.c b/tools/testing/memblock/tests/basic_api.c index 66f46f261e66..e668ceff2f10 100644 --- a/tools/testing/memblock/tests/basic_api.c +++ b/tools/testing/memblock/tests/basic_api.c @@ -8,6 +8,7 @@ #define FUNC_RESERVE "memblock_reserve" #define FUNC_REMOVE "memblock_remove" #define FUNC_FREE "memblock_free" +#define FUNC_DOUBLE_ARRAY "memblock_double_array" static int memblock_initialization_check(void) { @@ -1180,6 +1181,46 @@ static int memblock_free_checks(void) return 0; } +/* + * A simple test that adds to 129 memory blocks. + * Expect the region max doubled. + */ +static int memblock_double_array_check(void) +{ + int i; + struct memblock_region *regions = memblock.memory.regions; + struct region r = { + .base = 0, + .size = SZ_512, + }; + + prefix_reset(); + prefix_push(FUNC_DOUBLE_ARRAY); + test_print("Running %s tests...\n", FUNC_DOUBLE_ARRAY); + + dummy_physical_memory_init(); + reset_memblock_attributes(); + setup_memblock(); + memblock_allow_resize(); + + for (i = 0; i < INIT_MEMBLOCK_REGIONS; i++) { + r.base += SZ_1K; + memblock_add(r.base, r.size); + } + + ASSERT_EQ(memblock.memory.cnt, INIT_MEMBLOCK_REGIONS + 1); + ASSERT_EQ(memblock.memory.max, INIT_MEMBLOCK_REGIONS * 2); + + memblock.memory.regions = regions; + memblock.memory.cnt = INIT_MEMBLOCK_REGIONS; + dummy_physical_memory_cleanup(); + + test_pass_pop(); + + return 0; +} + + int memblock_basic_checks(void) { memblock_initialization_check(); @@ -1187,6 +1228,7 @@ int memblock_basic_checks(void) memblock_reserve_checks(); memblock_remove_checks(); memblock_free_checks(); + memblock_double_array_check(); return 0; } diff --git a/tools/testing/memblock/tests/common.c b/tools/testing/memblock/tests/common.c index e43b2676af81..1d295a71ad44 100644 --- a/tools/testing/memblock/tests/common.c +++ b/tools/testing/memblock/tests/common.c @@ -5,11 +5,6 @@ #include #include -#define INIT_MEMBLOCK_REGIONS 128 -#define INIT_MEMBLOCK_RESERVED_REGIONS INIT_MEMBLOCK_REGIONS -#define PREFIXES_MAX 15 -#define DELIM ": " - static struct test_memory memory_block; static const char __maybe_unused *prefixes[PREFIXES_MAX]; static int __maybe_unused nr_prefixes; diff --git a/tools/testing/memblock/tests/common.h b/tools/testing/memblock/tests/common.h index 3e7f23d341d7..13559825ddca 100644 --- a/tools/testing/memblock/tests/common.h +++ b/tools/testing/memblock/tests/common.h @@ -11,6 +11,10 @@ #include <../selftests/kselftest.h> #define MEM_SIZE SZ_16K +#define INIT_MEMBLOCK_REGIONS 128 +#define INIT_MEMBLOCK_RESERVED_REGIONS INIT_MEMBLOCK_REGIONS +#define PREFIXES_MAX 15 +#define DELIM ": " /** * ASSERT_EQ():