From patchwork Fri Sep 15 02:52:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13386315 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 20F9FEEAA42 for ; Fri, 15 Sep 2023 02:53:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 48AAE6B030C; Thu, 14 Sep 2023 22:53:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4115C6B030E; Thu, 14 Sep 2023 22:53:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1A1696B030F; Thu, 14 Sep 2023 22:53:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 07EB26B030C for ; Thu, 14 Sep 2023 22:53:10 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id D06B1C0746 for ; Fri, 15 Sep 2023 02:53:09 +0000 (UTC) X-FDA: 81237310098.08.6DD9ED6 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf08.hostedemail.com (Postfix) with ESMTP id 4C8A7160011 for ; Fri, 15 Sep 2023 02:53:08 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=vE+6+K2v; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf08.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=1694746388; 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=u9TmyMjuPTNAblor8OwPK1A1ey4pwH8Hdhs6lWbOca8=; b=cXngYQLFDpKEBBs3xnllZHROi9ANqhjhQE5WbV711jUVGijrUnaqklZEXbYgAoWTu413Ol 8iARH7yNkF9OjJ6qZlksKEyEvjBvM3NM5BdKQWl9rixqnfNDKWrvYVs2/6bMh1wIeFKfSR TRLEhJNnN65jzlmq9HVzkTAt9DSFZUU= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=vE+6+K2v; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf08.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=1694746388; a=rsa-sha256; cv=none; b=h+q42X1ZQ8OSVqfRRz6A5EEBSWiQ5LNdo15K10b/JcTFhf1EM0iyqQLLjeMOOTFlsw7DMC UBha9zrKU/xT7O/HD56UuBsvbAgbFxSvy61bDkARXTb2GsLoN+HDAGBfGsa7u/UpZHpx2b LQzSR+2oL7xUSjgoMybHun51tKnGvoI= 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 7CB9D61ED2; Fri, 15 Sep 2023 02:53:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 44B9DC433C8; Fri, 15 Sep 2023 02:53:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1694746386; bh=xT8faQ/VQn4QsrSETrKl21TSbXbkbXRLNmsjtMslsE0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vE+6+K2v8eFHCuG2uMpBuFLYWDxqqOXd+irJE2hgT8Kzn2qCdWCy1yLXm/zxJGcle 766beCUyr429m9vHPiYbpBIH1ir4Ac1FU1pAssUxZCd0fxPupJtIfjmwwqCV1CizFh urwwnI45LhwWV3A+6CX6il2CrZWabaG/fK1UIvPJW4QNgmq7jiOh7NATX2Jh8W9xyx sboRSLtK7W/n1muo988SNeyulnEUWTL/ZqrG2xmmHhw+zkZA3YEHyXowMDaMr2B5hD XGukIVihyc7OyD/VMQU5eVcRYGaRVI6Xe4hn3oV8PWGyIPnbyMw5YD+9QK8yLIrpZk HOBb+tcLjtjgQ== 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 4/8] mm/damon/core-test: add a unit test for damon_moving_sum() Date: Fri, 15 Sep 2023 02:52:47 +0000 Message-Id: <20230915025251.72816-5-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230915025251.72816-1-sj@kernel.org> References: <20230915025251.72816-1-sj@kernel.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 4C8A7160011 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: unwdncbcfoagoatpwinxwxjkdojep6zy X-HE-Tag: 1694746388-416848 X-HE-Meta: U2FsdGVkX19WLsP4OzjiLonCkqyW5/QjUza/Un4+KqMtqbl/gzO/A6fv2L1zWQyaRndM4n8v+L9ZsZwdOcF8+O3iwfPCg2lyX0kfi2AG/gJtqcHM5vT+s9QdJ75wlhduwtVxeEss3AdRE7l3+77jaF3ivv4cYofdJmIxUkSvMyFmV4GVQyKWJW14Vj/fuG7rt8Z8WM0VemcKFyaXoV7T6YGWaFWiSsR83cRW9mnY48iE6isPQbmCT42JEcZG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4DZBFyhCqyIlZtIXEsInklpzW8nYJoisS1hiE+FFkCLMLp 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: Add a simple unit test for the pseudo moving-sum function (damon_moving_sum()). Signed-off-by: SeongJae Park --- mm/damon/core-test.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/mm/damon/core-test.h b/mm/damon/core-test.h index 6cc8b245586d..c539f0e8377e 100644 --- a/mm/damon/core-test.h +++ b/mm/damon/core-test.h @@ -341,6 +341,21 @@ static void damon_test_set_attrs(struct kunit *test) KUNIT_EXPECT_EQ(test, damon_set_attrs(c, &invalid_attrs), -EINVAL); } +static void damon_test_moving_sum(struct kunit *test) +{ + unsigned int mvsum = 50000, nomvsum = 50000, len_window = 10; + unsigned int new_values[] = {10000, 0, 10000, 0, 0, 0, 10000, 0, 0, 0}; + unsigned int expects[] = {55000, 50000, 55000, 50000, 45000, 40000, + 45000, 40000, 35000, 30000}; + int i; + + for (i = 0; i < ARRAY_SIZE(new_values); i++) { + mvsum = damon_moving_sum(mvsum, nomvsum, len_window, + new_values[i]); + KUNIT_EXPECT_EQ(test, mvsum, expects[i]); + } +} + static void damos_test_new_filter(struct kunit *test) { struct damos_filter *filter; @@ -425,6 +440,7 @@ static struct kunit_case damon_test_cases[] = { KUNIT_CASE(damon_test_set_regions), KUNIT_CASE(damon_test_update_monitoring_result), KUNIT_CASE(damon_test_set_attrs), + KUNIT_CASE(damon_test_moving_sum), KUNIT_CASE(damos_test_new_filter), KUNIT_CASE(damos_test_filter_out), {},