From patchwork Wed Aug 2 21:43:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13338863 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 8809EC00528 for ; Wed, 2 Aug 2023 21:43:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B561C2801F0; Wed, 2 Aug 2023 17:43:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AB7062801EB; Wed, 2 Aug 2023 17:43:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 86DE82801F0; Wed, 2 Aug 2023 17:43:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 7023F2801EB for ; Wed, 2 Aug 2023 17:43:21 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 3A5FCC05FE for ; Wed, 2 Aug 2023 21:43:21 +0000 (UTC) X-FDA: 81080491002.26.FC5D2AF Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf01.hostedemail.com (Postfix) with ESMTP id 5D83740009 for ; Wed, 2 Aug 2023 21:43:19 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=LvH1bZLS; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf01.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1691012599; 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:in-reply-to:references:references:dkim-signature; bh=H7I3qOLZIoxUPB4H66Z79LzMY2GKKRBloWv4nV8FqAk=; b=tzuceuokA3THg8W71cWIU037VkKThXqcsIDTRQ0Q7JF+7JZoegVflSw0DLkIFP8UHgWBMa WM59geid92iCptfkH00uKL8v1Qx7wfxudPX0frcgjtnhkNhMBxozq/GAp5jWsI0pG3aEwO RzZMNTx8e94eZg8uCmggnygJY1/A/LU= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=LvH1bZLS; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf01.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1691012599; a=rsa-sha256; cv=none; b=aCrWGlQCRIfhNpoySW1I8cRZn7BMLbBQ3RIOLufVUVwW4fdGtQ52P0hQKzqHCLhFOrkAcE Xp92OmyuJ7h5rQiExdrLZYgk204+MCZfX5BV94dMTNvAl4cu4ndV8wA3bLFIle5roMOn1l 764Wdp1MJvAQ0dIflFSx3rCZbunVdz0= Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 9671261B32; Wed, 2 Aug 2023 21:43:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 761AFC433CB; Wed, 2 Aug 2023 21:43:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1691012598; bh=plLKrdhuxTu4fXv62XEDStD9l4o2qp5Q+Y0GoiThmrE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LvH1bZLSqUYN0scYv4lgnIiiDHf/QbLHgwsHOhtc3Vu4diL5ne6xiURe9ZI79A1j/ OIqJB+nLKkuOOaOvyLxQ13IN+eONATxWLDnpP64G30W9BWufAZcpdYRYmciHUccQOC nhQyU6uhjVaGyeL6rKJbEg02JFLwjDrrpcGMyjMQNTgRaAs0UTGGvfs/QmfY/lo7Qt 4s7GgdsMoCuHY+hP5os6TKeBmnMtJFXcc7fVhfKPACmGAsu6Ap7zZjyreNQ8Em5OWJ VpOG7/Q3fTDf75C/ilhCKDeDXjPE5ROuB8ebDYWwLJuMDDxyvuQDvsAXCahfNfp5eJ UdAuCeJNT/CBA== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , Brendan Higgins , damon@lists.linux.dev, linux-mm@kvack.org, kunit-dev@googlegroups.com, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 03/13] mm/damon/core-test: add a unit test for __damos_filter_out() Date: Wed, 2 Aug 2023 21:43:02 +0000 Message-Id: <20230802214312.110532-4-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230802214312.110532-1-sj@kernel.org> References: <20230802214312.110532-1-sj@kernel.org> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: okxj1sfgrfxeiw4jb45o5oejki7shg5e X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 5D83740009 X-HE-Tag: 1691012599-135819 X-HE-Meta: U2FsdGVkX1+JWYm+UW2DxiIh/M99s+yzRy0v9wAnBqwTBBGVPe5mqVxS69J9Fn7RLB2LhWJOmLHJmJuX8HjbHAMqo0MDGDXLEgZB8EgE8MCzY/Dp7gCMK5r5nVZjYn8fYLSegoloWaxb/wzWpZQCPWlCVtwHqQaaC5/OoaI/542z5pJzglJyFS76rS2VEd8ftKWSE9Den9NVY8isqLfBW0UhK6A2fnUUourSj0F3NXWtN9zhFaFf4zb4tUQefyE1NJL3o/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TKgSbTY44b2cyT12x8va 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: Implement a kunit test for the core of address range DAMOS filter handling, namely __damos_filter_out(). The test especially focus on regions that overlap with given filter's target address range. Signed-off-by: SeongJae Park --- mm/damon/core-test.h | 61 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/mm/damon/core-test.h b/mm/damon/core-test.h index 4bddbfe243c3..6cc8b245586d 100644 --- a/mm/damon/core-test.h +++ b/mm/damon/core-test.h @@ -353,6 +353,66 @@ static void damos_test_new_filter(struct kunit *test) damos_destroy_filter(filter); } +static void damos_test_filter_out(struct kunit *test) +{ + struct damon_target *t; + struct damon_region *r, *r2; + struct damos_filter *f; + + f = damos_new_filter(DAMOS_FILTER_TYPE_ADDR, true); + f->addr_range = (struct damon_addr_range){ + .start = DAMON_MIN_REGION * 2, .end = DAMON_MIN_REGION * 6}; + + t = damon_new_target(); + r = damon_new_region(DAMON_MIN_REGION * 3, DAMON_MIN_REGION * 5); + damon_add_region(r, t); + + /* region in the range */ + KUNIT_EXPECT_TRUE(test, __damos_filter_out(NULL, t, r, f)); + KUNIT_EXPECT_EQ(test, damon_nr_regions(t), 1); + + /* region before the range */ + r->ar.start = DAMON_MIN_REGION * 1; + r->ar.end = DAMON_MIN_REGION * 2; + KUNIT_EXPECT_FALSE(test, __damos_filter_out(NULL, t, r, f)); + KUNIT_EXPECT_EQ(test, damon_nr_regions(t), 1); + + /* region after the range */ + r->ar.start = DAMON_MIN_REGION * 6; + r->ar.end = DAMON_MIN_REGION * 8; + KUNIT_EXPECT_FALSE(test, __damos_filter_out(NULL, t, r, f)); + KUNIT_EXPECT_EQ(test, damon_nr_regions(t), 1); + + /* region started before the range */ + r->ar.start = DAMON_MIN_REGION * 1; + r->ar.end = DAMON_MIN_REGION * 4; + KUNIT_EXPECT_FALSE(test, __damos_filter_out(NULL, t, r, f)); + /* filter should have split the region */ + KUNIT_EXPECT_EQ(test, r->ar.start, DAMON_MIN_REGION * 1); + KUNIT_EXPECT_EQ(test, r->ar.end, DAMON_MIN_REGION * 2); + KUNIT_EXPECT_EQ(test, damon_nr_regions(t), 2); + r2 = damon_next_region(r); + KUNIT_EXPECT_EQ(test, r2->ar.start, DAMON_MIN_REGION * 2); + KUNIT_EXPECT_EQ(test, r2->ar.end, DAMON_MIN_REGION * 4); + damon_destroy_region(r2, t); + + /* region started in the range */ + r->ar.start = DAMON_MIN_REGION * 2; + r->ar.end = DAMON_MIN_REGION * 8; + KUNIT_EXPECT_TRUE(test, __damos_filter_out(NULL, t, r, f)); + /* filter should have split the region */ + KUNIT_EXPECT_EQ(test, r->ar.start, DAMON_MIN_REGION * 2); + KUNIT_EXPECT_EQ(test, r->ar.end, DAMON_MIN_REGION * 6); + KUNIT_EXPECT_EQ(test, damon_nr_regions(t), 2); + r2 = damon_next_region(r); + KUNIT_EXPECT_EQ(test, r2->ar.start, DAMON_MIN_REGION * 6); + KUNIT_EXPECT_EQ(test, r2->ar.end, DAMON_MIN_REGION * 8); + damon_destroy_region(r2, t); + + damon_free_target(t); + damos_free_filter(f); +} + static struct kunit_case damon_test_cases[] = { KUNIT_CASE(damon_test_target), KUNIT_CASE(damon_test_regions), @@ -366,6 +426,7 @@ static struct kunit_case damon_test_cases[] = { KUNIT_CASE(damon_test_update_monitoring_result), KUNIT_CASE(damon_test_set_attrs), KUNIT_CASE(damos_test_new_filter), + KUNIT_CASE(damos_test_filter_out), {}, };