From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.3 required=3.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 483CAC33CB3 for ; Fri, 31 Jan 2020 00:15:00 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id CC302217BA for ; Fri, 31 Jan 2020 00:14:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="L+S/ueOt" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CC302217BA Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 545E16B0492; Thu, 30 Jan 2020 19:14:59 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4F2146B0493; Thu, 30 Jan 2020 19:14:59 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3E11D6B0494; Thu, 30 Jan 2020 19:14:59 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0131.hostedemail.com [216.40.44.131]) by kanga.kvack.org (Postfix) with ESMTP id 269316B0492 for ; Thu, 30 Jan 2020 19:14:59 -0500 (EST) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id DE25345CD for ; Fri, 31 Jan 2020 00:14:58 +0000 (UTC) X-FDA: 76436009076.24.rod57_65978b8e4692c X-HE-Tag: rod57_65978b8e4692c X-Filterd-Recvd-Size: 23378 Received: from mail-pg1-f196.google.com (mail-pg1-f196.google.com [209.85.215.196]) by imf24.hostedemail.com (Postfix) with ESMTP for ; Fri, 31 Jan 2020 00:14:58 +0000 (UTC) Received: by mail-pg1-f196.google.com with SMTP id z124so2486759pgb.13 for ; Thu, 30 Jan 2020 16:14:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=PJvpOzkSpH5moLMAnd53cwYtElWV0Wkl0w3s6oAjBVU=; b=L+S/ueOtjfv2Ymm0gPx2DY1HXf1cp2Ug76fzCuPUD+sUf8KeQ8DRSZ8unLZpHDsz1w FhRMIjiXUHuMT1p5sHS5RbYZUQKjXaLsfFZnVsOB1Gdz19ZxoOjOaaGgNc+hqXXHljCB vfSh92we7dPJGj5mBTKBpxNQp2NXQ/w9fEbtmoMVfDhIkbGazxEHCxEpbTCuWfVNxwsy CAXt2Fl/LOtCRB39zmQ3bD986Eu+J3PYYfII6Sb5oI33YL6Bqb+g7D8IvajSQzHyc9og pyWkkeY53A50faLjhcWOUu5ulFNKXLF/OEmv0x9E0h0ho7csMWavoAbY70VHDRitUltu IZ9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=PJvpOzkSpH5moLMAnd53cwYtElWV0Wkl0w3s6oAjBVU=; b=jggBy0e6ZtcViCALMEIG8G004NjiUwHm95U2cKUoEWjFFJDGK8MjxykPrMx6TPxk6L Z36MaWfpQ5NocVpScr2qvxnzw+ZTD8lK8IQZAULGIzofqNXjr2NXp444jXVro97XVcAF hUXsuaiapbPDhU9hqAoK/Y73M18ORvgxvlvPNm+Lm8YbsPdr1w6lM4pFvrXY1ZnX8zMy tzlO+8DtbMpeNz1wxFROpCCJsAfIl6Ah5QR/HSD2jBeMGkQDaQs5hTHMvopW3SwQTzqn LNth22cZCu6IIyJkNcD4VqpVnKTeKmqCPyxXPvBMOfkxWWZGgsoQcJFKen7xOyX/iVw/ xa4Q== X-Gm-Message-State: APjAAAXC/9EjsrnySOVBrHiU3J4cD6qjnXx/dX2oTQN/hj1tWWUfm0Xv hLprSB0STwPkpr5JWOqhhBu2KjSFkM97xDMCoiCIwQ== X-Google-Smtp-Source: APXvYqzyDCxkNQI+bHVR6vZlIJkiVNXzGV5PEGQtDMuBxbo02R8a96u6N76V6GsDy921MAG//VFQu/jBjGswVp/Z0oQ= X-Received: by 2002:aa7:961b:: with SMTP id q27mr7709129pfg.23.1580429696504; Thu, 30 Jan 2020 16:14:56 -0800 (PST) MIME-Version: 1.0 References: <20200128085742.14566-1-sjpark@amazon.com> <20200128090127.16063-1-sjpark@amazon.com> In-Reply-To: <20200128090127.16063-1-sjpark@amazon.com> From: Brendan Higgins Date: Thu, 30 Jan 2020 16:14:45 -0800 Message-ID: Subject: Re: [PATCH v2 8/9] mm/damon: Add kunit tests To: SeongJae Park Cc: Andrew Morton , SeongJae Park , SeongJae Park , acme@kernel.org, amit@kernel.org, brendan.d.gregg@gmail.com, Jonathan Corbet , dwmw@amazon.com, mgorman@suse.de, Steven Rostedt , kirill@shutemov.name, colin.king@canonical.com, minchan@kernel.org, vdavydov.dev@gmail.com, vdavydov@parallels.com, linux-mm@kvack.org, "open list:DOCUMENTATION" , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" 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: On Tue, Jan 28, 2020 at 1:01 AM wrote: > > From: SeongJae Park > > This commit adds kunit based unit tests for DAMON. > > Signed-off-by: SeongJae Park > --- > MAINTAINERS | 1 + > mm/Kconfig | 11 + > mm/damon-test.h | 571 ++++++++++++++++++++++++++++++++++++++++++++++++ > mm/damon.c | 2 + > 4 files changed, 585 insertions(+) > create mode 100644 mm/damon-test.h > > diff --git a/MAINTAINERS b/MAINTAINERS > index 5c8a0c4e69b8..cb091bee16c7 100644 > --- a/MAINTAINERS > +++ b/MAINTAINERS > @@ -4616,6 +4616,7 @@ M: SeongJae Park > L: linux-mm@kvack.org > S: Maintained > F: mm/damon.c > +F: mm/damon-test.h > F: tools/damon/* > F: Documentation/admin-guide/mm/data_access_monitor.rst > > diff --git a/mm/Kconfig b/mm/Kconfig > index 144fb916aa8b..8b34711c6ee1 100644 > --- a/mm/Kconfig > +++ b/mm/Kconfig > @@ -751,4 +751,15 @@ config DAMON > be 1) accurate enough to be useful for performance-centric domains, > and 2) sufficiently light-weight so that it can be applied online. > > +config DAMON_KUNIT_TEST > + bool "Test for damon" > + depends on DAMON && KUNIT > + help > + This builds the DAMON Kunit test suite. > + > + For more information on KUnit and unit tests in general, please refer > + to the KUnit documentation. > + > + If unsure, say N. > + > endmenu > diff --git a/mm/damon-test.h b/mm/damon-test.h > new file mode 100644 > index 000000000000..3d92548058a7 > --- /dev/null > +++ b/mm/damon-test.h [...] > +/* > + * Test damon_three_regions_in_vmas() function > + * > + * DAMON converts the complex and dynamic memory mappings of each target task > + * to three discontiguous regions which cover every mapped areas. The two gaps > + * between the areas is two biggest unmapped areas in the original mapping. > + * 'damon_three_regions_in_vmas() receives an address space of a process. It > + * first identifies the start of mappings, end of mappings, and the two biggest > + * unmapped areas. After that, based on the information, it constructs the > + * three regions and returns. For more detail, refer to the comment of > + * 'damon_init_regions_of()' function definition in 'mm/damon.c' file. > + * > + * For example, suppose virtual address ranges of 10-20, 20-25, 200-210, > + * 210-220, 300-305, and 307-330 (Other comments represent this mappings in > + * more short form: 10-20-25, 200-210-220, 300-305, 307-330) of a process are > + * mapped. To cover every mappings, the three regions should start with 10, > + * and end with 305. Why? What's special about those numbers? Don't you need 10 to 330 to cover all the mappings? > The process also has three unmapped areas, 25-200, > + * 220-300, and 305-307. Among those, 25-200 and 220-300 are the biggest two > + * unmapped areas, and thus it should be converted to three regions of 10-25, > + * 200-220, and 300-330. > + */ > +static void damon_test_three_regions_in_vmas(struct kunit *test) > +{ > + struct region regions[3] = {0,}; > + /* 10-20-25, 200-210-220, 300-305, 307-330 */ > + struct vm_area_struct vmas[] = { > + (struct vm_area_struct) {.vm_start = 10, .vm_end = 20}, > + (struct vm_area_struct) {.vm_start = 20, .vm_end = 25}, > + (struct vm_area_struct) {.vm_start = 200, .vm_end = 210}, > + (struct vm_area_struct) {.vm_start = 210, .vm_end = 220}, > + (struct vm_area_struct) {.vm_start = 300, .vm_end = 305}, > + (struct vm_area_struct) {.vm_start = 307, .vm_end = 330}, > + }; > + vmas[0].vm_next = &vmas[1]; > + vmas[1].vm_next = &vmas[2]; > + vmas[2].vm_next = &vmas[3]; > + vmas[3].vm_next = &vmas[4]; > + vmas[4].vm_next = &vmas[5]; > + vmas[5].vm_next = NULL; > + > + damon_three_regions_in_vmas(&vmas[0], regions); > + > + KUNIT_EXPECT_EQ(test, 10ul, regions[0].start); > + KUNIT_EXPECT_EQ(test, 25ul, regions[0].end); > + KUNIT_EXPECT_EQ(test, 200ul, regions[1].start); > + KUNIT_EXPECT_EQ(test, 220ul, regions[1].end); > + KUNIT_EXPECT_EQ(test, 300ul, regions[2].start); > + KUNIT_EXPECT_EQ(test, 330ul, regions[2].end); > +} > + > +/* Clean up global state of damon */ > +static void damon_cleanup_global_state(void) > +{ > + struct damon_task *t, *next; > + > + damon_for_each_task_safe(t, next) > + damon_destroy_task(t); > + > + damon_rbuf_offset = 0; > +} > + > +/* > + * Test kdamond_flush_aggregated() > + * > + * DAMON checks access to each region and aggregates this information as the > + * access frequency of each region. In detail, it increases '->nr_accesses' of > + * regions that an access has confirmed. 'kdamond_flush_aggregated()' flushes > + * the aggregated information ('->nr_accesses' of each regions) to the result > + * buffer. As a result of the flushing, the '->nr_accesses' of regions are > + * initialized to zero. > + */ > +static void damon_test_aggregate(struct kunit *test) > +{ > + unsigned long pids[] = {1, 2, 3}; > + unsigned long saddr[][3] = {{10, 20, 30}, {5, 42, 49}, {13, 33, 55} }; > + unsigned long eaddr[][3] = {{15, 27, 40}, {31, 45, 55}, {23, 44, 66} }; > + unsigned long accesses[][3] = {{42, 95, 84}, {10, 20, 30}, {0, 1, 2} }; > + struct damon_task *t; > + struct damon_region *r; > + int it, ir; > + ssize_t sz, sr, sp; > + > + damon_set_pids(pids, 3); > + > + it = 0; > + damon_for_each_task(t) { > + for (ir = 0; ir < 3; ir++) { > + r = damon_new_region(saddr[it][ir], eaddr[it][ir]); > + r->nr_accesses = accesses[it][ir]; > + damon_add_region_tail(r, t); > + } > + it++; > + } > + kdamond_flush_aggregated(); > + it = 0; > + damon_for_each_task(t) { > + ir = 0; > + /* '->nr_accesses' should be zeroed */ > + damon_for_each_region(r, t) { > + KUNIT_EXPECT_EQ(test, 0u, r->nr_accesses); > + ir++; > + } > + /* regions should be preserved */ > + KUNIT_EXPECT_EQ(test, 3, ir); > + it++; > + } > + /* tasks also should be preserved */ > + KUNIT_EXPECT_EQ(test, 3, it); > + > + /* The aggregated information should be written in the buffer */ > + sr = sizeof(r->vm_start) + sizeof(r->vm_end) + sizeof(r->nr_accesses); > + sp = sizeof(t->pid) + sizeof(unsigned int) + 3 * sr; > + sz = sizeof(struct timespec64) + sizeof(unsigned int) + 3 * sp; > + KUNIT_EXPECT_EQ(test, (unsigned int)sz, damon_rbuf_offset); > + > + damon_cleanup_global_state(); > +} > + > +static void damon_test_write_rbuf(struct kunit *test) > +{ > + char *data; > + > + data = "hello"; > + damon_write_rbuf(data, strnlen(data, 256)); > + KUNIT_EXPECT_EQ(test, damon_rbuf_offset, 5u); > + > + damon_write_rbuf(data, 0); > + KUNIT_EXPECT_EQ(test, damon_rbuf_offset, 5u); > + > + KUNIT_EXPECT_STREQ(test, (char *)damon_rbuf, data); > +} > + > +/* > + * Test 'damon_apply_three_regions()' > + * > + * test kunit object > + * regions an array containing start/end addresses of current > + * monitoring target regions > + * nr_regions the number of the addresses in 'regions' > + * three_regions The three regions that need to be applied now > + * expected start/end addresses of monitoring target regions that > + * 'three_regions' are applied > + * nr_expected the number of addresses in 'expected' > + * > + * The memory mapping of the target processes changes dynamically. To follow > + * the change, DAMON periodically reads the mappings, simplifies it to the > + * three regions, and updates the monitoring target regions to fit in the three > + * regions. The update of current target regions is the role of > + * 'damon_apply_three_regions()'. > + * > + * This test passes the given target regions and the new three regions that > + * need to be applied to the function and check whether it updates the regions > + * as expected. > + */ > +static void damon_do_test_apply_three_regions(struct kunit *test, > + unsigned long *regions, int nr_regions, > + struct region *three_regions, > + unsigned long *expected, int nr_expected) > +{ > + struct damon_task *t; > + struct damon_region *r; > + int i; > + > + t = damon_new_task(42); > + for (i = 0; i < nr_regions / 2; i++) { > + r = damon_new_region(regions[i * 2], regions[i * 2 + 1]); > + damon_add_region_tail(r, t); > + } > + damon_add_task_tail(t); > + > + damon_apply_three_regions(t, three_regions); > + > + for (i = 0; i < nr_expected / 2; i++) { > + r = damon_nth_region_of(t, i); > + KUNIT_EXPECT_EQ(test, r->vm_start, expected[i * 2]); > + KUNIT_EXPECT_EQ(test, r->vm_end, expected[i * 2 + 1]); > + } > + > + damon_cleanup_global_state(); > +} > + > +/* below 4 functions test differnt inputs for 'damon_apply_three_regions()' */ Spelling. Also, I think this comment doesn't really say anything that you cannot get from reading the code. Maybe provide some more details? Maybe add why you picked the inputs that you did? > +static void damon_test_apply_three_regions1(struct kunit *test) > +{ > + /* 10-20-30, 50-55-57-59, 70-80-90-100 */ > + unsigned long regions[] = {10, 20, 20, 30, 50, 55, 55, 57, 57, 59, > + 70, 80, 80, 90, 90, 100}; > + /* 5-27, 45-55, 73-104 */ > + struct region new_three_regions[3] = { > + (struct region){.start = 5, .end = 27}, > + (struct region){.start = 45, .end = 55}, > + (struct region){.start = 73, .end = 104} }; > + /* 5-20-27, 45-55, 73-80-90-104 */ > + unsigned long expected[] = {5, 20, 20, 27, 45, 55, > + 73, 80, 80, 90, 90, 104}; > + > + damon_do_test_apply_three_regions(test, regions, ARRAY_SIZE(regions), > + new_three_regions, expected, ARRAY_SIZE(expected)); > +} > + > +static void damon_test_apply_three_regions2(struct kunit *test) > +{ > + /* 10-20-30, 50-55-57-59, 70-80-90-100 */ > + unsigned long regions[] = {10, 20, 20, 30, 50, 55, 55, 57, 57, 59, > + 70, 80, 80, 90, 90, 100}; > + /* 5-27, 56-57, 65-104 */ > + struct region new_three_regions[3] = { > + (struct region){.start = 5, .end = 27}, > + (struct region){.start = 56, .end = 57}, > + (struct region){.start = 65, .end = 104} }; > + /* 5-20-27, 56-57, 65-80-90-104 */ > + unsigned long expected[] = {5, 20, 20, 27, 56, 57, > + 65, 80, 80, 90, 90, 104}; > + > + damon_do_test_apply_three_regions(test, regions, ARRAY_SIZE(regions), > + new_three_regions, expected, ARRAY_SIZE(expected)); > +} > + > +static void damon_test_apply_three_regions3(struct kunit *test) > +{ > + /* 10-20-30, 50-55-57-59, 70-80-90-100 */ > + unsigned long regions[] = {10, 20, 20, 30, 50, 55, 55, 57, 57, 59, > + 70, 80, 80, 90, 90, 100}; > + /* 5-27, 61-63, 65-104 */ > + struct region new_three_regions[3] = { > + (struct region){.start = 5, .end = 27}, > + (struct region){.start = 61, .end = 63}, > + (struct region){.start = 65, .end = 104} }; > + /* 5-20-27, 61-63, 65-80-90-104 */ > + unsigned long expected[] = {5, 20, 20, 27, 61, 63, > + 65, 80, 80, 90, 90, 104}; > + > + damon_do_test_apply_three_regions(test, regions, ARRAY_SIZE(regions), > + new_three_regions, expected, ARRAY_SIZE(expected)); > +} > + > +static void damon_test_apply_three_regions4(struct kunit *test) > +{ > + /* 10-20-30, 50-55-57-59, 70-80-90-100 */ > + unsigned long regions[] = {10, 20, 20, 30, 50, 55, 55, 57, 57, 59, > + 70, 80, 80, 90, 90, 100}; > + /* 5-7, 30-32, 65-68 */ > + struct region new_three_regions[3] = { > + (struct region){.start = 5, .end = 7}, > + (struct region){.start = 30, .end = 32}, > + (struct region){.start = 65, .end = 68} }; > + /* expect 5-7, 30-32, 65-68 */ > + unsigned long expected[] = {5, 7, 30, 32, 65, 68}; > + > + damon_do_test_apply_three_regions(test, regions, ARRAY_SIZE(regions), > + new_three_regions, expected, ARRAY_SIZE(expected)); > +} > + > +static void damon_test_split_evenly(struct kunit *test) > +{ > + struct damon_task *t; > + struct damon_region *r; > + unsigned long i; > + > + KUNIT_EXPECT_EQ(test, damon_split_region_evenly(NULL, 5), -EINVAL); > + > + t = damon_new_task(42); > + r = damon_new_region(0, 100); > + KUNIT_EXPECT_EQ(test, damon_split_region_evenly(r, 0), -EINVAL); > + > + damon_add_region_tail(r, t); > + KUNIT_EXPECT_EQ(test, damon_split_region_evenly(r, 10), 0); > + KUNIT_EXPECT_EQ(test, nr_damon_regions(t), 10u); > + > + i = 0; > + damon_for_each_region(r, t) { > + KUNIT_EXPECT_EQ(test, r->vm_start, i++ * 10); > + KUNIT_EXPECT_EQ(test, r->vm_end, i * 10); > + } > + damon_free_task(t); > + > + t = damon_new_task(42); > + r = damon_new_region(5, 59); > + damon_add_region_tail(r, t); > + KUNIT_EXPECT_EQ(test, damon_split_region_evenly(r, 5), 0); > + KUNIT_EXPECT_EQ(test, nr_damon_regions(t), 5u); > + > + i = 0; > + damon_for_each_region(r, t) { > + if (i == 4) > + break; > + KUNIT_EXPECT_EQ(test, r->vm_start, 5 + 10 * i++); > + KUNIT_EXPECT_EQ(test, r->vm_end, 5 + 10 * i); > + } > + KUNIT_EXPECT_EQ(test, r->vm_start, 5 + 10 * i); > + KUNIT_EXPECT_EQ(test, r->vm_end, 59ul); > + damon_free_task(t); > + > + t = damon_new_task(42); > + r = damon_new_region(5, 6); > + damon_add_region_tail(r, t); > + KUNIT_EXPECT_EQ(test, damon_split_region_evenly(r, 2), -EINVAL); > + KUNIT_EXPECT_EQ(test, nr_damon_regions(t), 1u); > + > + damon_for_each_region(r, t) { > + KUNIT_EXPECT_EQ(test, r->vm_start, 5ul); > + KUNIT_EXPECT_EQ(test, r->vm_end, 6ul); > + } > + damon_free_task(t); > +} > + > +static void damon_test_split_at(struct kunit *test) > +{ > + struct damon_task *t; > + struct damon_region *r; > + > + t = damon_new_task(42); > + r = damon_new_region(0, 100); > + damon_add_region_tail(r, t); > + damon_split_region_at(r, 25); > + KUNIT_EXPECT_EQ(test, r->vm_start, 0ul); > + KUNIT_EXPECT_EQ(test, r->vm_end, 25ul); > + > + r = damon_next_region(r); > + KUNIT_EXPECT_EQ(test, r->vm_start, 25ul); > + KUNIT_EXPECT_EQ(test, r->vm_end, 100ul); > + > + damon_free_task(t); > +} > + > +static void damon_test_merge_two(struct kunit *test) > +{ > + struct damon_task *t; > + struct damon_region *r, *r2, *r3; > + int i; > + > + t = damon_new_task(42); > + r = damon_new_region(0, 100); > + r->nr_accesses = 10; > + damon_add_region_tail(r, t); > + r2 = damon_new_region(100, 300); > + r2->nr_accesses = 20; > + damon_add_region_tail(r2, t); > + > + damon_merge_two_regions(r, r2); > + KUNIT_EXPECT_EQ(test, r->vm_start, 0ul); > + KUNIT_EXPECT_EQ(test, r->vm_end, 300ul); > + KUNIT_EXPECT_EQ(test, r->nr_accesses, 16u); > + > + i = 0; > + damon_for_each_region(r3, t) { > + KUNIT_EXPECT_PTR_EQ(test, r, r3); > + i++; > + } > + KUNIT_EXPECT_EQ(test, i, 1); > + > + damon_free_task(t); > +} > + > +static void damon_test_merge_regions_of(struct kunit *test) > +{ > + struct damon_task *t; > + struct damon_region *r; > + unsigned long sa[] = {0, 100, 114, 122, 130, 156, 170, 184}; > + unsigned long ea[] = {100, 112, 122, 130, 156, 170, 184, 230}; > + unsigned int nrs[] = {0, 0, 10, 10, 20, 30, 1, 2}; > + > + unsigned long saddrs[] = {0, 114, 130, 156, 170}; > + unsigned long eaddrs[] = {112, 130, 156, 170, 230}; > + int i; > + > + t = damon_new_task(42); > + for (i = 0; i < ARRAY_SIZE(sa); i++) { > + r = damon_new_region(sa[i], ea[i]); > + r->nr_accesses = nrs[i]; > + damon_add_region_tail(r, t); > + } > + > + damon_merge_regions_of(t, 9); > + /* 0-112, 114-130, 130-156, 156-170 */ > + KUNIT_EXPECT_EQ(test, nr_damon_regions(t), 5u); > + for (i = 0; i < 5; i++) { > + r = damon_nth_region_of(t, i); > + KUNIT_EXPECT_EQ(test, r->vm_start, saddrs[i]); > + KUNIT_EXPECT_EQ(test, r->vm_end, eaddrs[i]); > + } > + damon_free_task(t); > +} > + > +static void damon_test_split_regions_of(struct kunit *test) > +{ > + struct damon_task *t; > + struct damon_region *r; > + > + t = damon_new_task(42); > + r = damon_new_region(0, 22); > + damon_add_region_tail(r, t); > + damon_split_regions_of(t); > + KUNIT_EXPECT_EQ(test, nr_damon_regions(t), 2u); > + damon_free_task(t); > +} > + > +static void damon_test_kdamond_need_stop(struct kunit *test) > +{ > + KUNIT_EXPECT_TRUE(test, kdamond_need_stop()); This doesn't look like a useful test, or a useful function. Why even check if the function always returns true? And if it doesn't always return true, then this test is not hermetic which is bad unit testing practice. > +} > + > +static struct kunit_case damon_test_cases[] = { > + KUNIT_CASE(damon_test_str_to_pids), > + KUNIT_CASE(damon_test_tasks), > + KUNIT_CASE(damon_test_regions), > + KUNIT_CASE(damon_test_set_pids), > + KUNIT_CASE(damon_test_three_regions_in_vmas), > + KUNIT_CASE(damon_test_aggregate), > + KUNIT_CASE(damon_test_write_rbuf), > + KUNIT_CASE(damon_test_apply_three_regions1), > + KUNIT_CASE(damon_test_apply_three_regions2), > + KUNIT_CASE(damon_test_apply_three_regions3), > + KUNIT_CASE(damon_test_apply_three_regions4), > + KUNIT_CASE(damon_test_split_evenly), > + KUNIT_CASE(damon_test_split_at), > + KUNIT_CASE(damon_test_merge_two), > + KUNIT_CASE(damon_test_merge_regions_of), > + KUNIT_CASE(damon_test_split_regions_of), > + KUNIT_CASE(damon_test_kdamond_need_stop), > + {}, > +}; > + > +static struct kunit_suite damon_test_suite = { > + .name = "damon", > + .test_cases = damon_test_cases, > +}; > +kunit_test_suite(damon_test_suite); > + > +#endif /* _DAMON_TEST_H */ > + > +#endif /* CONFIG_DAMON_KUNIT_TEST */ > diff --git a/mm/damon.c b/mm/damon.c > index 3e1b5eb945ea..f21968f079f0 100644 > --- a/mm/damon.c > +++ b/mm/damon.c > @@ -1289,3 +1289,5 @@ module_exit(damon_exit); > MODULE_LICENSE("GPL"); > MODULE_AUTHOR("SeongJae Park "); > MODULE_DESCRIPTION("DAMON: Data Access MONitor"); > + > +#include "damon-test.h" > -- > 2.17.1 >