Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp4304754rdb; Thu, 14 Sep 2023 19:53:27 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHTlqbadTyNozpxrtWcRyLPdTJEwC8Ybu50JtlYwJYt6eZKWBK5KpWtY9TmmURzeyHtLswd X-Received: by 2002:a05:620a:461f:b0:76f:16e9:be92 with SMTP id br31-20020a05620a461f00b0076f16e9be92mr275885qkb.11.1694746407054; Thu, 14 Sep 2023 19:53:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694746407; cv=none; d=google.com; s=arc-20160816; b=R4LGDIMnEZu96AgMBUm3HNB2aFs3Aj2Em+8flmPlr3ybpd2ugDSZihc65KARRIisx5 WvKAKZ5u7EFth6EtdBeWh1TVV8pbF0HWrxQ0cW1a/qdUwPTkQg6Hr29g6I4v5jyaCXZz SKEfIsIYT3JbHCiifFRxAJ/O9QjGTM+eiVYEWeiTO4/t3hjFcVYSsQJEQ5JPllYdStNk VncgVBvvCEc4SkXjUNV5Nkzp9Nakw7T1wrj7E2Po7a3IkYKVzG0RBBE0RVZe7+0W9Bf3 UHZ4lpaJKQf6K9r2XmMK2TFftvMJaGqw8RX4MS/7piMztmXcnZ1quYxgTwE4HQrpzNEK MU0g== 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=u9TmyMjuPTNAblor8OwPK1A1ey4pwH8Hdhs6lWbOca8=; fh=KYrqrUZLyrFtzsRGU6oAoSUmY0DAP9CMMvmnxe+fdzY=; b=TTIjvlwgi9QoV/XUdUgGbhMfeyZT3tp+EAIZY3HzMzt9ayaewG3ozZo+3M5XV7oYPA OHAC3LQN8TfegM0f98RKmkZYI5o7ppmL98jC2TqJigZ05PAmtZbhlGszyWNgAWypuLle MU/eGE7DqKm/Ar27xCbDENZ0TvkY1fbaXgieF2tGPVrdjX/nUR+UN3uHS2Z6X/VpC+k7 98qdfi9x93XbRoEMz9HXEh2svw3/iOxA5pQiEnpKIC3Go7FGpDiTqQU7N1nqIfv4aoyO 1TWuJHv3RZ7wm8lsCydLri+TInG6s0cv7/BohsgX9aCRfVGhKiaqp4ApYzw3EYqS08mB Gnfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=vE+6+K2v; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id a35-20020a631a63000000b00563d74b6347si2408730pgm.863.2023.09.14.19.53.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 19:53:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=vE+6+K2v; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id BC1848390007; Thu, 14 Sep 2023 19:53:23 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231799AbjIOCxP (ORCPT + 99 others); Thu, 14 Sep 2023 22:53:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44958 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231722AbjIOCxL (ORCPT ); Thu, 14 Sep 2023 22:53:11 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 806B72703; Thu, 14 Sep 2023 19:53:07 -0700 (PDT) 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 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Thu, 14 Sep 2023 19:53:23 -0700 (PDT) X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email 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