From patchwork Sun Apr 14 00:45:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 13628863 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 0CB58C4345F for ; Sun, 14 Apr 2024 00:46:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8DD406B0088; Sat, 13 Apr 2024 20:46:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 863A86B0089; Sat, 13 Apr 2024 20:46:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6B3686B008A; Sat, 13 Apr 2024 20:46:08 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 3D5506B0088 for ; Sat, 13 Apr 2024 20:46:08 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id D6D261A017C for ; Sun, 14 Apr 2024 00:46:07 +0000 (UTC) X-FDA: 82006295574.16.7360934 Received: from mail-ej1-f50.google.com (mail-ej1-f50.google.com [209.85.218.50]) by imf03.hostedemail.com (Postfix) with ESMTP id 41BDC2000D for ; Sun, 14 Apr 2024 00:46:06 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=kRqbqYjV; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf03.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.218.50 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1713055566; h=from:from: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:in-reply-to: references:references:dkim-signature; bh=nLZIOF8IGPGB5boRkZH5HmSTYgOAMdjrxYV0OFhlry4=; b=FbZA/eGRF3szqNEMlv7D5KkYUB2wbEeZywcYOLzw0lv9bXt5xwyd3IA0YrvcHiOzMKitXl 718QPyHFRYFkOFziFfDeGVtJH425FbFf6JcJrW1nezxAUVFDE/56yUecLeQlk9Fvgk29lv lBW2o3GQQcgM4AbeXaT7u1q5mQDFanY= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=kRqbqYjV; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf03.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.218.50 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1713055566; a=rsa-sha256; cv=none; b=BZf/7cvnhU6eqfJW1x+5wc+j8Sy/aSVWh9sEy9/z+yfrh9EzlpcprhZksBaclsztoPWjXf ceuxHRv/KArwLLRVMFls1C7RFzHcpckkJe380/nNo7oyuNSQqE3c9PGFkZNAgsvqaiUa76 1iv33fhubKTEnMVqeUa4uU8s2d0/py4= Received: by mail-ej1-f50.google.com with SMTP id a640c23a62f3a-a51a7dc45easo213502066b.2 for ; Sat, 13 Apr 2024 17:46:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713055565; x=1713660365; darn=kvack.org; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=nLZIOF8IGPGB5boRkZH5HmSTYgOAMdjrxYV0OFhlry4=; b=kRqbqYjVXpcWNL5upi/VTx34lJBOCjSqSezdGbn1wyNJLjG4fUPWiOJs/z51QuGwV5 ne6pl5lPajg4PHHUrcPpY6k+90bIvYm1cHcoc1v3gXH2B7kQ+pjsMbuUYF4zRJZkW9Ie wsUe2EpFeLuCtg7oWIPPpnWLWfl2FzIIWLqn9Ajl0mATWSQxDgA/2xh6lT1q+gIpNQME 0iwI5usLqFRx6BLV/t5pptkb6xlSWCdttuhvJYSdvfTcJ0Vkn21DYQMhE4q9lK9p9fMe XauDDE4WZQtXQ4qFPXTHtcdJtmt2iY5Uz3CQTO2iUN4rlmIpGzZfdi6E0k6Pk0pEzjnn +Pmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713055565; x=1713660365; h=references:in-reply-to:message-id:date:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=nLZIOF8IGPGB5boRkZH5HmSTYgOAMdjrxYV0OFhlry4=; b=Dml7tuzR75rVrqo3DjhGcnAsCfMhWOIbsZzYmGaYEZ+QARVWwzviNCqWUGgLLdKBaC Q3KZcueqNiktLseSyLe+tUrfyqwbBlmzSYspJl1yEfNRrvZU2lTXbu2Rvz/MJZJcKlzK EIIPBMohRYjiZb4HBHJq5kEi+vR2j0y9+Ak0VpMzS/W3hv+OGagQ5GZs5/YLlFam8D+G 86fhpF6Z2p+fSM5OO9wVWFBiwrjT71r3Z6fnm9nMG7OcRp2PJjhSZqt+QM54fK0t7ohX llYGaGRcL6gduMCvohOGnbO8YTLMeoHTlbLJOPIZHf2mzdi42P6JpMD3HJ6IvlqaPZYp QPaw== X-Gm-Message-State: AOJu0YzIS/zd3qlF6RICfHM85EK5I9+j8FFOUKbqv5l0bXTr78a8hEVi TRbRHVW4m++9RZp1Wuk6nYBMUsdk2I3swNckX6JqKLAg8d7pEyy9 X-Google-Smtp-Source: AGHT+IGF6/k0J1LpByQUbQDGxMgnmnDGxE1zqOHpq4sHUArSFWiijLFsN1hi4xEVPed2D5oBOm2jog== X-Received: by 2002:a17:906:dc8:b0:a52:5350:bc5f with SMTP id p8-20020a1709060dc800b00a525350bc5fmr1436399eji.2.1713055564558; Sat, 13 Apr 2024 17:46:04 -0700 (PDT) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id x16-20020a170906135000b00a51a7832a7asm3594690ejb.199.2024.04.13.17.46.03 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 13 Apr 2024 17:46:04 -0700 (PDT) From: Wei Yang To: rppt@kernel.org, akpm@linux-foundation.org Cc: linux-mm@kvack.org, Wei Yang Subject: [PATCH 5/6] memblock tests: add memblock_overlaps_region_checks Date: Sun, 14 Apr 2024 00:45:30 +0000 Message-Id: <20240414004531.6601-5-richard.weiyang@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20240414004531.6601-1-richard.weiyang@gmail.com> References: <20240414004531.6601-1-richard.weiyang@gmail.com> X-Rspamd-Queue-Id: 41BDC2000D X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: spmarrbuhufeqcig67qypcu5zpbq9uyh X-HE-Tag: 1713055566-127057 X-HE-Meta: U2FsdGVkX1+tjsAF0zEmE7+wVGcF2AmaV2cQHm5KJYJQKVw/kBvg3IQgi+nLl964d0Ue2EOvSQJdaeljTmWQPaIz/cr2QbawcD7xK9F0865SSVhhatEgwrQRdzaX7k4EH9DehwUqxXh2JLXbnh8I/ZA1B0X9sup8/Hvqvrt4R0fjPAu9TO7eEdMlwdBVefvVTJO3AU0deywiTQIEciq8vL+/GjRO1r2aSxcwsjG8N6RRk9BSDis+TegWXTcJXUxa9IAWTzxf6FU6U4eTh1gBzLQ2QOtJwI+12GIgM3pupIw/RfBcg6XRaddGGasZEiFQsMXhvtsvqgUKZy4wNvldsiOpvtHu2W4Lm4MOv6A1h+BEG7iLt+bdIdjdJRdbFTE885Jm4RBY+QYgcBay3fa4BsWmZOqBWMOaNNNaX9hQ3jlX9QzAJ1F1fSgiyfHOmPjnXWORQqRVAFw+CW3uK1BGSkmhLmNcobOaFmhvNfeVPy8/Kdi8+F7uueFQzmaeyp8Ok/PYAaXi/8CycoNuJ+pcrScL0S7Ajq7KdmsI6mtqcBjvET/pD4UTRcfPDTxmIWoftk5AzCxI3C4fRylimlqKVpzem7oh4OhuwKR01WCn+f4DbH1wki+/2s5v1B8zaZcoSlpRTG13i3/Nb3cM/oMoE+xK9pRu04N/mJ+DuP/6N2PlgCnvBceCSEBr39okrh6VRv8FJERbgcJ5JGJBoJAzdZxUFXqZTWfGTgSsvh6czVuobElOCebPVqNxH6wvaEU9LX1J/cn8g/0WEXnxQlt5xifIy3RS9taF5hMP1ZO3gEy7m+RxKinYySEmRgPQf6oURhKDk3kAs0IcxivQxpQD2g/iZZFX65o/v+ajEj2P+F2BagyVfCCZHvCen+8KxrWyP98RsfN5AlOpYDxn4Jh8BuOcKOqZVgsCars2+66u3/ur2HPNdJdrfgFDOVGOXnpulVHXOvqwQi3ldkYdTly ZAv9P+gv E5aTeFSPf4csfgP39obrB/AtqVQiu6J5evlM4qeJYQAlb4Rat7iKfF8JWDBS8a9Xm1no2Tq++NTejjOQROhyNObSIm9IkTOW3Zq90xGAYxUZVZvoyt90LASYu8/ueRJa25WqYxA3Iin12rfCZE9mp2wEzHa6mTkbTtK330us6fDptMm7OrOYpmudAoNTNHfAoATTfkF7yVGArhVaOYhEmqO4yMMg67zs6MQ2v X-Bogosity: Ham, tests=bogofilter, spamicity=0.000554, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Add a test case for memblock_overlaps_region(). Signed-off-by: Wei Yang --- tools/testing/memblock/tests/basic_api.c | 48 ++++++++++++++++++++++++ tools/testing/memblock/tests/common.h | 3 ++ 2 files changed, 51 insertions(+) diff --git a/tools/testing/memblock/tests/basic_api.c b/tools/testing/memblock/tests/basic_api.c index f1569ebb9872..5adb0c1eaab9 100644 --- a/tools/testing/memblock/tests/basic_api.c +++ b/tools/testing/memblock/tests/basic_api.c @@ -2143,6 +2143,53 @@ static int memblock_trim_memory_checks(void) return 0; } +static int memblock_overlaps_region_check(void) +{ + struct region r = { + .base = SZ_1G, + .size = SZ_4M + }; + + PREFIX_PUSH(); + + reset_memblock_regions(); + memblock_add(r.base, r.size); + + /* Far Away */ + ASSERT_FALSE(memblock_overlaps_region(&memblock.memory, SZ_1M, SZ_1M)); + ASSERT_FALSE(memblock_overlaps_region(&memblock.memory, SZ_2G, SZ_1M)); + + /* Neighbor */ + ASSERT_FALSE(memblock_overlaps_region(&memblock.memory, SZ_1G - SZ_1M, SZ_1M)); + ASSERT_FALSE(memblock_overlaps_region(&memblock.memory, SZ_1G + SZ_4M, SZ_1M)); + + /* Partial Overlap */ + ASSERT_TRUE(memblock_overlaps_region(&memblock.memory, SZ_1G - SZ_1M, SZ_2M)); + ASSERT_TRUE(memblock_overlaps_region(&memblock.memory, SZ_1G + SZ_2M, SZ_2M)); + + /* Totally Overlap */ + ASSERT_TRUE(memblock_overlaps_region(&memblock.memory, SZ_1G, SZ_4M)); + ASSERT_TRUE(memblock_overlaps_region(&memblock.memory, SZ_1G - SZ_2M, SZ_8M)); + ASSERT_TRUE(memblock_overlaps_region(&memblock.memory, SZ_1G + SZ_1M, SZ_1M)); + + test_pass_pop(); + + return 0; +} + +static int memblock_overlaps_region_checks(void) +{ + prefix_reset(); + prefix_push("memblock_overlaps_region"); + test_print("Running memblock_overlaps_region tests...\n"); + + memblock_overlaps_region_check(); + + prefix_pop(); + + return 0; +} + int memblock_basic_checks(void) { memblock_initialization_check(); @@ -2152,6 +2199,7 @@ int memblock_basic_checks(void) memblock_free_checks(); memblock_bottom_up_checks(); memblock_trim_memory_checks(); + memblock_overlaps_region_checks(); return 0; } diff --git a/tools/testing/memblock/tests/common.h b/tools/testing/memblock/tests/common.h index b5ec59aa62d7..d8f4c9e64055 100644 --- a/tools/testing/memblock/tests/common.h +++ b/tools/testing/memblock/tests/common.h @@ -39,6 +39,9 @@ enum test_flags { assert((_expected) == (_seen)); \ } while (0) +#define ASSERT_TRUE(_seen) ASSERT_EQ(true, _seen) +#define ASSERT_FALSE(_seen) ASSERT_EQ(false, _seen) + /** * ASSERT_NE(): * Check the condition