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: 140042 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp765631vqi; Thu, 14 Sep 2023 19:53:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEls1EpxckH5mAabOk6Bi3jQlDhAzwjHtmZLPYRrWWkDheBLyce/M6vFq6BlfEeQJGpepcj X-Received: by 2002:a05:6a20:1581:b0:12c:b10d:693d with SMTP id h1-20020a056a20158100b0012cb10d693dmr684628pzj.6.1694746425282; Thu, 14 Sep 2023 19:53:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694746425; cv=none; d=google.com; s=arc-20160816; b=rZ7HMS9yZSs40OlArSSuMfYwmQWvMP/lNDJe8fYWRKwe3jc2HYNkN3bsYUjo3RKTL9 0c7IOU1E5LdDeUuYXtYyIS1sXYAbDOr4OkNyGBrp1HANLHdH6SRCfdbu10adsF8GTX7Z 2NWvD8GKvJVoAw1+/cDfajrMQWIwePn79DIO3WKEX9az90E4Pa2JU6yeRzx5UghQdeKt avBHyzmNW5TPU7vSRA0w1uD0dBpwqh4vJKUBjY/AmFefDtD98uyk2dSvW3fc0GPFgfri +v/en2ql/kCyTAyLIKMrDAtJaOy9NJyFtlYR7veVSwvZ4S6HREIjAUN8vGiiQjkW3cPk EKQA== 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 23.128.96.38 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 fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id on16-20020a17090b1d1000b00274681ee3adsi2691201pjb.8.2023.09.14.19.53.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 19:53:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; 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 23.128.96.38 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 26BB1838F07F; Thu, 14 Sep 2023 19:53:43 -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 S231803AbjIOCxP (ORCPT + 33 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 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:43 -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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777070427241354467 X-GMAIL-MSGID: 1777070427241354467 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), {},