Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp1210942rdb; Sat, 9 Sep 2023 14:17:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IELDGWiL1ukC1o9RRfIIxVq8zJBJOfUiPe0uJONgqWbG5CG+5LIhEBN3XpRcY8+HlkZAROj X-Received: by 2002:a05:6808:23d4:b0:3a3:baf8:5b8a with SMTP id bq20-20020a05680823d400b003a3baf85b8amr8252398oib.13.1694294231295; Sat, 09 Sep 2023 14:17:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694294231; cv=none; d=google.com; s=arc-20160816; b=LOagPJS7/+9tGhsFgpKkkwMdWmIvy6pdeMaCkDNmYRIRvVwflWl0IdrdmuXzufSUeN n2CowYutTPOsBTIHivo1seX/49ZvgNr//UEx1RPr1MbecwB2MsrW3G6SvxYwAoeg+p60 qL7a1QbBu0hTDugvbxTNAtC7E32str+tO3FSD8Edvvn8hkQtLuBr15nnpm9ASEvWtvlO M6DvMIu5/KG0nCQSAPT7AYiQNqQ6SVuHOLif2L7izzkxZzamLpPmi82DYjuF5507LftY +kHpTksQ/S6TzV8eNNqb56Y/Gdpep/SY/WyAmke4K9F1Y90yW/hn6SIVKp2eS+xB3910 3/9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:from :dkim-signature; bh=u9TmyMjuPTNAblor8OwPK1A1ey4pwH8Hdhs6lWbOca8=; fh=94uYpO7FLrgLLvAQT7RSjW70OHzxQpeK2ugekYHQA8k=; b=hamQmpRczY2M2GZrrOgK9w6ulrY9qyD6+0wQ/DGOVyS/n/SHrPRxzUzxr5oa5hQncs hhhXCjfTrQAwyn1y9RfqvYWaFRMc02RNNC//07GkuyjJjDQj3O2R7DOE772KnqFEB44Z z3qXqpTFdPZvjyB8yhuR4D+s+Df4spMM2ulaKfuCsC+8uXpTC95md6wcjk6MCGXZEVLN ltFP5hSEkmQuceuJ7urJTkt98+Wj1WE6taZtmVq4mWg+PWAZnrC7cK2Cfu69LvFP/J8x 6ZD4X0Y9qCREIprfFbE8VJtvt1dlSMwUFIq0ZUWYaQ7YgIKuQE1a/SkFZGriov34EEEj B8/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@kernel.org header.s=k20201202 header.b=Q6nGX0tP; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q18-20020a656252000000b0057414c0fc48si3472497pgv.638.2023.09.09.14.16.57; Sat, 09 Sep 2023 14:17:11 -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=fail header.i=@kernel.org header.s=k20201202 header.b=Q6nGX0tP; 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 S241511AbjIIDhg (ORCPT + 99 others); Fri, 8 Sep 2023 23:37:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43870 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239261AbjIIDha (ORCPT ); Fri, 8 Sep 2023 23:37:30 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 236861FE5; Fri, 8 Sep 2023 20:37:27 -0700 (PDT) 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 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 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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), {}, -- 2.25.1