From mboxrd@z Thu Jan 1 00:00:00 1970 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 36453C433FE for ; Thu, 27 Jan 2022 13:23:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BA16F6B009A; Thu, 27 Jan 2022 08:23:04 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B522E6B009B; Thu, 27 Jan 2022 08:23:04 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 957646B009C; Thu, 27 Jan 2022 08:23:04 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0008.hostedemail.com [216.40.44.8]) by kanga.kvack.org (Postfix) with ESMTP id 808746B009A for ; Thu, 27 Jan 2022 08:23:04 -0500 (EST) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 40C70181CBC11 for ; Thu, 27 Jan 2022 13:23:04 +0000 (UTC) X-FDA: 79076132688.14.063D2A6 Received: from mail-lj1-f173.google.com (mail-lj1-f173.google.com [209.85.208.173]) by imf12.hostedemail.com (Postfix) with ESMTP id 7C2B94000F for ; Thu, 27 Jan 2022 13:23:03 +0000 (UTC) Received: by mail-lj1-f173.google.com with SMTP id q127so4311869ljq.2 for ; Thu, 27 Jan 2022 05:23:03 -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=Hy7Dd2f91UDJKml61GqO51OOP6//JtRGeIoiva3Pj4s=; b=eOBmJmDHfkuFeep90OvjOekwFn22R9eJ6NpFaGtjUtD5B8ra+NXr2/L42EZ/tIGqr1 Os+Xfz7s2sqwWFzFFEBHdWgxxVLc3GN8+kFNFiPHzsva5t0Evujp/h19Sk1V2I2/LBAN vp5NtiB9x6RHstR/aDYucdeSTWlQeT+fpPdOMg0iFxa3WEv21kWHzKrEuGAqXn436R/L y7HkgeDFwCiZXOd0iefHLlZ67/zUrVnJEe0FQlhVX7d+X+Nd/4d3D4a9CJun/QYqiRIR qQ1Wl8ZkUAr3ZEOCVSqskAwdz4/i0mFDzUpwBnGf2vCZ1Jd5iRsCdL/OrMR3PohB6ZkM JukQ== 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=Hy7Dd2f91UDJKml61GqO51OOP6//JtRGeIoiva3Pj4s=; b=rCqKQlmYQDcmLqS1UmJBF0hhNgMFexttAOemHZTG/d7NPfNHhvEP3Z6ILbLEUie9N1 6GOESFz6pQp5LJylx370FHZlg6mN54NuwPYzg8/AOhIYLNOrYYDn/oEYofNJMMX15t1o 9Edk8LFofwoYda+GUL/yRtxIkIoV0zJm9V1Sagt/pZfR60xdjNz5JZR28FyyUyd9XJaZ SnTshbSr0q4fO5MTE36dvfZNxFler5YHPIYSIC56Q+1o0XRxACl2NVS8xtr/ju0fxsdy 99AOZ978A/kovZB6j6wDZlh35CMLM/iCy4CN7ZyjdWY8CczU2jvw9QfqNJ7ji6JqRuqY GD0w== X-Gm-Message-State: AOAM5323mXeakb/FK3wnDqSv9E1MoL5oMh6t6Rjx0ntqxzGb4vzvbviz a/EFSsBFVBZnVxC4WbVCDleO6FxvNac= X-Google-Smtp-Source: ABdhPJylTzrNTw+ZvMPlNBQsGkLRQ2IxoY6wQKgiAfi4DWnoRMz0SCd4bbx9GZyc/0LHkhu8H9Ociw== X-Received: by 2002:a2e:a41a:: with SMTP id p26mr2927925ljn.176.1643289782157; Thu, 27 Jan 2022 05:23:02 -0800 (PST) Received: from elysium.toya.net.pl (staticline-31-183-166-172.toya.net.pl. [31.183.166.172]) by smtp.gmail.com with ESMTPSA id s16sm1306918lfp.197.2022.01.27.05.23.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jan 2022 05:23:01 -0800 (PST) From: Karolina Drobnik To: linux-mm@kvack.org Cc: akpm@linux-foundation.org, mike.rapoport@gmail.com, linux-kernel@vger.kernel.org, Karolina Drobnik Subject: [PATCH 14/16] memblock tests: Add memblock_remove tests Date: Thu, 27 Jan 2022 14:21:32 +0100 Message-Id: <680e9f43b98cae24f6c6364052be14f2bcefa694.1643206612.git.karolinadrobnik@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 7C2B94000F X-Stat-Signature: 5i9pyg68p35nhsdyd9bto7awbh7nxue1 Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=eOBmJmDH; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf12.hostedemail.com: domain of karolinadrobnik@gmail.com designates 209.85.208.173 as permitted sender) smtp.mailfrom=karolinadrobnik@gmail.com X-Rspam-User: nil X-HE-Tag: 1643289783-278821 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000560, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Add checks for removing a region from available memory in different scenarios: - The requested region matches one in the collection of available memory regions - The requested region does not exist in memblock.memory - The region overlaps with one of the entries: from the top (its end address is bigger than the base of the existing region) or from the bottom (its base address is smaller than the end address of one of the regions) - The region is within an already defined region Signed-off-by: Karolina Drobnik --- tools/testing/memblock/tests/basic_api.c | 203 +++++++++++++++++++++++ 1 file changed, 203 insertions(+) diff --git a/tools/testing/memblock/tests/basic_api.c b/tools/testing/mem= block/tests/basic_api.c index b055ff262d23..96af80bf9df9 100644 --- a/tools/testing/memblock/tests/basic_api.c +++ b/tools/testing/memblock/tests/basic_api.c @@ -450,11 +450,214 @@ static int memblock_reserve_checks(void) return 0; } =20 + /* + * A simple test that tries to remove the first entry of the array of a= vailable + * memory regions. By "removing" a region we mean overwriting it with t= he next + * region in memblock.memory. To check this is the case, the test adds = two memory + * blocks and verifies that the value of the latter was used to erase r= 1 region. + * It also checks if the region counter and total size were updated to = expected + * values. + */ +static int memblock_remove_simple_check(void) +{ + struct memblock_region *rgn; + + rgn =3D &memblock.memory.regions[0]; + + struct region r1 =3D { + .base =3D SZ_2K, + .size =3D SZ_4K + }; + struct region r2 =3D { + .base =3D SZ_128K, + .size =3D SZ_4M + }; + + reset_memblock(); + memblock_add(r1.base, r1.size); + memblock_add(r2.base, r2.size); + memblock_remove(r1.base, r1.size); + + assert(rgn->base =3D=3D r2.base); + assert(rgn->size =3D=3D r2.size); + + assert(memblock.memory.cnt =3D=3D 1); + assert(memblock.memory.total_size =3D=3D r2.size); + + return 0; +} + + /* + * A test that tries to remove a region that was not registered as avai= lable + * memory (i.e. has no corresponding entry in memblock.memory). It veri= fies + * that array, regions counter and total size were not modified. + */ +static int memblock_remove_absent_check(void) +{ + struct memblock_region *rgn; + + rgn =3D &memblock.memory.regions[0]; + + struct region r1 =3D { + .base =3D SZ_512K, + .size =3D SZ_4M + }; + struct region r2 =3D { + .base =3D SZ_64M, + .size =3D SZ_1G + }; + + reset_memblock(); + memblock_add(r1.base, r1.size); + memblock_remove(r2.base, r2.size); + + assert(rgn->base =3D=3D r1.base); + assert(rgn->size =3D=3D r1.size); + + assert(memblock.memory.cnt =3D=3D 1); + assert(memblock.memory.total_size =3D=3D r1.size); + + return 0; +} + +/* + * A test that tries to remove a region which overlaps with the beginnin= g of + * the already existing entry r1 (that is r1.base < r2.base + r2.size). = It + * checks if only the intersection of both regions is removed from the a= vailable + * memory pool. The test also checks if the regions counter and total si= ze are + * updated to expected values. + */ +static int memblock_remove_overlap_top_check(void) +{ + struct memblock_region *rgn; + phys_addr_t r1_end, r2_end, total_size; + + rgn =3D &memblock.memory.regions[0]; + + struct region r1 =3D { + .base =3D SZ_32M, + .size =3D SZ_32M + }; + struct region r2 =3D { + .base =3D SZ_16M, + .size =3D SZ_32M + }; + + r1_end =3D r1.base + r1.size; + r2_end =3D r2.base + r2.size; + total_size =3D r1_end - r2_end; + + reset_memblock(); + memblock_add(r1.base, r1.size); + memblock_remove(r2.base, r2.size); + + assert(rgn->base =3D=3D r1.base + r2.base); + assert(rgn->size =3D=3D total_size); + + assert(memblock.memory.cnt =3D=3D 1); + assert(memblock.memory.total_size =3D=3D total_size); + + return 0; +} + +/* + * A test that tries to remove a region which overlaps with the end of t= he + * first entry (that is r2.base < r1.base + r1.size). It checks if only = the + * intersection of both regions is removed from the available memory poo= l. + * The test also checks if the regions counter and total size are update= d to + * expected values. + */ +static int memblock_remove_overlap_bottom_check(void) +{ + struct memblock_region *rgn; + phys_addr_t total_size; + + rgn =3D &memblock.memory.regions[0]; + + struct region r1 =3D { + .base =3D SZ_2M, + .size =3D SZ_64M + }; + struct region r2 =3D { + .base =3D SZ_32M, + .size =3D SZ_256M + }; + + total_size =3D r2.base - r1.base; + + reset_memblock(); + memblock_add(r1.base, r1.size); + memblock_remove(r2.base, r2.size); + + assert(rgn->base =3D=3D r1.base); + assert(rgn->size =3D=3D total_size); + + assert(memblock.memory.cnt =3D=3D 1); + assert(memblock.memory.total_size =3D=3D total_size); + return 0; +} + +/* + * A test that tries to remove a region which is within the range of the= already + * existing entry (that is (r1.base < r2.base) && (r2.base + r2.size < r= 1.base + r1.size)). + * It checks if the region is split into two - one that ends at r2.base = and second + * that starts at r2.base + size, with appropriate sizes. The test also = checks if + * the region counter and total size were updated to expected values. + */ +static int memblock_remove_within_check(void) +{ + struct memblock_region *rgn1, *rgn2; + phys_addr_t r1_size, r2_size, total_size; + + rgn1 =3D &memblock.memory.regions[0]; + rgn2 =3D &memblock.memory.regions[1]; + + struct region r1 =3D { + .base =3D SZ_1M, + .size =3D SZ_32M + }; + struct region r2 =3D { + .base =3D SZ_16M, + .size =3D SZ_1M + }; + + r1_size =3D r2.base - r1.base; + r2_size =3D (r1.base + r1.size) - (r2.base + r2.size); + total_size =3D r1_size + r2_size; + + reset_memblock(); + memblock_add(r1.base, r1.size); + memblock_remove(r2.base, r2.size); + + assert(rgn1->base =3D=3D r1.base); + assert(rgn1->size =3D=3D r1_size); + + assert(rgn2->base =3D=3D r2.base + r2.size); + assert(rgn2->size =3D=3D r2_size); + + assert(memblock.memory.cnt =3D=3D 2); + assert(memblock.memory.total_size =3D=3D total_size); + + return 0; +} + +static int memblock_remove_checks(void) +{ + memblock_remove_simple_check(); + memblock_remove_absent_check(); + memblock_remove_overlap_top_check(); + memblock_remove_overlap_bottom_check(); + memblock_remove_within_check(); + + return 0; +} + int memblock_basic_checks(void) { memblock_initialization_check(); memblock_add_checks(); memblock_reserve_checks(); + memblock_remove_checks(); =20 return 0; } --=20 2.30.2