From patchwork Thu Jun 15 18:33:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 108688 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp856754vqr; Thu, 15 Jun 2023 12:07:47 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6TQ6G3Wls44AV3e1iF220biNvLuHxE8k4Q17l45bF4RTvr0DmKOPNglX16CQaLfJJYPx28 X-Received: by 2002:a17:907:3e16:b0:985:259f:6f50 with SMTP id hp22-20020a1709073e1600b00985259f6f50mr53202ejc.34.1686856067311; Thu, 15 Jun 2023 12:07:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686856067; cv=none; d=google.com; s=arc-20160816; b=zbPYIGKtxog4lJTjPXuqsIbmtZpF3TYAaU8AxirUOgCqv7jFG1KkunJ8OKmqMjA7bn TeB2tpmpkstweV7CPqadK6fudcYgw/WrstRAvsYBRud3dqHgfNcSs+iCKgUOd0wnQBOg WRHZS6kd29EhnGZMtjlGLJLY4lAaRuwOaUPtEgcRy3bAir8XfW6su7dg1h3UNILOs0ht tNAT5XujzuFKlkDKi81q9xXIT5PEYBWe+Al5LLwtREwObyApt95EIpCriRSfZbps2KwO 90poW7ZfjJkopcdG3R7Ae76Eq20TvDznkob3xcSWNWrZ3lrl9H0LON31Gf5bWBmHqBMf BZOA== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=77u9Ecxe/k177BLYwpjv293sgACR8Td6+c5LpAU7e70=; b=xRPADH59KUa8vpLjskRe3PIo8chMRbizSMgfGA36RDto1wK7IfhQPA3/cAZRLmpyqz W5PeQYF/JZCIGKcponk9rvghbVDOkRpghr5vmO2WgY3ym2l50UAPVOstT7BOrEElfUa3 U+MXYHVwoZ3oDKwYPhWDvaHNRu7qeNZOewVRvuMIv2m2lRz/PX/rkEGTPW+KeosQJfJm CItRYk+cNOE3FZlnWf3x3FjOS7YCBhWvDx01nS47MY0T1y4nqIUg5EP0AXbSmAhOAKOh hmvnLVzItN16xcyhZg041L6qA2X+FWqgeNsR7begaytX1JUXhYbqyGgk9C46p0wXIszK E40w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="fvmFV/WW"; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i7-20020a1709063c4700b00973877aac6fsi9546245ejg.30.2023.06.15.12.07.21; Thu, 15 Jun 2023 12:07:47 -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=pass header.i=@kernel.org header.s=k20201202 header.b="fvmFV/WW"; 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 S229723AbjFOSeI (ORCPT + 99 others); Thu, 15 Jun 2023 14:34:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43166 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229771AbjFOSeD (ORCPT ); Thu, 15 Jun 2023 14:34:03 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0386D270A for ; Thu, 15 Jun 2023 11:33:30 -0700 (PDT) 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 8D01B61E22 for ; Thu, 15 Jun 2023 18:33:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7D96EC433C8; Thu, 15 Jun 2023 18:33:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686854009; bh=Dsjd+ZpmvL/6xXc3Y13JGILcWmi7U4GqyYJ6md9X1xY=; h=From:To:Cc:Subject:Date:From; b=fvmFV/WWm6mNcOwWDpoxuttJZLSXSm9ssx8ToCjmoc+cU34XimcYrjr40gM60l9Rq 0fQINZ45Fqh+rXllOcuqIQLG8+Y8TzEUkIjXv8qPDZ3SlVa1XFkPQDIMG8ms5CWUsV cEqIsm/794h9b10+BGqxu3XPqzmmVMZoIBar/pOOdt58PU5zmG1LmJKjqvspCDTyoa y+ayOOLfq7RiJy36JsOR42b/eFiPNv2ekpW2Jsvt577E6C+o1wLaiQ0TB2bDzWL4Bs cX5VJnT4kI/pE7PF8agPnlLQN0H3rRum+cWkATm+AJTrWlTgqRMj+BKkkipUR87EEu 1ph524/oH87Gw== From: SeongJae Park To: akpm@linux-foundation.org Cc: SeongJae Park , wangkefeng.wang@huawei.com, damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH] mm/damon/core-test: add a test for damon_set_attrs() Date: Thu, 15 Jun 2023 18:33:22 +0000 Message-Id: <20230615183323.87561-1-sj@kernel.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 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,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768796787439000097?= X-GMAIL-MSGID: =?utf-8?q?1768796787439000097?= Commit 5ff6e2fff88e ("mm/damon/core: fix divide error in damon_nr_accesses_to_accesses_bp()") fixed a bug by adding arguments validation in damon_set_attrs(). Add a unit test for the added validation to ensure the bug cannot occur again. Signed-off-by: SeongJae Park Reviewed-by: Kefeng Wang --- mm/damon/core-test.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/mm/damon/core-test.h b/mm/damon/core-test.h index fae64d32b925..c11210124344 100644 --- a/mm/damon/core-test.h +++ b/mm/damon/core-test.h @@ -318,6 +318,29 @@ static void damon_test_update_monitoring_result(struct kunit *test) KUNIT_EXPECT_EQ(test, r->age, 20); } +static void damon_test_set_attrs(struct kunit *test) +{ + struct damon_ctx ctx; + struct damon_attrs valid_attrs = { + .min_nr_regions = 10, .max_nr_regions = 1000, + .sample_interval = 5000, .aggr_interval = 100000,}; + struct damon_attrs invalid_attrs; + + KUNIT_EXPECT_EQ(test, damon_set_attrs(&ctx, &valid_attrs), 0); + + invalid_attrs = valid_attrs; + invalid_attrs.min_nr_regions = 1; + KUNIT_EXPECT_EQ(test, damon_set_attrs(&ctx, &invalid_attrs), -EINVAL); + + invalid_attrs = valid_attrs; + invalid_attrs.max_nr_regions = 9; + KUNIT_EXPECT_EQ(test, damon_set_attrs(&ctx, &invalid_attrs), -EINVAL); + + invalid_attrs = valid_attrs; + invalid_attrs.aggr_interval = 4999; + KUNIT_EXPECT_EQ(test, damon_set_attrs(&ctx, &invalid_attrs), -EINVAL); +} + static struct kunit_case damon_test_cases[] = { KUNIT_CASE(damon_test_target), KUNIT_CASE(damon_test_regions), @@ -329,6 +352,7 @@ static struct kunit_case damon_test_cases[] = { KUNIT_CASE(damon_test_ops_registration), KUNIT_CASE(damon_test_set_regions), KUNIT_CASE(damon_test_update_monitoring_result), + KUNIT_CASE(damon_test_set_attrs), {}, };