From patchwork Sat Sep 9 03:37:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 13377948 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 AF3ADEEB581 for ; Sat, 9 Sep 2023 03:37:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 891F06B0105; Fri, 8 Sep 2023 23:37:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 823EE6B0106; Fri, 8 Sep 2023 23:37:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6B9946B0105; Fri, 8 Sep 2023 23:37:31 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 4ACC36B0103 for ; Fri, 8 Sep 2023 23:37:31 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 0F5F51A04E1 for ; Sat, 9 Sep 2023 03:37:31 +0000 (UTC) X-FDA: 81215649102.16.7B973BD Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf06.hostedemail.com (Postfix) with ESMTP id 59D8C180003 for ; Sat, 9 Sep 2023 03:37:29 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Q6nGX0tP; spf=pass (imf06.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 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694230649; a=rsa-sha256; cv=none; b=nVqKFy/YEaA1+DRyj113a+/m67nOKjoSe9+ZKu+vc0duqBGtV1lKMmArLY992tacgozt7s 5FQOvaQuZZoD2gMS6KpmuLWOGft0+sd/iWIsfUSF+K+49vVr91d5WJMMPkOYeAEUN8I35e QNzPYDI9iX0/jfAUTYUelHYfM/6/vy4= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Q6nGX0tP; spf=pass (imf06.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 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1694230649; 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=O3DIEBn4MNntneGMWPPuHBIKHiCuBMm2lSALAnY/+YatfFLX9SigkrEVreWKcU4Fqz6gHW B+ieVzr6+qM4krfySYwhgYv12lSiGV+ZNSdwPhKWJ9w+7oTiV4dP/Pz0kWgiujKY/bgCW/ p/WAJr9VoKgfTMIYRf19wyVrs2Ma/sQ= 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 ams.source.kernel.org (Postfix) with ESMTPS id 0B5FDB82335; Sat, 9 Sep 2023 03:37:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2AA87C433C8; Sat, 9 Sep 2023 03:37:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1694230646; bh=xT8faQ/VQn4QsrSETrKl21TSbXbkbXRLNmsjtMslsE0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Q6nGX0tPVQa7fCjabWv9V2jpJs1DiN5xW7gllO09XsezCUlzsXPYyvzHVicPumwDV lQnjQlf0l+hoeoKIWbMAHjjrxe9+3JDdv8MpG5M9yHTg23+or5jvfqib8eX3+JpL2y Tgl+amkWP0P6lRiUwZcxGAi/ZVz6ECjZVVZBqKKd/9sNED8QDpRKxGOAfgsV77P3sV RvEBOP5H8fZIhDl871XivTV6JqG8VefCQc56DqGs/IhVAYPgftaTalFZp8iP0Vfy9N WNu3+4BqDt7DOpVmHvOL6X8XAsYAqNm6XCbHkhz2n5C4kvbPJKktYT2qEQy54weRGP Ed5aJ0cXUmMYw== From: SeongJae Park To: Cc: SeongJae Park , Andrew Morton , 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: [RFC 4/8] mm/damon/core-test: add a unit test for damon_moving_sum() Date: Sat, 9 Sep 2023 03:37:07 +0000 Message-Id: <20230909033711.55794-5-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230909033711.55794-1-sj@kernel.org> References: <20230909033711.55794-1-sj@kernel.org> MIME-Version: 1.0 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 59D8C180003 X-Stat-Signature: wrmrc4f5rfaojcompxnep4ak9fk7q6yt X-Rspam-User: X-HE-Tag: 1694230649-880850 X-HE-Meta: U2FsdGVkX18sisTVsjxEfTR4vBgtR54fpEtR11GgpM0iksl8dwSNLciA1ltWH0/CMftcIbu2sWuIjNHtFH0a4ETSNbqwZVjoxVuHN+h4erYWGfI6KOH87YzDb0hyg3lwJQp3CBjVu2n2IgLVDkBj4LT630/NGzN/WpyaYkVEkf7g5BWF1h4iKaaBi+XI76dBtGu9EYVXRBiQVHEaTlcg2w7Nx3Qg0vJF/kRiVSjQaV7Z7Pf2qaH6JvYftcL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Yq4v5x1oRTzmU0rKvVhKTdemNIsU9U39WNKyNuhhrHQ8YZUcQgqNO 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), {},