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: 130169 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f41:0:b0:3e4:2afc:c1 with SMTP id v1csp762094vqx; Wed, 2 Aug 2023 15:20:37 -0700 (PDT) X-Google-Smtp-Source: APBJJlFXS76+q4Pn0AqRehRMlcAkTZDgeKV+9GmCpzGvPZRe/4Hm5D9YAayw0VUKpKpyuZFG5c9R X-Received: by 2002:a17:902:f54d:b0:1b8:9fc4:2733 with SMTP id h13-20020a170902f54d00b001b89fc42733mr17451031plf.3.1691014837330; Wed, 02 Aug 2023 15:20:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691014837; cv=none; d=google.com; s=arc-20160816; b=mQKjEvh3YJULdw44C1otwFL2y0HTwHF5q4hUnFut9f6om5eQdv7jUTRIlETxqNvPMX TR/wR13nbEKcXaqTW+Fs6vUuWLOUjomnypQ3esFfqYbpYNttnDrKi7DDzXe/wmdAhAOj RdjndI6u8TKUICywhC8Z+AIaH7w58OaAqYWItG0bAXZyF+JKiCatUB1qhoxrA59M0+xc N0AtIlg5ykj0aiL0gQRpxYmgj1TLUroOutd11/h+qAErFvOwrmYrV+RZZLkWWU4MAbu0 WhwBbvyAFSYXGiMR6pnKA+W8CdMM9oGHdYvE+ZxLWeeVN9gASF7iY7keDAxz95Er/2P6 mnUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=H7I3qOLZIoxUPB4H66Z79LzMY2GKKRBloWv4nV8FqAk=; fh=d/e0e8gtUnIan/NSjMuu66p3SVPUMATwe3K/TPr/ppM=; b=c5gk/c9c3bGynfD9bcxd/yZmTzS59iQOKXwu35NSdEz4DLxxOYmsNj0gaFFuzeeg+L 2u3oTRq6ry3Nj+16AHIn3Lq1RL2aNuZbyV3iwpC2HwEXvvL8QeAPW5qwLmk3gc2KfTw3 XUDmnjhD2wEUmPkFbsT4S0tSvLUKQ0jkTEh5mypcgo+R4wQU2DkbnR2j1Yj1w0xDNt23 dA+i5XtJyISTfW9udrt4UBCTuqe+Ju+d72ecgkAAHhGdb07E2Ne1mj/JVR0ljoaWw4qA 2hiVYYYdxDcTR9ox8MnPSLKP+fKlZQqGCcs2ctUr7iVSYY69Q2Cfjsal3iDgKxQylAr6 7NaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=LvH1bZLS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jz6-20020a170903430600b001b89eefc9fbsi11016137plb.262.2023.08.02.15.20.23; Wed, 02 Aug 2023 15:20:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=LvH1bZLS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233384AbjHBVn2 (ORCPT + 99 others); Wed, 2 Aug 2023 17:43:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232306AbjHBVnT (ORCPT ); Wed, 2 Aug 2023 17:43:19 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 09687E7D; Wed, 2 Aug 2023 14:43:19 -0700 (PDT) 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 9382061AF0; 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-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773157574141772636 X-GMAIL-MSGID: 1773157574141772636 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), {}, };