From patchwork Mon Feb 28 14:46:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Karolina Drobnik X-Patchwork-Id: 12763431 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 10917C433FE for ; Mon, 28 Feb 2022 14:47:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7B41F8D0005; Mon, 28 Feb 2022 09:47:20 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 714CC8D0001; Mon, 28 Feb 2022 09:47:20 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5B68A8D0005; Mon, 28 Feb 2022 09:47:20 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0018.hostedemail.com [216.40.44.18]) by kanga.kvack.org (Postfix) with ESMTP id 4B7AE8D0001 for ; Mon, 28 Feb 2022 09:47:20 -0500 (EST) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id F2639998AE for ; Mon, 28 Feb 2022 14:47:19 +0000 (UTC) X-FDA: 79192466598.23.885DF2B Received: from mail-lj1-f181.google.com (mail-lj1-f181.google.com [209.85.208.181]) by imf25.hostedemail.com (Postfix) with ESMTP id 2486CA0007 for ; Mon, 28 Feb 2022 14:47:19 +0000 (UTC) Received: by mail-lj1-f181.google.com with SMTP id l12so5840765ljh.12 for ; Mon, 28 Feb 2022 06:47:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wVolMfpuoGDt9XCP+363s8gQ0xUicGtJcmsMqdqFw1w=; b=j0Qo309S6hgbmP3ipd/KV2J3R+BIUQFYoZ83AhxK88SCE+HmSRf4w08bt+aPlfdW7/ uYLKmxXKTnSHV2INU3FvleBLvn9tb+GlIssYTgokngxJDd2JXGjI9oPzusCc9XqQwn3T 1Skv19AWT9gSL3FGuNmFXqZCaCslOyIhvdM8AaqcamrkDzBDMf4UyydzdofNjjdP+3ZZ kMOA6VbHJHB/DQQNRpMzLdtHu3zQlv7QrrtgQU5QJT0mTdkNZQ2p5fs2qd44GFsYTDa7 w6fDM6AJ0RY+JxY6nALgJt4J/snff05XTeZZM8fi0Ca5cH90HXknkANA8zFhKwK5A7EX BoqA== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=wVolMfpuoGDt9XCP+363s8gQ0xUicGtJcmsMqdqFw1w=; b=0HhYdbjOqTbWoKlP+gi/Y9qy/zDMJMb4fNJapbG1ZPGEgAbo2D+Q2twvHJSEeX615C wTnAacwE/GX452yNv7H39833EK50JsfG8wgx+l2RMcSHn2WAF0bUk5BhoVKnuDQ5YQuT OtarJsKFTT6dRz6QgbwSDfM68TsoTog/k8PtkthPUk2cPvI4iOnhMO7m11XpL4TpWEAw EdpTPBpELMK70NSyytGi7WE0o3VREgUUtnhVMaTFun3KvlSHnTy8UJXHgLl5m5ugvEvj gTOsMF2Q1aKsdRFoSHEqU0Vbj0GjhQ/DDdlLrZSXfa2SiNfDEB1KjknUTkjfhl2FGtH+ Angg== X-Gm-Message-State: AOAM533hewzzP9Mo0Ka+BUVrVfz8z+iAzFT+hARL1dHfWLQnFNjiSV4b tflfYvI5aAA2qf0DHO01Ez7imggqW00= X-Google-Smtp-Source: ABdhPJypZNl0cy1qm5rfj/e4qV8VLCzwXi5IXSlKHc3dq3Zof8peeKvCKbrtelr5Rod7+SKSnVyJqQ== X-Received: by 2002:a2e:bb8f:0:b0:244:c93b:3dff with SMTP id y15-20020a2ebb8f000000b00244c93b3dffmr14167825lje.226.1646059638221; Mon, 28 Feb 2022 06:47:18 -0800 (PST) Received: from elysium.toya.net.pl (staticline-31-183-165-244.toya.net.pl. [31.183.165.244]) by smtp.gmail.com with ESMTPSA id r14-20020ac252ae000000b00443f3cbc03asm993996lfm.6.2022.02.28.06.47.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Feb 2022 06:47:17 -0800 (PST) From: Karolina Drobnik To: linux-mm@kvack.org Cc: rppt@kernel.org, akpm@linux-foundation.org, linux-kernel@vger.kernel.org, Karolina Drobnik Subject: [PATCH 2/9] memblock tests: Add simulation of physical memory Date: Mon, 28 Feb 2022 15:46:44 +0100 Message-Id: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam10 X-Rspam-User: X-Stat-Signature: wshmzcf5j77mco7o6bzhpz4yb1bm7rpo Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=j0Qo309S; spf=pass (imf25.hostedemail.com: domain of karolinadrobnik@gmail.com designates 209.85.208.181 as permitted sender) smtp.mailfrom=karolinadrobnik@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspamd-Queue-Id: 2486CA0007 X-HE-Tag: 1646059639-307404 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: Allocation functions that return virtual addresses (with an exception of _raw variant) clear the allocated memory after reserving it. This requires valid memory ranges in memblock.memory. Introduce memory_block variable to store memory that can be registered with memblock data structure. Move assert.h and size.h includes to common.h to share them between the test files. Signed-off-by: Karolina Drobnik --- tools/testing/memblock/tests/basic_api.c | 1 - tools/testing/memblock/tests/basic_api.h | 1 - tools/testing/memblock/tests/common.c | 19 +++++++++++++++++++ tools/testing/memblock/tests/common.h | 18 ++++++++++++++++++ 4 files changed, 37 insertions(+), 2 deletions(-) diff --git a/tools/testing/memblock/tests/basic_api.c b/tools/testing/memblock/tests/basic_api.c index d5035a3dcce8..fbc1ce160303 100644 --- a/tools/testing/memblock/tests/basic_api.c +++ b/tools/testing/memblock/tests/basic_api.c @@ -1,7 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include #include -#include #include "basic_api.h" #define EXPECTED_MEMBLOCK_REGIONS 128 diff --git a/tools/testing/memblock/tests/basic_api.h b/tools/testing/memblock/tests/basic_api.h index 1ceecfca1f47..1873faa54754 100644 --- a/tools/testing/memblock/tests/basic_api.h +++ b/tools/testing/memblock/tests/basic_api.h @@ -2,7 +2,6 @@ #ifndef _MEMBLOCK_BASIC_H #define _MEMBLOCK_BASIC_H -#include #include "common.h" int memblock_basic_checks(void); diff --git a/tools/testing/memblock/tests/common.c b/tools/testing/memblock/tests/common.c index dd7e87c589fe..62d3191f7c9a 100644 --- a/tools/testing/memblock/tests/common.c +++ b/tools/testing/memblock/tests/common.c @@ -5,6 +5,8 @@ #define INIT_MEMBLOCK_REGIONS 128 #define INIT_MEMBLOCK_RESERVED_REGIONS INIT_MEMBLOCK_REGIONS +static struct test_memory memory_block; + void reset_memblock_regions(void) { memset(memblock.memory.regions, 0, @@ -27,3 +29,20 @@ void reset_memblock_attributes(void) memblock.bottom_up = false; memblock.current_limit = MEMBLOCK_ALLOC_ANYWHERE; } + +void setup_memblock(void) +{ + reset_memblock_regions(); + memblock_add((phys_addr_t)memory_block.base, MEM_SIZE); +} + +void dummy_physical_memory_init(void) +{ + memory_block.base = malloc(MEM_SIZE); + assert(memory_block.base); +} + +void dummy_physical_memory_cleanup(void) +{ + free(memory_block.base); +} diff --git a/tools/testing/memblock/tests/common.h b/tools/testing/memblock/tests/common.h index b864c64fb60f..619054d03219 100644 --- a/tools/testing/memblock/tests/common.h +++ b/tools/testing/memblock/tests/common.h @@ -2,8 +2,23 @@ #ifndef _MEMBLOCK_TEST_H #define _MEMBLOCK_TEST_H +#include +#include #include #include +#include + +#define MEM_SIZE SZ_16K + +/* + * Available memory registered with memblock needs to be valid for allocs + * test to run. This is a convenience wrapper for memory allocated in + * dummy_physical_memory_init() that is later registered with memblock + * in setup_memblock(). + */ +struct test_memory { + void *base; +}; struct region { phys_addr_t base; @@ -12,5 +27,8 @@ struct region { void reset_memblock_regions(void); void reset_memblock_attributes(void); +void setup_memblock(void); +void dummy_physical_memory_init(void); +void dummy_physical_memory_cleanup(void); #endif