From patchwork Tue Apr 19 12:22:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 12818136 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 97020C433EF for ; Tue, 19 Apr 2022 12:22:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 200648D006D; Tue, 19 Apr 2022 08:22:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1AF838D0047; Tue, 19 Apr 2022 08:22:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0787F8D006D; Tue, 19 Apr 2022 08:22:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0136.hostedemail.com [216.40.44.136]) by kanga.kvack.org (Postfix) with ESMTP id EAC638D0047 for ; Tue, 19 Apr 2022 08:22:38 -0400 (EDT) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 8925D1833821A for ; Tue, 19 Apr 2022 12:22:38 +0000 (UTC) X-FDA: 79373541996.29.ABE43D6 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf13.hostedemail.com (Postfix) with ESMTP id 491582000E for ; Tue, 19 Apr 2022 12:22:37 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 7841BB81886; Tue, 19 Apr 2022 12:22:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9FBFDC385A7; Tue, 19 Apr 2022 12:22:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1650370955; bh=dJPTLzgLBC9vMmTemXXBEDuiK/EVQA9bANSfzdNMn88=; h=From:To:Cc:Subject:Date:From; b=iYWsE0DDylqFD8v4bb036izvswIpFHFtuW/CRlISTdTMSIzmPb1Yvr8pZvpdxe8QM T/wLzwDXgtqbr6GZpcFK6YXFb9DxKb4PLt4qW2V22NC/KRXd0gDxJHna6MRlUHkbKz l2BYWH4T5GAB6z7/bvxUaJchObIZ3qc3oFtdP2dU2OK9BgJBqoUpw6/WGfjcgeHbdZ p2C2yGWDfn6DYYKLFsfXDjOAGHiP+Uj9aIzysQVxWBZtWv8cqJkqcZurIqxdiu55Jq QIN9iEwMfmVPe9Ga9xjMOyVarbVtZafzRWXbSykQSdRjzSjXNuFNqVfdLCEll0vv0u TWrAEeKOdZRCg== From: SeongJae Park To: akpm@linux-foundation.org Cc: brendanhiggins@google.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, SeongJae Park Subject: [PATCH] mm/damon/core-test: Add a kunit test case for ops registration Date: Tue, 19 Apr 2022 12:22:25 +0000 Message-Id: <20220419122225.290518-1-sj@kernel.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=iYWsE0DD; spf=pass (imf13.hostedemail.com: domain of sj@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=none) header.from=kernel.org X-Stat-Signature: brxz7o5gwodbgx6mue6tjgqwkmaoxsmf X-Rspamd-Queue-Id: 491582000E X-Rspamd-Server: rspam04 X-Rspam-User: X-HE-Tag: 1650370957-568739 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: This commit adds a simple kunit test case for DAMON operations registration feature. Signed-off-by: SeongJae Park --- mm/damon/core-test.h | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/mm/damon/core-test.h b/mm/damon/core-test.h index b4085deb9fa0..573669566f84 100644 --- a/mm/damon/core-test.h +++ b/mm/damon/core-test.h @@ -232,6 +232,41 @@ static void damon_test_split_regions_of(struct kunit *test) damon_destroy_ctx(c); } +static void damon_test_ops_registration(struct kunit *test) +{ + struct damon_ctx *c = damon_new_ctx(); + struct damon_operations ops, bak; + + /* DAMON_OPS_{V,P}ADDR are registered on subsys_initcall */ + KUNIT_EXPECT_EQ(test, damon_select_ops(c, DAMON_OPS_VADDR), 0); + KUNIT_EXPECT_EQ(test, damon_select_ops(c, DAMON_OPS_PADDR), 0); + + /* Double-registration is prohibited */ + ops.id = DAMON_OPS_VADDR; + KUNIT_EXPECT_EQ(test, damon_register_ops(&ops), -EINVAL); + ops.id = DAMON_OPS_PADDR; + KUNIT_EXPECT_EQ(test, damon_register_ops(&ops), -EINVAL); + + /* Unknown ops id cannot be registered */ + KUNIT_EXPECT_EQ(test, damon_select_ops(c, NR_DAMON_OPS), -EINVAL); + + /* Registration should success after unregistration */ + mutex_lock(&damon_ops_lock); + bak = damon_registered_ops[DAMON_OPS_VADDR]; + damon_registered_ops[DAMON_OPS_VADDR] = (struct damon_operations){}; + mutex_unlock(&damon_ops_lock); + + ops.id = DAMON_OPS_VADDR; + KUNIT_EXPECT_EQ(test, damon_register_ops(&ops), 0); + + mutex_lock(&damon_ops_lock); + damon_registered_ops[DAMON_OPS_VADDR] = bak; + mutex_unlock(&damon_ops_lock); + + /* Check double-registration failure again */ + KUNIT_EXPECT_EQ(test, damon_register_ops(&ops), -EINVAL); +} + static struct kunit_case damon_test_cases[] = { KUNIT_CASE(damon_test_target), KUNIT_CASE(damon_test_regions), @@ -240,6 +275,7 @@ static struct kunit_case damon_test_cases[] = { KUNIT_CASE(damon_test_merge_two), KUNIT_CASE(damon_test_merge_regions_of), KUNIT_CASE(damon_test_split_regions_of), + KUNIT_CASE(damon_test_ops_registration), {}, };